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>
35 #include <asm/system.h>
39 #include <scsi/scsi_host.h>
41 /* Common forward declarations for all Linux-versions: */
42 static int ibmmca_queuecommand (Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
43 static int ibmmca_abort (Scsi_Cmnd *);
44 static int ibmmca_host_reset (Scsi_Cmnd *);
45 static int ibmmca_biosparam (struct scsi_device *, struct block_device *, sector_t, int *);
46 static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout);
50 /* current version of this driver-source: */
51 #define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac"
53 /* driver configuration */
54 #define IM_MAX_HOSTS 8 /* maximum number of host adapters */
55 #define IM_RESET_DELAY 60 /* seconds allowed for a reset */
57 /* driver debugging - #undef all for normal operation */
58 /* if defined: count interrupts and ignore this special one: */
59 #undef IM_DEBUG_TIMEOUT //50
62 /* verbose interrupt: */
64 /* verbose queuecommand: */
66 /* verbose queucommand for specific SCSI-device type: */
67 #undef IM_DEBUG_CMD_SPEC_DEV
68 /* verbose device probing */
71 /* device type that shall be displayed on syslog (only during debugging): */
72 #define IM_DEBUG_CMD_DEVICE TYPE_TAPE
74 /* relative addresses of hardware registers on a subsystem */
75 #define IM_CMD_REG(h) ((h)->io_port) /*Command Interface, (4 bytes long) */
76 #define IM_ATTN_REG(h) ((h)->io_port+4) /*Attention (1 byte) */
77 #define IM_CTR_REG(h) ((h)->io_port+5) /*Basic Control (1 byte) */
78 #define IM_INTR_REG(h) ((h)->io_port+6) /*Interrupt Status (1 byte, r/o) */
79 #define IM_STAT_REG(h) ((h)->io_port+7) /*Basic Status (1 byte, read only) */
81 /* basic I/O-port of first adapter */
82 #define IM_IO_PORT 0x3540
83 /* maximum number of hosts that can be found */
84 #define IM_N_IO_PORT 8
86 /*requests going into the upper nibble of the Attention register */
87 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
88 #define IM_IMM_CMD 0x10 /*immediate command */
89 #define IM_SCB 0x30 /*Subsystem Control Block command */
90 #define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */
91 #define IM_EOI 0xe0 /*end-of-interrupt request */
93 /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */
94 #define IM_HW_RESET 0x80 /*hardware reset */
95 #define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */
96 #define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */
98 /*to interpret the upper nibble of Interrupt Status register */
99 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
100 #define IM_SCB_CMD_COMPLETED 0x10
101 #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50
102 #define IM_LOOP_SCATTER_BUFFER_FULL 0x60
103 #define IM_ADAPTER_HW_FAILURE 0x70
104 #define IM_IMMEDIATE_CMD_COMPLETED 0xa0
105 #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0
106 #define IM_CMD_ERROR 0xe0
107 #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0
109 /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */
110 #define IM_CMD_REG_FULL 0x08
111 #define IM_CMD_REG_EMPTY 0x04
112 #define IM_INTR_REQUEST 0x02
115 /*immediate commands (word written into low 2 bytes of command reg) */
116 #define IM_RESET_IMM_CMD 0x0400
117 #define IM_FEATURE_CTR_IMM_CMD 0x040c
118 #define IM_DMA_PACING_IMM_CMD 0x040d
119 #define IM_ASSIGN_IMM_CMD 0x040e
120 #define IM_ABORT_IMM_CMD 0x040f
121 #define IM_FORMAT_PREP_IMM_CMD 0x0417
123 /*SCB (Subsystem Control Block) structure */
125 unsigned short command; /*command word (read, etc.) */
126 unsigned short enable; /*enable word, modifies cmd */
128 unsigned long log_blk_adr; /*block address on SCSI device */
129 unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */
131 unsigned long sys_buf_adr; /*physical system memory adr */
132 unsigned long sys_buf_length; /*size of sys mem buffer */
133 unsigned long tsb_adr; /*Termination Status Block adr */
134 unsigned long scb_chain_adr; /*optional SCB chain address */
137 unsigned short count; /*block count, on SCSI device */
138 unsigned short length; /*block length, on SCSI device */
140 unsigned char scsi_command[12]; /*other scsi command */
144 /*structure scatter-gather element (for list of system memory areas) */
147 unsigned long byte_length;
150 /*structure returned by a get_pos_info command: */
152 unsigned short pos_id; /* adapter id */
153 unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */
154 unsigned char pos_2; /* pos 2 */
155 unsigned char int_level; /* interrupt level IRQ 11 or 14 */
156 unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */
157 unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */
158 unsigned char num_luns; /* number of supported luns per device */
159 unsigned char num_puns; /* number of supported puns */
160 unsigned char pacing_factor; /* pacing factor */
161 unsigned char num_ldns; /* number of ldns available */
162 unsigned char eoi_off; /* time EOI and interrupt inactive */
163 unsigned char max_busy; /* time between reset and busy on */
164 unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */
165 unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */
166 unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */
167 unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */
168 unsigned char pos_6; /* pos 6 */
169 unsigned char pos_5; /* pos 5 */
170 unsigned short max_overlap; /* maximum overlapping requests */
171 unsigned short num_bus; /* number of SCSI-busses */
174 /*values for SCB command word */
175 #define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */
176 #define IM_NO_DISCONNECT 0x0080 /*flag for any command */
177 #define IM_READ_DATA_CMD 0x1c01
178 #define IM_WRITE_DATA_CMD 0x1c02
179 #define IM_READ_VERIFY_CMD 0x1c03
180 #define IM_WRITE_VERIFY_CMD 0x1c04
181 #define IM_REQUEST_SENSE_CMD 0x1c08
182 #define IM_READ_CAPACITY_CMD 0x1c09
183 #define IM_DEVICE_INQUIRY_CMD 0x1c0b
184 #define IM_READ_LOGICAL_CMD 0x1c2a
185 #define IM_OTHER_SCSI_CMD_CMD 0x241f
187 /* unused, but supported, SCB commands */
188 #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */
189 #define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */
190 #define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */
191 #define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */
192 #define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */
194 /*values to set bits in the enable word of SCB */
195 #define IM_READ_CONTROL 0x8000
196 #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000
197 #define IM_RETRY_ENABLE 0x2000
198 #define IM_POINTER_TO_LIST 0x1000
199 #define IM_SUPRESS_EXCEPTION_SHORT 0x0400
200 #define IM_BYPASS_BUFFER 0x0200
201 #define IM_CHAIN_ON_NO_ERROR 0x0001
203 /*TSB (Termination Status Block) structure */
205 unsigned short end_status;
206 unsigned short reserved1;
207 unsigned long residual_byte_count;
208 unsigned long sg_list_element_adr;
209 unsigned short status_length;
210 unsigned char dev_status;
211 unsigned char cmd_status;
212 unsigned char dev_error;
213 unsigned char cmd_error;
214 unsigned short reserved2;
215 unsigned short reserved3;
216 unsigned short low_of_last_scb_adr;
217 unsigned short high_of_last_scb_adr;
220 /*subsystem uses interrupt request level 14 */
222 /*SCSI-2 F/W may evade to interrupt 11 */
225 /* Model 95 has an additional alphanumeric display, which can be used
226 to display SCSI-activities. 8595 models do not have any disk led, which
227 makes this feature quite useful.
228 The regular PS/2 disk led is turned on/off by bits 6,7 of system
231 /* LED display-port (actually, last LED on display) */
232 #define MOD95_LED_PORT 0x108
233 /* system-control-register of PS/2s with diskindicator */
234 #define PS2_SYS_CTR 0x92
235 /* activity displaying methods */
238 #define LED_ACTIVITY 4
242 /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED
243 displays. ldn is no longer displayed here, because the ldn mapping is now
244 done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime
245 or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble,
246 interest, debugging or just for having fun. The left number gives the
247 host-adapter number and the right shows the accessed SCSI-ID. */
249 /* display_mode is set by the ibmmcascsi= command line arg */
250 static int display_mode = 0;
251 /* set default adapter timeout */
252 static unsigned int adapter_timeout = 45;
253 /* for probing on feature-command: */
254 static unsigned int global_command_error_excuse = 0;
255 /* global setting by command line for adapter_speed */
256 static int global_adapter_speed = 0; /* full speed by default */
258 /* Panel / LED on, do it right for F/W addressin, too. adisplay will
259 * just ignore ids>7, as the panel has only 7 digits available */
260 #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \
261 outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \
262 outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \
263 if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \
264 outb((char)(ad+48), MOD95_LED_PORT); } \
265 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
266 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); }
268 /* Panel / LED off */
269 /* bug fixed, Dec 15, 1997, where | was replaced by & here */
270 #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \
271 outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \
272 outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \
273 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
274 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); }
276 /* types of different supported hardware that goes to hostdata special */
277 #define IBM_SCSI2_FW 0
278 #define IBM_7568_WCACHE 1
279 #define IBM_EXP_UNIT 2
280 #define IBM_SCSI_WCACHE 3
282 #define IBM_INTEGSCSI 5
284 /* other special flags for hostdata structure */
285 #define FORCED_DETECTION 100
286 #define INTEGRATED_SCSI 101
288 /* List of possible IBM-SCSI-adapters */
289 static short ibmmca_id_table[] = {
295 /* No entry for integrated SCSI, that's part of the register */
299 static const char *ibmmca_description[] = {
300 "IBM SCSI-2 F/W Adapter", /* special = 0 */
301 "IBM 7568 Industrial Computer SCSI Adapter w/Cache", /* special = 1 */
302 "IBM Expansion Unit SCSI Controller", /* special = 2 */
303 "IBM SCSI Adapter w/Cache", /* special = 3 */
304 "IBM SCSI Adapter", /* special = 4 */
305 "IBM Integrated SCSI Controller", /* special = 5 */
308 /* Max number of logical devices (can be up from 0 to 14). 15 is the address
309 of the adapter itself. */
310 #define MAX_LOG_DEV 15
312 /*local data for a logical device */
313 struct logical_device {
314 struct im_scb scb; /* SCSI-subsystem-control-block structure */
315 struct im_tsb tsb; /* SCSI command complete status block structure */
316 struct im_sge sge[16]; /* scatter gather list structure */
317 unsigned char buf[256]; /* SCSI command return data buffer */
318 Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */
319 int device_type; /* type of the SCSI-device. See include/scsi/scsi.h
320 for interpretation of the possible values */
321 int block_length; /* blocksize of a particular logical SCSI-device */
322 int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */
323 int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */
326 /* statistics of the driver during operations (for proc_info) */
327 struct Driver_Statistics {
328 /* SCSI statistics on the adapter */
329 int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */
330 int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */
331 int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */
332 int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */
333 int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */
334 int scbs; /* short SCBs queued */
335 int long_scbs; /* long SCBs queued */
336 int total_accesses; /* total accesses on all ldns */
337 int total_interrupts; /* total interrupts (should be
338 same as total_accesses) */
339 int total_errors; /* command completed with error */
340 /* dynamical assignment statistics */
341 int total_scsi_devices; /* number of physical pun,lun */
342 int dyn_flag; /* flag showing dynamical mode */
343 int dynamical_assignments; /* number of remappings of ldns */
344 int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each
348 /* data structure for each host adapter */
349 struct ibmmca_hostdata {
350 /* array of logical devices: */
351 struct logical_device _ld[MAX_LOG_DEV + 1];
352 /* array to convert (pun, lun) into logical device number: */
353 unsigned char _get_ldn[16][8];
354 /*array that contains the information about the physical SCSI-devices
355 attached to this host adapter: */
356 unsigned char _get_scsi[16][8];
357 /* used only when checking logical devices: */
358 int _local_checking_phase_flag;
359 /* report received interrupt: */
361 /* report termination-status of SCSI-command: */
363 /* reset status (used only when doing reset): */
365 /* code of the last SCSI command (needed for panic info): */
366 int _last_scsi_command[MAX_LOG_DEV + 1];
367 /* identifier of the last SCSI-command type */
368 int _last_scsi_type[MAX_LOG_DEV + 1];
369 /* last blockcount */
370 int _last_scsi_blockcount[MAX_LOG_DEV + 1];
371 /* last locgical block address */
372 unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1];
373 /* Counter that points on the next reassignable ldn for dynamical
374 remapping. The default value is 7, that is the first reassignable
375 number in the list at boottime: */
377 /* Statistics-structure for this IBM-SCSI-host: */
378 struct Driver_Statistics _IBM_DS;
379 /* This hostadapters pos-registers pos2 until pos6 */
380 unsigned int _pos[8];
381 /* assign a special variable, that contains dedicated info about the
384 /* connector size on the MCA bus */
386 /* synchronous SCSI transfer rate bitpattern */
390 /* macros to access host data structure */
391 #define subsystem_pun(h) ((h)->this_id)
392 #define subsystem_maxid(h) ((h)->max_id)
393 #define ld(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_ld)
394 #define get_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_ldn)
395 #define get_scsi(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_scsi)
396 #define local_checking_phase_flag(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_local_checking_phase_flag)
397 #define got_interrupt(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_got_interrupt)
398 #define stat_result(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_stat_result)
399 #define reset_status(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_reset_status)
400 #define last_scsi_command(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_command)
401 #define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type)
402 #define last_scsi_blockcount(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_blockcount)
403 #define last_scsi_logical_block(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_logical_block)
404 #define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type)
405 #define next_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_next_ldn)
406 #define IBM_DS(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_IBM_DS)
407 #define special(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_special)
408 #define subsystem_connector_size(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_connector_size)
409 #define adapter_speed(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_adapter_speed)
410 #define pos2(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[2])
411 #define pos3(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[3])
412 #define pos4(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[4])
413 #define pos5(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[5])
414 #define pos6(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[6])
416 /* Define a arbitrary number as subsystem-marker-type. This number is, as
417 described in the ANSI-SCSI-standard, not occupied by other device-types. */
418 #define TYPE_IBM_SCSI_ADAPTER 0x2F
420 /* Define 0xFF for no device type, because this type is not defined within
421 the ANSI-SCSI-standard, therefore, it can be used and should not cause any
423 #define TYPE_NO_DEVICE 0xFF
425 /* define medium-changer. If this is not defined previously, e.g. Linux
426 2.0.x, define this type here. */
427 #ifndef TYPE_MEDIUM_CHANGER
428 #define TYPE_MEDIUM_CHANGER 0x08
431 /* define possible operations for the immediate_assign command */
435 /* ldn which is used to probe the SCSI devices */
438 /* reset status flag contents */
439 #define IM_RESET_NOT_IN_PROGRESS 0
440 #define IM_RESET_IN_PROGRESS 1
441 #define IM_RESET_FINISHED_OK 2
442 #define IM_RESET_FINISHED_FAIL 3
443 #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4
444 #define IM_RESET_FINISHED_OK_NO_INT 5
446 /* define undefined SCSI-command */
447 #define NO_SCSI 0xffff
449 /*-----------------------------------------------------------------------*/
451 /* if this is nonzero, ibmmcascsi option has been passed to the kernel */
452 static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
453 static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 };
455 /* fill module-parameters only, when this define is present.
456 (that is kernel version 2.1.x) */
458 static char *boot_options = NULL;
459 module_param(boot_options, charp, 0);
460 module_param_array(io_port, int, NULL, 0);
461 module_param_array(scsi_id, int, NULL, 0);
463 MODULE_LICENSE("GPL");
465 /*counter of concurrent disk read/writes, to turn on/off disk led */
466 static int disk_rw_in_progress = 0;
468 static unsigned int pos[8]; /* whole pos register-line for diagnosis */
469 /* Taking into account the additions, made by ZP Gu.
470 * This selects now the preset value from the configfile and
471 * offers the 'normal' commandline option to be accepted */
472 #ifdef CONFIG_IBMMCA_SCSI_ORDER_STANDARD
473 static char ibm_ansi_order = 1;
475 static char ibm_ansi_order = 0;
478 static void issue_cmd(struct Scsi_Host *, unsigned long, unsigned char);
479 static void internal_done(Scsi_Cmnd * cmd);
480 static void check_devices(struct Scsi_Host *, int);
481 static int immediate_assign(struct Scsi_Host *, unsigned int, unsigned int, unsigned int, unsigned int);
482 static int immediate_feature(struct Scsi_Host *, unsigned int, unsigned int);
483 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
484 static int immediate_reset(struct Scsi_Host *, unsigned int);
486 static int device_inquiry(struct Scsi_Host *, int);
487 static int read_capacity(struct Scsi_Host *, int);
488 static int get_pos_info(struct Scsi_Host *);
489 static char *ti_p(int);
490 static char *ti_l(int);
491 static char *ibmrate(unsigned int, int);
492 static int probe_display(int);
493 static int probe_bus_mode(struct Scsi_Host *);
494 static int device_exists(struct Scsi_Host *, int, int *, int *);
495 static int option_setup(char *);
496 /* local functions needed for proc_info */
497 static int ldn_access_load(struct Scsi_Host *, int);
498 static int ldn_access_total_read_write(struct Scsi_Host *);
500 static irqreturn_t interrupt_handler(int irq, void *dev_id)
502 unsigned int intr_reg;
503 unsigned int cmd_result;
508 struct device *dev = dev_id;
509 struct Scsi_Host *shpnt = dev_get_drvdata(dev);
511 spin_lock_irqsave(shpnt->host_lock, flags);
513 if(!(inb(IM_STAT_REG(shpnt)) & IM_INTR_REQUEST)) {
514 spin_unlock_irqrestore(shpnt->host_lock, flags);
518 /* the reset-function already did all the job, even ints got
519 renabled on the subsystem, so just return */
520 if ((reset_status(shpnt) == IM_RESET_NOT_IN_PROGRESS_NO_INT) || (reset_status(shpnt) == IM_RESET_FINISHED_OK_NO_INT)) {
521 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS;
522 spin_unlock_irqrestore(shpnt->host_lock, flags);
526 /*must wait for attention reg not busy, then send EOI to subsystem */
528 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
533 /*get command result and logical device */
534 intr_reg = (unsigned char) (inb(IM_INTR_REG(shpnt)));
535 cmd_result = intr_reg & 0xf0;
536 ldn = intr_reg & 0x0f;
537 /* get the last_scsi_command here */
538 lastSCSI = last_scsi_command(shpnt)[ldn];
539 outb(IM_EOI | ldn, IM_ATTN_REG(shpnt));
541 /*these should never happen (hw fails, or a local programming bug) */
542 if (!global_command_error_excuse) {
543 switch (cmd_result) {
544 /* Prevent from Ooopsing on error to show the real reason */
545 case IM_ADAPTER_HW_FAILURE:
546 case IM_SOFTWARE_SEQUENCING_ERROR:
548 printk(KERN_ERR "IBM MCA SCSI: Fatal Subsystem ERROR!\n");
549 printk(KERN_ERR " Last cmd=0x%x, ena=%x, len=", lastSCSI, ld(shpnt)[ldn].scb.enable);
550 if (ld(shpnt)[ldn].cmd)
551 printk("%ld/%ld,", (long) (scsi_bufflen(ld(shpnt)[ldn].cmd)), (long) (ld(shpnt)[ldn].scb.sys_buf_length));
554 if (ld(shpnt)[ldn].cmd)
555 printk("Blocksize=%d", ld(shpnt)[ldn].scb.u2.blk.length);
557 printk("Blocksize=none");
558 printk(", host=%p, ldn=0x%x\n", shpnt, ldn);
559 if (ld(shpnt)[ldn].cmd) {
560 printk(KERN_ERR "Blockcount=%d/%d\n", last_scsi_blockcount(shpnt)[ldn], ld(shpnt)[ldn].scb.u2.blk.count);
561 printk(KERN_ERR "Logical block=%lx/%lx\n", last_scsi_logical_block(shpnt)[ldn], ld(shpnt)[ldn].scb.u1.log_blk_adr);
563 printk(KERN_ERR "Reason given: %s\n", (cmd_result == IM_ADAPTER_HW_FAILURE) ? "HARDWARE FAILURE" : (cmd_result == IM_SOFTWARE_SEQUENCING_ERROR) ? "SOFTWARE SEQUENCING ERROR" : (cmd_result == IM_CMD_ERROR) ? "COMMAND ERROR" : "UNKNOWN");
564 /* if errors appear, enter this section to give detailed info */
565 printk(KERN_ERR "IBM MCA SCSI: Subsystem Error-Status follows:\n");
566 printk(KERN_ERR " Command Type................: %x\n", last_scsi_type(shpnt)[ldn]);
567 printk(KERN_ERR " Attention Register..........: %x\n", inb(IM_ATTN_REG(shpnt)));
568 printk(KERN_ERR " Basic Control Register......: %x\n", inb(IM_CTR_REG(shpnt)));
569 printk(KERN_ERR " Interrupt Status Register...: %x\n", intr_reg);
570 printk(KERN_ERR " Basic Status Register.......: %x\n", inb(IM_STAT_REG(shpnt)));
571 if ((last_scsi_type(shpnt)[ldn] == IM_SCB) || (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB)) {
572 printk(KERN_ERR " SCB-Command.................: %x\n", ld(shpnt)[ldn].scb.command);
573 printk(KERN_ERR " SCB-Enable..................: %x\n", ld(shpnt)[ldn].scb.enable);
574 printk(KERN_ERR " SCB-logical block address...: %lx\n", ld(shpnt)[ldn].scb.u1.log_blk_adr);
575 printk(KERN_ERR " SCB-system buffer address...: %lx\n", ld(shpnt)[ldn].scb.sys_buf_adr);
576 printk(KERN_ERR " SCB-system buffer length....: %lx\n", ld(shpnt)[ldn].scb.sys_buf_length);
577 printk(KERN_ERR " SCB-tsb address.............: %lx\n", ld(shpnt)[ldn].scb.tsb_adr);
578 printk(KERN_ERR " SCB-Chain address...........: %lx\n", ld(shpnt)[ldn].scb.scb_chain_adr);
579 printk(KERN_ERR " SCB-block count.............: %x\n", ld(shpnt)[ldn].scb.u2.blk.count);
580 printk(KERN_ERR " SCB-block length............: %x\n", ld(shpnt)[ldn].scb.u2.blk.length);
582 printk(KERN_ERR " Send this report to the maintainer.\n");
583 panic("IBM MCA SCSI: Fatal error message from the subsystem (0x%X,0x%X)!\n", lastSCSI, cmd_result);
587 /* The command error handling is made silent, but we tell the
588 * calling function, that there is a reported error from the
590 switch (cmd_result) {
591 case IM_ADAPTER_HW_FAILURE:
592 case IM_SOFTWARE_SEQUENCING_ERROR:
594 global_command_error_excuse = CMD_FAIL;
597 global_command_error_excuse = 0;
601 /* if no panic appeared, increase the interrupt-counter */
602 IBM_DS(shpnt).total_interrupts++;
603 /*only for local checking phase */
604 if (local_checking_phase_flag(shpnt)) {
605 stat_result(shpnt) = cmd_result;
606 got_interrupt(shpnt) = 1;
607 reset_status(shpnt) = IM_RESET_FINISHED_OK;
608 last_scsi_command(shpnt)[ldn] = NO_SCSI;
609 spin_unlock_irqrestore(shpnt->host_lock, flags);
612 /* handling of commands coming from upper level of scsi driver */
613 if (last_scsi_type(shpnt)[ldn] == IM_IMM_CMD) {
614 /* verify ldn, and may handle rare reset immediate command */
615 if ((reset_status(shpnt) == IM_RESET_IN_PROGRESS) && (last_scsi_command(shpnt)[ldn] == IM_RESET_IMM_CMD)) {
616 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
617 disk_rw_in_progress = 0;
619 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
621 /*reset disk led counter, turn off disk led */
622 disk_rw_in_progress = 0;
624 reset_status(shpnt) = IM_RESET_FINISHED_OK;
626 stat_result(shpnt) = cmd_result;
627 last_scsi_command(shpnt)[ldn] = NO_SCSI;
628 last_scsi_type(shpnt)[ldn] = 0;
629 spin_unlock_irqrestore(shpnt->host_lock, flags);
631 } else if (last_scsi_command(shpnt)[ldn] == IM_ABORT_IMM_CMD) {
632 /* react on SCSI abort command */
633 #ifdef IM_DEBUG_PROBE
634 printk("IBM MCA SCSI: Interrupt from SCSI-abort.\n");
636 disk_rw_in_progress = 0;
638 cmd = ld(shpnt)[ldn].cmd;
639 ld(shpnt)[ldn].cmd = NULL;
640 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE)
641 cmd->result = DID_NO_CONNECT << 16;
643 cmd->result = DID_ABORT << 16;
644 stat_result(shpnt) = cmd_result;
645 last_scsi_command(shpnt)[ldn] = NO_SCSI;
646 last_scsi_type(shpnt)[ldn] = 0;
648 (cmd->scsi_done) (cmd); /* should be the internal_done */
649 spin_unlock_irqrestore(shpnt->host_lock, flags);
652 disk_rw_in_progress = 0;
654 reset_status(shpnt) = IM_RESET_FINISHED_OK;
655 stat_result(shpnt) = cmd_result;
656 last_scsi_command(shpnt)[ldn] = NO_SCSI;
657 spin_unlock_irqrestore(shpnt->host_lock, flags);
661 last_scsi_command(shpnt)[ldn] = NO_SCSI;
662 last_scsi_type(shpnt)[ldn] = 0;
663 cmd = ld(shpnt)[ldn].cmd;
664 ld(shpnt)[ldn].cmd = NULL;
665 #ifdef IM_DEBUG_TIMEOUT
667 if ((cmd->target == TIMEOUT_PUN) && (cmd->device->lun == TIMEOUT_LUN)) {
668 spin_unlock_irqsave(shpnt->host_lock, flags);
669 printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", cmd->target, cmd->device->lun);
674 /*if no command structure, just return, else clear cmd */
677 spin_unlock_irqrestore(shpnt->host_lock, flags);
682 printk("cmd=%02x ireg=%02x ds=%02x cs=%02x de=%02x ce=%02x\n", cmd->cmnd[0], intr_reg, ld(shpnt)[ldn].tsb.dev_status, ld(shpnt)[ldn].tsb.cmd_status, ld(shpnt)[ldn].tsb.dev_error, ld(shpnt)[ldn].tsb.cmd_error);
684 /*if this is end of media read/write, may turn off PS/2 disk led */
685 if ((ld(shpnt)[ldn].device_type != TYPE_NO_LUN) && (ld(shpnt)[ldn].device_type != TYPE_NO_DEVICE)) {
686 /* only access this, if there was a valid device addressed */
687 if (--disk_rw_in_progress == 0)
691 /* IBM describes the status-mask to be 0x1e, but this is not conform
692 * with SCSI-definition, I suppose, the reason for it is that IBM
693 * adapters do not support CMD_TERMINATED, TASK_SET_FULL and
694 * ACA_ACTIVE as returning statusbyte information. (ML) */
695 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
696 cmd->result = (unsigned char) (ld(shpnt)[ldn].tsb.dev_status & 0x1e);
697 IBM_DS(shpnt).total_errors++;
700 /* write device status into cmd->result, and call done function */
701 if (lastSCSI == NO_SCSI) { /* unexpected interrupt :-( */
702 cmd->result |= DID_BAD_INTR << 16;
703 printk("IBM MCA SCSI: WARNING - Interrupt from non-pending SCSI-command!\n");
704 } else /* things went right :-) */
705 cmd->result |= DID_OK << 16;
707 (cmd->scsi_done) (cmd);
708 spin_unlock_irqrestore(shpnt->host_lock, flags);
712 static void issue_cmd(struct Scsi_Host *shpnt, unsigned long cmd_reg,
713 unsigned char attn_reg)
716 /* must wait for attention reg not busy */
718 spin_lock_irqsave(shpnt->host_lock, flags);
719 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
721 spin_unlock_irqrestore(shpnt->host_lock, flags);
723 /* write registers and enable system interrupts */
724 outl(cmd_reg, IM_CMD_REG(shpnt));
725 outb(attn_reg, IM_ATTN_REG(shpnt));
726 spin_unlock_irqrestore(shpnt->host_lock, flags);
729 static void internal_done(Scsi_Cmnd * cmd)
735 /* SCSI-SCB-command for device_inquiry */
736 static int device_inquiry(struct Scsi_Host *shpnt, int ldn)
743 scb = &(ld(shpnt)[ldn].scb);
744 tsb = &(ld(shpnt)[ldn].tsb);
745 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
746 ld(shpnt)[ldn].tsb.dev_status = 0; /* prepare statusblock */
747 for (retr = 0; retr < 3; retr++) {
748 /* fill scb with inquiry command */
749 scb->command = IM_DEVICE_INQUIRY_CMD | IM_NO_DISCONNECT;
750 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
751 last_scsi_command(shpnt)[ldn] = IM_DEVICE_INQUIRY_CMD;
752 last_scsi_type(shpnt)[ldn] = IM_SCB;
753 scb->sys_buf_adr = isa_virt_to_bus(buf);
754 scb->sys_buf_length = 255; /* maximum bufferlength gives max info */
755 scb->tsb_adr = isa_virt_to_bus(tsb);
756 /* issue scb to passed ldn, and busy wait for interrupt */
757 got_interrupt(shpnt) = 0;
758 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
759 while (!got_interrupt(shpnt))
762 /*if command successful, break */
763 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
766 /*if all three retries failed, return "no device at this ldn" */
773 static int read_capacity(struct Scsi_Host *shpnt, int ldn)
780 scb = &(ld(shpnt)[ldn].scb);
781 tsb = &(ld(shpnt)[ldn].tsb);
782 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
783 ld(shpnt)[ldn].tsb.dev_status = 0;
784 for (retr = 0; retr < 3; retr++) {
785 /*fill scb with read capacity command */
786 scb->command = IM_READ_CAPACITY_CMD;
787 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
788 last_scsi_command(shpnt)[ldn] = IM_READ_CAPACITY_CMD;
789 last_scsi_type(shpnt)[ldn] = IM_SCB;
790 scb->sys_buf_adr = isa_virt_to_bus(buf);
791 scb->sys_buf_length = 8;
792 scb->tsb_adr = isa_virt_to_bus(tsb);
793 /*issue scb to passed ldn, and busy wait for interrupt */
794 got_interrupt(shpnt) = 0;
795 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
796 while (!got_interrupt(shpnt))
799 /*if got capacity, get block length and return one device found */
800 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
803 /*if all three retries failed, return "no device at this ldn" */
810 static int get_pos_info(struct Scsi_Host *shpnt)
817 scb = &(ld(shpnt)[MAX_LOG_DEV].scb);
818 tsb = &(ld(shpnt)[MAX_LOG_DEV].tsb);
819 buf = (unsigned char *) (&(ld(shpnt)[MAX_LOG_DEV].buf));
820 ld(shpnt)[MAX_LOG_DEV].tsb.dev_status = 0;
821 for (retr = 0; retr < 3; retr++) {
822 /*fill scb with get_pos_info command */
823 scb->command = IM_GET_POS_INFO_CMD;
824 scb->enable = IM_READ_CONTROL | IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
825 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_GET_POS_INFO_CMD;
826 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_SCB;
827 scb->sys_buf_adr = isa_virt_to_bus(buf);
828 if (special(shpnt) == IBM_SCSI2_FW)
829 scb->sys_buf_length = 256; /* get all info from F/W adapter */
831 scb->sys_buf_length = 18; /* get exactly 18 bytes for other SCSI */
832 scb->tsb_adr = isa_virt_to_bus(tsb);
833 /*issue scb to ldn=15, and busy wait for interrupt */
834 got_interrupt(shpnt) = 0;
835 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | MAX_LOG_DEV);
838 while (!got_interrupt(shpnt))
841 /*if got POS-stuff, get block length and return one device found */
842 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
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(struct Scsi_Host *shpnt, unsigned int pun,
856 unsigned int lun, unsigned int ldn,
857 unsigned int operation)
860 unsigned long imm_cmd;
862 for (retr = 0; retr < 3; retr++) {
863 /* select mutation level of the SCSI-adapter */
864 switch (special(shpnt)) {
866 imm_cmd = (unsigned long) (IM_ASSIGN_IMM_CMD);
867 imm_cmd |= (unsigned long) ((lun & 7) << 24);
868 imm_cmd |= (unsigned long) ((operation & 1) << 23);
869 imm_cmd |= (unsigned long) ((pun & 7) << 20) | ((pun & 8) << 24);
870 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
873 imm_cmd = inl(IM_CMD_REG(shpnt));
874 imm_cmd &= (unsigned long) (0xF8000000); /* keep reserved bits */
875 imm_cmd |= (unsigned long) (IM_ASSIGN_IMM_CMD);
876 imm_cmd |= (unsigned long) ((lun & 7) << 24);
877 imm_cmd |= (unsigned long) ((operation & 1) << 23);
878 imm_cmd |= (unsigned long) ((pun & 7) << 20);
879 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
882 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_ASSIGN_IMM_CMD;
883 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD;
884 got_interrupt(shpnt) = 0;
885 issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
886 while (!got_interrupt(shpnt))
889 /*if command successful, break */
890 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
899 static int immediate_feature(struct Scsi_Host *shpnt, unsigned int speed, unsigned int timeout)
902 unsigned long imm_cmd;
904 for (retr = 0; retr < 3; retr++) {
905 /* select mutation level of the SCSI-adapter */
906 imm_cmd = IM_FEATURE_CTR_IMM_CMD;
907 imm_cmd |= (unsigned long) ((speed & 0x7) << 29);
908 imm_cmd |= (unsigned long) ((timeout & 0x1fff) << 16);
909 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_FEATURE_CTR_IMM_CMD;
910 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD;
911 got_interrupt(shpnt) = 0;
912 /* we need to run into command errors in order to probe for the
914 global_command_error_excuse = 1;
915 issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
918 while (!got_interrupt(shpnt))
920 if (global_command_error_excuse == CMD_FAIL) {
921 global_command_error_excuse = 0;
924 global_command_error_excuse = 0;
925 /*if command successful, break */
926 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
935 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
936 static int immediate_reset(struct Scsi_Host *shpnt, unsigned int ldn)
940 unsigned long imm_command;
942 for (retries = 0; retries < 3; retries++) {
943 imm_command = inl(IM_CMD_REG(shpnt));
944 imm_command &= (unsigned long) (0xFFFF0000); /* keep reserved bits */
945 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
946 last_scsi_command(shpnt)[ldn] = IM_RESET_IMM_CMD;
947 last_scsi_type(shpnt)[ldn] = IM_IMM_CMD;
948 got_interrupt(shpnt) = 0;
949 reset_status(shpnt) = IM_RESET_IN_PROGRESS;
950 issue_cmd(shpnt, (unsigned long) (imm_command), IM_IMM_CMD | ldn);
951 ticks = IM_RESET_DELAY * HZ;
952 while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks) {
953 udelay((1 + 999 / HZ) * 1000);
956 /* if reset did not complete, just complain */
958 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
959 reset_status(shpnt) = IM_RESET_FINISHED_OK;
960 /* did not work, finish */
963 /*if command successful, break */
964 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
974 /* type-interpreter for physical device numbers */
975 static char *ti_p(int dev)
978 case TYPE_IBM_SCSI_ADAPTER:
994 case TYPE_MEDIUM_CHANGER:
997 return ("+"); /* show NO_LUN */
999 return ("-"); /* TYPE_NO_DEVICE and others */
1002 /* interpreter for logical device numbers (ldn) */
1003 static char *ti_l(int val)
1005 const char hex[16] = "0123456789abcdef";
1006 static char answer[2];
1008 answer[1] = (char) (0x0);
1009 if (val <= MAX_LOG_DEV)
1010 answer[0] = hex[val];
1013 return (char *) &answer;
1016 /* transfers bitpattern of the feature command to values in MHz */
1017 static char *ibmrate(unsigned int speed, int i)
1021 return i ? "5.00" : "10.00";
1023 return i ? "4.00" : "8.00";
1025 return i ? "3.33" : "6.66";
1027 return i ? "2.86" : "5.00";
1029 return i ? "2.50" : "4.00";
1031 return i ? "2.22" : "3.10";
1033 return i ? "2.00" : "2.50";
1035 return i ? "1.82" : "2.00";
1040 static int probe_display(int what)
1042 static int rotator = 0;
1043 const char rotor[] = "|/-\\";
1045 if (!(display_mode & LED_DISP))
1048 outl(0x20202020, MOD95_LED_PORT);
1049 outl(0x20202020, MOD95_LED_PORT + 4);
1051 outb('S', MOD95_LED_PORT + 7);
1052 outb('C', MOD95_LED_PORT + 6);
1053 outb('S', MOD95_LED_PORT + 5);
1054 outb('I', MOD95_LED_PORT + 4);
1055 outb('i', MOD95_LED_PORT + 3);
1056 outb('n', MOD95_LED_PORT + 2);
1057 outb('i', MOD95_LED_PORT + 1);
1058 outb((char) (rotor[rotator]), MOD95_LED_PORT);
1066 static int probe_bus_mode(struct Scsi_Host *shpnt)
1068 struct im_pos_info *info;
1072 info = (struct im_pos_info *) (&(ld(shpnt)[MAX_LOG_DEV].buf));
1073 if (get_pos_info(shpnt)) {
1074 if (info->connector_size & 0xf000)
1075 subsystem_connector_size(shpnt) = 16;
1077 subsystem_connector_size(shpnt) = 32;
1078 num_bus |= (info->pos_4b & 8) >> 3;
1079 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1080 if ((special(shpnt) == IBM_SCSI_WCACHE) || (special(shpnt) == IBM_7568_WCACHE)) {
1081 if (!((info->cache_stat >> ldn) & 1))
1082 ld(shpnt)[ldn].cache_flag = 0;
1084 if (!((info->retry_stat >> ldn) & 1))
1085 ld(shpnt)[ldn].retry_flag = 0;
1087 #ifdef IM_DEBUG_PROBE
1088 printk("IBM MCA SCSI: SCSI-Cache bits: ");
1089 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1090 printk("%d", ld(shpnt)[ldn].cache_flag);
1092 printk("\nIBM MCA SCSI: SCSI-Retry bits: ");
1093 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1094 printk("%d", ld(shpnt)[ldn].retry_flag);
1102 /* probing scsi devices */
1103 static void check_devices(struct Scsi_Host *shpnt, int adaptertype)
1105 int id, lun, ldn, ticks;
1106 int count_devices; /* local counter for connected device */
1109 int speedrun; /* local adapter_speed check variable */
1111 /* assign default values to certain variables */
1114 IBM_DS(shpnt).dyn_flag = 0; /* normally no need for dynamical ldn management */
1115 IBM_DS(shpnt).total_errors = 0; /* set errorcounter to 0 */
1116 next_ldn(shpnt) = 7; /* next ldn to be assigned is 7, because 0-6 is 'hardwired' */
1118 /* initialize the very important driver-informational arrays/structs */
1119 memset(ld(shpnt), 0, sizeof(ld(shpnt)));
1120 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
1121 last_scsi_command(shpnt)[ldn] = NO_SCSI; /* emptify last SCSI-command storage */
1122 last_scsi_type(shpnt)[ldn] = 0;
1123 ld(shpnt)[ldn].cache_flag = 1;
1124 ld(shpnt)[ldn].retry_flag = 1;
1126 memset(get_ldn(shpnt), TYPE_NO_DEVICE, sizeof(get_ldn(shpnt))); /* this is essential ! */
1127 memset(get_scsi(shpnt), TYPE_NO_DEVICE, sizeof(get_scsi(shpnt))); /* this is essential ! */
1128 for (lun = 0; lun < 8; lun++) {
1129 /* mark the adapter at its pun on all luns */
1130 get_scsi(shpnt)[subsystem_pun(shpnt)][lun] = TYPE_IBM_SCSI_ADAPTER;
1131 get_ldn(shpnt)[subsystem_pun(shpnt)][lun] = MAX_LOG_DEV; /* make sure, the subsystem
1132 ldn is active for all
1135 probe_display(0); /* Supercool display usage during SCSI-probing. */
1136 /* This makes sense, when booting without any */
1137 /* monitor connected on model XX95. */
1140 adapter_speed(shpnt) = global_adapter_speed;
1141 speedrun = adapter_speed(shpnt);
1142 while (immediate_feature(shpnt, speedrun, adapter_timeout) == 2) {
1145 panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n");
1150 adapter_speed(shpnt) = speedrun;
1151 /* Get detailed information about the current adapter, necessary for
1152 * device operations: */
1153 num_bus = probe_bus_mode(shpnt);
1155 /* num_bus contains only valid data for the F/W adapter! */
1156 if (adaptertype == IBM_SCSI2_FW) { /* F/W SCSI adapter: */
1157 /* F/W adapter PUN-space extension evaluation: */
1159 printk(KERN_INFO "IBM MCA SCSI: Separate bus mode (wide-addressing enabled)\n");
1160 subsystem_maxid(shpnt) = 16;
1162 printk(KERN_INFO "IBM MCA SCSI: Combined bus mode (wide-addressing disabled)\n");
1163 subsystem_maxid(shpnt) = 8;
1165 printk(KERN_INFO "IBM MCA SCSI: Sync.-Rate (F/W: 20, Int.: 10, Ext.: %s) MBytes/s\n", ibmrate(speedrun, adaptertype));
1166 } else /* all other IBM SCSI adapters: */
1167 printk(KERN_INFO "IBM MCA SCSI: Synchronous-SCSI-Transfer-Rate: %s MBytes/s\n", ibmrate(speedrun, adaptertype));
1169 /* assign correct PUN device space */
1170 max_pun = subsystem_maxid(shpnt);
1172 #ifdef IM_DEBUG_PROBE
1173 printk("IBM MCA SCSI: Current SCSI-host index: %d\n", shpnt);
1174 printk("IBM MCA SCSI: Removing default logical SCSI-device mapping.");
1176 printk(KERN_INFO "IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", (ibm_ansi_order) ? "ANSI" : "New");
1178 for (ldn = 0; ldn < MAX_LOG_DEV; ldn++) {
1180 #ifdef IM_DEBUG_PROBE
1183 immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN); /* remove ldn (wherever) */
1185 lun = 0; /* default lun is 0 */
1186 #ifndef IM_DEBUG_PROBE
1190 #ifdef IM_DEBUG_PROBE
1191 printk("\nIBM MCA SCSI: Scanning SCSI-devices.");
1193 for (id = 0; id < max_pun; id++)
1194 #ifdef CONFIG_SCSI_MULTI_LUN
1195 for (lun = 0; lun < 8; lun++)
1199 #ifdef IM_DEBUG_PROBE
1202 if (id != subsystem_pun(shpnt)) {
1203 /* if pun is not the adapter: */
1204 /* set ldn=0 to pun,lun */
1205 immediate_assign(shpnt, id, lun, PROBE_LDN, SET_LDN);
1206 if (device_inquiry(shpnt, PROBE_LDN)) { /* probe device */
1207 get_scsi(shpnt)[id][lun] = (unsigned char) (ld(shpnt)[PROBE_LDN].buf[0]);
1208 /* entry, even for NO_LUN */
1209 if (ld(shpnt)[PROBE_LDN].buf[0] != TYPE_NO_LUN)
1210 count_devices++; /* a existing device is found */
1213 immediate_assign(shpnt, id, lun, PROBE_LDN, REMOVE_LDN);
1216 #ifndef IM_DEBUG_PROBE
1220 #ifdef IM_DEBUG_PROBE
1221 printk("\nIBM MCA SCSI: Mapping SCSI-devices.");
1225 #ifdef CONFIG_SCSI_MULTI_LUN
1226 for (lun = 0; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1228 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1230 #ifdef IM_DEBUG_PROBE
1233 if (id != subsystem_pun(shpnt)) {
1234 if (get_scsi(shpnt)[id][lun] != TYPE_NO_LUN && get_scsi(shpnt)[id][lun] != TYPE_NO_DEVICE) {
1235 /* Only map if accepted type. Always enter for
1236 lun == 0 to get no gaps into ldn-mapping for ldn<7. */
1237 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1238 get_ldn(shpnt)[id][lun] = ldn; /* map ldn */
1239 if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) {
1240 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
1241 printk("resetting device at ldn=%x ... ", ldn);
1242 immediate_reset(shpnt, ldn);
1246 /* device vanished, probably because we don't know how to
1247 * handle it or because it has problems */
1249 /* remove mapping */
1250 get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE;
1251 immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN);
1255 } else if (lun == 0) {
1256 /* map lun == 0, even if no device exists */
1257 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1258 get_ldn(shpnt)[id][lun] = ldn; /* map ldn */
1265 /* map remaining ldns to non-existing devices */
1266 for (lun = 1; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1267 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1268 if (get_scsi(shpnt)[id][lun] == TYPE_NO_LUN || get_scsi(shpnt)[id][lun] == TYPE_NO_DEVICE) {
1270 /* Map remaining ldns only to NON-existing pun,lun
1271 combinations to make sure an inquiry will fail.
1272 For MULTI_LUN, it is needed to avoid adapter autonome
1274 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1275 get_ldn(shpnt)[id][lun] = ldn;
1279 #ifndef IM_DEBUG_PROBE
1283 #ifdef IM_DEBUG_PROBE
1285 printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n");
1287 printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n");
1290 #ifdef IM_DEBUG_PROBE
1291 /* Show the physical and logical mapping during boot. */
1292 printk("IBM MCA SCSI: Determined SCSI-device-mapping:\n");
1293 printk(" Physical SCSI-Device Map Logical SCSI-Device Map\n");
1294 printk("ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n");
1295 for (id = 0; id < max_pun; id++) {
1297 for (lun = 0; lun < 8; lun++)
1298 printk("%2s ", ti_p(get_scsi(shpnt)[id][lun]));
1299 printk(" %2d ", id);
1300 for (lun = 0; lun < 8; lun++)
1301 printk("%2s ", ti_l(get_ldn(shpnt)[id][lun]));
1306 /* assign total number of found SCSI-devices to the statistics struct */
1307 IBM_DS(shpnt).total_scsi_devices = count_devices;
1309 /* decide for output in /proc-filesystem, if the configuration of
1310 SCSI-devices makes dynamical reassignment of devices necessary */
1311 if (count_devices >= MAX_LOG_DEV)
1312 IBM_DS(shpnt).dyn_flag = 1; /* dynamical assignment is necessary */
1314 IBM_DS(shpnt).dyn_flag = 0; /* dynamical assignment is not necessary */
1316 /* If no SCSI-devices are assigned, return 1 in order to cause message. */
1318 printk("IBM MCA SCSI: Warning: No SCSI-devices found/assigned!\n");
1320 /* reset the counters for statistics on the current adapter */
1321 IBM_DS(shpnt).scbs = 0;
1322 IBM_DS(shpnt).long_scbs = 0;
1323 IBM_DS(shpnt).total_accesses = 0;
1324 IBM_DS(shpnt).total_interrupts = 0;
1325 IBM_DS(shpnt).dynamical_assignments = 0;
1326 memset(IBM_DS(shpnt).ldn_access, 0x0, sizeof(IBM_DS(shpnt).ldn_access));
1327 memset(IBM_DS(shpnt).ldn_read_access, 0x0, sizeof(IBM_DS(shpnt).ldn_read_access));
1328 memset(IBM_DS(shpnt).ldn_write_access, 0x0, sizeof(IBM_DS(shpnt).ldn_write_access));
1329 memset(IBM_DS(shpnt).ldn_inquiry_access, 0x0, sizeof(IBM_DS(shpnt).ldn_inquiry_access));
1330 memset(IBM_DS(shpnt).ldn_modeselect_access, 0x0, sizeof(IBM_DS(shpnt).ldn_modeselect_access));
1331 memset(IBM_DS(shpnt).ldn_assignments, 0x0, sizeof(IBM_DS(shpnt).ldn_assignments));
1336 static int device_exists(struct Scsi_Host *shpnt, int ldn, int *block_length, int *device_type)
1339 /* if no valid device found, return immediately with 0 */
1340 if (!(device_inquiry(shpnt, ldn)))
1342 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
1343 if (*buf == TYPE_ROM) {
1344 *device_type = TYPE_ROM;
1345 *block_length = 2048; /* (standard blocksize for yellow-/red-book) */
1348 if (*buf == TYPE_WORM) {
1349 *device_type = TYPE_WORM;
1350 *block_length = 2048;
1353 if (*buf == TYPE_DISK) {
1354 *device_type = TYPE_DISK;
1355 if (read_capacity(shpnt, ldn)) {
1356 *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24);
1361 if (*buf == TYPE_MOD) {
1362 *device_type = TYPE_MOD;
1363 if (read_capacity(shpnt, ldn)) {
1364 *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24);
1369 if (*buf == TYPE_TAPE) {
1370 *device_type = TYPE_TAPE;
1371 *block_length = 0; /* not in use (setting by mt and mtst in op.) */
1374 if (*buf == TYPE_PROCESSOR) {
1375 *device_type = TYPE_PROCESSOR;
1376 *block_length = 0; /* they set their stuff on drivers */
1379 if (*buf == TYPE_SCANNER) {
1380 *device_type = TYPE_SCANNER;
1381 *block_length = 0; /* they set their stuff on drivers */
1384 if (*buf == TYPE_MEDIUM_CHANGER) {
1385 *device_type = TYPE_MEDIUM_CHANGER;
1386 *block_length = 0; /* One never knows, what to expect on a medium
1393 static void internal_ibmmca_scsi_setup(char *str, int *ints)
1395 int i, j, io_base, id_base;
1402 while ((token = strsep(&str, ",")) != NULL) {
1403 if (!strcmp(token, "activity"))
1404 display_mode |= LED_ACTIVITY;
1405 if (!strcmp(token, "display"))
1406 display_mode |= LED_DISP;
1407 if (!strcmp(token, "adisplay"))
1408 display_mode |= LED_ADISP;
1409 if (!strcmp(token, "normal"))
1411 if (!strcmp(token, "ansi"))
1413 if (!strcmp(token, "fast"))
1414 global_adapter_speed = 0;
1415 if (!strcmp(token, "medium"))
1416 global_adapter_speed = 4;
1417 if (!strcmp(token, "slow"))
1418 global_adapter_speed = 7;
1419 if ((*token == '-') || (isdigit(*token))) {
1420 if (!(j % 2) && (io_base < IM_MAX_HOSTS))
1421 io_port[io_base++] = simple_strtoul(token, NULL, 0);
1422 if ((j % 2) && (id_base < IM_MAX_HOSTS))
1423 scsi_id[id_base++] = simple_strtoul(token, NULL, 0);
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];
1437 FIXME NEED TO MOVE TO SYSFS
1439 static int ibmmca_getinfo(char *buf, int slot, void *dev_id)
1441 struct Scsi_Host *shpnt;
1442 int len, speciale, connectore, k;
1443 unsigned int pos[8];
1444 unsigned long flags;
1445 struct Scsi_Host *dev = dev_id;
1447 spin_lock_irqsave(dev->host_lock, flags);
1449 shpnt = dev; /* assign host-structure to local pointer */
1450 len = 0; /* set filled text-buffer index to 0 */
1451 /* get the _special contents of the hostdata structure */
1452 speciale = ((struct ibmmca_hostdata *) shpnt->hostdata)->_special;
1453 connectore = ((struct ibmmca_hostdata *) shpnt->hostdata)->_connector_size;
1454 for (k = 2; k < 4; k++)
1455 pos[k] = ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k];
1456 if (speciale == FORCED_DETECTION) { /* forced detection */
1457 len += sprintf(buf + len,
1458 "Adapter category: forced detected\n" "***************************************\n" "*** Forced detected SCSI Adapter ***\n" "*** No chip-information available ***\n" "***************************************\n");
1459 } else if (speciale == INTEGRATED_SCSI) {
1460 /* if the integrated subsystem has been found automatically: */
1461 len += sprintf(buf + len,
1462 "Adapter category: integrated\n" "Chip revision level: %d\n" "Chip status: %s\n" "8 kByte NVRAM status: %s\n", ((pos[2] & 0xf0) >> 4), (pos[2] & 1) ? "enabled" : "disabled", (pos[2] & 2) ? "locked" : "accessible");
1463 } else if ((speciale >= 0) && (speciale < ARRAY_SIZE(subsys_list))) {
1464 /* if the subsystem is a slot adapter */
1465 len += sprintf(buf + len, "Adapter category: slot-card\n" "ROM Segment Address: ");
1466 if ((pos[2] & 0xf0) == 0xf0)
1467 len += sprintf(buf + len, "off\n");
1469 len += sprintf(buf + len, "0x%x\n", ((pos[2] & 0xf0) << 13) + 0xc0000);
1470 len += sprintf(buf + len, "Chip status: %s\n", (pos[2] & 1) ? "enabled" : "disabled");
1471 len += sprintf(buf + len, "Adapter I/O Offset: 0x%x\n", ((pos[2] & 0x0e) << 2));
1473 len += sprintf(buf + len, "Adapter category: unknown\n");
1475 /* common subsystem information to write to the slotn file */
1476 len += sprintf(buf + len, "Subsystem PUN: %d\n", shpnt->this_id);
1477 len += sprintf(buf + len, "I/O base address range: 0x%x-0x%x\n", (unsigned int) (shpnt->io_port), (unsigned int) (shpnt->io_port + 7));
1478 len += sprintf(buf + len, "MCA-slot size: %d bits", connectore);
1479 /* Now make sure, the bufferlength is devidable by 4 to avoid
1480 * paging problems of the buffer. */
1481 while (len % sizeof(int) != (sizeof(int) - 1))
1482 len += sprintf(buf + len, " ");
1483 len += sprintf(buf + len, "\n");
1485 spin_unlock_irqrestore(shpnt->host_lock, flags);
1491 static struct scsi_host_template ibmmca_driver_template = {
1492 .proc_name = "ibmmca",
1493 .proc_info = ibmmca_proc_info,
1494 .name = "IBM SCSI-Subsystem",
1495 .queuecommand = ibmmca_queuecommand,
1496 .eh_abort_handler = ibmmca_abort,
1497 .eh_host_reset_handler = ibmmca_host_reset,
1498 .bios_param = ibmmca_biosparam,
1503 .use_clustering = ENABLE_CLUSTERING,
1506 static int ibmmca_probe(struct device *dev)
1508 struct Scsi_Host *shpnt;
1509 int port, id, i, j, k, irq, enabled, ret = -EINVAL;
1510 struct mca_device *mca_dev = to_mca_device(dev);
1511 const char *description = ibmmca_description[mca_dev->index];
1513 /* First of all, print the version number of the driver. This is
1514 * important to allow better user bugreports in case of already
1515 * having problems with the MCA_bus probing. */
1516 printk(KERN_INFO "IBM MCA SCSI: Version %s\n", IBMMCA_SCSI_DRIVER_VERSION);
1517 /* The POS2-register of all PS/2 model SCSI-subsystems has the following
1518 * interpretation of bits:
1519 * Bit 7 - 4 : Chip Revision ID (Release)
1520 * Bit 3 - 2 : Reserved
1521 * Bit 1 : 8k NVRAM Disabled
1522 * Bit 0 : Chip Enable (EN-Signal)
1523 * The POS3-register is interpreted as follows:
1524 * Bit 7 - 5 : SCSI ID
1525 * Bit 4 : Reserved = 0
1526 * Bit 3 - 0 : Reserved = 0
1527 * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common
1528 * Interfaces (1991)").
1529 * In short words, this means, that IBM PS/2 machines only support
1530 * 1 single subsystem by default. The slot-adapters must have another
1531 * configuration on pos2. Here, one has to assume the following
1532 * things for POS2-register:
1533 * Bit 7 - 4 : Chip Revision ID (Release)
1534 * Bit 3 - 1 : port offset factor
1535 * Bit 0 : Chip Enable (EN-Signal)
1536 * As I found a patch here, setting the IO-registers to 0x3540 forced,
1537 * as there was a 0x05 in POS2 on a model 56, I assume, that the
1538 * port 0x3540 must be fix for integrated SCSI-controllers.
1539 * Ok, this discovery leads to the following implementation: (M.Lang) */
1541 /* first look for the IBM SCSI integrated subsystem on the motherboard */
1542 for (j = 0; j < 8; j++) /* read the pos-information */
1543 pos[j] = mca_device_read_pos(mca_dev, j);
1544 id = (pos[3] & 0xe0) >> 5; /* this is correct and represents the PUN */
1545 enabled = (pos[2] &0x01);
1547 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1548 printk(KERN_WARNING " SCSI-operations may not work.\n");
1551 /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but
1552 * if we ignore the settings of all surrounding pos registers, it is not
1553 * completely sufficient to only check pos2 and pos3. */
1554 /* Therefore, now the following if statement is used to
1555 * make sure, we see a real integrated onboard SCSI-interface and no
1556 * internal system information, which gets mapped to some pos registers
1557 * on models 95xx. */
1558 if (mca_dev->slot == MCA_INTEGSCSI &&
1559 ((!pos[0] && !pos[1] && pos[2] > 0 &&
1560 pos[3] > 0 && !pos[4] && !pos[5] &&
1561 !pos[6] && !pos[7]) ||
1562 (pos[0] == 0xff && pos[1] == 0xff &&
1563 pos[2] < 0xff && pos[3] < 0xff &&
1564 pos[4] == 0xff && pos[5] == 0xff &&
1565 pos[6] == 0xff && pos[7] == 0xff))) {
1570 port = IM_IO_PORT + ((pos[2] &0x0e) << 2);
1571 if ((mca_dev->index == IBM_SCSI2_FW) && (pos[6] != 0)) {
1572 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1573 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1574 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1577 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1578 if (mca_dev->index == IBM_SCSI2_FW) {
1579 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1580 * for F/W adapters */
1583 if ((mca_dev->index == IBM_SCSI2_FW) &&
1584 (pos[4] & 0x01) && (pos[6] == 0)) {
1585 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1586 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1593 /* give detailed information on the subsystem. This helps me
1594 * additionally during debugging and analyzing bug-reports. */
1595 printk(KERN_INFO "IBM MCA SCSI: %s found, io=0x%x, scsi id=%d,\n",
1596 description, port, id);
1597 if (mca_dev->slot == MCA_INTEGSCSI)
1598 printk(KERN_INFO " chip rev.=%d, 8K NVRAM=%s, subsystem=%s\n", ((pos[2] & 0xf0) >> 4), (pos[2] & 2) ? "locked" : "accessible", (pos[2] & 1) ? "enabled." : "disabled.");
1600 if ((pos[2] & 0xf0) == 0xf0)
1601 printk(KERN_DEBUG " ROM Addr.=off,");
1603 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
1605 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
1608 /* check I/O region */
1609 if (!request_region(port, IM_N_IO_PORT, description)) {
1610 printk(KERN_ERR "IBM MCA SCSI: Unable to get I/O region 0x%x-0x%x (%d ports).\n", port, port + IM_N_IO_PORT - 1, IM_N_IO_PORT);
1615 shpnt = scsi_host_alloc(&ibmmca_driver_template,
1616 sizeof(struct ibmmca_hostdata));
1618 printk(KERN_ERR "IBM MCA SCSI: Unable to register host.\n");
1622 dev_set_drvdata(dev, shpnt);
1623 if(request_irq(irq, interrupt_handler, IRQF_SHARED, description, dev)) {
1624 printk(KERN_ERR "IBM MCA SCSI: failed to request interrupt %d\n", irq);
1628 /* request I/O region */
1629 special(shpnt) = mca_dev->index; /* important assignment or else crash! */
1630 subsystem_connector_size(shpnt) = 0; /* preset slot-size */
1631 shpnt->irq = irq; /* assign necessary stuff for the adapter */
1632 shpnt->io_port = port;
1633 shpnt->n_io_port = IM_N_IO_PORT;
1634 shpnt->this_id = id;
1635 shpnt->max_id = 8; /* 8 PUNs are default */
1636 /* now, the SCSI-subsystem is connected to Linux */
1638 #ifdef IM_DEBUG_PROBE
1639 ctrl = (unsigned int) (inb(IM_CTR_REG(found))); /* get control-register status */
1640 printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", ctrl, inb(IM_STAT_REG(found)));
1641 printk("IBM MCA SCSI: This adapters' POS-registers: ");
1642 for (i = 0; i < 8; i++)
1643 printk("%x ", pos[i]);
1646 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS;
1648 for (i = 0; i < 16; i++) /* reset the tables */
1649 for (j = 0; j < 8; j++)
1650 get_ldn(shpnt)[i][j] = MAX_LOG_DEV;
1652 /* check which logical devices exist */
1653 /* after this line, local interrupting is possible: */
1654 local_checking_phase_flag(shpnt) = 1;
1655 check_devices(shpnt, mca_dev->index); /* call by value, using the global variable hosts */
1656 local_checking_phase_flag(shpnt) = 0;
1658 /* an ibm mca subsystem has been detected */
1660 for (k = 2; k < 7; k++)
1661 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1662 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = INTEGRATED_SCSI;
1663 mca_device_set_name(mca_dev, description);
1664 /* FIXME: NEED TO REPLUMB TO SYSFS
1665 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1667 mca_device_set_claim(mca_dev, 1);
1668 if (scsi_add_host(shpnt, dev)) {
1669 dev_printk(KERN_ERR, dev, "IBM MCA SCSI: scsi_add_host failed\n");
1672 scsi_scan_host(shpnt);
1676 scsi_host_put(shpnt);
1678 release_region(port, IM_N_IO_PORT);
1683 static int __devexit ibmmca_remove(struct device *dev)
1685 struct Scsi_Host *shpnt = dev_get_drvdata(dev);
1686 scsi_remove_host(shpnt);
1687 release_region(shpnt->io_port, shpnt->n_io_port);
1688 free_irq(shpnt->irq, dev);
1689 scsi_host_put(shpnt);
1693 /* The following routine is the SCSI command queue for the midlevel driver */
1694 static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1697 unsigned int scsi_cmd;
1699 struct Scsi_Host *shpnt;
1705 struct scatterlist *sg;
1707 shpnt = cmd->device->host;
1709 max_pun = subsystem_maxid(shpnt);
1710 if (ibm_ansi_order) {
1711 target = max_pun - 1 - cmd->device->id;
1712 if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt)))
1714 else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt)))
1717 target = cmd->device->id;
1719 /* if (target,lun) is NO LUN or not existing at all, return error */
1720 if ((get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_LUN) || (get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_DEVICE)) {
1721 cmd->result = DID_NO_CONNECT << 16;
1727 /*if (target,lun) unassigned, do further checks... */
1728 ldn = get_ldn(shpnt)[target][cmd->device->lun];
1729 if (ldn >= MAX_LOG_DEV) { /* on invalid ldn do special stuff */
1730 if (ldn > MAX_LOG_DEV) { /* dynamical remapping if ldn unassigned */
1731 current_ldn = next_ldn(shpnt); /* stop-value for one circle */
1732 while (ld(shpnt)[next_ldn(shpnt)].cmd) { /* search for a occupied, but not in */
1733 /* command-processing ldn. */
1735 if (next_ldn(shpnt) >= MAX_LOG_DEV)
1736 next_ldn(shpnt) = 7;
1737 if (current_ldn == next_ldn(shpnt)) { /* One circle done ? */
1738 /* no non-processing ldn found */
1739 scmd_printk(KERN_WARNING, cmd,
1740 "IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n"
1741 " On ldn 7-14 SCSI-commands everywhere in progress.\n"
1742 " Reporting DID_NO_CONNECT for device.\n");
1743 cmd->result = DID_NO_CONNECT << 16; /* return no connect */
1750 /* unmap non-processing ldn */
1751 for (id = 0; id < max_pun; id++)
1752 for (lun = 0; lun < 8; lun++) {
1753 if (get_ldn(shpnt)[id][lun] == next_ldn(shpnt)) {
1754 get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE;
1755 get_scsi(shpnt)[id][lun] = TYPE_NO_DEVICE;
1759 /* set reduced interrupt_handler-mode for checking */
1760 local_checking_phase_flag(shpnt) = 1;
1761 /* map found ldn to pun,lun */
1762 get_ldn(shpnt)[target][cmd->device->lun] = next_ldn(shpnt);
1763 /* change ldn to the right value, that is now next_ldn */
1764 ldn = next_ldn(shpnt);
1765 /* unassign all ldns (pun,lun,ldn does not matter for remove) */
1766 immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN);
1767 /* set only LDN for remapped device */
1768 immediate_assign(shpnt, target, cmd->device->lun, ldn, SET_LDN);
1769 /* get device information for ld[ldn] */
1770 if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) {
1771 ld(shpnt)[ldn].cmd = NULL; /* To prevent panic set 0, because
1772 devices that were not assigned,
1773 should have nothing in progress. */
1774 get_scsi(shpnt)[target][cmd->device->lun] = ld(shpnt)[ldn].device_type;
1775 /* increase assignment counters for statistics in /proc */
1776 IBM_DS(shpnt).dynamical_assignments++;
1777 IBM_DS(shpnt).ldn_assignments[ldn]++;
1779 /* panic here, because a device, found at boottime has
1781 panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", ldn, target, cmd->device->lun);
1782 /* unassign again all ldns (pun,lun,ldn does not matter for remove) */
1783 immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN);
1784 /* remap all ldns, as written in the pun/lun table */
1786 #ifdef CONFIG_SCSI_MULTI_LUN
1787 for (lun = 0; lun < 8; lun++)
1789 for (id = 0; id < max_pun; id++) {
1790 if (get_ldn(shpnt)[id][lun] <= MAX_LOG_DEV)
1791 immediate_assign(shpnt, id, lun, get_ldn(shpnt)[id][lun], SET_LDN);
1793 /* set back to normal interrupt_handling */
1794 local_checking_phase_flag(shpnt) = 0;
1795 #ifdef IM_DEBUG_PROBE
1796 /* Information on syslog terminal */
1797 printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", ldn, target, cmd->device->lun);
1799 /* increase next_ldn for next dynamical assignment */
1801 if (next_ldn(shpnt) >= MAX_LOG_DEV)
1802 next_ldn(shpnt) = 7;
1803 } else { /* wall against Linux accesses to the subsystem adapter */
1804 cmd->result = DID_BAD_TARGET << 16;
1811 /*verify there is no command already in progress for this log dev */
1812 if (ld(shpnt)[ldn].cmd)
1813 panic("IBM MCA SCSI: cmd already in progress for this ldn.\n");
1815 /*save done in cmd, and save cmd for the interrupt handler */
1816 cmd->scsi_done = done;
1817 ld(shpnt)[ldn].cmd = cmd;
1819 /*fill scb information independent of the scsi command */
1820 scb = &(ld(shpnt)[ldn].scb);
1821 ld(shpnt)[ldn].tsb.dev_status = 0;
1822 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE;
1823 scb->tsb_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].tsb));
1824 scsi_cmd = cmd->cmnd[0];
1826 if (scsi_sg_count(cmd)) {
1827 BUG_ON(scsi_sg_count(cmd) > 16);
1829 scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) {
1830 ld(shpnt)[ldn].sge[i].address = (void *) (isa_page_to_bus(sg_page(sg)) + sg->offset);
1831 ld(shpnt)[ldn].sge[i].byte_length = sg->length;
1833 scb->enable |= IM_POINTER_TO_LIST;
1834 scb->sys_buf_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].sge[0]));
1835 scb->sys_buf_length = scsi_sg_count(cmd) * sizeof(struct im_sge);
1837 scb->sys_buf_adr = isa_virt_to_bus(scsi_sglist(cmd));
1838 /* recent Linux midlevel SCSI places 1024 byte for inquiry
1839 * command. Far too much for old PS/2 hardware. */
1841 /* avoid command errors by setting bufferlengths to
1842 * ANSI-standard. Beware of forcing it to 255,
1843 * this could SEGV the kernel!!! */
1848 if (scsi_bufflen(cmd) > 255)
1849 scb->sys_buf_length = 255;
1851 scb->sys_buf_length = scsi_bufflen(cmd);
1853 case TEST_UNIT_READY:
1854 scb->sys_buf_length = 0;
1857 scb->sys_buf_length = scsi_bufflen(cmd);
1861 /*fill scb information dependent on scsi command */
1864 printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd, ldn);
1867 /* for specific device-type debugging: */
1868 #ifdef IM_DEBUG_CMD_SPEC_DEV
1869 if (ld(shpnt)[ldn].device_type == IM_DEBUG_CMD_DEVICE)
1870 printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", ld(shpnt)[ldn].device_type, scsi_cmd, ldn);
1873 /* for possible panics store current command */
1874 last_scsi_command(shpnt)[ldn] = scsi_cmd;
1875 last_scsi_type(shpnt)[ldn] = IM_SCB;
1876 /* update statistical info */
1877 IBM_DS(shpnt).total_accesses++;
1878 IBM_DS(shpnt).ldn_access[ldn]++;
1887 /* Distinguish between disk and other devices. Only disks (that are the
1888 most frequently accessed devices) should be supported by the
1889 IBM-SCSI-Subsystem commands. */
1890 switch (ld(shpnt)[ldn].device_type) {
1891 case TYPE_DISK: /* for harddisks enter here ... */
1892 case TYPE_MOD: /* ... try it also for MO-drives (send flames as */
1893 /* you like, if this won't work.) */
1894 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) {
1895 /* read command preparations */
1896 scb->enable |= IM_READ_CONTROL;
1897 IBM_DS(shpnt).ldn_read_access[ldn]++; /* increase READ-access on ldn stat. */
1898 scb->command = IM_READ_DATA_CMD | IM_NO_DISCONNECT;
1899 } else { /* write command preparations */
1900 IBM_DS(shpnt).ldn_write_access[ldn]++; /* increase write-count on ldn stat. */
1901 scb->command = IM_WRITE_DATA_CMD | IM_NO_DISCONNECT;
1903 if (scsi_cmd == READ_6 || scsi_cmd == WRITE_6) {
1904 scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[3]) << 0) | (((unsigned) cmd->cmnd[2]) << 8) | ((((unsigned) cmd->cmnd[1]) & 0x1f) << 16);
1905 scb->u2.blk.count = (unsigned) cmd->cmnd[4];
1907 scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[5]) << 0) | (((unsigned) cmd->cmnd[4]) << 8) | (((unsigned) cmd->cmnd[3]) << 16) | (((unsigned) cmd->cmnd[2]) << 24);
1908 scb->u2.blk.count = (((unsigned) cmd->cmnd[8]) << 0) | (((unsigned) cmd->cmnd[7]) << 8);
1910 last_scsi_logical_block(shpnt)[ldn] = scb->u1.log_blk_adr;
1911 last_scsi_blockcount(shpnt)[ldn] = scb->u2.blk.count;
1912 scb->u2.blk.length = ld(shpnt)[ldn].block_length;
1914 /* for other devices, enter here. Other types are not known by
1915 Linux! TYPE_NO_LUN is forbidden as valid device. */
1918 case TYPE_PROCESSOR:
1921 case TYPE_MEDIUM_CHANGER:
1922 /* If there is a sequential-device, IBM recommends to use
1923 IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE.
1924 This includes CD-ROM devices, too, due to the partial sequential
1925 read capabilities. */
1926 scb->command = IM_OTHER_SCSI_CMD_CMD;
1927 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12)
1929 scb->enable |= IM_READ_CONTROL;
1930 scb->enable |= IM_BYPASS_BUFFER;
1931 scb->u1.scsi_cmd_length = cmd->cmd_len;
1932 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
1933 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
1934 /* Read/write on this non-disk devices is also displayworthy,
1935 so flash-up the LED/display. */
1940 IBM_DS(shpnt).ldn_inquiry_access[ldn]++;
1941 scb->command = IM_DEVICE_INQUIRY_CMD;
1942 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1943 scb->u1.log_blk_adr = 0;
1945 case TEST_UNIT_READY:
1946 scb->command = IM_OTHER_SCSI_CMD_CMD;
1947 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1948 scb->u1.log_blk_adr = 0;
1949 scb->u1.scsi_cmd_length = 6;
1950 memcpy(scb->u2.scsi_command, cmd->cmnd, 6);
1951 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
1954 /* the length of system memory buffer must be exactly 8 bytes */
1955 scb->command = IM_READ_CAPACITY_CMD;
1956 scb->enable |= IM_READ_CONTROL | IM_BYPASS_BUFFER;
1957 if (scb->sys_buf_length > 8)
1958 scb->sys_buf_length = 8;
1960 /* Commands that need read-only-mode (system <- device): */
1962 scb->command = IM_REQUEST_SENSE_CMD;
1963 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1965 /* Commands that need write-only-mode (system -> device): */
1967 case MODE_SELECT_10:
1968 IBM_DS(shpnt).ldn_modeselect_access[ldn]++;
1969 scb->command = IM_OTHER_SCSI_CMD_CMD;
1970 scb->enable |= IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; /*Select needs WRITE-enabled */
1971 scb->u1.scsi_cmd_length = cmd->cmd_len;
1972 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
1973 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
1975 /* For other commands, read-only is useful. Most other commands are
1976 running without an input-data-block. */
1978 scb->command = IM_OTHER_SCSI_CMD_CMD;
1979 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1980 scb->u1.scsi_cmd_length = cmd->cmd_len;
1981 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
1982 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
1985 /*issue scb command, and return */
1986 if (++disk_rw_in_progress == 1)
1987 PS2_DISK_LED_ON(shpnt->host_no, target);
1989 if (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB) {
1990 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_LONG_SCB | ldn);
1991 IBM_DS(shpnt).long_scbs++;
1993 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
1994 IBM_DS(shpnt).scbs++;
1999 static int __ibmmca_abort(Scsi_Cmnd * cmd)
2001 /* Abort does not work, as the adapter never generates an interrupt on
2002 * whatever situation is simulated, even when really pending commands
2003 * are running on the adapters' hardware ! */
2005 struct Scsi_Host *shpnt;
2007 void (*saved_done) (Scsi_Cmnd *);
2010 unsigned long imm_command;
2012 #ifdef IM_DEBUG_PROBE
2013 printk("IBM MCA SCSI: Abort subroutine called...\n");
2016 shpnt = cmd->device->host;
2018 max_pun = subsystem_maxid(shpnt);
2019 if (ibm_ansi_order) {
2020 target = max_pun - 1 - cmd->device->id;
2021 if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt)))
2023 else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt)))
2026 target = cmd->device->id;
2028 /* get logical device number, and disable system interrupts */
2029 printk(KERN_WARNING "IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", target, cmd->device->lun);
2030 ldn = get_ldn(shpnt)[target][cmd->device->lun];
2032 /*if cmd for this ldn has already finished, no need to abort */
2033 if (!ld(shpnt)[ldn].cmd) {
2037 /* Clear ld.cmd, save done function, install internal done,
2038 * send abort immediate command (this enables sys. interrupts),
2039 * and wait until the interrupt arrives.
2041 saved_done = cmd->scsi_done;
2042 cmd->scsi_done = internal_done;
2043 cmd->SCp.Status = 0;
2044 last_scsi_command(shpnt)[ldn] = IM_ABORT_IMM_CMD;
2045 last_scsi_type(shpnt)[ldn] = IM_IMM_CMD;
2046 imm_command = inl(IM_CMD_REG(shpnt));
2047 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2048 imm_command |= (unsigned long) (IM_ABORT_IMM_CMD);
2049 /* must wait for attention reg not busy */
2050 /* FIXME - timeout, politeness */
2052 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
2055 /* write registers and enable system interrupts */
2056 outl(imm_command, IM_CMD_REG(shpnt));
2057 outb(IM_IMM_CMD | ldn, IM_ATTN_REG(shpnt));
2058 #ifdef IM_DEBUG_PROBE
2059 printk("IBM MCA SCSI: Abort queued to adapter...\n");
2061 spin_unlock_irq(shpnt->host_lock);
2062 while (!cmd->SCp.Status)
2064 spin_lock_irq(shpnt->host_lock);
2065 cmd->scsi_done = saved_done;
2066 #ifdef IM_DEBUG_PROBE
2067 printk("IBM MCA SCSI: Abort returned with adapter response...\n");
2070 /*if abort went well, call saved done, then return success or error */
2071 if (cmd->result == (DID_ABORT << 16))
2073 cmd->result |= DID_ABORT << 16;
2075 (cmd->scsi_done) (cmd);
2076 ld(shpnt)[ldn].cmd = NULL;
2077 #ifdef IM_DEBUG_PROBE
2078 printk("IBM MCA SCSI: Abort finished with success.\n");
2082 cmd->result |= DID_NO_CONNECT << 16;
2084 (cmd->scsi_done) (cmd);
2085 ld(shpnt)[ldn].cmd = NULL;
2086 #ifdef IM_DEBUG_PROBE
2087 printk("IBM MCA SCSI: Abort failed.\n");
2093 static int ibmmca_abort(Scsi_Cmnd * cmd)
2095 struct Scsi_Host *shpnt = cmd->device->host;
2098 spin_lock_irq(shpnt->host_lock);
2099 rc = __ibmmca_abort(cmd);
2100 spin_unlock_irq(shpnt->host_lock);
2105 static int __ibmmca_host_reset(Scsi_Cmnd * cmd)
2107 struct Scsi_Host *shpnt;
2110 unsigned long imm_command;
2112 BUG_ON(cmd == NULL);
2114 ticks = IM_RESET_DELAY * HZ;
2115 shpnt = cmd->device->host;
2117 if (local_checking_phase_flag(shpnt)) {
2118 printk(KERN_WARNING "IBM MCA SCSI: unable to reset while checking devices.\n");
2122 /* issue reset immediate command to subsystem, and wait for interrupt */
2123 printk("IBM MCA SCSI: resetting all devices.\n");
2124 reset_status(shpnt) = IM_RESET_IN_PROGRESS;
2125 last_scsi_command(shpnt)[0xf] = IM_RESET_IMM_CMD;
2126 last_scsi_type(shpnt)[0xf] = IM_IMM_CMD;
2127 imm_command = inl(IM_CMD_REG(shpnt));
2128 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2129 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
2130 /* must wait for attention reg not busy */
2132 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
2134 spin_unlock_irq(shpnt->host_lock);
2136 spin_lock_irq(shpnt->host_lock);
2138 /*write registers and enable system interrupts */
2139 outl(imm_command, IM_CMD_REG(shpnt));
2140 outb(IM_IMM_CMD | 0xf, IM_ATTN_REG(shpnt));
2141 /* wait for interrupt finished or intr_stat register to be set, as the
2142 * interrupt will not be executed, while we are in here! */
2144 /* FIXME: This is really really icky we so want a sleeping version of this ! */
2145 while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks && ((inb(IM_INTR_REG(shpnt)) & 0x8f) != 0x8f)) {
2146 udelay((1 + 999 / HZ) * 1000);
2149 /* if reset did not complete, just return an error */
2151 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
2152 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
2156 if ((inb(IM_INTR_REG(shpnt)) & 0x8f) == 0x8f) {
2157 /* analysis done by this routine and not by the intr-routine */
2158 if (inb(IM_INTR_REG(shpnt)) == 0xaf)
2159 reset_status(shpnt) = IM_RESET_FINISHED_OK_NO_INT;
2160 else if (inb(IM_INTR_REG(shpnt)) == 0xcf)
2161 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
2162 else /* failed, 4get it */
2163 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS_NO_INT;
2164 outb(IM_EOI | 0xf, IM_ATTN_REG(shpnt));
2167 /* if reset failed, just return an error */
2168 if (reset_status(shpnt) == IM_RESET_FINISHED_FAIL) {
2169 printk(KERN_ERR "IBM MCA SCSI: reset failed.\n");
2173 /* so reset finished ok - call outstanding done's, and return success */
2174 printk(KERN_INFO "IBM MCA SCSI: Reset successfully completed.\n");
2175 for (i = 0; i < MAX_LOG_DEV; i++) {
2176 cmd_aid = ld(shpnt)[i].cmd;
2177 if (cmd_aid && cmd_aid->scsi_done) {
2178 ld(shpnt)[i].cmd = NULL;
2179 cmd_aid->result = DID_RESET << 16;
2185 static int ibmmca_host_reset(Scsi_Cmnd * cmd)
2187 struct Scsi_Host *shpnt = cmd->device->host;
2190 spin_lock_irq(shpnt->host_lock);
2191 rc = __ibmmca_host_reset(cmd);
2192 spin_unlock_irq(shpnt->host_lock);
2197 static int ibmmca_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *info)
2199 int size = capacity;
2202 info[2] = size / (info[0] * info[1]);
2203 if (info[2] >= 1024) {
2206 info[2] = size / (info[0] * info[1]);
2207 if (info[2] >= 1024) {
2210 info[2] = size / (info[0] * info[1]);
2211 if (info[2] >= 1024)
2218 /* calculate percentage of total accesses on a ldn */
2219 static int ldn_access_load(struct Scsi_Host *shpnt, int ldn)
2221 if (IBM_DS(shpnt).total_accesses == 0)
2223 if (IBM_DS(shpnt).ldn_access[ldn] == 0)
2225 return (IBM_DS(shpnt).ldn_access[ldn] * 100) / IBM_DS(shpnt).total_accesses;
2228 /* calculate total amount of r/w-accesses */
2229 static int ldn_access_total_read_write(struct Scsi_Host *shpnt)
2235 for (i = 0; i <= MAX_LOG_DEV; i++)
2236 a += IBM_DS(shpnt).ldn_read_access[i] + IBM_DS(shpnt).ldn_write_access[i];
2240 static int ldn_access_total_inquiry(struct Scsi_Host *shpnt)
2246 for (i = 0; i <= MAX_LOG_DEV; i++)
2247 a += IBM_DS(shpnt).ldn_inquiry_access[i];
2251 static int ldn_access_total_modeselect(struct Scsi_Host *shpnt)
2257 for (i = 0; i <= MAX_LOG_DEV; i++)
2258 a += IBM_DS(shpnt).ldn_modeselect_access[i];
2262 /* routine to display info in the proc-fs-structure (a deluxe feature) */
2263 static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout)
2267 unsigned long flags;
2271 spin_lock_irqsave(shpnt->host_lock, flags); /* Check it */
2273 max_pun = subsystem_maxid(shpnt);
2275 len += sprintf(buffer + len, "\n IBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", IBMMCA_SCSI_DRIVER_VERSION);
2276 len += sprintf(buffer + len, " SCSI Access-Statistics:\n");
2277 len += sprintf(buffer + len, " Device Scanning Order....: %s\n", (ibm_ansi_order) ? "IBM/ANSI" : "New Industry Standard");
2278 #ifdef CONFIG_SCSI_MULTI_LUN
2279 len += sprintf(buffer + len, " Multiple LUN probing.....: Yes\n");
2281 len += sprintf(buffer + len, " Multiple LUN probing.....: No\n");
2283 len += sprintf(buffer + len, " This Hostnumber..........: %d\n", shpnt->host_no);
2284 len += sprintf(buffer + len, " Base I/O-Port............: 0x%x\n", (unsigned int) (IM_CMD_REG(shpnt)));
2285 len += sprintf(buffer + len, " (Shared) IRQ.............: %d\n", IM_IRQ);
2286 len += sprintf(buffer + len, " Total Interrupts.........: %d\n", IBM_DS(shpnt).total_interrupts);
2287 len += sprintf(buffer + len, " Total SCSI Accesses......: %d\n", IBM_DS(shpnt).total_accesses);
2288 len += sprintf(buffer + len, " Total short SCBs.........: %d\n", IBM_DS(shpnt).scbs);
2289 len += sprintf(buffer + len, " Total long SCBs..........: %d\n", IBM_DS(shpnt).long_scbs);
2290 len += sprintf(buffer + len, " Total SCSI READ/WRITE..: %d\n", ldn_access_total_read_write(shpnt));
2291 len += sprintf(buffer + len, " Total SCSI Inquiries...: %d\n", ldn_access_total_inquiry(shpnt));
2292 len += sprintf(buffer + len, " Total SCSI Modeselects.: %d\n", ldn_access_total_modeselect(shpnt));
2293 len += sprintf(buffer + len, " Total SCSI other cmds..: %d\n", IBM_DS(shpnt).total_accesses - ldn_access_total_read_write(shpnt)
2294 - ldn_access_total_modeselect(shpnt)
2295 - ldn_access_total_inquiry(shpnt));
2296 len += sprintf(buffer + len, " Total SCSI command fails.: %d\n\n", IBM_DS(shpnt).total_errors);
2297 len += sprintf(buffer + len, " Logical-Device-Number (LDN) Access-Statistics:\n");
2298 len += sprintf(buffer + len, " LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n");
2299 len += sprintf(buffer + len, " -----|--------------|-----------|-----------|--------------\n");
2300 for (i = 0; i <= MAX_LOG_DEV; i++)
2301 len += sprintf(buffer + len, " %2X | %3d | %8d | %8d | %8d\n", i, ldn_access_load(shpnt, i), IBM_DS(shpnt).ldn_read_access[i], IBM_DS(shpnt).ldn_write_access[i], IBM_DS(shpnt).ldn_assignments[i]);
2302 len += sprintf(buffer + len, " -----------------------------------------------------------\n\n");
2303 len += sprintf(buffer + len, " Dynamical-LDN-Assignment-Statistics:\n");
2304 len += sprintf(buffer + len, " Number of physical SCSI-devices..: %d (+ Adapter)\n", IBM_DS(shpnt).total_scsi_devices);
2305 len += sprintf(buffer + len, " Dynamical Assignment necessary...: %s\n", IBM_DS(shpnt).dyn_flag ? "Yes" : "No ");
2306 len += sprintf(buffer + len, " Next LDN to be assigned..........: 0x%x\n", next_ldn(shpnt));
2307 len += sprintf(buffer + len, " Dynamical assignments done yet...: %d\n", IBM_DS(shpnt).dynamical_assignments);
2308 len += sprintf(buffer + len, "\n Current SCSI-Device-Mapping:\n");
2309 len += sprintf(buffer + len, " Physical SCSI-Device Map Logical SCSI-Device Map\n");
2310 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");
2311 for (id = 0; id < max_pun; id++) {
2312 len += sprintf(buffer + len, " %2d ", id);
2313 for (lun = 0; lun < 8; lun++)
2314 len += sprintf(buffer + len, "%2s ", ti_p(get_scsi(shpnt)[id][lun]));
2315 len += sprintf(buffer + len, " %2d ", id);
2316 for (lun = 0; lun < 8; lun++)
2317 len += sprintf(buffer + len, "%2s ", ti_l(get_ldn(shpnt)[id][lun]));
2318 len += sprintf(buffer + len, "\n");
2321 len += sprintf(buffer + len, "(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n");
2322 len += sprintf(buffer + len, " R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n");
2323 len += sprintf(buffer + len, " - = nothing found, nothing assigned or unprobed LUN)\n\n");
2325 *start = buffer + offset;
2329 spin_unlock_irqrestore(shpnt->host_lock, flags);
2333 static int option_setup(char *str)
2335 int ints[IM_MAX_HOSTS];
2339 while (cur && isdigit(*cur) && i <= IM_MAX_HOSTS) {
2340 ints[i++] = simple_strtoul(cur, NULL, 0);
2341 if ((cur = strchr(cur, ',')) != NULL)
2345 internal_ibmmca_scsi_setup(cur, ints);
2349 __setup("ibmmcascsi=", option_setup);
2351 static struct mca_driver ibmmca_driver = {
2352 .id_table = ibmmca_id_table,
2355 .bus = &mca_bus_type,
2356 .probe = ibmmca_probe,
2357 .remove = __devexit_p(ibmmca_remove),
2361 static int __init ibmmca_init(void)
2364 /* If the driver is run as module, read from conf.modules or cmd-line */
2366 option_setup(boot_options);
2369 return mca_register_driver_integrated(&ibmmca_driver, MCA_INTEGSCSI);
2372 static void __exit ibmmca_exit(void)
2374 mca_unregister_driver(&ibmmca_driver);
2377 module_init(ibmmca_init);
2378 module_exit(ibmmca_exit);