PageRenderTime 78ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/scsi/ibmmca.c

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