dasd.c 68 KB

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