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