dasd.c 81 KB

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