blob: cd09132d5d7d22eb7c2d240b0d2da6758ad837a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Alan Coxfa195af2008-10-27 15:16:36 +000013 Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/spinlock.h>
33#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/io.h>
36
37#include "scsi.h"
38#include <scsi/scsi_host.h>
James Bottomley67b20092007-05-03 11:13:08 -050039
40/* Common forward declarations for all Linux-versions: */
Jeff Garzikf2812332010-11-16 02:10:29 -050041static int ibmmca_queuecommand (struct Scsi_Host *, struct scsi_cmnd *);
James Bottomley67b20092007-05-03 11:13:08 -050042static int ibmmca_abort (Scsi_Cmnd *);
43static int ibmmca_host_reset (Scsi_Cmnd *);
44static int ibmmca_biosparam (struct scsi_device *, struct block_device *, sector_t, int *);
45static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout);
46
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/* current version of this driver-source: */
50#define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac"
51
52/* driver configuration */
53#define IM_MAX_HOSTS 8 /* maximum number of host adapters */
54#define IM_RESET_DELAY 60 /* seconds allowed for a reset */
55
56/* driver debugging - #undef all for normal operation */
57/* if defined: count interrupts and ignore this special one: */
58#undef IM_DEBUG_TIMEOUT //50
59#define TIMEOUT_PUN 0
60#define TIMEOUT_LUN 0
61/* verbose interrupt: */
62#undef IM_DEBUG_INT
63/* verbose queuecommand: */
64#undef IM_DEBUG_CMD
65/* verbose queucommand for specific SCSI-device type: */
66#undef IM_DEBUG_CMD_SPEC_DEV
67/* verbose device probing */
68#undef IM_DEBUG_PROBE
69
70/* device type that shall be displayed on syslog (only during debugging): */
71#define IM_DEBUG_CMD_DEVICE TYPE_TAPE
72
73/* relative addresses of hardware registers on a subsystem */
James Bottomley67b20092007-05-03 11:13:08 -050074#define IM_CMD_REG(h) ((h)->io_port) /*Command Interface, (4 bytes long) */
75#define IM_ATTN_REG(h) ((h)->io_port+4) /*Attention (1 byte) */
76#define IM_CTR_REG(h) ((h)->io_port+5) /*Basic Control (1 byte) */
77#define IM_INTR_REG(h) ((h)->io_port+6) /*Interrupt Status (1 byte, r/o) */
78#define IM_STAT_REG(h) ((h)->io_port+7) /*Basic Status (1 byte, read only) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/* basic I/O-port of first adapter */
81#define IM_IO_PORT 0x3540
82/* maximum number of hosts that can be found */
83#define IM_N_IO_PORT 8
84
85/*requests going into the upper nibble of the Attention register */
86/*note: the lower nibble specifies the device(0-14), or subsystem(15) */
87#define IM_IMM_CMD 0x10 /*immediate command */
88#define IM_SCB 0x30 /*Subsystem Control Block command */
89#define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */
90#define IM_EOI 0xe0 /*end-of-interrupt request */
91
92/*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */
93#define IM_HW_RESET 0x80 /*hardware reset */
94#define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */
95#define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */
96
97/*to interpret the upper nibble of Interrupt Status register */
98/*note: the lower nibble specifies the device(0-14), or subsystem(15) */
99#define IM_SCB_CMD_COMPLETED 0x10
100#define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50
101#define IM_LOOP_SCATTER_BUFFER_FULL 0x60
102#define IM_ADAPTER_HW_FAILURE 0x70
103#define IM_IMMEDIATE_CMD_COMPLETED 0xa0
104#define IM_CMD_COMPLETED_WITH_FAILURE 0xc0
105#define IM_CMD_ERROR 0xe0
106#define IM_SOFTWARE_SEQUENCING_ERROR 0xf0
107
108/*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */
109#define IM_CMD_REG_FULL 0x08
110#define IM_CMD_REG_EMPTY 0x04
111#define IM_INTR_REQUEST 0x02
112#define IM_BUSY 0x01
113
114/*immediate commands (word written into low 2 bytes of command reg) */
115#define IM_RESET_IMM_CMD 0x0400
116#define IM_FEATURE_CTR_IMM_CMD 0x040c
117#define IM_DMA_PACING_IMM_CMD 0x040d
118#define IM_ASSIGN_IMM_CMD 0x040e
119#define IM_ABORT_IMM_CMD 0x040f
120#define IM_FORMAT_PREP_IMM_CMD 0x0417
121
122/*SCB (Subsystem Control Block) structure */
123struct im_scb {
124 unsigned short command; /*command word (read, etc.) */
125 unsigned short enable; /*enable word, modifies cmd */
126 union {
127 unsigned long log_blk_adr; /*block address on SCSI device */
128 unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */
129 } u1;
130 unsigned long sys_buf_adr; /*physical system memory adr */
131 unsigned long sys_buf_length; /*size of sys mem buffer */
132 unsigned long tsb_adr; /*Termination Status Block adr */
133 unsigned long scb_chain_adr; /*optional SCB chain address */
134 union {
135 struct {
136 unsigned short count; /*block count, on SCSI device */
137 unsigned short length; /*block length, on SCSI device */
138 } blk;
139 unsigned char scsi_command[12]; /*other scsi command */
140 } u2;
141};
142
143/*structure scatter-gather element (for list of system memory areas) */
144struct im_sge {
145 void *address;
146 unsigned long byte_length;
147};
148
149/*structure returned by a get_pos_info command: */
150struct im_pos_info {
151 unsigned short pos_id; /* adapter id */
152 unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */
153 unsigned char pos_2; /* pos 2 */
154 unsigned char int_level; /* interrupt level IRQ 11 or 14 */
155 unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */
156 unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */
157 unsigned char num_luns; /* number of supported luns per device */
158 unsigned char num_puns; /* number of supported puns */
159 unsigned char pacing_factor; /* pacing factor */
160 unsigned char num_ldns; /* number of ldns available */
161 unsigned char eoi_off; /* time EOI and interrupt inactive */
162 unsigned char max_busy; /* time between reset and busy on */
163 unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */
164 unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */
165 unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */
166 unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */
167 unsigned char pos_6; /* pos 6 */
168 unsigned char pos_5; /* pos 5 */
169 unsigned short max_overlap; /* maximum overlapping requests */
170 unsigned short num_bus; /* number of SCSI-busses */
171};
172
173/*values for SCB command word */
174#define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */
175#define IM_NO_DISCONNECT 0x0080 /*flag for any command */
176#define IM_READ_DATA_CMD 0x1c01
177#define IM_WRITE_DATA_CMD 0x1c02
178#define IM_READ_VERIFY_CMD 0x1c03
179#define IM_WRITE_VERIFY_CMD 0x1c04
180#define IM_REQUEST_SENSE_CMD 0x1c08
181#define IM_READ_CAPACITY_CMD 0x1c09
182#define IM_DEVICE_INQUIRY_CMD 0x1c0b
183#define IM_READ_LOGICAL_CMD 0x1c2a
184#define IM_OTHER_SCSI_CMD_CMD 0x241f
185
186/* unused, but supported, SCB commands */
187#define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */
188#define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */
189#define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */
190#define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */
191#define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */
192
193/*values to set bits in the enable word of SCB */
194#define IM_READ_CONTROL 0x8000
195#define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000
196#define IM_RETRY_ENABLE 0x2000
197#define IM_POINTER_TO_LIST 0x1000
198#define IM_SUPRESS_EXCEPTION_SHORT 0x0400
199#define IM_BYPASS_BUFFER 0x0200
200#define IM_CHAIN_ON_NO_ERROR 0x0001
201
202/*TSB (Termination Status Block) structure */
203struct im_tsb {
204 unsigned short end_status;
205 unsigned short reserved1;
206 unsigned long residual_byte_count;
207 unsigned long sg_list_element_adr;
208 unsigned short status_length;
209 unsigned char dev_status;
210 unsigned char cmd_status;
211 unsigned char dev_error;
212 unsigned char cmd_error;
213 unsigned short reserved2;
214 unsigned short reserved3;
215 unsigned short low_of_last_scb_adr;
216 unsigned short high_of_last_scb_adr;
217};
218
219/*subsystem uses interrupt request level 14 */
220#define IM_IRQ 14
221/*SCSI-2 F/W may evade to interrupt 11 */
222#define IM_IRQ_FW 11
223
224/* Model 95 has an additional alphanumeric display, which can be used
225 to display SCSI-activities. 8595 models do not have any disk led, which
226 makes this feature quite useful.
227 The regular PS/2 disk led is turned on/off by bits 6,7 of system
228 control port. */
229
230/* LED display-port (actually, last LED on display) */
231#define MOD95_LED_PORT 0x108
232/* system-control-register of PS/2s with diskindicator */
233#define PS2_SYS_CTR 0x92
234/* activity displaying methods */
235#define LED_DISP 1
236#define LED_ADISP 2
237#define LED_ACTIVITY 4
238/* failed intr */
239#define CMD_FAIL 255
240
241/* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED
242 displays. ldn is no longer displayed here, because the ldn mapping is now
243 done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime
244 or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble,
245 interest, debugging or just for having fun. The left number gives the
246 host-adapter number and the right shows the accessed SCSI-ID. */
247
248/* display_mode is set by the ibmmcascsi= command line arg */
249static int display_mode = 0;
250/* set default adapter timeout */
251static unsigned int adapter_timeout = 45;
252/* for probing on feature-command: */
253static unsigned int global_command_error_excuse = 0;
254/* global setting by command line for adapter_speed */
255static int global_adapter_speed = 0; /* full speed by default */
256
257/* Panel / LED on, do it right for F/W addressin, too. adisplay will
258 * just ignore ids>7, as the panel has only 7 digits available */
259#define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \
260 outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \
261 outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \
262 if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \
263 outb((char)(ad+48), MOD95_LED_PORT); } \
264 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
265 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); }
266
267/* Panel / LED off */
268/* bug fixed, Dec 15, 1997, where | was replaced by & here */
269#define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \
270 outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \
271 outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \
272 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
273 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); }
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275/* types of different supported hardware that goes to hostdata special */
276#define IBM_SCSI2_FW 0
277#define IBM_7568_WCACHE 1
278#define IBM_EXP_UNIT 2
279#define IBM_SCSI_WCACHE 3
280#define IBM_SCSI 4
James Bottomley67b20092007-05-03 11:13:08 -0500281#define IBM_INTEGSCSI 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283/* other special flags for hostdata structure */
284#define FORCED_DETECTION 100
285#define INTEGRATED_SCSI 101
286
287/* List of possible IBM-SCSI-adapters */
James Bottomley67b20092007-05-03 11:13:08 -0500288static short ibmmca_id_table[] = {
289 0x8efc,
290 0x8efd,
291 0x8ef8,
292 0x8eff,
293 0x8efe,
294 /* No entry for integrated SCSI, that's part of the register */
295 0
296};
297
298static const char *ibmmca_description[] = {
299 "IBM SCSI-2 F/W Adapter", /* special = 0 */
300 "IBM 7568 Industrial Computer SCSI Adapter w/Cache", /* special = 1 */
301 "IBM Expansion Unit SCSI Controller", /* special = 2 */
302 "IBM SCSI Adapter w/Cache", /* special = 3 */
303 "IBM SCSI Adapter", /* special = 4 */
304 "IBM Integrated SCSI Controller", /* special = 5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305};
306
307/* Max number of logical devices (can be up from 0 to 14). 15 is the address
308of the adapter itself. */
309#define MAX_LOG_DEV 15
310
311/*local data for a logical device */
312struct logical_device {
313 struct im_scb scb; /* SCSI-subsystem-control-block structure */
314 struct im_tsb tsb; /* SCSI command complete status block structure */
315 struct im_sge sge[16]; /* scatter gather list structure */
316 unsigned char buf[256]; /* SCSI command return data buffer */
317 Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */
318 int device_type; /* type of the SCSI-device. See include/scsi/scsi.h
319 for interpretation of the possible values */
320 int block_length; /* blocksize of a particular logical SCSI-device */
321 int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */
322 int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */
323};
324
325/* statistics of the driver during operations (for proc_info) */
326struct Driver_Statistics {
327 /* SCSI statistics on the adapter */
328 int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */
329 int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */
330 int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */
331 int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */
332 int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */
333 int scbs; /* short SCBs queued */
334 int long_scbs; /* long SCBs queued */
335 int total_accesses; /* total accesses on all ldns */
336 int total_interrupts; /* total interrupts (should be
337 same as total_accesses) */
338 int total_errors; /* command completed with error */
339 /* dynamical assignment statistics */
340 int total_scsi_devices; /* number of physical pun,lun */
341 int dyn_flag; /* flag showing dynamical mode */
342 int dynamical_assignments; /* number of remappings of ldns */
343 int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each
344 ldn */
345};
346
347/* data structure for each host adapter */
348struct ibmmca_hostdata {
349 /* array of logical devices: */
350 struct logical_device _ld[MAX_LOG_DEV + 1];
351 /* array to convert (pun, lun) into logical device number: */
352 unsigned char _get_ldn[16][8];
353 /*array that contains the information about the physical SCSI-devices
354 attached to this host adapter: */
355 unsigned char _get_scsi[16][8];
356 /* used only when checking logical devices: */
357 int _local_checking_phase_flag;
358 /* report received interrupt: */
359 int _got_interrupt;
360 /* report termination-status of SCSI-command: */
361 int _stat_result;
362 /* reset status (used only when doing reset): */
363 int _reset_status;
364 /* code of the last SCSI command (needed for panic info): */
365 int _last_scsi_command[MAX_LOG_DEV + 1];
366 /* identifier of the last SCSI-command type */
367 int _last_scsi_type[MAX_LOG_DEV + 1];
368 /* last blockcount */
369 int _last_scsi_blockcount[MAX_LOG_DEV + 1];
370 /* last locgical block address */
371 unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1];
372 /* Counter that points on the next reassignable ldn for dynamical
373 remapping. The default value is 7, that is the first reassignable
374 number in the list at boottime: */
375 int _next_ldn;
376 /* Statistics-structure for this IBM-SCSI-host: */
377 struct Driver_Statistics _IBM_DS;
378 /* This hostadapters pos-registers pos2 until pos6 */
379 unsigned int _pos[8];
380 /* assign a special variable, that contains dedicated info about the
381 adaptertype */
382 int _special;
383 /* connector size on the MCA bus */
384 int _connector_size;
385 /* synchronous SCSI transfer rate bitpattern */
386 int _adapter_speed;
387};
388
389/* macros to access host data structure */
James Bottomley67b20092007-05-03 11:13:08 -0500390#define subsystem_pun(h) ((h)->this_id)
391#define subsystem_maxid(h) ((h)->max_id)
392#define ld(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_ld)
393#define get_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_ldn)
394#define get_scsi(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_get_scsi)
395#define local_checking_phase_flag(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_local_checking_phase_flag)
396#define got_interrupt(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_got_interrupt)
397#define stat_result(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_stat_result)
398#define reset_status(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_reset_status)
399#define last_scsi_command(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_command)
400#define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type)
401#define last_scsi_blockcount(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_blockcount)
402#define last_scsi_logical_block(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_logical_block)
403#define last_scsi_type(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_last_scsi_type)
404#define next_ldn(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_next_ldn)
405#define IBM_DS(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_IBM_DS)
406#define special(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_special)
407#define subsystem_connector_size(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_connector_size)
408#define adapter_speed(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_adapter_speed)
409#define pos2(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[2])
410#define pos3(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[3])
411#define pos4(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[4])
412#define pos5(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[5])
413#define pos6(h) (((struct ibmmca_hostdata *) (h)->hostdata)->_pos[6])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415/* Define a arbitrary number as subsystem-marker-type. This number is, as
416 described in the ANSI-SCSI-standard, not occupied by other device-types. */
417#define TYPE_IBM_SCSI_ADAPTER 0x2F
418
419/* Define 0xFF for no device type, because this type is not defined within
420 the ANSI-SCSI-standard, therefore, it can be used and should not cause any
421 harm. */
422#define TYPE_NO_DEVICE 0xFF
423
424/* define medium-changer. If this is not defined previously, e.g. Linux
425 2.0.x, define this type here. */
426#ifndef TYPE_MEDIUM_CHANGER
427#define TYPE_MEDIUM_CHANGER 0x08
428#endif
429
430/* define possible operations for the immediate_assign command */
431#define SET_LDN 0
432#define REMOVE_LDN 1
433
434/* ldn which is used to probe the SCSI devices */
435#define PROBE_LDN 0
436
437/* reset status flag contents */
438#define IM_RESET_NOT_IN_PROGRESS 0
439#define IM_RESET_IN_PROGRESS 1
440#define IM_RESET_FINISHED_OK 2
441#define IM_RESET_FINISHED_FAIL 3
442#define IM_RESET_NOT_IN_PROGRESS_NO_INT 4
443#define IM_RESET_FINISHED_OK_NO_INT 5
444
445/* define undefined SCSI-command */
446#define NO_SCSI 0xffff
447
448/*-----------------------------------------------------------------------*/
449
450/* if this is nonzero, ibmmcascsi option has been passed to the kernel */
451static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
452static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 };
453
454/* fill module-parameters only, when this define is present.
455 (that is kernel version 2.1.x) */
456#if defined(MODULE)
457static char *boot_options = NULL;
458module_param(boot_options, charp, 0);
459module_param_array(io_port, int, NULL, 0);
460module_param_array(scsi_id, int, NULL, 0);
461
Randy.Dunlapd39a9422005-09-13 21:43:56 -0700462MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#endif
464/*counter of concurrent disk read/writes, to turn on/off disk led */
465static int disk_rw_in_progress = 0;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467static unsigned int pos[8]; /* whole pos register-line for diagnosis */
468/* Taking into account the additions, made by ZP Gu.
469 * This selects now the preset value from the configfile and
470 * offers the 'normal' commandline option to be accepted */
471#ifdef CONFIG_IBMMCA_SCSI_ORDER_STANDARD
472static char ibm_ansi_order = 1;
473#else
474static char ibm_ansi_order = 0;
475#endif
476
James Bottomley67b20092007-05-03 11:13:08 -0500477static void issue_cmd(struct Scsi_Host *, unsigned long, unsigned char);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478static void internal_done(Scsi_Cmnd * cmd);
James Bottomley67b20092007-05-03 11:13:08 -0500479static void check_devices(struct Scsi_Host *, int);
480static int immediate_assign(struct Scsi_Host *, unsigned int, unsigned int, unsigned int, unsigned int);
481static int immediate_feature(struct Scsi_Host *, unsigned int, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
James Bottomley67b20092007-05-03 11:13:08 -0500483static int immediate_reset(struct Scsi_Host *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#endif
James Bottomley67b20092007-05-03 11:13:08 -0500485static int device_inquiry(struct Scsi_Host *, int);
486static int read_capacity(struct Scsi_Host *, int);
487static int get_pos_info(struct Scsi_Host *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488static char *ti_p(int);
489static char *ti_l(int);
490static char *ibmrate(unsigned int, int);
491static int probe_display(int);
James Bottomley67b20092007-05-03 11:13:08 -0500492static int probe_bus_mode(struct Scsi_Host *);
493static int device_exists(struct Scsi_Host *, int, int *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494static int option_setup(char *);
495/* local functions needed for proc_info */
James Bottomley67b20092007-05-03 11:13:08 -0500496static int ldn_access_load(struct Scsi_Host *, int);
497static int ldn_access_total_read_write(struct Scsi_Host *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
David Howells7d12e782006-10-05 14:55:46 +0100499static irqreturn_t interrupt_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 unsigned int intr_reg;
502 unsigned int cmd_result;
503 unsigned int ldn;
James Bottomley67b20092007-05-03 11:13:08 -0500504 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 Scsi_Cmnd *cmd;
506 int lastSCSI;
James Bottomley67b20092007-05-03 11:13:08 -0500507 struct device *dev = dev_id;
508 struct Scsi_Host *shpnt = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
James Bottomley67b20092007-05-03 11:13:08 -0500510 spin_lock_irqsave(shpnt->host_lock, flags);
511
512 if(!(inb(IM_STAT_REG(shpnt)) & IM_INTR_REQUEST)) {
513 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return IRQ_NONE;
515 }
516
517 /* the reset-function already did all the job, even ints got
518 renabled on the subsystem, so just return */
James Bottomley67b20092007-05-03 11:13:08 -0500519 if ((reset_status(shpnt) == IM_RESET_NOT_IN_PROGRESS_NO_INT) || (reset_status(shpnt) == IM_RESET_FINISHED_OK_NO_INT)) {
520 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS;
521 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 return IRQ_HANDLED;
523 }
524
525 /*must wait for attention reg not busy, then send EOI to subsystem */
526 while (1) {
James Bottomley67b20092007-05-03 11:13:08 -0500527 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529 cpu_relax();
530 }
James Bottomley67b20092007-05-03 11:13:08 -0500531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /*get command result and logical device */
James Bottomley67b20092007-05-03 11:13:08 -0500533 intr_reg = (unsigned char) (inb(IM_INTR_REG(shpnt)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 cmd_result = intr_reg & 0xf0;
535 ldn = intr_reg & 0x0f;
536 /* get the last_scsi_command here */
James Bottomley67b20092007-05-03 11:13:08 -0500537 lastSCSI = last_scsi_command(shpnt)[ldn];
538 outb(IM_EOI | ldn, IM_ATTN_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 /*these should never happen (hw fails, or a local programming bug) */
541 if (!global_command_error_excuse) {
542 switch (cmd_result) {
543 /* Prevent from Ooopsing on error to show the real reason */
544 case IM_ADAPTER_HW_FAILURE:
545 case IM_SOFTWARE_SEQUENCING_ERROR:
546 case IM_CMD_ERROR:
547 printk(KERN_ERR "IBM MCA SCSI: Fatal Subsystem ERROR!\n");
James Bottomley67b20092007-05-03 11:13:08 -0500548 printk(KERN_ERR " Last cmd=0x%x, ena=%x, len=", lastSCSI, ld(shpnt)[ldn].scb.enable);
549 if (ld(shpnt)[ldn].cmd)
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +0900550 printk("%ld/%ld,", (long) (scsi_bufflen(ld(shpnt)[ldn].cmd)), (long) (ld(shpnt)[ldn].scb.sys_buf_length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 else
552 printk("none,");
James Bottomley67b20092007-05-03 11:13:08 -0500553 if (ld(shpnt)[ldn].cmd)
554 printk("Blocksize=%d", ld(shpnt)[ldn].scb.u2.blk.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 else
556 printk("Blocksize=none");
James Bottomley67b20092007-05-03 11:13:08 -0500557 printk(", host=%p, ldn=0x%x\n", shpnt, ldn);
558 if (ld(shpnt)[ldn].cmd) {
559 printk(KERN_ERR "Blockcount=%d/%d\n", last_scsi_blockcount(shpnt)[ldn], ld(shpnt)[ldn].scb.u2.blk.count);
560 printk(KERN_ERR "Logical block=%lx/%lx\n", last_scsi_logical_block(shpnt)[ldn], ld(shpnt)[ldn].scb.u1.log_blk_adr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562 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");
563 /* if errors appear, enter this section to give detailed info */
564 printk(KERN_ERR "IBM MCA SCSI: Subsystem Error-Status follows:\n");
James Bottomley67b20092007-05-03 11:13:08 -0500565 printk(KERN_ERR " Command Type................: %x\n", last_scsi_type(shpnt)[ldn]);
566 printk(KERN_ERR " Attention Register..........: %x\n", inb(IM_ATTN_REG(shpnt)));
567 printk(KERN_ERR " Basic Control Register......: %x\n", inb(IM_CTR_REG(shpnt)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 printk(KERN_ERR " Interrupt Status Register...: %x\n", intr_reg);
James Bottomley67b20092007-05-03 11:13:08 -0500569 printk(KERN_ERR " Basic Status Register.......: %x\n", inb(IM_STAT_REG(shpnt)));
570 if ((last_scsi_type(shpnt)[ldn] == IM_SCB) || (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB)) {
571 printk(KERN_ERR " SCB-Command.................: %x\n", ld(shpnt)[ldn].scb.command);
572 printk(KERN_ERR " SCB-Enable..................: %x\n", ld(shpnt)[ldn].scb.enable);
573 printk(KERN_ERR " SCB-logical block address...: %lx\n", ld(shpnt)[ldn].scb.u1.log_blk_adr);
574 printk(KERN_ERR " SCB-system buffer address...: %lx\n", ld(shpnt)[ldn].scb.sys_buf_adr);
575 printk(KERN_ERR " SCB-system buffer length....: %lx\n", ld(shpnt)[ldn].scb.sys_buf_length);
576 printk(KERN_ERR " SCB-tsb address.............: %lx\n", ld(shpnt)[ldn].scb.tsb_adr);
577 printk(KERN_ERR " SCB-Chain address...........: %lx\n", ld(shpnt)[ldn].scb.scb_chain_adr);
578 printk(KERN_ERR " SCB-block count.............: %x\n", ld(shpnt)[ldn].scb.u2.blk.count);
579 printk(KERN_ERR " SCB-block length............: %x\n", ld(shpnt)[ldn].scb.u2.blk.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581 printk(KERN_ERR " Send this report to the maintainer.\n");
582 panic("IBM MCA SCSI: Fatal error message from the subsystem (0x%X,0x%X)!\n", lastSCSI, cmd_result);
583 break;
584 }
585 } else {
586 /* The command error handling is made silent, but we tell the
587 * calling function, that there is a reported error from the
588 * adapter. */
589 switch (cmd_result) {
590 case IM_ADAPTER_HW_FAILURE:
591 case IM_SOFTWARE_SEQUENCING_ERROR:
592 case IM_CMD_ERROR:
593 global_command_error_excuse = CMD_FAIL;
594 break;
595 default:
596 global_command_error_excuse = 0;
597 break;
598 }
599 }
600 /* if no panic appeared, increase the interrupt-counter */
James Bottomley67b20092007-05-03 11:13:08 -0500601 IBM_DS(shpnt).total_interrupts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /*only for local checking phase */
James Bottomley67b20092007-05-03 11:13:08 -0500603 if (local_checking_phase_flag(shpnt)) {
604 stat_result(shpnt) = cmd_result;
605 got_interrupt(shpnt) = 1;
606 reset_status(shpnt) = IM_RESET_FINISHED_OK;
607 last_scsi_command(shpnt)[ldn] = NO_SCSI;
608 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return IRQ_HANDLED;
610 }
611 /* handling of commands coming from upper level of scsi driver */
James Bottomley67b20092007-05-03 11:13:08 -0500612 if (last_scsi_type(shpnt)[ldn] == IM_IMM_CMD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /* verify ldn, and may handle rare reset immediate command */
James Bottomley67b20092007-05-03 11:13:08 -0500614 if ((reset_status(shpnt) == IM_RESET_IN_PROGRESS) && (last_scsi_command(shpnt)[ldn] == IM_RESET_IMM_CMD)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
616 disk_rw_in_progress = 0;
617 PS2_DISK_LED_OFF();
James Bottomley67b20092007-05-03 11:13:08 -0500618 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 } else {
620 /*reset disk led counter, turn off disk led */
621 disk_rw_in_progress = 0;
622 PS2_DISK_LED_OFF();
James Bottomley67b20092007-05-03 11:13:08 -0500623 reset_status(shpnt) = IM_RESET_FINISHED_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
James Bottomley67b20092007-05-03 11:13:08 -0500625 stat_result(shpnt) = cmd_result;
626 last_scsi_command(shpnt)[ldn] = NO_SCSI;
627 last_scsi_type(shpnt)[ldn] = 0;
628 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return IRQ_HANDLED;
James Bottomley67b20092007-05-03 11:13:08 -0500630 } else if (last_scsi_command(shpnt)[ldn] == IM_ABORT_IMM_CMD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* react on SCSI abort command */
632#ifdef IM_DEBUG_PROBE
633 printk("IBM MCA SCSI: Interrupt from SCSI-abort.\n");
634#endif
635 disk_rw_in_progress = 0;
636 PS2_DISK_LED_OFF();
James Bottomley67b20092007-05-03 11:13:08 -0500637 cmd = ld(shpnt)[ldn].cmd;
638 ld(shpnt)[ldn].cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE)
640 cmd->result = DID_NO_CONNECT << 16;
641 else
642 cmd->result = DID_ABORT << 16;
James Bottomley67b20092007-05-03 11:13:08 -0500643 stat_result(shpnt) = cmd_result;
644 last_scsi_command(shpnt)[ldn] = NO_SCSI;
645 last_scsi_type(shpnt)[ldn] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (cmd->scsi_done)
647 (cmd->scsi_done) (cmd); /* should be the internal_done */
James Bottomley67b20092007-05-03 11:13:08 -0500648 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return IRQ_HANDLED;
650 } else {
651 disk_rw_in_progress = 0;
652 PS2_DISK_LED_OFF();
James Bottomley67b20092007-05-03 11:13:08 -0500653 reset_status(shpnt) = IM_RESET_FINISHED_OK;
654 stat_result(shpnt) = cmd_result;
655 last_scsi_command(shpnt)[ldn] = NO_SCSI;
656 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return IRQ_HANDLED;
658 }
659 }
James Bottomley67b20092007-05-03 11:13:08 -0500660 last_scsi_command(shpnt)[ldn] = NO_SCSI;
661 last_scsi_type(shpnt)[ldn] = 0;
662 cmd = ld(shpnt)[ldn].cmd;
663 ld(shpnt)[ldn].cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#ifdef IM_DEBUG_TIMEOUT
665 if (cmd) {
666 if ((cmd->target == TIMEOUT_PUN) && (cmd->device->lun == TIMEOUT_LUN)) {
James Bottomley67b20092007-05-03 11:13:08 -0500667 spin_unlock_irqsave(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", cmd->target, cmd->device->lun);
669 return IRQ_HANDLED;
670 }
671 }
672#endif
673 /*if no command structure, just return, else clear cmd */
674 if (!cmd)
675 {
James Bottomley67b20092007-05-03 11:13:08 -0500676 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 return IRQ_HANDLED;
678 }
679
680#ifdef IM_DEBUG_INT
James Bottomley67b20092007-05-03 11:13:08 -0500681 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682#endif
683 /*if this is end of media read/write, may turn off PS/2 disk led */
James Bottomley67b20092007-05-03 11:13:08 -0500684 if ((ld(shpnt)[ldn].device_type != TYPE_NO_LUN) && (ld(shpnt)[ldn].device_type != TYPE_NO_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /* only access this, if there was a valid device addressed */
686 if (--disk_rw_in_progress == 0)
687 PS2_DISK_LED_OFF();
688 }
689
690 /* IBM describes the status-mask to be 0x1e, but this is not conform
691 * with SCSI-definition, I suppose, the reason for it is that IBM
692 * adapters do not support CMD_TERMINATED, TASK_SET_FULL and
693 * ACA_ACTIVE as returning statusbyte information. (ML) */
694 if (cmd_result == IM_CMD_COMPLETED_WITH_FAILURE) {
James Bottomley67b20092007-05-03 11:13:08 -0500695 cmd->result = (unsigned char) (ld(shpnt)[ldn].tsb.dev_status & 0x1e);
696 IBM_DS(shpnt).total_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 } else
698 cmd->result = 0;
699 /* write device status into cmd->result, and call done function */
700 if (lastSCSI == NO_SCSI) { /* unexpected interrupt :-( */
701 cmd->result |= DID_BAD_INTR << 16;
702 printk("IBM MCA SCSI: WARNING - Interrupt from non-pending SCSI-command!\n");
703 } else /* things went right :-) */
704 cmd->result |= DID_OK << 16;
705 if (cmd->scsi_done)
706 (cmd->scsi_done) (cmd);
James Bottomley67b20092007-05-03 11:13:08 -0500707 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return IRQ_HANDLED;
709}
710
James Bottomley67b20092007-05-03 11:13:08 -0500711static void issue_cmd(struct Scsi_Host *shpnt, unsigned long cmd_reg,
712 unsigned char attn_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
714 unsigned long flags;
715 /* must wait for attention reg not busy */
716 while (1) {
James Bottomley67b20092007-05-03 11:13:08 -0500717 spin_lock_irqsave(shpnt->host_lock, flags);
718 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 break;
James Bottomley67b20092007-05-03 11:13:08 -0500720 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722 /* write registers and enable system interrupts */
James Bottomley67b20092007-05-03 11:13:08 -0500723 outl(cmd_reg, IM_CMD_REG(shpnt));
724 outb(attn_reg, IM_ATTN_REG(shpnt));
725 spin_unlock_irqrestore(shpnt->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
728static void internal_done(Scsi_Cmnd * cmd)
729{
730 cmd->SCp.Status++;
731 return;
732}
733
734/* SCSI-SCB-command for device_inquiry */
James Bottomley67b20092007-05-03 11:13:08 -0500735static int device_inquiry(struct Scsi_Host *shpnt, int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 int retr;
738 struct im_scb *scb;
739 struct im_tsb *tsb;
740 unsigned char *buf;
741
James Bottomley67b20092007-05-03 11:13:08 -0500742 scb = &(ld(shpnt)[ldn].scb);
743 tsb = &(ld(shpnt)[ldn].tsb);
744 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
745 ld(shpnt)[ldn].tsb.dev_status = 0; /* prepare statusblock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 for (retr = 0; retr < 3; retr++) {
747 /* fill scb with inquiry command */
748 scb->command = IM_DEVICE_INQUIRY_CMD | IM_NO_DISCONNECT;
749 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
James Bottomley67b20092007-05-03 11:13:08 -0500750 last_scsi_command(shpnt)[ldn] = IM_DEVICE_INQUIRY_CMD;
751 last_scsi_type(shpnt)[ldn] = IM_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 scb->sys_buf_adr = isa_virt_to_bus(buf);
753 scb->sys_buf_length = 255; /* maximum bufferlength gives max info */
754 scb->tsb_adr = isa_virt_to_bus(tsb);
755 /* issue scb to passed ldn, and busy wait for interrupt */
James Bottomley67b20092007-05-03 11:13:08 -0500756 got_interrupt(shpnt) = 0;
757 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
758 while (!got_interrupt(shpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 barrier();
760
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200761 /*if command successful, break */
James Bottomley67b20092007-05-03 11:13:08 -0500762 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return 1;
764 }
765 /*if all three retries failed, return "no device at this ldn" */
766 if (retr >= 3)
767 return 0;
768 else
769 return 1;
770}
771
James Bottomley67b20092007-05-03 11:13:08 -0500772static int read_capacity(struct Scsi_Host *shpnt, int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 int retr;
775 struct im_scb *scb;
776 struct im_tsb *tsb;
777 unsigned char *buf;
778
James Bottomley67b20092007-05-03 11:13:08 -0500779 scb = &(ld(shpnt)[ldn].scb);
780 tsb = &(ld(shpnt)[ldn].tsb);
781 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
782 ld(shpnt)[ldn].tsb.dev_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 for (retr = 0; retr < 3; retr++) {
784 /*fill scb with read capacity command */
785 scb->command = IM_READ_CAPACITY_CMD;
786 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_READ_CONTROL | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
James Bottomley67b20092007-05-03 11:13:08 -0500787 last_scsi_command(shpnt)[ldn] = IM_READ_CAPACITY_CMD;
788 last_scsi_type(shpnt)[ldn] = IM_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 scb->sys_buf_adr = isa_virt_to_bus(buf);
790 scb->sys_buf_length = 8;
791 scb->tsb_adr = isa_virt_to_bus(tsb);
792 /*issue scb to passed ldn, and busy wait for interrupt */
James Bottomley67b20092007-05-03 11:13:08 -0500793 got_interrupt(shpnt) = 0;
794 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
795 while (!got_interrupt(shpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 barrier();
797
798 /*if got capacity, get block length and return one device found */
James Bottomley67b20092007-05-03 11:13:08 -0500799 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return 1;
801 }
802 /*if all three retries failed, return "no device at this ldn" */
803 if (retr >= 3)
804 return 0;
805 else
806 return 1;
807}
808
James Bottomley67b20092007-05-03 11:13:08 -0500809static int get_pos_info(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
811 int retr;
812 struct im_scb *scb;
813 struct im_tsb *tsb;
814 unsigned char *buf;
815
James Bottomley67b20092007-05-03 11:13:08 -0500816 scb = &(ld(shpnt)[MAX_LOG_DEV].scb);
817 tsb = &(ld(shpnt)[MAX_LOG_DEV].tsb);
818 buf = (unsigned char *) (&(ld(shpnt)[MAX_LOG_DEV].buf));
819 ld(shpnt)[MAX_LOG_DEV].tsb.dev_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 for (retr = 0; retr < 3; retr++) {
821 /*fill scb with get_pos_info command */
822 scb->command = IM_GET_POS_INFO_CMD;
823 scb->enable = IM_READ_CONTROL | IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE | IM_BYPASS_BUFFER;
James Bottomley67b20092007-05-03 11:13:08 -0500824 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_GET_POS_INFO_CMD;
825 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 scb->sys_buf_adr = isa_virt_to_bus(buf);
James Bottomley67b20092007-05-03 11:13:08 -0500827 if (special(shpnt) == IBM_SCSI2_FW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 scb->sys_buf_length = 256; /* get all info from F/W adapter */
829 else
830 scb->sys_buf_length = 18; /* get exactly 18 bytes for other SCSI */
831 scb->tsb_adr = isa_virt_to_bus(tsb);
832 /*issue scb to ldn=15, and busy wait for interrupt */
James Bottomley67b20092007-05-03 11:13:08 -0500833 got_interrupt(shpnt) = 0;
834 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | MAX_LOG_DEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 /* FIXME: timeout */
James Bottomley67b20092007-05-03 11:13:08 -0500837 while (!got_interrupt(shpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 barrier();
839
840 /*if got POS-stuff, get block length and return one device found */
James Bottomley67b20092007-05-03 11:13:08 -0500841 if ((stat_result(shpnt) == IM_SCB_CMD_COMPLETED) || (stat_result(shpnt) == IM_SCB_CMD_COMPLETED_WITH_RETRIES))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return 1;
843 }
844 /* if all three retries failed, return "no device at this ldn" */
845 if (retr >= 3)
846 return 0;
847 else
848 return 1;
849}
850
851/* SCSI-immediate-command for assign. This functions maps/unmaps specific
852 ldn-numbers on SCSI (PUN,LUN). It is needed for presetting of the
853 subsystem and for dynamical remapping od ldns. */
James Bottomley67b20092007-05-03 11:13:08 -0500854static int immediate_assign(struct Scsi_Host *shpnt, unsigned int pun,
855 unsigned int lun, unsigned int ldn,
856 unsigned int operation)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 int retr;
859 unsigned long imm_cmd;
860
861 for (retr = 0; retr < 3; retr++) {
862 /* select mutation level of the SCSI-adapter */
James Bottomley67b20092007-05-03 11:13:08 -0500863 switch (special(shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 case IBM_SCSI2_FW:
865 imm_cmd = (unsigned long) (IM_ASSIGN_IMM_CMD);
866 imm_cmd |= (unsigned long) ((lun & 7) << 24);
867 imm_cmd |= (unsigned long) ((operation & 1) << 23);
868 imm_cmd |= (unsigned long) ((pun & 7) << 20) | ((pun & 8) << 24);
869 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
870 break;
871 default:
James Bottomley67b20092007-05-03 11:13:08 -0500872 imm_cmd = inl(IM_CMD_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 imm_cmd &= (unsigned long) (0xF8000000); /* keep reserved bits */
874 imm_cmd |= (unsigned long) (IM_ASSIGN_IMM_CMD);
875 imm_cmd |= (unsigned long) ((lun & 7) << 24);
876 imm_cmd |= (unsigned long) ((operation & 1) << 23);
877 imm_cmd |= (unsigned long) ((pun & 7) << 20);
878 imm_cmd |= (unsigned long) ((ldn & 15) << 16);
879 break;
880 }
James Bottomley67b20092007-05-03 11:13:08 -0500881 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_ASSIGN_IMM_CMD;
882 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD;
883 got_interrupt(shpnt) = 0;
884 issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
885 while (!got_interrupt(shpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 barrier();
887
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200888 /*if command successful, break */
James Bottomley67b20092007-05-03 11:13:08 -0500889 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 return 1;
891 }
892 if (retr >= 3)
893 return 0;
894 else
895 return 1;
896}
897
James Bottomley67b20092007-05-03 11:13:08 -0500898static int immediate_feature(struct Scsi_Host *shpnt, unsigned int speed, unsigned int timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900 int retr;
901 unsigned long imm_cmd;
902
903 for (retr = 0; retr < 3; retr++) {
904 /* select mutation level of the SCSI-adapter */
905 imm_cmd = IM_FEATURE_CTR_IMM_CMD;
906 imm_cmd |= (unsigned long) ((speed & 0x7) << 29);
907 imm_cmd |= (unsigned long) ((timeout & 0x1fff) << 16);
James Bottomley67b20092007-05-03 11:13:08 -0500908 last_scsi_command(shpnt)[MAX_LOG_DEV] = IM_FEATURE_CTR_IMM_CMD;
909 last_scsi_type(shpnt)[MAX_LOG_DEV] = IM_IMM_CMD;
910 got_interrupt(shpnt) = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /* we need to run into command errors in order to probe for the
912 * right speed! */
913 global_command_error_excuse = 1;
James Bottomley67b20092007-05-03 11:13:08 -0500914 issue_cmd(shpnt, (unsigned long) (imm_cmd), IM_IMM_CMD | MAX_LOG_DEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* FIXME: timeout */
James Bottomley67b20092007-05-03 11:13:08 -0500917 while (!got_interrupt(shpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 barrier();
919 if (global_command_error_excuse == CMD_FAIL) {
920 global_command_error_excuse = 0;
921 return 2;
922 } else
923 global_command_error_excuse = 0;
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200924 /*if command successful, break */
James Bottomley67b20092007-05-03 11:13:08 -0500925 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return 1;
927 }
928 if (retr >= 3)
929 return 0;
930 else
931 return 1;
932}
933
934#ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
James Bottomley67b20092007-05-03 11:13:08 -0500935static int immediate_reset(struct Scsi_Host *shpnt, unsigned int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 int retries;
938 int ticks;
939 unsigned long imm_command;
940
941 for (retries = 0; retries < 3; retries++) {
James Bottomley67b20092007-05-03 11:13:08 -0500942 imm_command = inl(IM_CMD_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 imm_command &= (unsigned long) (0xFFFF0000); /* keep reserved bits */
944 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
James Bottomley67b20092007-05-03 11:13:08 -0500945 last_scsi_command(shpnt)[ldn] = IM_RESET_IMM_CMD;
946 last_scsi_type(shpnt)[ldn] = IM_IMM_CMD;
947 got_interrupt(shpnt) = 0;
948 reset_status(shpnt) = IM_RESET_IN_PROGRESS;
949 issue_cmd(shpnt, (unsigned long) (imm_command), IM_IMM_CMD | ldn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 ticks = IM_RESET_DELAY * HZ;
James Bottomley67b20092007-05-03 11:13:08 -0500951 while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 udelay((1 + 999 / HZ) * 1000);
953 barrier();
954 }
955 /* if reset did not complete, just complain */
956 if (!ticks) {
957 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
James Bottomley67b20092007-05-03 11:13:08 -0500958 reset_status(shpnt) = IM_RESET_FINISHED_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /* did not work, finish */
960 return 1;
961 }
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200962 /*if command successful, break */
James Bottomley67b20092007-05-03 11:13:08 -0500963 if (stat_result(shpnt) == IM_IMMEDIATE_CMD_COMPLETED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 return 1;
965 }
966 if (retries >= 3)
967 return 0;
968 else
969 return 1;
970}
971#endif
972
973/* type-interpreter for physical device numbers */
974static char *ti_p(int dev)
975{
976 switch (dev) {
977 case TYPE_IBM_SCSI_ADAPTER:
978 return ("A");
979 case TYPE_DISK:
980 return ("D");
981 case TYPE_TAPE:
982 return ("T");
983 case TYPE_PROCESSOR:
984 return ("P");
985 case TYPE_WORM:
986 return ("W");
987 case TYPE_ROM:
988 return ("R");
989 case TYPE_SCANNER:
990 return ("S");
991 case TYPE_MOD:
992 return ("M");
993 case TYPE_MEDIUM_CHANGER:
994 return ("C");
995 case TYPE_NO_LUN:
996 return ("+"); /* show NO_LUN */
997 }
998 return ("-"); /* TYPE_NO_DEVICE and others */
999}
1000
1001/* interpreter for logical device numbers (ldn) */
1002static char *ti_l(int val)
1003{
1004 const char hex[16] = "0123456789abcdef";
1005 static char answer[2];
1006
1007 answer[1] = (char) (0x0);
1008 if (val <= MAX_LOG_DEV)
1009 answer[0] = hex[val];
1010 else
1011 answer[0] = '-';
1012 return (char *) &answer;
1013}
1014
1015/* transfers bitpattern of the feature command to values in MHz */
1016static char *ibmrate(unsigned int speed, int i)
1017{
1018 switch (speed) {
1019 case 0:
1020 return i ? "5.00" : "10.00";
1021 case 1:
1022 return i ? "4.00" : "8.00";
1023 case 2:
1024 return i ? "3.33" : "6.66";
1025 case 3:
1026 return i ? "2.86" : "5.00";
1027 case 4:
1028 return i ? "2.50" : "4.00";
1029 case 5:
1030 return i ? "2.22" : "3.10";
1031 case 6:
1032 return i ? "2.00" : "2.50";
1033 case 7:
1034 return i ? "1.82" : "2.00";
1035 }
1036 return "---";
1037}
1038
1039static int probe_display(int what)
1040{
1041 static int rotator = 0;
1042 const char rotor[] = "|/-\\";
1043
1044 if (!(display_mode & LED_DISP))
1045 return 0;
1046 if (!what) {
1047 outl(0x20202020, MOD95_LED_PORT);
1048 outl(0x20202020, MOD95_LED_PORT + 4);
1049 } else {
1050 outb('S', MOD95_LED_PORT + 7);
1051 outb('C', MOD95_LED_PORT + 6);
1052 outb('S', MOD95_LED_PORT + 5);
1053 outb('I', MOD95_LED_PORT + 4);
1054 outb('i', MOD95_LED_PORT + 3);
1055 outb('n', MOD95_LED_PORT + 2);
1056 outb('i', MOD95_LED_PORT + 1);
1057 outb((char) (rotor[rotator]), MOD95_LED_PORT);
1058 rotator++;
1059 if (rotator > 3)
1060 rotator = 0;
1061 }
1062 return 0;
1063}
1064
James Bottomley67b20092007-05-03 11:13:08 -05001065static int probe_bus_mode(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 struct im_pos_info *info;
1068 int num_bus = 0;
1069 int ldn;
1070
James Bottomley67b20092007-05-03 11:13:08 -05001071 info = (struct im_pos_info *) (&(ld(shpnt)[MAX_LOG_DEV].buf));
1072 if (get_pos_info(shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 if (info->connector_size & 0xf000)
James Bottomley67b20092007-05-03 11:13:08 -05001074 subsystem_connector_size(shpnt) = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 else
James Bottomley67b20092007-05-03 11:13:08 -05001076 subsystem_connector_size(shpnt) = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 num_bus |= (info->pos_4b & 8) >> 3;
1078 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
James Bottomley67b20092007-05-03 11:13:08 -05001079 if ((special(shpnt) == IBM_SCSI_WCACHE) || (special(shpnt) == IBM_7568_WCACHE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (!((info->cache_stat >> ldn) & 1))
James Bottomley67b20092007-05-03 11:13:08 -05001081 ld(shpnt)[ldn].cache_flag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083 if (!((info->retry_stat >> ldn) & 1))
James Bottomley67b20092007-05-03 11:13:08 -05001084 ld(shpnt)[ldn].retry_flag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086#ifdef IM_DEBUG_PROBE
1087 printk("IBM MCA SCSI: SCSI-Cache bits: ");
1088 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
James Bottomley67b20092007-05-03 11:13:08 -05001089 printk("%d", ld(shpnt)[ldn].cache_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 printk("\nIBM MCA SCSI: SCSI-Retry bits: ");
1092 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
James Bottomley67b20092007-05-03 11:13:08 -05001093 printk("%d", ld(shpnt)[ldn].retry_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095 printk("\n");
1096#endif
1097 }
1098 return num_bus;
1099}
1100
1101/* probing scsi devices */
James Bottomley67b20092007-05-03 11:13:08 -05001102static void check_devices(struct Scsi_Host *shpnt, int adaptertype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
1104 int id, lun, ldn, ticks;
1105 int count_devices; /* local counter for connected device */
1106 int max_pun;
1107 int num_bus;
1108 int speedrun; /* local adapter_speed check variable */
1109
1110 /* assign default values to certain variables */
1111 ticks = 0;
1112 count_devices = 0;
James Bottomley67b20092007-05-03 11:13:08 -05001113 IBM_DS(shpnt).dyn_flag = 0; /* normally no need for dynamical ldn management */
1114 IBM_DS(shpnt).total_errors = 0; /* set errorcounter to 0 */
1115 next_ldn(shpnt) = 7; /* next ldn to be assigned is 7, because 0-6 is 'hardwired' */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 /* initialize the very important driver-informational arrays/structs */
James Bottomley67b20092007-05-03 11:13:08 -05001118 memset(ld(shpnt), 0, sizeof(ld(shpnt)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 for (ldn = 0; ldn <= MAX_LOG_DEV; ldn++) {
James Bottomley67b20092007-05-03 11:13:08 -05001120 last_scsi_command(shpnt)[ldn] = NO_SCSI; /* emptify last SCSI-command storage */
1121 last_scsi_type(shpnt)[ldn] = 0;
1122 ld(shpnt)[ldn].cache_flag = 1;
1123 ld(shpnt)[ldn].retry_flag = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
James Bottomley67b20092007-05-03 11:13:08 -05001125 memset(get_ldn(shpnt), TYPE_NO_DEVICE, sizeof(get_ldn(shpnt))); /* this is essential ! */
1126 memset(get_scsi(shpnt), TYPE_NO_DEVICE, sizeof(get_scsi(shpnt))); /* this is essential ! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 for (lun = 0; lun < 8; lun++) {
1128 /* mark the adapter at its pun on all luns */
James Bottomley67b20092007-05-03 11:13:08 -05001129 get_scsi(shpnt)[subsystem_pun(shpnt)][lun] = TYPE_IBM_SCSI_ADAPTER;
1130 get_ldn(shpnt)[subsystem_pun(shpnt)][lun] = MAX_LOG_DEV; /* make sure, the subsystem
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 ldn is active for all
1132 luns. */
1133 }
1134 probe_display(0); /* Supercool display usage during SCSI-probing. */
1135 /* This makes sense, when booting without any */
1136 /* monitor connected on model XX95. */
1137
1138 /* STEP 1: */
James Bottomley67b20092007-05-03 11:13:08 -05001139 adapter_speed(shpnt) = global_adapter_speed;
1140 speedrun = adapter_speed(shpnt);
1141 while (immediate_feature(shpnt, speedrun, adapter_timeout) == 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 probe_display(1);
1143 if (speedrun == 7)
1144 panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n");
1145 speedrun++;
1146 if (speedrun > 7)
1147 speedrun = 7;
1148 }
James Bottomley67b20092007-05-03 11:13:08 -05001149 adapter_speed(shpnt) = speedrun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /* Get detailed information about the current adapter, necessary for
1151 * device operations: */
James Bottomley67b20092007-05-03 11:13:08 -05001152 num_bus = probe_bus_mode(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 /* num_bus contains only valid data for the F/W adapter! */
1155 if (adaptertype == IBM_SCSI2_FW) { /* F/W SCSI adapter: */
1156 /* F/W adapter PUN-space extension evaluation: */
1157 if (num_bus) {
1158 printk(KERN_INFO "IBM MCA SCSI: Separate bus mode (wide-addressing enabled)\n");
James Bottomley67b20092007-05-03 11:13:08 -05001159 subsystem_maxid(shpnt) = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 } else {
1161 printk(KERN_INFO "IBM MCA SCSI: Combined bus mode (wide-addressing disabled)\n");
James Bottomley67b20092007-05-03 11:13:08 -05001162 subsystem_maxid(shpnt) = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164 printk(KERN_INFO "IBM MCA SCSI: Sync.-Rate (F/W: 20, Int.: 10, Ext.: %s) MBytes/s\n", ibmrate(speedrun, adaptertype));
1165 } else /* all other IBM SCSI adapters: */
1166 printk(KERN_INFO "IBM MCA SCSI: Synchronous-SCSI-Transfer-Rate: %s MBytes/s\n", ibmrate(speedrun, adaptertype));
1167
1168 /* assign correct PUN device space */
James Bottomley67b20092007-05-03 11:13:08 -05001169 max_pun = subsystem_maxid(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171#ifdef IM_DEBUG_PROBE
James Bottomley67b20092007-05-03 11:13:08 -05001172 printk("IBM MCA SCSI: Current SCSI-host index: %d\n", shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 printk("IBM MCA SCSI: Removing default logical SCSI-device mapping.");
1174#else
1175 printk(KERN_INFO "IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", (ibm_ansi_order) ? "ANSI" : "New");
1176#endif
1177 for (ldn = 0; ldn < MAX_LOG_DEV; ldn++) {
1178 probe_display(1);
1179#ifdef IM_DEBUG_PROBE
1180 printk(".");
1181#endif
James Bottomley67b20092007-05-03 11:13:08 -05001182 immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN); /* remove ldn (wherever) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 }
1184 lun = 0; /* default lun is 0 */
1185#ifndef IM_DEBUG_PROBE
1186 printk("cleared,");
1187#endif
1188 /* STEP 2: */
1189#ifdef IM_DEBUG_PROBE
1190 printk("\nIBM MCA SCSI: Scanning SCSI-devices.");
1191#endif
1192 for (id = 0; id < max_pun; id++)
1193#ifdef CONFIG_SCSI_MULTI_LUN
1194 for (lun = 0; lun < 8; lun++)
1195#endif
1196 {
1197 probe_display(1);
1198#ifdef IM_DEBUG_PROBE
1199 printk(".");
1200#endif
James Bottomley67b20092007-05-03 11:13:08 -05001201 if (id != subsystem_pun(shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* if pun is not the adapter: */
1203 /* set ldn=0 to pun,lun */
James Bottomley67b20092007-05-03 11:13:08 -05001204 immediate_assign(shpnt, id, lun, PROBE_LDN, SET_LDN);
1205 if (device_inquiry(shpnt, PROBE_LDN)) { /* probe device */
1206 get_scsi(shpnt)[id][lun] = (unsigned char) (ld(shpnt)[PROBE_LDN].buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 /* entry, even for NO_LUN */
James Bottomley67b20092007-05-03 11:13:08 -05001208 if (ld(shpnt)[PROBE_LDN].buf[0] != TYPE_NO_LUN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 count_devices++; /* a existing device is found */
1210 }
1211 /* remove ldn */
James Bottomley67b20092007-05-03 11:13:08 -05001212 immediate_assign(shpnt, id, lun, PROBE_LDN, REMOVE_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214 }
1215#ifndef IM_DEBUG_PROBE
1216 printk("scanned,");
1217#endif
1218 /* STEP 3: */
1219#ifdef IM_DEBUG_PROBE
1220 printk("\nIBM MCA SCSI: Mapping SCSI-devices.");
1221#endif
1222 ldn = 0;
1223 lun = 0;
1224#ifdef CONFIG_SCSI_MULTI_LUN
1225 for (lun = 0; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1226#endif
1227 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
1228 probe_display(1);
1229#ifdef IM_DEBUG_PROBE
1230 printk(".");
1231#endif
James Bottomley67b20092007-05-03 11:13:08 -05001232 if (id != subsystem_pun(shpnt)) {
1233 if (get_scsi(shpnt)[id][lun] != TYPE_NO_LUN && get_scsi(shpnt)[id][lun] != TYPE_NO_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 /* Only map if accepted type. Always enter for
1235 lun == 0 to get no gaps into ldn-mapping for ldn<7. */
James Bottomley67b20092007-05-03 11:13:08 -05001236 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1237 get_ldn(shpnt)[id][lun] = ldn; /* map ldn */
1238 if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239#ifdef CONFIG_IBMMCA_SCSI_DEV_RESET
1240 printk("resetting device at ldn=%x ... ", ldn);
James Bottomley67b20092007-05-03 11:13:08 -05001241 immediate_reset(shpnt, ldn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242#endif
1243 ldn++;
1244 } else {
1245 /* device vanished, probably because we don't know how to
1246 * handle it or because it has problems */
1247 if (lun > 0) {
1248 /* remove mapping */
James Bottomley67b20092007-05-03 11:13:08 -05001249 get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE;
1250 immediate_assign(shpnt, 0, 0, ldn, REMOVE_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 } else
1252 ldn++;
1253 }
1254 } else if (lun == 0) {
1255 /* map lun == 0, even if no device exists */
James Bottomley67b20092007-05-03 11:13:08 -05001256 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1257 get_ldn(shpnt)[id][lun] = ldn; /* map ldn */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 ldn++;
1259 }
1260 }
1261 }
1262 /* STEP 4: */
1263
1264 /* map remaining ldns to non-existing devices */
1265 for (lun = 1; lun < 8 && ldn < MAX_LOG_DEV; lun++)
1266 for (id = 0; id < max_pun && ldn < MAX_LOG_DEV; id++) {
James Bottomley67b20092007-05-03 11:13:08 -05001267 if (get_scsi(shpnt)[id][lun] == TYPE_NO_LUN || get_scsi(shpnt)[id][lun] == TYPE_NO_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 probe_display(1);
1269 /* Map remaining ldns only to NON-existing pun,lun
1270 combinations to make sure an inquiry will fail.
1271 For MULTI_LUN, it is needed to avoid adapter autonome
1272 SCSI-remapping. */
James Bottomley67b20092007-05-03 11:13:08 -05001273 immediate_assign(shpnt, id, lun, ldn, SET_LDN);
1274 get_ldn(shpnt)[id][lun] = ldn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 ldn++;
1276 }
1277 }
1278#ifndef IM_DEBUG_PROBE
1279 printk("mapped.");
1280#endif
1281 printk("\n");
1282#ifdef IM_DEBUG_PROBE
1283 if (ibm_ansi_order)
1284 printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n");
1285 else
1286 printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n");
1287#endif
1288
1289#ifdef IM_DEBUG_PROBE
1290 /* Show the physical and logical mapping during boot. */
1291 printk("IBM MCA SCSI: Determined SCSI-device-mapping:\n");
1292 printk(" Physical SCSI-Device Map Logical SCSI-Device Map\n");
1293 printk("ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n");
1294 for (id = 0; id < max_pun; id++) {
1295 printk("%2d ", id);
1296 for (lun = 0; lun < 8; lun++)
James Bottomley67b20092007-05-03 11:13:08 -05001297 printk("%2s ", ti_p(get_scsi(shpnt)[id][lun]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 printk(" %2d ", id);
1299 for (lun = 0; lun < 8; lun++)
James Bottomley67b20092007-05-03 11:13:08 -05001300 printk("%2s ", ti_l(get_ldn(shpnt)[id][lun]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 printk("\n");
1302 }
1303#endif
1304
1305 /* assign total number of found SCSI-devices to the statistics struct */
James Bottomley67b20092007-05-03 11:13:08 -05001306 IBM_DS(shpnt).total_scsi_devices = count_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 /* decide for output in /proc-filesystem, if the configuration of
1309 SCSI-devices makes dynamical reassignment of devices necessary */
1310 if (count_devices >= MAX_LOG_DEV)
James Bottomley67b20092007-05-03 11:13:08 -05001311 IBM_DS(shpnt).dyn_flag = 1; /* dynamical assignment is necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 else
James Bottomley67b20092007-05-03 11:13:08 -05001313 IBM_DS(shpnt).dyn_flag = 0; /* dynamical assignment is not necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 /* If no SCSI-devices are assigned, return 1 in order to cause message. */
1316 if (ldn == 0)
1317 printk("IBM MCA SCSI: Warning: No SCSI-devices found/assigned!\n");
1318
1319 /* reset the counters for statistics on the current adapter */
James Bottomley67b20092007-05-03 11:13:08 -05001320 IBM_DS(shpnt).scbs = 0;
1321 IBM_DS(shpnt).long_scbs = 0;
1322 IBM_DS(shpnt).total_accesses = 0;
1323 IBM_DS(shpnt).total_interrupts = 0;
1324 IBM_DS(shpnt).dynamical_assignments = 0;
1325 memset(IBM_DS(shpnt).ldn_access, 0x0, sizeof(IBM_DS(shpnt).ldn_access));
1326 memset(IBM_DS(shpnt).ldn_read_access, 0x0, sizeof(IBM_DS(shpnt).ldn_read_access));
1327 memset(IBM_DS(shpnt).ldn_write_access, 0x0, sizeof(IBM_DS(shpnt).ldn_write_access));
1328 memset(IBM_DS(shpnt).ldn_inquiry_access, 0x0, sizeof(IBM_DS(shpnt).ldn_inquiry_access));
1329 memset(IBM_DS(shpnt).ldn_modeselect_access, 0x0, sizeof(IBM_DS(shpnt).ldn_modeselect_access));
1330 memset(IBM_DS(shpnt).ldn_assignments, 0x0, sizeof(IBM_DS(shpnt).ldn_assignments));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 probe_display(0);
1332 return;
1333}
1334
James Bottomley67b20092007-05-03 11:13:08 -05001335static int device_exists(struct Scsi_Host *shpnt, int ldn, int *block_length, int *device_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 unsigned char *buf;
1338 /* if no valid device found, return immediately with 0 */
James Bottomley67b20092007-05-03 11:13:08 -05001339 if (!(device_inquiry(shpnt, ldn)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 return 0;
James Bottomley67b20092007-05-03 11:13:08 -05001341 buf = (unsigned char *) (&(ld(shpnt)[ldn].buf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (*buf == TYPE_ROM) {
1343 *device_type = TYPE_ROM;
1344 *block_length = 2048; /* (standard blocksize for yellow-/red-book) */
1345 return 1;
1346 }
1347 if (*buf == TYPE_WORM) {
1348 *device_type = TYPE_WORM;
1349 *block_length = 2048;
1350 return 1;
1351 }
1352 if (*buf == TYPE_DISK) {
1353 *device_type = TYPE_DISK;
James Bottomley67b20092007-05-03 11:13:08 -05001354 if (read_capacity(shpnt, ldn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 *block_length = *(buf + 7) + (*(buf + 6) << 8) + (*(buf + 5) << 16) + (*(buf + 4) << 24);
1356 return 1;
1357 } else
1358 return 0;
1359 }
1360 if (*buf == TYPE_MOD) {
1361 *device_type = TYPE_MOD;
James Bottomley67b20092007-05-03 11:13:08 -05001362 if (read_capacity(shpnt, ldn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 *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_TAPE) {
1369 *device_type = TYPE_TAPE;
1370 *block_length = 0; /* not in use (setting by mt and mtst in op.) */
1371 return 1;
1372 }
1373 if (*buf == TYPE_PROCESSOR) {
1374 *device_type = TYPE_PROCESSOR;
1375 *block_length = 0; /* they set their stuff on drivers */
1376 return 1;
1377 }
1378 if (*buf == TYPE_SCANNER) {
1379 *device_type = TYPE_SCANNER;
1380 *block_length = 0; /* they set their stuff on drivers */
1381 return 1;
1382 }
1383 if (*buf == TYPE_MEDIUM_CHANGER) {
1384 *device_type = TYPE_MEDIUM_CHANGER;
1385 *block_length = 0; /* One never knows, what to expect on a medium
1386 changer device. */
1387 return 1;
1388 }
1389 return 0;
1390}
1391
1392static void internal_ibmmca_scsi_setup(char *str, int *ints)
1393{
1394 int i, j, io_base, id_base;
1395 char *token;
1396
1397 io_base = 0;
1398 id_base = 0;
1399 if (str) {
1400 j = 0;
1401 while ((token = strsep(&str, ",")) != NULL) {
1402 if (!strcmp(token, "activity"))
1403 display_mode |= LED_ACTIVITY;
1404 if (!strcmp(token, "display"))
1405 display_mode |= LED_DISP;
1406 if (!strcmp(token, "adisplay"))
1407 display_mode |= LED_ADISP;
1408 if (!strcmp(token, "normal"))
1409 ibm_ansi_order = 0;
1410 if (!strcmp(token, "ansi"))
1411 ibm_ansi_order = 1;
1412 if (!strcmp(token, "fast"))
1413 global_adapter_speed = 0;
1414 if (!strcmp(token, "medium"))
1415 global_adapter_speed = 4;
1416 if (!strcmp(token, "slow"))
1417 global_adapter_speed = 7;
1418 if ((*token == '-') || (isdigit(*token))) {
1419 if (!(j % 2) && (io_base < IM_MAX_HOSTS))
1420 io_port[io_base++] = simple_strtoul(token, NULL, 0);
1421 if ((j % 2) && (id_base < IM_MAX_HOSTS))
1422 scsi_id[id_base++] = simple_strtoul(token, NULL, 0);
1423 j++;
1424 }
1425 }
1426 } else if (ints) {
1427 for (i = 0; i < IM_MAX_HOSTS && 2 * i + 2 < ints[0]; i++) {
1428 io_port[i] = ints[2 * i + 2];
1429 scsi_id[i] = ints[2 * i + 2];
1430 }
1431 }
1432 return;
1433}
1434
James Bottomley67b20092007-05-03 11:13:08 -05001435#if 0
1436 FIXME NEED TO MOVE TO SYSFS
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438static int ibmmca_getinfo(char *buf, int slot, void *dev_id)
1439{
1440 struct Scsi_Host *shpnt;
1441 int len, speciale, connectore, k;
1442 unsigned int pos[8];
1443 unsigned long flags;
1444 struct Scsi_Host *dev = dev_id;
1445
1446 spin_lock_irqsave(dev->host_lock, flags);
Tobias Klauser6391a112006-06-08 22:23:48 -07001447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 shpnt = dev; /* assign host-structure to local pointer */
1449 len = 0; /* set filled text-buffer index to 0 */
1450 /* get the _special contents of the hostdata structure */
1451 speciale = ((struct ibmmca_hostdata *) shpnt->hostdata)->_special;
1452 connectore = ((struct ibmmca_hostdata *) shpnt->hostdata)->_connector_size;
1453 for (k = 2; k < 4; k++)
1454 pos[k] = ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k];
1455 if (speciale == FORCED_DETECTION) { /* forced detection */
1456 len += sprintf(buf + len,
1457 "Adapter category: forced detected\n" "***************************************\n" "*** Forced detected SCSI Adapter ***\n" "*** No chip-information available ***\n" "***************************************\n");
1458 } else if (speciale == INTEGRATED_SCSI) {
1459 /* if the integrated subsystem has been found automatically: */
1460 len += sprintf(buf + len,
1461 "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");
Tobias Klauser6391a112006-06-08 22:23:48 -07001462 } else if ((speciale >= 0) && (speciale < ARRAY_SIZE(subsys_list))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* if the subsystem is a slot adapter */
1464 len += sprintf(buf + len, "Adapter category: slot-card\n" "ROM Segment Address: ");
1465 if ((pos[2] & 0xf0) == 0xf0)
1466 len += sprintf(buf + len, "off\n");
1467 else
1468 len += sprintf(buf + len, "0x%x\n", ((pos[2] & 0xf0) << 13) + 0xc0000);
1469 len += sprintf(buf + len, "Chip status: %s\n", (pos[2] & 1) ? "enabled" : "disabled");
1470 len += sprintf(buf + len, "Adapter I/O Offset: 0x%x\n", ((pos[2] & 0x0e) << 2));
1471 } else {
1472 len += sprintf(buf + len, "Adapter category: unknown\n");
1473 }
1474 /* common subsystem information to write to the slotn file */
1475 len += sprintf(buf + len, "Subsystem PUN: %d\n", shpnt->this_id);
1476 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));
1477 len += sprintf(buf + len, "MCA-slot size: %d bits", connectore);
1478 /* Now make sure, the bufferlength is devidable by 4 to avoid
1479 * paging problems of the buffer. */
1480 while (len % sizeof(int) != (sizeof(int) - 1))
1481 len += sprintf(buf + len, " ");
1482 len += sprintf(buf + len, "\n");
Tobias Klauser6391a112006-06-08 22:23:48 -07001483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 spin_unlock_irqrestore(shpnt->host_lock, flags);
Tobias Klauser6391a112006-06-08 22:23:48 -07001485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 return len;
1487}
James Bottomley67b20092007-05-03 11:13:08 -05001488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
James Bottomley67b20092007-05-03 11:13:08 -05001490static struct scsi_host_template ibmmca_driver_template = {
1491 .proc_name = "ibmmca",
1492 .proc_info = ibmmca_proc_info,
1493 .name = "IBM SCSI-Subsystem",
1494 .queuecommand = ibmmca_queuecommand,
1495 .eh_abort_handler = ibmmca_abort,
1496 .eh_host_reset_handler = ibmmca_host_reset,
1497 .bios_param = ibmmca_biosparam,
1498 .can_queue = 16,
1499 .this_id = 7,
1500 .sg_tablesize = 16,
1501 .cmd_per_lun = 1,
1502 .use_clustering = ENABLE_CLUSTERING,
1503};
1504
1505static int ibmmca_probe(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506{
1507 struct Scsi_Host *shpnt;
James Bottomley67b20092007-05-03 11:13:08 -05001508 int port, id, i, j, k, irq, enabled, ret = -EINVAL;
1509 struct mca_device *mca_dev = to_mca_device(dev);
1510 const char *description = ibmmca_description[mca_dev->index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 /* First of all, print the version number of the driver. This is
1513 * important to allow better user bugreports in case of already
1514 * having problems with the MCA_bus probing. */
1515 printk(KERN_INFO "IBM MCA SCSI: Version %s\n", IBMMCA_SCSI_DRIVER_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /* The POS2-register of all PS/2 model SCSI-subsystems has the following
1517 * interpretation of bits:
1518 * Bit 7 - 4 : Chip Revision ID (Release)
1519 * Bit 3 - 2 : Reserved
1520 * Bit 1 : 8k NVRAM Disabled
1521 * Bit 0 : Chip Enable (EN-Signal)
1522 * The POS3-register is interpreted as follows:
1523 * Bit 7 - 5 : SCSI ID
1524 * Bit 4 : Reserved = 0
1525 * Bit 3 - 0 : Reserved = 0
1526 * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common
1527 * Interfaces (1991)").
1528 * In short words, this means, that IBM PS/2 machines only support
1529 * 1 single subsystem by default. The slot-adapters must have another
1530 * configuration on pos2. Here, one has to assume the following
1531 * things for POS2-register:
1532 * Bit 7 - 4 : Chip Revision ID (Release)
1533 * Bit 3 - 1 : port offset factor
1534 * Bit 0 : Chip Enable (EN-Signal)
1535 * As I found a patch here, setting the IO-registers to 0x3540 forced,
1536 * as there was a 0x05 in POS2 on a model 56, I assume, that the
1537 * port 0x3540 must be fix for integrated SCSI-controllers.
1538 * Ok, this discovery leads to the following implementation: (M.Lang) */
1539
1540 /* first look for the IBM SCSI integrated subsystem on the motherboard */
1541 for (j = 0; j < 8; j++) /* read the pos-information */
James Bottomley67b20092007-05-03 11:13:08 -05001542 pos[j] = mca_device_read_pos(mca_dev, j);
1543 id = (pos[3] & 0xe0) >> 5; /* this is correct and represents the PUN */
1544 enabled = (pos[2] &0x01);
1545 if (!enabled) {
1546 printk(KERN_WARNING "IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n");
1547 printk(KERN_WARNING " SCSI-operations may not work.\n");
1548 }
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but
1551 * if we ignore the settings of all surrounding pos registers, it is not
1552 * completely sufficient to only check pos2 and pos3. */
1553 /* Therefore, now the following if statement is used to
1554 * make sure, we see a real integrated onboard SCSI-interface and no
1555 * internal system information, which gets mapped to some pos registers
1556 * on models 95xx. */
James Bottomley67b20092007-05-03 11:13:08 -05001557 if (mca_dev->slot == MCA_INTEGSCSI &&
1558 ((!pos[0] && !pos[1] && pos[2] > 0 &&
1559 pos[3] > 0 && !pos[4] && !pos[5] &&
1560 !pos[6] && !pos[7]) ||
1561 (pos[0] == 0xff && pos[1] == 0xff &&
1562 pos[2] < 0xff && pos[3] < 0xff &&
1563 pos[4] == 0xff && pos[5] == 0xff &&
1564 pos[6] == 0xff && pos[7] == 0xff))) {
1565 irq = IM_IRQ;
1566 port = IM_IO_PORT;
1567 } else {
1568 irq = IM_IRQ;
1569 port = IM_IO_PORT + ((pos[2] &0x0e) << 2);
1570 if ((mca_dev->index == IBM_SCSI2_FW) && (pos[6] != 0)) {
1571 printk(KERN_ERR "IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n");
1572 printk(KERN_ERR " Impossible to determine adapter PUN!\n");
1573 printk(KERN_ERR " Guessing adapter PUN = 7.\n");
1574 id = 7;
1575 } else {
1576 id = (pos[3] & 0xe0) >> 5; /* get subsystem PUN */
1577 if (mca_dev->index == IBM_SCSI2_FW) {
1578 id |= (pos[3] & 0x10) >> 1; /* get subsystem PUN high-bit
1579 * for F/W adapters */
1580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
James Bottomley67b20092007-05-03 11:13:08 -05001582 if ((mca_dev->index == IBM_SCSI2_FW) &&
1583 (pos[4] & 0x01) && (pos[6] == 0)) {
1584 /* IRQ11 is used by SCSI-2 F/W Adapter/A */
1585 printk(KERN_DEBUG "IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n");
1586 irq = IM_IRQ_FW;
1587 }
1588 }
1589
1590
1591
1592 /* give detailed information on the subsystem. This helps me
1593 * additionally during debugging and analyzing bug-reports. */
1594 printk(KERN_INFO "IBM MCA SCSI: %s found, io=0x%x, scsi id=%d,\n",
1595 description, port, id);
1596 if (mca_dev->slot == MCA_INTEGSCSI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 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.");
James Bottomley67b20092007-05-03 11:13:08 -05001598 else {
1599 if ((pos[2] & 0xf0) == 0xf0)
1600 printk(KERN_DEBUG " ROM Addr.=off,");
1601 else
1602 printk(KERN_DEBUG " ROM Addr.=0x%x,", ((pos[2] & 0xf0) << 13) + 0xc0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
James Bottomley67b20092007-05-03 11:13:08 -05001604 printk(KERN_DEBUG " port-offset=0x%x, subsystem=%s\n", ((pos[2] & 0x0e) << 2), (pos[2] & 1) ? "enabled." : "disabled.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
1606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 /* check I/O region */
James Bottomley67b20092007-05-03 11:13:08 -05001608 if (!request_region(port, IM_N_IO_PORT, description)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 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);
James Bottomley67b20092007-05-03 11:13:08 -05001610 goto out_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 }
1612
1613 /* register host */
James Bottomley67b20092007-05-03 11:13:08 -05001614 shpnt = scsi_host_alloc(&ibmmca_driver_template,
1615 sizeof(struct ibmmca_hostdata));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 if (!shpnt) {
1617 printk(KERN_ERR "IBM MCA SCSI: Unable to register host.\n");
James Bottomley67b20092007-05-03 11:13:08 -05001618 goto out_release;
1619 }
1620
1621 dev_set_drvdata(dev, shpnt);
1622 if(request_irq(irq, interrupt_handler, IRQF_SHARED, description, dev)) {
1623 printk(KERN_ERR "IBM MCA SCSI: failed to request interrupt %d\n", irq);
1624 goto out_free_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 }
1626
1627 /* request I/O region */
James Bottomley67b20092007-05-03 11:13:08 -05001628 special(shpnt) = mca_dev->index; /* important assignment or else crash! */
1629 subsystem_connector_size(shpnt) = 0; /* preset slot-size */
1630 shpnt->irq = irq; /* assign necessary stuff for the adapter */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 shpnt->io_port = port;
1632 shpnt->n_io_port = IM_N_IO_PORT;
1633 shpnt->this_id = id;
1634 shpnt->max_id = 8; /* 8 PUNs are default */
1635 /* now, the SCSI-subsystem is connected to Linux */
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637#ifdef IM_DEBUG_PROBE
James Bottomley67b20092007-05-03 11:13:08 -05001638 ctrl = (unsigned int) (inb(IM_CTR_REG(found))); /* get control-register status */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", ctrl, inb(IM_STAT_REG(found)));
1640 printk("IBM MCA SCSI: This adapters' POS-registers: ");
1641 for (i = 0; i < 8; i++)
1642 printk("%x ", pos[i]);
1643 printk("\n");
1644#endif
James Bottomley67b20092007-05-03 11:13:08 -05001645 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 for (i = 0; i < 16; i++) /* reset the tables */
1648 for (j = 0; j < 8; j++)
James Bottomley67b20092007-05-03 11:13:08 -05001649 get_ldn(shpnt)[i][j] = MAX_LOG_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
1651 /* check which logical devices exist */
1652 /* after this line, local interrupting is possible: */
James Bottomley67b20092007-05-03 11:13:08 -05001653 local_checking_phase_flag(shpnt) = 1;
1654 check_devices(shpnt, mca_dev->index); /* call by value, using the global variable hosts */
1655 local_checking_phase_flag(shpnt) = 0;
1656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 /* an ibm mca subsystem has been detected */
James Bottomley67b20092007-05-03 11:13:08 -05001658
1659 for (k = 2; k < 7; k++)
1660 ((struct ibmmca_hostdata *) shpnt->hostdata)->_pos[k] = pos[k];
1661 ((struct ibmmca_hostdata *) shpnt->hostdata)->_special = INTEGRATED_SCSI;
1662 mca_device_set_name(mca_dev, description);
1663 /* FIXME: NEED TO REPLUMB TO SYSFS
1664 mca_set_adapter_procfn(MCA_INTEGSCSI, (MCA_ProcFn) ibmmca_getinfo, shpnt);
1665 */
1666 mca_device_set_claim(mca_dev, 1);
1667 if (scsi_add_host(shpnt, dev)) {
1668 dev_printk(KERN_ERR, dev, "IBM MCA SCSI: scsi_add_host failed\n");
1669 goto out_free_host;
1670 }
1671 scsi_scan_host(shpnt);
1672
1673 return 0;
1674 out_free_host:
1675 scsi_host_put(shpnt);
1676 out_release:
1677 release_region(port, IM_N_IO_PORT);
1678 out_fail:
1679 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
James Bottomley67b20092007-05-03 11:13:08 -05001682static int __devexit ibmmca_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
James Bottomley67b20092007-05-03 11:13:08 -05001684 struct Scsi_Host *shpnt = dev_get_drvdata(dev);
1685 scsi_remove_host(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 release_region(shpnt->io_port, shpnt->n_io_port);
James Bottomley67b20092007-05-03 11:13:08 -05001687 free_irq(shpnt->irq, dev);
Matthew Wilcox34f8f0d2007-08-15 12:56:58 -06001688 scsi_host_put(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 return 0;
1690}
1691
1692/* The following routine is the SCSI command queue for the midlevel driver */
Jeff Garzikf2812332010-11-16 02:10:29 -05001693static int ibmmca_queuecommand_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 unsigned int ldn;
1696 unsigned int scsi_cmd;
1697 struct im_scb *scb;
1698 struct Scsi_Host *shpnt;
1699 int current_ldn;
1700 int id, lun;
1701 int target;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 int max_pun;
1703 int i;
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001704 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 shpnt = cmd->device->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
James Bottomley67b20092007-05-03 11:13:08 -05001708 max_pun = subsystem_maxid(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 if (ibm_ansi_order) {
1710 target = max_pun - 1 - cmd->device->id;
James Bottomley67b20092007-05-03 11:13:08 -05001711 if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 target--;
James Bottomley67b20092007-05-03 11:13:08 -05001713 else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 target++;
1715 } else
1716 target = cmd->device->id;
1717
1718 /* if (target,lun) is NO LUN or not existing at all, return error */
James Bottomley67b20092007-05-03 11:13:08 -05001719 if ((get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_LUN) || (get_scsi(shpnt)[target][cmd->device->lun] == TYPE_NO_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 cmd->result = DID_NO_CONNECT << 16;
1721 if (done)
1722 done(cmd);
1723 return 0;
1724 }
1725
1726 /*if (target,lun) unassigned, do further checks... */
James Bottomley67b20092007-05-03 11:13:08 -05001727 ldn = get_ldn(shpnt)[target][cmd->device->lun];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 if (ldn >= MAX_LOG_DEV) { /* on invalid ldn do special stuff */
1729 if (ldn > MAX_LOG_DEV) { /* dynamical remapping if ldn unassigned */
James Bottomley67b20092007-05-03 11:13:08 -05001730 current_ldn = next_ldn(shpnt); /* stop-value for one circle */
1731 while (ld(shpnt)[next_ldn(shpnt)].cmd) { /* search for a occupied, but not in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 /* command-processing ldn. */
James Bottomley67b20092007-05-03 11:13:08 -05001733 next_ldn(shpnt)++;
1734 if (next_ldn(shpnt) >= MAX_LOG_DEV)
1735 next_ldn(shpnt) = 7;
1736 if (current_ldn == next_ldn(shpnt)) { /* One circle done ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 /* no non-processing ldn found */
Jeff Garzik017560f2005-10-24 18:04:36 -04001738 scmd_printk(KERN_WARNING, cmd,
1739 "IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n"
1740 " On ldn 7-14 SCSI-commands everywhere in progress.\n"
1741 " Reporting DID_NO_CONNECT for device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 cmd->result = DID_NO_CONNECT << 16; /* return no connect */
1743 if (done)
1744 done(cmd);
1745 return 0;
1746 }
1747 }
1748
1749 /* unmap non-processing ldn */
1750 for (id = 0; id < max_pun; id++)
1751 for (lun = 0; lun < 8; lun++) {
James Bottomley67b20092007-05-03 11:13:08 -05001752 if (get_ldn(shpnt)[id][lun] == next_ldn(shpnt)) {
1753 get_ldn(shpnt)[id][lun] = TYPE_NO_DEVICE;
1754 get_scsi(shpnt)[id][lun] = TYPE_NO_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 /* unmap entry */
1756 }
1757 }
1758 /* set reduced interrupt_handler-mode for checking */
James Bottomley67b20092007-05-03 11:13:08 -05001759 local_checking_phase_flag(shpnt) = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 /* map found ldn to pun,lun */
James Bottomley67b20092007-05-03 11:13:08 -05001761 get_ldn(shpnt)[target][cmd->device->lun] = next_ldn(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 /* change ldn to the right value, that is now next_ldn */
James Bottomley67b20092007-05-03 11:13:08 -05001763 ldn = next_ldn(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* unassign all ldns (pun,lun,ldn does not matter for remove) */
James Bottomley67b20092007-05-03 11:13:08 -05001765 immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 /* set only LDN for remapped device */
James Bottomley67b20092007-05-03 11:13:08 -05001767 immediate_assign(shpnt, target, cmd->device->lun, ldn, SET_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* get device information for ld[ldn] */
James Bottomley67b20092007-05-03 11:13:08 -05001769 if (device_exists(shpnt, ldn, &ld(shpnt)[ldn].block_length, &ld(shpnt)[ldn].device_type)) {
1770 ld(shpnt)[ldn].cmd = NULL; /* To prevent panic set 0, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 devices that were not assigned,
1772 should have nothing in progress. */
James Bottomley67b20092007-05-03 11:13:08 -05001773 get_scsi(shpnt)[target][cmd->device->lun] = ld(shpnt)[ldn].device_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 /* increase assignment counters for statistics in /proc */
James Bottomley67b20092007-05-03 11:13:08 -05001775 IBM_DS(shpnt).dynamical_assignments++;
1776 IBM_DS(shpnt).ldn_assignments[ldn]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 } else
1778 /* panic here, because a device, found at boottime has
1779 vanished */
1780 panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", ldn, target, cmd->device->lun);
1781 /* unassign again all ldns (pun,lun,ldn does not matter for remove) */
James Bottomley67b20092007-05-03 11:13:08 -05001782 immediate_assign(shpnt, 0, 0, 0, REMOVE_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 /* remap all ldns, as written in the pun/lun table */
1784 lun = 0;
1785#ifdef CONFIG_SCSI_MULTI_LUN
1786 for (lun = 0; lun < 8; lun++)
1787#endif
1788 for (id = 0; id < max_pun; id++) {
James Bottomley67b20092007-05-03 11:13:08 -05001789 if (get_ldn(shpnt)[id][lun] <= MAX_LOG_DEV)
1790 immediate_assign(shpnt, id, lun, get_ldn(shpnt)[id][lun], SET_LDN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 }
1792 /* set back to normal interrupt_handling */
James Bottomley67b20092007-05-03 11:13:08 -05001793 local_checking_phase_flag(shpnt) = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794#ifdef IM_DEBUG_PROBE
1795 /* Information on syslog terminal */
1796 printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", ldn, target, cmd->device->lun);
1797#endif
1798 /* increase next_ldn for next dynamical assignment */
James Bottomley67b20092007-05-03 11:13:08 -05001799 next_ldn(shpnt)++;
1800 if (next_ldn(shpnt) >= MAX_LOG_DEV)
1801 next_ldn(shpnt) = 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 } else { /* wall against Linux accesses to the subsystem adapter */
1803 cmd->result = DID_BAD_TARGET << 16;
1804 if (done)
1805 done(cmd);
1806 return 0;
1807 }
1808 }
1809
1810 /*verify there is no command already in progress for this log dev */
James Bottomley67b20092007-05-03 11:13:08 -05001811 if (ld(shpnt)[ldn].cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 panic("IBM MCA SCSI: cmd already in progress for this ldn.\n");
1813
1814 /*save done in cmd, and save cmd for the interrupt handler */
1815 cmd->scsi_done = done;
James Bottomley67b20092007-05-03 11:13:08 -05001816 ld(shpnt)[ldn].cmd = cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 /*fill scb information independent of the scsi command */
James Bottomley67b20092007-05-03 11:13:08 -05001819 scb = &(ld(shpnt)[ldn].scb);
1820 ld(shpnt)[ldn].tsb.dev_status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 scb->enable = IM_REPORT_TSB_ONLY_ON_ERROR | IM_RETRY_ENABLE;
James Bottomley67b20092007-05-03 11:13:08 -05001822 scb->tsb_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].tsb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 scsi_cmd = cmd->cmnd[0];
1824
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001825 if (scsi_sg_count(cmd)) {
1826 BUG_ON(scsi_sg_count(cmd) > 16);
1827
1828 scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) {
Jens Axboe45711f12007-10-22 21:19:53 +02001829 ld(shpnt)[ldn].sge[i].address = (void *) (isa_page_to_bus(sg_page(sg)) + sg->offset);
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001830 ld(shpnt)[ldn].sge[i].byte_length = sg->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832 scb->enable |= IM_POINTER_TO_LIST;
James Bottomley67b20092007-05-03 11:13:08 -05001833 scb->sys_buf_adr = isa_virt_to_bus(&(ld(shpnt)[ldn].sge[0]));
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001834 scb->sys_buf_length = scsi_sg_count(cmd) * sizeof(struct im_sge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 } else {
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001836 scb->sys_buf_adr = isa_virt_to_bus(scsi_sglist(cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 /* recent Linux midlevel SCSI places 1024 byte for inquiry
1838 * command. Far too much for old PS/2 hardware. */
1839 switch (scsi_cmd) {
1840 /* avoid command errors by setting bufferlengths to
1841 * ANSI-standard. Beware of forcing it to 255,
1842 * this could SEGV the kernel!!! */
1843 case INQUIRY:
1844 case REQUEST_SENSE:
1845 case MODE_SENSE:
1846 case MODE_SELECT:
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001847 if (scsi_bufflen(cmd) > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 scb->sys_buf_length = 255;
1849 else
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001850 scb->sys_buf_length = scsi_bufflen(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 break;
1852 case TEST_UNIT_READY:
1853 scb->sys_buf_length = 0;
1854 break;
1855 default:
FUJITA Tomonori5f60ef62007-05-21 15:10:00 +09001856 scb->sys_buf_length = scsi_bufflen(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 break;
1858 }
1859 }
1860 /*fill scb information dependent on scsi command */
1861
1862#ifdef IM_DEBUG_CMD
1863 printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd, ldn);
1864#endif
1865
1866 /* for specific device-type debugging: */
1867#ifdef IM_DEBUG_CMD_SPEC_DEV
James Bottomley67b20092007-05-03 11:13:08 -05001868 if (ld(shpnt)[ldn].device_type == IM_DEBUG_CMD_DEVICE)
1869 printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", ld(shpnt)[ldn].device_type, scsi_cmd, ldn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870#endif
1871
1872 /* for possible panics store current command */
James Bottomley67b20092007-05-03 11:13:08 -05001873 last_scsi_command(shpnt)[ldn] = scsi_cmd;
1874 last_scsi_type(shpnt)[ldn] = IM_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 /* update statistical info */
James Bottomley67b20092007-05-03 11:13:08 -05001876 IBM_DS(shpnt).total_accesses++;
1877 IBM_DS(shpnt).ldn_access[ldn]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 switch (scsi_cmd) {
1880 case READ_6:
1881 case WRITE_6:
1882 case READ_10:
1883 case WRITE_10:
1884 case READ_12:
1885 case WRITE_12:
1886 /* Distinguish between disk and other devices. Only disks (that are the
1887 most frequently accessed devices) should be supported by the
1888 IBM-SCSI-Subsystem commands. */
James Bottomley67b20092007-05-03 11:13:08 -05001889 switch (ld(shpnt)[ldn].device_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 case TYPE_DISK: /* for harddisks enter here ... */
1891 case TYPE_MOD: /* ... try it also for MO-drives (send flames as */
1892 /* you like, if this won't work.) */
1893 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12) {
1894 /* read command preparations */
1895 scb->enable |= IM_READ_CONTROL;
James Bottomley67b20092007-05-03 11:13:08 -05001896 IBM_DS(shpnt).ldn_read_access[ldn]++; /* increase READ-access on ldn stat. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 scb->command = IM_READ_DATA_CMD | IM_NO_DISCONNECT;
1898 } else { /* write command preparations */
James Bottomley67b20092007-05-03 11:13:08 -05001899 IBM_DS(shpnt).ldn_write_access[ldn]++; /* increase write-count on ldn stat. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 scb->command = IM_WRITE_DATA_CMD | IM_NO_DISCONNECT;
1901 }
1902 if (scsi_cmd == READ_6 || scsi_cmd == WRITE_6) {
1903 scb->u1.log_blk_adr = (((unsigned) cmd->cmnd[3]) << 0) | (((unsigned) cmd->cmnd[2]) << 8) | ((((unsigned) cmd->cmnd[1]) & 0x1f) << 16);
1904 scb->u2.blk.count = (unsigned) cmd->cmnd[4];
1905 } else {
1906 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);
1907 scb->u2.blk.count = (((unsigned) cmd->cmnd[8]) << 0) | (((unsigned) cmd->cmnd[7]) << 8);
1908 }
James Bottomley67b20092007-05-03 11:13:08 -05001909 last_scsi_logical_block(shpnt)[ldn] = scb->u1.log_blk_adr;
1910 last_scsi_blockcount(shpnt)[ldn] = scb->u2.blk.count;
1911 scb->u2.blk.length = ld(shpnt)[ldn].block_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 break;
1913 /* for other devices, enter here. Other types are not known by
1914 Linux! TYPE_NO_LUN is forbidden as valid device. */
1915 case TYPE_ROM:
1916 case TYPE_TAPE:
1917 case TYPE_PROCESSOR:
1918 case TYPE_WORM:
1919 case TYPE_SCANNER:
1920 case TYPE_MEDIUM_CHANGER:
1921 /* If there is a sequential-device, IBM recommends to use
1922 IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE.
1923 This includes CD-ROM devices, too, due to the partial sequential
1924 read capabilities. */
1925 scb->command = IM_OTHER_SCSI_CMD_CMD;
1926 if (scsi_cmd == READ_6 || scsi_cmd == READ_10 || scsi_cmd == READ_12)
1927 /* enable READ */
1928 scb->enable |= IM_READ_CONTROL;
1929 scb->enable |= IM_BYPASS_BUFFER;
1930 scb->u1.scsi_cmd_length = cmd->cmd_len;
1931 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
James Bottomley67b20092007-05-03 11:13:08 -05001932 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 /* Read/write on this non-disk devices is also displayworthy,
1934 so flash-up the LED/display. */
1935 break;
1936 }
1937 break;
1938 case INQUIRY:
James Bottomley67b20092007-05-03 11:13:08 -05001939 IBM_DS(shpnt).ldn_inquiry_access[ldn]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 scb->command = IM_DEVICE_INQUIRY_CMD;
1941 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1942 scb->u1.log_blk_adr = 0;
1943 break;
1944 case TEST_UNIT_READY:
1945 scb->command = IM_OTHER_SCSI_CMD_CMD;
1946 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1947 scb->u1.log_blk_adr = 0;
1948 scb->u1.scsi_cmd_length = 6;
1949 memcpy(scb->u2.scsi_command, cmd->cmnd, 6);
James Bottomley67b20092007-05-03 11:13:08 -05001950 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 break;
1952 case READ_CAPACITY:
1953 /* the length of system memory buffer must be exactly 8 bytes */
1954 scb->command = IM_READ_CAPACITY_CMD;
1955 scb->enable |= IM_READ_CONTROL | IM_BYPASS_BUFFER;
1956 if (scb->sys_buf_length > 8)
1957 scb->sys_buf_length = 8;
1958 break;
1959 /* Commands that need read-only-mode (system <- device): */
1960 case REQUEST_SENSE:
1961 scb->command = IM_REQUEST_SENSE_CMD;
1962 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1963 break;
1964 /* Commands that need write-only-mode (system -> device): */
1965 case MODE_SELECT:
1966 case MODE_SELECT_10:
James Bottomley67b20092007-05-03 11:13:08 -05001967 IBM_DS(shpnt).ldn_modeselect_access[ldn]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 scb->command = IM_OTHER_SCSI_CMD_CMD;
1969 scb->enable |= IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER; /*Select needs WRITE-enabled */
1970 scb->u1.scsi_cmd_length = cmd->cmd_len;
1971 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
James Bottomley67b20092007-05-03 11:13:08 -05001972 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 break;
1974 /* For other commands, read-only is useful. Most other commands are
1975 running without an input-data-block. */
1976 default:
1977 scb->command = IM_OTHER_SCSI_CMD_CMD;
1978 scb->enable |= IM_READ_CONTROL | IM_SUPRESS_EXCEPTION_SHORT | IM_BYPASS_BUFFER;
1979 scb->u1.scsi_cmd_length = cmd->cmd_len;
1980 memcpy(scb->u2.scsi_command, cmd->cmnd, cmd->cmd_len);
James Bottomley67b20092007-05-03 11:13:08 -05001981 last_scsi_type(shpnt)[ldn] = IM_LONG_SCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 break;
1983 }
1984 /*issue scb command, and return */
1985 if (++disk_rw_in_progress == 1)
1986 PS2_DISK_LED_ON(shpnt->host_no, target);
1987
James Bottomley67b20092007-05-03 11:13:08 -05001988 if (last_scsi_type(shpnt)[ldn] == IM_LONG_SCB) {
1989 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_LONG_SCB | ldn);
1990 IBM_DS(shpnt).long_scbs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 } else {
James Bottomley67b20092007-05-03 11:13:08 -05001992 issue_cmd(shpnt, isa_virt_to_bus(scb), IM_SCB | ldn);
1993 IBM_DS(shpnt).scbs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 }
1995 return 0;
1996}
1997
Jeff Garzikf2812332010-11-16 02:10:29 -05001998static DEF_SCSI_QCMD(ibmmca_queuecommand)
1999
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04002000static int __ibmmca_abort(Scsi_Cmnd * cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
2002 /* Abort does not work, as the adapter never generates an interrupt on
2003 * whatever situation is simulated, even when really pending commands
2004 * are running on the adapters' hardware ! */
2005
2006 struct Scsi_Host *shpnt;
2007 unsigned int ldn;
2008 void (*saved_done) (Scsi_Cmnd *);
2009 int target;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 int max_pun;
2011 unsigned long imm_command;
2012
2013#ifdef IM_DEBUG_PROBE
2014 printk("IBM MCA SCSI: Abort subroutine called...\n");
2015#endif
2016
2017 shpnt = cmd->device->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
James Bottomley67b20092007-05-03 11:13:08 -05002019 max_pun = subsystem_maxid(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 if (ibm_ansi_order) {
2021 target = max_pun - 1 - cmd->device->id;
James Bottomley67b20092007-05-03 11:13:08 -05002022 if ((target <= subsystem_pun(shpnt)) && (cmd->device->id <= subsystem_pun(shpnt)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 target--;
James Bottomley67b20092007-05-03 11:13:08 -05002024 else if ((target >= subsystem_pun(shpnt)) && (cmd->device->id >= subsystem_pun(shpnt)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 target++;
2026 } else
2027 target = cmd->device->id;
2028
2029 /* get logical device number, and disable system interrupts */
2030 printk(KERN_WARNING "IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", target, cmd->device->lun);
James Bottomley67b20092007-05-03 11:13:08 -05002031 ldn = get_ldn(shpnt)[target][cmd->device->lun];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 /*if cmd for this ldn has already finished, no need to abort */
James Bottomley67b20092007-05-03 11:13:08 -05002034 if (!ld(shpnt)[ldn].cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return SUCCESS;
2036 }
2037
2038 /* Clear ld.cmd, save done function, install internal done,
2039 * send abort immediate command (this enables sys. interrupts),
2040 * and wait until the interrupt arrives.
2041 */
2042 saved_done = cmd->scsi_done;
2043 cmd->scsi_done = internal_done;
2044 cmd->SCp.Status = 0;
James Bottomley67b20092007-05-03 11:13:08 -05002045 last_scsi_command(shpnt)[ldn] = IM_ABORT_IMM_CMD;
2046 last_scsi_type(shpnt)[ldn] = IM_IMM_CMD;
2047 imm_command = inl(IM_CMD_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2049 imm_command |= (unsigned long) (IM_ABORT_IMM_CMD);
2050 /* must wait for attention reg not busy */
2051 /* FIXME - timeout, politeness */
2052 while (1) {
James Bottomley67b20092007-05-03 11:13:08 -05002053 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 break;
2055 }
2056 /* write registers and enable system interrupts */
James Bottomley67b20092007-05-03 11:13:08 -05002057 outl(imm_command, IM_CMD_REG(shpnt));
2058 outb(IM_IMM_CMD | ldn, IM_ATTN_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059#ifdef IM_DEBUG_PROBE
2060 printk("IBM MCA SCSI: Abort queued to adapter...\n");
2061#endif
2062 spin_unlock_irq(shpnt->host_lock);
2063 while (!cmd->SCp.Status)
2064 yield();
2065 spin_lock_irq(shpnt->host_lock);
2066 cmd->scsi_done = saved_done;
2067#ifdef IM_DEBUG_PROBE
2068 printk("IBM MCA SCSI: Abort returned with adapter response...\n");
2069#endif
2070
2071 /*if abort went well, call saved done, then return success or error */
2072 if (cmd->result == (DID_ABORT << 16))
2073 {
2074 cmd->result |= DID_ABORT << 16;
2075 if (cmd->scsi_done)
2076 (cmd->scsi_done) (cmd);
James Bottomley67b20092007-05-03 11:13:08 -05002077 ld(shpnt)[ldn].cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078#ifdef IM_DEBUG_PROBE
2079 printk("IBM MCA SCSI: Abort finished with success.\n");
2080#endif
2081 return SUCCESS;
2082 } else {
2083 cmd->result |= DID_NO_CONNECT << 16;
2084 if (cmd->scsi_done)
2085 (cmd->scsi_done) (cmd);
James Bottomley67b20092007-05-03 11:13:08 -05002086 ld(shpnt)[ldn].cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087#ifdef IM_DEBUG_PROBE
2088 printk("IBM MCA SCSI: Abort failed.\n");
2089#endif
2090 return FAILED;
2091 }
2092}
2093
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04002094static int ibmmca_abort(Scsi_Cmnd * cmd)
2095{
2096 struct Scsi_Host *shpnt = cmd->device->host;
2097 int rc;
2098
2099 spin_lock_irq(shpnt->host_lock);
2100 rc = __ibmmca_abort(cmd);
2101 spin_unlock_irq(shpnt->host_lock);
2102
2103 return rc;
2104}
2105
Jeff Garzik df0ae242005-05-28 07:57:14 -04002106static int __ibmmca_host_reset(Scsi_Cmnd * cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct Scsi_Host *shpnt;
2109 Scsi_Cmnd *cmd_aid;
2110 int ticks, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 unsigned long imm_command;
2112
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002113 BUG_ON(cmd == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
2115 ticks = IM_RESET_DELAY * HZ;
2116 shpnt = cmd->device->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
James Bottomley67b20092007-05-03 11:13:08 -05002118 if (local_checking_phase_flag(shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 printk(KERN_WARNING "IBM MCA SCSI: unable to reset while checking devices.\n");
2120 return FAILED;
2121 }
2122
2123 /* issue reset immediate command to subsystem, and wait for interrupt */
2124 printk("IBM MCA SCSI: resetting all devices.\n");
James Bottomley67b20092007-05-03 11:13:08 -05002125 reset_status(shpnt) = IM_RESET_IN_PROGRESS;
2126 last_scsi_command(shpnt)[0xf] = IM_RESET_IMM_CMD;
2127 last_scsi_type(shpnt)[0xf] = IM_IMM_CMD;
2128 imm_command = inl(IM_CMD_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 imm_command &= (unsigned long) (0xffff0000); /* mask reserved stuff */
2130 imm_command |= (unsigned long) (IM_RESET_IMM_CMD);
2131 /* must wait for attention reg not busy */
2132 while (1) {
James Bottomley67b20092007-05-03 11:13:08 -05002133 if (!(inb(IM_STAT_REG(shpnt)) & IM_BUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 break;
2135 spin_unlock_irq(shpnt->host_lock);
2136 yield();
2137 spin_lock_irq(shpnt->host_lock);
2138 }
2139 /*write registers and enable system interrupts */
James Bottomley67b20092007-05-03 11:13:08 -05002140 outl(imm_command, IM_CMD_REG(shpnt));
2141 outb(IM_IMM_CMD | 0xf, IM_ATTN_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 /* wait for interrupt finished or intr_stat register to be set, as the
2143 * interrupt will not be executed, while we are in here! */
2144
2145 /* FIXME: This is really really icky we so want a sleeping version of this ! */
James Bottomley67b20092007-05-03 11:13:08 -05002146 while (reset_status(shpnt) == IM_RESET_IN_PROGRESS && --ticks && ((inb(IM_INTR_REG(shpnt)) & 0x8f) != 0x8f)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 udelay((1 + 999 / HZ) * 1000);
2148 barrier();
2149 }
2150 /* if reset did not complete, just return an error */
2151 if (!ticks) {
2152 printk(KERN_ERR "IBM MCA SCSI: reset did not complete within %d seconds.\n", IM_RESET_DELAY);
James Bottomley67b20092007-05-03 11:13:08 -05002153 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 return FAILED;
2155 }
2156
James Bottomley67b20092007-05-03 11:13:08 -05002157 if ((inb(IM_INTR_REG(shpnt)) & 0x8f) == 0x8f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 /* analysis done by this routine and not by the intr-routine */
James Bottomley67b20092007-05-03 11:13:08 -05002159 if (inb(IM_INTR_REG(shpnt)) == 0xaf)
2160 reset_status(shpnt) = IM_RESET_FINISHED_OK_NO_INT;
2161 else if (inb(IM_INTR_REG(shpnt)) == 0xcf)
2162 reset_status(shpnt) = IM_RESET_FINISHED_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 else /* failed, 4get it */
James Bottomley67b20092007-05-03 11:13:08 -05002164 reset_status(shpnt) = IM_RESET_NOT_IN_PROGRESS_NO_INT;
2165 outb(IM_EOI | 0xf, IM_ATTN_REG(shpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 }
2167
2168 /* if reset failed, just return an error */
James Bottomley67b20092007-05-03 11:13:08 -05002169 if (reset_status(shpnt) == IM_RESET_FINISHED_FAIL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 printk(KERN_ERR "IBM MCA SCSI: reset failed.\n");
2171 return FAILED;
2172 }
2173
2174 /* so reset finished ok - call outstanding done's, and return success */
2175 printk(KERN_INFO "IBM MCA SCSI: Reset successfully completed.\n");
2176 for (i = 0; i < MAX_LOG_DEV; i++) {
James Bottomley67b20092007-05-03 11:13:08 -05002177 cmd_aid = ld(shpnt)[i].cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if (cmd_aid && cmd_aid->scsi_done) {
James Bottomley67b20092007-05-03 11:13:08 -05002179 ld(shpnt)[i].cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 cmd_aid->result = DID_RESET << 16;
2181 }
2182 }
2183 return SUCCESS;
2184}
2185
Jeff Garzik df0ae242005-05-28 07:57:14 -04002186static int ibmmca_host_reset(Scsi_Cmnd * cmd)
2187{
2188 struct Scsi_Host *shpnt = cmd->device->host;
2189 int rc;
2190
2191 spin_lock_irq(shpnt->host_lock);
2192 rc = __ibmmca_host_reset(cmd);
2193 spin_unlock_irq(shpnt->host_lock);
2194
2195 return rc;
2196}
2197
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198static int ibmmca_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int *info)
2199{
2200 int size = capacity;
2201 info[0] = 64;
2202 info[1] = 32;
2203 info[2] = size / (info[0] * info[1]);
2204 if (info[2] >= 1024) {
2205 info[0] = 128;
2206 info[1] = 63;
2207 info[2] = size / (info[0] * info[1]);
2208 if (info[2] >= 1024) {
2209 info[0] = 255;
2210 info[1] = 63;
2211 info[2] = size / (info[0] * info[1]);
2212 if (info[2] >= 1024)
2213 info[2] = 1023;
2214 }
2215 }
2216 return 0;
2217}
2218
2219/* calculate percentage of total accesses on a ldn */
James Bottomley67b20092007-05-03 11:13:08 -05002220static int ldn_access_load(struct Scsi_Host *shpnt, int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
James Bottomley67b20092007-05-03 11:13:08 -05002222 if (IBM_DS(shpnt).total_accesses == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 return (0);
James Bottomley67b20092007-05-03 11:13:08 -05002224 if (IBM_DS(shpnt).ldn_access[ldn] == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 return (0);
James Bottomley67b20092007-05-03 11:13:08 -05002226 return (IBM_DS(shpnt).ldn_access[ldn] * 100) / IBM_DS(shpnt).total_accesses;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229/* calculate total amount of r/w-accesses */
James Bottomley67b20092007-05-03 11:13:08 -05002230static int ldn_access_total_read_write(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
2232 int a;
2233 int i;
2234
2235 a = 0;
2236 for (i = 0; i <= MAX_LOG_DEV; i++)
James Bottomley67b20092007-05-03 11:13:08 -05002237 a += IBM_DS(shpnt).ldn_read_access[i] + IBM_DS(shpnt).ldn_write_access[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 return (a);
2239}
2240
James Bottomley67b20092007-05-03 11:13:08 -05002241static int ldn_access_total_inquiry(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
2243 int a;
2244 int i;
2245
2246 a = 0;
2247 for (i = 0; i <= MAX_LOG_DEV; i++)
James Bottomley67b20092007-05-03 11:13:08 -05002248 a += IBM_DS(shpnt).ldn_inquiry_access[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 return (a);
2250}
2251
James Bottomley67b20092007-05-03 11:13:08 -05002252static int ldn_access_total_modeselect(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
2254 int a;
2255 int i;
2256
2257 a = 0;
2258 for (i = 0; i <= MAX_LOG_DEV; i++)
James Bottomley67b20092007-05-03 11:13:08 -05002259 a += IBM_DS(shpnt).ldn_modeselect_access[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 return (a);
2261}
2262
2263/* routine to display info in the proc-fs-structure (a deluxe feature) */
2264static int ibmmca_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout)
2265{
2266 int len = 0;
James Bottomley67b20092007-05-03 11:13:08 -05002267 int i, id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 unsigned long flags;
2269 int max_pun;
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
James Bottomley67b20092007-05-03 11:13:08 -05002272 spin_lock_irqsave(shpnt->host_lock, flags); /* Check it */
2273
2274 max_pun = subsystem_maxid(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 len += sprintf(buffer + len, "\n IBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", IBMMCA_SCSI_DRIVER_VERSION);
2277 len += sprintf(buffer + len, " SCSI Access-Statistics:\n");
2278 len += sprintf(buffer + len, " Device Scanning Order....: %s\n", (ibm_ansi_order) ? "IBM/ANSI" : "New Industry Standard");
2279#ifdef CONFIG_SCSI_MULTI_LUN
2280 len += sprintf(buffer + len, " Multiple LUN probing.....: Yes\n");
2281#else
2282 len += sprintf(buffer + len, " Multiple LUN probing.....: No\n");
2283#endif
2284 len += sprintf(buffer + len, " This Hostnumber..........: %d\n", shpnt->host_no);
James Bottomley67b20092007-05-03 11:13:08 -05002285 len += sprintf(buffer + len, " Base I/O-Port............: 0x%x\n", (unsigned int) (IM_CMD_REG(shpnt)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 len += sprintf(buffer + len, " (Shared) IRQ.............: %d\n", IM_IRQ);
James Bottomley67b20092007-05-03 11:13:08 -05002287 len += sprintf(buffer + len, " Total Interrupts.........: %d\n", IBM_DS(shpnt).total_interrupts);
2288 len += sprintf(buffer + len, " Total SCSI Accesses......: %d\n", IBM_DS(shpnt).total_accesses);
2289 len += sprintf(buffer + len, " Total short SCBs.........: %d\n", IBM_DS(shpnt).scbs);
2290 len += sprintf(buffer + len, " Total long SCBs..........: %d\n", IBM_DS(shpnt).long_scbs);
2291 len += sprintf(buffer + len, " Total SCSI READ/WRITE..: %d\n", ldn_access_total_read_write(shpnt));
2292 len += sprintf(buffer + len, " Total SCSI Inquiries...: %d\n", ldn_access_total_inquiry(shpnt));
2293 len += sprintf(buffer + len, " Total SCSI Modeselects.: %d\n", ldn_access_total_modeselect(shpnt));
2294 len += sprintf(buffer + len, " Total SCSI other cmds..: %d\n", IBM_DS(shpnt).total_accesses - ldn_access_total_read_write(shpnt)
2295 - ldn_access_total_modeselect(shpnt)
2296 - ldn_access_total_inquiry(shpnt));
2297 len += sprintf(buffer + len, " Total SCSI command fails.: %d\n\n", IBM_DS(shpnt).total_errors);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 len += sprintf(buffer + len, " Logical-Device-Number (LDN) Access-Statistics:\n");
2299 len += sprintf(buffer + len, " LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n");
2300 len += sprintf(buffer + len, " -----|--------------|-----------|-----------|--------------\n");
2301 for (i = 0; i <= MAX_LOG_DEV; i++)
James Bottomley67b20092007-05-03 11:13:08 -05002302 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]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 len += sprintf(buffer + len, " -----------------------------------------------------------\n\n");
2304 len += sprintf(buffer + len, " Dynamical-LDN-Assignment-Statistics:\n");
James Bottomley67b20092007-05-03 11:13:08 -05002305 len += sprintf(buffer + len, " Number of physical SCSI-devices..: %d (+ Adapter)\n", IBM_DS(shpnt).total_scsi_devices);
2306 len += sprintf(buffer + len, " Dynamical Assignment necessary...: %s\n", IBM_DS(shpnt).dyn_flag ? "Yes" : "No ");
2307 len += sprintf(buffer + len, " Next LDN to be assigned..........: 0x%x\n", next_ldn(shpnt));
2308 len += sprintf(buffer + len, " Dynamical assignments done yet...: %d\n", IBM_DS(shpnt).dynamical_assignments);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 len += sprintf(buffer + len, "\n Current SCSI-Device-Mapping:\n");
2310 len += sprintf(buffer + len, " Physical SCSI-Device Map Logical SCSI-Device Map\n");
2311 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");
2312 for (id = 0; id < max_pun; id++) {
2313 len += sprintf(buffer + len, " %2d ", id);
2314 for (lun = 0; lun < 8; lun++)
James Bottomley67b20092007-05-03 11:13:08 -05002315 len += sprintf(buffer + len, "%2s ", ti_p(get_scsi(shpnt)[id][lun]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 len += sprintf(buffer + len, " %2d ", id);
2317 for (lun = 0; lun < 8; lun++)
James Bottomley67b20092007-05-03 11:13:08 -05002318 len += sprintf(buffer + len, "%2s ", ti_l(get_ldn(shpnt)[id][lun]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 len += sprintf(buffer + len, "\n");
2320 }
2321
2322 len += sprintf(buffer + len, "(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n");
2323 len += sprintf(buffer + len, " R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n");
2324 len += sprintf(buffer + len, " - = nothing found, nothing assigned or unprobed LUN)\n\n");
2325
2326 *start = buffer + offset;
2327 len -= offset;
2328 if (len > length)
2329 len = length;
2330 spin_unlock_irqrestore(shpnt->host_lock, flags);
2331 return len;
2332}
2333
2334static int option_setup(char *str)
2335{
2336 int ints[IM_MAX_HOSTS];
2337 char *cur = str;
2338 int i = 1;
2339
Roel Kluin340f0522009-12-08 14:08:56 -08002340 while (cur && isdigit(*cur) && i < IM_MAX_HOSTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 ints[i++] = simple_strtoul(cur, NULL, 0);
2342 if ((cur = strchr(cur, ',')) != NULL)
2343 cur++;
2344 }
2345 ints[0] = i - 1;
2346 internal_ibmmca_scsi_setup(cur, ints);
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08002347 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350__setup("ibmmcascsi=", option_setup);
2351
James Bottomley67b20092007-05-03 11:13:08 -05002352static struct mca_driver ibmmca_driver = {
2353 .id_table = ibmmca_id_table,
2354 .driver = {
2355 .name = "ibmmca",
2356 .bus = &mca_bus_type,
2357 .probe = ibmmca_probe,
2358 .remove = __devexit_p(ibmmca_remove),
2359 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360};
James Bottomley67b20092007-05-03 11:13:08 -05002361
2362static int __init ibmmca_init(void)
2363{
2364#ifdef MODULE
2365 /* If the driver is run as module, read from conf.modules or cmd-line */
2366 if (boot_options)
2367 option_setup(boot_options);
2368#endif
2369
2370 return mca_register_driver_integrated(&ibmmca_driver, MCA_INTEGSCSI);
2371}
2372
2373static void __exit ibmmca_exit(void)
2374{
2375 mca_unregister_driver(&ibmmca_driver);
2376}
2377
2378module_init(ibmmca_init);
2379module_exit(ibmmca_exit);