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. #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. #include <asm/itcw.h>
  24. /* This is ugly... */
  25. #define PRINTK_HEADER "dasd:"
  26. #include "dasd_int.h"
  27. /*
  28. * SECTION: Constant definitions to be used within this file
  29. */
  30. #define DASD_CHANQ_MAX_SIZE 4
  31. /*
  32. * SECTION: exported variables of dasd.c
  33. */
  34. debug_info_t *dasd_debug_area;
  35. struct dasd_discipline *dasd_diag_discipline_pointer;
  36. void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
  37. MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
  38. MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
  39. " Copyright 2000 IBM Corporation");
  40. MODULE_SUPPORTED_DEVICE("dasd");
  41. MODULE_LICENSE("GPL");
  42. /*
  43. * SECTION: prototypes for static functions of dasd.c
  44. */
  45. static int dasd_alloc_queue(struct dasd_block *);
  46. static void dasd_setup_queue(struct dasd_block *);
  47. static void dasd_free_queue(struct dasd_block *);
  48. static void dasd_flush_request_queue(struct dasd_block *);
  49. static int dasd_flush_block_queue(struct dasd_block *);
  50. static void dasd_device_tasklet(struct dasd_device *);
  51. static void dasd_block_tasklet(struct dasd_block *);
  52. static void do_kick_device(struct work_struct *);
  53. static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
  54. static void dasd_device_timeout(unsigned long);
  55. static void dasd_block_timeout(unsigned long);
  56. /*
  57. * SECTION: Operations on the device structure.
  58. */
  59. static wait_queue_head_t dasd_init_waitq;
  60. static wait_queue_head_t dasd_flush_wq;
  61. static wait_queue_head_t generic_waitq;
  62. /*
  63. * Allocate memory for a new device structure.
  64. */
  65. struct dasd_device *dasd_alloc_device(void)
  66. {
  67. struct dasd_device *device;
  68. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  69. if (!device)
  70. return ERR_PTR(-ENOMEM);
  71. /* Get two pages for normal block device operations. */
  72. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  73. if (!device->ccw_mem) {
  74. kfree(device);
  75. return ERR_PTR(-ENOMEM);
  76. }
  77. /* Get one page for error recovery. */
  78. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  79. if (!device->erp_mem) {
  80. free_pages((unsigned long) device->ccw_mem, 1);
  81. kfree(device);
  82. return ERR_PTR(-ENOMEM);
  83. }
  84. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  85. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  86. spin_lock_init(&device->mem_lock);
  87. atomic_set(&device->tasklet_scheduled, 0);
  88. tasklet_init(&device->tasklet,
  89. (void (*)(unsigned long)) dasd_device_tasklet,
  90. (unsigned long) device);
  91. INIT_LIST_HEAD(&device->ccw_queue);
  92. init_timer(&device->timer);
  93. device->timer.function = dasd_device_timeout;
  94. device->timer.data = (unsigned long) device;
  95. INIT_WORK(&device->kick_work, do_kick_device);
  96. device->state = DASD_STATE_NEW;
  97. device->target = DASD_STATE_NEW;
  98. return device;
  99. }
  100. /*
  101. * Free memory of a device structure.
  102. */
  103. void dasd_free_device(struct dasd_device *device)
  104. {
  105. kfree(device->private);
  106. free_page((unsigned long) device->erp_mem);
  107. free_pages((unsigned long) device->ccw_mem, 1);
  108. kfree(device);
  109. }
  110. /*
  111. * Allocate memory for a new device structure.
  112. */
  113. struct dasd_block *dasd_alloc_block(void)
  114. {
  115. struct dasd_block *block;
  116. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  117. if (!block)
  118. return ERR_PTR(-ENOMEM);
  119. /* open_count = 0 means device online but not in use */
  120. atomic_set(&block->open_count, -1);
  121. spin_lock_init(&block->request_queue_lock);
  122. atomic_set(&block->tasklet_scheduled, 0);
  123. tasklet_init(&block->tasklet,
  124. (void (*)(unsigned long)) dasd_block_tasklet,
  125. (unsigned long) block);
  126. INIT_LIST_HEAD(&block->ccw_queue);
  127. spin_lock_init(&block->queue_lock);
  128. init_timer(&block->timer);
  129. block->timer.function = dasd_block_timeout;
  130. block->timer.data = (unsigned long) block;
  131. return block;
  132. }
  133. /*
  134. * Free memory of a device structure.
  135. */
  136. void dasd_free_block(struct dasd_block *block)
  137. {
  138. kfree(block);
  139. }
  140. /*
  141. * Make a new device known to the system.
  142. */
  143. static int dasd_state_new_to_known(struct dasd_device *device)
  144. {
  145. int rc;
  146. /*
  147. * As long as the device is not in state DASD_STATE_NEW we want to
  148. * keep the reference count > 0.
  149. */
  150. dasd_get_device(device);
  151. if (device->block) {
  152. rc = dasd_alloc_queue(device->block);
  153. if (rc) {
  154. dasd_put_device(device);
  155. return rc;
  156. }
  157. }
  158. device->state = DASD_STATE_KNOWN;
  159. return 0;
  160. }
  161. /*
  162. * Let the system forget about a device.
  163. */
  164. static int dasd_state_known_to_new(struct dasd_device *device)
  165. {
  166. /* Disable extended error reporting for this device. */
  167. dasd_eer_disable(device);
  168. /* Forget the discipline information. */
  169. if (device->discipline) {
  170. if (device->discipline->uncheck_device)
  171. device->discipline->uncheck_device(device);
  172. module_put(device->discipline->owner);
  173. }
  174. device->discipline = NULL;
  175. if (device->base_discipline)
  176. module_put(device->base_discipline->owner);
  177. device->base_discipline = NULL;
  178. device->state = DASD_STATE_NEW;
  179. if (device->block)
  180. dasd_free_queue(device->block);
  181. /* Give up reference we took in dasd_state_new_to_known. */
  182. dasd_put_device(device);
  183. return 0;
  184. }
  185. /*
  186. * Request the irq line for the device.
  187. */
  188. static int dasd_state_known_to_basic(struct dasd_device *device)
  189. {
  190. int rc;
  191. /* Allocate and register gendisk structure. */
  192. if (device->block) {
  193. rc = dasd_gendisk_alloc(device->block);
  194. if (rc)
  195. return rc;
  196. }
  197. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  198. device->debug_area = debug_register(dev_name(&device->cdev->dev), 1, 1,
  199. 8 * sizeof(long));
  200. debug_register_view(device->debug_area, &debug_sprintf_view);
  201. debug_set_level(device->debug_area, DBF_WARNING);
  202. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  203. device->state = DASD_STATE_BASIC;
  204. return 0;
  205. }
  206. /*
  207. * Release the irq line for the device. Terminate any running i/o.
  208. */
  209. static int dasd_state_basic_to_known(struct dasd_device *device)
  210. {
  211. int rc;
  212. if (device->block) {
  213. dasd_gendisk_free(device->block);
  214. dasd_block_clear_timer(device->block);
  215. }
  216. rc = dasd_flush_device_queue(device);
  217. if (rc)
  218. return rc;
  219. dasd_device_clear_timer(device);
  220. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  221. if (device->debug_area != NULL) {
  222. debug_unregister(device->debug_area);
  223. device->debug_area = NULL;
  224. }
  225. device->state = DASD_STATE_KNOWN;
  226. return 0;
  227. }
  228. /*
  229. * Do the initial analysis. The do_analysis function may return
  230. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  231. * until the discipline decides to continue the startup sequence
  232. * by calling the function dasd_change_state. The eckd disciplines
  233. * uses this to start a ccw that detects the format. The completion
  234. * interrupt for this detection ccw uses the kernel event daemon to
  235. * trigger the call to dasd_change_state. All this is done in the
  236. * discipline code, see dasd_eckd.c.
  237. * After the analysis ccw is done (do_analysis returned 0) the block
  238. * device is setup.
  239. * In case the analysis returns an error, the device setup is stopped
  240. * (a fake disk was already added to allow formatting).
  241. */
  242. static int dasd_state_basic_to_ready(struct dasd_device *device)
  243. {
  244. int rc;
  245. struct dasd_block *block;
  246. rc = 0;
  247. block = device->block;
  248. /* make disk known with correct capacity */
  249. if (block) {
  250. if (block->base->discipline->do_analysis != NULL)
  251. rc = block->base->discipline->do_analysis(block);
  252. if (rc) {
  253. if (rc != -EAGAIN)
  254. device->state = DASD_STATE_UNFMT;
  255. return rc;
  256. }
  257. dasd_setup_queue(block);
  258. set_capacity(block->gdp,
  259. block->blocks << block->s2b_shift);
  260. device->state = DASD_STATE_READY;
  261. rc = dasd_scan_partitions(block);
  262. if (rc)
  263. device->state = DASD_STATE_BASIC;
  264. } else {
  265. device->state = DASD_STATE_READY;
  266. }
  267. return rc;
  268. }
  269. /*
  270. * Remove device from block device layer. Destroy dirty buffers.
  271. * Forget format information. Check if the target level is basic
  272. * and if it is create fake disk for formatting.
  273. */
  274. static int dasd_state_ready_to_basic(struct dasd_device *device)
  275. {
  276. int rc;
  277. device->state = DASD_STATE_BASIC;
  278. if (device->block) {
  279. struct dasd_block *block = device->block;
  280. rc = dasd_flush_block_queue(block);
  281. if (rc) {
  282. device->state = DASD_STATE_READY;
  283. return rc;
  284. }
  285. dasd_destroy_partitions(block);
  286. dasd_flush_request_queue(block);
  287. block->blocks = 0;
  288. block->bp_block = 0;
  289. block->s2b_shift = 0;
  290. }
  291. return 0;
  292. }
  293. /*
  294. * Back to basic.
  295. */
  296. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  297. {
  298. device->state = DASD_STATE_BASIC;
  299. return 0;
  300. }
  301. /*
  302. * Make the device online and schedule the bottom half to start
  303. * the requeueing of requests from the linux request queue to the
  304. * ccw queue.
  305. */
  306. static int
  307. dasd_state_ready_to_online(struct dasd_device * device)
  308. {
  309. int rc;
  310. struct gendisk *disk;
  311. struct disk_part_iter piter;
  312. struct hd_struct *part;
  313. if (device->discipline->ready_to_online) {
  314. rc = device->discipline->ready_to_online(device);
  315. if (rc)
  316. return rc;
  317. }
  318. device->state = DASD_STATE_ONLINE;
  319. if (device->block) {
  320. dasd_schedule_block_bh(device->block);
  321. disk = device->block->bdev->bd_disk;
  322. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  323. while ((part = disk_part_iter_next(&piter)))
  324. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  325. disk_part_iter_exit(&piter);
  326. }
  327. return 0;
  328. }
  329. /*
  330. * Stop the requeueing of requests again.
  331. */
  332. static int dasd_state_online_to_ready(struct dasd_device *device)
  333. {
  334. int rc;
  335. struct gendisk *disk;
  336. struct disk_part_iter piter;
  337. struct hd_struct *part;
  338. if (device->discipline->online_to_ready) {
  339. rc = device->discipline->online_to_ready(device);
  340. if (rc)
  341. return rc;
  342. }
  343. device->state = DASD_STATE_READY;
  344. if (device->block) {
  345. disk = device->block->bdev->bd_disk;
  346. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  347. while ((part = disk_part_iter_next(&piter)))
  348. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  349. disk_part_iter_exit(&piter);
  350. }
  351. return 0;
  352. }
  353. /*
  354. * Device startup state changes.
  355. */
  356. static int dasd_increase_state(struct dasd_device *device)
  357. {
  358. int rc;
  359. rc = 0;
  360. if (device->state == DASD_STATE_NEW &&
  361. device->target >= DASD_STATE_KNOWN)
  362. rc = dasd_state_new_to_known(device);
  363. if (!rc &&
  364. device->state == DASD_STATE_KNOWN &&
  365. device->target >= DASD_STATE_BASIC)
  366. rc = dasd_state_known_to_basic(device);
  367. if (!rc &&
  368. device->state == DASD_STATE_BASIC &&
  369. device->target >= DASD_STATE_READY)
  370. rc = dasd_state_basic_to_ready(device);
  371. if (!rc &&
  372. device->state == DASD_STATE_UNFMT &&
  373. device->target > DASD_STATE_UNFMT)
  374. rc = -EPERM;
  375. if (!rc &&
  376. device->state == DASD_STATE_READY &&
  377. device->target >= DASD_STATE_ONLINE)
  378. rc = dasd_state_ready_to_online(device);
  379. return rc;
  380. }
  381. /*
  382. * Device shutdown state changes.
  383. */
  384. static int dasd_decrease_state(struct dasd_device *device)
  385. {
  386. int rc;
  387. rc = 0;
  388. if (device->state == DASD_STATE_ONLINE &&
  389. device->target <= DASD_STATE_READY)
  390. rc = dasd_state_online_to_ready(device);
  391. if (!rc &&
  392. device->state == DASD_STATE_READY &&
  393. device->target <= DASD_STATE_BASIC)
  394. rc = dasd_state_ready_to_basic(device);
  395. if (!rc &&
  396. device->state == DASD_STATE_UNFMT &&
  397. device->target <= DASD_STATE_BASIC)
  398. rc = dasd_state_unfmt_to_basic(device);
  399. if (!rc &&
  400. device->state == DASD_STATE_BASIC &&
  401. device->target <= DASD_STATE_KNOWN)
  402. rc = dasd_state_basic_to_known(device);
  403. if (!rc &&
  404. device->state == DASD_STATE_KNOWN &&
  405. device->target <= DASD_STATE_NEW)
  406. rc = dasd_state_known_to_new(device);
  407. return rc;
  408. }
  409. /*
  410. * This is the main startup/shutdown routine.
  411. */
  412. static void dasd_change_state(struct dasd_device *device)
  413. {
  414. int rc;
  415. if (device->state == device->target)
  416. /* Already where we want to go today... */
  417. return;
  418. if (device->state < device->target)
  419. rc = dasd_increase_state(device);
  420. else
  421. rc = dasd_decrease_state(device);
  422. if (rc && rc != -EAGAIN)
  423. device->target = device->state;
  424. if (device->state == device->target)
  425. wake_up(&dasd_init_waitq);
  426. /* let user-space know that the device status changed */
  427. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  428. }
  429. /*
  430. * Kick starter for devices that did not complete the startup/shutdown
  431. * procedure or were sleeping because of a pending state.
  432. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  433. * event daemon.
  434. */
  435. static void do_kick_device(struct work_struct *work)
  436. {
  437. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  438. dasd_change_state(device);
  439. dasd_schedule_device_bh(device);
  440. dasd_put_device(device);
  441. }
  442. void dasd_kick_device(struct dasd_device *device)
  443. {
  444. dasd_get_device(device);
  445. /* queue call to dasd_kick_device to the kernel event daemon. */
  446. schedule_work(&device->kick_work);
  447. }
  448. /*
  449. * Set the target state for a device and starts the state change.
  450. */
  451. void dasd_set_target_state(struct dasd_device *device, int target)
  452. {
  453. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  454. if (dasd_probeonly && target > DASD_STATE_READY)
  455. target = DASD_STATE_READY;
  456. if (device->target != target) {
  457. if (device->state == target)
  458. wake_up(&dasd_init_waitq);
  459. device->target = target;
  460. }
  461. if (device->state != device->target)
  462. dasd_change_state(device);
  463. }
  464. /*
  465. * Enable devices with device numbers in [from..to].
  466. */
  467. static inline int _wait_for_device(struct dasd_device *device)
  468. {
  469. return (device->state == device->target);
  470. }
  471. void dasd_enable_device(struct dasd_device *device)
  472. {
  473. dasd_set_target_state(device, DASD_STATE_ONLINE);
  474. if (device->state <= DASD_STATE_KNOWN)
  475. /* No discipline for device found. */
  476. dasd_set_target_state(device, DASD_STATE_NEW);
  477. /* Now wait for the devices to come up. */
  478. wait_event(dasd_init_waitq, _wait_for_device(device));
  479. }
  480. /*
  481. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  482. */
  483. #ifdef CONFIG_DASD_PROFILE
  484. struct dasd_profile_info_t dasd_global_profile;
  485. unsigned int dasd_profile_level = DASD_PROFILE_OFF;
  486. /*
  487. * Increments counter in global and local profiling structures.
  488. */
  489. #define dasd_profile_counter(value, counter, block) \
  490. { \
  491. int index; \
  492. for (index = 0; index < 31 && value >> (2+index); index++); \
  493. dasd_global_profile.counter[index]++; \
  494. block->profile.counter[index]++; \
  495. }
  496. /*
  497. * Add profiling information for cqr before execution.
  498. */
  499. static void dasd_profile_start(struct dasd_block *block,
  500. struct dasd_ccw_req *cqr,
  501. struct request *req)
  502. {
  503. struct list_head *l;
  504. unsigned int counter;
  505. if (dasd_profile_level != DASD_PROFILE_ON)
  506. return;
  507. /* count the length of the chanq for statistics */
  508. counter = 0;
  509. list_for_each(l, &block->ccw_queue)
  510. if (++counter >= 31)
  511. break;
  512. dasd_global_profile.dasd_io_nr_req[counter]++;
  513. block->profile.dasd_io_nr_req[counter]++;
  514. }
  515. /*
  516. * Add profiling information for cqr after execution.
  517. */
  518. static void dasd_profile_end(struct dasd_block *block,
  519. struct dasd_ccw_req *cqr,
  520. struct request *req)
  521. {
  522. long strtime, irqtime, endtime, tottime; /* in microseconds */
  523. long tottimeps, sectors;
  524. if (dasd_profile_level != DASD_PROFILE_ON)
  525. return;
  526. sectors = req->nr_sectors;
  527. if (!cqr->buildclk || !cqr->startclk ||
  528. !cqr->stopclk || !cqr->endclk ||
  529. !sectors)
  530. return;
  531. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  532. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  533. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  534. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  535. tottimeps = tottime / sectors;
  536. if (!dasd_global_profile.dasd_io_reqs)
  537. memset(&dasd_global_profile, 0,
  538. sizeof(struct dasd_profile_info_t));
  539. dasd_global_profile.dasd_io_reqs++;
  540. dasd_global_profile.dasd_io_sects += sectors;
  541. if (!block->profile.dasd_io_reqs)
  542. memset(&block->profile, 0,
  543. sizeof(struct dasd_profile_info_t));
  544. block->profile.dasd_io_reqs++;
  545. block->profile.dasd_io_sects += sectors;
  546. dasd_profile_counter(sectors, dasd_io_secs, block);
  547. dasd_profile_counter(tottime, dasd_io_times, block);
  548. dasd_profile_counter(tottimeps, dasd_io_timps, block);
  549. dasd_profile_counter(strtime, dasd_io_time1, block);
  550. dasd_profile_counter(irqtime, dasd_io_time2, block);
  551. dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
  552. dasd_profile_counter(endtime, dasd_io_time3, block);
  553. }
  554. #else
  555. #define dasd_profile_start(block, cqr, req) do {} while (0)
  556. #define dasd_profile_end(block, cqr, req) do {} while (0)
  557. #endif /* CONFIG_DASD_PROFILE */
  558. /*
  559. * Allocate memory for a channel program with 'cplength' channel
  560. * command words and 'datasize' additional space. There are two
  561. * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
  562. * memory and 2) dasd_smalloc_request uses the static ccw memory
  563. * that gets allocated for each device.
  564. */
  565. struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
  566. int datasize,
  567. struct dasd_device *device)
  568. {
  569. struct dasd_ccw_req *cqr;
  570. /* Sanity checks */
  571. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  572. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  573. cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
  574. if (cqr == NULL)
  575. return ERR_PTR(-ENOMEM);
  576. cqr->cpaddr = NULL;
  577. if (cplength > 0) {
  578. cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  579. GFP_ATOMIC | GFP_DMA);
  580. if (cqr->cpaddr == NULL) {
  581. kfree(cqr);
  582. return ERR_PTR(-ENOMEM);
  583. }
  584. }
  585. cqr->data = NULL;
  586. if (datasize > 0) {
  587. cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
  588. if (cqr->data == NULL) {
  589. kfree(cqr->cpaddr);
  590. kfree(cqr);
  591. return ERR_PTR(-ENOMEM);
  592. }
  593. }
  594. strncpy((char *) &cqr->magic, magic, 4);
  595. ASCEBC((char *) &cqr->magic, 4);
  596. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  597. dasd_get_device(device);
  598. return cqr;
  599. }
  600. struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
  601. int datasize,
  602. struct dasd_device *device)
  603. {
  604. unsigned long flags;
  605. struct dasd_ccw_req *cqr;
  606. char *data;
  607. int size;
  608. /* Sanity checks */
  609. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  610. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  611. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  612. if (cplength > 0)
  613. size += cplength * sizeof(struct ccw1);
  614. if (datasize > 0)
  615. size += datasize;
  616. spin_lock_irqsave(&device->mem_lock, flags);
  617. cqr = (struct dasd_ccw_req *)
  618. dasd_alloc_chunk(&device->ccw_chunks, size);
  619. spin_unlock_irqrestore(&device->mem_lock, flags);
  620. if (cqr == NULL)
  621. return ERR_PTR(-ENOMEM);
  622. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  623. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  624. cqr->cpaddr = NULL;
  625. if (cplength > 0) {
  626. cqr->cpaddr = (struct ccw1 *) data;
  627. data += cplength*sizeof(struct ccw1);
  628. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  629. }
  630. cqr->data = NULL;
  631. if (datasize > 0) {
  632. cqr->data = data;
  633. memset(cqr->data, 0, datasize);
  634. }
  635. strncpy((char *) &cqr->magic, magic, 4);
  636. ASCEBC((char *) &cqr->magic, 4);
  637. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  638. dasd_get_device(device);
  639. return cqr;
  640. }
  641. /*
  642. * Free memory of a channel program. This function needs to free all the
  643. * idal lists that might have been created by dasd_set_cda and the
  644. * struct dasd_ccw_req itself.
  645. */
  646. void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  647. {
  648. #ifdef CONFIG_64BIT
  649. struct ccw1 *ccw;
  650. /* Clear any idals used for the request. */
  651. ccw = cqr->cpaddr;
  652. do {
  653. clear_normalized_cda(ccw);
  654. } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
  655. #endif
  656. kfree(cqr->cpaddr);
  657. kfree(cqr->data);
  658. kfree(cqr);
  659. dasd_put_device(device);
  660. }
  661. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  662. {
  663. unsigned long flags;
  664. spin_lock_irqsave(&device->mem_lock, flags);
  665. dasd_free_chunk(&device->ccw_chunks, cqr);
  666. spin_unlock_irqrestore(&device->mem_lock, flags);
  667. dasd_put_device(device);
  668. }
  669. /*
  670. * Check discipline magic in cqr.
  671. */
  672. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  673. {
  674. struct dasd_device *device;
  675. if (cqr == NULL)
  676. return -EINVAL;
  677. device = cqr->startdev;
  678. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  679. DEV_MESSAGE(KERN_WARNING, device,
  680. " dasd_ccw_req 0x%08x magic doesn't match"
  681. " discipline 0x%08x",
  682. cqr->magic,
  683. *(unsigned int *) device->discipline->name);
  684. return -EINVAL;
  685. }
  686. return 0;
  687. }
  688. /*
  689. * Terminate the current i/o and set the request to clear_pending.
  690. * Timer keeps device runnig.
  691. * ccw_device_clear can fail if the i/o subsystem
  692. * is in a bad mood.
  693. */
  694. int dasd_term_IO(struct dasd_ccw_req *cqr)
  695. {
  696. struct dasd_device *device;
  697. int retries, rc;
  698. /* Check the cqr */
  699. rc = dasd_check_cqr(cqr);
  700. if (rc)
  701. return rc;
  702. retries = 0;
  703. device = (struct dasd_device *) cqr->startdev;
  704. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  705. rc = ccw_device_clear(device->cdev, (long) cqr);
  706. switch (rc) {
  707. case 0: /* termination successful */
  708. cqr->retries--;
  709. cqr->status = DASD_CQR_CLEAR_PENDING;
  710. cqr->stopclk = get_clock();
  711. cqr->starttime = 0;
  712. DBF_DEV_EVENT(DBF_DEBUG, device,
  713. "terminate cqr %p successful",
  714. cqr);
  715. break;
  716. case -ENODEV:
  717. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  718. "device gone, retry");
  719. break;
  720. case -EIO:
  721. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  722. "I/O error, retry");
  723. break;
  724. case -EINVAL:
  725. case -EBUSY:
  726. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  727. "device busy, retry later");
  728. break;
  729. default:
  730. DEV_MESSAGE(KERN_ERR, device,
  731. "line %d unknown RC=%d, please "
  732. "report to linux390@de.ibm.com",
  733. __LINE__, rc);
  734. BUG();
  735. break;
  736. }
  737. retries++;
  738. }
  739. dasd_schedule_device_bh(device);
  740. return rc;
  741. }
  742. /*
  743. * Start the i/o. This start_IO can fail if the channel is really busy.
  744. * In that case set up a timer to start the request later.
  745. */
  746. int dasd_start_IO(struct dasd_ccw_req *cqr)
  747. {
  748. struct dasd_device *device;
  749. int rc;
  750. /* Check the cqr */
  751. rc = dasd_check_cqr(cqr);
  752. if (rc)
  753. return rc;
  754. device = (struct dasd_device *) cqr->startdev;
  755. if (cqr->retries < 0) {
  756. DEV_MESSAGE(KERN_DEBUG, device,
  757. "start_IO: request %p (%02x/%i) - no retry left.",
  758. cqr, cqr->status, cqr->retries);
  759. cqr->status = DASD_CQR_ERROR;
  760. return -EIO;
  761. }
  762. cqr->startclk = get_clock();
  763. cqr->starttime = jiffies;
  764. cqr->retries--;
  765. if (cqr->cpmode == 1) {
  766. rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
  767. (long) cqr, cqr->lpm);
  768. } else {
  769. rc = ccw_device_start(device->cdev, cqr->cpaddr,
  770. (long) cqr, cqr->lpm, 0);
  771. }
  772. switch (rc) {
  773. case 0:
  774. cqr->status = DASD_CQR_IN_IO;
  775. DBF_DEV_EVENT(DBF_DEBUG, device,
  776. "start_IO: request %p started successful",
  777. cqr);
  778. break;
  779. case -EBUSY:
  780. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  781. "start_IO: device busy, retry later");
  782. break;
  783. case -ETIMEDOUT:
  784. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  785. "start_IO: request timeout, retry later");
  786. break;
  787. case -EACCES:
  788. /* -EACCES indicates that the request used only a
  789. * subset of the available pathes and all these
  790. * pathes are gone.
  791. * Do a retry with all available pathes.
  792. */
  793. cqr->lpm = LPM_ANYPATH;
  794. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  795. "start_IO: selected pathes gone,"
  796. " retry on all pathes");
  797. break;
  798. case -ENODEV:
  799. DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
  800. "start_IO: -ENODEV device gone, retry");
  801. break;
  802. case -EIO:
  803. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  804. "start_IO: -EIO device gone, retry");
  805. break;
  806. default:
  807. DEV_MESSAGE(KERN_ERR, device,
  808. "line %d unknown RC=%d, please report"
  809. " to linux390@de.ibm.com", __LINE__, rc);
  810. BUG();
  811. break;
  812. }
  813. return rc;
  814. }
  815. /*
  816. * Timeout function for dasd devices. This is used for different purposes
  817. * 1) missing interrupt handler for normal operation
  818. * 2) delayed start of request where start_IO failed with -EBUSY
  819. * 3) timeout for missing state change interrupts
  820. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  821. * DASD_CQR_QUEUED for 2) and 3).
  822. */
  823. static void dasd_device_timeout(unsigned long ptr)
  824. {
  825. unsigned long flags;
  826. struct dasd_device *device;
  827. device = (struct dasd_device *) ptr;
  828. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  829. /* re-activate request queue */
  830. device->stopped &= ~DASD_STOPPED_PENDING;
  831. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  832. dasd_schedule_device_bh(device);
  833. }
  834. /*
  835. * Setup timeout for a device in jiffies.
  836. */
  837. void dasd_device_set_timer(struct dasd_device *device, int expires)
  838. {
  839. if (expires == 0)
  840. del_timer(&device->timer);
  841. else
  842. mod_timer(&device->timer, jiffies + expires);
  843. }
  844. /*
  845. * Clear timeout for a device.
  846. */
  847. void dasd_device_clear_timer(struct dasd_device *device)
  848. {
  849. del_timer(&device->timer);
  850. }
  851. static void dasd_handle_killed_request(struct ccw_device *cdev,
  852. unsigned long intparm)
  853. {
  854. struct dasd_ccw_req *cqr;
  855. struct dasd_device *device;
  856. if (!intparm)
  857. return;
  858. cqr = (struct dasd_ccw_req *) intparm;
  859. if (cqr->status != DASD_CQR_IN_IO) {
  860. MESSAGE(KERN_DEBUG,
  861. "invalid status in handle_killed_request: "
  862. "bus_id %s, status %02x",
  863. dev_name(&cdev->dev), cqr->status);
  864. return;
  865. }
  866. device = (struct dasd_device *) cqr->startdev;
  867. if (device == NULL ||
  868. device != dasd_device_from_cdev_locked(cdev) ||
  869. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  870. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  871. dev_name(&cdev->dev));
  872. return;
  873. }
  874. /* Schedule request to be retried. */
  875. cqr->status = DASD_CQR_QUEUED;
  876. dasd_device_clear_timer(device);
  877. dasd_schedule_device_bh(device);
  878. dasd_put_device(device);
  879. }
  880. void dasd_generic_handle_state_change(struct dasd_device *device)
  881. {
  882. /* First of all start sense subsystem status request. */
  883. dasd_eer_snss(device);
  884. device->stopped &= ~DASD_STOPPED_PENDING;
  885. dasd_schedule_device_bh(device);
  886. if (device->block)
  887. dasd_schedule_block_bh(device->block);
  888. }
  889. /*
  890. * Interrupt handler for "normal" ssch-io based dasd devices.
  891. */
  892. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  893. struct irb *irb)
  894. {
  895. struct dasd_ccw_req *cqr, *next;
  896. struct dasd_device *device;
  897. unsigned long long now;
  898. int expires;
  899. if (IS_ERR(irb)) {
  900. switch (PTR_ERR(irb)) {
  901. case -EIO:
  902. break;
  903. case -ETIMEDOUT:
  904. printk(KERN_WARNING"%s(%s): request timed out\n",
  905. __func__, dev_name(&cdev->dev));
  906. break;
  907. default:
  908. printk(KERN_WARNING"%s(%s): unknown error %ld\n",
  909. __func__, dev_name(&cdev->dev), PTR_ERR(irb));
  910. }
  911. dasd_handle_killed_request(cdev, intparm);
  912. return;
  913. }
  914. now = get_clock();
  915. DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
  916. dev_name(&cdev->dev), ((irb->scsw.cmd.cstat << 8) |
  917. irb->scsw.cmd.dstat), (unsigned int) intparm);
  918. /* check for unsolicited interrupts */
  919. cqr = (struct dasd_ccw_req *) intparm;
  920. if (!cqr || ((scsw_cc(&irb->scsw) == 1) &&
  921. (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
  922. (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))) {
  923. if (cqr && cqr->status == DASD_CQR_IN_IO)
  924. cqr->status = DASD_CQR_QUEUED;
  925. device = dasd_device_from_cdev_locked(cdev);
  926. if (!IS_ERR(device)) {
  927. dasd_device_clear_timer(device);
  928. device->discipline->handle_unsolicited_interrupt(device,
  929. irb);
  930. dasd_put_device(device);
  931. }
  932. return;
  933. }
  934. device = (struct dasd_device *) cqr->startdev;
  935. if (!device ||
  936. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  937. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  938. dev_name(&cdev->dev));
  939. return;
  940. }
  941. /* Check for clear pending */
  942. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  943. scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
  944. cqr->status = DASD_CQR_CLEARED;
  945. dasd_device_clear_timer(device);
  946. wake_up(&dasd_flush_wq);
  947. dasd_schedule_device_bh(device);
  948. return;
  949. }
  950. /* check status - the request might have been killed by dyn detach */
  951. if (cqr->status != DASD_CQR_IN_IO) {
  952. MESSAGE(KERN_DEBUG,
  953. "invalid status: bus_id %s, status %02x",
  954. dev_name(&cdev->dev), cqr->status);
  955. return;
  956. }
  957. DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
  958. ((irb->scsw.cmd.cstat << 8) | irb->scsw.cmd.dstat), cqr);
  959. next = NULL;
  960. expires = 0;
  961. if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  962. scsw_cstat(&irb->scsw) == 0) {
  963. /* request was completed successfully */
  964. cqr->status = DASD_CQR_SUCCESS;
  965. cqr->stopclk = now;
  966. /* Start first request on queue if possible -> fast_io. */
  967. if (cqr->devlist.next != &device->ccw_queue) {
  968. next = list_entry(cqr->devlist.next,
  969. struct dasd_ccw_req, devlist);
  970. }
  971. } else { /* error */
  972. memcpy(&cqr->irb, irb, sizeof(struct irb));
  973. if (device->features & DASD_FEATURE_ERPLOG) {
  974. dasd_log_sense(cqr, irb);
  975. }
  976. /*
  977. * If we don't want complex ERP for this request, then just
  978. * reset this and retry it in the fastpath
  979. */
  980. if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
  981. cqr->retries > 0) {
  982. DEV_MESSAGE(KERN_DEBUG, device,
  983. "default ERP in fastpath (%i retries left)",
  984. cqr->retries);
  985. cqr->lpm = LPM_ANYPATH;
  986. cqr->status = DASD_CQR_QUEUED;
  987. next = cqr;
  988. } else
  989. cqr->status = DASD_CQR_ERROR;
  990. }
  991. if (next && (next->status == DASD_CQR_QUEUED) &&
  992. (!device->stopped)) {
  993. if (device->discipline->start_IO(next) == 0)
  994. expires = next->expires;
  995. else
  996. DEV_MESSAGE(KERN_DEBUG, device, "%s",
  997. "Interrupt fastpath "
  998. "failed!");
  999. }
  1000. if (expires != 0)
  1001. dasd_device_set_timer(device, expires);
  1002. else
  1003. dasd_device_clear_timer(device);
  1004. dasd_schedule_device_bh(device);
  1005. }
  1006. /*
  1007. * If we have an error on a dasd_block layer request then we cancel
  1008. * and return all further requests from the same dasd_block as well.
  1009. */
  1010. static void __dasd_device_recovery(struct dasd_device *device,
  1011. struct dasd_ccw_req *ref_cqr)
  1012. {
  1013. struct list_head *l, *n;
  1014. struct dasd_ccw_req *cqr;
  1015. /*
  1016. * only requeue request that came from the dasd_block layer
  1017. */
  1018. if (!ref_cqr->block)
  1019. return;
  1020. list_for_each_safe(l, n, &device->ccw_queue) {
  1021. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1022. if (cqr->status == DASD_CQR_QUEUED &&
  1023. ref_cqr->block == cqr->block) {
  1024. cqr->status = DASD_CQR_CLEARED;
  1025. }
  1026. }
  1027. };
  1028. /*
  1029. * Remove those ccw requests from the queue that need to be returned
  1030. * to the upper layer.
  1031. */
  1032. static void __dasd_device_process_ccw_queue(struct dasd_device *device,
  1033. struct list_head *final_queue)
  1034. {
  1035. struct list_head *l, *n;
  1036. struct dasd_ccw_req *cqr;
  1037. /* Process request with final status. */
  1038. list_for_each_safe(l, n, &device->ccw_queue) {
  1039. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1040. /* Stop list processing at the first non-final request. */
  1041. if (cqr->status == DASD_CQR_QUEUED ||
  1042. cqr->status == DASD_CQR_IN_IO ||
  1043. cqr->status == DASD_CQR_CLEAR_PENDING)
  1044. break;
  1045. if (cqr->status == DASD_CQR_ERROR) {
  1046. __dasd_device_recovery(device, cqr);
  1047. }
  1048. /* Rechain finished requests to final queue */
  1049. list_move_tail(&cqr->devlist, final_queue);
  1050. }
  1051. }
  1052. /*
  1053. * the cqrs from the final queue are returned to the upper layer
  1054. * by setting a dasd_block state and calling the callback function
  1055. */
  1056. static void __dasd_device_process_final_queue(struct dasd_device *device,
  1057. struct list_head *final_queue)
  1058. {
  1059. struct list_head *l, *n;
  1060. struct dasd_ccw_req *cqr;
  1061. struct dasd_block *block;
  1062. void (*callback)(struct dasd_ccw_req *, void *data);
  1063. void *callback_data;
  1064. list_for_each_safe(l, n, final_queue) {
  1065. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1066. list_del_init(&cqr->devlist);
  1067. block = cqr->block;
  1068. callback = cqr->callback;
  1069. callback_data = cqr->callback_data;
  1070. if (block)
  1071. spin_lock_bh(&block->queue_lock);
  1072. switch (cqr->status) {
  1073. case DASD_CQR_SUCCESS:
  1074. cqr->status = DASD_CQR_DONE;
  1075. break;
  1076. case DASD_CQR_ERROR:
  1077. cqr->status = DASD_CQR_NEED_ERP;
  1078. break;
  1079. case DASD_CQR_CLEARED:
  1080. cqr->status = DASD_CQR_TERMINATED;
  1081. break;
  1082. default:
  1083. DEV_MESSAGE(KERN_ERR, device,
  1084. "wrong cqr status in __dasd_process_final_queue "
  1085. "for cqr %p, status %x",
  1086. cqr, cqr->status);
  1087. BUG();
  1088. }
  1089. if (cqr->callback != NULL)
  1090. (callback)(cqr, callback_data);
  1091. if (block)
  1092. spin_unlock_bh(&block->queue_lock);
  1093. }
  1094. }
  1095. /*
  1096. * Take a look at the first request on the ccw queue and check
  1097. * if it reached its expire time. If so, terminate the IO.
  1098. */
  1099. static void __dasd_device_check_expire(struct dasd_device *device)
  1100. {
  1101. struct dasd_ccw_req *cqr;
  1102. if (list_empty(&device->ccw_queue))
  1103. return;
  1104. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1105. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1106. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1107. if (device->discipline->term_IO(cqr) != 0) {
  1108. /* Hmpf, try again in 5 sec */
  1109. DEV_MESSAGE(KERN_ERR, device,
  1110. "internal error - timeout (%is) expired "
  1111. "for cqr %p, termination failed, "
  1112. "retrying in 5s",
  1113. (cqr->expires/HZ), cqr);
  1114. cqr->expires += 5*HZ;
  1115. dasd_device_set_timer(device, 5*HZ);
  1116. } else {
  1117. DEV_MESSAGE(KERN_ERR, device,
  1118. "internal error - timeout (%is) expired "
  1119. "for cqr %p (%i retries left)",
  1120. (cqr->expires/HZ), cqr, cqr->retries);
  1121. }
  1122. }
  1123. }
  1124. /*
  1125. * Take a look at the first request on the ccw queue and check
  1126. * if it needs to be started.
  1127. */
  1128. static void __dasd_device_start_head(struct dasd_device *device)
  1129. {
  1130. struct dasd_ccw_req *cqr;
  1131. int rc;
  1132. if (list_empty(&device->ccw_queue))
  1133. return;
  1134. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1135. if (cqr->status != DASD_CQR_QUEUED)
  1136. return;
  1137. /* when device is stopped, return request to previous layer */
  1138. if (device->stopped) {
  1139. cqr->status = DASD_CQR_CLEARED;
  1140. dasd_schedule_device_bh(device);
  1141. return;
  1142. }
  1143. rc = device->discipline->start_IO(cqr);
  1144. if (rc == 0)
  1145. dasd_device_set_timer(device, cqr->expires);
  1146. else if (rc == -EACCES) {
  1147. dasd_schedule_device_bh(device);
  1148. } else
  1149. /* Hmpf, try again in 1/2 sec */
  1150. dasd_device_set_timer(device, 50);
  1151. }
  1152. /*
  1153. * Go through all request on the dasd_device request queue,
  1154. * terminate them on the cdev if necessary, and return them to the
  1155. * submitting layer via callback.
  1156. * Note:
  1157. * Make sure that all 'submitting layers' still exist when
  1158. * this function is called!. In other words, when 'device' is a base
  1159. * device then all block layer requests must have been removed before
  1160. * via dasd_flush_block_queue.
  1161. */
  1162. int dasd_flush_device_queue(struct dasd_device *device)
  1163. {
  1164. struct dasd_ccw_req *cqr, *n;
  1165. int rc;
  1166. struct list_head flush_queue;
  1167. INIT_LIST_HEAD(&flush_queue);
  1168. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1169. rc = 0;
  1170. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1171. /* Check status and move request to flush_queue */
  1172. switch (cqr->status) {
  1173. case DASD_CQR_IN_IO:
  1174. rc = device->discipline->term_IO(cqr);
  1175. if (rc) {
  1176. /* unable to terminate requeust */
  1177. DEV_MESSAGE(KERN_ERR, device,
  1178. "dasd flush ccw_queue is unable "
  1179. " to terminate request %p",
  1180. cqr);
  1181. /* stop flush processing */
  1182. goto finished;
  1183. }
  1184. break;
  1185. case DASD_CQR_QUEUED:
  1186. cqr->stopclk = get_clock();
  1187. cqr->status = DASD_CQR_CLEARED;
  1188. break;
  1189. default: /* no need to modify the others */
  1190. break;
  1191. }
  1192. list_move_tail(&cqr->devlist, &flush_queue);
  1193. }
  1194. finished:
  1195. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1196. /*
  1197. * After this point all requests must be in state CLEAR_PENDING,
  1198. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1199. * one of the others.
  1200. */
  1201. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1202. wait_event(dasd_flush_wq,
  1203. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1204. /*
  1205. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1206. * and call the callback function of flushed requests
  1207. */
  1208. __dasd_device_process_final_queue(device, &flush_queue);
  1209. return rc;
  1210. }
  1211. /*
  1212. * Acquire the device lock and process queues for the device.
  1213. */
  1214. static void dasd_device_tasklet(struct dasd_device *device)
  1215. {
  1216. struct list_head final_queue;
  1217. atomic_set (&device->tasklet_scheduled, 0);
  1218. INIT_LIST_HEAD(&final_queue);
  1219. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1220. /* Check expire time of first request on the ccw queue. */
  1221. __dasd_device_check_expire(device);
  1222. /* find final requests on ccw queue */
  1223. __dasd_device_process_ccw_queue(device, &final_queue);
  1224. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1225. /* Now call the callback function of requests with final status */
  1226. __dasd_device_process_final_queue(device, &final_queue);
  1227. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1228. /* Now check if the head of the ccw queue needs to be started. */
  1229. __dasd_device_start_head(device);
  1230. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1231. dasd_put_device(device);
  1232. }
  1233. /*
  1234. * Schedules a call to dasd_tasklet over the device tasklet.
  1235. */
  1236. void dasd_schedule_device_bh(struct dasd_device *device)
  1237. {
  1238. /* Protect against rescheduling. */
  1239. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1240. return;
  1241. dasd_get_device(device);
  1242. tasklet_hi_schedule(&device->tasklet);
  1243. }
  1244. /*
  1245. * Queue a request to the head of the device ccw_queue.
  1246. * Start the I/O if possible.
  1247. */
  1248. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1249. {
  1250. struct dasd_device *device;
  1251. unsigned long flags;
  1252. device = cqr->startdev;
  1253. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1254. cqr->status = DASD_CQR_QUEUED;
  1255. list_add(&cqr->devlist, &device->ccw_queue);
  1256. /* let the bh start the request to keep them in order */
  1257. dasd_schedule_device_bh(device);
  1258. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1259. }
  1260. /*
  1261. * Queue a request to the tail of the device ccw_queue.
  1262. * Start the I/O if possible.
  1263. */
  1264. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1265. {
  1266. struct dasd_device *device;
  1267. unsigned long flags;
  1268. device = cqr->startdev;
  1269. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1270. cqr->status = DASD_CQR_QUEUED;
  1271. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1272. /* let the bh start the request to keep them in order */
  1273. dasd_schedule_device_bh(device);
  1274. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1275. }
  1276. /*
  1277. * Wakeup helper for the 'sleep_on' functions.
  1278. */
  1279. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1280. {
  1281. wake_up((wait_queue_head_t *) data);
  1282. }
  1283. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1284. {
  1285. struct dasd_device *device;
  1286. int rc;
  1287. device = cqr->startdev;
  1288. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1289. rc = ((cqr->status == DASD_CQR_DONE ||
  1290. cqr->status == DASD_CQR_NEED_ERP ||
  1291. cqr->status == DASD_CQR_TERMINATED) &&
  1292. list_empty(&cqr->devlist));
  1293. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1294. return rc;
  1295. }
  1296. /*
  1297. * Queue a request to the tail of the device ccw_queue and wait for
  1298. * it's completion.
  1299. */
  1300. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1301. {
  1302. struct dasd_device *device;
  1303. int rc;
  1304. device = cqr->startdev;
  1305. cqr->callback = dasd_wakeup_cb;
  1306. cqr->callback_data = (void *) &generic_waitq;
  1307. dasd_add_request_tail(cqr);
  1308. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1309. /* Request status is either done or failed. */
  1310. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1311. return rc;
  1312. }
  1313. /*
  1314. * Queue a request to the tail of the device ccw_queue and wait
  1315. * interruptible for it's completion.
  1316. */
  1317. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1318. {
  1319. struct dasd_device *device;
  1320. int rc;
  1321. device = cqr->startdev;
  1322. cqr->callback = dasd_wakeup_cb;
  1323. cqr->callback_data = (void *) &generic_waitq;
  1324. dasd_add_request_tail(cqr);
  1325. rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr));
  1326. if (rc == -ERESTARTSYS) {
  1327. dasd_cancel_req(cqr);
  1328. /* wait (non-interruptible) for final status */
  1329. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1330. }
  1331. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1332. return rc;
  1333. }
  1334. /*
  1335. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1336. * for eckd devices) the currently running request has to be terminated
  1337. * and be put back to status queued, before the special request is added
  1338. * to the head of the queue. Then the special request is waited on normally.
  1339. */
  1340. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1341. {
  1342. struct dasd_ccw_req *cqr;
  1343. if (list_empty(&device->ccw_queue))
  1344. return 0;
  1345. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1346. return device->discipline->term_IO(cqr);
  1347. }
  1348. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1349. {
  1350. struct dasd_device *device;
  1351. int rc;
  1352. device = cqr->startdev;
  1353. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1354. rc = _dasd_term_running_cqr(device);
  1355. if (rc) {
  1356. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1357. return rc;
  1358. }
  1359. cqr->callback = dasd_wakeup_cb;
  1360. cqr->callback_data = (void *) &generic_waitq;
  1361. cqr->status = DASD_CQR_QUEUED;
  1362. list_add(&cqr->devlist, &device->ccw_queue);
  1363. /* let the bh start the request to keep them in order */
  1364. dasd_schedule_device_bh(device);
  1365. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1366. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1367. /* Request status is either done or failed. */
  1368. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1369. return rc;
  1370. }
  1371. /*
  1372. * Cancels a request that was started with dasd_sleep_on_req.
  1373. * This is useful to timeout requests. The request will be
  1374. * terminated if it is currently in i/o.
  1375. * Returns 1 if the request has been terminated.
  1376. * 0 if there was no need to terminate the request (not started yet)
  1377. * negative error code if termination failed
  1378. * Cancellation of a request is an asynchronous operation! The calling
  1379. * function has to wait until the request is properly returned via callback.
  1380. */
  1381. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1382. {
  1383. struct dasd_device *device = cqr->startdev;
  1384. unsigned long flags;
  1385. int rc;
  1386. rc = 0;
  1387. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1388. switch (cqr->status) {
  1389. case DASD_CQR_QUEUED:
  1390. /* request was not started - just set to cleared */
  1391. cqr->status = DASD_CQR_CLEARED;
  1392. break;
  1393. case DASD_CQR_IN_IO:
  1394. /* request in IO - terminate IO and release again */
  1395. rc = device->discipline->term_IO(cqr);
  1396. if (rc) {
  1397. DEV_MESSAGE(KERN_ERR, device,
  1398. "dasd_cancel_req is unable "
  1399. " to terminate request %p, rc = %d",
  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_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
  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_MESSAGE(KERN_INFO, base, "%s",
  1853. "No access to device due to probeonly mode");
  1854. rc = -EPERM;
  1855. goto out;
  1856. }
  1857. if (base->state <= DASD_STATE_BASIC) {
  1858. DBF_DEV_EVENT(DBF_ERR, base, " %s",
  1859. " Cannot open unrecognized device");
  1860. rc = -ENODEV;
  1861. goto out;
  1862. }
  1863. return 0;
  1864. out:
  1865. module_put(base->discipline->owner);
  1866. unlock:
  1867. atomic_dec(&block->open_count);
  1868. return rc;
  1869. }
  1870. static int dasd_release(struct gendisk *disk, fmode_t mode)
  1871. {
  1872. struct dasd_block *block = disk->private_data;
  1873. atomic_dec(&block->open_count);
  1874. module_put(block->base->discipline->owner);
  1875. return 0;
  1876. }
  1877. /*
  1878. * Return disk geometry.
  1879. */
  1880. static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  1881. {
  1882. struct dasd_block *block;
  1883. struct dasd_device *base;
  1884. block = bdev->bd_disk->private_data;
  1885. base = block->base;
  1886. if (!block)
  1887. return -ENODEV;
  1888. if (!base->discipline ||
  1889. !base->discipline->fill_geometry)
  1890. return -EINVAL;
  1891. base->discipline->fill_geometry(block, geo);
  1892. geo->start = get_start_sect(bdev) >> block->s2b_shift;
  1893. return 0;
  1894. }
  1895. struct block_device_operations
  1896. dasd_device_operations = {
  1897. .owner = THIS_MODULE,
  1898. .open = dasd_open,
  1899. .release = dasd_release,
  1900. .ioctl = dasd_ioctl,
  1901. .compat_ioctl = dasd_ioctl,
  1902. .getgeo = dasd_getgeo,
  1903. };
  1904. /*******************************************************************************
  1905. * end of block device operations
  1906. */
  1907. static void
  1908. dasd_exit(void)
  1909. {
  1910. #ifdef CONFIG_PROC_FS
  1911. dasd_proc_exit();
  1912. #endif
  1913. dasd_eer_exit();
  1914. if (dasd_page_cache != NULL) {
  1915. kmem_cache_destroy(dasd_page_cache);
  1916. dasd_page_cache = NULL;
  1917. }
  1918. dasd_gendisk_exit();
  1919. dasd_devmap_exit();
  1920. if (dasd_debug_area != NULL) {
  1921. debug_unregister(dasd_debug_area);
  1922. dasd_debug_area = NULL;
  1923. }
  1924. }
  1925. /*
  1926. * SECTION: common functions for ccw_driver use
  1927. */
  1928. /*
  1929. * Initial attempt at a probe function. this can be simplified once
  1930. * the other detection code is gone.
  1931. */
  1932. int dasd_generic_probe(struct ccw_device *cdev,
  1933. struct dasd_discipline *discipline)
  1934. {
  1935. int ret;
  1936. ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
  1937. if (ret) {
  1938. printk(KERN_WARNING
  1939. "dasd_generic_probe: could not set ccw-device options "
  1940. "for %s\n", dev_name(&cdev->dev));
  1941. return ret;
  1942. }
  1943. ret = dasd_add_sysfs_files(cdev);
  1944. if (ret) {
  1945. printk(KERN_WARNING
  1946. "dasd_generic_probe: could not add sysfs entries "
  1947. "for %s\n", dev_name(&cdev->dev));
  1948. return ret;
  1949. }
  1950. cdev->handler = &dasd_int_handler;
  1951. /*
  1952. * Automatically online either all dasd devices (dasd_autodetect)
  1953. * or all devices specified with dasd= parameters during
  1954. * initial probe.
  1955. */
  1956. if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
  1957. (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
  1958. ret = ccw_device_set_online(cdev);
  1959. if (ret)
  1960. printk(KERN_WARNING
  1961. "dasd_generic_probe: could not initially "
  1962. "online ccw-device %s; return code: %d\n",
  1963. dev_name(&cdev->dev), ret);
  1964. return 0;
  1965. }
  1966. /*
  1967. * This will one day be called from a global not_oper handler.
  1968. * It is also used by driver_unregister during module unload.
  1969. */
  1970. void dasd_generic_remove(struct ccw_device *cdev)
  1971. {
  1972. struct dasd_device *device;
  1973. struct dasd_block *block;
  1974. cdev->handler = NULL;
  1975. dasd_remove_sysfs_files(cdev);
  1976. device = dasd_device_from_cdev(cdev);
  1977. if (IS_ERR(device))
  1978. return;
  1979. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  1980. /* Already doing offline processing */
  1981. dasd_put_device(device);
  1982. return;
  1983. }
  1984. /*
  1985. * This device is removed unconditionally. Set offline
  1986. * flag to prevent dasd_open from opening it while it is
  1987. * no quite down yet.
  1988. */
  1989. dasd_set_target_state(device, DASD_STATE_NEW);
  1990. /* dasd_delete_device destroys the device reference. */
  1991. block = device->block;
  1992. device->block = NULL;
  1993. dasd_delete_device(device);
  1994. /*
  1995. * life cycle of block is bound to device, so delete it after
  1996. * device was safely removed
  1997. */
  1998. if (block)
  1999. dasd_free_block(block);
  2000. }
  2001. /*
  2002. * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
  2003. * the device is detected for the first time and is supposed to be used
  2004. * or the user has started activation through sysfs.
  2005. */
  2006. int dasd_generic_set_online(struct ccw_device *cdev,
  2007. struct dasd_discipline *base_discipline)
  2008. {
  2009. struct dasd_discipline *discipline;
  2010. struct dasd_device *device;
  2011. int rc;
  2012. /* first online clears initial online feature flag */
  2013. dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
  2014. device = dasd_create_device(cdev);
  2015. if (IS_ERR(device))
  2016. return PTR_ERR(device);
  2017. discipline = base_discipline;
  2018. if (device->features & DASD_FEATURE_USEDIAG) {
  2019. if (!dasd_diag_discipline_pointer) {
  2020. printk (KERN_WARNING
  2021. "dasd_generic couldn't online device %s "
  2022. "- discipline DIAG not available\n",
  2023. dev_name(&cdev->dev));
  2024. dasd_delete_device(device);
  2025. return -ENODEV;
  2026. }
  2027. discipline = dasd_diag_discipline_pointer;
  2028. }
  2029. if (!try_module_get(base_discipline->owner)) {
  2030. dasd_delete_device(device);
  2031. return -EINVAL;
  2032. }
  2033. if (!try_module_get(discipline->owner)) {
  2034. module_put(base_discipline->owner);
  2035. dasd_delete_device(device);
  2036. return -EINVAL;
  2037. }
  2038. device->base_discipline = base_discipline;
  2039. device->discipline = discipline;
  2040. /* check_device will allocate block device if necessary */
  2041. rc = discipline->check_device(device);
  2042. if (rc) {
  2043. printk (KERN_WARNING
  2044. "dasd_generic couldn't online device %s "
  2045. "with discipline %s rc=%i\n",
  2046. dev_name(&cdev->dev), discipline->name, rc);
  2047. module_put(discipline->owner);
  2048. module_put(base_discipline->owner);
  2049. dasd_delete_device(device);
  2050. return rc;
  2051. }
  2052. dasd_set_target_state(device, DASD_STATE_ONLINE);
  2053. if (device->state <= DASD_STATE_KNOWN) {
  2054. printk (KERN_WARNING
  2055. "dasd_generic discipline not found for %s\n",
  2056. dev_name(&cdev->dev));
  2057. rc = -ENODEV;
  2058. dasd_set_target_state(device, DASD_STATE_NEW);
  2059. if (device->block)
  2060. dasd_free_block(device->block);
  2061. dasd_delete_device(device);
  2062. } else
  2063. pr_debug("dasd_generic device %s found\n",
  2064. dev_name(&cdev->dev));
  2065. /* FIXME: we have to wait for the root device but we don't want
  2066. * to wait for each single device but for all at once. */
  2067. wait_event(dasd_init_waitq, _wait_for_device(device));
  2068. dasd_put_device(device);
  2069. return rc;
  2070. }
  2071. int dasd_generic_set_offline(struct ccw_device *cdev)
  2072. {
  2073. struct dasd_device *device;
  2074. struct dasd_block *block;
  2075. int max_count, open_count;
  2076. device = dasd_device_from_cdev(cdev);
  2077. if (IS_ERR(device))
  2078. return PTR_ERR(device);
  2079. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2080. /* Already doing offline processing */
  2081. dasd_put_device(device);
  2082. return 0;
  2083. }
  2084. /*
  2085. * We must make sure that this device is currently not in use.
  2086. * The open_count is increased for every opener, that includes
  2087. * the blkdev_get in dasd_scan_partitions. We are only interested
  2088. * in the other openers.
  2089. */
  2090. if (device->block) {
  2091. max_count = device->block->bdev ? 0 : -1;
  2092. open_count = atomic_read(&device->block->open_count);
  2093. if (open_count > max_count) {
  2094. if (open_count > 0)
  2095. printk(KERN_WARNING "Can't offline dasd "
  2096. "device with open count = %i.\n",
  2097. open_count);
  2098. else
  2099. printk(KERN_WARNING "%s",
  2100. "Can't offline dasd device due "
  2101. "to internal use\n");
  2102. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  2103. dasd_put_device(device);
  2104. return -EBUSY;
  2105. }
  2106. }
  2107. dasd_set_target_state(device, DASD_STATE_NEW);
  2108. /* dasd_delete_device destroys the device reference. */
  2109. block = device->block;
  2110. device->block = NULL;
  2111. dasd_delete_device(device);
  2112. /*
  2113. * life cycle of block is bound to device, so delete it after
  2114. * device was safely removed
  2115. */
  2116. if (block)
  2117. dasd_free_block(block);
  2118. return 0;
  2119. }
  2120. int dasd_generic_notify(struct ccw_device *cdev, int event)
  2121. {
  2122. struct dasd_device *device;
  2123. struct dasd_ccw_req *cqr;
  2124. int ret;
  2125. device = dasd_device_from_cdev_locked(cdev);
  2126. if (IS_ERR(device))
  2127. return 0;
  2128. ret = 0;
  2129. switch (event) {
  2130. case CIO_GONE:
  2131. case CIO_NO_PATH:
  2132. /* First of all call extended error reporting. */
  2133. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  2134. if (device->state < DASD_STATE_BASIC)
  2135. break;
  2136. /* Device is active. We want to keep it. */
  2137. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  2138. if (cqr->status == DASD_CQR_IN_IO) {
  2139. cqr->status = DASD_CQR_QUEUED;
  2140. cqr->retries++;
  2141. }
  2142. device->stopped |= DASD_STOPPED_DC_WAIT;
  2143. dasd_device_clear_timer(device);
  2144. dasd_schedule_device_bh(device);
  2145. ret = 1;
  2146. break;
  2147. case CIO_OPER:
  2148. /* FIXME: add a sanity check. */
  2149. device->stopped &= ~DASD_STOPPED_DC_WAIT;
  2150. dasd_schedule_device_bh(device);
  2151. if (device->block)
  2152. dasd_schedule_block_bh(device->block);
  2153. ret = 1;
  2154. break;
  2155. }
  2156. dasd_put_device(device);
  2157. return ret;
  2158. }
  2159. static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
  2160. void *rdc_buffer,
  2161. int rdc_buffer_size,
  2162. char *magic)
  2163. {
  2164. struct dasd_ccw_req *cqr;
  2165. struct ccw1 *ccw;
  2166. cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
  2167. if (IS_ERR(cqr)) {
  2168. DEV_MESSAGE(KERN_WARNING, device, "%s",
  2169. "Could not allocate RDC request");
  2170. return cqr;
  2171. }
  2172. ccw = cqr->cpaddr;
  2173. ccw->cmd_code = CCW_CMD_RDC;
  2174. ccw->cda = (__u32)(addr_t)rdc_buffer;
  2175. ccw->count = rdc_buffer_size;
  2176. cqr->startdev = device;
  2177. cqr->memdev = device;
  2178. cqr->expires = 10*HZ;
  2179. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  2180. cqr->retries = 2;
  2181. cqr->buildclk = get_clock();
  2182. cqr->status = DASD_CQR_FILLED;
  2183. return cqr;
  2184. }
  2185. int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
  2186. void **rdc_buffer, int rdc_buffer_size)
  2187. {
  2188. int ret;
  2189. struct dasd_ccw_req *cqr;
  2190. cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
  2191. magic);
  2192. if (IS_ERR(cqr))
  2193. return PTR_ERR(cqr);
  2194. ret = dasd_sleep_on(cqr);
  2195. dasd_sfree_request(cqr, cqr->memdev);
  2196. return ret;
  2197. }
  2198. EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
  2199. /*
  2200. * In command mode and transport mode we need to look for sense
  2201. * data in different places. The sense data itself is allways
  2202. * an array of 32 bytes, so we can unify the sense data access
  2203. * for both modes.
  2204. */
  2205. char *dasd_get_sense(struct irb *irb)
  2206. {
  2207. struct tsb *tsb = NULL;
  2208. char *sense = NULL;
  2209. if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
  2210. if (irb->scsw.tm.tcw)
  2211. tsb = tcw_get_tsb((struct tcw *)(unsigned long)
  2212. irb->scsw.tm.tcw);
  2213. if (tsb && tsb->length == 64 && tsb->flags)
  2214. switch (tsb->flags & 0x07) {
  2215. case 1: /* tsa_iostat */
  2216. sense = tsb->tsa.iostat.sense;
  2217. break;
  2218. case 2: /* tsa_ddpc */
  2219. sense = tsb->tsa.ddpc.sense;
  2220. break;
  2221. default:
  2222. /* currently we don't use interrogate data */
  2223. break;
  2224. }
  2225. } else if (irb->esw.esw0.erw.cons) {
  2226. sense = irb->ecw;
  2227. }
  2228. return sense;
  2229. }
  2230. EXPORT_SYMBOL_GPL(dasd_get_sense);
  2231. static int __init dasd_init(void)
  2232. {
  2233. int rc;
  2234. init_waitqueue_head(&dasd_init_waitq);
  2235. init_waitqueue_head(&dasd_flush_wq);
  2236. init_waitqueue_head(&generic_waitq);
  2237. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2238. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2239. if (dasd_debug_area == NULL) {
  2240. rc = -ENOMEM;
  2241. goto failed;
  2242. }
  2243. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2244. debug_set_level(dasd_debug_area, DBF_WARNING);
  2245. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2246. dasd_diag_discipline_pointer = NULL;
  2247. rc = dasd_devmap_init();
  2248. if (rc)
  2249. goto failed;
  2250. rc = dasd_gendisk_init();
  2251. if (rc)
  2252. goto failed;
  2253. rc = dasd_parse();
  2254. if (rc)
  2255. goto failed;
  2256. rc = dasd_eer_init();
  2257. if (rc)
  2258. goto failed;
  2259. #ifdef CONFIG_PROC_FS
  2260. rc = dasd_proc_init();
  2261. if (rc)
  2262. goto failed;
  2263. #endif
  2264. return 0;
  2265. failed:
  2266. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2267. dasd_exit();
  2268. return rc;
  2269. }
  2270. module_init(dasd_init);
  2271. module_exit(dasd_exit);
  2272. EXPORT_SYMBOL(dasd_debug_area);
  2273. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2274. EXPORT_SYMBOL(dasd_add_request_head);
  2275. EXPORT_SYMBOL(dasd_add_request_tail);
  2276. EXPORT_SYMBOL(dasd_cancel_req);
  2277. EXPORT_SYMBOL(dasd_device_clear_timer);
  2278. EXPORT_SYMBOL(dasd_block_clear_timer);
  2279. EXPORT_SYMBOL(dasd_enable_device);
  2280. EXPORT_SYMBOL(dasd_int_handler);
  2281. EXPORT_SYMBOL(dasd_kfree_request);
  2282. EXPORT_SYMBOL(dasd_kick_device);
  2283. EXPORT_SYMBOL(dasd_kmalloc_request);
  2284. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2285. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2286. EXPORT_SYMBOL(dasd_set_target_state);
  2287. EXPORT_SYMBOL(dasd_device_set_timer);
  2288. EXPORT_SYMBOL(dasd_block_set_timer);
  2289. EXPORT_SYMBOL(dasd_sfree_request);
  2290. EXPORT_SYMBOL(dasd_sleep_on);
  2291. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2292. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2293. EXPORT_SYMBOL(dasd_smalloc_request);
  2294. EXPORT_SYMBOL(dasd_start_IO);
  2295. EXPORT_SYMBOL(dasd_term_IO);
  2296. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2297. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2298. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2299. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2300. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2301. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2302. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2303. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2304. EXPORT_SYMBOL_GPL(dasd_free_block);