]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /************************************************************************ |
2 | * Linux driver for * | |
3 | * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers * | |
4 | * Intel Corporation: Storage RAID Controllers * | |
5 | * * | |
6 | * gdth.c * | |
cbd5f69b | 7 | * Copyright (C) 1995-06 ICP vortex GmbH, Achim Leubner * |
1da177e4 | 8 | * Copyright (C) 2002-04 Intel Corporation * |
cbd5f69b | 9 | * Copyright (C) 2003-06 Adaptec Inc. * |
1da177e4 LT |
10 | * <[email protected]> * |
11 | * * | |
12 | * Additions/Fixes: * | |
13 | * Boji Tony Kannanthanam <[email protected]> * | |
14 | * Johannes Dinner <[email protected]> * | |
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 | * * | |
8d7a5da4 | 30 | * Linux kernel 2.6.x supported * |
1da177e4 | 31 | * * |
1da177e4 LT |
32 | ************************************************************************/ |
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 | |
1da177e4 LT |
59 | * 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, | |
575c9687 | 62 | * appropriate controller firmware required |
1da177e4 LT |
63 | * 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, | |
52759e6a | 70 | * max_ids:127,rescan:N,hdr_channel:0, |
1da177e4 LT |
71 | * 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 | |
52759e6a | 81 | * max_ids=127 rescan=0 hdr_channel=0 shared_access=0 |
1da177e4 LT |
82 | * 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 | |
d35055a0 BH |
88 | * this_residual: unused |
89 | * buffer: unused | |
3892d88a | 90 | * dma_handle: unused |
d35055a0 | 91 | * buffers_residual: unused |
3892d88a | 92 | * Status: unused |
f842b64e BH |
93 | * Message: unused |
94 | * have_data_in: unused | |
95 | * sent_command: unused | |
96 | * phase: unused | |
1da177e4 LT |
97 | */ |
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> | |
1da177e4 LT |
116 | #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> | |
910638ae | 121 | #include <linux/dma-mapping.h> |
835cc24a | 122 | #include <linux/list.h> |
46787b48 | 123 | #include <linux/smp_lock.h> |
cbd5f69b | 124 | |
1da177e4 LT |
125 | #ifdef GDTH_RTC |
126 | #include <linux/mc146818rtc.h> | |
127 | #endif | |
128 | #include <linux/reboot.h> | |
129 | ||
130 | #include <asm/dma.h> | |
131 | #include <asm/system.h> | |
132 | #include <asm/io.h> | |
133 | #include <asm/uaccess.h> | |
134 | #include <linux/spinlock.h> | |
1da177e4 | 135 | #include <linux/blkdev.h> |
3892d88a | 136 | #include <linux/scatterlist.h> |
1da177e4 LT |
137 | |
138 | #include "scsi.h" | |
139 | #include <scsi/scsi_host.h> | |
cbd5f69b | 140 | #include "gdth.h" |
1da177e4 LT |
141 | |
142 | static void gdth_delay(int milliseconds); | |
1fe6dbf4 | 143 | static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs); |
7d12e780 | 144 | static irqreturn_t gdth_interrupt(int irq, void *dev_id); |
230e886e | 145 | static irqreturn_t __gdth_interrupt(gdth_ha_str *ha, |
10e1b4bc | 146 | int gdth_from_wait, int* pIndex); |
1fe6dbf4 | 147 | static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index, |
45f1a41b BH |
148 | Scsi_Cmnd *scp); |
149 | static int gdth_async_event(gdth_ha_str *ha); | |
1da177e4 LT |
150 | static void gdth_log_event(gdth_evt_data *dvr, char *buffer); |
151 | ||
1fe6dbf4 | 152 | static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 priority); |
45f1a41b | 153 | static void gdth_next(gdth_ha_str *ha); |
1fe6dbf4 | 154 | static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 b); |
45f1a41b | 155 | static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); |
1fe6dbf4 DJ |
156 | static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, u16 source, |
157 | u16 idx, gdth_evt_data *evt); | |
1da177e4 | 158 | static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr); |
1fe6dbf4 | 159 | static void gdth_readapp_event(gdth_ha_str *ha, u8 application, |
1da177e4 LT |
160 | gdth_evt_str *estr); |
161 | static void gdth_clear_events(void); | |
162 | ||
45f1a41b | 163 | static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, |
1fe6dbf4 | 164 | char *buffer, u16 count); |
45f1a41b | 165 | static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); |
1fe6dbf4 | 166 | static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u16 hdrive); |
1da177e4 | 167 | |
45f1a41b | 168 | static void gdth_enable_int(gdth_ha_str *ha); |
45f1a41b BH |
169 | static int gdth_test_busy(gdth_ha_str *ha); |
170 | static int gdth_get_cmd_index(gdth_ha_str *ha); | |
171 | static void gdth_release_event(gdth_ha_str *ha); | |
1fe6dbf4 DJ |
172 | static int gdth_wait(gdth_ha_str *ha, int index,u32 time); |
173 | static int gdth_internal_cmd(gdth_ha_str *ha, u8 service, u16 opcode, | |
174 | u32 p1, u64 p2,u64 p3); | |
45f1a41b | 175 | static int gdth_search_drives(gdth_ha_str *ha); |
1fe6dbf4 | 176 | static int gdth_analyse_hdrive(gdth_ha_str *ha, u16 hdrive); |
1da177e4 | 177 | |
45f1a41b | 178 | static const char *gdth_ctr_name(gdth_ha_str *ha); |
1da177e4 LT |
179 | |
180 | static int gdth_open(struct inode *inode, struct file *filep); | |
181 | static int gdth_close(struct inode *inode, struct file *filep); | |
182 | static int gdth_ioctl(struct inode *inode, struct file *filep, | |
183 | unsigned int cmd, unsigned long arg); | |
184 | ||
45f1a41b | 185 | static void gdth_flush(gdth_ha_str *ha); |
cbd5f69b | 186 | static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *)); |
3058d5de BH |
187 | static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, |
188 | struct gdth_cmndinfo *cmndinfo); | |
cbd5f69b | 189 | static void gdth_scsi_done(struct scsi_cmnd *scp); |
1da177e4 LT |
190 | |
191 | #ifdef DEBUG_GDTH | |
1fe6dbf4 | 192 | static u8 DebugState = DEBUG_GDTH; |
1da177e4 LT |
193 | |
194 | #ifdef __SERIAL__ | |
195 | #define MAX_SERBUF 160 | |
196 | static void ser_init(void); | |
197 | static void ser_puts(char *str); | |
198 | static void ser_putc(char c); | |
199 | static int ser_printk(const char *fmt, ...); | |
200 | static char strbuf[MAX_SERBUF+1]; | |
201 | #ifdef __COM2__ | |
202 | #define COM_BASE 0x2f8 | |
203 | #else | |
204 | #define COM_BASE 0x3f8 | |
205 | #endif | |
206 | static void ser_init() | |
207 | { | |
208 | unsigned port=COM_BASE; | |
209 | ||
210 | outb(0x80,port+3); | |
211 | outb(0,port+1); | |
212 | /* 19200 Baud, if 9600: outb(12,port) */ | |
213 | outb(6, port); | |
214 | outb(3,port+3); | |
215 | outb(0,port+1); | |
216 | /* | |
217 | ser_putc('I'); | |
218 | ser_putc(' '); | |
219 | */ | |
220 | } | |
221 | ||
222 | static void ser_puts(char *str) | |
223 | { | |
224 | char *ptr; | |
225 | ||
226 | ser_init(); | |
227 | for (ptr=str;*ptr;++ptr) | |
228 | ser_putc(*ptr); | |
229 | } | |
230 | ||
231 | static void ser_putc(char c) | |
232 | { | |
233 | unsigned port=COM_BASE; | |
234 | ||
235 | while ((inb(port+5) & 0x20)==0); | |
236 | outb(c,port); | |
237 | if (c==0x0a) | |
238 | { | |
239 | while ((inb(port+5) & 0x20)==0); | |
240 | outb(0x0d,port); | |
241 | } | |
242 | } | |
243 | ||
244 | static int ser_printk(const char *fmt, ...) | |
245 | { | |
246 | va_list args; | |
247 | int i; | |
248 | ||
249 | va_start(args,fmt); | |
250 | i = vsprintf(strbuf,fmt,args); | |
251 | ser_puts(strbuf); | |
252 | va_end(args); | |
253 | return i; | |
254 | } | |
255 | ||
256 | #define TRACE(a) {if (DebugState==1) {ser_printk a;}} | |
257 | #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}} | |
258 | #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}} | |
259 | ||
260 | #else /* !__SERIAL__ */ | |
261 | #define TRACE(a) {if (DebugState==1) {printk a;}} | |
262 | #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}} | |
263 | #define TRACE3(a) {if (DebugState!=0) {printk a;}} | |
264 | #endif | |
265 | ||
266 | #else /* !DEBUG */ | |
267 | #define TRACE(a) | |
268 | #define TRACE2(a) | |
269 | #define TRACE3(a) | |
270 | #endif | |
271 | ||
272 | #ifdef GDTH_STATISTICS | |
1fe6dbf4 | 273 | static u32 max_rq=0, max_index=0, max_sg=0; |
1da177e4 | 274 | #ifdef INT_COAL |
1fe6dbf4 | 275 | static u32 max_int_coal=0; |
1da177e4 | 276 | #endif |
1fe6dbf4 | 277 | static u32 act_ints=0, act_ios=0, act_stats=0, act_rq=0; |
1da177e4 LT |
278 | static struct timer_list gdth_timer; |
279 | #endif | |
280 | ||
1fe6dbf4 | 281 | #define PTR2USHORT(a) (u16)(unsigned long)(a) |
6391a113 TK |
282 | #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b) |
283 | #define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t)) | |
1da177e4 | 284 | |
1da177e4 LT |
285 | #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b)) |
286 | ||
aed91cb5 | 287 | #ifdef CONFIG_ISA |
1fe6dbf4 | 288 | static u8 gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */ |
aed91cb5 | 289 | #endif |
c8e91b0a | 290 | #if defined(CONFIG_EISA) || defined(CONFIG_ISA) |
1fe6dbf4 | 291 | static u8 gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */ |
706a5d45 | 292 | #endif |
1fe6dbf4 | 293 | static u8 gdth_polling; /* polling if TRUE */ |
1da177e4 | 294 | static int gdth_ctr_count = 0; /* controller count */ |
884f7fba | 295 | static LIST_HEAD(gdth_instances); /* controller list */ |
1fe6dbf4 | 296 | static u8 gdth_write_through = FALSE; /* write through */ |
1da177e4 LT |
297 | static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */ |
298 | static int elastidx; | |
299 | static int eoldidx; | |
300 | static int major; | |
301 | ||
302 | #define DIN 1 /* IN data direction */ | |
303 | #define DOU 2 /* OUT data direction */ | |
304 | #define DNO DIN /* no data transfer */ | |
305 | #define DUN DIN /* unknown data direction */ | |
1fe6dbf4 | 306 | static u8 gdth_direction_tab[0x100] = { |
1da177e4 LT |
307 | DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN, |
308 | DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN, | |
309 | DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU, | |
310 | DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU, | |
311 | DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN, | |
312 | DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,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,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, | |
315 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN, | |
316 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN, | |
317 | DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU, | |
318 | DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, | |
319 | DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, | |
320 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN, | |
321 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN, | |
322 | DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN | |
323 | }; | |
324 | ||
325 | /* LILO and modprobe/insmod parameters */ | |
326 | /* IRQ list for GDT3000/3020 EISA controllers */ | |
327 | static int irq[MAXHA] __initdata = | |
328 | {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, | |
329 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; | |
330 | /* disable driver flag */ | |
331 | static int disable __initdata = 0; | |
332 | /* reserve flag */ | |
333 | static int reserve_mode = 1; | |
334 | /* reserve list */ | |
335 | static int reserve_list[MAX_RES_ARGS] = | |
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,0xff,0xff, | |
338 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; | |
339 | /* scan order for PCI controllers */ | |
340 | static int reverse_scan = 0; | |
341 | /* virtual channel for the host drives */ | |
342 | static int hdr_channel = 0; | |
343 | /* max. IDs per channel */ | |
344 | static int max_ids = MAXID; | |
345 | /* rescan all IDs */ | |
346 | static int rescan = 0; | |
1da177e4 LT |
347 | /* shared access */ |
348 | static int shared_access = 1; | |
349 | /* enable support for EISA and ISA controllers */ | |
350 | static int probe_eisa_isa = 0; | |
351 | /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */ | |
352 | static int force_dma32 = 0; | |
353 | ||
354 | /* parameters for modprobe/insmod */ | |
355 | module_param_array(irq, int, NULL, 0); | |
356 | module_param(disable, int, 0); | |
357 | module_param(reserve_mode, int, 0); | |
358 | module_param_array(reserve_list, int, NULL, 0); | |
359 | module_param(reverse_scan, int, 0); | |
360 | module_param(hdr_channel, int, 0); | |
361 | module_param(max_ids, int, 0); | |
362 | module_param(rescan, int, 0); | |
1da177e4 LT |
363 | module_param(shared_access, int, 0); |
364 | module_param(probe_eisa_isa, int, 0); | |
365 | module_param(force_dma32, int, 0); | |
366 | MODULE_AUTHOR("Achim Leubner"); | |
367 | MODULE_LICENSE("GPL"); | |
368 | ||
369 | /* ioctl interface */ | |
00977a59 | 370 | static const struct file_operations gdth_fops = { |
1da177e4 LT |
371 | .ioctl = gdth_ioctl, |
372 | .open = gdth_open, | |
373 | .release = gdth_close, | |
374 | }; | |
375 | ||
376 | #include "gdth_proc.h" | |
377 | #include "gdth_proc.c" | |
378 | ||
884f7fba BH |
379 | static gdth_ha_str *gdth_find_ha(int hanum) |
380 | { | |
381 | gdth_ha_str *ha; | |
382 | ||
383 | list_for_each_entry(ha, &gdth_instances, list) | |
384 | if (hanum == ha->hanum) | |
385 | return ha; | |
386 | ||
387 | return NULL; | |
388 | } | |
389 | ||
3058d5de BH |
390 | static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha) |
391 | { | |
392 | struct gdth_cmndinfo *priv = NULL; | |
1fe6dbf4 | 393 | unsigned long flags; |
3058d5de BH |
394 | int i; |
395 | ||
396 | spin_lock_irqsave(&ha->smp_lock, flags); | |
397 | ||
398 | for (i=0; i<GDTH_MAXCMDS; ++i) { | |
399 | if (ha->cmndinfo[i].index == 0) { | |
400 | priv = &ha->cmndinfo[i]; | |
3058d5de | 401 | memset(priv, 0, sizeof(*priv)); |
ee54cc6a | 402 | priv->index = i+1; |
3058d5de BH |
403 | break; |
404 | } | |
405 | } | |
406 | ||
407 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
408 | ||
409 | return priv; | |
410 | } | |
411 | ||
412 | static void gdth_put_cmndinfo(struct gdth_cmndinfo *priv) | |
413 | { | |
414 | BUG_ON(!priv); | |
415 | priv->index = 0; | |
416 | } | |
417 | ||
1da177e4 LT |
418 | static void gdth_delay(int milliseconds) |
419 | { | |
420 | if (milliseconds == 0) { | |
421 | udelay(1); | |
422 | } else { | |
423 | mdelay(milliseconds); | |
424 | } | |
425 | } | |
426 | ||
cbd5f69b LA |
427 | static void gdth_scsi_done(struct scsi_cmnd *scp) |
428 | { | |
3058d5de BH |
429 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
430 | int internal_command = cmndinfo->internal_command; | |
431 | ||
b8bff2ae | 432 | TRACE2(("gdth_scsi_done()\n")); |
cbd5f69b | 433 | |
3058d5de BH |
434 | gdth_put_cmndinfo(cmndinfo); |
435 | scp->host_scribble = NULL; | |
436 | ||
437 | if (internal_command) | |
b8bff2ae MW |
438 | complete((struct completion *)scp->request); |
439 | else | |
440 | scp->scsi_done(scp); | |
cbd5f69b LA |
441 | } |
442 | ||
443 | int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd, | |
444 | int timeout, u32 *info) | |
445 | { | |
3058d5de | 446 | gdth_ha_str *ha = shost_priv(sdev->host); |
cbd5f69b | 447 | Scsi_Cmnd *scp; |
3058d5de | 448 | struct gdth_cmndinfo cmndinfo; |
6e9a4738 | 449 | DECLARE_COMPLETION_ONSTACK(wait); |
cbd5f69b LA |
450 | int rval; |
451 | ||
bbfbbbc1 | 452 | scp = kzalloc(sizeof(*scp), GFP_KERNEL); |
cbd5f69b LA |
453 | if (!scp) |
454 | return -ENOMEM; | |
bbfbbbc1 | 455 | |
1b96f895 SS |
456 | scp->sense_buffer = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); |
457 | if (!scp->sense_buffer) { | |
458 | kfree(scp); | |
459 | return -ENOMEM; | |
460 | } | |
461 | ||
cbd5f69b | 462 | scp->device = sdev; |
3058d5de BH |
463 | memset(&cmndinfo, 0, sizeof(cmndinfo)); |
464 | ||
beb40487 CH |
465 | /* use request field to save the ptr. to completion struct. */ |
466 | scp->request = (struct request *)&wait; | |
cbd5f69b | 467 | scp->cmd_len = 12; |
64a87b24 | 468 | scp->cmnd = cmnd; |
f842b64e | 469 | cmndinfo.priority = IOCTL_PRI; |
ee54cc6a | 470 | cmndinfo.internal_cmd_str = gdtcmd; |
3058d5de BH |
471 | cmndinfo.internal_command = 1; |
472 | ||
473 | TRACE(("__gdth_execute() cmd 0x%x\n", scp->cmnd[0])); | |
474 | __gdth_queuecommand(ha, scp, &cmndinfo); | |
475 | ||
cbd5f69b LA |
476 | wait_for_completion(&wait); |
477 | ||
f842b64e | 478 | rval = cmndinfo.status; |
cbd5f69b | 479 | if (info) |
f842b64e | 480 | *info = cmndinfo.info; |
1b96f895 | 481 | kfree(scp->sense_buffer); |
cbd5f69b LA |
482 | kfree(scp); |
483 | return rval; | |
484 | } | |
cbd5f69b LA |
485 | |
486 | int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd, | |
487 | int timeout, u32 *info) | |
488 | { | |
489 | struct scsi_device *sdev = scsi_get_host_dev(shost); | |
490 | int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info); | |
491 | ||
492 | scsi_free_host_dev(sdev); | |
493 | return rval; | |
494 | } | |
495 | ||
1fe6dbf4 | 496 | static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs) |
1da177e4 LT |
497 | { |
498 | *cyls = size /HEADS/SECS; | |
499 | if (*cyls <= MAXCYLS) { | |
500 | *heads = HEADS; | |
501 | *secs = SECS; | |
502 | } else { /* too high for 64*32 */ | |
503 | *cyls = size /MEDHEADS/MEDSECS; | |
504 | if (*cyls <= MAXCYLS) { | |
505 | *heads = MEDHEADS; | |
506 | *secs = MEDSECS; | |
507 | } else { /* too high for 127*63 */ | |
508 | *cyls = size /BIGHEADS/BIGSECS; | |
509 | *heads = BIGHEADS; | |
510 | *secs = BIGSECS; | |
511 | } | |
512 | } | |
513 | } | |
514 | ||
515 | /* controller search and initialization functions */ | |
706a5d45 | 516 | #ifdef CONFIG_EISA |
1fe6dbf4 | 517 | static int __init gdth_search_eisa(u16 eisa_adr) |
1da177e4 | 518 | { |
1fe6dbf4 | 519 | u32 id; |
1da177e4 LT |
520 | |
521 | TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr)); | |
522 | id = inl(eisa_adr+ID0REG); | |
523 | if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */ | |
524 | if ((inb(eisa_adr+EISAREG) & 8) == 0) | |
525 | return 0; /* not EISA configured */ | |
526 | return 1; | |
527 | } | |
528 | if (id == GDT3_ID) /* GDT3000 */ | |
529 | return 1; | |
530 | ||
531 | return 0; | |
532 | } | |
706a5d45 | 533 | #endif /* CONFIG_EISA */ |
1da177e4 | 534 | |
aed91cb5 | 535 | #ifdef CONFIG_ISA |
1fe6dbf4 | 536 | static int __init gdth_search_isa(u32 bios_adr) |
1da177e4 LT |
537 | { |
538 | void __iomem *addr; | |
1fe6dbf4 | 539 | u32 id; |
1da177e4 LT |
540 | |
541 | TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr)); | |
1fe6dbf4 | 542 | if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(u32))) != NULL) { |
a52667f3 | 543 | id = readl(addr); |
1da177e4 LT |
544 | iounmap(addr); |
545 | if (id == GDT2_ID) /* GDT2000 */ | |
546 | return 1; | |
547 | } | |
548 | return 0; | |
549 | } | |
aed91cb5 | 550 | #endif /* CONFIG_ISA */ |
1da177e4 | 551 | |
8514ef27 | 552 | #ifdef CONFIG_PCI |
8514ef27 | 553 | |
1fe6dbf4 | 554 | static bool gdth_search_vortex(u16 device) |
1da177e4 | 555 | { |
cff26806 JG |
556 | if (device <= PCI_DEVICE_ID_VORTEX_GDT6555) |
557 | return true; | |
558 | if (device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP && | |
559 | device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP) | |
560 | return true; | |
561 | if (device == PCI_DEVICE_ID_VORTEX_GDTNEWRX || | |
562 | device == PCI_DEVICE_ID_VORTEX_GDTNEWRX2) | |
563 | return true; | |
564 | return false; | |
1da177e4 LT |
565 | } |
566 | ||
cff26806 JG |
567 | static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out); |
568 | static int gdth_pci_init_one(struct pci_dev *pdev, | |
569 | const struct pci_device_id *ent); | |
570 | static void gdth_pci_remove_one(struct pci_dev *pdev); | |
571 | static void gdth_remove_one(gdth_ha_str *ha); | |
572 | ||
1da177e4 LT |
573 | /* Vortex only makes RAID controllers. |
574 | * We do not really want to specify all 550 ids here, so wildcard match. | |
575 | */ | |
cff26806 JG |
576 | static const struct pci_device_id gdthtable[] = { |
577 | { PCI_VDEVICE(VORTEX, PCI_ANY_ID) }, | |
578 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC) }, | |
579 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SRC_XSCALE) }, | |
580 | { } /* terminate list */ | |
1da177e4 | 581 | }; |
cff26806 | 582 | MODULE_DEVICE_TABLE(pci, gdthtable); |
1da177e4 | 583 | |
cff26806 JG |
584 | static struct pci_driver gdth_pci_driver = { |
585 | .name = "gdth", | |
586 | .id_table = gdthtable, | |
587 | .probe = gdth_pci_init_one, | |
588 | .remove = gdth_pci_remove_one, | |
589 | }; | |
590 | ||
ced7172a | 591 | static void __devexit gdth_pci_remove_one(struct pci_dev *pdev) |
1da177e4 | 592 | { |
cff26806 JG |
593 | gdth_ha_str *ha = pci_get_drvdata(pdev); |
594 | ||
595 | pci_set_drvdata(pdev, NULL); | |
596 | ||
597 | list_del(&ha->list); | |
598 | gdth_remove_one(ha); | |
599 | ||
600 | pci_disable_device(pdev); | |
601 | } | |
602 | ||
ced7172a | 603 | static int __devinit gdth_pci_init_one(struct pci_dev *pdev, |
cff26806 JG |
604 | const struct pci_device_id *ent) |
605 | { | |
1fe6dbf4 DJ |
606 | u16 vendor = pdev->vendor; |
607 | u16 device = pdev->device; | |
608 | unsigned long base0, base1, base2; | |
cff26806 JG |
609 | int rc; |
610 | gdth_pci_str gdth_pcistr; | |
611 | gdth_ha_str *ha = NULL; | |
1da177e4 | 612 | |
cff26806 JG |
613 | TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n", |
614 | gdth_ctr_count, vendor, device)); | |
1da177e4 | 615 | |
cff26806 JG |
616 | memset(&gdth_pcistr, 0, sizeof(gdth_pcistr)); |
617 | ||
618 | if (vendor == PCI_VENDOR_ID_VORTEX && !gdth_search_vortex(device)) | |
619 | return -ENODEV; | |
620 | ||
621 | rc = pci_enable_device(pdev); | |
622 | if (rc) | |
623 | return rc; | |
624 | ||
625 | if (gdth_ctr_count >= MAXHA) | |
626 | return -EBUSY; | |
99109301 | 627 | |
1da177e4 | 628 | /* GDT PCI controller found, resources are already in pdev */ |
cff26806 | 629 | gdth_pcistr.pdev = pdev; |
1da177e4 LT |
630 | base0 = pci_resource_flags(pdev, 0); |
631 | base1 = pci_resource_flags(pdev, 1); | |
632 | base2 = pci_resource_flags(pdev, 2); | |
633 | if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */ | |
634 | device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */ | |
635 | if (!(base0 & IORESOURCE_MEM)) | |
cff26806 JG |
636 | return -ENODEV; |
637 | gdth_pcistr.dpmem = pci_resource_start(pdev, 0); | |
1da177e4 LT |
638 | } else { /* GDT6110, GDT6120, .. */ |
639 | if (!(base0 & IORESOURCE_MEM) || | |
640 | !(base2 & IORESOURCE_MEM) || | |
641 | !(base1 & IORESOURCE_IO)) | |
cff26806 JG |
642 | return -ENODEV; |
643 | gdth_pcistr.dpmem = pci_resource_start(pdev, 2); | |
644 | gdth_pcistr.io = pci_resource_start(pdev, 1); | |
1da177e4 LT |
645 | } |
646 | TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n", | |
cff26806 JG |
647 | gdth_pcistr.pdev->bus->number, |
648 | PCI_SLOT(gdth_pcistr.pdev->devfn), | |
649 | gdth_pcistr.irq, | |
650 | gdth_pcistr.dpmem)); | |
1da177e4 | 651 | |
cff26806 JG |
652 | rc = gdth_pci_probe_one(&gdth_pcistr, &ha); |
653 | if (rc) | |
654 | return rc; | |
1da177e4 | 655 | |
cff26806 | 656 | return 0; |
1da177e4 | 657 | } |
8514ef27 | 658 | #endif /* CONFIG_PCI */ |
1da177e4 | 659 | |
706a5d45 | 660 | #ifdef CONFIG_EISA |
1fe6dbf4 | 661 | static int __init gdth_init_eisa(u16 eisa_adr,gdth_ha_str *ha) |
1da177e4 | 662 | { |
1fe6dbf4 DJ |
663 | u32 retries,id; |
664 | u8 prot_ver,eisacf,i,irq_found; | |
1da177e4 LT |
665 | |
666 | TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr)); | |
667 | ||
668 | /* disable board interrupts, deinitialize services */ | |
669 | outb(0xff,eisa_adr+EDOORREG); | |
670 | outb(0x00,eisa_adr+EDENABREG); | |
671 | outb(0x00,eisa_adr+EINTENABREG); | |
672 | ||
673 | outb(0xff,eisa_adr+LDOORREG); | |
674 | retries = INIT_RETRIES; | |
675 | gdth_delay(20); | |
676 | while (inb(eisa_adr+EDOORREG) != 0xff) { | |
677 | if (--retries == 0) { | |
678 | printk("GDT-EISA: Initialization error (DEINIT failed)\n"); | |
679 | return 0; | |
680 | } | |
681 | gdth_delay(1); | |
682 | TRACE2(("wait for DEINIT: retries=%d\n",retries)); | |
683 | } | |
684 | prot_ver = inb(eisa_adr+MAILBOXREG); | |
685 | outb(0xff,eisa_adr+EDOORREG); | |
686 | if (prot_ver != PROTOCOL_VERSION) { | |
687 | printk("GDT-EISA: Illegal protocol version\n"); | |
688 | return 0; | |
689 | } | |
690 | ha->bmic = eisa_adr; | |
1fe6dbf4 | 691 | ha->brd_phys = (u32)eisa_adr >> 12; |
1da177e4 LT |
692 | |
693 | outl(0,eisa_adr+MAILBOXREG); | |
694 | outl(0,eisa_adr+MAILBOXREG+4); | |
695 | outl(0,eisa_adr+MAILBOXREG+8); | |
696 | outl(0,eisa_adr+MAILBOXREG+12); | |
697 | ||
698 | /* detect IRQ */ | |
699 | if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) { | |
700 | ha->oem_id = OEM_ID_ICP; | |
701 | ha->type = GDT_EISA; | |
702 | ha->stype = id; | |
703 | outl(1,eisa_adr+MAILBOXREG+8); | |
704 | outb(0xfe,eisa_adr+LDOORREG); | |
705 | retries = INIT_RETRIES; | |
706 | gdth_delay(20); | |
707 | while (inb(eisa_adr+EDOORREG) != 0xfe) { | |
708 | if (--retries == 0) { | |
709 | printk("GDT-EISA: Initialization error (get IRQ failed)\n"); | |
710 | return 0; | |
711 | } | |
712 | gdth_delay(1); | |
713 | } | |
714 | ha->irq = inb(eisa_adr+MAILBOXREG); | |
715 | outb(0xff,eisa_adr+EDOORREG); | |
716 | TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq)); | |
717 | /* check the result */ | |
718 | if (ha->irq == 0) { | |
719 | TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n")); | |
720 | for (i = 0, irq_found = FALSE; | |
721 | i < MAXHA && irq[i] != 0xff; ++i) { | |
722 | if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) { | |
723 | irq_found = TRUE; | |
724 | break; | |
725 | } | |
726 | } | |
727 | if (irq_found) { | |
728 | ha->irq = irq[i]; | |
729 | irq[i] = 0; | |
730 | printk("GDT-EISA: Can not detect controller IRQ,\n"); | |
731 | printk("Use IRQ setting from command line (IRQ = %d)\n", | |
732 | ha->irq); | |
733 | } else { | |
734 | printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n"); | |
735 | printk("the controller BIOS or use command line parameters\n"); | |
736 | return 0; | |
737 | } | |
738 | } | |
739 | } else { | |
740 | eisacf = inb(eisa_adr+EISAREG) & 7; | |
741 | if (eisacf > 4) /* level triggered */ | |
742 | eisacf -= 4; | |
743 | ha->irq = gdth_irq_tab[eisacf]; | |
744 | ha->oem_id = OEM_ID_ICP; | |
745 | ha->type = GDT_EISA; | |
746 | ha->stype = id; | |
747 | } | |
748 | ||
749 | ha->dma64_support = 0; | |
750 | return 1; | |
751 | } | |
706a5d45 | 752 | #endif /* CONFIG_EISA */ |
1da177e4 | 753 | |
aed91cb5 | 754 | #ifdef CONFIG_ISA |
1fe6dbf4 | 755 | static int __init gdth_init_isa(u32 bios_adr,gdth_ha_str *ha) |
1da177e4 LT |
756 | { |
757 | register gdt2_dpram_str __iomem *dp2_ptr; | |
758 | int i; | |
1fe6dbf4 DJ |
759 | u8 irq_drq,prot_ver; |
760 | u32 retries; | |
1da177e4 LT |
761 | |
762 | TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr)); | |
763 | ||
764 | ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str)); | |
765 | if (ha->brd == NULL) { | |
766 | printk("GDT-ISA: Initialization error (DPMEM remap error)\n"); | |
767 | return 0; | |
768 | } | |
769 | dp2_ptr = ha->brd; | |
a52667f3 | 770 | writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */ |
1da177e4 LT |
771 | /* reset interface area */ |
772 | memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u)); | |
a52667f3 | 773 | if (readl(&dp2_ptr->u) != 0) { |
1da177e4 LT |
774 | printk("GDT-ISA: Initialization error (DPMEM write error)\n"); |
775 | iounmap(ha->brd); | |
776 | return 0; | |
777 | } | |
778 | ||
779 | /* disable board interrupts, read DRQ and IRQ */ | |
a52667f3 JG |
780 | writeb(0xff, &dp2_ptr->io.irqdel); |
781 | writeb(0x00, &dp2_ptr->io.irqen); | |
782 | writeb(0x00, &dp2_ptr->u.ic.S_Status); | |
783 | writeb(0x00, &dp2_ptr->u.ic.Cmd_Index); | |
1da177e4 | 784 | |
a52667f3 | 785 | irq_drq = readb(&dp2_ptr->io.rq); |
1da177e4 LT |
786 | for (i=0; i<3; ++i) { |
787 | if ((irq_drq & 1)==0) | |
788 | break; | |
789 | irq_drq >>= 1; | |
790 | } | |
791 | ha->drq = gdth_drq_tab[i]; | |
792 | ||
a52667f3 | 793 | irq_drq = readb(&dp2_ptr->io.rq) >> 3; |
1da177e4 LT |
794 | for (i=1; i<5; ++i) { |
795 | if ((irq_drq & 1)==0) | |
796 | break; | |
797 | irq_drq >>= 1; | |
798 | } | |
799 | ha->irq = gdth_irq_tab[i]; | |
800 | ||
801 | /* deinitialize services */ | |
a52667f3 JG |
802 | writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]); |
803 | writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx); | |
804 | writeb(0, &dp2_ptr->io.event); | |
1da177e4 LT |
805 | retries = INIT_RETRIES; |
806 | gdth_delay(20); | |
a52667f3 | 807 | while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) { |
1da177e4 LT |
808 | if (--retries == 0) { |
809 | printk("GDT-ISA: Initialization error (DEINIT failed)\n"); | |
810 | iounmap(ha->brd); | |
811 | return 0; | |
812 | } | |
813 | gdth_delay(1); | |
814 | } | |
1fe6dbf4 | 815 | prot_ver = (u8)readl(&dp2_ptr->u.ic.S_Info[0]); |
a52667f3 JG |
816 | writeb(0, &dp2_ptr->u.ic.Status); |
817 | writeb(0xff, &dp2_ptr->io.irqdel); | |
1da177e4 LT |
818 | if (prot_ver != PROTOCOL_VERSION) { |
819 | printk("GDT-ISA: Illegal protocol version\n"); | |
820 | iounmap(ha->brd); | |
821 | return 0; | |
822 | } | |
823 | ||
824 | ha->oem_id = OEM_ID_ICP; | |
825 | ha->type = GDT_ISA; | |
826 | ha->ic_all_size = sizeof(dp2_ptr->u); | |
827 | ha->stype= GDT2_ID; | |
828 | ha->brd_phys = bios_adr >> 4; | |
829 | ||
830 | /* special request to controller BIOS */ | |
a52667f3 JG |
831 | writel(0x00, &dp2_ptr->u.ic.S_Info[0]); |
832 | writel(0x00, &dp2_ptr->u.ic.S_Info[1]); | |
833 | writel(0x01, &dp2_ptr->u.ic.S_Info[2]); | |
834 | writel(0x00, &dp2_ptr->u.ic.S_Info[3]); | |
835 | writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx); | |
836 | writeb(0, &dp2_ptr->io.event); | |
1da177e4 LT |
837 | retries = INIT_RETRIES; |
838 | gdth_delay(20); | |
a52667f3 | 839 | while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) { |
1da177e4 LT |
840 | if (--retries == 0) { |
841 | printk("GDT-ISA: Initialization error\n"); | |
842 | iounmap(ha->brd); | |
843 | return 0; | |
844 | } | |
845 | gdth_delay(1); | |
846 | } | |
a52667f3 JG |
847 | writeb(0, &dp2_ptr->u.ic.Status); |
848 | writeb(0xff, &dp2_ptr->io.irqdel); | |
1da177e4 LT |
849 | |
850 | ha->dma64_support = 0; | |
851 | return 1; | |
852 | } | |
aed91cb5 | 853 | #endif /* CONFIG_ISA */ |
1da177e4 | 854 | |
8514ef27 | 855 | #ifdef CONFIG_PCI |
ced7172a | 856 | static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr, |
cff26806 | 857 | gdth_ha_str *ha) |
1da177e4 LT |
858 | { |
859 | register gdt6_dpram_str __iomem *dp6_ptr; | |
860 | register gdt6c_dpram_str __iomem *dp6c_ptr; | |
861 | register gdt6m_dpram_str __iomem *dp6m_ptr; | |
1fe6dbf4 DJ |
862 | u32 retries; |
863 | u8 prot_ver; | |
864 | u16 command; | |
1da177e4 LT |
865 | int i, found = FALSE; |
866 | ||
867 | TRACE(("gdth_init_pci()\n")); | |
868 | ||
4c9c8d78 | 869 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) |
1da177e4 LT |
870 | ha->oem_id = OEM_ID_INTEL; |
871 | else | |
872 | ha->oem_id = OEM_ID_ICP; | |
4c9c8d78 | 873 | ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8); |
1fe6dbf4 | 874 | ha->stype = (u32)pdev->device; |
4c9c8d78 JG |
875 | ha->irq = pdev->irq; |
876 | ha->pdev = pdev; | |
1da177e4 | 877 | |
8e9a8a0d | 878 | if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */ |
1da177e4 LT |
879 | TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq)); |
880 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str)); | |
881 | if (ha->brd == NULL) { | |
882 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
883 | return 0; | |
884 | } | |
885 | /* check and reset interface area */ | |
886 | dp6_ptr = ha->brd; | |
a52667f3 JG |
887 | writel(DPMEM_MAGIC, &dp6_ptr->u); |
888 | if (readl(&dp6_ptr->u) != DPMEM_MAGIC) { | |
1da177e4 LT |
889 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
890 | pcistr->dpmem); | |
891 | found = FALSE; | |
892 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { | |
893 | iounmap(ha->brd); | |
1fe6dbf4 | 894 | ha->brd = ioremap(i, sizeof(u16)); |
1da177e4 LT |
895 | if (ha->brd == NULL) { |
896 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
897 | return 0; | |
898 | } | |
a52667f3 | 899 | if (readw(ha->brd) != 0xffff) { |
1da177e4 LT |
900 | TRACE2(("init_pci_old() address 0x%x busy\n", i)); |
901 | continue; | |
902 | } | |
903 | iounmap(ha->brd); | |
4c9c8d78 | 904 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i); |
1da177e4 LT |
905 | ha->brd = ioremap(i, sizeof(gdt6_dpram_str)); |
906 | if (ha->brd == NULL) { | |
907 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
908 | return 0; | |
909 | } | |
910 | dp6_ptr = ha->brd; | |
a52667f3 JG |
911 | writel(DPMEM_MAGIC, &dp6_ptr->u); |
912 | if (readl(&dp6_ptr->u) == DPMEM_MAGIC) { | |
1da177e4 LT |
913 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
914 | found = TRUE; | |
915 | break; | |
916 | } | |
917 | } | |
918 | if (!found) { | |
919 | printk("GDT-PCI: No free address found!\n"); | |
920 | iounmap(ha->brd); | |
921 | return 0; | |
922 | } | |
923 | } | |
924 | memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u)); | |
a52667f3 | 925 | if (readl(&dp6_ptr->u) != 0) { |
1da177e4 LT |
926 | printk("GDT-PCI: Initialization error (DPMEM write error)\n"); |
927 | iounmap(ha->brd); | |
928 | return 0; | |
929 | } | |
930 | ||
931 | /* disable board interrupts, deinit services */ | |
a52667f3 JG |
932 | writeb(0xff, &dp6_ptr->io.irqdel); |
933 | writeb(0x00, &dp6_ptr->io.irqen); | |
934 | writeb(0x00, &dp6_ptr->u.ic.S_Status); | |
935 | writeb(0x00, &dp6_ptr->u.ic.Cmd_Index); | |
936 | ||
937 | writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]); | |
938 | writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx); | |
939 | writeb(0, &dp6_ptr->io.event); | |
1da177e4 LT |
940 | retries = INIT_RETRIES; |
941 | gdth_delay(20); | |
a52667f3 | 942 | while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) { |
1da177e4 LT |
943 | if (--retries == 0) { |
944 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); | |
945 | iounmap(ha->brd); | |
946 | return 0; | |
947 | } | |
948 | gdth_delay(1); | |
949 | } | |
1fe6dbf4 | 950 | prot_ver = (u8)readl(&dp6_ptr->u.ic.S_Info[0]); |
a52667f3 JG |
951 | writeb(0, &dp6_ptr->u.ic.S_Status); |
952 | writeb(0xff, &dp6_ptr->io.irqdel); | |
1da177e4 LT |
953 | if (prot_ver != PROTOCOL_VERSION) { |
954 | printk("GDT-PCI: Illegal protocol version\n"); | |
955 | iounmap(ha->brd); | |
956 | return 0; | |
957 | } | |
958 | ||
959 | ha->type = GDT_PCI; | |
960 | ha->ic_all_size = sizeof(dp6_ptr->u); | |
961 | ||
962 | /* special command to controller BIOS */ | |
a52667f3 JG |
963 | writel(0x00, &dp6_ptr->u.ic.S_Info[0]); |
964 | writel(0x00, &dp6_ptr->u.ic.S_Info[1]); | |
965 | writel(0x00, &dp6_ptr->u.ic.S_Info[2]); | |
966 | writel(0x00, &dp6_ptr->u.ic.S_Info[3]); | |
967 | writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx); | |
968 | writeb(0, &dp6_ptr->io.event); | |
1da177e4 LT |
969 | retries = INIT_RETRIES; |
970 | gdth_delay(20); | |
a52667f3 | 971 | while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) { |
1da177e4 LT |
972 | if (--retries == 0) { |
973 | printk("GDT-PCI: Initialization error\n"); | |
974 | iounmap(ha->brd); | |
975 | return 0; | |
976 | } | |
977 | gdth_delay(1); | |
978 | } | |
a52667f3 JG |
979 | writeb(0, &dp6_ptr->u.ic.S_Status); |
980 | writeb(0xff, &dp6_ptr->io.irqdel); | |
1da177e4 LT |
981 | |
982 | ha->dma64_support = 0; | |
983 | ||
8e9a8a0d | 984 | } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */ |
1da177e4 LT |
985 | ha->plx = (gdt6c_plx_regs *)pcistr->io; |
986 | TRACE2(("init_pci_new() dpmem %lx irq %d\n", | |
987 | pcistr->dpmem,ha->irq)); | |
988 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str)); | |
989 | if (ha->brd == NULL) { | |
990 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
991 | iounmap(ha->brd); | |
992 | return 0; | |
993 | } | |
994 | /* check and reset interface area */ | |
995 | dp6c_ptr = ha->brd; | |
a52667f3 JG |
996 | writel(DPMEM_MAGIC, &dp6c_ptr->u); |
997 | if (readl(&dp6c_ptr->u) != DPMEM_MAGIC) { | |
1da177e4 LT |
998 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
999 | pcistr->dpmem); | |
1000 | found = FALSE; | |
1001 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { | |
1002 | iounmap(ha->brd); | |
1fe6dbf4 | 1003 | ha->brd = ioremap(i, sizeof(u16)); |
1da177e4 LT |
1004 | if (ha->brd == NULL) { |
1005 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
1006 | return 0; | |
1007 | } | |
a52667f3 | 1008 | if (readw(ha->brd) != 0xffff) { |
1da177e4 LT |
1009 | TRACE2(("init_pci_plx() address 0x%x busy\n", i)); |
1010 | continue; | |
1011 | } | |
1012 | iounmap(ha->brd); | |
4c9c8d78 | 1013 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_2, i); |
1da177e4 LT |
1014 | ha->brd = ioremap(i, sizeof(gdt6c_dpram_str)); |
1015 | if (ha->brd == NULL) { | |
1016 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
1017 | return 0; | |
1018 | } | |
1019 | dp6c_ptr = ha->brd; | |
a52667f3 JG |
1020 | writel(DPMEM_MAGIC, &dp6c_ptr->u); |
1021 | if (readl(&dp6c_ptr->u) == DPMEM_MAGIC) { | |
1da177e4 LT |
1022 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
1023 | found = TRUE; | |
1024 | break; | |
1025 | } | |
1026 | } | |
1027 | if (!found) { | |
1028 | printk("GDT-PCI: No free address found!\n"); | |
1029 | iounmap(ha->brd); | |
1030 | return 0; | |
1031 | } | |
1032 | } | |
1033 | memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u)); | |
a52667f3 | 1034 | if (readl(&dp6c_ptr->u) != 0) { |
1da177e4 LT |
1035 | printk("GDT-PCI: Initialization error (DPMEM write error)\n"); |
1036 | iounmap(ha->brd); | |
1037 | return 0; | |
1038 | } | |
1039 | ||
1040 | /* disable board interrupts, deinit services */ | |
1041 | outb(0x00,PTR2USHORT(&ha->plx->control1)); | |
1042 | outb(0xff,PTR2USHORT(&ha->plx->edoor_reg)); | |
1043 | ||
a52667f3 JG |
1044 | writeb(0x00, &dp6c_ptr->u.ic.S_Status); |
1045 | writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index); | |
1da177e4 | 1046 | |
a52667f3 JG |
1047 | writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]); |
1048 | writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx); | |
1da177e4 LT |
1049 | |
1050 | outb(1,PTR2USHORT(&ha->plx->ldoor_reg)); | |
1051 | ||
1052 | retries = INIT_RETRIES; | |
1053 | gdth_delay(20); | |
a52667f3 | 1054 | while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) { |
1da177e4 LT |
1055 | if (--retries == 0) { |
1056 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); | |
1057 | iounmap(ha->brd); | |
1058 | return 0; | |
1059 | } | |
1060 | gdth_delay(1); | |
1061 | } | |
1fe6dbf4 | 1062 | prot_ver = (u8)readl(&dp6c_ptr->u.ic.S_Info[0]); |
a52667f3 | 1063 | writeb(0, &dp6c_ptr->u.ic.Status); |
1da177e4 LT |
1064 | if (prot_ver != PROTOCOL_VERSION) { |
1065 | printk("GDT-PCI: Illegal protocol version\n"); | |
1066 | iounmap(ha->brd); | |
1067 | return 0; | |
1068 | } | |
1069 | ||
1070 | ha->type = GDT_PCINEW; | |
1071 | ha->ic_all_size = sizeof(dp6c_ptr->u); | |
1072 | ||
1073 | /* special command to controller BIOS */ | |
a52667f3 JG |
1074 | writel(0x00, &dp6c_ptr->u.ic.S_Info[0]); |
1075 | writel(0x00, &dp6c_ptr->u.ic.S_Info[1]); | |
1076 | writel(0x00, &dp6c_ptr->u.ic.S_Info[2]); | |
1077 | writel(0x00, &dp6c_ptr->u.ic.S_Info[3]); | |
1078 | writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx); | |
1da177e4 LT |
1079 | |
1080 | outb(1,PTR2USHORT(&ha->plx->ldoor_reg)); | |
1081 | ||
1082 | retries = INIT_RETRIES; | |
1083 | gdth_delay(20); | |
a52667f3 | 1084 | while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) { |
1da177e4 LT |
1085 | if (--retries == 0) { |
1086 | printk("GDT-PCI: Initialization error\n"); | |
1087 | iounmap(ha->brd); | |
1088 | return 0; | |
1089 | } | |
1090 | gdth_delay(1); | |
1091 | } | |
a52667f3 | 1092 | writeb(0, &dp6c_ptr->u.ic.S_Status); |
1da177e4 LT |
1093 | |
1094 | ha->dma64_support = 0; | |
1095 | ||
1096 | } else { /* MPR */ | |
1097 | TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq)); | |
1098 | ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str)); | |
1099 | if (ha->brd == NULL) { | |
1100 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
1101 | return 0; | |
1102 | } | |
1103 | ||
1104 | /* manipulate config. space to enable DPMEM, start RP controller */ | |
4c9c8d78 | 1105 | pci_read_config_word(pdev, PCI_COMMAND, &command); |
1da177e4 | 1106 | command |= 6; |
4c9c8d78 JG |
1107 | pci_write_config_word(pdev, PCI_COMMAND, command); |
1108 | if (pci_resource_start(pdev, 8) == 1UL) | |
1109 | pci_resource_start(pdev, 8) = 0UL; | |
1da177e4 | 1110 | i = 0xFEFF0001UL; |
4c9c8d78 | 1111 | pci_write_config_dword(pdev, PCI_ROM_ADDRESS, i); |
1da177e4 | 1112 | gdth_delay(1); |
4c9c8d78 JG |
1113 | pci_write_config_dword(pdev, PCI_ROM_ADDRESS, |
1114 | pci_resource_start(pdev, 8)); | |
1da177e4 LT |
1115 | |
1116 | dp6m_ptr = ha->brd; | |
1117 | ||
1118 | /* Ensure that it is safe to access the non HW portions of DPMEM. | |
1119 | * Aditional check needed for Xscale based RAID controllers */ | |
a52667f3 | 1120 | while( ((int)readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 ) |
1da177e4 LT |
1121 | gdth_delay(1); |
1122 | ||
1123 | /* check and reset interface area */ | |
a52667f3 JG |
1124 | writel(DPMEM_MAGIC, &dp6m_ptr->u); |
1125 | if (readl(&dp6m_ptr->u) != DPMEM_MAGIC) { | |
1da177e4 LT |
1126 | printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", |
1127 | pcistr->dpmem); | |
1128 | found = FALSE; | |
1129 | for (i = 0xC8000; i < 0xE8000; i += 0x4000) { | |
1130 | iounmap(ha->brd); | |
1fe6dbf4 | 1131 | ha->brd = ioremap(i, sizeof(u16)); |
1da177e4 LT |
1132 | if (ha->brd == NULL) { |
1133 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
1134 | return 0; | |
1135 | } | |
a52667f3 | 1136 | if (readw(ha->brd) != 0xffff) { |
1da177e4 LT |
1137 | TRACE2(("init_pci_mpr() address 0x%x busy\n", i)); |
1138 | continue; | |
1139 | } | |
1140 | iounmap(ha->brd); | |
4c9c8d78 | 1141 | pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, i); |
1da177e4 LT |
1142 | ha->brd = ioremap(i, sizeof(gdt6m_dpram_str)); |
1143 | if (ha->brd == NULL) { | |
1144 | printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); | |
1145 | return 0; | |
1146 | } | |
1147 | dp6m_ptr = ha->brd; | |
a52667f3 JG |
1148 | writel(DPMEM_MAGIC, &dp6m_ptr->u); |
1149 | if (readl(&dp6m_ptr->u) == DPMEM_MAGIC) { | |
1da177e4 LT |
1150 | printk("GDT-PCI: Use free address at 0x%x\n", i); |
1151 | found = TRUE; | |
1152 | break; | |
1153 | } | |
1154 | } | |
1155 | if (!found) { | |
1156 | printk("GDT-PCI: No free address found!\n"); | |
1157 | iounmap(ha->brd); | |
1158 | return 0; | |
1159 | } | |
1160 | } | |
1161 | memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u)); | |
1162 | ||
1163 | /* disable board interrupts, deinit services */ | |
a52667f3 | 1164 | writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4, |
1da177e4 | 1165 | &dp6m_ptr->i960r.edoor_en_reg); |
a52667f3 JG |
1166 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
1167 | writeb(0x00, &dp6m_ptr->u.ic.S_Status); | |
1168 | writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index); | |
1da177e4 | 1169 | |
a52667f3 JG |
1170 | writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]); |
1171 | writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx); | |
1172 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); | |
1da177e4 LT |
1173 | retries = INIT_RETRIES; |
1174 | gdth_delay(20); | |
a52667f3 | 1175 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) { |
1da177e4 LT |
1176 | if (--retries == 0) { |
1177 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); | |
1178 | iounmap(ha->brd); | |
1179 | return 0; | |
1180 | } | |
1181 | gdth_delay(1); | |
1182 | } | |
1fe6dbf4 | 1183 | prot_ver = (u8)readl(&dp6m_ptr->u.ic.S_Info[0]); |
a52667f3 | 1184 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
1da177e4 LT |
1185 | if (prot_ver != PROTOCOL_VERSION) { |
1186 | printk("GDT-PCI: Illegal protocol version\n"); | |
1187 | iounmap(ha->brd); | |
1188 | return 0; | |
1189 | } | |
1190 | ||
1191 | ha->type = GDT_PCIMPR; | |
1192 | ha->ic_all_size = sizeof(dp6m_ptr->u); | |
1193 | ||
1194 | /* special command to controller BIOS */ | |
a52667f3 JG |
1195 | writel(0x00, &dp6m_ptr->u.ic.S_Info[0]); |
1196 | writel(0x00, &dp6m_ptr->u.ic.S_Info[1]); | |
1197 | writel(0x00, &dp6m_ptr->u.ic.S_Info[2]); | |
1198 | writel(0x00, &dp6m_ptr->u.ic.S_Info[3]); | |
1199 | writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx); | |
1200 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); | |
1da177e4 LT |
1201 | retries = INIT_RETRIES; |
1202 | gdth_delay(20); | |
a52667f3 | 1203 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) { |
1da177e4 LT |
1204 | if (--retries == 0) { |
1205 | printk("GDT-PCI: Initialization error\n"); | |
1206 | iounmap(ha->brd); | |
1207 | return 0; | |
1208 | } | |
1209 | gdth_delay(1); | |
1210 | } | |
a52667f3 | 1211 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
1da177e4 LT |
1212 | |
1213 | /* read FW version to detect 64-bit DMA support */ | |
a52667f3 JG |
1214 | writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx); |
1215 | writeb(1, &dp6m_ptr->i960r.ldoor_reg); | |
1da177e4 LT |
1216 | retries = INIT_RETRIES; |
1217 | gdth_delay(20); | |
a52667f3 | 1218 | while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) { |
1da177e4 LT |
1219 | if (--retries == 0) { |
1220 | printk("GDT-PCI: Initialization error (DEINIT failed)\n"); | |
1221 | iounmap(ha->brd); | |
1222 | return 0; | |
1223 | } | |
1224 | gdth_delay(1); | |
1225 | } | |
1fe6dbf4 | 1226 | prot_ver = (u8)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16); |
a52667f3 | 1227 | writeb(0, &dp6m_ptr->u.ic.S_Status); |
1da177e4 LT |
1228 | if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */ |
1229 | ha->dma64_support = 0; | |
1230 | else | |
1231 | ha->dma64_support = 1; | |
1232 | } | |
1233 | ||
1234 | return 1; | |
1235 | } | |
8514ef27 | 1236 | #endif /* CONFIG_PCI */ |
1da177e4 LT |
1237 | |
1238 | /* controller protocol functions */ | |
1239 | ||
ced7172a | 1240 | static void __devinit gdth_enable_int(gdth_ha_str *ha) |
1da177e4 | 1241 | { |
1fe6dbf4 | 1242 | unsigned long flags; |
1da177e4 LT |
1243 | gdt2_dpram_str __iomem *dp2_ptr; |
1244 | gdt6_dpram_str __iomem *dp6_ptr; | |
1245 | gdt6m_dpram_str __iomem *dp6m_ptr; | |
1246 | ||
45f1a41b | 1247 | TRACE(("gdth_enable_int() hanum %d\n",ha->hanum)); |
1da177e4 LT |
1248 | spin_lock_irqsave(&ha->smp_lock, flags); |
1249 | ||
1250 | if (ha->type == GDT_EISA) { | |
1251 | outb(0xff, ha->bmic + EDOORREG); | |
1252 | outb(0xff, ha->bmic + EDENABREG); | |
1253 | outb(0x01, ha->bmic + EINTENABREG); | |
1254 | } else if (ha->type == GDT_ISA) { | |
1255 | dp2_ptr = ha->brd; | |
a52667f3 JG |
1256 | writeb(1, &dp2_ptr->io.irqdel); |
1257 | writeb(0, &dp2_ptr->u.ic.Cmd_Index); | |
1258 | writeb(1, &dp2_ptr->io.irqen); | |
1da177e4 LT |
1259 | } else if (ha->type == GDT_PCI) { |
1260 | dp6_ptr = ha->brd; | |
a52667f3 JG |
1261 | writeb(1, &dp6_ptr->io.irqdel); |
1262 | writeb(0, &dp6_ptr->u.ic.Cmd_Index); | |
1263 | writeb(1, &dp6_ptr->io.irqen); | |
1da177e4 LT |
1264 | } else if (ha->type == GDT_PCINEW) { |
1265 | outb(0xff, PTR2USHORT(&ha->plx->edoor_reg)); | |
1266 | outb(0x03, PTR2USHORT(&ha->plx->control1)); | |
1267 | } else if (ha->type == GDT_PCIMPR) { | |
1268 | dp6m_ptr = ha->brd; | |
a52667f3 JG |
1269 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
1270 | writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4, | |
1da177e4 LT |
1271 | &dp6m_ptr->i960r.edoor_en_reg); |
1272 | } | |
1273 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
1274 | } | |
1275 | ||
10e1b4bc | 1276 | /* return IStatus if interrupt was from this card else 0 */ |
1fe6dbf4 | 1277 | static u8 gdth_get_status(gdth_ha_str *ha) |
1da177e4 | 1278 | { |
1fe6dbf4 | 1279 | u8 IStatus = 0; |
10e1b4bc | 1280 | |
230e886e | 1281 | TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count)); |
1da177e4 | 1282 | |
1da177e4 | 1283 | if (ha->type == GDT_EISA) |
1fe6dbf4 | 1284 | IStatus = inb((u16)ha->bmic + EDOORREG); |
1da177e4 | 1285 | else if (ha->type == GDT_ISA) |
10e1b4bc | 1286 | IStatus = |
a52667f3 | 1287 | readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index); |
1da177e4 | 1288 | else if (ha->type == GDT_PCI) |
10e1b4bc | 1289 | IStatus = |
a52667f3 | 1290 | readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index); |
1da177e4 | 1291 | else if (ha->type == GDT_PCINEW) |
10e1b4bc | 1292 | IStatus = inb(PTR2USHORT(&ha->plx->edoor_reg)); |
1da177e4 | 1293 | else if (ha->type == GDT_PCIMPR) |
10e1b4bc | 1294 | IStatus = |
a52667f3 | 1295 | readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg); |
10e1b4bc BH |
1296 | |
1297 | return IStatus; | |
1da177e4 | 1298 | } |
10e1b4bc | 1299 | |
45f1a41b | 1300 | static int gdth_test_busy(gdth_ha_str *ha) |
1da177e4 | 1301 | { |
1da177e4 LT |
1302 | register int gdtsema0 = 0; |
1303 | ||
45f1a41b BH |
1304 | TRACE(("gdth_test_busy() hanum %d\n", ha->hanum)); |
1305 | ||
1da177e4 LT |
1306 | if (ha->type == GDT_EISA) |
1307 | gdtsema0 = (int)inb(ha->bmic + SEMA0REG); | |
1308 | else if (ha->type == GDT_ISA) | |
a52667f3 | 1309 | gdtsema0 = (int)readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
1da177e4 | 1310 | else if (ha->type == GDT_PCI) |
a52667f3 | 1311 | gdtsema0 = (int)readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
1da177e4 LT |
1312 | else if (ha->type == GDT_PCINEW) |
1313 | gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg)); | |
1314 | else if (ha->type == GDT_PCIMPR) | |
1315 | gdtsema0 = | |
a52667f3 | 1316 | (int)readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg); |
1da177e4 LT |
1317 | |
1318 | return (gdtsema0 & 1); | |
1319 | } | |
1320 | ||
1321 | ||
45f1a41b | 1322 | static int gdth_get_cmd_index(gdth_ha_str *ha) |
1da177e4 | 1323 | { |
1da177e4 LT |
1324 | int i; |
1325 | ||
45f1a41b | 1326 | TRACE(("gdth_get_cmd_index() hanum %d\n", ha->hanum)); |
1da177e4 | 1327 | |
1da177e4 LT |
1328 | for (i=0; i<GDTH_MAXCMDS; ++i) { |
1329 | if (ha->cmd_tab[i].cmnd == UNUSED_CMND) { | |
1330 | ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer; | |
1331 | ha->cmd_tab[i].service = ha->pccb->Service; | |
1fe6dbf4 | 1332 | ha->pccb->CommandIndex = (u32)i+2; |
1da177e4 LT |
1333 | return (i+2); |
1334 | } | |
1335 | } | |
1336 | return 0; | |
1337 | } | |
1338 | ||
1339 | ||
45f1a41b | 1340 | static void gdth_set_sema0(gdth_ha_str *ha) |
1da177e4 | 1341 | { |
45f1a41b | 1342 | TRACE(("gdth_set_sema0() hanum %d\n", ha->hanum)); |
1da177e4 | 1343 | |
1da177e4 LT |
1344 | if (ha->type == GDT_EISA) { |
1345 | outb(1, ha->bmic + SEMA0REG); | |
1346 | } else if (ha->type == GDT_ISA) { | |
a52667f3 | 1347 | writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
1da177e4 | 1348 | } else if (ha->type == GDT_PCI) { |
a52667f3 | 1349 | writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0); |
1da177e4 LT |
1350 | } else if (ha->type == GDT_PCINEW) { |
1351 | outb(1, PTR2USHORT(&ha->plx->sema0_reg)); | |
1352 | } else if (ha->type == GDT_PCIMPR) { | |
a52667f3 | 1353 | writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg); |
1da177e4 LT |
1354 | } |
1355 | } | |
1356 | ||
1357 | ||
45f1a41b | 1358 | static void gdth_copy_command(gdth_ha_str *ha) |
1da177e4 | 1359 | { |
1da177e4 LT |
1360 | register gdth_cmd_str *cmd_ptr; |
1361 | register gdt6m_dpram_str __iomem *dp6m_ptr; | |
1362 | register gdt6c_dpram_str __iomem *dp6c_ptr; | |
1363 | gdt6_dpram_str __iomem *dp6_ptr; | |
1364 | gdt2_dpram_str __iomem *dp2_ptr; | |
1fe6dbf4 | 1365 | u16 cp_count,dp_offset,cmd_no; |
1da177e4 | 1366 | |
45f1a41b | 1367 | TRACE(("gdth_copy_command() hanum %d\n", ha->hanum)); |
1da177e4 | 1368 | |
1da177e4 LT |
1369 | cp_count = ha->cmd_len; |
1370 | dp_offset= ha->cmd_offs_dpmem; | |
1371 | cmd_no = ha->cmd_cnt; | |
1372 | cmd_ptr = ha->pccb; | |
1373 | ||
1374 | ++ha->cmd_cnt; | |
1375 | if (ha->type == GDT_EISA) | |
1376 | return; /* no DPMEM, no copy */ | |
1377 | ||
1378 | /* set cpcount dword aligned */ | |
1379 | if (cp_count & 3) | |
1380 | cp_count += (4 - (cp_count & 3)); | |
1381 | ||
1382 | ha->cmd_offs_dpmem += cp_count; | |
1383 | ||
1384 | /* set offset and service, copy command to DPMEM */ | |
1385 | if (ha->type == GDT_ISA) { | |
1386 | dp2_ptr = ha->brd; | |
a52667f3 | 1387 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
1da177e4 | 1388 | &dp2_ptr->u.ic.comm_queue[cmd_no].offset); |
1fe6dbf4 | 1389 | writew((u16)cmd_ptr->Service, |
1da177e4 LT |
1390 | &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id); |
1391 | memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); | |
1392 | } else if (ha->type == GDT_PCI) { | |
1393 | dp6_ptr = ha->brd; | |
a52667f3 | 1394 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
1da177e4 | 1395 | &dp6_ptr->u.ic.comm_queue[cmd_no].offset); |
1fe6dbf4 | 1396 | writew((u16)cmd_ptr->Service, |
1da177e4 LT |
1397 | &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id); |
1398 | memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); | |
1399 | } else if (ha->type == GDT_PCINEW) { | |
1400 | dp6c_ptr = ha->brd; | |
a52667f3 | 1401 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
1da177e4 | 1402 | &dp6c_ptr->u.ic.comm_queue[cmd_no].offset); |
1fe6dbf4 | 1403 | writew((u16)cmd_ptr->Service, |
1da177e4 LT |
1404 | &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id); |
1405 | memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); | |
1406 | } else if (ha->type == GDT_PCIMPR) { | |
1407 | dp6m_ptr = ha->brd; | |
a52667f3 | 1408 | writew(dp_offset + DPMEM_COMMAND_OFFSET, |
1da177e4 | 1409 | &dp6m_ptr->u.ic.comm_queue[cmd_no].offset); |
1fe6dbf4 | 1410 | writew((u16)cmd_ptr->Service, |
1da177e4 LT |
1411 | &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id); |
1412 | memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); | |
1413 | } | |
1414 | } | |
1415 | ||
1416 | ||
45f1a41b | 1417 | static void gdth_release_event(gdth_ha_str *ha) |
1da177e4 | 1418 | { |
45f1a41b | 1419 | TRACE(("gdth_release_event() hanum %d\n", ha->hanum)); |
1da177e4 LT |
1420 | |
1421 | #ifdef GDTH_STATISTICS | |
1422 | { | |
1fe6dbf4 | 1423 | u32 i,j; |
1da177e4 LT |
1424 | for (i=0,j=0; j<GDTH_MAXCMDS; ++j) { |
1425 | if (ha->cmd_tab[j].cmnd != UNUSED_CMND) | |
1426 | ++i; | |
1427 | } | |
1428 | if (max_index < i) { | |
1429 | max_index = i; | |
1fe6dbf4 | 1430 | TRACE3(("GDT: max_index = %d\n",(u16)i)); |
1da177e4 LT |
1431 | } |
1432 | } | |
1433 | #endif | |
1434 | ||
1435 | if (ha->pccb->OpCode == GDT_INIT) | |
1436 | ha->pccb->Service |= 0x80; | |
1437 | ||
1438 | if (ha->type == GDT_EISA) { | |
1439 | if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */ | |
1440 | outl(ha->ccb_phys, ha->bmic + MAILBOXREG); | |
1441 | outb(ha->pccb->Service, ha->bmic + LDOORREG); | |
1442 | } else if (ha->type == GDT_ISA) { | |
a52667f3 | 1443 | writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event); |
1da177e4 | 1444 | } else if (ha->type == GDT_PCI) { |
a52667f3 | 1445 | writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event); |
1da177e4 LT |
1446 | } else if (ha->type == GDT_PCINEW) { |
1447 | outb(1, PTR2USHORT(&ha->plx->ldoor_reg)); | |
1448 | } else if (ha->type == GDT_PCIMPR) { | |
a52667f3 | 1449 | writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg); |
1da177e4 LT |
1450 | } |
1451 | } | |
1452 | ||
1fe6dbf4 | 1453 | static int gdth_wait(gdth_ha_str *ha, int index, u32 time) |
1da177e4 | 1454 | { |
1da177e4 | 1455 | int answer_found = FALSE; |
10e1b4bc | 1456 | int wait_index = 0; |
1da177e4 | 1457 | |
45f1a41b | 1458 | TRACE(("gdth_wait() hanum %d index %d time %d\n", ha->hanum, index, time)); |
1da177e4 | 1459 | |
1da177e4 LT |
1460 | if (index == 0) |
1461 | return 1; /* no wait required */ | |
1462 | ||
1da177e4 | 1463 | do { |
230e886e | 1464 | __gdth_interrupt(ha, true, &wait_index); |
10e1b4bc | 1465 | if (wait_index == index) { |
1da177e4 LT |
1466 | answer_found = TRUE; |
1467 | break; | |
1468 | } | |
1469 | gdth_delay(1); | |
1470 | } while (--time); | |
45f1a41b BH |
1471 | |
1472 | while (gdth_test_busy(ha)) | |
1da177e4 LT |
1473 | gdth_delay(0); |
1474 | ||
1475 | return (answer_found); | |
1476 | } | |
1477 | ||
1478 | ||
1fe6dbf4 DJ |
1479 | static int gdth_internal_cmd(gdth_ha_str *ha, u8 service, u16 opcode, |
1480 | u32 p1, u64 p2, u64 p3) | |
1da177e4 | 1481 | { |
1da177e4 LT |
1482 | register gdth_cmd_str *cmd_ptr; |
1483 | int retries,index; | |
1484 | ||
1485 | TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode)); | |
1486 | ||
1da177e4 LT |
1487 | cmd_ptr = ha->pccb; |
1488 | memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str)); | |
1489 | ||
1490 | /* make command */ | |
1491 | for (retries = INIT_RETRIES;;) { | |
1492 | cmd_ptr->Service = service; | |
1493 | cmd_ptr->RequestBuffer = INTERNAL_CMND; | |
45f1a41b | 1494 | if (!(index=gdth_get_cmd_index(ha))) { |
1da177e4 LT |
1495 | TRACE(("GDT: No free command index found\n")); |
1496 | return 0; | |
1497 | } | |
45f1a41b | 1498 | gdth_set_sema0(ha); |
1da177e4 LT |
1499 | cmd_ptr->OpCode = opcode; |
1500 | cmd_ptr->BoardNode = LOCALBOARD; | |
1501 | if (service == CACHESERVICE) { | |
1502 | if (opcode == GDT_IOCTL) { | |
1503 | cmd_ptr->u.ioctl.subfunc = p1; | |
1fe6dbf4 DJ |
1504 | cmd_ptr->u.ioctl.channel = (u32)p2; |
1505 | cmd_ptr->u.ioctl.param_size = (u16)p3; | |
1da177e4 LT |
1506 | cmd_ptr->u.ioctl.p_param = ha->scratch_phys; |
1507 | } else { | |
1508 | if (ha->cache_feat & GDT_64BIT) { | |
1fe6dbf4 | 1509 | cmd_ptr->u.cache64.DeviceNo = (u16)p1; |
1da177e4 LT |
1510 | cmd_ptr->u.cache64.BlockNo = p2; |
1511 | } else { | |
1fe6dbf4 DJ |
1512 | cmd_ptr->u.cache.DeviceNo = (u16)p1; |
1513 | cmd_ptr->u.cache.BlockNo = (u32)p2; | |
1da177e4 LT |
1514 | } |
1515 | } | |
1516 | } else if (service == SCSIRAWSERVICE) { | |
1517 | if (ha->raw_feat & GDT_64BIT) { | |
1518 | cmd_ptr->u.raw64.direction = p1; | |
1fe6dbf4 DJ |
1519 | cmd_ptr->u.raw64.bus = (u8)p2; |
1520 | cmd_ptr->u.raw64.target = (u8)p3; | |
1521 | cmd_ptr->u.raw64.lun = (u8)(p3 >> 8); | |
1da177e4 LT |
1522 | } else { |
1523 | cmd_ptr->u.raw.direction = p1; | |
1fe6dbf4 DJ |
1524 | cmd_ptr->u.raw.bus = (u8)p2; |
1525 | cmd_ptr->u.raw.target = (u8)p3; | |
1526 | cmd_ptr->u.raw.lun = (u8)(p3 >> 8); | |
1da177e4 LT |
1527 | } |
1528 | } else if (service == SCREENSERVICE) { | |
1529 | if (opcode == GDT_REALTIME) { | |
1fe6dbf4 DJ |
1530 | *(u32 *)&cmd_ptr->u.screen.su.data[0] = p1; |
1531 | *(u32 *)&cmd_ptr->u.screen.su.data[4] = (u32)p2; | |
1532 | *(u32 *)&cmd_ptr->u.screen.su.data[8] = (u32)p3; | |
1da177e4 LT |
1533 | } |
1534 | } | |
1535 | ha->cmd_len = sizeof(gdth_cmd_str); | |
1536 | ha->cmd_offs_dpmem = 0; | |
1537 | ha->cmd_cnt = 0; | |
45f1a41b BH |
1538 | gdth_copy_command(ha); |
1539 | gdth_release_event(ha); | |
1da177e4 | 1540 | gdth_delay(20); |
45f1a41b | 1541 | if (!gdth_wait(ha, index, INIT_TIMEOUT)) { |
1da177e4 LT |
1542 | printk("GDT: Initialization error (timeout service %d)\n",service); |
1543 | return 0; | |
1544 | } | |
1545 | if (ha->status != S_BSY || --retries == 0) | |
1546 | break; | |
1547 | gdth_delay(1); | |
1548 | } | |
1549 | ||
1550 | return (ha->status != S_OK ? 0:1); | |
1551 | } | |
1552 | ||
1553 | ||
1554 | /* search for devices */ | |
1555 | ||
ced7172a | 1556 | static int __devinit gdth_search_drives(gdth_ha_str *ha) |
1da177e4 | 1557 | { |
1fe6dbf4 | 1558 | u16 cdev_cnt, i; |
1da177e4 | 1559 | int ok; |
1fe6dbf4 | 1560 | u32 bus_no, drv_cnt, drv_no, j; |
1da177e4 LT |
1561 | gdth_getch_str *chn; |
1562 | gdth_drlist_str *drl; | |
1563 | gdth_iochan_str *ioc; | |
1564 | gdth_raw_iochan_str *iocr; | |
1565 | gdth_arcdl_str *alst; | |
1566 | gdth_alist_str *alst2; | |
1567 | gdth_oem_str_ioctl *oemstr; | |
1568 | #ifdef INT_COAL | |
1569 | gdth_perf_modes *pmod; | |
1570 | #endif | |
1571 | ||
1572 | #ifdef GDTH_RTC | |
1fe6dbf4 DJ |
1573 | u8 rtc[12]; |
1574 | unsigned long flags; | |
1da177e4 LT |
1575 | #endif |
1576 | ||
45f1a41b | 1577 | TRACE(("gdth_search_drives() hanum %d\n", ha->hanum)); |
1da177e4 LT |
1578 | ok = 0; |
1579 | ||
1580 | /* initialize controller services, at first: screen service */ | |
1581 | ha->screen_feat = 0; | |
1582 | if (!force_dma32) { | |
45f1a41b | 1583 | ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_X_INIT_SCR, 0, 0, 0); |
1da177e4 LT |
1584 | if (ok) |
1585 | ha->screen_feat = GDT_64BIT; | |
1586 | } | |
1fe6dbf4 | 1587 | if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC)) |
45f1a41b | 1588 | ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0); |
1da177e4 LT |
1589 | if (!ok) { |
1590 | printk("GDT-HA %d: Initialization error screen service (code %d)\n", | |
45f1a41b | 1591 | ha->hanum, ha->status); |
1da177e4 LT |
1592 | return 0; |
1593 | } | |
1594 | TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n")); | |
1595 | ||
1596 | #ifdef GDTH_RTC | |
1597 | /* read realtime clock info, send to controller */ | |
1598 | /* 1. wait for the falling edge of update flag */ | |
1599 | spin_lock_irqsave(&rtc_lock, flags); | |
1600 | for (j = 0; j < 1000000; ++j) | |
1601 | if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) | |
1602 | break; | |
1603 | for (j = 0; j < 1000000; ++j) | |
1604 | if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) | |
1605 | break; | |
1606 | /* 2. read info */ | |
1607 | do { | |
1608 | for (j = 0; j < 12; ++j) | |
1609 | rtc[j] = CMOS_READ(j); | |
1610 | } while (rtc[0] != CMOS_READ(0)); | |
7a960b76 | 1611 | spin_unlock_irqrestore(&rtc_lock, flags); |
1fe6dbf4 DJ |
1612 | TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(u32 *)&rtc[0], |
1613 | *(u32 *)&rtc[4], *(u32 *)&rtc[8])); | |
1da177e4 | 1614 | /* 3. send to controller firmware */ |
1fe6dbf4 DJ |
1615 | gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(u32 *)&rtc[0], |
1616 | *(u32 *)&rtc[4], *(u32 *)&rtc[8]); | |
1da177e4 LT |
1617 | #endif |
1618 | ||
1619 | /* unfreeze all IOs */ | |
45f1a41b | 1620 | gdth_internal_cmd(ha, CACHESERVICE, GDT_UNFREEZE_IO, 0, 0, 0); |
1da177e4 LT |
1621 | |
1622 | /* initialize cache service */ | |
1623 | ha->cache_feat = 0; | |
1624 | if (!force_dma32) { | |
45f1a41b BH |
1625 | ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INIT_HOST, LINUX_OS, |
1626 | 0, 0); | |
1da177e4 LT |
1627 | if (ok) |
1628 | ha->cache_feat = GDT_64BIT; | |
1629 | } | |
1fe6dbf4 | 1630 | if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC)) |
45f1a41b | 1631 | ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0); |
1da177e4 LT |
1632 | if (!ok) { |
1633 | printk("GDT-HA %d: Initialization error cache service (code %d)\n", | |
45f1a41b | 1634 | ha->hanum, ha->status); |
1da177e4 LT |
1635 | return 0; |
1636 | } | |
1637 | TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n")); | |
1fe6dbf4 | 1638 | cdev_cnt = (u16)ha->info; |
1da177e4 LT |
1639 | ha->fw_vers = ha->service; |
1640 | ||
1641 | #ifdef INT_COAL | |
1642 | if (ha->type == GDT_PCIMPR) { | |
1643 | /* set perf. modes */ | |
1644 | pmod = (gdth_perf_modes *)ha->pscratch; | |
1645 | pmod->version = 1; | |
1646 | pmod->st_mode = 1; /* enable one status buffer */ | |
1fe6dbf4 | 1647 | *((u64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys; |
1da177e4 LT |
1648 | pmod->st_buff_indx1 = COALINDEX; |
1649 | pmod->st_buff_addr2 = 0; | |
1650 | pmod->st_buff_u_addr2 = 0; | |
1651 | pmod->st_buff_indx2 = 0; | |
1652 | pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS; | |
1653 | pmod->cmd_mode = 0; // disable all cmd buffers | |
1654 | pmod->cmd_buff_addr1 = 0; | |
1655 | pmod->cmd_buff_u_addr1 = 0; | |
1656 | pmod->cmd_buff_indx1 = 0; | |
1657 | pmod->cmd_buff_addr2 = 0; | |
1658 | pmod->cmd_buff_u_addr2 = 0; | |
1659 | pmod->cmd_buff_indx2 = 0; | |
1660 | pmod->cmd_buff_size = 0; | |
1661 | pmod->reserved1 = 0; | |
1662 | pmod->reserved2 = 0; | |
45f1a41b | 1663 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, SET_PERF_MODES, |
1da177e4 | 1664 | INVALID_CHANNEL,sizeof(gdth_perf_modes))) { |
45f1a41b | 1665 | printk("GDT-HA %d: Interrupt coalescing activated\n", ha->hanum); |
1da177e4 LT |
1666 | } |
1667 | } | |
1668 | #endif | |
1669 | ||
1670 | /* detect number of buses - try new IOCTL */ | |
1671 | iocr = (gdth_raw_iochan_str *)ha->pscratch; | |
1672 | iocr->hdr.version = 0xffffffff; | |
1673 | iocr->hdr.list_entries = MAXBUS; | |
1674 | iocr->hdr.first_chan = 0; | |
1675 | iocr->hdr.last_chan = MAXBUS-1; | |
1676 | iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]); | |
45f1a41b | 1677 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_RAW_DESC, |
1da177e4 LT |
1678 | INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) { |
1679 | TRACE2(("IOCHAN_RAW_DESC supported!\n")); | |
1680 | ha->bus_cnt = iocr->hdr.chan_count; | |
1681 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { | |
1682 | if (iocr->list[bus_no].proc_id < MAXID) | |
1683 | ha->bus_id[bus_no] = iocr->list[bus_no].proc_id; | |
1684 | else | |
1685 | ha->bus_id[bus_no] = 0xff; | |
1686 | } | |
1687 | } else { | |
1688 | /* old method */ | |
1689 | chn = (gdth_getch_str *)ha->pscratch; | |
1690 | for (bus_no = 0; bus_no < MAXBUS; ++bus_no) { | |
1691 | chn->channel_no = bus_no; | |
45f1a41b | 1692 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1693 | SCSI_CHAN_CNT | L_CTRL_PATTERN, |
1694 | IO_CHANNEL | INVALID_CHANNEL, | |
1695 | sizeof(gdth_getch_str))) { | |
1696 | if (bus_no == 0) { | |
1697 | printk("GDT-HA %d: Error detecting channel count (0x%x)\n", | |
45f1a41b | 1698 | ha->hanum, ha->status); |
1da177e4 LT |
1699 | return 0; |
1700 | } | |
1701 | break; | |
1702 | } | |
1703 | if (chn->siop_id < MAXID) | |
1704 | ha->bus_id[bus_no] = chn->siop_id; | |
1705 | else | |
1706 | ha->bus_id[bus_no] = 0xff; | |
1707 | } | |
1fe6dbf4 | 1708 | ha->bus_cnt = (u8)bus_no; |
1da177e4 LT |
1709 | } |
1710 | TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt)); | |
1711 | ||
1712 | /* read cache configuration */ | |
45f1a41b | 1713 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_INFO, |
1da177e4 LT |
1714 | INVALID_CHANNEL,sizeof(gdth_cinfo_str))) { |
1715 | printk("GDT-HA %d: Initialization error cache service (code %d)\n", | |
45f1a41b | 1716 | ha->hanum, ha->status); |
1da177e4 LT |
1717 | return 0; |
1718 | } | |
1719 | ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar; | |
1720 | TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n", | |
1721 | ha->cpar.version,ha->cpar.state,ha->cpar.strategy, | |
1722 | ha->cpar.write_back,ha->cpar.block_size)); | |
1723 | ||
1724 | /* read board info and features */ | |
1725 | ha->more_proc = FALSE; | |
45f1a41b | 1726 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_INFO, |
1da177e4 LT |
1727 | INVALID_CHANNEL,sizeof(gdth_binfo_str))) { |
1728 | memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch, | |
1729 | sizeof(gdth_binfo_str)); | |
45f1a41b | 1730 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, BOARD_FEATURES, |
1da177e4 LT |
1731 | INVALID_CHANNEL,sizeof(gdth_bfeat_str))) { |
1732 | TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n")); | |
1733 | ha->bfeat = *(gdth_bfeat_str *)ha->pscratch; | |
1734 | ha->more_proc = TRUE; | |
1735 | } | |
1736 | } else { | |
1737 | TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n")); | |
45f1a41b | 1738 | strcpy(ha->binfo.type_string, gdth_ctr_name(ha)); |
1da177e4 LT |
1739 | } |
1740 | TRACE2(("Controller name: %s\n",ha->binfo.type_string)); | |
1741 | ||
1742 | /* read more informations */ | |
1743 | if (ha->more_proc) { | |
1744 | /* physical drives, channel addresses */ | |
1745 | ioc = (gdth_iochan_str *)ha->pscratch; | |
1746 | ioc->hdr.version = 0xffffffff; | |
1747 | ioc->hdr.list_entries = MAXBUS; | |
1748 | ioc->hdr.first_chan = 0; | |
1749 | ioc->hdr.last_chan = MAXBUS-1; | |
1750 | ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]); | |
45f1a41b | 1751 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, IOCHAN_DESC, |
1da177e4 LT |
1752 | INVALID_CHANNEL,sizeof(gdth_iochan_str))) { |
1753 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { | |
1754 | ha->raw[bus_no].address = ioc->list[bus_no].address; | |
1755 | ha->raw[bus_no].local_no = ioc->list[bus_no].local_no; | |
1756 | } | |
1757 | } else { | |
1758 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { | |
1759 | ha->raw[bus_no].address = IO_CHANNEL; | |
1760 | ha->raw[bus_no].local_no = bus_no; | |
1761 | } | |
1762 | } | |
1763 | for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) { | |
1764 | chn = (gdth_getch_str *)ha->pscratch; | |
1765 | chn->channel_no = ha->raw[bus_no].local_no; | |
45f1a41b | 1766 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1767 | SCSI_CHAN_CNT | L_CTRL_PATTERN, |
1768 | ha->raw[bus_no].address | INVALID_CHANNEL, | |
1769 | sizeof(gdth_getch_str))) { | |
1770 | ha->raw[bus_no].pdev_cnt = chn->drive_cnt; | |
1771 | TRACE2(("Channel %d: %d phys. drives\n", | |
1772 | bus_no,chn->drive_cnt)); | |
1773 | } | |
1774 | if (ha->raw[bus_no].pdev_cnt > 0) { | |
1775 | drl = (gdth_drlist_str *)ha->pscratch; | |
1776 | drl->sc_no = ha->raw[bus_no].local_no; | |
1777 | drl->sc_cnt = ha->raw[bus_no].pdev_cnt; | |
45f1a41b | 1778 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1779 | SCSI_DR_LIST | L_CTRL_PATTERN, |
1780 | ha->raw[bus_no].address | INVALID_CHANNEL, | |
1781 | sizeof(gdth_drlist_str))) { | |
1782 | for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j) | |
1783 | ha->raw[bus_no].id_list[j] = drl->sc_list[j]; | |
1784 | } else { | |
1785 | ha->raw[bus_no].pdev_cnt = 0; | |
1786 | } | |
1787 | } | |
1788 | } | |
1789 | ||
1790 | /* logical drives */ | |
45f1a41b | 1791 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT, |
1fe6dbf4 DJ |
1792 | INVALID_CHANNEL,sizeof(u32))) { |
1793 | drv_cnt = *(u32 *)ha->pscratch; | |
45f1a41b | 1794 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST, |
1fe6dbf4 | 1795 | INVALID_CHANNEL,drv_cnt * sizeof(u32))) { |
1da177e4 | 1796 | for (j = 0; j < drv_cnt; ++j) { |
1fe6dbf4 | 1797 | drv_no = ((u32 *)ha->pscratch)[j]; |
1da177e4 LT |
1798 | if (drv_no < MAX_LDRIVES) { |
1799 | ha->hdr[drv_no].is_logdrv = TRUE; | |
1800 | TRACE2(("Drive %d is log. drive\n",drv_no)); | |
1801 | } | |
1802 | } | |
1803 | } | |
1804 | alst = (gdth_arcdl_str *)ha->pscratch; | |
1805 | alst->entries_avail = MAX_LDRIVES; | |
1806 | alst->first_entry = 0; | |
1807 | alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]); | |
45f1a41b | 1808 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1809 | ARRAY_DRV_LIST2 | LA_CTRL_PATTERN, |
1810 | INVALID_CHANNEL, sizeof(gdth_arcdl_str) + | |
1811 | (alst->entries_avail-1) * sizeof(gdth_alist_str))) { | |
1812 | for (j = 0; j < alst->entries_init; ++j) { | |
1813 | ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd; | |
1814 | ha->hdr[j].is_master = alst->list[j].is_master; | |
1815 | ha->hdr[j].is_parity = alst->list[j].is_parity; | |
1816 | ha->hdr[j].is_hotfix = alst->list[j].is_hotfix; | |
1817 | ha->hdr[j].master_no = alst->list[j].cd_handle; | |
1818 | } | |
45f1a41b | 1819 | } else if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1820 | ARRAY_DRV_LIST | LA_CTRL_PATTERN, |
1821 | 0, 35 * sizeof(gdth_alist_str))) { | |
1822 | for (j = 0; j < 35; ++j) { | |
1823 | alst2 = &((gdth_alist_str *)ha->pscratch)[j]; | |
1824 | ha->hdr[j].is_arraydrv = alst2->is_arrayd; | |
1825 | ha->hdr[j].is_master = alst2->is_master; | |
1826 | ha->hdr[j].is_parity = alst2->is_parity; | |
1827 | ha->hdr[j].is_hotfix = alst2->is_hotfix; | |
1828 | ha->hdr[j].master_no = alst2->cd_handle; | |
1829 | } | |
1830 | } | |
1831 | } | |
1832 | } | |
1833 | ||
1834 | /* initialize raw service */ | |
1835 | ha->raw_feat = 0; | |
1836 | if (!force_dma32) { | |
45f1a41b | 1837 | ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_X_INIT_RAW, 0, 0, 0); |
1da177e4 LT |
1838 | if (ok) |
1839 | ha->raw_feat = GDT_64BIT; | |
1840 | } | |
1fe6dbf4 | 1841 | if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC)) |
45f1a41b | 1842 | ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0); |
1da177e4 LT |
1843 | if (!ok) { |
1844 | printk("GDT-HA %d: Initialization error raw service (code %d)\n", | |
45f1a41b | 1845 | ha->hanum, ha->status); |
1da177e4 LT |
1846 | return 0; |
1847 | } | |
1848 | TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n")); | |
1849 | ||
1850 | /* set/get features raw service (scatter/gather) */ | |
45f1a41b BH |
1851 | if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_SET_FEAT, SCATTER_GATHER, |
1852 | 0, 0)) { | |
1da177e4 | 1853 | TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n")); |
45f1a41b | 1854 | if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) { |
1da177e4 LT |
1855 | TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n", |
1856 | ha->info)); | |
1fe6dbf4 | 1857 | ha->raw_feat |= (u16)ha->info; |
1da177e4 LT |
1858 | } |
1859 | } | |
1860 | ||
1861 | /* set/get features cache service (equal to raw service) */ | |
45f1a41b | 1862 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_SET_FEAT, 0, |
1da177e4 LT |
1863 | SCATTER_GATHER,0)) { |
1864 | TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n")); | |
45f1a41b | 1865 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) { |
1da177e4 LT |
1866 | TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n", |
1867 | ha->info)); | |
1fe6dbf4 | 1868 | ha->cache_feat |= (u16)ha->info; |
1da177e4 LT |
1869 | } |
1870 | } | |
1871 | ||
1872 | /* reserve drives for raw service */ | |
1873 | if (reserve_mode != 0) { | |
45f1a41b | 1874 | gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE_ALL, |
1da177e4 LT |
1875 | reserve_mode == 1 ? 1 : 3, 0, 0); |
1876 | TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n", | |
1877 | ha->status)); | |
1878 | } | |
1879 | for (i = 0; i < MAX_RES_ARGS; i += 4) { | |
45f1a41b | 1880 | if (reserve_list[i] == ha->hanum && reserve_list[i+1] < ha->bus_cnt && |
1da177e4 LT |
1881 | reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) { |
1882 | TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n", | |
1883 | reserve_list[i], reserve_list[i+1], | |
1884 | reserve_list[i+2], reserve_list[i+3])); | |
45f1a41b | 1885 | if (!gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESERVE, 0, |
1da177e4 LT |
1886 | reserve_list[i+1], reserve_list[i+2] | |
1887 | (reserve_list[i+3] << 8))) { | |
1888 | printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n", | |
45f1a41b | 1889 | ha->hanum, ha->status); |
1da177e4 LT |
1890 | } |
1891 | } | |
1892 | } | |
1893 | ||
1894 | /* Determine OEM string using IOCTL */ | |
1895 | oemstr = (gdth_oem_str_ioctl *)ha->pscratch; | |
1896 | oemstr->params.ctl_version = 0x01; | |
1897 | oemstr->params.buffer_size = sizeof(oemstr->text); | |
45f1a41b | 1898 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, |
1da177e4 LT |
1899 | CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL, |
1900 | sizeof(gdth_oem_str_ioctl))) { | |
1901 | TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n")); | |
1902 | printk("GDT-HA %d: Vendor: %s Name: %s\n", | |
45f1a41b | 1903 | ha->hanum, oemstr->text.oem_company_name, ha->binfo.type_string); |
1da177e4 | 1904 | /* Save the Host Drive inquiry data */ |
1da177e4 LT |
1905 | strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id, |
1906 | sizeof(ha->oem_name)); | |
1da177e4 LT |
1907 | } else { |
1908 | /* Old method, based on PCI ID */ | |
1909 | TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n")); | |
1910 | printk("GDT-HA %d: Name: %s\n", | |
45f1a41b | 1911 | ha->hanum, ha->binfo.type_string); |
1da177e4 LT |
1912 | if (ha->oem_id == OEM_ID_INTEL) |
1913 | strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name)); | |
1914 | else | |
1915 | strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name)); | |
1da177e4 LT |
1916 | } |
1917 | ||
1918 | /* scanning for host drives */ | |
1919 | for (i = 0; i < cdev_cnt; ++i) | |
45f1a41b | 1920 | gdth_analyse_hdrive(ha, i); |
1da177e4 LT |
1921 | |
1922 | TRACE(("gdth_search_drives() OK\n")); | |
1923 | return 1; | |
1924 | } | |
1925 | ||
1fe6dbf4 | 1926 | static int gdth_analyse_hdrive(gdth_ha_str *ha, u16 hdrive) |
1da177e4 | 1927 | { |
1fe6dbf4 | 1928 | u32 drv_cyls; |
1da177e4 LT |
1929 | int drv_hds, drv_secs; |
1930 | ||
45f1a41b | 1931 | TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive)); |
1da177e4 LT |
1932 | if (hdrive >= MAX_HDRIVES) |
1933 | return 0; | |
1da177e4 | 1934 | |
45f1a41b | 1935 | if (!gdth_internal_cmd(ha, CACHESERVICE, GDT_INFO, hdrive, 0, 0)) |
1da177e4 LT |
1936 | return 0; |
1937 | ha->hdr[hdrive].present = TRUE; | |
1938 | ha->hdr[hdrive].size = ha->info; | |
1939 | ||
1940 | /* evaluate mapping (sectors per head, heads per cylinder) */ | |
1941 | ha->hdr[hdrive].size &= ~SECS32; | |
1942 | if (ha->info2 == 0) { | |
1943 | gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs); | |
1944 | } else { | |
1945 | drv_hds = ha->info2 & 0xff; | |
1946 | drv_secs = (ha->info2 >> 8) & 0xff; | |
1fe6dbf4 | 1947 | drv_cyls = (u32)ha->hdr[hdrive].size / drv_hds / drv_secs; |
1da177e4 | 1948 | } |
1fe6dbf4 DJ |
1949 | ha->hdr[hdrive].heads = (u8)drv_hds; |
1950 | ha->hdr[hdrive].secs = (u8)drv_secs; | |
1da177e4 LT |
1951 | /* round size */ |
1952 | ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs; | |
1953 | ||
1954 | if (ha->cache_feat & GDT_64BIT) { | |
45f1a41b | 1955 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0) |
1da177e4 | 1956 | && ha->info2 != 0) { |
1fe6dbf4 | 1957 | ha->hdr[hdrive].size = ((u64)ha->info2 << 32) | ha->info; |
1da177e4 LT |
1958 | } |
1959 | } | |
1960 | TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n", | |
1961 | hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs)); | |
1962 | ||
1963 | /* get informations about device */ | |
45f1a41b | 1964 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) { |
1da177e4 LT |
1965 | TRACE2(("gdth_search_dr() cache drive %d devtype %d\n", |
1966 | hdrive,ha->info)); | |
1fe6dbf4 | 1967 | ha->hdr[hdrive].devtype = (u16)ha->info; |
1da177e4 LT |
1968 | } |
1969 | ||
1970 | /* cluster info */ | |
45f1a41b | 1971 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_CLUST_INFO, hdrive, 0, 0)) { |
1da177e4 LT |
1972 | TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n", |
1973 | hdrive,ha->info)); | |
1974 | if (!shared_access) | |
1fe6dbf4 | 1975 | ha->hdr[hdrive].cluster_type = (u8)ha->info; |
1da177e4 LT |
1976 | } |
1977 | ||
1978 | /* R/W attributes */ | |
45f1a41b | 1979 | if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) { |
1da177e4 LT |
1980 | TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n", |
1981 | hdrive,ha->info)); | |
1fe6dbf4 | 1982 | ha->hdr[hdrive].rw_attribs = (u8)ha->info; |
1da177e4 LT |
1983 | } |
1984 | ||
1985 | return 1; | |
1986 | } | |
1987 | ||
1988 | ||
1989 | /* command queueing/sending functions */ | |
1990 | ||
1fe6dbf4 | 1991 | static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 priority) |
1da177e4 | 1992 | { |
3058d5de | 1993 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 LT |
1994 | register Scsi_Cmnd *pscp; |
1995 | register Scsi_Cmnd *nscp; | |
1fe6dbf4 | 1996 | unsigned long flags; |
1da177e4 LT |
1997 | |
1998 | TRACE(("gdth_putq() priority %d\n",priority)); | |
1da177e4 LT |
1999 | spin_lock_irqsave(&ha->smp_lock, flags); |
2000 | ||
242f9dcb | 2001 | if (!cmndinfo->internal_command) |
f842b64e | 2002 | cmndinfo->priority = priority; |
1da177e4 LT |
2003 | |
2004 | if (ha->req_first==NULL) { | |
2005 | ha->req_first = scp; /* queue was empty */ | |
2006 | scp->SCp.ptr = NULL; | |
2007 | } else { /* queue not empty */ | |
2008 | pscp = ha->req_first; | |
2009 | nscp = (Scsi_Cmnd *)pscp->SCp.ptr; | |
2010 | /* priority: 0-highest,..,0xff-lowest */ | |
f842b64e | 2011 | while (nscp && gdth_cmnd_priv(nscp)->priority <= priority) { |
1da177e4 LT |
2012 | pscp = nscp; |
2013 | nscp = (Scsi_Cmnd *)pscp->SCp.ptr; | |
2014 | } | |
2015 | pscp->SCp.ptr = (char *)scp; | |
2016 | scp->SCp.ptr = (char *)nscp; | |
2017 | } | |
2018 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
2019 | ||
2020 | #ifdef GDTH_STATISTICS | |
2021 | flags = 0; | |
2022 | for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr) | |
2023 | ++flags; | |
2024 | if (max_rq < flags) { | |
2025 | max_rq = flags; | |
1fe6dbf4 | 2026 | TRACE3(("GDT: max_rq = %d\n",(u16)max_rq)); |
1da177e4 LT |
2027 | } |
2028 | #endif | |
2029 | } | |
2030 | ||
45f1a41b | 2031 | static void gdth_next(gdth_ha_str *ha) |
1da177e4 | 2032 | { |
1da177e4 LT |
2033 | register Scsi_Cmnd *pscp; |
2034 | register Scsi_Cmnd *nscp; | |
1fe6dbf4 DJ |
2035 | u8 b, t, l, firsttime; |
2036 | u8 this_cmd, next_cmd; | |
2037 | unsigned long flags = 0; | |
1da177e4 LT |
2038 | int cmd_index; |
2039 | ||
45f1a41b | 2040 | TRACE(("gdth_next() hanum %d\n", ha->hanum)); |
1da177e4 LT |
2041 | if (!gdth_polling) |
2042 | spin_lock_irqsave(&ha->smp_lock, flags); | |
2043 | ||
2044 | ha->cmd_cnt = ha->cmd_offs_dpmem = 0; | |
2045 | this_cmd = firsttime = TRUE; | |
2046 | next_cmd = gdth_polling ? FALSE:TRUE; | |
2047 | cmd_index = 0; | |
2048 | ||
2049 | for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) { | |
f842b64e | 2050 | struct gdth_cmndinfo *nscp_cmndinfo = gdth_cmnd_priv(nscp); |
1da177e4 LT |
2051 | if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr) |
2052 | pscp = (Scsi_Cmnd *)pscp->SCp.ptr; | |
f842b64e | 2053 | if (!nscp_cmndinfo->internal_command) { |
52759e6a | 2054 | b = nscp->device->channel; |
cbd5f69b LA |
2055 | t = nscp->device->id; |
2056 | l = nscp->device->lun; | |
f842b64e | 2057 | if (nscp_cmndinfo->priority >= DEFAULT_PRI) { |
cbd5f69b LA |
2058 | if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) || |
2059 | (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) | |
2060 | continue; | |
2061 | } | |
2062 | } else | |
2063 | b = t = l = 0; | |
1da177e4 LT |
2064 | |
2065 | if (firsttime) { | |
45f1a41b BH |
2066 | if (gdth_test_busy(ha)) { /* controller busy ? */ |
2067 | TRACE(("gdth_next() controller %d busy !\n", ha->hanum)); | |
1da177e4 LT |
2068 | if (!gdth_polling) { |
2069 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
2070 | return; | |
2071 | } | |
45f1a41b | 2072 | while (gdth_test_busy(ha)) |
1da177e4 LT |
2073 | gdth_delay(1); |
2074 | } | |
2075 | firsttime = FALSE; | |
2076 | } | |
2077 | ||
f842b64e BH |
2078 | if (!nscp_cmndinfo->internal_command) { |
2079 | if (nscp_cmndinfo->phase == -1) { | |
2080 | nscp_cmndinfo->phase = CACHESERVICE; /* default: cache svc. */ | |
1da177e4 LT |
2081 | if (nscp->cmnd[0] == TEST_UNIT_READY) { |
2082 | TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n", | |
2083 | b, t, l)); | |
2084 | /* TEST_UNIT_READY -> set scan mode */ | |
2085 | if ((ha->scan_mode & 0x0f) == 0) { | |
2086 | if (b == 0 && t == 0 && l == 0) { | |
2087 | ha->scan_mode |= 1; | |
2088 | TRACE2(("Scan mode: 0x%x\n", ha->scan_mode)); | |
2089 | } | |
2090 | } else if ((ha->scan_mode & 0x0f) == 1) { | |
2091 | if (b == 0 && ((t == 0 && l == 1) || | |
2092 | (t == 1 && l == 0))) { | |
f842b64e BH |
2093 | nscp_cmndinfo->OpCode = GDT_SCAN_START; |
2094 | nscp_cmndinfo->phase = ((ha->scan_mode & 0x10 ? 1:0) << 8) | |
1da177e4 LT |
2095 | | SCSIRAWSERVICE; |
2096 | ha->scan_mode = 0x12; | |
2097 | TRACE2(("Scan mode: 0x%x (SCAN_START)\n", | |
2098 | ha->scan_mode)); | |
2099 | } else { | |
2100 | ha->scan_mode &= 0x10; | |
2101 | TRACE2(("Scan mode: 0x%x\n", ha->scan_mode)); | |
2102 | } | |
2103 | } else if (ha->scan_mode == 0x12) { | |
2104 | if (b == ha->bus_cnt && t == ha->tid_cnt-1) { | |
f842b64e BH |
2105 | nscp_cmndinfo->phase = SCSIRAWSERVICE; |
2106 | nscp_cmndinfo->OpCode = GDT_SCAN_END; | |
1da177e4 LT |
2107 | ha->scan_mode &= 0x10; |
2108 | TRACE2(("Scan mode: 0x%x (SCAN_END)\n", | |
2109 | ha->scan_mode)); | |
2110 | } | |
2111 | } | |
2112 | } | |
2113 | if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY && | |
2114 | nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE && | |
2115 | (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) { | |
2116 | /* always GDT_CLUST_INFO! */ | |
f842b64e | 2117 | nscp_cmndinfo->OpCode = GDT_CLUST_INFO; |
1da177e4 LT |
2118 | } |
2119 | } | |
2120 | } | |
2121 | ||
f842b64e BH |
2122 | if (nscp_cmndinfo->OpCode != -1) { |
2123 | if ((nscp_cmndinfo->phase & 0xff) == CACHESERVICE) { | |
45f1a41b | 2124 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
1da177e4 LT |
2125 | this_cmd = FALSE; |
2126 | next_cmd = FALSE; | |
f842b64e | 2127 | } else if ((nscp_cmndinfo->phase & 0xff) == SCSIRAWSERVICE) { |
45f1a41b | 2128 | if (!(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b)))) |
1da177e4 LT |
2129 | this_cmd = FALSE; |
2130 | next_cmd = FALSE; | |
2131 | } else { | |
2132 | memset((char*)nscp->sense_buffer,0,16); | |
2133 | nscp->sense_buffer[0] = 0x70; | |
2134 | nscp->sense_buffer[2] = NOT_READY; | |
2135 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | |
f842b64e BH |
2136 | if (!nscp_cmndinfo->wait_for_completion) |
2137 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2138 | else |
b8bff2ae | 2139 | gdth_scsi_done(nscp); |
1da177e4 | 2140 | } |
3058d5de | 2141 | } else if (gdth_cmnd_priv(nscp)->internal_command) { |
45f1a41b | 2142 | if (!(cmd_index=gdth_special_cmd(ha, nscp))) |
1da177e4 LT |
2143 | this_cmd = FALSE; |
2144 | next_cmd = FALSE; | |
2145 | } else if (b != ha->virt_bus) { | |
2146 | if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW || | |
45f1a41b | 2147 | !(cmd_index=gdth_fill_raw_cmd(ha, nscp, BUS_L2P(ha, b)))) |
1da177e4 LT |
2148 | this_cmd = FALSE; |
2149 | else | |
2150 | ha->raw[BUS_L2P(ha,b)].io_cnt[t]++; | |
2151 | } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) { | |
2152 | TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n", | |
2153 | nscp->cmnd[0], b, t, l)); | |
2154 | nscp->result = DID_BAD_TARGET << 16; | |
f842b64e BH |
2155 | if (!nscp_cmndinfo->wait_for_completion) |
2156 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2157 | else |
b8bff2ae | 2158 | gdth_scsi_done(nscp); |
1da177e4 LT |
2159 | } else { |
2160 | switch (nscp->cmnd[0]) { | |
2161 | case TEST_UNIT_READY: | |
2162 | case INQUIRY: | |
2163 | case REQUEST_SENSE: | |
2164 | case READ_CAPACITY: | |
2165 | case VERIFY: | |
2166 | case START_STOP: | |
2167 | case MODE_SENSE: | |
2168 | case SERVICE_ACTION_IN: | |
2169 | TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], | |
2170 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], | |
2171 | nscp->cmnd[4],nscp->cmnd[5])); | |
2172 | if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) { | |
2173 | /* return UNIT_ATTENTION */ | |
2174 | TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n", | |
2175 | nscp->cmnd[0], t)); | |
2176 | ha->hdr[t].media_changed = FALSE; | |
2177 | memset((char*)nscp->sense_buffer,0,16); | |
2178 | nscp->sense_buffer[0] = 0x70; | |
2179 | nscp->sense_buffer[2] = UNIT_ATTENTION; | |
2180 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | |
f842b64e BH |
2181 | if (!nscp_cmndinfo->wait_for_completion) |
2182 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2183 | else |
b8bff2ae | 2184 | gdth_scsi_done(nscp); |
45f1a41b | 2185 | } else if (gdth_internal_cache_cmd(ha, nscp)) |
b8bff2ae | 2186 | gdth_scsi_done(nscp); |
1da177e4 LT |
2187 | break; |
2188 | ||
2189 | case ALLOW_MEDIUM_REMOVAL: | |
2190 | TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], | |
2191 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], | |
2192 | nscp->cmnd[4],nscp->cmnd[5])); | |
2193 | if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) { | |
2194 | TRACE(("Prevent r. nonremov. drive->do nothing\n")); | |
2195 | nscp->result = DID_OK << 16; | |
2196 | nscp->sense_buffer[0] = 0; | |
f842b64e BH |
2197 | if (!nscp_cmndinfo->wait_for_completion) |
2198 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2199 | else |
b8bff2ae | 2200 | gdth_scsi_done(nscp); |
1da177e4 LT |
2201 | } else { |
2202 | nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0; | |
2203 | TRACE(("Prevent/allow r. %d rem. drive %d\n", | |
2204 | nscp->cmnd[4],nscp->cmnd[3])); | |
45f1a41b | 2205 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
1da177e4 LT |
2206 | this_cmd = FALSE; |
2207 | } | |
2208 | break; | |
2209 | ||
2210 | case RESERVE: | |
2211 | case RELEASE: | |
2212 | TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ? | |
2213 | "RESERVE" : "RELEASE")); | |
45f1a41b | 2214 | if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
1da177e4 LT |
2215 | this_cmd = FALSE; |
2216 | break; | |
2217 | ||
2218 | case READ_6: | |
2219 | case WRITE_6: | |
2220 | case READ_10: | |
2221 | case WRITE_10: | |
2222 | case READ_16: | |
2223 | case WRITE_16: | |
2224 | if (ha->hdr[t].media_changed) { | |
2225 | /* return UNIT_ATTENTION */ | |
2226 | TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n", | |
2227 | nscp->cmnd[0], t)); | |
2228 | ha->hdr[t].media_changed = FALSE; | |
2229 | memset((char*)nscp->sense_buffer,0,16); | |
2230 | nscp->sense_buffer[0] = 0x70; | |
2231 | nscp->sense_buffer[2] = UNIT_ATTENTION; | |
2232 | nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | |
f842b64e BH |
2233 | if (!nscp_cmndinfo->wait_for_completion) |
2234 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2235 | else |
b8bff2ae | 2236 | gdth_scsi_done(nscp); |
45f1a41b | 2237 | } else if (!(cmd_index=gdth_fill_cache_cmd(ha, nscp, t))) |
1da177e4 LT |
2238 | this_cmd = FALSE; |
2239 | break; | |
2240 | ||
2241 | default: | |
2242 | TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0], | |
2243 | nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], | |
2244 | nscp->cmnd[4],nscp->cmnd[5])); | |
2245 | printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n", | |
45f1a41b | 2246 | ha->hanum, nscp->cmnd[0]); |
1da177e4 | 2247 | nscp->result = DID_ABORT << 16; |
f842b64e BH |
2248 | if (!nscp_cmndinfo->wait_for_completion) |
2249 | nscp_cmndinfo->wait_for_completion++; | |
1da177e4 | 2250 | else |
b8bff2ae | 2251 | gdth_scsi_done(nscp); |
1da177e4 LT |
2252 | break; |
2253 | } | |
2254 | } | |
2255 | ||
2256 | if (!this_cmd) | |
2257 | break; | |
2258 | if (nscp == ha->req_first) | |
2259 | ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr; | |
2260 | else | |
2261 | pscp->SCp.ptr = nscp->SCp.ptr; | |
2262 | if (!next_cmd) | |
2263 | break; | |
2264 | } | |
2265 | ||
2266 | if (ha->cmd_cnt > 0) { | |
45f1a41b | 2267 | gdth_release_event(ha); |
1da177e4 LT |
2268 | } |
2269 | ||
2270 | if (!gdth_polling) | |
2271 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
2272 | ||
2273 | if (gdth_polling && ha->cmd_cnt > 0) { | |
45f1a41b | 2274 | if (!gdth_wait(ha, cmd_index, POLL_TIMEOUT)) |
1da177e4 | 2275 | printk("GDT-HA %d: Command %d timed out !\n", |
45f1a41b | 2276 | ha->hanum, cmd_index); |
1da177e4 LT |
2277 | } |
2278 | } | |
3892d88a BH |
2279 | |
2280 | /* | |
2281 | * gdth_copy_internal_data() - copy to/from a buffer onto a scsi_cmnd's | |
2282 | * buffers, kmap_atomic() as needed. | |
2283 | */ | |
45f1a41b | 2284 | static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, |
1fe6dbf4 | 2285 | char *buffer, u16 count) |
1da177e4 | 2286 | { |
1fe6dbf4 DJ |
2287 | u16 cpcount,i, max_sg = scsi_sg_count(scp); |
2288 | u16 cpsum,cpnow; | |
1da177e4 | 2289 | struct scatterlist *sl; |
1da177e4 LT |
2290 | char *address; |
2291 | ||
1fe6dbf4 | 2292 | cpcount = min_t(u16, count, scsi_bufflen(scp)); |
1da177e4 | 2293 | |
3892d88a BH |
2294 | if (cpcount) { |
2295 | cpsum=0; | |
2296 | scsi_for_each_sg(scp, sl, max_sg, i) { | |
cbd5f69b | 2297 | unsigned long flags; |
1fe6dbf4 | 2298 | cpnow = (u16)sl->length; |
1da177e4 | 2299 | TRACE(("copy_internal() now %d sum %d count %d %d\n", |
d35055a0 | 2300 | cpnow, cpsum, cpcount, scsi_bufflen(scp))); |
1da177e4 LT |
2301 | if (cpsum+cpnow > cpcount) |
2302 | cpnow = cpcount - cpsum; | |
2303 | cpsum += cpnow; | |
45711f1a | 2304 | if (!sg_page(sl)) { |
1da177e4 | 2305 | printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n", |
45f1a41b | 2306 | ha->hanum); |
1da177e4 LT |
2307 | return; |
2308 | } | |
cbd5f69b | 2309 | local_irq_save(flags); |
45711f1a | 2310 | address = kmap_atomic(sg_page(sl), KM_BIO_SRC_IRQ) + sl->offset; |
ee54cc6a | 2311 | memcpy(address, buffer, cpnow); |
45711f1a | 2312 | flush_dcache_page(sg_page(sl)); |
cbd5f69b | 2313 | kunmap_atomic(address, KM_BIO_SRC_IRQ); |
cbd5f69b | 2314 | local_irq_restore(flags); |
1da177e4 LT |
2315 | if (cpsum == cpcount) |
2316 | break; | |
2317 | buffer += cpnow; | |
2318 | } | |
3892d88a BH |
2319 | } else if (count) { |
2320 | printk("GDT-HA %d: SCSI command with no buffers but data transfer expected!\n", | |
2321 | ha->hanum); | |
2322 | WARN_ON(1); | |
1da177e4 LT |
2323 | } |
2324 | } | |
2325 | ||
45f1a41b | 2326 | static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp) |
1da177e4 | 2327 | { |
1fe6dbf4 | 2328 | u8 t; |
1da177e4 LT |
2329 | gdth_inq_data inq; |
2330 | gdth_rdcap_data rdc; | |
2331 | gdth_sense_data sd; | |
2332 | gdth_modep_data mpd; | |
f842b64e | 2333 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 | 2334 | |
1da177e4 LT |
2335 | t = scp->device->id; |
2336 | TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n", | |
2337 | scp->cmnd[0],t)); | |
2338 | ||
2339 | scp->result = DID_OK << 16; | |
2340 | scp->sense_buffer[0] = 0; | |
2341 | ||
2342 | switch (scp->cmnd[0]) { | |
2343 | case TEST_UNIT_READY: | |
2344 | case VERIFY: | |
2345 | case START_STOP: | |
2346 | TRACE2(("Test/Verify/Start hdrive %d\n",t)); | |
2347 | break; | |
2348 | ||
2349 | case INQUIRY: | |
2350 | TRACE2(("Inquiry hdrive %d devtype %d\n", | |
2351 | t,ha->hdr[t].devtype)); | |
2352 | inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK; | |
2353 | /* you can here set all disks to removable, if you want to do | |
2354 | a flush using the ALLOW_MEDIUM_REMOVAL command */ | |
2355 | inq.modif_rmb = 0x00; | |
2356 | if ((ha->hdr[t].devtype & 1) || | |
2357 | (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) | |
2358 | inq.modif_rmb = 0x80; | |
2359 | inq.version = 2; | |
2360 | inq.resp_aenc = 2; | |
2361 | inq.add_length= 32; | |
2362 | strcpy(inq.vendor,ha->oem_name); | |
2363 | sprintf(inq.product,"Host Drive #%02d",t); | |
2364 | strcpy(inq.revision," "); | |
ee54cc6a | 2365 | gdth_copy_internal_data(ha, scp, (char*)&inq, sizeof(gdth_inq_data)); |
1da177e4 LT |
2366 | break; |
2367 | ||
2368 | case REQUEST_SENSE: | |
2369 | TRACE2(("Request sense hdrive %d\n",t)); | |
2370 | sd.errorcode = 0x70; | |
2371 | sd.segno = 0x00; | |
2372 | sd.key = NO_SENSE; | |
2373 | sd.info = 0; | |
2374 | sd.add_length= 0; | |
ee54cc6a | 2375 | gdth_copy_internal_data(ha, scp, (char*)&sd, sizeof(gdth_sense_data)); |
1da177e4 LT |
2376 | break; |
2377 | ||
2378 | case MODE_SENSE: | |
2379 | TRACE2(("Mode sense hdrive %d\n",t)); | |
2380 | memset((char*)&mpd,0,sizeof(gdth_modep_data)); | |
2381 | mpd.hd.data_length = sizeof(gdth_modep_data); | |
2382 | mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0; | |
2383 | mpd.hd.bd_length = sizeof(mpd.bd); | |
2384 | mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16; | |
2385 | mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8; | |
2386 | mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff); | |
ee54cc6a | 2387 | gdth_copy_internal_data(ha, scp, (char*)&mpd, sizeof(gdth_modep_data)); |
1da177e4 LT |
2388 | break; |
2389 | ||
2390 | case READ_CAPACITY: | |
2391 | TRACE2(("Read capacity hdrive %d\n",t)); | |
1fe6dbf4 | 2392 | if (ha->hdr[t].size > (u64)0xffffffff) |
1da177e4 LT |
2393 | rdc.last_block_no = 0xffffffff; |
2394 | else | |
2395 | rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1); | |
2396 | rdc.block_length = cpu_to_be32(SECTOR_SIZE); | |
ee54cc6a | 2397 | gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data)); |
1da177e4 LT |
2398 | break; |
2399 | ||
2400 | case SERVICE_ACTION_IN: | |
2401 | if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 && | |
2402 | (ha->cache_feat & GDT_64BIT)) { | |
2403 | gdth_rdcap16_data rdc16; | |
2404 | ||
2405 | TRACE2(("Read capacity (16) hdrive %d\n",t)); | |
2406 | rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1); | |
2407 | rdc16.block_length = cpu_to_be32(SECTOR_SIZE); | |
45f1a41b | 2408 | gdth_copy_internal_data(ha, scp, (char*)&rdc16, |
ee54cc6a | 2409 | sizeof(gdth_rdcap16_data)); |
1da177e4 LT |
2410 | } else { |
2411 | scp->result = DID_ABORT << 16; | |
2412 | } | |
2413 | break; | |
2414 | ||
2415 | default: | |
2416 | TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0])); | |
2417 | break; | |
2418 | } | |
2419 | ||
f842b64e BH |
2420 | if (!cmndinfo->wait_for_completion) |
2421 | cmndinfo->wait_for_completion++; | |
1da177e4 LT |
2422 | else |
2423 | return 1; | |
2424 | ||
2425 | return 0; | |
2426 | } | |
45f1a41b | 2427 | |
1fe6dbf4 | 2428 | static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u16 hdrive) |
1da177e4 | 2429 | { |
1da177e4 | 2430 | register gdth_cmd_str *cmdp; |
f842b64e | 2431 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
1fe6dbf4 DJ |
2432 | u32 cnt, blockcnt; |
2433 | u64 no, blockno; | |
1da177e4 | 2434 | int i, cmd_index, read_write, sgcnt, mode64; |
1da177e4 | 2435 | |
1da177e4 LT |
2436 | cmdp = ha->pccb; |
2437 | TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n", | |
2438 | scp->cmnd[0],scp->cmd_len,hdrive)); | |
2439 | ||
2440 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) | |
2441 | return 0; | |
2442 | ||
2443 | mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE; | |
2444 | /* test for READ_16, WRITE_16 if !mode64 ? --- | |
2445 | not required, should not occur due to error return on | |
2446 | READ_CAPACITY_16 */ | |
2447 | ||
2448 | cmdp->Service = CACHESERVICE; | |
2449 | cmdp->RequestBuffer = scp; | |
2450 | /* search free command index */ | |
45f1a41b | 2451 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
1da177e4 LT |
2452 | TRACE(("GDT: No free command index found\n")); |
2453 | return 0; | |
2454 | } | |
2455 | /* if it's the first command, set command semaphore */ | |
2456 | if (ha->cmd_cnt == 0) | |
45f1a41b | 2457 | gdth_set_sema0(ha); |
1da177e4 LT |
2458 | |
2459 | /* fill command */ | |
2460 | read_write = 0; | |
f842b64e BH |
2461 | if (cmndinfo->OpCode != -1) |
2462 | cmdp->OpCode = cmndinfo->OpCode; /* special cache cmd. */ | |
1da177e4 LT |
2463 | else if (scp->cmnd[0] == RESERVE) |
2464 | cmdp->OpCode = GDT_RESERVE_DRV; | |
2465 | else if (scp->cmnd[0] == RELEASE) | |
2466 | cmdp->OpCode = GDT_RELEASE_DRV; | |
2467 | else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { | |
2468 | if (scp->cmnd[4] & 1) /* prevent ? */ | |
2469 | cmdp->OpCode = GDT_MOUNT; | |
2470 | else if (scp->cmnd[3] & 1) /* removable drive ? */ | |
2471 | cmdp->OpCode = GDT_UNMOUNT; | |
2472 | else | |
2473 | cmdp->OpCode = GDT_FLUSH; | |
2474 | } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 || | |
2475 | scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16 | |
2476 | ) { | |
2477 | read_write = 1; | |
2478 | if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) && | |
2479 | (ha->cache_feat & GDT_WR_THROUGH))) | |
2480 | cmdp->OpCode = GDT_WRITE_THR; | |
2481 | else | |
2482 | cmdp->OpCode = GDT_WRITE; | |
2483 | } else { | |
2484 | read_write = 2; | |
2485 | cmdp->OpCode = GDT_READ; | |
2486 | } | |
2487 | ||
2488 | cmdp->BoardNode = LOCALBOARD; | |
2489 | if (mode64) { | |
2490 | cmdp->u.cache64.DeviceNo = hdrive; | |
2491 | cmdp->u.cache64.BlockNo = 1; | |
2492 | cmdp->u.cache64.sg_canz = 0; | |
2493 | } else { | |
2494 | cmdp->u.cache.DeviceNo = hdrive; | |
2495 | cmdp->u.cache.BlockNo = 1; | |
2496 | cmdp->u.cache.sg_canz = 0; | |
2497 | } | |
2498 | ||
2499 | if (read_write) { | |
2500 | if (scp->cmd_len == 16) { | |
1fe6dbf4 | 2501 | memcpy(&no, &scp->cmnd[2], sizeof(u64)); |
1da177e4 | 2502 | blockno = be64_to_cpu(no); |
1fe6dbf4 | 2503 | memcpy(&cnt, &scp->cmnd[10], sizeof(u32)); |
1da177e4 LT |
2504 | blockcnt = be32_to_cpu(cnt); |
2505 | } else if (scp->cmd_len == 10) { | |
1fe6dbf4 | 2506 | memcpy(&no, &scp->cmnd[2], sizeof(u32)); |
1da177e4 | 2507 | blockno = be32_to_cpu(no); |
1fe6dbf4 | 2508 | memcpy(&cnt, &scp->cmnd[7], sizeof(u16)); |
1da177e4 LT |
2509 | blockcnt = be16_to_cpu(cnt); |
2510 | } else { | |
1fe6dbf4 | 2511 | memcpy(&no, &scp->cmnd[0], sizeof(u32)); |
1da177e4 LT |
2512 | blockno = be32_to_cpu(no) & 0x001fffffUL; |
2513 | blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4]; | |
2514 | } | |
2515 | if (mode64) { | |
2516 | cmdp->u.cache64.BlockNo = blockno; | |
2517 | cmdp->u.cache64.BlockCnt = blockcnt; | |
2518 | } else { | |
1fe6dbf4 | 2519 | cmdp->u.cache.BlockNo = (u32)blockno; |
1da177e4 LT |
2520 | cmdp->u.cache.BlockCnt = blockcnt; |
2521 | } | |
2522 | ||
d35055a0 | 2523 | if (scsi_bufflen(scp)) { |
f842b64e | 2524 | cmndinfo->dma_dir = (read_write == 1 ? |
1da177e4 | 2525 | PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); |
d35055a0 | 2526 | sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), |
3892d88a | 2527 | cmndinfo->dma_dir); |
1da177e4 | 2528 | if (mode64) { |
3892d88a BH |
2529 | struct scatterlist *sl; |
2530 | ||
1fe6dbf4 | 2531 | cmdp->u.cache64.DestAddr= (u64)-1; |
1da177e4 | 2532 | cmdp->u.cache64.sg_canz = sgcnt; |
3892d88a | 2533 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
1da177e4 LT |
2534 | cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl); |
2535 | #ifdef GDTH_DMA_STATISTICS | |
1fe6dbf4 | 2536 | if (cmdp->u.cache64.sg_lst[i].sg_ptr > (u64)0xffffffff) |
1da177e4 LT |
2537 | ha->dma64_cnt++; |
2538 | else | |
2539 | ha->dma32_cnt++; | |
2540 | #endif | |
2541 | cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl); | |
2542 | } | |
2543 | } else { | |
3892d88a BH |
2544 | struct scatterlist *sl; |
2545 | ||
1da177e4 LT |
2546 | cmdp->u.cache.DestAddr= 0xffffffff; |
2547 | cmdp->u.cache.sg_canz = sgcnt; | |
3892d88a | 2548 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
1da177e4 LT |
2549 | cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl); |
2550 | #ifdef GDTH_DMA_STATISTICS | |
2551 | ha->dma32_cnt++; | |
2552 | #endif | |
2553 | cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl); | |
2554 | } | |
2555 | } | |
2556 | ||
2557 | #ifdef GDTH_STATISTICS | |
1fe6dbf4 DJ |
2558 | if (max_sg < (u32)sgcnt) { |
2559 | max_sg = (u32)sgcnt; | |
1da177e4 LT |
2560 | TRACE3(("GDT: max_sg = %d\n",max_sg)); |
2561 | } | |
2562 | #endif | |
2563 | ||
1da177e4 LT |
2564 | } |
2565 | } | |
2566 | /* evaluate command size, check space */ | |
2567 | if (mode64) { | |
2568 | TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", | |
2569 | cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz, | |
2570 | cmdp->u.cache64.sg_lst[0].sg_ptr, | |
2571 | cmdp->u.cache64.sg_lst[0].sg_len)); | |
2572 | TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", | |
2573 | cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt)); | |
2574 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + | |
1fe6dbf4 | 2575 | (u16)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str); |
1da177e4 LT |
2576 | } else { |
2577 | TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", | |
2578 | cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz, | |
2579 | cmdp->u.cache.sg_lst[0].sg_ptr, | |
2580 | cmdp->u.cache.sg_lst[0].sg_len)); | |
2581 | TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", | |
2582 | cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt)); | |
2583 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + | |
1fe6dbf4 | 2584 | (u16)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str); |
1da177e4 LT |
2585 | } |
2586 | if (ha->cmd_len & 3) | |
2587 | ha->cmd_len += (4 - (ha->cmd_len & 3)); | |
2588 | ||
2589 | if (ha->cmd_cnt > 0) { | |
2590 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > | |
2591 | ha->ic_all_size) { | |
2592 | TRACE2(("gdth_fill_cache() DPMEM overflow\n")); | |
2593 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; | |
2594 | return 0; | |
2595 | } | |
2596 | } | |
2597 | ||
2598 | /* copy command */ | |
45f1a41b | 2599 | gdth_copy_command(ha); |
1da177e4 LT |
2600 | return cmd_index; |
2601 | } | |
2602 | ||
1fe6dbf4 | 2603 | static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 b) |
1da177e4 | 2604 | { |
1da177e4 | 2605 | register gdth_cmd_str *cmdp; |
1fe6dbf4 | 2606 | u16 i; |
3892d88a | 2607 | dma_addr_t sense_paddr; |
1da177e4 | 2608 | int cmd_index, sgcnt, mode64; |
1fe6dbf4 | 2609 | u8 t,l; |
1da177e4 | 2610 | struct page *page; |
1fe6dbf4 | 2611 | unsigned long offset; |
3058d5de | 2612 | struct gdth_cmndinfo *cmndinfo; |
1da177e4 | 2613 | |
1da177e4 LT |
2614 | t = scp->device->id; |
2615 | l = scp->device->lun; | |
2616 | cmdp = ha->pccb; | |
2617 | TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n", | |
2618 | scp->cmnd[0],b,t,l)); | |
2619 | ||
2620 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) | |
2621 | return 0; | |
2622 | ||
2623 | mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE; | |
2624 | ||
2625 | cmdp->Service = SCSIRAWSERVICE; | |
2626 | cmdp->RequestBuffer = scp; | |
2627 | /* search free command index */ | |
45f1a41b | 2628 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
1da177e4 LT |
2629 | TRACE(("GDT: No free command index found\n")); |
2630 | return 0; | |
2631 | } | |
2632 | /* if it's the first command, set command semaphore */ | |
2633 | if (ha->cmd_cnt == 0) | |
45f1a41b | 2634 | gdth_set_sema0(ha); |
1da177e4 | 2635 | |
3058d5de | 2636 | cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 | 2637 | /* fill command */ |
f842b64e BH |
2638 | if (cmndinfo->OpCode != -1) { |
2639 | cmdp->OpCode = cmndinfo->OpCode; /* special raw cmd. */ | |
1da177e4 LT |
2640 | cmdp->BoardNode = LOCALBOARD; |
2641 | if (mode64) { | |
f842b64e | 2642 | cmdp->u.raw64.direction = (cmndinfo->phase >> 8); |
1da177e4 LT |
2643 | TRACE2(("special raw cmd 0x%x param 0x%x\n", |
2644 | cmdp->OpCode, cmdp->u.raw64.direction)); | |
2645 | /* evaluate command size */ | |
2646 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst); | |
2647 | } else { | |
f842b64e | 2648 | cmdp->u.raw.direction = (cmndinfo->phase >> 8); |
1da177e4 LT |
2649 | TRACE2(("special raw cmd 0x%x param 0x%x\n", |
2650 | cmdp->OpCode, cmdp->u.raw.direction)); | |
2651 | /* evaluate command size */ | |
2652 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst); | |
2653 | } | |
2654 | ||
2655 | } else { | |
2656 | page = virt_to_page(scp->sense_buffer); | |
1fe6dbf4 | 2657 | offset = (unsigned long)scp->sense_buffer & ~PAGE_MASK; |
1da177e4 LT |
2658 | sense_paddr = pci_map_page(ha->pdev,page,offset, |
2659 | 16,PCI_DMA_FROMDEVICE); | |
3058d5de BH |
2660 | |
2661 | cmndinfo->sense_paddr = sense_paddr; | |
1da177e4 LT |
2662 | cmdp->OpCode = GDT_WRITE; /* always */ |
2663 | cmdp->BoardNode = LOCALBOARD; | |
2664 | if (mode64) { | |
2665 | cmdp->u.raw64.reserved = 0; | |
2666 | cmdp->u.raw64.mdisc_time = 0; | |
2667 | cmdp->u.raw64.mcon_time = 0; | |
2668 | cmdp->u.raw64.clen = scp->cmd_len; | |
2669 | cmdp->u.raw64.target = t; | |
2670 | cmdp->u.raw64.lun = l; | |
2671 | cmdp->u.raw64.bus = b; | |
2672 | cmdp->u.raw64.priority = 0; | |
d35055a0 | 2673 | cmdp->u.raw64.sdlen = scsi_bufflen(scp); |
1da177e4 LT |
2674 | cmdp->u.raw64.sense_len = 16; |
2675 | cmdp->u.raw64.sense_data = sense_paddr; | |
2676 | cmdp->u.raw64.direction = | |
2677 | gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN; | |
2678 | memcpy(cmdp->u.raw64.cmd,scp->cmnd,16); | |
bb9ba31c | 2679 | cmdp->u.raw64.sg_ranz = 0; |
1da177e4 LT |
2680 | } else { |
2681 | cmdp->u.raw.reserved = 0; | |
2682 | cmdp->u.raw.mdisc_time = 0; | |
2683 | cmdp->u.raw.mcon_time = 0; | |
2684 | cmdp->u.raw.clen = scp->cmd_len; | |
2685 | cmdp->u.raw.target = t; | |
2686 | cmdp->u.raw.lun = l; | |
2687 | cmdp->u.raw.bus = b; | |
2688 | cmdp->u.raw.priority = 0; | |
2689 | cmdp->u.raw.link_p = 0; | |
d35055a0 | 2690 | cmdp->u.raw.sdlen = scsi_bufflen(scp); |
1da177e4 LT |
2691 | cmdp->u.raw.sense_len = 16; |
2692 | cmdp->u.raw.sense_data = sense_paddr; | |
2693 | cmdp->u.raw.direction = | |
2694 | gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN; | |
2695 | memcpy(cmdp->u.raw.cmd,scp->cmnd,12); | |
bb9ba31c | 2696 | cmdp->u.raw.sg_ranz = 0; |
1da177e4 LT |
2697 | } |
2698 | ||
d35055a0 | 2699 | if (scsi_bufflen(scp)) { |
f842b64e | 2700 | cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL; |
d35055a0 | 2701 | sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), |
3892d88a | 2702 | cmndinfo->dma_dir); |
1da177e4 | 2703 | if (mode64) { |
3892d88a BH |
2704 | struct scatterlist *sl; |
2705 | ||
1fe6dbf4 | 2706 | cmdp->u.raw64.sdata = (u64)-1; |
1da177e4 | 2707 | cmdp->u.raw64.sg_ranz = sgcnt; |
3892d88a | 2708 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
1da177e4 LT |
2709 | cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl); |
2710 | #ifdef GDTH_DMA_STATISTICS | |
1fe6dbf4 | 2711 | if (cmdp->u.raw64.sg_lst[i].sg_ptr > (u64)0xffffffff) |
1da177e4 LT |
2712 | ha->dma64_cnt++; |
2713 | else | |
2714 | ha->dma32_cnt++; | |
2715 | #endif | |
2716 | cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl); | |
2717 | } | |
2718 | } else { | |
3892d88a BH |
2719 | struct scatterlist *sl; |
2720 | ||
1da177e4 LT |
2721 | cmdp->u.raw.sdata = 0xffffffff; |
2722 | cmdp->u.raw.sg_ranz = sgcnt; | |
3892d88a | 2723 | scsi_for_each_sg(scp, sl, sgcnt, i) { |
1da177e4 LT |
2724 | cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl); |
2725 | #ifdef GDTH_DMA_STATISTICS | |
2726 | ha->dma32_cnt++; | |
2727 | #endif | |
2728 | cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl); | |
2729 | } | |
2730 | } | |
2731 | ||
2732 | #ifdef GDTH_STATISTICS | |
2733 | if (max_sg < sgcnt) { | |
2734 | max_sg = sgcnt; | |
2735 | TRACE3(("GDT: max_sg = %d\n",sgcnt)); | |
2736 | } | |
2737 | #endif | |
2738 | ||
1da177e4 LT |
2739 | } |
2740 | if (mode64) { | |
2741 | TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", | |
2742 | cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz, | |
2743 | cmdp->u.raw64.sg_lst[0].sg_ptr, | |
2744 | cmdp->u.raw64.sg_lst[0].sg_len)); | |
2745 | /* evaluate command size */ | |
2746 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + | |
1fe6dbf4 | 2747 | (u16)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str); |
1da177e4 LT |
2748 | } else { |
2749 | TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", | |
2750 | cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz, | |
2751 | cmdp->u.raw.sg_lst[0].sg_ptr, | |
2752 | cmdp->u.raw.sg_lst[0].sg_len)); | |
2753 | /* evaluate command size */ | |
2754 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + | |
1fe6dbf4 | 2755 | (u16)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str); |
1da177e4 LT |
2756 | } |
2757 | } | |
2758 | /* check space */ | |
2759 | if (ha->cmd_len & 3) | |
2760 | ha->cmd_len += (4 - (ha->cmd_len & 3)); | |
2761 | ||
2762 | if (ha->cmd_cnt > 0) { | |
2763 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > | |
2764 | ha->ic_all_size) { | |
2765 | TRACE2(("gdth_fill_raw() DPMEM overflow\n")); | |
2766 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; | |
2767 | return 0; | |
2768 | } | |
2769 | } | |
2770 | ||
2771 | /* copy command */ | |
45f1a41b | 2772 | gdth_copy_command(ha); |
1da177e4 LT |
2773 | return cmd_index; |
2774 | } | |
2775 | ||
45f1a41b | 2776 | static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp) |
1da177e4 | 2777 | { |
1da177e4 | 2778 | register gdth_cmd_str *cmdp; |
ee54cc6a | 2779 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 LT |
2780 | int cmd_index; |
2781 | ||
1da177e4 LT |
2782 | cmdp= ha->pccb; |
2783 | TRACE2(("gdth_special_cmd(): ")); | |
2784 | ||
2785 | if (ha->type==GDT_EISA && ha->cmd_cnt>0) | |
2786 | return 0; | |
2787 | ||
ee54cc6a | 2788 | *cmdp = *cmndinfo->internal_cmd_str; |
1da177e4 LT |
2789 | cmdp->RequestBuffer = scp; |
2790 | ||
2791 | /* search free command index */ | |
45f1a41b | 2792 | if (!(cmd_index=gdth_get_cmd_index(ha))) { |
1da177e4 LT |
2793 | TRACE(("GDT: No free command index found\n")); |
2794 | return 0; | |
2795 | } | |
2796 | ||
2797 | /* if it's the first command, set command semaphore */ | |
2798 | if (ha->cmd_cnt == 0) | |
45f1a41b | 2799 | gdth_set_sema0(ha); |
1da177e4 LT |
2800 | |
2801 | /* evaluate command size, check space */ | |
2802 | if (cmdp->OpCode == GDT_IOCTL) { | |
2803 | TRACE2(("IOCTL\n")); | |
2804 | ha->cmd_len = | |
1fe6dbf4 | 2805 | GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(u64); |
1da177e4 LT |
2806 | } else if (cmdp->Service == CACHESERVICE) { |
2807 | TRACE2(("cache command %d\n",cmdp->OpCode)); | |
2808 | if (ha->cache_feat & GDT_64BIT) | |
2809 | ha->cmd_len = | |
2810 | GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str); | |
2811 | else | |
2812 | ha->cmd_len = | |
2813 | GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str); | |
2814 | } else if (cmdp->Service == SCSIRAWSERVICE) { | |
2815 | TRACE2(("raw command %d\n",cmdp->OpCode)); | |
2816 | if (ha->raw_feat & GDT_64BIT) | |
2817 | ha->cmd_len = | |
2818 | GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str); | |
2819 | else | |
2820 | ha->cmd_len = | |
2821 | GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str); | |
2822 | } | |
2823 | ||
2824 | if (ha->cmd_len & 3) | |
2825 | ha->cmd_len += (4 - (ha->cmd_len & 3)); | |
2826 | ||
2827 | if (ha->cmd_cnt > 0) { | |
2828 | if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) > | |
2829 | ha->ic_all_size) { | |
2830 | TRACE2(("gdth_special_cmd() DPMEM overflow\n")); | |
2831 | ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND; | |
2832 | return 0; | |
2833 | } | |
2834 | } | |
2835 | ||
2836 | /* copy command */ | |
45f1a41b | 2837 | gdth_copy_command(ha); |
1da177e4 LT |
2838 | return cmd_index; |
2839 | } | |
2840 | ||
2841 | ||
2842 | /* Controller event handling functions */ | |
1fe6dbf4 DJ |
2843 | static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, u16 source, |
2844 | u16 idx, gdth_evt_data *evt) | |
1da177e4 LT |
2845 | { |
2846 | gdth_evt_str *e; | |
2847 | struct timeval tv; | |
2848 | ||
2849 | /* no GDTH_LOCK_HA() ! */ | |
2850 | TRACE2(("gdth_store_event() source %d idx %d\n", source, idx)); | |
2851 | if (source == 0) /* no source -> no event */ | |
2852 | return NULL; | |
2853 | ||
2854 | if (ebuffer[elastidx].event_source == source && | |
2855 | ebuffer[elastidx].event_idx == idx && | |
2856 | ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 && | |
2857 | !memcmp((char *)&ebuffer[elastidx].event_data.eu, | |
2858 | (char *)&evt->eu, evt->size)) || | |
2859 | (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 && | |
2860 | !strcmp((char *)&ebuffer[elastidx].event_data.event_string, | |
2861 | (char *)&evt->event_string)))) { | |
2862 | e = &ebuffer[elastidx]; | |
2863 | do_gettimeofday(&tv); | |
2864 | e->last_stamp = tv.tv_sec; | |
2865 | ++e->same_count; | |
2866 | } else { | |
2867 | if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */ | |
2868 | ++elastidx; | |
2869 | if (elastidx == MAX_EVENTS) | |
2870 | elastidx = 0; | |
2871 | if (elastidx == eoldidx) { /* reached mark ? */ | |
2872 | ++eoldidx; | |
2873 | if (eoldidx == MAX_EVENTS) | |
2874 | eoldidx = 0; | |
2875 | } | |
2876 | } | |
2877 | e = &ebuffer[elastidx]; | |
2878 | e->event_source = source; | |
2879 | e->event_idx = idx; | |
2880 | do_gettimeofday(&tv); | |
2881 | e->first_stamp = e->last_stamp = tv.tv_sec; | |
2882 | e->same_count = 1; | |
2883 | e->event_data = *evt; | |
2884 | e->application = 0; | |
2885 | } | |
2886 | return e; | |
2887 | } | |
2888 | ||
2889 | static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr) | |
2890 | { | |
2891 | gdth_evt_str *e; | |
2892 | int eindex; | |
1fe6dbf4 | 2893 | unsigned long flags; |
1da177e4 LT |
2894 | |
2895 | TRACE2(("gdth_read_event() handle %d\n", handle)); | |
2896 | spin_lock_irqsave(&ha->smp_lock, flags); | |
2897 | if (handle == -1) | |
2898 | eindex = eoldidx; | |
2899 | else | |
2900 | eindex = handle; | |
2901 | estr->event_source = 0; | |
2902 | ||
690e7448 | 2903 | if (eindex < 0 || eindex >= MAX_EVENTS) { |
1da177e4 LT |
2904 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
2905 | return eindex; | |
2906 | } | |
2907 | e = &ebuffer[eindex]; | |
2908 | if (e->event_source != 0) { | |
2909 | if (eindex != elastidx) { | |
2910 | if (++eindex == MAX_EVENTS) | |
2911 | eindex = 0; | |
2912 | } else { | |
2913 | eindex = -1; | |
2914 | } | |
2915 | memcpy(estr, e, sizeof(gdth_evt_str)); | |
2916 | } | |
2917 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
2918 | return eindex; | |
2919 | } | |
2920 | ||
2921 | static void gdth_readapp_event(gdth_ha_str *ha, | |
1fe6dbf4 | 2922 | u8 application, gdth_evt_str *estr) |
1da177e4 LT |
2923 | { |
2924 | gdth_evt_str *e; | |
2925 | int eindex; | |
1fe6dbf4 DJ |
2926 | unsigned long flags; |
2927 | u8 found = FALSE; | |
1da177e4 LT |
2928 | |
2929 | TRACE2(("gdth_readapp_event() app. %d\n", application)); | |
2930 | spin_lock_irqsave(&ha->smp_lock, flags); | |
2931 | eindex = eoldidx; | |
2932 | for (;;) { | |
2933 | e = &ebuffer[eindex]; | |
2934 | if (e->event_source == 0) | |
2935 | break; | |
2936 | if ((e->application & application) == 0) { | |
2937 | e->application |= application; | |
2938 | found = TRUE; | |
2939 | break; | |
2940 | } | |
2941 | if (eindex == elastidx) | |
2942 | break; | |
2943 | if (++eindex == MAX_EVENTS) | |
2944 | eindex = 0; | |
2945 | } | |
2946 | if (found) | |
2947 | memcpy(estr, e, sizeof(gdth_evt_str)); | |
2948 | else | |
2949 | estr->event_source = 0; | |
2950 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
2951 | } | |
2952 | ||
2953 | static void gdth_clear_events(void) | |
2954 | { | |
2955 | TRACE(("gdth_clear_events()")); | |
2956 | ||
2957 | eoldidx = elastidx = 0; | |
2958 | ebuffer[0].event_source = 0; | |
2959 | } | |
2960 | ||
2961 | ||
2962 | /* SCSI interface functions */ | |
2963 | ||
230e886e | 2964 | static irqreturn_t __gdth_interrupt(gdth_ha_str *ha, |
10e1b4bc | 2965 | int gdth_from_wait, int* pIndex) |
1da177e4 | 2966 | { |
1da177e4 LT |
2967 | gdt6m_dpram_str __iomem *dp6m_ptr = NULL; |
2968 | gdt6_dpram_str __iomem *dp6_ptr; | |
2969 | gdt2_dpram_str __iomem *dp2_ptr; | |
2970 | Scsi_Cmnd *scp; | |
10e1b4bc | 2971 | int rval, i; |
1fe6dbf4 DJ |
2972 | u8 IStatus; |
2973 | u16 Service; | |
2974 | unsigned long flags = 0; | |
1da177e4 LT |
2975 | #ifdef INT_COAL |
2976 | int coalesced = FALSE; | |
2977 | int next = FALSE; | |
2978 | gdth_coal_status *pcs = NULL; | |
2979 | int act_int_coal = 0; | |
2980 | #endif | |
2981 | ||
230e886e | 2982 | TRACE(("gdth_interrupt() IRQ %d\n", ha->irq)); |
1da177e4 LT |
2983 | |
2984 | /* if polling and not from gdth_wait() -> return */ | |
2985 | if (gdth_polling) { | |
2986 | if (!gdth_from_wait) { | |
2987 | return IRQ_HANDLED; | |
2988 | } | |
2989 | } | |
2990 | ||
2991 | if (!gdth_polling) | |
10e1b4bc | 2992 | spin_lock_irqsave(&ha->smp_lock, flags); |
1da177e4 LT |
2993 | |
2994 | /* search controller */ | |
230e886e JG |
2995 | IStatus = gdth_get_status(ha); |
2996 | if (IStatus == 0) { | |
1da177e4 LT |
2997 | /* spurious interrupt */ |
2998 | if (!gdth_polling) | |
10e1b4bc BH |
2999 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
3000 | return IRQ_HANDLED; | |
1da177e4 | 3001 | } |
1da177e4 LT |
3002 | |
3003 | #ifdef GDTH_STATISTICS | |
3004 | ++act_ints; | |
3005 | #endif | |
3006 | ||
3007 | #ifdef INT_COAL | |
3008 | /* See if the fw is returning coalesced status */ | |
3009 | if (IStatus == COALINDEX) { | |
3010 | /* Coalesced status. Setup the initial status | |
3011 | buffer pointer and flags */ | |
3012 | pcs = ha->coal_stat; | |
3013 | coalesced = TRUE; | |
3014 | next = TRUE; | |
3015 | } | |
3016 | ||
3017 | do { | |
3018 | if (coalesced) { | |
3019 | /* For coalesced requests all status | |
3020 | information is found in the status buffer */ | |
1fe6dbf4 | 3021 | IStatus = (u8)(pcs->status & 0xff); |
1da177e4 LT |
3022 | } |
3023 | #endif | |
3024 | ||
3025 | if (ha->type == GDT_EISA) { | |
3026 | if (IStatus & 0x80) { /* error flag */ | |
3027 | IStatus &= ~0x80; | |
3028 | ha->status = inw(ha->bmic + MAILBOXREG+8); | |
3029 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); | |
3030 | } else /* no error */ | |
3031 | ha->status = S_OK; | |
3032 | ha->info = inl(ha->bmic + MAILBOXREG+12); | |
3033 | ha->service = inw(ha->bmic + MAILBOXREG+10); | |
3034 | ha->info2 = inl(ha->bmic + MAILBOXREG+4); | |
3035 | ||
3036 | outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */ | |
3037 | outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */ | |
3038 | } else if (ha->type == GDT_ISA) { | |
3039 | dp2_ptr = ha->brd; | |
3040 | if (IStatus & 0x80) { /* error flag */ | |
3041 | IStatus &= ~0x80; | |
a52667f3 | 3042 | ha->status = readw(&dp2_ptr->u.ic.Status); |
1da177e4 LT |
3043 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
3044 | } else /* no error */ | |
3045 | ha->status = S_OK; | |
a52667f3 JG |
3046 | ha->info = readl(&dp2_ptr->u.ic.Info[0]); |
3047 | ha->service = readw(&dp2_ptr->u.ic.Service); | |
3048 | ha->info2 = readl(&dp2_ptr->u.ic.Info[1]); | |
1da177e4 | 3049 | |
a52667f3 JG |
3050 | writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */ |
3051 | writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */ | |
3052 | writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */ | |
1da177e4 LT |
3053 | } else if (ha->type == GDT_PCI) { |
3054 | dp6_ptr = ha->brd; | |
3055 | if (IStatus & 0x80) { /* error flag */ | |
3056 | IStatus &= ~0x80; | |
a52667f3 | 3057 | ha->status = readw(&dp6_ptr->u.ic.Status); |
1da177e4 LT |
3058 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
3059 | } else /* no error */ | |
3060 | ha->status = S_OK; | |
a52667f3 JG |
3061 | ha->info = readl(&dp6_ptr->u.ic.Info[0]); |
3062 | ha->service = readw(&dp6_ptr->u.ic.Service); | |
3063 | ha->info2 = readl(&dp6_ptr->u.ic.Info[1]); | |
1da177e4 | 3064 | |
a52667f3 JG |
3065 | writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */ |
3066 | writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */ | |
3067 | writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */ | |
1da177e4 LT |
3068 | } else if (ha->type == GDT_PCINEW) { |
3069 | if (IStatus & 0x80) { /* error flag */ | |
3070 | IStatus &= ~0x80; | |
3071 | ha->status = inw(PTR2USHORT(&ha->plx->status)); | |
3072 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); | |
3073 | } else | |
3074 | ha->status = S_OK; | |
3075 | ha->info = inl(PTR2USHORT(&ha->plx->info[0])); | |
3076 | ha->service = inw(PTR2USHORT(&ha->plx->service)); | |
3077 | ha->info2 = inl(PTR2USHORT(&ha->plx->info[1])); | |
3078 | ||
3079 | outb(0xff, PTR2USHORT(&ha->plx->edoor_reg)); | |
3080 | outb(0x00, PTR2USHORT(&ha->plx->sema1_reg)); | |
3081 | } else if (ha->type == GDT_PCIMPR) { | |
3082 | dp6m_ptr = ha->brd; | |
3083 | if (IStatus & 0x80) { /* error flag */ | |
3084 | IStatus &= ~0x80; | |
3085 | #ifdef INT_COAL | |
3086 | if (coalesced) | |
107e716b | 3087 | ha->status = pcs->ext_status & 0xffff; |
1da177e4 LT |
3088 | else |
3089 | #endif | |
a52667f3 | 3090 | ha->status = readw(&dp6m_ptr->i960r.status); |
1da177e4 LT |
3091 | TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status)); |
3092 | } else /* no error */ | |
3093 | ha->status = S_OK; | |
3094 | #ifdef INT_COAL | |
3095 | /* get information */ | |
3096 | if (coalesced) { | |
3097 | ha->info = pcs->info0; | |
3098 | ha->info2 = pcs->info1; | |
107e716b | 3099 | ha->service = (pcs->ext_status >> 16) & 0xffff; |
1da177e4 LT |
3100 | } else |
3101 | #endif | |
3102 | { | |
a52667f3 JG |
3103 | ha->info = readl(&dp6m_ptr->i960r.info[0]); |
3104 | ha->service = readw(&dp6m_ptr->i960r.service); | |
3105 | ha->info2 = readl(&dp6m_ptr->i960r.info[1]); | |
1da177e4 LT |
3106 | } |
3107 | /* event string */ | |
3108 | if (IStatus == ASYNCINDEX) { | |
3109 | if (ha->service != SCREENSERVICE && | |
3110 | (ha->fw_vers & 0xff) >= 0x1a) { | |
a52667f3 | 3111 | ha->dvr.severity = readb |
1da177e4 LT |
3112 | (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity); |
3113 | for (i = 0; i < 256; ++i) { | |
a52667f3 | 3114 | ha->dvr.event_string[i] = readb |
1da177e4 LT |
3115 | (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]); |
3116 | if (ha->dvr.event_string[i] == 0) | |
3117 | break; | |
3118 | } | |
3119 | } | |
3120 | } | |
3121 | #ifdef INT_COAL | |
3122 | /* Make sure that non coalesced interrupts get cleared | |
3123 | before being handled by gdth_async_event/gdth_sync_event */ | |
3124 | if (!coalesced) | |
3125 | #endif | |
3126 | { | |
a52667f3 JG |
3127 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
3128 | writeb(0, &dp6m_ptr->i960r.sema1_reg); | |
1da177e4 LT |
3129 | } |
3130 | } else { | |
3131 | TRACE2(("gdth_interrupt() unknown controller type\n")); | |
3132 | if (!gdth_polling) | |
10e1b4bc | 3133 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
3134 | return IRQ_HANDLED; |
3135 | } | |
3136 | ||
3137 | TRACE(("gdth_interrupt() index %d stat %d info %d\n", | |
3138 | IStatus,ha->status,ha->info)); | |
3139 | ||
3140 | if (gdth_from_wait) { | |
10e1b4bc | 3141 | *pIndex = (int)IStatus; |
1da177e4 LT |
3142 | } |
3143 | ||
3144 | if (IStatus == ASYNCINDEX) { | |
3145 | TRACE2(("gdth_interrupt() async. event\n")); | |
45f1a41b | 3146 | gdth_async_event(ha); |
1da177e4 | 3147 | if (!gdth_polling) |
10e1b4bc | 3148 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
45f1a41b | 3149 | gdth_next(ha); |
1da177e4 LT |
3150 | return IRQ_HANDLED; |
3151 | } | |
3152 | ||
3153 | if (IStatus == SPEZINDEX) { | |
3154 | TRACE2(("Service unknown or not initialized !\n")); | |
3155 | ha->dvr.size = sizeof(ha->dvr.eu.driver); | |
10e1b4bc | 3156 | ha->dvr.eu.driver.ionode = ha->hanum; |
1da177e4 LT |
3157 | gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr); |
3158 | if (!gdth_polling) | |
10e1b4bc | 3159 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
3160 | return IRQ_HANDLED; |
3161 | } | |
3162 | scp = ha->cmd_tab[IStatus-2].cmnd; | |
3163 | Service = ha->cmd_tab[IStatus-2].service; | |
3164 | ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND; | |
3165 | if (scp == UNUSED_CMND) { | |
3166 | TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus)); | |
3167 | ha->dvr.size = sizeof(ha->dvr.eu.driver); | |
10e1b4bc | 3168 | ha->dvr.eu.driver.ionode = ha->hanum; |
1da177e4 LT |
3169 | ha->dvr.eu.driver.index = IStatus; |
3170 | gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr); | |
3171 | if (!gdth_polling) | |
10e1b4bc | 3172 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
3173 | return IRQ_HANDLED; |
3174 | } | |
3175 | if (scp == INTERNAL_CMND) { | |
3176 | TRACE(("gdth_interrupt() answer to internal command\n")); | |
3177 | if (!gdth_polling) | |
10e1b4bc | 3178 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
3179 | return IRQ_HANDLED; |
3180 | } | |
3181 | ||
3182 | TRACE(("gdth_interrupt() sync. status\n")); | |
45f1a41b | 3183 | rval = gdth_sync_event(ha,Service,IStatus,scp); |
1da177e4 | 3184 | if (!gdth_polling) |
10e1b4bc | 3185 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 | 3186 | if (rval == 2) { |
f842b64e | 3187 | gdth_putq(ha, scp, gdth_cmnd_priv(scp)->priority); |
1da177e4 | 3188 | } else if (rval == 1) { |
b8bff2ae | 3189 | gdth_scsi_done(scp); |
1da177e4 LT |
3190 | } |
3191 | ||
3192 | #ifdef INT_COAL | |
3193 | if (coalesced) { | |
3194 | /* go to the next status in the status buffer */ | |
3195 | ++pcs; | |
3196 | #ifdef GDTH_STATISTICS | |
3197 | ++act_int_coal; | |
3198 | if (act_int_coal > max_int_coal) { | |
3199 | max_int_coal = act_int_coal; | |
1fe6dbf4 | 3200 | printk("GDT: max_int_coal = %d\n",(u16)max_int_coal); |
1da177e4 LT |
3201 | } |
3202 | #endif | |
3203 | /* see if there is another status */ | |
3204 | if (pcs->status == 0) | |
3205 | /* Stop the coalesce loop */ | |
3206 | next = FALSE; | |
3207 | } | |
3208 | } while (next); | |
3209 | ||
3210 | /* coalescing only for new GDT_PCIMPR controllers available */ | |
3211 | if (ha->type == GDT_PCIMPR && coalesced) { | |
a52667f3 JG |
3212 | writeb(0xff, &dp6m_ptr->i960r.edoor_reg); |
3213 | writeb(0, &dp6m_ptr->i960r.sema1_reg); | |
1da177e4 LT |
3214 | } |
3215 | #endif | |
3216 | ||
45f1a41b | 3217 | gdth_next(ha); |
1da177e4 LT |
3218 | return IRQ_HANDLED; |
3219 | } | |
3220 | ||
10e1b4bc BH |
3221 | static irqreturn_t gdth_interrupt(int irq, void *dev_id) |
3222 | { | |
230e886e | 3223 | gdth_ha_str *ha = dev_id; |
10e1b4bc | 3224 | |
230e886e | 3225 | return __gdth_interrupt(ha, false, NULL); |
10e1b4bc BH |
3226 | } |
3227 | ||
1fe6dbf4 | 3228 | static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index, |
45f1a41b | 3229 | Scsi_Cmnd *scp) |
1da177e4 | 3230 | { |
1da177e4 LT |
3231 | gdth_msg_str *msg; |
3232 | gdth_cmd_str *cmdp; | |
1fe6dbf4 | 3233 | u8 b, t; |
3058d5de | 3234 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 | 3235 | |
1da177e4 LT |
3236 | cmdp = ha->pccb; |
3237 | TRACE(("gdth_sync_event() serv %d status %d\n", | |
3238 | service,ha->status)); | |
3239 | ||
3240 | if (service == SCREENSERVICE) { | |
3241 | msg = ha->pmsg; | |
3242 | TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n", | |
3243 | msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen)); | |
3244 | if (msg->msg_len > MSGLEN+1) | |
3245 | msg->msg_len = MSGLEN+1; | |
3246 | if (msg->msg_len) | |
3247 | if (!(msg->msg_answer && msg->msg_ext)) { | |
3248 | msg->msg_text[msg->msg_len] = '\0'; | |
3249 | printk("%s",msg->msg_text); | |
3250 | } | |
3251 | ||
3252 | if (msg->msg_ext && !msg->msg_answer) { | |
45f1a41b | 3253 | while (gdth_test_busy(ha)) |
1da177e4 LT |
3254 | gdth_delay(0); |
3255 | cmdp->Service = SCREENSERVICE; | |
3256 | cmdp->RequestBuffer = SCREEN_CMND; | |
45f1a41b BH |
3257 | gdth_get_cmd_index(ha); |
3258 | gdth_set_sema0(ha); | |
1da177e4 LT |
3259 | cmdp->OpCode = GDT_READ; |
3260 | cmdp->BoardNode = LOCALBOARD; | |
3261 | cmdp->u.screen.reserved = 0; | |
3262 | cmdp->u.screen.su.msg.msg_handle= msg->msg_handle; | |
3263 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; | |
3264 | ha->cmd_offs_dpmem = 0; | |
3265 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) | |
1fe6dbf4 | 3266 | + sizeof(u64); |
1da177e4 | 3267 | ha->cmd_cnt = 0; |
45f1a41b BH |
3268 | gdth_copy_command(ha); |
3269 | gdth_release_event(ha); | |
1da177e4 LT |
3270 | return 0; |
3271 | } | |
3272 | ||
3273 | if (msg->msg_answer && msg->msg_alen) { | |
3274 | /* default answers (getchar() not possible) */ | |
3275 | if (msg->msg_alen == 1) { | |
3276 | msg->msg_alen = 0; | |
3277 | msg->msg_len = 1; | |
3278 | msg->msg_text[0] = 0; | |
3279 | } else { | |
3280 | msg->msg_alen -= 2; | |
3281 | msg->msg_len = 2; | |
3282 | msg->msg_text[0] = 1; | |
3283 | msg->msg_text[1] = 0; | |
3284 | } | |
3285 | msg->msg_ext = 0; | |
3286 | msg->msg_answer = 0; | |
45f1a41b | 3287 | while (gdth_test_busy(ha)) |
1da177e4 LT |
3288 | gdth_delay(0); |
3289 | cmdp->Service = SCREENSERVICE; | |
3290 | cmdp->RequestBuffer = SCREEN_CMND; | |
45f1a41b BH |
3291 | gdth_get_cmd_index(ha); |
3292 | gdth_set_sema0(ha); | |
1da177e4 LT |
3293 | cmdp->OpCode = GDT_WRITE; |
3294 | cmdp->BoardNode = LOCALBOARD; | |
3295 | cmdp->u.screen.reserved = 0; | |
3296 | cmdp->u.screen.su.msg.msg_handle= msg->msg_handle; | |
3297 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; | |
3298 | ha->cmd_offs_dpmem = 0; | |
3299 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) | |
1fe6dbf4 | 3300 | + sizeof(u64); |
1da177e4 | 3301 | ha->cmd_cnt = 0; |
45f1a41b BH |
3302 | gdth_copy_command(ha); |
3303 | gdth_release_event(ha); | |
1da177e4 LT |
3304 | return 0; |
3305 | } | |
3306 | printk("\n"); | |
3307 | ||
3308 | } else { | |
52759e6a | 3309 | b = scp->device->channel; |
1da177e4 | 3310 | t = scp->device->id; |
f842b64e | 3311 | if (cmndinfo->OpCode == -1 && b != ha->virt_bus) { |
1da177e4 LT |
3312 | ha->raw[BUS_L2P(ha,b)].io_cnt[t]--; |
3313 | } | |
3314 | /* cache or raw service */ | |
3315 | if (ha->status == S_BSY) { | |
3316 | TRACE2(("Controller busy -> retry !\n")); | |
f842b64e BH |
3317 | if (cmndinfo->OpCode == GDT_MOUNT) |
3318 | cmndinfo->OpCode = GDT_CLUST_INFO; | |
1da177e4 LT |
3319 | /* retry */ |
3320 | return 2; | |
3321 | } | |
d35055a0 BH |
3322 | if (scsi_bufflen(scp)) |
3323 | pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp), | |
3892d88a BH |
3324 | cmndinfo->dma_dir); |
3325 | ||
3058d5de BH |
3326 | if (cmndinfo->sense_paddr) |
3327 | pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16, | |
3328 | PCI_DMA_FROMDEVICE); | |
1da177e4 LT |
3329 | |
3330 | if (ha->status == S_OK) { | |
f842b64e BH |
3331 | cmndinfo->status = S_OK; |
3332 | cmndinfo->info = ha->info; | |
3333 | if (cmndinfo->OpCode != -1) { | |
1da177e4 | 3334 | TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n", |
f842b64e | 3335 | cmndinfo->OpCode)); |
1da177e4 | 3336 | /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */ |
f842b64e | 3337 | if (cmndinfo->OpCode == GDT_CLUST_INFO) { |
1fe6dbf4 | 3338 | ha->hdr[t].cluster_type = (u8)ha->info; |
1da177e4 LT |
3339 | if (!(ha->hdr[t].cluster_type & |
3340 | CLUSTER_MOUNTED)) { | |
3341 | /* NOT MOUNTED -> MOUNT */ | |
f842b64e | 3342 | cmndinfo->OpCode = GDT_MOUNT; |
1da177e4 LT |
3343 | if (ha->hdr[t].cluster_type & |
3344 | CLUSTER_RESERVED) { | |
3345 | /* cluster drive RESERVED (on the other node) */ | |
f842b64e | 3346 | cmndinfo->phase = -2; /* reservation conflict */ |
1da177e4 LT |
3347 | } |
3348 | } else { | |
f842b64e | 3349 | cmndinfo->OpCode = -1; |
1da177e4 LT |
3350 | } |
3351 | } else { | |
f842b64e | 3352 | if (cmndinfo->OpCode == GDT_MOUNT) { |
1da177e4 LT |
3353 | ha->hdr[t].cluster_type |= CLUSTER_MOUNTED; |
3354 | ha->hdr[t].media_changed = TRUE; | |
f842b64e | 3355 | } else if (cmndinfo->OpCode == GDT_UNMOUNT) { |
1da177e4 LT |
3356 | ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED; |
3357 | ha->hdr[t].media_changed = TRUE; | |
3358 | } | |
f842b64e | 3359 | cmndinfo->OpCode = -1; |
1da177e4 LT |
3360 | } |
3361 | /* retry */ | |
f842b64e | 3362 | cmndinfo->priority = HIGH_PRI; |
1da177e4 LT |
3363 | return 2; |
3364 | } else { | |
3365 | /* RESERVE/RELEASE ? */ | |
3366 | if (scp->cmnd[0] == RESERVE) { | |
3367 | ha->hdr[t].cluster_type |= CLUSTER_RESERVED; | |
3368 | } else if (scp->cmnd[0] == RELEASE) { | |
3369 | ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED; | |
3370 | } | |
3371 | scp->result = DID_OK << 16; | |
3372 | scp->sense_buffer[0] = 0; | |
3373 | } | |
3374 | } else { | |
f842b64e BH |
3375 | cmndinfo->status = ha->status; |
3376 | cmndinfo->info = ha->info; | |
1da177e4 | 3377 | |
f842b64e | 3378 | if (cmndinfo->OpCode != -1) { |
1da177e4 | 3379 | TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n", |
f842b64e BH |
3380 | cmndinfo->OpCode, ha->status)); |
3381 | if (cmndinfo->OpCode == GDT_SCAN_START || | |
3382 | cmndinfo->OpCode == GDT_SCAN_END) { | |
3383 | cmndinfo->OpCode = -1; | |
1da177e4 | 3384 | /* retry */ |
f842b64e | 3385 | cmndinfo->priority = HIGH_PRI; |
1da177e4 LT |
3386 | return 2; |
3387 | } | |
3388 | memset((char*)scp->sense_buffer,0,16); | |
3389 | scp->sense_buffer[0] = 0x70; | |
3390 | scp->sense_buffer[2] = NOT_READY; | |
3391 | scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | |
3392 | } else if (service == CACHESERVICE) { | |
3393 | if (ha->status == S_CACHE_UNKNOWN && | |
3394 | (ha->hdr[t].cluster_type & | |
3395 | CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) { | |
3396 | /* bus reset -> force GDT_CLUST_INFO */ | |
3397 | ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED; | |
3398 | } | |
3399 | memset((char*)scp->sense_buffer,0,16); | |
1fe6dbf4 | 3400 | if (ha->status == (u16)S_CACHE_RESERV) { |
1da177e4 LT |
3401 | scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1); |
3402 | } else { | |
3403 | scp->sense_buffer[0] = 0x70; | |
3404 | scp->sense_buffer[2] = NOT_READY; | |
3405 | scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | |
3406 | } | |
3058d5de | 3407 | if (!cmndinfo->internal_command) { |
1da177e4 | 3408 | ha->dvr.size = sizeof(ha->dvr.eu.sync); |
45f1a41b | 3409 | ha->dvr.eu.sync.ionode = ha->hanum; |
1da177e4 LT |
3410 | ha->dvr.eu.sync.service = service; |
3411 | ha->dvr.eu.sync.status = ha->status; | |
3412 | ha->dvr.eu.sync.info = ha->info; | |
3413 | ha->dvr.eu.sync.hostdrive = t; | |
3414 | if (ha->status >= 0x8000) | |
3415 | gdth_store_event(ha, ES_SYNC, 0, &ha->dvr); | |
3416 | else | |
3417 | gdth_store_event(ha, ES_SYNC, service, &ha->dvr); | |
3418 | } | |
3419 | } else { | |
3420 | /* sense buffer filled from controller firmware (DMA) */ | |
3421 | if (ha->status != S_RAW_SCSI || ha->info >= 0x100) { | |
3422 | scp->result = DID_BAD_TARGET << 16; | |
3423 | } else { | |
3424 | scp->result = (DID_OK << 16) | ha->info; | |
3425 | } | |
3426 | } | |
3427 | } | |
f842b64e BH |
3428 | if (!cmndinfo->wait_for_completion) |
3429 | cmndinfo->wait_for_completion++; | |
1da177e4 LT |
3430 | else |
3431 | return 1; | |
3432 | } | |
3433 | ||
3434 | return 0; | |
3435 | } | |
3436 | ||
3437 | static char *async_cache_tab[] = { | |
3438 | /* 0*/ "\011\000\002\002\002\004\002\006\004" | |
3439 | "GDT HA %u, service %u, async. status %u/%lu unknown", | |
3440 | /* 1*/ "\011\000\002\002\002\004\002\006\004" | |
3441 | "GDT HA %u, service %u, async. status %u/%lu unknown", | |
3442 | /* 2*/ "\005\000\002\006\004" | |
3443 | "GDT HA %u, Host Drive %lu not ready", | |
3444 | /* 3*/ "\005\000\002\006\004" | |
3445 | "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", | |
3446 | /* 4*/ "\005\000\002\006\004" | |
3447 | "GDT HA %u, mirror update on Host Drive %lu failed", | |
3448 | /* 5*/ "\005\000\002\006\004" | |
3449 | "GDT HA %u, Mirror Drive %lu failed", | |
3450 | /* 6*/ "\005\000\002\006\004" | |
3451 | "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", | |
3452 | /* 7*/ "\005\000\002\006\004" | |
3453 | "GDT HA %u, Host Drive %lu write protected", | |
3454 | /* 8*/ "\005\000\002\006\004" | |
3455 | "GDT HA %u, media changed in Host Drive %lu", | |
3456 | /* 9*/ "\005\000\002\006\004" | |
3457 | "GDT HA %u, Host Drive %lu is offline", | |
3458 | /*10*/ "\005\000\002\006\004" | |
3459 | "GDT HA %u, media change of Mirror Drive %lu", | |
3460 | /*11*/ "\005\000\002\006\004" | |
3461 | "GDT HA %u, Mirror Drive %lu is write protected", | |
3462 | /*12*/ "\005\000\002\006\004" | |
3463 | "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!", | |
3464 | /*13*/ "\007\000\002\006\002\010\002" | |
3465 | "GDT HA %u, Array Drive %u: Cache Drive %u failed", | |
3466 | /*14*/ "\005\000\002\006\002" | |
3467 | "GDT HA %u, Array Drive %u: FAIL state entered", | |
3468 | /*15*/ "\005\000\002\006\002" | |
3469 | "GDT HA %u, Array Drive %u: error", | |
3470 | /*16*/ "\007\000\002\006\002\010\002" | |
3471 | "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u", | |
3472 | /*17*/ "\005\000\002\006\002" | |
3473 | "GDT HA %u, Array Drive %u: parity build failed", | |
3474 | /*18*/ "\005\000\002\006\002" | |
3475 | "GDT HA %u, Array Drive %u: drive rebuild failed", | |
3476 | /*19*/ "\005\000\002\010\002" | |
3477 | "GDT HA %u, Test of Hot Fix %u failed", | |
3478 | /*20*/ "\005\000\002\006\002" | |
3479 | "GDT HA %u, Array Drive %u: drive build finished successfully", | |
3480 | /*21*/ "\005\000\002\006\002" | |
3481 | "GDT HA %u, Array Drive %u: drive rebuild finished successfully", | |
3482 | /*22*/ "\007\000\002\006\002\010\002" | |
3483 | "GDT HA %u, Array Drive %u: Hot Fix %u activated", | |
3484 | /*23*/ "\005\000\002\006\002" | |
3485 | "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error", | |
3486 | /*24*/ "\005\000\002\010\002" | |
3487 | "GDT HA %u, mirror update on Cache Drive %u completed", | |
3488 | /*25*/ "\005\000\002\010\002" | |
3489 | "GDT HA %u, mirror update on Cache Drive %lu failed", | |
3490 | /*26*/ "\005\000\002\006\002" | |
3491 | "GDT HA %u, Array Drive %u: drive rebuild started", | |
3492 | /*27*/ "\005\000\002\012\001" | |
3493 | "GDT HA %u, Fault bus %u: SHELF OK detected", | |
3494 | /*28*/ "\005\000\002\012\001" | |
3495 | "GDT HA %u, Fault bus %u: SHELF not OK detected", | |
3496 | /*29*/ "\007\000\002\012\001\013\001" | |
3497 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started", | |
3498 | /*30*/ "\007\000\002\012\001\013\001" | |
3499 | "GDT HA %u, Fault bus %u, ID %u: new disk detected", | |
3500 | /*31*/ "\007\000\002\012\001\013\001" | |
3501 | "GDT HA %u, Fault bus %u, ID %u: old disk detected", | |
3502 | /*32*/ "\007\000\002\012\001\013\001" | |
3503 | "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid", | |
3504 | /*33*/ "\007\000\002\012\001\013\001" | |
3505 | "GDT HA %u, Fault bus %u, ID %u: invalid device detected", | |
3506 | /*34*/ "\011\000\002\012\001\013\001\006\004" | |
3507 | "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)", | |
3508 | /*35*/ "\007\000\002\012\001\013\001" | |
3509 | "GDT HA %u, Fault bus %u, ID %u: disk write protected", | |
3510 | /*36*/ "\007\000\002\012\001\013\001" | |
3511 | "GDT HA %u, Fault bus %u, ID %u: disk not available", | |
3512 | /*37*/ "\007\000\002\012\001\006\004" | |
3513 | "GDT HA %u, Fault bus %u: swap detected (%lu)", | |
3514 | /*38*/ "\007\000\002\012\001\013\001" | |
3515 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully", | |
3516 | /*39*/ "\007\000\002\012\001\013\001" | |
3517 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug", | |
3518 | /*40*/ "\007\000\002\012\001\013\001" | |
3519 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted", | |
3520 | /*41*/ "\007\000\002\012\001\013\001" | |
3521 | "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started", | |
3522 | /*42*/ "\005\000\002\006\002" | |
3523 | "GDT HA %u, Array Drive %u: drive build started", | |
3524 | /*43*/ "\003\000\002" | |
3525 | "GDT HA %u, DRAM parity error detected", | |
3526 | /*44*/ "\005\000\002\006\002" | |
3527 | "GDT HA %u, Mirror Drive %u: update started", | |
3528 | /*45*/ "\007\000\002\006\002\010\002" | |
3529 | "GDT HA %u, Mirror Drive %u: Hot Fix %u activated", | |
3530 | /*46*/ "\005\000\002\006\002" | |
3531 | "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available", | |
3532 | /*47*/ "\005\000\002\006\002" | |
3533 | "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available", | |
3534 | /*48*/ "\005\000\002\006\002" | |
3535 | "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available", | |
3536 | /*49*/ "\005\000\002\006\002" | |
3537 | "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available", | |
3538 | /*50*/ "\007\000\002\012\001\013\001" | |
3539 | "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received", | |
3540 | /*51*/ "\005\000\002\006\002" | |
3541 | "GDT HA %u, Array Drive %u: expand started", | |
3542 | /*52*/ "\005\000\002\006\002" | |
3543 | "GDT HA %u, Array Drive %u: expand finished successfully", | |
3544 | /*53*/ "\005\000\002\006\002" | |
3545 | "GDT HA %u, Array Drive %u: expand failed", | |
3546 | /*54*/ "\003\000\002" | |
3547 | "GDT HA %u, CPU temperature critical", | |
3548 | /*55*/ "\003\000\002" | |
3549 | "GDT HA %u, CPU temperature OK", | |
3550 | /*56*/ "\005\000\002\006\004" | |
3551 | "GDT HA %u, Host drive %lu created", | |
3552 | /*57*/ "\005\000\002\006\002" | |
3553 | "GDT HA %u, Array Drive %u: expand restarted", | |
3554 | /*58*/ "\005\000\002\006\002" | |
3555 | "GDT HA %u, Array Drive %u: expand stopped", | |
3556 | /*59*/ "\005\000\002\010\002" | |
3557 | "GDT HA %u, Mirror Drive %u: drive build quited", | |
3558 | /*60*/ "\005\000\002\006\002" | |
3559 | "GDT HA %u, Array Drive %u: parity build quited", | |
3560 | /*61*/ "\005\000\002\006\002" | |
3561 | "GDT HA %u, Array Drive %u: drive rebuild quited", | |
3562 | /*62*/ "\005\000\002\006\002" | |
3563 | "GDT HA %u, Array Drive %u: parity verify started", | |
3564 | /*63*/ "\005\000\002\006\002" | |
3565 | "GDT HA %u, Array Drive %u: parity verify done", | |
3566 | /*64*/ "\005\000\002\006\002" | |
3567 | "GDT HA %u, Array Drive %u: parity verify failed", | |
3568 | /*65*/ "\005\000\002\006\002" | |
3569 | "GDT HA %u, Array Drive %u: parity error detected", | |
3570 | /*66*/ "\005\000\002\006\002" | |
3571 | "GDT HA %u, Array Drive %u: parity verify quited", | |
3572 | /*67*/ "\005\000\002\006\002" | |
3573 | "GDT HA %u, Host Drive %u reserved", | |
3574 | /*68*/ "\005\000\002\006\002" | |
3575 | "GDT HA %u, Host Drive %u mounted and released", | |
3576 | /*69*/ "\005\000\002\006\002" | |
3577 | "GDT HA %u, Host Drive %u released", | |
3578 | /*70*/ "\003\000\002" | |
3579 | "GDT HA %u, DRAM error detected and corrected with ECC", | |
3580 | /*71*/ "\003\000\002" | |
3581 | "GDT HA %u, Uncorrectable DRAM error detected with ECC", | |
3582 | /*72*/ "\011\000\002\012\001\013\001\014\001" | |
3583 | "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block", | |
3584 | /*73*/ "\005\000\002\006\002" | |
3585 | "GDT HA %u, Host drive %u resetted locally", | |
3586 | /*74*/ "\005\000\002\006\002" | |
3587 | "GDT HA %u, Host drive %u resetted remotely", | |
3588 | /*75*/ "\003\000\002" | |
3589 | "GDT HA %u, async. status 75 unknown", | |
3590 | }; | |
3591 | ||
3592 | ||
45f1a41b | 3593 | static int gdth_async_event(gdth_ha_str *ha) |
1da177e4 | 3594 | { |
1da177e4 LT |
3595 | gdth_cmd_str *cmdp; |
3596 | int cmd_index; | |
3597 | ||
1da177e4 LT |
3598 | cmdp= ha->pccb; |
3599 | TRACE2(("gdth_async_event() ha %d serv %d\n", | |
45f1a41b | 3600 | ha->hanum, ha->service)); |
1da177e4 LT |
3601 | |
3602 | if (ha->service == SCREENSERVICE) { | |
3603 | if (ha->status == MSG_REQUEST) { | |
45f1a41b | 3604 | while (gdth_test_busy(ha)) |
1da177e4 LT |
3605 | gdth_delay(0); |
3606 | cmdp->Service = SCREENSERVICE; | |
3607 | cmdp->RequestBuffer = SCREEN_CMND; | |
45f1a41b BH |
3608 | cmd_index = gdth_get_cmd_index(ha); |
3609 | gdth_set_sema0(ha); | |
1da177e4 LT |
3610 | cmdp->OpCode = GDT_READ; |
3611 | cmdp->BoardNode = LOCALBOARD; | |
3612 | cmdp->u.screen.reserved = 0; | |
3613 | cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE; | |
3614 | cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; | |
3615 | ha->cmd_offs_dpmem = 0; | |
3616 | ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) | |
1fe6dbf4 | 3617 | + sizeof(u64); |
1da177e4 | 3618 | ha->cmd_cnt = 0; |
45f1a41b | 3619 | gdth_copy_command(ha); |
1da177e4 | 3620 | if (ha->type == GDT_EISA) |
1fe6dbf4 | 3621 | printk("[EISA slot %d] ",(u16)ha->brd_phys); |
1da177e4 | 3622 | else if (ha->type == GDT_ISA) |
1fe6dbf4 | 3623 | printk("[DPMEM 0x%4X] ",(u16)ha->brd_phys); |
1da177e4 | 3624 | else |
1fe6dbf4 DJ |
3625 | printk("[PCI %d/%d] ",(u16)(ha->brd_phys>>8), |
3626 | (u16)((ha->brd_phys>>3)&0x1f)); | |
45f1a41b | 3627 | gdth_release_event(ha); |
1da177e4 LT |
3628 | } |
3629 | ||
3630 | } else { | |
3631 | if (ha->type == GDT_PCIMPR && | |
3632 | (ha->fw_vers & 0xff) >= 0x1a) { | |
3633 | ha->dvr.size = 0; | |
45f1a41b | 3634 | ha->dvr.eu.async.ionode = ha->hanum; |
1da177e4 LT |
3635 | ha->dvr.eu.async.status = ha->status; |
3636 | /* severity and event_string already set! */ | |
3637 | } else { | |
3638 | ha->dvr.size = sizeof(ha->dvr.eu.async); | |
45f1a41b | 3639 | ha->dvr.eu.async.ionode = ha->hanum; |
1da177e4 LT |
3640 | ha->dvr.eu.async.service = ha->service; |
3641 | ha->dvr.eu.async.status = ha->status; | |
3642 | ha->dvr.eu.async.info = ha->info; | |
1fe6dbf4 | 3643 | *(u32 *)ha->dvr.eu.async.scsi_coord = ha->info2; |
1da177e4 LT |
3644 | } |
3645 | gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr ); | |
3646 | gdth_log_event( &ha->dvr, NULL ); | |
3647 | ||
3648 | /* new host drive from expand? */ | |
3649 | if (ha->service == CACHESERVICE && ha->status == 56) { | |
3650 | TRACE2(("gdth_async_event(): new host drive %d created\n", | |
1fe6dbf4 DJ |
3651 | (u16)ha->info)); |
3652 | /* gdth_analyse_hdrive(hanum, (u16)ha->info); */ | |
1da177e4 LT |
3653 | } |
3654 | } | |
3655 | return 1; | |
3656 | } | |
3657 | ||
3658 | static void gdth_log_event(gdth_evt_data *dvr, char *buffer) | |
3659 | { | |
3660 | gdth_stackframe stack; | |
3661 | char *f = NULL; | |
3662 | int i,j; | |
3663 | ||
3664 | TRACE2(("gdth_log_event()\n")); | |
3665 | if (dvr->size == 0) { | |
3666 | if (buffer == NULL) { | |
3667 | printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string); | |
3668 | } else { | |
3669 | sprintf(buffer,"Adapter %d: %s\n", | |
3670 | dvr->eu.async.ionode,dvr->event_string); | |
3671 | } | |
3672 | } else if (dvr->eu.async.service == CACHESERVICE && | |
3673 | INDEX_OK(dvr->eu.async.status, async_cache_tab)) { | |
3674 | TRACE2(("GDT: Async. event cache service, event no.: %d\n", | |
3675 | dvr->eu.async.status)); | |
3676 | ||
3677 | f = async_cache_tab[dvr->eu.async.status]; | |
3678 | ||
3679 | /* i: parameter to push, j: stack element to fill */ | |
3680 | for (j=0,i=1; i < f[0]; i+=2) { | |
3681 | switch (f[i+1]) { | |
3682 | case 4: | |
1fe6dbf4 | 3683 | stack.b[j++] = *(u32*)&dvr->eu.stream[(int)f[i]]; |
1da177e4 LT |
3684 | break; |
3685 | case 2: | |
1fe6dbf4 | 3686 | stack.b[j++] = *(u16*)&dvr->eu.stream[(int)f[i]]; |
1da177e4 LT |
3687 | break; |
3688 | case 1: | |
1fe6dbf4 | 3689 | stack.b[j++] = *(u8*)&dvr->eu.stream[(int)f[i]]; |
1da177e4 LT |
3690 | break; |
3691 | default: | |
3692 | break; | |
3693 | } | |
3694 | } | |
3695 | ||
3696 | if (buffer == NULL) { | |
3697 | printk(&f[(int)f[0]],stack); | |
3698 | printk("\n"); | |
3699 | } else { | |
3700 | sprintf(buffer,&f[(int)f[0]],stack); | |
3701 | } | |
3702 | ||
3703 | } else { | |
3704 | if (buffer == NULL) { | |
3705 | printk("GDT HA %u, Unknown async. event service %d event no. %d\n", | |
3706 | dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status); | |
3707 | } else { | |
3708 | sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d", | |
3709 | dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status); | |
3710 | } | |
3711 | } | |
3712 | } | |
3713 | ||
3714 | #ifdef GDTH_STATISTICS | |
1fe6dbf4 | 3715 | static u8 gdth_timer_running; |
2d6f0d0c | 3716 | |
1fe6dbf4 | 3717 | static void gdth_timeout(unsigned long data) |
1da177e4 | 3718 | { |
1fe6dbf4 | 3719 | u32 i; |
1da177e4 LT |
3720 | Scsi_Cmnd *nscp; |
3721 | gdth_ha_str *ha; | |
1fe6dbf4 | 3722 | unsigned long flags; |
1da177e4 | 3723 | |
2d6f0d0c JB |
3724 | if(unlikely(list_empty(&gdth_instances))) { |
3725 | gdth_timer_running = 0; | |
3726 | return; | |
3727 | } | |
b31ddd31 | 3728 | |
884f7fba | 3729 | ha = list_first_entry(&gdth_instances, gdth_ha_str, list); |
1da177e4 LT |
3730 | spin_lock_irqsave(&ha->smp_lock, flags); |
3731 | ||
3732 | for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i) | |
3733 | if (ha->cmd_tab[i].cmnd != UNUSED_CMND) | |
3734 | ++act_stats; | |
3735 | ||
3736 | for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr) | |
3737 | ++act_rq; | |
3738 | ||
3739 | TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n", | |
3740 | act_ints, act_ios, act_stats, act_rq)); | |
3741 | act_ints = act_ios = 0; | |
3742 | ||
3743 | gdth_timer.expires = jiffies + 30 * HZ; | |
3744 | add_timer(&gdth_timer); | |
3745 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
3746 | } | |
2d6f0d0c JB |
3747 | |
3748 | static void gdth_timer_init(void) | |
3749 | { | |
3750 | if (gdth_timer_running) | |
3751 | return; | |
3752 | gdth_timer_running = 1; | |
3753 | TRACE2(("gdth_detect(): Initializing timer !\n")); | |
3754 | gdth_timer.expires = jiffies + HZ; | |
3755 | gdth_timer.data = 0L; | |
3756 | gdth_timer.function = gdth_timeout; | |
3757 | add_timer(&gdth_timer); | |
3758 | } | |
3759 | #else | |
3760 | static inline void gdth_timer_init(void) | |
3761 | { | |
3762 | } | |
1da177e4 LT |
3763 | #endif |
3764 | ||
8e879041 | 3765 | static void __init internal_setup(char *str,int *ints) |
1da177e4 LT |
3766 | { |
3767 | int i, argc; | |
3768 | char *cur_str, *argv; | |
3769 | ||
3770 | TRACE2(("internal_setup() str %s ints[0] %d\n", | |
3771 | str ? str:"NULL", ints ? ints[0]:0)); | |
3772 | ||
3773 | /* read irq[] from ints[] */ | |
3774 | if (ints) { | |
3775 | argc = ints[0]; | |
3776 | if (argc > 0) { | |
3777 | if (argc > MAXHA) | |
3778 | argc = MAXHA; | |
3779 | for (i = 0; i < argc; ++i) | |
3780 | irq[i] = ints[i+1]; | |
3781 | } | |
3782 | } | |
3783 | ||
3784 | /* analyse string */ | |
3785 | argv = str; | |
3786 | while (argv && (cur_str = strchr(argv, ':'))) { | |
3787 | int val = 0, c = *++cur_str; | |
3788 | ||
3789 | if (c == 'n' || c == 'N') | |
3790 | val = 0; | |
3791 | else if (c == 'y' || c == 'Y') | |
3792 | val = 1; | |
3793 | else | |
3794 | val = (int)simple_strtoul(cur_str, NULL, 0); | |
3795 | ||
3796 | if (!strncmp(argv, "disable:", 8)) | |
3797 | disable = val; | |
3798 | else if (!strncmp(argv, "reserve_mode:", 13)) | |
3799 | reserve_mode = val; | |
3800 | else if (!strncmp(argv, "reverse_scan:", 13)) | |
3801 | reverse_scan = val; | |
3802 | else if (!strncmp(argv, "hdr_channel:", 12)) | |
3803 | hdr_channel = val; | |
3804 | else if (!strncmp(argv, "max_ids:", 8)) | |
3805 | max_ids = val; | |
3806 | else if (!strncmp(argv, "rescan:", 7)) | |
3807 | rescan = val; | |
1da177e4 LT |
3808 | else if (!strncmp(argv, "shared_access:", 14)) |
3809 | shared_access = val; | |
3810 | else if (!strncmp(argv, "probe_eisa_isa:", 15)) | |
3811 | probe_eisa_isa = val; | |
3812 | else if (!strncmp(argv, "reserve_list:", 13)) { | |
3813 | reserve_list[0] = val; | |
3814 | for (i = 1; i < MAX_RES_ARGS; i++) { | |
3815 | cur_str = strchr(cur_str, ','); | |
3816 | if (!cur_str) | |
3817 | break; | |
3818 | if (!isdigit((int)*++cur_str)) { | |
3819 | --cur_str; | |
3820 | break; | |
3821 | } | |
3822 | reserve_list[i] = | |
3823 | (int)simple_strtoul(cur_str, NULL, 0); | |
3824 | } | |
3825 | if (!cur_str) | |
3826 | break; | |
3827 | argv = ++cur_str; | |
3828 | continue; | |
3829 | } | |
3830 | ||
3831 | if ((argv = strchr(argv, ','))) | |
3832 | ++argv; | |
3833 | } | |
3834 | } | |
3835 | ||
3836 | int __init option_setup(char *str) | |
3837 | { | |
3838 | int ints[MAXHA]; | |
3839 | char *cur = str; | |
3840 | int i = 1; | |
3841 | ||
3842 | TRACE2(("option_setup() str %s\n", str ? str:"NULL")); | |
3843 | ||
3844 | while (cur && isdigit(*cur) && i <= MAXHA) { | |
3845 | ints[i++] = simple_strtoul(cur, NULL, 0); | |
3846 | if ((cur = strchr(cur, ',')) != NULL) cur++; | |
3847 | } | |
3848 | ||
3849 | ints[0] = i - 1; | |
3850 | internal_setup(cur, ints); | |
3851 | return 1; | |
3852 | } | |
3853 | ||
45f1a41b | 3854 | static const char *gdth_ctr_name(gdth_ha_str *ha) |
1da177e4 | 3855 | { |
1da177e4 LT |
3856 | TRACE2(("gdth_ctr_name()\n")); |
3857 | ||
1da177e4 LT |
3858 | if (ha->type == GDT_EISA) { |
3859 | switch (ha->stype) { | |
3860 | case GDT3_ID: | |
3861 | return("GDT3000/3020"); | |
3862 | case GDT3A_ID: | |
3863 | return("GDT3000A/3020A/3050A"); | |
3864 | case GDT3B_ID: | |
3865 | return("GDT3000B/3010A"); | |
3866 | } | |
3867 | } else if (ha->type == GDT_ISA) { | |
3868 | return("GDT2000/2020"); | |
3869 | } else if (ha->type == GDT_PCI) { | |
8e9a8a0d | 3870 | switch (ha->pdev->device) { |
1da177e4 LT |
3871 | case PCI_DEVICE_ID_VORTEX_GDT60x0: |
3872 | return("GDT6000/6020/6050"); | |
3873 | case PCI_DEVICE_ID_VORTEX_GDT6000B: | |
3874 | return("GDT6000B/6010"); | |
3875 | } | |
3876 | } | |
3877 | /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */ | |
3878 | ||
3879 | return(""); | |
3880 | } | |
3881 | ||
8e879041 | 3882 | static const char *gdth_info(struct Scsi_Host *shp) |
1da177e4 | 3883 | { |
45f1a41b | 3884 | gdth_ha_str *ha = shost_priv(shp); |
1da177e4 LT |
3885 | |
3886 | TRACE2(("gdth_info()\n")); | |
1da177e4 LT |
3887 | return ((const char *)ha->binfo.type_string); |
3888 | } | |
3889 | ||
242f9dcb JA |
3890 | static enum blk_eh_timer_return gdth_timed_out(struct scsi_cmnd *scp) |
3891 | { | |
3892 | gdth_ha_str *ha = shost_priv(scp->device->host); | |
3893 | struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); | |
1fe6dbf4 DJ |
3894 | u8 b, t; |
3895 | unsigned long flags; | |
242f9dcb JA |
3896 | enum blk_eh_timer_return retval = BLK_EH_NOT_HANDLED; |
3897 | ||
3898 | TRACE(("%s() cmd 0x%x\n", scp->cmnd[0], __func__)); | |
3899 | b = scp->device->channel; | |
3900 | t = scp->device->id; | |
3901 | ||
3902 | /* | |
3903 | * We don't really honor the command timeout, but we try to | |
3904 | * honor 6 times of the actual command timeout! So reset the | |
3905 | * timer if this is less than 6th timeout on this command! | |
3906 | */ | |
3907 | if (++cmndinfo->timeout_count < 6) | |
3908 | retval = BLK_EH_RESET_TIMER; | |
3909 | ||
3910 | /* Reset the timeout if it is locked IO */ | |
3911 | spin_lock_irqsave(&ha->smp_lock, flags); | |
3912 | if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha, b)].lock) || | |
3913 | (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) { | |
3914 | TRACE2(("%s(): locked IO, reset timeout\n", __func__)); | |
3915 | retval = BLK_EH_RESET_TIMER; | |
3916 | } | |
3917 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
3918 | ||
3919 | return retval; | |
3920 | } | |
3921 | ||
3922 | ||
8e879041 | 3923 | static int gdth_eh_bus_reset(Scsi_Cmnd *scp) |
1da177e4 | 3924 | { |
45f1a41b BH |
3925 | gdth_ha_str *ha = shost_priv(scp->device->host); |
3926 | int i; | |
1fe6dbf4 | 3927 | unsigned long flags; |
1da177e4 | 3928 | Scsi_Cmnd *cmnd; |
1fe6dbf4 | 3929 | u8 b; |
1da177e4 LT |
3930 | |
3931 | TRACE2(("gdth_eh_bus_reset()\n")); | |
3932 | ||
52759e6a | 3933 | b = scp->device->channel; |
1da177e4 LT |
3934 | |
3935 | /* clear command tab */ | |
3936 | spin_lock_irqsave(&ha->smp_lock, flags); | |
3937 | for (i = 0; i < GDTH_MAXCMDS; ++i) { | |
3938 | cmnd = ha->cmd_tab[i].cmnd; | |
3939 | if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b) | |
3940 | ha->cmd_tab[i].cmnd = UNUSED_CMND; | |
3941 | } | |
3942 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
3943 | ||
3944 | if (b == ha->virt_bus) { | |
3945 | /* host drives */ | |
3946 | for (i = 0; i < MAX_HDRIVES; ++i) { | |
3947 | if (ha->hdr[i].present) { | |
3948 | spin_lock_irqsave(&ha->smp_lock, flags); | |
3949 | gdth_polling = TRUE; | |
45f1a41b | 3950 | while (gdth_test_busy(ha)) |
1da177e4 | 3951 | gdth_delay(0); |
45f1a41b | 3952 | if (gdth_internal_cmd(ha, CACHESERVICE, |
1da177e4 LT |
3953 | GDT_CLUST_RESET, i, 0, 0)) |
3954 | ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED; | |
3955 | gdth_polling = FALSE; | |
3956 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
3957 | } | |
3958 | } | |
3959 | } else { | |
3960 | /* raw devices */ | |
3961 | spin_lock_irqsave(&ha->smp_lock, flags); | |
3962 | for (i = 0; i < MAXID; ++i) | |
3963 | ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0; | |
3964 | gdth_polling = TRUE; | |
45f1a41b | 3965 | while (gdth_test_busy(ha)) |
1da177e4 | 3966 | gdth_delay(0); |
45f1a41b | 3967 | gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_RESET_BUS, |
1da177e4 LT |
3968 | BUS_L2P(ha,b), 0, 0); |
3969 | gdth_polling = FALSE; | |
cbd5f69b | 3970 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
3971 | } |
3972 | return SUCCESS; | |
3973 | } | |
3974 | ||
8e879041 | 3975 | static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip) |
1da177e4 | 3976 | { |
1fe6dbf4 | 3977 | u8 b, t; |
45f1a41b | 3978 | gdth_ha_str *ha = shost_priv(sdev->host); |
1da177e4 LT |
3979 | struct scsi_device *sd; |
3980 | unsigned capacity; | |
3981 | ||
1da177e4 LT |
3982 | sd = sdev; |
3983 | capacity = cap; | |
52759e6a | 3984 | b = sd->channel; |
1da177e4 | 3985 | t = sd->id; |
45f1a41b | 3986 | TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", ha->hanum, b, t)); |
1da177e4 LT |
3987 | |
3988 | if (b != ha->virt_bus || ha->hdr[t].heads == 0) { | |
3989 | /* raw device or host drive without mapping information */ | |
3990 | TRACE2(("Evaluate mapping\n")); | |
3991 | gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]); | |
3992 | } else { | |
3993 | ip[0] = ha->hdr[t].heads; | |
3994 | ip[1] = ha->hdr[t].secs; | |
3995 | ip[2] = capacity / ip[0] / ip[1]; | |
3996 | } | |
3997 | ||
3998 | TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n", | |
3999 | ip[0],ip[1],ip[2])); | |
4000 | return 0; | |
4001 | } | |
4002 | ||
4003 | ||
b8bff2ae MW |
4004 | static int gdth_queuecommand(struct scsi_cmnd *scp, |
4005 | void (*done)(struct scsi_cmnd *)) | |
1da177e4 | 4006 | { |
45f1a41b | 4007 | gdth_ha_str *ha = shost_priv(scp->device->host); |
3058d5de | 4008 | struct gdth_cmndinfo *cmndinfo; |
1da177e4 LT |
4009 | |
4010 | TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0])); | |
3058d5de BH |
4011 | |
4012 | cmndinfo = gdth_get_cmndinfo(ha); | |
4013 | BUG_ON(!cmndinfo); | |
4014 | ||
b8bff2ae | 4015 | scp->scsi_done = done; |
242f9dcb | 4016 | cmndinfo->timeout_count = 0; |
f842b64e | 4017 | cmndinfo->priority = DEFAULT_PRI; |
3892d88a | 4018 | |
3058d5de BH |
4019 | return __gdth_queuecommand(ha, scp, cmndinfo); |
4020 | } | |
4021 | ||
4022 | static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, | |
4023 | struct gdth_cmndinfo *cmndinfo) | |
4024 | { | |
4025 | scp->host_scribble = (unsigned char *)cmndinfo; | |
f842b64e BH |
4026 | cmndinfo->wait_for_completion = 1; |
4027 | cmndinfo->phase = -1; | |
4028 | cmndinfo->OpCode = -1; | |
1da177e4 | 4029 | |
1da177e4 LT |
4030 | #ifdef GDTH_STATISTICS |
4031 | ++act_ios; | |
4032 | #endif | |
4033 | ||
f842b64e | 4034 | gdth_putq(ha, scp, cmndinfo->priority); |
45f1a41b | 4035 | gdth_next(ha); |
1da177e4 LT |
4036 | return 0; |
4037 | } | |
4038 | ||
4039 | ||
4040 | static int gdth_open(struct inode *inode, struct file *filep) | |
4041 | { | |
4042 | gdth_ha_str *ha; | |
1da177e4 | 4043 | |
46787b48 | 4044 | lock_kernel(); |
884f7fba | 4045 | list_for_each_entry(ha, &gdth_instances, list) { |
1da177e4 | 4046 | if (!ha->sdev) |
884f7fba | 4047 | ha->sdev = scsi_get_host_dev(ha->shost); |
1da177e4 | 4048 | } |
46787b48 | 4049 | unlock_kernel(); |
1da177e4 LT |
4050 | |
4051 | TRACE(("gdth_open()\n")); | |
4052 | return 0; | |
4053 | } | |
4054 | ||
4055 | static int gdth_close(struct inode *inode, struct file *filep) | |
4056 | { | |
4057 | TRACE(("gdth_close()\n")); | |
4058 | return 0; | |
4059 | } | |
4060 | ||
4061 | static int ioc_event(void __user *arg) | |
4062 | { | |
4063 | gdth_ioctl_event evt; | |
4064 | gdth_ha_str *ha; | |
1fe6dbf4 | 4065 | unsigned long flags; |
1da177e4 | 4066 | |
884f7fba BH |
4067 | if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event))) |
4068 | return -EFAULT; | |
4069 | ha = gdth_find_ha(evt.ionode); | |
4070 | if (!ha) | |
1da177e4 | 4071 | return -EFAULT; |
1da177e4 LT |
4072 | |
4073 | if (evt.erase == 0xff) { | |
4074 | if (evt.event.event_source == ES_TEST) | |
4075 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.test); | |
4076 | else if (evt.event.event_source == ES_DRIVER) | |
4077 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver); | |
4078 | else if (evt.event.event_source == ES_SYNC) | |
4079 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync); | |
4080 | else | |
4081 | evt.event.event_data.size=sizeof(evt.event.event_data.eu.async); | |
4082 | spin_lock_irqsave(&ha->smp_lock, flags); | |
4083 | gdth_store_event(ha, evt.event.event_source, evt.event.event_idx, | |
4084 | &evt.event.event_data); | |
4085 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
4086 | } else if (evt.erase == 0xfe) { | |
4087 | gdth_clear_events(); | |
4088 | } else if (evt.erase == 0) { | |
4089 | evt.handle = gdth_read_event(ha, evt.handle, &evt.event); | |
4090 | } else { | |
4091 | gdth_readapp_event(ha, evt.erase, &evt.event); | |
4092 | } | |
4093 | if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event))) | |
4094 | return -EFAULT; | |
4095 | return 0; | |
4096 | } | |
4097 | ||
4098 | static int ioc_lockdrv(void __user *arg) | |
4099 | { | |
4100 | gdth_ioctl_lockdrv ldrv; | |
1fe6dbf4 DJ |
4101 | u8 i, j; |
4102 | unsigned long flags; | |
1da177e4 LT |
4103 | gdth_ha_str *ha; |
4104 | ||
884f7fba | 4105 | if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv))) |
1da177e4 | 4106 | return -EFAULT; |
884f7fba BH |
4107 | ha = gdth_find_ha(ldrv.ionode); |
4108 | if (!ha) | |
4109 | return -EFAULT; | |
4110 | ||
1da177e4 LT |
4111 | for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) { |
4112 | j = ldrv.drives[i]; | |
4113 | if (j >= MAX_HDRIVES || !ha->hdr[j].present) | |
4114 | continue; | |
4115 | if (ldrv.lock) { | |
4116 | spin_lock_irqsave(&ha->smp_lock, flags); | |
4117 | ha->hdr[j].lock = 1; | |
4118 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
45f1a41b | 4119 | gdth_wait_completion(ha, ha->bus_cnt, j); |
1da177e4 LT |
4120 | } else { |
4121 | spin_lock_irqsave(&ha->smp_lock, flags); | |
4122 | ha->hdr[j].lock = 0; | |
4123 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
45f1a41b | 4124 | gdth_next(ha); |
1da177e4 LT |
4125 | } |
4126 | } | |
4127 | return 0; | |
4128 | } | |
4129 | ||
4130 | static int ioc_resetdrv(void __user *arg, char *cmnd) | |
4131 | { | |
4132 | gdth_ioctl_reset res; | |
4133 | gdth_cmd_str cmd; | |
1da177e4 | 4134 | gdth_ha_str *ha; |
cbd5f69b | 4135 | int rval; |
1da177e4 LT |
4136 | |
4137 | if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) || | |
884f7fba BH |
4138 | res.number >= MAX_HDRIVES) |
4139 | return -EFAULT; | |
4140 | ha = gdth_find_ha(res.ionode); | |
4141 | if (!ha) | |
1da177e4 | 4142 | return -EFAULT; |
45f1a41b | 4143 | |
1da177e4 LT |
4144 | if (!ha->hdr[res.number].present) |
4145 | return 0; | |
4146 | memset(&cmd, 0, sizeof(gdth_cmd_str)); | |
4147 | cmd.Service = CACHESERVICE; | |
4148 | cmd.OpCode = GDT_CLUST_RESET; | |
4149 | if (ha->cache_feat & GDT_64BIT) | |
4150 | cmd.u.cache64.DeviceNo = res.number; | |
4151 | else | |
4152 | cmd.u.cache.DeviceNo = res.number; | |
cbd5f69b LA |
4153 | |
4154 | rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL); | |
4155 | if (rval < 0) | |
4156 | return rval; | |
4157 | res.status = rval; | |
1da177e4 LT |
4158 | |
4159 | if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset))) | |
4160 | return -EFAULT; | |
4161 | return 0; | |
4162 | } | |
4163 | ||
4164 | static int ioc_general(void __user *arg, char *cmnd) | |
4165 | { | |
4166 | gdth_ioctl_general gen; | |
4167 | char *buf = NULL; | |
1fe6dbf4 | 4168 | u64 paddr; |
cbd5f69b LA |
4169 | gdth_ha_str *ha; |
4170 | int rval; | |
884f7fba BH |
4171 | |
4172 | if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general))) | |
4173 | return -EFAULT; | |
4174 | ha = gdth_find_ha(gen.ionode); | |
4175 | if (!ha) | |
1da177e4 | 4176 | return -EFAULT; |
1da177e4 | 4177 | if (gen.data_len + gen.sense_len != 0) { |
45f1a41b | 4178 | if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len, |
1da177e4 LT |
4179 | FALSE, &paddr))) |
4180 | return -EFAULT; | |
4181 | if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general), | |
4182 | gen.data_len + gen.sense_len)) { | |
45f1a41b | 4183 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
1da177e4 LT |
4184 | return -EFAULT; |
4185 | } | |
4186 | ||
4187 | if (gen.command.OpCode == GDT_IOCTL) { | |
4188 | gen.command.u.ioctl.p_param = paddr; | |
4189 | } else if (gen.command.Service == CACHESERVICE) { | |
4190 | if (ha->cache_feat & GDT_64BIT) { | |
4191 | /* copy elements from 32-bit IOCTL structure */ | |
4192 | gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt; | |
4193 | gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo; | |
4194 | gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo; | |
4195 | /* addresses */ | |
4196 | if (ha->cache_feat & SCATTER_GATHER) { | |
1fe6dbf4 | 4197 | gen.command.u.cache64.DestAddr = (u64)-1; |
1da177e4 LT |
4198 | gen.command.u.cache64.sg_canz = 1; |
4199 | gen.command.u.cache64.sg_lst[0].sg_ptr = paddr; | |
4200 | gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len; | |
4201 | gen.command.u.cache64.sg_lst[1].sg_len = 0; | |
4202 | } else { | |
4203 | gen.command.u.cache64.DestAddr = paddr; | |
4204 | gen.command.u.cache64.sg_canz = 0; | |
4205 | } | |
4206 | } else { | |
4207 | if (ha->cache_feat & SCATTER_GATHER) { | |
4208 | gen.command.u.cache.DestAddr = 0xffffffff; | |
4209 | gen.command.u.cache.sg_canz = 1; | |
1fe6dbf4 | 4210 | gen.command.u.cache.sg_lst[0].sg_ptr = (u32)paddr; |
1da177e4 LT |
4211 | gen.command.u.cache.sg_lst[0].sg_len = gen.data_len; |
4212 | gen.command.u.cache.sg_lst[1].sg_len = 0; | |
4213 | } else { | |
4214 | gen.command.u.cache.DestAddr = paddr; | |
4215 | gen.command.u.cache.sg_canz = 0; | |
4216 | } | |
4217 | } | |
4218 | } else if (gen.command.Service == SCSIRAWSERVICE) { | |
4219 | if (ha->raw_feat & GDT_64BIT) { | |
4220 | /* copy elements from 32-bit IOCTL structure */ | |
4221 | char cmd[16]; | |
4222 | gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len; | |
4223 | gen.command.u.raw64.bus = gen.command.u.raw.bus; | |
4224 | gen.command.u.raw64.lun = gen.command.u.raw.lun; | |
4225 | gen.command.u.raw64.target = gen.command.u.raw.target; | |
4226 | memcpy(cmd, gen.command.u.raw.cmd, 16); | |
4227 | memcpy(gen.command.u.raw64.cmd, cmd, 16); | |
4228 | gen.command.u.raw64.clen = gen.command.u.raw.clen; | |
4229 | gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen; | |
4230 | gen.command.u.raw64.direction = gen.command.u.raw.direction; | |
4231 | /* addresses */ | |
4232 | if (ha->raw_feat & SCATTER_GATHER) { | |
1fe6dbf4 | 4233 | gen.command.u.raw64.sdata = (u64)-1; |
1da177e4 LT |
4234 | gen.command.u.raw64.sg_ranz = 1; |
4235 | gen.command.u.raw64.sg_lst[0].sg_ptr = paddr; | |
4236 | gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len; | |
4237 | gen.command.u.raw64.sg_lst[1].sg_len = 0; | |
4238 | } else { | |
4239 | gen.command.u.raw64.sdata = paddr; | |
4240 | gen.command.u.raw64.sg_ranz = 0; | |
4241 | } | |
4242 | gen.command.u.raw64.sense_data = paddr + gen.data_len; | |
4243 | } else { | |
4244 | if (ha->raw_feat & SCATTER_GATHER) { | |
4245 | gen.command.u.raw.sdata = 0xffffffff; | |
4246 | gen.command.u.raw.sg_ranz = 1; | |
1fe6dbf4 | 4247 | gen.command.u.raw.sg_lst[0].sg_ptr = (u32)paddr; |
1da177e4 LT |
4248 | gen.command.u.raw.sg_lst[0].sg_len = gen.data_len; |
4249 | gen.command.u.raw.sg_lst[1].sg_len = 0; | |
4250 | } else { | |
4251 | gen.command.u.raw.sdata = paddr; | |
4252 | gen.command.u.raw.sg_ranz = 0; | |
4253 | } | |
1fe6dbf4 | 4254 | gen.command.u.raw.sense_data = (u32)paddr + gen.data_len; |
1da177e4 LT |
4255 | } |
4256 | } else { | |
45f1a41b | 4257 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
1da177e4 LT |
4258 | return -EFAULT; |
4259 | } | |
4260 | } | |
4261 | ||
cbd5f69b LA |
4262 | rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info); |
4263 | if (rval < 0) | |
4264 | return rval; | |
4265 | gen.status = rval; | |
1da177e4 LT |
4266 | |
4267 | if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf, | |
4268 | gen.data_len + gen.sense_len)) { | |
45f1a41b | 4269 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
1da177e4 LT |
4270 | return -EFAULT; |
4271 | } | |
4272 | if (copy_to_user(arg, &gen, | |
4273 | sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) { | |
45f1a41b | 4274 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
1da177e4 LT |
4275 | return -EFAULT; |
4276 | } | |
45f1a41b | 4277 | gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); |
1da177e4 LT |
4278 | return 0; |
4279 | } | |
4280 | ||
4281 | static int ioc_hdrlist(void __user *arg, char *cmnd) | |
4282 | { | |
4283 | gdth_ioctl_rescan *rsc; | |
4284 | gdth_cmd_str *cmd; | |
4285 | gdth_ha_str *ha; | |
1fe6dbf4 | 4286 | u8 i; |
45f1a41b | 4287 | int rc = -ENOMEM; |
cbd5f69b LA |
4288 | u32 cluster_type = 0; |
4289 | ||
1da177e4 LT |
4290 | rsc = kmalloc(sizeof(*rsc), GFP_KERNEL); |
4291 | cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); | |
4292 | if (!rsc || !cmd) | |
cbd5f69b | 4293 | goto free_fail; |
1da177e4 LT |
4294 | |
4295 | if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) || | |
884f7fba | 4296 | (NULL == (ha = gdth_find_ha(rsc->ionode)))) { |
1da177e4 | 4297 | rc = -EFAULT; |
cbd5f69b | 4298 | goto free_fail; |
1da177e4 | 4299 | } |
1da177e4 LT |
4300 | memset(cmd, 0, sizeof(gdth_cmd_str)); |
4301 | ||
1da177e4 LT |
4302 | for (i = 0; i < MAX_HDRIVES; ++i) { |
4303 | if (!ha->hdr[i].present) { | |
4304 | rsc->hdr_list[i].bus = 0xff; | |
4305 | continue; | |
4306 | } | |
4307 | rsc->hdr_list[i].bus = ha->virt_bus; | |
4308 | rsc->hdr_list[i].target = i; | |
4309 | rsc->hdr_list[i].lun = 0; | |
4310 | rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type; | |
4311 | if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) { | |
4312 | cmd->Service = CACHESERVICE; | |
4313 | cmd->OpCode = GDT_CLUST_INFO; | |
4314 | if (ha->cache_feat & GDT_64BIT) | |
4315 | cmd->u.cache64.DeviceNo = i; | |
4316 | else | |
4317 | cmd->u.cache.DeviceNo = i; | |
cbd5f69b LA |
4318 | if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK) |
4319 | rsc->hdr_list[i].cluster_type = cluster_type; | |
1da177e4 LT |
4320 | } |
4321 | } | |
cbd5f69b | 4322 | |
1da177e4 LT |
4323 | if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan))) |
4324 | rc = -EFAULT; | |
4325 | else | |
cbd5f69b | 4326 | rc = 0; |
1da177e4 LT |
4327 | |
4328 | free_fail: | |
4329 | kfree(rsc); | |
4330 | kfree(cmd); | |
4331 | return rc; | |
4332 | } | |
4333 | ||
4334 | static int ioc_rescan(void __user *arg, char *cmnd) | |
4335 | { | |
4336 | gdth_ioctl_rescan *rsc; | |
4337 | gdth_cmd_str *cmd; | |
1fe6dbf4 DJ |
4338 | u16 i, status, hdr_cnt; |
4339 | u32 info; | |
45f1a41b | 4340 | int cyls, hds, secs; |
1da177e4 | 4341 | int rc = -ENOMEM; |
1fe6dbf4 | 4342 | unsigned long flags; |
1da177e4 | 4343 | gdth_ha_str *ha; |
1da177e4 LT |
4344 | |
4345 | rsc = kmalloc(sizeof(*rsc), GFP_KERNEL); | |
4346 | cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); | |
4347 | if (!cmd || !rsc) | |
cbd5f69b | 4348 | goto free_fail; |
1da177e4 LT |
4349 | |
4350 | if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) || | |
884f7fba | 4351 | (NULL == (ha = gdth_find_ha(rsc->ionode)))) { |
cbd5f69b LA |
4352 | rc = -EFAULT; |
4353 | goto free_fail; | |
1da177e4 | 4354 | } |
1da177e4 LT |
4355 | memset(cmd, 0, sizeof(gdth_cmd_str)); |
4356 | ||
1da177e4 LT |
4357 | if (rsc->flag == 0) { |
4358 | /* old method: re-init. cache service */ | |
4359 | cmd->Service = CACHESERVICE; | |
4360 | if (ha->cache_feat & GDT_64BIT) { | |
4361 | cmd->OpCode = GDT_X_INIT_HOST; | |
4362 | cmd->u.cache64.DeviceNo = LINUX_OS; | |
4363 | } else { | |
4364 | cmd->OpCode = GDT_INIT; | |
4365 | cmd->u.cache.DeviceNo = LINUX_OS; | |
4366 | } | |
cbd5f69b LA |
4367 | |
4368 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); | |
1da177e4 | 4369 | i = 0; |
1fe6dbf4 | 4370 | hdr_cnt = (status == S_OK ? (u16)info : 0); |
1da177e4 LT |
4371 | } else { |
4372 | i = rsc->hdr_no; | |
4373 | hdr_cnt = i + 1; | |
4374 | } | |
4375 | ||
4376 | for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) { | |
4377 | cmd->Service = CACHESERVICE; | |
4378 | cmd->OpCode = GDT_INFO; | |
4379 | if (ha->cache_feat & GDT_64BIT) | |
4380 | cmd->u.cache64.DeviceNo = i; | |
4381 | else | |
4382 | cmd->u.cache.DeviceNo = i; | |
cbd5f69b LA |
4383 | |
4384 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); | |
4385 | ||
1da177e4 LT |
4386 | spin_lock_irqsave(&ha->smp_lock, flags); |
4387 | rsc->hdr_list[i].bus = ha->virt_bus; | |
4388 | rsc->hdr_list[i].target = i; | |
4389 | rsc->hdr_list[i].lun = 0; | |
4390 | if (status != S_OK) { | |
4391 | ha->hdr[i].present = FALSE; | |
4392 | } else { | |
4393 | ha->hdr[i].present = TRUE; | |
4394 | ha->hdr[i].size = info; | |
4395 | /* evaluate mapping */ | |
4396 | ha->hdr[i].size &= ~SECS32; | |
4397 | gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs); | |
4398 | ha->hdr[i].heads = hds; | |
4399 | ha->hdr[i].secs = secs; | |
4400 | /* round size */ | |
4401 | ha->hdr[i].size = cyls * hds * secs; | |
4402 | } | |
4403 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
4404 | if (status != S_OK) | |
4405 | continue; | |
4406 | ||
4407 | /* extended info, if GDT_64BIT, for drives > 2 TB */ | |
4408 | /* but we need ha->info2, not yet stored in scp->SCp */ | |
4409 | ||
4410 | /* devtype, cluster info, R/W attribs */ | |
4411 | cmd->Service = CACHESERVICE; | |
4412 | cmd->OpCode = GDT_DEVTYPE; | |
4413 | if (ha->cache_feat & GDT_64BIT) | |
4414 | cmd->u.cache64.DeviceNo = i; | |
4415 | else | |
4416 | cmd->u.cache.DeviceNo = i; | |
cbd5f69b LA |
4417 | |
4418 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); | |
4419 | ||
1da177e4 | 4420 | spin_lock_irqsave(&ha->smp_lock, flags); |
1fe6dbf4 | 4421 | ha->hdr[i].devtype = (status == S_OK ? (u16)info : 0); |
1da177e4 LT |
4422 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
4423 | ||
4424 | cmd->Service = CACHESERVICE; | |
4425 | cmd->OpCode = GDT_CLUST_INFO; | |
4426 | if (ha->cache_feat & GDT_64BIT) | |
4427 | cmd->u.cache64.DeviceNo = i; | |
4428 | else | |
4429 | cmd->u.cache.DeviceNo = i; | |
cbd5f69b LA |
4430 | |
4431 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); | |
4432 | ||
1da177e4 LT |
4433 | spin_lock_irqsave(&ha->smp_lock, flags); |
4434 | ha->hdr[i].cluster_type = | |
1fe6dbf4 | 4435 | ((status == S_OK && !shared_access) ? (u16)info : 0); |
1da177e4 LT |
4436 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
4437 | rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type; | |
4438 | ||
4439 | cmd->Service = CACHESERVICE; | |
4440 | cmd->OpCode = GDT_RW_ATTRIBS; | |
4441 | if (ha->cache_feat & GDT_64BIT) | |
4442 | cmd->u.cache64.DeviceNo = i; | |
4443 | else | |
4444 | cmd->u.cache.DeviceNo = i; | |
cbd5f69b LA |
4445 | |
4446 | status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); | |
4447 | ||
1da177e4 | 4448 | spin_lock_irqsave(&ha->smp_lock, flags); |
1fe6dbf4 | 4449 | ha->hdr[i].rw_attribs = (status == S_OK ? (u16)info : 0); |
1da177e4 LT |
4450 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
4451 | } | |
1da177e4 LT |
4452 | |
4453 | if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan))) | |
4454 | rc = -EFAULT; | |
4455 | else | |
cbd5f69b | 4456 | rc = 0; |
1da177e4 LT |
4457 | |
4458 | free_fail: | |
4459 | kfree(rsc); | |
4460 | kfree(cmd); | |
4461 | return rc; | |
4462 | } | |
4463 | ||
4464 | static int gdth_ioctl(struct inode *inode, struct file *filep, | |
4465 | unsigned int cmd, unsigned long arg) | |
4466 | { | |
4467 | gdth_ha_str *ha; | |
4468 | Scsi_Cmnd *scp; | |
1fe6dbf4 | 4469 | unsigned long flags; |
1da177e4 LT |
4470 | char cmnd[MAX_COMMAND_SIZE]; |
4471 | void __user *argp = (void __user *)arg; | |
4472 | ||
4473 | memset(cmnd, 0xff, 12); | |
4474 | ||
4475 | TRACE(("gdth_ioctl() cmd 0x%x\n", cmd)); | |
4476 | ||
4477 | switch (cmd) { | |
4478 | case GDTIOCTL_CTRCNT: | |
4479 | { | |
4480 | int cnt = gdth_ctr_count; | |
4481 | if (put_user(cnt, (int __user *)argp)) | |
4482 | return -EFAULT; | |
4483 | break; | |
4484 | } | |
4485 | ||
4486 | case GDTIOCTL_DRVERS: | |
4487 | { | |
4488 | int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION; | |
4489 | if (put_user(ver, (int __user *)argp)) | |
4490 | return -EFAULT; | |
4491 | break; | |
4492 | } | |
4493 | ||
4494 | case GDTIOCTL_OSVERS: | |
4495 | { | |
4496 | gdth_ioctl_osvers osv; | |
4497 | ||
1fe6dbf4 DJ |
4498 | osv.version = (u8)(LINUX_VERSION_CODE >> 16); |
4499 | osv.subversion = (u8)(LINUX_VERSION_CODE >> 8); | |
4500 | osv.revision = (u16)(LINUX_VERSION_CODE & 0xff); | |
1da177e4 LT |
4501 | if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers))) |
4502 | return -EFAULT; | |
4503 | break; | |
4504 | } | |
4505 | ||
4506 | case GDTIOCTL_CTRTYPE: | |
4507 | { | |
4508 | gdth_ioctl_ctrtype ctrt; | |
4509 | ||
4510 | if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) || | |
884f7fba | 4511 | (NULL == (ha = gdth_find_ha(ctrt.ionode)))) |
1da177e4 | 4512 | return -EFAULT; |
884f7fba | 4513 | |
1da177e4 | 4514 | if (ha->type == GDT_ISA || ha->type == GDT_EISA) { |
1fe6dbf4 | 4515 | ctrt.type = (u8)((ha->stype>>20) - 0x10); |
1da177e4 LT |
4516 | } else { |
4517 | if (ha->type != GDT_PCIMPR) { | |
1fe6dbf4 | 4518 | ctrt.type = (u8)((ha->stype<<4) + 6); |
1da177e4 LT |
4519 | } else { |
4520 | ctrt.type = | |
4521 | (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe); | |
4522 | if (ha->stype >= 0x300) | |
8e9a8a0d | 4523 | ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device; |
1da177e4 LT |
4524 | else |
4525 | ctrt.ext_type = 0x6000 | ha->stype; | |
4526 | } | |
8e9a8a0d JG |
4527 | ctrt.device_id = ha->pdev->device; |
4528 | ctrt.sub_device_id = ha->pdev->subsystem_device; | |
1da177e4 LT |
4529 | } |
4530 | ctrt.info = ha->brd_phys; | |
4531 | ctrt.oem_id = ha->oem_id; | |
4532 | if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype))) | |
4533 | return -EFAULT; | |
4534 | break; | |
4535 | } | |
4536 | ||
4537 | case GDTIOCTL_GENERAL: | |
4538 | return ioc_general(argp, cmnd); | |
4539 | ||
4540 | case GDTIOCTL_EVENT: | |
4541 | return ioc_event(argp); | |
4542 | ||
4543 | case GDTIOCTL_LOCKDRV: | |
4544 | return ioc_lockdrv(argp); | |
4545 | ||
4546 | case GDTIOCTL_LOCKCHN: | |
4547 | { | |
4548 | gdth_ioctl_lockchn lchn; | |
1fe6dbf4 | 4549 | u8 i, j; |
1da177e4 LT |
4550 | |
4551 | if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) || | |
884f7fba | 4552 | (NULL == (ha = gdth_find_ha(lchn.ionode)))) |
1da177e4 | 4553 | return -EFAULT; |
884f7fba | 4554 | |
1da177e4 LT |
4555 | i = lchn.channel; |
4556 | if (i < ha->bus_cnt) { | |
4557 | if (lchn.lock) { | |
4558 | spin_lock_irqsave(&ha->smp_lock, flags); | |
4559 | ha->raw[i].lock = 1; | |
4560 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
242f9dcb | 4561 | for (j = 0; j < ha->tid_cnt; ++j) |
45f1a41b | 4562 | gdth_wait_completion(ha, i, j); |
1da177e4 LT |
4563 | } else { |
4564 | spin_lock_irqsave(&ha->smp_lock, flags); | |
4565 | ha->raw[i].lock = 0; | |
4566 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
242f9dcb | 4567 | for (j = 0; j < ha->tid_cnt; ++j) |
45f1a41b | 4568 | gdth_next(ha); |
1da177e4 LT |
4569 | } |
4570 | } | |
4571 | break; | |
4572 | } | |
4573 | ||
4574 | case GDTIOCTL_RESCAN: | |
4575 | return ioc_rescan(argp, cmnd); | |
4576 | ||
4577 | case GDTIOCTL_HDRLIST: | |
4578 | return ioc_hdrlist(argp, cmnd); | |
4579 | ||
4580 | case GDTIOCTL_RESET_BUS: | |
4581 | { | |
4582 | gdth_ioctl_reset res; | |
45f1a41b | 4583 | int rval; |
1da177e4 LT |
4584 | |
4585 | if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) || | |
884f7fba | 4586 | (NULL == (ha = gdth_find_ha(res.ionode)))) |
1da177e4 | 4587 | return -EFAULT; |
1da177e4 | 4588 | |
bbfbbbc1 | 4589 | scp = kzalloc(sizeof(*scp), GFP_KERNEL); |
1da177e4 LT |
4590 | if (!scp) |
4591 | return -ENOMEM; | |
cbd5f69b | 4592 | scp->device = ha->sdev; |
1da177e4 | 4593 | scp->cmd_len = 12; |
52759e6a | 4594 | scp->device->channel = res.number; |
1da177e4 LT |
4595 | rval = gdth_eh_bus_reset(scp); |
4596 | res.status = (rval == SUCCESS ? S_OK : S_GENERR); | |
cbd5f69b | 4597 | kfree(scp); |
8d7a5da4 | 4598 | |
1da177e4 LT |
4599 | if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset))) |
4600 | return -EFAULT; | |
4601 | break; | |
4602 | } | |
4603 | ||
4604 | case GDTIOCTL_RESET_DRV: | |
4605 | return ioc_resetdrv(argp, cmnd); | |
4606 | ||
4607 | default: | |
4608 | break; | |
4609 | } | |
4610 | return 0; | |
4611 | } | |
4612 | ||
4613 | ||
4614 | /* flush routine */ | |
45f1a41b | 4615 | static void gdth_flush(gdth_ha_str *ha) |
1da177e4 LT |
4616 | { |
4617 | int i; | |
1da177e4 | 4618 | gdth_cmd_str gdtcmd; |
1da177e4 LT |
4619 | char cmnd[MAX_COMMAND_SIZE]; |
4620 | memset(cmnd, 0xff, MAX_COMMAND_SIZE); | |
4621 | ||
45f1a41b | 4622 | TRACE2(("gdth_flush() hanum %d\n", ha->hanum)); |
1da177e4 | 4623 | |
1da177e4 LT |
4624 | for (i = 0; i < MAX_HDRIVES; ++i) { |
4625 | if (ha->hdr[i].present) { | |
4626 | gdtcmd.BoardNode = LOCALBOARD; | |
4627 | gdtcmd.Service = CACHESERVICE; | |
4628 | gdtcmd.OpCode = GDT_FLUSH; | |
4629 | if (ha->cache_feat & GDT_64BIT) { | |
4630 | gdtcmd.u.cache64.DeviceNo = i; | |
4631 | gdtcmd.u.cache64.BlockNo = 1; | |
4632 | gdtcmd.u.cache64.sg_canz = 0; | |
4633 | } else { | |
4634 | gdtcmd.u.cache.DeviceNo = i; | |
4635 | gdtcmd.u.cache.BlockNo = 1; | |
4636 | gdtcmd.u.cache.sg_canz = 0; | |
4637 | } | |
45f1a41b | 4638 | TRACE2(("gdth_flush(): flush ha %d drive %d\n", ha->hanum, i)); |
cbd5f69b | 4639 | |
45f1a41b | 4640 | gdth_execute(ha->shost, &gdtcmd, cmnd, 30, NULL); |
1da177e4 LT |
4641 | } |
4642 | } | |
1da177e4 LT |
4643 | } |
4644 | ||
cbd5f69b LA |
4645 | /* configure lun */ |
4646 | static int gdth_slave_configure(struct scsi_device *sdev) | |
4647 | { | |
4648 | scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); | |
4649 | sdev->skip_ms_page_3f = 1; | |
4650 | sdev->skip_ms_page_8 = 1; | |
4651 | return 0; | |
4652 | } | |
cbd5f69b | 4653 | |
835cc24a | 4654 | static struct scsi_host_template gdth_template = { |
1da177e4 | 4655 | .name = "GDT SCSI Disk Array Controller", |
1da177e4 LT |
4656 | .info = gdth_info, |
4657 | .queuecommand = gdth_queuecommand, | |
1da177e4 | 4658 | .eh_bus_reset_handler = gdth_eh_bus_reset, |
69916b7c | 4659 | .slave_configure = gdth_slave_configure, |
1da177e4 | 4660 | .bios_param = gdth_bios_param, |
69916b7c | 4661 | .proc_info = gdth_proc_info, |
242f9dcb | 4662 | .eh_timed_out = gdth_timed_out, |
69916b7c | 4663 | .proc_name = "gdth", |
1da177e4 LT |
4664 | .can_queue = GDTH_MAXCMDS, |
4665 | .this_id = -1, | |
4666 | .sg_tablesize = GDTH_MAXSG, | |
4667 | .cmd_per_lun = GDTH_MAXC_P_L, | |
4668 | .unchecked_isa_dma = 1, | |
4669 | .use_clustering = ENABLE_CLUSTERING, | |
1da177e4 LT |
4670 | }; |
4671 | ||
aed91cb5 | 4672 | #ifdef CONFIG_ISA |
1fe6dbf4 | 4673 | static int __init gdth_isa_probe_one(u32 isa_bios) |
aed91cb5 CH |
4674 | { |
4675 | struct Scsi_Host *shp; | |
4676 | gdth_ha_str *ha; | |
4677 | dma_addr_t scratch_dma_handle = 0; | |
884f7fba | 4678 | int error, i; |
aed91cb5 CH |
4679 | |
4680 | if (!gdth_search_isa(isa_bios)) | |
4681 | return -ENXIO; | |
4682 | ||
835cc24a | 4683 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
aed91cb5 CH |
4684 | if (!shp) |
4685 | return -ENOMEM; | |
45f1a41b | 4686 | ha = shost_priv(shp); |
aed91cb5 CH |
4687 | |
4688 | error = -ENODEV; | |
4689 | if (!gdth_init_isa(isa_bios,ha)) | |
4690 | goto out_host_put; | |
4691 | ||
4692 | /* controller found and initialized */ | |
4693 | printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n", | |
4694 | isa_bios, ha->irq, ha->drq); | |
4695 | ||
4696 | error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha); | |
4697 | if (error) { | |
4698 | printk("GDT-ISA: Unable to allocate IRQ\n"); | |
4699 | goto out_host_put; | |
4700 | } | |
4701 | ||
4702 | error = request_dma(ha->drq, "gdth"); | |
4703 | if (error) { | |
4704 | printk("GDT-ISA: Unable to allocate DMA channel\n"); | |
4705 | goto out_free_irq; | |
4706 | } | |
4707 | ||
4708 | set_dma_mode(ha->drq,DMA_MODE_CASCADE); | |
4709 | enable_dma(ha->drq); | |
4710 | shp->unchecked_isa_dma = 1; | |
4711 | shp->irq = ha->irq; | |
4712 | shp->dma_channel = ha->drq; | |
aed91cb5 | 4713 | |
884f7fba | 4714 | ha->hanum = gdth_ctr_count++; |
45f1a41b | 4715 | ha->shost = shp; |
aed91cb5 | 4716 | |
45f1a41b | 4717 | ha->pccb = &ha->cmdext; |
aed91cb5 CH |
4718 | ha->ccb_phys = 0L; |
4719 | ha->pdev = NULL; | |
4720 | ||
4721 | error = -ENOMEM; | |
4722 | ||
4723 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, | |
4724 | &scratch_dma_handle); | |
4725 | if (!ha->pscratch) | |
4726 | goto out_dec_counters; | |
4727 | ha->scratch_phys = scratch_dma_handle; | |
4728 | ||
4729 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), | |
4730 | &scratch_dma_handle); | |
4731 | if (!ha->pmsg) | |
4732 | goto out_free_pscratch; | |
4733 | ha->msg_phys = scratch_dma_handle; | |
4734 | ||
4735 | #ifdef INT_COAL | |
4736 | ha->coal_stat = pci_alloc_consistent(ha->pdev, | |
4737 | sizeof(gdth_coal_status) * MAXOFFSETS, | |
4738 | &scratch_dma_handle); | |
4739 | if (!ha->coal_stat) | |
4740 | goto out_free_pmsg; | |
4741 | ha->coal_stat_phys = scratch_dma_handle; | |
4742 | #endif | |
4743 | ||
4744 | ha->scratch_busy = FALSE; | |
4745 | ha->req_first = NULL; | |
4746 | ha->tid_cnt = MAX_HDRIVES; | |
4747 | if (max_ids > 0 && max_ids < ha->tid_cnt) | |
4748 | ha->tid_cnt = max_ids; | |
4749 | for (i = 0; i < GDTH_MAXCMDS; ++i) | |
4750 | ha->cmd_tab[i].cmnd = UNUSED_CMND; | |
4751 | ha->scan_mode = rescan ? 0x10 : 0; | |
4752 | ||
4753 | error = -ENODEV; | |
45f1a41b | 4754 | if (!gdth_search_drives(ha)) { |
aed91cb5 CH |
4755 | printk("GDT-ISA: Error during device scan\n"); |
4756 | goto out_free_coal_stat; | |
4757 | } | |
4758 | ||
4759 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) | |
4760 | hdr_channel = ha->bus_cnt; | |
4761 | ha->virt_bus = hdr_channel; | |
4762 | ||
4763 | if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) | |
4764 | shp->max_cmd_len = 16; | |
4765 | ||
4766 | shp->max_id = ha->tid_cnt; | |
4767 | shp->max_lun = MAXLUN; | |
52759e6a | 4768 | shp->max_channel = ha->bus_cnt; |
aed91cb5 CH |
4769 | |
4770 | spin_lock_init(&ha->smp_lock); | |
45f1a41b | 4771 | gdth_enable_int(ha); |
aed91cb5 | 4772 | |
835cc24a CH |
4773 | error = scsi_add_host(shp, NULL); |
4774 | if (error) | |
4775 | goto out_free_coal_stat; | |
4776 | list_add_tail(&ha->list, &gdth_instances); | |
2d6f0d0c | 4777 | gdth_timer_init(); |
61c92814 BH |
4778 | |
4779 | scsi_scan_host(shp); | |
4780 | ||
aed91cb5 CH |
4781 | return 0; |
4782 | ||
4783 | out_free_coal_stat: | |
4784 | #ifdef INT_COAL | |
4785 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, | |
4786 | ha->coal_stat, ha->coal_stat_phys); | |
4787 | out_free_pmsg: | |
4788 | #endif | |
4789 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), | |
4790 | ha->pmsg, ha->msg_phys); | |
4791 | out_free_pscratch: | |
4792 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, | |
4793 | ha->pscratch, ha->scratch_phys); | |
4794 | out_dec_counters: | |
4795 | gdth_ctr_count--; | |
aed91cb5 CH |
4796 | out_free_irq: |
4797 | free_irq(ha->irq, ha); | |
4798 | out_host_put: | |
835cc24a | 4799 | scsi_host_put(shp); |
aed91cb5 CH |
4800 | return error; |
4801 | } | |
4802 | #endif /* CONFIG_ISA */ | |
4803 | ||
706a5d45 | 4804 | #ifdef CONFIG_EISA |
1fe6dbf4 | 4805 | static int __init gdth_eisa_probe_one(u16 eisa_slot) |
706a5d45 CH |
4806 | { |
4807 | struct Scsi_Host *shp; | |
4808 | gdth_ha_str *ha; | |
4809 | dma_addr_t scratch_dma_handle = 0; | |
884f7fba | 4810 | int error, i; |
706a5d45 CH |
4811 | |
4812 | if (!gdth_search_eisa(eisa_slot)) | |
4813 | return -ENXIO; | |
4814 | ||
835cc24a | 4815 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
706a5d45 CH |
4816 | if (!shp) |
4817 | return -ENOMEM; | |
45f1a41b | 4818 | ha = shost_priv(shp); |
706a5d45 CH |
4819 | |
4820 | error = -ENODEV; | |
4821 | if (!gdth_init_eisa(eisa_slot,ha)) | |
4822 | goto out_host_put; | |
4823 | ||
4824 | /* controller found and initialized */ | |
4825 | printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n", | |
4826 | eisa_slot >> 12, ha->irq); | |
4827 | ||
4828 | error = request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha); | |
4829 | if (error) { | |
4830 | printk("GDT-EISA: Unable to allocate IRQ\n"); | |
4831 | goto out_host_put; | |
4832 | } | |
4833 | ||
4834 | shp->unchecked_isa_dma = 0; | |
4835 | shp->irq = ha->irq; | |
4836 | shp->dma_channel = 0xff; | |
706a5d45 | 4837 | |
884f7fba | 4838 | ha->hanum = gdth_ctr_count++; |
45f1a41b BH |
4839 | ha->shost = shp; |
4840 | ||
4841 | TRACE2(("EISA detect Bus 0: hanum %d\n", ha->hanum)); | |
706a5d45 | 4842 | |
45f1a41b | 4843 | ha->pccb = &ha->cmdext; |
706a5d45 CH |
4844 | ha->ccb_phys = 0L; |
4845 | ||
4846 | error = -ENOMEM; | |
4847 | ||
4848 | ha->pdev = NULL; | |
4849 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, | |
4850 | &scratch_dma_handle); | |
4851 | if (!ha->pscratch) | |
4852 | goto out_free_irq; | |
4853 | ha->scratch_phys = scratch_dma_handle; | |
4854 | ||
4855 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), | |
4856 | &scratch_dma_handle); | |
4857 | if (!ha->pmsg) | |
4858 | goto out_free_pscratch; | |
4859 | ha->msg_phys = scratch_dma_handle; | |
4860 | ||
4861 | #ifdef INT_COAL | |
4862 | ha->coal_stat = pci_alloc_consistent(ha->pdev, | |
4863 | sizeof(gdth_coal_status) * MAXOFFSETS, | |
4864 | &scratch_dma_handle); | |
4865 | if (!ha->coal_stat) | |
4866 | goto out_free_pmsg; | |
4867 | ha->coal_stat_phys = scratch_dma_handle; | |
4868 | #endif | |
4869 | ||
4870 | ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb, | |
4871 | sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL); | |
4872 | if (!ha->ccb_phys) | |
4873 | goto out_free_coal_stat; | |
4874 | ||
4875 | ha->scratch_busy = FALSE; | |
4876 | ha->req_first = NULL; | |
4877 | ha->tid_cnt = MAX_HDRIVES; | |
4878 | if (max_ids > 0 && max_ids < ha->tid_cnt) | |
4879 | ha->tid_cnt = max_ids; | |
4880 | for (i = 0; i < GDTH_MAXCMDS; ++i) | |
4881 | ha->cmd_tab[i].cmnd = UNUSED_CMND; | |
4882 | ha->scan_mode = rescan ? 0x10 : 0; | |
4883 | ||
45f1a41b | 4884 | if (!gdth_search_drives(ha)) { |
706a5d45 CH |
4885 | printk("GDT-EISA: Error during device scan\n"); |
4886 | error = -ENODEV; | |
4887 | goto out_free_ccb_phys; | |
4888 | } | |
4889 | ||
4890 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) | |
4891 | hdr_channel = ha->bus_cnt; | |
4892 | ha->virt_bus = hdr_channel; | |
4893 | ||
4894 | if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) | |
4895 | shp->max_cmd_len = 16; | |
4896 | ||
4897 | shp->max_id = ha->tid_cnt; | |
4898 | shp->max_lun = MAXLUN; | |
52759e6a | 4899 | shp->max_channel = ha->bus_cnt; |
706a5d45 CH |
4900 | |
4901 | spin_lock_init(&ha->smp_lock); | |
45f1a41b | 4902 | gdth_enable_int(ha); |
835cc24a CH |
4903 | |
4904 | error = scsi_add_host(shp, NULL); | |
4905 | if (error) | |
4906 | goto out_free_coal_stat; | |
4907 | list_add_tail(&ha->list, &gdth_instances); | |
2d6f0d0c | 4908 | gdth_timer_init(); |
61c92814 BH |
4909 | |
4910 | scsi_scan_host(shp); | |
4911 | ||
706a5d45 CH |
4912 | return 0; |
4913 | ||
4914 | out_free_ccb_phys: | |
4915 | pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str), | |
4916 | PCI_DMA_BIDIRECTIONAL); | |
4917 | out_free_coal_stat: | |
4918 | #ifdef INT_COAL | |
4919 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, | |
4920 | ha->coal_stat, ha->coal_stat_phys); | |
4921 | out_free_pmsg: | |
4922 | #endif | |
4923 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), | |
4924 | ha->pmsg, ha->msg_phys); | |
4925 | out_free_pscratch: | |
4926 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, | |
4927 | ha->pscratch, ha->scratch_phys); | |
4928 | out_free_irq: | |
4929 | free_irq(ha->irq, ha); | |
4930 | gdth_ctr_count--; | |
706a5d45 | 4931 | out_host_put: |
835cc24a | 4932 | scsi_host_put(shp); |
706a5d45 CH |
4933 | return error; |
4934 | } | |
4935 | #endif /* CONFIG_EISA */ | |
aed91cb5 | 4936 | |
8514ef27 | 4937 | #ifdef CONFIG_PCI |
ced7172a | 4938 | static int __devinit gdth_pci_probe_one(gdth_pci_str *pcistr, |
cff26806 | 4939 | gdth_ha_str **ha_out) |
8514ef27 CH |
4940 | { |
4941 | struct Scsi_Host *shp; | |
4942 | gdth_ha_str *ha; | |
4943 | dma_addr_t scratch_dma_handle = 0; | |
884f7fba | 4944 | int error, i; |
4c9c8d78 | 4945 | struct pci_dev *pdev = pcistr->pdev; |
8514ef27 | 4946 | |
cff26806 JG |
4947 | *ha_out = NULL; |
4948 | ||
835cc24a | 4949 | shp = scsi_host_alloc(&gdth_template, sizeof(gdth_ha_str)); |
8514ef27 CH |
4950 | if (!shp) |
4951 | return -ENOMEM; | |
45f1a41b | 4952 | ha = shost_priv(shp); |
8514ef27 CH |
4953 | |
4954 | error = -ENODEV; | |
4c9c8d78 | 4955 | if (!gdth_init_pci(pdev, pcistr, ha)) |
8514ef27 CH |
4956 | goto out_host_put; |
4957 | ||
4958 | /* controller found and initialized */ | |
4959 | printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n", | |
4c9c8d78 JG |
4960 | pdev->bus->number, |
4961 | PCI_SLOT(pdev->devfn), | |
8514ef27 CH |
4962 | ha->irq); |
4963 | ||
4964 | error = request_irq(ha->irq, gdth_interrupt, | |
4965 | IRQF_DISABLED|IRQF_SHARED, "gdth", ha); | |
4966 | if (error) { | |
4967 | printk("GDT-PCI: Unable to allocate IRQ\n"); | |
4968 | goto out_host_put; | |
4969 | } | |
4970 | ||
4971 | shp->unchecked_isa_dma = 0; | |
4972 | shp->irq = ha->irq; | |
4973 | shp->dma_channel = 0xff; | |
8514ef27 | 4974 | |
884f7fba | 4975 | ha->hanum = gdth_ctr_count++; |
45f1a41b | 4976 | ha->shost = shp; |
8514ef27 | 4977 | |
45f1a41b | 4978 | ha->pccb = &ha->cmdext; |
8514ef27 CH |
4979 | ha->ccb_phys = 0L; |
4980 | ||
4981 | error = -ENOMEM; | |
4982 | ||
4983 | ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH, | |
4984 | &scratch_dma_handle); | |
4985 | if (!ha->pscratch) | |
4986 | goto out_free_irq; | |
4987 | ha->scratch_phys = scratch_dma_handle; | |
4988 | ||
4989 | ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str), | |
4990 | &scratch_dma_handle); | |
4991 | if (!ha->pmsg) | |
4992 | goto out_free_pscratch; | |
4993 | ha->msg_phys = scratch_dma_handle; | |
4994 | ||
4995 | #ifdef INT_COAL | |
4996 | ha->coal_stat = pci_alloc_consistent(ha->pdev, | |
4997 | sizeof(gdth_coal_status) * MAXOFFSETS, | |
4998 | &scratch_dma_handle); | |
4999 | if (!ha->coal_stat) | |
5000 | goto out_free_pmsg; | |
5001 | ha->coal_stat_phys = scratch_dma_handle; | |
5002 | #endif | |
5003 | ||
5004 | ha->scratch_busy = FALSE; | |
5005 | ha->req_first = NULL; | |
4c9c8d78 | 5006 | ha->tid_cnt = pdev->device >= 0x200 ? MAXID : MAX_HDRIVES; |
8514ef27 CH |
5007 | if (max_ids > 0 && max_ids < ha->tid_cnt) |
5008 | ha->tid_cnt = max_ids; | |
5009 | for (i = 0; i < GDTH_MAXCMDS; ++i) | |
5010 | ha->cmd_tab[i].cmnd = UNUSED_CMND; | |
5011 | ha->scan_mode = rescan ? 0x10 : 0; | |
5012 | ||
5013 | error = -ENODEV; | |
45f1a41b BH |
5014 | if (!gdth_search_drives(ha)) { |
5015 | printk("GDT-PCI %d: Error during device scan\n", ha->hanum); | |
8514ef27 CH |
5016 | goto out_free_coal_stat; |
5017 | } | |
5018 | ||
5019 | if (hdr_channel < 0 || hdr_channel > ha->bus_cnt) | |
5020 | hdr_channel = ha->bus_cnt; | |
5021 | ha->virt_bus = hdr_channel; | |
5022 | ||
5023 | /* 64-bit DMA only supported from FW >= x.43 */ | |
5024 | if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) || | |
5025 | !ha->dma64_support) { | |
284901a9 | 5026 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
8514ef27 | 5027 | printk(KERN_WARNING "GDT-PCI %d: " |
45f1a41b | 5028 | "Unable to set 32-bit DMA\n", ha->hanum); |
8514ef27 CH |
5029 | goto out_free_coal_stat; |
5030 | } | |
5031 | } else { | |
5032 | shp->max_cmd_len = 16; | |
6a35528a | 5033 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { |
45f1a41b | 5034 | printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum); |
284901a9 | 5035 | } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
8514ef27 | 5036 | printk(KERN_WARNING "GDT-PCI %d: " |
45f1a41b | 5037 | "Unable to set 64/32-bit DMA\n", ha->hanum); |
8514ef27 CH |
5038 | goto out_free_coal_stat; |
5039 | } | |
5040 | } | |
5041 | ||
5042 | shp->max_id = ha->tid_cnt; | |
5043 | shp->max_lun = MAXLUN; | |
52759e6a | 5044 | shp->max_channel = ha->bus_cnt; |
8514ef27 CH |
5045 | |
5046 | spin_lock_init(&ha->smp_lock); | |
45f1a41b | 5047 | gdth_enable_int(ha); |
835cc24a | 5048 | |
4c9c8d78 | 5049 | error = scsi_add_host(shp, &pdev->dev); |
835cc24a CH |
5050 | if (error) |
5051 | goto out_free_coal_stat; | |
5052 | list_add_tail(&ha->list, &gdth_instances); | |
61c92814 | 5053 | |
cff26806 | 5054 | pci_set_drvdata(ha->pdev, ha); |
2d6f0d0c | 5055 | gdth_timer_init(); |
cff26806 | 5056 | |
61c92814 BH |
5057 | scsi_scan_host(shp); |
5058 | ||
cff26806 JG |
5059 | *ha_out = ha; |
5060 | ||
8514ef27 CH |
5061 | return 0; |
5062 | ||
5063 | out_free_coal_stat: | |
5064 | #ifdef INT_COAL | |
5065 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS, | |
5066 | ha->coal_stat, ha->coal_stat_phys); | |
5067 | out_free_pmsg: | |
5068 | #endif | |
5069 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), | |
5070 | ha->pmsg, ha->msg_phys); | |
5071 | out_free_pscratch: | |
5072 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, | |
5073 | ha->pscratch, ha->scratch_phys); | |
5074 | out_free_irq: | |
5075 | free_irq(ha->irq, ha); | |
5076 | gdth_ctr_count--; | |
8514ef27 | 5077 | out_host_put: |
835cc24a | 5078 | scsi_host_put(shp); |
8514ef27 CH |
5079 | return error; |
5080 | } | |
5081 | #endif /* CONFIG_PCI */ | |
5082 | ||
835cc24a CH |
5083 | static void gdth_remove_one(gdth_ha_str *ha) |
5084 | { | |
5085 | struct Scsi_Host *shp = ha->shost; | |
5086 | ||
5087 | TRACE2(("gdth_remove_one()\n")); | |
5088 | ||
5089 | scsi_remove_host(shp); | |
5090 | ||
b31ddd31 BH |
5091 | gdth_flush(ha); |
5092 | ||
835cc24a CH |
5093 | if (ha->sdev) { |
5094 | scsi_free_host_dev(ha->sdev); | |
5095 | ha->sdev = NULL; | |
5096 | } | |
5097 | ||
835cc24a CH |
5098 | if (shp->irq) |
5099 | free_irq(shp->irq,ha); | |
5100 | ||
5101 | #ifdef CONFIG_ISA | |
5102 | if (shp->dma_channel != 0xff) | |
5103 | free_dma(shp->dma_channel); | |
5104 | #endif | |
5105 | #ifdef INT_COAL | |
5106 | if (ha->coal_stat) | |
5107 | pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * | |
5108 | MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys); | |
5109 | #endif | |
5110 | if (ha->pscratch) | |
5111 | pci_free_consistent(ha->pdev, GDTH_SCRATCH, | |
5112 | ha->pscratch, ha->scratch_phys); | |
5113 | if (ha->pmsg) | |
5114 | pci_free_consistent(ha->pdev, sizeof(gdth_msg_str), | |
5115 | ha->pmsg, ha->msg_phys); | |
5116 | if (ha->ccb_phys) | |
5117 | pci_unmap_single(ha->pdev,ha->ccb_phys, | |
5118 | sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL); | |
5119 | ||
5120 | scsi_host_put(shp); | |
5121 | } | |
5122 | ||
1fe6dbf4 | 5123 | static int gdth_halt(struct notifier_block *nb, unsigned long event, void *buf) |
b31ddd31 BH |
5124 | { |
5125 | gdth_ha_str *ha; | |
5126 | ||
5127 | TRACE2(("gdth_halt() event %d\n", (int)event)); | |
5128 | if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF) | |
5129 | return NOTIFY_DONE; | |
5130 | ||
5131 | list_for_each_entry(ha, &gdth_instances, list) | |
5132 | gdth_flush(ha); | |
5133 | ||
5134 | return NOTIFY_OK; | |
5135 | } | |
5136 | ||
5137 | static struct notifier_block gdth_notifier = { | |
5138 | gdth_halt, NULL, 0 | |
5139 | }; | |
5140 | ||
835cc24a CH |
5141 | static int __init gdth_init(void) |
5142 | { | |
5143 | if (disable) { | |
5144 | printk("GDT-HA: Controller driver disabled from" | |
5145 | " command line !\n"); | |
5146 | return 0; | |
5147 | } | |
5148 | ||
5149 | printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n", | |
5150 | GDTH_VERSION_STR); | |
5151 | ||
5152 | /* initializations */ | |
5153 | gdth_polling = TRUE; | |
5154 | gdth_clear_events(); | |
2d6f0d0c | 5155 | init_timer(&gdth_timer); |
835cc24a CH |
5156 | |
5157 | /* As default we do not probe for EISA or ISA controllers */ | |
5158 | if (probe_eisa_isa) { | |
5159 | /* scanning for controllers, at first: ISA controller */ | |
5160 | #ifdef CONFIG_ISA | |
1fe6dbf4 | 5161 | u32 isa_bios; |
835cc24a | 5162 | for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL; |
884f7fba | 5163 | isa_bios += 0x8000UL) |
835cc24a | 5164 | gdth_isa_probe_one(isa_bios); |
835cc24a CH |
5165 | #endif |
5166 | #ifdef CONFIG_EISA | |
5167 | { | |
1fe6dbf4 | 5168 | u16 eisa_slot; |
835cc24a | 5169 | for (eisa_slot = 0x1000; eisa_slot <= 0x8000; |
884f7fba | 5170 | eisa_slot += 0x1000) |
835cc24a | 5171 | gdth_eisa_probe_one(eisa_slot); |
835cc24a CH |
5172 | } |
5173 | #endif | |
5174 | } | |
5175 | ||
5176 | #ifdef CONFIG_PCI | |
5177 | /* scanning for PCI controllers */ | |
a85591fd JB |
5178 | if (pci_register_driver(&gdth_pci_driver)) { |
5179 | gdth_ha_str *ha; | |
5180 | ||
5181 | list_for_each_entry(ha, &gdth_instances, list) | |
5182 | gdth_remove_one(ha); | |
5183 | return -ENODEV; | |
5184 | } | |
835cc24a CH |
5185 | #endif /* CONFIG_PCI */ |
5186 | ||
5187 | TRACE2(("gdth_detect() %d controller detected\n", gdth_ctr_count)); | |
c596cc46 | 5188 | |
835cc24a | 5189 | major = register_chrdev(0,"gdth", &gdth_fops); |
835cc24a CH |
5190 | register_reboot_notifier(&gdth_notifier); |
5191 | gdth_polling = FALSE; | |
5192 | return 0; | |
5193 | } | |
5194 | ||
5195 | static void __exit gdth_exit(void) | |
5196 | { | |
5197 | gdth_ha_str *ha; | |
5198 | ||
b31ddd31 BH |
5199 | unregister_chrdev(major, "gdth"); |
5200 | unregister_reboot_notifier(&gdth_notifier); | |
835cc24a CH |
5201 | |
5202 | #ifdef GDTH_STATISTICS | |
b31ddd31 | 5203 | del_timer_sync(&gdth_timer); |
835cc24a | 5204 | #endif |
b31ddd31 | 5205 | |
cff26806 | 5206 | #ifdef CONFIG_PCI |
a85591fd | 5207 | pci_unregister_driver(&gdth_pci_driver); |
cff26806 JG |
5208 | #endif |
5209 | ||
b31ddd31 BH |
5210 | list_for_each_entry(ha, &gdth_instances, list) |
5211 | gdth_remove_one(ha); | |
835cc24a CH |
5212 | } |
5213 | ||
5214 | module_init(gdth_init); | |
5215 | module_exit(gdth_exit); | |
5216 | ||
1da177e4 LT |
5217 | #ifndef MODULE |
5218 | __setup("gdth=", option_setup); | |
5219 | #endif |