dasd.c 95 KB

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