ibmmca.c 95 KB

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