2 Low Level Linux Driver for the IBM Microchannel SCSI Subsystem for
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
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 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/ctype.h>
24 #include <linux/string.h>
25 #include <linux/interrupt.h>
26 #include <linux/ioport.h>
27 #include <linux/delay.h>
28 #include <linux/blkdev.h>
29 #include <linux/proc_fs.h>
30 #include <linux/stat.h>
31 #include <linux/mca.h>
32 #include <linux/spinlock.h>
33 #include <linux/init.h>
34 #include <linux/mca-legacy.h>
36 #include <asm/system.h>
40 #include <scsi/scsi_host.h>
43 /* current version of this driver-source: */
44 #define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac"
46 /* driver configuration */
47 #define IM_MAX_HOSTS 8 /* maximum number of host adapters */
48 #define IM_RESET_DELAY 60 /* seconds allowed for a reset */
50 /* driver debugging - #undef all for normal operation */
51 /* if defined: count interrupts and ignore this special one: */
52 #undef IM_DEBUG_TIMEOUT //50
55 /* verbose interrupt: */
57 /* verbose queuecommand: */
59 /* verbose queucommand for specific SCSI-device type: */
60 #undef IM_DEBUG_CMD_SPEC_DEV
61 /* verbose device probing */
64 /* device type that shall be displayed on syslog (only during debugging): */
65 #define IM_DEBUG_CMD_DEVICE TYPE_TAPE
67 /* relative addresses of hardware registers on a subsystem */
68 #define IM_CMD_REG(hi) (hosts[(hi)]->io_port) /*Command Interface, (4 bytes long) */
69 #define IM_ATTN_REG(hi) (hosts[(hi)]->io_port+4) /*Attention (1 byte) */
70 #define IM_CTR_REG(hi) (hosts[(hi)]->io_port+5) /*Basic Control (1 byte) */
71 #define IM_INTR_REG(hi) (hosts[(hi)]->io_port+6) /*Interrupt Status (1 byte, r/o) */
72 #define IM_STAT_REG(hi) (hosts[(hi)]->io_port+7) /*Basic Status (1 byte, read only) */
74 /* basic I/O-port of first adapter */
75 #define IM_IO_PORT 0x3540
76 /* maximum number of hosts that can be found */
77 #define IM_N_IO_PORT 8
79 /*requests going into the upper nibble of the Attention register */
80 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
81 #define IM_IMM_CMD 0x10 /*immediate command */
82 #define IM_SCB 0x30 /*Subsystem Control Block command */
83 #define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */
84 #define IM_EOI 0xe0 /*end-of-interrupt request */
86 /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */
87 #define IM_HW_RESET 0x80 /*hardware reset */
88 #define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */
89 #define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */
91 /*to interpret the upper nibble of Interrupt Status register */
92 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
93 #define IM_SCB_CMD_COMPLETED 0x10
94 #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50
95 #define IM_LOOP_SCATTER_BUFFER_FULL 0x60
96 #define IM_ADAPTER_HW_FAILURE 0x70
97 #define IM_IMMEDIATE_CMD_COMPLETED 0xa0
98 #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0
99 #define IM_CMD_ERROR 0xe0
100 #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0
102 /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */
103 #define IM_CMD_REG_FULL 0x08
104 #define IM_CMD_REG_EMPTY 0x04
105 #define IM_INTR_REQUEST 0x02
108 /*immediate commands (word written into low 2 bytes of command reg) */
109 #define IM_RESET_IMM_CMD 0x0400
110 #define IM_FEATURE_CTR_IMM_CMD 0x040c
111 #define IM_DMA_PACING_IMM_CMD 0x040d
112 #define IM_ASSIGN_IMM_CMD 0x040e
113 #define IM_ABORT_IMM_CMD 0x040f
114 #define IM_FORMAT_PREP_IMM_CMD 0x0417
116 /*SCB (Subsystem Control Block) structure */
118 unsigned short command; /*command word (read, etc.) */
119 unsigned short enable; /*enable word, modifies cmd */
121 unsigned long log_blk_adr; /*block address on SCSI device */
122 unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */
124 unsigned long sys_buf_adr; /*physical system memory adr */
125 unsigned long sys_buf_length; /*size of sys mem buffer */
126 unsigned long tsb_adr; /*Termination Status Block adr */
127 unsigned long scb_chain_adr; /*optional SCB chain address */
130 unsigned short count; /*block count, on SCSI device */
131 unsigned short length; /*block length, on SCSI device */
133 unsigned char scsi_command[12]; /*other scsi command */
137 /*structure scatter-gather element (for list of system memory areas) */
140 unsigned long byte_length;
143 /*structure returned by a get_pos_info command: */
145 unsigned short pos_id; /* adapter id */
146 unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */
147 unsigned char pos_2; /* pos 2 */
148 unsigned char int_level; /* interrupt level IRQ 11 or 14 */
149 unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */
150 unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */
151 unsigned char num_luns; /* number of supported luns per device */
152 unsigned char num_puns; /* number of supported puns */
153 unsigned char pacing_factor; /* pacing factor */
154 unsigned char num_ldns; /* number of ldns available */
155 unsigned char eoi_off; /* time EOI and interrupt inactive */
156 unsigned char max_busy; /* time between reset and busy on */
157 unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */
158 unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */
159 unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */
160 unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */
161 unsigned char pos_6; /* pos 6 */
162 unsigned char pos_5; /* pos 5 */
163 unsigned short max_overlap; /* maximum overlapping requests */
164 unsigned short num_bus; /* number of SCSI-busses */
167 /*values for SCB command word */
168 #define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */
169 #define IM_NO_DISCONNECT 0x0080 /*flag for any command */
170 #define IM_READ_DATA_CMD 0x1c01
171 #define IM_WRITE_DATA_CMD 0x1c02
172 #define IM_READ_VERIFY_CMD 0x1c03
173 #define IM_WRITE_VERIFY_CMD 0x1c04
174 #define IM_REQUEST_SENSE_CMD 0x1c08
175 #define IM_READ_CAPACITY_CMD 0x1c09
176 #define IM_DEVICE_INQUIRY_CMD 0x1c0b
177 #define IM_READ_LOGICAL_CMD 0x1c2a
178 #define IM_OTHER_SCSI_CMD_CMD 0x241f
180 /* unused, but supported, SCB commands */
181 #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */
182 #define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */
183 #define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */
184 #define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */
185 #define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */
187 /*values to set bits in the enable word of SCB */
188 #define IM_READ_CONTROL 0x8000
189 #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000
190 #define IM_RETRY_ENABLE 0x2000
191 #define IM_POINTER_TO_LIST 0x1000
192 #define IM_SUPRESS_EXCEPTION_SHORT 0x0400
193 #define IM_BYPASS_BUFFER 0x0200
194 #define IM_CHAIN_ON_NO_ERROR 0x0001
196 /*TSB (Termination Status Block) structure */
198 unsigned short end_status;
199 unsigned short reserved1;
200 unsigned long residual_byte_count;
201 unsigned long sg_list_element_adr;
202 unsigned short status_length;
203 unsigned char dev_status;
204 unsigned char cmd_status;
205 unsigned char dev_error;
206 unsigned char cmd_error;
207 unsigned short reserved2;
208 unsigned short reserved3;
209 unsigned short low_of_last_scb_adr;
210 unsigned short high_of_last_scb_adr;
213 /*subsystem uses interrupt request level 14 */
215 /*SCSI-2 F/W may evade to interrupt 11 */
218 /* Model 95 has an additional alphanumeric display, which can be used
219 to display SCSI-activities. 8595 models do not have any disk led, which
220 makes this feature quite useful.
221 The regular PS/2 disk led is turned on/off by bits 6,7 of system
224 /* LED display-port (actually, last LED on display) */
225 #define MOD95_LED_PORT 0x108
226 /* system-control-register of PS/2s with diskindicator */
227 #define PS2_SYS_CTR 0x92
228 /* activity displaying methods */
231 #define LED_ACTIVITY 4
235 /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED
236 displays. ldn is no longer displayed here, because the ldn mapping is now
237 done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime
238 or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble,
239 interest, debugging or just for having fun. The left number gives the
240 host-adapter number and the right shows the accessed SCSI-ID. */
242 /* display_mode is set by the ibmmcascsi= command line arg */
243 static int display_mode = 0;
244 /* set default adapter timeout */
245 static unsigned int adapter_timeout = 45;
246 /* for probing on feature-command: */
247 static unsigned int global_command_error_excuse = 0;
248 /* global setting by command line for adapter_speed */
249 static int global_adapter_speed = 0; /* full speed by default */
251 /* Panel / LED on, do it right for F/W addressin, too. adisplay will
252 * just ignore ids>7, as the panel has only 7 digits available */
253 #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \
254 outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \
255 outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \
256 if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \
257 outb((char)(ad+48), MOD95_LED_PORT); } \
258 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
259 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); }
261 /* Panel / LED off */
262 /* bug fixed, Dec 15, 1997, where | was replaced by & here */
263 #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \
264 outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \
265 outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \
266 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
267 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); }
269 /*list of supported subsystems */
270 struct subsys_list_struct {
271 unsigned short mca_id;
275 /* types of different supported hardware that goes to hostdata special */
276 #define IBM_SCSI2_FW 0
277 #define IBM_7568_WCACHE 1
278 #define IBM_EXP_UNIT 2
279 #define IBM_SCSI_WCACHE 3
282 /* other special flags for hostdata structure */
283 #define FORCED_DETECTION 100
284 #define INTEGRATED_SCSI 101
286 /* List of possible IBM-SCSI-adapters */
287 static struct subsys_list_struct subsys_list[] = {
288 {0x8efc, "IBM SCSI-2 F/W Adapter"}, /* special = 0 */
289 {0x8efd, "IBM 7568 Industrial Computer SCSI Adapter w/Cache"}, /* special = 1 */
290 {0x8ef8, "IBM Expansion Unit SCSI Controller"}, /* special = 2 */
291 {0x8eff, "IBM SCSI Adapter w/Cache"}, /* special = 3 */
292 {0x8efe, "IBM SCSI Adapter"}, /* special = 4 */
295 /* Max number of logical devices (can be up from 0 to 14). 15 is the address
296 of the adapter itself. */
297 #define MAX_LOG_DEV 15
299 /*local data for a logical device */
300 struct logical_device {
301 struct im_scb scb; /* SCSI-subsystem-control-block structure */
302 struct im_tsb tsb; /* SCSI command complete status block structure */
303 struct im_sge sge[16]; /* scatter gather list structure */
304 unsigned char buf[256]; /* SCSI command return data buffer */
305 Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */
306 int device_type; /* type of the SCSI-device. See include/scsi/scsi.h
307 for interpretation of the possible values */
308 int block_length; /* blocksize of a particular logical SCSI-device */
309 int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */
310 int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */
313 /* statistics of the driver during operations (for proc_info) */
314 struct Driver_Statistics {
315 /* SCSI statistics on the adapter */
316 int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */
317 int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */
318 int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */
319 int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */
320 int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */
321 int scbs; /* short SCBs queued */
322 int long_scbs; /* long SCBs queued */
323 int total_accesses; /* total accesses on all ldns */
324 int total_interrupts; /* total interrupts (should be
325 same as total_accesses) */
326 int total_errors; /* command completed with error */
327 /* dynamical assignment statistics */
328 int total_scsi_devices; /* number of physical pun,lun */
329 int dyn_flag; /* flag showing dynamical mode */
330 int dynamical_assignments; /* number of remappings of ldns */
331 int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each
335 /* data structure for each host adapter */
336 struct ibmmca_hostdata {
337 /* array of logical devices: */
338 struct logical_device _ld[MAX_LOG_DEV + 1];
339 /* array to convert (pun, lun) into logical device number: */
340 unsigned char _get_ldn[16][8];
341 /*array that contains the information about the physical SCSI-devices
342 attached to this host adapter: */
343 unsigned char _get_scsi[16][8];
344 /* used only when checking logical devices: */
345 int _local_checking_phase_flag;
346 /* report received interrupt: */
348 /* report termination-status of SCSI-command: */
350 /* reset status (used only when doing reset): */
352 /* code of the last SCSI command (needed for panic info): */
353 int _last_scsi_command[MAX_LOG_DEV + 1];
354 /* identifier of the last SCSI-command type */
355 int _last_scsi_type[MAX_LOG_DEV + 1];
356 /* last blockcount */
357 int _last_scsi_blockcount[MAX_LOG_DEV + 1];
358 /* last locgical block address */
359 unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1];
360 /* Counter that points on the next reassignable ldn for dynamical
361 remapping. The default value is 7, that is the first reassignable
362 number in the list at boottime: */
364 /* Statistics-structure for this IBM-SCSI-host: */
365 struct Driver_Statistics _IBM_DS;
366 /* This hostadapters pos-registers pos2 until pos6 */
367 unsigned int _pos[8];
368 /* assign a special variable, that contains dedicated info about the
371 /* connector size on the MCA bus */
373 /* synchronous SCSI transfer rate bitpattern */
377 /* macros to access host data structure */
378 #define subsystem_pun(hi) (hosts[(hi)]->this_id)
379 #define subsystem_maxid(hi) (hosts[(hi)]->max_id)
380 #define ld(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_ld)
381 #define get_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_ldn)
382 #define get_scsi(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_scsi)
383 #define local_checking_phase_flag(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_local_checking_phase_flag)
384 #define got_interrupt(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_got_interrupt)
385 #define stat_result(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_stat_result)
386 #define reset_status(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_reset_status)
387 #define last_scsi_command(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_command)
388 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
389 #define last_scsi_blockcount(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_blockcount)
390 #define last_scsi_logical_block(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_logical_block)
391 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
392 #define next_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_next_ldn)
393 #define IBM_DS(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_IBM_DS)
394 #define special(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_special)
395 #define subsystem_connector_size(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_connector_size)
396 #define adapter_speed(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_adapter_speed)
397 #define pos2(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[2])
398 #define pos3(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[3])
399 #define pos4(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[4])
400 #define pos5(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[5])
401 #define pos6(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[6])
403 /* Define a arbitrary number as subsystem-marker-type. This number is, as
404 described in the ANSI-SCSI-standard, not occupied by other device-types. */
405 #define TYPE_IBM_SCSI_ADAPTER 0x2F
407 /* Define 0xFF for no device type, because this type is not defined within
408 the ANSI-SCSI-standard, therefore, it can be used and should not cause any
410 #define TYPE_NO_DEVICE 0xFF
412 /* define medium-changer. If this is not defined previously, e.g. Linux
413 2.0.x, define this type here. */
414 #ifndef TYPE_MEDIUM_CHANGER
415 #define TYPE_MEDIUM_CHANGER 0x08
418 /* define possible operations for the immediate_assign command */
422 /* ldn which is used to probe the SCSI devices */
425 /* reset status flag contents */
426 #define IM_RESET_NOT_IN_PROGRESS 0
427 #define IM_RESET_IN_PROGRESS 1
428 #define IM_RESET_FINISHED_OK 2
429 #define IM_RESET_FINISHED_FAIL 3
430 #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4
431 #define IM_RESET_FINISHED_OK_NO_INT 5
433 /* define undefined SCSI-command */
434 #define NO_SCSI 0xffff
436 /*-----------------------------------------------------------------------*/
438 /* if this is nonzero, ibmmcascsi option has been passed to the kernel */
439 static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
440 static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 };
442 /* fill module-parameters only, when this define is present.
443 (that is kernel version 2.1.x) */
445 static char *boot_options = NULL;
446 module_param(boot_options, charp, 0);
447 module_param_array(io_port, int, NULL, 0);
448 module_param_array(scsi_id, int, NULL, 0);
450 #if 0 /* FIXME: No longer exist? --RR */
451 MODULE_PARM(display, "1i");
452 MODULE_PARM(adisplay, "1i");
453 MODULE_PARM(normal, "1i");
454 MODULE_PARM(ansi, "1i");
457 MODULE_LICENSE("GPL");
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;
474 static char ibm_ansi_order = 0;
477 static void issue_cmd(int, unsigned long, unsigned char);
478 static void internal_done(Scsi_Cmnd * cmd);
479 static void check_devices(int, int);
480 static int immediate_assign(int, unsigned int, unsigned int, unsigned int, unsigned int);
481 static int immediate_feature(int, unsigned int, unsigned int);
482 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
483 static int immediate_reset(int, unsigned int);
485 static int device_inquiry(int, int);
486 static int read_capacity(int, int);
487 static int get_pos_info(int);
488 static char *ti_p(int);
489 static char *ti_l(int);
490 static char *ibmrate(unsigned int, int);
491 static int probe_display(int);
492 static int probe_bus_mode(int);
493 static int device_exists(int, int, int *, int *);
494 static struct Scsi_Host *ibmmca_register(struct scsi_host_template *, int, int, int, char *);
495 static int option_setup(char *);
496 /* local functions needed for proc_info */
497 static int ldn_access_load(int, int);
498 static int ldn_access_total_read_write(int);
500 static irqreturn_t interrupt_handler(int irq, void *dev_id,
501 struct pt_regs *regs)
503 int host_index, ihost_index;
504 unsigned int intr_reg;
505 unsigned int cmd_result;
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);
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);
528 /*must wait for attention reg not busy, then send EOI to subsystem */
530 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
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:
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));
556 if (ld(ihost_index)[ldn].cmd)
557 printk("Blocksize=%d", ld(ihost_index)[ldn].scb.u2.blk.length);
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);
589 /* The command error handling is made silent, but we tell the
590 * calling function, that there is a reported error from the
592 switch (cmd_result) {
593 case IM_ADAPTER_HW_FAILURE:
594 case IM_SOFTWARE_SEQUENCING_ERROR:
596 global_command_error_excuse = CMD_FAIL;
599 global_command_error_excuse = 0;
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);
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;
621 reset_status(ihost_index) = IM_RESET_FINISHED_FAIL;
623 /*reset disk led counter, turn off disk led */
624 disk_rw_in_progress = 0;
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);
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");
638 disk_rw_in_progress = 0;
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;
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;
650 (cmd->scsi_done) (cmd); /* should be the internal_done */
651 spin_unlock(dev->host_lock);
654 disk_rw_in_progress = 0;
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);
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
669 if ((cmd->target == TIMEOUT_PUN) && (cmd->device->lun == TIMEOUT_LUN)) {
670 printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", cmd->target, cmd->device->lun);
675 /*if no command structure, just return, else clear cmd */
678 spin_unlock(dev->host_lock);
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);
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)
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++;
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;
708 (cmd->scsi_done) (cmd);
709 spin_unlock(dev->host_lock);
713 static void issue_cmd(int host_index, unsigned long cmd_reg, unsigned char attn_reg)
716 /* must wait for attention reg not busy */
718 spin_lock_irqsave(hosts[host_index]->host_lock, flags);
719 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
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)
735 /* SCSI-SCB-command for device_inquiry */
736 static int device_inquiry(int host_index, int ldn)
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))
762 /*if command successful, break */
763 if ((stat_result(host_index) == IM_SCB_CMD_COMPLETED) || (stat_result(host_index) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
766 /*if all three retries failed, return "no device at this ldn" */
773 static int read_capacity(int host_index, int ldn)
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))
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))
803 /*if all three retries failed, return "no device at this ldn" */
810 static int get_pos_info(int host_index)
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 */
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);
838 while (!got_interrupt(host_index))
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))
845 /* if all three retries failed, return "no device at this ldn" */
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)
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)) {
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);
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);
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))
887 /*if command successful, break */
888 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
897 static int immediate_feature(int host_index, unsigned int speed, unsigned int timeout)
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
912 global_command_error_excuse = 1;
913 issue_cmd(host_index, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
916 while (!got_interrupt(host_index))
918 if (global_command_error_excuse == CMD_FAIL) {
919 global_command_error_excuse = 0;
922 global_command_error_excuse = 0;
923 /*if command successful, break */
924 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
933 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
934 static int immediate_reset(int host_index, unsigned int ldn)
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);
954 /* if reset did not complete, just complain */
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 */
961 /*if command successful, break */
962 if (stat_result(host_index) == IM_IMMEDIATE_CMD_COMPLETED)
972 /* type-interpreter for physical device numbers */
973 static char *ti_p(int dev)
976 case TYPE_IBM_SCSI_ADAPTER:
992 case TYPE_MEDIUM_CHANGER:
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];
1011 return (char *) &answer;
1014 /* transfers bitpattern of the feature command to values in MHz */
1015 static char *ibmrate(unsigned int speed, int i)
1019 return i ? "5.00" : "10.00";
1021 return i ? "4.00" : "8.00";
1023 return i ? "3.33" : "6.66";
1025 return i ? "2.86" : "5.00";
1027 return i ? "2.50" : "4.00";
1029 return i ? "2.22" : "3.10";
1031 return i ? "2.00" : "2.50";
1033 return i ? "1.82" : "2.00";
1038 static int probe_display(int what)
1040 static int rotator = 0;
1041 const char rotor[] = "|/-\\";
1043 if (!(display_mode & LED_DISP))
1046 outl(0x20202020, MOD95_LED_PORT);
1047 outl(0x20202020, MOD95_LED_PORT + 4);
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);
1064 static int probe_bus_mode(int host_index)
1066 struct im_pos_info *info;
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;
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);
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 */
1107 int speedrun; /* local adapter_speed check variable */
1109 /* assign default values to certain variables */
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
1133 probe_display(0); /* Supercool display usage during SCSI-probing. */
1134 /* This makes sense, when booting without any */
1135 /* monitor connected on model XX95. */
1138 adapter_speed(host_index) = global_adapter_speed;
1139 speedrun = adapter_speed(host_index);
1140 while (immediate_feature(host_index, speedrun, adapter_timeout) == 2) {
1143 panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n");
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: */
1157 printk(KERN_INFO "IBM MCA SCSI: Separate bus mode (wide-addressing enabled)\n");
1158 subsystem_maxid(host_index) = 16;
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.");
1174 printk(KERN_INFO "IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", (ibm_ansi_order) ? "ANSI" : "New");
1176 for (ldn = 0; ldn < MAX_LOG_DEV; ldn++) {
1178 #ifdef IM_DEBUG_PROBE
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
1188 #ifdef IM_DEBUG_PROBE
1189 printk("\nIBM MCA SCSI: Scanning SCSI-devices.");
1191 for (id = 0; id < max_pun; id++)
1192 #ifdef CONFIG_SCSI_MULTI_LUN
1193 for (lun = 0; lun < 8; lun++)
1197 #ifdef IM_DEBUG_PROBE
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 */
1211 immediate_assign(host_index, id, lun, PROBE_LDN, REMOVE_LDN);
1214 #ifndef IM_DEBUG_PROBE
1218 #ifdef IM_DEBUG_PROBE
1219 printk("\nIBM MCA SCSI: Mapping SCSI-devices.");
1223 #ifdef CONFIG_SCSI_MULTI_LUN
1224 for (lun = 0; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1226 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1228 #ifdef IM_DEBUG_PROBE
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);
1244 /* device vanished, probably because we don't know how to
1245 * handle it or because it has problems */
1247 /* remove mapping */
1248 get_ldn(host_index)[id][lun] = TYPE_NO_DEVICE;
1249 immediate_assign(host_index, 0, 0, ldn, REMOVE_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 */
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) {
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
1272 immediate_assign(host_index, id, lun, ldn, SET_LDN);
1273 get_ldn(host_index)[id][lun] = ldn;
1277 #ifndef IM_DEBUG_PROBE
1281 #ifdef IM_DEBUG_PROBE
1283 printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n");
1285 printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n");
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++) {
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]));
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 */
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. */
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));
1334 static int device_exists(int host_index, int ldn, int *block_length, int *device_type)
1337 /* if no valid device found, return immediately with 0 */
1338 if (!(device_inquiry(host_index, ldn)))
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) */
1346 if (*buf == TYPE_WORM) {
1347 *device_type = TYPE_WORM;
1348 *block_length = 2048;
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);
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);
1367 if (*buf == TYPE_TAPE) {
1368 *device_type = TYPE_TAPE;
1369 *block_length = 0; /* not in use (setting by mt and mtst in op.) */
1372 if (*buf == TYPE_PROCESSOR) {
1373 *device_type = TYPE_PROCESSOR;
1374 *block_length = 0; /* they set their stuff on drivers */
1377 if (*buf == TYPE_SCANNER) {
1378 *device_type = TYPE_SCANNER;
1379 *block_length = 0; /* they set their stuff on drivers */
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
1391 static void internal_ibmmca_scsi_setup(char *str, int *ints)
1393 int i, j, io_base, id_base;
1400 while ((token = strsep(&str, ",")) != NULL) {
1401 if (!strcmp(token, "activity"))
1402 display_mode |= LED_ACTIVITY;
1403 if (!strcmp(token, "display"))
1404 display_mode |= LED_DISP;
1405 if (!strcmp(token, "adisplay"))
1406 display_mode |= LED_ADISP;
1407 if (!strcmp(token, "normal"))
1409 if (!strcmp(token, "ansi"))
1411 if (!strcmp(token, "fast"))
1412 global_adapter_speed = 0;
1413 if (!strcmp(token, "medium"))
1414 global_adapter_speed = 4;
1415 if (!strcmp(token, "slow"))
1416 global_adapter_speed = 7;
1417 if ((*token == '-') || (isdigit(*token))) {
1418 if (!(j % 2) && (io_base < IM_MAX_HOSTS))
1419 io_port[io_base++] = simple_strtoul(token, NULL, 0);
1420 if ((j % 2) && (id_base < IM_MAX_HOSTS))
1421 scsi_id[id_base++] = simple_strtoul(token, NULL, 0);
1426 for (i = 0; i < IM_MAX_HOSTS && 2 * i + 2 < ints[0]; i++) {
1427 io_port[i] = ints[2 * i + 2];
1428 scsi_id[i] = ints[2 * i + 2];
1434 static int ibmmca_getinfo(char *buf, int slot, void *dev_id)
1436 struct Scsi_Host *shpnt;
1437 int len, speciale, connectore, k;
1438 unsigned int pos[8];
1439 unsigned long flags;
1440 struct Scsi_Host *dev = dev_id;
1442 spin_lock_irqsave(dev->host_lock, flags);
1444 shpnt = dev; /* assign host-structure to local pointer */
1445 len = 0; /* set filled text-buffer index to 0 */
1446 /* get the _special contents of the hostdata structure */
1447 speciale = ((struct ibmmca_hostdata *) shpnt->hostdata)->_special;
1448 connectore = ((struct ibmmca_hostdata *) shpnt->hostdata)->_connector_size;
1449 for (k = 2; k < 4; k++)
1450 pos[k] = ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k];
1451 if (speciale == FORCED_DETECTION) { /* forced detection */
1452 len += sprintf(buf + len,
1453 "Adapter category: forced detected\n" "***************************************\n" "*** Forced detected SCSI Adapter ***\n" "*** No chip-information available ***\n" "***************************************\n");
1454 } else if (speciale == INTEGRATED_SCSI) {
1455 /* if the integrated subsystem has been found automatically: */
1456 len += sprintf(buf + len,
1457 "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");
1458 } else if ((speciale >= 0) && (speciale < ARRAY_SIZE(subsys_list))) {
1459 /* if the subsystem is a slot adapter */
1460 len += sprintf(buf + len, "Adapter category: slot-card\n" "ROM Segment Address: ");
1461 if ((pos[2] & 0xf0) == 0xf0)
1462 len += sprintf(buf + len, "off\n");
1464 len += sprintf(buf + len, "0x%x\n", ((pos[2] & 0xf0) << 13) + 0xc0000);
1465 len += sprintf(buf + len, "Chip status: %s\n", (pos[2] & 1) ? "enabled" : "disabled");
1466 len += sprintf(buf + len, "Adapter I/O Offset: 0x%x\n", ((pos[2] & 0x0e) << 2));
1468 len += sprintf(buf + len, "Adapter category: unknown\n");
1470 /* common subsystem information to write to the slotn file */
1471 len += sprintf(buf + len, "Subsystem PUN: %d\n", shpnt->this_id);
1472 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));
1473 len += sprintf(buf + len, "MCA-slot size: %d bits", connectore);
1474 /* Now make sure, the bufferlength is devidable by 4 to avoid
1475 * paging problems of the buffer. */
1476 while (len % sizeof(int) != (sizeof(int) - 1))
1477 len += sprintf(buf + len, " ");
1478 len += sprintf(buf + len, "\n");
1480 spin_unlock_irqrestore(shpnt->host_lock, flags);
1485 int ibmmca_detect(struct scsi_host_template * scsi_template)
1487 struct Scsi_Host *shpnt;
1488 int port, id, i, j, k, slot;
1489 int devices_on_irq_11 = 0;
1490 int devices_on_irq_14 = 0;
1491 int IRQ14_registered = 0;
1492 int IRQ11_registered = 0;
1494 found = 0; /* make absolutely sure, that found is set to 0 */
1496 /* First of all, print the version number of the driver. This is
1497 * important to allow better user bugreports in case of already
1498 * having problems with the MCA_bus probing. */
1499 printk(KERN_INFO "IBM MCA SCSI: Version %s\n", IBMMCA_SCSI_DRIVER_VERSION);
1500 /* if this is not MCA machine, return "nothing found" */
1502 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");
1507 /* If the driver is run as module, read from conf.modules or cmd-line */
1509 option_setup(boot_options);
1512 /* get interrupt request level */
1513 if (request_irq(IM_IRQ, interrupt_handler, IRQF_SHARED, "ibmmcascsi", hosts)) {
1514 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ);
1519 /* if ibmmcascsi setup option was passed to kernel, return "found" */
1520 for (i = 0; i < IM_MAX_HOSTS; i++)
1521 if (io_port[i] > 0 && scsi_id[i] >= 0 && scsi_id[i] < 8) {
1522 printk("IBM MCA SCSI: forced detected SCSI Adapter, io=0x%x, scsi id=%d.\n", io_port[i], scsi_id[i]);
1523 if ((shpnt = ibmmca_register(scsi_template, io_port[i], scsi_id[i], FORCED_DETECTION, "forced detected SCSI Adapter"))) {
1524 for (k = 2; k < 7; k++)
1525 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = 0;
1526 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = FORCED_DETECTION;
1527 mca_set_adapter_name(MCA_INTEGSCSI, "forced detected SCSI Adapter");
1528 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1529 mca_mark_as_used(MCA_INTEGSCSI);
1530 devices_on_irq_14++;
1536 /* The POS2-register of all PS/2 model SCSI-subsystems has the following
1537 * interpretation of bits:
1538 * Bit 7 - 4 : Chip Revision ID (Release)
1539 * Bit 3 - 2 : Reserved
1540 * Bit 1 : 8k NVRAM Disabled
1541 * Bit 0 : Chip Enable (EN-Signal)
1542 * The POS3-register is interpreted as follows:
1543 * Bit 7 - 5 : SCSI ID
1544 * Bit 4 : Reserved = 0
1545 * Bit 3 - 0 : Reserved = 0
1546 * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common
1547 * Interfaces (1991)").
1548 * In short words, this means, that IBM PS/2 machines only support
1549 * 1 single subsystem by default. The slot-adapters must have another
1550 * configuration on pos2. Here, one has to assume the following
1551 * things for POS2-register:
1552 * Bit 7 - 4 : Chip Revision ID (Release)
1553 * Bit 3 - 1 : port offset factor
1554 * Bit 0 : Chip Enable (EN-Signal)
1555 * As I found a patch here, setting the IO-registers to 0x3540 forced,
1556 * as there was a 0x05 in POS2 on a model 56, I assume, that the
1557 * port 0x3540 must be fix for integrated SCSI-controllers.
1558 * Ok, this discovery leads to the following implementation: (M.Lang) */
1560 /* first look for the IBM SCSI integrated subsystem on the motherboard */
1561 for (j = 0; j < 8; j++) /* read the pos-information */
1562 pos[j] = mca_read_stored_pos(MCA_INTEGSCSI, j);
1563 /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but
1564 * if we ignore the settings of all surrounding pos registers, it is not
1565 * completely sufficient to only check pos2 and pos3. */
1566 /* Therefore, now the following if statement is used to
1567 * make sure, we see a real integrated onboard SCSI-interface and no
1568 * internal system information, which gets mapped to some pos registers
1569 * on models 95xx. */
1570 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)) {
1571 if ((pos[2] & 1) == 1) /* is the subsystem chip enabled ? */
1573 else { /* if disabled, no IRQs will be generated, as the chip won't
1574 * listen to the incoming commands and will do really nothing,
1575 * except for listening to the pos-register settings. If this
1576 * happens, I need to hugely think about it, as one has to
1577 * write something to the MCA-Bus pos register in order to
1578 * enable the chip. Normally, IBM-SCSI won't pass the POST,
1579 * when the chip is disabled (see IBM tech. ref.). */
1580 port = IM_IO_PORT; /* anyway, set the portnumber and warn */
1581 printk("IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n" " SCSI-operations may not work.\n");
1583 id = (pos[3] & 0xe0) >> 5; /* this is correct and represents the PUN */
1584 /* give detailed information on the subsystem. This helps me
1585 * additionally during debugging and analyzing bug-reports. */
1586 printk(KERN_INFO "IBM MCA SCSI: IBM Integrated SCSI Controller ffound, io=0x%x, scsi id=%d,\n", port, id);
1587 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.");
1589 /* register the found integrated SCSI-subsystem */
1590 if ((shpnt = ibmmca_register(scsi_template, port, id, INTEGRATED_SCSI, "IBM Integrated SCSI Controller")))
1592 for (k = 2; k < 7; k++)
1593 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1594 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = INTEGRATED_SCSI;
1595 mca_set_adapter_name(MCA_INTEGSCSI, "IBM Integrated SCSI Controller");
1596 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1597 mca_mark_as_used(MCA_INTEGSCSI);
1598 devices_on_irq_14++;
1602 /* now look for other adapters in MCA slots, */
1603 /* determine the number of known IBM-SCSI-subsystem types */
1604 /* see the pos[2] dependence to get the adapter port-offset. */
1605 for (i = 0; i < ARRAY_SIZE(subsys_list); i++) {
1606 /* scan each slot for a fitting adapter id */
1607 slot = 0; /* start at slot 0 */
1608 while ((slot = mca_find_adapter(subsys_list[i].mca_id, slot))
1609 != MCA_NOTFOUND) { /* scan through all slots */
1610 for (j = 0; j < 8; j++) /* read the pos-information */
1611 pos[j] = mca_read_stored_pos(slot, j);
1612 if ((pos[2] & 1) == 1)
1613 /* is the subsystem chip enabled ? */
1614 /* (explanations see above) */
1615 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1617 /* anyway, set the portnumber and warn */
1618 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1619 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1620 printk(KERN_WARNING " SCSI-operations may not work.\n");
1622 if ((i == IBM_SCSI2_FW) && (pos[6] != 0)) {
1623 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1624 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1625 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1628 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1629 if (i == IBM_SCSI2_FW) {
1630 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1631 * for F/W adapters */
1634 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0)) {
1635 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1636 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1637 /* get interrupt request level */
1638 if (request_irq(IM_IRQ_FW, interrupt_handler, IRQF_SHARED, "ibmmcascsi", hosts)) {
1639 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ_FW);
1643 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);
1644 if ((pos[2] & 0xf0) == 0xf0)
1645 printk(KERN_DEBUG" ROM Addr.=off,");
1647 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
1648 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
1650 /* register the hostadapter */
1651 if ((shpnt = ibmmca_register(scsi_template, port, id, i, subsys_list[i].description))) {
1652 for (k = 2; k < 8; k++)
1653 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1654 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = i;
1655 mca_set_adapter_name(slot, subsys_list[i].description);
1656 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1657 mca_mark_as_used(slot);
1658 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0))
1659 devices_on_irq_11++;
1661 devices_on_irq_14++;
1663 slot++; /* advance to next slot */
1664 } /* advance to next adapter id in the list of IBM-SCSI-subsystems */
1667 /* now check for SCSI-adapters, mapped to the integrated SCSI
1668 * area. E.g. a W/Cache in MCA-slot 9(!). Do the check correct here,
1669 * as this is a known effect on some models 95xx. */
1670 for (i = 0; i < ARRAY_SIZE(subsys_list); i++) {
1671 /* scan each slot for a fitting adapter id */
1672 slot = mca_find_adapter(subsys_list[i].mca_id, MCA_INTEGSCSI);
1673 if (slot != MCA_NOTFOUND) { /* scan through all slots */
1674 for (j = 0; j < 8; j++) /* read the pos-information */
1675 pos[j] = mca_read_stored_pos(slot, j);
1676 if ((pos[2] & 1) == 1) { /* is the subsystem chip enabled ? */
1677 /* (explanations see above) */
1678 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1679 } else { /* anyway, set the portnumber and warn */
1680 port = IM_IO_PORT + ((pos[2] & 0x0e) << 2);
1681 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1682 printk(KERN_WARNING " SCSI-operations may not work.\n");
1684 if ((i == IBM_SCSI2_FW) && (pos[6] != 0)) {
1685 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1686 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1687 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1690 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1691 if (i == IBM_SCSI2_FW)
1692 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1693 * for F/W adapters */
1695 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0)) {
1696 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1697 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1698 /* get interrupt request level */
1699 if (request_irq(IM_IRQ_FW, interrupt_handler, IRQF_SHARED, "ibmmcascsi", hosts))
1700 printk(KERN_ERR "IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ_FW);
1704 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);
1705 if ((pos[2] & 0xf0) == 0xf0)
1706 printk(KERN_DEBUG " ROM Addr.=off,");
1708 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
1709 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
1711 /* register the hostadapter */
1712 if ((shpnt = ibmmca_register(scsi_template, port, id, i, subsys_list[i].description))) {
1713 for (k = 2; k < 7; k++)
1714 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1715 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = i;
1716 mca_set_adapter_name(slot, subsys_list[i].description);
1717 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1718 mca_mark_as_used(slot);
1719 if ((i == IBM_SCSI2_FW) && (pos[4] & 0x01) && (pos[6] == 0))
1720 devices_on_irq_11++;
1722 devices_on_irq_14++;
1724 slot++; /* advance to next slot */
1725 } /* advance to next adapter id in the list of IBM-SCSI-subsystems */
1727 if (IRQ11_registered && !devices_on_irq_11)
1728 free_irq(IM_IRQ_FW, hosts); /* no devices on IRQ 11 */
1729 if (IRQ14_registered && !devices_on_irq_14)
1730 free_irq(IM_IRQ, hosts); /* no devices on IRQ 14 */
1731 if (!devices_on_irq_11 && !devices_on_irq_14)
1732 printk(KERN_WARNING "IBM MCA SCSI: No IBM SCSI-subsystem adapter attached.\n");
1733 return found; /* return the number of found SCSI hosts. Should be 1 or 0. */
1736 static struct Scsi_Host *ibmmca_register(struct scsi_host_template * scsi_template, int port, int id, int adaptertype, char *hostname)
1738 struct Scsi_Host *shpnt;
1742 /* check I/O region */
1743 if (!request_region(port, IM_N_IO_PORT, hostname)) {
1744 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 shpnt = scsi_register(scsi_template, sizeof(struct ibmmca_hostdata));
1751 printk(KERN_ERR "IBM MCA SCSI: Unable to register host.\n");
1752 release_region(port, IM_N_IO_PORT);
1756 /* request I/O region */
1757 hosts[found] = shpnt; /* add new found hostadapter to the list */
1758 special(found) = adaptertype; /* important assignment or else crash! */
1759 subsystem_connector_size(found) = 0; /* preset slot-size */
1760 shpnt->irq = IM_IRQ; /* assign necessary stuff for the adapter */
1761 shpnt->io_port = port;
1762 shpnt->n_io_port = IM_N_IO_PORT;
1763 shpnt->this_id = id;
1764 shpnt->max_id = 8; /* 8 PUNs are default */
1765 /* now, the SCSI-subsystem is connected to Linux */
1767 ctrl = (unsigned int) (inb(IM_CTR_REG(found))); /* get control-register status */
1768 #ifdef IM_DEBUG_PROBE
1769 printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", ctrl, inb(IM_STAT_REG(found)));
1770 printk("IBM MCA SCSI: This adapters' POS-registers: ");
1771 for (i = 0; i < 8; i++)
1772 printk("%x ", pos[i]);
1775 reset_status(found) = IM_RESET_NOT_IN_PROGRESS;
1777 for (i = 0; i < 16; i++) /* reset the tables */
1778 for (j = 0; j < 8; j++)
1779 get_ldn(found)[i][j] = MAX_LOG_DEV;
1781 /* check which logical devices exist */
1782 /* after this line, local interrupting is possible: */
1783 local_checking_phase_flag(found) = 1;
1784 check_devices(found, adaptertype); /* call by value, using the global variable hosts */
1785 local_checking_phase_flag(found) = 0;
1786 found++; /* now increase index to be prepared for next found subsystem */
1787 /* an ibm mca subsystem has been detected */
1791 static int ibmmca_release(struct Scsi_Host *shpnt)
1793 release_region(shpnt->io_port, shpnt->n_io_port);
1795 free_irq(shpnt->irq, hosts);
1799 /* The following routine is the SCSI command queue for the midlevel driver */
1800 static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1803 unsigned int scsi_cmd;
1805 struct Scsi_Host *shpnt;
1812 struct scatterlist *sl;
1814 shpnt = cmd->device->host;
1815 /* search for the right hostadapter */
1816 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
1818 if (!hosts[host_index]) { /* invalid hostadapter descriptor address */
1819 cmd->result = DID_NO_CONNECT << 16;
1824 max_pun = subsystem_maxid(host_index);
1825 if (ibm_ansi_order) {
1826 target = max_pun - 1 - cmd->device->id;
1827 if ((target <= subsystem_pun(host_index)) && (cmd->device->id <= subsystem_pun(host_index)))
1829 else if ((target >= subsystem_pun(host_index)) && (cmd->device->id >= subsystem_pun(host_index)))
1832 target = cmd->device->id;
1834 /* if (target,lun) is NO LUN or not existing at all, return error */
1835 if ((get_scsi(host_index)[target][cmd->device->lun] == TYPE_NO_LUN) || (get_scsi(host_index)[target][cmd->device->lun] == TYPE_NO_DEVICE)) {
1836 cmd->result = DID_NO_CONNECT << 16;
1842 /*if (target,lun) unassigned, do further checks... */
1843 ldn = get_ldn(host_index)[target][cmd->device->lun];
1844 if (ldn >= MAX_LOG_DEV) { /* on invalid ldn do special stuff */
1845 if (ldn > MAX_LOG_DEV) { /* dynamical remapping if ldn unassigned */
1846 current_ldn = next_ldn(host_index); /* stop-value for one circle */
1847 while (ld(host_index)[next_ldn(host_index)].cmd) { /* search for a occupied, but not in */
1848 /* command-processing ldn. */
1849 next_ldn(host_index)++;
1850 if (next_ldn(host_index) >= MAX_LOG_DEV)
1851 next_ldn(host_index) = 7;
1852 if (current_ldn == next_ldn(host_index)) { /* One circle done ? */
1853 /* no non-processing ldn found */
1854 scmd_printk(KERN_WARNING, cmd,
1855 "IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n"
1856 " On ldn 7-14 SCSI-commands everywhere in progress.\n"
1857 " Reporting DID_NO_CONNECT for device.\n");
1858 cmd->result = DID_NO_CONNECT << 16; /* return no connect */
1865 /* unmap non-processing ldn */
1866 for (id = 0; id < max_pun; id++)
1867 for (lun = 0; lun < 8; lun++) {
1868 if (get_ldn(host_index)[id][lun] == next_ldn(host_index)) {
1869 get_ldn(host_index)[id][lun] = TYPE_NO_DEVICE;
1870 get_scsi(host_index)[id][lun] = TYPE_NO_DEVICE;
1874 /* set reduced interrupt_handler-mode for checking */
1875 local_checking_phase_flag(host_index) = 1;
1876 /* map found ldn to pun,lun */
1877 get_ldn(host_index)[target][cmd->device->lun] = next_ldn(host_index);
1878 /* change ldn to the right value, that is now next_ldn */
1879 ldn = next_ldn(host_index);
1880 /* unassign all ldns (pun,lun,ldn does not matter for remove) */
1881 immediate_assign(host_index, 0, 0, 0, REMOVE_LDN);
1882 /* set only LDN for remapped device */
1883 immediate_assign(host_index, target, cmd->device->lun, ldn, SET_LDN);
1884 /* get device information for ld[ldn] */
1885 if (device_exists(host_index, ldn, &ld(host_index)[ldn].block_length, &ld(host_index)[ldn].device_type)) {
1886 ld(host_index)[ldn].cmd = NULL; /* To prevent panic set 0, because
1887 devices that were not assigned,
1888 should have nothing in progress. */
1889 get_scsi(host_index)[target][cmd->device->lun] = ld(host_index)[ldn].device_type;
1890 /* increase assignment counters for statistics in /proc */
1891 IBM_DS(host_index).dynamical_assignments++;
1892 IBM_DS(host_index).ldn_assignments[ldn]++;
1894 /* panic here, because a device, found at boottime has
1896 panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", ldn, target, cmd->device->lun);
1897 /* unassign again all ldns (pun,lun,ldn does not matter for remove) */
1898 immediate_assign(host_index, 0, 0, 0, REMOVE_LDN);
1899 /* remap all ldns, as written in the pun/lun table */
1901 #ifdef CONFIG_SCSI_MULTI_LUN
1902 for (lun = 0; lun < 8; lun++)
1904 for (id = 0; id < max_pun; id++) {
1905 if (get_ldn(host_index)[id][lun] <= MAX_LOG_DEV)
1906 immediate_assign(host_index, id, lun, get_ldn(host_index)[id][lun], SET_LDN);
1908 /* set back to normal interrupt_handling */
1909 local_checking_phase_flag(host_index) = 0;
1910 #ifdef IM_DEBUG_PROBE
1911 /* Information on syslog terminal */
1912 printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", ldn, target, cmd->device->lun);
1914 /* increase next_ldn for next dynamical assignment */
1915 next_ldn(host_index)++;
1916 if (next_ldn(host_index) >= MAX_LOG_DEV)
1917 next_ldn(host_index) = 7;
1918 } else { /* wall against Linux accesses to the subsystem adapter */
1919 cmd->result = DID_BAD_TARGET << 16;
1926 /*verify there is no command already in progress for this log dev */
1927 if (ld(host_index)[ldn].cmd)
1928 panic("IBM MCA SCSI: cmd already in progress for this ldn.\n");
1930 /*save done in cmd, and save cmd for the interrupt handler */
1931 cmd->scsi_done = done;
1932 ld(host_index)[ldn].cmd = cmd;
1934 /*fill scb information independent of the scsi command */
1935 scb = &(ld(host_index)[ldn].scb);
1936 ld(host_index)[ldn].tsb.dev_status = 0;
1937 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE;
1938 scb->tsb_adr = isa_virt_to_bus(&(ld(host_index)[ldn].tsb));
1939 scsi_cmd = cmd->cmnd[0];
1943 sl = (struct scatterlist *) (cmd->request_buffer);
1945 panic("IBM MCA SCSI: scatter-gather list too long.\n");
1947 ld(host_index)[ldn].sge[i].address = (void *) (isa_page_to_bus(sl[i].page) + sl[i].offset);
1948 ld(host_index)[ldn].sge[i].byte_length = sl[i].length;
1950 scb->enable |= IM_POINTER_TO_LIST;
1951 scb->sys_buf_adr = isa_virt_to_bus(&(ld(host_index)[ldn].sge[0]));
1952 scb->sys_buf_length = cmd->use_sg * sizeof(struct im_sge);
1954 scb->sys_buf_adr = isa_virt_to_bus(cmd->request_buffer);
1955 /* recent Linux midlevel SCSI places 1024 byte for inquiry
1956 * command. Far too much for old PS/2 hardware. */
1958 /* avoid command errors by setting bufferlengths to
1959 * ANSI-standard. Beware of forcing it to 255,
1960 * this could SEGV the kernel!!! */
1965 if (cmd->request_bufflen > 255)
1966 scb->sys_buf_length = 255;
1968 scb->sys_buf_length = cmd->request_bufflen;
1970 case TEST_UNIT_READY:
1971 scb->sys_buf_length = 0;
1974 scb->sys_buf_length = cmd->request_bufflen;
1978 /*fill scb information dependent on scsi command */
1981 printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd, ldn);
1984 /* for specific device-type debugging: */
1985 #ifdef IM_DEBUG_CMD_SPEC_DEV
1986 if (ld(host_index)[ldn].device_type == IM_DEBUG_CMD_DEVICE)
1987 printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", ld(host_index)[ldn].device_type, scsi_cmd, ldn);
1990 /* for possible panics store current command */
1991 last_scsi_command(host_index)[ldn] = scsi_cmd;
1992 last_scsi_type(host_index)[ldn] = IM_SCB;
1993 /* update statistical info */
1994 IBM_DS(host_index).total_accesses++;
1995 IBM_DS(host_index).ldn_access[ldn]++;
2004 /* Distinguish between disk and other devices. Only disks (that are the
2005 most frequently accessed devices) should be supported by the
2006 IBM-SCSI-Subsystem commands. */
2007 switch (ld(host_index)[ldn].device_type) {
2008 case TYPE_DISK: /* for harddisks enter here ... */
2009 case TYPE_MOD: /* ... try it also for MO-drives (send flames as */
2010 /* you like, if this won't work.) */
2011 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) {
2012 /* read command preparations */
2013 scb->enable |= IM_READ_CONTROL;
2014 IBM_DS(host_index).ldn_read_access[ldn]++; /* increase READ-access on ldn stat. */
2015 scb->command = IM_READ_DATA_CMD | IM_NO_DISCONNECT;
2016 } else { /* write command preparations */
2017 IBM_DS(host_index).ldn_write_access[ldn]++; /* increase write-count on ldn stat. */
2018 scb->command = IM_WRITE_DATA_CMD | IM_NO_DISCONNECT;
2020 if (scsi_cmd == READ_6 || scsi_cmd == WRITE_6) {
2021 scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[3]) << 0) | (((unsigned) cmd->cmnd[2]) << 8) | ((((unsigned) cmd->cmnd[1]) & 0x1f) << 16);
2022 scb->u2.blk.count = (unsigned) cmd->cmnd[4];
2024 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);
2025 scb->u2.blk.count = (((unsigned) cmd->cmnd[8]) << 0) | (((unsigned) cmd->cmnd[7]) << 8);
2027 last_scsi_logical_block(host_index)[ldn] = scb->u1.log_blk_adr;
2028 last_scsi_blockcount(host_index)[ldn] = scb->u2.blk.count;
2029 scb->u2.blk.length = ld(host_index)[ldn].block_length;
2031 /* for other devices, enter here. Other types are not known by
2032 Linux! TYPE_NO_LUN is forbidden as valid device. */
2035 case TYPE_PROCESSOR:
2038 case TYPE_MEDIUM_CHANGER:
2039 /* If there is a sequential-device, IBM recommends to use
2040 IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE.
2041 This includes CD-ROM devices, too, due to the partial sequential
2042 read capabilities. */
2043 scb->command = IM_OTHER_SCSI_CMD_CMD;
2044 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12)
2046 scb->enable |= IM_READ_CONTROL;
2047 scb->enable |= IM_BYPASS_BUFFER;
2048 scb->u1.scsi_cmd_length = cmd->cmd_len;
2049 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2050 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2051 /* Read/write on this non-disk devices is also displayworthy,
2052 so flash-up the LED/display. */
2057 IBM_DS(host_index).ldn_inquiry_access[ldn]++;
2058 scb->command = IM_DEVICE_INQUIRY_CMD;
2059 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2060 scb->u1.log_blk_adr = 0;
2062 case TEST_UNIT_READY:
2063 scb->command = IM_OTHER_SCSI_CMD_CMD;
2064 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2065 scb->u1.log_blk_adr = 0;
2066 scb->u1.scsi_cmd_length = 6;
2067 memcpy(scb->u2.scsi_command, cmd->cmnd, 6);
2068 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2071 /* the length of system memory buffer must be exactly 8 bytes */
2072 scb->command = IM_READ_CAPACITY_CMD;
2073 scb->enable |= IM_READ_CONTROL | IM_BYPASS_BUFFER;
2074 if (scb->sys_buf_length > 8)
2075 scb->sys_buf_length = 8;
2077 /* Commands that need read-only-mode (system <- device): */
2079 scb->command = IM_REQUEST_SENSE_CMD;
2080 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2082 /* Commands that need write-only-mode (system -> device): */
2084 case MODE_SELECT_10:
2085 IBM_DS(host_index).ldn_modeselect_access[ldn]++;
2086 scb->command = IM_OTHER_SCSI_CMD_CMD;
2087 scb->enable |= IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; /*Select needs WRITE-enabled */
2088 scb->u1.scsi_cmd_length = cmd->cmd_len;
2089 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2090 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2092 /* For other commands, read-only is useful. Most other commands are
2093 running without an input-data-block. */
2095 scb->command = IM_OTHER_SCSI_CMD_CMD;
2096 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
2097 scb->u1.scsi_cmd_length = cmd->cmd_len;
2098 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
2099 last_scsi_type(host_index)[ldn] = IM_LONG_SCB;
2102 /*issue scb command, and return */
2103 if (++disk_rw_in_progress == 1)
2104 PS2_DISK_LED_ON(shpnt->host_no, target);
2106 if (last_scsi_type(host_index)[ldn] == IM_LONG_SCB) {
2107 issue_cmd(host_index, isa_virt_to_bus(scb), IM_LONG_SCB | ldn);
2108 IBM_DS(host_index).long_scbs++;
2110 issue_cmd(host_index, isa_virt_to_bus(scb), IM_SCB | ldn);
2111 IBM_DS(host_index).scbs++;
2116 static int __ibmmca_abort(Scsi_Cmnd * cmd)
2118 /* Abort does not work, as the adapter never generates an interrupt on
2119 * whatever situation is simulated, even when really pending commands
2120 * are running on the adapters' hardware ! */
2122 struct Scsi_Host *shpnt;
2124 void (*saved_done) (Scsi_Cmnd *);
2128 unsigned long imm_command;
2130 #ifdef IM_DEBUG_PROBE
2131 printk("IBM MCA SCSI: Abort subroutine called...\n");
2134 shpnt = cmd->device->host;
2135 /* search for the right hostadapter */
2136 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
2138 if (!hosts[host_index]) { /* invalid hostadapter descriptor address */
2139 cmd->result = DID_NO_CONNECT << 16;
2141 (cmd->scsi_done) (cmd);
2142 shpnt = cmd->device->host;
2143 #ifdef IM_DEBUG_PROBE
2144 printk(KERN_DEBUG "IBM MCA SCSI: Abort adapter selection failed!\n");
2148 max_pun = subsystem_maxid(host_index);
2149 if (ibm_ansi_order) {
2150 target = max_pun - 1 - cmd->device->id;
2151 if ((target <= subsystem_pun(host_index)) && (cmd->device->id <= subsystem_pun(host_index)))
2153 else if ((target >= subsystem_pun(host_index)) && (cmd->device->id >= subsystem_pun(host_index)))
2156 target = cmd->device->id;
2158 /* get logical device number, and disable system interrupts */
2159 printk(KERN_WARNING "IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", target, cmd->device->lun);
2160 ldn = get_ldn(host_index)[target][cmd->device->lun];
2162 /*if cmd for this ldn has already finished, no need to abort */
2163 if (!ld(host_index)[ldn].cmd) {
2167 /* Clear ld.cmd, save done function, install internal done,
2168 * send abort immediate command (this enables sys. interrupts),
2169 * and wait until the interrupt arrives.
2171 saved_done = cmd->scsi_done;
2172 cmd->scsi_done = internal_done;
2173 cmd->SCp.Status = 0;
2174 last_scsi_command(host_index)[ldn] = IM_ABORT_IMM_CMD;
2175 last_scsi_type(host_index)[ldn] = IM_IMM_CMD;
2176 imm_command = inl(IM_CMD_REG(host_index));
2177 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2178 imm_command |= (unsigned long) (IM_ABORT_IMM_CMD);
2179 /* must wait for attention reg not busy */
2180 /* FIXME - timeout, politeness */
2182 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
2185 /* write registers and enable system interrupts */
2186 outl(imm_command, IM_CMD_REG(host_index));
2187 outb(IM_IMM_CMD | ldn, IM_ATTN_REG(host_index));
2188 #ifdef IM_DEBUG_PROBE
2189 printk("IBM MCA SCSI: Abort queued to adapter...\n");
2191 spin_unlock_irq(shpnt->host_lock);
2192 while (!cmd->SCp.Status)
2194 spin_lock_irq(shpnt->host_lock);
2195 cmd->scsi_done = saved_done;
2196 #ifdef IM_DEBUG_PROBE
2197 printk("IBM MCA SCSI: Abort returned with adapter response...\n");
2200 /*if abort went well, call saved done, then return success or error */
2201 if (cmd->result == (DID_ABORT << 16))
2203 cmd->result |= DID_ABORT << 16;
2205 (cmd->scsi_done) (cmd);
2206 ld(host_index)[ldn].cmd = NULL;
2207 #ifdef IM_DEBUG_PROBE
2208 printk("IBM MCA SCSI: Abort finished with success.\n");
2212 cmd->result |= DID_NO_CONNECT << 16;
2214 (cmd->scsi_done) (cmd);
2215 ld(host_index)[ldn].cmd = NULL;
2216 #ifdef IM_DEBUG_PROBE
2217 printk("IBM MCA SCSI: Abort failed.\n");
2223 static int ibmmca_abort(Scsi_Cmnd * cmd)
2225 struct Scsi_Host *shpnt = cmd->device->host;
2228 spin_lock_irq(shpnt->host_lock);
2229 rc = __ibmmca_abort(cmd);
2230 spin_unlock_irq(shpnt->host_lock);
2235 static int __ibmmca_host_reset(Scsi_Cmnd * cmd)
2237 struct Scsi_Host *shpnt;
2241 unsigned long imm_command;
2243 BUG_ON(cmd == NULL);
2245 ticks = IM_RESET_DELAY * HZ;
2246 shpnt = cmd->device->host;
2247 /* search for the right hostadapter */
2248 for (host_index = 0; hosts[host_index] && hosts[host_index]->host_no != shpnt->host_no; host_index++);
2250 if (!hosts[host_index]) /* invalid hostadapter descriptor address */
2253 if (local_checking_phase_flag(host_index)) {
2254 printk(KERN_WARNING "IBM MCA SCSI: unable to reset while checking devices.\n");
2258 /* issue reset immediate command to subsystem, and wait for interrupt */
2259 printk("IBM MCA SCSI: resetting all devices.\n");
2260 reset_status(host_index) = IM_RESET_IN_PROGRESS;
2261 last_scsi_command(host_index)[0xf] = IM_RESET_IMM_CMD;
2262 last_scsi_type(host_index)[0xf] = IM_IMM_CMD;
2263 imm_command = inl(IM_CMD_REG(host_index));
2264 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2265 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
2266 /* must wait for attention reg not busy */
2268 if (!(inb(IM_STAT_REG(host_index)) & IM_BUSY))
2270 spin_unlock_irq(shpnt->host_lock);
2272 spin_lock_irq(shpnt->host_lock);
2274 /*write registers and enable system interrupts */
2275 outl(imm_command, IM_CMD_REG(host_index));
2276 outb(IM_IMM_CMD | 0xf, IM_ATTN_REG(host_index));
2277 /* wait for interrupt finished or intr_stat register to be set, as the
2278 * interrupt will not be executed, while we are in here! */
2280 /* FIXME: This is really really icky we so want a sleeping version of this ! */
2281 while (reset_status(host_index) == IM_RESET_IN_PROGRESS && --ticks && ((inb(IM_INTR_REG(host_index)) & 0x8f) != 0x8f)) {
2282 udelay((1 + 999 / HZ) * 1000);
2285 /* if reset did not complete, just return an error */
2287 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
2288 reset_status(host_index) = IM_RESET_FINISHED_FAIL;
2292 if ((inb(IM_INTR_REG(host_index)) & 0x8f) == 0x8f) {
2293 /* analysis done by this routine and not by the intr-routine */
2294 if (inb(IM_INTR_REG(host_index)) == 0xaf)
2295 reset_status(host_index) = IM_RESET_FINISHED_OK_NO_INT;
2296 else if (inb(IM_INTR_REG(host_index)) == 0xcf)
2297 reset_status(host_index) = IM_RESET_FINISHED_FAIL;
2298 else /* failed, 4get it */
2299 reset_status(host_index) = IM_RESET_NOT_IN_PROGRESS_NO_INT;
2300 outb(IM_EOI | 0xf, IM_ATTN_REG(host_index));
2303 /* if reset failed, just return an error */
2304 if (reset_status(host_index) == IM_RESET_FINISHED_FAIL) {
2305 printk(KERN_ERR "IBM MCA SCSI: reset failed.\n");
2309 /* so reset finished ok - call outstanding done's, and return success */
2310 printk(KERN_INFO "IBM MCA SCSI: Reset successfully completed.\n");
2311 for (i = 0; i < MAX_LOG_DEV; i++) {
2312 cmd_aid = ld(host_index)[i].cmd;
2313 if (cmd_aid && cmd_aid->scsi_done) {
2314 ld(host_index)[i].cmd = NULL;
2315 cmd_aid->result = DID_RESET << 16;
2321 static int ibmmca_host_reset(Scsi_Cmnd * cmd)
2323 struct Scsi_Host *shpnt = cmd->device->host;
2326 spin_lock_irq(shpnt->host_lock);
2327 rc = __ibmmca_host_reset(cmd);
2328 spin_unlock_irq(shpnt->host_lock);
2333 static int ibmmca_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *info)
2335 int size = capacity;
2338 info[2] = size / (info[0] * info[1]);
2339 if (info[2] >= 1024) {
2342 info[2] = size / (info[0] * info[1]);
2343 if (info[2] >= 1024) {
2346 info[2] = size / (info[0] * info[1]);
2347 if (info[2] >= 1024)
2354 /* calculate percentage of total accesses on a ldn */
2355 static int ldn_access_load(int host_index, int ldn)
2357 if (IBM_DS(host_index).total_accesses == 0)
2359 if (IBM_DS(host_index).ldn_access[ldn] == 0)
2361 return (IBM_DS(host_index).ldn_access[ldn] * 100) / IBM_DS(host_index).total_accesses;
2364 /* calculate total amount of r/w-accesses */
2365 static int ldn_access_total_read_write(int host_index)
2371 for (i = 0; i <= MAX_LOG_DEV; i++)
2372 a += IBM_DS(host_index).ldn_read_access[i] + IBM_DS(host_index).ldn_write_access[i];
2376 static int ldn_access_total_inquiry(int host_index)
2382 for (i = 0; i <= MAX_LOG_DEV; i++)
2383 a += IBM_DS(host_index).ldn_inquiry_access[i];
2387 static int ldn_access_total_modeselect(int host_index)
2393 for (i = 0; i <= MAX_LOG_DEV; i++)
2394 a += IBM_DS(host_index).ldn_modeselect_access[i];
2398 /* routine to display info in the proc-fs-structure (a deluxe feature) */
2399 static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout)
2402 int i, id, lun, host_index;
2403 unsigned long flags;
2406 for (i = 0; hosts[i] && hosts[i] != shpnt; i++);
2408 spin_lock_irqsave(hosts[i]->host_lock, flags); /* Check it */
2411 len += sprintf(buffer + len, "\nIBM MCA SCSI: Can't find adapter");
2414 max_pun = subsystem_maxid(host_index);
2416 len += sprintf(buffer + len, "\n IBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", IBMMCA_SCSI_DRIVER_VERSION);
2417 len += sprintf(buffer + len, " SCSI Access-Statistics:\n");
2418 len += sprintf(buffer + len, " Device Scanning Order....: %s\n", (ibm_ansi_order) ? "IBM/ANSI" : "New Industry Standard");
2419 #ifdef CONFIG_SCSI_MULTI_LUN
2420 len += sprintf(buffer + len, " Multiple LUN probing.....: Yes\n");
2422 len += sprintf(buffer + len, " Multiple LUN probing.....: No\n");
2424 len += sprintf(buffer + len, " This Hostnumber..........: %d\n", shpnt->host_no);
2425 len += sprintf(buffer + len, " Base I/O-Port............: 0x%x\n", (unsigned int) (IM_CMD_REG(host_index)));
2426 len += sprintf(buffer + len, " (Shared) IRQ.............: %d\n", IM_IRQ);
2427 len += sprintf(buffer + len, " Total Interrupts.........: %d\n", IBM_DS(host_index).total_interrupts);
2428 len += sprintf(buffer + len, " Total SCSI Accesses......: %d\n", IBM_DS(host_index).total_accesses);
2429 len += sprintf(buffer + len, " Total short SCBs.........: %d\n", IBM_DS(host_index).scbs);
2430 len += sprintf(buffer + len, " Total long SCBs..........: %d\n", IBM_DS(host_index).long_scbs);
2431 len += sprintf(buffer + len, " Total SCSI READ/WRITE..: %d\n", ldn_access_total_read_write(host_index));
2432 len += sprintf(buffer + len, " Total SCSI Inquiries...: %d\n", ldn_access_total_inquiry(host_index));
2433 len += sprintf(buffer + len, " Total SCSI Modeselects.: %d\n", ldn_access_total_modeselect(host_index));
2434 len += sprintf(buffer + len, " Total SCSI other cmds..: %d\n", IBM_DS(host_index).total_accesses - ldn_access_total_read_write(host_index)
2435 - ldn_access_total_modeselect(host_index)
2436 - ldn_access_total_inquiry(host_index));
2437 len += sprintf(buffer + len, " Total SCSI command fails.: %d\n\n", IBM_DS(host_index).total_errors);
2438 len += sprintf(buffer + len, " Logical-Device-Number (LDN) Access-Statistics:\n");
2439 len += sprintf(buffer + len, " LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n");
2440 len += sprintf(buffer + len, " -----|--------------|-----------|-----------|--------------\n");
2441 for (i = 0; i <= MAX_LOG_DEV; i++)
2442 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]);
2443 len += sprintf(buffer + len, " -----------------------------------------------------------\n\n");
2444 len += sprintf(buffer + len, " Dynamical-LDN-Assignment-Statistics:\n");
2445 len += sprintf(buffer + len, " Number of physical SCSI-devices..: %d (+ Adapter)\n", IBM_DS(host_index).total_scsi_devices);
2446 len += sprintf(buffer + len, " Dynamical Assignment necessary...: %s\n", IBM_DS(host_index).dyn_flag ? "Yes" : "No ");
2447 len += sprintf(buffer + len, " Next LDN to be assigned..........: 0x%x\n", next_ldn(host_index));
2448 len += sprintf(buffer + len, " Dynamical assignments done yet...: %d\n", IBM_DS(host_index).dynamical_assignments);
2449 len += sprintf(buffer + len, "\n Current SCSI-Device-Mapping:\n");
2450 len += sprintf(buffer + len, " Physical SCSI-Device Map Logical SCSI-Device Map\n");
2451 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");
2452 for (id = 0; id < max_pun; id++) {
2453 len += sprintf(buffer + len, " %2d ", id);
2454 for (lun = 0; lun < 8; lun++)
2455 len += sprintf(buffer + len, "%2s ", ti_p(get_scsi(host_index)[id][lun]));
2456 len += sprintf(buffer + len, " %2d ", id);
2457 for (lun = 0; lun < 8; lun++)
2458 len += sprintf(buffer + len, "%2s ", ti_l(get_ldn(host_index)[id][lun]));
2459 len += sprintf(buffer + len, "\n");
2462 len += sprintf(buffer + len, "(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n");
2463 len += sprintf(buffer + len, " R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n");
2464 len += sprintf(buffer + len, " - = nothing found, nothing assigned or unprobed LUN)\n\n");
2466 *start = buffer + offset;
2470 spin_unlock_irqrestore(shpnt->host_lock, flags);
2474 static int option_setup(char *str)
2476 int ints[IM_MAX_HOSTS];
2480 while (cur && isdigit(*cur) && i <= IM_MAX_HOSTS) {
2481 ints[i++] = simple_strtoul(cur, NULL, 0);
2482 if ((cur = strchr(cur, ',')) != NULL)
2486 internal_ibmmca_scsi_setup(cur, ints);
2490 __setup("ibmmcascsi=", option_setup);
2492 static struct scsi_host_template driver_template = {
2493 .proc_name = "ibmmca",
2494 .proc_info = ibmmca_proc_info,
2495 .name = "IBM SCSI-Subsystem",
2496 .detect = ibmmca_detect,
2497 .release = ibmmca_release,
2498 .queuecommand = ibmmca_queuecommand,
2499 .eh_abort_handler = ibmmca_abort,
2500 .eh_host_reset_handler = ibmmca_host_reset,
2501 .bios_param = ibmmca_biosparam,
2506 .use_clustering = ENABLE_CLUSTERING,
2508 #include "scsi_module.c"