dasd.c 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  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/kmod.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/ctype.h>
  16. #include <linux/major.h>
  17. #include <linux/slab.h>
  18. #include <linux/hdreg.h>
  19. #include <linux/async.h>
  20. #include <linux/mutex.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/vmalloc.h>
  24. #include <asm/ccwdev.h>
  25. #include <asm/ebcdic.h>
  26. #include <asm/idals.h>
  27. #include <asm/itcw.h>
  28. #include <asm/diag.h>
  29. /* This is ugly... */
  30. #define PRINTK_HEADER "dasd:"
  31. #include "dasd_int.h"
  32. /*
  33. * SECTION: Constant definitions to be used within this file
  34. */
  35. #define DASD_CHANQ_MAX_SIZE 4
  36. #define DASD_DIAG_MOD "dasd_diag_mod"
  37. static unsigned int queue_depth = 32;
  38. static unsigned int nr_hw_queues = 4;
  39. module_param(queue_depth, uint, 0444);
  40. MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
  41. module_param(nr_hw_queues, uint, 0444);
  42. MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
  43. /*
  44. * SECTION: exported variables of dasd.c
  45. */
  46. debug_info_t *dasd_debug_area;
  47. EXPORT_SYMBOL(dasd_debug_area);
  48. static struct dentry *dasd_debugfs_root_entry;
  49. struct dasd_discipline *dasd_diag_discipline_pointer;
  50. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  51. void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
  52. MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
  53. MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
  54. " Copyright IBM Corp. 2000");
  55. MODULE_SUPPORTED_DEVICE("dasd");
  56. MODULE_LICENSE("GPL");
  57. /*
  58. * SECTION: prototypes for static functions of dasd.c
  59. */
  60. static int dasd_alloc_queue(struct dasd_block *);
  61. static void dasd_setup_queue(struct dasd_block *);
  62. static void dasd_free_queue(struct dasd_block *);
  63. static int dasd_flush_block_queue(struct dasd_block *);
  64. static void dasd_device_tasklet(unsigned long);
  65. static void dasd_block_tasklet(unsigned long);
  66. static void do_kick_device(struct work_struct *);
  67. static void do_restore_device(struct work_struct *);
  68. static void do_reload_device(struct work_struct *);
  69. static void do_requeue_requests(struct work_struct *);
  70. static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
  71. static void dasd_device_timeout(struct timer_list *);
  72. static void dasd_block_timeout(struct timer_list *);
  73. static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
  74. static void dasd_profile_init(struct dasd_profile *, struct dentry *);
  75. static void dasd_profile_exit(struct dasd_profile *);
  76. static void dasd_hosts_init(struct dentry *, struct dasd_device *);
  77. static void dasd_hosts_exit(struct dasd_device *);
  78. /*
  79. * SECTION: Operations on the device structure.
  80. */
  81. static wait_queue_head_t dasd_init_waitq;
  82. static wait_queue_head_t dasd_flush_wq;
  83. static wait_queue_head_t generic_waitq;
  84. static wait_queue_head_t shutdown_waitq;
  85. /*
  86. * Allocate memory for a new device structure.
  87. */
  88. struct dasd_device *dasd_alloc_device(void)
  89. {
  90. struct dasd_device *device;
  91. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  92. if (!device)
  93. return ERR_PTR(-ENOMEM);
  94. /* Get two pages for normal block device operations. */
  95. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  96. if (!device->ccw_mem) {
  97. kfree(device);
  98. return ERR_PTR(-ENOMEM);
  99. }
  100. /* Get one page for error recovery. */
  101. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  102. if (!device->erp_mem) {
  103. free_pages((unsigned long) device->ccw_mem, 1);
  104. kfree(device);
  105. return ERR_PTR(-ENOMEM);
  106. }
  107. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  108. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  109. spin_lock_init(&device->mem_lock);
  110. atomic_set(&device->tasklet_scheduled, 0);
  111. tasklet_init(&device->tasklet, dasd_device_tasklet,
  112. (unsigned long) device);
  113. INIT_LIST_HEAD(&device->ccw_queue);
  114. timer_setup(&device->timer, dasd_device_timeout, 0);
  115. INIT_WORK(&device->kick_work, do_kick_device);
  116. INIT_WORK(&device->restore_device, do_restore_device);
  117. INIT_WORK(&device->reload_device, do_reload_device);
  118. INIT_WORK(&device->requeue_requests, do_requeue_requests);
  119. device->state = DASD_STATE_NEW;
  120. device->target = DASD_STATE_NEW;
  121. mutex_init(&device->state_mutex);
  122. spin_lock_init(&device->profile.lock);
  123. return device;
  124. }
  125. /*
  126. * Free memory of a device structure.
  127. */
  128. void dasd_free_device(struct dasd_device *device)
  129. {
  130. kfree(device->private);
  131. free_page((unsigned long) device->erp_mem);
  132. free_pages((unsigned long) device->ccw_mem, 1);
  133. kfree(device);
  134. }
  135. /*
  136. * Allocate memory for a new device structure.
  137. */
  138. struct dasd_block *dasd_alloc_block(void)
  139. {
  140. struct dasd_block *block;
  141. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  142. if (!block)
  143. return ERR_PTR(-ENOMEM);
  144. /* open_count = 0 means device online but not in use */
  145. atomic_set(&block->open_count, -1);
  146. atomic_set(&block->tasklet_scheduled, 0);
  147. tasklet_init(&block->tasklet, dasd_block_tasklet,
  148. (unsigned long) block);
  149. INIT_LIST_HEAD(&block->ccw_queue);
  150. spin_lock_init(&block->queue_lock);
  151. timer_setup(&block->timer, dasd_block_timeout, 0);
  152. spin_lock_init(&block->profile.lock);
  153. return block;
  154. }
  155. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  156. /*
  157. * Free memory of a device structure.
  158. */
  159. void dasd_free_block(struct dasd_block *block)
  160. {
  161. kfree(block);
  162. }
  163. EXPORT_SYMBOL_GPL(dasd_free_block);
  164. /*
  165. * Make a new device known to the system.
  166. */
  167. static int dasd_state_new_to_known(struct dasd_device *device)
  168. {
  169. int rc;
  170. /*
  171. * As long as the device is not in state DASD_STATE_NEW we want to
  172. * keep the reference count > 0.
  173. */
  174. dasd_get_device(device);
  175. if (device->block) {
  176. rc = dasd_alloc_queue(device->block);
  177. if (rc) {
  178. dasd_put_device(device);
  179. return rc;
  180. }
  181. }
  182. device->state = DASD_STATE_KNOWN;
  183. return 0;
  184. }
  185. /*
  186. * Let the system forget about a device.
  187. */
  188. static int dasd_state_known_to_new(struct dasd_device *device)
  189. {
  190. /* Disable extended error reporting for this device. */
  191. dasd_eer_disable(device);
  192. device->state = DASD_STATE_NEW;
  193. if (device->block)
  194. dasd_free_queue(device->block);
  195. /* Give up reference we took in dasd_state_new_to_known. */
  196. dasd_put_device(device);
  197. return 0;
  198. }
  199. static struct dentry *dasd_debugfs_setup(const char *name,
  200. struct dentry *base_dentry)
  201. {
  202. struct dentry *pde;
  203. if (!base_dentry)
  204. return NULL;
  205. pde = debugfs_create_dir(name, base_dentry);
  206. if (!pde || IS_ERR(pde))
  207. return NULL;
  208. return pde;
  209. }
  210. /*
  211. * Request the irq line for the device.
  212. */
  213. static int dasd_state_known_to_basic(struct dasd_device *device)
  214. {
  215. struct dasd_block *block = device->block;
  216. int rc = 0;
  217. /* Allocate and register gendisk structure. */
  218. if (block) {
  219. rc = dasd_gendisk_alloc(block);
  220. if (rc)
  221. return rc;
  222. block->debugfs_dentry =
  223. dasd_debugfs_setup(block->gdp->disk_name,
  224. dasd_debugfs_root_entry);
  225. dasd_profile_init(&block->profile, block->debugfs_dentry);
  226. if (dasd_global_profile_level == DASD_PROFILE_ON)
  227. dasd_profile_on(&device->block->profile);
  228. }
  229. device->debugfs_dentry =
  230. dasd_debugfs_setup(dev_name(&device->cdev->dev),
  231. dasd_debugfs_root_entry);
  232. dasd_profile_init(&device->profile, device->debugfs_dentry);
  233. dasd_hosts_init(device->debugfs_dentry, device);
  234. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  235. device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
  236. 8 * sizeof(long));
  237. debug_register_view(device->debug_area, &debug_sprintf_view);
  238. debug_set_level(device->debug_area, DBF_WARNING);
  239. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  240. device->state = DASD_STATE_BASIC;
  241. return rc;
  242. }
  243. /*
  244. * Release the irq line for the device. Terminate any running i/o.
  245. */
  246. static int dasd_state_basic_to_known(struct dasd_device *device)
  247. {
  248. int rc;
  249. if (device->discipline->basic_to_known) {
  250. rc = device->discipline->basic_to_known(device);
  251. if (rc)
  252. return rc;
  253. }
  254. if (device->block) {
  255. dasd_profile_exit(&device->block->profile);
  256. debugfs_remove(device->block->debugfs_dentry);
  257. dasd_gendisk_free(device->block);
  258. dasd_block_clear_timer(device->block);
  259. }
  260. rc = dasd_flush_device_queue(device);
  261. if (rc)
  262. return rc;
  263. dasd_device_clear_timer(device);
  264. dasd_profile_exit(&device->profile);
  265. dasd_hosts_exit(device);
  266. debugfs_remove(device->debugfs_dentry);
  267. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  268. if (device->debug_area != NULL) {
  269. debug_unregister(device->debug_area);
  270. device->debug_area = NULL;
  271. }
  272. device->state = DASD_STATE_KNOWN;
  273. return 0;
  274. }
  275. /*
  276. * Do the initial analysis. The do_analysis function may return
  277. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  278. * until the discipline decides to continue the startup sequence
  279. * by calling the function dasd_change_state. The eckd disciplines
  280. * uses this to start a ccw that detects the format. The completion
  281. * interrupt for this detection ccw uses the kernel event daemon to
  282. * trigger the call to dasd_change_state. All this is done in the
  283. * discipline code, see dasd_eckd.c.
  284. * After the analysis ccw is done (do_analysis returned 0) the block
  285. * device is setup.
  286. * In case the analysis returns an error, the device setup is stopped
  287. * (a fake disk was already added to allow formatting).
  288. */
  289. static int dasd_state_basic_to_ready(struct dasd_device *device)
  290. {
  291. int rc;
  292. struct dasd_block *block;
  293. struct gendisk *disk;
  294. rc = 0;
  295. block = device->block;
  296. /* make disk known with correct capacity */
  297. if (block) {
  298. if (block->base->discipline->do_analysis != NULL)
  299. rc = block->base->discipline->do_analysis(block);
  300. if (rc) {
  301. if (rc != -EAGAIN) {
  302. device->state = DASD_STATE_UNFMT;
  303. disk = device->block->gdp;
  304. kobject_uevent(&disk_to_dev(disk)->kobj,
  305. KOBJ_CHANGE);
  306. goto out;
  307. }
  308. return rc;
  309. }
  310. dasd_setup_queue(block);
  311. set_capacity(block->gdp,
  312. block->blocks << block->s2b_shift);
  313. device->state = DASD_STATE_READY;
  314. rc = dasd_scan_partitions(block);
  315. if (rc) {
  316. device->state = DASD_STATE_BASIC;
  317. return rc;
  318. }
  319. } else {
  320. device->state = DASD_STATE_READY;
  321. }
  322. out:
  323. if (device->discipline->basic_to_ready)
  324. rc = device->discipline->basic_to_ready(device);
  325. return rc;
  326. }
  327. static inline
  328. int _wait_for_empty_queues(struct dasd_device *device)
  329. {
  330. if (device->block)
  331. return list_empty(&device->ccw_queue) &&
  332. list_empty(&device->block->ccw_queue);
  333. else
  334. return list_empty(&device->ccw_queue);
  335. }
  336. /*
  337. * Remove device from block device layer. Destroy dirty buffers.
  338. * Forget format information. Check if the target level is basic
  339. * and if it is create fake disk for formatting.
  340. */
  341. static int dasd_state_ready_to_basic(struct dasd_device *device)
  342. {
  343. int rc;
  344. device->state = DASD_STATE_BASIC;
  345. if (device->block) {
  346. struct dasd_block *block = device->block;
  347. rc = dasd_flush_block_queue(block);
  348. if (rc) {
  349. device->state = DASD_STATE_READY;
  350. return rc;
  351. }
  352. dasd_destroy_partitions(block);
  353. block->blocks = 0;
  354. block->bp_block = 0;
  355. block->s2b_shift = 0;
  356. }
  357. return 0;
  358. }
  359. /*
  360. * Back to basic.
  361. */
  362. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  363. {
  364. device->state = DASD_STATE_BASIC;
  365. return 0;
  366. }
  367. /*
  368. * Make the device online and schedule the bottom half to start
  369. * the requeueing of requests from the linux request queue to the
  370. * ccw queue.
  371. */
  372. static int
  373. dasd_state_ready_to_online(struct dasd_device * device)
  374. {
  375. struct gendisk *disk;
  376. struct disk_part_iter piter;
  377. struct hd_struct *part;
  378. device->state = DASD_STATE_ONLINE;
  379. if (device->block) {
  380. dasd_schedule_block_bh(device->block);
  381. if ((device->features & DASD_FEATURE_USERAW)) {
  382. disk = device->block->gdp;
  383. kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
  384. return 0;
  385. }
  386. disk = device->block->bdev->bd_disk;
  387. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  388. while ((part = disk_part_iter_next(&piter)))
  389. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  390. disk_part_iter_exit(&piter);
  391. }
  392. return 0;
  393. }
  394. /*
  395. * Stop the requeueing of requests again.
  396. */
  397. static int dasd_state_online_to_ready(struct dasd_device *device)
  398. {
  399. int rc;
  400. struct gendisk *disk;
  401. struct disk_part_iter piter;
  402. struct hd_struct *part;
  403. if (device->discipline->online_to_ready) {
  404. rc = device->discipline->online_to_ready(device);
  405. if (rc)
  406. return rc;
  407. }
  408. device->state = DASD_STATE_READY;
  409. if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
  410. disk = device->block->bdev->bd_disk;
  411. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  412. while ((part = disk_part_iter_next(&piter)))
  413. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  414. disk_part_iter_exit(&piter);
  415. }
  416. return 0;
  417. }
  418. /*
  419. * Device startup state changes.
  420. */
  421. static int dasd_increase_state(struct dasd_device *device)
  422. {
  423. int rc;
  424. rc = 0;
  425. if (device->state == DASD_STATE_NEW &&
  426. device->target >= DASD_STATE_KNOWN)
  427. rc = dasd_state_new_to_known(device);
  428. if (!rc &&
  429. device->state == DASD_STATE_KNOWN &&
  430. device->target >= DASD_STATE_BASIC)
  431. rc = dasd_state_known_to_basic(device);
  432. if (!rc &&
  433. device->state == DASD_STATE_BASIC &&
  434. device->target >= DASD_STATE_READY)
  435. rc = dasd_state_basic_to_ready(device);
  436. if (!rc &&
  437. device->state == DASD_STATE_UNFMT &&
  438. device->target > DASD_STATE_UNFMT)
  439. rc = -EPERM;
  440. if (!rc &&
  441. device->state == DASD_STATE_READY &&
  442. device->target >= DASD_STATE_ONLINE)
  443. rc = dasd_state_ready_to_online(device);
  444. return rc;
  445. }
  446. /*
  447. * Device shutdown state changes.
  448. */
  449. static int dasd_decrease_state(struct dasd_device *device)
  450. {
  451. int rc;
  452. rc = 0;
  453. if (device->state == DASD_STATE_ONLINE &&
  454. device->target <= DASD_STATE_READY)
  455. rc = dasd_state_online_to_ready(device);
  456. if (!rc &&
  457. device->state == DASD_STATE_READY &&
  458. device->target <= DASD_STATE_BASIC)
  459. rc = dasd_state_ready_to_basic(device);
  460. if (!rc &&
  461. device->state == DASD_STATE_UNFMT &&
  462. device->target <= DASD_STATE_BASIC)
  463. rc = dasd_state_unfmt_to_basic(device);
  464. if (!rc &&
  465. device->state == DASD_STATE_BASIC &&
  466. device->target <= DASD_STATE_KNOWN)
  467. rc = dasd_state_basic_to_known(device);
  468. if (!rc &&
  469. device->state == DASD_STATE_KNOWN &&
  470. device->target <= DASD_STATE_NEW)
  471. rc = dasd_state_known_to_new(device);
  472. return rc;
  473. }
  474. /*
  475. * This is the main startup/shutdown routine.
  476. */
  477. static void dasd_change_state(struct dasd_device *device)
  478. {
  479. int rc;
  480. if (device->state == device->target)
  481. /* Already where we want to go today... */
  482. return;
  483. if (device->state < device->target)
  484. rc = dasd_increase_state(device);
  485. else
  486. rc = dasd_decrease_state(device);
  487. if (rc == -EAGAIN)
  488. return;
  489. if (rc)
  490. device->target = device->state;
  491. /* let user-space know that the device status changed */
  492. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  493. if (device->state == device->target)
  494. wake_up(&dasd_init_waitq);
  495. }
  496. /*
  497. * Kick starter for devices that did not complete the startup/shutdown
  498. * procedure or were sleeping because of a pending state.
  499. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  500. * event daemon.
  501. */
  502. static void do_kick_device(struct work_struct *work)
  503. {
  504. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  505. mutex_lock(&device->state_mutex);
  506. dasd_change_state(device);
  507. mutex_unlock(&device->state_mutex);
  508. dasd_schedule_device_bh(device);
  509. dasd_put_device(device);
  510. }
  511. void dasd_kick_device(struct dasd_device *device)
  512. {
  513. dasd_get_device(device);
  514. /* queue call to dasd_kick_device to the kernel event daemon. */
  515. if (!schedule_work(&device->kick_work))
  516. dasd_put_device(device);
  517. }
  518. EXPORT_SYMBOL(dasd_kick_device);
  519. /*
  520. * dasd_reload_device will schedule a call do do_reload_device to the kernel
  521. * event daemon.
  522. */
  523. static void do_reload_device(struct work_struct *work)
  524. {
  525. struct dasd_device *device = container_of(work, struct dasd_device,
  526. reload_device);
  527. device->discipline->reload(device);
  528. dasd_put_device(device);
  529. }
  530. void dasd_reload_device(struct dasd_device *device)
  531. {
  532. dasd_get_device(device);
  533. /* queue call to dasd_reload_device to the kernel event daemon. */
  534. if (!schedule_work(&device->reload_device))
  535. dasd_put_device(device);
  536. }
  537. EXPORT_SYMBOL(dasd_reload_device);
  538. /*
  539. * dasd_restore_device will schedule a call do do_restore_device to the kernel
  540. * event daemon.
  541. */
  542. static void do_restore_device(struct work_struct *work)
  543. {
  544. struct dasd_device *device = container_of(work, struct dasd_device,
  545. restore_device);
  546. device->cdev->drv->restore(device->cdev);
  547. dasd_put_device(device);
  548. }
  549. void dasd_restore_device(struct dasd_device *device)
  550. {
  551. dasd_get_device(device);
  552. /* queue call to dasd_restore_device to the kernel event daemon. */
  553. if (!schedule_work(&device->restore_device))
  554. dasd_put_device(device);
  555. }
  556. /*
  557. * Set the target state for a device and starts the state change.
  558. */
  559. void dasd_set_target_state(struct dasd_device *device, int target)
  560. {
  561. dasd_get_device(device);
  562. mutex_lock(&device->state_mutex);
  563. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  564. if (dasd_probeonly && target > DASD_STATE_READY)
  565. target = DASD_STATE_READY;
  566. if (device->target != target) {
  567. if (device->state == target)
  568. wake_up(&dasd_init_waitq);
  569. device->target = target;
  570. }
  571. if (device->state != device->target)
  572. dasd_change_state(device);
  573. mutex_unlock(&device->state_mutex);
  574. dasd_put_device(device);
  575. }
  576. EXPORT_SYMBOL(dasd_set_target_state);
  577. /*
  578. * Enable devices with device numbers in [from..to].
  579. */
  580. static inline int _wait_for_device(struct dasd_device *device)
  581. {
  582. return (device->state == device->target);
  583. }
  584. void dasd_enable_device(struct dasd_device *device)
  585. {
  586. dasd_set_target_state(device, DASD_STATE_ONLINE);
  587. if (device->state <= DASD_STATE_KNOWN)
  588. /* No discipline for device found. */
  589. dasd_set_target_state(device, DASD_STATE_NEW);
  590. /* Now wait for the devices to come up. */
  591. wait_event(dasd_init_waitq, _wait_for_device(device));
  592. dasd_reload_device(device);
  593. if (device->discipline->kick_validate)
  594. device->discipline->kick_validate(device);
  595. }
  596. EXPORT_SYMBOL(dasd_enable_device);
  597. /*
  598. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  599. */
  600. unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
  601. #ifdef CONFIG_DASD_PROFILE
  602. struct dasd_profile dasd_global_profile = {
  603. .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
  604. };
  605. static struct dentry *dasd_debugfs_global_entry;
  606. /*
  607. * Add profiling information for cqr before execution.
  608. */
  609. static void dasd_profile_start(struct dasd_block *block,
  610. struct dasd_ccw_req *cqr,
  611. struct request *req)
  612. {
  613. struct list_head *l;
  614. unsigned int counter;
  615. struct dasd_device *device;
  616. /* count the length of the chanq for statistics */
  617. counter = 0;
  618. if (dasd_global_profile_level || block->profile.data)
  619. list_for_each(l, &block->ccw_queue)
  620. if (++counter >= 31)
  621. break;
  622. spin_lock(&dasd_global_profile.lock);
  623. if (dasd_global_profile.data) {
  624. dasd_global_profile.data->dasd_io_nr_req[counter]++;
  625. if (rq_data_dir(req) == READ)
  626. dasd_global_profile.data->dasd_read_nr_req[counter]++;
  627. }
  628. spin_unlock(&dasd_global_profile.lock);
  629. spin_lock(&block->profile.lock);
  630. if (block->profile.data) {
  631. block->profile.data->dasd_io_nr_req[counter]++;
  632. if (rq_data_dir(req) == READ)
  633. block->profile.data->dasd_read_nr_req[counter]++;
  634. }
  635. spin_unlock(&block->profile.lock);
  636. /*
  637. * We count the request for the start device, even though it may run on
  638. * some other device due to error recovery. This way we make sure that
  639. * we count each request only once.
  640. */
  641. device = cqr->startdev;
  642. if (device->profile.data) {
  643. counter = 1; /* request is not yet queued on the start device */
  644. list_for_each(l, &device->ccw_queue)
  645. if (++counter >= 31)
  646. break;
  647. }
  648. spin_lock(&device->profile.lock);
  649. if (device->profile.data) {
  650. device->profile.data->dasd_io_nr_req[counter]++;
  651. if (rq_data_dir(req) == READ)
  652. device->profile.data->dasd_read_nr_req[counter]++;
  653. }
  654. spin_unlock(&device->profile.lock);
  655. }
  656. /*
  657. * Add profiling information for cqr after execution.
  658. */
  659. #define dasd_profile_counter(value, index) \
  660. { \
  661. for (index = 0; index < 31 && value >> (2+index); index++) \
  662. ; \
  663. }
  664. static void dasd_profile_end_add_data(struct dasd_profile_info *data,
  665. int is_alias,
  666. int is_tpm,
  667. int is_read,
  668. long sectors,
  669. int sectors_ind,
  670. int tottime_ind,
  671. int tottimeps_ind,
  672. int strtime_ind,
  673. int irqtime_ind,
  674. int irqtimeps_ind,
  675. int endtime_ind)
  676. {
  677. /* in case of an overflow, reset the whole profile */
  678. if (data->dasd_io_reqs == UINT_MAX) {
  679. memset(data, 0, sizeof(*data));
  680. ktime_get_real_ts64(&data->starttod);
  681. }
  682. data->dasd_io_reqs++;
  683. data->dasd_io_sects += sectors;
  684. if (is_alias)
  685. data->dasd_io_alias++;
  686. if (is_tpm)
  687. data->dasd_io_tpm++;
  688. data->dasd_io_secs[sectors_ind]++;
  689. data->dasd_io_times[tottime_ind]++;
  690. data->dasd_io_timps[tottimeps_ind]++;
  691. data->dasd_io_time1[strtime_ind]++;
  692. data->dasd_io_time2[irqtime_ind]++;
  693. data->dasd_io_time2ps[irqtimeps_ind]++;
  694. data->dasd_io_time3[endtime_ind]++;
  695. if (is_read) {
  696. data->dasd_read_reqs++;
  697. data->dasd_read_sects += sectors;
  698. if (is_alias)
  699. data->dasd_read_alias++;
  700. if (is_tpm)
  701. data->dasd_read_tpm++;
  702. data->dasd_read_secs[sectors_ind]++;
  703. data->dasd_read_times[tottime_ind]++;
  704. data->dasd_read_time1[strtime_ind]++;
  705. data->dasd_read_time2[irqtime_ind]++;
  706. data->dasd_read_time3[endtime_ind]++;
  707. }
  708. }
  709. static void dasd_profile_end(struct dasd_block *block,
  710. struct dasd_ccw_req *cqr,
  711. struct request *req)
  712. {
  713. unsigned long strtime, irqtime, endtime, tottime;
  714. unsigned long tottimeps, sectors;
  715. struct dasd_device *device;
  716. int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
  717. int irqtime_ind, irqtimeps_ind, endtime_ind;
  718. struct dasd_profile_info *data;
  719. device = cqr->startdev;
  720. if (!(dasd_global_profile_level ||
  721. block->profile.data ||
  722. device->profile.data))
  723. return;
  724. sectors = blk_rq_sectors(req);
  725. if (!cqr->buildclk || !cqr->startclk ||
  726. !cqr->stopclk || !cqr->endclk ||
  727. !sectors)
  728. return;
  729. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  730. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  731. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  732. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  733. tottimeps = tottime / sectors;
  734. dasd_profile_counter(sectors, sectors_ind);
  735. dasd_profile_counter(tottime, tottime_ind);
  736. dasd_profile_counter(tottimeps, tottimeps_ind);
  737. dasd_profile_counter(strtime, strtime_ind);
  738. dasd_profile_counter(irqtime, irqtime_ind);
  739. dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
  740. dasd_profile_counter(endtime, endtime_ind);
  741. spin_lock(&dasd_global_profile.lock);
  742. if (dasd_global_profile.data) {
  743. data = dasd_global_profile.data;
  744. data->dasd_sum_times += tottime;
  745. data->dasd_sum_time_str += strtime;
  746. data->dasd_sum_time_irq += irqtime;
  747. data->dasd_sum_time_end += endtime;
  748. dasd_profile_end_add_data(dasd_global_profile.data,
  749. cqr->startdev != block->base,
  750. cqr->cpmode == 1,
  751. rq_data_dir(req) == READ,
  752. sectors, sectors_ind, tottime_ind,
  753. tottimeps_ind, strtime_ind,
  754. irqtime_ind, irqtimeps_ind,
  755. endtime_ind);
  756. }
  757. spin_unlock(&dasd_global_profile.lock);
  758. spin_lock(&block->profile.lock);
  759. if (block->profile.data) {
  760. data = block->profile.data;
  761. data->dasd_sum_times += tottime;
  762. data->dasd_sum_time_str += strtime;
  763. data->dasd_sum_time_irq += irqtime;
  764. data->dasd_sum_time_end += endtime;
  765. dasd_profile_end_add_data(block->profile.data,
  766. cqr->startdev != block->base,
  767. cqr->cpmode == 1,
  768. rq_data_dir(req) == READ,
  769. sectors, sectors_ind, tottime_ind,
  770. tottimeps_ind, strtime_ind,
  771. irqtime_ind, irqtimeps_ind,
  772. endtime_ind);
  773. }
  774. spin_unlock(&block->profile.lock);
  775. spin_lock(&device->profile.lock);
  776. if (device->profile.data) {
  777. data = device->profile.data;
  778. data->dasd_sum_times += tottime;
  779. data->dasd_sum_time_str += strtime;
  780. data->dasd_sum_time_irq += irqtime;
  781. data->dasd_sum_time_end += endtime;
  782. dasd_profile_end_add_data(device->profile.data,
  783. cqr->startdev != block->base,
  784. cqr->cpmode == 1,
  785. rq_data_dir(req) == READ,
  786. sectors, sectors_ind, tottime_ind,
  787. tottimeps_ind, strtime_ind,
  788. irqtime_ind, irqtimeps_ind,
  789. endtime_ind);
  790. }
  791. spin_unlock(&device->profile.lock);
  792. }
  793. void dasd_profile_reset(struct dasd_profile *profile)
  794. {
  795. struct dasd_profile_info *data;
  796. spin_lock_bh(&profile->lock);
  797. data = profile->data;
  798. if (!data) {
  799. spin_unlock_bh(&profile->lock);
  800. return;
  801. }
  802. memset(data, 0, sizeof(*data));
  803. ktime_get_real_ts64(&data->starttod);
  804. spin_unlock_bh(&profile->lock);
  805. }
  806. int dasd_profile_on(struct dasd_profile *profile)
  807. {
  808. struct dasd_profile_info *data;
  809. data = kzalloc(sizeof(*data), GFP_KERNEL);
  810. if (!data)
  811. return -ENOMEM;
  812. spin_lock_bh(&profile->lock);
  813. if (profile->data) {
  814. spin_unlock_bh(&profile->lock);
  815. kfree(data);
  816. return 0;
  817. }
  818. ktime_get_real_ts64(&data->starttod);
  819. profile->data = data;
  820. spin_unlock_bh(&profile->lock);
  821. return 0;
  822. }
  823. void dasd_profile_off(struct dasd_profile *profile)
  824. {
  825. spin_lock_bh(&profile->lock);
  826. kfree(profile->data);
  827. profile->data = NULL;
  828. spin_unlock_bh(&profile->lock);
  829. }
  830. char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
  831. {
  832. char *buffer;
  833. buffer = vmalloc(user_len + 1);
  834. if (buffer == NULL)
  835. return ERR_PTR(-ENOMEM);
  836. if (copy_from_user(buffer, user_buf, user_len) != 0) {
  837. vfree(buffer);
  838. return ERR_PTR(-EFAULT);
  839. }
  840. /* got the string, now strip linefeed. */
  841. if (buffer[user_len - 1] == '\n')
  842. buffer[user_len - 1] = 0;
  843. else
  844. buffer[user_len] = 0;
  845. return buffer;
  846. }
  847. static ssize_t dasd_stats_write(struct file *file,
  848. const char __user *user_buf,
  849. size_t user_len, loff_t *pos)
  850. {
  851. char *buffer, *str;
  852. int rc;
  853. struct seq_file *m = (struct seq_file *)file->private_data;
  854. struct dasd_profile *prof = m->private;
  855. if (user_len > 65536)
  856. user_len = 65536;
  857. buffer = dasd_get_user_string(user_buf, user_len);
  858. if (IS_ERR(buffer))
  859. return PTR_ERR(buffer);
  860. str = skip_spaces(buffer);
  861. rc = user_len;
  862. if (strncmp(str, "reset", 5) == 0) {
  863. dasd_profile_reset(prof);
  864. } else if (strncmp(str, "on", 2) == 0) {
  865. rc = dasd_profile_on(prof);
  866. if (rc)
  867. goto out;
  868. rc = user_len;
  869. if (prof == &dasd_global_profile) {
  870. dasd_profile_reset(prof);
  871. dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
  872. }
  873. } else if (strncmp(str, "off", 3) == 0) {
  874. if (prof == &dasd_global_profile)
  875. dasd_global_profile_level = DASD_PROFILE_OFF;
  876. dasd_profile_off(prof);
  877. } else
  878. rc = -EINVAL;
  879. out:
  880. vfree(buffer);
  881. return rc;
  882. }
  883. static void dasd_stats_array(struct seq_file *m, unsigned int *array)
  884. {
  885. int i;
  886. for (i = 0; i < 32; i++)
  887. seq_printf(m, "%u ", array[i]);
  888. seq_putc(m, '\n');
  889. }
  890. static void dasd_stats_seq_print(struct seq_file *m,
  891. struct dasd_profile_info *data)
  892. {
  893. seq_printf(m, "start_time %lld.%09ld\n",
  894. (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
  895. seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
  896. seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
  897. seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
  898. seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
  899. seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
  900. data->dasd_sum_times / data->dasd_io_reqs : 0UL);
  901. seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
  902. data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
  903. seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
  904. data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
  905. seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
  906. data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
  907. seq_puts(m, "histogram_sectors ");
  908. dasd_stats_array(m, data->dasd_io_secs);
  909. seq_puts(m, "histogram_io_times ");
  910. dasd_stats_array(m, data->dasd_io_times);
  911. seq_puts(m, "histogram_io_times_weighted ");
  912. dasd_stats_array(m, data->dasd_io_timps);
  913. seq_puts(m, "histogram_time_build_to_ssch ");
  914. dasd_stats_array(m, data->dasd_io_time1);
  915. seq_puts(m, "histogram_time_ssch_to_irq ");
  916. dasd_stats_array(m, data->dasd_io_time2);
  917. seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
  918. dasd_stats_array(m, data->dasd_io_time2ps);
  919. seq_puts(m, "histogram_time_irq_to_end ");
  920. dasd_stats_array(m, data->dasd_io_time3);
  921. seq_puts(m, "histogram_ccw_queue_length ");
  922. dasd_stats_array(m, data->dasd_io_nr_req);
  923. seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
  924. seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
  925. seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
  926. seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
  927. seq_puts(m, "histogram_read_sectors ");
  928. dasd_stats_array(m, data->dasd_read_secs);
  929. seq_puts(m, "histogram_read_times ");
  930. dasd_stats_array(m, data->dasd_read_times);
  931. seq_puts(m, "histogram_read_time_build_to_ssch ");
  932. dasd_stats_array(m, data->dasd_read_time1);
  933. seq_puts(m, "histogram_read_time_ssch_to_irq ");
  934. dasd_stats_array(m, data->dasd_read_time2);
  935. seq_puts(m, "histogram_read_time_irq_to_end ");
  936. dasd_stats_array(m, data->dasd_read_time3);
  937. seq_puts(m, "histogram_read_ccw_queue_length ");
  938. dasd_stats_array(m, data->dasd_read_nr_req);
  939. }
  940. static int dasd_stats_show(struct seq_file *m, void *v)
  941. {
  942. struct dasd_profile *profile;
  943. struct dasd_profile_info *data;
  944. profile = m->private;
  945. spin_lock_bh(&profile->lock);
  946. data = profile->data;
  947. if (!data) {
  948. spin_unlock_bh(&profile->lock);
  949. seq_puts(m, "disabled\n");
  950. return 0;
  951. }
  952. dasd_stats_seq_print(m, data);
  953. spin_unlock_bh(&profile->lock);
  954. return 0;
  955. }
  956. static int dasd_stats_open(struct inode *inode, struct file *file)
  957. {
  958. struct dasd_profile *profile = inode->i_private;
  959. return single_open(file, dasd_stats_show, profile);
  960. }
  961. static const struct file_operations dasd_stats_raw_fops = {
  962. .owner = THIS_MODULE,
  963. .open = dasd_stats_open,
  964. .read = seq_read,
  965. .llseek = seq_lseek,
  966. .release = single_release,
  967. .write = dasd_stats_write,
  968. };
  969. static void dasd_profile_init(struct dasd_profile *profile,
  970. struct dentry *base_dentry)
  971. {
  972. umode_t mode;
  973. struct dentry *pde;
  974. if (!base_dentry)
  975. return;
  976. profile->dentry = NULL;
  977. profile->data = NULL;
  978. mode = (S_IRUSR | S_IWUSR | S_IFREG);
  979. pde = debugfs_create_file("statistics", mode, base_dentry,
  980. profile, &dasd_stats_raw_fops);
  981. if (pde && !IS_ERR(pde))
  982. profile->dentry = pde;
  983. return;
  984. }
  985. static void dasd_profile_exit(struct dasd_profile *profile)
  986. {
  987. dasd_profile_off(profile);
  988. debugfs_remove(profile->dentry);
  989. profile->dentry = NULL;
  990. }
  991. static void dasd_statistics_removeroot(void)
  992. {
  993. dasd_global_profile_level = DASD_PROFILE_OFF;
  994. dasd_profile_exit(&dasd_global_profile);
  995. debugfs_remove(dasd_debugfs_global_entry);
  996. debugfs_remove(dasd_debugfs_root_entry);
  997. }
  998. static void dasd_statistics_createroot(void)
  999. {
  1000. struct dentry *pde;
  1001. dasd_debugfs_root_entry = NULL;
  1002. pde = debugfs_create_dir("dasd", NULL);
  1003. if (!pde || IS_ERR(pde))
  1004. goto error;
  1005. dasd_debugfs_root_entry = pde;
  1006. pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
  1007. if (!pde || IS_ERR(pde))
  1008. goto error;
  1009. dasd_debugfs_global_entry = pde;
  1010. dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
  1011. return;
  1012. error:
  1013. DBF_EVENT(DBF_ERR, "%s",
  1014. "Creation of the dasd debugfs interface failed");
  1015. dasd_statistics_removeroot();
  1016. return;
  1017. }
  1018. #else
  1019. #define dasd_profile_start(block, cqr, req) do {} while (0)
  1020. #define dasd_profile_end(block, cqr, req) do {} while (0)
  1021. static void dasd_statistics_createroot(void)
  1022. {
  1023. return;
  1024. }
  1025. static void dasd_statistics_removeroot(void)
  1026. {
  1027. return;
  1028. }
  1029. int dasd_stats_generic_show(struct seq_file *m, void *v)
  1030. {
  1031. seq_puts(m, "Statistics are not activated in this kernel\n");
  1032. return 0;
  1033. }
  1034. static void dasd_profile_init(struct dasd_profile *profile,
  1035. struct dentry *base_dentry)
  1036. {
  1037. return;
  1038. }
  1039. static void dasd_profile_exit(struct dasd_profile *profile)
  1040. {
  1041. return;
  1042. }
  1043. int dasd_profile_on(struct dasd_profile *profile)
  1044. {
  1045. return 0;
  1046. }
  1047. #endif /* CONFIG_DASD_PROFILE */
  1048. static int dasd_hosts_show(struct seq_file *m, void *v)
  1049. {
  1050. struct dasd_device *device;
  1051. int rc = -EOPNOTSUPP;
  1052. device = m->private;
  1053. dasd_get_device(device);
  1054. if (device->discipline->hosts_print)
  1055. rc = device->discipline->hosts_print(device, m);
  1056. dasd_put_device(device);
  1057. return rc;
  1058. }
  1059. static int dasd_hosts_open(struct inode *inode, struct file *file)
  1060. {
  1061. struct dasd_device *device = inode->i_private;
  1062. return single_open(file, dasd_hosts_show, device);
  1063. }
  1064. static const struct file_operations dasd_hosts_fops = {
  1065. .owner = THIS_MODULE,
  1066. .open = dasd_hosts_open,
  1067. .read = seq_read,
  1068. .llseek = seq_lseek,
  1069. .release = single_release,
  1070. };
  1071. static void dasd_hosts_exit(struct dasd_device *device)
  1072. {
  1073. debugfs_remove(device->hosts_dentry);
  1074. device->hosts_dentry = NULL;
  1075. }
  1076. static void dasd_hosts_init(struct dentry *base_dentry,
  1077. struct dasd_device *device)
  1078. {
  1079. struct dentry *pde;
  1080. umode_t mode;
  1081. if (!base_dentry)
  1082. return;
  1083. mode = S_IRUSR | S_IFREG;
  1084. pde = debugfs_create_file("host_access_list", mode, base_dentry,
  1085. device, &dasd_hosts_fops);
  1086. if (pde && !IS_ERR(pde))
  1087. device->hosts_dentry = pde;
  1088. }
  1089. struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
  1090. struct dasd_device *device,
  1091. struct dasd_ccw_req *cqr)
  1092. {
  1093. unsigned long flags;
  1094. char *data, *chunk;
  1095. int size = 0;
  1096. if (cplength > 0)
  1097. size += cplength * sizeof(struct ccw1);
  1098. if (datasize > 0)
  1099. size += datasize;
  1100. if (!cqr)
  1101. size += (sizeof(*cqr) + 7L) & -8L;
  1102. spin_lock_irqsave(&device->mem_lock, flags);
  1103. data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
  1104. spin_unlock_irqrestore(&device->mem_lock, flags);
  1105. if (!chunk)
  1106. return ERR_PTR(-ENOMEM);
  1107. if (!cqr) {
  1108. cqr = (void *) data;
  1109. data += (sizeof(*cqr) + 7L) & -8L;
  1110. }
  1111. memset(cqr, 0, sizeof(*cqr));
  1112. cqr->mem_chunk = chunk;
  1113. if (cplength > 0) {
  1114. cqr->cpaddr = data;
  1115. data += cplength * sizeof(struct ccw1);
  1116. memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
  1117. }
  1118. if (datasize > 0) {
  1119. cqr->data = data;
  1120. memset(cqr->data, 0, datasize);
  1121. }
  1122. cqr->magic = magic;
  1123. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1124. dasd_get_device(device);
  1125. return cqr;
  1126. }
  1127. EXPORT_SYMBOL(dasd_smalloc_request);
  1128. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  1129. {
  1130. unsigned long flags;
  1131. spin_lock_irqsave(&device->mem_lock, flags);
  1132. dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
  1133. spin_unlock_irqrestore(&device->mem_lock, flags);
  1134. dasd_put_device(device);
  1135. }
  1136. EXPORT_SYMBOL(dasd_sfree_request);
  1137. /*
  1138. * Check discipline magic in cqr.
  1139. */
  1140. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  1141. {
  1142. struct dasd_device *device;
  1143. if (cqr == NULL)
  1144. return -EINVAL;
  1145. device = cqr->startdev;
  1146. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  1147. DBF_DEV_EVENT(DBF_WARNING, device,
  1148. " dasd_ccw_req 0x%08x magic doesn't match"
  1149. " discipline 0x%08x",
  1150. cqr->magic,
  1151. *(unsigned int *) device->discipline->name);
  1152. return -EINVAL;
  1153. }
  1154. return 0;
  1155. }
  1156. /*
  1157. * Terminate the current i/o and set the request to clear_pending.
  1158. * Timer keeps device runnig.
  1159. * ccw_device_clear can fail if the i/o subsystem
  1160. * is in a bad mood.
  1161. */
  1162. int dasd_term_IO(struct dasd_ccw_req *cqr)
  1163. {
  1164. struct dasd_device *device;
  1165. int retries, rc;
  1166. char errorstring[ERRORLENGTH];
  1167. /* Check the cqr */
  1168. rc = dasd_check_cqr(cqr);
  1169. if (rc)
  1170. return rc;
  1171. retries = 0;
  1172. device = (struct dasd_device *) cqr->startdev;
  1173. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  1174. rc = ccw_device_clear(device->cdev, (long) cqr);
  1175. switch (rc) {
  1176. case 0: /* termination successful */
  1177. cqr->status = DASD_CQR_CLEAR_PENDING;
  1178. cqr->stopclk = get_tod_clock();
  1179. cqr->starttime = 0;
  1180. DBF_DEV_EVENT(DBF_DEBUG, device,
  1181. "terminate cqr %p successful",
  1182. cqr);
  1183. break;
  1184. case -ENODEV:
  1185. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  1186. "device gone, retry");
  1187. break;
  1188. case -EINVAL:
  1189. /*
  1190. * device not valid so no I/O could be running
  1191. * handle CQR as termination successful
  1192. */
  1193. cqr->status = DASD_CQR_CLEARED;
  1194. cqr->stopclk = get_tod_clock();
  1195. cqr->starttime = 0;
  1196. /* no retries for invalid devices */
  1197. cqr->retries = -1;
  1198. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  1199. "EINVAL, handle as terminated");
  1200. /* fake rc to success */
  1201. rc = 0;
  1202. break;
  1203. default:
  1204. /* internal error 10 - unknown rc*/
  1205. snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
  1206. dev_err(&device->cdev->dev, "An error occurred in the "
  1207. "DASD device driver, reason=%s\n", errorstring);
  1208. BUG();
  1209. break;
  1210. }
  1211. retries++;
  1212. }
  1213. dasd_schedule_device_bh(device);
  1214. return rc;
  1215. }
  1216. EXPORT_SYMBOL(dasd_term_IO);
  1217. /*
  1218. * Start the i/o. This start_IO can fail if the channel is really busy.
  1219. * In that case set up a timer to start the request later.
  1220. */
  1221. int dasd_start_IO(struct dasd_ccw_req *cqr)
  1222. {
  1223. struct dasd_device *device;
  1224. int rc;
  1225. char errorstring[ERRORLENGTH];
  1226. /* Check the cqr */
  1227. rc = dasd_check_cqr(cqr);
  1228. if (rc) {
  1229. cqr->intrc = rc;
  1230. return rc;
  1231. }
  1232. device = (struct dasd_device *) cqr->startdev;
  1233. if (((cqr->block &&
  1234. test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
  1235. test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
  1236. !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
  1237. DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
  1238. "because of stolen lock", cqr);
  1239. cqr->status = DASD_CQR_ERROR;
  1240. cqr->intrc = -EPERM;
  1241. return -EPERM;
  1242. }
  1243. if (cqr->retries < 0) {
  1244. /* internal error 14 - start_IO run out of retries */
  1245. sprintf(errorstring, "14 %p", cqr);
  1246. dev_err(&device->cdev->dev, "An error occurred in the DASD "
  1247. "device driver, reason=%s\n", errorstring);
  1248. cqr->status = DASD_CQR_ERROR;
  1249. return -EIO;
  1250. }
  1251. cqr->startclk = get_tod_clock();
  1252. cqr->starttime = jiffies;
  1253. cqr->retries--;
  1254. if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
  1255. cqr->lpm &= dasd_path_get_opm(device);
  1256. if (!cqr->lpm)
  1257. cqr->lpm = dasd_path_get_opm(device);
  1258. }
  1259. if (cqr->cpmode == 1) {
  1260. rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
  1261. (long) cqr, cqr->lpm);
  1262. } else {
  1263. rc = ccw_device_start(device->cdev, cqr->cpaddr,
  1264. (long) cqr, cqr->lpm, 0);
  1265. }
  1266. switch (rc) {
  1267. case 0:
  1268. cqr->status = DASD_CQR_IN_IO;
  1269. break;
  1270. case -EBUSY:
  1271. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1272. "start_IO: device busy, retry later");
  1273. break;
  1274. case -EACCES:
  1275. /* -EACCES indicates that the request used only a subset of the
  1276. * available paths and all these paths are gone. If the lpm of
  1277. * this request was only a subset of the opm (e.g. the ppm) then
  1278. * we just do a retry with all available paths.
  1279. * If we already use the full opm, something is amiss, and we
  1280. * need a full path verification.
  1281. */
  1282. if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
  1283. DBF_DEV_EVENT(DBF_WARNING, device,
  1284. "start_IO: selected paths gone (%x)",
  1285. cqr->lpm);
  1286. } else if (cqr->lpm != dasd_path_get_opm(device)) {
  1287. cqr->lpm = dasd_path_get_opm(device);
  1288. DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
  1289. "start_IO: selected paths gone,"
  1290. " retry on all paths");
  1291. } else {
  1292. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1293. "start_IO: all paths in opm gone,"
  1294. " do path verification");
  1295. dasd_generic_last_path_gone(device);
  1296. dasd_path_no_path(device);
  1297. dasd_path_set_tbvpm(device,
  1298. ccw_device_get_path_mask(
  1299. device->cdev));
  1300. }
  1301. break;
  1302. case -ENODEV:
  1303. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1304. "start_IO: -ENODEV device gone, retry");
  1305. break;
  1306. case -EIO:
  1307. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1308. "start_IO: -EIO device gone, retry");
  1309. break;
  1310. case -EINVAL:
  1311. /* most likely caused in power management context */
  1312. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1313. "start_IO: -EINVAL device currently "
  1314. "not accessible");
  1315. break;
  1316. default:
  1317. /* internal error 11 - unknown rc */
  1318. snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
  1319. dev_err(&device->cdev->dev,
  1320. "An error occurred in the DASD device driver, "
  1321. "reason=%s\n", errorstring);
  1322. BUG();
  1323. break;
  1324. }
  1325. cqr->intrc = rc;
  1326. return rc;
  1327. }
  1328. EXPORT_SYMBOL(dasd_start_IO);
  1329. /*
  1330. * Timeout function for dasd devices. This is used for different purposes
  1331. * 1) missing interrupt handler for normal operation
  1332. * 2) delayed start of request where start_IO failed with -EBUSY
  1333. * 3) timeout for missing state change interrupts
  1334. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  1335. * DASD_CQR_QUEUED for 2) and 3).
  1336. */
  1337. static void dasd_device_timeout(struct timer_list *t)
  1338. {
  1339. unsigned long flags;
  1340. struct dasd_device *device;
  1341. device = from_timer(device, t, timer);
  1342. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1343. /* re-activate request queue */
  1344. dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
  1345. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1346. dasd_schedule_device_bh(device);
  1347. }
  1348. /*
  1349. * Setup timeout for a device in jiffies.
  1350. */
  1351. void dasd_device_set_timer(struct dasd_device *device, int expires)
  1352. {
  1353. if (expires == 0)
  1354. del_timer(&device->timer);
  1355. else
  1356. mod_timer(&device->timer, jiffies + expires);
  1357. }
  1358. EXPORT_SYMBOL(dasd_device_set_timer);
  1359. /*
  1360. * Clear timeout for a device.
  1361. */
  1362. void dasd_device_clear_timer(struct dasd_device *device)
  1363. {
  1364. del_timer(&device->timer);
  1365. }
  1366. EXPORT_SYMBOL(dasd_device_clear_timer);
  1367. static void dasd_handle_killed_request(struct ccw_device *cdev,
  1368. unsigned long intparm)
  1369. {
  1370. struct dasd_ccw_req *cqr;
  1371. struct dasd_device *device;
  1372. if (!intparm)
  1373. return;
  1374. cqr = (struct dasd_ccw_req *) intparm;
  1375. if (cqr->status != DASD_CQR_IN_IO) {
  1376. DBF_EVENT_DEVID(DBF_DEBUG, cdev,
  1377. "invalid status in handle_killed_request: "
  1378. "%02x", cqr->status);
  1379. return;
  1380. }
  1381. device = dasd_device_from_cdev_locked(cdev);
  1382. if (IS_ERR(device)) {
  1383. DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
  1384. "unable to get device from cdev");
  1385. return;
  1386. }
  1387. if (!cqr->startdev ||
  1388. device != cqr->startdev ||
  1389. strncmp(cqr->startdev->discipline->ebcname,
  1390. (char *) &cqr->magic, 4)) {
  1391. DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
  1392. "invalid device in request");
  1393. dasd_put_device(device);
  1394. return;
  1395. }
  1396. /* Schedule request to be retried. */
  1397. cqr->status = DASD_CQR_QUEUED;
  1398. dasd_device_clear_timer(device);
  1399. dasd_schedule_device_bh(device);
  1400. dasd_put_device(device);
  1401. }
  1402. void dasd_generic_handle_state_change(struct dasd_device *device)
  1403. {
  1404. /* First of all start sense subsystem status request. */
  1405. dasd_eer_snss(device);
  1406. dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
  1407. dasd_schedule_device_bh(device);
  1408. if (device->block) {
  1409. dasd_schedule_block_bh(device->block);
  1410. if (device->block->request_queue)
  1411. blk_mq_run_hw_queues(device->block->request_queue,
  1412. true);
  1413. }
  1414. }
  1415. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  1416. static int dasd_check_hpf_error(struct irb *irb)
  1417. {
  1418. return (scsw_tm_is_valid_schxs(&irb->scsw) &&
  1419. (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
  1420. irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
  1421. }
  1422. /*
  1423. * Interrupt handler for "normal" ssch-io based dasd devices.
  1424. */
  1425. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  1426. struct irb *irb)
  1427. {
  1428. struct dasd_ccw_req *cqr, *next;
  1429. struct dasd_device *device;
  1430. unsigned long now;
  1431. int nrf_suppressed = 0;
  1432. int fp_suppressed = 0;
  1433. u8 *sense = NULL;
  1434. int expires;
  1435. cqr = (struct dasd_ccw_req *) intparm;
  1436. if (IS_ERR(irb)) {
  1437. switch (PTR_ERR(irb)) {
  1438. case -EIO:
  1439. if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
  1440. device = cqr->startdev;
  1441. cqr->status = DASD_CQR_CLEARED;
  1442. dasd_device_clear_timer(device);
  1443. wake_up(&dasd_flush_wq);
  1444. dasd_schedule_device_bh(device);
  1445. return;
  1446. }
  1447. break;
  1448. case -ETIMEDOUT:
  1449. DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
  1450. "request timed out\n", __func__);
  1451. break;
  1452. default:
  1453. DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
  1454. "unknown error %ld\n", __func__,
  1455. PTR_ERR(irb));
  1456. }
  1457. dasd_handle_killed_request(cdev, intparm);
  1458. return;
  1459. }
  1460. now = get_tod_clock();
  1461. /* check for conditions that should be handled immediately */
  1462. if (!cqr ||
  1463. !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  1464. scsw_cstat(&irb->scsw) == 0)) {
  1465. if (cqr)
  1466. memcpy(&cqr->irb, irb, sizeof(*irb));
  1467. device = dasd_device_from_cdev_locked(cdev);
  1468. if (IS_ERR(device))
  1469. return;
  1470. /* ignore unsolicited interrupts for DIAG discipline */
  1471. if (device->discipline == dasd_diag_discipline_pointer) {
  1472. dasd_put_device(device);
  1473. return;
  1474. }
  1475. /*
  1476. * In some cases 'File Protected' or 'No Record Found' errors
  1477. * might be expected and debug log messages for the
  1478. * corresponding interrupts shouldn't be written then.
  1479. * Check if either of the according suppress bits is set.
  1480. */
  1481. sense = dasd_get_sense(irb);
  1482. if (sense) {
  1483. fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
  1484. test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
  1485. nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
  1486. test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
  1487. }
  1488. if (!(fp_suppressed || nrf_suppressed))
  1489. device->discipline->dump_sense_dbf(device, irb, "int");
  1490. if (device->features & DASD_FEATURE_ERPLOG)
  1491. device->discipline->dump_sense(device, cqr, irb);
  1492. device->discipline->check_for_device_change(device, cqr, irb);
  1493. dasd_put_device(device);
  1494. }
  1495. /* check for for attention message */
  1496. if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
  1497. device = dasd_device_from_cdev_locked(cdev);
  1498. if (!IS_ERR(device)) {
  1499. device->discipline->check_attention(device,
  1500. irb->esw.esw1.lpum);
  1501. dasd_put_device(device);
  1502. }
  1503. }
  1504. if (!cqr)
  1505. return;
  1506. device = (struct dasd_device *) cqr->startdev;
  1507. if (!device ||
  1508. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  1509. DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
  1510. "invalid device in request");
  1511. return;
  1512. }
  1513. /* Check for clear pending */
  1514. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  1515. scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
  1516. cqr->status = DASD_CQR_CLEARED;
  1517. dasd_device_clear_timer(device);
  1518. wake_up(&dasd_flush_wq);
  1519. dasd_schedule_device_bh(device);
  1520. return;
  1521. }
  1522. /* check status - the request might have been killed by dyn detach */
  1523. if (cqr->status != DASD_CQR_IN_IO) {
  1524. DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
  1525. "status %02x", dev_name(&cdev->dev), cqr->status);
  1526. return;
  1527. }
  1528. next = NULL;
  1529. expires = 0;
  1530. if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  1531. scsw_cstat(&irb->scsw) == 0) {
  1532. /* request was completed successfully */
  1533. cqr->status = DASD_CQR_SUCCESS;
  1534. cqr->stopclk = now;
  1535. /* Start first request on queue if possible -> fast_io. */
  1536. if (cqr->devlist.next != &device->ccw_queue) {
  1537. next = list_entry(cqr->devlist.next,
  1538. struct dasd_ccw_req, devlist);
  1539. }
  1540. } else { /* error */
  1541. /* check for HPF error
  1542. * call discipline function to requeue all requests
  1543. * and disable HPF accordingly
  1544. */
  1545. if (cqr->cpmode && dasd_check_hpf_error(irb) &&
  1546. device->discipline->handle_hpf_error)
  1547. device->discipline->handle_hpf_error(device, irb);
  1548. /*
  1549. * If we don't want complex ERP for this request, then just
  1550. * reset this and retry it in the fastpath
  1551. */
  1552. if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
  1553. cqr->retries > 0) {
  1554. if (cqr->lpm == dasd_path_get_opm(device))
  1555. DBF_DEV_EVENT(DBF_DEBUG, device,
  1556. "default ERP in fastpath "
  1557. "(%i retries left)",
  1558. cqr->retries);
  1559. if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
  1560. cqr->lpm = dasd_path_get_opm(device);
  1561. cqr->status = DASD_CQR_QUEUED;
  1562. next = cqr;
  1563. } else
  1564. cqr->status = DASD_CQR_ERROR;
  1565. }
  1566. if (next && (next->status == DASD_CQR_QUEUED) &&
  1567. (!device->stopped)) {
  1568. if (device->discipline->start_IO(next) == 0)
  1569. expires = next->expires;
  1570. }
  1571. if (expires != 0)
  1572. dasd_device_set_timer(device, expires);
  1573. else
  1574. dasd_device_clear_timer(device);
  1575. dasd_schedule_device_bh(device);
  1576. }
  1577. EXPORT_SYMBOL(dasd_int_handler);
  1578. enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
  1579. {
  1580. struct dasd_device *device;
  1581. device = dasd_device_from_cdev_locked(cdev);
  1582. if (IS_ERR(device))
  1583. goto out;
  1584. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  1585. device->state != device->target ||
  1586. !device->discipline->check_for_device_change){
  1587. dasd_put_device(device);
  1588. goto out;
  1589. }
  1590. if (device->discipline->dump_sense_dbf)
  1591. device->discipline->dump_sense_dbf(device, irb, "uc");
  1592. device->discipline->check_for_device_change(device, NULL, irb);
  1593. dasd_put_device(device);
  1594. out:
  1595. return UC_TODO_RETRY;
  1596. }
  1597. EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
  1598. /*
  1599. * If we have an error on a dasd_block layer request then we cancel
  1600. * and return all further requests from the same dasd_block as well.
  1601. */
  1602. static void __dasd_device_recovery(struct dasd_device *device,
  1603. struct dasd_ccw_req *ref_cqr)
  1604. {
  1605. struct list_head *l, *n;
  1606. struct dasd_ccw_req *cqr;
  1607. /*
  1608. * only requeue request that came from the dasd_block layer
  1609. */
  1610. if (!ref_cqr->block)
  1611. return;
  1612. list_for_each_safe(l, n, &device->ccw_queue) {
  1613. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1614. if (cqr->status == DASD_CQR_QUEUED &&
  1615. ref_cqr->block == cqr->block) {
  1616. cqr->status = DASD_CQR_CLEARED;
  1617. }
  1618. }
  1619. };
  1620. /*
  1621. * Remove those ccw requests from the queue that need to be returned
  1622. * to the upper layer.
  1623. */
  1624. static void __dasd_device_process_ccw_queue(struct dasd_device *device,
  1625. struct list_head *final_queue)
  1626. {
  1627. struct list_head *l, *n;
  1628. struct dasd_ccw_req *cqr;
  1629. /* Process request with final status. */
  1630. list_for_each_safe(l, n, &device->ccw_queue) {
  1631. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1632. /* Skip any non-final request. */
  1633. if (cqr->status == DASD_CQR_QUEUED ||
  1634. cqr->status == DASD_CQR_IN_IO ||
  1635. cqr->status == DASD_CQR_CLEAR_PENDING)
  1636. continue;
  1637. if (cqr->status == DASD_CQR_ERROR) {
  1638. __dasd_device_recovery(device, cqr);
  1639. }
  1640. /* Rechain finished requests to final queue */
  1641. list_move_tail(&cqr->devlist, final_queue);
  1642. }
  1643. }
  1644. static void __dasd_process_cqr(struct dasd_device *device,
  1645. struct dasd_ccw_req *cqr)
  1646. {
  1647. char errorstring[ERRORLENGTH];
  1648. switch (cqr->status) {
  1649. case DASD_CQR_SUCCESS:
  1650. cqr->status = DASD_CQR_DONE;
  1651. break;
  1652. case DASD_CQR_ERROR:
  1653. cqr->status = DASD_CQR_NEED_ERP;
  1654. break;
  1655. case DASD_CQR_CLEARED:
  1656. cqr->status = DASD_CQR_TERMINATED;
  1657. break;
  1658. default:
  1659. /* internal error 12 - wrong cqr status*/
  1660. snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
  1661. dev_err(&device->cdev->dev,
  1662. "An error occurred in the DASD device driver, "
  1663. "reason=%s\n", errorstring);
  1664. BUG();
  1665. }
  1666. if (cqr->callback)
  1667. cqr->callback(cqr, cqr->callback_data);
  1668. }
  1669. /*
  1670. * the cqrs from the final queue are returned to the upper layer
  1671. * by setting a dasd_block state and calling the callback function
  1672. */
  1673. static void __dasd_device_process_final_queue(struct dasd_device *device,
  1674. struct list_head *final_queue)
  1675. {
  1676. struct list_head *l, *n;
  1677. struct dasd_ccw_req *cqr;
  1678. struct dasd_block *block;
  1679. list_for_each_safe(l, n, final_queue) {
  1680. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1681. list_del_init(&cqr->devlist);
  1682. block = cqr->block;
  1683. if (!block) {
  1684. __dasd_process_cqr(device, cqr);
  1685. } else {
  1686. spin_lock_bh(&block->queue_lock);
  1687. __dasd_process_cqr(device, cqr);
  1688. spin_unlock_bh(&block->queue_lock);
  1689. }
  1690. }
  1691. }
  1692. /*
  1693. * Take a look at the first request on the ccw queue and check
  1694. * if it reached its expire time. If so, terminate the IO.
  1695. */
  1696. static void __dasd_device_check_expire(struct dasd_device *device)
  1697. {
  1698. struct dasd_ccw_req *cqr;
  1699. if (list_empty(&device->ccw_queue))
  1700. return;
  1701. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1702. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1703. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1704. if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  1705. /*
  1706. * IO in safe offline processing should not
  1707. * run out of retries
  1708. */
  1709. cqr->retries++;
  1710. }
  1711. if (device->discipline->term_IO(cqr) != 0) {
  1712. /* Hmpf, try again in 5 sec */
  1713. dev_err(&device->cdev->dev,
  1714. "cqr %p timed out (%lus) but cannot be "
  1715. "ended, retrying in 5 s\n",
  1716. cqr, (cqr->expires/HZ));
  1717. cqr->expires += 5*HZ;
  1718. dasd_device_set_timer(device, 5*HZ);
  1719. } else {
  1720. dev_err(&device->cdev->dev,
  1721. "cqr %p timed out (%lus), %i retries "
  1722. "remaining\n", cqr, (cqr->expires/HZ),
  1723. cqr->retries);
  1724. }
  1725. }
  1726. }
  1727. /*
  1728. * return 1 when device is not eligible for IO
  1729. */
  1730. static int __dasd_device_is_unusable(struct dasd_device *device,
  1731. struct dasd_ccw_req *cqr)
  1732. {
  1733. int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
  1734. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
  1735. !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  1736. /*
  1737. * dasd is being set offline
  1738. * but it is no safe offline where we have to allow I/O
  1739. */
  1740. return 1;
  1741. }
  1742. if (device->stopped) {
  1743. if (device->stopped & mask) {
  1744. /* stopped and CQR will not change that. */
  1745. return 1;
  1746. }
  1747. if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
  1748. /* CQR is not able to change device to
  1749. * operational. */
  1750. return 1;
  1751. }
  1752. /* CQR required to get device operational. */
  1753. }
  1754. return 0;
  1755. }
  1756. /*
  1757. * Take a look at the first request on the ccw queue and check
  1758. * if it needs to be started.
  1759. */
  1760. static void __dasd_device_start_head(struct dasd_device *device)
  1761. {
  1762. struct dasd_ccw_req *cqr;
  1763. int rc;
  1764. if (list_empty(&device->ccw_queue))
  1765. return;
  1766. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1767. if (cqr->status != DASD_CQR_QUEUED)
  1768. return;
  1769. /* if device is not usable return request to upper layer */
  1770. if (__dasd_device_is_unusable(device, cqr)) {
  1771. cqr->intrc = -EAGAIN;
  1772. cqr->status = DASD_CQR_CLEARED;
  1773. dasd_schedule_device_bh(device);
  1774. return;
  1775. }
  1776. rc = device->discipline->start_IO(cqr);
  1777. if (rc == 0)
  1778. dasd_device_set_timer(device, cqr->expires);
  1779. else if (rc == -EACCES) {
  1780. dasd_schedule_device_bh(device);
  1781. } else
  1782. /* Hmpf, try again in 1/2 sec */
  1783. dasd_device_set_timer(device, 50);
  1784. }
  1785. static void __dasd_device_check_path_events(struct dasd_device *device)
  1786. {
  1787. int rc;
  1788. if (!dasd_path_get_tbvpm(device))
  1789. return;
  1790. if (device->stopped &
  1791. ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
  1792. return;
  1793. rc = device->discipline->verify_path(device,
  1794. dasd_path_get_tbvpm(device));
  1795. if (rc)
  1796. dasd_device_set_timer(device, 50);
  1797. else
  1798. dasd_path_clear_all_verify(device);
  1799. };
  1800. /*
  1801. * Go through all request on the dasd_device request queue,
  1802. * terminate them on the cdev if necessary, and return them to the
  1803. * submitting layer via callback.
  1804. * Note:
  1805. * Make sure that all 'submitting layers' still exist when
  1806. * this function is called!. In other words, when 'device' is a base
  1807. * device then all block layer requests must have been removed before
  1808. * via dasd_flush_block_queue.
  1809. */
  1810. int dasd_flush_device_queue(struct dasd_device *device)
  1811. {
  1812. struct dasd_ccw_req *cqr, *n;
  1813. int rc;
  1814. struct list_head flush_queue;
  1815. INIT_LIST_HEAD(&flush_queue);
  1816. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1817. rc = 0;
  1818. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1819. /* Check status and move request to flush_queue */
  1820. switch (cqr->status) {
  1821. case DASD_CQR_IN_IO:
  1822. rc = device->discipline->term_IO(cqr);
  1823. if (rc) {
  1824. /* unable to terminate requeust */
  1825. dev_err(&device->cdev->dev,
  1826. "Flushing the DASD request queue "
  1827. "failed for request %p\n", cqr);
  1828. /* stop flush processing */
  1829. goto finished;
  1830. }
  1831. break;
  1832. case DASD_CQR_QUEUED:
  1833. cqr->stopclk = get_tod_clock();
  1834. cqr->status = DASD_CQR_CLEARED;
  1835. break;
  1836. default: /* no need to modify the others */
  1837. break;
  1838. }
  1839. list_move_tail(&cqr->devlist, &flush_queue);
  1840. }
  1841. finished:
  1842. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1843. /*
  1844. * After this point all requests must be in state CLEAR_PENDING,
  1845. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1846. * one of the others.
  1847. */
  1848. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1849. wait_event(dasd_flush_wq,
  1850. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1851. /*
  1852. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1853. * and call the callback function of flushed requests
  1854. */
  1855. __dasd_device_process_final_queue(device, &flush_queue);
  1856. return rc;
  1857. }
  1858. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  1859. /*
  1860. * Acquire the device lock and process queues for the device.
  1861. */
  1862. static void dasd_device_tasklet(unsigned long data)
  1863. {
  1864. struct dasd_device *device = (struct dasd_device *) data;
  1865. struct list_head final_queue;
  1866. atomic_set (&device->tasklet_scheduled, 0);
  1867. INIT_LIST_HEAD(&final_queue);
  1868. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1869. /* Check expire time of first request on the ccw queue. */
  1870. __dasd_device_check_expire(device);
  1871. /* find final requests on ccw queue */
  1872. __dasd_device_process_ccw_queue(device, &final_queue);
  1873. __dasd_device_check_path_events(device);
  1874. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1875. /* Now call the callback function of requests with final status */
  1876. __dasd_device_process_final_queue(device, &final_queue);
  1877. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1878. /* Now check if the head of the ccw queue needs to be started. */
  1879. __dasd_device_start_head(device);
  1880. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1881. if (waitqueue_active(&shutdown_waitq))
  1882. wake_up(&shutdown_waitq);
  1883. dasd_put_device(device);
  1884. }
  1885. /*
  1886. * Schedules a call to dasd_tasklet over the device tasklet.
  1887. */
  1888. void dasd_schedule_device_bh(struct dasd_device *device)
  1889. {
  1890. /* Protect against rescheduling. */
  1891. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1892. return;
  1893. dasd_get_device(device);
  1894. tasklet_hi_schedule(&device->tasklet);
  1895. }
  1896. EXPORT_SYMBOL(dasd_schedule_device_bh);
  1897. void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
  1898. {
  1899. device->stopped |= bits;
  1900. }
  1901. EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
  1902. void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
  1903. {
  1904. device->stopped &= ~bits;
  1905. if (!device->stopped)
  1906. wake_up(&generic_waitq);
  1907. }
  1908. EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
  1909. /*
  1910. * Queue a request to the head of the device ccw_queue.
  1911. * Start the I/O if possible.
  1912. */
  1913. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1914. {
  1915. struct dasd_device *device;
  1916. unsigned long flags;
  1917. device = cqr->startdev;
  1918. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1919. cqr->status = DASD_CQR_QUEUED;
  1920. list_add(&cqr->devlist, &device->ccw_queue);
  1921. /* let the bh start the request to keep them in order */
  1922. dasd_schedule_device_bh(device);
  1923. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1924. }
  1925. EXPORT_SYMBOL(dasd_add_request_head);
  1926. /*
  1927. * Queue a request to the tail of the device ccw_queue.
  1928. * Start the I/O if possible.
  1929. */
  1930. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1931. {
  1932. struct dasd_device *device;
  1933. unsigned long flags;
  1934. device = cqr->startdev;
  1935. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1936. cqr->status = DASD_CQR_QUEUED;
  1937. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1938. /* let the bh start the request to keep them in order */
  1939. dasd_schedule_device_bh(device);
  1940. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1941. }
  1942. EXPORT_SYMBOL(dasd_add_request_tail);
  1943. /*
  1944. * Wakeup helper for the 'sleep_on' functions.
  1945. */
  1946. void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1947. {
  1948. spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
  1949. cqr->callback_data = DASD_SLEEPON_END_TAG;
  1950. spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
  1951. wake_up(&generic_waitq);
  1952. }
  1953. EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
  1954. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1955. {
  1956. struct dasd_device *device;
  1957. int rc;
  1958. device = cqr->startdev;
  1959. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1960. rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
  1961. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1962. return rc;
  1963. }
  1964. /*
  1965. * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
  1966. */
  1967. static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
  1968. {
  1969. struct dasd_device *device;
  1970. dasd_erp_fn_t erp_fn;
  1971. if (cqr->status == DASD_CQR_FILLED)
  1972. return 0;
  1973. device = cqr->startdev;
  1974. if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
  1975. if (cqr->status == DASD_CQR_TERMINATED) {
  1976. device->discipline->handle_terminated_request(cqr);
  1977. return 1;
  1978. }
  1979. if (cqr->status == DASD_CQR_NEED_ERP) {
  1980. erp_fn = device->discipline->erp_action(cqr);
  1981. erp_fn(cqr);
  1982. return 1;
  1983. }
  1984. if (cqr->status == DASD_CQR_FAILED)
  1985. dasd_log_sense(cqr, &cqr->irb);
  1986. if (cqr->refers) {
  1987. __dasd_process_erp(device, cqr);
  1988. return 1;
  1989. }
  1990. }
  1991. return 0;
  1992. }
  1993. static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
  1994. {
  1995. if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
  1996. if (cqr->refers) /* erp is not done yet */
  1997. return 1;
  1998. return ((cqr->status != DASD_CQR_DONE) &&
  1999. (cqr->status != DASD_CQR_FAILED));
  2000. } else
  2001. return (cqr->status == DASD_CQR_FILLED);
  2002. }
  2003. static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
  2004. {
  2005. struct dasd_device *device;
  2006. int rc;
  2007. struct list_head ccw_queue;
  2008. struct dasd_ccw_req *cqr;
  2009. INIT_LIST_HEAD(&ccw_queue);
  2010. maincqr->status = DASD_CQR_FILLED;
  2011. device = maincqr->startdev;
  2012. list_add(&maincqr->blocklist, &ccw_queue);
  2013. for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
  2014. cqr = list_first_entry(&ccw_queue,
  2015. struct dasd_ccw_req, blocklist)) {
  2016. if (__dasd_sleep_on_erp(cqr))
  2017. continue;
  2018. if (cqr->status != DASD_CQR_FILLED) /* could be failed */
  2019. continue;
  2020. if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
  2021. !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
  2022. cqr->status = DASD_CQR_FAILED;
  2023. cqr->intrc = -EPERM;
  2024. continue;
  2025. }
  2026. /* Non-temporary stop condition will trigger fail fast */
  2027. if (device->stopped & ~DASD_STOPPED_PENDING &&
  2028. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  2029. (!dasd_eer_enabled(device))) {
  2030. cqr->status = DASD_CQR_FAILED;
  2031. cqr->intrc = -ENOLINK;
  2032. continue;
  2033. }
  2034. /*
  2035. * Don't try to start requests if device is in
  2036. * offline processing, it might wait forever
  2037. */
  2038. if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2039. cqr->status = DASD_CQR_FAILED;
  2040. cqr->intrc = -ENODEV;
  2041. continue;
  2042. }
  2043. /*
  2044. * Don't try to start requests if device is stopped
  2045. * except path verification requests
  2046. */
  2047. if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
  2048. if (interruptible) {
  2049. rc = wait_event_interruptible(
  2050. generic_waitq, !(device->stopped));
  2051. if (rc == -ERESTARTSYS) {
  2052. cqr->status = DASD_CQR_FAILED;
  2053. maincqr->intrc = rc;
  2054. continue;
  2055. }
  2056. } else
  2057. wait_event(generic_waitq, !(device->stopped));
  2058. }
  2059. if (!cqr->callback)
  2060. cqr->callback = dasd_wakeup_cb;
  2061. cqr->callback_data = DASD_SLEEPON_START_TAG;
  2062. dasd_add_request_tail(cqr);
  2063. if (interruptible) {
  2064. rc = wait_event_interruptible(
  2065. generic_waitq, _wait_for_wakeup(cqr));
  2066. if (rc == -ERESTARTSYS) {
  2067. dasd_cancel_req(cqr);
  2068. /* wait (non-interruptible) for final status */
  2069. wait_event(generic_waitq,
  2070. _wait_for_wakeup(cqr));
  2071. cqr->status = DASD_CQR_FAILED;
  2072. maincqr->intrc = rc;
  2073. continue;
  2074. }
  2075. } else
  2076. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  2077. }
  2078. maincqr->endclk = get_tod_clock();
  2079. if ((maincqr->status != DASD_CQR_DONE) &&
  2080. (maincqr->intrc != -ERESTARTSYS))
  2081. dasd_log_sense(maincqr, &maincqr->irb);
  2082. if (maincqr->status == DASD_CQR_DONE)
  2083. rc = 0;
  2084. else if (maincqr->intrc)
  2085. rc = maincqr->intrc;
  2086. else
  2087. rc = -EIO;
  2088. return rc;
  2089. }
  2090. static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
  2091. {
  2092. struct dasd_ccw_req *cqr;
  2093. list_for_each_entry(cqr, ccw_queue, blocklist) {
  2094. if (cqr->callback_data != DASD_SLEEPON_END_TAG)
  2095. return 0;
  2096. }
  2097. return 1;
  2098. }
  2099. static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
  2100. {
  2101. struct dasd_device *device;
  2102. struct dasd_ccw_req *cqr, *n;
  2103. u8 *sense = NULL;
  2104. int rc;
  2105. retry:
  2106. list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
  2107. device = cqr->startdev;
  2108. if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
  2109. continue;
  2110. if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
  2111. !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
  2112. cqr->status = DASD_CQR_FAILED;
  2113. cqr->intrc = -EPERM;
  2114. continue;
  2115. }
  2116. /*Non-temporary stop condition will trigger fail fast*/
  2117. if (device->stopped & ~DASD_STOPPED_PENDING &&
  2118. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  2119. !dasd_eer_enabled(device)) {
  2120. cqr->status = DASD_CQR_FAILED;
  2121. cqr->intrc = -EAGAIN;
  2122. continue;
  2123. }
  2124. /*Don't try to start requests if device is stopped*/
  2125. if (interruptible) {
  2126. rc = wait_event_interruptible(
  2127. generic_waitq, !device->stopped);
  2128. if (rc == -ERESTARTSYS) {
  2129. cqr->status = DASD_CQR_FAILED;
  2130. cqr->intrc = rc;
  2131. continue;
  2132. }
  2133. } else
  2134. wait_event(generic_waitq, !(device->stopped));
  2135. if (!cqr->callback)
  2136. cqr->callback = dasd_wakeup_cb;
  2137. cqr->callback_data = DASD_SLEEPON_START_TAG;
  2138. dasd_add_request_tail(cqr);
  2139. }
  2140. wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
  2141. rc = 0;
  2142. list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
  2143. /*
  2144. * In some cases the 'File Protected' or 'Incorrect Length'
  2145. * error might be expected and error recovery would be
  2146. * unnecessary in these cases. Check if the according suppress
  2147. * bit is set.
  2148. */
  2149. sense = dasd_get_sense(&cqr->irb);
  2150. if (sense && sense[1] & SNS1_FILE_PROTECTED &&
  2151. test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
  2152. continue;
  2153. if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
  2154. test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
  2155. continue;
  2156. /*
  2157. * for alias devices simplify error recovery and
  2158. * return to upper layer
  2159. * do not skip ERP requests
  2160. */
  2161. if (cqr->startdev != cqr->basedev && !cqr->refers &&
  2162. (cqr->status == DASD_CQR_TERMINATED ||
  2163. cqr->status == DASD_CQR_NEED_ERP))
  2164. return -EAGAIN;
  2165. /* normal recovery for basedev IO */
  2166. if (__dasd_sleep_on_erp(cqr))
  2167. /* handle erp first */
  2168. goto retry;
  2169. }
  2170. return 0;
  2171. }
  2172. /*
  2173. * Queue a request to the tail of the device ccw_queue and wait for
  2174. * it's completion.
  2175. */
  2176. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  2177. {
  2178. return _dasd_sleep_on(cqr, 0);
  2179. }
  2180. EXPORT_SYMBOL(dasd_sleep_on);
  2181. /*
  2182. * Start requests from a ccw_queue and wait for their completion.
  2183. */
  2184. int dasd_sleep_on_queue(struct list_head *ccw_queue)
  2185. {
  2186. return _dasd_sleep_on_queue(ccw_queue, 0);
  2187. }
  2188. EXPORT_SYMBOL(dasd_sleep_on_queue);
  2189. /*
  2190. * Queue a request to the tail of the device ccw_queue and wait
  2191. * interruptible for it's completion.
  2192. */
  2193. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  2194. {
  2195. return _dasd_sleep_on(cqr, 1);
  2196. }
  2197. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2198. /*
  2199. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  2200. * for eckd devices) the currently running request has to be terminated
  2201. * and be put back to status queued, before the special request is added
  2202. * to the head of the queue. Then the special request is waited on normally.
  2203. */
  2204. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  2205. {
  2206. struct dasd_ccw_req *cqr;
  2207. int rc;
  2208. if (list_empty(&device->ccw_queue))
  2209. return 0;
  2210. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  2211. rc = device->discipline->term_IO(cqr);
  2212. if (!rc)
  2213. /*
  2214. * CQR terminated because a more important request is pending.
  2215. * Undo decreasing of retry counter because this is
  2216. * not an error case.
  2217. */
  2218. cqr->retries++;
  2219. return rc;
  2220. }
  2221. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  2222. {
  2223. struct dasd_device *device;
  2224. int rc;
  2225. device = cqr->startdev;
  2226. if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
  2227. !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
  2228. cqr->status = DASD_CQR_FAILED;
  2229. cqr->intrc = -EPERM;
  2230. return -EIO;
  2231. }
  2232. spin_lock_irq(get_ccwdev_lock(device->cdev));
  2233. rc = _dasd_term_running_cqr(device);
  2234. if (rc) {
  2235. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  2236. return rc;
  2237. }
  2238. cqr->callback = dasd_wakeup_cb;
  2239. cqr->callback_data = DASD_SLEEPON_START_TAG;
  2240. cqr->status = DASD_CQR_QUEUED;
  2241. /*
  2242. * add new request as second
  2243. * first the terminated cqr needs to be finished
  2244. */
  2245. list_add(&cqr->devlist, device->ccw_queue.next);
  2246. /* let the bh start the request to keep them in order */
  2247. dasd_schedule_device_bh(device);
  2248. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  2249. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  2250. if (cqr->status == DASD_CQR_DONE)
  2251. rc = 0;
  2252. else if (cqr->intrc)
  2253. rc = cqr->intrc;
  2254. else
  2255. rc = -EIO;
  2256. /* kick tasklets */
  2257. dasd_schedule_device_bh(device);
  2258. if (device->block)
  2259. dasd_schedule_block_bh(device->block);
  2260. return rc;
  2261. }
  2262. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2263. /*
  2264. * Cancels a request that was started with dasd_sleep_on_req.
  2265. * This is useful to timeout requests. The request will be
  2266. * terminated if it is currently in i/o.
  2267. * Returns 0 if request termination was successful
  2268. * negative error code if termination failed
  2269. * Cancellation of a request is an asynchronous operation! The calling
  2270. * function has to wait until the request is properly returned via callback.
  2271. */
  2272. static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
  2273. {
  2274. struct dasd_device *device = cqr->startdev;
  2275. int rc = 0;
  2276. switch (cqr->status) {
  2277. case DASD_CQR_QUEUED:
  2278. /* request was not started - just set to cleared */
  2279. cqr->status = DASD_CQR_CLEARED;
  2280. break;
  2281. case DASD_CQR_IN_IO:
  2282. /* request in IO - terminate IO and release again */
  2283. rc = device->discipline->term_IO(cqr);
  2284. if (rc) {
  2285. dev_err(&device->cdev->dev,
  2286. "Cancelling request %p failed with rc=%d\n",
  2287. cqr, rc);
  2288. } else {
  2289. cqr->stopclk = get_tod_clock();
  2290. }
  2291. break;
  2292. default: /* already finished or clear pending - do nothing */
  2293. break;
  2294. }
  2295. dasd_schedule_device_bh(device);
  2296. return rc;
  2297. }
  2298. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  2299. {
  2300. struct dasd_device *device = cqr->startdev;
  2301. unsigned long flags;
  2302. int rc;
  2303. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  2304. rc = __dasd_cancel_req(cqr);
  2305. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  2306. return rc;
  2307. }
  2308. /*
  2309. * SECTION: Operations of the dasd_block layer.
  2310. */
  2311. /*
  2312. * Timeout function for dasd_block. This is used when the block layer
  2313. * is waiting for something that may not come reliably, (e.g. a state
  2314. * change interrupt)
  2315. */
  2316. static void dasd_block_timeout(struct timer_list *t)
  2317. {
  2318. unsigned long flags;
  2319. struct dasd_block *block;
  2320. block = from_timer(block, t, timer);
  2321. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  2322. /* re-activate request queue */
  2323. dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
  2324. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  2325. dasd_schedule_block_bh(block);
  2326. blk_mq_run_hw_queues(block->request_queue, true);
  2327. }
  2328. /*
  2329. * Setup timeout for a dasd_block in jiffies.
  2330. */
  2331. void dasd_block_set_timer(struct dasd_block *block, int expires)
  2332. {
  2333. if (expires == 0)
  2334. del_timer(&block->timer);
  2335. else
  2336. mod_timer(&block->timer, jiffies + expires);
  2337. }
  2338. EXPORT_SYMBOL(dasd_block_set_timer);
  2339. /*
  2340. * Clear timeout for a dasd_block.
  2341. */
  2342. void dasd_block_clear_timer(struct dasd_block *block)
  2343. {
  2344. del_timer(&block->timer);
  2345. }
  2346. EXPORT_SYMBOL(dasd_block_clear_timer);
  2347. /*
  2348. * Process finished error recovery ccw.
  2349. */
  2350. static void __dasd_process_erp(struct dasd_device *device,
  2351. struct dasd_ccw_req *cqr)
  2352. {
  2353. dasd_erp_fn_t erp_fn;
  2354. if (cqr->status == DASD_CQR_DONE)
  2355. DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
  2356. else
  2357. dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
  2358. erp_fn = device->discipline->erp_postaction(cqr);
  2359. erp_fn(cqr);
  2360. }
  2361. static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
  2362. {
  2363. struct request *req;
  2364. blk_status_t error = BLK_STS_OK;
  2365. int status;
  2366. req = (struct request *) cqr->callback_data;
  2367. dasd_profile_end(cqr->block, cqr, req);
  2368. status = cqr->block->base->discipline->free_cp(cqr, req);
  2369. if (status < 0)
  2370. error = errno_to_blk_status(status);
  2371. else if (status == 0) {
  2372. switch (cqr->intrc) {
  2373. case -EPERM:
  2374. error = BLK_STS_NEXUS;
  2375. break;
  2376. case -ENOLINK:
  2377. error = BLK_STS_TRANSPORT;
  2378. break;
  2379. case -ETIMEDOUT:
  2380. error = BLK_STS_TIMEOUT;
  2381. break;
  2382. default:
  2383. error = BLK_STS_IOERR;
  2384. break;
  2385. }
  2386. }
  2387. /*
  2388. * We need to take care for ETIMEDOUT errors here since the
  2389. * complete callback does not get called in this case.
  2390. * Take care of all errors here and avoid additional code to
  2391. * transfer the error value to the complete callback.
  2392. */
  2393. if (error) {
  2394. blk_mq_end_request(req, error);
  2395. blk_mq_run_hw_queues(req->q, true);
  2396. } else {
  2397. blk_mq_complete_request(req);
  2398. }
  2399. }
  2400. /*
  2401. * Process ccw request queue.
  2402. */
  2403. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  2404. struct list_head *final_queue)
  2405. {
  2406. struct list_head *l, *n;
  2407. struct dasd_ccw_req *cqr;
  2408. dasd_erp_fn_t erp_fn;
  2409. unsigned long flags;
  2410. struct dasd_device *base = block->base;
  2411. restart:
  2412. /* Process request with final status. */
  2413. list_for_each_safe(l, n, &block->ccw_queue) {
  2414. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  2415. if (cqr->status != DASD_CQR_DONE &&
  2416. cqr->status != DASD_CQR_FAILED &&
  2417. cqr->status != DASD_CQR_NEED_ERP &&
  2418. cqr->status != DASD_CQR_TERMINATED)
  2419. continue;
  2420. if (cqr->status == DASD_CQR_TERMINATED) {
  2421. base->discipline->handle_terminated_request(cqr);
  2422. goto restart;
  2423. }
  2424. /* Process requests that may be recovered */
  2425. if (cqr->status == DASD_CQR_NEED_ERP) {
  2426. erp_fn = base->discipline->erp_action(cqr);
  2427. if (IS_ERR(erp_fn(cqr)))
  2428. continue;
  2429. goto restart;
  2430. }
  2431. /* log sense for fatal error */
  2432. if (cqr->status == DASD_CQR_FAILED) {
  2433. dasd_log_sense(cqr, &cqr->irb);
  2434. }
  2435. /* First of all call extended error reporting. */
  2436. if (dasd_eer_enabled(base) &&
  2437. cqr->status == DASD_CQR_FAILED) {
  2438. dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
  2439. /* restart request */
  2440. cqr->status = DASD_CQR_FILLED;
  2441. cqr->retries = 255;
  2442. spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
  2443. dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
  2444. spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
  2445. flags);
  2446. goto restart;
  2447. }
  2448. /* Process finished ERP request. */
  2449. if (cqr->refers) {
  2450. __dasd_process_erp(base, cqr);
  2451. goto restart;
  2452. }
  2453. /* Rechain finished requests to final queue */
  2454. cqr->endclk = get_tod_clock();
  2455. list_move_tail(&cqr->blocklist, final_queue);
  2456. }
  2457. }
  2458. static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
  2459. {
  2460. dasd_schedule_block_bh(cqr->block);
  2461. }
  2462. static void __dasd_block_start_head(struct dasd_block *block)
  2463. {
  2464. struct dasd_ccw_req *cqr;
  2465. if (list_empty(&block->ccw_queue))
  2466. return;
  2467. /* We allways begin with the first requests on the queue, as some
  2468. * of previously started requests have to be enqueued on a
  2469. * dasd_device again for error recovery.
  2470. */
  2471. list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
  2472. if (cqr->status != DASD_CQR_FILLED)
  2473. continue;
  2474. if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
  2475. !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
  2476. cqr->status = DASD_CQR_FAILED;
  2477. cqr->intrc = -EPERM;
  2478. dasd_schedule_block_bh(block);
  2479. continue;
  2480. }
  2481. /* Non-temporary stop condition will trigger fail fast */
  2482. if (block->base->stopped & ~DASD_STOPPED_PENDING &&
  2483. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  2484. (!dasd_eer_enabled(block->base))) {
  2485. cqr->status = DASD_CQR_FAILED;
  2486. cqr->intrc = -ENOLINK;
  2487. dasd_schedule_block_bh(block);
  2488. continue;
  2489. }
  2490. /* Don't try to start requests if device is stopped */
  2491. if (block->base->stopped)
  2492. return;
  2493. /* just a fail safe check, should not happen */
  2494. if (!cqr->startdev)
  2495. cqr->startdev = block->base;
  2496. /* make sure that the requests we submit find their way back */
  2497. cqr->callback = dasd_return_cqr_cb;
  2498. dasd_add_request_tail(cqr);
  2499. }
  2500. }
  2501. /*
  2502. * Central dasd_block layer routine. Takes requests from the generic
  2503. * block layer request queue, creates ccw requests, enqueues them on
  2504. * a dasd_device and processes ccw requests that have been returned.
  2505. */
  2506. static void dasd_block_tasklet(unsigned long data)
  2507. {
  2508. struct dasd_block *block = (struct dasd_block *) data;
  2509. struct list_head final_queue;
  2510. struct list_head *l, *n;
  2511. struct dasd_ccw_req *cqr;
  2512. struct dasd_queue *dq;
  2513. atomic_set(&block->tasklet_scheduled, 0);
  2514. INIT_LIST_HEAD(&final_queue);
  2515. spin_lock_irq(&block->queue_lock);
  2516. /* Finish off requests on ccw queue */
  2517. __dasd_process_block_ccw_queue(block, &final_queue);
  2518. spin_unlock_irq(&block->queue_lock);
  2519. /* Now call the callback function of requests with final status */
  2520. list_for_each_safe(l, n, &final_queue) {
  2521. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  2522. dq = cqr->dq;
  2523. spin_lock_irq(&dq->lock);
  2524. list_del_init(&cqr->blocklist);
  2525. __dasd_cleanup_cqr(cqr);
  2526. spin_unlock_irq(&dq->lock);
  2527. }
  2528. spin_lock_irq(&block->queue_lock);
  2529. /* Now check if the head of the ccw queue needs to be started. */
  2530. __dasd_block_start_head(block);
  2531. spin_unlock_irq(&block->queue_lock);
  2532. if (waitqueue_active(&shutdown_waitq))
  2533. wake_up(&shutdown_waitq);
  2534. dasd_put_device(block->base);
  2535. }
  2536. static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
  2537. {
  2538. wake_up(&dasd_flush_wq);
  2539. }
  2540. /*
  2541. * Requeue a request back to the block request queue
  2542. * only works for block requests
  2543. */
  2544. static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
  2545. {
  2546. struct dasd_block *block = cqr->block;
  2547. struct request *req;
  2548. if (!block)
  2549. return -EINVAL;
  2550. /*
  2551. * If the request is an ERP request there is nothing to requeue.
  2552. * This will be done with the remaining original request.
  2553. */
  2554. if (cqr->refers)
  2555. return 0;
  2556. spin_lock_irq(&cqr->dq->lock);
  2557. req = (struct request *) cqr->callback_data;
  2558. blk_mq_requeue_request(req, false);
  2559. spin_unlock_irq(&cqr->dq->lock);
  2560. return 0;
  2561. }
  2562. /*
  2563. * Go through all request on the dasd_block request queue, cancel them
  2564. * on the respective dasd_device, and return them to the generic
  2565. * block layer.
  2566. */
  2567. static int dasd_flush_block_queue(struct dasd_block *block)
  2568. {
  2569. struct dasd_ccw_req *cqr, *n;
  2570. int rc, i;
  2571. struct list_head flush_queue;
  2572. unsigned long flags;
  2573. INIT_LIST_HEAD(&flush_queue);
  2574. spin_lock_bh(&block->queue_lock);
  2575. rc = 0;
  2576. restart:
  2577. list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
  2578. /* if this request currently owned by a dasd_device cancel it */
  2579. if (cqr->status >= DASD_CQR_QUEUED)
  2580. rc = dasd_cancel_req(cqr);
  2581. if (rc < 0)
  2582. break;
  2583. /* Rechain request (including erp chain) so it won't be
  2584. * touched by the dasd_block_tasklet anymore.
  2585. * Replace the callback so we notice when the request
  2586. * is returned from the dasd_device layer.
  2587. */
  2588. cqr->callback = _dasd_wake_block_flush_cb;
  2589. for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
  2590. list_move_tail(&cqr->blocklist, &flush_queue);
  2591. if (i > 1)
  2592. /* moved more than one request - need to restart */
  2593. goto restart;
  2594. }
  2595. spin_unlock_bh(&block->queue_lock);
  2596. /* Now call the callback function of flushed requests */
  2597. restart_cb:
  2598. list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
  2599. wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
  2600. /* Process finished ERP request. */
  2601. if (cqr->refers) {
  2602. spin_lock_bh(&block->queue_lock);
  2603. __dasd_process_erp(block->base, cqr);
  2604. spin_unlock_bh(&block->queue_lock);
  2605. /* restart list_for_xx loop since dasd_process_erp
  2606. * might remove multiple elements */
  2607. goto restart_cb;
  2608. }
  2609. /* call the callback function */
  2610. spin_lock_irqsave(&cqr->dq->lock, flags);
  2611. cqr->endclk = get_tod_clock();
  2612. list_del_init(&cqr->blocklist);
  2613. __dasd_cleanup_cqr(cqr);
  2614. spin_unlock_irqrestore(&cqr->dq->lock, flags);
  2615. }
  2616. return rc;
  2617. }
  2618. /*
  2619. * Schedules a call to dasd_tasklet over the device tasklet.
  2620. */
  2621. void dasd_schedule_block_bh(struct dasd_block *block)
  2622. {
  2623. /* Protect against rescheduling. */
  2624. if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
  2625. return;
  2626. /* life cycle of block is bound to it's base device */
  2627. dasd_get_device(block->base);
  2628. tasklet_hi_schedule(&block->tasklet);
  2629. }
  2630. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2631. /*
  2632. * SECTION: external block device operations
  2633. * (request queue handling, open, release, etc.)
  2634. */
  2635. /*
  2636. * Dasd request queue function. Called from ll_rw_blk.c
  2637. */
  2638. static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
  2639. const struct blk_mq_queue_data *qd)
  2640. {
  2641. struct dasd_block *block = hctx->queue->queuedata;
  2642. struct dasd_queue *dq = hctx->driver_data;
  2643. struct request *req = qd->rq;
  2644. struct dasd_device *basedev;
  2645. struct dasd_ccw_req *cqr;
  2646. blk_status_t rc = BLK_STS_OK;
  2647. basedev = block->base;
  2648. spin_lock_irq(&dq->lock);
  2649. if (basedev->state < DASD_STATE_READY ||
  2650. test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
  2651. DBF_DEV_EVENT(DBF_ERR, basedev,
  2652. "device not ready for request %p", req);
  2653. rc = BLK_STS_IOERR;
  2654. goto out;
  2655. }
  2656. /*
  2657. * if device is stopped do not fetch new requests
  2658. * except failfast is active which will let requests fail
  2659. * immediately in __dasd_block_start_head()
  2660. */
  2661. if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
  2662. DBF_DEV_EVENT(DBF_ERR, basedev,
  2663. "device stopped request %p", req);
  2664. rc = BLK_STS_RESOURCE;
  2665. goto out;
  2666. }
  2667. if (basedev->features & DASD_FEATURE_READONLY &&
  2668. rq_data_dir(req) == WRITE) {
  2669. DBF_DEV_EVENT(DBF_ERR, basedev,
  2670. "Rejecting write request %p", req);
  2671. rc = BLK_STS_IOERR;
  2672. goto out;
  2673. }
  2674. if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
  2675. (basedev->features & DASD_FEATURE_FAILFAST ||
  2676. blk_noretry_request(req))) {
  2677. DBF_DEV_EVENT(DBF_ERR, basedev,
  2678. "Rejecting failfast request %p", req);
  2679. rc = BLK_STS_IOERR;
  2680. goto out;
  2681. }
  2682. cqr = basedev->discipline->build_cp(basedev, block, req);
  2683. if (IS_ERR(cqr)) {
  2684. if (PTR_ERR(cqr) == -EBUSY ||
  2685. PTR_ERR(cqr) == -ENOMEM ||
  2686. PTR_ERR(cqr) == -EAGAIN) {
  2687. rc = BLK_STS_RESOURCE;
  2688. goto out;
  2689. }
  2690. DBF_DEV_EVENT(DBF_ERR, basedev,
  2691. "CCW creation failed (rc=%ld) on request %p",
  2692. PTR_ERR(cqr), req);
  2693. rc = BLK_STS_IOERR;
  2694. goto out;
  2695. }
  2696. /*
  2697. * Note: callback is set to dasd_return_cqr_cb in
  2698. * __dasd_block_start_head to cover erp requests as well
  2699. */
  2700. cqr->callback_data = req;
  2701. cqr->status = DASD_CQR_FILLED;
  2702. cqr->dq = dq;
  2703. blk_mq_start_request(req);
  2704. spin_lock(&block->queue_lock);
  2705. list_add_tail(&cqr->blocklist, &block->ccw_queue);
  2706. INIT_LIST_HEAD(&cqr->devlist);
  2707. dasd_profile_start(block, cqr, req);
  2708. dasd_schedule_block_bh(block);
  2709. spin_unlock(&block->queue_lock);
  2710. out:
  2711. spin_unlock_irq(&dq->lock);
  2712. return rc;
  2713. }
  2714. /*
  2715. * Block timeout callback, called from the block layer
  2716. *
  2717. * Return values:
  2718. * BLK_EH_RESET_TIMER if the request should be left running
  2719. * BLK_EH_DONE if the request is handled or terminated
  2720. * by the driver.
  2721. */
  2722. enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
  2723. {
  2724. struct dasd_block *block = req->q->queuedata;
  2725. struct dasd_device *device;
  2726. struct dasd_ccw_req *cqr;
  2727. unsigned long flags;
  2728. int rc = 0;
  2729. cqr = blk_mq_rq_to_pdu(req);
  2730. if (!cqr)
  2731. return BLK_EH_DONE;
  2732. spin_lock_irqsave(&cqr->dq->lock, flags);
  2733. device = cqr->startdev ? cqr->startdev : block->base;
  2734. if (!device->blk_timeout) {
  2735. spin_unlock_irqrestore(&cqr->dq->lock, flags);
  2736. return BLK_EH_RESET_TIMER;
  2737. }
  2738. DBF_DEV_EVENT(DBF_WARNING, device,
  2739. " dasd_times_out cqr %p status %x",
  2740. cqr, cqr->status);
  2741. spin_lock(&block->queue_lock);
  2742. spin_lock(get_ccwdev_lock(device->cdev));
  2743. cqr->retries = -1;
  2744. cqr->intrc = -ETIMEDOUT;
  2745. if (cqr->status >= DASD_CQR_QUEUED) {
  2746. rc = __dasd_cancel_req(cqr);
  2747. } else if (cqr->status == DASD_CQR_FILLED ||
  2748. cqr->status == DASD_CQR_NEED_ERP) {
  2749. cqr->status = DASD_CQR_TERMINATED;
  2750. } else if (cqr->status == DASD_CQR_IN_ERP) {
  2751. struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
  2752. list_for_each_entry_safe(searchcqr, nextcqr,
  2753. &block->ccw_queue, blocklist) {
  2754. tmpcqr = searchcqr;
  2755. while (tmpcqr->refers)
  2756. tmpcqr = tmpcqr->refers;
  2757. if (tmpcqr != cqr)
  2758. continue;
  2759. /* searchcqr is an ERP request for cqr */
  2760. searchcqr->retries = -1;
  2761. searchcqr->intrc = -ETIMEDOUT;
  2762. if (searchcqr->status >= DASD_CQR_QUEUED) {
  2763. rc = __dasd_cancel_req(searchcqr);
  2764. } else if ((searchcqr->status == DASD_CQR_FILLED) ||
  2765. (searchcqr->status == DASD_CQR_NEED_ERP)) {
  2766. searchcqr->status = DASD_CQR_TERMINATED;
  2767. rc = 0;
  2768. } else if (searchcqr->status == DASD_CQR_IN_ERP) {
  2769. /*
  2770. * Shouldn't happen; most recent ERP
  2771. * request is at the front of queue
  2772. */
  2773. continue;
  2774. }
  2775. break;
  2776. }
  2777. }
  2778. spin_unlock(get_ccwdev_lock(device->cdev));
  2779. dasd_schedule_block_bh(block);
  2780. spin_unlock(&block->queue_lock);
  2781. spin_unlock_irqrestore(&cqr->dq->lock, flags);
  2782. return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
  2783. }
  2784. static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
  2785. unsigned int idx)
  2786. {
  2787. struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
  2788. if (!dq)
  2789. return -ENOMEM;
  2790. spin_lock_init(&dq->lock);
  2791. hctx->driver_data = dq;
  2792. return 0;
  2793. }
  2794. static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
  2795. {
  2796. kfree(hctx->driver_data);
  2797. hctx->driver_data = NULL;
  2798. }
  2799. static void dasd_request_done(struct request *req)
  2800. {
  2801. blk_mq_end_request(req, 0);
  2802. blk_mq_run_hw_queues(req->q, true);
  2803. }
  2804. static struct blk_mq_ops dasd_mq_ops = {
  2805. .queue_rq = do_dasd_request,
  2806. .complete = dasd_request_done,
  2807. .timeout = dasd_times_out,
  2808. .init_hctx = dasd_init_hctx,
  2809. .exit_hctx = dasd_exit_hctx,
  2810. };
  2811. /*
  2812. * Allocate and initialize request queue and default I/O scheduler.
  2813. */
  2814. static int dasd_alloc_queue(struct dasd_block *block)
  2815. {
  2816. int rc;
  2817. block->tag_set.ops = &dasd_mq_ops;
  2818. block->tag_set.cmd_size = sizeof(struct dasd_ccw_req);
  2819. block->tag_set.nr_hw_queues = nr_hw_queues;
  2820. block->tag_set.queue_depth = queue_depth;
  2821. block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
  2822. block->tag_set.numa_node = NUMA_NO_NODE;
  2823. rc = blk_mq_alloc_tag_set(&block->tag_set);
  2824. if (rc)
  2825. return rc;
  2826. block->request_queue = blk_mq_init_queue(&block->tag_set);
  2827. if (IS_ERR(block->request_queue))
  2828. return PTR_ERR(block->request_queue);
  2829. block->request_queue->queuedata = block;
  2830. return 0;
  2831. }
  2832. /*
  2833. * Allocate and initialize request queue.
  2834. */
  2835. static void dasd_setup_queue(struct dasd_block *block)
  2836. {
  2837. unsigned int logical_block_size = block->bp_block;
  2838. struct request_queue *q = block->request_queue;
  2839. unsigned int max_bytes, max_discard_sectors;
  2840. int max;
  2841. if (block->base->features & DASD_FEATURE_USERAW) {
  2842. /*
  2843. * the max_blocks value for raw_track access is 256
  2844. * it is higher than the native ECKD value because we
  2845. * only need one ccw per track
  2846. * so the max_hw_sectors are
  2847. * 2048 x 512B = 1024kB = 16 tracks
  2848. */
  2849. max = 2048;
  2850. } else {
  2851. max = block->base->discipline->max_blocks << block->s2b_shift;
  2852. }
  2853. blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
  2854. q->limits.max_dev_sectors = max;
  2855. blk_queue_logical_block_size(q, logical_block_size);
  2856. blk_queue_max_hw_sectors(q, max);
  2857. blk_queue_max_segments(q, USHRT_MAX);
  2858. /* with page sized segments we can translate each segement into
  2859. * one idaw/tidaw
  2860. */
  2861. blk_queue_max_segment_size(q, PAGE_SIZE);
  2862. blk_queue_segment_boundary(q, PAGE_SIZE - 1);
  2863. /* Only activate blocklayer discard support for devices that support it */
  2864. if (block->base->features & DASD_FEATURE_DISCARD) {
  2865. q->limits.discard_granularity = logical_block_size;
  2866. q->limits.discard_alignment = PAGE_SIZE;
  2867. /* Calculate max_discard_sectors and make it PAGE aligned */
  2868. max_bytes = USHRT_MAX * logical_block_size;
  2869. max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
  2870. max_discard_sectors = max_bytes / logical_block_size;
  2871. blk_queue_max_discard_sectors(q, max_discard_sectors);
  2872. blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
  2873. blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
  2874. }
  2875. }
  2876. /*
  2877. * Deactivate and free request queue.
  2878. */
  2879. static void dasd_free_queue(struct dasd_block *block)
  2880. {
  2881. if (block->request_queue) {
  2882. blk_cleanup_queue(block->request_queue);
  2883. blk_mq_free_tag_set(&block->tag_set);
  2884. block->request_queue = NULL;
  2885. }
  2886. }
  2887. static int dasd_open(struct block_device *bdev, fmode_t mode)
  2888. {
  2889. struct dasd_device *base;
  2890. int rc;
  2891. base = dasd_device_from_gendisk(bdev->bd_disk);
  2892. if (!base)
  2893. return -ENODEV;
  2894. atomic_inc(&base->block->open_count);
  2895. if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
  2896. rc = -ENODEV;
  2897. goto unlock;
  2898. }
  2899. if (!try_module_get(base->discipline->owner)) {
  2900. rc = -EINVAL;
  2901. goto unlock;
  2902. }
  2903. if (dasd_probeonly) {
  2904. dev_info(&base->cdev->dev,
  2905. "Accessing the DASD failed because it is in "
  2906. "probeonly mode\n");
  2907. rc = -EPERM;
  2908. goto out;
  2909. }
  2910. if (base->state <= DASD_STATE_BASIC) {
  2911. DBF_DEV_EVENT(DBF_ERR, base, " %s",
  2912. " Cannot open unrecognized device");
  2913. rc = -ENODEV;
  2914. goto out;
  2915. }
  2916. if ((mode & FMODE_WRITE) &&
  2917. (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
  2918. (base->features & DASD_FEATURE_READONLY))) {
  2919. rc = -EROFS;
  2920. goto out;
  2921. }
  2922. dasd_put_device(base);
  2923. return 0;
  2924. out:
  2925. module_put(base->discipline->owner);
  2926. unlock:
  2927. atomic_dec(&base->block->open_count);
  2928. dasd_put_device(base);
  2929. return rc;
  2930. }
  2931. static void dasd_release(struct gendisk *disk, fmode_t mode)
  2932. {
  2933. struct dasd_device *base = dasd_device_from_gendisk(disk);
  2934. if (base) {
  2935. atomic_dec(&base->block->open_count);
  2936. module_put(base->discipline->owner);
  2937. dasd_put_device(base);
  2938. }
  2939. }
  2940. /*
  2941. * Return disk geometry.
  2942. */
  2943. static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  2944. {
  2945. struct dasd_device *base;
  2946. base = dasd_device_from_gendisk(bdev->bd_disk);
  2947. if (!base)
  2948. return -ENODEV;
  2949. if (!base->discipline ||
  2950. !base->discipline->fill_geometry) {
  2951. dasd_put_device(base);
  2952. return -EINVAL;
  2953. }
  2954. base->discipline->fill_geometry(base->block, geo);
  2955. geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
  2956. dasd_put_device(base);
  2957. return 0;
  2958. }
  2959. const struct block_device_operations
  2960. dasd_device_operations = {
  2961. .owner = THIS_MODULE,
  2962. .open = dasd_open,
  2963. .release = dasd_release,
  2964. .ioctl = dasd_ioctl,
  2965. .compat_ioctl = dasd_ioctl,
  2966. .getgeo = dasd_getgeo,
  2967. };
  2968. /*******************************************************************************
  2969. * end of block device operations
  2970. */
  2971. static void
  2972. dasd_exit(void)
  2973. {
  2974. #ifdef CONFIG_PROC_FS
  2975. dasd_proc_exit();
  2976. #endif
  2977. dasd_eer_exit();
  2978. if (dasd_page_cache != NULL) {
  2979. kmem_cache_destroy(dasd_page_cache);
  2980. dasd_page_cache = NULL;
  2981. }
  2982. dasd_gendisk_exit();
  2983. dasd_devmap_exit();
  2984. if (dasd_debug_area != NULL) {
  2985. debug_unregister(dasd_debug_area);
  2986. dasd_debug_area = NULL;
  2987. }
  2988. dasd_statistics_removeroot();
  2989. }
  2990. /*
  2991. * SECTION: common functions for ccw_driver use
  2992. */
  2993. /*
  2994. * Is the device read-only?
  2995. * Note that this function does not report the setting of the
  2996. * readonly device attribute, but how it is configured in z/VM.
  2997. */
  2998. int dasd_device_is_ro(struct dasd_device *device)
  2999. {
  3000. struct ccw_dev_id dev_id;
  3001. struct diag210 diag_data;
  3002. int rc;
  3003. if (!MACHINE_IS_VM)
  3004. return 0;
  3005. ccw_device_get_id(device->cdev, &dev_id);
  3006. memset(&diag_data, 0, sizeof(diag_data));
  3007. diag_data.vrdcdvno = dev_id.devno;
  3008. diag_data.vrdclen = sizeof(diag_data);
  3009. rc = diag210(&diag_data);
  3010. if (rc == 0 || rc == 2) {
  3011. return diag_data.vrdcvfla & 0x80;
  3012. } else {
  3013. DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
  3014. dev_id.devno, rc);
  3015. return 0;
  3016. }
  3017. }
  3018. EXPORT_SYMBOL_GPL(dasd_device_is_ro);
  3019. static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
  3020. {
  3021. struct ccw_device *cdev = data;
  3022. int ret;
  3023. ret = ccw_device_set_online(cdev);
  3024. if (ret)
  3025. pr_warn("%s: Setting the DASD online failed with rc=%d\n",
  3026. dev_name(&cdev->dev), ret);
  3027. }
  3028. /*
  3029. * Initial attempt at a probe function. this can be simplified once
  3030. * the other detection code is gone.
  3031. */
  3032. int dasd_generic_probe(struct ccw_device *cdev,
  3033. struct dasd_discipline *discipline)
  3034. {
  3035. int ret;
  3036. ret = dasd_add_sysfs_files(cdev);
  3037. if (ret) {
  3038. DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
  3039. "dasd_generic_probe: could not add "
  3040. "sysfs entries");
  3041. return ret;
  3042. }
  3043. cdev->handler = &dasd_int_handler;
  3044. /*
  3045. * Automatically online either all dasd devices (dasd_autodetect)
  3046. * or all devices specified with dasd= parameters during
  3047. * initial probe.
  3048. */
  3049. if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
  3050. (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
  3051. async_schedule(dasd_generic_auto_online, cdev);
  3052. return 0;
  3053. }
  3054. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  3055. void dasd_generic_free_discipline(struct dasd_device *device)
  3056. {
  3057. /* Forget the discipline information. */
  3058. if (device->discipline) {
  3059. if (device->discipline->uncheck_device)
  3060. device->discipline->uncheck_device(device);
  3061. module_put(device->discipline->owner);
  3062. device->discipline = NULL;
  3063. }
  3064. if (device->base_discipline) {
  3065. module_put(device->base_discipline->owner);
  3066. device->base_discipline = NULL;
  3067. }
  3068. }
  3069. EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
  3070. /*
  3071. * This will one day be called from a global not_oper handler.
  3072. * It is also used by driver_unregister during module unload.
  3073. */
  3074. void dasd_generic_remove(struct ccw_device *cdev)
  3075. {
  3076. struct dasd_device *device;
  3077. struct dasd_block *block;
  3078. device = dasd_device_from_cdev(cdev);
  3079. if (IS_ERR(device)) {
  3080. dasd_remove_sysfs_files(cdev);
  3081. return;
  3082. }
  3083. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
  3084. !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  3085. /* Already doing offline processing */
  3086. dasd_put_device(device);
  3087. dasd_remove_sysfs_files(cdev);
  3088. return;
  3089. }
  3090. /*
  3091. * This device is removed unconditionally. Set offline
  3092. * flag to prevent dasd_open from opening it while it is
  3093. * no quite down yet.
  3094. */
  3095. dasd_set_target_state(device, DASD_STATE_NEW);
  3096. cdev->handler = NULL;
  3097. /* dasd_delete_device destroys the device reference. */
  3098. block = device->block;
  3099. dasd_delete_device(device);
  3100. /*
  3101. * life cycle of block is bound to device, so delete it after
  3102. * device was safely removed
  3103. */
  3104. if (block)
  3105. dasd_free_block(block);
  3106. dasd_remove_sysfs_files(cdev);
  3107. }
  3108. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  3109. /*
  3110. * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
  3111. * the device is detected for the first time and is supposed to be used
  3112. * or the user has started activation through sysfs.
  3113. */
  3114. int dasd_generic_set_online(struct ccw_device *cdev,
  3115. struct dasd_discipline *base_discipline)
  3116. {
  3117. struct dasd_discipline *discipline;
  3118. struct dasd_device *device;
  3119. int rc;
  3120. /* first online clears initial online feature flag */
  3121. dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
  3122. device = dasd_create_device(cdev);
  3123. if (IS_ERR(device))
  3124. return PTR_ERR(device);
  3125. discipline = base_discipline;
  3126. if (device->features & DASD_FEATURE_USEDIAG) {
  3127. if (!dasd_diag_discipline_pointer) {
  3128. /* Try to load the required module. */
  3129. rc = request_module(DASD_DIAG_MOD);
  3130. if (rc) {
  3131. pr_warn("%s Setting the DASD online failed "
  3132. "because the required module %s "
  3133. "could not be loaded (rc=%d)\n",
  3134. dev_name(&cdev->dev), DASD_DIAG_MOD,
  3135. rc);
  3136. dasd_delete_device(device);
  3137. return -ENODEV;
  3138. }
  3139. }
  3140. /* Module init could have failed, so check again here after
  3141. * request_module(). */
  3142. if (!dasd_diag_discipline_pointer) {
  3143. pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
  3144. dev_name(&cdev->dev));
  3145. dasd_delete_device(device);
  3146. return -ENODEV;
  3147. }
  3148. discipline = dasd_diag_discipline_pointer;
  3149. }
  3150. if (!try_module_get(base_discipline->owner)) {
  3151. dasd_delete_device(device);
  3152. return -EINVAL;
  3153. }
  3154. if (!try_module_get(discipline->owner)) {
  3155. module_put(base_discipline->owner);
  3156. dasd_delete_device(device);
  3157. return -EINVAL;
  3158. }
  3159. device->base_discipline = base_discipline;
  3160. device->discipline = discipline;
  3161. /* check_device will allocate block device if necessary */
  3162. rc = discipline->check_device(device);
  3163. if (rc) {
  3164. pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
  3165. dev_name(&cdev->dev), discipline->name, rc);
  3166. module_put(discipline->owner);
  3167. module_put(base_discipline->owner);
  3168. dasd_delete_device(device);
  3169. return rc;
  3170. }
  3171. dasd_set_target_state(device, DASD_STATE_ONLINE);
  3172. if (device->state <= DASD_STATE_KNOWN) {
  3173. pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
  3174. dev_name(&cdev->dev));
  3175. rc = -ENODEV;
  3176. dasd_set_target_state(device, DASD_STATE_NEW);
  3177. if (device->block)
  3178. dasd_free_block(device->block);
  3179. dasd_delete_device(device);
  3180. } else
  3181. pr_debug("dasd_generic device %s found\n",
  3182. dev_name(&cdev->dev));
  3183. wait_event(dasd_init_waitq, _wait_for_device(device));
  3184. dasd_put_device(device);
  3185. return rc;
  3186. }
  3187. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  3188. int dasd_generic_set_offline(struct ccw_device *cdev)
  3189. {
  3190. struct dasd_device *device;
  3191. struct dasd_block *block;
  3192. int max_count, open_count, rc;
  3193. unsigned long flags;
  3194. rc = 0;
  3195. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  3196. device = dasd_device_from_cdev_locked(cdev);
  3197. if (IS_ERR(device)) {
  3198. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  3199. return PTR_ERR(device);
  3200. }
  3201. /*
  3202. * We must make sure that this device is currently not in use.
  3203. * The open_count is increased for every opener, that includes
  3204. * the blkdev_get in dasd_scan_partitions. We are only interested
  3205. * in the other openers.
  3206. */
  3207. if (device->block) {
  3208. max_count = device->block->bdev ? 0 : -1;
  3209. open_count = atomic_read(&device->block->open_count);
  3210. if (open_count > max_count) {
  3211. if (open_count > 0)
  3212. pr_warn("%s: The DASD cannot be set offline with open count %i\n",
  3213. dev_name(&cdev->dev), open_count);
  3214. else
  3215. pr_warn("%s: The DASD cannot be set offline while it is in use\n",
  3216. dev_name(&cdev->dev));
  3217. rc = -EBUSY;
  3218. goto out_err;
  3219. }
  3220. }
  3221. /*
  3222. * Test if the offline processing is already running and exit if so.
  3223. * If a safe offline is being processed this could only be a normal
  3224. * offline that should be able to overtake the safe offline and
  3225. * cancel any I/O we do not want to wait for any longer
  3226. */
  3227. if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  3228. if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  3229. clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
  3230. &device->flags);
  3231. } else {
  3232. rc = -EBUSY;
  3233. goto out_err;
  3234. }
  3235. }
  3236. set_bit(DASD_FLAG_OFFLINE, &device->flags);
  3237. /*
  3238. * if safe_offline is called set safe_offline_running flag and
  3239. * clear safe_offline so that a call to normal offline
  3240. * can overrun safe_offline processing
  3241. */
  3242. if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
  3243. !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  3244. /* need to unlock here to wait for outstanding I/O */
  3245. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  3246. /*
  3247. * If we want to set the device safe offline all IO operations
  3248. * should be finished before continuing the offline process
  3249. * so sync bdev first and then wait for our queues to become
  3250. * empty
  3251. */
  3252. if (device->block) {
  3253. rc = fsync_bdev(device->block->bdev);
  3254. if (rc != 0)
  3255. goto interrupted;
  3256. }
  3257. dasd_schedule_device_bh(device);
  3258. rc = wait_event_interruptible(shutdown_waitq,
  3259. _wait_for_empty_queues(device));
  3260. if (rc != 0)
  3261. goto interrupted;
  3262. /*
  3263. * check if a normal offline process overtook the offline
  3264. * processing in this case simply do nothing beside returning
  3265. * that we got interrupted
  3266. * otherwise mark safe offline as not running any longer and
  3267. * continue with normal offline
  3268. */
  3269. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  3270. if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  3271. rc = -ERESTARTSYS;
  3272. goto out_err;
  3273. }
  3274. clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
  3275. }
  3276. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  3277. dasd_set_target_state(device, DASD_STATE_NEW);
  3278. /* dasd_delete_device destroys the device reference. */
  3279. block = device->block;
  3280. dasd_delete_device(device);
  3281. /*
  3282. * life cycle of block is bound to device, so delete it after
  3283. * device was safely removed
  3284. */
  3285. if (block)
  3286. dasd_free_block(block);
  3287. return 0;
  3288. interrupted:
  3289. /* interrupted by signal */
  3290. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  3291. clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
  3292. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  3293. out_err:
  3294. dasd_put_device(device);
  3295. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  3296. return rc;
  3297. }
  3298. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  3299. int dasd_generic_last_path_gone(struct dasd_device *device)
  3300. {
  3301. struct dasd_ccw_req *cqr;
  3302. dev_warn(&device->cdev->dev, "No operational channel path is left "
  3303. "for the device\n");
  3304. DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
  3305. /* First of all call extended error reporting. */
  3306. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  3307. if (device->state < DASD_STATE_BASIC)
  3308. return 0;
  3309. /* Device is active. We want to keep it. */
  3310. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  3311. if ((cqr->status == DASD_CQR_IN_IO) ||
  3312. (cqr->status == DASD_CQR_CLEAR_PENDING)) {
  3313. cqr->status = DASD_CQR_QUEUED;
  3314. cqr->retries++;
  3315. }
  3316. dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
  3317. dasd_device_clear_timer(device);
  3318. dasd_schedule_device_bh(device);
  3319. return 1;
  3320. }
  3321. EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
  3322. int dasd_generic_path_operational(struct dasd_device *device)
  3323. {
  3324. dev_info(&device->cdev->dev, "A channel path to the device has become "
  3325. "operational\n");
  3326. DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
  3327. dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
  3328. if (device->stopped & DASD_UNRESUMED_PM) {
  3329. dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
  3330. dasd_restore_device(device);
  3331. return 1;
  3332. }
  3333. dasd_schedule_device_bh(device);
  3334. if (device->block) {
  3335. dasd_schedule_block_bh(device->block);
  3336. if (device->block->request_queue)
  3337. blk_mq_run_hw_queues(device->block->request_queue,
  3338. true);
  3339. }
  3340. if (!device->stopped)
  3341. wake_up(&generic_waitq);
  3342. return 1;
  3343. }
  3344. EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
  3345. int dasd_generic_notify(struct ccw_device *cdev, int event)
  3346. {
  3347. struct dasd_device *device;
  3348. int ret;
  3349. device = dasd_device_from_cdev_locked(cdev);
  3350. if (IS_ERR(device))
  3351. return 0;
  3352. ret = 0;
  3353. switch (event) {
  3354. case CIO_GONE:
  3355. case CIO_BOXED:
  3356. case CIO_NO_PATH:
  3357. dasd_path_no_path(device);
  3358. ret = dasd_generic_last_path_gone(device);
  3359. break;
  3360. case CIO_OPER:
  3361. ret = 1;
  3362. if (dasd_path_get_opm(device))
  3363. ret = dasd_generic_path_operational(device);
  3364. break;
  3365. }
  3366. dasd_put_device(device);
  3367. return ret;
  3368. }
  3369. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  3370. void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
  3371. {
  3372. struct dasd_device *device;
  3373. int chp, oldopm, hpfpm, ifccpm;
  3374. device = dasd_device_from_cdev_locked(cdev);
  3375. if (IS_ERR(device))
  3376. return;
  3377. oldopm = dasd_path_get_opm(device);
  3378. for (chp = 0; chp < 8; chp++) {
  3379. if (path_event[chp] & PE_PATH_GONE) {
  3380. dasd_path_notoper(device, chp);
  3381. }
  3382. if (path_event[chp] & PE_PATH_AVAILABLE) {
  3383. dasd_path_available(device, chp);
  3384. dasd_schedule_device_bh(device);
  3385. }
  3386. if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
  3387. if (!dasd_path_is_operational(device, chp) &&
  3388. !dasd_path_need_verify(device, chp)) {
  3389. /*
  3390. * we can not establish a pathgroup on an
  3391. * unavailable path, so trigger a path
  3392. * verification first
  3393. */
  3394. dasd_path_available(device, chp);
  3395. dasd_schedule_device_bh(device);
  3396. }
  3397. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3398. "Pathgroup re-established\n");
  3399. if (device->discipline->kick_validate)
  3400. device->discipline->kick_validate(device);
  3401. }
  3402. }
  3403. hpfpm = dasd_path_get_hpfpm(device);
  3404. ifccpm = dasd_path_get_ifccpm(device);
  3405. if (!dasd_path_get_opm(device) && hpfpm) {
  3406. /*
  3407. * device has no operational paths but at least one path is
  3408. * disabled due to HPF errors
  3409. * disable HPF at all and use the path(s) again
  3410. */
  3411. if (device->discipline->disable_hpf)
  3412. device->discipline->disable_hpf(device);
  3413. dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
  3414. dasd_path_set_tbvpm(device, hpfpm);
  3415. dasd_schedule_device_bh(device);
  3416. dasd_schedule_requeue(device);
  3417. } else if (!dasd_path_get_opm(device) && ifccpm) {
  3418. /*
  3419. * device has no operational paths but at least one path is
  3420. * disabled due to IFCC errors
  3421. * trigger path verification on paths with IFCC errors
  3422. */
  3423. dasd_path_set_tbvpm(device, ifccpm);
  3424. dasd_schedule_device_bh(device);
  3425. }
  3426. if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
  3427. dev_warn(&device->cdev->dev,
  3428. "No verified channel paths remain for the device\n");
  3429. DBF_DEV_EVENT(DBF_WARNING, device,
  3430. "%s", "last verified path gone");
  3431. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  3432. dasd_device_set_stop_bits(device,
  3433. DASD_STOPPED_DC_WAIT);
  3434. }
  3435. dasd_put_device(device);
  3436. }
  3437. EXPORT_SYMBOL_GPL(dasd_generic_path_event);
  3438. int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
  3439. {
  3440. if (!dasd_path_get_opm(device) && lpm) {
  3441. dasd_path_set_opm(device, lpm);
  3442. dasd_generic_path_operational(device);
  3443. } else
  3444. dasd_path_add_opm(device, lpm);
  3445. return 0;
  3446. }
  3447. EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
  3448. /*
  3449. * clear active requests and requeue them to block layer if possible
  3450. */
  3451. static int dasd_generic_requeue_all_requests(struct dasd_device *device)
  3452. {
  3453. struct list_head requeue_queue;
  3454. struct dasd_ccw_req *cqr, *n;
  3455. struct dasd_ccw_req *refers;
  3456. int rc;
  3457. INIT_LIST_HEAD(&requeue_queue);
  3458. spin_lock_irq(get_ccwdev_lock(device->cdev));
  3459. rc = 0;
  3460. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  3461. /* Check status and move request to flush_queue */
  3462. if (cqr->status == DASD_CQR_IN_IO) {
  3463. rc = device->discipline->term_IO(cqr);
  3464. if (rc) {
  3465. /* unable to terminate requeust */
  3466. dev_err(&device->cdev->dev,
  3467. "Unable to terminate request %p "
  3468. "on suspend\n", cqr);
  3469. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  3470. dasd_put_device(device);
  3471. return rc;
  3472. }
  3473. }
  3474. list_move_tail(&cqr->devlist, &requeue_queue);
  3475. }
  3476. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  3477. list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
  3478. wait_event(dasd_flush_wq,
  3479. (cqr->status != DASD_CQR_CLEAR_PENDING));
  3480. /*
  3481. * requeue requests to blocklayer will only work
  3482. * for block device requests
  3483. */
  3484. if (_dasd_requeue_request(cqr))
  3485. continue;
  3486. /* remove requests from device and block queue */
  3487. list_del_init(&cqr->devlist);
  3488. while (cqr->refers != NULL) {
  3489. refers = cqr->refers;
  3490. /* remove the request from the block queue */
  3491. list_del(&cqr->blocklist);
  3492. /* free the finished erp request */
  3493. dasd_free_erp_request(cqr, cqr->memdev);
  3494. cqr = refers;
  3495. }
  3496. /*
  3497. * _dasd_requeue_request already checked for a valid
  3498. * blockdevice, no need to check again
  3499. * all erp requests (cqr->refers) have a cqr->block
  3500. * pointer copy from the original cqr
  3501. */
  3502. list_del_init(&cqr->blocklist);
  3503. cqr->block->base->discipline->free_cp(
  3504. cqr, (struct request *) cqr->callback_data);
  3505. }
  3506. /*
  3507. * if requests remain then they are internal request
  3508. * and go back to the device queue
  3509. */
  3510. if (!list_empty(&requeue_queue)) {
  3511. /* move freeze_queue to start of the ccw_queue */
  3512. spin_lock_irq(get_ccwdev_lock(device->cdev));
  3513. list_splice_tail(&requeue_queue, &device->ccw_queue);
  3514. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  3515. }
  3516. dasd_schedule_device_bh(device);
  3517. return rc;
  3518. }
  3519. static void do_requeue_requests(struct work_struct *work)
  3520. {
  3521. struct dasd_device *device = container_of(work, struct dasd_device,
  3522. requeue_requests);
  3523. dasd_generic_requeue_all_requests(device);
  3524. dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
  3525. if (device->block)
  3526. dasd_schedule_block_bh(device->block);
  3527. dasd_put_device(device);
  3528. }
  3529. void dasd_schedule_requeue(struct dasd_device *device)
  3530. {
  3531. dasd_get_device(device);
  3532. /* queue call to dasd_reload_device to the kernel event daemon. */
  3533. if (!schedule_work(&device->requeue_requests))
  3534. dasd_put_device(device);
  3535. }
  3536. EXPORT_SYMBOL(dasd_schedule_requeue);
  3537. int dasd_generic_pm_freeze(struct ccw_device *cdev)
  3538. {
  3539. struct dasd_device *device = dasd_device_from_cdev(cdev);
  3540. if (IS_ERR(device))
  3541. return PTR_ERR(device);
  3542. /* mark device as suspended */
  3543. set_bit(DASD_FLAG_SUSPENDED, &device->flags);
  3544. if (device->discipline->freeze)
  3545. device->discipline->freeze(device);
  3546. /* disallow new I/O */
  3547. dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
  3548. return dasd_generic_requeue_all_requests(device);
  3549. }
  3550. EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
  3551. int dasd_generic_restore_device(struct ccw_device *cdev)
  3552. {
  3553. struct dasd_device *device = dasd_device_from_cdev(cdev);
  3554. int rc = 0;
  3555. if (IS_ERR(device))
  3556. return PTR_ERR(device);
  3557. /* allow new IO again */
  3558. dasd_device_remove_stop_bits(device,
  3559. (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
  3560. dasd_schedule_device_bh(device);
  3561. /*
  3562. * call discipline restore function
  3563. * if device is stopped do nothing e.g. for disconnected devices
  3564. */
  3565. if (device->discipline->restore && !(device->stopped))
  3566. rc = device->discipline->restore(device);
  3567. if (rc || device->stopped)
  3568. /*
  3569. * if the resume failed for the DASD we put it in
  3570. * an UNRESUMED stop state
  3571. */
  3572. device->stopped |= DASD_UNRESUMED_PM;
  3573. if (device->block) {
  3574. dasd_schedule_block_bh(device->block);
  3575. if (device->block->request_queue)
  3576. blk_mq_run_hw_queues(device->block->request_queue,
  3577. true);
  3578. }
  3579. clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
  3580. dasd_put_device(device);
  3581. return 0;
  3582. }
  3583. EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
  3584. static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
  3585. void *rdc_buffer,
  3586. int rdc_buffer_size,
  3587. int magic)
  3588. {
  3589. struct dasd_ccw_req *cqr;
  3590. struct ccw1 *ccw;
  3591. unsigned long *idaw;
  3592. cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
  3593. NULL);
  3594. if (IS_ERR(cqr)) {
  3595. /* internal error 13 - Allocating the RDC request failed*/
  3596. dev_err(&device->cdev->dev,
  3597. "An error occurred in the DASD device driver, "
  3598. "reason=%s\n", "13");
  3599. return cqr;
  3600. }
  3601. ccw = cqr->cpaddr;
  3602. ccw->cmd_code = CCW_CMD_RDC;
  3603. if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
  3604. idaw = (unsigned long *) (cqr->data);
  3605. ccw->cda = (__u32)(addr_t) idaw;
  3606. ccw->flags = CCW_FLAG_IDA;
  3607. idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
  3608. } else {
  3609. ccw->cda = (__u32)(addr_t) rdc_buffer;
  3610. ccw->flags = 0;
  3611. }
  3612. ccw->count = rdc_buffer_size;
  3613. cqr->startdev = device;
  3614. cqr->memdev = device;
  3615. cqr->expires = 10*HZ;
  3616. cqr->retries = 256;
  3617. cqr->buildclk = get_tod_clock();
  3618. cqr->status = DASD_CQR_FILLED;
  3619. return cqr;
  3620. }
  3621. int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
  3622. void *rdc_buffer, int rdc_buffer_size)
  3623. {
  3624. int ret;
  3625. struct dasd_ccw_req *cqr;
  3626. cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
  3627. magic);
  3628. if (IS_ERR(cqr))
  3629. return PTR_ERR(cqr);
  3630. ret = dasd_sleep_on(cqr);
  3631. dasd_sfree_request(cqr, cqr->memdev);
  3632. return ret;
  3633. }
  3634. EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
  3635. /*
  3636. * In command mode and transport mode we need to look for sense
  3637. * data in different places. The sense data itself is allways
  3638. * an array of 32 bytes, so we can unify the sense data access
  3639. * for both modes.
  3640. */
  3641. char *dasd_get_sense(struct irb *irb)
  3642. {
  3643. struct tsb *tsb = NULL;
  3644. char *sense = NULL;
  3645. if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
  3646. if (irb->scsw.tm.tcw)
  3647. tsb = tcw_get_tsb((struct tcw *)(unsigned long)
  3648. irb->scsw.tm.tcw);
  3649. if (tsb && tsb->length == 64 && tsb->flags)
  3650. switch (tsb->flags & 0x07) {
  3651. case 1: /* tsa_iostat */
  3652. sense = tsb->tsa.iostat.sense;
  3653. break;
  3654. case 2: /* tsa_ddpc */
  3655. sense = tsb->tsa.ddpc.sense;
  3656. break;
  3657. default:
  3658. /* currently we don't use interrogate data */
  3659. break;
  3660. }
  3661. } else if (irb->esw.esw0.erw.cons) {
  3662. sense = irb->ecw;
  3663. }
  3664. return sense;
  3665. }
  3666. EXPORT_SYMBOL_GPL(dasd_get_sense);
  3667. void dasd_generic_shutdown(struct ccw_device *cdev)
  3668. {
  3669. struct dasd_device *device;
  3670. device = dasd_device_from_cdev(cdev);
  3671. if (IS_ERR(device))
  3672. return;
  3673. if (device->block)
  3674. dasd_schedule_block_bh(device->block);
  3675. dasd_schedule_device_bh(device);
  3676. wait_event(shutdown_waitq, _wait_for_empty_queues(device));
  3677. }
  3678. EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
  3679. static int __init dasd_init(void)
  3680. {
  3681. int rc;
  3682. init_waitqueue_head(&dasd_init_waitq);
  3683. init_waitqueue_head(&dasd_flush_wq);
  3684. init_waitqueue_head(&generic_waitq);
  3685. init_waitqueue_head(&shutdown_waitq);
  3686. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  3687. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  3688. if (dasd_debug_area == NULL) {
  3689. rc = -ENOMEM;
  3690. goto failed;
  3691. }
  3692. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  3693. debug_set_level(dasd_debug_area, DBF_WARNING);
  3694. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  3695. dasd_diag_discipline_pointer = NULL;
  3696. dasd_statistics_createroot();
  3697. rc = dasd_devmap_init();
  3698. if (rc)
  3699. goto failed;
  3700. rc = dasd_gendisk_init();
  3701. if (rc)
  3702. goto failed;
  3703. rc = dasd_parse();
  3704. if (rc)
  3705. goto failed;
  3706. rc = dasd_eer_init();
  3707. if (rc)
  3708. goto failed;
  3709. #ifdef CONFIG_PROC_FS
  3710. rc = dasd_proc_init();
  3711. if (rc)
  3712. goto failed;
  3713. #endif
  3714. return 0;
  3715. failed:
  3716. pr_info("The DASD device driver could not be initialized\n");
  3717. dasd_exit();
  3718. return rc;
  3719. }
  3720. module_init(dasd_init);
  3721. module_exit(dasd_exit);