ibmmca.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  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/string.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/init.h>
  39. #include <linux/mca-legacy.h>
  40. #include <asm/system.h>
  41. #include <asm/io.h>
  42. #include "scsi.h"
  43. #include <scsi/scsi_host.h>
  44. #include "ibmmca.h"
  45. /* current version of this driver-source: */
  46. #define IBMMCA_SCSI_DRIVER_VERSION "4.0b-ac"
  47. /* driver configuration */
  48. #define IM_MAX_HOSTS 8 /* maximum number of host adapters */
  49. #define IM_RESET_DELAY 60 /* seconds allowed for a reset */
  50. /* driver debugging - #undef all for normal operation */
  51. /* if defined: count interrupts and ignore this special one: */
  52. #undef IM_DEBUG_TIMEOUT //50
  53. #define TIMEOUT_PUN 0
  54. #define TIMEOUT_LUN 0
  55. /* verbose interrupt: */
  56. #undef IM_DEBUG_INT
  57. /* verbose queuecommand: */
  58. #undef IM_DEBUG_CMD
  59. /* verbose queucommand for specific SCSI-device type: */
  60. #undef IM_DEBUG_CMD_SPEC_DEV
  61. /* verbose device probing */
  62. #undef IM_DEBUG_PROBE
  63. /* device type that shall be displayed on syslog (only during debugging): */
  64. #define IM_DEBUG_CMD_DEVICE TYPE_TAPE
  65. /* relative addresses of hardware registers on a subsystem */
  66. #define IM_CMD_REG(hi) (hosts[(hi)]->io_port) /*Command Interface, (4 bytes long) */
  67. #define IM_ATTN_REG(hi) (hosts[(hi)]->io_port+4) /*Attention (1 byte) */
  68. #define IM_CTR_REG(hi) (hosts[(hi)]->io_port+5) /*Basic Control (1 byte) */
  69. #define IM_INTR_REG(hi) (hosts[(hi)]->io_port+6) /*Interrupt Status (1 byte, r/o) */
  70. #define IM_STAT_REG(hi) (hosts[(hi)]->io_port+7) /*Basic Status (1 byte, read only) */
  71. /* basic I/O-port of first adapter */
  72. #define IM_IO_PORT 0x3540
  73. /* maximum number of hosts that can be found */
  74. #define IM_N_IO_PORT 8
  75. /*requests going into the upper nibble of the Attention register */
  76. /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
  77. #define IM_IMM_CMD 0x10 /*immediate command */
  78. #define IM_SCB 0x30 /*Subsystem Control Block command */
  79. #define IM_LONG_SCB 0x40 /*long Subsystem Control Block command */
  80. #define IM_EOI 0xe0 /*end-of-interrupt request */
  81. /*values for bits 7,1,0 of Basic Control reg. (bits 6-2 reserved) */
  82. #define IM_HW_RESET 0x80 /*hardware reset */
  83. #define IM_ENABLE_DMA 0x02 /*enable subsystem's busmaster DMA */
  84. #define IM_ENABLE_INTR 0x01 /*enable interrupts to the system */
  85. /*to interpret the upper nibble of Interrupt Status register */
  86. /*note: the lower nibble specifies the device(0-14), or subsystem(15) */
  87. #define IM_SCB_CMD_COMPLETED 0x10
  88. #define IM_SCB_CMD_COMPLETED_WITH_RETRIES 0x50
  89. #define IM_LOOP_SCATTER_BUFFER_FULL 0x60
  90. #define IM_ADAPTER_HW_FAILURE 0x70
  91. #define IM_IMMEDIATE_CMD_COMPLETED 0xa0
  92. #define IM_CMD_COMPLETED_WITH_FAILURE 0xc0
  93. #define IM_CMD_ERROR 0xe0
  94. #define IM_SOFTWARE_SEQUENCING_ERROR 0xf0
  95. /*to interpret bits 3-0 of Basic Status register (bits 7-4 reserved) */
  96. #define IM_CMD_REG_FULL 0x08
  97. #define IM_CMD_REG_EMPTY 0x04
  98. #define IM_INTR_REQUEST 0x02
  99. #define IM_BUSY 0x01
  100. /*immediate commands (word written into low 2 bytes of command reg) */
  101. #define IM_RESET_IMM_CMD 0x0400
  102. #define IM_FEATURE_CTR_IMM_CMD 0x040c
  103. #define IM_DMA_PACING_IMM_CMD 0x040d
  104. #define IM_ASSIGN_IMM_CMD 0x040e
  105. #define IM_ABORT_IMM_CMD 0x040f
  106. #define IM_FORMAT_PREP_IMM_CMD 0x0417
  107. /*SCB (Subsystem Control Block) structure */
  108. struct im_scb {
  109. unsigned short command; /*command word (read, etc.) */
  110. unsigned short enable; /*enable word, modifies cmd */
  111. union {
  112. unsigned long log_blk_adr; /*block address on SCSI device */
  113. unsigned char scsi_cmd_length; /*6,10,12, for other scsi cmd */
  114. } u1;
  115. unsigned long sys_buf_adr; /*physical system memory adr */
  116. unsigned long sys_buf_length; /*size of sys mem buffer */
  117. unsigned long tsb_adr; /*Termination Status Block adr */
  118. unsigned long scb_chain_adr; /*optional SCB chain address */
  119. union {
  120. struct {
  121. unsigned short count; /*block count, on SCSI device */
  122. unsigned short length; /*block length, on SCSI device */
  123. } blk;
  124. unsigned char scsi_command[12]; /*other scsi command */
  125. } u2;
  126. };
  127. /*structure scatter-gather element (for list of system memory areas) */
  128. struct im_sge {
  129. void *address;
  130. unsigned long byte_length;
  131. };
  132. /*structure returned by a get_pos_info command: */
  133. struct im_pos_info {
  134. unsigned short pos_id; /* adapter id */
  135. unsigned char pos_3a; /* pos 3 (if pos 6 = 0) */
  136. unsigned char pos_2; /* pos 2 */
  137. unsigned char int_level; /* interrupt level IRQ 11 or 14 */
  138. unsigned char pos_4a; /* pos 4 (if pos 6 = 0) */
  139. unsigned short connector_size; /* MCA connector size: 16 or 32 Bit */
  140. unsigned char num_luns; /* number of supported luns per device */
  141. unsigned char num_puns; /* number of supported puns */
  142. unsigned char pacing_factor; /* pacing factor */
  143. unsigned char num_ldns; /* number of ldns available */
  144. unsigned char eoi_off; /* time EOI and interrupt inactive */
  145. unsigned char max_busy; /* time between reset and busy on */
  146. unsigned short cache_stat; /* ldn cachestat. Bit=1 = not cached */
  147. unsigned short retry_stat; /* retry status of ldns. Bit=1=disabled */
  148. unsigned char pos_4b; /* pos 4 (if pos 6 = 1) */
  149. unsigned char pos_3b; /* pos 3 (if pos 6 = 1) */
  150. unsigned char pos_6; /* pos 6 */
  151. unsigned char pos_5; /* pos 5 */
  152. unsigned short max_overlap; /* maximum overlapping requests */
  153. unsigned short num_bus; /* number of SCSI-busses */
  154. };
  155. /*values for SCB command word */
  156. #define IM_NO_SYNCHRONOUS 0x0040 /*flag for any command */
  157. #define IM_NO_DISCONNECT 0x0080 /*flag for any command */
  158. #define IM_READ_DATA_CMD 0x1c01
  159. #define IM_WRITE_DATA_CMD 0x1c02
  160. #define IM_READ_VERIFY_CMD 0x1c03
  161. #define IM_WRITE_VERIFY_CMD 0x1c04
  162. #define IM_REQUEST_SENSE_CMD 0x1c08
  163. #define IM_READ_CAPACITY_CMD 0x1c09
  164. #define IM_DEVICE_INQUIRY_CMD 0x1c0b
  165. #define IM_READ_LOGICAL_CMD 0x1c2a
  166. #define IM_OTHER_SCSI_CMD_CMD 0x241f
  167. /* unused, but supported, SCB commands */
  168. #define IM_GET_COMMAND_COMPLETE_STATUS_CMD 0x1c07 /* command status */
  169. #define IM_GET_POS_INFO_CMD 0x1c0a /* returns neat stuff */
  170. #define IM_READ_PREFETCH_CMD 0x1c31 /* caching controller only */
  171. #define IM_FOMAT_UNIT_CMD 0x1c16 /* format unit */
  172. #define IM_REASSIGN_BLOCK_CMD 0x1c18 /* in case of error */
  173. /*values to set bits in the enable word of SCB */
  174. #define IM_READ_CONTROL 0x8000
  175. #define IM_REPORT_TSB_ONLY_ON_ERROR 0x4000
  176. #define IM_RETRY_ENABLE 0x2000
  177. #define IM_POINTER_TO_LIST 0x1000
  178. #define IM_SUPRESS_EXCEPTION_SHORT 0x0400
  179. #define IM_BYPASS_BUFFER 0x0200
  180. #define IM_CHAIN_ON_NO_ERROR 0x0001
  181. /*TSB (Termination Status Block) structure */
  182. struct im_tsb {
  183. unsigned short end_status;
  184. unsigned short reserved1;
  185. unsigned long residual_byte_count;
  186. unsigned long sg_list_element_adr;
  187. unsigned short status_length;
  188. unsigned char dev_status;
  189. unsigned char cmd_status;
  190. unsigned char dev_error;
  191. unsigned char cmd_error;
  192. unsigned short reserved2;
  193. unsigned short reserved3;
  194. unsigned short low_of_last_scb_adr;
  195. unsigned short high_of_last_scb_adr;
  196. };
  197. /*subsystem uses interrupt request level 14 */
  198. #define IM_IRQ 14
  199. /*SCSI-2 F/W may evade to interrupt 11 */
  200. #define IM_IRQ_FW 11
  201. /* Model 95 has an additional alphanumeric display, which can be used
  202. to display SCSI-activities. 8595 models do not have any disk led, which
  203. makes this feature quite useful.
  204. The regular PS/2 disk led is turned on/off by bits 6,7 of system
  205. control port. */
  206. /* LED display-port (actually, last LED on display) */
  207. #define MOD95_LED_PORT 0x108
  208. /* system-control-register of PS/2s with diskindicator */
  209. #define PS2_SYS_CTR 0x92
  210. /* activity displaying methods */
  211. #define LED_DISP 1
  212. #define LED_ADISP 2
  213. #define LED_ACTIVITY 4
  214. /* failed intr */
  215. #define CMD_FAIL 255
  216. /* The SCSI-ID(!) of the accessed SCSI-device is shown on PS/2-95 machines' LED
  217. displays. ldn is no longer displayed here, because the ldn mapping is now
  218. done dynamically and the ldn <-> pun,lun maps can be looked-up at boottime
  219. or during uptime in /proc/scsi/ibmmca/<host_no> in case of trouble,
  220. interest, debugging or just for having fun. The left number gives the
  221. host-adapter number and the right shows the accessed SCSI-ID. */
  222. /* display_mode is set by the ibmmcascsi= command line arg */
  223. static int display_mode = 0;
  224. /* set default adapter timeout */
  225. static unsigned int adapter_timeout = 45;
  226. /* for probing on feature-command: */
  227. static unsigned int global_command_error_excuse = 0;
  228. /* global setting by command line for adapter_speed */
  229. static int global_adapter_speed = 0; /* full speed by default */
  230. /* Panel / LED on, do it right for F/W addressin, too. adisplay will
  231. * just ignore ids>7, as the panel has only 7 digits available */
  232. #define PS2_DISK_LED_ON(ad,id) { if (display_mode & LED_DISP) { if (id>9) \
  233. outw((ad+48)|((id+55)<<8), MOD95_LED_PORT ); else \
  234. outw((ad+48)|((id+48)<<8), MOD95_LED_PORT ); } else \
  235. if (display_mode & LED_ADISP) { if (id<7) outb((char)(id+48),MOD95_LED_PORT+1+id); \
  236. outb((char)(ad+48), MOD95_LED_PORT); } \
  237. if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
  238. outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR); }
  239. /* Panel / LED off */
  240. /* bug fixed, Dec 15, 1997, where | was replaced by & here */
  241. #define PS2_DISK_LED_OFF() { if (display_mode & LED_DISP) \
  242. outw(0x2020, MOD95_LED_PORT ); else if (display_mode & LED_ADISP) { \
  243. outl(0x20202020,MOD95_LED_PORT); outl(0x20202020,MOD95_LED_PORT+4); } \
  244. if ((display_mode & LED_ACTIVITY)||(!display_mode)) \
  245. outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR); }
  246. /*list of supported subsystems */
  247. struct subsys_list_struct {
  248. unsigned short mca_id;
  249. char *description;
  250. };
  251. /* types of different supported hardware that goes to hostdata special */
  252. #define IBM_SCSI2_FW 0
  253. #define IBM_7568_WCACHE 1
  254. #define IBM_EXP_UNIT 2
  255. #define IBM_SCSI_WCACHE 3
  256. #define IBM_SCSI 4
  257. /* other special flags for hostdata structure */
  258. #define FORCED_DETECTION 100
  259. #define INTEGRATED_SCSI 101
  260. /* List of possible IBM-SCSI-adapters */
  261. static struct subsys_list_struct subsys_list[] = {
  262. {0x8efc, "IBM SCSI-2 F/W Adapter"}, /* special = 0 */
  263. {0x8efd, "IBM 7568 Industrial Computer SCSI Adapter w/Cache"}, /* special = 1 */
  264. {0x8ef8, "IBM Expansion Unit SCSI Controller"}, /* special = 2 */
  265. {0x8eff, "IBM SCSI Adapter w/Cache"}, /* special = 3 */
  266. {0x8efe, "IBM SCSI Adapter"}, /* special = 4 */
  267. };
  268. /* Max number of logical devices (can be up from 0 to 14). 15 is the address
  269. of the adapter itself. */
  270. #define MAX_LOG_DEV 15
  271. /*local data for a logical device */
  272. struct logical_device {
  273. struct im_scb scb; /* SCSI-subsystem-control-block structure */
  274. struct im_tsb tsb; /* SCSI command complete status block structure */
  275. struct im_sge sge[16]; /* scatter gather list structure */
  276. unsigned char buf[256]; /* SCSI command return data buffer */
  277. Scsi_Cmnd *cmd; /* SCSI-command that is currently in progress */
  278. int device_type; /* type of the SCSI-device. See include/scsi/scsi.h
  279. for interpretation of the possible values */
  280. int block_length; /* blocksize of a particular logical SCSI-device */
  281. int cache_flag; /* 1 if this is uncached, 0 if cache is present for ldn */
  282. int retry_flag; /* 1 if adapter retry is disabled, 0 if enabled */
  283. };
  284. /* statistics of the driver during operations (for proc_info) */
  285. struct Driver_Statistics {
  286. /* SCSI statistics on the adapter */
  287. int ldn_access[MAX_LOG_DEV + 1]; /* total accesses on a ldn */
  288. int ldn_read_access[MAX_LOG_DEV + 1]; /* total read-access on a ldn */
  289. int ldn_write_access[MAX_LOG_DEV + 1]; /* total write-access on a ldn */
  290. int ldn_inquiry_access[MAX_LOG_DEV + 1]; /* total inquiries on a ldn */
  291. int ldn_modeselect_access[MAX_LOG_DEV + 1]; /* total mode selects on ldn */
  292. int scbs; /* short SCBs queued */
  293. int long_scbs; /* long SCBs queued */
  294. int total_accesses; /* total accesses on all ldns */
  295. int total_interrupts; /* total interrupts (should be
  296. same as total_accesses) */
  297. int total_errors; /* command completed with error */
  298. /* dynamical assignment statistics */
  299. int total_scsi_devices; /* number of physical pun,lun */
  300. int dyn_flag; /* flag showing dynamical mode */
  301. int dynamical_assignments; /* number of remappings of ldns */
  302. int ldn_assignments[MAX_LOG_DEV + 1]; /* number of remappings of each
  303. ldn */
  304. };
  305. /* data structure for each host adapter */
  306. struct ibmmca_hostdata {
  307. /* array of logical devices: */
  308. struct logical_device _ld[MAX_LOG_DEV + 1];
  309. /* array to convert (pun, lun) into logical device number: */
  310. unsigned char _get_ldn[16][8];
  311. /*array that contains the information about the physical SCSI-devices
  312. attached to this host adapter: */
  313. unsigned char _get_scsi[16][8];
  314. /* used only when checking logical devices: */
  315. int _local_checking_phase_flag;
  316. /* report received interrupt: */
  317. int _got_interrupt;
  318. /* report termination-status of SCSI-command: */
  319. int _stat_result;
  320. /* reset status (used only when doing reset): */
  321. int _reset_status;
  322. /* code of the last SCSI command (needed for panic info): */
  323. int _last_scsi_command[MAX_LOG_DEV + 1];
  324. /* identifier of the last SCSI-command type */
  325. int _last_scsi_type[MAX_LOG_DEV + 1];
  326. /* last blockcount */
  327. int _last_scsi_blockcount[MAX_LOG_DEV + 1];
  328. /* last locgical block address */
  329. unsigned long _last_scsi_logical_block[MAX_LOG_DEV + 1];
  330. /* Counter that points on the next reassignable ldn for dynamical
  331. remapping. The default value is 7, that is the first reassignable
  332. number in the list at boottime: */
  333. int _next_ldn;
  334. /* Statistics-structure for this IBM-SCSI-host: */
  335. struct Driver_Statistics _IBM_DS;
  336. /* This hostadapters pos-registers pos2 until pos6 */
  337. unsigned int _pos[8];
  338. /* assign a special variable, that contains dedicated info about the
  339. adaptertype */
  340. int _special;
  341. /* connector size on the MCA bus */
  342. int _connector_size;
  343. /* synchronous SCSI transfer rate bitpattern */
  344. int _adapter_speed;
  345. };
  346. /* macros to access host data structure */
  347. #define subsystem_pun(hi) (hosts[(hi)]->this_id)
  348. #define subsystem_maxid(hi) (hosts[(hi)]->max_id)
  349. #define ld(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_ld)
  350. #define get_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_ldn)
  351. #define get_scsi(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_get_scsi)
  352. #define local_checking_phase_flag(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_local_checking_phase_flag)
  353. #define got_interrupt(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_got_interrupt)
  354. #define stat_result(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_stat_result)
  355. #define reset_status(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_reset_status)
  356. #define last_scsi_command(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_command)
  357. #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
  358. #define last_scsi_blockcount(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_blockcount)
  359. #define last_scsi_logical_block(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_logical_block)
  360. #define last_scsi_type(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_last_scsi_type)
  361. #define next_ldn(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_next_ldn)
  362. #define IBM_DS(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_IBM_DS)
  363. #define special(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_special)
  364. #define subsystem_connector_size(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_connector_size)
  365. #define adapter_speed(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_adapter_speed)
  366. #define pos2(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[2])
  367. #define pos3(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[3])
  368. #define pos4(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[4])
  369. #define pos5(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[5])
  370. #define pos6(hi) (((struct ibmmca_hostdata *) hosts[(hi)]->hostdata)->_pos[6])
  371. /* Define a arbitrary number as subsystem-marker-type. This number is, as
  372. described in the ANSI-SCSI-standard, not occupied by other device-types. */
  373. #define TYPE_IBM_SCSI_ADAPTER 0x2F
  374. /* Define 0xFF for no device type, because this type is not defined within
  375. the ANSI-SCSI-standard, therefore, it can be used and should not cause any
  376. harm. */
  377. #define TYPE_NO_DEVICE 0xFF
  378. /* define medium-changer. If this is not defined previously, e.g. Linux
  379. 2.0.x, define this type here. */
  380. #ifndef TYPE_MEDIUM_CHANGER
  381. #define TYPE_MEDIUM_CHANGER 0x08
  382. #endif
  383. /* define possible operations for the immediate_assign command */
  384. #define SET_LDN 0
  385. #define REMOVE_LDN 1
  386. /* ldn which is used to probe the SCSI devices */
  387. #define PROBE_LDN 0
  388. /* reset status flag contents */
  389. #define IM_RESET_NOT_IN_PROGRESS 0
  390. #define IM_RESET_IN_PROGRESS 1
  391. #define IM_RESET_FINISHED_OK 2
  392. #define IM_RESET_FINISHED_FAIL 3
  393. #define IM_RESET_NOT_IN_PROGRESS_NO_INT 4
  394. #define IM_RESET_FINISHED_OK_NO_INT 5
  395. /* define undefined SCSI-command */
  396. #define NO_SCSI 0xffff
  397. /*-----------------------------------------------------------------------*/
  398. /* if this is nonzero, ibmmcascsi option has been passed to the kernel */
  399. static int io_port[IM_MAX_HOSTS] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  400. static int scsi_id[IM_MAX_HOSTS] = { 7, 7, 7, 7, 7, 7, 7, 7 };
  401. /* fill module-parameters only, when this define is present.
  402. (that is kernel version 2.1.x) */
  403. #if defined(MODULE)
  404. static char *boot_options = NULL;
  405. module_param(boot_options, charp, 0);
  406. module_param_array(io_port, int, NULL, 0);
  407. module_param_array(scsi_id, int, NULL, 0);
  408. #if 0 /* FIXME: No longer exist? --RR */
  409. MODULE_PARM(display, "1i");
  410. MODULE_PARM(adisplay, "1i");
  411. MODULE_PARM(normal, "1i");
  412. MODULE_PARM(ansi, "1i");
  413. #endif
  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"