diff options
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/fd_mcs.c | 1355 | ||||
-rw-r--r-- | drivers/scsi/ibmmca.c | 2380 | ||||
-rw-r--r-- | drivers/scsi/ibmvscsi/iseries_vscsi.c | 173 | ||||
-rw-r--r-- | drivers/scsi/ibmvscsi/rpa_vscsi.c | 368 | ||||
-rw-r--r-- | drivers/scsi/isci/firmware/Makefile | 19 | ||||
-rw-r--r-- | drivers/scsi/isci/firmware/README | 36 | ||||
-rw-r--r-- | drivers/scsi/isci/firmware/create_fw.c | 99 | ||||
-rw-r--r-- | drivers/scsi/isci/firmware/create_fw.h | 77 | ||||
-rw-r--r-- | drivers/scsi/scsi_wait_scan.c | 42 |
9 files changed, 4549 insertions, 0 deletions
diff --git a/drivers/scsi/fd_mcs.c b/drivers/scsi/fd_mcs.c new file mode 100644 index 00000000000..a2c6135d337 --- /dev/null +++ b/drivers/scsi/fd_mcs.c | |||
@@ -0,0 +1,1355 @@ | |||
1 | /* fd_mcs.c -- Future Domain MCS 600/700 (or IBM OEM) driver | ||
2 | * | ||
3 | * FutureDomain MCS-600/700 v0.2 03/11/1998 by ZP Gu (zpg@castle.net) | ||
4 | * | ||
5 | * This driver is cloned from fdomain.* to specifically support | ||
6 | * the Future Domain MCS 600/700 MCA SCSI adapters. Some PS/2s | ||
7 | * also equipped with IBM Fast SCSI Adapter/A which is an OEM | ||
8 | * of MCS 700. | ||
9 | * | ||
10 | * This driver also supports Reply SB16/SCSI card (the SCSI part). | ||
11 | * | ||
12 | * What makes this driver different is that this driver is MCA only | ||
13 | * and it supports multiple adapters in the same system, IRQ | ||
14 | * sharing, some driver statistics, and maps highest SCSI id to sda. | ||
15 | * All cards are auto-detected. | ||
16 | * | ||
17 | * Assumptions: TMC-1800/18C50/18C30, BIOS >= 3.4 | ||
18 | * | ||
19 | * LILO command-line options: | ||
20 | * fd_mcs=<FIFO_COUNT>[,<FIFO_SIZE>] | ||
21 | * | ||
22 | * ******************************************************** | ||
23 | * Please see Copyrights/Comments in fdomain.* for credits. | ||
24 | * Following is from fdomain.c for acknowledgement: | ||
25 | * | ||
26 | * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu | ||
27 | * Revised: Wed Oct 2 11:10:55 1996 by r.faith@ieee.org | ||
28 | * Author: Rickard E. Faith, faith@cs.unc.edu | ||
29 | * Copyright 1992, 1993, 1994, 1995, 1996 Rickard E. Faith | ||
30 | * | ||
31 | * $Id: fdomain.c,v 5.45 1996/10/02 15:13:06 root Exp $ | ||
32 | |||
33 | * This program is free software; you can redistribute it and/or modify it | ||
34 | * under the terms of the GNU General Public License as published by the | ||
35 | * Free Software Foundation; either version 2, or (at your option) any | ||
36 | * later version. | ||
37 | |||
38 | * This program is distributed in the hope that it will be useful, but | ||
39 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
41 | * General Public License for more details. | ||
42 | |||
43 | * You should have received a copy of the GNU General Public License along | ||
44 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
45 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
46 | |||
47 | ************************************************************************** | ||
48 | |||
49 | NOTES ON USER DEFINABLE OPTIONS: | ||
50 | |||
51 | DEBUG: This turns on the printing of various debug information. | ||
52 | |||
53 | ENABLE_PARITY: This turns on SCSI parity checking. With the current | ||
54 | driver, all attached devices must support SCSI parity. If none of your | ||
55 | devices support parity, then you can probably get the driver to work by | ||
56 | turning this option off. I have no way of testing this, however, and it | ||
57 | would appear that no one ever uses this option. | ||
58 | |||
59 | FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the | ||
60 | 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by | ||
61 | the SCSI device, an interrupt will be raised. Therefore, this could be as | ||
62 | low as 0, or as high as 16. Note, however, that values which are too high | ||
63 | or too low seem to prevent any interrupts from occurring, and thereby lock | ||
64 | up the machine. I have found that 2 is a good number, but throughput may | ||
65 | be increased by changing this value to values which are close to 2. | ||
66 | Please let me know if you try any different values. | ||
67 | [*****Now a runtime option*****] | ||
68 | |||
69 | RESELECTION: This is no longer an option, since I gave up trying to | ||
70 | implement it in version 4.x of this driver. It did not improve | ||
71 | performance at all and made the driver unstable (because I never found one | ||
72 | of the two race conditions which were introduced by the multiple | ||
73 | outstanding command code). The instability seems a very high price to pay | ||
74 | just so that you don't have to wait for the tape to rewind. If you want | ||
75 | this feature implemented, send me patches. I'll be happy to send a copy | ||
76 | of my (broken) driver to anyone who would like to see a copy. | ||
77 | |||
78 | **************************************************************************/ | ||
79 | |||
80 | #include <linux/module.h> | ||
81 | #include <linux/init.h> | ||
82 | #include <linux/interrupt.h> | ||
83 | #include <linux/blkdev.h> | ||
84 | #include <linux/errno.h> | ||
85 | #include <linux/string.h> | ||
86 | #include <linux/ioport.h> | ||
87 | #include <linux/proc_fs.h> | ||
88 | #include <linux/delay.h> | ||
89 | #include <linux/mca.h> | ||
90 | #include <linux/spinlock.h> | ||
91 | #include <linux/slab.h> | ||
92 | #include <scsi/scsicam.h> | ||
93 | #include <linux/mca-legacy.h> | ||
94 | |||
95 | #include <asm/io.h> | ||
96 | #include <asm/system.h> | ||
97 | |||
98 | #include "scsi.h" | ||
99 | #include <scsi/scsi_host.h> | ||
100 | |||
101 | #define DRIVER_VERSION "v0.2 by ZP Gu<zpg@castle.net>" | ||
102 | |||
103 | /* START OF USER DEFINABLE OPTIONS */ | ||
104 | |||
105 | #define DEBUG 0 /* Enable debugging output */ | ||
106 | #define ENABLE_PARITY 1 /* Enable SCSI Parity */ | ||
107 | |||
108 | /* END OF USER DEFINABLE OPTIONS */ | ||
109 | |||
110 | #if DEBUG | ||
111 | #define EVERY_ACCESS 0 /* Write a line on every scsi access */ | ||
112 | #define ERRORS_ONLY 1 /* Only write a line if there is an error */ | ||
113 | #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */ | ||
114 | #define DEBUG_ABORT 1 /* Debug abort() routine */ | ||
115 | #define DEBUG_RESET 1 /* Debug reset() routine */ | ||
116 | #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */ | ||
117 | #else | ||
118 | #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */ | ||
119 | #define ERRORS_ONLY 0 | ||
120 | #define DEBUG_MESSAGES 0 | ||
121 | #define DEBUG_ABORT 0 | ||
122 | #define DEBUG_RESET 0 | ||
123 | #define DEBUG_RACE 0 | ||
124 | #endif | ||
125 | |||
126 | /* Errors are reported on the line, so we don't need to report them again */ | ||
127 | #if EVERY_ACCESS | ||
128 | #undef ERRORS_ONLY | ||
129 | #define ERRORS_ONLY 0 | ||
130 | #endif | ||
131 | |||
132 | #if ENABLE_PARITY | ||
133 | #define PARITY_MASK 0x08 | ||
134 | #else | ||
135 | #define PARITY_MASK 0x00 | ||
136 | #endif | ||
137 | |||
138 | enum chip_type { | ||
139 | unknown = 0x00, | ||
140 | tmc1800 = 0x01, | ||
141 | tmc18c50 = 0x02, | ||
142 | tmc18c30 = 0x03, | ||
143 | }; | ||
144 | |||
145 | enum { | ||
146 | in_arbitration = 0x02, | ||
147 | in_selection = 0x04, | ||
148 | in_other = 0x08, | ||
149 | disconnect = 0x10, | ||
150 | aborted = 0x20, | ||
151 | sent_ident = 0x40, | ||
152 | }; | ||
153 | |||
154 | enum in_port_type { | ||
155 | Read_SCSI_Data = 0, | ||
156 | SCSI_Status = 1, | ||
157 | TMC_Status = 2, | ||
158 | FIFO_Status = 3, /* tmc18c50/tmc18c30 only */ | ||
159 | Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */ | ||
160 | LSB_ID_Code = 5, | ||
161 | MSB_ID_Code = 6, | ||
162 | Read_Loopback = 7, | ||
163 | SCSI_Data_NoACK = 8, | ||
164 | Interrupt_Status = 9, | ||
165 | Configuration1 = 10, | ||
166 | Configuration2 = 11, /* tmc18c50/tmc18c30 only */ | ||
167 | Read_FIFO = 12, | ||
168 | FIFO_Data_Count = 14 | ||
169 | }; | ||
170 | |||
171 | enum out_port_type { | ||
172 | Write_SCSI_Data = 0, | ||
173 | SCSI_Cntl = 1, | ||
174 | Interrupt_Cntl = 2, | ||
175 | SCSI_Mode_Cntl = 3, | ||
176 | TMC_Cntl = 4, | ||
177 | Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */ | ||
178 | Write_Loopback = 7, | ||
179 | IO_Control = 11, /* tmc18c30 only */ | ||
180 | Write_FIFO = 12 | ||
181 | }; | ||
182 | |||
183 | struct fd_hostdata { | ||
184 | unsigned long _bios_base; | ||
185 | int _bios_major; | ||
186 | int _bios_minor; | ||
187 | volatile int _in_command; | ||
188 | Scsi_Cmnd *_current_SC; | ||
189 | enum chip_type _chip; | ||
190 | int _adapter_mask; | ||
191 | int _fifo_count; /* Number of 512 byte blocks before INTR */ | ||
192 | |||
193 | char _adapter_name[64]; | ||
194 | #if DEBUG_RACE | ||
195 | volatile int _in_interrupt_flag; | ||
196 | #endif | ||
197 | |||
198 | int _SCSI_Mode_Cntl_port; | ||
199 | int _FIFO_Data_Count_port; | ||
200 | int _Interrupt_Cntl_port; | ||
201 | int _Interrupt_Status_port; | ||
202 | int _Interrupt_Cond_port; | ||
203 | int _Read_FIFO_port; | ||
204 | int _Read_SCSI_Data_port; | ||
205 | int _SCSI_Cntl_port; | ||
206 | int _SCSI_Data_NoACK_port; | ||
207 | int _SCSI_Status_port; | ||
208 | int _TMC_Cntl_port; | ||
209 | int _TMC_Status_port; | ||
210 | int _Write_FIFO_port; | ||
211 | int _Write_SCSI_Data_port; | ||
212 | |||
213 | int _FIFO_Size; /* = 0x2000; 8k FIFO for | ||
214 | pre-tmc18c30 chips */ | ||
215 | /* simple stats */ | ||
216 | int _Bytes_Read; | ||
217 | int _Bytes_Written; | ||
218 | int _INTR_Processed; | ||
219 | }; | ||
220 | |||
221 | #define FD_MAX_HOSTS 3 /* enough? */ | ||
222 | |||
223 | #define HOSTDATA(shpnt) ((struct fd_hostdata *) shpnt->hostdata) | ||
224 | #define bios_base (HOSTDATA(shpnt)->_bios_base) | ||
225 | #define bios_major (HOSTDATA(shpnt)->_bios_major) | ||
226 | #define bios_minor (HOSTDATA(shpnt)->_bios_minor) | ||
227 | #define in_command (HOSTDATA(shpnt)->_in_command) | ||
228 | #define current_SC (HOSTDATA(shpnt)->_current_SC) | ||
229 | #define chip (HOSTDATA(shpnt)->_chip) | ||
230 | #define adapter_mask (HOSTDATA(shpnt)->_adapter_mask) | ||
231 | #define FIFO_COUNT (HOSTDATA(shpnt)->_fifo_count) | ||
232 | #define adapter_name (HOSTDATA(shpnt)->_adapter_name) | ||
233 | #if DEBUG_RACE | ||
234 | #define in_interrupt_flag (HOSTDATA(shpnt)->_in_interrupt_flag) | ||
235 | #endif | ||
236 | #define SCSI_Mode_Cntl_port (HOSTDATA(shpnt)->_SCSI_Mode_Cntl_port) | ||
237 | #define FIFO_Data_Count_port (HOSTDATA(shpnt)->_FIFO_Data_Count_port) | ||
238 | #define Interrupt_Cntl_port (HOSTDATA(shpnt)->_Interrupt_Cntl_port) | ||
239 | #define Interrupt_Status_port (HOSTDATA(shpnt)->_Interrupt_Status_port) | ||
240 | #define Interrupt_Cond_port (HOSTDATA(shpnt)->_Interrupt_Cond_port) | ||
241 | #define Read_FIFO_port (HOSTDATA(shpnt)->_Read_FIFO_port) | ||
242 | #define Read_SCSI_Data_port (HOSTDATA(shpnt)->_Read_SCSI_Data_port) | ||
243 | #define SCSI_Cntl_port (HOSTDATA(shpnt)->_SCSI_Cntl_port) | ||
244 | #define SCSI_Data_NoACK_port (HOSTDATA(shpnt)->_SCSI_Data_NoACK_port) | ||
245 | #define SCSI_Status_port (HOSTDATA(shpnt)->_SCSI_Status_port) | ||
246 | #define TMC_Cntl_port (HOSTDATA(shpnt)->_TMC_Cntl_port) | ||
247 | #define TMC_Status_port (HOSTDATA(shpnt)->_TMC_Status_port) | ||
248 | #define Write_FIFO_port (HOSTDATA(shpnt)->_Write_FIFO_port) | ||
249 | #define Write_SCSI_Data_port (HOSTDATA(shpnt)->_Write_SCSI_Data_port) | ||
250 | #define FIFO_Size (HOSTDATA(shpnt)->_FIFO_Size) | ||
251 | #define Bytes_Read (HOSTDATA(shpnt)->_Bytes_Read) | ||
252 | #define Bytes_Written (HOSTDATA(shpnt)->_Bytes_Written) | ||
253 | #define INTR_Processed (HOSTDATA(shpnt)->_INTR_Processed) | ||
254 | |||
255 | struct fd_mcs_adapters_struct { | ||
256 | char *name; | ||
257 | int id; | ||
258 | enum chip_type fd_chip; | ||
259 | int fifo_size; | ||
260 | int fifo_count; | ||
261 | }; | ||
262 | |||
263 | #define REPLY_ID 0x5137 | ||
264 | |||
265 | static struct fd_mcs_adapters_struct fd_mcs_adapters[] = { | ||
266 | {"Future Domain SCSI Adapter MCS-700(18C50)", | ||
267 | 0x60e9, | ||
268 | tmc18c50, | ||
269 | 0x2000, | ||
270 | 4}, | ||
271 | {"Future Domain SCSI Adapter MCS-600/700(TMC-1800)", | ||
272 | 0x6127, | ||
273 | tmc1800, | ||
274 | 0x2000, | ||
275 | 4}, | ||
276 | {"Reply Sound Blaster/SCSI Adapter", | ||
277 | REPLY_ID, | ||
278 | tmc18c30, | ||
279 | 0x800, | ||
280 | 2}, | ||
281 | }; | ||
282 | |||
283 | #define FD_BRDS ARRAY_SIZE(fd_mcs_adapters) | ||
284 | |||
285 | static irqreturn_t fd_mcs_intr(int irq, void *dev_id); | ||
286 | |||
287 | static unsigned long addresses[] = { 0xc8000, 0xca000, 0xce000, 0xde000 }; | ||
288 | static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 }; | ||
289 | static unsigned short interrupts[] = { 3, 5, 10, 11, 12, 14, 15, 0 }; | ||
290 | |||
291 | /* host information */ | ||
292 | static int found = 0; | ||
293 | static struct Scsi_Host *hosts[FD_MAX_HOSTS + 1] = { NULL }; | ||
294 | |||
295 | static int user_fifo_count = 0; | ||
296 | static int user_fifo_size = 0; | ||
297 | |||
298 | #ifndef MODULE | ||
299 | static int __init fd_mcs_setup(char *str) | ||
300 | { | ||
301 | static int done_setup = 0; | ||
302 | int ints[3]; | ||
303 | |||
304 | get_options(str, 3, ints); | ||
305 | if (done_setup++ || ints[0] < 1 || ints[0] > 2 || ints[1] < 1 || ints[1] > 16) { | ||
306 | printk("fd_mcs: usage: fd_mcs=FIFO_COUNT, FIFO_SIZE\n"); | ||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | user_fifo_count = ints[0] >= 1 ? ints[1] : 0; | ||
311 | user_fifo_size = ints[0] >= 2 ? ints[2] : 0; | ||
312 | return 1; | ||
313 | } | ||
314 | |||
315 | __setup("fd_mcs=", fd_mcs_setup); | ||
316 | #endif /* !MODULE */ | ||
317 | |||
318 | static void print_banner(struct Scsi_Host *shpnt) | ||
319 | { | ||
320 | printk("scsi%d <fd_mcs>: ", shpnt->host_no); | ||
321 | |||
322 | if (bios_base) { | ||
323 | printk("BIOS at 0x%lX", bios_base); | ||
324 | } else { | ||
325 | printk("No BIOS"); | ||
326 | } | ||
327 | |||
328 | printk(", HostID %d, %s Chip, IRQ %d, IO 0x%lX\n", shpnt->this_id, chip == tmc18c50 ? "TMC-18C50" : (chip == tmc18c30 ? "TMC-18C30" : (chip == tmc1800 ? "TMC-1800" : "Unknown")), shpnt->irq, shpnt->io_port); | ||
329 | } | ||
330 | |||
331 | |||
332 | static void do_pause(unsigned amount) | ||
333 | { /* Pause for amount*10 milliseconds */ | ||
334 | do { | ||
335 | mdelay(10); | ||
336 | } while (--amount); | ||
337 | } | ||
338 | |||
339 | static void fd_mcs_make_bus_idle(struct Scsi_Host *shpnt) | ||
340 | { | ||
341 | outb(0, SCSI_Cntl_port); | ||
342 | outb(0, SCSI_Mode_Cntl_port); | ||
343 | if (chip == tmc18c50 || chip == tmc18c30) | ||
344 | outb(0x21 | PARITY_MASK, TMC_Cntl_port); /* Clear forced intr. */ | ||
345 | else | ||
346 | outb(0x01 | PARITY_MASK, TMC_Cntl_port); | ||
347 | } | ||
348 | |||
349 | static int fd_mcs_detect(struct scsi_host_template * tpnt) | ||
350 | { | ||
351 | int loop; | ||
352 | struct Scsi_Host *shpnt; | ||
353 | |||
354 | /* get id, port, bios, irq */ | ||
355 | int slot; | ||
356 | u_char pos2, pos3, pos4; | ||
357 | int id, port, irq; | ||
358 | unsigned long bios; | ||
359 | |||
360 | /* if not MCA machine, return */ | ||
361 | if (!MCA_bus) | ||
362 | return 0; | ||
363 | |||
364 | /* changeable? */ | ||
365 | id = 7; | ||
366 | |||
367 | for (loop = 0; loop < FD_BRDS; loop++) { | ||
368 | slot = 0; | ||
369 | while (MCA_NOTFOUND != (slot = mca_find_adapter(fd_mcs_adapters[loop].id, slot))) { | ||
370 | |||
371 | /* if we get this far, an adapter has been detected and is | ||
372 | enabled */ | ||
373 | |||
374 | printk(KERN_INFO "scsi <fd_mcs>: %s at slot %d\n", fd_mcs_adapters[loop].name, slot + 1); | ||
375 | |||
376 | pos2 = mca_read_stored_pos(slot, 2); | ||
377 | pos3 = mca_read_stored_pos(slot, 3); | ||
378 | pos4 = mca_read_stored_pos(slot, 4); | ||
379 | |||
380 | /* ready for next probe */ | ||
381 | slot++; | ||
382 | |||
383 | if (fd_mcs_adapters[loop].id == REPLY_ID) { /* reply card */ | ||
384 | static int reply_irq[] = { 10, 11, 14, 15 }; | ||
385 | |||
386 | bios = 0; /* no bios */ | ||
387 | |||
388 | if (pos2 & 0x2) | ||
389 | port = ports[pos4 & 0x3]; | ||
390 | else | ||
391 | continue; | ||
392 | |||
393 | /* can't really disable it, same as irq=10 */ | ||
394 | irq = reply_irq[((pos4 >> 2) & 0x1) + 2 * ((pos4 >> 4) & 0x1)]; | ||
395 | } else { | ||
396 | bios = addresses[pos2 >> 6]; | ||
397 | port = ports[(pos2 >> 4) & 0x03]; | ||
398 | irq = interrupts[(pos2 >> 1) & 0x07]; | ||
399 | } | ||
400 | |||
401 | if (irq) { | ||
402 | /* claim the slot */ | ||
403 | mca_set_adapter_name(slot - 1, fd_mcs_adapters[loop].name); | ||
404 | |||
405 | /* check irq/region */ | ||
406 | if (request_irq(irq, fd_mcs_intr, IRQF_SHARED, "fd_mcs", hosts)) { | ||
407 | printk(KERN_ERR "fd_mcs: interrupt is not available, skipping...\n"); | ||
408 | continue; | ||
409 | } | ||
410 | |||
411 | /* request I/O region */ | ||
412 | if (request_region(port, 0x10, "fd_mcs")) { | ||
413 | printk(KERN_ERR "fd_mcs: I/O region is already in use, skipping...\n"); | ||
414 | continue; | ||
415 | } | ||
416 | /* register */ | ||
417 | if (!(shpnt = scsi_register(tpnt, sizeof(struct fd_hostdata)))) { | ||
418 | printk(KERN_ERR "fd_mcs: scsi_register() failed\n"); | ||
419 | release_region(port, 0x10); | ||
420 | free_irq(irq, hosts); | ||
421 | continue; | ||
422 | } | ||
423 | |||
424 | |||
425 | /* save name */ | ||
426 | strcpy(adapter_name, fd_mcs_adapters[loop].name); | ||
427 | |||
428 | /* chip/fifo */ | ||
429 | chip = fd_mcs_adapters[loop].fd_chip; | ||
430 | /* use boot time value if available */ | ||
431 | FIFO_COUNT = user_fifo_count ? user_fifo_count : fd_mcs_adapters[loop].fifo_count; | ||
432 | FIFO_Size = user_fifo_size ? user_fifo_size : fd_mcs_adapters[loop].fifo_size; | ||
433 | |||
434 | /* FIXME: Do we need to keep this bit of code inside NOT_USED around at all? */ | ||
435 | #ifdef NOT_USED | ||
436 | /* *************************************************** */ | ||
437 | /* Try to toggle 32-bit mode. This only | ||
438 | works on an 18c30 chip. (User reports | ||
439 | say this works, so we should switch to | ||
440 | it in the near future.) */ | ||
441 | outb(0x80, port + IO_Control); | ||
442 | if ((inb(port + Configuration2) & 0x80) == 0x80) { | ||
443 | outb(0x00, port + IO_Control); | ||
444 | if ((inb(port + Configuration2) & 0x80) == 0x00) { | ||
445 | chip = tmc18c30; | ||
446 | FIFO_Size = 0x800; /* 2k FIFO */ | ||
447 | |||
448 | printk("FIRST: chip=%s, fifo_size=0x%x\n", (chip == tmc18c30) ? "tmc18c30" : "tmc18c50", FIFO_Size); | ||
449 | } | ||
450 | } | ||
451 | |||
452 | /* That should have worked, but appears to | ||
453 | have problems. Let's assume it is an | ||
454 | 18c30 if the RAM is disabled. */ | ||
455 | |||
456 | if (inb(port + Configuration2) & 0x02) { | ||
457 | chip = tmc18c30; | ||
458 | FIFO_Size = 0x800; /* 2k FIFO */ | ||
459 | |||
460 | printk("SECOND: chip=%s, fifo_size=0x%x\n", (chip == tmc18c30) ? "tmc18c30" : "tmc18c50", FIFO_Size); | ||
461 | } | ||
462 | /* *************************************************** */ | ||
463 | #endif | ||
464 | |||
465 | /* IBM/ANSI scsi scan ordering */ | ||
466 | /* Stick this back in when the scsi.c changes are there */ | ||
467 | shpnt->reverse_ordering = 1; | ||
468 | |||
469 | |||
470 | /* saving info */ | ||
471 | hosts[found++] = shpnt; | ||
472 | |||
473 | shpnt->this_id = id; | ||
474 | shpnt->irq = irq; | ||
475 | shpnt->io_port = port; | ||
476 | shpnt->n_io_port = 0x10; | ||
477 | |||
478 | /* save */ | ||
479 | bios_base = bios; | ||
480 | adapter_mask = (1 << id); | ||
481 | |||
482 | /* save more */ | ||
483 | SCSI_Mode_Cntl_port = port + SCSI_Mode_Cntl; | ||
484 | FIFO_Data_Count_port = port + FIFO_Data_Count; | ||
485 | Interrupt_Cntl_port = port + Interrupt_Cntl; | ||
486 | Interrupt_Status_port = port + Interrupt_Status; | ||
487 | Interrupt_Cond_port = port + Interrupt_Cond; | ||
488 | Read_FIFO_port = port + Read_FIFO; | ||
489 | Read_SCSI_Data_port = port + Read_SCSI_Data; | ||
490 | SCSI_Cntl_port = port + SCSI_Cntl; | ||
491 | SCSI_Data_NoACK_port = port + SCSI_Data_NoACK; | ||
492 | SCSI_Status_port = port + SCSI_Status; | ||
493 | TMC_Cntl_port = port + TMC_Cntl; | ||
494 | TMC_Status_port = port + TMC_Status; | ||
495 | Write_FIFO_port = port + Write_FIFO; | ||
496 | Write_SCSI_Data_port = port + Write_SCSI_Data; | ||
497 | |||
498 | Bytes_Read = 0; | ||
499 | Bytes_Written = 0; | ||
500 | INTR_Processed = 0; | ||
501 | |||
502 | /* say something */ | ||
503 | print_banner(shpnt); | ||
504 | |||
505 | /* reset */ | ||
506 | outb(1, SCSI_Cntl_port); | ||
507 | do_pause(2); | ||
508 | outb(0, SCSI_Cntl_port); | ||
509 | do_pause(115); | ||
510 | outb(0, SCSI_Mode_Cntl_port); | ||
511 | outb(PARITY_MASK, TMC_Cntl_port); | ||
512 | /* done reset */ | ||
513 | } | ||
514 | } | ||
515 | |||
516 | if (found == FD_MAX_HOSTS) { | ||
517 | printk("fd_mcs: detecting reached max=%d host adapters.\n", FD_MAX_HOSTS); | ||
518 | break; | ||
519 | } | ||
520 | } | ||
521 | |||
522 | return found; | ||
523 | } | ||
524 | |||
525 | static const char *fd_mcs_info(struct Scsi_Host *shpnt) | ||
526 | { | ||
527 | return adapter_name; | ||
528 | } | ||
529 | |||
530 | static int TOTAL_INTR = 0; | ||
531 | |||
532 | /* | ||
533 | * inout : decides on the direction of the dataflow and the meaning of the | ||
534 | * variables | ||
535 | * buffer: If inout==FALSE data is being written to it else read from it | ||
536 | * *start: If inout==FALSE start of the valid data in the buffer | ||
537 | * offset: If inout==FALSE offset from the beginning of the imaginary file | ||
538 | * from which we start writing into the buffer | ||
539 | * length: If inout==FALSE max number of bytes to be written into the buffer | ||
540 | * else number of bytes in the buffer | ||
541 | */ | ||
542 | static int fd_mcs_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout) | ||
543 | { | ||
544 | int len = 0; | ||
545 | |||
546 | if (inout) | ||
547 | return (-ENOSYS); | ||
548 | |||
549 | *start = buffer + offset; | ||
550 | |||
551 | len += sprintf(buffer + len, "Future Domain MCS-600/700 Driver %s\n", DRIVER_VERSION); | ||
552 | len += sprintf(buffer + len, "HOST #%d: %s\n", shpnt->host_no, adapter_name); | ||
553 | len += sprintf(buffer + len, "FIFO Size=0x%x, FIFO Count=%d\n", FIFO_Size, FIFO_COUNT); | ||
554 | len += sprintf(buffer + len, "DriverCalls=%d, Interrupts=%d, BytesRead=%d, BytesWrite=%d\n\n", TOTAL_INTR, INTR_Processed, Bytes_Read, Bytes_Written); | ||
555 | |||
556 | if ((len -= offset) <= 0) | ||
557 | return 0; | ||
558 | if (len > length) | ||
559 | len = length; | ||
560 | return len; | ||
561 | } | ||
562 | |||
563 | static int fd_mcs_select(struct Scsi_Host *shpnt, int target) | ||
564 | { | ||
565 | int status; | ||
566 | unsigned long timeout; | ||
567 | |||
568 | outb(0x82, SCSI_Cntl_port); /* Bus Enable + Select */ | ||
569 | outb(adapter_mask | (1 << target), SCSI_Data_NoACK_port); | ||
570 | |||
571 | /* Stop arbitration and enable parity */ | ||
572 | outb(PARITY_MASK, TMC_Cntl_port); | ||
573 | |||
574 | timeout = 350; /* 350mS -- because of timeouts | ||
575 | (was 250mS) */ | ||
576 | |||
577 | do { | ||
578 | status = inb(SCSI_Status_port); /* Read adapter status */ | ||
579 | if (status & 1) { /* Busy asserted */ | ||
580 | /* Enable SCSI Bus (on error, should make bus idle with 0) */ | ||
581 | outb(0x80, SCSI_Cntl_port); | ||
582 | return 0; | ||
583 | } | ||
584 | udelay(1000); /* wait one msec */ | ||
585 | } while (--timeout); | ||
586 | |||
587 | /* Make bus idle */ | ||
588 | fd_mcs_make_bus_idle(shpnt); | ||
589 | #if EVERY_ACCESS | ||
590 | if (!target) | ||
591 | printk("Selection failed\n"); | ||
592 | #endif | ||
593 | #if ERRORS_ONLY | ||
594 | if (!target) { | ||
595 | static int flag = 0; | ||
596 | |||
597 | if (!flag) /* Skip first failure for all chips. */ | ||
598 | ++flag; | ||
599 | else | ||
600 | printk("fd_mcs: Selection failed\n"); | ||
601 | } | ||
602 | #endif | ||
603 | return 1; | ||
604 | } | ||
605 | |||
606 | static void my_done(struct Scsi_Host *shpnt, int error) | ||
607 | { | ||
608 | if (in_command) { | ||
609 | in_command = 0; | ||
610 | outb(0x00, Interrupt_Cntl_port); | ||
611 | fd_mcs_make_bus_idle(shpnt); | ||
612 | current_SC->result = error; | ||
613 | current_SC->scsi_done(current_SC); | ||
614 | } else { | ||
615 | panic("fd_mcs: my_done() called outside of command\n"); | ||
616 | } | ||
617 | #if DEBUG_RACE | ||
618 | in_interrupt_flag = 0; | ||
619 | #endif | ||
620 | } | ||
621 | |||
622 | /* only my_done needs to be protected */ | ||
623 | static irqreturn_t fd_mcs_intr(int irq, void *dev_id) | ||
624 | { | ||
625 | unsigned long flags; | ||
626 | int status; | ||
627 | int done = 0; | ||
628 | unsigned data_count, tmp_count; | ||
629 | |||
630 | int i = 0; | ||
631 | struct Scsi_Host *shpnt; | ||
632 | |||
633 | TOTAL_INTR++; | ||
634 | |||
635 | /* search for one adapter-response on shared interrupt */ | ||
636 | while ((shpnt = hosts[i++])) { | ||
637 | if ((inb(TMC_Status_port)) & 1) | ||
638 | break; | ||
639 | } | ||
640 | |||
641 | /* return if some other device on this IRQ caused the interrupt */ | ||
642 | if (!shpnt) { | ||
643 | return IRQ_NONE; | ||
644 | } | ||
645 | |||
646 | INTR_Processed++; | ||
647 | |||
648 | outb(0x00, Interrupt_Cntl_port); | ||
649 | |||
650 | /* Abort calls my_done, so we do nothing here. */ | ||
651 | if (current_SC->SCp.phase & aborted) { | ||
652 | #if DEBUG_ABORT | ||
653 | printk("Interrupt after abort, ignoring\n"); | ||
654 | #endif | ||
655 | /* return IRQ_HANDLED; */ | ||
656 | } | ||
657 | #if DEBUG_RACE | ||
658 | ++in_interrupt_flag; | ||
659 | #endif | ||
660 | |||
661 | if (current_SC->SCp.phase & in_arbitration) { | ||
662 | status = inb(TMC_Status_port); /* Read adapter status */ | ||
663 | if (!(status & 0x02)) { | ||
664 | #if EVERY_ACCESS | ||
665 | printk(" AFAIL "); | ||
666 | #endif | ||
667 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
668 | my_done(shpnt, DID_BUS_BUSY << 16); | ||
669 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
670 | return IRQ_HANDLED; | ||
671 | } | ||
672 | current_SC->SCp.phase = in_selection; | ||
673 | |||
674 | outb(0x40 | FIFO_COUNT, Interrupt_Cntl_port); | ||
675 | |||
676 | outb(0x82, SCSI_Cntl_port); /* Bus Enable + Select */ | ||
677 | outb(adapter_mask | (1 << scmd_id(current_SC)), SCSI_Data_NoACK_port); | ||
678 | |||
679 | /* Stop arbitration and enable parity */ | ||
680 | outb(0x10 | PARITY_MASK, TMC_Cntl_port); | ||
681 | #if DEBUG_RACE | ||
682 | in_interrupt_flag = 0; | ||
683 | #endif | ||
684 | return IRQ_HANDLED; | ||
685 | } else if (current_SC->SCp.phase & in_selection) { | ||
686 | status = inb(SCSI_Status_port); | ||
687 | if (!(status & 0x01)) { | ||
688 | /* Try again, for slow devices */ | ||
689 | if (fd_mcs_select(shpnt, scmd_id(current_SC))) { | ||
690 | #if EVERY_ACCESS | ||
691 | printk(" SFAIL "); | ||
692 | #endif | ||
693 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
694 | my_done(shpnt, DID_NO_CONNECT << 16); | ||
695 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
696 | return IRQ_HANDLED; | ||
697 | } else { | ||
698 | #if EVERY_ACCESS | ||
699 | printk(" AltSel "); | ||
700 | #endif | ||
701 | /* Stop arbitration and enable parity */ | ||
702 | outb(0x10 | PARITY_MASK, TMC_Cntl_port); | ||
703 | } | ||
704 | } | ||
705 | current_SC->SCp.phase = in_other; | ||
706 | outb(0x90 | FIFO_COUNT, Interrupt_Cntl_port); | ||
707 | outb(0x80, SCSI_Cntl_port); | ||
708 | #if DEBUG_RACE | ||
709 | in_interrupt_flag = 0; | ||
710 | #endif | ||
711 | return IRQ_HANDLED; | ||
712 | } | ||
713 | |||
714 | /* current_SC->SCp.phase == in_other: this is the body of the routine */ | ||
715 | |||
716 | status = inb(SCSI_Status_port); | ||
717 | |||
718 | if (status & 0x10) { /* REQ */ | ||
719 | |||
720 | switch (status & 0x0e) { | ||
721 | |||
722 | case 0x08: /* COMMAND OUT */ | ||
723 | outb(current_SC->cmnd[current_SC->SCp.sent_command++], Write_SCSI_Data_port); | ||
724 | #if EVERY_ACCESS | ||
725 | printk("CMD = %x,", current_SC->cmnd[current_SC->SCp.sent_command - 1]); | ||
726 | #endif | ||
727 | break; | ||
728 | case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */ | ||
729 | if (chip != tmc1800 && !current_SC->SCp.have_data_in) { | ||
730 | current_SC->SCp.have_data_in = -1; | ||
731 | outb(0xd0 | PARITY_MASK, TMC_Cntl_port); | ||
732 | } | ||
733 | break; | ||
734 | case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */ | ||
735 | if (chip != tmc1800 && !current_SC->SCp.have_data_in) { | ||
736 | current_SC->SCp.have_data_in = 1; | ||
737 | outb(0x90 | PARITY_MASK, TMC_Cntl_port); | ||
738 | } | ||
739 | break; | ||
740 | case 0x0c: /* STATUS IN */ | ||
741 | current_SC->SCp.Status = inb(Read_SCSI_Data_port); | ||
742 | #if EVERY_ACCESS | ||
743 | printk("Status = %x, ", current_SC->SCp.Status); | ||
744 | #endif | ||
745 | #if ERRORS_ONLY | ||
746 | if (current_SC->SCp.Status && current_SC->SCp.Status != 2 && current_SC->SCp.Status != 8) { | ||
747 | printk("ERROR fd_mcs: target = %d, command = %x, status = %x\n", current_SC->device->id, current_SC->cmnd[0], current_SC->SCp.Status); | ||
748 | } | ||
749 | #endif | ||
750 | break; | ||
751 | case 0x0a: /* MESSAGE OUT */ | ||
752 | outb(MESSAGE_REJECT, Write_SCSI_Data_port); /* Reject */ | ||
753 | break; | ||
754 | case 0x0e: /* MESSAGE IN */ | ||
755 | current_SC->SCp.Message = inb(Read_SCSI_Data_port); | ||
756 | #if EVERY_ACCESS | ||
757 | printk("Message = %x, ", current_SC->SCp.Message); | ||
758 | #endif | ||
759 | if (!current_SC->SCp.Message) | ||
760 | ++done; | ||
761 | #if DEBUG_MESSAGES || EVERY_ACCESS | ||
762 | if (current_SC->SCp.Message) { | ||
763 | printk("fd_mcs: message = %x\n", current_SC->SCp.Message); | ||
764 | } | ||
765 | #endif | ||
766 | break; | ||
767 | } | ||
768 | } | ||
769 | |||
770 | if (chip == tmc1800 && !current_SC->SCp.have_data_in && (current_SC->SCp.sent_command >= current_SC->cmd_len)) { | ||
771 | /* We have to get the FIFO direction | ||
772 | correct, so I've made a table based | ||
773 | on the SCSI Standard of which commands | ||
774 | appear to require a DATA OUT phase. | ||
775 | */ | ||
776 | /* | ||
777 | p. 94: Command for all device types | ||
778 | CHANGE DEFINITION 40 DATA OUT | ||
779 | COMPARE 39 DATA OUT | ||
780 | COPY 18 DATA OUT | ||
781 | COPY AND VERIFY 3a DATA OUT | ||
782 | INQUIRY 12 | ||
783 | LOG SELECT 4c DATA OUT | ||
784 | LOG SENSE 4d | ||
785 | MODE SELECT (6) 15 DATA OUT | ||
786 | MODE SELECT (10) 55 DATA OUT | ||
787 | MODE SENSE (6) 1a | ||
788 | MODE SENSE (10) 5a | ||
789 | READ BUFFER 3c | ||
790 | RECEIVE DIAGNOSTIC RESULTS 1c | ||
791 | REQUEST SENSE 03 | ||
792 | SEND DIAGNOSTIC 1d DATA OUT | ||
793 | TEST UNIT READY 00 | ||
794 | WRITE BUFFER 3b DATA OUT | ||
795 | |||
796 | p.178: Commands for direct-access devices (not listed on p. 94) | ||
797 | FORMAT UNIT 04 DATA OUT | ||
798 | LOCK-UNLOCK CACHE 36 | ||
799 | PRE-FETCH 34 | ||
800 | PREVENT-ALLOW MEDIUM REMOVAL 1e | ||
801 | READ (6)/RECEIVE 08 | ||
802 | READ (10) 3c | ||
803 | READ CAPACITY 25 | ||
804 | READ DEFECT DATA (10) 37 | ||
805 | READ LONG 3e | ||
806 | REASSIGN BLOCKS 07 DATA OUT | ||
807 | RELEASE 17 | ||
808 | RESERVE 16 DATA OUT | ||
809 | REZERO UNIT/REWIND 01 | ||
810 | SEARCH DATA EQUAL (10) 31 DATA OUT | ||
811 | SEARCH DATA HIGH (10) 30 DATA OUT | ||
812 | SEARCH DATA LOW (10) 32 DATA OUT | ||
813 | SEEK (6) 0b | ||
814 | SEEK (10) 2b | ||
815 | SET LIMITS (10) 33 | ||
816 | START STOP UNIT 1b | ||
817 | SYNCHRONIZE CACHE 35 | ||
818 | VERIFY (10) 2f | ||
819 | WRITE (6)/PRINT/SEND 0a DATA OUT | ||
820 | WRITE (10)/SEND 2a DATA OUT | ||
821 | WRITE AND VERIFY (10) 2e DATA OUT | ||
822 | WRITE LONG 3f DATA OUT | ||
823 | WRITE SAME 41 DATA OUT ? | ||
824 | |||
825 | p. 261: Commands for sequential-access devices (not previously listed) | ||
826 | ERASE 19 | ||
827 | LOAD UNLOAD 1b | ||
828 | LOCATE 2b | ||
829 | READ BLOCK LIMITS 05 | ||
830 | READ POSITION 34 | ||
831 | READ REVERSE 0f | ||
832 | RECOVER BUFFERED DATA 14 | ||
833 | SPACE 11 | ||
834 | WRITE FILEMARKS 10 ? | ||
835 | |||
836 | p. 298: Commands for printer devices (not previously listed) | ||
837 | ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) ***** | ||
838 | SLEW AND PRINT 0b DATA OUT -- same as seek | ||
839 | STOP PRINT 1b | ||
840 | SYNCHRONIZE BUFFER 10 | ||
841 | |||
842 | p. 315: Commands for processor devices (not previously listed) | ||
843 | |||
844 | p. 321: Commands for write-once devices (not previously listed) | ||
845 | MEDIUM SCAN 38 | ||
846 | READ (12) a8 | ||
847 | SEARCH DATA EQUAL (12) b1 DATA OUT | ||
848 | SEARCH DATA HIGH (12) b0 DATA OUT | ||
849 | SEARCH DATA LOW (12) b2 DATA OUT | ||
850 | SET LIMITS (12) b3 | ||
851 | VERIFY (12) af | ||
852 | WRITE (12) aa DATA OUT | ||
853 | WRITE AND VERIFY (12) ae DATA OUT | ||
854 | |||
855 | p. 332: Commands for CD-ROM devices (not previously listed) | ||
856 | PAUSE/RESUME 4b | ||
857 | PLAY AUDIO (10) 45 | ||
858 | PLAY AUDIO (12) a5 | ||
859 | PLAY AUDIO MSF 47 | ||
860 | PLAY TRACK RELATIVE (10) 49 | ||
861 | PLAY TRACK RELATIVE (12) a9 | ||
862 | READ HEADER 44 | ||
863 | READ SUB-CHANNEL 42 | ||
864 | READ TOC 43 | ||
865 | |||
866 | p. 370: Commands for scanner devices (not previously listed) | ||
867 | GET DATA BUFFER STATUS 34 | ||
868 | GET WINDOW 25 | ||
869 | OBJECT POSITION 31 | ||
870 | SCAN 1b | ||
871 | SET WINDOW 24 DATA OUT | ||
872 | |||
873 | p. 391: Commands for optical memory devices (not listed) | ||
874 | ERASE (10) 2c | ||
875 | ERASE (12) ac | ||
876 | MEDIUM SCAN 38 DATA OUT | ||
877 | READ DEFECT DATA (12) b7 | ||
878 | READ GENERATION 29 | ||
879 | READ UPDATED BLOCK 2d | ||
880 | UPDATE BLOCK 3d DATA OUT | ||
881 | |||
882 | p. 419: Commands for medium changer devices (not listed) | ||
883 | EXCHANGE MEDIUM 46 | ||
884 | INITIALIZE ELEMENT STATUS 07 | ||
885 | MOVE MEDIUM a5 | ||
886 | POSITION TO ELEMENT 2b | ||
887 | READ ELEMENT STATUS b8 | ||
888 | REQUEST VOL. ELEMENT ADDRESS b5 | ||
889 | SEND VOLUME TAG b6 DATA OUT | ||
890 | |||
891 | p. 454: Commands for communications devices (not listed previously) | ||
892 | GET MESSAGE (6) 08 | ||
893 | GET MESSAGE (10) 28 | ||
894 | GET MESSAGE (12) a8 | ||
895 | */ | ||
896 | |||
897 | switch (current_SC->cmnd[0]) { | ||
898 | case CHANGE_DEFINITION: | ||
899 | case COMPARE: | ||
900 | case COPY: | ||
901 | case COPY_VERIFY: | ||
902 | case LOG_SELECT: | ||
903 | case MODE_SELECT: | ||
904 | case MODE_SELECT_10: | ||
905 | case SEND_DIAGNOSTIC: | ||
906 | case WRITE_BUFFER: | ||
907 | |||
908 | case FORMAT_UNIT: | ||
909 | case REASSIGN_BLOCKS: | ||
910 | case RESERVE: | ||
911 | case SEARCH_EQUAL: | ||
912 | case SEARCH_HIGH: | ||
913 | case SEARCH_LOW: | ||
914 | case WRITE_6: | ||
915 | case WRITE_10: | ||
916 | case WRITE_VERIFY: | ||
917 | case 0x3f: | ||
918 | case 0x41: | ||
919 | |||
920 | case 0xb1: | ||
921 | case 0xb0: | ||
922 | case 0xb2: | ||
923 | case 0xaa: | ||
924 | case 0xae: | ||
925 | |||
926 | case 0x24: | ||
927 | |||
928 | case 0x38: | ||
929 | case 0x3d: | ||
930 | |||
931 | case 0xb6: | ||
932 | |||
933 | case 0xea: /* alternate number for WRITE LONG */ | ||
934 | |||
935 | current_SC->SCp.have_data_in = -1; | ||
936 | outb(0xd0 | PARITY_MASK, TMC_Cntl_port); | ||
937 | break; | ||
938 | |||
939 | case 0x00: | ||
940 | default: | ||
941 | |||
942 | current_SC->SCp.have_data_in = 1; | ||
943 | outb(0x90 | PARITY_MASK, TMC_Cntl_port); | ||
944 | break; | ||
945 | } | ||
946 | } | ||
947 | |||
948 | if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */ | ||
949 | while ((data_count = FIFO_Size - inw(FIFO_Data_Count_port)) > 512) { | ||
950 | #if EVERY_ACCESS | ||
951 | printk("DC=%d, ", data_count); | ||
952 | #endif | ||
953 | if (data_count > current_SC->SCp.this_residual) | ||
954 | data_count = current_SC->SCp.this_residual; | ||
955 | if (data_count > 0) { | ||
956 | #if EVERY_ACCESS | ||
957 | printk("%d OUT, ", data_count); | ||
958 | #endif | ||
959 | if (data_count == 1) { | ||
960 | Bytes_Written++; | ||
961 | |||
962 | outb(*current_SC->SCp.ptr++, Write_FIFO_port); | ||
963 | --current_SC->SCp.this_residual; | ||
964 | } else { | ||
965 | data_count >>= 1; | ||
966 | tmp_count = data_count << 1; | ||
967 | outsw(Write_FIFO_port, current_SC->SCp.ptr, data_count); | ||
968 | current_SC->SCp.ptr += tmp_count; | ||
969 | Bytes_Written += tmp_count; | ||
970 | current_SC->SCp.this_residual -= tmp_count; | ||
971 | } | ||
972 | } | ||
973 | if (!current_SC->SCp.this_residual) { | ||
974 | if (current_SC->SCp.buffers_residual) { | ||
975 | --current_SC->SCp.buffers_residual; | ||
976 | ++current_SC->SCp.buffer; | ||
977 | current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer); | ||
978 | current_SC->SCp.this_residual = current_SC->SCp.buffer->length; | ||
979 | } else | ||
980 | break; | ||
981 | } | ||
982 | } | ||
983 | } else if (current_SC->SCp.have_data_in == 1) { /* DATA IN */ | ||
984 | while ((data_count = inw(FIFO_Data_Count_port)) > 0) { | ||
985 | #if EVERY_ACCESS | ||
986 | printk("DC=%d, ", data_count); | ||
987 | #endif | ||
988 | if (data_count > current_SC->SCp.this_residual) | ||
989 | data_count = current_SC->SCp.this_residual; | ||
990 | if (data_count) { | ||
991 | #if EVERY_ACCESS | ||
992 | printk("%d IN, ", data_count); | ||
993 | #endif | ||
994 | if (data_count == 1) { | ||
995 | Bytes_Read++; | ||
996 | *current_SC->SCp.ptr++ = inb(Read_FIFO_port); | ||
997 | --current_SC->SCp.this_residual; | ||
998 | } else { | ||
999 | data_count >>= 1; /* Number of words */ | ||
1000 | tmp_count = data_count << 1; | ||
1001 | insw(Read_FIFO_port, current_SC->SCp.ptr, data_count); | ||
1002 | current_SC->SCp.ptr += tmp_count; | ||
1003 | Bytes_Read += tmp_count; | ||
1004 | current_SC->SCp.this_residual -= tmp_count; | ||
1005 | } | ||
1006 | } | ||
1007 | if (!current_SC->SCp.this_residual && current_SC->SCp.buffers_residual) { | ||
1008 | --current_SC->SCp.buffers_residual; | ||
1009 | ++current_SC->SCp.buffer; | ||
1010 | current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer); | ||
1011 | current_SC->SCp.this_residual = current_SC->SCp.buffer->length; | ||
1012 | } | ||
1013 | } | ||
1014 | } | ||
1015 | |||
1016 | if (done) { | ||
1017 | #if EVERY_ACCESS | ||
1018 | printk(" ** IN DONE %d ** ", current_SC->SCp.have_data_in); | ||
1019 | #endif | ||
1020 | |||
1021 | #if EVERY_ACCESS | ||
1022 | printk("BEFORE MY_DONE. . ."); | ||
1023 | #endif | ||
1024 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
1025 | my_done(shpnt, (current_SC->SCp.Status & 0xff) | ||
1026 | | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16)); | ||
1027 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
1028 | #if EVERY_ACCESS | ||
1029 | printk("RETURNING.\n"); | ||
1030 | #endif | ||
1031 | |||
1032 | } else { | ||
1033 | if (current_SC->SCp.phase & disconnect) { | ||
1034 | outb(0xd0 | FIFO_COUNT, Interrupt_Cntl_port); | ||
1035 | outb(0x00, SCSI_Cntl_port); | ||
1036 | } else { | ||
1037 | outb(0x90 | FIFO_COUNT, Interrupt_Cntl_port); | ||
1038 | } | ||
1039 | } | ||
1040 | #if DEBUG_RACE | ||
1041 | in_interrupt_flag = 0; | ||
1042 | #endif | ||
1043 | return IRQ_HANDLED; | ||
1044 | } | ||
1045 | |||
1046 | static int fd_mcs_release(struct Scsi_Host *shpnt) | ||
1047 | { | ||
1048 | int i, this_host, irq_usage; | ||
1049 | |||
1050 | release_region(shpnt->io_port, shpnt->n_io_port); | ||
1051 | |||
1052 | this_host = -1; | ||
1053 | irq_usage = 0; | ||
1054 | for (i = 0; i < found; i++) { | ||
1055 | if (shpnt == hosts[i]) | ||
1056 | this_host = i; | ||
1057 | if (shpnt->irq == hosts[i]->irq) | ||
1058 | irq_usage++; | ||
1059 | } | ||
1060 | |||
1061 | /* only for the last one */ | ||
1062 | if (1 == irq_usage) | ||
1063 | free_irq(shpnt->irq, hosts); | ||
1064 | |||
1065 | found--; | ||
1066 | |||
1067 | for (i = this_host; i < found; i++) | ||
1068 | hosts[i] = hosts[i + 1]; | ||
1069 | |||
1070 | hosts[found] = NULL; | ||
1071 | |||
1072 | return 0; | ||
1073 | } | ||
1074 | |||
1075 | static int fd_mcs_queue_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *)) | ||
1076 | { | ||
1077 | struct Scsi_Host *shpnt = SCpnt->device->host; | ||
1078 | |||
1079 | if (in_command) { | ||
1080 | panic("fd_mcs: fd_mcs_queue() NOT REENTRANT!\n"); | ||
1081 | } | ||
1082 | #if EVERY_ACCESS | ||
1083 | printk("queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n", | ||
1084 | SCpnt->target, *(unsigned char *) SCpnt->cmnd, | ||
1085 | scsi_sg_count(SCpnt), scsi_bufflen(SCpnt)); | ||
1086 | #endif | ||
1087 | |||
1088 | fd_mcs_make_bus_idle(shpnt); | ||
1089 | |||
1090 | SCpnt->scsi_done = done; /* Save this for the done function */ | ||
1091 | current_SC = SCpnt; | ||
1092 | |||
1093 | /* Initialize static data */ | ||
1094 | |||
1095 | if (scsi_bufflen(current_SC)) { | ||
1096 | current_SC->SCp.buffer = scsi_sglist(current_SC); | ||
1097 | current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer); | ||
1098 | current_SC->SCp.this_residual = current_SC->SCp.buffer->length; | ||
1099 | current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 1; | ||
1100 | } else { | ||
1101 | current_SC->SCp.ptr = NULL; | ||
1102 | current_SC->SCp.this_residual = 0; | ||
1103 | current_SC->SCp.buffer = NULL; | ||
1104 | current_SC->SCp.buffers_residual = 0; | ||
1105 | } | ||
1106 | |||
1107 | |||
1108 | current_SC->SCp.Status = 0; | ||
1109 | current_SC->SCp.Message = 0; | ||
1110 | current_SC->SCp.have_data_in = 0; | ||
1111 | current_SC->SCp.sent_command = 0; | ||
1112 | current_SC->SCp.phase = in_arbitration; | ||
1113 | |||
1114 | /* Start arbitration */ | ||
1115 | outb(0x00, Interrupt_Cntl_port); | ||
1116 | outb(0x00, SCSI_Cntl_port); /* Disable data drivers */ | ||
1117 | outb(adapter_mask, SCSI_Data_NoACK_port); /* Set our id bit */ | ||
1118 | in_command = 1; | ||
1119 | outb(0x20, Interrupt_Cntl_port); | ||
1120 | outb(0x14 | PARITY_MASK, TMC_Cntl_port); /* Start arbitration */ | ||
1121 | |||
1122 | return 0; | ||
1123 | } | ||
1124 | |||
1125 | static DEF_SCSI_QCMD(fd_mcs_queue) | ||
1126 | |||
1127 | #if DEBUG_ABORT || DEBUG_RESET | ||
1128 | static void fd_mcs_print_info(Scsi_Cmnd * SCpnt) | ||
1129 | { | ||
1130 | unsigned int imr; | ||
1131 | unsigned int irr; | ||
1132 | unsigned int isr; | ||
1133 | struct Scsi_Host *shpnt = SCpnt->host; | ||
1134 | |||
1135 | if (!SCpnt || !SCpnt->host) { | ||
1136 | printk("fd_mcs: cannot provide detailed information\n"); | ||
1137 | } | ||
1138 | |||
1139 | printk("%s\n", fd_mcs_info(SCpnt->host)); | ||
1140 | print_banner(SCpnt->host); | ||
1141 | switch (SCpnt->SCp.phase) { | ||
1142 | case in_arbitration: | ||
1143 | printk("arbitration "); | ||
1144 | break; | ||
1145 | case in_selection: | ||
1146 | printk("selection "); | ||
1147 | break; | ||
1148 | case in_other: | ||
1149 | printk("other "); | ||
1150 | break; | ||
1151 | default: | ||
1152 | printk("unknown "); | ||
1153 | break; | ||
1154 | } | ||
1155 | |||
1156 | printk("(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n", | ||
1157 | SCpnt->SCp.phase, SCpnt->device->id, *(unsigned char *) SCpnt->cmnd, | ||
1158 | scsi_sg_count(SCpnt), scsi_bufflen(SCpnt)); | ||
1159 | printk("sent_command = %d, have_data_in = %d, timeout = %d\n", SCpnt->SCp.sent_command, SCpnt->SCp.have_data_in, SCpnt->timeout); | ||
1160 | #if DEBUG_RACE | ||
1161 | printk("in_interrupt_flag = %d\n", in_interrupt_flag); | ||
1162 | #endif | ||
1163 | |||
1164 | imr = (inb(0x0a1) << 8) + inb(0x21); | ||
1165 | outb(0x0a, 0xa0); | ||
1166 | irr = inb(0xa0) << 8; | ||
1167 | outb(0x0a, 0x20); | ||
1168 | irr += inb(0x20); | ||
1169 | outb(0x0b, 0xa0); | ||
1170 | isr = inb(0xa0) << 8; | ||
1171 | outb(0x0b, 0x20); | ||
1172 | isr += inb(0x20); | ||
1173 | |||
1174 | /* Print out interesting information */ | ||
1175 | printk("IMR = 0x%04x", imr); | ||
1176 | if (imr & (1 << shpnt->irq)) | ||
1177 | printk(" (masked)"); | ||
1178 | printk(", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr); | ||
1179 | |||
1180 | printk("SCSI Status = 0x%02x\n", inb(SCSI_Status_port)); | ||
1181 | printk("TMC Status = 0x%02x", inb(TMC_Status_port)); | ||
1182 | if (inb(TMC_Status_port) & 1) | ||
1183 | printk(" (interrupt)"); | ||
1184 | printk("\n"); | ||
1185 | printk("Interrupt Status = 0x%02x", inb(Interrupt_Status_port)); | ||
1186 | if (inb(Interrupt_Status_port) & 0x08) | ||
1187 | printk(" (enabled)"); | ||
1188 | printk("\n"); | ||
1189 | if (chip == tmc18c50 || chip == tmc18c30) { | ||
1190 | printk("FIFO Status = 0x%02x\n", inb(shpnt->io_port + FIFO_Status)); | ||
1191 | printk("Int. Condition = 0x%02x\n", inb(shpnt->io_port + Interrupt_Cond)); | ||
1192 | } | ||
1193 | printk("Configuration 1 = 0x%02x\n", inb(shpnt->io_port + Configuration1)); | ||
1194 | if (chip == tmc18c50 || chip == tmc18c30) | ||
1195 | printk("Configuration 2 = 0x%02x\n", inb(shpnt->io_port + Configuration2)); | ||
1196 | } | ||
1197 | #endif | ||
1198 | |||
1199 | static int fd_mcs_abort(Scsi_Cmnd * SCpnt) | ||
1200 | { | ||
1201 | struct Scsi_Host *shpnt = SCpnt->device->host; | ||
1202 | |||
1203 | unsigned long flags; | ||
1204 | #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT | ||
1205 | printk("fd_mcs: abort "); | ||
1206 | #endif | ||
1207 | |||
1208 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
1209 | if (!in_command) { | ||
1210 | #if EVERY_ACCESS || ERRORS_ONLY | ||
1211 | printk(" (not in command)\n"); | ||
1212 | #endif | ||
1213 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
1214 | return FAILED; | ||
1215 | } else | ||
1216 | printk("\n"); | ||
1217 | |||
1218 | #if DEBUG_ABORT | ||
1219 | fd_mcs_print_info(SCpnt); | ||
1220 | #endif | ||
1221 | |||
1222 | fd_mcs_make_bus_idle(shpnt); | ||
1223 | |||
1224 | current_SC->SCp.phase |= aborted; | ||
1225 | |||
1226 | current_SC->result = DID_ABORT << 16; | ||
1227 | |||
1228 | /* Aborts are not done well. . . */ | ||
1229 | my_done(shpnt, DID_ABORT << 16); | ||
1230 | |||
1231 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
1232 | return SUCCESS; | ||
1233 | } | ||
1234 | |||
1235 | static int fd_mcs_bus_reset(Scsi_Cmnd * SCpnt) { | ||
1236 | struct Scsi_Host *shpnt = SCpnt->device->host; | ||
1237 | unsigned long flags; | ||
1238 | |||
1239 | #if DEBUG_RESET | ||
1240 | static int called_once = 0; | ||
1241 | #endif | ||
1242 | |||
1243 | #if ERRORS_ONLY | ||
1244 | if (SCpnt) | ||
1245 | printk("fd_mcs: SCSI Bus Reset\n"); | ||
1246 | #endif | ||
1247 | |||
1248 | #if DEBUG_RESET | ||
1249 | if (called_once) | ||
1250 | fd_mcs_print_info(current_SC); | ||
1251 | called_once = 1; | ||
1252 | #endif | ||
1253 | |||
1254 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
1255 | |||
1256 | outb(1, SCSI_Cntl_port); | ||
1257 | do_pause(2); | ||
1258 | outb(0, SCSI_Cntl_port); | ||
1259 | do_pause(115); | ||
1260 | outb(0, SCSI_Mode_Cntl_port); | ||
1261 | outb(PARITY_MASK, TMC_Cntl_port); | ||
1262 | |||
1263 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
1264 | |||
1265 | /* Unless this is the very first call (i.e., SCPnt == NULL), everything | ||
1266 | is probably hosed at this point. We will, however, try to keep | ||
1267 | things going by informing the high-level code that we need help. */ | ||
1268 | return SUCCESS; | ||
1269 | } | ||
1270 | |||
1271 | #include <scsi/scsi_ioctl.h> | ||
1272 | |||
1273 | static int fd_mcs_biosparam(struct scsi_device * disk, struct block_device *bdev, | ||
1274 | sector_t capacity, int *info_array) | ||
1275 | { | ||
1276 | unsigned char *p = scsi_bios_ptable(bdev); | ||
1277 | int size = capacity; | ||
1278 | |||
1279 | /* BIOS >= 3.4 for MCA cards */ | ||
1280 | /* This algorithm was provided by Future Domain (much thanks!). */ | ||
1281 | |||
1282 | if (p && p[65] == 0xaa && p[64] == 0x55 /* Partition table valid */ | ||
1283 | && p[4]) { /* Partition type */ | ||
1284 | /* The partition table layout is as follows: | ||
1285 | |||
1286 | Start: 0x1b3h | ||
1287 | Offset: 0 = partition status | ||
1288 | 1 = starting head | ||
1289 | 2 = starting sector and cylinder (word, encoded) | ||
1290 | 4 = partition type | ||
1291 | 5 = ending head | ||
1292 | 6 = ending sector and cylinder (word, encoded) | ||
1293 | 8 = starting absolute sector (double word) | ||
1294 | c = number of sectors (double word) | ||
1295 | Signature: 0x1fe = 0x55aa | ||
1296 | |||
1297 | So, this algorithm assumes: | ||
1298 | 1) the first partition table is in use, | ||
1299 | 2) the data in the first entry is correct, and | ||
1300 | 3) partitions never divide cylinders | ||
1301 | |||
1302 | Note that (1) may be FALSE for NetBSD (and other BSD flavors), | ||
1303 | as well as for Linux. Note also, that Linux doesn't pay any | ||
1304 | attention to the fields that are used by this algorithm -- it | ||
1305 | only uses the absolute sector data. Recent versions of Linux's | ||
1306 | fdisk(1) will fill this data in correctly, and forthcoming | ||
1307 | versions will check for consistency. | ||
1308 | |||
1309 | Checking for a non-zero partition type is not part of the | ||
1310 | Future Domain algorithm, but it seemed to be a reasonable thing | ||
1311 | to do, especially in the Linux and BSD worlds. */ | ||
1312 | |||
1313 | info_array[0] = p[5] + 1; /* heads */ | ||
1314 | info_array[1] = p[6] & 0x3f; /* sectors */ | ||
1315 | } else { | ||
1316 | /* Note that this new method guarantees that there will always be | ||
1317 | less than 1024 cylinders on a platter. This is good for drives | ||
1318 | up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */ | ||
1319 | if ((unsigned int) size >= 0x7e0000U) | ||
1320 | { | ||
1321 | info_array[0] = 0xff; /* heads = 255 */ | ||
1322 | info_array[1] = 0x3f; /* sectors = 63 */ | ||
1323 | } else if ((unsigned int) size >= 0x200000U) { | ||
1324 | info_array[0] = 0x80; /* heads = 128 */ | ||
1325 | info_array[1] = 0x3f; /* sectors = 63 */ | ||
1326 | } else { | ||
1327 | info_array[0] = 0x40; /* heads = 64 */ | ||
1328 | info_array[1] = 0x20; /* sectors = 32 */ | ||
1329 | } | ||
1330 | } | ||
1331 | /* For both methods, compute the cylinders */ | ||
1332 | info_array[2] = (unsigned int) size / (info_array[0] * info_array[1]); | ||
1333 | kfree(p); | ||
1334 | return 0; | ||
1335 | } | ||
1336 | |||
1337 | static struct scsi_host_template driver_template = { | ||
1338 | .proc_name = "fd_mcs", | ||
1339 | .proc_info = fd_mcs_proc_info, | ||
1340 | .detect = fd_mcs_detect, | ||
1341 | .release = fd_mcs_release, | ||
1342 | .info = fd_mcs_info, | ||
1343 | .queuecommand = fd_mcs_queue, | ||
1344 | .eh_abort_handler = fd_mcs_abort, | ||
1345 | .eh_bus_reset_handler = fd_mcs_bus_reset, | ||
1346 | .bios_param = fd_mcs_biosparam, | ||
1347 | .can_queue = 1, | ||
1348 | .this_id = 7, | ||
1349 | .sg_tablesize = 64, | ||
1350 | .cmd_per_lun = 1, | ||
1351 | .use_clustering = DISABLE_CLUSTERING, | ||
1352 | }; | ||
1353 | #include "scsi_module.c" | ||
1354 | |||
1355 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c new file mode 100644 index 00000000000..67fc8ffd52e --- /dev/null +++ b/drivers/scsi/ibmmca.c | |||
@@ -0,0 +1,2380 @@ | |||
1 | /* | ||
2 | Low Level Linux Driver for the IBM Microchannel SCSI Subsystem for | ||
3 | Linux Kernel >= 2.4.0. | ||
4 | Copyright (c) 1995 Strom Systems, Inc. under the terms of the GNU | ||
5 | General Public License. Written by Martin Kolinek, December 1995. | ||
6 | Further development by: Chris Beauregard, Klaus Kudielka, Michael Lang | ||
7 | See the file Documentation/scsi/ibmmca.txt for a detailed description | ||
8 | of this driver, the commandline arguments and the history of its | ||
9 | development. | ||
10 | See the WWW-page: http://www.uni-mainz.de/~langm000/linux.html for latest | ||
11 | updates, info and ADF-files for adapters supported by this driver. | ||
12 | |||
13 | Alan Cox <alan@lxorguk.ukuu.org.uk> | ||
14 | Updated for Linux 2.5.45 to use the new error handler, cleaned up the | ||
15 | lock macros and did a few unavoidable locking tweaks, plus one locking | ||
16 | fix in the irq and completion path. | ||
17 | |||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/types.h> | ||
23 | #include <linux/ctype.h> | ||
24 | #include <linux/string.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/ioport.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/blkdev.h> | ||
29 | #include <linux/proc_fs.h> | ||
30 | #include <linux/stat.h> | ||
31 | #include <linux/mca.h> | ||
32 | #include <linux/spinlock.h> | ||
33 | #include <linux/init.h> | ||
34 | |||
35 | #include <asm/system.h> | ||
36 | #include <asm/io.h> | ||
37 | |||
38 | #include "scsi.h" | ||
39 | #include <scsi/scsi_host.h> | ||
40 | |||
41 | /* Common forward declarations for all Linux-versions: */ | ||
42 | static int ibmmca_queuecommand (struct Scsi_Host *, struct scsi_cmnd *); | ||
43 | static int ibmmca_abort (Scsi_Cmnd *); | ||
44 | static int ibmmca_host_reset (Scsi_Cmnd *); | ||
45 | static int ibmmca_biosparam (struct scsi_device *, struct block_device *, sector_t, int *); | ||
46 | static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout); | ||
47 | |||
48 | |||
49 | |||
50 | /* current version of this driver-source: */ | ||
51 | #define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac" | ||
52 | |||
53 | /* driver configuration */ | ||
54 | #define IM_MAX_HOSTS 8 /* maximum number of host adapters */ | ||
55 | #define IM_RESET_DELAY 60 /* seconds allowed for a reset */ | ||
56 | |||
57 | /* driver debugging - #undef all for normal operation */ | ||
58 | /* if defined: count interrupts and ignore this special one: */ | ||
59 | #undef IM_DEBUG_TIMEOUT //50 | ||
60 | #define TIMEOUT_PUN 0 | ||
61 | #define TIMEOUT_LUN 0 | ||
62 | /* verbose interrupt: */ | ||
63 | #undef IM_DEBUG_INT | ||
64 | /* verbose queuecommand: */ | ||
65 | #undef IM_DEBUG_CMD | ||
66 | /* verbose queucommand for specific SCSI-device type: */ | ||
67 | #undef IM_DEBUG_CMD_SPEC_DEV | ||
68 | /* verbose device probing */ | ||
69 | #undef IM_DEBUG_PROBE | ||
70 | |||
71 | /* device type that shall be displayed on syslog (only during debugging): */ | ||
72 | #define IM_DEBUG_CMD_DEVICE TYPE_TAPE | ||
73 | |||
74 | /* relative addresses of hardware registers on a subsystem */ | ||
75 | #define IM_CMD_REG(h) ((h)->io_port) /*Command Interface, (4 bytes long) */ | ||
76 | #define IM_ATTN_REG(h) ((h)->io_port+4) /*Attention (1 byte) */ | ||
77 | #define IM_CTR_REG(h) ((h)->io_port+5) /*Basic Control (1 byte) */ | ||
78 | #define IM_INTR_REG(h) ((h)->io_port+6) /*Interrupt Status (1 byte, r/o) */ | ||
79 | #define IM_STAT_REG(h) ((h)->io_port+7) /*Basic Status (1 byte, read only) */ | ||
80 | |||
81 | /* basic I/O-port of first adapter */ | ||
82 | #define IM_IO_PORT 0x3540 | ||
83 | /* maximum number of hosts that can be found */ | ||
84 | #define IM_N_IO_PORT 8 | ||
85 | |||
86 | /*requests going into the upper nibble of the Attention register */ | ||
87 | /*note: the lower nibble specifies the device(0-14), or subsystem(15) */ | ||
88 | #define IM_IMM_CMD 0x10 /*immediate command */ | ||
89 | #define IM_SCB 0x30 /*Subsystem Control Block command */ | ||
90 | #define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */ | ||
91 | #define IM_EOI 0xe0 /*end-of-interrupt request */ | ||
92 | |||
93 | /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */ | ||
94 | #define IM_HW_RESET 0x80 /*hardware reset */ | ||
95 | #define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */ | ||
96 | #define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */ | ||
97 | |||
98 | /*to interpret the upper nibble of Interrupt Status register */ | ||
99 | /*note: the lower nibble specifies the device(0-14), or subsystem(15) */ | ||
100 | #define IM_SCB_CMD_COMPLETED 0x10 | ||
101 | #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50 | ||
102 | #define IM_LOOP_SCATTER_BUFFER_FULL 0x60 | ||
103 | #define IM_ADAPTER_HW_FAILURE 0x70 | ||
104 | #define IM_IMMEDIATE_CMD_COMPLETED 0xa0 | ||
105 | #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0 | ||
106 | #define IM_CMD_ERROR 0xe0 | ||
107 | #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0 | ||
108 | |||
109 | /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */ | ||
110 | #define IM_CMD_REG_FULL 0x08 | ||
111 | #define IM_CMD_REG_EMPTY 0x04 | ||
112 | #define IM_INTR_REQUEST 0x02 | ||
113 | #define IM_BUSY 0x01 | ||
114 | |||
115 | /*immediate commands (word written into low 2 bytes of command reg) */ | ||
116 | #define IM_RESET_IMM_CMD 0x0400 | ||
117 | #define IM_FEATURE_CTR_IMM_CMD 0x040c | ||
118 | #define IM_DMA_PACING_IMM_CMD 0x040d | ||
119 | #define IM_ASSIGN_IMM_CMD 0x040e | ||
120 | #define IM_ABORT_IMM_CMD 0x040f | ||
121 | #define IM_FORMAT_PREP_IMM_CMD 0x0417 | ||
122 | |||
123 | /*SCB (Subsystem Control Block) structure */ | ||
124 | struct im_scb { | ||
125 | unsigned short command; /*command word (read, etc.) */ | ||
126 | unsigned short enable; /*enable word, modifies cmd */ | ||
127 | union { | ||
128 | unsigned long log_blk_adr; /*block address on SCSI device */ | ||
129 | unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */ | ||
130 | } u1; | ||
131 | unsigned long sys_buf_adr; /*physical system memory adr */ | ||
132 | unsigned long sys_buf_length; /*size of sys mem buffer */ | ||
133 | unsigned long tsb_adr; /*Termination Status Block adr */ | ||
134 | unsigned long scb_chain_adr; /*optional SCB chain address */ | ||
135 | union { | ||
136 | struct { | ||
137 | unsigned short count; /*block count, on SCSI device */ | ||
138 | unsigned short length; /*block length, on SCSI device */ | ||
139 | } blk; | ||
140 | unsigned char scsi_command[12]; /*other scsi command */ | ||
141 | } u2; | ||
142 | }; | ||
143 | |||
144 | /*structure scatter-gather element (for list of system memory areas) */ | ||
145 | struct im_sge { | ||
146 | void *address; | ||
147 | unsigned long byte_length; | ||
148 | }; | ||
149 | |||
150 | /*structure returned by a get_pos_info command: */ | ||
151 | struct im_pos_info { | ||
152 | unsigned short pos_id; /* adapter id */ | ||
153 | unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */ | ||
154 | unsigned char pos_2; /* pos 2 */ | ||
155 | unsigned char int_level; /* interrupt level IRQ 11 or 14 */ | ||
156 | unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */ | ||
157 | unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */ | ||
158 | unsigned char num_luns; /* number of supported luns per device */ | ||
159 | unsigned char num_puns; /* number of supported puns */ | ||
160 | unsigned char pacing_factor; /* pacing factor */ | ||
161 | unsigned char num_ldns; /* number of ldns available */ | ||
162 | unsigned char eoi_off; /* time EOI and interrupt inactive */ | ||
163 | unsigned char max_busy; /* time between reset and busy on */ | ||
164 | unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */ | ||
165 | unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */ | ||
166 | unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */ | ||
167 | unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */ | ||
168 | unsigned char pos_6; /* pos 6 */ | ||
169 | unsigned char pos_5; /* pos 5 */ | ||
170 | unsigned short max_overlap; /* maximum overlapping requests */ | ||
171 | unsigned short num_bus; /* number of SCSI-busses */ | ||
172 | }; | ||
173 | |||
174 | /*values for SCB command word */ | ||
175 | #define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */ | ||
176 | #define IM_NO_DISCONNECT 0x0080 /*flag for any command */ | ||
177 | #define IM_READ_DATA_CMD 0x1c01 | ||
178 | #define IM_WRITE_DATA_CMD 0x1c02 | ||
179 | #define IM_READ_VERIFY_CMD 0x1c03 | ||
180 | #define IM_WRITE_VERIFY_CMD 0x1c04 | ||
181 | #define IM_REQUEST_SENSE_CMD 0x1c08 | ||
182 | #define IM_READ_CAPACITY_CMD 0x1c09 | ||
183 | #define IM_DEVICE_INQUIRY_CMD 0x1c0b | ||
184 | #define IM_READ_LOGICAL_CMD 0x1c2a | ||
185 | #define IM_OTHER_SCSI_CMD_CMD 0x241f | ||
186 | |||
187 | /* unused, but supported, SCB commands */ | ||
188 | #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */ | ||
189 | #define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */ | ||
190 | #define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */ | ||
191 | #define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */ | ||
192 | #define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */ | ||
193 | |||
194 | /*values to set bits in the enable word of SCB */ | ||
195 | #define IM_READ_CONTROL 0x8000 | ||
196 | #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000 | ||
197 | #define IM_RETRY_ENABLE 0x2000 | ||
198 | #define IM_POINTER_TO_LIST 0x1000 | ||
199 | #define IM_SUPRESS_EXCEPTION_SHORT 0x0400 | ||
200 | #define IM_BYPASS_BUFFER 0x0200 | ||
201 | #define IM_CHAIN_ON_NO_ERROR 0x0001 | ||
202 | |||
203 | /*TSB (Termination Status Block) structure */ | ||
204 | struct im_tsb { | ||
205 | unsigned short end_status; | ||
206 | unsigned short reserved1; | ||
207 | unsigned long residual_byte_count; | ||
208 | unsigned long sg_list_element_adr; | ||
209 | unsigned short status_length; | ||
210 | unsigned char dev_status; | ||
211 | unsigned char cmd_status; | ||
212 | unsigned char dev_error; | ||
213 | unsigned char cmd_error; | ||
214 | unsigned short reserved2; | ||
215 | unsigned short reserved3; | ||
216 | unsigned short low_of_last_scb_adr; | ||
217 | unsigned short high_of_last_scb_adr; | ||
218 | }; | ||
219 | |||
220 | /*subsystem uses interrupt request level 14 */ | ||
221 | #define IM_IRQ 14 | ||
222 | /*SCSI-2 F/W may evade to interrupt 11 */ | ||
223 | #define IM_IRQ_FW 11 | ||
224 | |||
225 | /* Model 95 has an additional alphanumeric display, which can be used | ||
226 | to display SCSI-activities. 8595 models do not have any disk led, which | ||
227 | makes this feature quite useful. | ||
228 | The regular PS/2 disk led is turned on/off by bits 6,7 of system | ||
229 | control port. */ | ||
230 | |||
231 | /* LED display-port (actually, last LED on display) */ | ||
232 | #define MOD95_LED_PORT 0x108 | ||
233 | /* system-control-register of PS/2s with diskindicator */ | ||
234 | #define PS2_SYS_CTR 0x92 | ||
235 | /* activity displaying methods */ | ||
236 | #define LED_DISP 1 | ||
237 | #define LED_ADISP 2 | ||
238 | #define LED_ACTIVITY 4 | ||
239 | /* failed intr */ | ||
240 | #define CMD_FAIL 255 | ||
241 | |||
242 | /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED | ||
243 | displays. ldn is no longer displayed here, because the ldn mapping is now | ||
244 | done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime | ||
245 | or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble, | ||
246 | interest, debugging or just for having fun. The left number gives the | ||
247 | host-adapter number and the right shows the accessed SCSI-ID. */ | ||
248 | |||
249 | /* display_mode is set by the ibmmcascsi= command line arg */ | ||
250 | static int display_mode = 0; | ||
251 | /* set default adapter timeout */ | ||
252 | static unsigned int adapter_timeout = 45; | ||
253 | /* for probing on feature-command: */ | ||
254 | static unsigned int global_command_error_excuse = 0; | ||
255 | /* global setting by command line for adapter_speed */ | ||
256 | static int global_adapter_speed = 0; /* full speed by default */ | ||
257 | |||
258 | /* Panel / LED on, do it right for F/W addressin, too. adisplay will | ||
259 | * just ignore ids>7, as the panel has only 7 digits available */ | ||
260 | #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \ | ||
261 | outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \ | ||
262 | outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \ | ||
263 | if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \ | ||
264 | outb((char)(ad+48), MOD95_LED_PORT); } \ | ||
265 | if ((display_mode & LED_ACTIVITY)||(!display_mode)) \ | ||
266 | outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); } | ||
267 | |||
268 | /* Panel / LED off */ | ||
269 | /* bug fixed, Dec 15, 1997, where | was replaced by & here */ | ||
270 | #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \ | ||
271 | outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \ | ||
272 | outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \ | ||
273 | if ((display_mode & LED_ACTIVITY)||(!display_mode)) \ | ||
274 | outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); } | ||
275 | |||
276 | /* types of different supported hardware that goes to hostdata special */ | ||
277 | #define IBM_SCSI2_FW 0 | ||
278 | #define IBM_7568_WCACHE 1 | ||
279 | #define IBM_EXP_UNIT 2 | ||
280 | #define IBM_SCSI_WCACHE 3 | ||
281 | #define IBM_SCSI 4 | ||
282 | #define IBM_INTEGSCSI 5 | ||
283 | |||
284 | /* other special flags for hostdata structure */ | ||
285 | #define FORCED_DETECTION 100 | ||
286 | #define INTEGRATED_SCSI 101 | ||
287 | |||
288 | /* List of possible IBM-SCSI-adapters */ | ||
289 | static short ibmmca_id_table[] = { | ||
290 | 0x8efc, | ||
291 | 0x8efd, | ||
292 | 0x8ef8, | ||
293 | 0x8eff, | ||
294 | 0x8efe, | ||
295 | /* No entry for integrated SCSI, that's part of the register */ | ||
296 | 0 | ||
297 | }; | ||
298 | |||
299 | static const char *ibmmca_description[] = { | ||
300 | "IBM SCSI-2 F/W Adapter", /* special = 0 */ | ||
301 | "IBM 7568 Industrial Computer SCSI Adapter w/Cache", /* special = 1 */ | ||
302 | "IBM Expansion Unit SCSI Controller", /* special = 2 */ | ||
303 | "IBM SCSI Adapter w/Cache", /* special = 3 */ | ||
304 | "IBM SCSI Adapter", /* special = 4 */ | ||
305 | "IBM Integrated SCSI Controller", /* special = 5 */ | ||
306 | }; | ||
307 | |||
308 | /* Max number of logical devices (can be up from 0 to 14). 15 is the address | ||
309 | of the adapter itself. */ | ||
310 | #define MAX_LOG_DEV 15 | ||
311 | |||
312 | /*local data for a logical device */ | ||
313 | struct logical_device { | ||
314 | struct im_scb scb; /* SCSI-subsystem-control-block structure */ | ||
315 | struct im_tsb tsb; /* SCSI command complete status block structure */ | ||
316 | struct im_sge sge[16]; /* scatter gather list structure */ | ||
317 | unsigned char buf[256]; /* SCSI command return data buffer */ | ||
318 | Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */ | ||
319 | int device_type; /* type of the SCSI-device. See include/scsi/scsi.h | ||
320 | for interpretation of the possible values */ | ||
321 | int block_length; /* blocksize of a particular logical SCSI-device */ | ||
322 | int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */ | ||
323 | int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */ | ||
324 | }; | ||
325 | |||
326 | /* statistics of the driver during operations (for proc_info) */ | ||
327 | struct Driver_Statistics { | ||
328 | /* SCSI statistics on the adapter */ | ||
329 | int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */ | ||
330 | int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */ | ||
331 | int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */ | ||
332 | int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */ | ||
333 | int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */ | ||
334 | int scbs; /* short SCBs queued */ | ||
335 | int long_scbs; /* long SCBs queued */ | ||
336 | int total_accesses; /* total accesses on all ldns */ | ||
337 | int total_interrupts; /* total interrupts (should be | ||
338 | same as total_accesses) */ | ||
339 | int total_errors; /* command completed with error */ | ||
340 | /* dynamical assignment statistics */ | ||
341 | int total_scsi_devices; /* number of physical pun,lun */ | ||
342 | int dyn_flag; /* flag showing dynamical mode */ | ||
343 | int dynamical_assignments; /* number of remappings of ldns */ | ||
344 | int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each | ||
345 | ldn */ | ||
346 | }; | ||
347 | |||
348 | /* data structure for each host adapter */ | ||
349 | struct ibmmca_hostdata { | ||
350 | /* array of logical devices: */ | ||
351 | struct logical_device _ld[MAX_LOG_DEV + 1]; | ||
352 | /* array to convert (pun, lun) into logical device number: */ | ||
353 | unsigned char _get_ldn[16][8]; | ||
354 | /*array that contains the information about the physical SCSI-devices | ||
355 | attached to this host adapter: */ | ||
356 | unsigned char _get_scsi[16][8]; | ||
357 | /* used only when checking logical devices: */ | ||
358 | int _local_checking_phase_flag; | ||
359 | /* report received interrupt: */ | ||
360 | int _got_interrupt; | ||
361 | /* report termination-status of SCSI-command: */ | ||
362 | int _stat_result; | ||
363 | /* reset status (used only when doing reset): */ | ||
364 | int _reset_status; | ||
365 | /* code of the last SCSI command (needed for panic info): */ | ||
366 | int _last_scsi_command[MAX_LOG_DEV + 1]; | ||
367 | /* identifier of the last SCSI-command type */ | ||
368 | int _last_scsi_type[MAX_LOG_DEV + 1]; | ||
369 | /* last blockcount */ | ||
370 | int _last_scsi_blockcount[MAX_LOG_DEV + 1]; | ||
371 | /* last locgical block address */ | ||
372 | unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1]; | ||
373 | /* Counter that points on the next reassignable ldn for dynamical | ||
374 | remapping. The default value is 7, that is the first reassignable | ||
375 | number in the list at boottime: */ | ||
376 | int _next_ldn; | ||
377 | /* Statistics-structure for this IBM-SCSI-host: */ | ||
378 | struct Driver_Statistics _IBM_DS; | ||
379 | /* This hostadapters pos-registers pos2 until pos6 */ | ||
380 | unsigned int _pos[8]; | ||
381 | /* assign a special variable, that contains dedicated info about the | ||
382 | adaptertype */ | ||
383 | int _special; | ||
384 | /* connector size on the MCA bus */ | ||
385 | int _connector_size; | ||
386 | /* synchronous SCSI transfer rate bitpattern */ | ||
387 | int _adapter_speed; | ||
388 | }; | ||
389 | |||
390 | /* macros to access host data structure */ | ||
391 | #define subsystem_pun(h) ((h)->this_id) | ||
392 | #define subsystem_maxid(h) ((h)->max_id) | ||
393 | #define ld(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_ld) | ||
394 | #define get_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_ldn) | ||
395 | #define get_scsi(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_scsi) | ||
396 | #define local_checking_phase_flag(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_local_checking_phase_flag) | ||
397 | #define got_interrupt(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_got_interrupt) | ||
398 | #define stat_result(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_stat_result) | ||
399 | #define reset_status(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_reset_status) | ||
400 | #define last_scsi_command(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_command) | ||
401 | #define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type) | ||
402 | #define last_scsi_blockcount(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_blockcount) | ||
403 | #define last_scsi_logical_block(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_logical_block) | ||
404 | #define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type) | ||
405 | #define next_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_next_ldn) | ||
406 | #define IBM_DS(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_IBM_DS) | ||
407 | #define special(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_special) | ||
408 | #define subsystem_connector_size(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_connector_size) | ||
409 | #define adapter_speed(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_adapter_speed) | ||
410 | #define pos2(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[2]) | ||
411 | #define pos3(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[3]) | ||
412 | #define pos4(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[4]) | ||
413 | #define pos5(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[5]) | ||
414 | #define pos6(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[6]) | ||
415 | |||
416 | /* Define a arbitrary number as subsystem-marker-type. This number is, as | ||
417 | described in the ANSI-SCSI-standard, not occupied by other device-types. */ | ||
418 | #define TYPE_IBM_SCSI_ADAPTER 0x2F | ||
419 | |||
420 | /* Define 0xFF for no device type, because this type is not defined within | ||
421 | the ANSI-SCSI-standard, therefore, it can be used and should not cause any | ||
422 | harm. */ | ||
423 | #define TYPE_NO_DEVICE 0xFF | ||
424 | |||
425 | /* define medium-changer. If this is not defined previously, e.g. Linux | ||
426 | 2.0.x, define this type here. */ | ||
427 | #ifndef TYPE_MEDIUM_CHANGER | ||
428 | #define TYPE_MEDIUM_CHANGER 0x08 | ||
429 | #endif | ||
430 | |||
431 | /* define possible operations for the immediate_assign command */ | ||
432 | #define SET_LDN 0 | ||
433 | #define REMOVE_LDN 1 | ||
434 | |||
435 | /* ldn which is used to probe the SCSI devices */ | ||
436 | #define PROBE_LDN 0 | ||
437 | |||
438 | /* reset status flag contents */ | ||
439 | #define IM_RESET_NOT_IN_PROGRESS 0 | ||
440 | #define IM_RESET_IN_PROGRESS 1 | ||
441 | #define IM_RESET_FINISHED_OK 2 | ||
442 | #define IM_RESET_FINISHED_FAIL 3 | ||
443 | #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4 | ||
444 | #define IM_RESET_FINISHED_OK_NO_INT 5 | ||
445 | |||
446 | /* define undefined SCSI-command */ | ||
447 | #define NO_SCSI 0xffff | ||
448 | |||
449 | /*-----------------------------------------------------------------------*/ | ||
450 | |||
451 | /* if this is nonzero, ibmmcascsi option has been passed to the kernel */ | ||
452 | static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
453 | static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 }; | ||
454 | |||
455 | /* fill module-parameters only, when this define is present. | ||
456 | (that is kernel version 2.1.x) */ | ||
457 | #if defined(MODULE) | ||
458 | static char *boot_options = NULL; | ||
459 | module_param(boot_options, charp, 0); | ||
460 | module_param_array(io_port, int, NULL, 0); | ||
461 | module_param_array(scsi_id, int, NULL, 0); | ||
462 | |||
463 | MODULE_LICENSE("GPL"); | ||
464 | #endif | ||
465 | /*counter of concurrent disk read/writes, to turn on/off disk led */ | ||
466 | static int disk_rw_in_progress = 0; | ||
467 | |||
468 | static unsigned int pos[8]; /* whole pos register-line for diagnosis */ | ||
469 | /* Taking into account the additions, made by ZP Gu. | ||
470 | * This selects now the preset value from the configfile and | ||
471 | * offers the 'normal' commandline option to be accepted */ | ||
472 | #ifdef CONFIG_IBMMCA_SCSI_ORDER_STANDARD | ||
473 | static char ibm_ansi_order = 1; | ||
474 | #else | ||
475 | static char ibm_ansi_order = 0; | ||
476 | #endif | ||
477 | |||
478 | static void issue_cmd(struct Scsi_Host *, unsigned long, unsigned char); | ||
479 | static void internal_done(Scsi_Cmnd * cmd); | ||
480 | static void check_devices(struct Scsi_Host *, int); | ||
481 | static int immediate_assign(struct Scsi_Host *, unsigned int, unsigned int, unsigned int, unsigned int); | ||
482 | static int immediate_feature(struct Scsi_Host *, unsigned int, unsigned int); | ||
483 | #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET | ||
484 | static int immediate_reset(struct Scsi_Host *, unsigned int); | ||
485 | #endif | ||
486 | static int device_inquiry(struct Scsi_Host *, int); | ||
487 | static int read_capacity(struct Scsi_Host *, int); | ||
488 | static int get_pos_info(struct Scsi_Host *); | ||
489 | static char *ti_p(int); | ||
490 | static char *ti_l(int); | ||
491 | static char *ibmrate(unsigned int, int); | ||
492 | static int probe_display(int); | ||
493 | static int probe_bus_mode(struct Scsi_Host *); | ||
494 | static int device_exists(struct Scsi_Host *, int, int *, int *); | ||
495 | static int option_setup(char *); | ||
496 | /* local functions needed for proc_info */ | ||
497 | static int ldn_access_load(struct Scsi_Host *, int); | ||
498 | static int ldn_access_total_read_write(struct Scsi_Host *); | ||
499 | |||
500 | static irqreturn_t interrupt_handler(int irq, void *dev_id) | ||
501 | { | ||
502 | unsigned int intr_reg; | ||
503 | unsigned int cmd_result; | ||
504 | unsigned int ldn; | ||
505 | unsigned long flags; | ||
506 | Scsi_Cmnd *cmd; | ||
507 | int lastSCSI; | ||
508 | struct device *dev = dev_id; | ||
509 | struct Scsi_Host *shpnt = dev_get_drvdata(dev); | ||
510 | |||
511 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
512 | |||
513 | if(!(inb(IM_STAT_REG(shpnt)) & IM_INTR_REQUEST)) { | ||
514 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
515 | return IRQ_NONE; | ||
516 | } | ||
517 | |||
518 | /* the reset-function already did all the job, even ints got | ||
519 | renabled on the subsystem, so just return */ | ||
520 | if ((reset_status(shpnt) == IM_RESET_NOT_IN_PROGRESS_NO_INT) || (reset_status(shpnt) == IM_RESET_FINISHED_OK_NO_INT)) { | ||
521 | reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS; | ||
522 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
523 | return IRQ_HANDLED; | ||
524 | } | ||
525 | |||
526 | /*must wait for attention reg not busy, then send EOI to subsystem */ | ||
527 | while (1) { | ||
528 | if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY)) | ||
529 | break; | ||
530 | cpu_relax(); | ||
531 | } | ||
532 | |||
533 | /*get command result and logical device */ | ||
534 | intr_reg = (unsigned char) (inb(IM_INTR_REG(shpnt))); | ||
535 | cmd_result = intr_reg & 0xf0; | ||
536 | ldn = intr_reg & 0x0f; | ||
537 | /* get the last_scsi_command here */ | ||
538 | lastSCSI = last_scsi_command(shpnt)[ldn]; | ||
539 | outb(IM_EOI | ldn, IM_ATTN_REG(shpnt)); | ||
540 | |||
541 | /*these should never happen (hw fails, or a local programming bug) */ | ||
542 | if (!global_command_error_excuse) { | ||
543 | switch (cmd_result) { | ||
544 | /* Prevent from Ooopsing on error to show the real reason */ | ||
545 | case IM_ADAPTER_HW_FAILURE: | ||
546 | case IM_SOFTWARE_SEQUENCING_ERROR: | ||
547 | case IM_CMD_ERROR: | ||
548 | printk(KERN_ERR "IBM MCA SCSI: Fatal Subsystem ERROR!\n"); | ||
549 | printk(KERN_ERR " Last cmd=0x%x, ena=%x, len=", lastSCSI, ld(shpnt)[ldn].scb.enable); | ||
550 | if (ld(shpnt)[ldn].cmd) | ||
551 | printk("%ld/%ld,", (long) (scsi_bufflen(ld(shpnt)[ldn].cmd)), (long) (ld(shpnt)[ldn].scb.sys_buf_length)); | ||
552 | else | ||
553 | printk("none,"); | ||
554 | if (ld(shpnt)[ldn].cmd) | ||
555 | printk("Blocksize=%d", ld(shpnt)[ldn].scb.u2.blk.length); | ||
556 | else | ||
557 | printk("Blocksize=none"); | ||
558 | printk(", host=%p, ldn=0x%x\n", shpnt, ldn); | ||
559 | if (ld(shpnt)[ldn].cmd) { | ||
560 | printk(KERN_ERR "Blockcount=%d/%d\n", last_scsi_blockcount(shpnt)[ldn], ld(shpnt)[ldn].scb.u2.blk.count); | ||
561 | printk(KERN_ERR "Logical block=%lx/%lx\n", last_scsi_logical_block(shpnt)[ldn], ld(shpnt)[ldn].scb.u1.log_blk_adr); | ||
562 | } | ||
563 | printk(KERN_ERR "Reason given: %s\n", (cmd_result == IM_ADAPTER_HW_FAILURE) ? "HARDWARE FAILURE" : (cmd_result == IM_SOFTWARE_SEQUENCING_ERROR) ? "SOFTWARE SEQUENCING ERROR" : (cmd_result == IM_CMD_ERROR) ? "COMMAND ERROR" : "UNKNOWN"); | ||
564 | /* if errors appear, enter this section to give detailed info */ | ||
565 | printk(KERN_ERR "IBM MCA SCSI: Subsystem Error-Status follows:\n"); | ||
566 | printk(KERN_ERR " Command Type................: %x\n", last_scsi_type(shpnt)[ldn]); | ||
567 | printk(KERN_ERR " Attention Register..........: %x\n", inb(IM_ATTN_REG(shpnt))); | ||
568 | printk(KERN_ERR " Basic Control Register......: %x\n", inb(IM_CTR_REG(shpnt))); | ||
569 | printk(KERN_ERR " Interrupt Status Register...: %x\n", intr_reg); | ||
570 | printk(KERN_ERR " Basic Status Register.......: %x\n", inb(IM_STAT_REG(shpnt))); | ||
571 | if ((last_scsi_type(shpnt)[ldn] == IM_SCB) || (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB)) { | ||
572 | printk(KERN_ERR " SCB-Command.................: %x\n", ld(shpnt)[ldn].scb.command); | ||
573 | printk(KERN_ERR " SCB-Enable..................: %x\n", ld(shpnt)[ldn].scb.enable); | ||
574 | printk(KERN_ERR " SCB-logical block address...: %lx\n", ld(shpnt)[ldn].scb.u1.log_blk_adr); | ||
575 | printk(KERN_ERR " SCB-system buffer address...: %lx\n", ld(shpnt)[ldn].scb.sys_buf_adr); | ||
576 | printk(KERN_ERR " SCB-system buffer length....: %lx\n", ld(shpnt)[ldn].scb.sys_buf_length); | ||
577 | printk(KERN_ERR " SCB-tsb address.............: %lx\n", ld(shpnt)[ldn].scb.tsb_adr); | ||
578 | printk(KERN_ERR " SCB-Chain address...........: %lx\n", ld(shpnt)[ldn].scb.scb_chain_adr); | ||
579 | printk(KERN_ERR " SCB-block count.............: %x\n", ld(shpnt)[ldn].scb.u2.blk.count); | ||
580 | printk(KERN_ERR " SCB-block length............: %x\n", ld(shpnt)[ldn].scb.u2.blk.length); | ||
581 | } | ||
582 | printk(KERN_ERR " Send this report to the maintainer.\n"); | ||
583 | panic("IBM MCA SCSI: Fatal error message from the subsystem (0x%X,0x%X)!\n", lastSCSI, cmd_result); | ||
584 | break; | ||
585 | } | ||
586 | } else { | ||
587 | /* The command error handling is made silent, but we tell the | ||
588 | * calling function, that there is a reported error from the | ||
589 | * adapter. */ | ||
590 | switch (cmd_result) { | ||
591 | case IM_ADAPTER_HW_FAILURE: | ||
592 | case IM_SOFTWARE_SEQUENCING_ERROR: | ||
593 | case IM_CMD_ERROR: | ||
594 | global_command_error_excuse = CMD_FAIL; | ||
595 | break; | ||
596 | default: | ||
597 | global_command_error_excuse = 0; | ||
598 | break; | ||
599 | } | ||
600 | } | ||
601 | /* if no panic appeared, increase the interrupt-counter */ | ||
602 | IBM_DS(shpnt).total_interrupts++; | ||
603 | /*only for local checking phase */ | ||
604 | if (local_checking_phase_flag(shpnt)) { | ||
605 | stat_result(shpnt) = cmd_result; | ||
606 | got_interrupt(shpnt) = 1; | ||
607 | reset_status(shpnt) = IM_RESET_FINISHED_OK; | ||
608 | last_scsi_command(shpnt)[ldn] = NO_SCSI; | ||
609 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
610 | return IRQ_HANDLED; | ||
611 | } | ||
612 | /* handling of commands coming from upper level of scsi driver */ | ||
613 | if (last_scsi_type(shpnt)[ldn] == IM_IMM_CMD) { | ||
614 | /* verify ldn, and may handle rare reset immediate command */ | ||
615 | if ((reset_status(shpnt) == IM_RESET_IN_PROGRESS) && (last_scsi_command(shpnt)[ldn] == IM_RESET_IMM_CMD)) { | ||
616 | if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) { | ||
617 | disk_rw_in_progress = 0; | ||
618 | PS2_DISK_LED_OFF(); | ||
619 | reset_status(shpnt) = IM_RESET_FINISHED_FAIL; | ||
620 | } else { | ||
621 | /*reset disk led counter, turn off disk led */ | ||
622 | disk_rw_in_progress = 0; | ||
623 | PS2_DISK_LED_OFF(); | ||
624 | reset_status(shpnt) = IM_RESET_FINISHED_OK; | ||
625 | } | ||
626 | stat_result(shpnt) = cmd_result; | ||
627 | last_scsi_command(shpnt)[ldn] = NO_SCSI; | ||
628 | last_scsi_type(shpnt)[ldn] = 0; | ||
629 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
630 | return IRQ_HANDLED; | ||
631 | } else if (last_scsi_command(shpnt)[ldn] == IM_ABORT_IMM_CMD) { | ||
632 | /* react on SCSI abort command */ | ||
633 | #ifdef IM_DEBUG_PROBE | ||
634 | printk("IBM MCA SCSI: Interrupt from SCSI-abort.\n"); | ||
635 | #endif | ||
636 | disk_rw_in_progress = 0; | ||
637 | PS2_DISK_LED_OFF(); | ||
638 | cmd = ld(shpnt)[ldn].cmd; | ||
639 | ld(shpnt)[ldn].cmd = NULL; | ||
640 | if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) | ||
641 | cmd->result = DID_NO_CONNECT << 16; | ||
642 | else | ||
643 | cmd->result = DID_ABORT << 16; | ||
644 | stat_result(shpnt) = cmd_result; | ||
645 | last_scsi_command(shpnt)[ldn] = NO_SCSI; | ||
646 | last_scsi_type(shpnt)[ldn] = 0; | ||
647 | if (cmd->scsi_done) | ||
648 | (cmd->scsi_done) (cmd); /* should be the internal_done */ | ||
649 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
650 | return IRQ_HANDLED; | ||
651 | } else { | ||
652 | disk_rw_in_progress = 0; | ||
653 | PS2_DISK_LED_OFF(); | ||
654 | reset_status(shpnt) = IM_RESET_FINISHED_OK; | ||
655 | stat_result(shpnt) = cmd_result; | ||
656 | last_scsi_command(shpnt)[ldn] = NO_SCSI; | ||
657 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
658 | return IRQ_HANDLED; | ||
659 | } | ||
660 | } | ||
661 | last_scsi_command(shpnt)[ldn] = NO_SCSI; | ||
662 | last_scsi_type(shpnt)[ldn] = 0; | ||
663 | cmd = ld(shpnt)[ldn].cmd; | ||
664 | ld(shpnt)[ldn].cmd = NULL; | ||
665 | #ifdef IM_DEBUG_TIMEOUT | ||
666 | if (cmd) { | ||
667 | if ((cmd->target == TIMEOUT_PUN) && (cmd->device->lun == TIMEOUT_LUN)) { | ||
668 | spin_unlock_irqsave(shpnt->host_lock, flags); | ||
669 | printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", cmd->target, cmd->device->lun); | ||
670 | return IRQ_HANDLED; | ||
671 | } | ||
672 | } | ||
673 | #endif | ||
674 | /*if no command structure, just return, else clear cmd */ | ||
675 | if (!cmd) | ||
676 | { | ||
677 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
678 | return IRQ_HANDLED; | ||
679 | } | ||
680 | |||
681 | #ifdef IM_DEBUG_INT | ||
682 | printk("cmd=%02x ireg=%02x ds=%02x cs=%02x de=%02x ce=%02x\n", cmd->cmnd[0], intr_reg, ld(shpnt)[ldn].tsb.dev_status, ld(shpnt)[ldn].tsb.cmd_status, ld(shpnt)[ldn].tsb.dev_error, ld(shpnt)[ldn].tsb.cmd_error); | ||
683 | #endif | ||
684 | /*if this is end of media read/write, may turn off PS/2 disk led */ | ||
685 | if ((ld(shpnt)[ldn].device_type != TYPE_NO_LUN) && (ld(shpnt)[ldn].device_type != TYPE_NO_DEVICE)) { | ||
686 | /* only access this, if there was a valid device addressed */ | ||
687 | if (--disk_rw_in_progress == 0) | ||
688 | PS2_DISK_LED_OFF(); | ||
689 | } | ||
690 | |||
691 | /* IBM describes the status-mask to be 0x1e, but this is not conform | ||
692 | * with SCSI-definition, I suppose, the reason for it is that IBM | ||
693 | * adapters do not support CMD_TERMINATED, TASK_SET_FULL and | ||
694 | * ACA_ACTIVE as returning statusbyte information. (ML) */ | ||
695 | if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) { | ||
696 | cmd->result = (unsigned char) (ld(shpnt)[ldn].tsb.dev_status & 0x1e); | ||
697 | IBM_DS(shpnt).total_errors++; | ||
698 | } else | ||
699 | cmd->result = 0; | ||
700 | /* write device status into cmd->result, and call done function */ | ||
701 | if (lastSCSI == NO_SCSI) { /* unexpected interrupt :-( */ | ||
702 | cmd->result |= DID_BAD_INTR << 16; | ||
703 | printk("IBM MCA SCSI: WARNING - Interrupt from non-pending SCSI-command!\n"); | ||
704 | } else /* things went right :-) */ | ||
705 | cmd->result |= DID_OK << 16; | ||
706 | if (cmd->scsi_done) | ||
707 | (cmd->scsi_done) (cmd); | ||
708 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
709 | return IRQ_HANDLED; | ||
710 | } | ||
711 | |||
712 | static void issue_cmd(struct Scsi_Host *shpnt, unsigned long cmd_reg, | ||
713 | unsigned char attn_reg) | ||
714 | { | ||
715 | unsigned long flags; | ||
716 | /* must wait for attention reg not busy */ | ||
717 | while (1) { | ||
718 | spin_lock_irqsave(shpnt->host_lock, flags); | ||
719 | if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY)) | ||
720 | break; | ||
721 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
722 | } | ||
723 | /* write registers and enable system interrupts */ | ||
724 | outl(cmd_reg, IM_CMD_REG(shpnt)); | ||
725 | outb(attn_reg, IM_ATTN_REG(shpnt)); | ||
726 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
727 | } | ||
728 | |||
729 | static void internal_done(Scsi_Cmnd * cmd) | ||
730 | { | ||
731 | cmd->SCp.Status++; | ||
732 | return; | ||
733 | } | ||
734 | |||
735 | /* SCSI-SCB-command for device_inquiry */ | ||
736 | static int device_inquiry(struct Scsi_Host *shpnt, int ldn) | ||
737 | { | ||
738 | int retr; | ||
739 | struct im_scb *scb; | ||
740 | struct im_tsb *tsb; | ||
741 | unsigned char *buf; | ||
742 | |||
743 | scb = &(ld(shpnt)[ldn].scb); | ||
744 | tsb = &(ld(shpnt)[ldn].tsb); | ||
745 | buf = (unsigned char *) (&(ld(shpnt)[ldn].buf)); | ||
746 | ld(shpnt)[ldn].tsb.dev_status = 0; /* prepare statusblock */ | ||
747 | for (retr = 0; retr < 3; retr++) { | ||
748 | /* fill scb with inquiry command */ | ||
749 | scb->command = IM_DEVICE_INQUIRY_CMD | IM_NO_DISCONNECT; | ||
750 | scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_RETRY_ENABLE | IM_BYPASS_BUFFER; | ||
751 | last_scsi_command(shpnt)[ldn] = IM_DEVICE_INQUIRY_CMD; | ||
752 | last_scsi_type(shpnt)[ldn] = IM_SCB; | ||
753 | scb->sys_buf_adr = isa_virt_to_bus(buf); | ||
754 | scb->sys_buf_length = 255; /* maximum bufferlength gives max info */ | ||
755 | scb->tsb_adr = isa_virt_to_bus(tsb); | ||
756 | /* issue scb to passed ldn, and busy wait for interrupt */ | ||
757 | got_interrupt(shpnt) = 0; | ||
758 | issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn); | ||
759 | while (!got_interrupt(shpnt)) | ||
760 | barrier(); | ||
761 | |||
762 | /*if command successful, break */ | ||
763 | if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES)) | ||
764 | return 1; | ||
765 | } | ||
766 | /*if all three retries failed, return "no device at this ldn" */ | ||
767 | if (retr >= 3) | ||
768 | return 0; | ||
769 | else | ||
770 | return 1; | ||
771 | } | ||
772 | |||
773 | static int read_capacity(struct Scsi_Host *shpnt, int ldn) | ||
774 | { | ||
775 | int retr; | ||
776 | struct im_scb *scb; | ||
777 | struct im_tsb *tsb; | ||
778 | unsigned char *buf; | ||
779 | |||
780 | scb = &(ld(shpnt)[ldn].scb); | ||
781 | tsb = &(ld(shpnt)[ldn].tsb); | ||
782 | buf = (unsigned char *) (&(ld(shpnt)[ldn].buf)); | ||
783 | ld(shpnt)[ldn].tsb.dev_status = 0; | ||
784 | for (retr = 0; retr < 3; retr++) { | ||
785 | /*fill scb with read capacity command */ | ||
786 | scb->command = IM_READ_CAPACITY_CMD; | ||
787 | scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_RETRY_ENABLE | IM_BYPASS_BUFFER; | ||
788 | last_scsi_command(shpnt)[ldn] = IM_READ_CAPACITY_CMD; | ||
789 | last_scsi_type(shpnt)[ldn] = IM_SCB; | ||
790 | scb->sys_buf_adr = isa_virt_to_bus(buf); | ||
791 | scb->sys_buf_length = 8; | ||
792 | scb->tsb_adr = isa_virt_to_bus(tsb); | ||
793 | /*issue scb to passed ldn, and busy wait for interrupt */ | ||
794 | got_interrupt(shpnt) = 0; | ||
795 | issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn); | ||
796 | while (!got_interrupt(shpnt)) | ||
797 | barrier(); | ||
798 | |||
799 | /*if got capacity, get block length and return one device found */ | ||
800 | if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES)) | ||
801 | return 1; | ||
802 | } | ||
803 | /*if all three retries failed, return "no device at this ldn" */ | ||
804 | if (retr >= 3) | ||
805 | return 0; | ||
806 | else | ||
807 | return 1; | ||
808 | } | ||
809 | |||
810 | static int get_pos_info(struct Scsi_Host *shpnt) | ||
811 | { | ||
812 | int retr; | ||
813 | struct im_scb *scb; | ||
814 | struct im_tsb *tsb; | ||
815 | unsigned char *buf; | ||
816 | |||
817 | scb = &(ld(shpnt)[MAX_LOG_DEV].scb); | ||
818 | tsb = &(ld(shpnt)[MAX_LOG_DEV].tsb); | ||
819 | buf = (unsigned char *) (&(ld(shpnt)[MAX_LOG_DEV].buf)); | ||
820 | ld(shpnt)[MAX_LOG_DEV].tsb.dev_status = 0; | ||
821 | for (retr = 0; retr < 3; retr++) { | ||
822 | /*fill scb with get_pos_info command */ | ||
823 | scb->command = IM_GET_POS_INFO_CMD; | ||
824 | scb->enable = IM_READ_CONTROL | IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE | IM_BYPASS_BUFFER; | ||
825 | last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_GET_POS_INFO_CMD; | ||
826 | last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_SCB; | ||
827 | scb->sys_buf_adr = isa_virt_to_bus(buf); | ||
828 | if (special(shpnt) == IBM_SCSI2_FW) | ||
829 | scb->sys_buf_length = 256; /* get all info from F/W adapter */ | ||
830 | else | ||
831 | scb->sys_buf_length = 18; /* get exactly 18 bytes for other SCSI */ | ||
832 | scb->tsb_adr = isa_virt_to_bus(tsb); | ||
833 | /*issue scb to ldn=15, and busy wait for interrupt */ | ||
834 | got_interrupt(shpnt) = 0; | ||
835 | issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | MAX_LOG_DEV); | ||
836 | |||
837 | /* FIXME: timeout */ | ||
838 | while (!got_interrupt(shpnt)) | ||
839 | barrier(); | ||
840 | |||
841 | /*if got POS-stuff, get block length and return one device found */ | ||
842 | if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES)) | ||
843 | return 1; | ||
844 | } | ||
845 | /* if all three retries failed, return "no device at this ldn" */ | ||
846 | if (retr >= 3) | ||
847 | return 0; | ||
848 | else | ||
849 | return 1; | ||
850 | } | ||
851 | |||
852 | /* SCSI-immediate-command for assign. This functions maps/unmaps specific | ||
853 | ldn-numbers on SCSI (PUN,LUN). It is needed for presetting of the | ||
854 | subsystem and for dynamical remapping od ldns. */ | ||
855 | static int immediate_assign(struct Scsi_Host *shpnt, unsigned int pun, | ||
856 | unsigned int lun, unsigned int ldn, | ||
857 | unsigned int operation) | ||
858 | { | ||
859 | int retr; | ||
860 | unsigned long imm_cmd; | ||
861 | |||
862 | for (retr = 0; retr < 3; retr++) { | ||
863 | /* select mutation level of the SCSI-adapter */ | ||
864 | switch (special(shpnt)) { | ||
865 | case IBM_SCSI2_FW: | ||
866 | imm_cmd = (unsigned long) (IM_ASSIGN_IMM_CMD); | ||
867 | imm_cmd |= (unsigned long) ((lun & 7) << 24); | ||
868 | imm_cmd |= (unsigned long) ((operation & 1) << 23); | ||
869 | imm_cmd |= (unsigned long) ((pun & 7) << 20) | ((pun & 8) << 24); | ||
870 | imm_cmd |= (unsigned long) ((ldn & 15) << 16); | ||
871 | break; | ||
872 | default: | ||
873 | imm_cmd = inl(IM_CMD_REG(shpnt)); | ||
874 | imm_cmd &= (unsigned long) (0xF8000000); /* keep reserved bits */ | ||
875 | imm_cmd |= (unsigned long) (IM_ASSIGN_IMM_CMD); | ||
876 | imm_cmd |= (unsigned long) ((lun & 7) << 24); | ||
877 | imm_cmd |= (unsigned long) ((operation & 1) << 23); | ||
878 | imm_cmd |= (unsigned long) ((pun & 7) << 20); | ||
879 | imm_cmd |= (unsigned long) ((ldn & 15) << 16); | ||
880 | break; | ||
881 | } | ||
882 | last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_ASSIGN_IMM_CMD; | ||
883 | last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD; | ||
884 | got_interrupt(shpnt) = 0; | ||
885 | issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV); | ||
886 | while (!got_interrupt(shpnt)) | ||
887 | barrier(); | ||
888 | |||
889 | /*if command successful, break */ | ||
890 | if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED) | ||
891 | return 1; | ||
892 | } | ||
893 | if (retr >= 3) | ||
894 | return 0; | ||
895 | else | ||
896 | return 1; | ||
897 | } | ||
898 | |||
899 | static int immediate_feature(struct Scsi_Host *shpnt, unsigned int speed, unsigned int timeout) | ||
900 | { | ||
901 | int retr; | ||
902 | unsigned long imm_cmd; | ||
903 | |||
904 | for (retr = 0; retr < 3; retr++) { | ||
905 | /* select mutation level of the SCSI-adapter */ | ||
906 | imm_cmd = IM_FEATURE_CTR_IMM_CMD; | ||
907 | imm_cmd |= (unsigned long) ((speed & 0x7) << 29); | ||
908 | imm_cmd |= (unsigned long) ((timeout & 0x1fff) << 16); | ||
909 | last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_FEATURE_CTR_IMM_CMD; | ||
910 | last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD; | ||
911 | got_interrupt(shpnt) = 0; | ||
912 | /* we need to run into command errors in order to probe for the | ||
913 | * right speed! */ | ||
914 | global_command_error_excuse = 1; | ||
915 | issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV); | ||
916 | |||
917 | /* FIXME: timeout */ | ||
918 | while (!got_interrupt(shpnt)) | ||
919 | barrier(); | ||
920 | if (global_command_error_excuse == CMD_FAIL) { | ||
921 | global_command_error_excuse = 0; | ||
922 | return 2; | ||
923 | } else | ||
924 | global_command_error_excuse = 0; | ||
925 | /*if command successful, break */ | ||
926 | if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED) | ||
927 | return 1; | ||
928 | } | ||
929 | if (retr >= 3) | ||
930 | return 0; | ||
931 | else | ||
932 | return 1; | ||
933 | } | ||
934 | |||
935 | #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET | ||
936 | static int immediate_reset(struct Scsi_Host *shpnt, unsigned int ldn) | ||
937 | { | ||
938 | int retries; | ||
939 | int ticks; | ||
940 | unsigned long imm_command; | ||
941 | |||
942 | for (retries = 0; retries < 3; retries++) { | ||
943 | imm_command = inl(IM_CMD_REG(shpnt)); | ||
944 | imm_command &= (unsigned long) (0xFFFF0000); /* keep reserved bits */ | ||
945 | imm_command |= (unsigned long) (IM_RESET_IMM_CMD); | ||
946 | last_scsi_command(shpnt)[ldn] = IM_RESET_IMM_CMD; | ||
947 | last_scsi_type(shpnt)[ldn] = IM_IMM_CMD; | ||
948 | got_interrupt(shpnt) = 0; | ||
949 | reset_status(shpnt) = IM_RESET_IN_PROGRESS; | ||
950 | issue_cmd(shpnt, (unsigned long) (imm_command), IM_IMM_CMD | ldn); | ||
951 | ticks = IM_RESET_DELAY * HZ; | ||
952 | while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks) { | ||
953 | udelay((1 + 999 / HZ) * 1000); | ||
954 | barrier(); | ||
955 | } | ||
956 | /* if reset did not complete, just complain */ | ||
957 | if (!ticks) { | ||
958 | printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY); | ||
959 | reset_status(shpnt) = IM_RESET_FINISHED_OK; | ||
960 | /* did not work, finish */ | ||
961 | return 1; | ||
962 | } | ||
963 | /*if command successful, break */ | ||
964 | if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED) | ||
965 | return 1; | ||
966 | } | ||
967 | if (retries >= 3) | ||
968 | return 0; | ||
969 | else | ||
970 | return 1; | ||
971 | } | ||
972 | #endif | ||
973 | |||
974 | /* type-interpreter for physical device numbers */ | ||
975 | static char *ti_p(int dev) | ||
976 | { | ||
977 | switch (dev) { | ||
978 | case TYPE_IBM_SCSI_ADAPTER: | ||
979 | return ("A"); | ||
980 | case TYPE_DISK: | ||
981 | return ("D"); | ||
982 | case TYPE_TAPE: | ||
983 | return ("T"); | ||
984 | case TYPE_PROCESSOR: | ||
985 | return ("P"); | ||
986 | case TYPE_WORM: | ||
987 | return ("W"); | ||
988 | case TYPE_ROM: | ||
989 | return ("R"); | ||
990 | case TYPE_SCANNER: | ||
991 | return ("S"); | ||
992 | case TYPE_MOD: | ||
993 | return ("M"); | ||
994 | case TYPE_MEDIUM_CHANGER: | ||
995 | return ("C"); | ||
996 | case TYPE_NO_LUN: | ||
997 | return ("+"); /* show NO_LUN */ | ||
998 | } | ||
999 | return ("-"); /* TYPE_NO_DEVICE and others */ | ||
1000 | } | ||
1001 | |||
1002 | /* interpreter for logical device numbers (ldn) */ | ||
1003 | static char *ti_l(int val) | ||
1004 | { | ||
1005 | const char hex[16] = "0123456789abcdef"; | ||
1006 | static char answer[2]; | ||
1007 | |||
1008 | answer[1] = (char) (0x0); | ||
1009 | if (val <= MAX_LOG_DEV) | ||
1010 | answer[0] = hex[val]; | ||
1011 | else | ||
1012 | answer[0] = '-'; | ||
1013 | return (char *) &answer; | ||
1014 | } | ||
1015 | |||
1016 | /* transfers bitpattern of the feature command to values in MHz */ | ||
1017 | static char *ibmrate(unsigned int speed, int i) | ||
1018 | { | ||
1019 | switch (speed) { | ||
1020 | case 0: | ||
1021 | return i ? "5.00" : "10.00"; | ||
1022 | case 1: | ||
1023 | return i ? "4.00" : "8.00"; | ||
1024 | case 2: | ||
1025 | return i ? "3.33" : "6.66"; | ||
1026 | case 3: | ||
1027 | return i ? "2.86" : "5.00"; | ||
1028 | case 4: | ||
1029 | return i ? "2.50" : "4.00"; | ||
1030 | case 5: | ||
1031 | return i ? "2.22" : "3.10"; | ||
1032 | case 6: | ||
1033 | return i ? "2.00" : "2.50"; | ||
1034 | case 7: | ||
1035 | return i ? "1.82" : "2.00"; | ||
1036 | } | ||
1037 | return "---"; | ||
1038 | } | ||
1039 | |||
1040 | static int probe_display(int what) | ||
1041 | { | ||
1042 | static int rotator = 0; | ||
1043 | const char rotor[] = "|/-\\"; | ||
1044 | |||
1045 | if (!(display_mode & LED_DISP)) | ||
1046 | return 0; | ||
1047 | if (!what) { | ||
1048 | outl(0x20202020, MOD95_LED_PORT); | ||
1049 | outl(0x20202020, MOD95_LED_PORT + 4); | ||
1050 | } else { | ||
1051 | outb('S', MOD95_LED_PORT + 7); | ||
1052 | outb('C', MOD95_LED_PORT + 6); | ||
1053 | outb('S', MOD95_LED_PORT + 5); | ||
1054 | outb('I', MOD95_LED_PORT + 4); | ||
1055 | outb('i', MOD95_LED_PORT + 3); | ||
1056 | outb('n', MOD95_LED_PORT + 2); | ||
1057 | outb('i', MOD95_LED_PORT + 1); | ||
1058 | outb((char) (rotor[rotator]), MOD95_LED_PORT); | ||
1059 | rotator++; | ||
1060 | if (rotator > 3) | ||
1061 | rotator = 0; | ||
1062 | } | ||
1063 | return 0; | ||
1064 | } | ||
1065 | |||
1066 | static int probe_bus_mode(struct Scsi_Host *shpnt) | ||
1067 | { | ||
1068 | struct im_pos_info *info; | ||
1069 | int num_bus = 0; | ||
1070 | int ldn; | ||
1071 | |||
1072 | info = (struct im_pos_info *) (&(ld(shpnt)[MAX_LOG_DEV].buf)); | ||
1073 | if (get_pos_info(shpnt)) { | ||
1074 | if (info->connector_size & 0xf000) | ||
1075 | subsystem_connector_size(shpnt) = 16; | ||
1076 | else | ||
1077 | subsystem_connector_size(shpnt) = 32; | ||
1078 | num_bus |= (info->pos_4b & 8) >> 3; | ||
1079 | for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) { | ||
1080 | if ((special(shpnt) == IBM_SCSI_WCACHE) || (special(shpnt) == IBM_7568_WCACHE)) { | ||
1081 | if (!((info->cache_stat >> ldn) & 1)) | ||
1082 | ld(shpnt)[ldn].cache_flag = 0; | ||
1083 | } | ||
1084 | if (!((info->retry_stat >> ldn) & 1)) | ||
1085 | ld(shpnt)[ldn].retry_flag = 0; | ||
1086 | } | ||
1087 | #ifdef IM_DEBUG_PROBE | ||
1088 | printk("IBM MCA SCSI: SCSI-Cache bits: "); | ||
1089 | for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) { | ||
1090 | printk("%d", ld(shpnt)[ldn].cache_flag); | ||
1091 | } | ||
1092 | printk("\nIBM MCA SCSI: SCSI-Retry bits: "); | ||
1093 | for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) { | ||
1094 | printk("%d", ld(shpnt)[ldn].retry_flag); | ||
1095 | } | ||
1096 | printk("\n"); | ||
1097 | #endif | ||
1098 | } | ||
1099 | return num_bus; | ||
1100 | } | ||
1101 | |||
1102 | /* probing scsi devices */ | ||
1103 | static void check_devices(struct Scsi_Host *shpnt, int adaptertype) | ||
1104 | { | ||
1105 | int id, lun, ldn, ticks; | ||
1106 | int count_devices; /* local counter for connected device */ | ||
1107 | int max_pun; | ||
1108 | int num_bus; | ||
1109 | int speedrun; /* local adapter_speed check variable */ | ||
1110 | |||
1111 | /* assign default values to certain variables */ | ||
1112 | ticks = 0; | ||
1113 | count_devices = 0; | ||
1114 | IBM_DS(shpnt).dyn_flag = 0; /* normally no need for dynamical ldn management */ | ||
1115 | IBM_DS(shpnt).total_errors = 0; /* set errorcounter to 0 */ | ||
1116 | next_ldn(shpnt) = 7; /* next ldn to be assigned is 7, because 0-6 is 'hardwired' */ | ||
1117 | |||
1118 | /* initialize the very important driver-informational arrays/structs */ | ||
1119 | memset(ld(shpnt), 0, sizeof(ld(shpnt))); | ||
1120 | for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) { | ||
1121 | last_scsi_command(shpnt)[ldn] = NO_SCSI; /* emptify last SCSI-command storage */ | ||
1122 | last_scsi_type(shpnt)[ldn] = 0; | ||
1123 | ld(shpnt)[ldn].cache_flag = 1; | ||
1124 | ld(shpnt)[ldn].retry_flag = 1; | ||
1125 | } | ||
1126 | memset(get_ldn(shpnt), TYPE_NO_DEVICE, sizeof(get_ldn(shpnt))); /* this is essential ! */ | ||
1127 | memset(get_scsi(shpnt), TYPE_NO_DEVICE, sizeof(get_scsi(shpnt))); /* this is essential ! */ | ||
1128 | for (lun = 0; lun < 8; lun++) { | ||
1129 | /* mark the adapter at its pun on all luns */ | ||
1130 | get_scsi(shpnt)[subsystem_pun(shpnt)][lun] = TYPE_IBM_SCSI_ADAPTER; | ||
1131 | get_ldn(shpnt)[subsystem_pun(shpnt)][lun] = MAX_LOG_DEV; /* make sure, the subsystem | ||
1132 | ldn is active for all | ||
1133 | luns. */ | ||
1134 | } | ||
1135 | probe_display(0); /* Supercool display usage during SCSI-probing. */ | ||
1136 | /* This makes sense, when booting without any */ | ||
1137 | /* monitor connected on model XX95. */ | ||
1138 | |||
1139 | /* STEP 1: */ | ||
1140 | adapter_speed(shpnt) = global_adapter_speed; | ||
1141 | speedrun = adapter_speed(shpnt); | ||
1142 | while (immediate_feature(shpnt, speedrun, adapter_timeout) == 2) { | ||
1143 | probe_display(1); | ||
1144 | if (speedrun == 7) | ||
1145 | panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n"); | ||
1146 | speedrun++; | ||
1147 | if (speedrun > 7) | ||
1148 | speedrun = 7; | ||
1149 | } | ||
1150 | adapter_speed(shpnt) = speedrun; | ||
1151 | /* Get detailed information about the current adapter, necessary for | ||
1152 | * device operations: */ | ||
1153 | num_bus = probe_bus_mode(shpnt); | ||
1154 | |||
1155 | /* num_bus contains only valid data for the F/W adapter! */ | ||
1156 | if (adaptertype == IBM_SCSI2_FW) { /* F/W SCSI adapter: */ | ||
1157 | /* F/W adapter PUN-space extension evaluation: */ | ||
1158 | if (num_bus) { | ||
1159 | printk(KERN_INFO "IBM MCA SCSI: Separate bus mode (wide-addressing enabled)\n"); | ||
1160 | subsystem_maxid(shpnt) = 16; | ||
1161 | } else { | ||
1162 | printk(KERN_INFO "IBM MCA SCSI: Combined bus mode (wide-addressing disabled)\n"); | ||
1163 | subsystem_maxid(shpnt) = 8; | ||
1164 | } | ||
1165 | printk(KERN_INFO "IBM MCA SCSI: Sync.-Rate (F/W: 20, Int.: 10, Ext.: %s) MBytes/s\n", ibmrate(speedrun, adaptertype)); | ||
1166 | } else /* all other IBM SCSI adapters: */ | ||
1167 | printk(KERN_INFO "IBM MCA SCSI: Synchronous-SCSI-Transfer-Rate: %s MBytes/s\n", ibmrate(speedrun, adaptertype)); | ||
1168 | |||
1169 | /* assign correct PUN device space */ | ||
1170 | max_pun = subsystem_maxid(shpnt); | ||
1171 | |||
1172 | #ifdef IM_DEBUG_PROBE | ||
1173 | printk("IBM MCA SCSI: Current SCSI-host index: %d\n", shpnt); | ||
1174 | printk("IBM MCA SCSI: Removing default logical SCSI-device mapping."); | ||
1175 | #else | ||
1176 | printk(KERN_INFO "IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", (ibm_ansi_order) ? "ANSI" : "New"); | ||
1177 | #endif | ||
1178 | for (ldn = 0; ldn < MAX_LOG_DEV; ldn++) { | ||
1179 | probe_display(1); | ||
1180 | #ifdef IM_DEBUG_PROBE | ||
1181 | printk("."); | ||
1182 | #endif | ||
1183 | immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN); /* remove ldn (wherever) */ | ||
1184 | } | ||
1185 | lun = 0; /* default lun is 0 */ | ||
1186 | #ifndef IM_DEBUG_PROBE | ||
1187 | printk("cleared,"); | ||
1188 | #endif | ||
1189 | /* STEP 2: */ | ||
1190 | #ifdef IM_DEBUG_PROBE | ||
1191 | printk("\nIBM MCA SCSI: Scanning SCSI-devices."); | ||
1192 | #endif | ||
1193 | for (id = 0; id < max_pun; id++) | ||
1194 | #ifdef CONFIG_SCSI_MULTI_LUN | ||
1195 | for (lun = 0; lun < 8; lun++) | ||
1196 | #endif | ||
1197 | { | ||
1198 | probe_display(1); | ||
1199 | #ifdef IM_DEBUG_PROBE | ||
1200 | printk("."); | ||
1201 | #endif | ||
1202 | if (id != subsystem_pun(shpnt)) { | ||
1203 | /* if pun is not the adapter: */ | ||
1204 | /* set ldn=0 to pun,lun */ | ||
1205 | immediate_assign(shpnt, id, lun, PROBE_LDN, SET_LDN); | ||
1206 | if (device_inquiry(shpnt, PROBE_LDN)) { /* probe device */ | ||
1207 | get_scsi(shpnt)[id][lun] = (unsigned char) (ld(shpnt)[PROBE_LDN].buf[0]); | ||
1208 | /* entry, even for NO_LUN */ | ||
1209 | if (ld(shpnt)[PROBE_LDN].buf[0] != TYPE_NO_LUN) | ||
1210 | count_devices++; /* a existing device is found */ | ||
1211 | } | ||
1212 | /* remove ldn */ | ||
1213 | immediate_assign(shpnt, id, lun, PROBE_LDN, REMOVE_LDN); | ||
1214 | } | ||
1215 | } | ||
1216 | #ifndef IM_DEBUG_PROBE | ||
1217 | printk("scanned,"); | ||
1218 | #endif | ||
1219 | /* STEP 3: */ | ||
1220 | #ifdef IM_DEBUG_PROBE | ||
1221 | printk("\nIBM MCA SCSI: Mapping SCSI-devices."); | ||
1222 | #endif | ||
1223 | ldn = 0; | ||
1224 | lun = 0; | ||
1225 | #ifdef CONFIG_SCSI_MULTI_LUN | ||
1226 | for (lun = 0; lun < 8 && ldn < MAX_LOG_DEV; lun++) | ||
1227 | #endif | ||
1228 | for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) { | ||
1229 | probe_display(1); | ||
1230 | #ifdef IM_DEBUG_PROBE | ||
1231 | printk("."); | ||
1232 | #endif | ||
1233 | if (id != subsystem_pun(shpnt)) { | ||
1234 | if (get_scsi(shpnt)[id][lun] != TYPE_NO_LUN && get_scsi(shpnt)[id][lun] != TYPE_NO_DEVICE) { | ||
1235 | /* Only map if accepted type. Always enter for | ||
1236 | lun == 0 to get no gaps into ldn-mapping for ldn<7. */ | ||
1237 | immediate_assign(shpnt, id, lun, ldn, SET_LDN); | ||
1238 | get_ldn(shpnt)[id][lun] = ldn; /* map ldn */ | ||
1239 | if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) { | ||
1240 | #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET | ||
1241 | printk("resetting device at ldn=%x ... ", ldn); | ||
1242 | immediate_reset(shpnt, ldn); | ||
1243 | #endif | ||
1244 | ldn++; | ||
1245 | } else { | ||
1246 | /* device vanished, probably because we don't know how to | ||
1247 | * handle it or because it has problems */ | ||
1248 | if (lun > 0) { | ||
1249 | /* remove mapping */ | ||
1250 | get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE; | ||
1251 | immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN); | ||
1252 | } else | ||
1253 | ldn++; | ||
1254 | } | ||
1255 | } else if (lun == 0) { | ||
1256 | /* map lun == 0, even if no device exists */ | ||
1257 | immediate_assign(shpnt, id, lun, ldn, SET_LDN); | ||
1258 | get_ldn(shpnt)[id][lun] = ldn; /* map ldn */ | ||
1259 | ldn++; | ||
1260 | } | ||
1261 | } | ||
1262 | } | ||
1263 | /* STEP 4: */ | ||
1264 | |||
1265 | /* map remaining ldns to non-existing devices */ | ||
1266 | for (lun = 1; lun < 8 && ldn < MAX_LOG_DEV; lun++) | ||
1267 | for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) { | ||
1268 | if (get_scsi(shpnt)[id][lun] == TYPE_NO_LUN || get_scsi(shpnt)[id][lun] == TYPE_NO_DEVICE) { | ||
1269 | probe_display(1); | ||
1270 | /* Map remaining ldns only to NON-existing pun,lun | ||
1271 | combinations to make sure an inquiry will fail. | ||
1272 | For MULTI_LUN, it is needed to avoid adapter autonome | ||
1273 | SCSI-remapping. */ | ||
1274 | immediate_assign(shpnt, id, lun, ldn, SET_LDN); | ||
1275 | get_ldn(shpnt)[id][lun] = ldn; | ||
1276 | ldn++; | ||
1277 | } | ||
1278 | } | ||
1279 | #ifndef IM_DEBUG_PROBE | ||
1280 | printk("mapped."); | ||
1281 | #endif | ||
1282 | printk("\n"); | ||
1283 | #ifdef IM_DEBUG_PROBE | ||
1284 | if (ibm_ansi_order) | ||
1285 | printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n"); | ||
1286 | else | ||
1287 | printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n"); | ||
1288 | #endif | ||
1289 | |||
1290 | #ifdef IM_DEBUG_PROBE | ||
1291 | /* Show the physical and logical mapping during boot. */ | ||
1292 | printk("IBM MCA SCSI: Determined SCSI-device-mapping:\n"); | ||
1293 | printk(" Physical SCSI-Device Map Logical SCSI-Device Map\n"); | ||
1294 | printk("ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n"); | ||
1295 | for (id = 0; id < max_pun; id++) { | ||
1296 | printk("%2d ", id); | ||
1297 | for (lun = 0; lun < 8; lun++) | ||
1298 | printk("%2s ", ti_p(get_scsi(shpnt)[id][lun])); | ||
1299 | printk(" %2d ", id); | ||
1300 | for (lun = 0; lun < 8; lun++) | ||
1301 | printk("%2s ", ti_l(get_ldn(shpnt)[id][lun])); | ||
1302 | printk("\n"); | ||
1303 | } | ||
1304 | #endif | ||
1305 | |||
1306 | /* assign total number of found SCSI-devices to the statistics struct */ | ||
1307 | IBM_DS(shpnt).total_scsi_devices = count_devices; | ||
1308 | |||
1309 | /* decide for output in /proc-filesystem, if the configuration of | ||
1310 | SCSI-devices makes dynamical reassignment of devices necessary */ | ||
1311 | if (count_devices >= MAX_LOG_DEV) | ||
1312 | IBM_DS(shpnt).dyn_flag = 1; /* dynamical assignment is necessary */ | ||
1313 | else | ||
1314 | IBM_DS(shpnt).dyn_flag = 0; /* dynamical assignment is not necessary */ | ||
1315 | |||
1316 | /* If no SCSI-devices are assigned, return 1 in order to cause message. */ | ||
1317 | if (ldn == 0) | ||
1318 | printk("IBM MCA SCSI: Warning: No SCSI-devices found/assigned!\n"); | ||
1319 | |||
1320 | /* reset the counters for statistics on the current adapter */ | ||
1321 | IBM_DS(shpnt).scbs = 0; | ||
1322 | IBM_DS(shpnt).long_scbs = 0; | ||
1323 | IBM_DS(shpnt).total_accesses = 0; | ||
1324 | IBM_DS(shpnt).total_interrupts = 0; | ||
1325 | IBM_DS(shpnt).dynamical_assignments = 0; | ||
1326 | memset(IBM_DS(shpnt).ldn_access, 0x0, sizeof(IBM_DS(shpnt).ldn_access)); | ||
1327 | memset(IBM_DS(shpnt).ldn_read_access, 0x0, sizeof(IBM_DS(shpnt).ldn_read_access)); | ||
1328 | memset(IBM_DS(shpnt).ldn_write_access, 0x0, sizeof(IBM_DS(shpnt).ldn_write_access)); | ||
1329 | memset(IBM_DS(shpnt).ldn_inquiry_access, 0x0, sizeof(IBM_DS(shpnt).ldn_inquiry_access)); | ||
1330 | memset(IBM_DS(shpnt).ldn_modeselect_access, 0x0, sizeof(IBM_DS(shpnt).ldn_modeselect_access)); | ||
1331 | memset(IBM_DS(shpnt).ldn_assignments, 0x0, sizeof(IBM_DS(shpnt).ldn_assignments)); | ||
1332 | probe_display(0); | ||
1333 | return; | ||
1334 | } | ||
1335 | |||
1336 | static int device_exists(struct Scsi_Host *shpnt, int ldn, int *block_length, int *device_type) | ||
1337 | { | ||
1338 | unsigned char *buf; | ||
1339 | /* if no valid device found, return immediately with 0 */ | ||
1340 | if (!(device_inquiry(shpnt, ldn))) | ||
1341 | return 0; | ||
1342 | buf = (unsigned char *) (&(ld(shpnt)[ldn].buf)); | ||
1343 | if (*buf == TYPE_ROM) { | ||
1344 | *device_type = TYPE_ROM; | ||
1345 | *block_length = 2048; /* (standard blocksize for yellow-/red-book) */ | ||
1346 | return 1; | ||
1347 | } | ||
1348 | if (*buf == TYPE_WORM) { | ||
1349 | *device_type = TYPE_WORM; | ||
1350 | *block_length = 2048; | ||
1351 | return 1; | ||
1352 | } | ||
1353 | if (*buf == TYPE_DISK) { | ||
1354 | *device_type = TYPE_DISK; | ||
1355 | if (read_capacity(shpnt, ldn)) { | ||
1356 | *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24); | ||
1357 | return 1; | ||
1358 | } else | ||
1359 | return 0; | ||
1360 | } | ||
1361 | if (*buf == TYPE_MOD) { | ||
1362 | *device_type = TYPE_MOD; | ||
1363 | if (read_capacity(shpnt, ldn)) { | ||
1364 | *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24); | ||
1365 | return 1; | ||
1366 | } else | ||
1367 | return 0; | ||
1368 | } | ||
1369 | if (*buf == TYPE_TAPE) { | ||
1370 | *device_type = TYPE_TAPE; | ||
1371 | *block_length = 0; /* not in use (setting by mt and mtst in op.) */ | ||
1372 | return 1; | ||
1373 | } | ||
1374 | if (*buf == TYPE_PROCESSOR) { | ||
1375 | *device_type = TYPE_PROCESSOR; | ||
1376 | *block_length = 0; /* they set their stuff on drivers */ | ||
1377 | return 1; | ||
1378 | } | ||
1379 | if (*buf == TYPE_SCANNER) { | ||
1380 | *device_type = TYPE_SCANNER; | ||
1381 | *block_length = 0; /* they set their stuff on drivers */ | ||
1382 | return 1; | ||
1383 | } | ||
1384 | if (*buf == TYPE_MEDIUM_CHANGER) { | ||
1385 | *device_type = TYPE_MEDIUM_CHANGER; | ||
1386 | *block_length = 0; /* One never knows, what to expect on a medium | ||
1387 | changer device. */ | ||
1388 | return 1; | ||
1389 | } | ||
1390 | return 0; | ||
1391 | } | ||
1392 | |||
1393 | static void internal_ibmmca_scsi_setup(char *str, int *ints) | ||
1394 | { | ||
1395 | int i, j, io_base, id_base; | ||
1396 | char *token; | ||
1397 | |||
1398 | io_base = 0; | ||
1399 | id_base = 0; | ||
1400 | if (str) { | ||
1401 | j = 0; | ||
1402 | while ((token = strsep(&str, ",")) != NULL) { | ||
1403 | if (!strcmp(token, "activity")) | ||
1404 | display_mode |= LED_ACTIVITY; | ||
1405 | if (!strcmp(token, "display")) | ||
1406 | display_mode |= LED_DISP; | ||
1407 | if (!strcmp(token, "adisplay")) | ||
1408 | display_mode |= LED_ADISP; | ||
1409 | if (!strcmp(token, "normal")) | ||
1410 | ibm_ansi_order = 0; | ||
1411 | if (!strcmp(token, "ansi")) | ||
1412 | ibm_ansi_order = 1; | ||
1413 | if (!strcmp(token, "fast")) | ||
1414 | global_adapter_speed = 0; | ||
1415 | if (!strcmp(token, "medium")) | ||
1416 | global_adapter_speed = 4; | ||
1417 | if (!strcmp(token, "slow")) | ||
1418 | global_adapter_speed = 7; | ||
1419 | if ((*token == '-') || (isdigit(*token))) { | ||
1420 | if (!(j % 2) && (io_base < IM_MAX_HOSTS)) | ||
1421 | io_port[io_base++] = simple_strtoul(token, NULL, 0); | ||
1422 | if ((j % 2) && (id_base < IM_MAX_HOSTS)) | ||
1423 | scsi_id[id_base++] = simple_strtoul(token, NULL, 0); | ||
1424 | j++; | ||
1425 | } | ||
1426 | } | ||
1427 | } else if (ints) { | ||
1428 | for (i = 0; i < IM_MAX_HOSTS && 2 * i + 2 < ints[0]; i++) { | ||
1429 | io_port[i] = ints[2 * i + 2]; | ||
1430 | scsi_id[i] = ints[2 * i + 2]; | ||
1431 | } | ||
1432 | } | ||
1433 | return; | ||
1434 | } | ||
1435 | |||
1436 | #if 0 | ||
1437 | FIXME NEED TO MOVE TO SYSFS | ||
1438 | |||
1439 | static int ibmmca_getinfo(char *buf, int slot, void *dev_id) | ||
1440 | { | ||
1441 | struct Scsi_Host *shpnt; | ||
1442 | int len, speciale, connectore, k; | ||
1443 | unsigned int pos[8]; | ||
1444 | unsigned long flags; | ||
1445 | struct Scsi_Host *dev = dev_id; | ||
1446 | |||
1447 | spin_lock_irqsave(dev->host_lock, flags); | ||
1448 | |||
1449 | shpnt = dev; /* assign host-structure to local pointer */ | ||
1450 | len = 0; /* set filled text-buffer index to 0 */ | ||
1451 | /* get the _special contents of the hostdata structure */ | ||
1452 | speciale = ((struct ibmmca_hostdata *) shpnt->hostdata)->_special; | ||
1453 | connectore = ((struct ibmmca_hostdata *) shpnt->hostdata)->_connector_size; | ||
1454 | for (k = 2; k < 4; k++) | ||
1455 | pos[k] = ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k]; | ||
1456 | if (speciale == FORCED_DETECTION) { /* forced detection */ | ||
1457 | len += sprintf(buf + len, | ||
1458 | "Adapter category: forced detected\n" "***************************************\n" "*** Forced detected SCSI Adapter ***\n" "*** No chip-information available ***\n" "***************************************\n"); | ||
1459 | } else if (speciale == INTEGRATED_SCSI) { | ||
1460 | /* if the integrated subsystem has been found automatically: */ | ||
1461 | len += sprintf(buf + len, | ||
1462 | "Adapter category: integrated\n" "Chip revision level: %d\n" "Chip status: %s\n" "8 kByte NVRAM status: %s\n", ((pos[2] & 0xf0) >> 4), (pos[2] & 1) ? "enabled" : "disabled", (pos[2] & 2) ? "locked" : "accessible"); | ||
1463 | } else if ((speciale >= 0) && (speciale < ARRAY_SIZE(subsys_list))) { | ||
1464 | /* if the subsystem is a slot adapter */ | ||
1465 | len += sprintf(buf + len, "Adapter category: slot-card\n" "ROM Segment Address: "); | ||
1466 | if ((pos[2] & 0xf0) == 0xf0) | ||
1467 | len += sprintf(buf + len, "off\n"); | ||
1468 | else | ||
1469 | len += sprintf(buf + len, "0x%x\n", ((pos[2] & 0xf0) << 13) + 0xc0000); | ||
1470 | len += sprintf(buf + len, "Chip status: %s\n", (pos[2] & 1) ? "enabled" : "disabled"); | ||
1471 | len += sprintf(buf + len, "Adapter I/O Offset: 0x%x\n", ((pos[2] & 0x0e) << 2)); | ||
1472 | } else { | ||
1473 | len += sprintf(buf + len, "Adapter category: unknown\n"); | ||
1474 | } | ||
1475 | /* common subsystem information to write to the slotn file */ | ||
1476 | len += sprintf(buf + len, "Subsystem PUN: %d\n", shpnt->this_id); | ||
1477 | len += sprintf(buf + len, "I/O base address range: 0x%x-0x%x\n", (unsigned int) (shpnt->io_port), (unsigned int) (shpnt->io_port + 7)); | ||
1478 | len += sprintf(buf + len, "MCA-slot size: %d bits", connectore); | ||
1479 | /* Now make sure, the bufferlength is devidable by 4 to avoid | ||
1480 | * paging problems of the buffer. */ | ||
1481 | while (len % sizeof(int) != (sizeof(int) - 1)) | ||
1482 | len += sprintf(buf + len, " "); | ||
1483 | len += sprintf(buf + len, "\n"); | ||
1484 | |||
1485 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
1486 | |||
1487 | return len; | ||
1488 | } | ||
1489 | #endif | ||
1490 | |||
1491 | static struct scsi_host_template ibmmca_driver_template = { | ||
1492 | .proc_name = "ibmmca", | ||
1493 | .proc_info = ibmmca_proc_info, | ||
1494 | .name = "IBM SCSI-Subsystem", | ||
1495 | .queuecommand = ibmmca_queuecommand, | ||
1496 | .eh_abort_handler = ibmmca_abort, | ||
1497 | .eh_host_reset_handler = ibmmca_host_reset, | ||
1498 | .bios_param = ibmmca_biosparam, | ||
1499 | .can_queue = 16, | ||
1500 | .this_id = 7, | ||
1501 | .sg_tablesize = 16, | ||
1502 | .cmd_per_lun = 1, | ||
1503 | .use_clustering = ENABLE_CLUSTERING, | ||
1504 | }; | ||
1505 | |||
1506 | static int ibmmca_probe(struct device *dev) | ||
1507 | { | ||
1508 | struct Scsi_Host *shpnt; | ||
1509 | int port, id, i, j, k, irq, enabled, ret = -EINVAL; | ||
1510 | struct mca_device *mca_dev = to_mca_device(dev); | ||
1511 | const char *description = ibmmca_description[mca_dev->index]; | ||
1512 | |||
1513 | /* First of all, print the version number of the driver. This is | ||
1514 | * important to allow better user bugreports in case of already | ||
1515 | * having problems with the MCA_bus probing. */ | ||
1516 | printk(KERN_INFO "IBM MCA SCSI: Version %s\n", IBMMCA_SCSI_DRIVER_VERSION); | ||
1517 | /* The POS2-register of all PS/2 model SCSI-subsystems has the following | ||
1518 | * interpretation of bits: | ||
1519 | * Bit 7 - 4 : Chip Revision ID (Release) | ||
1520 | * Bit 3 - 2 : Reserved | ||
1521 | * Bit 1 : 8k NVRAM Disabled | ||
1522 | * Bit 0 : Chip Enable (EN-Signal) | ||
1523 | * The POS3-register is interpreted as follows: | ||
1524 | * Bit 7 - 5 : SCSI ID | ||
1525 | * Bit 4 : Reserved = 0 | ||
1526 | * Bit 3 - 0 : Reserved = 0 | ||
1527 | * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common | ||
1528 | * Interfaces (1991)"). | ||
1529 | * In short words, this means, that IBM PS/2 machines only support | ||
1530 | * 1 single subsystem by default. The slot-adapters must have another | ||
1531 | * configuration on pos2. Here, one has to assume the following | ||
1532 | * things for POS2-register: | ||
1533 | * Bit 7 - 4 : Chip Revision ID (Release) | ||
1534 | * Bit 3 - 1 : port offset factor | ||
1535 | * Bit 0 : Chip Enable (EN-Signal) | ||
1536 | * As I found a patch here, setting the IO-registers to 0x3540 forced, | ||
1537 | * as there was a 0x05 in POS2 on a model 56, I assume, that the | ||
1538 | * port 0x3540 must be fix for integrated SCSI-controllers. | ||
1539 | * Ok, this discovery leads to the following implementation: (M.Lang) */ | ||
1540 | |||
1541 | /* first look for the IBM SCSI integrated subsystem on the motherboard */ | ||
1542 | for (j = 0; j < 8; j++) /* read the pos-information */ | ||
1543 | pos[j] = mca_device_read_pos(mca_dev, j); | ||
1544 | id = (pos[3] & 0xe0) >> 5; /* this is correct and represents the PUN */ | ||
1545 | enabled = (pos[2] &0x01); | ||
1546 | if (!enabled) { | ||
1547 | printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n"); | ||
1548 | printk(KERN_WARNING " SCSI-operations may not work.\n"); | ||
1549 | } | ||
1550 | |||
1551 | /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but | ||
1552 | * if we ignore the settings of all surrounding pos registers, it is not | ||
1553 | * completely sufficient to only check pos2 and pos3. */ | ||
1554 | /* Therefore, now the following if statement is used to | ||
1555 | * make sure, we see a real integrated onboard SCSI-interface and no | ||
1556 | * internal system information, which gets mapped to some pos registers | ||
1557 | * on models 95xx. */ | ||
1558 | if (mca_dev->slot == MCA_INTEGSCSI && | ||
1559 | ((!pos[0] && !pos[1] && pos[2] > 0 && | ||
1560 | pos[3] > 0 && !pos[4] && !pos[5] && | ||
1561 | !pos[6] && !pos[7]) || | ||
1562 | (pos[0] == 0xff && pos[1] == 0xff && | ||
1563 | pos[2] < 0xff && pos[3] < 0xff && | ||
1564 | pos[4] == 0xff && pos[5] == 0xff && | ||
1565 | pos[6] == 0xff && pos[7] == 0xff))) { | ||
1566 | irq = IM_IRQ; | ||
1567 | port = IM_IO_PORT; | ||
1568 | } else { | ||
1569 | irq = IM_IRQ; | ||
1570 | port = IM_IO_PORT + ((pos[2] &0x0e) << 2); | ||
1571 | if ((mca_dev->index == IBM_SCSI2_FW) && (pos[6] != 0)) { | ||
1572 | printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n"); | ||
1573 | printk(KERN_ERR " Impossible to determine adapter PUN!\n"); | ||
1574 | printk(KERN_ERR " Guessing adapter PUN = 7.\n"); | ||
1575 | id = 7; | ||
1576 | } else { | ||
1577 | id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */ | ||
1578 | if (mca_dev->index == IBM_SCSI2_FW) { | ||
1579 | id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit | ||
1580 | * for F/W adapters */ | ||
1581 | } | ||
1582 | } | ||
1583 | if ((mca_dev->index == IBM_SCSI2_FW) && | ||
1584 | (pos[4] & 0x01) && (pos[6] == 0)) { | ||
1585 | /* IRQ11 is used by SCSI-2 F/W Adapter/A */ | ||
1586 | printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n"); | ||
1587 | irq = IM_IRQ_FW; | ||
1588 | } | ||
1589 | } | ||
1590 | |||
1591 | |||
1592 | |||
1593 | /* give detailed information on the subsystem. This helps me | ||
1594 | * additionally during debugging and analyzing bug-reports. */ | ||
1595 | printk(KERN_INFO "IBM MCA SCSI: %s found, io=0x%x, scsi id=%d,\n", | ||
1596 | description, port, id); | ||
1597 | if (mca_dev->slot == MCA_INTEGSCSI) | ||
1598 | printk(KERN_INFO " chip rev.=%d, 8K NVRAM=%s, subsystem=%s\n", ((pos[2] & 0xf0) >> 4), (pos[2] & 2) ? "locked" : "accessible", (pos[2] & 1) ? "enabled." : "disabled."); | ||
1599 | else { | ||
1600 | if ((pos[2] & 0xf0) == 0xf0) | ||
1601 | printk(KERN_DEBUG " ROM Addr.=off,"); | ||
1602 | else | ||
1603 | printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000); | ||
1604 | |||
1605 | printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled."); | ||
1606 | } | ||
1607 | |||
1608 | /* check I/O region */ | ||
1609 | if (!request_region(port, IM_N_IO_PORT, description)) { | ||
1610 | printk(KERN_ERR "IBM MCA SCSI: Unable to get I/O region 0x%x-0x%x (%d ports).\n", port, port + IM_N_IO_PORT - 1, IM_N_IO_PORT); | ||
1611 | goto out_fail; | ||
1612 | } | ||
1613 | |||
1614 | /* register host */ | ||
1615 | shpnt = scsi_host_alloc(&ibmmca_driver_template, | ||
1616 | sizeof(struct ibmmca_hostdata)); | ||
1617 | if (!shpnt) { | ||
1618 | printk(KERN_ERR "IBM MCA SCSI: Unable to register host.\n"); | ||
1619 | goto out_release; | ||
1620 | } | ||
1621 | |||
1622 | dev_set_drvdata(dev, shpnt); | ||
1623 | if(request_irq(irq, interrupt_handler, IRQF_SHARED, description, dev)) { | ||
1624 | printk(KERN_ERR "IBM MCA SCSI: failed to request interrupt %d\n", irq); | ||
1625 | goto out_free_host; | ||
1626 | } | ||
1627 | |||
1628 | /* request I/O region */ | ||
1629 | special(shpnt) = mca_dev->index; /* important assignment or else crash! */ | ||
1630 | subsystem_connector_size(shpnt) = 0; /* preset slot-size */ | ||
1631 | shpnt->irq = irq; /* assign necessary stuff for the adapter */ | ||
1632 | shpnt->io_port = port; | ||
1633 | shpnt->n_io_port = IM_N_IO_PORT; | ||
1634 | shpnt->this_id = id; | ||
1635 | shpnt->max_id = 8; /* 8 PUNs are default */ | ||
1636 | /* now, the SCSI-subsystem is connected to Linux */ | ||
1637 | |||
1638 | #ifdef IM_DEBUG_PROBE | ||
1639 | ctrl = (unsigned int) (inb(IM_CTR_REG(found))); /* get control-register status */ | ||
1640 | printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", ctrl, inb(IM_STAT_REG(found))); | ||
1641 | printk("IBM MCA SCSI: This adapters' POS-registers: "); | ||
1642 | for (i = 0; i < 8; i++) | ||
1643 | printk("%x ", pos[i]); | ||
1644 | printk("\n"); | ||
1645 | #endif | ||
1646 | reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS; | ||
1647 | |||
1648 | for (i = 0; i < 16; i++) /* reset the tables */ | ||
1649 | for (j = 0; j < 8; j++) | ||
1650 | get_ldn(shpnt)[i][j] = MAX_LOG_DEV; | ||
1651 | |||
1652 | /* check which logical devices exist */ | ||
1653 | /* after this line, local interrupting is possible: */ | ||
1654 | local_checking_phase_flag(shpnt) = 1; | ||
1655 | check_devices(shpnt, mca_dev->index); /* call by value, using the global variable hosts */ | ||
1656 | local_checking_phase_flag(shpnt) = 0; | ||
1657 | |||
1658 | /* an ibm mca subsystem has been detected */ | ||
1659 | |||
1660 | for (k = 2; k < 7; k++) | ||
1661 | ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k]; | ||
1662 | ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = INTEGRATED_SCSI; | ||
1663 | mca_device_set_name(mca_dev, description); | ||
1664 | /* FIXME: NEED TO REPLUMB TO SYSFS | ||
1665 | mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt); | ||
1666 | */ | ||
1667 | mca_device_set_claim(mca_dev, 1); | ||
1668 | if (scsi_add_host(shpnt, dev)) { | ||
1669 | dev_printk(KERN_ERR, dev, "IBM MCA SCSI: scsi_add_host failed\n"); | ||
1670 | goto out_free_host; | ||
1671 | } | ||
1672 | scsi_scan_host(shpnt); | ||
1673 | |||
1674 | return 0; | ||
1675 | out_free_host: | ||
1676 | scsi_host_put(shpnt); | ||
1677 | out_release: | ||
1678 | release_region(port, IM_N_IO_PORT); | ||
1679 | out_fail: | ||
1680 | return ret; | ||
1681 | } | ||
1682 | |||
1683 | static int __devexit ibmmca_remove(struct device *dev) | ||
1684 | { | ||
1685 | struct Scsi_Host *shpnt = dev_get_drvdata(dev); | ||
1686 | scsi_remove_host(shpnt); | ||
1687 | release_region(shpnt->io_port, shpnt->n_io_port); | ||
1688 | free_irq(shpnt->irq, dev); | ||
1689 | scsi_host_put(shpnt); | ||
1690 | return 0; | ||
1691 | } | ||
1692 | |||
1693 | /* The following routine is the SCSI command queue for the midlevel driver */ | ||
1694 | static int ibmmca_queuecommand_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) | ||
1695 | { | ||
1696 | unsigned int ldn; | ||
1697 | unsigned int scsi_cmd; | ||
1698 | struct im_scb *scb; | ||
1699 | struct Scsi_Host *shpnt; | ||
1700 | int current_ldn; | ||
1701 | int id, lun; | ||
1702 | int target; | ||
1703 | int max_pun; | ||
1704 | int i; | ||
1705 | struct scatterlist *sg; | ||
1706 | |||
1707 | shpnt = cmd->device->host; | ||
1708 | |||
1709 | max_pun = subsystem_maxid(shpnt); | ||
1710 | if (ibm_ansi_order) { | ||
1711 | target = max_pun - 1 - cmd->device->id; | ||
1712 | if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt))) | ||
1713 | target--; | ||
1714 | else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt))) | ||
1715 | target++; | ||
1716 | } else | ||
1717 | target = cmd->device->id; | ||
1718 | |||
1719 | /* if (target,lun) is NO LUN or not existing at all, return error */ | ||
1720 | if ((get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_LUN) || (get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_DEVICE)) { | ||
1721 | cmd->result = DID_NO_CONNECT << 16; | ||
1722 | if (done) | ||
1723 | done(cmd); | ||
1724 | return 0; | ||
1725 | } | ||
1726 | |||
1727 | /*if (target,lun) unassigned, do further checks... */ | ||
1728 | ldn = get_ldn(shpnt)[target][cmd->device->lun]; | ||
1729 | if (ldn >= MAX_LOG_DEV) { /* on invalid ldn do special stuff */ | ||
1730 | if (ldn > MAX_LOG_DEV) { /* dynamical remapping if ldn unassigned */ | ||
1731 | current_ldn = next_ldn(shpnt); /* stop-value for one circle */ | ||
1732 | while (ld(shpnt)[next_ldn(shpnt)].cmd) { /* search for a occupied, but not in */ | ||
1733 | /* command-processing ldn. */ | ||
1734 | next_ldn(shpnt)++; | ||
1735 | if (next_ldn(shpnt) >= MAX_LOG_DEV) | ||
1736 | next_ldn(shpnt) = 7; | ||
1737 | if (current_ldn == next_ldn(shpnt)) { /* One circle done ? */ | ||
1738 | /* no non-processing ldn found */ | ||
1739 | scmd_printk(KERN_WARNING, cmd, | ||
1740 | "IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n" | ||
1741 | " On ldn 7-14 SCSI-commands everywhere in progress.\n" | ||
1742 | " Reporting DID_NO_CONNECT for device.\n"); | ||
1743 | cmd->result = DID_NO_CONNECT << 16; /* return no connect */ | ||
1744 | if (done) | ||
1745 | done(cmd); | ||
1746 | return 0; | ||
1747 | } | ||
1748 | } | ||
1749 | |||
1750 | /* unmap non-processing ldn */ | ||
1751 | for (id = 0; id < max_pun; id++) | ||
1752 | for (lun = 0; lun < 8; lun++) { | ||
1753 | if (get_ldn(shpnt)[id][lun] == next_ldn(shpnt)) { | ||
1754 | get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE; | ||
1755 | get_scsi(shpnt)[id][lun] = TYPE_NO_DEVICE; | ||
1756 | /* unmap entry */ | ||
1757 | } | ||
1758 | } | ||
1759 | /* set reduced interrupt_handler-mode for checking */ | ||
1760 | local_checking_phase_flag(shpnt) = 1; | ||
1761 | /* map found ldn to pun,lun */ | ||
1762 | get_ldn(shpnt)[target][cmd->device->lun] = next_ldn(shpnt); | ||
1763 | /* change ldn to the right value, that is now next_ldn */ | ||
1764 | ldn = next_ldn(shpnt); | ||
1765 | /* unassign all ldns (pun,lun,ldn does not matter for remove) */ | ||
1766 | immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN); | ||
1767 | /* set only LDN for remapped device */ | ||
1768 | immediate_assign(shpnt, target, cmd->device->lun, ldn, SET_LDN); | ||
1769 | /* get device information for ld[ldn] */ | ||
1770 | if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) { | ||
1771 | ld(shpnt)[ldn].cmd = NULL; /* To prevent panic set 0, because | ||
1772 | devices that were not assigned, | ||
1773 | should have nothing in progress. */ | ||
1774 | get_scsi(shpnt)[target][cmd->device->lun] = ld(shpnt)[ldn].device_type; | ||
1775 | /* increase assignment counters for statistics in /proc */ | ||
1776 | IBM_DS(shpnt).dynamical_assignments++; | ||
1777 | IBM_DS(shpnt).ldn_assignments[ldn]++; | ||
1778 | } else | ||
1779 | /* panic here, because a device, found at boottime has | ||
1780 | vanished */ | ||
1781 | panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", ldn, target, cmd->device->lun); | ||
1782 | /* unassign again all ldns (pun,lun,ldn does not matter for remove) */ | ||
1783 | immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN); | ||
1784 | /* remap all ldns, as written in the pun/lun table */ | ||
1785 | lun = 0; | ||
1786 | #ifdef CONFIG_SCSI_MULTI_LUN | ||
1787 | for (lun = 0; lun < 8; lun++) | ||
1788 | #endif | ||
1789 | for (id = 0; id < max_pun; id++) { | ||
1790 | if (get_ldn(shpnt)[id][lun] <= MAX_LOG_DEV) | ||
1791 | immediate_assign(shpnt, id, lun, get_ldn(shpnt)[id][lun], SET_LDN); | ||
1792 | } | ||
1793 | /* set back to normal interrupt_handling */ | ||
1794 | local_checking_phase_flag(shpnt) = 0; | ||
1795 | #ifdef IM_DEBUG_PROBE | ||
1796 | /* Information on syslog terminal */ | ||
1797 | printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", ldn, target, cmd->device->lun); | ||
1798 | #endif | ||
1799 | /* increase next_ldn for next dynamical assignment */ | ||
1800 | next_ldn(shpnt)++; | ||
1801 | if (next_ldn(shpnt) >= MAX_LOG_DEV) | ||
1802 | next_ldn(shpnt) = 7; | ||
1803 | } else { /* wall against Linux accesses to the subsystem adapter */ | ||
1804 | cmd->result = DID_BAD_TARGET << 16; | ||
1805 | if (done) | ||
1806 | done(cmd); | ||
1807 | return 0; | ||
1808 | } | ||
1809 | } | ||
1810 | |||
1811 | /*verify there is no command already in progress for this log dev */ | ||
1812 | if (ld(shpnt)[ldn].cmd) | ||
1813 | panic("IBM MCA SCSI: cmd already in progress for this ldn.\n"); | ||
1814 | |||
1815 | /*save done in cmd, and save cmd for the interrupt handler */ | ||
1816 | cmd->scsi_done = done; | ||
1817 | ld(shpnt)[ldn].cmd = cmd; | ||
1818 | |||
1819 | /*fill scb information independent of the scsi command */ | ||
1820 | scb = &(ld(shpnt)[ldn].scb); | ||
1821 | ld(shpnt)[ldn].tsb.dev_status = 0; | ||
1822 | scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE; | ||
1823 | scb->tsb_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].tsb)); | ||
1824 | scsi_cmd = cmd->cmnd[0]; | ||
1825 | |||
1826 | if (scsi_sg_count(cmd)) { | ||
1827 | BUG_ON(scsi_sg_count(cmd) > 16); | ||
1828 | |||
1829 | scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) { | ||
1830 | ld(shpnt)[ldn].sge[i].address = (void *) (isa_page_to_bus(sg_page(sg)) + sg->offset); | ||
1831 | ld(shpnt)[ldn].sge[i].byte_length = sg->length; | ||
1832 | } | ||
1833 | scb->enable |= IM_POINTER_TO_LIST; | ||
1834 | scb->sys_buf_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].sge[0])); | ||
1835 | scb->sys_buf_length = scsi_sg_count(cmd) * sizeof(struct im_sge); | ||
1836 | } else { | ||
1837 | scb->sys_buf_adr = isa_virt_to_bus(scsi_sglist(cmd)); | ||
1838 | /* recent Linux midlevel SCSI places 1024 byte for inquiry | ||
1839 | * command. Far too much for old PS/2 hardware. */ | ||
1840 | switch (scsi_cmd) { | ||
1841 | /* avoid command errors by setting bufferlengths to | ||
1842 | * ANSI-standard. Beware of forcing it to 255, | ||
1843 | * this could SEGV the kernel!!! */ | ||
1844 | case INQUIRY: | ||
1845 | case REQUEST_SENSE: | ||
1846 | case MODE_SENSE: | ||
1847 | case MODE_SELECT: | ||
1848 | if (scsi_bufflen(cmd) > 255) | ||
1849 | scb->sys_buf_length = 255; | ||
1850 | else | ||
1851 | scb->sys_buf_length = scsi_bufflen(cmd); | ||
1852 | break; | ||
1853 | case TEST_UNIT_READY: | ||
1854 | scb->sys_buf_length = 0; | ||
1855 | break; | ||
1856 | default: | ||
1857 | scb->sys_buf_length = scsi_bufflen(cmd); | ||
1858 | break; | ||
1859 | } | ||
1860 | } | ||
1861 | /*fill scb information dependent on scsi command */ | ||
1862 | |||
1863 | #ifdef IM_DEBUG_CMD | ||
1864 | printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd, ldn); | ||
1865 | #endif | ||
1866 | |||
1867 | /* for specific device-type debugging: */ | ||
1868 | #ifdef IM_DEBUG_CMD_SPEC_DEV | ||
1869 | if (ld(shpnt)[ldn].device_type == IM_DEBUG_CMD_DEVICE) | ||
1870 | printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", ld(shpnt)[ldn].device_type, scsi_cmd, ldn); | ||
1871 | #endif | ||
1872 | |||
1873 | /* for possible panics store current command */ | ||
1874 | last_scsi_command(shpnt)[ldn] = scsi_cmd; | ||
1875 | last_scsi_type(shpnt)[ldn] = IM_SCB; | ||
1876 | /* update statistical info */ | ||
1877 | IBM_DS(shpnt).total_accesses++; | ||
1878 | IBM_DS(shpnt).ldn_access[ldn]++; | ||
1879 | |||
1880 | switch (scsi_cmd) { | ||
1881 | case READ_6: | ||
1882 | case WRITE_6: | ||
1883 | case READ_10: | ||
1884 | case WRITE_10: | ||
1885 | case READ_12: | ||
1886 | case WRITE_12: | ||
1887 | /* Distinguish between disk and other devices. Only disks (that are the | ||
1888 | most frequently accessed devices) should be supported by the | ||
1889 | IBM-SCSI-Subsystem commands. */ | ||
1890 | switch (ld(shpnt)[ldn].device_type) { | ||
1891 | case TYPE_DISK: /* for harddisks enter here ... */ | ||
1892 | case TYPE_MOD: /* ... try it also for MO-drives (send flames as */ | ||
1893 | /* you like, if this won't work.) */ | ||
1894 | if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) { | ||
1895 | /* read command preparations */ | ||
1896 | scb->enable |= IM_READ_CONTROL; | ||
1897 | IBM_DS(shpnt).ldn_read_access[ldn]++; /* increase READ-access on ldn stat. */ | ||
1898 | scb->command = IM_READ_DATA_CMD | IM_NO_DISCONNECT; | ||
1899 | } else { /* write command preparations */ | ||
1900 | IBM_DS(shpnt).ldn_write_access[ldn]++; /* increase write-count on ldn stat. */ | ||
1901 | scb->command = IM_WRITE_DATA_CMD | IM_NO_DISCONNECT; | ||
1902 | } | ||
1903 | if (scsi_cmd == READ_6 || scsi_cmd == WRITE_6) { | ||
1904 | scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[3]) << 0) | (((unsigned) cmd->cmnd[2]) << 8) | ((((unsigned) cmd->cmnd[1]) & 0x1f) << 16); | ||
1905 | scb->u2.blk.count = (unsigned) cmd->cmnd[4]; | ||
1906 | } else { | ||
1907 | scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[5]) << 0) | (((unsigned) cmd->cmnd[4]) << 8) | (((unsigned) cmd->cmnd[3]) << 16) | (((unsigned) cmd->cmnd[2]) << 24); | ||
1908 | scb->u2.blk.count = (((unsigned) cmd->cmnd[8]) << 0) | (((unsigned) cmd->cmnd[7]) << 8); | ||
1909 | } | ||
1910 | last_scsi_logical_block(shpnt)[ldn] = scb->u1.log_blk_adr; | ||
1911 | last_scsi_blockcount(shpnt)[ldn] = scb->u2.blk.count; | ||
1912 | scb->u2.blk.length = ld(shpnt)[ldn].block_length; | ||
1913 | break; | ||
1914 | /* for other devices, enter here. Other types are not known by | ||
1915 | Linux! TYPE_NO_LUN is forbidden as valid device. */ | ||
1916 | case TYPE_ROM: | ||
1917 | case TYPE_TAPE: | ||
1918 | case TYPE_PROCESSOR: | ||
1919 | case TYPE_WORM: | ||
1920 | case TYPE_SCANNER: | ||
1921 | case TYPE_MEDIUM_CHANGER: | ||
1922 | /* If there is a sequential-device, IBM recommends to use | ||
1923 | IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE. | ||
1924 | This includes CD-ROM devices, too, due to the partial sequential | ||
1925 | read capabilities. */ | ||
1926 | scb->command = IM_OTHER_SCSI_CMD_CMD; | ||
1927 | if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) | ||
1928 | /* enable READ */ | ||
1929 | scb->enable |= IM_READ_CONTROL; | ||
1930 | scb->enable |= IM_BYPASS_BUFFER; | ||
1931 | scb->u1.scsi_cmd_length = cmd->cmd_len; | ||
1932 | memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len); | ||
1933 | last_scsi_type(shpnt)[ldn] = IM_LONG_SCB; | ||
1934 | /* Read/write on this non-disk devices is also displayworthy, | ||
1935 | so flash-up the LED/display. */ | ||
1936 | break; | ||
1937 | } | ||
1938 | break; | ||
1939 | case INQUIRY: | ||
1940 | IBM_DS(shpnt).ldn_inquiry_access[ldn]++; | ||
1941 | scb->command = IM_DEVICE_INQUIRY_CMD; | ||
1942 | scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; | ||
1943 | scb->u1.log_blk_adr = 0; | ||
1944 | break; | ||
1945 | case TEST_UNIT_READY: | ||
1946 | scb->command = IM_OTHER_SCSI_CMD_CMD; | ||
1947 | scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; | ||
1948 | scb->u1.log_blk_adr = 0; | ||
1949 | scb->u1.scsi_cmd_length = 6; | ||
1950 | memcpy(scb->u2.scsi_command, cmd->cmnd, 6); | ||
1951 | last_scsi_type(shpnt)[ldn] = IM_LONG_SCB; | ||
1952 | break; | ||
1953 | case READ_CAPACITY: | ||
1954 | /* the length of system memory buffer must be exactly 8 bytes */ | ||
1955 | scb->command = IM_READ_CAPACITY_CMD; | ||
1956 | scb->enable |= IM_READ_CONTROL | IM_BYPASS_BUFFER; | ||
1957 | if (scb->sys_buf_length > 8) | ||
1958 | scb->sys_buf_length = 8; | ||
1959 | break; | ||
1960 | /* Commands that need read-only-mode (system <- device): */ | ||
1961 | case REQUEST_SENSE: | ||
1962 | scb->command = IM_REQUEST_SENSE_CMD; | ||
1963 | scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; | ||
1964 | break; | ||
1965 | /* Commands that need write-only-mode (system -> device): */ | ||
1966 | case MODE_SELECT: | ||
1967 | case MODE_SELECT_10: | ||
1968 | IBM_DS(shpnt).ldn_modeselect_access[ldn]++; | ||
1969 | scb->command = IM_OTHER_SCSI_CMD_CMD; | ||
1970 | scb->enable |= IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; /*Select needs WRITE-enabled */ | ||
1971 | scb->u1.scsi_cmd_length = cmd->cmd_len; | ||
1972 | memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len); | ||
1973 | last_scsi_type(shpnt)[ldn] = IM_LONG_SCB; | ||
1974 | break; | ||
1975 | /* For other commands, read-only is useful. Most other commands are | ||
1976 | running without an input-data-block. */ | ||
1977 | default: | ||
1978 | scb->command = IM_OTHER_SCSI_CMD_CMD; | ||
1979 | scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; | ||
1980 | scb->u1.scsi_cmd_length = cmd->cmd_len; | ||
1981 | memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len); | ||
1982 | last_scsi_type(shpnt)[ldn] = IM_LONG_SCB; | ||
1983 | break; | ||
1984 | } | ||
1985 | /*issue scb command, and return */ | ||
1986 | if (++disk_rw_in_progress == 1) | ||
1987 | PS2_DISK_LED_ON(shpnt->host_no, target); | ||
1988 | |||
1989 | if (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB) { | ||
1990 | issue_cmd(shpnt, isa_virt_to_bus(scb), IM_LONG_SCB | ldn); | ||
1991 | IBM_DS(shpnt).long_scbs++; | ||
1992 | } else { | ||
1993 | issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn); | ||
1994 | IBM_DS(shpnt).scbs++; | ||
1995 | } | ||
1996 | return 0; | ||
1997 | } | ||
1998 | |||
1999 | static DEF_SCSI_QCMD(ibmmca_queuecommand) | ||
2000 | |||
2001 | static int __ibmmca_abort(Scsi_Cmnd * cmd) | ||
2002 | { | ||
2003 | /* Abort does not work, as the adapter never generates an interrupt on | ||
2004 | * whatever situation is simulated, even when really pending commands | ||
2005 | * are running on the adapters' hardware ! */ | ||
2006 | |||
2007 | struct Scsi_Host *shpnt; | ||
2008 | unsigned int ldn; | ||
2009 | void (*saved_done) (Scsi_Cmnd *); | ||
2010 | int target; | ||
2011 | int max_pun; | ||
2012 | unsigned long imm_command; | ||
2013 | |||
2014 | #ifdef IM_DEBUG_PROBE | ||
2015 | printk("IBM MCA SCSI: Abort subroutine called...\n"); | ||
2016 | #endif | ||
2017 | |||
2018 | shpnt = cmd->device->host; | ||
2019 | |||
2020 | max_pun = subsystem_maxid(shpnt); | ||
2021 | if (ibm_ansi_order) { | ||
2022 | target = max_pun - 1 - cmd->device->id; | ||
2023 | if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt))) | ||
2024 | target--; | ||
2025 | else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt))) | ||
2026 | target++; | ||
2027 | } else | ||
2028 | target = cmd->device->id; | ||
2029 | |||
2030 | /* get logical device number, and disable system interrupts */ | ||
2031 | printk(KERN_WARNING "IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", target, cmd->device->lun); | ||
2032 | ldn = get_ldn(shpnt)[target][cmd->device->lun]; | ||
2033 | |||
2034 | /*if cmd for this ldn has already finished, no need to abort */ | ||
2035 | if (!ld(shpnt)[ldn].cmd) { | ||
2036 | return SUCCESS; | ||
2037 | } | ||
2038 | |||
2039 | /* Clear ld.cmd, save done function, install internal done, | ||
2040 | * send abort immediate command (this enables sys. interrupts), | ||
2041 | * and wait until the interrupt arrives. | ||
2042 | */ | ||
2043 | saved_done = cmd->scsi_done; | ||
2044 | cmd->scsi_done = internal_done; | ||
2045 | cmd->SCp.Status = 0; | ||
2046 | last_scsi_command(shpnt)[ldn] = IM_ABORT_IMM_CMD; | ||
2047 | last_scsi_type(shpnt)[ldn] = IM_IMM_CMD; | ||
2048 | imm_command = inl(IM_CMD_REG(shpnt)); | ||
2049 | imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */ | ||
2050 | imm_command |= (unsigned long) (IM_ABORT_IMM_CMD); | ||
2051 | /* must wait for attention reg not busy */ | ||
2052 | /* FIXME - timeout, politeness */ | ||
2053 | while (1) { | ||
2054 | if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY)) | ||
2055 | break; | ||
2056 | } | ||
2057 | /* write registers and enable system interrupts */ | ||
2058 | outl(imm_command, IM_CMD_REG(shpnt)); | ||
2059 | outb(IM_IMM_CMD | ldn, IM_ATTN_REG(shpnt)); | ||
2060 | #ifdef IM_DEBUG_PROBE | ||
2061 | printk("IBM MCA SCSI: Abort queued to adapter...\n"); | ||
2062 | #endif | ||
2063 | spin_unlock_irq(shpnt->host_lock); | ||
2064 | while (!cmd->SCp.Status) | ||
2065 | yield(); | ||
2066 | spin_lock_irq(shpnt->host_lock); | ||
2067 | cmd->scsi_done = saved_done; | ||
2068 | #ifdef IM_DEBUG_PROBE | ||
2069 | printk("IBM MCA SCSI: Abort returned with adapter response...\n"); | ||
2070 | #endif | ||
2071 | |||
2072 | /*if abort went well, call saved done, then return success or error */ | ||
2073 | if (cmd->result == (DID_ABORT << 16)) | ||
2074 | { | ||
2075 | cmd->result |= DID_ABORT << 16; | ||
2076 | if (cmd->scsi_done) | ||
2077 | (cmd->scsi_done) (cmd); | ||
2078 | ld(shpnt)[ldn].cmd = NULL; | ||
2079 | #ifdef IM_DEBUG_PROBE | ||
2080 | printk("IBM MCA SCSI: Abort finished with success.\n"); | ||
2081 | #endif | ||
2082 | return SUCCESS; | ||
2083 | } else { | ||
2084 | cmd->result |= DID_NO_CONNECT << 16; | ||
2085 | if (cmd->scsi_done) | ||
2086 | (cmd->scsi_done) (cmd); | ||
2087 | ld(shpnt)[ldn].cmd = NULL; | ||
2088 | #ifdef IM_DEBUG_PROBE | ||
2089 | printk("IBM MCA SCSI: Abort failed.\n"); | ||
2090 | #endif | ||
2091 | return FAILED; | ||
2092 | } | ||
2093 | } | ||
2094 | |||
2095 | static int ibmmca_abort(Scsi_Cmnd * cmd) | ||
2096 | { | ||
2097 | struct Scsi_Host *shpnt = cmd->device->host; | ||
2098 | int rc; | ||
2099 | |||
2100 | spin_lock_irq(shpnt->host_lock); | ||
2101 | rc = __ibmmca_abort(cmd); | ||
2102 | spin_unlock_irq(shpnt->host_lock); | ||
2103 | |||
2104 | return rc; | ||
2105 | } | ||
2106 | |||
2107 | static int __ibmmca_host_reset(Scsi_Cmnd * cmd) | ||
2108 | { | ||
2109 | struct Scsi_Host *shpnt; | ||
2110 | Scsi_Cmnd *cmd_aid; | ||
2111 | int ticks, i; | ||
2112 | unsigned long imm_command; | ||
2113 | |||
2114 | BUG_ON(cmd == NULL); | ||
2115 | |||
2116 | ticks = IM_RESET_DELAY * HZ; | ||
2117 | shpnt = cmd->device->host; | ||
2118 | |||
2119 | if (local_checking_phase_flag(shpnt)) { | ||
2120 | printk(KERN_WARNING "IBM MCA SCSI: unable to reset while checking devices.\n"); | ||
2121 | return FAILED; | ||
2122 | } | ||
2123 | |||
2124 | /* issue reset immediate command to subsystem, and wait for interrupt */ | ||
2125 | printk("IBM MCA SCSI: resetting all devices.\n"); | ||
2126 | reset_status(shpnt) = IM_RESET_IN_PROGRESS; | ||
2127 | last_scsi_command(shpnt)[0xf] = IM_RESET_IMM_CMD; | ||
2128 | last_scsi_type(shpnt)[0xf] = IM_IMM_CMD; | ||
2129 | imm_command = inl(IM_CMD_REG(shpnt)); | ||
2130 | imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */ | ||
2131 | imm_command |= (unsigned long) (IM_RESET_IMM_CMD); | ||
2132 | /* must wait for attention reg not busy */ | ||
2133 | while (1) { | ||
2134 | if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY)) | ||
2135 | break; | ||
2136 | spin_unlock_irq(shpnt->host_lock); | ||
2137 | yield(); | ||
2138 | spin_lock_irq(shpnt->host_lock); | ||
2139 | } | ||
2140 | /*write registers and enable system interrupts */ | ||
2141 | outl(imm_command, IM_CMD_REG(shpnt)); | ||
2142 | outb(IM_IMM_CMD | 0xf, IM_ATTN_REG(shpnt)); | ||
2143 | /* wait for interrupt finished or intr_stat register to be set, as the | ||
2144 | * interrupt will not be executed, while we are in here! */ | ||
2145 | |||
2146 | /* FIXME: This is really really icky we so want a sleeping version of this ! */ | ||
2147 | while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks && ((inb(IM_INTR_REG(shpnt)) & 0x8f) != 0x8f)) { | ||
2148 | udelay((1 + 999 / HZ) * 1000); | ||
2149 | barrier(); | ||
2150 | } | ||
2151 | /* if reset did not complete, just return an error */ | ||
2152 | if (!ticks) { | ||
2153 | printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY); | ||
2154 | reset_status(shpnt) = IM_RESET_FINISHED_FAIL; | ||
2155 | return FAILED; | ||
2156 | } | ||
2157 | |||
2158 | if ((inb(IM_INTR_REG(shpnt)) & 0x8f) == 0x8f) { | ||
2159 | /* analysis done by this routine and not by the intr-routine */ | ||
2160 | if (inb(IM_INTR_REG(shpnt)) == 0xaf) | ||
2161 | reset_status(shpnt) = IM_RESET_FINISHED_OK_NO_INT; | ||
2162 | else if (inb(IM_INTR_REG(shpnt)) == 0xcf) | ||
2163 | reset_status(shpnt) = IM_RESET_FINISHED_FAIL; | ||
2164 | else /* failed, 4get it */ | ||
2165 | reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS_NO_INT; | ||
2166 | outb(IM_EOI | 0xf, IM_ATTN_REG(shpnt)); | ||
2167 | } | ||
2168 | |||
2169 | /* if reset failed, just return an error */ | ||
2170 | if (reset_status(shpnt) == IM_RESET_FINISHED_FAIL) { | ||
2171 | printk(KERN_ERR "IBM MCA SCSI: reset failed.\n"); | ||
2172 | return FAILED; | ||
2173 | } | ||
2174 | |||
2175 | /* so reset finished ok - call outstanding done's, and return success */ | ||
2176 | printk(KERN_INFO "IBM MCA SCSI: Reset successfully completed.\n"); | ||
2177 | for (i = 0; i < MAX_LOG_DEV; i++) { | ||
2178 | cmd_aid = ld(shpnt)[i].cmd; | ||
2179 | if (cmd_aid && cmd_aid->scsi_done) { | ||
2180 | ld(shpnt)[i].cmd = NULL; | ||
2181 | cmd_aid->result = DID_RESET << 16; | ||
2182 | } | ||
2183 | } | ||
2184 | return SUCCESS; | ||
2185 | } | ||
2186 | |||
2187 | static int ibmmca_host_reset(Scsi_Cmnd * cmd) | ||
2188 | { | ||
2189 | struct Scsi_Host *shpnt = cmd->device->host; | ||
2190 | int rc; | ||
2191 | |||
2192 | spin_lock_irq(shpnt->host_lock); | ||
2193 | rc = __ibmmca_host_reset(cmd); | ||
2194 | spin_unlock_irq(shpnt->host_lock); | ||
2195 | |||
2196 | return rc; | ||
2197 | } | ||
2198 | |||
2199 | static int ibmmca_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *info) | ||
2200 | { | ||
2201 | int size = capacity; | ||
2202 | info[0] = 64; | ||
2203 | info[1] = 32; | ||
2204 | info[2] = size / (info[0] * info[1]); | ||
2205 | if (info[2] >= 1024) { | ||
2206 | info[0] = 128; | ||
2207 | info[1] = 63; | ||
2208 | info[2] = size / (info[0] * info[1]); | ||
2209 | if (info[2] >= 1024) { | ||
2210 | info[0] = 255; | ||
2211 | info[1] = 63; | ||
2212 | info[2] = size / (info[0] * info[1]); | ||
2213 | if (info[2] >= 1024) | ||
2214 | info[2] = 1023; | ||
2215 | } | ||
2216 | } | ||
2217 | return 0; | ||
2218 | } | ||
2219 | |||
2220 | /* calculate percentage of total accesses on a ldn */ | ||
2221 | static int ldn_access_load(struct Scsi_Host *shpnt, int ldn) | ||
2222 | { | ||
2223 | if (IBM_DS(shpnt).total_accesses == 0) | ||
2224 | return (0); | ||
2225 | if (IBM_DS(shpnt).ldn_access[ldn] == 0) | ||
2226 | return (0); | ||
2227 | return (IBM_DS(shpnt).ldn_access[ldn] * 100) / IBM_DS(shpnt).total_accesses; | ||
2228 | } | ||
2229 | |||
2230 | /* calculate total amount of r/w-accesses */ | ||
2231 | static int ldn_access_total_read_write(struct Scsi_Host *shpnt) | ||
2232 | { | ||
2233 | int a; | ||
2234 | int i; | ||
2235 | |||
2236 | a = 0; | ||
2237 | for (i = 0; i <= MAX_LOG_DEV; i++) | ||
2238 | a += IBM_DS(shpnt).ldn_read_access[i] + IBM_DS(shpnt).ldn_write_access[i]; | ||
2239 | return (a); | ||
2240 | } | ||
2241 | |||
2242 | static int ldn_access_total_inquiry(struct Scsi_Host *shpnt) | ||
2243 | { | ||
2244 | int a; | ||
2245 | int i; | ||
2246 | |||
2247 | a = 0; | ||
2248 | for (i = 0; i <= MAX_LOG_DEV; i++) | ||
2249 | a += IBM_DS(shpnt).ldn_inquiry_access[i]; | ||
2250 | return (a); | ||
2251 | } | ||
2252 | |||
2253 | static int ldn_access_total_modeselect(struct Scsi_Host *shpnt) | ||
2254 | { | ||
2255 | int a; | ||
2256 | int i; | ||
2257 | |||
2258 | a = 0; | ||
2259 | for (i = 0; i <= MAX_LOG_DEV; i++) | ||
2260 | a += IBM_DS(shpnt).ldn_modeselect_access[i]; | ||
2261 | return (a); | ||
2262 | } | ||
2263 | |||
2264 | /* routine to display info in the proc-fs-structure (a deluxe feature) */ | ||
2265 | static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout) | ||
2266 | { | ||
2267 | int len = 0; | ||
2268 | int i, id, lun; | ||
2269 | unsigned long flags; | ||
2270 | int max_pun; | ||
2271 | |||
2272 | |||
2273 | spin_lock_irqsave(shpnt->host_lock, flags); /* Check it */ | ||
2274 | |||
2275 | max_pun = subsystem_maxid(shpnt); | ||
2276 | |||
2277 | len += sprintf(buffer + len, "\n IBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", IBMMCA_SCSI_DRIVER_VERSION); | ||
2278 | len += sprintf(buffer + len, " SCSI Access-Statistics:\n"); | ||
2279 | len += sprintf(buffer + len, " Device Scanning Order....: %s\n", (ibm_ansi_order) ? "IBM/ANSI" : "New Industry Standard"); | ||
2280 | #ifdef CONFIG_SCSI_MULTI_LUN | ||
2281 | len += sprintf(buffer + len, " Multiple LUN probing.....: Yes\n"); | ||
2282 | #else | ||
2283 | len += sprintf(buffer + len, " Multiple LUN probing.....: No\n"); | ||
2284 | #endif | ||
2285 | len += sprintf(buffer + len, " This Hostnumber..........: %d\n", shpnt->host_no); | ||
2286 | len += sprintf(buffer + len, " Base I/O-Port............: 0x%x\n", (unsigned int) (IM_CMD_REG(shpnt))); | ||
2287 | len += sprintf(buffer + len, " (Shared) IRQ.............: %d\n", IM_IRQ); | ||
2288 | len += sprintf(buffer + len, " Total Interrupts.........: %d\n", IBM_DS(shpnt).total_interrupts); | ||
2289 | len += sprintf(buffer + len, " Total SCSI Accesses......: %d\n", IBM_DS(shpnt).total_accesses); | ||
2290 | len += sprintf(buffer + len, " Total short SCBs.........: %d\n", IBM_DS(shpnt).scbs); | ||
2291 | len += sprintf(buffer + len, " Total long SCBs..........: %d\n", IBM_DS(shpnt).long_scbs); | ||
2292 | len += sprintf(buffer + len, " Total SCSI READ/WRITE..: %d\n", ldn_access_total_read_write(shpnt)); | ||
2293 | len += sprintf(buffer + len, " Total SCSI Inquiries...: %d\n", ldn_access_total_inquiry(shpnt)); | ||
2294 | len += sprintf(buffer + len, " Total SCSI Modeselects.: %d\n", ldn_access_total_modeselect(shpnt)); | ||
2295 | len += sprintf(buffer + len, " Total SCSI other cmds..: %d\n", IBM_DS(shpnt).total_accesses - ldn_access_total_read_write(shpnt) | ||
2296 | - ldn_access_total_modeselect(shpnt) | ||
2297 | - ldn_access_total_inquiry(shpnt)); | ||
2298 | len += sprintf(buffer + len, " Total SCSI command fails.: %d\n\n", IBM_DS(shpnt).total_errors); | ||
2299 | len += sprintf(buffer + len, " Logical-Device-Number (LDN) Access-Statistics:\n"); | ||
2300 | len += sprintf(buffer + len, " LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n"); | ||
2301 | len += sprintf(buffer + len, " -----|--------------|-----------|-----------|--------------\n"); | ||
2302 | for (i = 0; i <= MAX_LOG_DEV; i++) | ||
2303 | len += sprintf(buffer + len, " %2X | %3d | %8d | %8d | %8d\n", i, ldn_access_load(shpnt, i), IBM_DS(shpnt).ldn_read_access[i], IBM_DS(shpnt).ldn_write_access[i], IBM_DS(shpnt).ldn_assignments[i]); | ||
2304 | len += sprintf(buffer + len, " -----------------------------------------------------------\n\n"); | ||
2305 | len += sprintf(buffer + len, " Dynamical-LDN-Assignment-Statistics:\n"); | ||
2306 | len += sprintf(buffer + len, " Number of physical SCSI-devices..: %d (+ Adapter)\n", IBM_DS(shpnt).total_scsi_devices); | ||
2307 | len += sprintf(buffer + len, " Dynamical Assignment necessary...: %s\n", IBM_DS(shpnt).dyn_flag ? "Yes" : "No "); | ||
2308 | len += sprintf(buffer + len, " Next LDN to be assigned..........: 0x%x\n", next_ldn(shpnt)); | ||
2309 | len += sprintf(buffer + len, " Dynamical assignments done yet...: %d\n", IBM_DS(shpnt).dynamical_assignments); | ||
2310 | len += sprintf(buffer + len, "\n Current SCSI-Device-Mapping:\n"); | ||
2311 | len += sprintf(buffer + len, " Physical SCSI-Device Map Logical SCSI-Device Map\n"); | ||
2312 | len += sprintf(buffer + len, " ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n"); | ||
2313 | for (id = 0; id < max_pun; id++) { | ||
2314 | len += sprintf(buffer + len, " %2d ", id); | ||
2315 | for (lun = 0; lun < 8; lun++) | ||
2316 | len += sprintf(buffer + len, "%2s ", ti_p(get_scsi(shpnt)[id][lun])); | ||
2317 | len += sprintf(buffer + len, " %2d ", id); | ||
2318 | for (lun = 0; lun < 8; lun++) | ||
2319 | len += sprintf(buffer + len, "%2s ", ti_l(get_ldn(shpnt)[id][lun])); | ||
2320 | len += sprintf(buffer + len, "\n"); | ||
2321 | } | ||
2322 | |||
2323 | len += sprintf(buffer + len, "(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n"); | ||
2324 | len += sprintf(buffer + len, " R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n"); | ||
2325 | len += sprintf(buffer + len, " - = nothing found, nothing assigned or unprobed LUN)\n\n"); | ||
2326 | |||
2327 | *start = buffer + offset; | ||
2328 | len -= offset; | ||
2329 | if (len > length) | ||
2330 | len = length; | ||
2331 | spin_unlock_irqrestore(shpnt->host_lock, flags); | ||
2332 | return len; | ||
2333 | } | ||
2334 | |||
2335 | static int option_setup(char *str) | ||
2336 | { | ||
2337 | int ints[IM_MAX_HOSTS]; | ||
2338 | char *cur = str; | ||
2339 | int i = 1; | ||
2340 | |||
2341 | while (cur && isdigit(*cur) && i < IM_MAX_HOSTS) { | ||
2342 | ints[i++] = simple_strtoul(cur, NULL, 0); | ||
2343 | if ((cur = strchr(cur, ',')) != NULL) | ||
2344 | cur++; | ||
2345 | } | ||
2346 | ints[0] = i - 1; | ||
2347 | internal_ibmmca_scsi_setup(cur, ints); | ||
2348 | return 1; | ||
2349 | } | ||
2350 | |||
2351 | __setup("ibmmcascsi=", option_setup); | ||
2352 | |||
2353 | static struct mca_driver ibmmca_driver = { | ||
2354 | .id_table = ibmmca_id_table, | ||
2355 | .driver = { | ||
2356 | .name = "ibmmca", | ||
2357 | .bus = &mca_bus_type, | ||
2358 | .probe = ibmmca_probe, | ||
2359 | .remove = __devexit_p(ibmmca_remove), | ||
2360 | }, | ||
2361 | }; | ||
2362 | |||
2363 | static int __init ibmmca_init(void) | ||
2364 | { | ||
2365 | #ifdef MODULE | ||
2366 | /* If the driver is run as module, read from conf.modules or cmd-line */ | ||
2367 | if (boot_options) | ||
2368 | option_setup(boot_options); | ||
2369 | #endif | ||
2370 | |||
2371 | return mca_register_driver_integrated(&ibmmca_driver, MCA_INTEGSCSI); | ||
2372 | } | ||
2373 | |||
2374 | static void __exit ibmmca_exit(void) | ||
2375 | { | ||
2376 | mca_unregister_driver(&ibmmca_driver); | ||
2377 | } | ||
2378 | |||
2379 | module_init(ibmmca_init); | ||
2380 | module_exit(ibmmca_exit); | ||
diff --git a/drivers/scsi/ibmvscsi/iseries_vscsi.c b/drivers/scsi/ibmvscsi/iseries_vscsi.c new file mode 100644 index 00000000000..f4776451a75 --- /dev/null +++ b/drivers/scsi/ibmvscsi/iseries_vscsi.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /* ------------------------------------------------------------ | ||
2 | * iSeries_vscsi.c | ||
3 | * (C) Copyright IBM Corporation 1994, 2003 | ||
4 | * Authors: Colin DeVilbiss (devilbis@us.ibm.com) | ||
5 | * Santiago Leon (santil@us.ibm.com) | ||
6 | * Dave Boutcher (sleddog@us.ibm.com) | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
21 | * USA | ||
22 | * | ||
23 | * ------------------------------------------------------------ | ||
24 | * iSeries-specific functions of the SCSI host adapter for Virtual I/O devices | ||
25 | * | ||
26 | * This driver allows the Linux SCSI peripheral drivers to directly | ||
27 | * access devices in the hosting partition, either on an iSeries | ||
28 | * hypervisor system or a converged hypervisor system. | ||
29 | */ | ||
30 | |||
31 | #include <asm/iseries/vio.h> | ||
32 | #include <asm/iseries/hv_lp_event.h> | ||
33 | #include <asm/iseries/hv_types.h> | ||
34 | #include <asm/iseries/hv_lp_config.h> | ||
35 | #include <asm/vio.h> | ||
36 | #include <linux/device.h> | ||
37 | #include "ibmvscsi.h" | ||
38 | |||
39 | /* global variables */ | ||
40 | static struct ibmvscsi_host_data *single_host_data; | ||
41 | |||
42 | /* ------------------------------------------------------------ | ||
43 | * Routines for direct interpartition interaction | ||
44 | */ | ||
45 | struct srp_lp_event { | ||
46 | struct HvLpEvent lpevt; /* 0x00-0x17 */ | ||
47 | u32 reserved1; /* 0x18-0x1B; unused */ | ||
48 | u16 version; /* 0x1C-0x1D; unused */ | ||
49 | u16 subtype_rc; /* 0x1E-0x1F; unused */ | ||
50 | struct viosrp_crq crq; /* 0x20-0x3F */ | ||
51 | }; | ||
52 | |||
53 | /** | ||
54 | * standard interface for handling logical partition events. | ||
55 | */ | ||
56 | static void iseriesvscsi_handle_event(struct HvLpEvent *lpevt) | ||
57 | { | ||
58 | struct srp_lp_event *evt = (struct srp_lp_event *)lpevt; | ||
59 | |||
60 | if (!evt) { | ||
61 | printk(KERN_ERR "ibmvscsi: received null event\n"); | ||
62 | return; | ||
63 | } | ||
64 | |||
65 | if (single_host_data == NULL) { | ||
66 | printk(KERN_ERR | ||
67 | "ibmvscsi: received event, no adapter present\n"); | ||
68 | return; | ||
69 | } | ||
70 | |||
71 | ibmvscsi_handle_crq(&evt->crq, single_host_data); | ||
72 | } | ||
73 | |||
74 | /* ------------------------------------------------------------ | ||
75 | * Routines for driver initialization | ||
76 | */ | ||
77 | static int iseriesvscsi_init_crq_queue(struct crq_queue *queue, | ||
78 | struct ibmvscsi_host_data *hostdata, | ||
79 | int max_requests) | ||
80 | { | ||
81 | int rc; | ||
82 | |||
83 | single_host_data = hostdata; | ||
84 | rc = viopath_open(viopath_hostLp, viomajorsubtype_scsi, max_requests); | ||
85 | if (rc < 0) { | ||
86 | printk("viopath_open failed with rc %d in open_event_path\n", | ||
87 | rc); | ||
88 | goto viopath_open_failed; | ||
89 | } | ||
90 | |||
91 | rc = vio_setHandler(viomajorsubtype_scsi, iseriesvscsi_handle_event); | ||
92 | if (rc < 0) { | ||
93 | printk("vio_setHandler failed with rc %d in open_event_path\n", | ||
94 | rc); | ||
95 | goto vio_setHandler_failed; | ||
96 | } | ||
97 | return 0; | ||
98 | |||
99 | vio_setHandler_failed: | ||
100 | viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests); | ||
101 | viopath_open_failed: | ||
102 | return -1; | ||
103 | } | ||
104 | |||
105 | static void iseriesvscsi_release_crq_queue(struct crq_queue *queue, | ||
106 | struct ibmvscsi_host_data *hostdata, | ||
107 | int max_requests) | ||
108 | { | ||
109 | vio_clearHandler(viomajorsubtype_scsi); | ||
110 | viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * reset_crq_queue: - resets a crq after a failure | ||
115 | * @queue: crq_queue to initialize and register | ||
116 | * @hostdata: ibmvscsi_host_data of host | ||
117 | * | ||
118 | * no-op for iSeries | ||
119 | */ | ||
120 | static int iseriesvscsi_reset_crq_queue(struct crq_queue *queue, | ||
121 | struct ibmvscsi_host_data *hostdata) | ||
122 | { | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * reenable_crq_queue: - reenables a crq after a failure | ||
128 | * @queue: crq_queue to initialize and register | ||
129 | * @hostdata: ibmvscsi_host_data of host | ||
130 | * | ||
131 | * no-op for iSeries | ||
132 | */ | ||
133 | static int iseriesvscsi_reenable_crq_queue(struct crq_queue *queue, | ||
134 | struct ibmvscsi_host_data *hostdata) | ||
135 | { | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * iseriesvscsi_send_crq: - Send a CRQ | ||
141 | * @hostdata: the adapter | ||
142 | * @word1: the first 64 bits of the data | ||
143 | * @word2: the second 64 bits of the data | ||
144 | */ | ||
145 | static int iseriesvscsi_send_crq(struct ibmvscsi_host_data *hostdata, | ||
146 | u64 word1, u64 word2) | ||
147 | { | ||
148 | single_host_data = hostdata; | ||
149 | return HvCallEvent_signalLpEventFast(viopath_hostLp, | ||
150 | HvLpEvent_Type_VirtualIo, | ||
151 | viomajorsubtype_scsi, | ||
152 | HvLpEvent_AckInd_NoAck, | ||
153 | HvLpEvent_AckType_ImmediateAck, | ||
154 | viopath_sourceinst(viopath_hostLp), | ||
155 | viopath_targetinst(viopath_hostLp), | ||
156 | 0, | ||
157 | VIOVERSION << 16, word1, word2, 0, | ||
158 | 0); | ||
159 | } | ||
160 | |||
161 | static int iseriesvscsi_resume(struct ibmvscsi_host_data *hostdata) | ||
162 | { | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | struct ibmvscsi_ops iseriesvscsi_ops = { | ||
167 | .init_crq_queue = iseriesvscsi_init_crq_queue, | ||
168 | .release_crq_queue = iseriesvscsi_release_crq_queue, | ||
169 | .reset_crq_queue = iseriesvscsi_reset_crq_queue, | ||
170 | .reenable_crq_queue = iseriesvscsi_reenable_crq_queue, | ||
171 | .send_crq = iseriesvscsi_send_crq, | ||
172 | .resume = iseriesvscsi_resume, | ||
173 | }; | ||
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c new file mode 100644 index 00000000000..f48ae0190d9 --- /dev/null +++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c | |||
@@ -0,0 +1,368 @@ | |||
1 | /* ------------------------------------------------------------ | ||
2 | * rpa_vscsi.c | ||
3 | * (C) Copyright IBM Corporation 1994, 2003 | ||
4 | * Authors: Colin DeVilbiss (devilbis@us.ibm.com) | ||
5 | * Santiago Leon (santil@us.ibm.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
20 | * USA | ||
21 | * | ||
22 | * ------------------------------------------------------------ | ||
23 | * RPA-specific functions of the SCSI host adapter for Virtual I/O devices | ||
24 | * | ||
25 | * This driver allows the Linux SCSI peripheral drivers to directly | ||
26 | * access devices in the hosting partition, either on an iSeries | ||
27 | * hypervisor system or a converged hypervisor system. | ||
28 | */ | ||
29 | |||
30 | #include <asm/vio.h> | ||
31 | #include <asm/prom.h> | ||
32 | #include <asm/iommu.h> | ||
33 | #include <asm/hvcall.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/dma-mapping.h> | ||
36 | #include <linux/gfp.h> | ||
37 | #include <linux/interrupt.h> | ||
38 | #include "ibmvscsi.h" | ||
39 | |||
40 | static char partition_name[97] = "UNKNOWN"; | ||
41 | static unsigned int partition_number = -1; | ||
42 | |||
43 | /* ------------------------------------------------------------ | ||
44 | * Routines for managing the command/response queue | ||
45 | */ | ||
46 | /** | ||
47 | * rpavscsi_handle_event: - Interrupt handler for crq events | ||
48 | * @irq: number of irq to handle, not used | ||
49 | * @dev_instance: ibmvscsi_host_data of host that received interrupt | ||
50 | * | ||
51 | * Disables interrupts and schedules srp_task | ||
52 | * Always returns IRQ_HANDLED | ||
53 | */ | ||
54 | static irqreturn_t rpavscsi_handle_event(int irq, void *dev_instance) | ||
55 | { | ||
56 | struct ibmvscsi_host_data *hostdata = | ||
57 | (struct ibmvscsi_host_data *)dev_instance; | ||
58 | vio_disable_interrupts(to_vio_dev(hostdata->dev)); | ||
59 | tasklet_schedule(&hostdata->srp_task); | ||
60 | return IRQ_HANDLED; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * release_crq_queue: - Deallocates data and unregisters CRQ | ||
65 | * @queue: crq_queue to initialize and register | ||
66 | * @host_data: ibmvscsi_host_data of host | ||
67 | * | ||
68 | * Frees irq, deallocates a page for messages, unmaps dma, and unregisters | ||
69 | * the crq with the hypervisor. | ||
70 | */ | ||
71 | static void rpavscsi_release_crq_queue(struct crq_queue *queue, | ||
72 | struct ibmvscsi_host_data *hostdata, | ||
73 | int max_requests) | ||
74 | { | ||
75 | long rc = 0; | ||
76 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
77 | free_irq(vdev->irq, (void *)hostdata); | ||
78 | tasklet_kill(&hostdata->srp_task); | ||
79 | do { | ||
80 | if (rc) | ||
81 | msleep(100); | ||
82 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | ||
83 | } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); | ||
84 | dma_unmap_single(hostdata->dev, | ||
85 | queue->msg_token, | ||
86 | queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); | ||
87 | free_page((unsigned long)queue->msgs); | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * crq_queue_next_crq: - Returns the next entry in message queue | ||
92 | * @queue: crq_queue to use | ||
93 | * | ||
94 | * Returns pointer to next entry in queue, or NULL if there are no new | ||
95 | * entried in the CRQ. | ||
96 | */ | ||
97 | static struct viosrp_crq *crq_queue_next_crq(struct crq_queue *queue) | ||
98 | { | ||
99 | struct viosrp_crq *crq; | ||
100 | unsigned long flags; | ||
101 | |||
102 | spin_lock_irqsave(&queue->lock, flags); | ||
103 | crq = &queue->msgs[queue->cur]; | ||
104 | if (crq->valid & 0x80) { | ||
105 | if (++queue->cur == queue->size) | ||
106 | queue->cur = 0; | ||
107 | } else | ||
108 | crq = NULL; | ||
109 | spin_unlock_irqrestore(&queue->lock, flags); | ||
110 | |||
111 | return crq; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * rpavscsi_send_crq: - Send a CRQ | ||
116 | * @hostdata: the adapter | ||
117 | * @word1: the first 64 bits of the data | ||
118 | * @word2: the second 64 bits of the data | ||
119 | */ | ||
120 | static int rpavscsi_send_crq(struct ibmvscsi_host_data *hostdata, | ||
121 | u64 word1, u64 word2) | ||
122 | { | ||
123 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
124 | |||
125 | return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * rpavscsi_task: - Process srps asynchronously | ||
130 | * @data: ibmvscsi_host_data of host | ||
131 | */ | ||
132 | static void rpavscsi_task(void *data) | ||
133 | { | ||
134 | struct ibmvscsi_host_data *hostdata = (struct ibmvscsi_host_data *)data; | ||
135 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
136 | struct viosrp_crq *crq; | ||
137 | int done = 0; | ||
138 | |||
139 | while (!done) { | ||
140 | /* Pull all the valid messages off the CRQ */ | ||
141 | while ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) { | ||
142 | ibmvscsi_handle_crq(crq, hostdata); | ||
143 | crq->valid = 0x00; | ||
144 | } | ||
145 | |||
146 | vio_enable_interrupts(vdev); | ||
147 | if ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) { | ||
148 | vio_disable_interrupts(vdev); | ||
149 | ibmvscsi_handle_crq(crq, hostdata); | ||
150 | crq->valid = 0x00; | ||
151 | } else { | ||
152 | done = 1; | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | |||
157 | static void gather_partition_info(void) | ||
158 | { | ||
159 | struct device_node *rootdn; | ||
160 | |||
161 | const char *ppartition_name; | ||
162 | const unsigned int *p_number_ptr; | ||
163 | |||
164 | /* Retrieve information about this partition */ | ||
165 | rootdn = of_find_node_by_path("/"); | ||
166 | if (!rootdn) { | ||
167 | return; | ||
168 | } | ||
169 | |||
170 | ppartition_name = of_get_property(rootdn, "ibm,partition-name", NULL); | ||
171 | if (ppartition_name) | ||
172 | strncpy(partition_name, ppartition_name, | ||
173 | sizeof(partition_name)); | ||
174 | p_number_ptr = of_get_property(rootdn, "ibm,partition-no", NULL); | ||
175 | if (p_number_ptr) | ||
176 | partition_number = *p_number_ptr; | ||
177 | of_node_put(rootdn); | ||
178 | } | ||
179 | |||
180 | static void set_adapter_info(struct ibmvscsi_host_data *hostdata) | ||
181 | { | ||
182 | memset(&hostdata->madapter_info, 0x00, | ||
183 | sizeof(hostdata->madapter_info)); | ||
184 | |||
185 | dev_info(hostdata->dev, "SRP_VERSION: %s\n", SRP_VERSION); | ||
186 | strcpy(hostdata->madapter_info.srp_version, SRP_VERSION); | ||
187 | |||
188 | strncpy(hostdata->madapter_info.partition_name, partition_name, | ||
189 | sizeof(hostdata->madapter_info.partition_name)); | ||
190 | |||
191 | hostdata->madapter_info.partition_number = partition_number; | ||
192 | |||
193 | hostdata->madapter_info.mad_version = 1; | ||
194 | hostdata->madapter_info.os_type = 2; | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * reset_crq_queue: - resets a crq after a failure | ||
199 | * @queue: crq_queue to initialize and register | ||
200 | * @hostdata: ibmvscsi_host_data of host | ||
201 | * | ||
202 | */ | ||
203 | static int rpavscsi_reset_crq_queue(struct crq_queue *queue, | ||
204 | struct ibmvscsi_host_data *hostdata) | ||
205 | { | ||
206 | int rc = 0; | ||
207 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
208 | |||
209 | /* Close the CRQ */ | ||
210 | do { | ||
211 | if (rc) | ||
212 | msleep(100); | ||
213 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | ||
214 | } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); | ||
215 | |||
216 | /* Clean out the queue */ | ||
217 | memset(queue->msgs, 0x00, PAGE_SIZE); | ||
218 | queue->cur = 0; | ||
219 | |||
220 | set_adapter_info(hostdata); | ||
221 | |||
222 | /* And re-open it again */ | ||
223 | rc = plpar_hcall_norets(H_REG_CRQ, | ||
224 | vdev->unit_address, | ||
225 | queue->msg_token, PAGE_SIZE); | ||
226 | if (rc == 2) { | ||
227 | /* Adapter is good, but other end is not ready */ | ||
228 | dev_warn(hostdata->dev, "Partner adapter not ready\n"); | ||
229 | } else if (rc != 0) { | ||
230 | dev_warn(hostdata->dev, "couldn't register crq--rc 0x%x\n", rc); | ||
231 | } | ||
232 | return rc; | ||
233 | } | ||
234 | |||
235 | /** | ||
236 | * initialize_crq_queue: - Initializes and registers CRQ with hypervisor | ||
237 | * @queue: crq_queue to initialize and register | ||
238 | * @hostdata: ibmvscsi_host_data of host | ||
239 | * | ||
240 | * Allocates a page for messages, maps it for dma, and registers | ||
241 | * the crq with the hypervisor. | ||
242 | * Returns zero on success. | ||
243 | */ | ||
244 | static int rpavscsi_init_crq_queue(struct crq_queue *queue, | ||
245 | struct ibmvscsi_host_data *hostdata, | ||
246 | int max_requests) | ||
247 | { | ||
248 | int rc; | ||
249 | int retrc; | ||
250 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
251 | |||
252 | queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); | ||
253 | |||
254 | if (!queue->msgs) | ||
255 | goto malloc_failed; | ||
256 | queue->size = PAGE_SIZE / sizeof(*queue->msgs); | ||
257 | |||
258 | queue->msg_token = dma_map_single(hostdata->dev, queue->msgs, | ||
259 | queue->size * sizeof(*queue->msgs), | ||
260 | DMA_BIDIRECTIONAL); | ||
261 | |||
262 | if (dma_mapping_error(hostdata->dev, queue->msg_token)) | ||
263 | goto map_failed; | ||
264 | |||
265 | gather_partition_info(); | ||
266 | set_adapter_info(hostdata); | ||
267 | |||
268 | retrc = rc = plpar_hcall_norets(H_REG_CRQ, | ||
269 | vdev->unit_address, | ||
270 | queue->msg_token, PAGE_SIZE); | ||
271 | if (rc == H_RESOURCE) | ||
272 | /* maybe kexecing and resource is busy. try a reset */ | ||
273 | rc = rpavscsi_reset_crq_queue(queue, | ||
274 | hostdata); | ||
275 | |||
276 | if (rc == 2) { | ||
277 | /* Adapter is good, but other end is not ready */ | ||
278 | dev_warn(hostdata->dev, "Partner adapter not ready\n"); | ||
279 | retrc = 0; | ||
280 | } else if (rc != 0) { | ||
281 | dev_warn(hostdata->dev, "Error %d opening adapter\n", rc); | ||
282 | goto reg_crq_failed; | ||
283 | } | ||
284 | |||
285 | queue->cur = 0; | ||
286 | spin_lock_init(&queue->lock); | ||
287 | |||
288 | tasklet_init(&hostdata->srp_task, (void *)rpavscsi_task, | ||
289 | (unsigned long)hostdata); | ||
290 | |||
291 | if (request_irq(vdev->irq, | ||
292 | rpavscsi_handle_event, | ||
293 | 0, "ibmvscsi", (void *)hostdata) != 0) { | ||
294 | dev_err(hostdata->dev, "couldn't register irq 0x%x\n", | ||
295 | vdev->irq); | ||
296 | goto req_irq_failed; | ||
297 | } | ||
298 | |||
299 | rc = vio_enable_interrupts(vdev); | ||
300 | if (rc != 0) { | ||
301 | dev_err(hostdata->dev, "Error %d enabling interrupts!!!\n", rc); | ||
302 | goto req_irq_failed; | ||
303 | } | ||
304 | |||
305 | return retrc; | ||
306 | |||
307 | req_irq_failed: | ||
308 | tasklet_kill(&hostdata->srp_task); | ||
309 | rc = 0; | ||
310 | do { | ||
311 | if (rc) | ||
312 | msleep(100); | ||
313 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | ||
314 | } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); | ||
315 | reg_crq_failed: | ||
316 | dma_unmap_single(hostdata->dev, | ||
317 | queue->msg_token, | ||
318 | queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); | ||
319 | map_failed: | ||
320 | free_page((unsigned long)queue->msgs); | ||
321 | malloc_failed: | ||
322 | return -1; | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * reenable_crq_queue: - reenables a crq after | ||
327 | * @queue: crq_queue to initialize and register | ||
328 | * @hostdata: ibmvscsi_host_data of host | ||
329 | * | ||
330 | */ | ||
331 | static int rpavscsi_reenable_crq_queue(struct crq_queue *queue, | ||
332 | struct ibmvscsi_host_data *hostdata) | ||
333 | { | ||
334 | int rc = 0; | ||
335 | struct vio_dev *vdev = to_vio_dev(hostdata->dev); | ||
336 | |||
337 | /* Re-enable the CRQ */ | ||
338 | do { | ||
339 | if (rc) | ||
340 | msleep(100); | ||
341 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); | ||
342 | } while ((rc == H_IN_PROGRESS) || (rc == H_BUSY) || (H_IS_LONG_BUSY(rc))); | ||
343 | |||
344 | if (rc) | ||
345 | dev_err(hostdata->dev, "Error %d enabling adapter\n", rc); | ||
346 | return rc; | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * rpavscsi_resume: - resume after suspend | ||
351 | * @hostdata: ibmvscsi_host_data of host | ||
352 | * | ||
353 | */ | ||
354 | static int rpavscsi_resume(struct ibmvscsi_host_data *hostdata) | ||
355 | { | ||
356 | vio_disable_interrupts(to_vio_dev(hostdata->dev)); | ||
357 | tasklet_schedule(&hostdata->srp_task); | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | struct ibmvscsi_ops rpavscsi_ops = { | ||
362 | .init_crq_queue = rpavscsi_init_crq_queue, | ||
363 | .release_crq_queue = rpavscsi_release_crq_queue, | ||
364 | .reset_crq_queue = rpavscsi_reset_crq_queue, | ||
365 | .reenable_crq_queue = rpavscsi_reenable_crq_queue, | ||
366 | .send_crq = rpavscsi_send_crq, | ||
367 | .resume = rpavscsi_resume, | ||
368 | }; | ||
diff --git a/drivers/scsi/isci/firmware/Makefile b/drivers/scsi/isci/firmware/Makefile new file mode 100644 index 00000000000..5f54461cabc --- /dev/null +++ b/drivers/scsi/isci/firmware/Makefile | |||
@@ -0,0 +1,19 @@ | |||
1 | # Makefile for create_fw | ||
2 | # | ||
3 | CC=gcc | ||
4 | CFLAGS=-c -Wall -O2 -g | ||
5 | LDFLAGS= | ||
6 | SOURCES=create_fw.c | ||
7 | OBJECTS=$(SOURCES:.cpp=.o) | ||
8 | EXECUTABLE=create_fw | ||
9 | |||
10 | all: $(SOURCES) $(EXECUTABLE) | ||
11 | |||
12 | $(EXECUTABLE): $(OBJECTS) | ||
13 | $(CC) $(LDFLAGS) $(OBJECTS) -o $@ | ||
14 | |||
15 | .c.o: | ||
16 | $(CC) $(CFLAGS) $< -O $@ | ||
17 | |||
18 | clean: | ||
19 | rm -f *.o $(EXECUTABLE) | ||
diff --git a/drivers/scsi/isci/firmware/README b/drivers/scsi/isci/firmware/README new file mode 100644 index 00000000000..8056d2bd233 --- /dev/null +++ b/drivers/scsi/isci/firmware/README | |||
@@ -0,0 +1,36 @@ | |||
1 | This defines the temporary binary blow we are to pass to the SCU | ||
2 | driver to emulate the binary firmware that we will eventually be | ||
3 | able to access via NVRAM on the SCU controller. | ||
4 | |||
5 | The current size of the binary blob is expected to be 149 bytes or larger | ||
6 | |||
7 | Header Types: | ||
8 | 0x1: Phy Masks | ||
9 | 0x2: Phy Gens | ||
10 | 0x3: SAS Addrs | ||
11 | 0xff: End of Data | ||
12 | |||
13 | ID string - u8[12]: "#SCU MAGIC#\0" | ||
14 | Version - u8: 1 | ||
15 | SubVersion - u8: 0 | ||
16 | |||
17 | Header Type - u8: 0x1 | ||
18 | Size - u8: 8 | ||
19 | Phy Mask - u32[8] | ||
20 | |||
21 | Header Type - u8: 0x2 | ||
22 | Size - u8: 8 | ||
23 | Phy Gen - u32[8] | ||
24 | |||
25 | Header Type - u8: 0x3 | ||
26 | Size - u8: 8 | ||
27 | Sas Addr - u64[8] | ||
28 | |||
29 | Header Type - u8: 0xf | ||
30 | |||
31 | |||
32 | ============================================================================== | ||
33 | |||
34 | Place isci_firmware.bin in /lib/firmware | ||
35 | Be sure to recreate the initramfs image to include the firmware. | ||
36 | |||
diff --git a/drivers/scsi/isci/firmware/create_fw.c b/drivers/scsi/isci/firmware/create_fw.c new file mode 100644 index 00000000000..c7a2887a7e9 --- /dev/null +++ b/drivers/scsi/isci/firmware/create_fw.c | |||
@@ -0,0 +1,99 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <unistd.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <string.h> | ||
8 | #include <errno.h> | ||
9 | #include <asm/types.h> | ||
10 | #include <strings.h> | ||
11 | #include <stdint.h> | ||
12 | |||
13 | #include "create_fw.h" | ||
14 | #include "../probe_roms.h" | ||
15 | |||
16 | int write_blob(struct isci_orom *isci_orom) | ||
17 | { | ||
18 | FILE *fd; | ||
19 | int err; | ||
20 | size_t count; | ||
21 | |||
22 | fd = fopen(blob_name, "w+"); | ||
23 | if (!fd) { | ||
24 | perror("Open file for write failed"); | ||
25 | fclose(fd); | ||
26 | return -EIO; | ||
27 | } | ||
28 | |||
29 | count = fwrite(isci_orom, sizeof(struct isci_orom), 1, fd); | ||
30 | if (count != 1) { | ||
31 | perror("Write data failed"); | ||
32 | fclose(fd); | ||
33 | return -EIO; | ||
34 | } | ||
35 | |||
36 | fclose(fd); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | void set_binary_values(struct isci_orom *isci_orom) | ||
42 | { | ||
43 | int ctrl_idx, phy_idx, port_idx; | ||
44 | |||
45 | /* setting OROM signature */ | ||
46 | strncpy(isci_orom->hdr.signature, sig, strlen(sig)); | ||
47 | isci_orom->hdr.version = version; | ||
48 | isci_orom->hdr.total_block_length = sizeof(struct isci_orom); | ||
49 | isci_orom->hdr.hdr_length = sizeof(struct sci_bios_oem_param_block_hdr); | ||
50 | isci_orom->hdr.num_elements = num_elements; | ||
51 | |||
52 | for (ctrl_idx = 0; ctrl_idx < 2; ctrl_idx++) { | ||
53 | isci_orom->ctrl[ctrl_idx].controller.mode_type = mode_type; | ||
54 | isci_orom->ctrl[ctrl_idx].controller.max_concurrent_dev_spin_up = | ||
55 | max_num_concurrent_dev_spin_up; | ||
56 | isci_orom->ctrl[ctrl_idx].controller.do_enable_ssc = | ||
57 | enable_ssc; | ||
58 | |||
59 | for (port_idx = 0; port_idx < 4; port_idx++) | ||
60 | isci_orom->ctrl[ctrl_idx].ports[port_idx].phy_mask = | ||
61 | phy_mask[ctrl_idx][port_idx]; | ||
62 | |||
63 | for (phy_idx = 0; phy_idx < 4; phy_idx++) { | ||
64 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].sas_address.high = | ||
65 | (__u32)(sas_addr[ctrl_idx][phy_idx] >> 32); | ||
66 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].sas_address.low = | ||
67 | (__u32)(sas_addr[ctrl_idx][phy_idx]); | ||
68 | |||
69 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control0 = | ||
70 | afe_tx_amp_control0; | ||
71 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control1 = | ||
72 | afe_tx_amp_control1; | ||
73 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control2 = | ||
74 | afe_tx_amp_control2; | ||
75 | isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control3 = | ||
76 | afe_tx_amp_control3; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | int main(void) | ||
82 | { | ||
83 | int err; | ||
84 | struct isci_orom *isci_orom; | ||
85 | |||
86 | isci_orom = malloc(sizeof(struct isci_orom)); | ||
87 | memset(isci_orom, 0, sizeof(struct isci_orom)); | ||
88 | |||
89 | set_binary_values(isci_orom); | ||
90 | |||
91 | err = write_blob(isci_orom); | ||
92 | if (err < 0) { | ||
93 | free(isci_orom); | ||
94 | return err; | ||
95 | } | ||
96 | |||
97 | free(isci_orom); | ||
98 | return 0; | ||
99 | } | ||
diff --git a/drivers/scsi/isci/firmware/create_fw.h b/drivers/scsi/isci/firmware/create_fw.h new file mode 100644 index 00000000000..5f298828d22 --- /dev/null +++ b/drivers/scsi/isci/firmware/create_fw.h | |||
@@ -0,0 +1,77 @@ | |||
1 | #ifndef _CREATE_FW_H_ | ||
2 | #define _CREATE_FW_H_ | ||
3 | #include "../probe_roms.h" | ||
4 | |||
5 | |||
6 | /* we are configuring for 2 SCUs */ | ||
7 | static const int num_elements = 2; | ||
8 | |||
9 | /* | ||
10 | * For all defined arrays: | ||
11 | * elements 0-3 are for SCU0, ports 0-3 | ||
12 | * elements 4-7 are for SCU1, ports 0-3 | ||
13 | * | ||
14 | * valid configurations for one SCU are: | ||
15 | * P0 P1 P2 P3 | ||
16 | * ---------------- | ||
17 | * 0xF,0x0,0x0,0x0 # 1 x4 port | ||
18 | * 0x3,0x0,0x4,0x8 # Phys 0 and 1 are a x2 port, phy 2 and phy 3 are each x1 | ||
19 | * # ports | ||
20 | * 0x1,0x2,0xC,0x0 # Phys 0 and 1 are each x1 ports, phy 2 and phy 3 are a x2 | ||
21 | * # port | ||
22 | * 0x3,0x0,0xC,0x0 # Phys 0 and 1 are a x2 port, phy 2 and phy 3 are a x2 port | ||
23 | * 0x1,0x2,0x4,0x8 # Each phy is a x1 port (this is the default configuration) | ||
24 | * | ||
25 | * if there is a port/phy on which you do not wish to override the default | ||
26 | * values, use the value assigned to UNINIT_PARAM (255). | ||
27 | */ | ||
28 | |||
29 | /* discovery mode type (port auto config mode by default ) */ | ||
30 | |||
31 | /* | ||
32 | * if there is a port/phy on which you do not wish to override the default | ||
33 | * values, use the value "0000000000000000". SAS address of zero's is | ||
34 | * considered invalid and will not be used. | ||
35 | */ | ||
36 | #ifdef MPC | ||
37 | static const int mode_type = SCIC_PORT_MANUAL_CONFIGURATION_MODE; | ||
38 | static const __u8 phy_mask[2][4] = { {1, 2, 4, 8}, | ||
39 | {1, 2, 4, 8} }; | ||
40 | static const unsigned long long sas_addr[2][4] = { { 0x5FCFFFFFF0000001ULL, | ||
41 | 0x5FCFFFFFF0000002ULL, | ||
42 | 0x5FCFFFFFF0000003ULL, | ||
43 | 0x5FCFFFFFF0000004ULL }, | ||
44 | { 0x5FCFFFFFF0000005ULL, | ||
45 | 0x5FCFFFFFF0000006ULL, | ||
46 | 0x5FCFFFFFF0000007ULL, | ||
47 | 0x5FCFFFFFF0000008ULL } }; | ||
48 | #else /* APC (default) */ | ||
49 | static const int mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE; | ||
50 | static const __u8 phy_mask[2][4]; | ||
51 | static const unsigned long long sas_addr[2][4] = { { 0x5FCFFFFF00000001ULL, | ||
52 | 0x5FCFFFFF00000001ULL, | ||
53 | 0x5FCFFFFF00000001ULL, | ||
54 | 0x5FCFFFFF00000001ULL }, | ||
55 | { 0x5FCFFFFF00000002ULL, | ||
56 | 0x5FCFFFFF00000002ULL, | ||
57 | 0x5FCFFFFF00000002ULL, | ||
58 | 0x5FCFFFFF00000002ULL } }; | ||
59 | #endif | ||
60 | |||
61 | /* Maximum number of concurrent device spin up */ | ||
62 | static const int max_num_concurrent_dev_spin_up = 1; | ||
63 | |||
64 | /* enable of ssc operation */ | ||
65 | static const int enable_ssc; | ||
66 | |||
67 | /* AFE_TX_AMP_CONTROL */ | ||
68 | static const unsigned int afe_tx_amp_control0 = 0x000bdd08; | ||
69 | static const unsigned int afe_tx_amp_control1 = 0x000ffc00; | ||
70 | static const unsigned int afe_tx_amp_control2 = 0x000b7c09; | ||
71 | static const unsigned int afe_tx_amp_control3 = 0x000afc6e; | ||
72 | |||
73 | static const char blob_name[] = "isci_firmware.bin"; | ||
74 | static const char sig[] = "ISCUOEMB"; | ||
75 | static const unsigned char version = 0x10; | ||
76 | |||
77 | #endif | ||
diff --git a/drivers/scsi/scsi_wait_scan.c b/drivers/scsi/scsi_wait_scan.c new file mode 100644 index 00000000000..74708fcaf82 --- /dev/null +++ b/drivers/scsi/scsi_wait_scan.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * scsi_wait_scan.c | ||
3 | * | ||
4 | * Copyright (C) 2006 James Bottomley <James.Bottomley@SteelEye.com> | ||
5 | * | ||
6 | * This is a simple module to wait until all the async scans are | ||
7 | * complete. The idea is to use it in initrd/initramfs scripts. You | ||
8 | * modprobe it after all the modprobes of the root SCSI drivers and it | ||
9 | * will wait until they have all finished scanning their busses before | ||
10 | * allowing the boot to proceed | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <scsi/scsi_scan.h> | ||
16 | |||
17 | static int __init wait_scan_init(void) | ||
18 | { | ||
19 | /* | ||
20 | * First we need to wait for device probing to finish; | ||
21 | * the drivers we just loaded might just still be probing | ||
22 | * and might not yet have reached the scsi async scanning | ||
23 | */ | ||
24 | wait_for_device_probe(); | ||
25 | /* | ||
26 | * and then we wait for the actual asynchronous scsi scan | ||
27 | * to finish. | ||
28 | */ | ||
29 | scsi_complete_async_scans(); | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static void __exit wait_scan_exit(void) | ||
34 | { | ||
35 | } | ||
36 | |||
37 | MODULE_DESCRIPTION("SCSI wait for scans"); | ||
38 | MODULE_AUTHOR("James Bottomley"); | ||
39 | MODULE_LICENSE("GPL"); | ||
40 | |||
41 | late_initcall(wait_scan_init); | ||
42 | module_exit(wait_scan_exit); | ||