ibmmca.c 95 KB

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