dasd.c 109 KB

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