2 Low Level Linux Driver for the IBM Microchannel SCSI Subsystem for 4 Copyright (c) 1995 Strom Systems, Inc. under the terms of the GNU 5 General Public License. Written by Martin Kolinek, December 1995. 6 Further development by: Chris Beauregard, Klaus Kudielka, Michael Lang 7 See the file README.ibmmca for a detailed description of this driver, 8 the commandline arguments and the history of its development. 9 See the WWW-page: http://www.uni-mainz.de/~langm000/linux.html for latest 10 updates, info and ADF-files for adapters supported by this driver. 13 #ifndef LINUX_VERSION_CODE 14 #include <linux/version.h> 16 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) 17 #error"This driver works only with kernel 2.4.0 or higher!" 19 #include <linux/kernel.h> 20 #include <linux/types.h> 21 #include <linux/ctype.h> 22 #include <linux/string.h> 23 #include <linux/ioport.h> 24 #include <linux/delay.h> 25 #include <linux/sched.h> 26 #include <linux/blk.h> 27 #include <linux/proc_fs.h> 28 #include <linux/stat.h> 29 #include <linux/mca.h> 30 #include <asm/system.h> 31 #include <linux/spinlock.h> 33 #include <linux/init.h> 38 #include <linux/config.h> 40 /* current version of this driver-source: */ 41 #define IBMMCA_SCSI_DRIVER_VERSION"4.0" 43 #define IBMLOCK spin_lock_irqsave(&io_request_lock, flags); 44 #define IBMUNLOCK spin_unlock_irqrestore(&io_request_lock, flags); 46 /* driver configuration */ 47 #define IM_MAX_HOSTS 8/* maximum number of host adapters */ 48 #define IM_RESET_DELAY 60/* seconds allowed for a reset */ 50 /* driver debugging - #undef all for normal operation */ 51 /* if defined: count interrupts and ignore this special one: */ 52 #undef IM_DEBUG_TIMEOUT 50 55 /* verbose interrupt: */ 57 /* verbose queuecommand: */ 59 /* verbose queucommand for specific SCSI-device type: */ 60 #undef IM_DEBUG_CMD_SPEC_DEV 61 /* verbose device probing */ 64 /* device type that shall be displayed on syslog (only during debugging): */ 65 #define IM_DEBUG_CMD_DEVICE TYPE_TAPE 67 /* relative addresses of hardware registers on a subsystem */ 68 #define IM_CMD_REG(hi) (hosts[(hi)]->io_port)/*Command Interface, (4 bytes long) */ 69 #define IM_ATTN_REG(hi) (hosts[(hi)]->io_port+4)/*Attention (1 byte) */ 70 #define IM_CTR_REG(hi) (hosts[(hi)]->io_port+5)/*Basic Control (1 byte) */ 71 #define IM_INTR_REG(hi) (hosts[(hi)]->io_port+6)/*Interrupt Status (1 byte, r/o) */ 72 #define IM_STAT_REG(hi) (hosts[(hi)]->io_port+7)/*Basic Status (1 byte, read only) */ 74 /* basic I/O-port of first adapter */ 75 #define IM_IO_PORT 0x3540 76 /* maximum number of hosts that can be found */ 77 #define IM_N_IO_PORT 8 79 /*requests going into the upper nibble of the Attention register */ 80 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */ 81 #define IM_IMM_CMD 0x10/*immediate command */ 82 #define IM_SCB 0x30/*Subsystem Control Block command */ 83 #define IM_LONG_SCB 0x40/*long Subsystem Control Block command */ 84 #define IM_EOI 0xe0/*end-of-interrupt request */ 86 /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */ 87 #define IM_HW_RESET 0x80/*hardware reset */ 88 #define IM_ENABLE_DMA 0x02/*enable subsystem's busmaster DMA */ 89 #define IM_ENABLE_INTR 0x01/*enable interrupts to the system */ 91 /*to interpret the upper nibble of Interrupt Status register */ 92 /*note: the lower nibble specifies the device(0-14), or subsystem(15) */ 93 #define IM_SCB_CMD_COMPLETED 0x10 94 #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50 95 #define IM_LOOP_SCATTER_BUFFER_FULL 0x60 96 #define IM_ADAPTER_HW_FAILURE 0x70 97 #define IM_IMMEDIATE_CMD_COMPLETED 0xa0 98 #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0 99 #define IM_CMD_ERROR 0xe0 100 #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0 102 /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */ 103 #define IM_CMD_REG_FULL 0x08 104 #define IM_CMD_REG_EMPTY 0x04 105 #define IM_INTR_REQUEST 0x02 108 /*immediate commands (word written into low 2 bytes of command reg) */ 109 #define IM_RESET_IMM_CMD 0x0400 110 #define IM_FEATURE_CTR_IMM_CMD 0x040c 111 #define IM_DMA_PACING_IMM_CMD 0x040d 112 #define IM_ASSIGN_IMM_CMD 0x040e 113 #define IM_ABORT_IMM_CMD 0x040f 114 #define IM_FORMAT_PREP_IMM_CMD 0x0417 116 /*SCB (Subsystem Control Block) structure */ 118 unsigned short command
;/*command word (read, etc.) */ 119 unsigned short enable
;/*enable word, modifies cmd */ 121 unsigned long log_blk_adr
;/*block address on SCSI device */ 122 unsigned char scsi_cmd_length
;/*6,10,12, for other scsi cmd */ 124 unsigned long sys_buf_adr
;/*physical system memory adr */ 125 unsigned long sys_buf_length
;/*size of sys mem buffer */ 126 unsigned long tsb_adr
;/*Termination Status Block adr */ 127 unsigned long scb_chain_adr
;/*optional SCB chain address */ 130 unsigned short count
;/*block count, on SCSI device */ 131 unsigned short length
;/*block length, on SCSI device */ 133 unsigned char scsi_command
[12];/*other scsi command */ 137 /*structure scatter-gather element (for list of system memory areas) */ 140 unsigned long byte_length
; 143 /*structure returned by a get_pos_info command: */ 145 unsigned short pos_id
;/* adapter id */ 146 unsigned char pos_3a
;/* pos 3 (if pos 6 = 0) */ 147 unsigned char pos_2
;/* pos 2 */ 148 unsigned char int_level
;/* interrupt level IRQ 11 or 14 */ 149 unsigned char pos_4a
;/* pos 4 (if pos 6 = 0) */ 150 unsigned short connector_size
;/* MCA connector size: 16 or 32 Bit */ 151 unsigned char num_luns
;/* number of supported luns per device */ 152 unsigned char num_puns
;/* number of supported puns */ 153 unsigned char pacing_factor
;/* pacing factor */ 154 unsigned char num_ldns
;/* number of ldns available */ 155 unsigned char eoi_off
;/* time EOI and interrupt inactive */ 156 unsigned char max_busy
;/* time between reset and busy on */ 157 unsigned short cache_stat
;/* ldn cachestat. Bit=1 = not cached */ 158 unsigned short retry_stat
;/* retry status of ldns. Bit=1=disabled */ 159 unsigned char pos_4b
;/* pos 4 (if pos 6 = 1) */ 160 unsigned char pos_3b
;/* pos 3 (if pos 6 = 1) */ 161 unsigned char pos_6
;/* pos 6 */ 162 unsigned char pos_5
;/* pos 5 */ 163 unsigned short max_overlap
;/* maximum overlapping requests */ 164 unsigned short num_bus
;/* number of SCSI-busses */ 167 /*values for SCB command word */ 168 #define IM_NO_SYNCHRONOUS 0x0040/*flag for any command */ 169 #define IM_NO_DISCONNECT 0x0080/*flag for any command */ 170 #define IM_READ_DATA_CMD 0x1c01 171 #define IM_WRITE_DATA_CMD 0x1c02 172 #define IM_READ_VERIFY_CMD 0x1c03 173 #define IM_WRITE_VERIFY_CMD 0x1c04 174 #define IM_REQUEST_SENSE_CMD 0x1c08 175 #define IM_READ_CAPACITY_CMD 0x1c09 176 #define IM_DEVICE_INQUIRY_CMD 0x1c0b 177 #define IM_READ_LOGICAL_CMD 0x1c2a 178 #define IM_OTHER_SCSI_CMD_CMD 0x241f 180 /* unused, but supported, SCB commands */ 181 #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07/* command status */ 182 #define IM_GET_POS_INFO_CMD 0x1c0a/* returns neat stuff */ 183 #define IM_READ_PREFETCH_CMD 0x1c31/* caching controller only */ 184 #define IM_FOMAT_UNIT_CMD 0x1c16/* format unit */ 185 #define IM_REASSIGN_BLOCK_CMD 0x1c18/* in case of error */ 187 /*values to set bits in the enable word of SCB */ 188 #define IM_READ_CONTROL 0x8000 189 #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000 190 #define IM_RETRY_ENABLE 0x2000 191 #define IM_POINTER_TO_LIST 0x1000 192 #define IM_SUPRESS_EXCEPTION_SHORT 0x0400 193 #define IM_BYPASS_BUFFER 0x0200 194 #define IM_CHAIN_ON_NO_ERROR 0x0001 196 /*TSB (Termination Status Block) structure */ 198 unsigned short end_status
; 199 unsigned short reserved1
; 200 unsigned long residual_byte_count
; 201 unsigned long sg_list_element_adr
; 202 unsigned short status_length
; 203 unsigned char dev_status
; 204 unsigned char cmd_status
; 205 unsigned char dev_error
; 206 unsigned char cmd_error
; 207 unsigned short reserved2
; 208 unsigned short reserved3
; 209 unsigned short low_of_last_scb_adr
; 210 unsigned short high_of_last_scb_adr
; 213 /*subsystem uses interrupt request level 14 */ 215 /*SCSI-2 F/W may evade to interrupt 11 */ 218 /* Model 95 has an additional alphanumeric display, which can be used 219 to display SCSI-activities. 8595 models do not have any disk led, which 220 makes this feature quite useful. 221 The regular PS/2 disk led is turned on/off by bits 6,7 of system 224 /* LED display-port (actually, last LED on display) */ 225 #define MOD95_LED_PORT 0x108 226 /* system-control-register of PS/2s with diskindicator */ 227 #define PS2_SYS_CTR 0x92 228 /* activity displaying methods */ 231 #define LED_ACTIVITY 4 235 /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED 236 displays. ldn is no longer displayed here, because the ldn mapping is now 237 done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime 238 or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble, 239 interest, debugging or just for having fun. The left number gives the 240 host-adapter number and the right shows the accessed SCSI-ID. */ 242 /* display_mode is set by the ibmmcascsi= command line arg */ 243 static int display_mode
=0; 244 /* set default adapter timeout */ 245 static unsigned int adapter_timeout
=45; 246 /* for probing on feature-command: */ 247 static unsigned int global_command_error_excuse
=0; 248 /* global setting by command line for adapter_speed */ 249 static int global_adapter_speed
=0;/* full speed by default */ 251 /* Panel / LED on, do it right for F/W addressin, too. adisplay will 252 * just ignore ids>7, as the panel has only 7 digits available */ 253 #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \ 254 outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \ 255 outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \ 256 if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \ 257 outb((char)(ad+48), MOD95_LED_PORT); } \ 258 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \ 259 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); } 261 /* Panel / LED off */ 262 /* bug fixed, Dec 15, 1997, where | was replaced by & here */ 263 #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \ 264 outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \ 265 outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \ 266 if ((display_mode & LED_ACTIVITY)||(!display_mode)) \ 267 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); } 269 /*list of supported subsystems */ 270 struct subsys_list_struct
{ 271 unsigned short mca_id
; 275 /* types of different supported hardware that goes to hostdata special */ 276 #define IBM_SCSI2_FW 0 277 #define IBM_7568_WCACHE 1 278 #define IBM_EXP_UNIT 2 279 #define IBM_SCSI_WCACHE 3 282 /* other special flags for hostdata structure */ 283 #define FORCED_DETECTION 100 284 #define INTEGRATED_SCSI 101 286 /* List of possible IBM-SCSI-adapters */ 287 struct subsys_list_struct subsys_list
[] = { 288 {0x8efc,"IBM SCSI-2 F/W Adapter"},/* special = 0 */ 289 {0x8efd,"IBM 7568 Industrial Computer SCSI Adapter w/Cache"},/* special = 1 */ 290 {0x8ef8,"IBM Expansion Unit SCSI Controller"},/* special = 2 */ 291 {0x8eff,"IBM SCSI Adapter w/Cache"},/* special = 3 */ 292 {0x8efe,"IBM SCSI Adapter"},/* special = 4 */ 295 /* Max number of logical devices (can be up from 0 to 14). 15 is the address 296 of the adapter itself. */ 297 #define MAX_LOG_DEV 15 299 /*local data for a logical device */ 300 struct logical_device
{ 301 struct im_scb scb
;/* SCSI-subsystem-control-block structure */ 302 struct im_tsb tsb
;/* SCSI command complete status block structure */ 303 struct im_sge sge
[16];/* scatter gather list structure */ 304 unsigned char buf
[256];/* SCSI command return data buffer */ 305 Scsi_Cmnd
*cmd
;/* SCSI-command that is currently in progress */ 306 int device_type
;/* type of the SCSI-device. See include/scsi/scsi.h 307 for interpretation of the possible values */ 308 int block_length
;/* blocksize of a particular logical SCSI-device */ 309 int cache_flag
;/* 1 if this is uncached, 0 if cache is present for ldn */ 310 int retry_flag
;/* 1 if adapter retry is disabled, 0 if enabled */ 313 /* statistics of the driver during operations (for proc_info) */ 314 struct Driver_Statistics
{ 315 /* SCSI statistics on the adapter */ 316 int ldn_access
[MAX_LOG_DEV
+1];/* total accesses on a ldn */ 317 int ldn_read_access
[MAX_LOG_DEV
+1];/* total read-access on a ldn */ 318 int ldn_write_access
[MAX_LOG_DEV
+1];/* total write-access on a ldn */ 319 int ldn_inquiry_access
[MAX_LOG_DEV
+1];/* total inquiries on a ldn */ 320 int ldn_modeselect_access
[MAX_LOG_DEV
+1];/* total mode selects on ldn */ 321 int scbs
;/* short SCBs queued */ 322 int long_scbs
;/* long SCBs queued */ 323 int total_accesses
;/* total accesses on all ldns */ 324 int total_interrupts
;/* total interrupts (should be 325 same as total_accesses) */ 326 int total_errors
;/* command completed with error */ 327 /* dynamical assignment statistics */ 328 int total_scsi_devices
;/* number of physical pun,lun */ 329 int dyn_flag
;/* flag showing dynamical mode */ 330 int dynamical_assignments
;/* number of remappings of ldns */ 331 int ldn_assignments
[MAX_LOG_DEV
+1];/* number of remappings of each 335 /* data structure for each host adapter */ 336 struct ibmmca_hostdata
{ 337 /* array of logical devices: */ 338 struct logical_device _ld
[MAX_LOG_DEV
+1]; 339 /* array to convert (pun, lun) into logical device number: */ 340 unsigned char _get_ldn
[16][8]; 341 /*array that contains the information about the physical SCSI-devices 342 attached to this host adapter: */ 343 unsigned char _get_scsi
[16][8]; 344 /* used only when checking logical devices: */ 345 int _local_checking_phase_flag
; 346 /* report received interrupt: */ 348 /* report termination-status of SCSI-command: */ 350 /* reset status (used only when doing reset): */ 352 /* code of the last SCSI command (needed for panic info): */ 353 int _last_scsi_command
[MAX_LOG_DEV
+1]; 354 /* identifier of the last SCSI-command type */ 355 int _last_scsi_type
[MAX_LOG_DEV
+1]; 356 /* last blockcount */ 357 int _last_scsi_blockcount
[MAX_LOG_DEV
+1]; 358 /* last locgical block address */ 359 unsigned long _last_scsi_logical_block
[MAX_LOG_DEV
+1]; 360 /* Counter that points on the next reassignable ldn for dynamical 361 remapping. The default value is 7, that is the first reassignable 362 number in the list at boottime: */ 364 /* Statistics-structure for this IBM-SCSI-host: */ 365 struct Driver_Statistics _IBM_DS
; 366 /* This hostadapters pos-registers pos2 until pos6 */ 367 unsigned int _pos
[8]; 368 /* assign a special variable, that contains dedicated info about the 371 /* connector size on the MCA bus */ 373 /* synchronous SCSI transfer rate bitpattern */ 377 /* macros to access host data structure */ 378 #define subsystem_pun(hi) (hosts[(hi)]->this_id) 379 #define subsystem_maxid(hi) (hosts[(hi)]->max_id) 380 #define ld(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_ld) 381 #define get_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_ldn) 382 #define get_scsi(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_scsi) 383 #define local_checking_phase_flag(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_local_checking_phase_flag) 384 #define got_interrupt(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_got_interrupt) 385 #define stat_result(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_stat_result) 386 #define reset_status(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_reset_status) 387 #define last_scsi_command(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_command) 388 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type) 389 #define last_scsi_blockcount(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_blockcount) 390 #define last_scsi_logical_block(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_logical_block) 391 #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type) 392 #define next_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_next_ldn) 393 #define IBM_DS(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_IBM_DS) 394 #define special(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_special) 395 #define subsystem_connector_size(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_connector_size) 396 #define adapter_speed(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_adapter_speed) 397 #define pos2(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[2]) 398 #define pos3(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[3]) 399 #define pos4(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[4]) 400 #define pos5(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[5]) 401 #define pos6(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[6]) 403 /* Define a arbitrary number as subsystem-marker-type. This number is, as 404 described in the ANSI-SCSI-standard, not occupied by other device-types. */ 405 #define TYPE_IBM_SCSI_ADAPTER 0x2F 407 /* Define 0xFF for no device type, because this type is not defined within 408 the ANSI-SCSI-standard, therefore, it can be used and should not cause any 410 #define TYPE_NO_DEVICE 0xFF 412 /* define medium-changer. If this is not defined previously, e.g. Linux 413 2.0.x, define this type here. */ 414 #ifndef TYPE_MEDIUM_CHANGER 415 #define TYPE_MEDIUM_CHANGER 0x08 418 /* define possible operations for the immediate_assign command */ 422 /* ldn which is used to probe the SCSI devices */ 425 /* reset status flag contents */ 426 #define IM_RESET_NOT_IN_PROGRESS 0 427 #define IM_RESET_IN_PROGRESS 1 428 #define IM_RESET_FINISHED_OK 2 429 #define IM_RESET_FINISHED_FAIL 3 430 #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4 431 #define IM_RESET_FINISHED_OK_NO_INT 5 433 /* define undefined SCSI-command */ 434 #define NO_SCSI 0xffff 436 /*-----------------------------------------------------------------------*/ 438 /* if this is nonzero, ibmmcascsi option has been passed to the kernel */ 439 static int io_port
[IM_MAX_HOSTS
] = {0,0,0,0,0,0,0,0}; 440 static int scsi_id
[IM_MAX_HOSTS
] = {7,7,7,7,7,7,7,7}; 442 /* fill module-parameters only, when this define is present. 443 (that is kernel version 2.1.x) */ 445 static char*boot_options
= NULL
; 446 #include <linux/module.h> 447 MODULE_PARM(boot_options
,"s"); 448 MODULE_PARM(io_port
,"1-"__MODULE_STRING(IM_MAX_HOSTS
)"i"); 449 MODULE_PARM(scsi_id
,"1-"__MODULE_STRING(IM_MAX_HOSTS
)"i"); 450 MODULE_PARM(display
,"1i"); 451 MODULE_PARM(adisplay
,"1i"); 452 MODULE_PARM(normal
,"1i"); 453 MODULE_PARM(ansi
,"1i"); 455 /*counter of concurrent disk read/writes, to turn on/off disk led */ 456 static int disk_rw_in_progress
=0; 458 /* host information */ 460 static struct Scsi_Host
*hosts
[IM_MAX_HOSTS
+1] = { 461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}; 462 static unsigned int pos
[8];/* whole pos register-line for diagnosis */ 463 /* Taking into account the additions, made by ZP Gu. 464 * This selects now the preset value from the configfile and 465 * offers the 'normal' commandline option to be accepted */ 466 #ifdef CONFIG_IBMMCA_SCSI_ORDER_STANDARD 467 static char ibm_ansi_order
=1; 469 static char ibm_ansi_order
=0; 472 static voidinterrupt_handler(int,void*,struct pt_regs
*); 473 static voidissue_cmd(int,unsigned long,unsigned char); 474 static voidinternal_done(Scsi_Cmnd
* cmd
); 475 static voidcheck_devices(int,int); 476 static intimmediate_assign(int,unsigned int,unsigned int,unsigned int, 478 static intimmediate_feature(int,unsigned int,unsigned int); 479 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET 480 static intimmediate_reset(int,unsigned int); 482 static intdevice_inquiry(int,int); 483 static intread_capacity(int,int); 484 static intget_pos_info(int); 485 static char*ti_p(int); 486 static char*ti_l(int); 487 static char*ibmrate(unsigned int,int); 488 static intprobe_display(int); 489 static intprobe_bus_mode(int); 490 static intdevice_exists(int,int,int*,int*); 491 static struct Scsi_Host
*ibmmca_register(Scsi_Host_Template
*, 493 /* local functions needed for proc_info */ 494 static intldn_access_load(int,int); 495 static intldn_access_total_read_write(int); 497 static voidinterrupt_handler(int irq
,void*dev_id
,struct pt_regs
*regs
) 499 int host_index
, ihost_index
; 500 unsigned int intr_reg
; 501 unsigned int cmd_result
; 508 /* search for one adapter-response on shared interrupt */ 510 hosts
[host_index
] && !(inb(IM_STAT_REG(host_index
)) & IM_INTR_REQUEST
); 512 /* return if some other device on this IRQ caused the interrupt */ 513 if(!hosts
[host_index
]) { 518 /* the reset-function already did all the job, even ints got 519 renabled on the subsystem, so just return */ 520 if((reset_status(host_index
) == IM_RESET_NOT_IN_PROGRESS_NO_INT
)|| 521 (reset_status(host_index
) == IM_RESET_FINISHED_OK_NO_INT
)) { 522 reset_status(host_index
) = IM_RESET_NOT_IN_PROGRESS
; 527 /*must wait for attention reg not busy, then send EOI to subsystem */ 529 if(!(inb(IM_STAT_REG(host_index
)) & IM_BUSY
))break; 530 IBMUNLOCK
/* cycle interrupt */ 533 ihost_index
=host_index
; 534 /*get command result and logical device */ 535 intr_reg
= (unsigned char)(inb(IM_INTR_REG(ihost_index
))); 536 cmd_result
= intr_reg
&0xf0; 537 ldn
= intr_reg
&0x0f; 538 /* get the last_scsi_command here */ 539 lastSCSI
=last_scsi_command(ihost_index
)[ldn
]; 540 outb(IM_EOI
| ldn
,IM_ATTN_REG(ihost_index
)); 542 /*these should never happen (hw fails, or a local programming bug) */ 543 if(!global_command_error_excuse
) { 545 /* Prevent from Ooopsing on error to show the real reason */ 546 case IM_ADAPTER_HW_FAILURE
: 547 case IM_SOFTWARE_SEQUENCING_ERROR
: 549 printk("\nIBM MCA SCSI: Fatal Subsystem ERROR!\n"); 550 printk(" Last cmd=0x%x, ena=%x, len=",lastSCSI
, 551 ld(ihost_index
)[ldn
].scb
.enable
); 552 if(ld(ihost_index
)[ldn
].cmd
) 553 printk("%ld/%ld,",(long)(ld(ihost_index
)[ldn
].cmd
->request_bufflen
), 554 (long)(ld(ihost_index
)[ldn
].scb
.sys_buf_length
)); 557 if(ld(ihost_index
)[ldn
].cmd
) 558 printk("Blocksize=%d",ld(ihost_index
)[ldn
].scb
.u2
.blk
.length
); 560 printk("Blocksize=none"); 561 printk(", host=0x%x, ldn=0x%x\n",ihost_index
, ldn
); 562 if(ld(ihost_index
)[ldn
].cmd
) { 563 printk("Blockcount=%d/%d\n",last_scsi_blockcount(ihost_index
)[ldn
], 564 ld(ihost_index
)[ldn
].scb
.u2
.blk
.count
); 565 printk("Logical block=%lx/%lx\n",last_scsi_logical_block(ihost_index
)[ldn
], 566 ld(ihost_index
)[ldn
].scb
.u1
.log_blk_adr
); 568 printk("Reason given: %s\n", 569 (cmd_result
==IM_ADAPTER_HW_FAILURE
) ?"HARDWARE FAILURE": 570 (cmd_result
==IM_SOFTWARE_SEQUENCING_ERROR
) ?"SOFTWARE SEQUENCING ERROR": 571 (cmd_result
==IM_CMD_ERROR
) ?"COMMAND ERROR":"UNKNOWN"); 572 /* if errors appear, enter this section to give detailed info */ 573 printk("IBM MCA SCSI: Subsystem Error-Status follows:\n"); 574 printk(" Command Type................: %x\n", 575 last_scsi_type(ihost_index
)[ldn
]); 576 printk(" Attention Register..........: %x\n", 577 inb(IM_ATTN_REG(ihost_index
))); 578 printk(" Basic Control Register......: %x\n", 579 inb(IM_CTR_REG(ihost_index
))); 580 printk(" Interrupt Status Register...: %x\n", 582 printk(" Basic Status Register.......: %x\n", 583 inb(IM_STAT_REG(ihost_index
))); 584 if((last_scsi_type(ihost_index
)[ldn
]==IM_SCB
)|| 585 (last_scsi_type(ihost_index
)[ldn
]==IM_LONG_SCB
)) { 586 printk(" SCB-Command.................: %x\n", 587 ld(ihost_index
)[ldn
].scb
.command
); 588 printk(" SCB-Enable..................: %x\n", 589 ld(ihost_index
)[ldn
].scb
.enable
); 590 printk(" SCB-logical block address...: %lx\n", 591 ld(ihost_index
)[ldn
].scb
.u1
.log_blk_adr
); 592 printk(" SCB-system buffer address...: %lx\n", 593 ld(ihost_index
)[ldn
].scb
.sys_buf_adr
); 594 printk(" SCB-system buffer length....: %lx\n", 595 ld(ihost_index
)[ldn
].scb
.sys_buf_length
); 596 printk(" SCB-tsb address.............: %lx\n", 597 ld(ihost_index
)[ldn
].scb
.tsb_adr
); 598 printk(" SCB-Chain address...........: %lx\n", 599 ld(ihost_index
)[ldn
].scb
.scb_chain_adr
); 600 printk(" SCB-block count.............: %x\n", 601 ld(ihost_index
)[ldn
].scb
.u2
.blk
.count
); 602 printk(" SCB-block length............: %x\n", 603 ld(ihost_index
)[ldn
].scb
.u2
.blk
.length
); 605 printk(" Send this report to the maintainer.\n"); 606 panic("IBM MCA SCSI: Fatal errormessage from the subsystem (0x%X,0x%X)!\n", 607 lastSCSI
,cmd_result
); 611 /* The command error handling is made silent, but we tell the 612 * calling function, that there is a reported error from the 615 case IM_ADAPTER_HW_FAILURE
:case IM_SOFTWARE_SEQUENCING_ERROR
: 616 case IM_CMD_ERROR
: global_command_error_excuse
= CMD_FAIL
;break; 617 default: global_command_error_excuse
=0;break; 620 /* if no panic appeared, increase the interrupt-counter */ 621 IBM_DS(ihost_index
).total_interrupts
++; 622 /*only for local checking phase */ 623 if(local_checking_phase_flag(ihost_index
)) { 624 stat_result(ihost_index
) = cmd_result
; 625 got_interrupt(ihost_index
) =1; 626 reset_status(ihost_index
) = IM_RESET_FINISHED_OK
; 627 last_scsi_command(ihost_index
)[ldn
] = NO_SCSI
; 630 /* handling of commands coming from upper level of scsi driver */ 631 if(last_scsi_type(ihost_index
)[ldn
] == IM_IMM_CMD
) { 632 /* verify ldn, and may handle rare reset immediate command */ 633 if((reset_status(ihost_index
) == IM_RESET_IN_PROGRESS
)&& 634 (last_scsi_command(ihost_index
)[ldn
] == IM_RESET_IMM_CMD
)) { 635 if(cmd_result
== IM_CMD_COMPLETED_WITH_FAILURE
) { 636 disk_rw_in_progress
=0; 638 reset_status(ihost_index
) = IM_RESET_FINISHED_FAIL
; 640 /*reset disk led counter, turn off disk led */ 641 disk_rw_in_progress
=0; 643 reset_status(ihost_index
) = IM_RESET_FINISHED_OK
; 645 stat_result(ihost_index
) = cmd_result
; 646 last_scsi_command(ihost_index
)[ldn
] = NO_SCSI
; 647 last_scsi_type(ihost_index
)[ldn
] =0; 649 }else if(last_scsi_command(ihost_index
)[ldn
] == IM_ABORT_IMM_CMD
) { 650 /* react on SCSI abort command */ 651 #ifdef IM_DEBUG_PROBE 652 printk("IBM MCA SCSI: Interrupt from SCSI-abort.\n"); 654 disk_rw_in_progress
=0; 656 cmd
=ld(ihost_index
)[ldn
].cmd
; 657 ld(ihost_index
)[ldn
].cmd
= NULL
; 658 if(cmd_result
== IM_CMD_COMPLETED_WITH_FAILURE
) 659 cmd
->result
= DID_NO_CONNECT
<<16; 661 cmd
->result
= DID_ABORT
<<16; 662 stat_result(ihost_index
) = cmd_result
; 663 last_scsi_command(ihost_index
)[ldn
] = NO_SCSI
; 664 last_scsi_type(ihost_index
)[ldn
] =0; 666 (cmd
->scsi_done
)(cmd
);/* should be the internal_done */ 669 disk_rw_in_progress
=0; 671 reset_status(ihost_index
) = IM_RESET_FINISHED_OK
; 672 stat_result(ihost_index
) = cmd_result
; 673 last_scsi_command(ihost_index
)[ldn
] = NO_SCSI
; 677 last_scsi_command(ihost_index
)[ldn
] = NO_SCSI
; 678 last_scsi_type(ihost_index
)[ldn
] =0; 679 cmd
=ld(ihost_index
)[ldn
].cmd
; 680 ld(ihost_index
)[ldn
].cmd
= NULL
; 681 #ifdef IM_DEBUG_TIMEOUT 683 if((cmd
->target
== TIMEOUT_PUN
)&&(cmd
->lun
== TIMEOUT_LUN
)) { 684 printk("IBM MCA SCSI: Ignoring interrupt from pun=%x, lun=%x.\n", 685 cmd
->target
, cmd
->lun
); 690 /*if no command structure, just return, else clear cmd */ 694 printk("cmd=%02x ireg=%02x ds=%02x cs=%02x de=%02x ce=%02x\n", 695 cmd
->cmnd
[0], intr_reg
, 696 ld(ihost_index
)[ldn
].tsb
.dev_status
, 697 ld(ihost_index
)[ldn
].tsb
.cmd_status
, 698 ld(ihost_index
)[ldn
].tsb
.dev_error
, 699 ld(ihost_index
)[ldn
].tsb
.cmd_error
); 701 /*if this is end of media read/write, may turn off PS/2 disk led */ 702 if((ld(ihost_index
)[ldn
].device_type
!=TYPE_NO_LUN
)&& 703 (ld(ihost_index
)[ldn
].device_type
!=TYPE_NO_DEVICE
)) { 704 /* only access this, if there was a valid device addressed */ 705 if(--disk_rw_in_progress
==0)PS2_DISK_LED_OFF(); 708 /* IBM describes the status-mask to be 0x1e, but this is not conform 709 * with SCSI-definition, I suppose, the reason for it is that IBM 710 * adapters do not support CMD_TERMINATED, TASK_SET_FULL and 711 * ACA_ACTIVE as returning statusbyte information. (ML) */ 712 if(cmd_result
== IM_CMD_COMPLETED_WITH_FAILURE
) { 713 cmd
->result
= (unsigned char)(ld(ihost_index
)[ldn
].tsb
.dev_status
&0x1e); 714 IBM_DS(ihost_index
).total_errors
++; 717 /* write device status into cmd->result, and call done function */ 718 if(lastSCSI
== NO_SCSI
) {/* unexpected interrupt :-( */ 719 cmd
->result
|= DID_BAD_INTR
<<16; 720 printk("IBM MCA SCSI: WARNING - Interrupt from non-pending SCSI-command!\n"); 721 }else/* things went right :-) */ 722 cmd
->result
|= DID_OK
<<16; 723 if(cmd
->scsi_done
) (cmd
->scsi_done
)(cmd
); 727 static voidissue_cmd(int host_index
,unsigned long cmd_reg
, 728 unsigned char attn_reg
) 731 /* must wait for attention reg not busy */ 734 if(!(inb(IM_STAT_REG(host_index
)) & IM_BUSY
))break; 737 /* write registers and enable system interrupts */ 738 outl(cmd_reg
,IM_CMD_REG(host_index
)); 739 outb(attn_reg
,IM_ATTN_REG(host_index
)); 744 static voidinternal_done(Scsi_Cmnd
* cmd
) 750 /* SCSI-SCB-command for device_inquiry */ 751 static intdevice_inquiry(int host_index
,int ldn
) 758 scb
= &(ld(host_index
)[ldn
].scb
); 759 tsb
= &(ld(host_index
)[ldn
].tsb
); 760 buf
= (unsigned char*)(&(ld(host_index
)[ldn
].buf
)); 761 ld(host_index
)[ldn
].tsb
.dev_status
=0;/* prepare statusblock */ 762 for(retries
=0; retries
<3; retries
++) { 763 /* fill scb with inquiry command */ 764 scb
->command
= IM_DEVICE_INQUIRY_CMD
| IM_NO_DISCONNECT
; 765 scb
->enable
= IM_REPORT_TSB_ONLY_ON_ERROR
| IM_READ_CONTROL
| IM_SUPRESS_EXCEPTION_SHORT
| IM_RETRY_ENABLE
| IM_BYPASS_BUFFER
; 766 last_scsi_command(host_index
)[ldn
] = IM_DEVICE_INQUIRY_CMD
; 767 last_scsi_type(host_index
)[ldn
] = IM_SCB
; 768 scb
->sys_buf_adr
=virt_to_bus(buf
); 769 scb
->sys_buf_length
=0xff;/* maximum bufferlength gives max info */ 770 scb
->tsb_adr
=virt_to_bus(tsb
); 771 /* issue scb to passed ldn, and busy wait for interrupt */ 772 got_interrupt(host_index
) =0; 773 issue_cmd(host_index
,virt_to_bus(scb
), IM_SCB
| ldn
); 774 while(!got_interrupt(host_index
)) 777 /*if command succesful, break */ 778 if((stat_result(host_index
) == IM_SCB_CMD_COMPLETED
)|| 779 (stat_result(host_index
) == IM_SCB_CMD_COMPLETED_WITH_RETRIES
)) 782 /*if all three retries failed, return "no device at this ldn" */ 789 static intread_capacity(int host_index
,int ldn
) 796 scb
= &(ld(host_index
)[ldn
].scb
); 797 tsb
= &(ld(host_index
)[ldn
].tsb
); 798 buf
= (unsigned char*)(&(ld(host_index
)[ldn
].buf
)); 799 ld(host_index
)[ldn
].tsb
.dev_status
=0; 800 for(retries
=0; retries
<3; retries
++) { 801 /*fill scb with read capacity command */ 802 scb
->command
= IM_READ_CAPACITY_CMD
; 803 scb
->enable
= IM_REPORT_TSB_ONLY_ON_ERROR
| IM_READ_CONTROL
| IM_RETRY_ENABLE
| IM_BYPASS_BUFFER
; 804 last_scsi_command(host_index
)[ldn
] = IM_READ_CAPACITY_CMD
; 805 last_scsi_type(host_index
)[ldn
] = IM_SCB
; 806 scb
->sys_buf_adr
=virt_to_bus(buf
); 807 scb
->sys_buf_length
=8; 808 scb
->tsb_adr
=virt_to_bus(tsb
); 809 /*issue scb to passed ldn, and busy wait for interrupt */ 810 got_interrupt(host_index
) =0; 811 issue_cmd(host_index
,virt_to_bus(scb
), IM_SCB
| ldn
); 812 while(!got_interrupt(host_index
)) 815 /*if got capacity, get block length and return one device found */ 816 if((stat_result(host_index
) == IM_SCB_CMD_COMPLETED
)|| 817 (stat_result(host_index
) == IM_SCB_CMD_COMPLETED_WITH_RETRIES
)) 820 /*if all three retries failed, return "no device at this ldn" */ 827 static intget_pos_info(int host_index
) 834 scb
= &(ld(host_index
)[MAX_LOG_DEV
].scb
); 835 tsb
= &(ld(host_index
)[MAX_LOG_DEV
].tsb
); 836 buf
= (unsigned char*)(&(ld(host_index
)[MAX_LOG_DEV
].buf
)); 837 ld(host_index
)[MAX_LOG_DEV
].tsb
.dev_status
=0; 838 for(retries
=0; retries
<3; retries
++) { 839 /*fill scb with get_pos_info command */ 840 scb
->command
= IM_GET_POS_INFO_CMD
; 841 scb
->enable
= IM_READ_CONTROL
| IM_REPORT_TSB_ONLY_ON_ERROR
| IM_RETRY_ENABLE
| IM_BYPASS_BUFFER
; 842 last_scsi_command(host_index
)[MAX_LOG_DEV
] = IM_GET_POS_INFO_CMD
; 843 last_scsi_type(host_index
)[MAX_LOG_DEV
] = IM_SCB
; 844 scb
->sys_buf_adr
=virt_to_bus(buf
); 845 if(special(host_index
)==IBM_SCSI2_FW
) 846 scb
->sys_buf_length
=256;/* get all info from F/W adapter */ 848 scb
->sys_buf_length
=18;/* get exactly 18 bytes for other SCSI */ 849 scb
->tsb_adr
=virt_to_bus(tsb
); 850 /*issue scb to ldn=15, and busy wait for interrupt */ 851 got_interrupt(host_index
) =0; 852 issue_cmd(host_index
,virt_to_bus(scb
), IM_SCB
| MAX_LOG_DEV
); 853 while(!got_interrupt(host_index
)) 856 /*if got POS-stuff, get block length and return one device found */ 857 if((stat_result(host_index
) == IM_SCB_CMD_COMPLETED
)|| 858 (stat_result(host_index
) == IM_SCB_CMD_COMPLETED_WITH_RETRIES
)) 861 /* if all three retries failed, return "no device at this ldn" */ 868 /* SCSI-immediate-command for assign. This functions maps/unmaps specific 869 ldn-numbers on SCSI (PUN,LUN). It is needed for presetting of the 870 subsystem and for dynamical remapping od ldns. */ 871 static intimmediate_assign(int host_index
,unsigned int pun
, 872 unsigned int lun
,unsigned int ldn
, 873 unsigned int operation
) 876 unsigned long imm_command
; 878 for(retries
=0; retries
<3; retries
++) { 879 /* select mutation level of the SCSI-adapter */ 880 switch(special(host_index
)) { 882 imm_command
= (unsigned long)(IM_ASSIGN_IMM_CMD
); 883 imm_command
|= (unsigned long)((lun
&7) <<24); 884 imm_command
|= (unsigned long)((operation
&1) <<23); 885 imm_command
|= (unsigned long)((pun
&7)<<20)|((pun
&8)<<24); 886 imm_command
|= (unsigned long)((ldn
&15) <<16); 889 imm_command
=inl(IM_CMD_REG(host_index
)); 890 imm_command
&= (unsigned long)(0xF8000000);/* keep reserved bits */ 891 imm_command
|= (unsigned long)(IM_ASSIGN_IMM_CMD
); 892 imm_command
|= (unsigned long)((lun
&7) <<24); 893 imm_command
|= (unsigned long)((operation
&1) <<23); 894 imm_command
|= (unsigned long)((pun
&7) <<20); 895 imm_command
|= (unsigned long)((ldn
&15) <<16); 898 last_scsi_command(host_index
)[MAX_LOG_DEV
] = IM_ASSIGN_IMM_CMD
; 899 last_scsi_type(host_index
)[MAX_LOG_DEV
] = IM_IMM_CMD
; 900 got_interrupt(host_index
) =0; 901 issue_cmd(host_index
, (unsigned long)(imm_command
), IM_IMM_CMD
| MAX_LOG_DEV
); 902 while(!got_interrupt(host_index
)) 905 /*if command succesful, break */ 906 if(stat_result(host_index
) == IM_IMMEDIATE_CMD_COMPLETED
) 915 static intimmediate_feature(int host_index
,unsigned int speed
, 916 unsigned int timeout
) 919 unsigned long imm_command
; 921 for(retries
=0; retries
<3; retries
++) { 922 /* select mutation level of the SCSI-adapter */ 923 imm_command
= IM_FEATURE_CTR_IMM_CMD
; 924 imm_command
|= (unsigned long)((speed
&0x7) <<29); 925 imm_command
|= (unsigned long)((timeout
&0x1fff) <<16); 926 last_scsi_command(host_index
)[MAX_LOG_DEV
] = IM_FEATURE_CTR_IMM_CMD
; 927 last_scsi_type(host_index
)[MAX_LOG_DEV
] = IM_IMM_CMD
; 928 got_interrupt(host_index
) =0; 929 /* we need to run into command errors in order to probe for the 931 global_command_error_excuse
=1; 932 issue_cmd(host_index
, (unsigned long)(imm_command
), IM_IMM_CMD
| MAX_LOG_DEV
); 933 while(!got_interrupt(host_index
)) 935 if(global_command_error_excuse
== CMD_FAIL
) { 936 global_command_error_excuse
=0; 939 global_command_error_excuse
=0; 940 /*if command succesful, break */ 941 if(stat_result(host_index
) == IM_IMMEDIATE_CMD_COMPLETED
) 950 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET 951 static intimmediate_reset(int host_index
,unsigned int ldn
) 955 unsigned long imm_command
; 957 for(retries
=0; retries
<3; retries
++) { 958 imm_command
=inl(IM_CMD_REG(host_index
)); 959 imm_command
&= (unsigned long)(0xFFFF0000);/* keep reserved bits */ 960 imm_command
|= (unsigned long)(IM_RESET_IMM_CMD
); 961 last_scsi_command(host_index
)[ldn
] = IM_RESET_IMM_CMD
; 962 last_scsi_type(host_index
)[ldn
] = IM_IMM_CMD
; 963 got_interrupt(host_index
) =0; 964 reset_status(host_index
) = IM_RESET_IN_PROGRESS
; 965 issue_cmd(host_index
, (unsigned long)(imm_command
), IM_IMM_CMD
| ldn
); 966 ticks
= IM_RESET_DELAY
*HZ
; 967 while(reset_status(host_index
) == IM_RESET_IN_PROGRESS
&& --ticks
) { 968 udelay((1+999/HZ
)*1000); 971 /* if reset did not complete, just complain */ 973 printk("IBM MCA SCSI: reset did not complete within %d seconds.\n", 975 reset_status(host_index
) = IM_RESET_FINISHED_OK
; 976 /* did not work, finish */ 979 /*if command succesful, break */ 980 if(stat_result(host_index
) == IM_IMMEDIATE_CMD_COMPLETED
) 990 /* type-interpreter for physical device numbers */ 991 static char*ti_p(int value
) 994 case TYPE_IBM_SCSI_ADAPTER
:return("A");break; 995 case TYPE_DISK
:return("D");break; 996 case TYPE_TAPE
:return("T");break; 997 case TYPE_PROCESSOR
:return("P");break; 998 case TYPE_WORM
:return("W");break; 999 case TYPE_ROM
:return("R");break; 1000 case TYPE_SCANNER
:return("S");break; 1001 case TYPE_MOD
:return("M");break; 1002 case TYPE_MEDIUM_CHANGER
:return("C");break; 1003 case TYPE_NO_LUN
:return("+");break;/* show NO_LUN */ 1004 case TYPE_NO_DEVICE
: 1005 default:return("-");break; 1010 /* interpreter for logical device numbers (ldn) */ 1011 static char*ti_l(int value
) 1013 const char hex
[16] ="0123456789abcdef"; 1014 static char answer
[2]; 1016 answer
[1] = (char)(0x0); 1017 if(value
<=MAX_LOG_DEV
) answer
[0] = hex
[value
];else answer
[0] ='-'; 1018 return(char*)&answer
; 1021 /* transfers bitpattern of the feature command to values in MHz */ 1022 static char*ibmrate(unsigned int speed
,int i
) 1025 case0:if(i
)return"5.00";else return"10.00";break; 1026 case1:if(i
)return"4.00";else return"8.00";break; 1027 case2:if(i
)return"3.33";else return"6.66";break; 1028 case3:if(i
)return"2.86";else return"5.00";break; 1029 case4:if(i
)return"2.50";else return"4.00";break; 1030 case5:if(i
)return"2.22";else return"3.10";break; 1031 case6:if(i
)return"2.00";else return"2.50";break; 1032 case7:if(i
)return"1.82";else return"2.00";break; 1037 static intprobe_display(int what
) 1039 static int rotator
=0; 1040 const char rotor
[] ="|/-\\"; 1042 if(!(display_mode
& LED_DISP
)) 1045 outl(0x20202020,MOD95_LED_PORT
); 1046 outl(0x20202020,MOD95_LED_PORT
+4); 1048 outb('S',MOD95_LED_PORT
+7);outb('C',MOD95_LED_PORT
+6); 1049 outb('S',MOD95_LED_PORT
+5);outb('I',MOD95_LED_PORT
+4); 1050 outb('i',MOD95_LED_PORT
+3);outb('n',MOD95_LED_PORT
+2); 1051 outb('i',MOD95_LED_PORT
+1);outb((char)(rotor
[rotator
]),MOD95_LED_PORT
); 1053 if(rotator
>3) rotator
=0; 1058 static intprobe_bus_mode(int host_index
) 1060 struct im_pos_info
*info
; 1064 info
= (struct im_pos_info
*)(&(ld(host_index
)[MAX_LOG_DEV
].buf
)); 1065 if(get_pos_info(host_index
)) { 1066 if(info
->connector_size
&0xf000) 1067 subsystem_connector_size(host_index
)=16; 1069 subsystem_connector_size(host_index
)=32; 1070 num_bus
|= (info
->pos_4b
&8) >>3; 1071 for(ldn
=0; ldn
<=MAX_LOG_DEV
; ldn
++) { 1072 if((special(host_index
)==IBM_SCSI_WCACHE
)|| 1073 (special(host_index
)==IBM_7568_WCACHE
)) { 1074 if(!((info
->cache_stat
>> ldn
) &1)) 1075 ld(host_index
)[ldn
].cache_flag
=0; 1077 if(!((info
->retry_stat
>> ldn
) &1)) 1078 ld(host_index
)[ldn
].retry_flag
=0; 1080 #ifdef IM_DEBUG_PROBE 1081 printk("IBM MCA SCSI: SCSI-Cache bits: "); 1082 for(ldn
=0; ldn
<=MAX_LOG_DEV
; ldn
++) { 1083 printk("%d",ld(host_index
)[ldn
].cache_flag
); 1085 printk("\nIBM MCA SCSI: SCSI-Retry bits: "); 1086 for(ldn
=0; ldn
<=MAX_LOG_DEV
; ldn
++) { 1087 printk("%d",ld(host_index
)[ldn
].retry_flag
); 1095 /* probing scsi devices */ 1096 static voidcheck_devices(int host_index
,int adaptertype
) 1098 int id
, lun
, ldn
, ticks
; 1099 int count_devices
;/* local counter for connected device */ 1102 int speedrun
;/* local adapter_speed check variable */ 1104 /* assign default values to certain variables */ 1107 IBM_DS(host_index
).dyn_flag
=0;/* normally no need for dynamical ldn management */ 1108 IBM_DS(host_index
).total_errors
=0;/* set errorcounter to 0 */ 1109 next_ldn(host_index
) =7;/* next ldn to be assigned is 7, because 0-6 is 'hardwired'*/ 1111 /* initialize the very important driver-informational arrays/structs */ 1112 memset(ld(host_index
),0,sizeof(ld(host_index
))); 1113 for(ldn
=0; ldn
<=MAX_LOG_DEV
; ldn
++) { 1114 last_scsi_command(host_index
)[ldn
] = NO_SCSI
;/* emptify last SCSI-command storage */ 1115 last_scsi_type(host_index
)[ldn
] =0; 1116 ld(host_index
)[ldn
].cache_flag
=1; 1117 ld(host_index
)[ldn
].retry_flag
=1; 1119 memset(get_ldn(host_index
), TYPE_NO_DEVICE
,sizeof(get_ldn(host_index
)));/* this is essential ! */ 1120 memset(get_scsi(host_index
), TYPE_NO_DEVICE
,sizeof(get_scsi(host_index
)));/* this is essential ! */ 1121 for(lun
=0; lun
<8; lun
++) { 1122 /* mark the adapter at its pun on all luns*/ 1123 get_scsi(host_index
)[subsystem_pun(host_index
)][lun
] = TYPE_IBM_SCSI_ADAPTER
; 1124 get_ldn(host_index
)[subsystem_pun(host_index
)][lun
] = MAX_LOG_DEV
;/* make sure, the subsystem 1125 ldn is active for all 1128 probe_display(0);/* Supercool display usage during SCSI-probing. */ 1129 /* This makes sense, when booting without any */ 1130 /* monitor connected on model XX95. */ 1133 adapter_speed(host_index
) = global_adapter_speed
; 1134 speedrun
=adapter_speed(host_index
); 1135 while(immediate_feature(host_index
,speedrun
,adapter_timeout
)==2) { 1138 panic("IBM MCA SCSI: Cannot set Synchronous-Transfer-Rate!\n"); 1143 adapter_speed(host_index
) = speedrun
; 1144 /* Get detailed information about the current adapter, necessary for 1145 * device operations: */ 1146 num_bus
=probe_bus_mode(host_index
); 1148 /* num_bus contains only valid data for the F/W adapter! */ 1149 if(adaptertype
==IBM_SCSI2_FW
) {/* F/W SCSI adapter: */ 1150 /* F/W adapter PUN-space extension evaluation: */ 1152 printk("IBM MCA SCSI: Seperate bus mode (wide-addressing enabled)\n"); 1153 subsystem_maxid(host_index
) =16; 1155 printk("IBM MCA SCSI: Combined bus mode (wide-addressing disabled)\n"); 1156 subsystem_maxid(host_index
) =8; 1158 printk("IBM MCA SCSI: Sync.-Rate (F/W: 20, Int.: 10, Ext.: %s) MBytes/s\n", 1159 ibmrate(speedrun
,adaptertype
)); 1160 }else/* all other IBM SCSI adapters: */ 1161 printk("IBM MCA SCSI: Synchronous-SCSI-Transfer-Rate: %s MBytes/s\n", 1162 ibmrate(speedrun
,adaptertype
)); 1164 /* assign correct PUN device space */ 1165 max_pun
=subsystem_maxid(host_index
); 1167 #ifdef IM_DEBUG_PROBE 1168 printk("IBM MCA SCSI: Current SCSI-host index: %d\n",host_index
); 1169 printk("IBM MCA SCSI: Removing default logical SCSI-device mapping."); 1171 printk("IBM MCA SCSI: Dev. Order: %s, Mapping (takes <2min): ", 1172 (ibm_ansi_order
) ?"ANSI":"New"); 1174 for(ldn
=0; ldn
<MAX_LOG_DEV
; ldn
++) { 1176 #ifdef IM_DEBUG_PROBE 1179 immediate_assign(host_index
,0,0,ldn
,REMOVE_LDN
);/* remove ldn (wherever)*/ 1181 lun
=0;/* default lun is 0 */ 1182 #ifndef IM_DEBUG_PROBE 1186 #ifdef IM_DEBUG_PROBE 1187 printk("\nIBM MCA SCSI: Scanning SCSI-devices."); 1189 for(id
=0; id
<max_pun
; id
++) 1190 #ifdef CONFIG_SCSI_MULTI_LUN 1191 for(lun
=0; lun
<8; lun
++) 1195 #ifdef IM_DEBUG_PROBE 1198 if(id
!=subsystem_pun(host_index
)) { 1199 /* if pun is not the adapter: */ 1200 /* set ldn=0 to pun,lun*/ 1201 immediate_assign(host_index
,id
,lun
,PROBE_LDN
,SET_LDN
); 1202 if(device_inquiry(host_index
, PROBE_LDN
)) {/* probe device */ 1203 get_scsi(host_index
)[id
][lun
]= 1204 (unsigned char)(ld(host_index
)[PROBE_LDN
].buf
[0]); 1205 /* entry, even for NO_LUN */ 1206 if(ld(host_index
)[PROBE_LDN
].buf
[0] != TYPE_NO_LUN
) 1207 count_devices
++;/* a existing device is found */ 1210 immediate_assign(host_index
,id
,lun
,PROBE_LDN
,REMOVE_LDN
); 1213 #ifndef IM_DEBUG_PROBE 1217 #ifdef IM_DEBUG_PROBE 1218 printk("\nIBM MCA SCSI: Mapping SCSI-devices."); 1222 #ifdef CONFIG_SCSI_MULTI_LUN 1223 for(lun
=0; lun
<8&& ldn
<MAX_LOG_DEV
; lun
++) 1225 for(id
=0; id
<max_pun
&& ldn
<MAX_LOG_DEV
; id
++) { 1227 #ifdef IM_DEBUG_PROBE 1230 if(id
!=subsystem_pun(host_index
)) { 1231 if(get_scsi(host_index
)[id
][lun
] != TYPE_NO_LUN
&& 1232 get_scsi(host_index
)[id
][lun
] != TYPE_NO_DEVICE
) { 1233 /* Only map if accepted type. Always enter for 1234 lun == 0 to get no gaps into ldn-mapping for ldn<7. */ 1235 immediate_assign(host_index
,id
,lun
,ldn
,SET_LDN
); 1236 get_ldn(host_index
)[id
][lun
]=ldn
;/* map ldn */ 1237 if(device_exists(host_index
, ldn
, 1238 &ld(host_index
)[ldn
].block_length
, 1239 &ld(host_index
)[ldn
].device_type
)) { 1240 #ifdef CONFIG_IBMMCA_SCSI_DEV_RESET 1241 printk("resetting device at ldn=%x ... ",ldn
); 1242 immediate_reset(host_index
,ldn
); 1246 /* device vanished, probably because we don't know how to 1247 * handle it or because it has problems */ 1249 /* remove mapping */ 1250 get_ldn(host_index
)[id
][lun
]=TYPE_NO_DEVICE
; 1251 immediate_assign(host_index
,0,0,ldn
,REMOVE_LDN
); 1255 /* map lun == 0, even if no device exists */ 1256 immediate_assign(host_index
,id
,lun
,ldn
,SET_LDN
); 1257 get_ldn(host_index
)[id
][lun
]=ldn
;/* map ldn */ 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
++) { 1267 if(get_scsi(host_index
)[id
][lun
] == TYPE_NO_LUN
|| 1268 get_scsi(host_index
)[id
][lun
] == TYPE_NO_DEVICE
) { 1270 /* Map remaining ldns only to NON-existing pun,lun 1271 combinations to make sure an inquiry will fail. 1272 For MULTI_LUN, it is needed to avoid adapter autonome 1274 immediate_assign(host_index
,id
,lun
,ldn
,SET_LDN
); 1275 get_ldn(host_index
)[id
][lun
]=ldn
; 1279 #ifndef IM_DEBUG_PROBE 1283 #ifdef IM_DEBUG_PROBE 1285 printk("IBM MCA SCSI: Device order: IBM/ANSI (pun=7 is first).\n"); 1287 printk("IBM MCA SCSI: Device order: New Industry Standard (pun=0 is first).\n"); 1290 #ifdef IM_DEBUG_PROBE 1291 /* Show the physical and logical mapping during boot. */ 1292 printk("IBM MCA SCSI: Determined SCSI-device-mapping:\n"); 1293 printk(" Physical SCSI-Device Map Logical SCSI-Device Map\n"); 1294 printk("ID\\LUN 0 1 2 3 4 5 6 7 ID\\LUN 0 1 2 3 4 5 6 7\n"); 1295 for(id
=0; id
<max_pun
; id
++) { 1297 for(lun
=0; lun
<8; lun
++) 1298 printk("%2s ",ti_p(get_scsi(host_index
)[id
][lun
])); 1300 for(lun
=0; lun
<8; lun
++) 1301 printk("%2s ",ti_l(get_ldn(host_index
)[id
][lun
])); 1306 /* assign total number of found SCSI-devices to the statistics struct */ 1307 IBM_DS(host_index
).total_scsi_devices
= count_devices
; 1309 /* decide for output in /proc-filesystem, if the configuration of 1310 SCSI-devices makes dynamical reassignment of devices necessary */ 1311 if(count_devices
>=MAX_LOG_DEV
) 1312 IBM_DS(host_index
).dyn_flag
=1;/* dynamical assignment is necessary */ 1314 IBM_DS(host_index
).dyn_flag
=0;/* dynamical assignment is not necessary */ 1316 /* If no SCSI-devices are assigned, return 1 in order to cause message. */ 1318 printk("IBM MCA SCSI: Warning: No SCSI-devices found/assigned!\n"); 1320 /* reset the counters for statistics on the current adapter */ 1321 IBM_DS(host_index
).scbs
=0; 1322 IBM_DS(host_index
).long_scbs
=0; 1323 IBM_DS(host_index
).total_accesses
=0; 1324 IBM_DS(host_index
).total_interrupts
=0; 1325 IBM_DS(host_index
).dynamical_assignments
=0; 1326 memset(IBM_DS(host_index
).ldn_access
,0x0, 1327 sizeof(IBM_DS(host_index
).ldn_access
)); 1328 memset(IBM_DS(host_index
).ldn_read_access
,0x0, 1329 sizeof(IBM_DS(host_index
).ldn_read_access
)); 1330 memset(IBM_DS(host_index
).ldn_write_access
,0x0, 1331 sizeof(IBM_DS(host_index
).ldn_write_access
)); 1332 memset(IBM_DS(host_index
).ldn_inquiry_access
,0x0, 1333 sizeof(IBM_DS(host_index
).ldn_inquiry_access
)); 1334 memset(IBM_DS(host_index
).ldn_modeselect_access
,0x0, 1335 sizeof(IBM_DS(host_index
).ldn_modeselect_access
)); 1336 memset(IBM_DS(host_index
).ldn_assignments
,0x0, 1337 sizeof(IBM_DS(host_index
).ldn_assignments
)); 1342 static intdevice_exists(int host_index
,int ldn
,int*block_length
, 1346 /* if no valid device found, return immediately with 0 */ 1347 if(!(device_inquiry(host_index
, ldn
))) 1349 buf
= (unsigned char*)(&(ld(host_index
)[ldn
].buf
)); 1350 if(*buf
== TYPE_ROM
) { 1351 *device_type
= TYPE_ROM
; 1352 *block_length
=2048;/* (standard blocksize for yellow-/red-book) */ 1355 if(*buf
== TYPE_WORM
) { 1356 *device_type
= TYPE_WORM
; 1357 *block_length
=2048; 1360 if(*buf
== TYPE_DISK
) { 1361 *device_type
= TYPE_DISK
; 1362 if(read_capacity( host_index
, ldn
)) { 1363 *block_length
= *(buf
+7) + (*(buf
+6) <<8) + 1364 (*(buf
+5) <<16) + (*(buf
+4) <<24); 1369 if(*buf
== TYPE_MOD
) { 1370 *device_type
= TYPE_MOD
; 1371 if(read_capacity( host_index
, ldn
)) { 1372 *block_length
= *(buf
+7) + (*(buf
+6) <<8) + 1373 (*(buf
+5) <<16) + (*(buf
+4) <<24); 1378 if(*buf
== TYPE_TAPE
) { 1379 *device_type
= TYPE_TAPE
; 1380 *block_length
=0;/* not in use (setting by mt and mtst in op.) */ 1383 if(*buf
== TYPE_PROCESSOR
) { 1384 *device_type
= TYPE_PROCESSOR
; 1385 *block_length
=0;/* they set their stuff on drivers */ 1388 if(*buf
== TYPE_SCANNER
) { 1389 *device_type
= TYPE_SCANNER
; 1390 *block_length
=0;/* they set their stuff on drivers */ 1393 if(*buf
== TYPE_MEDIUM_CHANGER
) { 1394 *device_type
= TYPE_MEDIUM_CHANGER
; 1395 *block_length
=0;/* One never knows, what to expect on a medium 1402 #ifdef CONFIG_SCSI_IBMMCA 1403 voidinternal_ibmmca_scsi_setup(char*str
,int*ints
) 1405 int i
, j
, io_base
, id_base
; 1411 token
=strtok(str
,","); 1414 if(!strcmp(token
,"activity")) display_mode
|= LED_ACTIVITY
; 1415 if(!strcmp(token
,"display")) display_mode
|= LED_DISP
; 1416 if(!strcmp(token
,"adisplay")) display_mode
|= LED_ADISP
; 1417 if(!strcmp(token
,"normal")) ibm_ansi_order
=0; 1418 if(!strcmp(token
,"ansi")) ibm_ansi_order
=1; 1419 if(!strcmp(token
,"fast")) global_adapter_speed
=0; 1420 if(!strcmp(token
,"medium")) global_adapter_speed
=4; 1421 if(!strcmp(token
,"slow")) global_adapter_speed
=7; 1422 if((*token
=='-') || (isdigit(*token
))) { 1423 if(!(j
%2) && (io_base
< IM_MAX_HOSTS
)) 1424 io_port
[io_base
++] =simple_strtoul(token
,NULL
,0); 1425 if((j
%2) && (id_base
< IM_MAX_HOSTS
)) 1426 scsi_id
[id_base
++] =simple_strtoul(token
,NULL
,0); 1429 token
=strtok(NULL
,","); 1432 for(i
=0; i
< IM_MAX_HOSTS
&&2*i
+2< ints
[0]; i
++) { 1433 io_port
[i
] = ints
[2*i
+2]; 1434 scsi_id
[i
] = ints
[2*i
+2]; 1441 static intibmmca_getinfo(char*buf
,int slot
,void*dev
) 1443 struct Scsi_Host
*shpnt
; 1444 int len
, speciale
, connectore
, k
; 1445 unsigned int pos
[8]; 1446 unsigned long flags
; 1449 shpnt
= dev
;/* assign host-structure to local pointer */ 1450 len
=0;/* set filled text-buffer index to 0 */ 1451 /* get the _special contents of the hostdata structure */ 1452 speciale
= ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_special
; 1453 connectore
= ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_connector_size
; 1455 pos
[k
] = ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_pos
[k
]; 1456 if(speciale
== FORCED_DETECTION
) {/* forced detection */ 1457 len
+=sprintf(buf
+len
, 1458 "Adapter category: forced detected\n" 1459 "***************************************\n" 1460 "*** Forced detected SCSI Adapter ***\n" 1461 "*** No chip-information available ***\n" 1462 "***************************************\n"); 1463 }else if(speciale
== INTEGRATED_SCSI
) { 1464 /* if the integrated subsystem has been found automatically: */ 1465 len
+=sprintf(buf
+len
, 1466 "Adapter category: integrated\n" 1467 "Chip revision level: %d\n" 1469 "8 kByte NVRAM status: %s\n", 1470 ((pos
[2] &0xf0) >>4), 1471 (pos
[2] &1) ?"enabled":"disabled", 1472 (pos
[2] &2) ?"locked":"accessible"); 1473 }else if((speciale
>=0)&& 1474 (speciale
<(sizeof(subsys_list
)/sizeof(struct subsys_list_struct
)))) { 1475 /* if the subsystem is a slot adapter */ 1476 len
+=sprintf(buf
+len
, 1477 "Adapter category: slot-card\n" 1478 "ROM Segment Address: "); 1479 if((pos
[2] &0xf0) ==0xf0) 1480 len
+=sprintf(buf
+len
,"off\n"); 1482 len
+=sprintf(buf
+len
,"0x%x\n", 1483 ((pos
[2] &0xf0) <<13) +0xc0000); 1484 len
+=sprintf(buf
+ len
,"Chip status: %s\n", 1485 (pos
[2] &1) ?"enabled":"disabled"); 1486 len
+=sprintf(buf
+ len
,"Adapter I/O Offset: 0x%x\n", 1487 ((pos
[2] &0x0e) <<2)); 1489 len
+=sprintf(buf
+ len
,"Adapter category: unknown\n"); 1491 /* common subsystem information to write to the slotn file */ 1492 len
+=sprintf(buf
+ len
,"Subsystem PUN: %d\n", shpnt
->this_id
); 1493 len
+=sprintf(buf
+ len
,"I/O base address range: 0x%x-0x%x\n", 1494 (unsigned int)(shpnt
->io_port
), 1495 (unsigned int)(shpnt
->io_port
+7)); 1496 len
+=sprintf(buf
+ len
,"MCA-slot size: %d bits",connectore
); 1497 /* Now make sure, the bufferlength is devidable by 4 to avoid 1498 * paging problems of the buffer. */ 1499 while( len
%sizeof(int) != (sizeof(int) -1) ) 1500 len
+=sprintf(buf
+len
," "); 1501 len
+=sprintf(buf
+len
,"\n"); 1506 intibmmca_detect(Scsi_Host_Template
* scsi_template
) 1508 struct Scsi_Host
*shpnt
; 1509 int port
, id
, i
, j
, k
, list_size
, slot
; 1510 int devices_on_irq_11
=0; 1511 int devices_on_irq_14
=0; 1512 int IRQ14_registered
=0; 1513 int IRQ11_registered
=0; 1515 found
=0;/* make absolutely sure, that found is set to 0 */ 1517 /* First of all, print the version number of the driver. This is 1518 * important to allow better user bugreports in case of already 1519 * having problems with the MCA_bus probing. */ 1520 printk("IBM MCA SCSI: Version %s\n",IBMMCA_SCSI_DRIVER_VERSION
); 1521 /* if this is not MCA machine, return "nothing found" */ 1523 printk("IBM MCA SCSI: No Microchannel-bus present --> Aborting.\n" 1524 " This machine does not have any IBM MCA-bus\n" 1525 " or the MCA-Kernel-support is not enabled!\n"); 1530 /* If the driver is run as module, read from conf.modules or cmd-line */ 1531 if(boot_options
)option_setup(boot_options
); 1534 /* get interrupt request level */ 1535 if(request_irq(IM_IRQ
, interrupt_handler
, SA_SHIRQ
,"ibmmcascsi", 1537 printk("IBM MCA SCSI: Unable to get shared IRQ %d.\n", IM_IRQ
); 1542 /* if ibmmcascsi setup option was passed to kernel, return "found" */ 1543 for(i
=0; i
< IM_MAX_HOSTS
; i
++) 1544 if(io_port
[i
] >0&& scsi_id
[i
] >=0&& scsi_id
[i
] <8) { 1545 printk("IBM MCA SCSI: forced detected SCSI Adapter, io=0x%x, scsi id=%d.\n", 1546 io_port
[i
], scsi_id
[i
]); 1547 if((shpnt
=ibmmca_register(scsi_template
, io_port
[i
], scsi_id
[i
], 1548 FORCED_DETECTION
,"forced detected SCSI Adapter"))) { 1550 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_pos
[k
] =0; 1551 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_special
= FORCED_DETECTION
; 1552 mca_set_adapter_name(MCA_INTEGSCSI
,"forced detected SCSI Adapter"); 1553 mca_set_adapter_procfn(MCA_INTEGSCSI
, (MCA_ProcFn
) ibmmca_getinfo
, 1555 mca_mark_as_used(MCA_INTEGSCSI
); 1556 devices_on_irq_14
++; 1559 if(found
)return found
; 1561 /* The POS2-register of all PS/2 model SCSI-subsystems has the following 1562 * interpretation of bits: 1563 * Bit 7 - 4 : Chip Revision ID (Release) 1564 * Bit 3 - 2 : Reserved 1565 * Bit 1 : 8k NVRAM Disabled 1566 * Bit 0 : Chip Enable (EN-Signal) 1567 * The POS3-register is interpreted as follows: 1568 * Bit 7 - 5 : SCSI ID 1569 * Bit 4 : Reserved = 0 1570 * Bit 3 - 0 : Reserved = 0 1571 * (taken from "IBM, PS/2 Hardware Interface Technical Reference, Common 1572 * Interfaces (1991)"). 1573 * In short words, this means, that IBM PS/2 machines only support 1574 * 1 single subsystem by default. The slot-adapters must have another 1575 * configuration on pos2. Here, one has to assume the following 1576 * things for POS2-register: 1577 * Bit 7 - 4 : Chip Revision ID (Release) 1578 * Bit 3 - 1 : port offset factor 1579 * Bit 0 : Chip Enable (EN-Signal) 1580 * As I found a patch here, setting the IO-registers to 0x3540 forced, 1581 * as there was a 0x05 in POS2 on a model 56, I assume, that the 1582 * port 0x3540 must be fix for integrated SCSI-controllers. 1583 * Ok, this discovery leads to the following implementation: (M.Lang) */ 1585 /* first look for the IBM SCSI integrated subsystem on the motherboard */ 1586 for(j
=0;j
<8;j
++)/* read the pos-information */ 1587 pos
[j
] =mca_read_stored_pos(MCA_INTEGSCSI
,j
); 1588 /* pos2 = pos3 = 0xff if there is no integrated SCSI-subsystem present, but 1589 * if we ignore the settings of all surrounding pos registers, it is not 1590 * completely sufficient to only check pos2 and pos3. */ 1591 /* Therefore, now the following if statement is used to 1592 * make sure, we see a real integrated onboard SCSI-interface and no 1593 * internal system information, which gets mapped to some pos registers 1594 * on models 95xx. */ 1595 if((!pos
[0] && !pos
[1] && pos
[2]>0&& pos
[3]>0&& !pos
[4] && !pos
[5] && !pos
[6] && !pos
[7]) || 1596 (pos
[0]==0xff&& pos
[1]==0xff&& pos
[2]<0xff&& pos
[3]<0xff&& pos
[4]==0xff&& pos
[5]==0xff&& pos
[6]==0xff&& pos
[7]==0xff)) { 1597 if((pos
[2] &1) ==1)/* is the subsystem chip enabled ? */ 1599 else{/* if disabled, no IRQs will be generated, as the chip won't 1600 * listen to the incomming commands and will do really nothing, 1601 * except for listening to the pos-register settings. If this 1602 * happens, I need to hugely think about it, as one has to 1603 * write something to the MCA-Bus pos register in order to 1604 * enable the chip. Normally, IBM-SCSI won't pass the POST, 1605 * when the chip is disabled (see IBM tech. ref.). */ 1606 port
= IM_IO_PORT
;/* anyway, set the portnumber and warn */ 1607 printk("IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n" 1608 " SCSI-operations may not work.\n"); 1610 id
= (pos
[3] &0xe0) >>5;/* this is correct and represents the PUN */ 1611 /* give detailed information on the subsystem. This helps me 1612 * additionally during debugging and analyzing bug-reports. */ 1613 printk("IBM MCA SCSI: IBM Integrated SCSI Controller found, io=0x%x, scsi id=%d,\n" 1614 " chip rev.=%d, 8K NVRAM=%s, subsystem=%s\n", 1616 ((pos
[2] &0xf0) >>4), (pos
[2] &2) ?"locked":"accessible", 1617 (pos
[2] &1) ?"enabled.":"disabled."); 1619 /* register the found integrated SCSI-subsystem */ 1620 if((shpnt
=ibmmca_register(scsi_template
, port
, id
, INTEGRATED_SCSI
, 1621 "IBM Integrated SCSI Controller"))) { 1623 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_pos
[k
] = pos
[k
]; 1624 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_special
= INTEGRATED_SCSI
; 1625 mca_set_adapter_name(MCA_INTEGSCSI
,"IBM Integrated SCSI Controller"); 1626 mca_set_adapter_procfn(MCA_INTEGSCSI
, (MCA_ProcFn
) ibmmca_getinfo
, 1628 mca_mark_as_used(MCA_INTEGSCSI
); 1629 devices_on_irq_14
++; 1633 /* now look for other adapters in MCA slots, */ 1634 /* determine the number of known IBM-SCSI-subsystem types */ 1635 /* see the pos[2] dependence to get the adapter port-offset. */ 1636 list_size
=sizeof(subsys_list
) /sizeof(struct subsys_list_struct
); 1637 for(i
=0; i
< list_size
; i
++) { 1638 /* scan each slot for a fitting adapter id */ 1639 slot
=0;/* start at slot 0 */ 1640 while((slot
=mca_find_adapter(subsys_list
[i
].mca_id
, slot
)) 1641 != MCA_NOTFOUND
) {/* scan through all slots */ 1642 for(j
=0;j
<8;j
++)/* read the pos-information */ 1643 pos
[j
] =mca_read_stored_pos(slot
, j
); 1644 if((pos
[2] &1) ==1)/* is the subsystem chip enabled ? */ 1645 /* (explanations see above) */ 1646 port
= IM_IO_PORT
+ ((pos
[2] &0x0e) <<2); 1648 /* anyway, set the portnumber and warn */ 1649 port
= IM_IO_PORT
+ ((pos
[2] &0x0e) <<2); 1650 printk("IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n" 1651 " SCSI-operations may not work.\n"); 1653 if((i
==IBM_SCSI2_FW
)&&(pos
[6]!=0)) { 1654 printk("IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n" 1655 " Impossible to determine adapter PUN!\n" 1656 " Guessing adapter PUN = 7.\n"); 1659 id
= (pos
[3] &0xe0) >>5;/* get subsystem PUN */ 1660 if(i
==IBM_SCSI2_FW
) { 1661 id
|= (pos
[3] &0x10) >>1;/* get subsystem PUN high-bit 1662 * for F/W adapters */ 1665 if((i
==IBM_SCSI2_FW
)&&(pos
[4] &0x01)&&(pos
[6]==0)) { 1666 /* IRQ11 is used by SCSI-2 F/W Adapter/A */ 1667 printk("IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n"); 1668 /* get interrupt request level */ 1669 if(request_irq(IM_IRQ_FW
, interrupt_handler
, SA_SHIRQ
, 1670 "ibmmcascsi", hosts
)) { 1671 printk("IBM MCA SCSI: Unable to get shared IRQ %d.\n", 1676 printk("IBM MCA SCSI: %s found in slot %d, io=0x%x, scsi id=%d,\n", 1677 subsys_list
[i
].description
, slot
+1, port
, id
); 1678 if((pos
[2] &0xf0) ==0xf0) 1679 printk(" ROM Addr.=off,"); 1681 printk(" ROM Addr.=0x%x,", 1682 ((pos
[2] &0xf0) <<13) +0xc0000); 1683 printk(" port-offset=0x%x, subsystem=%s\n", 1684 ((pos
[2] &0x0e) <<2), 1685 (pos
[2] &1) ?"enabled.":"disabled."); 1687 /* register the hostadapter */ 1688 if((shpnt
=ibmmca_register(scsi_template
, port
, id
, i
, 1689 subsys_list
[i
].description
))) { 1691 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_pos
[k
] = pos
[k
]; 1692 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_special
= i
; 1693 mca_set_adapter_name(slot
, subsys_list
[i
].description
); 1694 mca_set_adapter_procfn(slot
, (MCA_ProcFn
) ibmmca_getinfo
, 1696 mca_mark_as_used(slot
); 1697 if((i
==IBM_SCSI2_FW
)&&(pos
[4] &0x01)&&(pos
[6]==0)) 1698 devices_on_irq_11
++; 1700 devices_on_irq_14
++; 1702 slot
++;/* advance to next slot */ 1703 }/* advance to next adapter id in the list of IBM-SCSI-subsystems*/ 1706 /* now check for SCSI-adapters, mapped to the integrated SCSI 1707 * area. E.g. a W/Cache in MCA-slot 9(!). Do the check correct here, 1708 * as this is a known effect on some models 95xx. */ 1709 list_size
=sizeof(subsys_list
) /sizeof(struct subsys_list_struct
); 1710 for(i
=0; i
< list_size
; i
++) { 1711 /* scan each slot for a fitting adapter id */ 1712 slot
=mca_find_adapter(subsys_list
[i
].mca_id
, MCA_INTEGSCSI
); 1713 if(slot
!= MCA_NOTFOUND
) {/* scan through all slots */ 1714 for(j
=0;j
<8;j
++)/* read the pos-information */ 1715 pos
[j
] =mca_read_stored_pos(slot
, j
); 1716 if((pos
[2] &1) ==1) {/* is the subsystem chip enabled ? */ 1717 /* (explanations see above) */ 1718 port
= IM_IO_PORT
+ ((pos
[2] &0x0e) <<2); 1719 }else{/* anyway, set the portnumber and warn */ 1720 port
= IM_IO_PORT
+ ((pos
[2] &0x0e) <<2); 1721 printk("IBM MCA SCSI: WARNING - Your SCSI-subsystem is disabled!\n" 1722 " SCSI-operations may not work.\n"); 1724 if((i
==IBM_SCSI2_FW
)&&(pos
[6]!=0)) { 1725 printk("IBM MCA SCSI: ERROR - Wrong POS(6)-register setting!\n" 1726 " Impossible to determine adapter PUN!\n" 1727 " Guessing adapter PUN = 7.\n"); 1730 id
= (pos
[3] &0xe0) >>5;/* get subsystem PUN */ 1732 id
|= (pos
[3] &0x10) >>1;/* get subsystem PUN high-bit 1733 * for F/W adapters */ 1735 if((i
==IBM_SCSI2_FW
)&&(pos
[4] &0x01)&&(pos
[6]==0)) { 1736 /* IRQ11 is used by SCSI-2 F/W Adapter/A */ 1737 printk("IBM MCA SCSI: SCSI-2 F/W adapter needs IRQ 11.\n"); 1738 /* get interrupt request level */ 1739 if(request_irq(IM_IRQ_FW
, interrupt_handler
, SA_SHIRQ
, 1740 "ibmmcascsi", hosts
)) 1741 printk("IBM MCA SCSI: Unable to get shared IRQ %d.\n", 1746 printk("IBM MCA SCSI: %s found in slot %d, io=0x%x, scsi id=%d,\n", 1747 subsys_list
[i
].description
, slot
+1, port
, id
); 1748 if((pos
[2] &0xf0) ==0xf0) 1749 printk(" ROM Addr.=off,"); 1751 printk(" ROM Addr.=0x%x,", 1752 ((pos
[2] &0xf0) <<13) +0xc0000); 1753 printk(" port-offset=0x%x, subsystem=%s\n", 1754 ((pos
[2] &0x0e) <<2), 1755 (pos
[2] &1) ?"enabled.":"disabled."); 1757 /* register the hostadapter */ 1758 if((shpnt
=ibmmca_register(scsi_template
, port
, id
, i
, 1759 subsys_list
[i
].description
))) { 1761 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_pos
[k
] = pos
[k
]; 1762 ((struct ibmmca_hostdata
*)shpnt
->hostdata
)->_special
= i
; 1763 mca_set_adapter_name(slot
, subsys_list
[i
].description
); 1764 mca_set_adapter_procfn(slot
, (MCA_ProcFn
) ibmmca_getinfo
, shpnt
); 1765 mca_mark_as_used(slot
); 1766 if((i
==IBM_SCSI2_FW
)&&(pos
[4] &0x01)&&(pos
[6]==0)) 1767 devices_on_irq_11
++; 1769 devices_on_irq_14
++; 1771 slot
++;/* advance to next slot */ 1772 }/* advance to next adapter id in the list of IBM-SCSI-subsystems*/ 1774 if( IRQ11_registered
&& !devices_on_irq_11
) 1775 free_irq(IM_IRQ_FW
, hosts
);/* no devices on IRQ 11 */ 1776 if( IRQ14_registered
&& !devices_on_irq_14
) 1777 free_irq(IM_IRQ
, hosts
);/* no devices on IRQ 14 */ 1778 if( !devices_on_irq_11
&& !devices_on_irq_14
) 1779 printk("IBM MCA SCSI: No IBM SCSI-subsystem adapter attached.\n"); 1780 return found
;/* return the number of found SCSI hosts. Should be 1 or 0. */ 1783 static struct Scsi_Host
* 1784 ibmmca_register(Scsi_Host_Template
* scsi_template
,int port
,int id
, 1785 int adaptertype
,char*hostname
) 1787 struct Scsi_Host
*shpnt
; 1791 /* check I/O region */ 1792 if(check_region(port
, IM_N_IO_PORT
)) { 1793 printk("IBM MCA SCSI: Unable to get I/O region 0x%x-0x%x (%d ports).\n", 1794 port
, port
+ IM_N_IO_PORT
-1, IM_N_IO_PORT
); 1799 shpnt
=scsi_register(scsi_template
,sizeof(struct ibmmca_hostdata
)); 1801 printk("IBM MCA SCSI: Unable to register host.\n"); 1805 /* request I/O region */ 1806 request_region(port
, IM_N_IO_PORT
, hostname
); 1807 hosts
[found
] = shpnt
;/* add new found hostadapter to the list */ 1808 special(found
) = adaptertype
;/* important assignment or else crash! */ 1809 subsystem_connector_size(found
) =0;/* preset slot-size */ 1810 shpnt
->irq
= IM_IRQ
;/* assign necessary stuff for the adapter */ 1811 shpnt
->io_port
= port
; 1812 shpnt
->n_io_port
= IM_N_IO_PORT
; 1813 shpnt
->this_id
= id
; 1814 shpnt
->max_id
=8;/* 8 PUNs are default */ 1815 /* now, the SCSI-subsystem is connected to Linux */ 1817 ctrl
= (unsigned int)(inb(IM_CTR_REG(found
)));/* get control-register status */ 1818 #ifdef IM_DEBUG_PROBE 1819 printk("IBM MCA SCSI: Control Register contents: %x, status: %x\n", 1820 ctrl
,inb(IM_STAT_REG(found
))); 1821 printk("IBM MCA SCSI: This adapters' POS-registers: "); 1823 printk("%x ",pos
[i
]); 1826 reset_status(found
) = IM_RESET_NOT_IN_PROGRESS
; 1828 for(i
=0; i
<16; i
++)/* reset the tables */ 1829 for(j
=0; j
<8; j
++) 1830 get_ldn(found
)[i
][j
] = MAX_LOG_DEV
; 1832 /* check which logical devices exist */ 1833 /* after this line, local interrupting is possible: */ 1834 local_checking_phase_flag(found
) =1; 1835 check_devices(found
,adaptertype
);/* call by value, using the global variable hosts*/ 1836 local_checking_phase_flag(found
) =0; 1837 found
++;/* now increase index to be prepared for next found subsystem */ 1838 /* an ibm mca subsystem has been detected */ 1842 intibmmca_command(Scsi_Cmnd
* cmd
) 1844 ibmmca_queuecommand(cmd
, internal_done
); 1846 while(!cmd
->SCp
.Status
)barrier(); 1850 intibmmca_release(struct Scsi_Host
*shpnt
) 1852 release_region(shpnt
->io_port
, shpnt
->n_io_port
); 1853 if(!(--found
))free_irq(shpnt
->irq
, hosts
); 1857 /* The following routine is the SCSI command queue for the midlevel driver */ 1858 intibmmca_queuecommand(Scsi_Cmnd
* cmd
,void(*done
) (Scsi_Cmnd
*)) 1861 unsigned int scsi_cmd
; 1863 struct Scsi_Host
*shpnt
; 1870 struct scatterlist
*sl
; 1873 /* search for the right hostadapter */ 1874 for(host_index
=0; hosts
[host_index
] && hosts
[host_index
]->host_no
!= shpnt
->host_no
; host_index
++); 1876 if(!hosts
[host_index
]) {/* invalid hostadapter descriptor address */ 1877 cmd
->result
= DID_NO_CONNECT
<<16; 1881 max_pun
=subsystem_maxid(host_index
); 1882 if(ibm_ansi_order
) { 1883 target
= max_pun
-1- cmd
->target
; 1884 if((target
<=subsystem_pun(host_index
))&&(cmd
->target
<=subsystem_pun(host_index
))) 1886 else if((target
>=subsystem_pun(host_index
))&&(cmd
->target
>=subsystem_pun(host_index
))) 1889 target
= cmd
->target
; 1891 /* if (target,lun) is NO LUN or not existing at all, return error */ 1892 if((get_scsi(host_index
)[target
][cmd
->lun
] == TYPE_NO_LUN
)|| 1893 (get_scsi(host_index
)[target
][cmd
->lun
] == TYPE_NO_DEVICE
)) { 1894 cmd
->result
= DID_NO_CONNECT
<<16; 1899 /*if (target,lun) unassigned, do further checks... */ 1900 ldn
=get_ldn(host_index
)[target
][cmd
->lun
]; 1901 if(ldn
>= MAX_LOG_DEV
) {/* on invalid ldn do special stuff */ 1902 if(ldn
> MAX_LOG_DEV
) {/* dynamical remapping if ldn unassigned */ 1903 current_ldn
=next_ldn(host_index
);/* stop-value for one circle */ 1904 while(ld(host_index
)[next_ldn(host_index
)].cmd
) {/* search for a occupied, but not in */ 1905 /* command-processing ldn. */ 1906 next_ldn(host_index
)++; 1907 if(next_ldn(host_index
)>=MAX_LOG_DEV
) 1908 next_ldn(host_index
) =7; 1909 if(current_ldn
==next_ldn(host_index
)) {/* One circle done ? */ 1910 /* no non-processing ldn found */ 1911 printk("IBM MCA SCSI: Cannot assign SCSI-device dynamically!\n" \
1912 " On ldn 7-14 SCSI-commands everywhere in progress.\n" \
1913 " Reporting DID_NO_CONNECT for device (%d,%d).\n", 1915 cmd
->result
= DID_NO_CONNECT
<<16;/* return no connect*/ 1921 /* unmap non-processing ldn */ 1922 for(id
=0; id
<max_pun
; id
++) 1923 for(lun
=0; lun
<8; lun
++) { 1924 if(get_ldn(host_index
)[id
][lun
] ==next_ldn(host_index
)) { 1925 get_ldn(host_index
)[id
][lun
] = TYPE_NO_DEVICE
; 1926 get_scsi(host_index
)[id
][lun
] = TYPE_NO_DEVICE
; 1930 /* set reduced interrupt_handler-mode for checking */ 1931 local_checking_phase_flag(host_index
) =1; 1932 /* map found ldn to pun,lun */ 1933 get_ldn(host_index
)[target
][cmd
->lun
] =next_ldn(host_index
); 1934 /* change ldn to the right value, that is now next_ldn */ 1935 ldn
=next_ldn(host_index
); 1936 /* unassign all ldns (pun,lun,ldn does not matter for remove) */ 1937 immediate_assign(host_index
,0,0,0,REMOVE_LDN
); 1938 /* set only LDN for remapped device */ 1939 immediate_assign(host_index
,target
,cmd
->lun
,ldn
,SET_LDN
); 1940 /* get device information for ld[ldn] */ 1941 if(device_exists(host_index
, ldn
, 1942 &ld(host_index
)[ldn
].block_length
, 1943 &ld(host_index
)[ldn
].device_type
)) { 1944 ld(host_index
)[ldn
].cmd
= NULL
;/* To prevent panic set 0, because 1945 devices that were not assigned, 1946 should have nothing in progress. */ 1947 get_scsi(host_index
)[target
][cmd
->lun
] =ld(host_index
)[ldn
].device_type
; 1948 /* increase assignment counters for statistics in /proc */ 1949 IBM_DS(host_index
).dynamical_assignments
++; 1950 IBM_DS(host_index
).ldn_assignments
[ldn
]++; 1952 /* panic here, because a device, found at boottime has 1954 panic("IBM MCA SCSI: ldn=0x%x, SCSI-device on (%d,%d) vanished!\n", 1955 ldn
, target
, cmd
->lun
); 1956 /* unassign again all ldns (pun,lun,ldn does not matter for remove) */ 1957 immediate_assign(host_index
,0,0,0,REMOVE_LDN
); 1958 /* remap all ldns, as written in the pun/lun table */ 1960 #ifdef CONFIG_SCSI_MULTI_LUN 1961 for(lun
=0; lun
<8; lun
++) 1963 for(id
=0; id
<max_pun
; id
++) { 1964 if(get_ldn(host_index
)[id
][lun
] <= MAX_LOG_DEV
) 1965 immediate_assign(host_index
,id
,lun
, 1966 get_ldn(host_index
)[id
][lun
],SET_LDN
); 1968 /* set back to normal interrupt_handling */ 1969 local_checking_phase_flag(host_index
) =0; 1970 #ifdef IM_DEBUG_PROBE 1971 /* Information on syslog terminal */ 1972 printk("IBM MCA SCSI: ldn=0x%x dynamically reassigned to (%d,%d).\n", 1973 ldn
, target
, cmd
->lun
); 1975 /* increase next_ldn for next dynamical assignment */ 1976 next_ldn(host_index
)++; 1977 if(next_ldn(host_index
)>=MAX_LOG_DEV
) 1978 next_ldn(host_index
) =7; 1979 }else{/* wall against Linux accesses to the subsystem adapter */ 1980 cmd
->result
= DID_BAD_TARGET
<<16; 1986 /*verify there is no command already in progress for this log dev */ 1987 if(ld(host_index
)[ldn
].cmd
) 1988 panic("IBM MCA SCSI: cmd already in progress for this ldn.\n"); 1990 /*save done in cmd, and save cmd for the interrupt handler */ 1991 cmd
->scsi_done
= done
; 1992 ld(host_index
)[ldn
].cmd
= cmd
; 1994 /*fill scb information independent of the scsi command */ 1995 scb
= &(ld(host_index
)[ldn
].scb
); 1996 ld(host_index
)[ldn
].tsb
.dev_status
=0; 1997 scb
->enable
= IM_REPORT_TSB_ONLY_ON_ERROR
| IM_RETRY_ENABLE
; 1998 scb
->tsb_adr
=virt_to_bus(&(ld(host_index
)[ldn
].tsb
)); 1999 scsi_cmd
= cmd
->cmnd
[0]; 2003 sl
= (struct scatterlist
*)(cmd
->request_buffer
); 2005 panic("IBM MCA SCSI: scatter-gather list too long.\n"); 2007 ld(host_index
)[ldn
].sge
[i
].address
= (void*)(virt_to_bus(sl
[i
].address
)); 2008 ld(host_index
)[ldn
].sge
[i
].byte_length
= sl
[i
].length
; 2010 scb
->enable
|= IM_POINTER_TO_LIST
; 2011 scb
->sys_buf_adr
=virt_to_bus(&(ld(host_index
)[ldn
].sge
[0])); 2012 scb
->sys_buf_length
= cmd
->use_sg
*sizeof(struct im_sge
); 2014 scb
->sys_buf_adr
=virt_to_bus(cmd
->request_buffer
); 2015 /* recent Linux midlevel SCSI places 1024 byte for inquiry 2016 * command. Far too much for old PS/2 hardware. */ 2018 /* avoid command errors by setting bufferlengths to 2019 * ANSI-standard. Beware of forcing it to 255, 2020 * this could SEGV the kernel!!! */ 2025 if(cmd
->request_bufflen
>255) scb
->sys_buf_length
=255; 2026 else scb
->sys_buf_length
= cmd
->request_bufflen
; 2028 case TEST_UNIT_READY
: 2029 scb
->sys_buf_length
=0; 2032 scb
->sys_buf_length
= cmd
->request_bufflen
; 2036 /*fill scb information dependent on scsi command */ 2039 printk("issue scsi cmd=%02x to ldn=%d\n", scsi_cmd
, ldn
); 2042 /* for specific device-type debugging: */ 2043 #ifdef IM_DEBUG_CMD_SPEC_DEV 2044 if(ld(host_index
)[ldn
].device_type
==IM_DEBUG_CMD_DEVICE
) 2045 printk("(SCSI-device-type=0x%x) issue scsi cmd=%02x to ldn=%d\n", 2046 ld(host_index
)[ldn
].device_type
, scsi_cmd
, ldn
); 2049 /* for possible panics store current command */ 2050 last_scsi_command(host_index
)[ldn
] = scsi_cmd
; 2051 last_scsi_type(host_index
)[ldn
] = IM_SCB
; 2052 /* update statistical info */ 2053 IBM_DS(host_index
).total_accesses
++; 2054 IBM_DS(host_index
).ldn_access
[ldn
]++; 2063 /* Distinguish between disk and other devices. Only disks (that are the 2064 most frequently accessed devices) should be supported by the 2065 IBM-SCSI-Subsystem commands. */ 2066 switch(ld(host_index
)[ldn
].device_type
) { 2067 case TYPE_DISK
:/* for harddisks enter here ... */ 2068 case TYPE_MOD
:/* ... try it also for MO-drives (send flames as */ 2069 /* you like, if this won't work.) */ 2070 if(scsi_cmd
== READ_6
|| scsi_cmd
== READ_10
|| scsi_cmd
== READ_12
) { 2071 /* read command preparations */ 2072 scb
->enable
|= IM_READ_CONTROL
; 2073 IBM_DS(host_index
).ldn_read_access
[ldn
]++;/* increase READ-access on ldn stat. */ 2074 scb
->command
= IM_READ_DATA_CMD
| IM_NO_DISCONNECT
; 2075 }else{/* write command preparations */ 2076 IBM_DS(host_index
).ldn_write_access
[ldn
]++;/* increase write-count on ldn stat.*/ 2077 scb
->command
= IM_WRITE_DATA_CMD
| IM_NO_DISCONNECT
; 2079 if(scsi_cmd
== READ_6
|| scsi_cmd
== WRITE_6
) { 2080 scb
->u1
.log_blk_adr
= (((unsigned) cmd
->cmnd
[3]) <<0) | 2081 (((unsigned) cmd
->cmnd
[2]) <<8) | 2082 ((((unsigned) cmd
->cmnd
[1]) &0x1f) <<16); 2083 scb
->u2
.blk
.count
= (unsigned) cmd
->cmnd
[4]; 2085 scb
->u1
.log_blk_adr
= (((unsigned) cmd
->cmnd
[5]) <<0) | 2086 (((unsigned) cmd
->cmnd
[4]) <<8) | 2087 (((unsigned) cmd
->cmnd
[3]) <<16) | 2088 (((unsigned) cmd
->cmnd
[2]) <<24); 2089 scb
->u2
.blk
.count
= (((unsigned) cmd
->cmnd
[8]) <<0) | 2090 (((unsigned) cmd
->cmnd
[7]) <<8); 2092 last_scsi_logical_block(host_index
)[ldn
] = scb
->u1
.log_blk_adr
; 2093 last_scsi_blockcount(host_index
)[ldn
] = scb
->u2
.blk
.count
; 2094 scb
->u2
.blk
.length
=ld(host_index
)[ldn
].block_length
; 2096 /* for other devices, enter here. Other types are not known by 2097 Linux! TYPE_NO_LUN is forbidden as valid device. */ 2100 case TYPE_PROCESSOR
: 2103 case TYPE_MEDIUM_CHANGER
: 2104 /* If there is a sequential-device, IBM recommends to use 2105 IM_OTHER_SCSI_CMD_CMD instead of subsystem READ/WRITE. 2106 This includes CD-ROM devices, too, due to the partial sequential 2107 read capabilities. */ 2108 scb
->command
= IM_OTHER_SCSI_CMD_CMD
; 2109 if(scsi_cmd
== READ_6
|| scsi_cmd
== READ_10
|| scsi_cmd
== READ_12
) 2111 scb
->enable
|= IM_READ_CONTROL
; 2112 scb
->enable
|= IM_BYPASS_BUFFER
; 2113 scb
->u1
.scsi_cmd_length
= cmd
->cmd_len
; 2114 memcpy(scb
->u2
.scsi_command
, cmd
->cmnd
, cmd
->cmd_len
); 2115 last_scsi_type(host_index
)[ldn
] = IM_LONG_SCB
; 2116 /* Read/write on this non-disk devices is also displayworthy, 2117 so flash-up the LED/display. */ 2122 IBM_DS(host_index
).ldn_inquiry_access
[ldn
]++; 2123 scb
->command
= IM_DEVICE_INQUIRY_CMD
; 2124 scb
->enable
|= IM_READ_CONTROL
| IM_SUPRESS_EXCEPTION_SHORT
| IM_BYPASS_BUFFER
; 2125 scb
->u1
.log_blk_adr
=0; 2127 case TEST_UNIT_READY
: 2128 scb
->command
= IM_OTHER_SCSI_CMD_CMD
; 2129 scb
->enable
|= IM_READ_CONTROL
| IM_SUPRESS_EXCEPTION_SHORT
| IM_BYPASS_BUFFER
; 2130 scb
->u1
.log_blk_adr
=0; 2131 scb
->u1
.scsi_cmd_length
=6; 2132 memcpy(scb
->u2
.scsi_command
, cmd
->cmnd
,6); 2133 last_scsi_type(host_index
)[ldn
] = IM_LONG_SCB
; 2136 /* the length of system memory buffer must be exactly 8 bytes */ 2137 scb
->command
= IM_READ_CAPACITY_CMD
; 2138 scb
->enable
|= IM_READ_CONTROL
| IM_BYPASS_BUFFER
; 2139 if(scb
->sys_buf_length
>8) scb
->sys_buf_length
=8; 2141 /* Commands that need read-only-mode (system <- device): */ 2143 scb
->command
= IM_REQUEST_SENSE_CMD
; 2144 scb
->enable
|= IM_READ_CONTROL
| IM_SUPRESS_EXCEPTION_SHORT
| IM_BYPASS_BUFFER
; 2146 /* Commands that need write-only-mode (system -> device): */ 2148 case MODE_SELECT_10
: 2149 IBM_DS(host_index
).ldn_modeselect_access
[ldn
]++; 2150 scb
->command
= IM_OTHER_SCSI_CMD_CMD
; 2151 scb
->enable
|= IM_SUPRESS_EXCEPTION_SHORT
| IM_BYPASS_BUFFER
;/*Select needs WRITE-enabled*/ 2152 scb
->u1
.scsi_cmd_length
= cmd
->cmd_len
; 2153 memcpy(scb
->u2
.scsi_command
, cmd
->cmnd
, cmd
->cmd_len
); 2154 last_scsi_type(host_index
)[ldn
] = IM_LONG_SCB
; 2156 /* For other commands, read-only is useful. Most other commands are 2157 running without an input-data-block. */ 2159 scb
->command
= IM_OTHER_SCSI_CMD_CMD
; 2160 scb
->enable
|= IM_READ_CONTROL
| IM_SUPRESS_EXCEPTION_SHORT
| IM_BYPASS_BUFFER
; 2161 scb
->u1
.scsi_cmd_length
= cmd
->cmd_len
; 2162 memcpy(scb
->u2
.scsi_command
, cmd
->cmnd
, cmd
->cmd_len
); 2163 last_scsi_type(host_index
)[ldn
] = IM_LONG_SCB
; 2166 /*issue scb command, and return */ 2167 if(++disk_rw_in_progress
==1) 2168 PS2_DISK_LED_ON(shpnt
->host_no
, target
); 2170 if(last_scsi_type(host_index
)[ldn
] == IM_LONG_SCB
) { 2171 issue_cmd(host_index
,virt_to_bus(scb
), IM_LONG_SCB
| ldn
); 2172 IBM_DS(host_index
).long_scbs
++; 2174 issue_cmd(host_index
,virt_to_bus(scb
), IM_SCB
| ldn
); 2175 IBM_DS(host_index
).scbs
++; 2180 intibmmca_abort(Scsi_Cmnd
* cmd
) 2182 /* Abort does not work, as the adapter never generates an interrupt on 2183 * whatever situation is simulated, even when really pending commands 2184 * are running on the adapters' hardware ! */ 2186 struct Scsi_Host
*shpnt
; 2188 void(*saved_done
) (Scsi_Cmnd
*); 2192 static unsigned long flags
; 2193 unsigned long imm_command
; 2195 #ifdef IM_DEBUG_PROBE 2196 printk("IBM MCA SCSI: Abort subroutine called...\n"); 2200 /* search for the right hostadapter */ 2201 for(host_index
=0; hosts
[host_index
] && hosts
[host_index
]->host_no
!= shpnt
->host_no
; host_index
++); 2203 if(!hosts
[host_index
]) {/* invalid hostadapter descriptor address */ 2204 cmd
->result
= DID_NO_CONNECT
<<16; 2205 if(cmd
->scsi_done
) (cmd
->scsi_done
) (cmd
); 2208 #ifdef IM_DEBUG_PROBE 2209 printk("IBM MCA SCSI: Abort adapter selection failed!\n"); 2211 return SCSI_ABORT_SNOOZE
; 2213 max_pun
=subsystem_maxid(host_index
); 2214 if(ibm_ansi_order
) { 2215 target
= max_pun
-1- cmd
->target
; 2216 if((target
<=subsystem_pun(host_index
))&&(cmd
->target
<=subsystem_pun(host_index
))) 2218 else if((target
>=subsystem_pun(host_index
))&&(cmd
->target
>=subsystem_pun(host_index
))) 2221 target
= cmd
->target
; 2223 /* get logical device number, and disable system interrupts */ 2224 printk("IBM MCA SCSI: Sending abort to device pun=%d, lun=%d.\n", 2226 ldn
=get_ldn(host_index
)[target
][cmd
->lun
]; 2228 /*if cmd for this ldn has already finished, no need to abort */ 2229 if(!ld(host_index
)[ldn
].cmd
) { 2231 return SCSI_ABORT_NOT_RUNNING
; 2234 /* Clear ld.cmd, save done function, install internal done, 2235 * send abort immediate command (this enables sys. interrupts), 2236 * and wait until the interrupt arrives. 2238 saved_done
= cmd
->scsi_done
; 2239 cmd
->scsi_done
= internal_done
; 2241 last_scsi_command(host_index
)[ldn
] = IM_ABORT_IMM_CMD
; 2242 last_scsi_type(host_index
)[ldn
] = IM_IMM_CMD
; 2243 imm_command
=inl(IM_CMD_REG(host_index
)); 2244 imm_command
&= (unsigned long)(0xffff0000);/* mask reserved stuff */ 2245 imm_command
|= (unsigned long)(IM_ABORT_IMM_CMD
); 2246 /* must wait for attention reg not busy */ 2248 if(!(inb(IM_STAT_REG(host_index
)) & IM_BUSY
)) 2253 /* write registers and enable system interrupts */ 2254 outl(imm_command
,IM_CMD_REG(host_index
)); 2255 outb(IM_IMM_CMD
| ldn
,IM_ATTN_REG(host_index
)); 2257 #ifdef IM_DEBUG_PROBE 2258 printk("IBM MCA SCSI: Abort queued to adapter...\n"); 2260 while(!cmd
->SCp
.Status
)barrier(); 2261 cmd
->scsi_done
= saved_done
; 2262 #ifdef IM_DEBUG_PROBE 2263 printk("IBM MCA SCSI: Abort returned with adapter response...\n"); 2266 /*if abort went well, call saved done, then return success or error */ 2267 if(cmd
->result
== (DID_ABORT
<<16)) { 2269 cmd
->result
|= DID_ABORT
<<16; 2270 if(cmd
->scsi_done
) (cmd
->scsi_done
) (cmd
); 2271 ld(host_index
)[ldn
].cmd
= NULL
; 2273 #ifdef IM_DEBUG_PROBE 2274 printk("IBM MCA SCSI: Abort finished with success.\n"); 2276 return SCSI_ABORT_SUCCESS
; 2279 cmd
->result
|= DID_NO_CONNECT
<<16; 2280 if(cmd
->scsi_done
) (cmd
->scsi_done
) (cmd
); 2281 ld(host_index
)[ldn
].cmd
= NULL
; 2283 #ifdef IM_DEBUG_PROBE 2284 printk("IBM MCA SCSI: Abort failed.\n"); 2286 return SCSI_ABORT_ERROR
; 2290 intibmmca_reset(Scsi_Cmnd
* cmd
,unsigned int reset_flags
) 2292 struct Scsi_Host
*shpnt
; 2296 static unsigned long flags
; 2297 unsigned long imm_command
; 2300 printk("IBM MCA SCSI: Reset called with NULL-command!\n"); 2301 return(SCSI_RESET_SNOOZE
); 2304 ticks
= IM_RESET_DELAY
*HZ
; 2306 /* search for the right hostadapter */ 2307 for(host_index
=0; hosts
[host_index
] && hosts
[host_index
]->host_no
!= shpnt
->host_no
; host_index
++); 2309 if(!hosts
[host_index
])/* invalid hostadapter descriptor address */ 2310 return SCSI_ABORT_SNOOZE
; 2312 if(local_checking_phase_flag(host_index
)) { 2313 printk("IBM MCA SCSI: unable to reset while checking devices.\n"); 2315 return SCSI_RESET_SNOOZE
; 2318 /* issue reset immediate command to subsystem, and wait for interrupt */ 2319 printk("IBM MCA SCSI: resetting all devices.\n"); 2320 reset_status(host_index
) = IM_RESET_IN_PROGRESS
; 2321 last_scsi_command(host_index
)[0xf] = IM_RESET_IMM_CMD
; 2322 last_scsi_type(host_index
)[0xf] = IM_IMM_CMD
; 2323 imm_command
=inl(IM_CMD_REG(host_index
)); 2324 imm_command
&= (unsigned long)(0xffff0000);/* mask reserved stuff */ 2325 imm_command
|= (unsigned long)(IM_RESET_IMM_CMD
); 2326 /* must wait for attention reg not busy */ 2328 if(!(inb(IM_STAT_REG(host_index
)) & IM_BUSY
)) 2333 /*write registers and enable system interrupts */ 2334 outl(imm_command
,IM_CMD_REG(host_index
)); 2335 outb(IM_IMM_CMD
|0xf,IM_ATTN_REG(host_index
)); 2336 /* wait for interrupt finished or intr_stat register to be set, as the 2337 * interrupt will not be executed, while we are in here! */ 2338 while(reset_status(host_index
) == IM_RESET_IN_PROGRESS
&& --ticks
2339 && ((inb(IM_INTR_REG(host_index
)) &0x8f)!=0x8f)) { 2340 udelay((1+999/HZ
)*1000); 2343 /* if reset did not complete, just return an error*/ 2345 printk("IBM MCA SCSI: reset did not complete within %d seconds.\n", 2347 reset_status(host_index
) = IM_RESET_FINISHED_FAIL
; 2349 return SCSI_RESET_ERROR
; 2352 if((inb(IM_INTR_REG(host_index
)) &0x8f)==0x8f) { 2353 /* analysis done by this routine and not by the intr-routine */ 2354 if(inb(IM_INTR_REG(host_index
))==0xaf) 2355 reset_status(host_index
) = IM_RESET_FINISHED_OK_NO_INT
; 2356 else if(inb(IM_INTR_REG(host_index
))==0xcf) 2357 reset_status(host_index
) = IM_RESET_FINISHED_FAIL
; 2358 else/* failed, 4get it */ 2359 reset_status(host_index
) = IM_RESET_NOT_IN_PROGRESS_NO_INT
; 2360 outb(IM_EOI
|0xf,IM_ATTN_REG(host_index
)); 2363 /* if reset failed, just return an error */ 2364 if(reset_status(host_index
) == IM_RESET_FINISHED_FAIL
) { 2365 printk("IBM MCA SCSI: reset failed.\n"); 2367 return SCSI_RESET_ERROR
; 2370 /* so reset finished ok - call outstanding done's, and return success */ 2371 printk("IBM MCA SCSI: Reset successfully completed.\n"); 2373 for(i
=0; i
< MAX_LOG_DEV
; i
++) { 2374 cmd_aid
=ld(host_index
)[i
].cmd
; 2375 if(cmd_aid
&& cmd_aid
->scsi_done
) { 2376 ld(host_index
)[i
].cmd
= NULL
; 2377 cmd_aid
->result
= DID_RESET
<<16; 2380 if(reset_flags
& SCSI_RESET_SUGGEST_HOST_RESET
) 2381 return(SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
); 2382 else if(reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) 2383 return(SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
); 2385 return SCSI_RESET_SUCCESS
; 2388 intibmmca_biosparam(Disk
* disk
, kdev_t dev
,int*info
) 2392 info
[2] = disk
->capacity
/ (info
[0] * info
[1]); 2393 if(info
[2] >=1024) { 2396 info
[2] = disk
->capacity
/ (info
[0] * info
[1]); 2397 if(info
[2] >=1024) { 2400 info
[2] = disk
->capacity
/ (info
[0] * info
[1]); 2408 /* calculate percentage of total accesses on a ldn */ 2409 static intldn_access_load(int host_index
,int ldn
) 2411 if(IBM_DS(host_index
).total_accesses
==0)return(0); 2412 if(IBM_DS(host_index
).ldn_access
[ldn
] ==0)return(0); 2413 return(IBM_DS(host_index
).ldn_access
[ldn
] *100) /IBM_DS(host_index
).total_accesses
; 2416 /* calculate total amount of r/w-accesses */ 2417 static intldn_access_total_read_write(int host_index
) 2423 for(i
=0; i
<=MAX_LOG_DEV
; i
++) 2424 a
+=IBM_DS(host_index
).ldn_read_access
[i
]+IBM_DS(host_index
).ldn_write_access
[i
]; 2428 static intldn_access_total_inquiry(int host_index
) 2434 for(i
=0; i
<=MAX_LOG_DEV
; i
++) 2435 a
+=IBM_DS(host_index
).ldn_inquiry_access
[i
]; 2439 static intldn_access_total_modeselect(int host_index
) 2445 for(i
=0; i
<=MAX_LOG_DEV
; i
++) 2446 a
+=IBM_DS(host_index
).ldn_modeselect_access
[i
]; 2450 /* routine to display info in the proc-fs-structure (a deluxe feature) */ 2451 intibmmca_proc_info(char*buffer
,char**start
, off_t offset
,int length
, 2452 int hostno
,int inout
) 2455 int i
,id
,lun
,host_index
; 2456 struct Scsi_Host
*shpnt
; 2457 unsigned long flags
; 2461 for(i
=0; hosts
[i
] && hosts
[i
]->host_no
!= hostno
; i
++); 2465 len
+=sprintf(buffer
+len
,"\nIBM MCA SCSI: Can't find adapter for host number %d\n", hostno
); 2468 max_pun
=subsystem_maxid(host_index
); 2470 len
+=sprintf(buffer
+len
,"\nIBM-SCSI-Subsystem-Linux-Driver, Version %s\n\n\n", 2471 IBMMCA_SCSI_DRIVER_VERSION
); 2472 len
+=sprintf(buffer
+len
," SCSI Access-Statistics:\n"); 2473 len
+=sprintf(buffer
+len
," Device Scanning Order....: %s\n", 2474 (ibm_ansi_order
) ?"IBM/ANSI":"New Industry Standard"); 2475 #ifdef CONFIG_SCSI_MULTI_LUN 2476 len
+=sprintf(buffer
+len
," Multiple LUN probing.....: Yes\n"); 2478 len
+=sprintf(buffer
+len
," Multiple LUN probing.....: No\n"); 2480 len
+=sprintf(buffer
+len
," This Hostnumber..........: %d\n", 2482 len
+=sprintf(buffer
+len
," Base I/O-Port............: 0x%x\n", 2483 (unsigned int)(IM_CMD_REG(host_index
))); 2484 len
+=sprintf(buffer
+len
," (Shared) IRQ.............: %d\n", 2486 len
+=sprintf(buffer
+len
," Total Interrupts.........: %d\n", 2487 IBM_DS(host_index
).total_interrupts
); 2488 len
+=sprintf(buffer
+len
," Total SCSI Accesses......: %d\n", 2489 IBM_DS(host_index
).total_accesses
); 2490 len
+=sprintf(buffer
+len
," Total short SCBs.........: %d\n", 2491 IBM_DS(host_index
).scbs
); 2492 len
+=sprintf(buffer
+len
," Total long SCBs..........: %d\n", 2493 IBM_DS(host_index
).long_scbs
); 2494 len
+=sprintf(buffer
+len
," Total SCSI READ/WRITE..: %d\n", 2495 ldn_access_total_read_write(host_index
)); 2496 len
+=sprintf(buffer
+len
," Total SCSI Inquiries...: %d\n", 2497 ldn_access_total_inquiry(host_index
)); 2498 len
+=sprintf(buffer
+len
," Total SCSI Modeselects.: %d\n", 2499 ldn_access_total_modeselect(host_index
)); 2500 len
+=sprintf(buffer
+len
," Total SCSI other cmds..: %d\n", 2501 IBM_DS(host_index
).total_accesses
-ldn_access_total_read_write(host_index
) 2502 -ldn_access_total_modeselect(host_index
) 2503 -ldn_access_total_inquiry(host_index
)); 2504 len
+=sprintf(buffer
+len
," Total SCSI command fails.: %d\n\n", 2505 IBM_DS(host_index
).total_errors
); 2506 len
+=sprintf(buffer
+len
," Logical-Device-Number (LDN) Access-Statistics:\n"); 2507 len
+=sprintf(buffer
+len
," LDN | Accesses [%%] | READ | WRITE | ASSIGNMENTS\n"); 2508 len
+=sprintf(buffer
+len
," -----|--------------|-----------|-----------|--------------\n"); 2509 for(i
=0; i
<=MAX_LOG_DEV
; i
++) 2510 len
+=sprintf(buffer
+len
," %2X | %3d | %8d | %8d | %8d\n", 2511 i
,ldn_access_load(host_index
, i
),IBM_DS(host_index
).ldn_read_access
[i
], 2512 IBM_DS(host_index
).ldn_write_access
[i
],IBM_DS(host_index
).ldn_assignments
[i
]); 2513 len
+=sprintf(buffer
+len
," -----------------------------------------------------------\n\n"); 2514 len
+=sprintf(buffer
+len
," Dynamical-LDN-Assignment-Statistics:\n"); 2515 len
+=sprintf(buffer
+len
," Number of physical SCSI-devices..: %d (+ Adapter)\n", 2516 IBM_DS(host_index
).total_scsi_devices
); 2517 len
+=sprintf(buffer
+len
," Dynamical Assignment necessary...: %s\n", 2518 IBM_DS(host_index
).dyn_flag
?"Yes":"No "); 2519 len
+=sprintf(buffer
+len
," Next LDN to be assigned..........: 0x%x\n", 2520 next_ldn(host_index
)); 2521 len
+=sprintf(buffer
+len
," Dynamical assignments done yet...: %d\n", 2522 IBM_DS(host_index
).dynamical_assignments
); 2523 len
+=sprintf(buffer
+len
,"\nCurrent SCSI-Device-Mapping:\n"); 2524 len
+=sprintf(buffer
+len
," Physical SCSI-Device Map Logical SCSI-Device Map\n"); 2525 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"); 2526 for(id
=0; id
<max_pun
; id
++) { 2527 len
+=sprintf(buffer
+len
," %2d ",id
); 2528 for(lun
=0; lun
<8; lun
++) 2529 len
+=sprintf(buffer
+len
,"%2s ",ti_p(get_scsi(host_index
)[id
][lun
])); 2530 len
+=sprintf(buffer
+len
," %2d ",id
); 2531 for(lun
=0; lun
<8; lun
++) 2532 len
+=sprintf(buffer
+len
,"%2s ",ti_l(get_ldn(host_index
)[id
][lun
])); 2533 len
+=sprintf(buffer
+len
,"\n"); 2536 len
+=sprintf(buffer
+len
,"(A = IBM-Subsystem, D = Harddisk, T = Tapedrive, P = Processor, W = WORM,\n"); 2537 len
+=sprintf(buffer
+len
," R = CD-ROM, S = Scanner, M = MO-Drive, C = Medium-Changer, + = unprovided LUN,\n"); 2538 len
+=sprintf(buffer
+len
," - = nothing found, nothing assigned or unprobed LUN)\n\n"); 2540 *start
= buffer
+ offset
; 2542 if(len
> length
) len
= length
; 2547 voidibmmca_scsi_setup(char*str
,int*ints
) 2549 internal_ibmmca_scsi_setup(str
, ints
); 2552 static intoption_setup(char*str
) 2554 int ints
[IM_MAX_HOSTS
]; 2558 while(cur
&&isdigit(*cur
) && i
<= IM_MAX_HOSTS
) { 2559 ints
[i
++] =simple_strtoul(cur
, NULL
,0); 2560 if((cur
=strchr(cur
,',')) != NULL
) cur
++; 2563 internal_ibmmca_scsi_setup(cur
, ints
); 2567 __setup("ibmmcascsi=", option_setup
); 2570 /* Eventually this will go into an include file, but this will be later */ 2571 Scsi_Host_Template driver_template
= IBMMCA
; 2573 #include"scsi_module.c"