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