ibmmca.c 95 KB

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