dasd.c 67 KB

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