dasd.c 81 KB

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