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