Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / drivers / scsi / ibmmca.c
blobd383253d1f275240ac36b10d883b91694568d69c
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.
13 Alan Cox <alan@redhat.com>
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.
20 #ifndef LINUX_VERSION_CODE
21 #include <linux/version.h>
22 #endif
23 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45)
24 #error "This driver works only with kernel 2.5.45 or higher!"
25 #endif
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/ctype.h>
30 #include <linux/string.h>
31 #include <linux/ioport.h>
32 #include <linux/delay.h>
33 #include <linux/sched.h>
34 #include <linux/blk.h>
35 #include <linux/proc_fs.h>
36 #include <linux/stat.h>
37 #include <linux/mca.h>
38 #include <linux/string.h>
39 #include <asm/system.h>
40 #include <linux/spinlock.h>
41 #include <asm/io.h>
42 #include <linux/init.h>
43 #include "scsi.h"
44 #include "hosts.h"
45 #include "ibmmca.h"
46 #include <linux/config.h>
48 /* current version of this driver-source: */
49 #define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac"
51 /* driver configuration */
52 #define IM_MAX_HOSTS 8 /* maximum number of host adapters */
53 #define IM_RESET_DELAY 60 /* seconds allowed for a reset */
55 /* driver debugging - #undef all for normal operation */
56 /* if defined: count interrupts and ignore this special one: */
57 #undef IM_DEBUG_TIMEOUT //50
58 #define TIMEOUT_PUN 0
59 #define TIMEOUT_LUN 0
60 /* verbose interrupt: */
61 #undef IM_DEBUG_INT
62 /* verbose queuecommand: */
63 #undef IM_DEBUG_CMD
64 /* verbose queucommand for specific SCSI-device type: */
65 #undef IM_DEBUG_CMD_SPEC_DEV
66 /* verbose device probing */
67 #undef IM_DEBUG_PROBE
69 /* device type that shall be displayed on syslog (only during debugging): */
70 #define IM_DEBUG_CMD_DEVICE TYPE_TAPE
72 /* relative addresses of hardware registers on a subsystem */
73 #define IM_CMD_REG(hi) (hosts[(hi)]->io_port) /*Command Interface, (4 bytes long) */
74 #define IM_ATTN_REG(hi) (hosts[(hi)]->io_port+4) /*Attention (1 byte) */
75 #define IM_CTR_REG(hi) (hosts[(hi)]->io_port+5) /*Basic Control (1 byte) */
76 #define IM_INTR_REG(hi) (hosts[(hi)]->io_port+6) /*Interrupt Status (1 byte, r/o) */
77 #define IM_STAT_REG(hi) (hosts[(hi)]->io_port+7) /*Basic Status (1 byte, read only) */
79 /* basic I/O-port of first adapter */
80 #define IM_IO_PORT 0x3540
81 /* maximum number of hosts that can be found */
82 #define IM_N_IO_PORT 8
84 /*requests going into the upper nibble of the Attention register */
85 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
86 #define IM_IMM_CMD 0x10 /*immediate command */
87 #define IM_SCB 0x30 /*Subsystem Control Block command */
88 #define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */
89 #define IM_EOI 0xe0 /*end-of-interrupt request */
91 /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */
92 #define IM_HW_RESET 0x80 /*hardware reset */
93 #define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */
94 #define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */
96 /*to interpret the upper nibble of Interrupt Status register */
97 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
98 #define IM_SCB_CMD_COMPLETED 0x10
99 #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50
100 #define IM_LOOP_SCATTER_BUFFER_FULL 0x60
101 #define IM_ADAPTER_HW_FAILURE 0x70
102 #define IM_IMMEDIATE_CMD_COMPLETED 0xa0
103 #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0
104 #define IM_CMD_ERROR 0xe0
105 #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0
107 /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */
108 #define IM_CMD_REG_FULL 0x08
109 #define IM_CMD_REG_EMPTY 0x04
110 #define IM_INTR_REQUEST 0x02
111 #define IM_BUSY 0x01
113 /*immediate commands (word written into low 2 bytes of command reg) */
114 #define IM_RESET_IMM_CMD 0x0400
115 #define IM_FEATURE_CTR_IMM_CMD 0x040c
116 #define IM_DMA_PACING_IMM_CMD 0x040d
117 #define IM_ASSIGN_IMM_CMD 0x040e
118 #define IM_ABORT_IMM_CMD 0x040f
119 #define IM_FORMAT_PREP_IMM_CMD 0x0417
121 /*SCB (Subsystem Control Block) structure */
122 struct im_scb {
123 unsigned short command; /*command word (read, etc.) */
124 unsigned short enable; /*enable word, modifies cmd */
125 union {
126 unsigned long log_blk_adr; /*block address on SCSI device */
127 unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */
128 } u1;
129 unsigned long sys_buf_adr; /*physical system memory adr */
130 unsigned long sys_buf_length; /*size of sys mem buffer */
131 unsigned long tsb_adr; /*Termination Status Block adr */
132 unsigned long scb_chain_adr; /*optional SCB chain address */
133 union {
134 struct {
135 unsigned short count; /*block count, on SCSI device */
136 unsigned short length; /*block length, on SCSI device */
137 } blk;
138 unsigned char scsi_command[12]; /*other scsi command */
139 } u2;
142 /*structure scatter-gather element (for list of system memory areas) */
143 struct im_sge {
144 void *address;
145 unsigned long byte_length;
148 /*structure returned by a get_pos_info command: */
149 struct im_pos_info {
150 unsigned short pos_id; /* adapter id */
151 unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */
152 unsigned char pos_2; /* pos 2 */
153 unsigned char int_level; /* interrupt level IRQ 11 or 14 */
154 unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */
155 unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */
156 unsigned char num_luns; /* number of supported luns per device */
157 unsigned char num_puns; /* number of supported puns */
158 unsigned char pacing_factor; /* pacing factor */
159 unsigned char num_ldns; /* number of ldns available */
160 unsigned char eoi_off; /* time EOI and interrupt inactive */
161 unsigned char max_busy; /* time between reset and busy on */
162 unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */
163 unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */
164 unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */
165 unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */
166 unsigned char pos_6; /* pos 6 */
167 unsigned char pos_5; /* pos 5 */
168 unsigned short max_overlap; /* maximum overlapping requests */
169 unsigned short num_bus; /* number of SCSI-busses */
172 /*values for SCB command word */
173 #define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */
174 #define IM_NO_DISCONNECT 0x0080 /*flag for any command */
175 #define IM_READ_DATA_CMD 0x1c01
176 #define IM_WRITE_DATA_CMD 0x1c02
177 #define IM_READ_VERIFY_CMD 0x1c03
178 #define IM_WRITE_VERIFY_CMD 0x1c04
179 #define IM_REQUEST_SENSE_CMD 0x1c08
180 #define IM_READ_CAPACITY_CMD 0x1c09
181 #define IM_DEVICE_INQUIRY_CMD 0x1c0b
182 #define IM_READ_LOGICAL_CMD 0x1c2a
183 #define IM_OTHER_SCSI_CMD_CMD 0x241f
185 /* unused, but supported, SCB commands */
186 #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */
187 #define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */
188 #define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */
189 #define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */
190 #define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */
192 /*values to set bits in the enable word of SCB */
193 #define IM_READ_CONTROL 0x8000
194 #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000
195 #define IM_RETRY_ENABLE 0x2000
196 #define IM_POINTER_TO_LIST 0x1000
197 #define IM_SUPRESS_EXCEPTION_SHORT 0x0400
198 #define IM_BYPASS_BUFFER 0x0200
199 #define IM_CHAIN_ON_NO_ERROR 0x0001
201 /*TSB (Termination Status Block) structure */
202 struct im_tsb {
203 unsigned short end_status;
204 unsigned short reserved1;
205 unsigned long residual_byte_count;
206 unsigned long sg_list_element_adr;
207 unsigned short status_length;
208 unsigned char dev_status;
209 unsigned char cmd_status;
210 unsigned char dev_error;
211 unsigned char cmd_error;
212 unsigned short reserved2;
213 unsigned short reserved3;
214 unsigned short low_of_last_scb_adr;
215 unsigned short high_of_last_scb_adr;
218 /*subsystem uses interrupt request level 14 */
219 #define IM_IRQ 14
220 /*SCSI-2 F/W may evade to interrupt 11 */
221 #define IM_IRQ_FW 11
223 /* Model 95 has an additional alphanumeric display, which can be used
224 to display SCSI-activities. 8595 models do not have any disk led, which
225 makes this feature quite useful.
226 The regular PS/2 disk led is turned on/off by bits 6,7 of system
227 control port. */
229 /* LED display-port (actually, last LED on display) */
230 #define MOD95_LED_PORT 0x108
231 /* system-control-register of PS/2s with diskindicator */
232 #define PS2_SYS_CTR 0x92
233 /* activity displaying methods */
234 #define LED_DISP 1
235 #define LED_ADISP 2
236 #define LED_ACTIVITY 4
237 /* failed intr */
238 #define CMD_FAIL 255
240 /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED
241 displays. ldn is no longer displayed here, because the ldn mapping is now
242 done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime
243 or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble,
244 interest, debugging or just for having fun. The left number gives the
245 host-adapter number and the right shows the accessed SCSI-ID. */
247 /* display_mode is set by the ibmmcascsi= command line arg */
248 static int display_mode = 0;
249 /* set default adapter timeout */
250 static unsigned int adapter_timeout = 45;
251 /* for probing on feature-command: */
252 static unsigned int global_command_error_excuse = 0;
253 /* global setting by command line for adapter_speed */
254 static int global_adapter_speed = 0; /* full speed by default */
256 /* Panel / LED on, do it right for F/W addressin, too. adisplay will
257 * just ignore ids>7, as the panel has only 7 digits available */
258 #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \
259 outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \
260 outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \
261 if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \
262 outb((char)(ad+48), MOD95_LED_PORT); } \
263 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
264 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); }
266 /* Panel / LED off */
267 /* bug fixed, Dec 15, 1997, where | was replaced by & here */
268 #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \
269 outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \
270 outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \
271 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
272 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); }
274 /*list of supported subsystems */
275 struct subsys_list_struct {
276 unsigned short mca_id;
277 char *description;
280 /* types of different supported hardware that goes to hostdata special */
281 #define IBM_SCSI2_FW 0
282 #define IBM_7568_WCACHE 1
283 #define IBM_EXP_UNIT 2
284 #define IBM_SCSI_WCACHE 3
285 #define IBM_SCSI 4
287 /* other special flags for hostdata structure */
288 #define FORCED_DETECTION 100
289 #define INTEGRATED_SCSI 101
291 /* List of possible IBM-SCSI-adapters */
292 struct subsys_list_struct subsys_list[] = {
293 {0x8efc, "IBM SCSI-2 F/W Adapter"}, /* special = 0 */
294 {0x8efd, "IBM 7568 Industrial Computer SCSI Adapter w/Cache"}, /* special = 1 */
295 {0x8ef8, "IBM Expansion Unit SCSI Controller"}, /* special = 2 */
296 {0x8eff, "IBM SCSI Adapter w/Cache"}, /* special = 3 */
297 {0x8efe, "IBM SCSI Adapter"}, /* special = 4 */
300 /* Max number of logical devices (can be up from 0 to 14). 15 is the address
301 of the adapter itself. */
302 #define MAX_LOG_DEV 15
304 /*local data for a logical device */
305 struct logical_device {
306 struct im_scb scb; /* SCSI-subsystem-control-block structure */
307 struct im_tsb tsb; /* SCSI command complete status block structure */
308 struct im_sge sge[16]; /* scatter gather list structure */
309 unsigned char buf[256]; /* SCSI command return data buffer */
310 Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */
311 int device_type; /* type of the SCSI-device. See include/scsi/scsi.h
312 for interpretation of the possible values */
313 int block_length; /* blocksize of a particular logical SCSI-device */
314 int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */
315 int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */
318 /* statistics of the driver during operations (for proc_info) */
319 struct Driver_Statistics {
320 /* SCSI statistics on the adapter */
321 int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */
322 int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */
323 int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */
324 int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */
325 int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */
326 int scbs; /* short SCBs queued */
327 int long_scbs; /* long SCBs queued */
328 int total_accesses; /* total accesses on all ldns */
329 int total_interrupts; /* total interrupts (should be
330 same as total_accesses) */
331 int total_errors; /* command completed with error */
332 /* dynamical assignment statistics */
333 int total_scsi_devices; /* number of physical pun,lun */
334 int dyn_flag; /* flag showing dynamical mode */
335 int dynamical_assignments; /* number of remappings of ldns */
336 int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each
337 ldn */
340 /* data structure for each host adapter */
341 struct ibmmca_hostdata {
342 /* array of logical devices: */
343 struct logical_device _ld[MAX_LOG_DEV + 1];
344 /* array to convert (pun, lun) into logical device number: */
345 unsigned char _get_ldn[16][8];
346 /*array that contains the information about the physical SCSI-devices
347 attached to this host adapter: */
348 unsigned char _get_scsi[16][8];
349 /* used only when checking logical devices: */
350 int _local_checking_phase_flag;
351 /* report received interrupt: */
352 int _got_interrupt;
353 /* report termination-status of SCSI-command: */
354 int _stat_result;
355 /* reset status (used only when doing reset): */
356 int _reset_status;
357 /* code of the last SCSI command (needed for panic info): */
358 int _last_scsi_command[MAX_LOG_DEV + 1];
359 /* identifier of the last SCSI-command type */
360 int _last_scsi_type[MAX_LOG_DEV + 1];
361 /* last blockcount */
362 int _last_scsi_blockcount[MAX_LOG_DEV + 1];
363 /* last locgical block address */
364 unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1];
365 /* Counter that points on the next reassignable ldn for dynamical
366 remapping. The default value is 7, that is the first reassignable
367 number in the list at boottime: */
368 int _next_ldn;
369 /* Statistics-structure for this IBM-SCSI-host: */
370 struct Driver_Statistics _IBM_DS;
371 /* This hostadapters pos-registers pos2 until pos6 */
372 unsigned int _pos[8];
373 /* assign a special variable, that contains dedicated info about the
374 adaptertype */
375 int _special;
376 /* connector size on the MCA bus */
377 int _connector_size;
378 /* synchronous SCSI transfer rate bitpattern */
379 int _adapter_speed;
382 /* macros to access host data structure */
383 #define subsystem_pun(hi) (hosts[(hi)]->this_id)
384 #define subsystem_maxid(hi) (hosts[(hi)]->max_id)
385 #define ld(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_ld)
386 #define get_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_ldn)
387 #define get_scsi(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_scsi)
388 #define local_checking_phase_flag(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_local_checking_phase_flag)
389 #define got_interrupt(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_got_interrupt)
390 #define stat_result(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_stat_result)
391 #define reset_status(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_reset_status)
392 #define last_scsi_command(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_command)
393 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
394 #define last_scsi_blockcount(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_blockcount)
395 #define last_scsi_logical_block(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_logical_block)
396 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
397 #define next_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_next_ldn)
398 #define IBM_DS(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_IBM_DS)
399 #define special(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_special)
400 #define subsystem_connector_size(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_connector_size)
401 #define adapter_speed(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_adapter_speed)
402 #define pos2(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[2])
403 #define pos3(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[3])
404 #define pos4(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[4])
405 #define pos5(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[5])
406 #define pos6(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[6])
408 /* Define a arbitrary number as subsystem-marker-type. This number is, as
409 described in the ANSI-SCSI-standard, not occupied by other device-types. */
410 #define TYPE_IBM_SCSI_ADAPTER 0x2F
412 /* Define 0xFF for no device type, because this type is not defined within
413 the ANSI-SCSI-standard, therefore, it can be used and should not cause any
414 harm. */
415 #define TYPE_NO_DEVICE 0xFF
417 /* define medium-changer. If this is not defined previously, e.g. Linux
418 2.0.x, define this type here. */
419 #ifndef TYPE_MEDIUM_CHANGER
420 #define TYPE_MEDIUM_CHANGER 0x08
421 #endif
423 /* define possible operations for the immediate_assign command */
424 #define SET_LDN 0
425 #define REMOVE_LDN 1
427 /* ldn which is used to probe the SCSI devices */
428 #define PROBE_LDN 0
430 /* reset status flag contents */
431 #define IM_RESET_NOT_IN_PROGRESS 0
432 #define IM_RESET_IN_PROGRESS 1
433 #define IM_RESET_FINISHED_OK 2
434 #define IM_RESET_FINISHED_FAIL 3
435 #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4
436 #define IM_RESET_FINISHED_OK_NO_INT 5
438 /* define undefined SCSI-command */
439 #define NO_SCSI 0xffff
441 /*-----------------------------------------------------------------------*/
443 /* if this is nonzero, ibmmcascsi option has been passed to the kernel */
444 static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
445 static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 };
447 /* fill module-parameters only, when this define is present.
448 (that is kernel version 2.1.x) */
449 #if defined(MODULE)
450 static char *boot_options = NULL;
451 MODULE_PARM(boot_options, "s");
452 MODULE_PARM(io_port, "1-" __MODULE_STRING(IM_MAX_HOSTS) "i");
453 MODULE_PARM(scsi_id, "1-" __MODULE_STRING(IM_MAX_HOSTS) "i");
454 MODULE_PARM(display, "1i");
455 MODULE_PARM(adisplay, "1i");
456 MODULE_PARM(normal, "1i");
457 MODULE_PARM(ansi, "1i");
458 #endif
459 /*counter of concurrent disk read/writes, to turn on/off disk led */
460 static int disk_rw_in_progress = 0;
462 /* host information */
463 static int found = 0;
464 static struct Scsi_Host *hosts[IM_MAX_HOSTS + 1] = {
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
467 static unsigned int pos[8]; /* whole pos register-line for diagnosis */
468 /* Taking into account the additions, made by ZP Gu.
469 * This selects now the preset value from the configfile and
470 * offers the 'normal' commandline option to be accepted */
471 #ifdef CONFIG_IBMMCA_SCSI_ORDER_STANDARD
472 static char ibm_ansi_order = 1;
473 #else
474 static char ibm_ansi_order = 0;
475 #endif
477 static void interrupt_handler(int, void *, struct pt_regs *);
478 static void issue_cmd(int, unsigned long, unsigned char);
479 static void internal_done(Scsi_Cmnd * cmd);
480 static void check_devices(int, int);
481 static int immediate_assign(int, unsigned int, unsigned int, unsigned int, unsigned int);
482 static int immediate_feature(int, unsigned int, unsigned int);
483 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
484 static int immediate_reset(int, unsigned int);
485 #endif
486 static int device_inquiry(int, int);
487 static int read_capacity(int, int);
488 static int get_pos_info(int);
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(int);
494 static int device_exists(int, int, int *, int *);
495 static struct Scsi_Host *ibmmca_register(Scsi_Host_Template *, int, int, int, char *);
496 static int option_setup(char *);
497 /* local functions needed for proc_info */
498 static int ldn_access_load(int, int);
499 static int ldn_access_total_read_write(int);
501 static void interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
503 int host_index, ihost_index;
504 unsigned int intr_reg;
505 unsigned int cmd_result;
506 unsigned int ldn;
507 Scsi_Cmnd *cmd;
508 int lastSCSI;
509 struct Scsi_Host *dev = dev_id;
511 spin_lock(dev->host_lock);
512 /* search for one adapter-response on shared interrupt */
513 for (host_index = 0; hosts[host_index] && !(inb(IM_STAT_REG(host_index)) & IM_INTR_REQUEST); host_index++);
514 /* return if some other device on this IRQ caused the interrupt */
515 if (!hosts[host_index]) {
516 spin_unlock(dev->host_lock);
517 return;
520 /* the reset-function already did all the job, even ints got
521 renabled on the subsystem, so just return */
522 if ((reset_status(host_index) == IM_RESET_NOT_IN_PROGRESS_NO_INT) || (reset_status(host_index) == IM_RESET_FINISHED_OK_NO_INT)) {
523 reset_status(host_index) = IM_RESET_NOT_IN_PROGRESS;
524 spin_unlock(dev->host_lock);
525 return;
528 /*must wait for attention reg not busy, then send EOI to subsystem */
529 while (1) {
530 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
531 break;
532 cpu_relax();
534 ihost_index = host_index;
535 /*get command result and logical device */
536 intr_reg = (unsigned char) (inb(IM_INTR_REG(ihost_index)));
537 cmd_result = intr_reg & 0xf0;
538 ldn = intr_reg & 0x0f;
539 /* get the last_scsi_command here */
540 lastSCSI = last_scsi_command(ihost_index)[ldn];
541 outb(IM_EOI | ldn, IM_ATTN_REG(ihost_index));
543 /*these should never happen (hw fails, or a local programming bug) */
544 if (!global_command_error_excuse) {
545 switch (cmd_result) {
546 /* Prevent from Ooopsing on error to show the real reason */
547 case IM_ADAPTER_HW_FAILURE:
548 case IM_SOFTWARE_SEQUENCING_ERROR:
549 case IM_CMD_ERROR:
550 printk(KERN_ERR "IBM MCA SCSI: Fatal Subsystem ERROR!\n");
551 printk(KERN_ERR " Last cmd=0x%x, ena=%x, len=", lastSCSI, ld(ihost_index)[ldn].scb.enable);
552 if (ld(ihost_index)[ldn].cmd)
553 printk("%ld/%ld,", (long) (ld(ihost_index)[ldn].cmd->request_bufflen), (long) (ld(ihost_index)[ldn].scb.sys_buf_length));
554 else
555 printk("none,");
556 if (ld(ihost_index)[ldn].cmd)
557 printk("Blocksize=%d", ld(ihost_index)[ldn].scb.u2.blk.length);
558 else
559 printk("Blocksize=none");
560 printk(", host=0x%x, ldn=0x%x\n", ihost_index, ldn);
561 if (ld(ihost_index)[ldn].cmd) {
562 printk(KERN_ERR "Blockcount=%d/%d\n", last_scsi_blockcount(ihost_index)[ldn], ld(ihost_index)[ldn].scb.u2.blk.count);
563 printk(KERN_ERR "Logical block=%lx/%lx\n", last_scsi_logical_block(ihost_index)[ldn], ld(ihost_index)[ldn].scb.u1.log_blk_adr);
565 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");
566 /* if errors appear, enter this section to give detailed info */
567 printk(KERN_ERR "IBM MCA SCSI: Subsystem Error-Status follows:\n");
568 printk(KERN_ERR " Command Type................: %x\n", last_scsi_type(ihost_index)[ldn]);
569 printk(KERN_ERR " Attention Register..........: %x\n", inb(IM_ATTN_REG(ihost_index)));
570 printk(KERN_ERR " Basic Control Register......: %x\n", inb(IM_CTR_REG(ihost_index)));
571 printk(KERN_ERR " Interrupt Status Register...: %x\n", intr_reg);
572 printk(KERN_ERR " Basic Status Register.......: %x\n", inb(IM_STAT_REG(ihost_index)));
573 if ((last_scsi_type(ihost_index)[ldn] == IM_SCB) || (last_scsi_type(ihost_index)[ldn] == IM_LONG_SCB)) {
574 printk(KERN_ERR " SCB-Command.................: %x\n", ld(ihost_index)[ldn].scb.command);
575 printk(KERN_ERR " SCB-Enable..................: %x\n", ld(ihost_index)[ldn].scb.enable);
576 printk(KERN_ERR " SCB-logical block address...: %lx\n", ld(ihost_index)[ldn].scb.u1.log_blk_adr);
577 printk(KERN_ERR " SCB-system buffer address...: %lx\n", ld(ihost_index)[ldn].scb.sys_buf_adr);
578 printk(KERN_ERR " SCB-system buffer length....: %lx\n", ld(ihost_index)[ldn].scb.sys_buf_length);
579 printk(KERN_ERR " SCB-tsb address.............: %lx\n", ld(ihost_index)[ldn].scb.tsb_adr);
580 printk(KERN_ERR " SCB-Chain address...........: %lx\n", ld(ihost_index)[ldn].scb.scb_chain_adr);
581 printk(KERN_ERR " SCB-block count.............: %x\n", ld(ihost_index)[ldn].scb.u2.blk.count);
582 printk(KERN_ERR " SCB-block length............: %x\n", ld(ihost_index)[ldn].scb.u2.blk.length);
584 printk(KERN_ERR " Send this report to the maintainer.\n");
585 panic("IBM MCA SCSI: Fatal error message from the subsystem (0x%X,0x%X)!\n", lastSCSI, cmd_result);
586 break;
588 } else {
589 /* The command error handling is made silent, but we tell the
590 * calling function, that there is a reported error from the
591 * adapter. */
592 switch (cmd_result) {
593 case IM_ADAPTER_HW_FAILURE:
594 case IM_SOFTWARE_SEQUENCING_ERROR:
595 case IM_CMD_ERROR:
596 global_command_error_excuse = CMD_FAIL;
597 break;
598 default:
599 global_command_error_excuse = 0;
600 break;
603 /* if no panic appeared, increase the interrupt-counter */
604 IBM_DS(ihost_index).total_interrupts++;
605 /*only for local checking phase */
606 if (local_checking_phase_flag(ihost_index)) {
607 stat_result(ihost_index) = cmd_result;
608 got_interrupt(ihost_index) = 1;
609 reset_status(ihost_index) = IM_RESET_FINISHED_OK;
610 last_scsi_command(ihost_index)[ldn] = NO_SCSI;
611 spin_unlock(dev->host_lock);
612 return;
614 /* handling of commands coming from upper level of scsi driver */
615 if (last_scsi_type(ihost_index)[ldn] == IM_IMM_CMD) {
616 /* verify ldn, and may handle rare reset immediate command */
617 if ((reset_status(ihost_index) == IM_RESET_IN_PROGRESS) && (last_scsi_command(ihost_index)[ldn] == IM_RESET_IMM_CMD)) {
618 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
619 disk_rw_in_progress = 0;
620 PS2_DISK_LED_OFF();
621 reset_status(ihost_index) = IM_RESET_FINISHED_FAIL;
622 } else {
623 /*reset disk led counter, turn off disk led */
624 disk_rw_in_progress = 0;
625 PS2_DISK_LED_OFF();
626 reset_status(ihost_index) = IM_RESET_FINISHED_OK;
628 stat_result(ihost_index) = cmd_result;
629 last_scsi_command(ihost_index)[ldn] = NO_SCSI;
630 last_scsi_type(ihost_index)[ldn] = 0;
631 spin_unlock(dev->host_lock);
632 return;
633 } else if (last_scsi_command(ihost_index)[ldn] == IM_ABORT_IMM_CMD) {
634 /* react on SCSI abort command */
635 #ifdef IM_DEBUG_PROBE
636 printk("IBM MCA SCSI: Interrupt from SCSI-abort.\n");
637 #endif
638 disk_rw_in_progress = 0;
639 PS2_DISK_LED_OFF();
640 cmd = ld(ihost_index)[ldn].cmd;
641 ld(ihost_index)[ldn].cmd = NULL;
642 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE)
643 cmd->result = DID_NO_CONNECT << 16;
644 else
645 cmd->result = DID_ABORT << 16;
646 stat_result(ihost_index) = cmd_result;
647 last_scsi_command(ihost_index)[ldn] = NO_SCSI;
648 last_scsi_type(ihost_index)[ldn] = 0;
649 if (cmd->scsi_done)
650 (cmd->scsi_done) (cmd); /* should be the internal_done */
651 spin_unlock(dev->host_lock);
652 return;
653 } else {
654 disk_rw_in_progress = 0;
655 PS2_DISK_LED_OFF();
656 reset_status(ihost_index) = IM_RESET_FINISHED_OK;
657 stat_result(ihost_index) = cmd_result;
658 last_scsi_command(ihost_index)[ldn] = NO_SCSI;
659 spin_unlock(dev->host_lock);
660 return;
663 last_scsi_command(ihost_index)[ldn] = NO_SCSI;
664 last_scsi_type(ihost_index)[ldn] = 0;
665 cmd = ld(ihost_index)[ldn].cmd;
666 ld(ihost_index)[ldn].cmd = NULL;
667 #ifdef IM_DEBUG_TIMEOUT
668 if (cmd) {
669 if ((cmd->target == TIMEOUT_PUN) && (cmd->lun == TIMEOUT_LUN)) {
670 printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", cmd->target, cmd->lun);
671 return;
674 #endif
675 /*if no command structure, just return, else clear cmd */
676 if (!cmd)
678 spin_unlock(dev->host_lock);
679 return;
682 #ifdef IM_DEBUG_INT
683 printk("cmd=%02x ireg=%02x ds=%02x cs=%02x de=%02x ce=%02x\n", cmd->cmnd[0], intr_reg, ld(ihost_index)[ldn].tsb.dev_status, ld(ihost_index)[ldn].tsb.cmd_status, ld(ihost_index)[ldn].tsb.dev_error, ld(ihost_index)[ldn].tsb.cmd_error);
684 #endif
685 /*if this is end of media read/write, may turn off PS/2 disk led */
686 if ((ld(ihost_index)[ldn].device_type != TYPE_NO_LUN) && (ld(ihost_index)[ldn].device_type != TYPE_NO_DEVICE)) {
687 /* only access this, if there was a valid device addressed */
688 if (--disk_rw_in_progress == 0)
689 PS2_DISK_LED_OFF();
692 /* IBM describes the status-mask to be 0x1e, but this is not conform
693 * with SCSI-definition, I suppose, the reason for it is that IBM
694 * adapters do not support CMD_TERMINATED, TASK_SET_FULL and
695 * ACA_ACTIVE as returning statusbyte information. (ML) */
696 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
697 cmd->result = (unsigned char) (ld(ihost_index)[ldn].tsb.dev_status & 0x1e);
698 IBM_DS(ihost_index).total_errors++;
699 } else
700 cmd->result = 0;
701 /* write device status into cmd->result, and call done function */
702 if (lastSCSI == NO_SCSI) { /* unexpected interrupt :-( */
703 cmd->result |= DID_BAD_INTR << 16;
704 printk("IBM MCA SCSI: WARNING - Interrupt from non-pending SCSI-command!\n");
705 } else /* things went right :-) */
706 cmd->result |= DID_OK << 16;
707 if (cmd->scsi_done)
708 (cmd->scsi_done) (cmd);
709 spin_unlock(dev->host_lock);
710 return;
713 static void issue_cmd(int host_index, unsigned long cmd_reg, unsigned char attn_reg)
715 unsigned long flags;
716 /* must wait for attention reg not busy */
717 while (1) {
718 spin_lock_irqsave(hosts[host_index]->host_lock, flags);
719 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
720 break;
721 spin_unlock_irqrestore(hosts[host_index]->host_lock, flags);
723 /* write registers and enable system interrupts */
724 outl(cmd_reg, IM_CMD_REG(host_index));
725 outb(attn_reg, IM_ATTN_REG(host_index));
726 spin_unlock_irqrestore(hosts[host_index]->host_lock, flags);
729 static void internal_done(Scsi_Cmnd * cmd)
731 cmd->SCp.Status++;
732 return;
735 /* SCSI-SCB-command for device_inquiry */
736 static int device_inquiry(int host_index, int ldn)
738 int retr;
739 struct im_scb *scb;
740 struct im_tsb *tsb;
741 unsigned char *buf;
743 scb = &(ld(host_index)[ldn].scb);
744 tsb = &(ld(host_index)[ldn].tsb);
745 buf = (unsigned char *) (&(ld(host_index)[ldn].buf));
746 ld(host_index)[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(host_index)[ldn] = IM_DEVICE_INQUIRY_CMD;
752 last_scsi_type(host_index)[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(host_index) = 0;
758 issue_cmd(host_index, isa_virt_to_bus(scb), IM_SCB | ldn);
759 while (!got_interrupt(host_index))
760 barrier();
762 /*if command succesful, break */
763 if ((stat_result(host_index) == IM_SCB_CMD_COMPLETED) || (stat_result(host_index) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
764 return 1;
766 /*if all three retries failed, return "no device at this ldn" */
767 if (retr >= 3)
768 return 0;
769 else
770 return 1;
773 static int read_capacity(int host_index, int ldn)
775 int retr;
776 struct im_scb *scb;
777 struct im_tsb *tsb;
778 unsigned char *buf;
780 scb = &(ld(host_index)[ldn].scb);
781 tsb = &(ld(host_index)[ldn].tsb);
782 buf = (unsigned char *) (&(ld(host_index)[ldn].buf));
783 ld(host_index)[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(host_index)[ldn] = IM_READ_CAPACITY_CMD;
789 last_scsi_type(host_index)[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(host_index) = 0;
795 issue_cmd(host_index, isa_virt_to_bus(scb), IM_SCB | ldn);
796 while (!got_interrupt(host_index))
797 barrier();
799 /*if got capacity, get block length and return one device found */
800 if ((stat_result(host_index) == IM_SCB_CMD_COMPLETED) || (stat_result(host_index) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
801 return 1;
803 /*if all three retries failed, return "no device at this ldn" */
804 if (retr >= 3)
805 return 0;
806 else
807 return 1;
810 static int get_pos_info(int host_index)
812 int retr;
813 struct im_scb *scb;
814 struct im_tsb *tsb;
815 unsigned char *buf;
817 scb = &(ld(host_index)[MAX_LOG_DEV].scb);
818 tsb = &(ld(host_index)[MAX_LOG_DEV].tsb);
819 buf = (unsigned char *) (&(ld(host_index)[MAX_LOG_DEV].buf));
820 ld(host_index)[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(host_index)[MAX_LOG_DEV] = IM_GET_POS_INFO_CMD;
826 last_scsi_type(host_index)[MAX_LOG_DEV] = IM_SCB;
827 scb->sys_buf_adr = isa_virt_to_bus(buf);
828 if (special(host_index) == 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(host_index) = 0;
835 issue_cmd(host_index, isa_virt_to_bus(scb), IM_SCB | MAX_LOG_DEV);
837 /* FIXME: timeout */
838 while (!got_interrupt(host_index))
839 barrier();
841 /*if got POS-stuff, get block length and return one device found */
842 if ((stat_result(host_index) == IM_SCB_CMD_COMPLETED) || (stat_result(host_index) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
843 return 1;
845 /* if all three retries failed, return "no device at this ldn" */
846 if (retr >= 3)
847 return 0;
848 else
849 return 1;
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(int host_index, unsigned int pun, unsigned int lun, unsigned int ldn, unsigned int operation)
857 int retr;
858 unsigned long imm_cmd;
860 for (retr = 0; retr < 3; retr++) {
861 /* select mutation level of the SCSI-adapter */
862 switch (special(host_index)) {
863 case IBM_SCSI2_FW:
864 imm_cmd = (unsigned long) (IM_ASSIGN_IMM_CMD);
865 imm_cmd |= (unsigned long) ((lun & 7) << 24);
866 imm_cmd |= (unsigned long) ((operation & 1) << 23);
867 imm_cmd |= (unsigned long) ((pun & 7) << 20) | ((pun & 8) << 24);
868 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
869 break;
870 default:
871 imm_cmd = inl(IM_CMD_REG(host_index));
872 imm_cmd &= (unsigned long) (0xF8000000); /* keep reserved bits */
873 imm_cmd |= (unsigned long) (IM_ASSIGN_IMM_CMD);
874 imm_cmd |= (unsigned long) ((lun & 7) << 24);
875 imm_cmd |= (unsigned long) ((operation & 1) << 23);
876 imm_cmd |= (unsigned long) ((pun & 7) << 20);
877 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
878 break;
880 last_scsi_command(host_index)[MAX_LOG_DEV] = IM_ASSIGN_IMM_CMD;
881 last_scsi_type(host_index)[MAX_LOG_DEV] = IM_IMM_CMD;
882 got_interrupt(host_index) = 0;
883 issue_cmd(host_index, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
884 while (!got_interrupt(host_index))
885 barrier();
887 /*if command succesful, break */
888 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
889 return 1;
891 if (retr >= 3)
892 return 0;
893 else
894 return 1;
897 static int immediate_feature(int host_index, unsigned int speed, unsigned int timeout)
899 int retr;
900 unsigned long imm_cmd;
902 for (retr = 0; retr < 3; retr++) {
903 /* select mutation level of the SCSI-adapter */
904 imm_cmd = IM_FEATURE_CTR_IMM_CMD;
905 imm_cmd |= (unsigned long) ((speed & 0x7) << 29);
906 imm_cmd |= (unsigned long) ((timeout & 0x1fff) << 16);
907 last_scsi_command(host_index)[MAX_LOG_DEV] = IM_FEATURE_CTR_IMM_CMD;
908 last_scsi_type(host_index)[MAX_LOG_DEV] = IM_IMM_CMD;
909 got_interrupt(host_index) = 0;
910 /* we need to run into command errors in order to probe for the
911 * right speed! */
912 global_command_error_excuse = 1;
913 issue_cmd(host_index, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
915 /* FIXME: timeout */
916 while (!got_interrupt(host_index))
917 barrier();
918 if (global_command_error_excuse == CMD_FAIL) {
919 global_command_error_excuse = 0;
920 return 2;
921 } else
922 global_command_error_excuse = 0;
923 /*if command succesful, break */
924 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
925 return 1;
927 if (retr >= 3)
928 return 0;
929 else
930 return 1;
933 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
934 static int immediate_reset(int host_index, unsigned int ldn)
936 int retries;
937 int ticks;
938 unsigned long imm_command;
940 for (retries = 0; retries < 3; retries++) {
941 imm_command = inl(IM_CMD_REG(host_index));
942 imm_command &= (unsigned long) (0xFFFF0000); /* keep reserved bits */
943 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
944 last_scsi_command(host_index)[ldn] = IM_RESET_IMM_CMD;
945 last_scsi_type(host_index)[ldn] = IM_IMM_CMD;
946 got_interrupt(host_index) = 0;
947 reset_status(host_index) = IM_RESET_IN_PROGRESS;
948 issue_cmd(host_index, (unsigned long) (imm_command), IM_IMM_CMD | ldn);
949 ticks = IM_RESET_DELAY * HZ;
950 while (reset_status(host_index) == IM_RESET_IN_PROGRESS && --ticks) {
951 udelay((1 + 999 / HZ) * 1000);
952 barrier();
954 /* if reset did not complete, just complain */
955 if (!ticks) {
956 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
957 reset_status(host_index) = IM_RESET_FINISHED_OK;
958 /* did not work, finish */
959 return 1;
961 /*if command succesful, break */
962 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
963 return 1;
965 if (retries >= 3)
966 return 0;
967 else
968 return 1;
970 #endif
972 /* type-interpreter for physical device numbers */
973 static char *ti_p(int dev)
975 switch (dev) {
976 case TYPE_IBM_SCSI_ADAPTER:
977 return ("A");
978 case TYPE_DISK:
979 return ("D");
980 case TYPE_TAPE:
981 return ("T");
982 case TYPE_PROCESSOR:
983 return ("P");
984 case TYPE_WORM:
985 return ("W");
986 case TYPE_ROM:
987 return ("R");
988 case TYPE_SCANNER:
989 return ("S");
990 case TYPE_MOD:
991 return ("M");
992 case TYPE_MEDIUM_CHANGER:
993 return ("C");
994 case TYPE_NO_LUN:
995 return ("+"); /* show NO_LUN */
997 return ("-"); /* TYPE_NO_DEVICE and others */
1000 /* interpreter for logical device numbers (ldn) */
1001 static char *ti_l(int val)
1003 const char hex[16] = "0123456789abcdef";
1004 static char answer[2];
1006 answer[1] = (char) (0x0);
1007 if (val <= MAX_LOG_DEV)
1008 answer[0] = hex[val];
1009 else
1010 answer[0] = '-';
1011 return (char *) &answer;
1014 /* transfers bitpattern of the feature command to values in MHz */
1015 static char *ibmrate(unsigned int speed, int i)
1017 switch (speed) {
1018 case 0:
1019 return i ? "5.00" : "10.00";
1020 case 1:
1021 return i ? "4.00" : "8.00";
1022 case 2:
1023 return i ? "3.33" : "6.66";
1024 case 3:
1025 return i ? "2.86" : "5.00";
1026 case 4:
1027 return i ? "2.50" : "4.00";
1028 case 5:
1029 return i ? "2.22" : "3.10";
1030 case 6:
1031 return i ? "2.00" : "2.50";
1032 case 7:
1033 return i ? "1.82" : "2.00";
1035 return "---";
1038 static int probe_display(int what)
1040 static int rotator = 0;
1041 const char rotor[] = "|/-\\";
1043 if (!(display_mode & LED_DISP))
1044 return 0;
1045 if (!what) {
1046 outl(0x20202020, MOD95_LED_PORT);
1047 outl(0x20202020, MOD95_LED_PORT + 4);
1048 } else {
1049 outb('S', MOD95_LED_PORT + 7);
1050 outb('C', MOD95_LED_PORT + 6);
1051 outb('S', MOD95_LED_PORT + 5);
1052 outb('I', MOD95_LED_PORT + 4);
1053 outb('i', MOD95_LED_PORT + 3);
1054 outb('n', MOD95_LED_PORT + 2);
1055 outb('i', MOD95_LED_PORT + 1);
1056 outb((char) (rotor[rotator]), MOD95_LED_PORT);
1057 rotator++;
1058 if (rotator > 3)
1059 rotator = 0;
1061 return 0;
1064 static int probe_bus_mode(int host_index)
1066 struct im_pos_info *info;
1067 int num_bus = 0;
1068 int ldn;
1070 info = (struct im_pos_info *) (&(ld(host_index)[MAX_LOG_DEV].buf));
1071 if (get_pos_info(host_index)) {
1072 if (info->connector_size & 0xf000)
1073 subsystem_connector_size(host_index) = 16;
1074 else
1075 subsystem_connector_size(host_index) = 32;
1076 num_bus |= (info->pos_4b & 8) >> 3;
1077 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1078 if ((special(host_index) == IBM_SCSI_WCACHE) || (special(host_index) == IBM_7568_WCACHE)) {
1079 if (!((info->cache_stat >> ldn) & 1))
1080 ld(host_index)[ldn].cache_flag = 0;
1082 if (!((info->retry_stat >> ldn) & 1))
1083 ld(host_index)[ldn].retry_flag = 0;
1085 #ifdef IM_DEBUG_PROBE
1086 printk("IBM MCA SCSI: SCSI-Cache bits: ");
1087 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1088 printk("%d", ld(host_index)[ldn].cache_flag);
1090 printk("\nIBM MCA SCSI: SCSI-Retry bits: ");
1091 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1092 printk("%d", ld(host_index)[ldn].retry_flag);
1094 printk("\n");
1095 #endif
1097 return num_bus;
1100 /* probing scsi devices */
1101 static void check_devices(int host_index, int adaptertype)
1103 int id, lun, ldn, ticks;
1104 int count_devices; /* local counter for connected device */
1105 int max_pun;
1106 int num_bus;
1107 int speedrun; /* local adapter_speed check variable */
1109 /* assign default values to certain variables */
1110 ticks = 0;
1111 count_devices = 0;
1112 IBM_DS(host_index).dyn_flag = 0; /* normally no need for dynamical ldn management */
1113 IBM_DS(host_index).total_errors = 0; /* set errorcounter to 0 */
1114 next_ldn(host_index) = 7; /* next ldn to be assigned is 7, because 0-6 is 'hardwired' */
1116 /* initialize the very important driver-informational arrays/structs */
1117 memset(ld(host_index), 0, sizeof(ld(host_index)));
1118 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1119 last_scsi_command(host_index)[ldn] = NO_SCSI; /* emptify last SCSI-command storage */
1120 last_scsi_type(host_index)[ldn] = 0;
1121 ld(host_index)[ldn].cache_flag = 1;
1122 ld(host_index)[ldn].retry_flag = 1;
1124 memset(get_ldn(host_index), TYPE_NO_DEVICE, sizeof(get_ldn(host_index))); /* this is essential ! */
1125 memset(get_scsi(host_index), TYPE_NO_DEVICE, sizeof(get_scsi(host_index))); /* this is essential ! */
1126 for (lun = 0; lun < 8; lun++) {
1127 /* mark the adapter at its pun on all luns */
1128 get_scsi(host_index)[subsystem_pun(host_index)][lun] = TYPE_IBM_SCSI_ADAPTER;
1129 get_ldn(host_index)[subsystem_pun(host_index)][lun] = MAX_LOG_DEV; /* make sure, the subsystem
1130 ldn is active for all
1131 luns. */
1133 probe_display(0); /* Supercool display usage during SCSI-probing. */
1134 /* This makes sense, when booting without any */
1135 /* monitor connected on model XX95. */
1137 /* STEP 1: */
1138 adapter_speed(host_index) = global_adapter_speed;
1139 speedrun = adapter_speed(host_index);
1140 while (immediate_feature(host_index, speedrun, adapter_timeout) == 2) {
1141 probe_display(1);
1142 if (speedrun == 7)
1143 panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n");
1144 speedrun++;
1145 if (speedrun > 7)
1146 speedrun = 7;
1148 adapter_speed(host_index) = speedrun;
1149 /* Get detailed information about the current adapter, necessary for
1150 * device operations: */
1151 num_bus = probe_bus_mode(host_index);
1153 /* num_bus contains only valid data for the F/W adapter! */
1154 if (adaptertype == IBM_SCSI2_FW) { /* F/W SCSI adapter: */
1155 /* F/W adapter PUN-space extension evaluation: */
1156 if (num_bus) {
1157 printk(KERN_INFO "IBM MCA SCSI: Seperate bus mode (wide-addressing enabled)\n");
1158 subsystem_maxid(host_index) = 16;
1159 } else {
1160 printk(KERN_INFO "IBM MCA SCSI: Combined bus mode (wide-addressing disabled)\n");
1161 subsystem_maxid(host_index) = 8;
1163 printk(KERN_INFO "IBM MCA SCSI: Sync.-Rate (F/W: 20, Int.: 10, Ext.: %s) MBytes/s\n", ibmrate(speedrun, adaptertype));
1164 } else /* all other IBM SCSI adapters: */
1165 printk(KERN_INFO "IBM MCA SCSI: Synchronous-SCSI-Transfer-Rate: %s MBytes/s\n", ibmrate(speedrun, adaptertype));
1167 /* assign correct PUN device space */
1168 max_pun = subsystem_maxid(host_index);
1170 #ifdef IM_DEBUG_PROBE
1171 printk("IBM MCA SCSI: Current SCSI-host index: %d\n", host_index);
1172 printk("IBM MCA SCSI: Removing default logical SCSI-device mapping.");
1173 #else
1174 printk(KERN_INFO "IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", (ibm_ansi_order) ? "ANSI" : "New");
1175 #endif
1176 for (ldn = 0; ldn < MAX_LOG_DEV; ldn++) {
1177 probe_display(1);
1178 #ifdef IM_DEBUG_PROBE
1179 printk(".");
1180 #endif
1181 immediate_assign(host_index, 0, 0, ldn, REMOVE_LDN); /* remove ldn (wherever) */
1183 lun = 0; /* default lun is 0 */
1184 #ifndef IM_DEBUG_PROBE
1185 printk("cleared,");
1186 #endif
1187 /* STEP 2: */
1188 #ifdef IM_DEBUG_PROBE
1189 printk("\nIBM MCA SCSI: Scanning SCSI-devices.");
1190 #endif
1191 for (id = 0; id < max_pun; id++)
1192 #ifdef CONFIG_SCSI_MULTI_LUN
1193 for (lun = 0; lun < 8; lun++)
1194 #endif
1196 probe_display(1);
1197 #ifdef IM_DEBUG_PROBE
1198 printk(".");
1199 #endif
1200 if (id != subsystem_pun(host_index)) {
1201 /* if pun is not the adapter: */
1202 /* set ldn=0 to pun,lun */
1203 immediate_assign(host_index, id, lun, PROBE_LDN, SET_LDN);
1204 if (device_inquiry(host_index, PROBE_LDN)) { /* probe device */
1205 get_scsi(host_index)[id][lun] = (unsigned char) (ld(host_index)[PROBE_LDN].buf[0]);
1206 /* entry, even for NO_LUN */
1207 if (ld(host_index)[PROBE_LDN].buf[0] != TYPE_NO_LUN)
1208 count_devices++; /* a existing device is found */
1210 /* remove ldn */
1211 immediate_assign(host_index, id, lun, PROBE_LDN, REMOVE_LDN);
1214 #ifndef IM_DEBUG_PROBE
1215 printk("scanned,");
1216 #endif
1217 /* STEP 3: */
1218 #ifdef IM_DEBUG_PROBE
1219 printk("\nIBM MCA SCSI: Mapping SCSI-devices.");
1220 #endif
1221 ldn = 0;
1222 lun = 0;
1223 #ifdef CONFIG_SCSI_MULTI_LUN
1224 for (lun = 0; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1225 #endif
1226 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1227 probe_display(1);
1228 #ifdef IM_DEBUG_PROBE
1229 printk(".");
1230 #endif
1231 if (id != subsystem_pun(host_index)) {
1232 if (get_scsi(host_index)[id][lun] != TYPE_NO_LUN && get_scsi(host_index)[id][lun] != TYPE_NO_DEVICE) {
1233 /* Only map if accepted type. Always enter for
1234 lun == 0 to get no gaps into ldn-mapping for ldn<7. */
1235 immediate_assign(host_index, id, lun, ldn, SET_LDN);
1236 get_ldn(host_index)[id][lun] = ldn; /* map ldn */
1237 if (device_exists(host_index, ldn, &ld(host_index)[ldn].block_length, &ld(host_index)[ldn].device_type)) {
1238 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
1239 printk("resetting device at ldn=%x ... ", ldn);
1240 immediate_reset(host_index, ldn);
1241 #endif
1242 ldn++;
1243 } else {
1244 /* device vanished, probably because we don't know how to
1245 * handle it or because it has problems */
1246 if (lun > 0) {
1247 /* remove mapping */
1248 get_ldn(host_index)[id][lun] = TYPE_NO_DEVICE;
1249 immediate_assign(host_index, 0, 0, ldn, REMOVE_LDN);
1250 } else
1251 ldn++;
1253 } else if (lun == 0) {
1254 /* map lun == 0, even if no device exists */
1255 immediate_assign(host_index, id, lun, ldn, SET_LDN);
1256 get_ldn(host_index)[id][lun] = ldn; /* map ldn */
1257 ldn++;
1261 /* STEP 4: */
1263 /* map remaining ldns to non-existing devices */
1264 for (lun = 1; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1265 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1266 if (get_scsi(host_index)[id][lun] == TYPE_NO_LUN || get_scsi(host_index)[id][lun] == TYPE_NO_DEVICE) {
1267 probe_display(1);
1268 /* Map remaining ldns only to NON-existing pun,lun
1269 combinations to make sure an inquiry will fail.
1270 For MULTI_LUN, it is needed to avoid adapter autonome
1271 SCSI-remapping. */
1272 immediate_assign(host_index, id, lun, ldn, SET_LDN);
1273 get_ldn(host_index)[id][lun] = ldn;
1274 ldn++;
1277 #ifndef IM_DEBUG_PROBE
1278 printk("mapped.");
1279 #endif
1280 printk("\n");
1281 #ifdef IM_DEBUG_PROBE
1282 if (ibm_ansi_order)
1283 printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n");
1284 else
1285 printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n");
1286 #endif
1288 #ifdef IM_DEBUG_PROBE
1289 /* Show the physical and logical mapping during boot. */
1290 printk("IBM MCA SCSI: Determined SCSI-device-mapping:\n");
1291 printk(" Physical SCSI-Device Map Logical SCSI-Device Map\n");
1292 printk("ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n");
1293 for (id = 0; id < max_pun; id++) {
1294 printk("%2d ", id);
1295 for (lun = 0; lun < 8; lun++)
1296 printk("%2s ", ti_p(get_scsi(host_index)[id][lun]));
1297 printk(" %2d ", id);
1298 for (lun = 0; lun < 8; lun++)
1299 printk("%2s ", ti_l(get_ldn(host_index)[id][lun]));
1300 printk("\n");
1302 #endif
1304 /* assign total number of found SCSI-devices to the statistics struct */
1305 IBM_DS(host_index).total_scsi_devices = count_devices;
1307 /* decide for output in /proc-filesystem, if the configuration of
1308 SCSI-devices makes dynamical reassignment of devices necessary */
1309 if (count_devices >= MAX_LOG_DEV)
1310 IBM_DS(host_index).dyn_flag = 1; /* dynamical assignment is necessary */
1311 else
1312 IBM_DS(host_index).dyn_flag = 0; /* dynamical assignment is not necessary */
1314 /* If no SCSI-devices are assigned, return 1 in order to cause message. */
1315 if (ldn == 0)
1316 printk("IBM MCA SCSI: Warning: No SCSI-devices found/assigned!\n");
1318 /* reset the counters for statistics on the current adapter */
1319 IBM_DS(host_index).scbs = 0;
1320 IBM_DS(host_index).long_scbs = 0;
1321 IBM_DS(host_index).total_accesses = 0;
1322 IBM_DS(host_index).total_interrupts = 0;
1323 IBM_DS(host_index).dynamical_assignments = 0;
1324 memset(IBM_DS(host_index).ldn_access, 0x0, sizeof(IBM_DS(host_index).ldn_access));
1325 memset(IBM_DS(host_index).ldn_read_access, 0x0, sizeof(IBM_DS(host_index).ldn_read_access));
1326 memset(IBM_DS(host_index).ldn_write_access, 0x0, sizeof(IBM_DS(host_index).ldn_write_access));
1327 memset(IBM_DS(host_index).ldn_inquiry_access, 0x0, sizeof(IBM_DS(host_index).ldn_inquiry_access));
1328 memset(IBM_DS(host_index).ldn_modeselect_access, 0x0, sizeof(IBM_DS(host_index).ldn_modeselect_access));
1329 memset(IBM_DS(host_index).ldn_assignments, 0x0, sizeof(IBM_DS(host_index).ldn_assignments));
1330 probe_display(0);
1331 return;
1334 static int device_exists(int host_index, int ldn, int *block_length, int *device_type)
1336 unsigned char *buf;
1337 /* if no valid device found, return immediately with 0 */
1338 if (!(device_inquiry(host_index, ldn)))
1339 return 0;
1340 buf = (unsigned char *) (&(ld(host_index)[ldn].buf));
1341 if (*buf == TYPE_ROM) {
1342 *device_type = TYPE_ROM;
1343 *block_length = 2048; /* (standard blocksize for yellow-/red-book) */
1344 return 1;
1346 if (*buf == TYPE_WORM) {
1347 *device_type = TYPE_WORM;
1348 *block_length = 2048;
1349 return 1;
1351 if (*buf == TYPE_DISK) {
1352 *device_type = TYPE_DISK;
1353 if (read_capacity(host_index, ldn)) {
1354 *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24);
1355 return 1;
1356 } else
1357 return 0;
1359 if (*buf == TYPE_MOD) {
1360 *device_type = TYPE_MOD;
1361 if (read_capacity(host_index, ldn)) {
1362 *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24);
1363 return 1;
1364 } else
1365 return 0;
1367 if (*buf == TYPE_TAPE) {
1368 *device_type = TYPE_TAPE;
1369 *block_length = 0; /* not in use (setting by mt and mtst in op.) */
1370 return 1;
1372 if (*buf == TYPE_PROCESSOR) {
1373 *device_type = TYPE_PROCESSOR;
1374 *block_length = 0; /* they set their stuff on drivers */
1375 return 1;
1377 if (*buf == TYPE_SCANNER) {
1378 *device_type = TYPE_SCANNER;
1379 *block_length = 0; /* they set their stuff on drivers */
1380 return 1;
1382 if (*buf == TYPE_MEDIUM_CHANGER) {
1383 *device_type = TYPE_MEDIUM_CHANGER;
1384 *block_length = 0; /* One never knows, what to expect on a medium
1385 changer device. */
1386 return 1;
1388 return 0;
1391 static void internal_ibmmca_scsi_setup(char *str, int *ints)
1393 int i, j, io_base, id_base;
1394 char *token;
1396 io_base = 0;
1397 id_base = 0;
1398 if (str) {
1399 token = strtok(str, ",");
1400 j = 0;
1401 while (token) {
1402 if (!strcmp(token, "activity"))
1403 display_mode |= LED_ACTIVITY;
1404 if (!strcmp(token, "display"))
1405 display_mode |= LED_DISP;
1406 if (!strcmp(token, "adisplay"))
1407 display_mode |= LED_ADISP;
1408 if (!strcmp(token, "normal"))
1409 ibm_ansi_order = 0;
1410 if (!strcmp(token, "ansi"))
1411 ibm_ansi_order = 1;
1412 if (!strcmp(token, "fast"))
1413 global_adapter_speed = 0;
1414 if (!strcmp(token, "medium"))
1415 global_adapter_speed = 4;
1416 if (!strcmp(token, "slow"))
1417 global_adapter_speed = 7;
1418 if ((*token == '-') || (isdigit(*token))) {
1419 if (!(j % 2) && (io_base < IM_MAX_HOSTS))
1420 io_port[io_base++] = simple_strtoul(token, NULL, 0);
1421 if ((j % 2) && (id_base < IM_MAX_HOSTS))
1422 scsi_id[id_base++] = simple_strtoul(token, NULL, 0);
1423 j++;
1425 token = strtok(NULL, ",");
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];
1433 return;
1436 static int ibmmca_getinfo(char *buf, int slot, void *dev_id)
1438 struct Scsi_Host *shpnt;
1439 int len, speciale, connectore, k;
1440 unsigned int pos[8];
1441 unsigned long flags;
1442 struct Scsi_Host *dev = dev_id;
1444 spin_lock_irqsave(dev->host_lock, flags);
1446 shpnt = dev; /* assign host-structure to local pointer */
1447 len = 0; /* set filled text-buffer index to 0 */
1448 /* get the _special contents of the hostdata structure */
1449 speciale = ((struct ibmmca_hostdata *) shpnt->hostdata)->_special;
1450 connectore = ((struct ibmmca_hostdata *) shpnt->hostdata)->_connector_size;
1451 for (k = 2; k < 4; k++)
1452 pos[k] = ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k];
1453 if (speciale == FORCED_DETECTION) { /* forced detection */
1454 len += sprintf(buf + len,
1455 "Adapter category: forced detected\n" "***************************************\n" "*** Forced detected SCSI Adapter ***\n" "*** No chip-information available ***\n" "***************************************\n");
1456 } else if (speciale == INTEGRATED_SCSI) {
1457 /* if the integrated subsystem has been found automatically: */
1458 len += sprintf(buf + len,
1459 "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");
1460 } else if ((speciale >= 0) && (speciale < (sizeof(subsys_list) / sizeof(struct subsys_list_struct)))) {
1461 /* if the subsystem is a slot adapter */
1462 len += sprintf(buf + len, "Adapter category: slot-card\n" "ROM Segment Address: ");
1463 if ((pos[2] & 0xf0) == 0xf0)
1464 len += sprintf(buf + len, "off\n");
1465 else
1466 len += sprintf(buf + len, "0x%x\n", ((pos[2] & 0xf0) << 13) + 0xc0000);
1467 len += sprintf(buf + len, "Chip status: %s\n", (pos[2] & 1) ? "enabled" : "disabled");
1468 len += sprintf(buf + len, "Adapter I/O Offset: 0x%x\n", ((pos[2] & 0x0e) << 2));
1469 } else {
1470 len += sprintf(buf + len, "Adapter category: unknown\n");
1472 /* common subsystem information to write to the slotn file */
1473 len += sprintf(buf + len, "Subsystem PUN: %d\n", shpnt->this_id);
1474 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));
1475 len += sprintf(buf + len, "MCA-slot size: %d bits", connectore);
1476 /* Now make sure, the bufferlength is devidable by 4 to avoid
1477 * paging problems of the buffer. */
1478 while (len % sizeof(int) != (sizeof(int) - 1))
1479 len += sprintf(buf + len, " ");
1480 len += sprintf(buf + len, "\n");
1482 spin_unlock_irqrestore(shpnt->host_lock, flags);
1484 return len;
1487 int ibmmca_detect(Scsi_Host_Template * scsi_template)
1489 struct Scsi_Host *shpnt;
1490 int port, id, i, j, k, list_size, slot;
1491 int devices_on_irq_11 = 0;
1492 int devices_on_irq_14 = 0;
1493 int IRQ14_registered = 0;
1494 int IRQ11_registered = 0;
1496 found = 0; /* make absolutely sure, that found is set to 0 */
1498 /* First of all, print the version number of the driver. This is
1499 * important to allow better user bugreports in case of already
1500 * having problems with the MCA_bus probing. */
1501 printk(KERN_INFO "IBM MCA SCSI: Version %s\n", IBMMCA_SCSI_DRIVER_VERSION);
1502 /* if this is not MCA machine, return "nothing found" */
1503 if (!MCA_bus) {
1504 printk(KERN_INFO "IBM MCA SCSI: No Microchannel-bus present --> Aborting.\n" " This machine does not have any IBM MCA-bus\n" " or the MCA-Kernel-support is not enabled!\n");
1505 return 0;
1508 #ifdef MODULE
1509 /* If the driver is run as module, read from conf.modules or cmd-line */
1510 if (boot_options)
1511 option_setup(boot_options);
1512 #endif
1514 /* get interrupt request level */
1515 if (request_irq(IM_IRQ, interrupt_handler, SA_SHIRQ, "ibmmcascsi", hosts)) {
1516 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ);
1517 return 0;
1518 } else
1519 IRQ14_registered++;
1521 /* if ibmmcascsi setup option was passed to kernel, return "found" */
1522 for (i = 0; i < IM_MAX_HOSTS; i++)
1523 if (io_port[i] > 0 && scsi_id[i] >= 0 && scsi_id[i] < 8) {
1524 printk("IBM MCA SCSI: forced detected SCSI Adapter, io=0x%x, scsi id=%d.\n", io_port[i], scsi_id[i]);
1525 if ((shpnt = ibmmca_register(scsi_template, io_port[i], scsi_id[i], FORCED_DETECTION, "forced detected SCSI Adapter"))) {
1526 for (k = 2; k < 7; k++)
1527 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = 0;
1528 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = FORCED_DETECTION;
1529 mca_set_adapter_name(MCA_INTEGSCSI, "forced detected SCSI Adapter");
1530 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1531 mca_mark_as_used(MCA_INTEGSCSI);
1532 devices_on_irq_14++;
1535 if (found)
1536 return found;
1538 /* The POS2-register of all PS/2 model SCSI-subsystems has the following
1539 * interpretation of bits:
1540 * Bit 7 - 4 : Chip Revision ID (Release)
1541 * Bit 3 - 2 : Reserved
1542 * Bit 1 : 8k NVRAM Disabled
1543 * Bit 0 : Chip Enable (EN-Signal)
1544 * The POS3-register is interpreted as follows:
1545 * Bit 7 - 5 : SCSI ID
1546 * Bit 4 : Reserved = 0
1547 * Bit 3 - 0 : Reserved = 0
1548 * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common
1549 * Interfaces (1991)").
1550 * In short words, this means, that IBM PS/2 machines only support
1551 * 1 single subsystem by default. The slot-adapters must have another
1552 * configuration on pos2. Here, one has to assume the following
1553 * things for POS2-register:
1554 * Bit 7 - 4 : Chip Revision ID (Release)
1555 * Bit 3 - 1 : port offset factor
1556 * Bit 0 : Chip Enable (EN-Signal)
1557 * As I found a patch here, setting the IO-registers to 0x3540 forced,
1558 * as there was a 0x05 in POS2 on a model 56, I assume, that the
1559 * port 0x3540 must be fix for integrated SCSI-controllers.
1560 * Ok, this discovery leads to the following implementation: (M.Lang) */
1562 /* first look for the IBM SCSI integrated subsystem on the motherboard */
1563 for (j = 0; j < 8; j++) /* read the pos-information */
1564 pos[j] = mca_read_stored_pos(MCA_INTEGSCSI, j);
1565 /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but
1566 * if we ignore the settings of all surrounding pos registers, it is not
1567 * completely sufficient to only check pos2 and pos3. */
1568 /* Therefore, now the following if statement is used to
1569 * make sure, we see a real integrated onboard SCSI-interface and no
1570 * internal system information, which gets mapped to some pos registers
1571 * on models 95xx. */
1572 if ((!pos[0] && !pos[1] && pos[2] > 0 && pos[3] > 0 && !pos[4] && !pos[5] && !pos[6] && !pos[7]) || (pos[0] == 0xff && pos[1] == 0xff && pos[2] < 0xff && pos[3] < 0xff && pos[4] == 0xff && pos[5] == 0xff && pos[6] == 0xff && pos[7] == 0xff)) {
1573 if ((pos[2] & 1) == 1) /* is the subsystem chip enabled ? */
1574 port = IM_IO_PORT;
1575 else { /* if disabled, no IRQs will be generated, as the chip won't
1576 * listen to the incoming commands and will do really nothing,
1577 * except for listening to the pos-register settings. If this
1578 * happens, I need to hugely think about it, as one has to
1579 * write something to the MCA-Bus pos register in order to
1580 * enable the chip. Normally, IBM-SCSI won't pass the POST,
1581 * when the chip is disabled (see IBM tech. ref.). */
1582 port = IM_IO_PORT; /* anyway, set the portnumber and warn */
1583 printk("IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n" " SCSI-operations may not work.\n");
1585 id = (pos[3] & 0xe0) >> 5; /* this is correct and represents the PUN */
1586 /* give detailed information on the subsystem. This helps me
1587 * additionally during debugging and analyzing bug-reports. */
1588 printk(KERN_INFO "IBM MCA SCSI: IBM Integrated SCSI Controller ffound, io=0x%x, scsi id=%d,\n", port, id);
1589 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.");
1591 /* register the found integrated SCSI-subsystem */
1592 if ((shpnt = ibmmca_register(scsi_template, port, id, INTEGRATED_SCSI, "IBM Integrated SCSI Controller")))
1594 for (k = 2; k < 7; k++)
1595 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1596 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = INTEGRATED_SCSI;
1597 mca_set_adapter_name(MCA_INTEGSCSI, "IBM Integrated SCSI Controller");
1598 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1599 mca_mark_as_used(MCA_INTEGSCSI);
1600 devices_on_irq_14++;
1604 /* now look for other adapters in MCA slots, */
1605 /* determine the number of known IBM-SCSI-subsystem types */
1606 /* see the pos[2] dependence to get the adapter port-offset. */
1607 list_size = sizeof(subsys_list) / sizeof(struct subsys_list_struct);
1608 for (i = 0; i < list_size; i++) {
1609 /* scan each slot for a fitting adapter id */
1610 slot = 0; /* start at slot 0 */
1611 while ((slot = mca_find_adapter(subsys_list[i].mca_id, slot))
1612 != MCA_NOTFOUND) { /* scan through all slots */
1613 for (j = 0; j < 8; j++) /* read the pos-information */
1614 pos[j] = mca_read_stored_pos(slot, j);
1615 if ((pos[2] & 1) == 1)
1616 /* is the subsystem chip enabled ? */
1617 /* (explanations see above) */
1618 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1619 else {
1620 /* anyway, set the portnumber and warn */
1621 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1622 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1623 printk(KERN_WARNING " SCSI-operations may not work.\n");
1625 if ((i == IBM_SCSI2_FW) && (pos[6] != 0)) {
1626 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1627 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1628 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1629 id = 7;
1630 } else {
1631 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1632 if (i == IBM_SCSI2_FW) {
1633 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1634 * for F/W adapters */
1637 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0)) {
1638 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1639 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1640 /* get interrupt request level */
1641 if (request_irq(IM_IRQ_FW, interrupt_handler, SA_SHIRQ, "ibmmcascsi", hosts)) {
1642 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ_FW);
1643 } else
1644 IRQ11_registered++;
1646 printk(KERN_INFO "IBM MCA SCSI: %s found in slot %d, io=0x%x, scsi id=%d,\n", subsys_list[i].description, slot + 1, port, id);
1647 if ((pos[2] & 0xf0) == 0xf0)
1648 printk(KERN_DEBUG" ROM Addr.=off,");
1649 else
1650 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
1651 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
1653 /* register the hostadapter */
1654 if ((shpnt = ibmmca_register(scsi_template, port, id, i, subsys_list[i].description))) {
1655 for (k = 2; k < 8; k++)
1656 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1657 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = i;
1658 mca_set_adapter_name(slot, subsys_list[i].description);
1659 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1660 mca_mark_as_used(slot);
1661 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0))
1662 devices_on_irq_11++;
1663 else
1664 devices_on_irq_14++;
1666 slot++; /* advance to next slot */
1667 } /* advance to next adapter id in the list of IBM-SCSI-subsystems */
1670 /* now check for SCSI-adapters, mapped to the integrated SCSI
1671 * area. E.g. a W/Cache in MCA-slot 9(!). Do the check correct here,
1672 * as this is a known effect on some models 95xx. */
1673 list_size = sizeof(subsys_list) / sizeof(struct subsys_list_struct);
1674 for (i = 0; i < list_size; i++) {
1675 /* scan each slot for a fitting adapter id */
1676 slot = mca_find_adapter(subsys_list[i].mca_id, MCA_INTEGSCSI);
1677 if (slot != MCA_NOTFOUND) { /* scan through all slots */
1678 for (j = 0; j < 8; j++) /* read the pos-information */
1679 pos[j] = mca_read_stored_pos(slot, j);
1680 if ((pos[2] & 1) == 1) { /* is the subsystem chip enabled ? */
1681 /* (explanations see above) */
1682 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1683 } else { /* anyway, set the portnumber and warn */
1684 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1685 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1686 printk(KERN_WARNING " SCSI-operations may not work.\n");
1688 if ((i == IBM_SCSI2_FW) && (pos[6] != 0)) {
1689 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1690 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1691 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1692 id = 7;
1693 } else {
1694 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1695 if (i == IBM_SCSI2_FW)
1696 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1697 * for F/W adapters */
1699 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0)) {
1700 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1701 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1702 /* get interrupt request level */
1703 if (request_irq(IM_IRQ_FW, interrupt_handler, SA_SHIRQ, "ibmmcascsi", hosts))
1704 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ_FW);
1705 else
1706 IRQ11_registered++;
1708 printk(KERN_INFO "IBM MCA SCSI: %s found in slot %d, io=0x%x, scsi id=%d,\n", subsys_list[i].description, slot + 1, port, id);
1709 if ((pos[2] & 0xf0) == 0xf0)
1710 printk(KERN_DEBUG " ROM Addr.=off,");
1711 else
1712 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
1713 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
1715 /* register the hostadapter */
1716 if ((shpnt = ibmmca_register(scsi_template, port, id, i, subsys_list[i].description))) {
1717 for (k = 2; k < 7; k++)
1718 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1719 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = i;
1720 mca_set_adapter_name(slot, subsys_list[i].description);
1721 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1722 mca_mark_as_used(slot);
1723 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0))
1724 devices_on_irq_11++;
1725 else
1726 devices_on_irq_14++;
1728 slot++; /* advance to next slot */
1729 } /* advance to next adapter id in the list of IBM-SCSI-subsystems */
1731 if (IRQ11_registered && !devices_on_irq_11)
1732 free_irq(IM_IRQ_FW, hosts); /* no devices on IRQ 11 */
1733 if (IRQ14_registered && !devices_on_irq_14)
1734 free_irq(IM_IRQ, hosts); /* no devices on IRQ 14 */
1735 if (!devices_on_irq_11 && !devices_on_irq_14)
1736 printk(KERN_WARNING "IBM MCA SCSI: No IBM SCSI-subsystem adapter attached.\n");
1737 return found; /* return the number of found SCSI hosts. Should be 1 or 0. */
1740 static struct Scsi_Host *ibmmca_register(Scsi_Host_Template * scsi_template, int port, int id, int adaptertype, char *hostname)
1742 struct Scsi_Host *shpnt;
1743 int i, j;
1744 unsigned int ctrl;
1746 /* check I/O region */
1747 if (!request_region(port, IM_N_IO_PORT, hostname)) {
1748 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);
1749 return NULL;
1752 /* register host */
1753 shpnt = scsi_register(scsi_template, sizeof(struct ibmmca_hostdata));
1754 if (!shpnt) {
1755 printk(KERN_ERR "IBM MCA SCSI: Unable to register host.\n");
1756 release_region(port, IM_N_IO_PORT);
1757 return NULL;
1760 /* request I/O region */
1761 hosts[found] = shpnt; /* add new found hostadapter to the list */
1762 special(found) = adaptertype; /* important assignment or else crash! */
1763 subsystem_connector_size(found) = 0; /* preset slot-size */
1764 shpnt->irq = IM_IRQ; /* assign necessary stuff for the adapter */
1765 shpnt->io_port = port;
1766 shpnt->n_io_port = IM_N_IO_PORT;
1767 shpnt->this_id = id;
1768 shpnt->max_id = 8; /* 8 PUNs are default */
1769 /* now, the SCSI-subsystem is connected to Linux */
1771 ctrl = (unsigned int) (inb(IM_CTR_REG(found))); /* get control-register status */
1772 #ifdef IM_DEBUG_PROBE
1773 printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", ctrl, inb(IM_STAT_REG(found)));
1774 printk("IBM MCA SCSI: This adapters' POS-registers: ");
1775 for (i = 0; i < 8; i++)
1776 printk("%x ", pos[i]);
1777 printk("\n");
1778 #endif
1779 reset_status(found) = IM_RESET_NOT_IN_PROGRESS;
1781 for (i = 0; i < 16; i++) /* reset the tables */
1782 for (j = 0; j < 8; j++)
1783 get_ldn(found)[i][j] = MAX_LOG_DEV;
1785 /* check which logical devices exist */
1786 /* after this line, local interrupting is possible: */
1787 local_checking_phase_flag(found) = 1;
1788 check_devices(found, adaptertype); /* call by value, using the global variable hosts */
1789 local_checking_phase_flag(found) = 0;
1790 found++; /* now increase index to be prepared for next found subsystem */
1791 /* an ibm mca subsystem has been detected */
1792 return shpnt;
1795 static int ibmmca_command(Scsi_Cmnd * cmd)
1797 ibmmca_queuecommand(cmd, internal_done);
1798 cmd->SCp.Status = 0;
1799 while (!cmd->SCp.Status)
1800 barrier();
1801 return cmd->result;
1804 static int ibmmca_release(struct Scsi_Host *shpnt)
1806 release_region(shpnt->io_port, shpnt->n_io_port);
1807 if (!(--found))
1808 free_irq(shpnt->irq, hosts);
1809 return 0;
1812 /* The following routine is the SCSI command queue for the midlevel driver */
1813 static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1815 unsigned int ldn;
1816 unsigned int scsi_cmd;
1817 struct im_scb *scb;
1818 struct Scsi_Host *shpnt;
1819 int current_ldn;
1820 int id, lun;
1821 int target;
1822 int host_index;
1823 int max_pun;
1824 int i;
1825 struct scatterlist *sl;
1827 shpnt = cmd->host;
1828 /* search for the right hostadapter */
1829 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
1831 if (!hosts[host_index]) { /* invalid hostadapter descriptor address */
1832 cmd->result = DID_NO_CONNECT << 16;
1833 if (done)
1834 done(cmd);
1835 return 0;
1837 max_pun = subsystem_maxid(host_index);
1838 if (ibm_ansi_order) {
1839 target = max_pun - 1 - cmd->target;
1840 if ((target <= subsystem_pun(host_index)) && (cmd->target <= subsystem_pun(host_index)))
1841 target--;
1842 else if ((target >= subsystem_pun(host_index)) && (cmd->target >= subsystem_pun(host_index)))
1843 target++;
1844 } else
1845 target = cmd->target;
1847 /* if (target,lun) is NO LUN or not existing at all, return error */
1848 if ((get_scsi(host_index)[target][cmd->lun] == TYPE_NO_LUN) || (get_scsi(host_index)[target][cmd->lun] == TYPE_NO_DEVICE)) {
1849 cmd->result = DID_NO_CONNECT << 16;
1850 if (done)
1851 done(cmd);
1852 return 0;
1855 /*if (target,lun) unassigned, do further checks... */
1856 ldn = get_ldn(host_index)[target][cmd->lun];
1857 if (ldn >= MAX_LOG_DEV) { /* on invalid ldn do special stuff */
1858 if (ldn > MAX_LOG_DEV) { /* dynamical remapping if ldn unassigned */
1859 current_ldn = next_ldn(host_index); /* stop-value for one circle */
1860 while (ld(host_index)[next_ldn(host_index)].cmd) { /* search for a occupied, but not in */
1861 /* command-processing ldn. */
1862 next_ldn(host_index)++;
1863 if (next_ldn(host_index) >= MAX_LOG_DEV)
1864 next_ldn(host_index) = 7;
1865 if (current_ldn == next_ldn(host_index)) { /* One circle done ? */
1866 /* no non-processing ldn found */
1867 printk("IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n" " On ldn 7-14 SCSI-commands everywhere in progress.\n" " Reporting DID_NO_CONNECT for device (%d,%d).\n", target, cmd->lun);
1868 cmd->result = DID_NO_CONNECT << 16; /* return no connect */
1869 if (done)
1870 done(cmd);
1871 return 0;
1875 /* unmap non-processing ldn */
1876 for (id = 0; id < max_pun; id++)
1877 for (lun = 0; lun < 8; lun++) {
1878 if (get_ldn(host_index)[id][lun] == next_ldn(host_index)) {
1879 get_ldn(host_index)[id][lun] = TYPE_NO_DEVICE;
1880 get_scsi(host_index)[id][lun] = TYPE_NO_DEVICE;
1881 /* unmap entry */
1884 /* set reduced interrupt_handler-mode for checking */
1885 local_checking_phase_flag(host_index) = 1;
1886 /* map found ldn to pun,lun */
1887 get_ldn(host_index)[target][cmd->lun] = next_ldn(host_index);
1888 /* change ldn to the right value, that is now next_ldn */
1889 ldn = next_ldn(host_index);
1890 /* unassign all ldns (pun,lun,ldn does not matter for remove) */
1891 immediate_assign(host_index, 0, 0, 0, REMOVE_LDN);
1892 /* set only LDN for remapped device */
1893 immediate_assign(host_index, target, cmd->lun, ldn, SET_LDN);
1894 /* get device information for ld[ldn] */
1895 if (device_exists(host_index, ldn, &ld(host_index)[ldn].block_length, &ld(host_index)[ldn].device_type)) {
1896 ld(host_index)[ldn].cmd = NULL; /* To prevent panic set 0, because
1897 devices that were not assigned,
1898 should have nothing in progress. */
1899 get_scsi(host_index)[target][cmd->lun] = ld(host_index)[ldn].device_type;
1900 /* increase assignment counters for statistics in /proc */
1901 IBM_DS(host_index).dynamical_assignments++;
1902 IBM_DS(host_index).ldn_assignments[ldn]++;
1903 } else
1904 /* panic here, because a device, found at boottime has
1905 vanished */
1906 panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", ldn, target, cmd->lun);
1907 /* unassign again all ldns (pun,lun,ldn does not matter for remove) */
1908 immediate_assign(host_index, 0, 0, 0, REMOVE_LDN);
1909 /* remap all ldns, as written in the pun/lun table */
1910 lun = 0;
1911 #ifdef CONFIG_SCSI_MULTI_LUN
1912 for (lun = 0; lun < 8; lun++)
1913 #endif
1914 for (id = 0; id < max_pun; id++) {
1915 if (get_ldn(host_index)[id][lun] <= MAX_LOG_DEV)
1916 immediate_assign(host_index, id, lun, get_ldn(host_index)[id][lun], SET_LDN);
1918 /* set back to normal interrupt_handling */
1919 local_checking_phase_flag(host_index) = 0;
1920 #ifdef IM_DEBUG_PROBE
1921 /* Information on syslog terminal */
1922 printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", ldn, target, cmd->lun);
1923 #endif
1924 /* increase next_ldn for next dynamical assignment */
1925 next_ldn(host_index)++;
1926 if (next_ldn(host_index) >= MAX_LOG_DEV)
1927 next_ldn(host_index) = 7;
1928 } else { /* wall against Linux accesses to the subsystem adapter */
1929 cmd->result = DID_BAD_TARGET << 16;
1930 if (done)
1931 done(cmd);
1932 return 0;
1936 /*verify there is no command already in progress for this log dev */
1937 if (ld(host_index)[ldn].cmd)
1938 panic("IBM MCA SCSI: cmd already in progress for this ldn.\n");
1940 /*save done in cmd, and save cmd for the interrupt handler */
1941 cmd->scsi_done = done;
1942 ld(host_index)[ldn].cmd = cmd;
1944 /*fill scb information independent of the scsi command */
1945 scb = &(ld(host_index)[ldn].scb);
1946 ld(host_index)[ldn].tsb.dev_status = 0;
1947 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE;
1948 scb->tsb_adr = isa_virt_to_bus(&(ld(host_index)[ldn].tsb));
1949 scsi_cmd = cmd->cmnd[0];
1951 if (cmd->use_sg) {
1952 i = cmd->use_sg;
1953 sl = (struct scatterlist *) (cmd->request_buffer);
1954 if (i > 16)
1955 panic("IBM MCA SCSI: scatter-gather list too long.\n");
1956 while (--i >= 0) {
1957 ld(host_index)[ldn].sge[i].address = (void *) (isa_page_to_bus(sl[i].page) + sl[i].offset);
1958 ld(host_index)[ldn].sge[i].byte_length = sl[i].length;
1960 scb->enable |= IM_POINTER_TO_LIST;
1961 scb->sys_buf_adr = isa_virt_to_bus(&(ld(host_index)[ldn].sge[0]));
1962 scb->sys_buf_length = cmd->use_sg * sizeof(struct im_sge);
1963 } else {
1964 scb->sys_buf_adr = isa_virt_to_bus(cmd->request_buffer);
1965 /* recent Linux midlevel SCSI places 1024 byte for inquiry
1966 * command. Far too much for old PS/2 hardware. */
1967 switch (scsi_cmd) {
1968 /* avoid command errors by setting bufferlengths to
1969 * ANSI-standard. Beware of forcing it to 255,
1970 * this could SEGV the kernel!!! */
1971 case INQUIRY:
1972 case REQUEST_SENSE:
1973 case MODE_SENSE:
1974 case MODE_SELECT:
1975 if (cmd->request_bufflen > 255)
1976 scb->sys_buf_length = 255;
1977 else
1978 scb->sys_buf_length = cmd->request_bufflen;
1979 break;
1980 case TEST_UNIT_READY:
1981 scb->sys_buf_length = 0;
1982 break;
1983 default:
1984 scb->sys_buf_length = cmd->request_bufflen;
1985 break;
1988 /*fill scb information dependent on scsi command */
1990 #ifdef IM_DEBUG_CMD
1991 printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd, ldn);
1992 #endif
1994 /* for specific device-type debugging: */
1995 #ifdef IM_DEBUG_CMD_SPEC_DEV
1996 if (ld(host_index)[ldn].device_type == IM_DEBUG_CMD_DEVICE)
1997 printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", ld(host_index)[ldn].device_type, scsi_cmd, ldn);
1998 #endif
2000 /* for possible panics store current command */
2001 last_scsi_command(host_index)[ldn] = scsi_cmd;
2002 last_scsi_type(host_index)[ldn] = IM_SCB;
2003 /* update statistical info */
2004 IBM_DS(host_index).total_accesses++;
2005 IBM_DS(host_index).ldn_access[ldn]++;
2007 switch (scsi_cmd) {
2008 case READ_6:
2009 case WRITE_6:
2010 case READ_10:
2011 case WRITE_10:
2012 case READ_12:
2013 case WRITE_12:
2014 /* Distinguish between disk and other devices. Only disks (that are the
2015 most frequently accessed devices) should be supported by the
2016 IBM-SCSI-Subsystem commands. */
2017 switch (ld(host_index)[ldn].device_type) {
2018 case TYPE_DISK: /* for harddisks enter here ... */
2019 case TYPE_MOD: /* ... try it also for MO-drives (send flames as */
2020 /* you like, if this won't work.) */
2021 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) {
2022 /* read command preparations */
2023 scb->enable |= IM_READ_CONTROL;
2024 IBM_DS(host_index).ldn_read_access[ldn]++; /* increase READ-access on ldn stat. */
2025 scb->command = IM_READ_DATA_CMD | IM_NO_DISCONNECT;
2026 } else { /* write command preparations */
2027 IBM_DS(host_index).ldn_write_access[ldn]++; /* increase write-count on ldn stat. */
2028 scb->command = IM_WRITE_DATA_CMD | IM_NO_DISCONNECT;
2030 if (scsi_cmd == READ_6 || scsi_cmd == WRITE_6) {
2031 scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[3]) << 0) | (((unsigned) cmd->cmnd[2]) << 8) | ((((unsigned) cmd->cmnd[1]) & 0x1f) << 16);
2032 scb->u2.blk.count = (unsigned) cmd->cmnd[4];
2033 } else {
2034 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);
2035 scb->u2.blk.count = (((unsigned) cmd->cmnd[8]) << 0) | (((unsigned) cmd->cmnd[7]) << 8);
2037 last_scsi_logical_block(host_index)[ldn] = scb->u1.log_blk_adr;
2038 last_scsi_blockcount(host_index)[ldn] = scb->u2.blk.count;
2039 scb->u2.blk.length = ld(host_index)[ldn].block_length;
2040 break;
2041 /* for other devices, enter here. Other types are not known by
2042 Linux! TYPE_NO_LUN is forbidden as valid device. */
2043 case TYPE_ROM:
2044 case TYPE_TAPE:
2045 case TYPE_PROCESSOR:
2046 case TYPE_WORM:
2047 case TYPE_SCANNER:
2048 case TYPE_MEDIUM_CHANGER:
2049 /* If there is a sequential-device, IBM recommends to use
2050 IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE.
2051 This includes CD-ROM devices, too, due to the partial sequential
2052 read capabilities. */
2053 scb->command = IM_OTHER_SCSI_CMD_CMD;
2054 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12)
2055 /* enable READ */
2056 scb->enable |= IM_READ_CONTROL;
2057 scb->enable |= IM_BYPASS_BUFFER;
2058 scb->u1.scsi_cmd_length = cmd->cmd_len;
2059 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2060 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2061 /* Read/write on this non-disk devices is also displayworthy,
2062 so flash-up the LED/display. */
2063 break;
2065 break;
2066 case INQUIRY:
2067 IBM_DS(host_index).ldn_inquiry_access[ldn]++;
2068 scb->command = IM_DEVICE_INQUIRY_CMD;
2069 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2070 scb->u1.log_blk_adr = 0;
2071 break;
2072 case TEST_UNIT_READY:
2073 scb->command = IM_OTHER_SCSI_CMD_CMD;
2074 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2075 scb->u1.log_blk_adr = 0;
2076 scb->u1.scsi_cmd_length = 6;
2077 memcpy(scb->u2.scsi_command, cmd->cmnd, 6);
2078 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2079 break;
2080 case READ_CAPACITY:
2081 /* the length of system memory buffer must be exactly 8 bytes */
2082 scb->command = IM_READ_CAPACITY_CMD;
2083 scb->enable |= IM_READ_CONTROL | IM_BYPASS_BUFFER;
2084 if (scb->sys_buf_length > 8)
2085 scb->sys_buf_length = 8;
2086 break;
2087 /* Commands that need read-only-mode (system <- device): */
2088 case REQUEST_SENSE:
2089 scb->command = IM_REQUEST_SENSE_CMD;
2090 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2091 break;
2092 /* Commands that need write-only-mode (system -> device): */
2093 case MODE_SELECT:
2094 case MODE_SELECT_10:
2095 IBM_DS(host_index).ldn_modeselect_access[ldn]++;
2096 scb->command = IM_OTHER_SCSI_CMD_CMD;
2097 scb->enable |= IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; /*Select needs WRITE-enabled */
2098 scb->u1.scsi_cmd_length = cmd->cmd_len;
2099 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2100 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2101 break;
2102 /* For other commands, read-only is useful. Most other commands are
2103 running without an input-data-block. */
2104 default:
2105 scb->command = IM_OTHER_SCSI_CMD_CMD;
2106 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2107 scb->u1.scsi_cmd_length = cmd->cmd_len;
2108 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2109 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2110 break;
2112 /*issue scb command, and return */
2113 if (++disk_rw_in_progress == 1)
2114 PS2_DISK_LED_ON(shpnt->host_no, target);
2116 if (last_scsi_type(host_index)[ldn] == IM_LONG_SCB) {
2117 issue_cmd(host_index, isa_virt_to_bus(scb), IM_LONG_SCB | ldn);
2118 IBM_DS(host_index).long_scbs++;
2119 } else {
2120 issue_cmd(host_index, isa_virt_to_bus(scb), IM_SCB | ldn);
2121 IBM_DS(host_index).scbs++;
2123 return 0;
2126 static int ibmmca_abort(Scsi_Cmnd * cmd)
2128 /* Abort does not work, as the adapter never generates an interrupt on
2129 * whatever situation is simulated, even when really pending commands
2130 * are running on the adapters' hardware ! */
2132 struct Scsi_Host *shpnt;
2133 unsigned int ldn;
2134 void (*saved_done) (Scsi_Cmnd *);
2135 int target;
2136 int host_index;
2137 int max_pun;
2138 unsigned long imm_command;
2140 #ifdef IM_DEBUG_PROBE
2141 printk("IBM MCA SCSI: Abort subroutine called...\n");
2142 #endif
2144 shpnt = cmd->host;
2145 /* search for the right hostadapter */
2146 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
2148 if (!hosts[host_index]) { /* invalid hostadapter descriptor address */
2149 cmd->result = DID_NO_CONNECT << 16;
2150 if (cmd->scsi_done)
2151 (cmd->scsi_done) (cmd);
2152 shpnt = cmd->host;
2153 #ifdef IM_DEBUG_PROBE
2154 printk(KERN_DEBUG "IBM MCA SCSI: Abort adapter selection failed!\n");
2155 #endif
2156 return SUCCESS;
2158 max_pun = subsystem_maxid(host_index);
2159 if (ibm_ansi_order) {
2160 target = max_pun - 1 - cmd->target;
2161 if ((target <= subsystem_pun(host_index)) && (cmd->target <= subsystem_pun(host_index)))
2162 target--;
2163 else if ((target >= subsystem_pun(host_index)) && (cmd->target >= subsystem_pun(host_index)))
2164 target++;
2165 } else
2166 target = cmd->target;
2168 /* get logical device number, and disable system interrupts */
2169 printk(KERN_WARNING "IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", target, cmd->lun);
2170 ldn = get_ldn(host_index)[target][cmd->lun];
2172 /*if cmd for this ldn has already finished, no need to abort */
2173 if (!ld(host_index)[ldn].cmd) {
2174 return SUCCESS;
2177 /* Clear ld.cmd, save done function, install internal done,
2178 * send abort immediate command (this enables sys. interrupts),
2179 * and wait until the interrupt arrives.
2181 saved_done = cmd->scsi_done;
2182 cmd->scsi_done = internal_done;
2183 cmd->SCp.Status = 0;
2184 last_scsi_command(host_index)[ldn] = IM_ABORT_IMM_CMD;
2185 last_scsi_type(host_index)[ldn] = IM_IMM_CMD;
2186 imm_command = inl(IM_CMD_REG(host_index));
2187 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2188 imm_command |= (unsigned long) (IM_ABORT_IMM_CMD);
2189 /* must wait for attention reg not busy */
2190 /* FIXME - timeout, politeness */
2191 while (1) {
2192 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
2193 break;
2195 /* write registers and enable system interrupts */
2196 outl(imm_command, IM_CMD_REG(host_index));
2197 outb(IM_IMM_CMD | ldn, IM_ATTN_REG(host_index));
2198 #ifdef IM_DEBUG_PROBE
2199 printk("IBM MCA SCSI: Abort queued to adapter...\n");
2200 #endif
2201 spin_unlock_irq(shpnt->host_lock);
2202 while (!cmd->SCp.Status)
2203 yield();
2204 spin_lock_irq(shpnt->host_lock);
2205 cmd->scsi_done = saved_done;
2206 #ifdef IM_DEBUG_PROBE
2207 printk("IBM MCA SCSI: Abort returned with adapter response...\n");
2208 #endif
2210 /*if abort went well, call saved done, then return success or error */
2211 if (cmd->result == (DID_ABORT << 16))
2213 cmd->result |= DID_ABORT << 16;
2214 if (cmd->scsi_done)
2215 (cmd->scsi_done) (cmd);
2216 ld(host_index)[ldn].cmd = NULL;
2217 #ifdef IM_DEBUG_PROBE
2218 printk("IBM MCA SCSI: Abort finished with success.\n");
2219 #endif
2220 return SUCCESS;
2221 } else {
2222 cmd->result |= DID_NO_CONNECT << 16;
2223 if (cmd->scsi_done)
2224 (cmd->scsi_done) (cmd);
2225 ld(host_index)[ldn].cmd = NULL;
2226 #ifdef IM_DEBUG_PROBE
2227 printk("IBM MCA SCSI: Abort failed.\n");
2228 #endif
2229 return FAILED;
2233 static int ibmmca_host_reset(Scsi_Cmnd * cmd)
2235 struct Scsi_Host *shpnt;
2236 Scsi_Cmnd *cmd_aid;
2237 int ticks, i;
2238 int host_index;
2239 unsigned long imm_command;
2241 if (cmd == NULL)
2242 BUG();
2244 ticks = IM_RESET_DELAY * HZ;
2245 shpnt = cmd->host;
2246 /* search for the right hostadapter */
2247 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
2249 if (!hosts[host_index]) /* invalid hostadapter descriptor address */
2250 return FAILED;
2252 if (local_checking_phase_flag(host_index)) {
2253 printk(KERN_WARNING "IBM MCA SCSI: unable to reset while checking devices.\n");
2254 return FAILED;
2257 /* issue reset immediate command to subsystem, and wait for interrupt */
2258 printk("IBM MCA SCSI: resetting all devices.\n");
2259 reset_status(host_index) = IM_RESET_IN_PROGRESS;
2260 last_scsi_command(host_index)[0xf] = IM_RESET_IMM_CMD;
2261 last_scsi_type(host_index)[0xf] = IM_IMM_CMD;
2262 imm_command = inl(IM_CMD_REG(host_index));
2263 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2264 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
2265 /* must wait for attention reg not busy */
2266 while (1) {
2267 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
2268 break;
2269 spin_unlock_irq(shpnt->host_lock);
2270 yield();
2271 spin_lock_irq(shpnt->host_lock);
2273 /*write registers and enable system interrupts */
2274 outl(imm_command, IM_CMD_REG(host_index));
2275 outb(IM_IMM_CMD | 0xf, IM_ATTN_REG(host_index));
2276 /* wait for interrupt finished or intr_stat register to be set, as the
2277 * interrupt will not be executed, while we are in here! */
2279 /* FIXME: This is really really icky we so want a sleeping version of this ! */
2280 while (reset_status(host_index) == IM_RESET_IN_PROGRESS && --ticks && ((inb(IM_INTR_REG(host_index)) & 0x8f) != 0x8f)) {
2281 udelay((1 + 999 / HZ) * 1000);
2282 barrier();
2284 /* if reset did not complete, just return an error */
2285 if (!ticks) {
2286 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
2287 reset_status(host_index) = IM_RESET_FINISHED_FAIL;
2288 return FAILED;
2291 if ((inb(IM_INTR_REG(host_index)) & 0x8f) == 0x8f) {
2292 /* analysis done by this routine and not by the intr-routine */
2293 if (inb(IM_INTR_REG(host_index)) == 0xaf)
2294 reset_status(host_index) = IM_RESET_FINISHED_OK_NO_INT;
2295 else if (inb(IM_INTR_REG(host_index)) == 0xcf)
2296 reset_status(host_index) = IM_RESET_FINISHED_FAIL;
2297 else /* failed, 4get it */
2298 reset_status(host_index) = IM_RESET_NOT_IN_PROGRESS_NO_INT;
2299 outb(IM_EOI | 0xf, IM_ATTN_REG(host_index));
2302 /* if reset failed, just return an error */
2303 if (reset_status(host_index) == IM_RESET_FINISHED_FAIL) {
2304 printk(KERN_ERR "IBM MCA SCSI: reset failed.\n");
2305 return FAILED;
2308 /* so reset finished ok - call outstanding done's, and return success */
2309 printk(KERN_INFO "IBM MCA SCSI: Reset successfully completed.\n");
2310 for (i = 0; i < MAX_LOG_DEV; i++) {
2311 cmd_aid = ld(host_index)[i].cmd;
2312 if (cmd_aid && cmd_aid->scsi_done) {
2313 ld(host_index)[i].cmd = NULL;
2314 cmd_aid->result = DID_RESET << 16;
2317 return SUCCESS;
2320 static int ibmmca_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *info)
2322 int size = capacity;
2323 info[0] = 64;
2324 info[1] = 32;
2325 info[2] = size / (info[0] * info[1]);
2326 if (info[2] >= 1024) {
2327 info[0] = 128;
2328 info[1] = 63;
2329 info[2] = size / (info[0] * info[1]);
2330 if (info[2] >= 1024) {
2331 info[0] = 255;
2332 info[1] = 63;
2333 info[2] = size / (info[0] * info[1]);
2334 if (info[2] >= 1024)
2335 info[2] = 1023;
2338 return 0;
2341 /* calculate percentage of total accesses on a ldn */
2342 static int ldn_access_load(int host_index, int ldn)
2344 if (IBM_DS(host_index).total_accesses == 0)
2345 return (0);
2346 if (IBM_DS(host_index).ldn_access[ldn] == 0)
2347 return (0);
2348 return (IBM_DS(host_index).ldn_access[ldn] * 100) / IBM_DS(host_index).total_accesses;
2351 /* calculate total amount of r/w-accesses */
2352 static int ldn_access_total_read_write(int host_index)
2354 int a;
2355 int i;
2357 a = 0;
2358 for (i = 0; i <= MAX_LOG_DEV; i++)
2359 a += IBM_DS(host_index).ldn_read_access[i] + IBM_DS(host_index).ldn_write_access[i];
2360 return (a);
2363 static int ldn_access_total_inquiry(int host_index)
2365 int a;
2366 int i;
2368 a = 0;
2369 for (i = 0; i <= MAX_LOG_DEV; i++)
2370 a += IBM_DS(host_index).ldn_inquiry_access[i];
2371 return (a);
2374 static int ldn_access_total_modeselect(int host_index)
2376 int a;
2377 int i;
2379 a = 0;
2380 for (i = 0; i <= MAX_LOG_DEV; i++)
2381 a += IBM_DS(host_index).ldn_modeselect_access[i];
2382 return (a);
2385 /* routine to display info in the proc-fs-structure (a deluxe feature) */
2386 static int ibmmca_proc_info(char *buffer, char **start, off_t offset, int length, int hostno, int inout)
2388 int len = 0;
2389 int i, id, lun, host_index;
2390 struct Scsi_Host *shpnt;
2391 unsigned long flags;
2392 int max_pun;
2394 for (i = 0; hosts[i] && hosts[i]->host_no != hostno; i++);
2396 spin_lock_irqsave(hosts[i]->host_lock, flags); /* Check it */
2397 shpnt = hosts[i];
2398 host_index = i;
2399 if (!shpnt) {
2400 len += sprintf(buffer + len, "\nIBM MCA SCSI: Can't find adapter for host number %d\n", hostno);
2401 return len;
2403 max_pun = subsystem_maxid(host_index);
2405 len += sprintf(buffer + len, "\n IBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", IBMMCA_SCSI_DRIVER_VERSION);
2406 len += sprintf(buffer + len, " SCSI Access-Statistics:\n");
2407 len += sprintf(buffer + len, " Device Scanning Order....: %s\n", (ibm_ansi_order) ? "IBM/ANSI" : "New Industry Standard");
2408 #ifdef CONFIG_SCSI_MULTI_LUN
2409 len += sprintf(buffer + len, " Multiple LUN probing.....: Yes\n");
2410 #else
2411 len += sprintf(buffer + len, " Multiple LUN probing.....: No\n");
2412 #endif
2413 len += sprintf(buffer + len, " This Hostnumber..........: %d\n", hostno);
2414 len += sprintf(buffer + len, " Base I/O-Port............: 0x%x\n", (unsigned int) (IM_CMD_REG(host_index)));
2415 len += sprintf(buffer + len, " (Shared) IRQ.............: %d\n", IM_IRQ);
2416 len += sprintf(buffer + len, " Total Interrupts.........: %d\n", IBM_DS(host_index).total_interrupts);
2417 len += sprintf(buffer + len, " Total SCSI Accesses......: %d\n", IBM_DS(host_index).total_accesses);
2418 len += sprintf(buffer + len, " Total short SCBs.........: %d\n", IBM_DS(host_index).scbs);
2419 len += sprintf(buffer + len, " Total long SCBs..........: %d\n", IBM_DS(host_index).long_scbs);
2420 len += sprintf(buffer + len, " Total SCSI READ/WRITE..: %d\n", ldn_access_total_read_write(host_index));
2421 len += sprintf(buffer + len, " Total SCSI Inquiries...: %d\n", ldn_access_total_inquiry(host_index));
2422 len += sprintf(buffer + len, " Total SCSI Modeselects.: %d\n", ldn_access_total_modeselect(host_index));
2423 len += sprintf(buffer + len, " Total SCSI other cmds..: %d\n", IBM_DS(host_index).total_accesses - ldn_access_total_read_write(host_index)
2424 - ldn_access_total_modeselect(host_index)
2425 - ldn_access_total_inquiry(host_index));
2426 len += sprintf(buffer + len, " Total SCSI command fails.: %d\n\n", IBM_DS(host_index).total_errors);
2427 len += sprintf(buffer + len, " Logical-Device-Number (LDN) Access-Statistics:\n");
2428 len += sprintf(buffer + len, " LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n");
2429 len += sprintf(buffer + len, " -----|--------------|-----------|-----------|--------------\n");
2430 for (i = 0; i <= MAX_LOG_DEV; i++)
2431 len += sprintf(buffer + len, " %2X | %3d | %8d | %8d | %8d\n", i, ldn_access_load(host_index, i), IBM_DS(host_index).ldn_read_access[i], IBM_DS(host_index).ldn_write_access[i], IBM_DS(host_index).ldn_assignments[i]);
2432 len += sprintf(buffer + len, " -----------------------------------------------------------\n\n");
2433 len += sprintf(buffer + len, " Dynamical-LDN-Assignment-Statistics:\n");
2434 len += sprintf(buffer + len, " Number of physical SCSI-devices..: %d (+ Adapter)\n", IBM_DS(host_index).total_scsi_devices);
2435 len += sprintf(buffer + len, " Dynamical Assignment necessary...: %s\n", IBM_DS(host_index).dyn_flag ? "Yes" : "No ");
2436 len += sprintf(buffer + len, " Next LDN to be assigned..........: 0x%x\n", next_ldn(host_index));
2437 len += sprintf(buffer + len, " Dynamical assignments done yet...: %d\n", IBM_DS(host_index).dynamical_assignments);
2438 len += sprintf(buffer + len, "\n Current SCSI-Device-Mapping:\n");
2439 len += sprintf(buffer + len, " Physical SCSI-Device Map Logical SCSI-Device Map\n");
2440 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");
2441 for (id = 0; id < max_pun; id++) {
2442 len += sprintf(buffer + len, " %2d ", id);
2443 for (lun = 0; lun < 8; lun++)
2444 len += sprintf(buffer + len, "%2s ", ti_p(get_scsi(host_index)[id][lun]));
2445 len += sprintf(buffer + len, " %2d ", id);
2446 for (lun = 0; lun < 8; lun++)
2447 len += sprintf(buffer + len, "%2s ", ti_l(get_ldn(host_index)[id][lun]));
2448 len += sprintf(buffer + len, "\n");
2451 len += sprintf(buffer + len, "(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n");
2452 len += sprintf(buffer + len, " R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n");
2453 len += sprintf(buffer + len, " - = nothing found, nothing assigned or unprobed LUN)\n\n");
2455 *start = buffer + offset;
2456 len -= offset;
2457 if (len > length)
2458 len = length;
2459 spin_unlock_irqrestore(shpnt->host_lock, flags);
2460 return len;
2463 static void ibmmca_scsi_setup(char *str, int *ints)
2465 internal_ibmmca_scsi_setup(str, ints);
2468 static int option_setup(char *str)
2470 int ints[IM_MAX_HOSTS];
2471 char *cur = str;
2472 int i = 1;
2474 while (cur && isdigit(*cur) && i <= IM_MAX_HOSTS) {
2475 ints[i++] = simple_strtoul(cur, NULL, 0);
2476 if ((cur = strchr(cur, ',')) != NULL)
2477 cur++;
2479 ints[0] = i - 1;
2480 internal_ibmmca_scsi_setup(cur, ints);
2481 return 0;
2484 __setup("ibmmcascsi=", option_setup);
2486 static Scsi_Host_Template driver_template = IBMMCA;
2488 #include "scsi_module.c"