ibmmca.c 95 KB

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