ibmmca.c 95 KB

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