ibmmca.c 85 KB

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