dasd.c 97 KB

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