blob: 4941997c484efb064133c8068960e772d2e64639 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/************************************************************************
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 *
Leubner, Achimcbd5f692006-06-09 11:34:29 -07007 * Copyright (C) 1995-06 ICP vortex GmbH, Achim Leubner *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Copyright (C) 2002-04 Intel Corporation *
Leubner, Achimcbd5f692006-06-09 11:34:29 -07009 * Copyright (C) 2003-06 Adaptec Inc. *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * <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 * *
Jeff Garzik8d7a5da2007-10-02 22:54:28 +020030 * Linux kernel 2.6.x supported *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 ************************************************************************/
33
34/* All GDT Disk Array Controllers are fully supported by this driver.
35 * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
36 * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
37 * list of all controller types.
38 *
39 * If you have one or more GDT3000/3020 EISA controllers with
40 * controller BIOS disabled, you have to set the IRQ values with the
41 * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
42 * the IRQ values for the EISA controllers.
43 *
44 * After the optional list of IRQ values, other possible
45 * command line options are:
46 * disable:Y disable driver
47 * disable:N enable driver
48 * reserve_mode:0 reserve no drives for the raw service
49 * reserve_mode:1 reserve all not init., removable drives
50 * reserve_mode:2 reserve all not init. drives
51 * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with
52 * h- controller no., b- channel no.,
53 * t- target ID, l- LUN
54 * reverse_scan:Y reverse scan order for PCI controllers
55 * reverse_scan:N scan PCI controllers like BIOS
56 * max_ids:x x - target ID count per channel (1..MAXID)
57 * rescan:Y rescan all channels/IDs
58 * rescan:N use all devices found until now
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * hdr_channel:x x - number of virtual bus for host drives
60 * shared_access:Y disable driver reserve/release protocol to
61 * access a shared resource from several nodes,
Adrian Bunk575c9682006-01-15 02:00:17 +010062 * appropriate controller firmware required
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * shared_access:N enable driver reserve/release protocol
64 * probe_eisa_isa:Y scan for EISA/ISA controllers
65 * probe_eisa_isa:N do not scan for EISA/ISA controllers
66 * force_dma32:Y use only 32 bit DMA mode
67 * force_dma32:N use 64 bit DMA mode, if supported
68 *
69 * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
Christoph Hellwig52759e62007-10-02 22:59:53 +020070 * max_ids:127,rescan:N,hdr_channel:0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
72 * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
73 *
74 * When loading the gdth driver as a module, the same options are available.
75 * You can set the IRQs with "IRQ=...". However, the syntax to specify the
76 * options changes slightly. You must replace all ',' between options
77 * with ' ' and all ':' with '=' and you must use
78 * '1' in place of 'Y' and '0' in place of 'N'.
79 *
80 * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
Christoph Hellwig52759e62007-10-02 22:59:53 +020081 * max_ids=127 rescan=0 hdr_channel=0 shared_access=0
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * probe_eisa_isa=0 force_dma32=0"
83 * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
84 */
85
86/* The meaning of the Scsi_Pointer members in this driver is as follows:
87 * ptr: Chaining
Boaz Harrosh3892d882007-10-02 23:18:03 +020088 * this_residual: gdth_bufflen
89 * buffer: gdth_sglist
90 * dma_handle: unused
91 * buffers_residual: gdth_sg_count
92 * Status: unused
Boaz Harroshf842b642007-10-02 23:16:01 +020093 * Message: unused
94 * have_data_in: unused
95 * sent_command: unused
96 * phase: unused
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 */
98
99
100/* interrupt coalescing */
101/* #define INT_COAL */
102
103/* statistics */
104#define GDTH_STATISTICS
105
106#include <linux/module.h>
107
108#include <linux/version.h>
109#include <linux/kernel.h>
110#include <linux/types.h>
111#include <linux/pci.h>
112#include <linux/string.h>
113#include <linux/ctype.h>
114#include <linux/ioport.h>
115#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#include <linux/interrupt.h>
117#include <linux/in.h>
118#include <linux/proc_fs.h>
119#include <linux/time.h>
120#include <linux/timer.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800121#include <linux/dma-mapping.h>
Christoph Hellwig835cc242007-10-02 23:09:56 +0200122#include <linux/list.h>
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#ifdef GDTH_RTC
125#include <linux/mc146818rtc.h>
126#endif
127#include <linux/reboot.h>
128
129#include <asm/dma.h>
130#include <asm/system.h>
131#include <asm/io.h>
132#include <asm/uaccess.h>
133#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#include <linux/blkdev.h>
Boaz Harrosh3892d882007-10-02 23:18:03 +0200135#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137#include "scsi.h"
138#include <scsi/scsi_host.h>
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700139#include "gdth.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141static void gdth_delay(int milliseconds);
142static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs);
David Howells7d12e782006-10-05 14:55:46 +0100143static irqreturn_t gdth_interrupt(int irq, void *dev_id);
Jeff Garzik230e8862007-12-13 16:14:12 -0800144static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +0200145 int gdth_from_wait, int* pIndex);
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200146static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
147 Scsi_Cmnd *scp);
148static int gdth_async_event(gdth_ha_str *ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
150
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200151static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority);
152static void gdth_next(gdth_ha_str *ha);
153static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b);
154static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
156 ushort idx, gdth_evt_data *evt);
157static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
158static void gdth_readapp_event(gdth_ha_str *ha, unchar application,
159 gdth_evt_str *estr);
160static void gdth_clear_events(void);
161
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200162static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
Boaz Harroshee54cc62008-02-27 15:29:15 -0800163 char *buffer, ushort count);
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200164static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp);
165static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200167static void gdth_enable_int(gdth_ha_str *ha);
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200168static int gdth_test_busy(gdth_ha_str *ha);
169static int gdth_get_cmd_index(gdth_ha_str *ha);
170static void gdth_release_event(gdth_ha_str *ha);
171static int gdth_wait(gdth_ha_str *ha, int index,ulong32 time);
172static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode,
173 ulong32 p1, ulong64 p2,ulong64 p3);
174static int gdth_search_drives(gdth_ha_str *ha);
175static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200177static const char *gdth_ctr_name(gdth_ha_str *ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179static int gdth_open(struct inode *inode, struct file *filep);
180static int gdth_close(struct inode *inode, struct file *filep);
181static int gdth_ioctl(struct inode *inode, struct file *filep,
182 unsigned int cmd, unsigned long arg);
183
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200184static void gdth_flush(gdth_ha_str *ha);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700185static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *));
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200186static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
187 struct gdth_cmndinfo *cmndinfo);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700188static void gdth_scsi_done(struct scsi_cmnd *scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190#ifdef DEBUG_GDTH
191static unchar DebugState = DEBUG_GDTH;
192
193#ifdef __SERIAL__
194#define MAX_SERBUF 160
195static void ser_init(void);
196static void ser_puts(char *str);
197static void ser_putc(char c);
198static int ser_printk(const char *fmt, ...);
199static char strbuf[MAX_SERBUF+1];
200#ifdef __COM2__
201#define COM_BASE 0x2f8
202#else
203#define COM_BASE 0x3f8
204#endif
205static void ser_init()
206{
207 unsigned port=COM_BASE;
208
209 outb(0x80,port+3);
210 outb(0,port+1);
211 /* 19200 Baud, if 9600: outb(12,port) */
212 outb(6, port);
213 outb(3,port+3);
214 outb(0,port+1);
215 /*
216 ser_putc('I');
217 ser_putc(' ');
218 */
219}
220
221static void ser_puts(char *str)
222{
223 char *ptr;
224
225 ser_init();
226 for (ptr=str;*ptr;++ptr)
227 ser_putc(*ptr);
228}
229
230static void ser_putc(char c)
231{
232 unsigned port=COM_BASE;
233
234 while ((inb(port+5) & 0x20)==0);
235 outb(c,port);
236 if (c==0x0a)
237 {
238 while ((inb(port+5) & 0x20)==0);
239 outb(0x0d,port);
240 }
241}
242
243static int ser_printk(const char *fmt, ...)
244{
245 va_list args;
246 int i;
247
248 va_start(args,fmt);
249 i = vsprintf(strbuf,fmt,args);
250 ser_puts(strbuf);
251 va_end(args);
252 return i;
253}
254
255#define TRACE(a) {if (DebugState==1) {ser_printk a;}}
256#define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
257#define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
258
259#else /* !__SERIAL__ */
260#define TRACE(a) {if (DebugState==1) {printk a;}}
261#define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
262#define TRACE3(a) {if (DebugState!=0) {printk a;}}
263#endif
264
265#else /* !DEBUG */
266#define TRACE(a)
267#define TRACE2(a)
268#define TRACE3(a)
269#endif
270
271#ifdef GDTH_STATISTICS
272static ulong32 max_rq=0, max_index=0, max_sg=0;
273#ifdef INT_COAL
274static ulong32 max_int_coal=0;
275#endif
276static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
277static struct timer_list gdth_timer;
278#endif
279
280#define PTR2USHORT(a) (ushort)(ulong)(a)
Tobias Klauser6391a112006-06-08 22:23:48 -0700281#define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
282#define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
285
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200286#ifdef CONFIG_ISA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200288#endif
Dhaval Gianic8e91b02007-10-12 15:12:31 +0530289#if defined(CONFIG_EISA) || defined(CONFIG_ISA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
Christoph Hellwig706a5d42007-10-02 22:49:35 +0200291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292static unchar gdth_polling; /* polling if TRUE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static int gdth_ctr_count = 0; /* controller count */
Boaz Harrosh884f7fb2007-10-02 23:11:24 +0200294static LIST_HEAD(gdth_instances); /* controller list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static unchar gdth_write_through = FALSE; /* write through */
296static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
297static int elastidx;
298static int eoldidx;
299static int major;
300
301#define DIN 1 /* IN data direction */
302#define DOU 2 /* OUT data direction */
303#define DNO DIN /* no data transfer */
304#define DUN DIN /* unknown data direction */
305static unchar gdth_direction_tab[0x100] = {
306 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
307 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
308 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
309 DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU,
310 DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN,
311 DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN,
312 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
313 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
314 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
315 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,
316 DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU,
317 DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
318 DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
319 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
320 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
321 DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
322};
323
324/* LILO and modprobe/insmod parameters */
325/* IRQ list for GDT3000/3020 EISA controllers */
326static int irq[MAXHA] __initdata =
327{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
328 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
329/* disable driver flag */
330static int disable __initdata = 0;
331/* reserve flag */
332static int reserve_mode = 1;
333/* reserve list */
334static int reserve_list[MAX_RES_ARGS] =
335{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
336 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
337 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
338/* scan order for PCI controllers */
339static int reverse_scan = 0;
340/* virtual channel for the host drives */
341static int hdr_channel = 0;
342/* max. IDs per channel */
343static int max_ids = MAXID;
344/* rescan all IDs */
345static int rescan = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346/* shared access */
347static int shared_access = 1;
348/* enable support for EISA and ISA controllers */
349static int probe_eisa_isa = 0;
350/* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
351static int force_dma32 = 0;
352
353/* parameters for modprobe/insmod */
354module_param_array(irq, int, NULL, 0);
355module_param(disable, int, 0);
356module_param(reserve_mode, int, 0);
357module_param_array(reserve_list, int, NULL, 0);
358module_param(reverse_scan, int, 0);
359module_param(hdr_channel, int, 0);
360module_param(max_ids, int, 0);
361module_param(rescan, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362module_param(shared_access, int, 0);
363module_param(probe_eisa_isa, int, 0);
364module_param(force_dma32, int, 0);
365MODULE_AUTHOR("Achim Leubner");
366MODULE_LICENSE("GPL");
367
368/* ioctl interface */
Arjan van de Ven00977a52007-02-12 00:55:34 -0800369static const struct file_operations gdth_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .ioctl = gdth_ioctl,
371 .open = gdth_open,
372 .release = gdth_close,
373};
374
Boaz Harrosh3892d882007-10-02 23:18:03 +0200375/*
376 * gdth scsi_command access wrappers.
377 * below 6 functions are used throughout the driver to access scsi_command's
378 * io parameters. The reason we do not use the regular accessors from
379 * scsi_cmnd.h is because of gdth_execute(). Since it is unrecommended for
380 * llds to directly set scsi_cmnd's IO members. This driver will use SCp
381 * members for IO parameters, and will copy scsi_cmnd's members to Scp
382 * members in queuecommand. For internal commands through gdth_execute()
383 * SCp's members will be set directly.
384 */
385static inline unsigned gdth_bufflen(struct scsi_cmnd *cmd)
386{
387 return (unsigned)cmd->SCp.this_residual;
388}
389
390static inline void gdth_set_bufflen(struct scsi_cmnd *cmd, unsigned bufflen)
391{
392 cmd->SCp.this_residual = bufflen;
393}
394
395static inline unsigned gdth_sg_count(struct scsi_cmnd *cmd)
396{
397 return (unsigned)cmd->SCp.buffers_residual;
398}
399
400static inline void gdth_set_sg_count(struct scsi_cmnd *cmd, unsigned sg_count)
401{
402 cmd->SCp.buffers_residual = sg_count;
403}
404
405static inline struct scatterlist *gdth_sglist(struct scsi_cmnd *cmd)
406{
407 return cmd->SCp.buffer;
408}
409
410static inline void gdth_set_sglist(struct scsi_cmnd *cmd,
411 struct scatterlist *sglist)
412{
413 cmd->SCp.buffer = sglist;
414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#include "gdth_proc.h"
417#include "gdth_proc.c"
418
Boaz Harrosh884f7fb2007-10-02 23:11:24 +0200419static gdth_ha_str *gdth_find_ha(int hanum)
420{
421 gdth_ha_str *ha;
422
423 list_for_each_entry(ha, &gdth_instances, list)
424 if (hanum == ha->hanum)
425 return ha;
426
427 return NULL;
428}
429
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200430static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha)
431{
432 struct gdth_cmndinfo *priv = NULL;
433 ulong flags;
434 int i;
435
436 spin_lock_irqsave(&ha->smp_lock, flags);
437
438 for (i=0; i<GDTH_MAXCMDS; ++i) {
439 if (ha->cmndinfo[i].index == 0) {
440 priv = &ha->cmndinfo[i];
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200441 memset(priv, 0, sizeof(*priv));
Boaz Harroshee54cc62008-02-27 15:29:15 -0800442 priv->index = i+1;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200443 break;
444 }
445 }
446
447 spin_unlock_irqrestore(&ha->smp_lock, flags);
448
449 return priv;
450}
451
452static void gdth_put_cmndinfo(struct gdth_cmndinfo *priv)
453{
454 BUG_ON(!priv);
455 priv->index = 0;
456}
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458static void gdth_delay(int milliseconds)
459{
460 if (milliseconds == 0) {
461 udelay(1);
462 } else {
463 mdelay(milliseconds);
464 }
465}
466
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700467static void gdth_scsi_done(struct scsi_cmnd *scp)
468{
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200469 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
470 int internal_command = cmndinfo->internal_command;
471
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +0200472 TRACE2(("gdth_scsi_done()\n"));
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700473
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200474 gdth_put_cmndinfo(cmndinfo);
475 scp->host_scribble = NULL;
476
477 if (internal_command)
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +0200478 complete((struct completion *)scp->request);
479 else
480 scp->scsi_done(scp);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700481}
482
483int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
484 int timeout, u32 *info)
485{
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200486 gdth_ha_str *ha = shost_priv(sdev->host);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700487 Scsi_Cmnd *scp;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200488 struct gdth_cmndinfo cmndinfo;
Peter Zijlstra6e9a4732006-09-30 23:28:10 -0700489 DECLARE_COMPLETION_ONSTACK(wait);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700490 int rval;
491
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +0200492 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700493 if (!scp)
494 return -ENOMEM;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +0200495
Sven Schnelle1b96f892008-03-10 22:50:04 +0100496 scp->sense_buffer = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
497 if (!scp->sense_buffer) {
498 kfree(scp);
499 return -ENOMEM;
500 }
501
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700502 scp->device = sdev;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200503 memset(&cmndinfo, 0, sizeof(cmndinfo));
504
Christoph Hellwigbeb40482006-06-10 18:01:03 +0200505 /* use request field to save the ptr. to completion struct. */
506 scp->request = (struct request *)&wait;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700507 scp->timeout_per_command = timeout*HZ;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700508 scp->cmd_len = 12;
509 memcpy(scp->cmnd, cmnd, 12);
Boaz Harroshf842b642007-10-02 23:16:01 +0200510 cmndinfo.priority = IOCTL_PRI;
Boaz Harroshee54cc62008-02-27 15:29:15 -0800511 cmndinfo.internal_cmd_str = gdtcmd;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +0200512 cmndinfo.internal_command = 1;
513
514 TRACE(("__gdth_execute() cmd 0x%x\n", scp->cmnd[0]));
515 __gdth_queuecommand(ha, scp, &cmndinfo);
516
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700517 wait_for_completion(&wait);
518
Boaz Harroshf842b642007-10-02 23:16:01 +0200519 rval = cmndinfo.status;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700520 if (info)
Boaz Harroshf842b642007-10-02 23:16:01 +0200521 *info = cmndinfo.info;
Sven Schnelle1b96f892008-03-10 22:50:04 +0100522 kfree(scp->sense_buffer);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700523 kfree(scp);
524 return rval;
525}
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700526
527int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
528 int timeout, u32 *info)
529{
530 struct scsi_device *sdev = scsi_get_host_dev(shost);
531 int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info);
532
533 scsi_free_host_dev(sdev);
534 return rval;
535}
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
538{
539 *cyls = size /HEADS/SECS;
540 if (*cyls <= MAXCYLS) {
541 *heads = HEADS;
542 *secs = SECS;
543 } else { /* too high for 64*32 */
544 *cyls = size /MEDHEADS/MEDSECS;
545 if (*cyls <= MAXCYLS) {
546 *heads = MEDHEADS;
547 *secs = MEDSECS;
548 } else { /* too high for 127*63 */
549 *cyls = size /BIGHEADS/BIGSECS;
550 *heads = BIGHEADS;
551 *secs = BIGSECS;
552 }
553 }
554}
555
556/* controller search and initialization functions */
Christoph Hellwig706a5d42007-10-02 22:49:35 +0200557#ifdef CONFIG_EISA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558static int __init gdth_search_eisa(ushort eisa_adr)
559{
560 ulong32 id;
561
562 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
563 id = inl(eisa_adr+ID0REG);
564 if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
565 if ((inb(eisa_adr+EISAREG) & 8) == 0)
566 return 0; /* not EISA configured */
567 return 1;
568 }
569 if (id == GDT3_ID) /* GDT3000 */
570 return 1;
571
572 return 0;
573}
Christoph Hellwig706a5d42007-10-02 22:49:35 +0200574#endif /* CONFIG_EISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200576#ifdef CONFIG_ISA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577static int __init gdth_search_isa(ulong32 bios_adr)
578{
579 void __iomem *addr;
580 ulong32 id;
581
582 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
583 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
Jeff Garzika52667f2007-10-02 22:55:53 +0200584 id = readl(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 iounmap(addr);
586 if (id == GDT2_ID) /* GDT2000 */
587 return 1;
588 }
589 return 0;
590}
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200591#endif /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Christoph Hellwig8514ef22007-10-02 22:51:06 +0200593#ifdef CONFIG_PCI
Jeff Garzikcff26802008-02-15 22:20:09 -0500594static bool gdth_pci_registered;
Christoph Hellwig8514ef22007-10-02 22:51:06 +0200595
Jeff Garzikcff26802008-02-15 22:20:09 -0500596static bool gdth_search_vortex(ushort device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Jeff Garzikcff26802008-02-15 22:20:09 -0500598 if (device <= PCI_DEVICE_ID_VORTEX_GDT6555)
599 return true;
600 if (device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP &&
601 device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP)
602 return true;
603 if (device == PCI_DEVICE_ID_VORTEX_GDTNEWRX ||
604 device == PCI_DEVICE_ID_VORTEX_GDTNEWRX2)
605 return true;
606 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Jeff Garzikcff26802008-02-15 22:20:09 -0500609static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out);
610static int gdth_pci_init_one(struct pci_dev *pdev,
611 const struct pci_device_id *ent);
612static void gdth_pci_remove_one(struct pci_dev *pdev);
613static void gdth_remove_one(gdth_ha_str *ha);
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615/* Vortex only makes RAID controllers.
616 * We do not really want to specify all 550 ids here, so wildcard match.
617 */
Jeff Garzikcff26802008-02-15 22:20:09 -0500618static const struct pci_device_id gdthtable[] = {
619 { PCI_VDEVICE(VORTEX, PCI_ANY_ID) },
620 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC) },
621 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC_XSCALE) },
622 { } /* terminate list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623};
Jeff Garzikcff26802008-02-15 22:20:09 -0500624MODULE_DEVICE_TABLE(pci, gdthtable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Jeff Garzikcff26802008-02-15 22:20:09 -0500626static struct pci_driver gdth_pci_driver = {
627 .name = "gdth",
628 .id_table = gdthtable,
629 .probe = gdth_pci_init_one,
630 .remove = gdth_pci_remove_one,
631};
632
633static void gdth_pci_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Jeff Garzikcff26802008-02-15 22:20:09 -0500635 gdth_ha_str *ha = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Jeff Garzikcff26802008-02-15 22:20:09 -0500637 pci_set_drvdata(pdev, NULL);
638
639 list_del(&ha->list);
640 gdth_remove_one(ha);
641
642 pci_disable_device(pdev);
643}
644
645static int gdth_pci_init_one(struct pci_dev *pdev,
646 const struct pci_device_id *ent)
647{
648 ushort vendor = pdev->vendor;
649 ushort device = pdev->device;
650 ulong base0, base1, base2;
651 int rc;
652 gdth_pci_str gdth_pcistr;
653 gdth_ha_str *ha = NULL;
654
655 TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
656 gdth_ctr_count, vendor, device));
657
658 memset(&gdth_pcistr, 0, sizeof(gdth_pcistr));
659
660 if (vendor == PCI_VENDOR_ID_VORTEX && !gdth_search_vortex(device))
661 return -ENODEV;
662
663 rc = pci_enable_device(pdev);
664 if (rc)
665 return rc;
666
667 if (gdth_ctr_count >= MAXHA)
668 return -EBUSY;
Sergio Luis99109302008-02-12 20:48:03 -0300669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* GDT PCI controller found, resources are already in pdev */
Jeff Garzikcff26802008-02-15 22:20:09 -0500671 gdth_pcistr.pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 base0 = pci_resource_flags(pdev, 0);
673 base1 = pci_resource_flags(pdev, 1);
674 base2 = pci_resource_flags(pdev, 2);
675 if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
676 device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
677 if (!(base0 & IORESOURCE_MEM))
Jeff Garzikcff26802008-02-15 22:20:09 -0500678 return -ENODEV;
679 gdth_pcistr.dpmem = pci_resource_start(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 } else { /* GDT6110, GDT6120, .. */
681 if (!(base0 & IORESOURCE_MEM) ||
682 !(base2 & IORESOURCE_MEM) ||
683 !(base1 & IORESOURCE_IO))
Jeff Garzikcff26802008-02-15 22:20:09 -0500684 return -ENODEV;
685 gdth_pcistr.dpmem = pci_resource_start(pdev, 2);
686 gdth_pcistr.io = pci_resource_start(pdev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688 TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
Jeff Garzikcff26802008-02-15 22:20:09 -0500689 gdth_pcistr.pdev->bus->number,
690 PCI_SLOT(gdth_pcistr.pdev->devfn),
691 gdth_pcistr.irq,
692 gdth_pcistr.dpmem));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Jeff Garzikcff26802008-02-15 22:20:09 -0500694 rc = gdth_pci_probe_one(&gdth_pcistr, &ha);
695 if (rc)
696 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Jeff Garzikcff26802008-02-15 22:20:09 -0500698 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
Christoph Hellwig8514ef22007-10-02 22:51:06 +0200700#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Christoph Hellwig706a5d42007-10-02 22:49:35 +0200702#ifdef CONFIG_EISA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
704{
705 ulong32 retries,id;
706 unchar prot_ver,eisacf,i,irq_found;
707
708 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
709
710 /* disable board interrupts, deinitialize services */
711 outb(0xff,eisa_adr+EDOORREG);
712 outb(0x00,eisa_adr+EDENABREG);
713 outb(0x00,eisa_adr+EINTENABREG);
714
715 outb(0xff,eisa_adr+LDOORREG);
716 retries = INIT_RETRIES;
717 gdth_delay(20);
718 while (inb(eisa_adr+EDOORREG) != 0xff) {
719 if (--retries == 0) {
720 printk("GDT-EISA: Initialization error (DEINIT failed)\n");
721 return 0;
722 }
723 gdth_delay(1);
724 TRACE2(("wait for DEINIT: retries=%d\n",retries));
725 }
726 prot_ver = inb(eisa_adr+MAILBOXREG);
727 outb(0xff,eisa_adr+EDOORREG);
728 if (prot_ver != PROTOCOL_VERSION) {
729 printk("GDT-EISA: Illegal protocol version\n");
730 return 0;
731 }
732 ha->bmic = eisa_adr;
733 ha->brd_phys = (ulong32)eisa_adr >> 12;
734
735 outl(0,eisa_adr+MAILBOXREG);
736 outl(0,eisa_adr+MAILBOXREG+4);
737 outl(0,eisa_adr+MAILBOXREG+8);
738 outl(0,eisa_adr+MAILBOXREG+12);
739
740 /* detect IRQ */
741 if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
742 ha->oem_id = OEM_ID_ICP;
743 ha->type = GDT_EISA;
744 ha->stype = id;
745 outl(1,eisa_adr+MAILBOXREG+8);
746 outb(0xfe,eisa_adr+LDOORREG);
747 retries = INIT_RETRIES;
748 gdth_delay(20);
749 while (inb(eisa_adr+EDOORREG) != 0xfe) {
750 if (--retries == 0) {
751 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
752 return 0;
753 }
754 gdth_delay(1);
755 }
756 ha->irq = inb(eisa_adr+MAILBOXREG);
757 outb(0xff,eisa_adr+EDOORREG);
758 TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
759 /* check the result */
760 if (ha->irq == 0) {
761 TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
762 for (i = 0, irq_found = FALSE;
763 i < MAXHA && irq[i] != 0xff; ++i) {
764 if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
765 irq_found = TRUE;
766 break;
767 }
768 }
769 if (irq_found) {
770 ha->irq = irq[i];
771 irq[i] = 0;
772 printk("GDT-EISA: Can not detect controller IRQ,\n");
773 printk("Use IRQ setting from command line (IRQ = %d)\n",
774 ha->irq);
775 } else {
776 printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
777 printk("the controller BIOS or use command line parameters\n");
778 return 0;
779 }
780 }
781 } else {
782 eisacf = inb(eisa_adr+EISAREG) & 7;
783 if (eisacf > 4) /* level triggered */
784 eisacf -= 4;
785 ha->irq = gdth_irq_tab[eisacf];
786 ha->oem_id = OEM_ID_ICP;
787 ha->type = GDT_EISA;
788 ha->stype = id;
789 }
790
791 ha->dma64_support = 0;
792 return 1;
793}
Christoph Hellwig706a5d42007-10-02 22:49:35 +0200794#endif /* CONFIG_EISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200796#ifdef CONFIG_ISA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
798{
799 register gdt2_dpram_str __iomem *dp2_ptr;
800 int i;
801 unchar irq_drq,prot_ver;
802 ulong32 retries;
803
804 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
805
806 ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
807 if (ha->brd == NULL) {
808 printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
809 return 0;
810 }
811 dp2_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +0200812 writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 /* reset interface area */
814 memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
Jeff Garzika52667f2007-10-02 22:55:53 +0200815 if (readl(&dp2_ptr->u) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 printk("GDT-ISA: Initialization error (DPMEM write error)\n");
817 iounmap(ha->brd);
818 return 0;
819 }
820
821 /* disable board interrupts, read DRQ and IRQ */
Jeff Garzika52667f2007-10-02 22:55:53 +0200822 writeb(0xff, &dp2_ptr->io.irqdel);
823 writeb(0x00, &dp2_ptr->io.irqen);
824 writeb(0x00, &dp2_ptr->u.ic.S_Status);
825 writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Jeff Garzika52667f2007-10-02 22:55:53 +0200827 irq_drq = readb(&dp2_ptr->io.rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 for (i=0; i<3; ++i) {
829 if ((irq_drq & 1)==0)
830 break;
831 irq_drq >>= 1;
832 }
833 ha->drq = gdth_drq_tab[i];
834
Jeff Garzika52667f2007-10-02 22:55:53 +0200835 irq_drq = readb(&dp2_ptr->io.rq) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 for (i=1; i<5; ++i) {
837 if ((irq_drq & 1)==0)
838 break;
839 irq_drq >>= 1;
840 }
841 ha->irq = gdth_irq_tab[i];
842
843 /* deinitialize services */
Jeff Garzika52667f2007-10-02 22:55:53 +0200844 writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
845 writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
846 writeb(0, &dp2_ptr->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 retries = INIT_RETRIES;
848 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +0200849 while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 if (--retries == 0) {
851 printk("GDT-ISA: Initialization error (DEINIT failed)\n");
852 iounmap(ha->brd);
853 return 0;
854 }
855 gdth_delay(1);
856 }
Jeff Garzika52667f2007-10-02 22:55:53 +0200857 prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]);
858 writeb(0, &dp2_ptr->u.ic.Status);
859 writeb(0xff, &dp2_ptr->io.irqdel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (prot_ver != PROTOCOL_VERSION) {
861 printk("GDT-ISA: Illegal protocol version\n");
862 iounmap(ha->brd);
863 return 0;
864 }
865
866 ha->oem_id = OEM_ID_ICP;
867 ha->type = GDT_ISA;
868 ha->ic_all_size = sizeof(dp2_ptr->u);
869 ha->stype= GDT2_ID;
870 ha->brd_phys = bios_adr >> 4;
871
872 /* special request to controller BIOS */
Jeff Garzika52667f2007-10-02 22:55:53 +0200873 writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
874 writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
875 writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
876 writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
877 writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
878 writeb(0, &dp2_ptr->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 retries = INIT_RETRIES;
880 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +0200881 while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (--retries == 0) {
883 printk("GDT-ISA: Initialization error\n");
884 iounmap(ha->brd);
885 return 0;
886 }
887 gdth_delay(1);
888 }
Jeff Garzika52667f2007-10-02 22:55:53 +0200889 writeb(0, &dp2_ptr->u.ic.Status);
890 writeb(0xff, &dp2_ptr->io.irqdel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 ha->dma64_support = 0;
893 return 1;
894}
Christoph Hellwigaed91cb2007-10-02 22:48:16 +0200895#endif /* CONFIG_ISA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Christoph Hellwig8514ef22007-10-02 22:51:06 +0200897#ifdef CONFIG_PCI
Jeff Garzikcff26802008-02-15 22:20:09 -0500898static int gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
899 gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
901 register gdt6_dpram_str __iomem *dp6_ptr;
902 register gdt6c_dpram_str __iomem *dp6c_ptr;
903 register gdt6m_dpram_str __iomem *dp6m_ptr;
904 ulong32 retries;
905 unchar prot_ver;
906 ushort command;
907 int i, found = FALSE;
908
909 TRACE(("gdth_init_pci()\n"));
910
Jeff Garzik4c9c8d72008-02-15 21:35:26 -0500911 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 ha->oem_id = OEM_ID_INTEL;
913 else
914 ha->oem_id = OEM_ID_ICP;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -0500915 ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8);
916 ha->stype = (ulong32)pdev->device;
917 ha->irq = pdev->irq;
918 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Jeff Garzik8e9a8a02007-07-17 05:25:17 -0400920 if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
922 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
923 if (ha->brd == NULL) {
924 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
925 return 0;
926 }
927 /* check and reset interface area */
928 dp6_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +0200929 writel(DPMEM_MAGIC, &dp6_ptr->u);
930 if (readl(&dp6_ptr->u) != DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
932 pcistr->dpmem);
933 found = FALSE;
934 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
935 iounmap(ha->brd);
936 ha->brd = ioremap(i, sizeof(ushort));
937 if (ha->brd == NULL) {
938 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
939 return 0;
940 }
Jeff Garzika52667f2007-10-02 22:55:53 +0200941 if (readw(ha->brd) != 0xffff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 TRACE2(("init_pci_old() address 0x%x busy\n", i));
943 continue;
944 }
945 iounmap(ha->brd);
Jeff Garzik4c9c8d72008-02-15 21:35:26 -0500946 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
948 if (ha->brd == NULL) {
949 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
950 return 0;
951 }
952 dp6_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +0200953 writel(DPMEM_MAGIC, &dp6_ptr->u);
954 if (readl(&dp6_ptr->u) == DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 printk("GDT-PCI: Use free address at 0x%x\n", i);
956 found = TRUE;
957 break;
958 }
959 }
960 if (!found) {
961 printk("GDT-PCI: No free address found!\n");
962 iounmap(ha->brd);
963 return 0;
964 }
965 }
966 memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
Jeff Garzika52667f2007-10-02 22:55:53 +0200967 if (readl(&dp6_ptr->u) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
969 iounmap(ha->brd);
970 return 0;
971 }
972
973 /* disable board interrupts, deinit services */
Jeff Garzika52667f2007-10-02 22:55:53 +0200974 writeb(0xff, &dp6_ptr->io.irqdel);
975 writeb(0x00, &dp6_ptr->io.irqen);
976 writeb(0x00, &dp6_ptr->u.ic.S_Status);
977 writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Jeff Garzika52667f2007-10-02 22:55:53 +0200979 writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
980 writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
981 writeb(0, &dp6_ptr->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 retries = INIT_RETRIES;
983 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +0200984 while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (--retries == 0) {
986 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
987 iounmap(ha->brd);
988 return 0;
989 }
990 gdth_delay(1);
991 }
Jeff Garzika52667f2007-10-02 22:55:53 +0200992 prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]);
993 writeb(0, &dp6_ptr->u.ic.S_Status);
994 writeb(0xff, &dp6_ptr->io.irqdel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (prot_ver != PROTOCOL_VERSION) {
996 printk("GDT-PCI: Illegal protocol version\n");
997 iounmap(ha->brd);
998 return 0;
999 }
1000
1001 ha->type = GDT_PCI;
1002 ha->ic_all_size = sizeof(dp6_ptr->u);
1003
1004 /* special command to controller BIOS */
Jeff Garzika52667f2007-10-02 22:55:53 +02001005 writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
1006 writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
1007 writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
1008 writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
1009 writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
1010 writeb(0, &dp6_ptr->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 retries = INIT_RETRIES;
1012 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001013 while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (--retries == 0) {
1015 printk("GDT-PCI: Initialization error\n");
1016 iounmap(ha->brd);
1017 return 0;
1018 }
1019 gdth_delay(1);
1020 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001021 writeb(0, &dp6_ptr->u.ic.S_Status);
1022 writeb(0xff, &dp6_ptr->io.irqdel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 ha->dma64_support = 0;
1025
Jeff Garzik8e9a8a02007-07-17 05:25:17 -04001026 } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 ha->plx = (gdt6c_plx_regs *)pcistr->io;
1028 TRACE2(("init_pci_new() dpmem %lx irq %d\n",
1029 pcistr->dpmem,ha->irq));
1030 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
1031 if (ha->brd == NULL) {
1032 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1033 iounmap(ha->brd);
1034 return 0;
1035 }
1036 /* check and reset interface area */
1037 dp6c_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001038 writel(DPMEM_MAGIC, &dp6c_ptr->u);
1039 if (readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1041 pcistr->dpmem);
1042 found = FALSE;
1043 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1044 iounmap(ha->brd);
1045 ha->brd = ioremap(i, sizeof(ushort));
1046 if (ha->brd == NULL) {
1047 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1048 return 0;
1049 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001050 if (readw(ha->brd) != 0xffff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 TRACE2(("init_pci_plx() address 0x%x busy\n", i));
1052 continue;
1053 }
1054 iounmap(ha->brd);
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001055 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_2, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
1057 if (ha->brd == NULL) {
1058 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1059 return 0;
1060 }
1061 dp6c_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001062 writel(DPMEM_MAGIC, &dp6c_ptr->u);
1063 if (readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 printk("GDT-PCI: Use free address at 0x%x\n", i);
1065 found = TRUE;
1066 break;
1067 }
1068 }
1069 if (!found) {
1070 printk("GDT-PCI: No free address found!\n");
1071 iounmap(ha->brd);
1072 return 0;
1073 }
1074 }
1075 memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
Jeff Garzika52667f2007-10-02 22:55:53 +02001076 if (readl(&dp6c_ptr->u) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 printk("GDT-PCI: Initialization error (DPMEM write error)\n");
1078 iounmap(ha->brd);
1079 return 0;
1080 }
1081
1082 /* disable board interrupts, deinit services */
1083 outb(0x00,PTR2USHORT(&ha->plx->control1));
1084 outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
1085
Jeff Garzika52667f2007-10-02 22:55:53 +02001086 writeb(0x00, &dp6c_ptr->u.ic.S_Status);
1087 writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Jeff Garzika52667f2007-10-02 22:55:53 +02001089 writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
1090 writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1093
1094 retries = INIT_RETRIES;
1095 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001096 while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if (--retries == 0) {
1098 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1099 iounmap(ha->brd);
1100 return 0;
1101 }
1102 gdth_delay(1);
1103 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001104 prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]);
1105 writeb(0, &dp6c_ptr->u.ic.Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 if (prot_ver != PROTOCOL_VERSION) {
1107 printk("GDT-PCI: Illegal protocol version\n");
1108 iounmap(ha->brd);
1109 return 0;
1110 }
1111
1112 ha->type = GDT_PCINEW;
1113 ha->ic_all_size = sizeof(dp6c_ptr->u);
1114
1115 /* special command to controller BIOS */
Jeff Garzika52667f2007-10-02 22:55:53 +02001116 writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
1117 writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
1118 writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
1119 writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
1120 writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
1123
1124 retries = INIT_RETRIES;
1125 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001126 while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (--retries == 0) {
1128 printk("GDT-PCI: Initialization error\n");
1129 iounmap(ha->brd);
1130 return 0;
1131 }
1132 gdth_delay(1);
1133 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001134 writeb(0, &dp6c_ptr->u.ic.S_Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 ha->dma64_support = 0;
1137
1138 } else { /* MPR */
1139 TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
1140 ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
1141 if (ha->brd == NULL) {
1142 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1143 return 0;
1144 }
1145
1146 /* manipulate config. space to enable DPMEM, start RP controller */
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001147 pci_read_config_word(pdev, PCI_COMMAND, &command);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 command |= 6;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001149 pci_write_config_word(pdev, PCI_COMMAND, command);
1150 if (pci_resource_start(pdev, 8) == 1UL)
1151 pci_resource_start(pdev, 8) = 0UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 i = 0xFEFF0001UL;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001153 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 gdth_delay(1);
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001155 pci_write_config_dword(pdev, PCI_ROM_ADDRESS,
1156 pci_resource_start(pdev, 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 dp6m_ptr = ha->brd;
1159
1160 /* Ensure that it is safe to access the non HW portions of DPMEM.
1161 * Aditional check needed for Xscale based RAID controllers */
Jeff Garzika52667f2007-10-02 22:55:53 +02001162 while( ((int)readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 gdth_delay(1);
1164
1165 /* check and reset interface area */
Jeff Garzika52667f2007-10-02 22:55:53 +02001166 writel(DPMEM_MAGIC, &dp6m_ptr->u);
1167 if (readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
1169 pcistr->dpmem);
1170 found = FALSE;
1171 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1172 iounmap(ha->brd);
1173 ha->brd = ioremap(i, sizeof(ushort));
1174 if (ha->brd == NULL) {
1175 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1176 return 0;
1177 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001178 if (readw(ha->brd) != 0xffff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
1180 continue;
1181 }
1182 iounmap(ha->brd);
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05001183 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
1185 if (ha->brd == NULL) {
1186 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1187 return 0;
1188 }
1189 dp6m_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001190 writel(DPMEM_MAGIC, &dp6m_ptr->u);
1191 if (readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 printk("GDT-PCI: Use free address at 0x%x\n", i);
1193 found = TRUE;
1194 break;
1195 }
1196 }
1197 if (!found) {
1198 printk("GDT-PCI: No free address found!\n");
1199 iounmap(ha->brd);
1200 return 0;
1201 }
1202 }
1203 memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
1204
1205 /* disable board interrupts, deinit services */
Jeff Garzika52667f2007-10-02 22:55:53 +02001206 writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 &dp6m_ptr->i960r.edoor_en_reg);
Jeff Garzika52667f2007-10-02 22:55:53 +02001208 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1209 writeb(0x00, &dp6m_ptr->u.ic.S_Status);
1210 writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Jeff Garzika52667f2007-10-02 22:55:53 +02001212 writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
1213 writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
1214 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 retries = INIT_RETRIES;
1216 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001217 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if (--retries == 0) {
1219 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1220 iounmap(ha->brd);
1221 return 0;
1222 }
1223 gdth_delay(1);
1224 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001225 prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]);
1226 writeb(0, &dp6m_ptr->u.ic.S_Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 if (prot_ver != PROTOCOL_VERSION) {
1228 printk("GDT-PCI: Illegal protocol version\n");
1229 iounmap(ha->brd);
1230 return 0;
1231 }
1232
1233 ha->type = GDT_PCIMPR;
1234 ha->ic_all_size = sizeof(dp6m_ptr->u);
1235
1236 /* special command to controller BIOS */
Jeff Garzika52667f2007-10-02 22:55:53 +02001237 writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
1238 writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
1239 writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
1240 writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
1241 writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
1242 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 retries = INIT_RETRIES;
1244 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001245 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 if (--retries == 0) {
1247 printk("GDT-PCI: Initialization error\n");
1248 iounmap(ha->brd);
1249 return 0;
1250 }
1251 gdth_delay(1);
1252 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001253 writeb(0, &dp6m_ptr->u.ic.S_Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 /* read FW version to detect 64-bit DMA support */
Jeff Garzika52667f2007-10-02 22:55:53 +02001256 writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
1257 writeb(1, &dp6m_ptr->i960r.ldoor_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 retries = INIT_RETRIES;
1259 gdth_delay(20);
Jeff Garzika52667f2007-10-02 22:55:53 +02001260 while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 if (--retries == 0) {
1262 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
1263 iounmap(ha->brd);
1264 return 0;
1265 }
1266 gdth_delay(1);
1267 }
Jeff Garzika52667f2007-10-02 22:55:53 +02001268 prot_ver = (unchar)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1269 writeb(0, &dp6m_ptr->u.ic.S_Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1271 ha->dma64_support = 0;
1272 else
1273 ha->dma64_support = 1;
1274 }
1275
1276 return 1;
1277}
Christoph Hellwig8514ef22007-10-02 22:51:06 +02001278#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280/* controller protocol functions */
1281
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001282static void __init gdth_enable_int(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 ulong flags;
1285 gdt2_dpram_str __iomem *dp2_ptr;
1286 gdt6_dpram_str __iomem *dp6_ptr;
1287 gdt6m_dpram_str __iomem *dp6m_ptr;
1288
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001289 TRACE(("gdth_enable_int() hanum %d\n",ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 spin_lock_irqsave(&ha->smp_lock, flags);
1291
1292 if (ha->type == GDT_EISA) {
1293 outb(0xff, ha->bmic + EDOORREG);
1294 outb(0xff, ha->bmic + EDENABREG);
1295 outb(0x01, ha->bmic + EINTENABREG);
1296 } else if (ha->type == GDT_ISA) {
1297 dp2_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001298 writeb(1, &dp2_ptr->io.irqdel);
1299 writeb(0, &dp2_ptr->u.ic.Cmd_Index);
1300 writeb(1, &dp2_ptr->io.irqen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 } else if (ha->type == GDT_PCI) {
1302 dp6_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001303 writeb(1, &dp6_ptr->io.irqdel);
1304 writeb(0, &dp6_ptr->u.ic.Cmd_Index);
1305 writeb(1, &dp6_ptr->io.irqen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 } else if (ha->type == GDT_PCINEW) {
1307 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
1308 outb(0x03, PTR2USHORT(&ha->plx->control1));
1309 } else if (ha->type == GDT_PCIMPR) {
1310 dp6m_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001311 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
1312 writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 &dp6m_ptr->i960r.edoor_en_reg);
1314 }
1315 spin_unlock_irqrestore(&ha->smp_lock, flags);
1316}
1317
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001318/* return IStatus if interrupt was from this card else 0 */
Jeff Garzik230e8862007-12-13 16:14:12 -08001319static unchar gdth_get_status(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001321 unchar IStatus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Jeff Garzik230e8862007-12-13 16:14:12 -08001323 TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count));
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (ha->type == GDT_EISA)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001326 IStatus = inb((ushort)ha->bmic + EDOORREG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 else if (ha->type == GDT_ISA)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001328 IStatus =
Jeff Garzika52667f2007-10-02 22:55:53 +02001329 readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 else if (ha->type == GDT_PCI)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001331 IStatus =
Jeff Garzika52667f2007-10-02 22:55:53 +02001332 readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 else if (ha->type == GDT_PCINEW)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001334 IStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 else if (ha->type == GDT_PCIMPR)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001336 IStatus =
Jeff Garzika52667f2007-10-02 22:55:53 +02001337 readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001338
1339 return IStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001341
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001342static int gdth_test_busy(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 register int gdtsema0 = 0;
1345
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001346 TRACE(("gdth_test_busy() hanum %d\n", ha->hanum));
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 if (ha->type == GDT_EISA)
1349 gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
1350 else if (ha->type == GDT_ISA)
Jeff Garzika52667f2007-10-02 22:55:53 +02001351 gdtsema0 = (int)readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 else if (ha->type == GDT_PCI)
Jeff Garzika52667f2007-10-02 22:55:53 +02001353 gdtsema0 = (int)readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 else if (ha->type == GDT_PCINEW)
1355 gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
1356 else if (ha->type == GDT_PCIMPR)
1357 gdtsema0 =
Jeff Garzika52667f2007-10-02 22:55:53 +02001358 (int)readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 return (gdtsema0 & 1);
1361}
1362
1363
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001364static int gdth_get_cmd_index(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 int i;
1367
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001368 TRACE(("gdth_get_cmd_index() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 for (i=0; i<GDTH_MAXCMDS; ++i) {
1371 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1372 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1373 ha->cmd_tab[i].service = ha->pccb->Service;
1374 ha->pccb->CommandIndex = (ulong32)i+2;
1375 return (i+2);
1376 }
1377 }
1378 return 0;
1379}
1380
1381
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001382static void gdth_set_sema0(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001384 TRACE(("gdth_set_sema0() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if (ha->type == GDT_EISA) {
1387 outb(1, ha->bmic + SEMA0REG);
1388 } else if (ha->type == GDT_ISA) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001389 writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 } else if (ha->type == GDT_PCI) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001391 writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 } else if (ha->type == GDT_PCINEW) {
1393 outb(1, PTR2USHORT(&ha->plx->sema0_reg));
1394 } else if (ha->type == GDT_PCIMPR) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001395 writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001400static void gdth_copy_command(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 register gdth_cmd_str *cmd_ptr;
1403 register gdt6m_dpram_str __iomem *dp6m_ptr;
1404 register gdt6c_dpram_str __iomem *dp6c_ptr;
1405 gdt6_dpram_str __iomem *dp6_ptr;
1406 gdt2_dpram_str __iomem *dp2_ptr;
1407 ushort cp_count,dp_offset,cmd_no;
1408
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001409 TRACE(("gdth_copy_command() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 cp_count = ha->cmd_len;
1412 dp_offset= ha->cmd_offs_dpmem;
1413 cmd_no = ha->cmd_cnt;
1414 cmd_ptr = ha->pccb;
1415
1416 ++ha->cmd_cnt;
1417 if (ha->type == GDT_EISA)
1418 return; /* no DPMEM, no copy */
1419
1420 /* set cpcount dword aligned */
1421 if (cp_count & 3)
1422 cp_count += (4 - (cp_count & 3));
1423
1424 ha->cmd_offs_dpmem += cp_count;
1425
1426 /* set offset and service, copy command to DPMEM */
1427 if (ha->type == GDT_ISA) {
1428 dp2_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001429 writew(dp_offset + DPMEM_COMMAND_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
Jeff Garzika52667f2007-10-02 22:55:53 +02001431 writew((ushort)cmd_ptr->Service,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1433 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1434 } else if (ha->type == GDT_PCI) {
1435 dp6_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001436 writew(dp_offset + DPMEM_COMMAND_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
Jeff Garzika52667f2007-10-02 22:55:53 +02001438 writew((ushort)cmd_ptr->Service,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1440 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1441 } else if (ha->type == GDT_PCINEW) {
1442 dp6c_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001443 writew(dp_offset + DPMEM_COMMAND_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
Jeff Garzika52667f2007-10-02 22:55:53 +02001445 writew((ushort)cmd_ptr->Service,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1447 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1448 } else if (ha->type == GDT_PCIMPR) {
1449 dp6m_ptr = ha->brd;
Jeff Garzika52667f2007-10-02 22:55:53 +02001450 writew(dp_offset + DPMEM_COMMAND_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
Jeff Garzika52667f2007-10-02 22:55:53 +02001452 writew((ushort)cmd_ptr->Service,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1454 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1455 }
1456}
1457
1458
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001459static void gdth_release_event(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001461 TRACE(("gdth_release_event() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463#ifdef GDTH_STATISTICS
1464 {
1465 ulong32 i,j;
1466 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1467 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1468 ++i;
1469 }
1470 if (max_index < i) {
1471 max_index = i;
1472 TRACE3(("GDT: max_index = %d\n",(ushort)i));
1473 }
1474 }
1475#endif
1476
1477 if (ha->pccb->OpCode == GDT_INIT)
1478 ha->pccb->Service |= 0x80;
1479
1480 if (ha->type == GDT_EISA) {
1481 if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
1482 outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
1483 outb(ha->pccb->Service, ha->bmic + LDOORREG);
1484 } else if (ha->type == GDT_ISA) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001485 writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 } else if (ha->type == GDT_PCI) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001487 writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 } else if (ha->type == GDT_PCINEW) {
1489 outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
1490 } else if (ha->type == GDT_PCIMPR) {
Jeff Garzika52667f2007-10-02 22:55:53 +02001491 writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 }
1493}
1494
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001495static int gdth_wait(gdth_ha_str *ha, int index, ulong32 time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 int answer_found = FALSE;
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001498 int wait_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001500 TRACE(("gdth_wait() hanum %d index %d time %d\n", ha->hanum, index, time));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 if (index == 0)
1503 return 1; /* no wait required */
1504
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 do {
Jeff Garzik230e8862007-12-13 16:14:12 -08001506 __gdth_interrupt(ha, true, &wait_index);
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02001507 if (wait_index == index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 answer_found = TRUE;
1509 break;
1510 }
1511 gdth_delay(1);
1512 } while (--time);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001513
1514 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 gdth_delay(0);
1516
1517 return (answer_found);
1518}
1519
1520
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001521static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode,
1522 ulong32 p1, ulong64 p2, ulong64 p3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 register gdth_cmd_str *cmd_ptr;
1525 int retries,index;
1526
1527 TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 cmd_ptr = ha->pccb;
1530 memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
1531
1532 /* make command */
1533 for (retries = INIT_RETRIES;;) {
1534 cmd_ptr->Service = service;
1535 cmd_ptr->RequestBuffer = INTERNAL_CMND;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001536 if (!(index=gdth_get_cmd_index(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 TRACE(("GDT: No free command index found\n"));
1538 return 0;
1539 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001540 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 cmd_ptr->OpCode = opcode;
1542 cmd_ptr->BoardNode = LOCALBOARD;
1543 if (service == CACHESERVICE) {
1544 if (opcode == GDT_IOCTL) {
1545 cmd_ptr->u.ioctl.subfunc = p1;
1546 cmd_ptr->u.ioctl.channel = (ulong32)p2;
1547 cmd_ptr->u.ioctl.param_size = (ushort)p3;
1548 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1549 } else {
1550 if (ha->cache_feat & GDT_64BIT) {
1551 cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
1552 cmd_ptr->u.cache64.BlockNo = p2;
1553 } else {
1554 cmd_ptr->u.cache.DeviceNo = (ushort)p1;
1555 cmd_ptr->u.cache.BlockNo = (ulong32)p2;
1556 }
1557 }
1558 } else if (service == SCSIRAWSERVICE) {
1559 if (ha->raw_feat & GDT_64BIT) {
1560 cmd_ptr->u.raw64.direction = p1;
1561 cmd_ptr->u.raw64.bus = (unchar)p2;
1562 cmd_ptr->u.raw64.target = (unchar)p3;
1563 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
1564 } else {
1565 cmd_ptr->u.raw.direction = p1;
1566 cmd_ptr->u.raw.bus = (unchar)p2;
1567 cmd_ptr->u.raw.target = (unchar)p3;
1568 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
1569 }
1570 } else if (service == SCREENSERVICE) {
1571 if (opcode == GDT_REALTIME) {
1572 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1573 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
1574 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
1575 }
1576 }
1577 ha->cmd_len = sizeof(gdth_cmd_str);
1578 ha->cmd_offs_dpmem = 0;
1579 ha->cmd_cnt = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001580 gdth_copy_command(ha);
1581 gdth_release_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 gdth_delay(20);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001583 if (!gdth_wait(ha, index, INIT_TIMEOUT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 printk("GDT: Initialization error (timeout service %d)\n",service);
1585 return 0;
1586 }
1587 if (ha->status != S_BSY || --retries == 0)
1588 break;
1589 gdth_delay(1);
1590 }
1591
1592 return (ha->status != S_OK ? 0:1);
1593}
1594
1595
1596/* search for devices */
1597
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001598static int __init gdth_search_drives(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 ushort cdev_cnt, i;
1601 int ok;
1602 ulong32 bus_no, drv_cnt, drv_no, j;
1603 gdth_getch_str *chn;
1604 gdth_drlist_str *drl;
1605 gdth_iochan_str *ioc;
1606 gdth_raw_iochan_str *iocr;
1607 gdth_arcdl_str *alst;
1608 gdth_alist_str *alst2;
1609 gdth_oem_str_ioctl *oemstr;
1610#ifdef INT_COAL
1611 gdth_perf_modes *pmod;
1612#endif
1613
1614#ifdef GDTH_RTC
1615 unchar rtc[12];
1616 ulong flags;
1617#endif
1618
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001619 TRACE(("gdth_search_drives() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 ok = 0;
1621
1622 /* initialize controller services, at first: screen service */
1623 ha->screen_feat = 0;
1624 if (!force_dma32) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001625 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_X_INIT_SCR, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 if (ok)
1627 ha->screen_feat = GDT_64BIT;
1628 }
1629 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001630 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 if (!ok) {
1632 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001633 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 return 0;
1635 }
1636 TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
1637
1638#ifdef GDTH_RTC
1639 /* read realtime clock info, send to controller */
1640 /* 1. wait for the falling edge of update flag */
1641 spin_lock_irqsave(&rtc_lock, flags);
1642 for (j = 0; j < 1000000; ++j)
1643 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
1644 break;
1645 for (j = 0; j < 1000000; ++j)
1646 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
1647 break;
1648 /* 2. read info */
1649 do {
1650 for (j = 0; j < 12; ++j)
1651 rtc[j] = CMOS_READ(j);
1652 } while (rtc[0] != CMOS_READ(0));
Robert P. J. Day7a960b72007-05-23 14:41:40 -07001653 spin_unlock_irqrestore(&rtc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
1655 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
1656 /* 3. send to controller firmware */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001657 gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(ulong32 *)&rtc[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
1659#endif
1660
1661 /* unfreeze all IOs */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001662 gdth_internal_cmd(ha, CACHESERVICE, GDT_UNFREEZE_IO, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
1664 /* initialize cache service */
1665 ha->cache_feat = 0;
1666 if (!force_dma32) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001667 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INIT_HOST, LINUX_OS,
1668 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 if (ok)
1670 ha->cache_feat = GDT_64BIT;
1671 }
1672 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001673 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 if (!ok) {
1675 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001676 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 return 0;
1678 }
1679 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1680 cdev_cnt = (ushort)ha->info;
1681 ha->fw_vers = ha->service;
1682
1683#ifdef INT_COAL
1684 if (ha->type == GDT_PCIMPR) {
1685 /* set perf. modes */
1686 pmod = (gdth_perf_modes *)ha->pscratch;
1687 pmod->version = 1;
1688 pmod->st_mode = 1; /* enable one status buffer */
1689 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1690 pmod->st_buff_indx1 = COALINDEX;
1691 pmod->st_buff_addr2 = 0;
1692 pmod->st_buff_u_addr2 = 0;
1693 pmod->st_buff_indx2 = 0;
1694 pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
1695 pmod->cmd_mode = 0; // disable all cmd buffers
1696 pmod->cmd_buff_addr1 = 0;
1697 pmod->cmd_buff_u_addr1 = 0;
1698 pmod->cmd_buff_indx1 = 0;
1699 pmod->cmd_buff_addr2 = 0;
1700 pmod->cmd_buff_u_addr2 = 0;
1701 pmod->cmd_buff_indx2 = 0;
1702 pmod->cmd_buff_size = 0;
1703 pmod->reserved1 = 0;
1704 pmod->reserved2 = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001705 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, SET_PERF_MODES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001707 printk("GDT-HA %d: Interrupt coalescing activated\n", ha->hanum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 }
1709 }
1710#endif
1711
1712 /* detect number of buses - try new IOCTL */
1713 iocr = (gdth_raw_iochan_str *)ha->pscratch;
1714 iocr->hdr.version = 0xffffffff;
1715 iocr->hdr.list_entries = MAXBUS;
1716 iocr->hdr.first_chan = 0;
1717 iocr->hdr.last_chan = MAXBUS-1;
1718 iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001719 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_RAW_DESC,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
1721 TRACE2(("IOCHAN_RAW_DESC supported!\n"));
1722 ha->bus_cnt = iocr->hdr.chan_count;
1723 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1724 if (iocr->list[bus_no].proc_id < MAXID)
1725 ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
1726 else
1727 ha->bus_id[bus_no] = 0xff;
1728 }
1729 } else {
1730 /* old method */
1731 chn = (gdth_getch_str *)ha->pscratch;
1732 for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
1733 chn->channel_no = bus_no;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001734 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1736 IO_CHANNEL | INVALID_CHANNEL,
1737 sizeof(gdth_getch_str))) {
1738 if (bus_no == 0) {
1739 printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001740 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 return 0;
1742 }
1743 break;
1744 }
1745 if (chn->siop_id < MAXID)
1746 ha->bus_id[bus_no] = chn->siop_id;
1747 else
1748 ha->bus_id[bus_no] = 0xff;
1749 }
1750 ha->bus_cnt = (unchar)bus_no;
1751 }
1752 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
1753
1754 /* read cache configuration */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001755 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_INFO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
1757 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001758 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return 0;
1760 }
1761 ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
1762 TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
1763 ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
1764 ha->cpar.write_back,ha->cpar.block_size));
1765
1766 /* read board info and features */
1767 ha->more_proc = FALSE;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001768 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_INFO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
1770 memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
1771 sizeof(gdth_binfo_str));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001772 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_FEATURES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
1774 TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
1775 ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
1776 ha->more_proc = TRUE;
1777 }
1778 } else {
1779 TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001780 strcpy(ha->binfo.type_string, gdth_ctr_name(ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 }
1782 TRACE2(("Controller name: %s\n",ha->binfo.type_string));
1783
1784 /* read more informations */
1785 if (ha->more_proc) {
1786 /* physical drives, channel addresses */
1787 ioc = (gdth_iochan_str *)ha->pscratch;
1788 ioc->hdr.version = 0xffffffff;
1789 ioc->hdr.list_entries = MAXBUS;
1790 ioc->hdr.first_chan = 0;
1791 ioc->hdr.last_chan = MAXBUS-1;
1792 ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001793 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_DESC,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
1795 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1796 ha->raw[bus_no].address = ioc->list[bus_no].address;
1797 ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
1798 }
1799 } else {
1800 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1801 ha->raw[bus_no].address = IO_CHANNEL;
1802 ha->raw[bus_no].local_no = bus_no;
1803 }
1804 }
1805 for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
1806 chn = (gdth_getch_str *)ha->pscratch;
1807 chn->channel_no = ha->raw[bus_no].local_no;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001808 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 SCSI_CHAN_CNT | L_CTRL_PATTERN,
1810 ha->raw[bus_no].address | INVALID_CHANNEL,
1811 sizeof(gdth_getch_str))) {
1812 ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
1813 TRACE2(("Channel %d: %d phys. drives\n",
1814 bus_no,chn->drive_cnt));
1815 }
1816 if (ha->raw[bus_no].pdev_cnt > 0) {
1817 drl = (gdth_drlist_str *)ha->pscratch;
1818 drl->sc_no = ha->raw[bus_no].local_no;
1819 drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001820 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 SCSI_DR_LIST | L_CTRL_PATTERN,
1822 ha->raw[bus_no].address | INVALID_CHANNEL,
1823 sizeof(gdth_drlist_str))) {
1824 for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
1825 ha->raw[bus_no].id_list[j] = drl->sc_list[j];
1826 } else {
1827 ha->raw[bus_no].pdev_cnt = 0;
1828 }
1829 }
1830 }
1831
1832 /* logical drives */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001833 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 INVALID_CHANNEL,sizeof(ulong32))) {
1835 drv_cnt = *(ulong32 *)ha->pscratch;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001836 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
1838 for (j = 0; j < drv_cnt; ++j) {
1839 drv_no = ((ulong32 *)ha->pscratch)[j];
1840 if (drv_no < MAX_LDRIVES) {
1841 ha->hdr[drv_no].is_logdrv = TRUE;
1842 TRACE2(("Drive %d is log. drive\n",drv_no));
1843 }
1844 }
1845 }
1846 alst = (gdth_arcdl_str *)ha->pscratch;
1847 alst->entries_avail = MAX_LDRIVES;
1848 alst->first_entry = 0;
1849 alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001850 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
1852 INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
1853 (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
1854 for (j = 0; j < alst->entries_init; ++j) {
1855 ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
1856 ha->hdr[j].is_master = alst->list[j].is_master;
1857 ha->hdr[j].is_parity = alst->list[j].is_parity;
1858 ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
1859 ha->hdr[j].master_no = alst->list[j].cd_handle;
1860 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001861 } else if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 ARRAY_DRV_LIST | LA_CTRL_PATTERN,
1863 0, 35 * sizeof(gdth_alist_str))) {
1864 for (j = 0; j < 35; ++j) {
1865 alst2 = &((gdth_alist_str *)ha->pscratch)[j];
1866 ha->hdr[j].is_arraydrv = alst2->is_arrayd;
1867 ha->hdr[j].is_master = alst2->is_master;
1868 ha->hdr[j].is_parity = alst2->is_parity;
1869 ha->hdr[j].is_hotfix = alst2->is_hotfix;
1870 ha->hdr[j].master_no = alst2->cd_handle;
1871 }
1872 }
1873 }
1874 }
1875
1876 /* initialize raw service */
1877 ha->raw_feat = 0;
1878 if (!force_dma32) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001879 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_X_INIT_RAW, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 if (ok)
1881 ha->raw_feat = GDT_64BIT;
1882 }
1883 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001884 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 if (!ok) {
1886 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001887 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 return 0;
1889 }
1890 TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
1891
1892 /* set/get features raw service (scatter/gather) */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001893 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_SET_FEAT, SCATTER_GATHER,
1894 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001896 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
1898 ha->info));
1899 ha->raw_feat |= (ushort)ha->info;
1900 }
1901 }
1902
1903 /* set/get features cache service (equal to raw service) */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001904 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_SET_FEAT, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 SCATTER_GATHER,0)) {
1906 TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001907 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
1909 ha->info));
1910 ha->cache_feat |= (ushort)ha->info;
1911 }
1912 }
1913
1914 /* reserve drives for raw service */
1915 if (reserve_mode != 0) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001916 gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE_ALL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 reserve_mode == 1 ? 1 : 3, 0, 0);
1918 TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
1919 ha->status));
1920 }
1921 for (i = 0; i < MAX_RES_ARGS; i += 4) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001922 if (reserve_list[i] == ha->hanum && reserve_list[i+1] < ha->bus_cnt &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
1924 TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
1925 reserve_list[i], reserve_list[i+1],
1926 reserve_list[i+2], reserve_list[i+3]));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001927 if (!gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 reserve_list[i+1], reserve_list[i+2] |
1929 (reserve_list[i+3] << 8))) {
1930 printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001931 ha->hanum, ha->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 }
1933 }
1934 }
1935
1936 /* Determine OEM string using IOCTL */
1937 oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
1938 oemstr->params.ctl_version = 0x01;
1939 oemstr->params.buffer_size = sizeof(oemstr->text);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001940 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
1942 sizeof(gdth_oem_str_ioctl))) {
1943 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
1944 printk("GDT-HA %d: Vendor: %s Name: %s\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001945 ha->hanum, oemstr->text.oem_company_name, ha->binfo.type_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 /* Save the Host Drive inquiry data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
1948 sizeof(ha->oem_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 } else {
1950 /* Old method, based on PCI ID */
1951 TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
1952 printk("GDT-HA %d: Name: %s\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001953 ha->hanum, ha->binfo.type_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 if (ha->oem_id == OEM_ID_INTEL)
1955 strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
1956 else
1957 strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959
1960 /* scanning for host drives */
1961 for (i = 0; i < cdev_cnt; ++i)
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001962 gdth_analyse_hdrive(ha, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 TRACE(("gdth_search_drives() OK\n"));
1965 return 1;
1966}
1967
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001968static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 ulong32 drv_cyls;
1971 int drv_hds, drv_secs;
1972
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001973 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 if (hdrive >= MAX_HDRIVES)
1975 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001977 if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_INFO, hdrive, 0, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 return 0;
1979 ha->hdr[hdrive].present = TRUE;
1980 ha->hdr[hdrive].size = ha->info;
1981
1982 /* evaluate mapping (sectors per head, heads per cylinder) */
1983 ha->hdr[hdrive].size &= ~SECS32;
1984 if (ha->info2 == 0) {
1985 gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
1986 } else {
1987 drv_hds = ha->info2 & 0xff;
1988 drv_secs = (ha->info2 >> 8) & 0xff;
1989 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
1990 }
1991 ha->hdr[hdrive].heads = (unchar)drv_hds;
1992 ha->hdr[hdrive].secs = (unchar)drv_secs;
1993 /* round size */
1994 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
1995
1996 if (ha->cache_feat & GDT_64BIT) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02001997 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 && ha->info2 != 0) {
1999 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
2000 }
2001 }
2002 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
2003 hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
2004
2005 /* get informations about device */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002006 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
2008 hdrive,ha->info));
2009 ha->hdr[hdrive].devtype = (ushort)ha->info;
2010 }
2011
2012 /* cluster info */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002013 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_CLUST_INFO, hdrive, 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
2015 hdrive,ha->info));
2016 if (!shared_access)
2017 ha->hdr[hdrive].cluster_type = (unchar)ha->info;
2018 }
2019
2020 /* R/W attributes */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002021 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
2023 hdrive,ha->info));
2024 ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
2025 }
2026
2027 return 1;
2028}
2029
2030
2031/* command queueing/sending functions */
2032
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002033static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034{
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002035 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 register Scsi_Cmnd *pscp;
2037 register Scsi_Cmnd *nscp;
2038 ulong flags;
2039 unchar b, t;
2040
2041 TRACE(("gdth_putq() priority %d\n",priority));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 spin_lock_irqsave(&ha->smp_lock, flags);
2043
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002044 if (!cmndinfo->internal_command) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002045 cmndinfo->priority = priority;
Christoph Hellwig52759e62007-10-02 22:59:53 +02002046 b = scp->device->channel;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002047 t = scp->device->id;
2048 if (priority >= DEFAULT_PRI) {
2049 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2050 (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) {
2051 TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
Boaz Harroshf842b642007-10-02 23:16:01 +02002052 cmndinfo->timeout = gdth_update_timeout(scp, 0);
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055 }
2056
2057 if (ha->req_first==NULL) {
2058 ha->req_first = scp; /* queue was empty */
2059 scp->SCp.ptr = NULL;
2060 } else { /* queue not empty */
2061 pscp = ha->req_first;
2062 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2063 /* priority: 0-highest,..,0xff-lowest */
Boaz Harroshf842b642007-10-02 23:16:01 +02002064 while (nscp && gdth_cmnd_priv(nscp)->priority <= priority) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 pscp = nscp;
2066 nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
2067 }
2068 pscp->SCp.ptr = (char *)scp;
2069 scp->SCp.ptr = (char *)nscp;
2070 }
2071 spin_unlock_irqrestore(&ha->smp_lock, flags);
2072
2073#ifdef GDTH_STATISTICS
2074 flags = 0;
2075 for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
2076 ++flags;
2077 if (max_rq < flags) {
2078 max_rq = flags;
2079 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
2080 }
2081#endif
2082}
2083
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002084static void gdth_next(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 register Scsi_Cmnd *pscp;
2087 register Scsi_Cmnd *nscp;
2088 unchar b, t, l, firsttime;
2089 unchar this_cmd, next_cmd;
2090 ulong flags = 0;
2091 int cmd_index;
2092
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002093 TRACE(("gdth_next() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 if (!gdth_polling)
2095 spin_lock_irqsave(&ha->smp_lock, flags);
2096
2097 ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
2098 this_cmd = firsttime = TRUE;
2099 next_cmd = gdth_polling ? FALSE:TRUE;
2100 cmd_index = 0;
2101
2102 for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002103 struct gdth_cmndinfo *nscp_cmndinfo = gdth_cmnd_priv(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
2105 pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
Boaz Harroshf842b642007-10-02 23:16:01 +02002106 if (!nscp_cmndinfo->internal_command) {
Christoph Hellwig52759e62007-10-02 22:59:53 +02002107 b = nscp->device->channel;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002108 t = nscp->device->id;
2109 l = nscp->device->lun;
Boaz Harroshf842b642007-10-02 23:16:01 +02002110 if (nscp_cmndinfo->priority >= DEFAULT_PRI) {
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002111 if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
2112 (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
2113 continue;
2114 }
2115 } else
2116 b = t = l = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118 if (firsttime) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002119 if (gdth_test_busy(ha)) { /* controller busy ? */
2120 TRACE(("gdth_next() controller %d busy !\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 if (!gdth_polling) {
2122 spin_unlock_irqrestore(&ha->smp_lock, flags);
2123 return;
2124 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002125 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 gdth_delay(1);
2127 }
2128 firsttime = FALSE;
2129 }
2130
Boaz Harroshf842b642007-10-02 23:16:01 +02002131 if (!nscp_cmndinfo->internal_command) {
2132 if (nscp_cmndinfo->phase == -1) {
2133 nscp_cmndinfo->phase = CACHESERVICE; /* default: cache svc. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 if (nscp->cmnd[0] == TEST_UNIT_READY) {
2135 TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
2136 b, t, l));
2137 /* TEST_UNIT_READY -> set scan mode */
2138 if ((ha->scan_mode & 0x0f) == 0) {
2139 if (b == 0 && t == 0 && l == 0) {
2140 ha->scan_mode |= 1;
2141 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2142 }
2143 } else if ((ha->scan_mode & 0x0f) == 1) {
2144 if (b == 0 && ((t == 0 && l == 1) ||
2145 (t == 1 && l == 0))) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002146 nscp_cmndinfo->OpCode = GDT_SCAN_START;
2147 nscp_cmndinfo->phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 | SCSIRAWSERVICE;
2149 ha->scan_mode = 0x12;
2150 TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
2151 ha->scan_mode));
2152 } else {
2153 ha->scan_mode &= 0x10;
2154 TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
2155 }
2156 } else if (ha->scan_mode == 0x12) {
2157 if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002158 nscp_cmndinfo->phase = SCSIRAWSERVICE;
2159 nscp_cmndinfo->OpCode = GDT_SCAN_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 ha->scan_mode &= 0x10;
2161 TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
2162 ha->scan_mode));
2163 }
2164 }
2165 }
2166 if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
2167 nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
2168 (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
2169 /* always GDT_CLUST_INFO! */
Boaz Harroshf842b642007-10-02 23:16:01 +02002170 nscp_cmndinfo->OpCode = GDT_CLUST_INFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 }
2172 }
2173 }
2174
Boaz Harroshf842b642007-10-02 23:16:01 +02002175 if (nscp_cmndinfo->OpCode != -1) {
2176 if ((nscp_cmndinfo->phase & 0xff) == CACHESERVICE) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002177 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 this_cmd = FALSE;
2179 next_cmd = FALSE;
Boaz Harroshf842b642007-10-02 23:16:01 +02002180 } else if ((nscp_cmndinfo->phase & 0xff) == SCSIRAWSERVICE) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002181 if (!(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 this_cmd = FALSE;
2183 next_cmd = FALSE;
2184 } else {
2185 memset((char*)nscp->sense_buffer,0,16);
2186 nscp->sense_buffer[0] = 0x70;
2187 nscp->sense_buffer[2] = NOT_READY;
2188 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
Boaz Harroshf842b642007-10-02 23:16:01 +02002189 if (!nscp_cmndinfo->wait_for_completion)
2190 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002192 gdth_scsi_done(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 }
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002194 } else if (gdth_cmnd_priv(nscp)->internal_command) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002195 if (!(cmd_index=gdth_special_cmd(ha, nscp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 this_cmd = FALSE;
2197 next_cmd = FALSE;
2198 } else if (b != ha->virt_bus) {
2199 if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002200 !(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 this_cmd = FALSE;
2202 else
2203 ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
2204 } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
2205 TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
2206 nscp->cmnd[0], b, t, l));
2207 nscp->result = DID_BAD_TARGET << 16;
Boaz Harroshf842b642007-10-02 23:16:01 +02002208 if (!nscp_cmndinfo->wait_for_completion)
2209 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002211 gdth_scsi_done(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 } else {
2213 switch (nscp->cmnd[0]) {
2214 case TEST_UNIT_READY:
2215 case INQUIRY:
2216 case REQUEST_SENSE:
2217 case READ_CAPACITY:
2218 case VERIFY:
2219 case START_STOP:
2220 case MODE_SENSE:
2221 case SERVICE_ACTION_IN:
2222 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2223 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2224 nscp->cmnd[4],nscp->cmnd[5]));
2225 if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
2226 /* return UNIT_ATTENTION */
2227 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2228 nscp->cmnd[0], t));
2229 ha->hdr[t].media_changed = FALSE;
2230 memset((char*)nscp->sense_buffer,0,16);
2231 nscp->sense_buffer[0] = 0x70;
2232 nscp->sense_buffer[2] = UNIT_ATTENTION;
2233 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
Boaz Harroshf842b642007-10-02 23:16:01 +02002234 if (!nscp_cmndinfo->wait_for_completion)
2235 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002237 gdth_scsi_done(nscp);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002238 } else if (gdth_internal_cache_cmd(ha, nscp))
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002239 gdth_scsi_done(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 break;
2241
2242 case ALLOW_MEDIUM_REMOVAL:
2243 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2244 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2245 nscp->cmnd[4],nscp->cmnd[5]));
2246 if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
2247 TRACE(("Prevent r. nonremov. drive->do nothing\n"));
2248 nscp->result = DID_OK << 16;
2249 nscp->sense_buffer[0] = 0;
Boaz Harroshf842b642007-10-02 23:16:01 +02002250 if (!nscp_cmndinfo->wait_for_completion)
2251 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002253 gdth_scsi_done(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 } else {
2255 nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
2256 TRACE(("Prevent/allow r. %d rem. drive %d\n",
2257 nscp->cmnd[4],nscp->cmnd[3]));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002258 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 this_cmd = FALSE;
2260 }
2261 break;
2262
2263 case RESERVE:
2264 case RELEASE:
2265 TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
2266 "RESERVE" : "RELEASE"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002267 if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 this_cmd = FALSE;
2269 break;
2270
2271 case READ_6:
2272 case WRITE_6:
2273 case READ_10:
2274 case WRITE_10:
2275 case READ_16:
2276 case WRITE_16:
2277 if (ha->hdr[t].media_changed) {
2278 /* return UNIT_ATTENTION */
2279 TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
2280 nscp->cmnd[0], t));
2281 ha->hdr[t].media_changed = FALSE;
2282 memset((char*)nscp->sense_buffer,0,16);
2283 nscp->sense_buffer[0] = 0x70;
2284 nscp->sense_buffer[2] = UNIT_ATTENTION;
2285 nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
Boaz Harroshf842b642007-10-02 23:16:01 +02002286 if (!nscp_cmndinfo->wait_for_completion)
2287 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002289 gdth_scsi_done(nscp);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002290 } else if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 this_cmd = FALSE;
2292 break;
2293
2294 default:
2295 TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
2296 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2297 nscp->cmnd[4],nscp->cmnd[5]));
2298 printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002299 ha->hanum, nscp->cmnd[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 nscp->result = DID_ABORT << 16;
Boaz Harroshf842b642007-10-02 23:16:01 +02002301 if (!nscp_cmndinfo->wait_for_completion)
2302 nscp_cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 else
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02002304 gdth_scsi_done(nscp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 break;
2306 }
2307 }
2308
2309 if (!this_cmd)
2310 break;
2311 if (nscp == ha->req_first)
2312 ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
2313 else
2314 pscp->SCp.ptr = nscp->SCp.ptr;
2315 if (!next_cmd)
2316 break;
2317 }
2318
2319 if (ha->cmd_cnt > 0) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002320 gdth_release_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 }
2322
2323 if (!gdth_polling)
2324 spin_unlock_irqrestore(&ha->smp_lock, flags);
2325
2326 if (gdth_polling && ha->cmd_cnt > 0) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002327 if (!gdth_wait(ha, cmd_index, POLL_TIMEOUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 printk("GDT-HA %d: Command %d timed out !\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002329 ha->hanum, cmd_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 }
2331}
Boaz Harrosh3892d882007-10-02 23:18:03 +02002332
2333/*
2334 * gdth_copy_internal_data() - copy to/from a buffer onto a scsi_cmnd's
2335 * buffers, kmap_atomic() as needed.
2336 */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002337static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
Boaz Harroshee54cc62008-02-27 15:29:15 -08002338 char *buffer, ushort count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
Boaz Harrosh3892d882007-10-02 23:18:03 +02002340 ushort cpcount,i, max_sg = gdth_sg_count(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 ushort cpsum,cpnow;
2342 struct scatterlist *sl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 char *address;
2344
Boaz Harrosh3892d882007-10-02 23:18:03 +02002345 cpcount = min_t(ushort, count, gdth_bufflen(scp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
Boaz Harrosh3892d882007-10-02 23:18:03 +02002347 if (cpcount) {
2348 cpsum=0;
2349 scsi_for_each_sg(scp, sl, max_sg, i) {
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002350 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 cpnow = (ushort)sl->length;
2352 TRACE(("copy_internal() now %d sum %d count %d %d\n",
Boaz Harrosh3892d882007-10-02 23:18:03 +02002353 cpnow, cpsum, cpcount, gdth_bufflen(scp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 if (cpsum+cpnow > cpcount)
2355 cpnow = cpcount - cpsum;
2356 cpsum += cpnow;
Jens Axboe45711f12007-10-22 21:19:53 +02002357 if (!sg_page(sl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002359 ha->hanum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 return;
2361 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002362 local_irq_save(flags);
Jens Axboe45711f12007-10-22 21:19:53 +02002363 address = kmap_atomic(sg_page(sl), KM_BIO_SRC_IRQ) + sl->offset;
Boaz Harroshee54cc62008-02-27 15:29:15 -08002364 memcpy(address, buffer, cpnow);
Jens Axboe45711f12007-10-22 21:19:53 +02002365 flush_dcache_page(sg_page(sl));
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002366 kunmap_atomic(address, KM_BIO_SRC_IRQ);
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002367 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 if (cpsum == cpcount)
2369 break;
2370 buffer += cpnow;
2371 }
Boaz Harrosh3892d882007-10-02 23:18:03 +02002372 } else if (count) {
2373 printk("GDT-HA %d: SCSI command with no buffers but data transfer expected!\n",
2374 ha->hanum);
2375 WARN_ON(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 }
2377}
2378
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002379static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 unchar t;
2382 gdth_inq_data inq;
2383 gdth_rdcap_data rdc;
2384 gdth_sense_data sd;
2385 gdth_modep_data mpd;
Boaz Harroshf842b642007-10-02 23:16:01 +02002386 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 t = scp->device->id;
2389 TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
2390 scp->cmnd[0],t));
2391
2392 scp->result = DID_OK << 16;
2393 scp->sense_buffer[0] = 0;
2394
2395 switch (scp->cmnd[0]) {
2396 case TEST_UNIT_READY:
2397 case VERIFY:
2398 case START_STOP:
2399 TRACE2(("Test/Verify/Start hdrive %d\n",t));
2400 break;
2401
2402 case INQUIRY:
2403 TRACE2(("Inquiry hdrive %d devtype %d\n",
2404 t,ha->hdr[t].devtype));
2405 inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
2406 /* you can here set all disks to removable, if you want to do
2407 a flush using the ALLOW_MEDIUM_REMOVAL command */
2408 inq.modif_rmb = 0x00;
2409 if ((ha->hdr[t].devtype & 1) ||
2410 (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
2411 inq.modif_rmb = 0x80;
2412 inq.version = 2;
2413 inq.resp_aenc = 2;
2414 inq.add_length= 32;
2415 strcpy(inq.vendor,ha->oem_name);
2416 sprintf(inq.product,"Host Drive #%02d",t);
2417 strcpy(inq.revision," ");
Boaz Harroshee54cc62008-02-27 15:29:15 -08002418 gdth_copy_internal_data(ha, scp, (char*)&inq, sizeof(gdth_inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 break;
2420
2421 case REQUEST_SENSE:
2422 TRACE2(("Request sense hdrive %d\n",t));
2423 sd.errorcode = 0x70;
2424 sd.segno = 0x00;
2425 sd.key = NO_SENSE;
2426 sd.info = 0;
2427 sd.add_length= 0;
Boaz Harroshee54cc62008-02-27 15:29:15 -08002428 gdth_copy_internal_data(ha, scp, (char*)&sd, sizeof(gdth_sense_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 break;
2430
2431 case MODE_SENSE:
2432 TRACE2(("Mode sense hdrive %d\n",t));
2433 memset((char*)&mpd,0,sizeof(gdth_modep_data));
2434 mpd.hd.data_length = sizeof(gdth_modep_data);
2435 mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
2436 mpd.hd.bd_length = sizeof(mpd.bd);
2437 mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
2438 mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
2439 mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
Boaz Harroshee54cc62008-02-27 15:29:15 -08002440 gdth_copy_internal_data(ha, scp, (char*)&mpd, sizeof(gdth_modep_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 break;
2442
2443 case READ_CAPACITY:
2444 TRACE2(("Read capacity hdrive %d\n",t));
2445 if (ha->hdr[t].size > (ulong64)0xffffffff)
2446 rdc.last_block_no = 0xffffffff;
2447 else
2448 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
2449 rdc.block_length = cpu_to_be32(SECTOR_SIZE);
Boaz Harroshee54cc62008-02-27 15:29:15 -08002450 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 break;
2452
2453 case SERVICE_ACTION_IN:
2454 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2455 (ha->cache_feat & GDT_64BIT)) {
2456 gdth_rdcap16_data rdc16;
2457
2458 TRACE2(("Read capacity (16) hdrive %d\n",t));
2459 rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
2460 rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002461 gdth_copy_internal_data(ha, scp, (char*)&rdc16,
Boaz Harroshee54cc62008-02-27 15:29:15 -08002462 sizeof(gdth_rdcap16_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 } else {
2464 scp->result = DID_ABORT << 16;
2465 }
2466 break;
2467
2468 default:
2469 TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
2470 break;
2471 }
2472
Boaz Harroshf842b642007-10-02 23:16:01 +02002473 if (!cmndinfo->wait_for_completion)
2474 cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 else
2476 return 1;
2477
2478 return 0;
2479}
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002480
2481static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 register gdth_cmd_str *cmdp;
Boaz Harroshf842b642007-10-02 23:16:01 +02002484 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 ulong32 cnt, blockcnt;
2486 ulong64 no, blockno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 int i, cmd_index, read_write, sgcnt, mode64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 cmdp = ha->pccb;
2490 TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
2491 scp->cmnd[0],scp->cmd_len,hdrive));
2492
2493 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2494 return 0;
2495
2496 mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
2497 /* test for READ_16, WRITE_16 if !mode64 ? ---
2498 not required, should not occur due to error return on
2499 READ_CAPACITY_16 */
2500
2501 cmdp->Service = CACHESERVICE;
2502 cmdp->RequestBuffer = scp;
2503 /* search free command index */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002504 if (!(cmd_index=gdth_get_cmd_index(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 TRACE(("GDT: No free command index found\n"));
2506 return 0;
2507 }
2508 /* if it's the first command, set command semaphore */
2509 if (ha->cmd_cnt == 0)
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002510 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 /* fill command */
2513 read_write = 0;
Boaz Harroshf842b642007-10-02 23:16:01 +02002514 if (cmndinfo->OpCode != -1)
2515 cmdp->OpCode = cmndinfo->OpCode; /* special cache cmd. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 else if (scp->cmnd[0] == RESERVE)
2517 cmdp->OpCode = GDT_RESERVE_DRV;
2518 else if (scp->cmnd[0] == RELEASE)
2519 cmdp->OpCode = GDT_RELEASE_DRV;
2520 else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
2521 if (scp->cmnd[4] & 1) /* prevent ? */
2522 cmdp->OpCode = GDT_MOUNT;
2523 else if (scp->cmnd[3] & 1) /* removable drive ? */
2524 cmdp->OpCode = GDT_UNMOUNT;
2525 else
2526 cmdp->OpCode = GDT_FLUSH;
2527 } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
2528 scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16
2529 ) {
2530 read_write = 1;
2531 if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
2532 (ha->cache_feat & GDT_WR_THROUGH)))
2533 cmdp->OpCode = GDT_WRITE_THR;
2534 else
2535 cmdp->OpCode = GDT_WRITE;
2536 } else {
2537 read_write = 2;
2538 cmdp->OpCode = GDT_READ;
2539 }
2540
2541 cmdp->BoardNode = LOCALBOARD;
2542 if (mode64) {
2543 cmdp->u.cache64.DeviceNo = hdrive;
2544 cmdp->u.cache64.BlockNo = 1;
2545 cmdp->u.cache64.sg_canz = 0;
2546 } else {
2547 cmdp->u.cache.DeviceNo = hdrive;
2548 cmdp->u.cache.BlockNo = 1;
2549 cmdp->u.cache.sg_canz = 0;
2550 }
2551
2552 if (read_write) {
2553 if (scp->cmd_len == 16) {
2554 memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
2555 blockno = be64_to_cpu(no);
2556 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
2557 blockcnt = be32_to_cpu(cnt);
2558 } else if (scp->cmd_len == 10) {
2559 memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
2560 blockno = be32_to_cpu(no);
2561 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
2562 blockcnt = be16_to_cpu(cnt);
2563 } else {
2564 memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
2565 blockno = be32_to_cpu(no) & 0x001fffffUL;
2566 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2567 }
2568 if (mode64) {
2569 cmdp->u.cache64.BlockNo = blockno;
2570 cmdp->u.cache64.BlockCnt = blockcnt;
2571 } else {
2572 cmdp->u.cache.BlockNo = (ulong32)blockno;
2573 cmdp->u.cache.BlockCnt = blockcnt;
2574 }
2575
Boaz Harrosh3892d882007-10-02 23:18:03 +02002576 if (gdth_bufflen(scp)) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002577 cmndinfo->dma_dir = (read_write == 1 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
Boaz Harrosh3892d882007-10-02 23:18:03 +02002579 sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
2580 cmndinfo->dma_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 if (mode64) {
Boaz Harrosh3892d882007-10-02 23:18:03 +02002582 struct scatterlist *sl;
2583
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 cmdp->u.cache64.DestAddr= (ulong64)-1;
2585 cmdp->u.cache64.sg_canz = sgcnt;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002586 scsi_for_each_sg(scp, sl, sgcnt, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2588#ifdef GDTH_DMA_STATISTICS
2589 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2590 ha->dma64_cnt++;
2591 else
2592 ha->dma32_cnt++;
2593#endif
2594 cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
2595 }
2596 } else {
Boaz Harrosh3892d882007-10-02 23:18:03 +02002597 struct scatterlist *sl;
2598
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 cmdp->u.cache.DestAddr= 0xffffffff;
2600 cmdp->u.cache.sg_canz = sgcnt;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002601 scsi_for_each_sg(scp, sl, sgcnt, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
2603#ifdef GDTH_DMA_STATISTICS
2604 ha->dma32_cnt++;
2605#endif
2606 cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
2607 }
2608 }
2609
2610#ifdef GDTH_STATISTICS
2611 if (max_sg < (ulong32)sgcnt) {
2612 max_sg = (ulong32)sgcnt;
2613 TRACE3(("GDT: max_sg = %d\n",max_sg));
2614 }
2615#endif
2616
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618 }
2619 /* evaluate command size, check space */
2620 if (mode64) {
2621 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2622 cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
2623 cmdp->u.cache64.sg_lst[0].sg_ptr,
2624 cmdp->u.cache64.sg_lst[0].sg_len));
2625 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2626 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
2627 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
2628 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
2629 } else {
2630 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2631 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
2632 cmdp->u.cache.sg_lst[0].sg_ptr,
2633 cmdp->u.cache.sg_lst[0].sg_len));
2634 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2635 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
2636 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
2637 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
2638 }
2639 if (ha->cmd_len & 3)
2640 ha->cmd_len += (4 - (ha->cmd_len & 3));
2641
2642 if (ha->cmd_cnt > 0) {
2643 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2644 ha->ic_all_size) {
2645 TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
2646 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2647 return 0;
2648 }
2649 }
2650
2651 /* copy command */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002652 gdth_copy_command(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 return cmd_index;
2654}
2655
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002656static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 register gdth_cmd_str *cmdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 ushort i;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002660 dma_addr_t sense_paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 int cmd_index, sgcnt, mode64;
2662 unchar t,l;
2663 struct page *page;
2664 ulong offset;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002665 struct gdth_cmndinfo *cmndinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 t = scp->device->id;
2668 l = scp->device->lun;
2669 cmdp = ha->pccb;
2670 TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
2671 scp->cmnd[0],b,t,l));
2672
2673 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2674 return 0;
2675
2676 mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
2677
2678 cmdp->Service = SCSIRAWSERVICE;
2679 cmdp->RequestBuffer = scp;
2680 /* search free command index */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002681 if (!(cmd_index=gdth_get_cmd_index(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 TRACE(("GDT: No free command index found\n"));
2683 return 0;
2684 }
2685 /* if it's the first command, set command semaphore */
2686 if (ha->cmd_cnt == 0)
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002687 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002689 cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 /* fill command */
Boaz Harroshf842b642007-10-02 23:16:01 +02002691 if (cmndinfo->OpCode != -1) {
2692 cmdp->OpCode = cmndinfo->OpCode; /* special raw cmd. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 cmdp->BoardNode = LOCALBOARD;
2694 if (mode64) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002695 cmdp->u.raw64.direction = (cmndinfo->phase >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2697 cmdp->OpCode, cmdp->u.raw64.direction));
2698 /* evaluate command size */
2699 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
2700 } else {
Boaz Harroshf842b642007-10-02 23:16:01 +02002701 cmdp->u.raw.direction = (cmndinfo->phase >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 TRACE2(("special raw cmd 0x%x param 0x%x\n",
2703 cmdp->OpCode, cmdp->u.raw.direction));
2704 /* evaluate command size */
2705 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
2706 }
2707
2708 } else {
2709 page = virt_to_page(scp->sense_buffer);
2710 offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
2711 sense_paddr = pci_map_page(ha->pdev,page,offset,
2712 16,PCI_DMA_FROMDEVICE);
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02002713
2714 cmndinfo->sense_paddr = sense_paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 cmdp->OpCode = GDT_WRITE; /* always */
2716 cmdp->BoardNode = LOCALBOARD;
2717 if (mode64) {
2718 cmdp->u.raw64.reserved = 0;
2719 cmdp->u.raw64.mdisc_time = 0;
2720 cmdp->u.raw64.mcon_time = 0;
2721 cmdp->u.raw64.clen = scp->cmd_len;
2722 cmdp->u.raw64.target = t;
2723 cmdp->u.raw64.lun = l;
2724 cmdp->u.raw64.bus = b;
2725 cmdp->u.raw64.priority = 0;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002726 cmdp->u.raw64.sdlen = gdth_bufflen(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 cmdp->u.raw64.sense_len = 16;
2728 cmdp->u.raw64.sense_data = sense_paddr;
2729 cmdp->u.raw64.direction =
2730 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2731 memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
Joerg Dorchainbb9ba312007-03-06 02:46:54 -08002732 cmdp->u.raw64.sg_ranz = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 } else {
2734 cmdp->u.raw.reserved = 0;
2735 cmdp->u.raw.mdisc_time = 0;
2736 cmdp->u.raw.mcon_time = 0;
2737 cmdp->u.raw.clen = scp->cmd_len;
2738 cmdp->u.raw.target = t;
2739 cmdp->u.raw.lun = l;
2740 cmdp->u.raw.bus = b;
2741 cmdp->u.raw.priority = 0;
2742 cmdp->u.raw.link_p = 0;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002743 cmdp->u.raw.sdlen = gdth_bufflen(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 cmdp->u.raw.sense_len = 16;
2745 cmdp->u.raw.sense_data = sense_paddr;
2746 cmdp->u.raw.direction =
2747 gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
2748 memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
Joerg Dorchainbb9ba312007-03-06 02:46:54 -08002749 cmdp->u.raw.sg_ranz = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 }
2751
Boaz Harrosh3892d882007-10-02 23:18:03 +02002752 if (gdth_bufflen(scp)) {
Boaz Harroshf842b642007-10-02 23:16:01 +02002753 cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002754 sgcnt = pci_map_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
2755 cmndinfo->dma_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 if (mode64) {
Boaz Harrosh3892d882007-10-02 23:18:03 +02002757 struct scatterlist *sl;
2758
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 cmdp->u.raw64.sdata = (ulong64)-1;
2760 cmdp->u.raw64.sg_ranz = sgcnt;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002761 scsi_for_each_sg(scp, sl, sgcnt, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2763#ifdef GDTH_DMA_STATISTICS
2764 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
2765 ha->dma64_cnt++;
2766 else
2767 ha->dma32_cnt++;
2768#endif
2769 cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
2770 }
2771 } else {
Boaz Harrosh3892d882007-10-02 23:18:03 +02002772 struct scatterlist *sl;
2773
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 cmdp->u.raw.sdata = 0xffffffff;
2775 cmdp->u.raw.sg_ranz = sgcnt;
Boaz Harrosh3892d882007-10-02 23:18:03 +02002776 scsi_for_each_sg(scp, sl, sgcnt, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
2778#ifdef GDTH_DMA_STATISTICS
2779 ha->dma32_cnt++;
2780#endif
2781 cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
2782 }
2783 }
2784
2785#ifdef GDTH_STATISTICS
2786 if (max_sg < sgcnt) {
2787 max_sg = sgcnt;
2788 TRACE3(("GDT: max_sg = %d\n",sgcnt));
2789 }
2790#endif
2791
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793 if (mode64) {
2794 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2795 cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
2796 cmdp->u.raw64.sg_lst[0].sg_ptr,
2797 cmdp->u.raw64.sg_lst[0].sg_len));
2798 /* evaluate command size */
2799 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
2800 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
2801 } else {
2802 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2803 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
2804 cmdp->u.raw.sg_lst[0].sg_ptr,
2805 cmdp->u.raw.sg_lst[0].sg_len));
2806 /* evaluate command size */
2807 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
2808 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
2809 }
2810 }
2811 /* check space */
2812 if (ha->cmd_len & 3)
2813 ha->cmd_len += (4 - (ha->cmd_len & 3));
2814
2815 if (ha->cmd_cnt > 0) {
2816 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2817 ha->ic_all_size) {
2818 TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
2819 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2820 return 0;
2821 }
2822 }
2823
2824 /* copy command */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002825 gdth_copy_command(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 return cmd_index;
2827}
2828
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002829static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 register gdth_cmd_str *cmdp;
Boaz Harroshee54cc62008-02-27 15:29:15 -08002832 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 int cmd_index;
2834
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 cmdp= ha->pccb;
2836 TRACE2(("gdth_special_cmd(): "));
2837
2838 if (ha->type==GDT_EISA && ha->cmd_cnt>0)
2839 return 0;
2840
Boaz Harroshee54cc62008-02-27 15:29:15 -08002841 *cmdp = *cmndinfo->internal_cmd_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 cmdp->RequestBuffer = scp;
2843
2844 /* search free command index */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002845 if (!(cmd_index=gdth_get_cmd_index(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 TRACE(("GDT: No free command index found\n"));
2847 return 0;
2848 }
2849
2850 /* if it's the first command, set command semaphore */
2851 if (ha->cmd_cnt == 0)
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002852 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
2854 /* evaluate command size, check space */
2855 if (cmdp->OpCode == GDT_IOCTL) {
2856 TRACE2(("IOCTL\n"));
2857 ha->cmd_len =
2858 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
2859 } else if (cmdp->Service == CACHESERVICE) {
2860 TRACE2(("cache command %d\n",cmdp->OpCode));
2861 if (ha->cache_feat & GDT_64BIT)
2862 ha->cmd_len =
2863 GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
2864 else
2865 ha->cmd_len =
2866 GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
2867 } else if (cmdp->Service == SCSIRAWSERVICE) {
2868 TRACE2(("raw command %d\n",cmdp->OpCode));
2869 if (ha->raw_feat & GDT_64BIT)
2870 ha->cmd_len =
2871 GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
2872 else
2873 ha->cmd_len =
2874 GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
2875 }
2876
2877 if (ha->cmd_len & 3)
2878 ha->cmd_len += (4 - (ha->cmd_len & 3));
2879
2880 if (ha->cmd_cnt > 0) {
2881 if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
2882 ha->ic_all_size) {
2883 TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
2884 ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
2885 return 0;
2886 }
2887 }
2888
2889 /* copy command */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02002890 gdth_copy_command(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 return cmd_index;
2892}
2893
2894
2895/* Controller event handling functions */
2896static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
2897 ushort idx, gdth_evt_data *evt)
2898{
2899 gdth_evt_str *e;
2900 struct timeval tv;
2901
2902 /* no GDTH_LOCK_HA() ! */
2903 TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
2904 if (source == 0) /* no source -> no event */
2905 return NULL;
2906
2907 if (ebuffer[elastidx].event_source == source &&
2908 ebuffer[elastidx].event_idx == idx &&
2909 ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
2910 !memcmp((char *)&ebuffer[elastidx].event_data.eu,
2911 (char *)&evt->eu, evt->size)) ||
2912 (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
2913 !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
2914 (char *)&evt->event_string)))) {
2915 e = &ebuffer[elastidx];
2916 do_gettimeofday(&tv);
2917 e->last_stamp = tv.tv_sec;
2918 ++e->same_count;
2919 } else {
2920 if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
2921 ++elastidx;
2922 if (elastidx == MAX_EVENTS)
2923 elastidx = 0;
2924 if (elastidx == eoldidx) { /* reached mark ? */
2925 ++eoldidx;
2926 if (eoldidx == MAX_EVENTS)
2927 eoldidx = 0;
2928 }
2929 }
2930 e = &ebuffer[elastidx];
2931 e->event_source = source;
2932 e->event_idx = idx;
2933 do_gettimeofday(&tv);
2934 e->first_stamp = e->last_stamp = tv.tv_sec;
2935 e->same_count = 1;
2936 e->event_data = *evt;
2937 e->application = 0;
2938 }
2939 return e;
2940}
2941
2942static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
2943{
2944 gdth_evt_str *e;
2945 int eindex;
2946 ulong flags;
2947
2948 TRACE2(("gdth_read_event() handle %d\n", handle));
2949 spin_lock_irqsave(&ha->smp_lock, flags);
2950 if (handle == -1)
2951 eindex = eoldidx;
2952 else
2953 eindex = handle;
2954 estr->event_source = 0;
2955
2956 if (eindex >= MAX_EVENTS) {
2957 spin_unlock_irqrestore(&ha->smp_lock, flags);
2958 return eindex;
2959 }
2960 e = &ebuffer[eindex];
2961 if (e->event_source != 0) {
2962 if (eindex != elastidx) {
2963 if (++eindex == MAX_EVENTS)
2964 eindex = 0;
2965 } else {
2966 eindex = -1;
2967 }
2968 memcpy(estr, e, sizeof(gdth_evt_str));
2969 }
2970 spin_unlock_irqrestore(&ha->smp_lock, flags);
2971 return eindex;
2972}
2973
2974static void gdth_readapp_event(gdth_ha_str *ha,
2975 unchar application, gdth_evt_str *estr)
2976{
2977 gdth_evt_str *e;
2978 int eindex;
2979 ulong flags;
2980 unchar found = FALSE;
2981
2982 TRACE2(("gdth_readapp_event() app. %d\n", application));
2983 spin_lock_irqsave(&ha->smp_lock, flags);
2984 eindex = eoldidx;
2985 for (;;) {
2986 e = &ebuffer[eindex];
2987 if (e->event_source == 0)
2988 break;
2989 if ((e->application & application) == 0) {
2990 e->application |= application;
2991 found = TRUE;
2992 break;
2993 }
2994 if (eindex == elastidx)
2995 break;
2996 if (++eindex == MAX_EVENTS)
2997 eindex = 0;
2998 }
2999 if (found)
3000 memcpy(estr, e, sizeof(gdth_evt_str));
3001 else
3002 estr->event_source = 0;
3003 spin_unlock_irqrestore(&ha->smp_lock, flags);
3004}
3005
3006static void gdth_clear_events(void)
3007{
3008 TRACE(("gdth_clear_events()"));
3009
3010 eoldidx = elastidx = 0;
3011 ebuffer[0].event_source = 0;
3012}
3013
3014
3015/* SCSI interface functions */
3016
Jeff Garzik230e8862007-12-13 16:14:12 -08003017static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003018 int gdth_from_wait, int* pIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
3021 gdt6_dpram_str __iomem *dp6_ptr;
3022 gdt2_dpram_str __iomem *dp2_ptr;
3023 Scsi_Cmnd *scp;
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003024 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 unchar IStatus;
3026 ushort Service;
3027 ulong flags = 0;
3028#ifdef INT_COAL
3029 int coalesced = FALSE;
3030 int next = FALSE;
3031 gdth_coal_status *pcs = NULL;
3032 int act_int_coal = 0;
3033#endif
3034
Jeff Garzik230e8862007-12-13 16:14:12 -08003035 TRACE(("gdth_interrupt() IRQ %d\n", ha->irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
3037 /* if polling and not from gdth_wait() -> return */
3038 if (gdth_polling) {
3039 if (!gdth_from_wait) {
3040 return IRQ_HANDLED;
3041 }
3042 }
3043
3044 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003045 spin_lock_irqsave(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 /* search controller */
Jeff Garzik230e8862007-12-13 16:14:12 -08003048 IStatus = gdth_get_status(ha);
3049 if (IStatus == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 /* spurious interrupt */
3051 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003052 spin_unlock_irqrestore(&ha->smp_lock, flags);
3053 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
3056#ifdef GDTH_STATISTICS
3057 ++act_ints;
3058#endif
3059
3060#ifdef INT_COAL
3061 /* See if the fw is returning coalesced status */
3062 if (IStatus == COALINDEX) {
3063 /* Coalesced status. Setup the initial status
3064 buffer pointer and flags */
3065 pcs = ha->coal_stat;
3066 coalesced = TRUE;
3067 next = TRUE;
3068 }
3069
3070 do {
3071 if (coalesced) {
3072 /* For coalesced requests all status
3073 information is found in the status buffer */
3074 IStatus = (unchar)(pcs->status & 0xff);
3075 }
3076#endif
3077
3078 if (ha->type == GDT_EISA) {
3079 if (IStatus & 0x80) { /* error flag */
3080 IStatus &= ~0x80;
3081 ha->status = inw(ha->bmic + MAILBOXREG+8);
3082 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3083 } else /* no error */
3084 ha->status = S_OK;
3085 ha->info = inl(ha->bmic + MAILBOXREG+12);
3086 ha->service = inw(ha->bmic + MAILBOXREG+10);
3087 ha->info2 = inl(ha->bmic + MAILBOXREG+4);
3088
3089 outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
3090 outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
3091 } else if (ha->type == GDT_ISA) {
3092 dp2_ptr = ha->brd;
3093 if (IStatus & 0x80) { /* error flag */
3094 IStatus &= ~0x80;
Jeff Garzika52667f2007-10-02 22:55:53 +02003095 ha->status = readw(&dp2_ptr->u.ic.Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3097 } else /* no error */
3098 ha->status = S_OK;
Jeff Garzika52667f2007-10-02 22:55:53 +02003099 ha->info = readl(&dp2_ptr->u.ic.Info[0]);
3100 ha->service = readw(&dp2_ptr->u.ic.Service);
3101 ha->info2 = readl(&dp2_ptr->u.ic.Info[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102
Jeff Garzika52667f2007-10-02 22:55:53 +02003103 writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
3104 writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
3105 writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 } else if (ha->type == GDT_PCI) {
3107 dp6_ptr = ha->brd;
3108 if (IStatus & 0x80) { /* error flag */
3109 IStatus &= ~0x80;
Jeff Garzika52667f2007-10-02 22:55:53 +02003110 ha->status = readw(&dp6_ptr->u.ic.Status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3112 } else /* no error */
3113 ha->status = S_OK;
Jeff Garzika52667f2007-10-02 22:55:53 +02003114 ha->info = readl(&dp6_ptr->u.ic.Info[0]);
3115 ha->service = readw(&dp6_ptr->u.ic.Service);
3116 ha->info2 = readl(&dp6_ptr->u.ic.Info[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
Jeff Garzika52667f2007-10-02 22:55:53 +02003118 writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
3119 writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
3120 writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 } else if (ha->type == GDT_PCINEW) {
3122 if (IStatus & 0x80) { /* error flag */
3123 IStatus &= ~0x80;
3124 ha->status = inw(PTR2USHORT(&ha->plx->status));
3125 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3126 } else
3127 ha->status = S_OK;
3128 ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
3129 ha->service = inw(PTR2USHORT(&ha->plx->service));
3130 ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
3131
3132 outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
3133 outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
3134 } else if (ha->type == GDT_PCIMPR) {
3135 dp6m_ptr = ha->brd;
3136 if (IStatus & 0x80) { /* error flag */
3137 IStatus &= ~0x80;
3138#ifdef INT_COAL
3139 if (coalesced)
Jean Delvare107e7162006-11-09 21:45:09 +01003140 ha->status = pcs->ext_status & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 else
3142#endif
Jeff Garzika52667f2007-10-02 22:55:53 +02003143 ha->status = readw(&dp6m_ptr->i960r.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
3145 } else /* no error */
3146 ha->status = S_OK;
3147#ifdef INT_COAL
3148 /* get information */
3149 if (coalesced) {
3150 ha->info = pcs->info0;
3151 ha->info2 = pcs->info1;
Jean Delvare107e7162006-11-09 21:45:09 +01003152 ha->service = (pcs->ext_status >> 16) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 } else
3154#endif
3155 {
Jeff Garzika52667f2007-10-02 22:55:53 +02003156 ha->info = readl(&dp6m_ptr->i960r.info[0]);
3157 ha->service = readw(&dp6m_ptr->i960r.service);
3158 ha->info2 = readl(&dp6m_ptr->i960r.info[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 }
3160 /* event string */
3161 if (IStatus == ASYNCINDEX) {
3162 if (ha->service != SCREENSERVICE &&
3163 (ha->fw_vers & 0xff) >= 0x1a) {
Jeff Garzika52667f2007-10-02 22:55:53 +02003164 ha->dvr.severity = readb
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
3166 for (i = 0; i < 256; ++i) {
Jeff Garzika52667f2007-10-02 22:55:53 +02003167 ha->dvr.event_string[i] = readb
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
3169 if (ha->dvr.event_string[i] == 0)
3170 break;
3171 }
3172 }
3173 }
3174#ifdef INT_COAL
3175 /* Make sure that non coalesced interrupts get cleared
3176 before being handled by gdth_async_event/gdth_sync_event */
3177 if (!coalesced)
3178#endif
3179 {
Jeff Garzika52667f2007-10-02 22:55:53 +02003180 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3181 writeb(0, &dp6m_ptr->i960r.sema1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 }
3183 } else {
3184 TRACE2(("gdth_interrupt() unknown controller type\n"));
3185 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003186 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 return IRQ_HANDLED;
3188 }
3189
3190 TRACE(("gdth_interrupt() index %d stat %d info %d\n",
3191 IStatus,ha->status,ha->info));
3192
3193 if (gdth_from_wait) {
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003194 *pIndex = (int)IStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 }
3196
3197 if (IStatus == ASYNCINDEX) {
3198 TRACE2(("gdth_interrupt() async. event\n"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003199 gdth_async_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003201 spin_unlock_irqrestore(&ha->smp_lock, flags);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003202 gdth_next(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 return IRQ_HANDLED;
3204 }
3205
3206 if (IStatus == SPEZINDEX) {
3207 TRACE2(("Service unknown or not initialized !\n"));
3208 ha->dvr.size = sizeof(ha->dvr.eu.driver);
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003209 ha->dvr.eu.driver.ionode = ha->hanum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
3211 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003212 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 return IRQ_HANDLED;
3214 }
3215 scp = ha->cmd_tab[IStatus-2].cmnd;
3216 Service = ha->cmd_tab[IStatus-2].service;
3217 ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
3218 if (scp == UNUSED_CMND) {
3219 TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
3220 ha->dvr.size = sizeof(ha->dvr.eu.driver);
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003221 ha->dvr.eu.driver.ionode = ha->hanum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 ha->dvr.eu.driver.index = IStatus;
3223 gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
3224 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003225 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 return IRQ_HANDLED;
3227 }
3228 if (scp == INTERNAL_CMND) {
3229 TRACE(("gdth_interrupt() answer to internal command\n"));
3230 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003231 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 return IRQ_HANDLED;
3233 }
3234
3235 TRACE(("gdth_interrupt() sync. status\n"));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003236 rval = gdth_sync_event(ha,Service,IStatus,scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 if (!gdth_polling)
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003238 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 if (rval == 2) {
Boaz Harroshf842b642007-10-02 23:16:01 +02003240 gdth_putq(ha, scp, gdth_cmnd_priv(scp)->priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 } else if (rval == 1) {
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02003242 gdth_scsi_done(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 }
3244
3245#ifdef INT_COAL
3246 if (coalesced) {
3247 /* go to the next status in the status buffer */
3248 ++pcs;
3249#ifdef GDTH_STATISTICS
3250 ++act_int_coal;
3251 if (act_int_coal > max_int_coal) {
3252 max_int_coal = act_int_coal;
3253 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
3254 }
3255#endif
3256 /* see if there is another status */
3257 if (pcs->status == 0)
3258 /* Stop the coalesce loop */
3259 next = FALSE;
3260 }
3261 } while (next);
3262
3263 /* coalescing only for new GDT_PCIMPR controllers available */
3264 if (ha->type == GDT_PCIMPR && coalesced) {
Jeff Garzika52667f2007-10-02 22:55:53 +02003265 writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
3266 writeb(0, &dp6m_ptr->i960r.sema1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 }
3268#endif
3269
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003270 gdth_next(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 return IRQ_HANDLED;
3272}
3273
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003274static irqreturn_t gdth_interrupt(int irq, void *dev_id)
3275{
Jeff Garzik230e8862007-12-13 16:14:12 -08003276 gdth_ha_str *ha = dev_id;
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003277
Jeff Garzik230e8862007-12-13 16:14:12 -08003278 return __gdth_interrupt(ha, false, NULL);
Boaz Harrosh10e1b4b2007-10-02 23:08:10 +02003279}
3280
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003281static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3282 Scsi_Cmnd *scp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 gdth_msg_str *msg;
3285 gdth_cmd_str *cmdp;
3286 unchar b, t;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02003287 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 cmdp = ha->pccb;
3290 TRACE(("gdth_sync_event() serv %d status %d\n",
3291 service,ha->status));
3292
3293 if (service == SCREENSERVICE) {
3294 msg = ha->pmsg;
3295 TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
3296 msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
3297 if (msg->msg_len > MSGLEN+1)
3298 msg->msg_len = MSGLEN+1;
3299 if (msg->msg_len)
3300 if (!(msg->msg_answer && msg->msg_ext)) {
3301 msg->msg_text[msg->msg_len] = '\0';
3302 printk("%s",msg->msg_text);
3303 }
3304
3305 if (msg->msg_ext && !msg->msg_answer) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003306 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 gdth_delay(0);
3308 cmdp->Service = SCREENSERVICE;
3309 cmdp->RequestBuffer = SCREEN_CMND;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003310 gdth_get_cmd_index(ha);
3311 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 cmdp->OpCode = GDT_READ;
3313 cmdp->BoardNode = LOCALBOARD;
3314 cmdp->u.screen.reserved = 0;
3315 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3316 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3317 ha->cmd_offs_dpmem = 0;
3318 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3319 + sizeof(ulong64);
3320 ha->cmd_cnt = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003321 gdth_copy_command(ha);
3322 gdth_release_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 return 0;
3324 }
3325
3326 if (msg->msg_answer && msg->msg_alen) {
3327 /* default answers (getchar() not possible) */
3328 if (msg->msg_alen == 1) {
3329 msg->msg_alen = 0;
3330 msg->msg_len = 1;
3331 msg->msg_text[0] = 0;
3332 } else {
3333 msg->msg_alen -= 2;
3334 msg->msg_len = 2;
3335 msg->msg_text[0] = 1;
3336 msg->msg_text[1] = 0;
3337 }
3338 msg->msg_ext = 0;
3339 msg->msg_answer = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003340 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 gdth_delay(0);
3342 cmdp->Service = SCREENSERVICE;
3343 cmdp->RequestBuffer = SCREEN_CMND;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003344 gdth_get_cmd_index(ha);
3345 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 cmdp->OpCode = GDT_WRITE;
3347 cmdp->BoardNode = LOCALBOARD;
3348 cmdp->u.screen.reserved = 0;
3349 cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
3350 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3351 ha->cmd_offs_dpmem = 0;
3352 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3353 + sizeof(ulong64);
3354 ha->cmd_cnt = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003355 gdth_copy_command(ha);
3356 gdth_release_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 return 0;
3358 }
3359 printk("\n");
3360
3361 } else {
Christoph Hellwig52759e62007-10-02 22:59:53 +02003362 b = scp->device->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 t = scp->device->id;
Boaz Harroshf842b642007-10-02 23:16:01 +02003364 if (cmndinfo->OpCode == -1 && b != ha->virt_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
3366 }
3367 /* cache or raw service */
3368 if (ha->status == S_BSY) {
3369 TRACE2(("Controller busy -> retry !\n"));
Boaz Harroshf842b642007-10-02 23:16:01 +02003370 if (cmndinfo->OpCode == GDT_MOUNT)
3371 cmndinfo->OpCode = GDT_CLUST_INFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 /* retry */
3373 return 2;
3374 }
Boaz Harrosh3892d882007-10-02 23:18:03 +02003375 if (gdth_bufflen(scp))
3376 pci_unmap_sg(ha->pdev, gdth_sglist(scp), gdth_sg_count(scp),
3377 cmndinfo->dma_dir);
3378
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02003379 if (cmndinfo->sense_paddr)
3380 pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16,
3381 PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
3383 if (ha->status == S_OK) {
Boaz Harroshf842b642007-10-02 23:16:01 +02003384 cmndinfo->status = S_OK;
3385 cmndinfo->info = ha->info;
3386 if (cmndinfo->OpCode != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
Boaz Harroshf842b642007-10-02 23:16:01 +02003388 cmndinfo->OpCode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
Boaz Harroshf842b642007-10-02 23:16:01 +02003390 if (cmndinfo->OpCode == GDT_CLUST_INFO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 ha->hdr[t].cluster_type = (unchar)ha->info;
3392 if (!(ha->hdr[t].cluster_type &
3393 CLUSTER_MOUNTED)) {
3394 /* NOT MOUNTED -> MOUNT */
Boaz Harroshf842b642007-10-02 23:16:01 +02003395 cmndinfo->OpCode = GDT_MOUNT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 if (ha->hdr[t].cluster_type &
3397 CLUSTER_RESERVED) {
3398 /* cluster drive RESERVED (on the other node) */
Boaz Harroshf842b642007-10-02 23:16:01 +02003399 cmndinfo->phase = -2; /* reservation conflict */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 }
3401 } else {
Boaz Harroshf842b642007-10-02 23:16:01 +02003402 cmndinfo->OpCode = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 }
3404 } else {
Boaz Harroshf842b642007-10-02 23:16:01 +02003405 if (cmndinfo->OpCode == GDT_MOUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
3407 ha->hdr[t].media_changed = TRUE;
Boaz Harroshf842b642007-10-02 23:16:01 +02003408 } else if (cmndinfo->OpCode == GDT_UNMOUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
3410 ha->hdr[t].media_changed = TRUE;
3411 }
Boaz Harroshf842b642007-10-02 23:16:01 +02003412 cmndinfo->OpCode = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 }
3414 /* retry */
Boaz Harroshf842b642007-10-02 23:16:01 +02003415 cmndinfo->priority = HIGH_PRI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return 2;
3417 } else {
3418 /* RESERVE/RELEASE ? */
3419 if (scp->cmnd[0] == RESERVE) {
3420 ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
3421 } else if (scp->cmnd[0] == RELEASE) {
3422 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3423 }
3424 scp->result = DID_OK << 16;
3425 scp->sense_buffer[0] = 0;
3426 }
3427 } else {
Boaz Harroshf842b642007-10-02 23:16:01 +02003428 cmndinfo->status = ha->status;
3429 cmndinfo->info = ha->info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
Boaz Harroshf842b642007-10-02 23:16:01 +02003431 if (cmndinfo->OpCode != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
Boaz Harroshf842b642007-10-02 23:16:01 +02003433 cmndinfo->OpCode, ha->status));
3434 if (cmndinfo->OpCode == GDT_SCAN_START ||
3435 cmndinfo->OpCode == GDT_SCAN_END) {
3436 cmndinfo->OpCode = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 /* retry */
Boaz Harroshf842b642007-10-02 23:16:01 +02003438 cmndinfo->priority = HIGH_PRI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 return 2;
3440 }
3441 memset((char*)scp->sense_buffer,0,16);
3442 scp->sense_buffer[0] = 0x70;
3443 scp->sense_buffer[2] = NOT_READY;
3444 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3445 } else if (service == CACHESERVICE) {
3446 if (ha->status == S_CACHE_UNKNOWN &&
3447 (ha->hdr[t].cluster_type &
3448 CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
3449 /* bus reset -> force GDT_CLUST_INFO */
3450 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3451 }
3452 memset((char*)scp->sense_buffer,0,16);
3453 if (ha->status == (ushort)S_CACHE_RESERV) {
3454 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
3455 } else {
3456 scp->sense_buffer[0] = 0x70;
3457 scp->sense_buffer[2] = NOT_READY;
3458 scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
3459 }
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02003460 if (!cmndinfo->internal_command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 ha->dvr.size = sizeof(ha->dvr.eu.sync);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003462 ha->dvr.eu.sync.ionode = ha->hanum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 ha->dvr.eu.sync.service = service;
3464 ha->dvr.eu.sync.status = ha->status;
3465 ha->dvr.eu.sync.info = ha->info;
3466 ha->dvr.eu.sync.hostdrive = t;
3467 if (ha->status >= 0x8000)
3468 gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
3469 else
3470 gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
3471 }
3472 } else {
3473 /* sense buffer filled from controller firmware (DMA) */
3474 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
3475 scp->result = DID_BAD_TARGET << 16;
3476 } else {
3477 scp->result = (DID_OK << 16) | ha->info;
3478 }
3479 }
3480 }
Boaz Harroshf842b642007-10-02 23:16:01 +02003481 if (!cmndinfo->wait_for_completion)
3482 cmndinfo->wait_for_completion++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 else
3484 return 1;
3485 }
3486
3487 return 0;
3488}
3489
3490static char *async_cache_tab[] = {
3491/* 0*/ "\011\000\002\002\002\004\002\006\004"
3492 "GDT HA %u, service %u, async. status %u/%lu unknown",
3493/* 1*/ "\011\000\002\002\002\004\002\006\004"
3494 "GDT HA %u, service %u, async. status %u/%lu unknown",
3495/* 2*/ "\005\000\002\006\004"
3496 "GDT HA %u, Host Drive %lu not ready",
3497/* 3*/ "\005\000\002\006\004"
3498 "GDT HA %u, Host Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
3499/* 4*/ "\005\000\002\006\004"
3500 "GDT HA %u, mirror update on Host Drive %lu failed",
3501/* 5*/ "\005\000\002\006\004"
3502 "GDT HA %u, Mirror Drive %lu failed",
3503/* 6*/ "\005\000\002\006\004"
3504 "GDT HA %u, Mirror Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
3505/* 7*/ "\005\000\002\006\004"
3506 "GDT HA %u, Host Drive %lu write protected",
3507/* 8*/ "\005\000\002\006\004"
3508 "GDT HA %u, media changed in Host Drive %lu",
3509/* 9*/ "\005\000\002\006\004"
3510 "GDT HA %u, Host Drive %lu is offline",
3511/*10*/ "\005\000\002\006\004"
3512 "GDT HA %u, media change of Mirror Drive %lu",
3513/*11*/ "\005\000\002\006\004"
3514 "GDT HA %u, Mirror Drive %lu is write protected",
3515/*12*/ "\005\000\002\006\004"
3516 "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
3517/*13*/ "\007\000\002\006\002\010\002"
3518 "GDT HA %u, Array Drive %u: Cache Drive %u failed",
3519/*14*/ "\005\000\002\006\002"
3520 "GDT HA %u, Array Drive %u: FAIL state entered",
3521/*15*/ "\005\000\002\006\002"
3522 "GDT HA %u, Array Drive %u: error",
3523/*16*/ "\007\000\002\006\002\010\002"
3524 "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
3525/*17*/ "\005\000\002\006\002"
3526 "GDT HA %u, Array Drive %u: parity build failed",
3527/*18*/ "\005\000\002\006\002"
3528 "GDT HA %u, Array Drive %u: drive rebuild failed",
3529/*19*/ "\005\000\002\010\002"
3530 "GDT HA %u, Test of Hot Fix %u failed",
3531/*20*/ "\005\000\002\006\002"
3532 "GDT HA %u, Array Drive %u: drive build finished successfully",
3533/*21*/ "\005\000\002\006\002"
3534 "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
3535/*22*/ "\007\000\002\006\002\010\002"
3536 "GDT HA %u, Array Drive %u: Hot Fix %u activated",
3537/*23*/ "\005\000\002\006\002"
3538 "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
3539/*24*/ "\005\000\002\010\002"
3540 "GDT HA %u, mirror update on Cache Drive %u completed",
3541/*25*/ "\005\000\002\010\002"
3542 "GDT HA %u, mirror update on Cache Drive %lu failed",
3543/*26*/ "\005\000\002\006\002"
3544 "GDT HA %u, Array Drive %u: drive rebuild started",
3545/*27*/ "\005\000\002\012\001"
3546 "GDT HA %u, Fault bus %u: SHELF OK detected",
3547/*28*/ "\005\000\002\012\001"
3548 "GDT HA %u, Fault bus %u: SHELF not OK detected",
3549/*29*/ "\007\000\002\012\001\013\001"
3550 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
3551/*30*/ "\007\000\002\012\001\013\001"
3552 "GDT HA %u, Fault bus %u, ID %u: new disk detected",
3553/*31*/ "\007\000\002\012\001\013\001"
3554 "GDT HA %u, Fault bus %u, ID %u: old disk detected",
3555/*32*/ "\007\000\002\012\001\013\001"
3556 "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
3557/*33*/ "\007\000\002\012\001\013\001"
3558 "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
3559/*34*/ "\011\000\002\012\001\013\001\006\004"
3560 "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
3561/*35*/ "\007\000\002\012\001\013\001"
3562 "GDT HA %u, Fault bus %u, ID %u: disk write protected",
3563/*36*/ "\007\000\002\012\001\013\001"
3564 "GDT HA %u, Fault bus %u, ID %u: disk not available",
3565/*37*/ "\007\000\002\012\001\006\004"
3566 "GDT HA %u, Fault bus %u: swap detected (%lu)",
3567/*38*/ "\007\000\002\012\001\013\001"
3568 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
3569/*39*/ "\007\000\002\012\001\013\001"
3570 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
3571/*40*/ "\007\000\002\012\001\013\001"
3572 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
3573/*41*/ "\007\000\002\012\001\013\001"
3574 "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
3575/*42*/ "\005\000\002\006\002"
3576 "GDT HA %u, Array Drive %u: drive build started",
3577/*43*/ "\003\000\002"
3578 "GDT HA %u, DRAM parity error detected",
3579/*44*/ "\005\000\002\006\002"
3580 "GDT HA %u, Mirror Drive %u: update started",
3581/*45*/ "\007\000\002\006\002\010\002"
3582 "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
3583/*46*/ "\005\000\002\006\002"
3584 "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
3585/*47*/ "\005\000\002\006\002"
3586 "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
3587/*48*/ "\005\000\002\006\002"
3588 "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
3589/*49*/ "\005\000\002\006\002"
3590 "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
3591/*50*/ "\007\000\002\012\001\013\001"
3592 "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
3593/*51*/ "\005\000\002\006\002"
3594 "GDT HA %u, Array Drive %u: expand started",
3595/*52*/ "\005\000\002\006\002"
3596 "GDT HA %u, Array Drive %u: expand finished successfully",
3597/*53*/ "\005\000\002\006\002"
3598 "GDT HA %u, Array Drive %u: expand failed",
3599/*54*/ "\003\000\002"
3600 "GDT HA %u, CPU temperature critical",
3601/*55*/ "\003\000\002"
3602 "GDT HA %u, CPU temperature OK",
3603/*56*/ "\005\000\002\006\004"
3604 "GDT HA %u, Host drive %lu created",
3605/*57*/ "\005\000\002\006\002"
3606 "GDT HA %u, Array Drive %u: expand restarted",
3607/*58*/ "\005\000\002\006\002"
3608 "GDT HA %u, Array Drive %u: expand stopped",
3609/*59*/ "\005\000\002\010\002"
3610 "GDT HA %u, Mirror Drive %u: drive build quited",
3611/*60*/ "\005\000\002\006\002"
3612 "GDT HA %u, Array Drive %u: parity build quited",
3613/*61*/ "\005\000\002\006\002"
3614 "GDT HA %u, Array Drive %u: drive rebuild quited",
3615/*62*/ "\005\000\002\006\002"
3616 "GDT HA %u, Array Drive %u: parity verify started",
3617/*63*/ "\005\000\002\006\002"
3618 "GDT HA %u, Array Drive %u: parity verify done",
3619/*64*/ "\005\000\002\006\002"
3620 "GDT HA %u, Array Drive %u: parity verify failed",
3621/*65*/ "\005\000\002\006\002"
3622 "GDT HA %u, Array Drive %u: parity error detected",
3623/*66*/ "\005\000\002\006\002"
3624 "GDT HA %u, Array Drive %u: parity verify quited",
3625/*67*/ "\005\000\002\006\002"
3626 "GDT HA %u, Host Drive %u reserved",
3627/*68*/ "\005\000\002\006\002"
3628 "GDT HA %u, Host Drive %u mounted and released",
3629/*69*/ "\005\000\002\006\002"
3630 "GDT HA %u, Host Drive %u released",
3631/*70*/ "\003\000\002"
3632 "GDT HA %u, DRAM error detected and corrected with ECC",
3633/*71*/ "\003\000\002"
3634 "GDT HA %u, Uncorrectable DRAM error detected with ECC",
3635/*72*/ "\011\000\002\012\001\013\001\014\001"
3636 "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
3637/*73*/ "\005\000\002\006\002"
3638 "GDT HA %u, Host drive %u resetted locally",
3639/*74*/ "\005\000\002\006\002"
3640 "GDT HA %u, Host drive %u resetted remotely",
3641/*75*/ "\003\000\002"
3642 "GDT HA %u, async. status 75 unknown",
3643};
3644
3645
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003646static int gdth_async_event(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 gdth_cmd_str *cmdp;
3649 int cmd_index;
3650
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 cmdp= ha->pccb;
3652 TRACE2(("gdth_async_event() ha %d serv %d\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003653 ha->hanum, ha->service));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654
3655 if (ha->service == SCREENSERVICE) {
3656 if (ha->status == MSG_REQUEST) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003657 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 gdth_delay(0);
3659 cmdp->Service = SCREENSERVICE;
3660 cmdp->RequestBuffer = SCREEN_CMND;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003661 cmd_index = gdth_get_cmd_index(ha);
3662 gdth_set_sema0(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 cmdp->OpCode = GDT_READ;
3664 cmdp->BoardNode = LOCALBOARD;
3665 cmdp->u.screen.reserved = 0;
3666 cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
3667 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3668 ha->cmd_offs_dpmem = 0;
3669 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3670 + sizeof(ulong64);
3671 ha->cmd_cnt = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003672 gdth_copy_command(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 if (ha->type == GDT_EISA)
3674 printk("[EISA slot %d] ",(ushort)ha->brd_phys);
3675 else if (ha->type == GDT_ISA)
3676 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
3677 else
3678 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
3679 (ushort)((ha->brd_phys>>3)&0x1f));
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003680 gdth_release_event(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 }
3682
3683 } else {
3684 if (ha->type == GDT_PCIMPR &&
3685 (ha->fw_vers & 0xff) >= 0x1a) {
3686 ha->dvr.size = 0;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003687 ha->dvr.eu.async.ionode = ha->hanum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 ha->dvr.eu.async.status = ha->status;
3689 /* severity and event_string already set! */
3690 } else {
3691 ha->dvr.size = sizeof(ha->dvr.eu.async);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003692 ha->dvr.eu.async.ionode = ha->hanum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 ha->dvr.eu.async.service = ha->service;
3694 ha->dvr.eu.async.status = ha->status;
3695 ha->dvr.eu.async.info = ha->info;
3696 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
3697 }
3698 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
3699 gdth_log_event( &ha->dvr, NULL );
3700
3701 /* new host drive from expand? */
3702 if (ha->service == CACHESERVICE && ha->status == 56) {
3703 TRACE2(("gdth_async_event(): new host drive %d created\n",
3704 (ushort)ha->info));
3705 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
3706 }
3707 }
3708 return 1;
3709}
3710
3711static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3712{
3713 gdth_stackframe stack;
3714 char *f = NULL;
3715 int i,j;
3716
3717 TRACE2(("gdth_log_event()\n"));
3718 if (dvr->size == 0) {
3719 if (buffer == NULL) {
3720 printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
3721 } else {
3722 sprintf(buffer,"Adapter %d: %s\n",
3723 dvr->eu.async.ionode,dvr->event_string);
3724 }
3725 } else if (dvr->eu.async.service == CACHESERVICE &&
3726 INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
3727 TRACE2(("GDT: Async. event cache service, event no.: %d\n",
3728 dvr->eu.async.status));
3729
3730 f = async_cache_tab[dvr->eu.async.status];
3731
3732 /* i: parameter to push, j: stack element to fill */
3733 for (j=0,i=1; i < f[0]; i+=2) {
3734 switch (f[i+1]) {
3735 case 4:
3736 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
3737 break;
3738 case 2:
3739 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
3740 break;
3741 case 1:
3742 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
3743 break;
3744 default:
3745 break;
3746 }
3747 }
3748
3749 if (buffer == NULL) {
3750 printk(&f[(int)f[0]],stack);
3751 printk("\n");
3752 } else {
3753 sprintf(buffer,&f[(int)f[0]],stack);
3754 }
3755
3756 } else {
3757 if (buffer == NULL) {
3758 printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
3759 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3760 } else {
3761 sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
3762 dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
3763 }
3764 }
3765}
3766
3767#ifdef GDTH_STATISTICS
8e879042005-04-17 15:28:39 -05003768static void gdth_timeout(ulong data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769{
3770 ulong32 i;
3771 Scsi_Cmnd *nscp;
3772 gdth_ha_str *ha;
3773 ulong flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Boaz Harroshb31ddd32008-02-27 15:27:16 -08003775 BUG_ON(list_empty(&gdth_instances));
3776
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02003777 ha = list_first_entry(&gdth_instances, gdth_ha_str, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 spin_lock_irqsave(&ha->smp_lock, flags);
3779
3780 for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
3781 if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
3782 ++act_stats;
3783
3784 for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
3785 ++act_rq;
3786
3787 TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
3788 act_ints, act_ios, act_stats, act_rq));
3789 act_ints = act_ios = 0;
3790
3791 gdth_timer.expires = jiffies + 30 * HZ;
3792 add_timer(&gdth_timer);
3793 spin_unlock_irqrestore(&ha->smp_lock, flags);
3794}
3795#endif
3796
8e879042005-04-17 15:28:39 -05003797static void __init internal_setup(char *str,int *ints)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798{
3799 int i, argc;
3800 char *cur_str, *argv;
3801
3802 TRACE2(("internal_setup() str %s ints[0] %d\n",
3803 str ? str:"NULL", ints ? ints[0]:0));
3804
3805 /* read irq[] from ints[] */
3806 if (ints) {
3807 argc = ints[0];
3808 if (argc > 0) {
3809 if (argc > MAXHA)
3810 argc = MAXHA;
3811 for (i = 0; i < argc; ++i)
3812 irq[i] = ints[i+1];
3813 }
3814 }
3815
3816 /* analyse string */
3817 argv = str;
3818 while (argv && (cur_str = strchr(argv, ':'))) {
3819 int val = 0, c = *++cur_str;
3820
3821 if (c == 'n' || c == 'N')
3822 val = 0;
3823 else if (c == 'y' || c == 'Y')
3824 val = 1;
3825 else
3826 val = (int)simple_strtoul(cur_str, NULL, 0);
3827
3828 if (!strncmp(argv, "disable:", 8))
3829 disable = val;
3830 else if (!strncmp(argv, "reserve_mode:", 13))
3831 reserve_mode = val;
3832 else if (!strncmp(argv, "reverse_scan:", 13))
3833 reverse_scan = val;
3834 else if (!strncmp(argv, "hdr_channel:", 12))
3835 hdr_channel = val;
3836 else if (!strncmp(argv, "max_ids:", 8))
3837 max_ids = val;
3838 else if (!strncmp(argv, "rescan:", 7))
3839 rescan = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 else if (!strncmp(argv, "shared_access:", 14))
3841 shared_access = val;
3842 else if (!strncmp(argv, "probe_eisa_isa:", 15))
3843 probe_eisa_isa = val;
3844 else if (!strncmp(argv, "reserve_list:", 13)) {
3845 reserve_list[0] = val;
3846 for (i = 1; i < MAX_RES_ARGS; i++) {
3847 cur_str = strchr(cur_str, ',');
3848 if (!cur_str)
3849 break;
3850 if (!isdigit((int)*++cur_str)) {
3851 --cur_str;
3852 break;
3853 }
3854 reserve_list[i] =
3855 (int)simple_strtoul(cur_str, NULL, 0);
3856 }
3857 if (!cur_str)
3858 break;
3859 argv = ++cur_str;
3860 continue;
3861 }
3862
3863 if ((argv = strchr(argv, ',')))
3864 ++argv;
3865 }
3866}
3867
3868int __init option_setup(char *str)
3869{
3870 int ints[MAXHA];
3871 char *cur = str;
3872 int i = 1;
3873
3874 TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
3875
3876 while (cur && isdigit(*cur) && i <= MAXHA) {
3877 ints[i++] = simple_strtoul(cur, NULL, 0);
3878 if ((cur = strchr(cur, ',')) != NULL) cur++;
3879 }
3880
3881 ints[0] = i - 1;
3882 internal_setup(cur, ints);
3883 return 1;
3884}
3885
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003886static const char *gdth_ctr_name(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 TRACE2(("gdth_ctr_name()\n"));
3889
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if (ha->type == GDT_EISA) {
3891 switch (ha->stype) {
3892 case GDT3_ID:
3893 return("GDT3000/3020");
3894 case GDT3A_ID:
3895 return("GDT3000A/3020A/3050A");
3896 case GDT3B_ID:
3897 return("GDT3000B/3010A");
3898 }
3899 } else if (ha->type == GDT_ISA) {
3900 return("GDT2000/2020");
3901 } else if (ha->type == GDT_PCI) {
Jeff Garzik8e9a8a02007-07-17 05:25:17 -04003902 switch (ha->pdev->device) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 case PCI_DEVICE_ID_VORTEX_GDT60x0:
3904 return("GDT6000/6020/6050");
3905 case PCI_DEVICE_ID_VORTEX_GDT6000B:
3906 return("GDT6000B/6010");
3907 }
3908 }
3909 /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
3910
3911 return("");
3912}
3913
8e879042005-04-17 15:28:39 -05003914static const char *gdth_info(struct Scsi_Host *shp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915{
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003916 gdth_ha_str *ha = shost_priv(shp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
3918 TRACE2(("gdth_info()\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 return ((const char *)ha->binfo.type_string);
3920}
3921
8e879042005-04-17 15:28:39 -05003922static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923{
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003924 gdth_ha_str *ha = shost_priv(scp->device->host);
3925 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 ulong flags;
3927 Scsi_Cmnd *cmnd;
3928 unchar b;
3929
3930 TRACE2(("gdth_eh_bus_reset()\n"));
3931
Christoph Hellwig52759e62007-10-02 22:59:53 +02003932 b = scp->device->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
3934 /* clear command tab */
3935 spin_lock_irqsave(&ha->smp_lock, flags);
3936 for (i = 0; i < GDTH_MAXCMDS; ++i) {
3937 cmnd = ha->cmd_tab[i].cmnd;
3938 if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
3939 ha->cmd_tab[i].cmnd = UNUSED_CMND;
3940 }
3941 spin_unlock_irqrestore(&ha->smp_lock, flags);
3942
3943 if (b == ha->virt_bus) {
3944 /* host drives */
3945 for (i = 0; i < MAX_HDRIVES; ++i) {
3946 if (ha->hdr[i].present) {
3947 spin_lock_irqsave(&ha->smp_lock, flags);
3948 gdth_polling = TRUE;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003949 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 gdth_delay(0);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003951 if (gdth_internal_cmd(ha, CACHESERVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 GDT_CLUST_RESET, i, 0, 0))
3953 ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
3954 gdth_polling = FALSE;
3955 spin_unlock_irqrestore(&ha->smp_lock, flags);
3956 }
3957 }
3958 } else {
3959 /* raw devices */
3960 spin_lock_irqsave(&ha->smp_lock, flags);
3961 for (i = 0; i < MAXID; ++i)
3962 ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
3963 gdth_polling = TRUE;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003964 while (gdth_test_busy(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 gdth_delay(0);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003966 gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESET_BUS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 BUS_L2P(ha,b), 0, 0);
3968 gdth_polling = FALSE;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07003969 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 }
3971 return SUCCESS;
3972}
3973
8e879042005-04-17 15:28:39 -05003974static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975{
3976 unchar b, t;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003977 gdth_ha_str *ha = shost_priv(sdev->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 struct scsi_device *sd;
3979 unsigned capacity;
3980
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 sd = sdev;
3982 capacity = cap;
Christoph Hellwig52759e62007-10-02 22:59:53 +02003983 b = sd->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 t = sd->id;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02003985 TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", ha->hanum, b, t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986
3987 if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
3988 /* raw device or host drive without mapping information */
3989 TRACE2(("Evaluate mapping\n"));
3990 gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
3991 } else {
3992 ip[0] = ha->hdr[t].heads;
3993 ip[1] = ha->hdr[t].secs;
3994 ip[2] = capacity / ip[0] / ip[1];
3995 }
3996
3997 TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
3998 ip[0],ip[1],ip[2]));
3999 return 0;
4000}
4001
4002
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02004003static int gdth_queuecommand(struct scsi_cmnd *scp,
4004 void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005{
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004006 gdth_ha_str *ha = shost_priv(scp->device->host);
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02004007 struct gdth_cmndinfo *cmndinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008
4009 TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02004010
4011 cmndinfo = gdth_get_cmndinfo(ha);
4012 BUG_ON(!cmndinfo);
4013
Matthew Wilcoxb8bff2a2007-10-02 22:40:22 +02004014 scp->scsi_done = done;
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02004015 gdth_update_timeout(scp, scp->timeout_per_command * 6);
Boaz Harroshf842b642007-10-02 23:16:01 +02004016 cmndinfo->priority = DEFAULT_PRI;
Boaz Harrosh3892d882007-10-02 23:18:03 +02004017
4018 gdth_set_bufflen(scp, scsi_bufflen(scp));
4019 gdth_set_sg_count(scp, scsi_sg_count(scp));
4020 gdth_set_sglist(scp, scsi_sglist(scp));
4021
Boaz Harrosh3058d5d2007-10-02 23:14:39 +02004022 return __gdth_queuecommand(ha, scp, cmndinfo);
4023}
4024
4025static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
4026 struct gdth_cmndinfo *cmndinfo)
4027{
4028 scp->host_scribble = (unsigned char *)cmndinfo;
Boaz Harroshf842b642007-10-02 23:16:01 +02004029 cmndinfo->wait_for_completion = 1;
4030 cmndinfo->phase = -1;
4031 cmndinfo->OpCode = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033#ifdef GDTH_STATISTICS
4034 ++act_ios;
4035#endif
4036
Boaz Harroshf842b642007-10-02 23:16:01 +02004037 gdth_putq(ha, scp, cmndinfo->priority);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004038 gdth_next(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 return 0;
4040}
4041
4042
4043static int gdth_open(struct inode *inode, struct file *filep)
4044{
4045 gdth_ha_str *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004047 list_for_each_entry(ha, &gdth_instances, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 if (!ha->sdev)
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004049 ha->sdev = scsi_get_host_dev(ha->shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 }
4051
4052 TRACE(("gdth_open()\n"));
4053 return 0;
4054}
4055
4056static int gdth_close(struct inode *inode, struct file *filep)
4057{
4058 TRACE(("gdth_close()\n"));
4059 return 0;
4060}
4061
4062static int ioc_event(void __user *arg)
4063{
4064 gdth_ioctl_event evt;
4065 gdth_ha_str *ha;
4066 ulong flags;
4067
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004068 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004070 ha = gdth_find_ha(evt.ionode);
4071 if (!ha)
4072 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073
4074 if (evt.erase == 0xff) {
4075 if (evt.event.event_source == ES_TEST)
4076 evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
4077 else if (evt.event.event_source == ES_DRIVER)
4078 evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
4079 else if (evt.event.event_source == ES_SYNC)
4080 evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
4081 else
4082 evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
4083 spin_lock_irqsave(&ha->smp_lock, flags);
4084 gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
4085 &evt.event.event_data);
4086 spin_unlock_irqrestore(&ha->smp_lock, flags);
4087 } else if (evt.erase == 0xfe) {
4088 gdth_clear_events();
4089 } else if (evt.erase == 0) {
4090 evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
4091 } else {
4092 gdth_readapp_event(ha, evt.erase, &evt.event);
4093 }
4094 if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
4095 return -EFAULT;
4096 return 0;
4097}
4098
4099static int ioc_lockdrv(void __user *arg)
4100{
4101 gdth_ioctl_lockdrv ldrv;
4102 unchar i, j;
4103 ulong flags;
4104 gdth_ha_str *ha;
4105
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004106 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004108 ha = gdth_find_ha(ldrv.ionode);
4109 if (!ha)
4110 return -EFAULT;
4111
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
4113 j = ldrv.drives[i];
4114 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
4115 continue;
4116 if (ldrv.lock) {
4117 spin_lock_irqsave(&ha->smp_lock, flags);
4118 ha->hdr[j].lock = 1;
4119 spin_unlock_irqrestore(&ha->smp_lock, flags);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004120 gdth_wait_completion(ha, ha->bus_cnt, j);
4121 gdth_stop_timeout(ha, ha->bus_cnt, j);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 } else {
4123 spin_lock_irqsave(&ha->smp_lock, flags);
4124 ha->hdr[j].lock = 0;
4125 spin_unlock_irqrestore(&ha->smp_lock, flags);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004126 gdth_start_timeout(ha, ha->bus_cnt, j);
4127 gdth_next(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 }
4129 }
4130 return 0;
4131}
4132
4133static int ioc_resetdrv(void __user *arg, char *cmnd)
4134{
4135 gdth_ioctl_reset res;
4136 gdth_cmd_str cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 gdth_ha_str *ha;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004138 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
4140 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004141 res.number >= MAX_HDRIVES)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004143 ha = gdth_find_ha(res.ionode);
4144 if (!ha)
4145 return -EFAULT;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004146
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 if (!ha->hdr[res.number].present)
4148 return 0;
4149 memset(&cmd, 0, sizeof(gdth_cmd_str));
4150 cmd.Service = CACHESERVICE;
4151 cmd.OpCode = GDT_CLUST_RESET;
4152 if (ha->cache_feat & GDT_64BIT)
4153 cmd.u.cache64.DeviceNo = res.number;
4154 else
4155 cmd.u.cache.DeviceNo = res.number;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004156
4157 rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL);
4158 if (rval < 0)
4159 return rval;
4160 res.status = rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
4162 if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
4163 return -EFAULT;
4164 return 0;
4165}
4166
4167static int ioc_general(void __user *arg, char *cmnd)
4168{
4169 gdth_ioctl_general gen;
4170 char *buf = NULL;
4171 ulong64 paddr;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004172 gdth_ha_str *ha;
4173 int rval;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004174
4175 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004177 ha = gdth_find_ha(gen.ionode);
4178 if (!ha)
4179 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 if (gen.data_len + gen.sense_len != 0) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004181 if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 FALSE, &paddr)))
4183 return -EFAULT;
4184 if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
4185 gen.data_len + gen.sense_len)) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004186 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return -EFAULT;
4188 }
4189
4190 if (gen.command.OpCode == GDT_IOCTL) {
4191 gen.command.u.ioctl.p_param = paddr;
4192 } else if (gen.command.Service == CACHESERVICE) {
4193 if (ha->cache_feat & GDT_64BIT) {
4194 /* copy elements from 32-bit IOCTL structure */
4195 gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
4196 gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
4197 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
4198 /* addresses */
4199 if (ha->cache_feat & SCATTER_GATHER) {
4200 gen.command.u.cache64.DestAddr = (ulong64)-1;
4201 gen.command.u.cache64.sg_canz = 1;
4202 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
4203 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
4204 gen.command.u.cache64.sg_lst[1].sg_len = 0;
4205 } else {
4206 gen.command.u.cache64.DestAddr = paddr;
4207 gen.command.u.cache64.sg_canz = 0;
4208 }
4209 } else {
4210 if (ha->cache_feat & SCATTER_GATHER) {
4211 gen.command.u.cache.DestAddr = 0xffffffff;
4212 gen.command.u.cache.sg_canz = 1;
4213 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
4214 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
4215 gen.command.u.cache.sg_lst[1].sg_len = 0;
4216 } else {
4217 gen.command.u.cache.DestAddr = paddr;
4218 gen.command.u.cache.sg_canz = 0;
4219 }
4220 }
4221 } else if (gen.command.Service == SCSIRAWSERVICE) {
4222 if (ha->raw_feat & GDT_64BIT) {
4223 /* copy elements from 32-bit IOCTL structure */
4224 char cmd[16];
4225 gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
4226 gen.command.u.raw64.bus = gen.command.u.raw.bus;
4227 gen.command.u.raw64.lun = gen.command.u.raw.lun;
4228 gen.command.u.raw64.target = gen.command.u.raw.target;
4229 memcpy(cmd, gen.command.u.raw.cmd, 16);
4230 memcpy(gen.command.u.raw64.cmd, cmd, 16);
4231 gen.command.u.raw64.clen = gen.command.u.raw.clen;
4232 gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
4233 gen.command.u.raw64.direction = gen.command.u.raw.direction;
4234 /* addresses */
4235 if (ha->raw_feat & SCATTER_GATHER) {
4236 gen.command.u.raw64.sdata = (ulong64)-1;
4237 gen.command.u.raw64.sg_ranz = 1;
4238 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
4239 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
4240 gen.command.u.raw64.sg_lst[1].sg_len = 0;
4241 } else {
4242 gen.command.u.raw64.sdata = paddr;
4243 gen.command.u.raw64.sg_ranz = 0;
4244 }
4245 gen.command.u.raw64.sense_data = paddr + gen.data_len;
4246 } else {
4247 if (ha->raw_feat & SCATTER_GATHER) {
4248 gen.command.u.raw.sdata = 0xffffffff;
4249 gen.command.u.raw.sg_ranz = 1;
4250 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
4251 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
4252 gen.command.u.raw.sg_lst[1].sg_len = 0;
4253 } else {
4254 gen.command.u.raw.sdata = paddr;
4255 gen.command.u.raw.sg_ranz = 0;
4256 }
4257 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
4258 }
4259 } else {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004260 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 return -EFAULT;
4262 }
4263 }
4264
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004265 rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info);
4266 if (rval < 0)
4267 return rval;
4268 gen.status = rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269
4270 if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
4271 gen.data_len + gen.sense_len)) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004272 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 return -EFAULT;
4274 }
4275 if (copy_to_user(arg, &gen,
4276 sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004277 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 return -EFAULT;
4279 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004280 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 return 0;
4282}
4283
4284static int ioc_hdrlist(void __user *arg, char *cmnd)
4285{
4286 gdth_ioctl_rescan *rsc;
4287 gdth_cmd_str *cmd;
4288 gdth_ha_str *ha;
4289 unchar i;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004290 int rc = -ENOMEM;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004291 u32 cluster_type = 0;
4292
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4294 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4295 if (!rsc || !cmd)
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004296 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297
4298 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004299 (NULL == (ha = gdth_find_ha(rsc->ionode)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 rc = -EFAULT;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004301 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 memset(cmd, 0, sizeof(gdth_cmd_str));
4304
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 for (i = 0; i < MAX_HDRIVES; ++i) {
4306 if (!ha->hdr[i].present) {
4307 rsc->hdr_list[i].bus = 0xff;
4308 continue;
4309 }
4310 rsc->hdr_list[i].bus = ha->virt_bus;
4311 rsc->hdr_list[i].target = i;
4312 rsc->hdr_list[i].lun = 0;
4313 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4314 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
4315 cmd->Service = CACHESERVICE;
4316 cmd->OpCode = GDT_CLUST_INFO;
4317 if (ha->cache_feat & GDT_64BIT)
4318 cmd->u.cache64.DeviceNo = i;
4319 else
4320 cmd->u.cache.DeviceNo = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004321 if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK)
4322 rsc->hdr_list[i].cluster_type = cluster_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 }
4324 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004325
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4327 rc = -EFAULT;
4328 else
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004329 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
4331free_fail:
4332 kfree(rsc);
4333 kfree(cmd);
4334 return rc;
4335}
4336
4337static int ioc_rescan(void __user *arg, char *cmnd)
4338{
4339 gdth_ioctl_rescan *rsc;
4340 gdth_cmd_str *cmd;
4341 ushort i, status, hdr_cnt;
4342 ulong32 info;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004343 int cyls, hds, secs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 int rc = -ENOMEM;
4345 ulong flags;
4346 gdth_ha_str *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
4348 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
4349 cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
4350 if (!cmd || !rsc)
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004351 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352
4353 if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004354 (NULL == (ha = gdth_find_ha(rsc->ionode)))) {
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004355 rc = -EFAULT;
4356 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 memset(cmd, 0, sizeof(gdth_cmd_str));
4359
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 if (rsc->flag == 0) {
4361 /* old method: re-init. cache service */
4362 cmd->Service = CACHESERVICE;
4363 if (ha->cache_feat & GDT_64BIT) {
4364 cmd->OpCode = GDT_X_INIT_HOST;
4365 cmd->u.cache64.DeviceNo = LINUX_OS;
4366 } else {
4367 cmd->OpCode = GDT_INIT;
4368 cmd->u.cache.DeviceNo = LINUX_OS;
4369 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004370
4371 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 i = 0;
4373 hdr_cnt = (status == S_OK ? (ushort)info : 0);
4374 } else {
4375 i = rsc->hdr_no;
4376 hdr_cnt = i + 1;
4377 }
4378
4379 for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
4380 cmd->Service = CACHESERVICE;
4381 cmd->OpCode = GDT_INFO;
4382 if (ha->cache_feat & GDT_64BIT)
4383 cmd->u.cache64.DeviceNo = i;
4384 else
4385 cmd->u.cache.DeviceNo = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004386
4387 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4388
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 spin_lock_irqsave(&ha->smp_lock, flags);
4390 rsc->hdr_list[i].bus = ha->virt_bus;
4391 rsc->hdr_list[i].target = i;
4392 rsc->hdr_list[i].lun = 0;
4393 if (status != S_OK) {
4394 ha->hdr[i].present = FALSE;
4395 } else {
4396 ha->hdr[i].present = TRUE;
4397 ha->hdr[i].size = info;
4398 /* evaluate mapping */
4399 ha->hdr[i].size &= ~SECS32;
4400 gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
4401 ha->hdr[i].heads = hds;
4402 ha->hdr[i].secs = secs;
4403 /* round size */
4404 ha->hdr[i].size = cyls * hds * secs;
4405 }
4406 spin_unlock_irqrestore(&ha->smp_lock, flags);
4407 if (status != S_OK)
4408 continue;
4409
4410 /* extended info, if GDT_64BIT, for drives > 2 TB */
4411 /* but we need ha->info2, not yet stored in scp->SCp */
4412
4413 /* devtype, cluster info, R/W attribs */
4414 cmd->Service = CACHESERVICE;
4415 cmd->OpCode = GDT_DEVTYPE;
4416 if (ha->cache_feat & GDT_64BIT)
4417 cmd->u.cache64.DeviceNo = i;
4418 else
4419 cmd->u.cache.DeviceNo = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004420
4421 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4422
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 spin_lock_irqsave(&ha->smp_lock, flags);
4424 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
4425 spin_unlock_irqrestore(&ha->smp_lock, flags);
4426
4427 cmd->Service = CACHESERVICE;
4428 cmd->OpCode = GDT_CLUST_INFO;
4429 if (ha->cache_feat & GDT_64BIT)
4430 cmd->u.cache64.DeviceNo = i;
4431 else
4432 cmd->u.cache.DeviceNo = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004433
4434 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4435
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 spin_lock_irqsave(&ha->smp_lock, flags);
4437 ha->hdr[i].cluster_type =
4438 ((status == S_OK && !shared_access) ? (ushort)info : 0);
4439 spin_unlock_irqrestore(&ha->smp_lock, flags);
4440 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4441
4442 cmd->Service = CACHESERVICE;
4443 cmd->OpCode = GDT_RW_ATTRIBS;
4444 if (ha->cache_feat & GDT_64BIT)
4445 cmd->u.cache64.DeviceNo = i;
4446 else
4447 cmd->u.cache.DeviceNo = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004448
4449 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4450
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 spin_lock_irqsave(&ha->smp_lock, flags);
4452 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
4453 spin_unlock_irqrestore(&ha->smp_lock, flags);
4454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
4456 if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
4457 rc = -EFAULT;
4458 else
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004459 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
4461free_fail:
4462 kfree(rsc);
4463 kfree(cmd);
4464 return rc;
4465}
4466
4467static int gdth_ioctl(struct inode *inode, struct file *filep,
4468 unsigned int cmd, unsigned long arg)
4469{
4470 gdth_ha_str *ha;
4471 Scsi_Cmnd *scp;
4472 ulong flags;
4473 char cmnd[MAX_COMMAND_SIZE];
4474 void __user *argp = (void __user *)arg;
4475
4476 memset(cmnd, 0xff, 12);
4477
4478 TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
4479
4480 switch (cmd) {
4481 case GDTIOCTL_CTRCNT:
4482 {
4483 int cnt = gdth_ctr_count;
4484 if (put_user(cnt, (int __user *)argp))
4485 return -EFAULT;
4486 break;
4487 }
4488
4489 case GDTIOCTL_DRVERS:
4490 {
4491 int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
4492 if (put_user(ver, (int __user *)argp))
4493 return -EFAULT;
4494 break;
4495 }
4496
4497 case GDTIOCTL_OSVERS:
4498 {
4499 gdth_ioctl_osvers osv;
4500
4501 osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
4502 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
4503 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
4504 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
4505 return -EFAULT;
4506 break;
4507 }
4508
4509 case GDTIOCTL_CTRTYPE:
4510 {
4511 gdth_ioctl_ctrtype ctrt;
4512
4513 if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004514 (NULL == (ha = gdth_find_ha(ctrt.ionode))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004516
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
4518 ctrt.type = (unchar)((ha->stype>>20) - 0x10);
4519 } else {
4520 if (ha->type != GDT_PCIMPR) {
4521 ctrt.type = (unchar)((ha->stype<<4) + 6);
4522 } else {
4523 ctrt.type =
4524 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
4525 if (ha->stype >= 0x300)
Jeff Garzik8e9a8a02007-07-17 05:25:17 -04004526 ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 else
4528 ctrt.ext_type = 0x6000 | ha->stype;
4529 }
Jeff Garzik8e9a8a02007-07-17 05:25:17 -04004530 ctrt.device_id = ha->pdev->device;
4531 ctrt.sub_device_id = ha->pdev->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 }
4533 ctrt.info = ha->brd_phys;
4534 ctrt.oem_id = ha->oem_id;
4535 if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
4536 return -EFAULT;
4537 break;
4538 }
4539
4540 case GDTIOCTL_GENERAL:
4541 return ioc_general(argp, cmnd);
4542
4543 case GDTIOCTL_EVENT:
4544 return ioc_event(argp);
4545
4546 case GDTIOCTL_LOCKDRV:
4547 return ioc_lockdrv(argp);
4548
4549 case GDTIOCTL_LOCKCHN:
4550 {
4551 gdth_ioctl_lockchn lchn;
4552 unchar i, j;
4553
4554 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004555 (NULL == (ha = gdth_find_ha(lchn.ionode))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 return -EFAULT;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004557
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 i = lchn.channel;
4559 if (i < ha->bus_cnt) {
4560 if (lchn.lock) {
4561 spin_lock_irqsave(&ha->smp_lock, flags);
4562 ha->raw[i].lock = 1;
4563 spin_unlock_irqrestore(&ha->smp_lock, flags);
4564 for (j = 0; j < ha->tid_cnt; ++j) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004565 gdth_wait_completion(ha, i, j);
4566 gdth_stop_timeout(ha, i, j);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 }
4568 } else {
4569 spin_lock_irqsave(&ha->smp_lock, flags);
4570 ha->raw[i].lock = 0;
4571 spin_unlock_irqrestore(&ha->smp_lock, flags);
4572 for (j = 0; j < ha->tid_cnt; ++j) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004573 gdth_start_timeout(ha, i, j);
4574 gdth_next(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 }
4576 }
4577 }
4578 break;
4579 }
4580
4581 case GDTIOCTL_RESCAN:
4582 return ioc_rescan(argp, cmnd);
4583
4584 case GDTIOCTL_HDRLIST:
4585 return ioc_hdrlist(argp, cmnd);
4586
4587 case GDTIOCTL_RESET_BUS:
4588 {
4589 gdth_ioctl_reset res;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004590 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591
4592 if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004593 (NULL == (ha = gdth_find_ha(res.ionode))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004596 scp = kzalloc(sizeof(*scp), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 if (!scp)
4598 return -ENOMEM;
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004599 scp->device = ha->sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 scp->cmd_len = 12;
Christoph Hellwig52759e62007-10-02 22:59:53 +02004601 scp->device->channel = res.number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 rval = gdth_eh_bus_reset(scp);
4603 res.status = (rval == SUCCESS ? S_OK : S_GENERR);
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004604 kfree(scp);
Jeff Garzik8d7a5da2007-10-02 22:54:28 +02004605
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
4607 return -EFAULT;
4608 break;
4609 }
4610
4611 case GDTIOCTL_RESET_DRV:
4612 return ioc_resetdrv(argp, cmnd);
4613
4614 default:
4615 break;
4616 }
4617 return 0;
4618}
4619
4620
4621/* flush routine */
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004622static void gdth_flush(gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623{
4624 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 gdth_cmd_str gdtcmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 char cmnd[MAX_COMMAND_SIZE];
4627 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
4628
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004629 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 for (i = 0; i < MAX_HDRIVES; ++i) {
4632 if (ha->hdr[i].present) {
4633 gdtcmd.BoardNode = LOCALBOARD;
4634 gdtcmd.Service = CACHESERVICE;
4635 gdtcmd.OpCode = GDT_FLUSH;
4636 if (ha->cache_feat & GDT_64BIT) {
4637 gdtcmd.u.cache64.DeviceNo = i;
4638 gdtcmd.u.cache64.BlockNo = 1;
4639 gdtcmd.u.cache64.sg_canz = 0;
4640 } else {
4641 gdtcmd.u.cache.DeviceNo = i;
4642 gdtcmd.u.cache.BlockNo = 1;
4643 gdtcmd.u.cache.sg_canz = 0;
4644 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004645 TRACE2(("gdth_flush(): flush ha %d drive %d\n", ha->hanum, i));
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004646
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004647 gdth_execute(ha->shost, &gdtcmd, cmnd, 30, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 }
4649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650}
4651
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004652/* configure lun */
4653static int gdth_slave_configure(struct scsi_device *sdev)
4654{
4655 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4656 sdev->skip_ms_page_3f = 1;
4657 sdev->skip_ms_page_8 = 1;
4658 return 0;
4659}
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004660
Christoph Hellwig835cc242007-10-02 23:09:56 +02004661static struct scsi_host_template gdth_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 .name = "GDT SCSI Disk Array Controller",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 .info = gdth_info,
4664 .queuecommand = gdth_queuecommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 .eh_bus_reset_handler = gdth_eh_bus_reset,
Leubner, Achimcbd5f692006-06-09 11:34:29 -07004666 .slave_configure = gdth_slave_configure,
Jeff Garzik69916b72007-10-02 22:57:58 +02004667 .bios_param = gdth_bios_param,
4668 .proc_info = gdth_proc_info,
4669 .proc_name = "gdth",
4670 .can_queue = GDTH_MAXCMDS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 .this_id = -1,
4672 .sg_tablesize = GDTH_MAXSG,
4673 .cmd_per_lun = GDTH_MAXC_P_L,
4674 .unchecked_isa_dma = 1,
4675 .use_clustering = ENABLE_CLUSTERING,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676};
4677
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004678#ifdef CONFIG_ISA
Adrian Bunk05dd7ed2007-10-18 12:51:05 +02004679static int __init gdth_isa_probe_one(ulong32 isa_bios)
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004680{
4681 struct Scsi_Host *shp;
4682 gdth_ha_str *ha;
4683 dma_addr_t scratch_dma_handle = 0;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004684 int error, i;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004685
4686 if (!gdth_search_isa(isa_bios))
4687 return -ENXIO;
4688
Christoph Hellwig835cc242007-10-02 23:09:56 +02004689 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004690 if (!shp)
4691 return -ENOMEM;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004692 ha = shost_priv(shp);
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004693
4694 error = -ENODEV;
4695 if (!gdth_init_isa(isa_bios,ha))
4696 goto out_host_put;
4697
4698 /* controller found and initialized */
4699 printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
4700 isa_bios, ha->irq, ha->drq);
4701
4702 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
4703 if (error) {
4704 printk("GDT-ISA: Unable to allocate IRQ\n");
4705 goto out_host_put;
4706 }
4707
4708 error = request_dma(ha->drq, "gdth");
4709 if (error) {
4710 printk("GDT-ISA: Unable to allocate DMA channel\n");
4711 goto out_free_irq;
4712 }
4713
4714 set_dma_mode(ha->drq,DMA_MODE_CASCADE);
4715 enable_dma(ha->drq);
4716 shp->unchecked_isa_dma = 1;
4717 shp->irq = ha->irq;
4718 shp->dma_channel = ha->drq;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004719
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004720 ha->hanum = gdth_ctr_count++;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004721 ha->shost = shp;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004722
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004723 ha->pccb = &ha->cmdext;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004724 ha->ccb_phys = 0L;
4725 ha->pdev = NULL;
4726
4727 error = -ENOMEM;
4728
4729 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4730 &scratch_dma_handle);
4731 if (!ha->pscratch)
4732 goto out_dec_counters;
4733 ha->scratch_phys = scratch_dma_handle;
4734
4735 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4736 &scratch_dma_handle);
4737 if (!ha->pmsg)
4738 goto out_free_pscratch;
4739 ha->msg_phys = scratch_dma_handle;
4740
4741#ifdef INT_COAL
4742 ha->coal_stat = pci_alloc_consistent(ha->pdev,
4743 sizeof(gdth_coal_status) * MAXOFFSETS,
4744 &scratch_dma_handle);
4745 if (!ha->coal_stat)
4746 goto out_free_pmsg;
4747 ha->coal_stat_phys = scratch_dma_handle;
4748#endif
4749
4750 ha->scratch_busy = FALSE;
4751 ha->req_first = NULL;
4752 ha->tid_cnt = MAX_HDRIVES;
4753 if (max_ids > 0 && max_ids < ha->tid_cnt)
4754 ha->tid_cnt = max_ids;
4755 for (i = 0; i < GDTH_MAXCMDS; ++i)
4756 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4757 ha->scan_mode = rescan ? 0x10 : 0;
4758
4759 error = -ENODEV;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004760 if (!gdth_search_drives(ha)) {
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004761 printk("GDT-ISA: Error during device scan\n");
4762 goto out_free_coal_stat;
4763 }
4764
4765 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4766 hdr_channel = ha->bus_cnt;
4767 ha->virt_bus = hdr_channel;
4768
4769 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4770 shp->max_cmd_len = 16;
4771
4772 shp->max_id = ha->tid_cnt;
4773 shp->max_lun = MAXLUN;
Christoph Hellwig52759e62007-10-02 22:59:53 +02004774 shp->max_channel = ha->bus_cnt;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004775
4776 spin_lock_init(&ha->smp_lock);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004777 gdth_enable_int(ha);
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004778
Christoph Hellwig835cc242007-10-02 23:09:56 +02004779 error = scsi_add_host(shp, NULL);
4780 if (error)
4781 goto out_free_coal_stat;
4782 list_add_tail(&ha->list, &gdth_instances);
Boaz Harrosh61c92812008-02-12 19:35:22 +02004783
4784 scsi_scan_host(shp);
4785
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004786 return 0;
4787
4788 out_free_coal_stat:
4789#ifdef INT_COAL
4790 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
4791 ha->coal_stat, ha->coal_stat_phys);
4792 out_free_pmsg:
4793#endif
4794 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4795 ha->pmsg, ha->msg_phys);
4796 out_free_pscratch:
4797 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4798 ha->pscratch, ha->scratch_phys);
4799 out_dec_counters:
4800 gdth_ctr_count--;
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004801 out_free_irq:
4802 free_irq(ha->irq, ha);
4803 out_host_put:
Christoph Hellwig835cc242007-10-02 23:09:56 +02004804 scsi_host_put(shp);
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004805 return error;
4806}
4807#endif /* CONFIG_ISA */
4808
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004809#ifdef CONFIG_EISA
Adrian Bunk05dd7ed2007-10-18 12:51:05 +02004810static int __init gdth_eisa_probe_one(ushort eisa_slot)
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004811{
4812 struct Scsi_Host *shp;
4813 gdth_ha_str *ha;
4814 dma_addr_t scratch_dma_handle = 0;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004815 int error, i;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004816
4817 if (!gdth_search_eisa(eisa_slot))
4818 return -ENXIO;
4819
Christoph Hellwig835cc242007-10-02 23:09:56 +02004820 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004821 if (!shp)
4822 return -ENOMEM;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004823 ha = shost_priv(shp);
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004824
4825 error = -ENODEV;
4826 if (!gdth_init_eisa(eisa_slot,ha))
4827 goto out_host_put;
4828
4829 /* controller found and initialized */
4830 printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
4831 eisa_slot >> 12, ha->irq);
4832
4833 error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha);
4834 if (error) {
4835 printk("GDT-EISA: Unable to allocate IRQ\n");
4836 goto out_host_put;
4837 }
4838
4839 shp->unchecked_isa_dma = 0;
4840 shp->irq = ha->irq;
4841 shp->dma_channel = 0xff;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004842
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004843 ha->hanum = gdth_ctr_count++;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004844 ha->shost = shp;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004845
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004846 TRACE2(("EISA detect Bus 0: hanum %d\n", ha->hanum));
4847
4848 ha->pccb = &ha->cmdext;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004849 ha->ccb_phys = 0L;
4850
4851 error = -ENOMEM;
4852
4853 ha->pdev = NULL;
4854 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4855 &scratch_dma_handle);
4856 if (!ha->pscratch)
4857 goto out_free_irq;
4858 ha->scratch_phys = scratch_dma_handle;
4859
4860 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4861 &scratch_dma_handle);
4862 if (!ha->pmsg)
4863 goto out_free_pscratch;
4864 ha->msg_phys = scratch_dma_handle;
4865
4866#ifdef INT_COAL
4867 ha->coal_stat = pci_alloc_consistent(ha->pdev,
4868 sizeof(gdth_coal_status) * MAXOFFSETS,
4869 &scratch_dma_handle);
4870 if (!ha->coal_stat)
4871 goto out_free_pmsg;
4872 ha->coal_stat_phys = scratch_dma_handle;
4873#endif
4874
4875 ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb,
4876 sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL);
4877 if (!ha->ccb_phys)
4878 goto out_free_coal_stat;
4879
4880 ha->scratch_busy = FALSE;
4881 ha->req_first = NULL;
4882 ha->tid_cnt = MAX_HDRIVES;
4883 if (max_ids > 0 && max_ids < ha->tid_cnt)
4884 ha->tid_cnt = max_ids;
4885 for (i = 0; i < GDTH_MAXCMDS; ++i)
4886 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4887 ha->scan_mode = rescan ? 0x10 : 0;
4888
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004889 if (!gdth_search_drives(ha)) {
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004890 printk("GDT-EISA: Error during device scan\n");
4891 error = -ENODEV;
4892 goto out_free_ccb_phys;
4893 }
4894
4895 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4896 hdr_channel = ha->bus_cnt;
4897 ha->virt_bus = hdr_channel;
4898
4899 if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
4900 shp->max_cmd_len = 16;
4901
4902 shp->max_id = ha->tid_cnt;
4903 shp->max_lun = MAXLUN;
Christoph Hellwig52759e62007-10-02 22:59:53 +02004904 shp->max_channel = ha->bus_cnt;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004905
4906 spin_lock_init(&ha->smp_lock);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004907 gdth_enable_int(ha);
Christoph Hellwig835cc242007-10-02 23:09:56 +02004908
4909 error = scsi_add_host(shp, NULL);
4910 if (error)
4911 goto out_free_coal_stat;
4912 list_add_tail(&ha->list, &gdth_instances);
Boaz Harrosh61c92812008-02-12 19:35:22 +02004913
4914 scsi_scan_host(shp);
4915
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004916 return 0;
4917
4918 out_free_ccb_phys:
4919 pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str),
4920 PCI_DMA_BIDIRECTIONAL);
4921 out_free_coal_stat:
4922#ifdef INT_COAL
4923 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
4924 ha->coal_stat, ha->coal_stat_phys);
4925 out_free_pmsg:
4926#endif
4927 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4928 ha->pmsg, ha->msg_phys);
4929 out_free_pscratch:
4930 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4931 ha->pscratch, ha->scratch_phys);
4932 out_free_irq:
4933 free_irq(ha->irq, ha);
4934 gdth_ctr_count--;
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004935 out_host_put:
Christoph Hellwig835cc242007-10-02 23:09:56 +02004936 scsi_host_put(shp);
Christoph Hellwig706a5d42007-10-02 22:49:35 +02004937 return error;
4938}
4939#endif /* CONFIG_EISA */
Christoph Hellwigaed91cb2007-10-02 22:48:16 +02004940
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004941#ifdef CONFIG_PCI
Jeff Garzikcff26802008-02-15 22:20:09 -05004942static int gdth_pci_probe_one(gdth_pci_str *pcistr,
4943 gdth_ha_str **ha_out)
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004944{
4945 struct Scsi_Host *shp;
4946 gdth_ha_str *ha;
4947 dma_addr_t scratch_dma_handle = 0;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004948 int error, i;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05004949 struct pci_dev *pdev = pcistr->pdev;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004950
Jeff Garzikcff26802008-02-15 22:20:09 -05004951 *ha_out = NULL;
4952
Christoph Hellwig835cc242007-10-02 23:09:56 +02004953 shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str));
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004954 if (!shp)
4955 return -ENOMEM;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004956 ha = shost_priv(shp);
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004957
4958 error = -ENODEV;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05004959 if (!gdth_init_pci(pdev, pcistr, ha))
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004960 goto out_host_put;
4961
4962 /* controller found and initialized */
4963 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05004964 pdev->bus->number,
4965 PCI_SLOT(pdev->devfn),
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004966 ha->irq);
4967
4968 error = request_irq(ha->irq, gdth_interrupt,
4969 IRQF_DISABLED|IRQF_SHARED, "gdth", ha);
4970 if (error) {
4971 printk("GDT-PCI: Unable to allocate IRQ\n");
4972 goto out_host_put;
4973 }
4974
4975 shp->unchecked_isa_dma = 0;
4976 shp->irq = ha->irq;
4977 shp->dma_channel = 0xff;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004978
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02004979 ha->hanum = gdth_ctr_count++;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004980 ha->shost = shp;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004981
Boaz Harrosh45f1a412007-10-02 23:05:53 +02004982 ha->pccb = &ha->cmdext;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02004983 ha->ccb_phys = 0L;
4984
4985 error = -ENOMEM;
4986
4987 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4988 &scratch_dma_handle);
4989 if (!ha->pscratch)
4990 goto out_free_irq;
4991 ha->scratch_phys = scratch_dma_handle;
4992
4993 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4994 &scratch_dma_handle);
4995 if (!ha->pmsg)
4996 goto out_free_pscratch;
4997 ha->msg_phys = scratch_dma_handle;
4998
4999#ifdef INT_COAL
5000 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5001 sizeof(gdth_coal_status) * MAXOFFSETS,
5002 &scratch_dma_handle);
5003 if (!ha->coal_stat)
5004 goto out_free_pmsg;
5005 ha->coal_stat_phys = scratch_dma_handle;
5006#endif
5007
5008 ha->scratch_busy = FALSE;
5009 ha->req_first = NULL;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05005010 ha->tid_cnt = pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005011 if (max_ids > 0 && max_ids < ha->tid_cnt)
5012 ha->tid_cnt = max_ids;
5013 for (i = 0; i < GDTH_MAXCMDS; ++i)
5014 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5015 ha->scan_mode = rescan ? 0x10 : 0;
5016
5017 error = -ENODEV;
Boaz Harrosh45f1a412007-10-02 23:05:53 +02005018 if (!gdth_search_drives(ha)) {
5019 printk("GDT-PCI %d: Error during device scan\n", ha->hanum);
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005020 goto out_free_coal_stat;
5021 }
5022
5023 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5024 hdr_channel = ha->bus_cnt;
5025 ha->virt_bus = hdr_channel;
5026
5027 /* 64-bit DMA only supported from FW >= x.43 */
5028 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
5029 !ha->dma64_support) {
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05005030 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005031 printk(KERN_WARNING "GDT-PCI %d: "
Boaz Harrosh45f1a412007-10-02 23:05:53 +02005032 "Unable to set 32-bit DMA\n", ha->hanum);
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005033 goto out_free_coal_stat;
5034 }
5035 } else {
5036 shp->max_cmd_len = 16;
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05005037 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +02005038 printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum);
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05005039 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005040 printk(KERN_WARNING "GDT-PCI %d: "
Boaz Harrosh45f1a412007-10-02 23:05:53 +02005041 "Unable to set 64/32-bit DMA\n", ha->hanum);
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005042 goto out_free_coal_stat;
5043 }
5044 }
5045
5046 shp->max_id = ha->tid_cnt;
5047 shp->max_lun = MAXLUN;
Christoph Hellwig52759e62007-10-02 22:59:53 +02005048 shp->max_channel = ha->bus_cnt;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005049
5050 spin_lock_init(&ha->smp_lock);
Boaz Harrosh45f1a412007-10-02 23:05:53 +02005051 gdth_enable_int(ha);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005052
Jeff Garzik4c9c8d72008-02-15 21:35:26 -05005053 error = scsi_add_host(shp, &pdev->dev);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005054 if (error)
5055 goto out_free_coal_stat;
5056 list_add_tail(&ha->list, &gdth_instances);
Boaz Harrosh61c92812008-02-12 19:35:22 +02005057
Jeff Garzikcff26802008-02-15 22:20:09 -05005058 pci_set_drvdata(ha->pdev, ha);
5059
Boaz Harrosh61c92812008-02-12 19:35:22 +02005060 scsi_scan_host(shp);
5061
Jeff Garzikcff26802008-02-15 22:20:09 -05005062 *ha_out = ha;
5063
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005064 return 0;
5065
5066 out_free_coal_stat:
5067#ifdef INT_COAL
5068 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5069 ha->coal_stat, ha->coal_stat_phys);
5070 out_free_pmsg:
5071#endif
5072 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5073 ha->pmsg, ha->msg_phys);
5074 out_free_pscratch:
5075 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5076 ha->pscratch, ha->scratch_phys);
5077 out_free_irq:
5078 free_irq(ha->irq, ha);
5079 gdth_ctr_count--;
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005080 out_host_put:
Christoph Hellwig835cc242007-10-02 23:09:56 +02005081 scsi_host_put(shp);
Christoph Hellwig8514ef22007-10-02 22:51:06 +02005082 return error;
5083}
5084#endif /* CONFIG_PCI */
5085
Christoph Hellwig835cc242007-10-02 23:09:56 +02005086static void gdth_remove_one(gdth_ha_str *ha)
5087{
5088 struct Scsi_Host *shp = ha->shost;
5089
5090 TRACE2(("gdth_remove_one()\n"));
5091
5092 scsi_remove_host(shp);
5093
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005094 gdth_flush(ha);
5095
Christoph Hellwig835cc242007-10-02 23:09:56 +02005096 if (ha->sdev) {
5097 scsi_free_host_dev(ha->sdev);
5098 ha->sdev = NULL;
5099 }
5100
Christoph Hellwig835cc242007-10-02 23:09:56 +02005101 if (shp->irq)
5102 free_irq(shp->irq,ha);
5103
5104#ifdef CONFIG_ISA
5105 if (shp->dma_channel != 0xff)
5106 free_dma(shp->dma_channel);
5107#endif
5108#ifdef INT_COAL
5109 if (ha->coal_stat)
5110 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
5111 MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
5112#endif
5113 if (ha->pscratch)
5114 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5115 ha->pscratch, ha->scratch_phys);
5116 if (ha->pmsg)
5117 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5118 ha->pmsg, ha->msg_phys);
5119 if (ha->ccb_phys)
5120 pci_unmap_single(ha->pdev,ha->ccb_phys,
5121 sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
5122
5123 scsi_host_put(shp);
5124}
5125
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005126static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
5127{
5128 gdth_ha_str *ha;
5129
5130 TRACE2(("gdth_halt() event %d\n", (int)event));
5131 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
5132 return NOTIFY_DONE;
5133
5134 list_for_each_entry(ha, &gdth_instances, list)
5135 gdth_flush(ha);
5136
5137 return NOTIFY_OK;
5138}
5139
5140static struct notifier_block gdth_notifier = {
5141 gdth_halt, NULL, 0
5142};
5143
Christoph Hellwig835cc242007-10-02 23:09:56 +02005144static int __init gdth_init(void)
5145{
5146 if (disable) {
5147 printk("GDT-HA: Controller driver disabled from"
5148 " command line !\n");
5149 return 0;
5150 }
5151
5152 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",
5153 GDTH_VERSION_STR);
5154
5155 /* initializations */
5156 gdth_polling = TRUE;
5157 gdth_clear_events();
5158
5159 /* As default we do not probe for EISA or ISA controllers */
5160 if (probe_eisa_isa) {
5161 /* scanning for controllers, at first: ISA controller */
5162#ifdef CONFIG_ISA
5163 ulong32 isa_bios;
5164 for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02005165 isa_bios += 0x8000UL)
Christoph Hellwig835cc242007-10-02 23:09:56 +02005166 gdth_isa_probe_one(isa_bios);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005167#endif
5168#ifdef CONFIG_EISA
5169 {
5170 ushort eisa_slot;
5171 for (eisa_slot = 0x1000; eisa_slot <= 0x8000;
Boaz Harrosh884f7fb2007-10-02 23:11:24 +02005172 eisa_slot += 0x1000)
Christoph Hellwig835cc242007-10-02 23:09:56 +02005173 gdth_eisa_probe_one(eisa_slot);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005174 }
5175#endif
5176 }
5177
5178#ifdef CONFIG_PCI
5179 /* scanning for PCI controllers */
Jeff Garzikcff26802008-02-15 22:20:09 -05005180 if (pci_register_driver(&gdth_pci_driver) == 0)
5181 gdth_pci_registered = true;
Christoph Hellwig835cc242007-10-02 23:09:56 +02005182#endif /* CONFIG_PCI */
5183
5184 TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count));
Linus Torvaldsc596cc42007-10-15 12:46:16 -07005185
5186 if (list_empty(&gdth_instances))
5187 return -ENODEV;
5188
Christoph Hellwig835cc242007-10-02 23:09:56 +02005189#ifdef GDTH_STATISTICS
5190 TRACE2(("gdth_detect(): Initializing timer !\n"));
5191 init_timer(&gdth_timer);
5192 gdth_timer.expires = jiffies + HZ;
5193 gdth_timer.data = 0L;
5194 gdth_timer.function = gdth_timeout;
5195 add_timer(&gdth_timer);
5196#endif
5197 major = register_chrdev(0,"gdth", &gdth_fops);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005198 register_reboot_notifier(&gdth_notifier);
5199 gdth_polling = FALSE;
5200 return 0;
5201}
5202
5203static void __exit gdth_exit(void)
5204{
5205 gdth_ha_str *ha;
5206
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005207 unregister_chrdev(major, "gdth");
5208 unregister_reboot_notifier(&gdth_notifier);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005209
5210#ifdef GDTH_STATISTICS
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005211 del_timer_sync(&gdth_timer);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005212#endif
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005213
Jeff Garzikcff26802008-02-15 22:20:09 -05005214#ifdef CONFIG_PCI
5215 if (gdth_pci_registered)
5216 pci_unregister_driver(&gdth_pci_driver);
5217#endif
5218
Boaz Harroshb31ddd32008-02-27 15:27:16 -08005219 list_for_each_entry(ha, &gdth_instances, list)
5220 gdth_remove_one(ha);
Christoph Hellwig835cc242007-10-02 23:09:56 +02005221}
5222
5223module_init(gdth_init);
5224module_exit(gdth_exit);
5225
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226#ifndef MODULE
5227__setup("gdth=", option_setup);
5228#endif