dasd.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
  9. *
  10. */
  11. #include <linux/kmod.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/ctype.h>
  15. #include <linux/major.h>
  16. #include <linux/slab.h>
  17. #include <linux/buffer_head.h>
  18. #include <linux/hdreg.h>
  19. #include <asm/ccwdev.h>
  20. #include <asm/ebcdic.h>
  21. #include <asm/idals.h>
  22. #include <asm/todclk.h>
  23. /* This is ugly... */
  24. #define PRINTK_HEADER "dasd:"
  25. #include "dasd_int.h"
  26. /*
  27. * SECTION: Constant definitions to be used within this file
  28. */
  29. #define DASD_CHANQ_MAX_SIZE 4
  30. /*
  31. * SECTION: exported variables of dasd.c
  32. */
  33. debug_info_t *dasd_debug_area;
  34. struct dasd_discipline *dasd_diag_discipline_pointer;
  35. void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
  36. MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
  37. MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
  38. " Copyright 2000 IBM Corporation");
  39. MODULE_SUPPORTED_DEVICE("dasd");
  40. MODULE_LICENSE("GPL");
  41. /*
  42. * SECTION: prototypes for static functions of dasd.c
  43. */
  44. static int dasd_alloc_queue(struct dasd_block *);
  45. static void dasd_setup_queue(struct dasd_block *);
  46. static void dasd_free_queue(struct dasd_block *);
  47. static void dasd_flush_request_queue(struct dasd_block *);
  48. static int dasd_flush_block_queue(struct dasd_block *);
  49. static void dasd_device_tasklet(struct dasd_device *);
  50. static void dasd_block_tasklet(struct dasd_block *);
  51. static void do_kick_device(struct work_struct *);
  52. static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
  53. /*
  54. * SECTION: Operations on the device structure.
  55. */
  56. static wait_queue_head_t dasd_init_waitq;
  57. static wait_queue_head_t dasd_flush_wq;
  58. /*
  59. * Allocate memory for a new device structure.
  60. */
  61. struct dasd_device *dasd_alloc_device(void)
  62. {
  63. struct dasd_device *device;
  64. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  65. if (!device)
  66. return ERR_PTR(-ENOMEM);
  67. /* Get two pages for normal block device operations. */
  68. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  69. if (!device->ccw_mem) {
  70. kfree(device);
  71. return ERR_PTR(-ENOMEM);
  72. }
  73. /* Get one page for error recovery. */
  74. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  75. if (!device->erp_mem) {
  76. free_pages((unsigned long) device->ccw_mem, 1);
  77. kfree(device);
  78. return ERR_PTR(-ENOMEM);
  79. }
  80. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  81. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  82. spin_lock_init(&device->mem_lock);
  83. atomic_set(&device->tasklet_scheduled, 0);
  84. tasklet_init(&device->tasklet,
  85. (void (*)(unsigned long)) dasd_device_tasklet,
  86. (unsigned long) device);
  87. INIT_LIST_HEAD(&device->ccw_queue);
  88. init_timer(&device->timer);
  89. INIT_WORK(&device->kick_work, do_kick_device);
  90. device->state = DASD_STATE_NEW;
  91. device->target = DASD_STATE_NEW;
  92. return device;
  93. }
  94. /*
  95. * Free memory of a device structure.
  96. */
  97. void dasd_free_device(struct dasd_device *device)
  98. {
  99. kfree(device->private);
  100. free_page((unsigned long) device->erp_mem);
  101. free_pages((unsigned long) device->ccw_mem, 1);
  102. kfree(device);
  103. }
  104. /*
  105. * Allocate memory for a new device structure.
  106. */
  107. struct dasd_block *dasd_alloc_block(void)
  108. {
  109. struct dasd_block *block;
  110. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  111. if (!block)
  112. return ERR_PTR(-ENOMEM);
  113. /* open_count = 0 means device online but not in use */
  114. atomic_set(&block->open_count, -1);
  115. spin_lock_init(&block->request_queue_lock);
  116. atomic_set(&block->tasklet_scheduled, 0);
  117. tasklet_init(&block->tasklet,
  118. (void (*)(unsigned long)) dasd_block_tasklet,
  119. (unsigned long) block);
  120. INIT_LIST_HEAD(&block->ccw_queue);
  121. spin_lock_init(&block->queue_lock);
  122. init_timer(&block->timer);
  123. return block;
  124. }
  125. /*
  126. * Free memory of a device structure.
  127. */
  128. void dasd_free_block(struct dasd_block *block)
  129. {
  130. kfree(block);
  131. }
  132. /*
  133. * Make a new device known to the system.
  134. */
  135. static int dasd_state_new_to_known(struct dasd_device *device)
  136. {
  137. int rc;
  138. /*
  139. * As long as the device is not in state DASD_STATE_NEW we want to
  140. * keep the reference count > 0.
  141. */
  142. dasd_get_device(device);
  143. if (device->block) {
  144. rc = dasd_alloc_queue(device->block);
  145. if (rc) {
  146. dasd_put_device(device);
  147. return rc;
  148. }
  149. }
  150. device->state = DASD_STATE_KNOWN;
  151. return 0;
  152. }
  153. /*
  154. * Let the system forget about a device.
  155. */
  156. static int dasd_state_known_to_new(struct dasd_device *device)
  157. {
  158. /* Disable extended error reporting for this device. */
  159. dasd_eer_disable(device);
  160. /* Forget the discipline information. */
  161. if (device->discipline) {
  162. if (device->discipline->uncheck_device)
  163. device->discipline->uncheck_device(device);
  164. module_put(device->discipline->owner);
  165. }
  166. device->discipline = NULL;
  167. if (device->base_discipline)
  168. module_put(device->base_discipline->owner);
  169. device->base_discipline = NULL;
  170. device->state = DASD_STATE_NEW;
  171. if (device->block)
  172. dasd_free_queue(device->block);
  173. /* Give up reference we took in dasd_state_new_to_known. */
  174. dasd_put_device(device);
  175. return 0;
  176. }
  177. /*
  178. * Request the irq line for the device.
  179. */
  180. static int dasd_state_known_to_basic(struct dasd_device *device)
  181. {
  182. int rc;
  183. /* Allocate and register gendisk structure. */
  184. if (device->block) {
  185. rc = dasd_gendisk_alloc(device->block);
  186. if (rc)
  187. return rc;
  188. }
  189. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  190. device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 1,
  191. 8 * sizeof(long));
  192. debug_register_view(device->debug_area, &debug_sprintf_view);
  193. debug_set_level(device->debug_area, DBF_WARNING);
  194. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  195. device->state = DASD_STATE_BASIC;
  196. return 0;
  197. }
  198. /*
  199. * Release the irq line for the device. Terminate any running i/o.
  200. */
  201. static int dasd_state_basic_to_known(struct dasd_device *device)
  202. {
  203. int rc;
  204. if (device->block) {
  205. dasd_gendisk_free(device->block);
  206. dasd_block_clear_timer(device->block);
  207. }
  208. rc = dasd_flush_device_queue(device);
  209. if (rc)
  210. return rc;
  211. dasd_device_clear_timer(device);
  212. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  213. if (device->debug_area != NULL) {
  214. debug_unregister(device->debug_area);
  215. device->debug_area = NULL;
  216. }
  217. device->state = DASD_STATE_KNOWN;
  218. return 0;
  219. }
  220. /*
  221. * Do the initial analysis. The do_analysis function may return
  222. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  223. * until the discipline decides to continue the startup sequence
  224. * by calling the function dasd_change_state. The eckd disciplines
  225. * uses this to start a ccw that detects the format. The completion
  226. * interrupt for this detection ccw uses the kernel event daemon to
  227. * trigger the call to dasd_change_state. All this is done in the
  228. * discipline code, see dasd_eckd.c.
  229. * After the analysis ccw is done (do_analysis returned 0) the block
  230. * device is setup.
  231. * In case the analysis returns an error, the device setup is stopped
  232. * (a fake disk was already added to allow formatting).
  233. */
  234. static int dasd_state_basic_to_ready(struct dasd_device *device)
  235. {
  236. int rc;
  237. struct dasd_block *block;
  238. rc = 0;
  239. block = device->block;
  240. /* make disk known with correct capacity */
  241. if (block) {
  242. if (block->base->discipline->do_analysis != NULL)
  243. rc = block->base->discipline->do_analysis(block);
  244. if (rc) {
  245. if (rc != -EAGAIN)
  246. device->state = DASD_STATE_UNFMT;
  247. return rc;
  248. }
  249. dasd_setup_queue(block);
  250. set_capacity(block->gdp,
  251. block->blocks << block->s2b_shift);
  252. device->state = DASD_STATE_READY;
  253. rc = dasd_scan_partitions(block);
  254. if (rc)
  255. device->state = DASD_STATE_BASIC;
  256. } else {
  257. device->state = DASD_STATE_READY;
  258. }
  259. return rc;
  260. }
  261. /*
  262. * Remove device from block device layer. Destroy dirty buffers.
  263. * Forget format information. Check if the target level is basic
  264. * and if it is create fake disk for formatting.
  265. */
  266. static int dasd_state_ready_to_basic(struct dasd_device *device)
  267. {
  268. int rc;
  269. device->state = DASD_STATE_BASIC;
  270. if (device->block) {
  271. struct dasd_block *block = device->block;
  272. rc = dasd_flush_block_queue(block);
  273. if (rc) {
  274. device->state = DASD_STATE_READY;
  275. return rc;
  276. }
  277. dasd_destroy_partitions(block);
  278. dasd_flush_request_queue(block);
  279. block->blocks = 0;
  280. block->bp_block = 0;
  281. block->s2b_shift = 0;
  282. }
  283. return 0;
  284. }
  285. /*
  286. * Back to basic.
  287. */
  288. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  289. {
  290. device->state = DASD_STATE_BASIC;
  291. return 0;
  292. }
  293. /*
  294. * Make the device online and schedule the bottom half to start
  295. * the requeueing of requests from the linux request queue to the
  296. * ccw queue.
  297. */
  298. static int
  299. dasd_state_ready_to_online(struct dasd_device * device)
  300. {
  301. int rc;
  302. if (device->discipline->ready_to_online) {
  303. rc = device->discipline->ready_to_online(device);
  304. if (rc)
  305. return rc;
  306. }
  307. device->state = DASD_STATE_ONLINE;
  308. if (device->block)
  309. dasd_schedule_block_bh(device->block);
  310. return 0;
  311. }
  312. /*
  313. * Stop the requeueing of requests again.
  314. */
  315. static int dasd_state_online_to_ready(struct dasd_device *device)
  316. {
  317. int rc;
  318. if (device->discipline->online_to_ready) {
  319. rc = device->discipline->online_to_ready(device);
  320. if (rc)
  321. return rc;
  322. }
  323. device->state = DASD_STATE_READY;
  324. return 0;
  325. }
  326. /*
  327. * Device startup state changes.
  328. */
  329. static int dasd_increase_state(struct dasd_device *device)
  330. {
  331. int rc;
  332. rc = 0;
  333. if (device->state == DASD_STATE_NEW &&
  334. device->target >= DASD_STATE_KNOWN)
  335. rc = dasd_state_new_to_known(device);
  336. if (!rc &&
  337. device->state == DASD_STATE_KNOWN &&
  338. device->target >= DASD_STATE_BASIC)
  339. rc = dasd_state_known_to_basic(device);
  340. if (!rc &&
  341. device->state == DASD_STATE_BASIC &&
  342. device->target >= DASD_STATE_READY)
  343. rc = dasd_state_basic_to_ready(device);
  344. if (!rc &&
  345. device->state == DASD_STATE_UNFMT &&
  346. device->target > DASD_STATE_UNFMT)
  347. rc = -EPERM;
  348. if (!rc &&
  349. device->state == DASD_STATE_READY &&
  350. device->target >= DASD_STATE_ONLINE)
  351. rc = dasd_state_ready_to_online(device);
  352. return rc;
  353. }
  354. /*
  355. * Device shutdown state changes.
  356. */
  357. static int dasd_decrease_state(struct dasd_device *device)
  358. {
  359. int rc;
  360. rc = 0;
  361. if (device->state == DASD_STATE_ONLINE &&
  362. device->target <= DASD_STATE_READY)
  363. rc = dasd_state_online_to_ready(device);
  364. if (!rc &&
  365. device->state == DASD_STATE_READY &&
  366. device->target <= DASD_STATE_BASIC)
  367. rc = dasd_state_ready_to_basic(device);
  368. if (!rc &&
  369. device->state == DASD_STATE_UNFMT &&
  370. device->target <= DASD_STATE_BASIC)
  371. rc = dasd_state_unfmt_to_basic(device);
  372. if (!rc &&
  373. device->state == DASD_STATE_BASIC &&
  374. device->target <= DASD_STATE_KNOWN)
  375. rc = dasd_state_basic_to_known(device);
  376. if (!rc &&
  377. device->state == DASD_STATE_KNOWN &&
  378. device->target <= DASD_STATE_NEW)
  379. rc = dasd_state_known_to_new(device);
  380. return rc;
  381. }
  382. /*
  383. * This is the main startup/shutdown routine.
  384. */
  385. static void dasd_change_state(struct dasd_device *device)
  386. {
  387. int rc;
  388. if (device->state == device->target)
  389. /* Already where we want to go today... */
  390. return;
  391. if (device->state < device->target)
  392. rc = dasd_increase_state(device);
  393. else
  394. rc = dasd_decrease_state(device);
  395. if (rc && rc != -EAGAIN)
  396. device->target = device->state;
  397. if (device->state == device->target)
  398. wake_up(&dasd_init_waitq);
  399. /* let user-space know that the device status changed */
  400. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  401. }
  402. /*
  403. * Kick starter for devices that did not complete the startup/shutdown
  404. * procedure or were sleeping because of a pending state.
  405. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  406. * event daemon.
  407. */
  408. static void do_kick_device(struct work_struct *work)
  409. {
  410. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  411. dasd_change_state(device);
  412. dasd_schedule_device_bh(device);
  413. dasd_put_device(device);
  414. }
  415. void dasd_kick_device(struct dasd_device *device)
  416. {
  417. dasd_get_device(device);
  418. /* queue call to dasd_kick_device to the kernel event daemon. */
  419. schedule_work(&device->kick_work);
  420. }
  421. /*
  422. * Set the target state for a device and starts the state change.
  423. */
  424. void dasd_set_target_state(struct dasd_device *device, int target)
  425. {
  426. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  427. if (dasd_probeonly && target > DASD_STATE_READY)
  428. target = DASD_STATE_READY;
  429. if (device->target != target) {
  430. if (device->state == target)
  431. wake_up(&dasd_init_waitq);
  432. device->target = target;
  433. }
  434. if (device->state != device->target)
  435. dasd_change_state(device);
  436. }
  437. /*
  438. * Enable devices with device numbers in [from..to].
  439. */
  440. static inline int _wait_for_device(struct dasd_device *device)
  441. {
  442. return (device->state == device->target);
  443. }
  444. void dasd_enable_device(struct dasd_device *device)
  445. {
  446. dasd_set_target_state(device, DASD_STATE_ONLINE);
  447. if (device->state <= DASD_STATE_KNOWN)
  448. /* No discipline for device found. */
  449. dasd_set_target_state(device, DASD_STATE_NEW);
  450. /* Now wait for the devices to come up. */
  451. wait_event(dasd_init_waitq, _wait_for_device(device));
  452. }
  453. /*
  454. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  455. */
  456. #ifdef CONFIG_DASD_PROFILE
  457. struct dasd_profile_info_t dasd_global_profile;
  458. unsigned int dasd_profile_level = DASD_PROFILE_OFF;
  459. /*
  460. * Increments counter in global and local profiling structures.
  461. */
  462. #define dasd_profile_counter(value, counter, block) \
  463. { \
  464. int index; \
  465. for (index = 0; index < 31 && value >> (2+index); index++); \
  466. dasd_global_profile.counter[index]++; \
  467. block->profile.counter[index]++; \
  468. }
  469. /*
  470. * Add profiling information for cqr before execution.
  471. */
  472. static void dasd_profile_start(struct dasd_block *block,
  473. struct dasd_ccw_req *cqr,
  474. struct request *req)
  475. {
  476. struct list_head *l;
  477. unsigned int counter;
  478. if (dasd_profile_level != DASD_PROFILE_ON)
  479. return;
  480. /* count the length of the chanq for statistics */
  481. counter = 0;
  482. list_for_each(l, &block->ccw_queue)
  483. if (++counter >= 31)
  484. break;
  485. dasd_global_profile.dasd_io_nr_req[counter]++;
  486. block->profile.dasd_io_nr_req[counter]++;
  487. }
  488. /*
  489. * Add profiling information for cqr after execution.
  490. */
  491. static void dasd_profile_end(struct dasd_block *block,
  492. struct dasd_ccw_req *cqr,
  493. struct request *req)
  494. {
  495. long strtime, irqtime, endtime, tottime; /* in microseconds */
  496. long tottimeps, sectors;
  497. if (dasd_profile_level != DASD_PROFILE_ON)
  498. return;
  499. sectors = req->nr_sectors;
  500. if (!cqr->buildclk || !cqr->startclk ||
  501. !cqr->stopclk || !cqr->endclk ||
  502. !sectors)
  503. return;
  504. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  505. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  506. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  507. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  508. tottimeps = tottime / sectors;
  509. if (!dasd_global_profile.dasd_io_reqs)
  510. memset(&dasd_global_profile, 0,
  511. sizeof(struct dasd_profile_info_t));
  512. dasd_global_profile.dasd_io_reqs++;
  513. dasd_global_profile.dasd_io_sects += sectors;
  514. if (!block->profile.dasd_io_reqs)
  515. memset(&block->profile, 0,
  516. sizeof(struct dasd_profile_info_t));
  517. block->profile.dasd_io_reqs++;
  518. block->profile.dasd_io_sects += sectors;
  519. dasd_profile_counter(sectors, dasd_io_secs, block);
  520. dasd_profile_counter(tottime, dasd_io_times, block);
  521. dasd_profile_counter(tottimeps, dasd_io_timps, block);
  522. dasd_profile_counter(strtime, dasd_io_time1, block);
  523. dasd_profile_counter(irqtime, dasd_io_time2, block);
  524. dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
  525. dasd_profile_counter(endtime, dasd_io_time3, block);
  526. }
  527. #else
  528. #define dasd_profile_start(block, cqr, req) do {} while (0)
  529. #define dasd_profile_end(block, cqr, req) do {} while (0)
  530. #endif /* CONFIG_DASD_PROFILE */
  531. /*
  532. * Allocate memory for a channel program with 'cplength' channel
  533. * command words and 'datasize' additional space. There are two
  534. * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
  535. * memory and 2) dasd_smalloc_request uses the static ccw memory
  536. * that gets allocated for each device.
  537. */
  538. struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
  539. int datasize,
  540. struct dasd_device *device)
  541. {
  542. struct dasd_ccw_req *cqr;
  543. /* Sanity checks */
  544. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  545. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  546. cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
  547. if (cqr == NULL)
  548. return ERR_PTR(-ENOMEM);
  549. cqr->cpaddr = NULL;
  550. if (cplength > 0) {
  551. cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  552. GFP_ATOMIC | GFP_DMA);
  553. if (cqr->cpaddr == NULL) {
  554. kfree(cqr);
  555. return ERR_PTR(-ENOMEM);
  556. }
  557. }
  558. cqr->data = NULL;
  559. if (datasize > 0) {
  560. cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
  561. if (cqr->data == NULL) {
  562. kfree(cqr->cpaddr);
  563. kfree(cqr);
  564. return ERR_PTR(-ENOMEM);
  565. }
  566. }
  567. strncpy((char *) &cqr->magic, magic, 4);
  568. ASCEBC((char *) &cqr->magic, 4);
  569. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  570. dasd_get_device(device);
  571. return cqr;
  572. }
  573. struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
  574. int datasize,
  575. struct dasd_device *device)
  576. {
  577. unsigned long flags;
  578. struct dasd_ccw_req *cqr;
  579. char *data;
  580. int size;
  581. /* Sanity checks */
  582. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  583. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  584. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  585. if (cplength > 0)
  586. size += cplength * sizeof(struct ccw1);
  587. if (datasize > 0)
  588. size += datasize;
  589. spin_lock_irqsave(&device->mem_lock, flags);
  590. cqr = (struct dasd_ccw_req *)
  591. dasd_alloc_chunk(&device->ccw_chunks, size);
  592. spin_unlock_irqrestore(&device->mem_lock, flags);
  593. if (cqr == NULL)
  594. return ERR_PTR(-ENOMEM);
  595. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  596. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  597. cqr->cpaddr = NULL;
  598. if (cplength > 0) {
  599. cqr->cpaddr = (struct ccw1 *) data;
  600. data += cplength*sizeof(struct ccw1);
  601. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  602. }
  603. cqr->data = NULL;
  604. if (datasize > 0) {
  605. cqr->data = data;
  606. memset(cqr->data, 0, datasize);
  607. }
  608. strncpy((char *) &cqr->magic, magic, 4);
  609. ASCEBC((char *) &cqr->magic, 4);
  610. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  611. dasd_get_device(device);
  612. return cqr;
  613. }
  614. /*
  615. * Free memory of a channel program. This function needs to free all the
  616. * idal lists that might have been created by dasd_set_cda and the
  617. * struct dasd_ccw_req itself.
  618. */
  619. void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  620. {
  621. #ifdef CONFIG_64BIT
  622. struct ccw1 *ccw;
  623. /* Clear any idals used for the request. */
  624. ccw = cqr->cpaddr;
  625. do {
  626. clear_normalized_cda(ccw);
  627. } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
  628. #endif
  629. kfree(cqr->cpaddr);
  630. kfree(cqr->data);
  631. kfree(cqr);
  632. dasd_put_device(device);
  633. }
  634. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  635. {
  636. unsigned long flags;
  637. spin_lock_irqsave(&device->mem_lock, flags);
  638. dasd_free_chunk(&device->ccw_chunks, cqr);
  639. spin_unlock_irqrestore(&device->mem_lock, flags);
  640. dasd_put_device(device);
  641. }
  642. /*
  643. * Check discipline magic in cqr.
  644. */
  645. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  646. {
  647. struct dasd_device *device;
  648. if (cqr == NULL)
  649. return -EINVAL;
  650. device = cqr->startdev;
  651. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  652. DEV_MESSAGE(KERN_WARNING, device,
  653. " dasd_ccw_req 0x%08x magic doesn't match"
  654. " discipline 0x%08x",
  655. cqr->magic,
  656. *(unsigned int *) device->discipline->name);
  657. return -EINVAL;
  658. }
  659. return 0;
  660. }
  661. /*
  662. * Terminate the current i/o and set the request to clear_pending.
  663. * Timer keeps device runnig.
  664. * ccw_device_clear can fail if the i/o subsystem
  665. * is in a bad mood.
  666. */
  667. int dasd_term_IO(struct dasd_ccw_req *cqr)
  668. {
  669. struct dasd_device *device;
  670. int retries, rc;
  671. /* Check the cqr */
  672. rc = dasd_check_cqr(cqr);
  673. if (rc)
  674. return rc;
  675. retries = 0;
  676. device = (struct dasd_device *) cqr->startdev;
  677. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  678. rc = ccw_device_clear(device->cdev, (long) cqr);
  679. switch (rc) {
  680. case 0: /* termination successful */
  681. cqr->retries--;
  682. cqr->status = DASD_CQR_CLEAR_PENDING;
  683. cqr->stopclk = get_clock();
  684. cqr->starttime = 0;
  685. DBF_DEV_EVENT(DBF_DEBUG, device,
  686. "terminate cqr %p successful",
  687. cqr);
  688. break;
  689. case -ENODEV:
  690. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  691. "device gone, retry");
  692. break;
  693. case -EIO:
  694. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  695. "I/O error, retry");
  696. break;
  697. case -EINVAL:
  698. case -EBUSY:
  699. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  700. "device busy, retry later");
  701. break;
  702. default:
  703. DEV_MESSAGE(KERN_ERR, device,
  704. "line %d unknown RC=%d, please "
  705. "report to linux390@de.ibm.com",
  706. __LINE__, rc);
  707. BUG();
  708. break;
  709. }
  710. retries++;
  711. }
  712. dasd_schedule_device_bh(device);
  713. return rc;
  714. }
  715. /*
  716. * Start the i/o. This start_IO can fail if the channel is really busy.
  717. * In that case set up a timer to start the request later.
  718. */
  719. int dasd_start_IO(struct dasd_ccw_req *cqr)
  720. {
  721. struct dasd_device *device;
  722. int rc;
  723. /* Check the cqr */
  724. rc = dasd_check_cqr(cqr);
  725. if (rc)
  726. return rc;
  727. device = (struct dasd_device *) cqr->startdev;
  728. if (cqr->retries < 0) {
  729. DEV_MESSAGE(KERN_DEBUG, device,
  730. "start_IO: request %p (%02x/%i) - no retry left.",
  731. cqr, cqr->status, cqr->retries);
  732. cqr->status = DASD_CQR_ERROR;
  733. return -EIO;
  734. }
  735. cqr->startclk = get_clock();
  736. cqr->starttime = jiffies;
  737. cqr->retries--;
  738. rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
  739. cqr->lpm, 0);
  740. switch (rc) {
  741. case 0:
  742. cqr->status = DASD_CQR_IN_IO;
  743. DBF_DEV_EVENT(DBF_DEBUG, device,
  744. "start_IO: request %p started successful",
  745. cqr);
  746. break;
  747. case -EBUSY:
  748. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  749. "start_IO: device busy, retry later");
  750. break;
  751. case -ETIMEDOUT:
  752. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  753. "start_IO: request timeout, retry later");
  754. break;
  755. case -EACCES:
  756. /* -EACCES indicates that the request used only a
  757. * subset of the available pathes and all these
  758. * pathes are gone.
  759. * Do a retry with all available pathes.
  760. */
  761. cqr->lpm = LPM_ANYPATH;
  762. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  763. "start_IO: selected pathes gone,"
  764. " retry on all pathes");
  765. break;
  766. case -ENODEV:
  767. case -EIO:
  768. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  769. "start_IO: device gone, retry");
  770. break;
  771. default:
  772. DEV_MESSAGE(KERN_ERR, device,
  773. "line %d unknown RC=%d, please report"
  774. " to linux390@de.ibm.com", __LINE__, rc);
  775. BUG();
  776. break;
  777. }
  778. return rc;
  779. }
  780. /*
  781. * Timeout function for dasd devices. This is used for different purposes
  782. * 1) missing interrupt handler for normal operation
  783. * 2) delayed start of request where start_IO failed with -EBUSY
  784. * 3) timeout for missing state change interrupts
  785. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  786. * DASD_CQR_QUEUED for 2) and 3).
  787. */
  788. static void dasd_device_timeout(unsigned long ptr)
  789. {
  790. unsigned long flags;
  791. struct dasd_device *device;
  792. device = (struct dasd_device *) ptr;
  793. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  794. /* re-activate request queue */
  795. device->stopped &= ~DASD_STOPPED_PENDING;
  796. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  797. dasd_schedule_device_bh(device);
  798. }
  799. /*
  800. * Setup timeout for a device in jiffies.
  801. */
  802. void dasd_device_set_timer(struct dasd_device *device, int expires)
  803. {
  804. if (expires == 0) {
  805. if (timer_pending(&device->timer))
  806. del_timer(&device->timer);
  807. return;
  808. }
  809. if (timer_pending(&device->timer)) {
  810. if (mod_timer(&device->timer, jiffies + expires))
  811. return;
  812. }
  813. device->timer.function = dasd_device_timeout;
  814. device->timer.data = (unsigned long) device;
  815. device->timer.expires = jiffies + expires;
  816. add_timer(&device->timer);
  817. }
  818. /*
  819. * Clear timeout for a device.
  820. */
  821. void dasd_device_clear_timer(struct dasd_device *device)
  822. {
  823. if (timer_pending(&device->timer))
  824. del_timer(&device->timer);
  825. }
  826. static void dasd_handle_killed_request(struct ccw_device *cdev,
  827. unsigned long intparm)
  828. {
  829. struct dasd_ccw_req *cqr;
  830. struct dasd_device *device;
  831. cqr = (struct dasd_ccw_req *) intparm;
  832. if (cqr->status != DASD_CQR_IN_IO) {
  833. MESSAGE(KERN_DEBUG,
  834. "invalid status in handle_killed_request: "
  835. "bus_id %s, status %02x",
  836. cdev->dev.bus_id, cqr->status);
  837. return;
  838. }
  839. device = (struct dasd_device *) cqr->startdev;
  840. if (device == NULL ||
  841. device != dasd_device_from_cdev_locked(cdev) ||
  842. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  843. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  844. cdev->dev.bus_id);
  845. return;
  846. }
  847. /* Schedule request to be retried. */
  848. cqr->status = DASD_CQR_QUEUED;
  849. dasd_device_clear_timer(device);
  850. dasd_schedule_device_bh(device);
  851. dasd_put_device(device);
  852. }
  853. void dasd_generic_handle_state_change(struct dasd_device *device)
  854. {
  855. /* First of all start sense subsystem status request. */
  856. dasd_eer_snss(device);
  857. device->stopped &= ~DASD_STOPPED_PENDING;
  858. dasd_schedule_device_bh(device);
  859. if (device->block)
  860. dasd_schedule_block_bh(device->block);
  861. }
  862. /*
  863. * Interrupt handler for "normal" ssch-io based dasd devices.
  864. */
  865. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  866. struct irb *irb)
  867. {
  868. struct dasd_ccw_req *cqr, *next;
  869. struct dasd_device *device;
  870. unsigned long long now;
  871. int expires;
  872. if (IS_ERR(irb)) {
  873. switch (PTR_ERR(irb)) {
  874. case -EIO:
  875. dasd_handle_killed_request(cdev, intparm);
  876. break;
  877. case -ETIMEDOUT:
  878. printk(KERN_WARNING"%s(%s): request timed out\n",
  879. __FUNCTION__, cdev->dev.bus_id);
  880. //FIXME - dasd uses own timeout interface...
  881. break;
  882. default:
  883. printk(KERN_WARNING"%s(%s): unknown error %ld\n",
  884. __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
  885. }
  886. return;
  887. }
  888. now = get_clock();
  889. DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
  890. cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
  891. (unsigned int) intparm);
  892. /* check for unsolicited interrupts */
  893. cqr = (struct dasd_ccw_req *) intparm;
  894. if (!cqr || ((irb->scsw.cc == 1) &&
  895. (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
  896. (irb->scsw.stctl & SCSW_STCTL_STATUS_PEND)) ) {
  897. if (cqr && cqr->status == DASD_CQR_IN_IO)
  898. cqr->status = DASD_CQR_QUEUED;
  899. device = dasd_device_from_cdev_locked(cdev);
  900. if (!IS_ERR(device)) {
  901. dasd_device_clear_timer(device);
  902. device->discipline->handle_unsolicited_interrupt(device,
  903. irb);
  904. dasd_put_device(device);
  905. }
  906. return;
  907. }
  908. device = (struct dasd_device *) cqr->startdev;
  909. if (!device ||
  910. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  911. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  912. cdev->dev.bus_id);
  913. return;
  914. }
  915. /* Check for clear pending */
  916. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  917. irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
  918. cqr->status = DASD_CQR_CLEARED;
  919. dasd_device_clear_timer(device);
  920. wake_up(&dasd_flush_wq);
  921. dasd_schedule_device_bh(device);
  922. return;
  923. }
  924. /* check status - the request might have been killed by dyn detach */
  925. if (cqr->status != DASD_CQR_IN_IO) {
  926. MESSAGE(KERN_DEBUG,
  927. "invalid status: bus_id %s, status %02x",
  928. cdev->dev.bus_id, cqr->status);
  929. return;
  930. }
  931. DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
  932. ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
  933. next = NULL;
  934. expires = 0;
  935. if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  936. irb->scsw.cstat == 0 && !irb->esw.esw0.erw.cons) {
  937. /* request was completed successfully */
  938. cqr->status = DASD_CQR_SUCCESS;
  939. cqr->stopclk = now;
  940. /* Start first request on queue if possible -> fast_io. */
  941. if (cqr->devlist.next != &device->ccw_queue) {
  942. next = list_entry(cqr->devlist.next,
  943. struct dasd_ccw_req, devlist);
  944. }
  945. } else { /* error */
  946. memcpy(&cqr->irb, irb, sizeof(struct irb));
  947. if (device->features & DASD_FEATURE_ERPLOG) {
  948. dasd_log_sense(cqr, irb);
  949. }
  950. /* If we have no sense data, or we just don't want complex ERP
  951. * for this request, but if we have retries left, then just
  952. * reset this request and retry it in the fastpath
  953. */
  954. if (!(cqr->irb.esw.esw0.erw.cons &&
  955. test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) &&
  956. cqr->retries > 0) {
  957. DEV_MESSAGE(KERN_DEBUG, device,
  958. "default ERP in fastpath (%i retries left)",
  959. cqr->retries);
  960. cqr->lpm = LPM_ANYPATH;
  961. cqr->status = DASD_CQR_QUEUED;
  962. next = cqr;
  963. } else
  964. cqr->status = DASD_CQR_ERROR;
  965. }
  966. if (next && (next->status == DASD_CQR_QUEUED) &&
  967. (!device->stopped)) {
  968. if (device->discipline->start_IO(next) == 0)
  969. expires = next->expires;
  970. else
  971. DEV_MESSAGE(KERN_DEBUG, device, "%s",
  972. "Interrupt fastpath "
  973. "failed!");
  974. }
  975. if (expires != 0)
  976. dasd_device_set_timer(device, expires);
  977. else
  978. dasd_device_clear_timer(device);
  979. dasd_schedule_device_bh(device);
  980. }
  981. /*
  982. * If we have an error on a dasd_block layer request then we cancel
  983. * and return all further requests from the same dasd_block as well.
  984. */
  985. static void __dasd_device_recovery(struct dasd_device *device,
  986. struct dasd_ccw_req *ref_cqr)
  987. {
  988. struct list_head *l, *n;
  989. struct dasd_ccw_req *cqr;
  990. /*
  991. * only requeue request that came from the dasd_block layer
  992. */
  993. if (!ref_cqr->block)
  994. return;
  995. list_for_each_safe(l, n, &device->ccw_queue) {
  996. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  997. if (cqr->status == DASD_CQR_QUEUED &&
  998. ref_cqr->block == cqr->block) {
  999. cqr->status = DASD_CQR_CLEARED;
  1000. }
  1001. }
  1002. };
  1003. /*
  1004. * Remove those ccw requests from the queue that need to be returned
  1005. * to the upper layer.
  1006. */
  1007. static void __dasd_device_process_ccw_queue(struct dasd_device *device,
  1008. struct list_head *final_queue)
  1009. {
  1010. struct list_head *l, *n;
  1011. struct dasd_ccw_req *cqr;
  1012. /* Process request with final status. */
  1013. list_for_each_safe(l, n, &device->ccw_queue) {
  1014. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1015. /* Stop list processing at the first non-final request. */
  1016. if (cqr->status == DASD_CQR_QUEUED ||
  1017. cqr->status == DASD_CQR_IN_IO ||
  1018. cqr->status == DASD_CQR_CLEAR_PENDING)
  1019. break;
  1020. if (cqr->status == DASD_CQR_ERROR) {
  1021. __dasd_device_recovery(device, cqr);
  1022. }
  1023. /* Rechain finished requests to final queue */
  1024. list_move_tail(&cqr->devlist, final_queue);
  1025. }
  1026. }
  1027. /*
  1028. * the cqrs from the final queue are returned to the upper layer
  1029. * by setting a dasd_block state and calling the callback function
  1030. */
  1031. static void __dasd_device_process_final_queue(struct dasd_device *device,
  1032. struct list_head *final_queue)
  1033. {
  1034. struct list_head *l, *n;
  1035. struct dasd_ccw_req *cqr;
  1036. list_for_each_safe(l, n, final_queue) {
  1037. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1038. list_del_init(&cqr->devlist);
  1039. if (cqr->block)
  1040. spin_lock_bh(&cqr->block->queue_lock);
  1041. switch (cqr->status) {
  1042. case DASD_CQR_SUCCESS:
  1043. cqr->status = DASD_CQR_DONE;
  1044. break;
  1045. case DASD_CQR_ERROR:
  1046. cqr->status = DASD_CQR_NEED_ERP;
  1047. break;
  1048. case DASD_CQR_CLEARED:
  1049. cqr->status = DASD_CQR_TERMINATED;
  1050. break;
  1051. default:
  1052. DEV_MESSAGE(KERN_ERR, device,
  1053. "wrong cqr status in __dasd_process_final_queue "
  1054. "for cqr %p, status %x",
  1055. cqr, cqr->status);
  1056. BUG();
  1057. }
  1058. if (cqr->block)
  1059. spin_unlock_bh(&cqr->block->queue_lock);
  1060. if (cqr->callback != NULL)
  1061. (cqr->callback)(cqr, cqr->callback_data);
  1062. }
  1063. }
  1064. /*
  1065. * Take a look at the first request on the ccw queue and check
  1066. * if it reached its expire time. If so, terminate the IO.
  1067. */
  1068. static void __dasd_device_check_expire(struct dasd_device *device)
  1069. {
  1070. struct dasd_ccw_req *cqr;
  1071. if (list_empty(&device->ccw_queue))
  1072. return;
  1073. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1074. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1075. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1076. if (device->discipline->term_IO(cqr) != 0) {
  1077. /* Hmpf, try again in 5 sec */
  1078. DEV_MESSAGE(KERN_ERR, device,
  1079. "internal error - timeout (%is) expired "
  1080. "for cqr %p, termination failed, "
  1081. "retrying in 5s",
  1082. (cqr->expires/HZ), cqr);
  1083. cqr->expires += 5*HZ;
  1084. dasd_device_set_timer(device, 5*HZ);
  1085. } else {
  1086. DEV_MESSAGE(KERN_ERR, device,
  1087. "internal error - timeout (%is) expired "
  1088. "for cqr %p (%i retries left)",
  1089. (cqr->expires/HZ), cqr, cqr->retries);
  1090. }
  1091. }
  1092. }
  1093. /*
  1094. * Take a look at the first request on the ccw queue and check
  1095. * if it needs to be started.
  1096. */
  1097. static void __dasd_device_start_head(struct dasd_device *device)
  1098. {
  1099. struct dasd_ccw_req *cqr;
  1100. int rc;
  1101. if (list_empty(&device->ccw_queue))
  1102. return;
  1103. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1104. if (cqr->status != DASD_CQR_QUEUED)
  1105. return;
  1106. /* when device is stopped, return request to previous layer */
  1107. if (device->stopped) {
  1108. cqr->status = DASD_CQR_CLEARED;
  1109. dasd_schedule_device_bh(device);
  1110. return;
  1111. }
  1112. rc = device->discipline->start_IO(cqr);
  1113. if (rc == 0)
  1114. dasd_device_set_timer(device, cqr->expires);
  1115. else if (rc == -EACCES) {
  1116. dasd_schedule_device_bh(device);
  1117. } else
  1118. /* Hmpf, try again in 1/2 sec */
  1119. dasd_device_set_timer(device, 50);
  1120. }
  1121. /*
  1122. * Go through all request on the dasd_device request queue,
  1123. * terminate them on the cdev if necessary, and return them to the
  1124. * submitting layer via callback.
  1125. * Note:
  1126. * Make sure that all 'submitting layers' still exist when
  1127. * this function is called!. In other words, when 'device' is a base
  1128. * device then all block layer requests must have been removed before
  1129. * via dasd_flush_block_queue.
  1130. */
  1131. int dasd_flush_device_queue(struct dasd_device *device)
  1132. {
  1133. struct dasd_ccw_req *cqr, *n;
  1134. int rc;
  1135. struct list_head flush_queue;
  1136. INIT_LIST_HEAD(&flush_queue);
  1137. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1138. rc = 0;
  1139. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1140. /* Check status and move request to flush_queue */
  1141. switch (cqr->status) {
  1142. case DASD_CQR_IN_IO:
  1143. rc = device->discipline->term_IO(cqr);
  1144. if (rc) {
  1145. /* unable to terminate requeust */
  1146. DEV_MESSAGE(KERN_ERR, device,
  1147. "dasd flush ccw_queue is unable "
  1148. " to terminate request %p",
  1149. cqr);
  1150. /* stop flush processing */
  1151. goto finished;
  1152. }
  1153. break;
  1154. case DASD_CQR_QUEUED:
  1155. cqr->stopclk = get_clock();
  1156. cqr->status = DASD_CQR_CLEARED;
  1157. break;
  1158. default: /* no need to modify the others */
  1159. break;
  1160. }
  1161. list_move_tail(&cqr->devlist, &flush_queue);
  1162. }
  1163. finished:
  1164. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1165. /*
  1166. * After this point all requests must be in state CLEAR_PENDING,
  1167. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1168. * one of the others.
  1169. */
  1170. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1171. wait_event(dasd_flush_wq,
  1172. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1173. /*
  1174. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1175. * and call the callback function of flushed requests
  1176. */
  1177. __dasd_device_process_final_queue(device, &flush_queue);
  1178. return rc;
  1179. }
  1180. /*
  1181. * Acquire the device lock and process queues for the device.
  1182. */
  1183. static void dasd_device_tasklet(struct dasd_device *device)
  1184. {
  1185. struct list_head final_queue;
  1186. atomic_set (&device->tasklet_scheduled, 0);
  1187. INIT_LIST_HEAD(&final_queue);
  1188. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1189. /* Check expire time of first request on the ccw queue. */
  1190. __dasd_device_check_expire(device);
  1191. /* find final requests on ccw queue */
  1192. __dasd_device_process_ccw_queue(device, &final_queue);
  1193. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1194. /* Now call the callback function of requests with final status */
  1195. __dasd_device_process_final_queue(device, &final_queue);
  1196. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1197. /* Now check if the head of the ccw queue needs to be started. */
  1198. __dasd_device_start_head(device);
  1199. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1200. dasd_put_device(device);
  1201. }
  1202. /*
  1203. * Schedules a call to dasd_tasklet over the device tasklet.
  1204. */
  1205. void dasd_schedule_device_bh(struct dasd_device *device)
  1206. {
  1207. /* Protect against rescheduling. */
  1208. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1209. return;
  1210. dasd_get_device(device);
  1211. tasklet_hi_schedule(&device->tasklet);
  1212. }
  1213. /*
  1214. * Queue a request to the head of the device ccw_queue.
  1215. * Start the I/O if possible.
  1216. */
  1217. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1218. {
  1219. struct dasd_device *device;
  1220. unsigned long flags;
  1221. device = cqr->startdev;
  1222. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1223. cqr->status = DASD_CQR_QUEUED;
  1224. list_add(&cqr->devlist, &device->ccw_queue);
  1225. /* let the bh start the request to keep them in order */
  1226. dasd_schedule_device_bh(device);
  1227. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1228. }
  1229. /*
  1230. * Queue a request to the tail of the device ccw_queue.
  1231. * Start the I/O if possible.
  1232. */
  1233. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1234. {
  1235. struct dasd_device *device;
  1236. unsigned long flags;
  1237. device = cqr->startdev;
  1238. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1239. cqr->status = DASD_CQR_QUEUED;
  1240. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1241. /* let the bh start the request to keep them in order */
  1242. dasd_schedule_device_bh(device);
  1243. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1244. }
  1245. /*
  1246. * Wakeup helper for the 'sleep_on' functions.
  1247. */
  1248. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1249. {
  1250. wake_up((wait_queue_head_t *) data);
  1251. }
  1252. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1253. {
  1254. struct dasd_device *device;
  1255. int rc;
  1256. device = cqr->startdev;
  1257. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1258. rc = ((cqr->status == DASD_CQR_DONE ||
  1259. cqr->status == DASD_CQR_NEED_ERP ||
  1260. cqr->status == DASD_CQR_TERMINATED) &&
  1261. list_empty(&cqr->devlist));
  1262. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1263. return rc;
  1264. }
  1265. /*
  1266. * Queue a request to the tail of the device ccw_queue and wait for
  1267. * it's completion.
  1268. */
  1269. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1270. {
  1271. wait_queue_head_t wait_q;
  1272. struct dasd_device *device;
  1273. int rc;
  1274. device = cqr->startdev;
  1275. init_waitqueue_head (&wait_q);
  1276. cqr->callback = dasd_wakeup_cb;
  1277. cqr->callback_data = (void *) &wait_q;
  1278. dasd_add_request_tail(cqr);
  1279. wait_event(wait_q, _wait_for_wakeup(cqr));
  1280. /* Request status is either done or failed. */
  1281. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1282. return rc;
  1283. }
  1284. /*
  1285. * Queue a request to the tail of the device ccw_queue and wait
  1286. * interruptible for it's completion.
  1287. */
  1288. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1289. {
  1290. wait_queue_head_t wait_q;
  1291. struct dasd_device *device;
  1292. int rc;
  1293. device = cqr->startdev;
  1294. init_waitqueue_head (&wait_q);
  1295. cqr->callback = dasd_wakeup_cb;
  1296. cqr->callback_data = (void *) &wait_q;
  1297. dasd_add_request_tail(cqr);
  1298. rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
  1299. if (rc == -ERESTARTSYS) {
  1300. dasd_cancel_req(cqr);
  1301. /* wait (non-interruptible) for final status */
  1302. wait_event(wait_q, _wait_for_wakeup(cqr));
  1303. }
  1304. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1305. return rc;
  1306. }
  1307. /*
  1308. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1309. * for eckd devices) the currently running request has to be terminated
  1310. * and be put back to status queued, before the special request is added
  1311. * to the head of the queue. Then the special request is waited on normally.
  1312. */
  1313. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1314. {
  1315. struct dasd_ccw_req *cqr;
  1316. if (list_empty(&device->ccw_queue))
  1317. return 0;
  1318. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1319. return device->discipline->term_IO(cqr);
  1320. }
  1321. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1322. {
  1323. wait_queue_head_t wait_q;
  1324. struct dasd_device *device;
  1325. int rc;
  1326. device = cqr->startdev;
  1327. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1328. rc = _dasd_term_running_cqr(device);
  1329. if (rc) {
  1330. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1331. return rc;
  1332. }
  1333. init_waitqueue_head (&wait_q);
  1334. cqr->callback = dasd_wakeup_cb;
  1335. cqr->callback_data = (void *) &wait_q;
  1336. cqr->status = DASD_CQR_QUEUED;
  1337. list_add(&cqr->devlist, &device->ccw_queue);
  1338. /* let the bh start the request to keep them in order */
  1339. dasd_schedule_device_bh(device);
  1340. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1341. wait_event(wait_q, _wait_for_wakeup(cqr));
  1342. /* Request status is either done or failed. */
  1343. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1344. return rc;
  1345. }
  1346. /*
  1347. * Cancels a request that was started with dasd_sleep_on_req.
  1348. * This is useful to timeout requests. The request will be
  1349. * terminated if it is currently in i/o.
  1350. * Returns 1 if the request has been terminated.
  1351. * 0 if there was no need to terminate the request (not started yet)
  1352. * negative error code if termination failed
  1353. * Cancellation of a request is an asynchronous operation! The calling
  1354. * function has to wait until the request is properly returned via callback.
  1355. */
  1356. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1357. {
  1358. struct dasd_device *device = cqr->startdev;
  1359. unsigned long flags;
  1360. int rc;
  1361. rc = 0;
  1362. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1363. switch (cqr->status) {
  1364. case DASD_CQR_QUEUED:
  1365. /* request was not started - just set to cleared */
  1366. cqr->status = DASD_CQR_CLEARED;
  1367. break;
  1368. case DASD_CQR_IN_IO:
  1369. /* request in IO - terminate IO and release again */
  1370. rc = device->discipline->term_IO(cqr);
  1371. if (rc) {
  1372. DEV_MESSAGE(KERN_ERR, device,
  1373. "dasd_cancel_req is unable "
  1374. " to terminate request %p, rc = %d",
  1375. cqr, rc);
  1376. } else {
  1377. cqr->stopclk = get_clock();
  1378. rc = 1;
  1379. }
  1380. break;
  1381. default: /* already finished or clear pending - do nothing */
  1382. break;
  1383. }
  1384. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1385. dasd_schedule_device_bh(device);
  1386. return rc;
  1387. }
  1388. /*
  1389. * SECTION: Operations of the dasd_block layer.
  1390. */
  1391. /*
  1392. * Timeout function for dasd_block. This is used when the block layer
  1393. * is waiting for something that may not come reliably, (e.g. a state
  1394. * change interrupt)
  1395. */
  1396. static void dasd_block_timeout(unsigned long ptr)
  1397. {
  1398. unsigned long flags;
  1399. struct dasd_block *block;
  1400. block = (struct dasd_block *) ptr;
  1401. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  1402. /* re-activate request queue */
  1403. block->base->stopped &= ~DASD_STOPPED_PENDING;
  1404. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  1405. dasd_schedule_block_bh(block);
  1406. }
  1407. /*
  1408. * Setup timeout for a dasd_block in jiffies.
  1409. */
  1410. void dasd_block_set_timer(struct dasd_block *block, int expires)
  1411. {
  1412. if (expires == 0) {
  1413. if (timer_pending(&block->timer))
  1414. del_timer(&block->timer);
  1415. return;
  1416. }
  1417. if (timer_pending(&block->timer)) {
  1418. if (mod_timer(&block->timer, jiffies + expires))
  1419. return;
  1420. }
  1421. block->timer.function = dasd_block_timeout;
  1422. block->timer.data = (unsigned long) block;
  1423. block->timer.expires = jiffies + expires;
  1424. add_timer(&block->timer);
  1425. }
  1426. /*
  1427. * Clear timeout for a dasd_block.
  1428. */
  1429. void dasd_block_clear_timer(struct dasd_block *block)
  1430. {
  1431. if (timer_pending(&block->timer))
  1432. del_timer(&block->timer);
  1433. }
  1434. /*
  1435. * posts the buffer_cache about a finalized request
  1436. */
  1437. static inline void dasd_end_request(struct request *req, int error)
  1438. {
  1439. if (__blk_end_request(req, error, blk_rq_bytes(req)))
  1440. BUG();
  1441. }
  1442. /*
  1443. * Process finished error recovery ccw.
  1444. */
  1445. static inline void __dasd_block_process_erp(struct dasd_block *block,
  1446. struct dasd_ccw_req *cqr)
  1447. {
  1448. dasd_erp_fn_t erp_fn;
  1449. struct dasd_device *device = block->base;
  1450. if (cqr->status == DASD_CQR_DONE)
  1451. DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
  1452. else
  1453. DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
  1454. erp_fn = device->discipline->erp_postaction(cqr);
  1455. erp_fn(cqr);
  1456. }
  1457. /*
  1458. * Fetch requests from the block device queue.
  1459. */
  1460. static void __dasd_process_request_queue(struct dasd_block *block)
  1461. {
  1462. struct request_queue *queue;
  1463. struct request *req;
  1464. struct dasd_ccw_req *cqr;
  1465. struct dasd_device *basedev;
  1466. unsigned long flags;
  1467. queue = block->request_queue;
  1468. basedev = block->base;
  1469. /* No queue ? Then there is nothing to do. */
  1470. if (queue == NULL)
  1471. return;
  1472. /*
  1473. * We requeue request from the block device queue to the ccw
  1474. * queue only in two states. In state DASD_STATE_READY the
  1475. * partition detection is done and we need to requeue requests
  1476. * for that. State DASD_STATE_ONLINE is normal block device
  1477. * operation.
  1478. */
  1479. if (basedev->state < DASD_STATE_READY)
  1480. return;
  1481. /* Now we try to fetch requests from the request queue */
  1482. while (!blk_queue_plugged(queue) &&
  1483. elv_next_request(queue)) {
  1484. req = elv_next_request(queue);
  1485. if (basedev->features & DASD_FEATURE_READONLY &&
  1486. rq_data_dir(req) == WRITE) {
  1487. DBF_DEV_EVENT(DBF_ERR, basedev,
  1488. "Rejecting write request %p",
  1489. req);
  1490. blkdev_dequeue_request(req);
  1491. dasd_end_request(req, -EIO);
  1492. continue;
  1493. }
  1494. cqr = basedev->discipline->build_cp(basedev, block, req);
  1495. if (IS_ERR(cqr)) {
  1496. if (PTR_ERR(cqr) == -EBUSY)
  1497. break; /* normal end condition */
  1498. if (PTR_ERR(cqr) == -ENOMEM)
  1499. break; /* terminate request queue loop */
  1500. if (PTR_ERR(cqr) == -EAGAIN) {
  1501. /*
  1502. * The current request cannot be build right
  1503. * now, we have to try later. If this request
  1504. * is the head-of-queue we stop the device
  1505. * for 1/2 second.
  1506. */
  1507. if (!list_empty(&block->ccw_queue))
  1508. break;
  1509. spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
  1510. basedev->stopped |= DASD_STOPPED_PENDING;
  1511. spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
  1512. dasd_block_set_timer(block, HZ/2);
  1513. break;
  1514. }
  1515. DBF_DEV_EVENT(DBF_ERR, basedev,
  1516. "CCW creation failed (rc=%ld) "
  1517. "on request %p",
  1518. PTR_ERR(cqr), req);
  1519. blkdev_dequeue_request(req);
  1520. dasd_end_request(req, -EIO);
  1521. continue;
  1522. }
  1523. /*
  1524. * Note: callback is set to dasd_return_cqr_cb in
  1525. * __dasd_block_start_head to cover erp requests as well
  1526. */
  1527. cqr->callback_data = (void *) req;
  1528. cqr->status = DASD_CQR_FILLED;
  1529. blkdev_dequeue_request(req);
  1530. list_add_tail(&cqr->blocklist, &block->ccw_queue);
  1531. dasd_profile_start(block, cqr, req);
  1532. }
  1533. }
  1534. static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
  1535. {
  1536. struct request *req;
  1537. int status;
  1538. int error = 0;
  1539. req = (struct request *) cqr->callback_data;
  1540. dasd_profile_end(cqr->block, cqr, req);
  1541. status = cqr->memdev->discipline->free_cp(cqr, req);
  1542. if (status <= 0)
  1543. error = status ? status : -EIO;
  1544. dasd_end_request(req, error);
  1545. }
  1546. /*
  1547. * Process ccw request queue.
  1548. */
  1549. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  1550. struct list_head *final_queue)
  1551. {
  1552. struct list_head *l, *n;
  1553. struct dasd_ccw_req *cqr;
  1554. dasd_erp_fn_t erp_fn;
  1555. unsigned long flags;
  1556. struct dasd_device *base = block->base;
  1557. restart:
  1558. /* Process request with final status. */
  1559. list_for_each_safe(l, n, &block->ccw_queue) {
  1560. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1561. if (cqr->status != DASD_CQR_DONE &&
  1562. cqr->status != DASD_CQR_FAILED &&
  1563. cqr->status != DASD_CQR_NEED_ERP &&
  1564. cqr->status != DASD_CQR_TERMINATED)
  1565. continue;
  1566. if (cqr->status == DASD_CQR_TERMINATED) {
  1567. base->discipline->handle_terminated_request(cqr);
  1568. goto restart;
  1569. }
  1570. /* Process requests that may be recovered */
  1571. if (cqr->status == DASD_CQR_NEED_ERP) {
  1572. if (cqr->irb.esw.esw0.erw.cons &&
  1573. test_bit(DASD_CQR_FLAGS_USE_ERP,
  1574. &cqr->flags)) {
  1575. erp_fn = base->discipline->erp_action(cqr);
  1576. erp_fn(cqr);
  1577. }
  1578. goto restart;
  1579. }
  1580. /* First of all call extended error reporting. */
  1581. if (dasd_eer_enabled(base) &&
  1582. cqr->status == DASD_CQR_FAILED) {
  1583. dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
  1584. /* restart request */
  1585. cqr->status = DASD_CQR_FILLED;
  1586. cqr->retries = 255;
  1587. spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
  1588. base->stopped |= DASD_STOPPED_QUIESCE;
  1589. spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
  1590. flags);
  1591. goto restart;
  1592. }
  1593. /* Process finished ERP request. */
  1594. if (cqr->refers) {
  1595. __dasd_block_process_erp(block, cqr);
  1596. goto restart;
  1597. }
  1598. /* Rechain finished requests to final queue */
  1599. cqr->endclk = get_clock();
  1600. list_move_tail(&cqr->blocklist, final_queue);
  1601. }
  1602. }
  1603. static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
  1604. {
  1605. dasd_schedule_block_bh(cqr->block);
  1606. }
  1607. static void __dasd_block_start_head(struct dasd_block *block)
  1608. {
  1609. struct dasd_ccw_req *cqr;
  1610. if (list_empty(&block->ccw_queue))
  1611. return;
  1612. /* We allways begin with the first requests on the queue, as some
  1613. * of previously started requests have to be enqueued on a
  1614. * dasd_device again for error recovery.
  1615. */
  1616. list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
  1617. if (cqr->status != DASD_CQR_FILLED)
  1618. continue;
  1619. /* Non-temporary stop condition will trigger fail fast */
  1620. if (block->base->stopped & ~DASD_STOPPED_PENDING &&
  1621. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  1622. (!dasd_eer_enabled(block->base))) {
  1623. cqr->status = DASD_CQR_FAILED;
  1624. dasd_schedule_block_bh(block);
  1625. continue;
  1626. }
  1627. /* Don't try to start requests if device is stopped */
  1628. if (block->base->stopped)
  1629. return;
  1630. /* just a fail safe check, should not happen */
  1631. if (!cqr->startdev)
  1632. cqr->startdev = block->base;
  1633. /* make sure that the requests we submit find their way back */
  1634. cqr->callback = dasd_return_cqr_cb;
  1635. dasd_add_request_tail(cqr);
  1636. }
  1637. }
  1638. /*
  1639. * Central dasd_block layer routine. Takes requests from the generic
  1640. * block layer request queue, creates ccw requests, enqueues them on
  1641. * a dasd_device and processes ccw requests that have been returned.
  1642. */
  1643. static void dasd_block_tasklet(struct dasd_block *block)
  1644. {
  1645. struct list_head final_queue;
  1646. struct list_head *l, *n;
  1647. struct dasd_ccw_req *cqr;
  1648. atomic_set(&block->tasklet_scheduled, 0);
  1649. INIT_LIST_HEAD(&final_queue);
  1650. spin_lock(&block->queue_lock);
  1651. /* Finish off requests on ccw queue */
  1652. __dasd_process_block_ccw_queue(block, &final_queue);
  1653. spin_unlock(&block->queue_lock);
  1654. /* Now call the callback function of requests with final status */
  1655. spin_lock_irq(&block->request_queue_lock);
  1656. list_for_each_safe(l, n, &final_queue) {
  1657. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1658. list_del_init(&cqr->blocklist);
  1659. __dasd_cleanup_cqr(cqr);
  1660. }
  1661. spin_lock(&block->queue_lock);
  1662. /* Get new request from the block device request queue */
  1663. __dasd_process_request_queue(block);
  1664. /* Now check if the head of the ccw queue needs to be started. */
  1665. __dasd_block_start_head(block);
  1666. spin_unlock(&block->queue_lock);
  1667. spin_unlock_irq(&block->request_queue_lock);
  1668. dasd_put_device(block->base);
  1669. }
  1670. static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
  1671. {
  1672. wake_up(&dasd_flush_wq);
  1673. }
  1674. /*
  1675. * Go through all request on the dasd_block request queue, cancel them
  1676. * on the respective dasd_device, and return them to the generic
  1677. * block layer.
  1678. */
  1679. static int dasd_flush_block_queue(struct dasd_block *block)
  1680. {
  1681. struct dasd_ccw_req *cqr, *n;
  1682. int rc, i;
  1683. struct list_head flush_queue;
  1684. INIT_LIST_HEAD(&flush_queue);
  1685. spin_lock_bh(&block->queue_lock);
  1686. rc = 0;
  1687. restart:
  1688. list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
  1689. /* if this request currently owned by a dasd_device cancel it */
  1690. if (cqr->status >= DASD_CQR_QUEUED)
  1691. rc = dasd_cancel_req(cqr);
  1692. if (rc < 0)
  1693. break;
  1694. /* Rechain request (including erp chain) so it won't be
  1695. * touched by the dasd_block_tasklet anymore.
  1696. * Replace the callback so we notice when the request
  1697. * is returned from the dasd_device layer.
  1698. */
  1699. cqr->callback = _dasd_wake_block_flush_cb;
  1700. for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
  1701. list_move_tail(&cqr->blocklist, &flush_queue);
  1702. if (i > 1)
  1703. /* moved more than one request - need to restart */
  1704. goto restart;
  1705. }
  1706. spin_unlock_bh(&block->queue_lock);
  1707. /* Now call the callback function of flushed requests */
  1708. restart_cb:
  1709. list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
  1710. wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
  1711. /* Process finished ERP request. */
  1712. if (cqr->refers) {
  1713. __dasd_block_process_erp(block, cqr);
  1714. /* restart list_for_xx loop since dasd_process_erp
  1715. * might remove multiple elements */
  1716. goto restart_cb;
  1717. }
  1718. /* call the callback function */
  1719. cqr->endclk = get_clock();
  1720. list_del_init(&cqr->blocklist);
  1721. __dasd_cleanup_cqr(cqr);
  1722. }
  1723. return rc;
  1724. }
  1725. /*
  1726. * Schedules a call to dasd_tasklet over the device tasklet.
  1727. */
  1728. void dasd_schedule_block_bh(struct dasd_block *block)
  1729. {
  1730. /* Protect against rescheduling. */
  1731. if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
  1732. return;
  1733. /* life cycle of block is bound to it's base device */
  1734. dasd_get_device(block->base);
  1735. tasklet_hi_schedule(&block->tasklet);
  1736. }
  1737. /*
  1738. * SECTION: external block device operations
  1739. * (request queue handling, open, release, etc.)
  1740. */
  1741. /*
  1742. * Dasd request queue function. Called from ll_rw_blk.c
  1743. */
  1744. static void do_dasd_request(struct request_queue *queue)
  1745. {
  1746. struct dasd_block *block;
  1747. block = queue->queuedata;
  1748. spin_lock(&block->queue_lock);
  1749. /* Get new request from the block device request queue */
  1750. __dasd_process_request_queue(block);
  1751. /* Now check if the head of the ccw queue needs to be started. */
  1752. __dasd_block_start_head(block);
  1753. spin_unlock(&block->queue_lock);
  1754. }
  1755. /*
  1756. * Allocate and initialize request queue and default I/O scheduler.
  1757. */
  1758. static int dasd_alloc_queue(struct dasd_block *block)
  1759. {
  1760. int rc;
  1761. block->request_queue = blk_init_queue(do_dasd_request,
  1762. &block->request_queue_lock);
  1763. if (block->request_queue == NULL)
  1764. return -ENOMEM;
  1765. block->request_queue->queuedata = block;
  1766. elevator_exit(block->request_queue->elevator);
  1767. rc = elevator_init(block->request_queue, "deadline");
  1768. if (rc) {
  1769. blk_cleanup_queue(block->request_queue);
  1770. return rc;
  1771. }
  1772. return 0;
  1773. }
  1774. /*
  1775. * Allocate and initialize request queue.
  1776. */
  1777. static void dasd_setup_queue(struct dasd_block *block)
  1778. {
  1779. int max;
  1780. blk_queue_hardsect_size(block->request_queue, block->bp_block);
  1781. max = block->base->discipline->max_blocks << block->s2b_shift;
  1782. blk_queue_max_sectors(block->request_queue, max);
  1783. blk_queue_max_phys_segments(block->request_queue, -1L);
  1784. blk_queue_max_hw_segments(block->request_queue, -1L);
  1785. blk_queue_max_segment_size(block->request_queue, -1L);
  1786. blk_queue_segment_boundary(block->request_queue, -1L);
  1787. blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL);
  1788. }
  1789. /*
  1790. * Deactivate and free request queue.
  1791. */
  1792. static void dasd_free_queue(struct dasd_block *block)
  1793. {
  1794. if (block->request_queue) {
  1795. blk_cleanup_queue(block->request_queue);
  1796. block->request_queue = NULL;
  1797. }
  1798. }
  1799. /*
  1800. * Flush request on the request queue.
  1801. */
  1802. static void dasd_flush_request_queue(struct dasd_block *block)
  1803. {
  1804. struct request *req;
  1805. if (!block->request_queue)
  1806. return;
  1807. spin_lock_irq(&block->request_queue_lock);
  1808. while ((req = elv_next_request(block->request_queue))) {
  1809. blkdev_dequeue_request(req);
  1810. dasd_end_request(req, -EIO);
  1811. }
  1812. spin_unlock_irq(&block->request_queue_lock);
  1813. }
  1814. static int dasd_open(struct inode *inp, struct file *filp)
  1815. {
  1816. struct gendisk *disk = inp->i_bdev->bd_disk;
  1817. struct dasd_block *block = disk->private_data;
  1818. struct dasd_device *base = block->base;
  1819. int rc;
  1820. atomic_inc(&block->open_count);
  1821. if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
  1822. rc = -ENODEV;
  1823. goto unlock;
  1824. }
  1825. if (!try_module_get(base->discipline->owner)) {
  1826. rc = -EINVAL;
  1827. goto unlock;
  1828. }
  1829. if (dasd_probeonly) {
  1830. DEV_MESSAGE(KERN_INFO, base, "%s",
  1831. "No access to device due to probeonly mode");
  1832. rc = -EPERM;
  1833. goto out;
  1834. }
  1835. if (base->state <= DASD_STATE_BASIC) {
  1836. DBF_DEV_EVENT(DBF_ERR, base, " %s",
  1837. " Cannot open unrecognized device");
  1838. rc = -ENODEV;
  1839. goto out;
  1840. }
  1841. return 0;
  1842. out:
  1843. module_put(base->discipline->owner);
  1844. unlock:
  1845. atomic_dec(&block->open_count);
  1846. return rc;
  1847. }
  1848. static int dasd_release(struct inode *inp, struct file *filp)
  1849. {
  1850. struct gendisk *disk = inp->i_bdev->bd_disk;
  1851. struct dasd_block *block = disk->private_data;
  1852. atomic_dec(&block->open_count);
  1853. module_put(block->base->discipline->owner);
  1854. return 0;
  1855. }
  1856. /*
  1857. * Return disk geometry.
  1858. */
  1859. static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  1860. {
  1861. struct dasd_block *block;
  1862. struct dasd_device *base;
  1863. block = bdev->bd_disk->private_data;
  1864. base = block->base;
  1865. if (!block)
  1866. return -ENODEV;
  1867. if (!base->discipline ||
  1868. !base->discipline->fill_geometry)
  1869. return -EINVAL;
  1870. base->discipline->fill_geometry(block, geo);
  1871. geo->start = get_start_sect(bdev) >> block->s2b_shift;
  1872. return 0;
  1873. }
  1874. struct block_device_operations
  1875. dasd_device_operations = {
  1876. .owner = THIS_MODULE,
  1877. .open = dasd_open,
  1878. .release = dasd_release,
  1879. .ioctl = dasd_ioctl,
  1880. .compat_ioctl = dasd_compat_ioctl,
  1881. .getgeo = dasd_getgeo,
  1882. };
  1883. /*******************************************************************************
  1884. * end of block device operations
  1885. */
  1886. static void
  1887. dasd_exit(void)
  1888. {
  1889. #ifdef CONFIG_PROC_FS
  1890. dasd_proc_exit();
  1891. #endif
  1892. dasd_eer_exit();
  1893. if (dasd_page_cache != NULL) {
  1894. kmem_cache_destroy(dasd_page_cache);
  1895. dasd_page_cache = NULL;
  1896. }
  1897. dasd_gendisk_exit();
  1898. dasd_devmap_exit();
  1899. if (dasd_debug_area != NULL) {
  1900. debug_unregister(dasd_debug_area);
  1901. dasd_debug_area = NULL;
  1902. }
  1903. }
  1904. /*
  1905. * SECTION: common functions for ccw_driver use
  1906. */
  1907. /*
  1908. * Initial attempt at a probe function. this can be simplified once
  1909. * the other detection code is gone.
  1910. */
  1911. int dasd_generic_probe(struct ccw_device *cdev,
  1912. struct dasd_discipline *discipline)
  1913. {
  1914. int ret;
  1915. ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
  1916. if (ret) {
  1917. printk(KERN_WARNING
  1918. "dasd_generic_probe: could not set ccw-device options "
  1919. "for %s\n", cdev->dev.bus_id);
  1920. return ret;
  1921. }
  1922. ret = dasd_add_sysfs_files(cdev);
  1923. if (ret) {
  1924. printk(KERN_WARNING
  1925. "dasd_generic_probe: could not add sysfs entries "
  1926. "for %s\n", cdev->dev.bus_id);
  1927. return ret;
  1928. }
  1929. cdev->handler = &dasd_int_handler;
  1930. /*
  1931. * Automatically online either all dasd devices (dasd_autodetect)
  1932. * or all devices specified with dasd= parameters during
  1933. * initial probe.
  1934. */
  1935. if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
  1936. (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
  1937. ret = ccw_device_set_online(cdev);
  1938. if (ret)
  1939. printk(KERN_WARNING
  1940. "dasd_generic_probe: could not initially "
  1941. "online ccw-device %s; return code: %d\n",
  1942. cdev->dev.bus_id, ret);
  1943. return 0;
  1944. }
  1945. /*
  1946. * This will one day be called from a global not_oper handler.
  1947. * It is also used by driver_unregister during module unload.
  1948. */
  1949. void dasd_generic_remove(struct ccw_device *cdev)
  1950. {
  1951. struct dasd_device *device;
  1952. struct dasd_block *block;
  1953. cdev->handler = NULL;
  1954. dasd_remove_sysfs_files(cdev);
  1955. device = dasd_device_from_cdev(cdev);
  1956. if (IS_ERR(device))
  1957. return;
  1958. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  1959. /* Already doing offline processing */
  1960. dasd_put_device(device);
  1961. return;
  1962. }
  1963. /*
  1964. * This device is removed unconditionally. Set offline
  1965. * flag to prevent dasd_open from opening it while it is
  1966. * no quite down yet.
  1967. */
  1968. dasd_set_target_state(device, DASD_STATE_NEW);
  1969. /* dasd_delete_device destroys the device reference. */
  1970. block = device->block;
  1971. device->block = NULL;
  1972. dasd_delete_device(device);
  1973. /*
  1974. * life cycle of block is bound to device, so delete it after
  1975. * device was safely removed
  1976. */
  1977. if (block)
  1978. dasd_free_block(block);
  1979. }
  1980. /*
  1981. * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
  1982. * the device is detected for the first time and is supposed to be used
  1983. * or the user has started activation through sysfs.
  1984. */
  1985. int dasd_generic_set_online(struct ccw_device *cdev,
  1986. struct dasd_discipline *base_discipline)
  1987. {
  1988. struct dasd_discipline *discipline;
  1989. struct dasd_device *device;
  1990. int rc;
  1991. /* first online clears initial online feature flag */
  1992. dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
  1993. device = dasd_create_device(cdev);
  1994. if (IS_ERR(device))
  1995. return PTR_ERR(device);
  1996. discipline = base_discipline;
  1997. if (device->features & DASD_FEATURE_USEDIAG) {
  1998. if (!dasd_diag_discipline_pointer) {
  1999. printk (KERN_WARNING
  2000. "dasd_generic couldn't online device %s "
  2001. "- discipline DIAG not available\n",
  2002. cdev->dev.bus_id);
  2003. dasd_delete_device(device);
  2004. return -ENODEV;
  2005. }
  2006. discipline = dasd_diag_discipline_pointer;
  2007. }
  2008. if (!try_module_get(base_discipline->owner)) {
  2009. dasd_delete_device(device);
  2010. return -EINVAL;
  2011. }
  2012. if (!try_module_get(discipline->owner)) {
  2013. module_put(base_discipline->owner);
  2014. dasd_delete_device(device);
  2015. return -EINVAL;
  2016. }
  2017. device->base_discipline = base_discipline;
  2018. device->discipline = discipline;
  2019. /* check_device will allocate block device if necessary */
  2020. rc = discipline->check_device(device);
  2021. if (rc) {
  2022. printk (KERN_WARNING
  2023. "dasd_generic couldn't online device %s "
  2024. "with discipline %s rc=%i\n",
  2025. cdev->dev.bus_id, discipline->name, rc);
  2026. module_put(discipline->owner);
  2027. module_put(base_discipline->owner);
  2028. dasd_delete_device(device);
  2029. return rc;
  2030. }
  2031. dasd_set_target_state(device, DASD_STATE_ONLINE);
  2032. if (device->state <= DASD_STATE_KNOWN) {
  2033. printk (KERN_WARNING
  2034. "dasd_generic discipline not found for %s\n",
  2035. cdev->dev.bus_id);
  2036. rc = -ENODEV;
  2037. dasd_set_target_state(device, DASD_STATE_NEW);
  2038. if (device->block)
  2039. dasd_free_block(device->block);
  2040. dasd_delete_device(device);
  2041. } else
  2042. pr_debug("dasd_generic device %s found\n",
  2043. cdev->dev.bus_id);
  2044. /* FIXME: we have to wait for the root device but we don't want
  2045. * to wait for each single device but for all at once. */
  2046. wait_event(dasd_init_waitq, _wait_for_device(device));
  2047. dasd_put_device(device);
  2048. return rc;
  2049. }
  2050. int dasd_generic_set_offline(struct ccw_device *cdev)
  2051. {
  2052. struct dasd_device *device;
  2053. struct dasd_block *block;
  2054. int max_count, open_count;
  2055. device = dasd_device_from_cdev(cdev);
  2056. if (IS_ERR(device))
  2057. return PTR_ERR(device);
  2058. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2059. /* Already doing offline processing */
  2060. dasd_put_device(device);
  2061. return 0;
  2062. }
  2063. /*
  2064. * We must make sure that this device is currently not in use.
  2065. * The open_count is increased for every opener, that includes
  2066. * the blkdev_get in dasd_scan_partitions. We are only interested
  2067. * in the other openers.
  2068. */
  2069. if (device->block) {
  2070. struct dasd_block *block = device->block;
  2071. max_count = block->bdev ? 0 : -1;
  2072. open_count = (int) atomic_read(&block->open_count);
  2073. if (open_count > max_count) {
  2074. if (open_count > 0)
  2075. printk(KERN_WARNING "Can't offline dasd "
  2076. "device with open count = %i.\n",
  2077. open_count);
  2078. else
  2079. printk(KERN_WARNING "%s",
  2080. "Can't offline dasd device due "
  2081. "to internal use\n");
  2082. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  2083. dasd_put_device(device);
  2084. return -EBUSY;
  2085. }
  2086. }
  2087. dasd_set_target_state(device, DASD_STATE_NEW);
  2088. /* dasd_delete_device destroys the device reference. */
  2089. block = device->block;
  2090. device->block = NULL;
  2091. dasd_delete_device(device);
  2092. /*
  2093. * life cycle of block is bound to device, so delete it after
  2094. * device was safely removed
  2095. */
  2096. if (block)
  2097. dasd_free_block(block);
  2098. return 0;
  2099. }
  2100. int dasd_generic_notify(struct ccw_device *cdev, int event)
  2101. {
  2102. struct dasd_device *device;
  2103. struct dasd_ccw_req *cqr;
  2104. unsigned long flags;
  2105. int ret;
  2106. device = dasd_device_from_cdev(cdev);
  2107. if (IS_ERR(device))
  2108. return 0;
  2109. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  2110. ret = 0;
  2111. switch (event) {
  2112. case CIO_GONE:
  2113. case CIO_NO_PATH:
  2114. /* First of all call extended error reporting. */
  2115. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  2116. if (device->state < DASD_STATE_BASIC)
  2117. break;
  2118. /* Device is active. We want to keep it. */
  2119. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  2120. if (cqr->status == DASD_CQR_IN_IO) {
  2121. cqr->status = DASD_CQR_QUEUED;
  2122. cqr->retries++;
  2123. }
  2124. device->stopped |= DASD_STOPPED_DC_WAIT;
  2125. dasd_device_clear_timer(device);
  2126. dasd_schedule_device_bh(device);
  2127. ret = 1;
  2128. break;
  2129. case CIO_OPER:
  2130. /* FIXME: add a sanity check. */
  2131. device->stopped &= ~DASD_STOPPED_DC_WAIT;
  2132. dasd_schedule_device_bh(device);
  2133. if (device->block)
  2134. dasd_schedule_block_bh(device->block);
  2135. ret = 1;
  2136. break;
  2137. }
  2138. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  2139. dasd_put_device(device);
  2140. return ret;
  2141. }
  2142. static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
  2143. void *rdc_buffer,
  2144. int rdc_buffer_size,
  2145. char *magic)
  2146. {
  2147. struct dasd_ccw_req *cqr;
  2148. struct ccw1 *ccw;
  2149. cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
  2150. if (IS_ERR(cqr)) {
  2151. DEV_MESSAGE(KERN_WARNING, device, "%s",
  2152. "Could not allocate RDC request");
  2153. return cqr;
  2154. }
  2155. ccw = cqr->cpaddr;
  2156. ccw->cmd_code = CCW_CMD_RDC;
  2157. ccw->cda = (__u32)(addr_t)rdc_buffer;
  2158. ccw->count = rdc_buffer_size;
  2159. cqr->startdev = device;
  2160. cqr->memdev = device;
  2161. cqr->expires = 10*HZ;
  2162. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  2163. cqr->retries = 2;
  2164. cqr->buildclk = get_clock();
  2165. cqr->status = DASD_CQR_FILLED;
  2166. return cqr;
  2167. }
  2168. int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
  2169. void **rdc_buffer, int rdc_buffer_size)
  2170. {
  2171. int ret;
  2172. struct dasd_ccw_req *cqr;
  2173. cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
  2174. magic);
  2175. if (IS_ERR(cqr))
  2176. return PTR_ERR(cqr);
  2177. ret = dasd_sleep_on(cqr);
  2178. dasd_sfree_request(cqr, cqr->memdev);
  2179. return ret;
  2180. }
  2181. EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
  2182. static int __init dasd_init(void)
  2183. {
  2184. int rc;
  2185. init_waitqueue_head(&dasd_init_waitq);
  2186. init_waitqueue_head(&dasd_flush_wq);
  2187. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2188. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2189. if (dasd_debug_area == NULL) {
  2190. rc = -ENOMEM;
  2191. goto failed;
  2192. }
  2193. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2194. debug_set_level(dasd_debug_area, DBF_WARNING);
  2195. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2196. dasd_diag_discipline_pointer = NULL;
  2197. rc = dasd_devmap_init();
  2198. if (rc)
  2199. goto failed;
  2200. rc = dasd_gendisk_init();
  2201. if (rc)
  2202. goto failed;
  2203. rc = dasd_parse();
  2204. if (rc)
  2205. goto failed;
  2206. rc = dasd_eer_init();
  2207. if (rc)
  2208. goto failed;
  2209. #ifdef CONFIG_PROC_FS
  2210. rc = dasd_proc_init();
  2211. if (rc)
  2212. goto failed;
  2213. #endif
  2214. return 0;
  2215. failed:
  2216. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2217. dasd_exit();
  2218. return rc;
  2219. }
  2220. module_init(dasd_init);
  2221. module_exit(dasd_exit);
  2222. EXPORT_SYMBOL(dasd_debug_area);
  2223. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2224. EXPORT_SYMBOL(dasd_add_request_head);
  2225. EXPORT_SYMBOL(dasd_add_request_tail);
  2226. EXPORT_SYMBOL(dasd_cancel_req);
  2227. EXPORT_SYMBOL(dasd_device_clear_timer);
  2228. EXPORT_SYMBOL(dasd_block_clear_timer);
  2229. EXPORT_SYMBOL(dasd_enable_device);
  2230. EXPORT_SYMBOL(dasd_int_handler);
  2231. EXPORT_SYMBOL(dasd_kfree_request);
  2232. EXPORT_SYMBOL(dasd_kick_device);
  2233. EXPORT_SYMBOL(dasd_kmalloc_request);
  2234. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2235. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2236. EXPORT_SYMBOL(dasd_set_target_state);
  2237. EXPORT_SYMBOL(dasd_device_set_timer);
  2238. EXPORT_SYMBOL(dasd_block_set_timer);
  2239. EXPORT_SYMBOL(dasd_sfree_request);
  2240. EXPORT_SYMBOL(dasd_sleep_on);
  2241. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2242. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2243. EXPORT_SYMBOL(dasd_smalloc_request);
  2244. EXPORT_SYMBOL(dasd_start_IO);
  2245. EXPORT_SYMBOL(dasd_term_IO);
  2246. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2247. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2248. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2249. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2250. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2251. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2252. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2253. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2254. EXPORT_SYMBOL_GPL(dasd_free_block);