dasd.c 109 KB

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