dasd.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517
  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. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
  9. *
  10. */
  11. #include <linux/kmod.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/ctype.h>
  15. #include <linux/major.h>
  16. #include <linux/slab.h>
  17. #include <linux/buffer_head.h>
  18. #include <linux/hdreg.h>
  19. #include <asm/ccwdev.h>
  20. #include <asm/ebcdic.h>
  21. #include <asm/idals.h>
  22. #include <asm/todclk.h>
  23. /* This is ugly... */
  24. #define PRINTK_HEADER "dasd:"
  25. #include "dasd_int.h"
  26. /*
  27. * SECTION: Constant definitions to be used within this file
  28. */
  29. #define DASD_CHANQ_MAX_SIZE 4
  30. /*
  31. * SECTION: exported variables of dasd.c
  32. */
  33. debug_info_t *dasd_debug_area;
  34. struct dasd_discipline *dasd_diag_discipline_pointer;
  35. void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
  36. MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
  37. MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
  38. " Copyright 2000 IBM Corporation");
  39. MODULE_SUPPORTED_DEVICE("dasd");
  40. MODULE_LICENSE("GPL");
  41. /*
  42. * SECTION: prototypes for static functions of dasd.c
  43. */
  44. static int dasd_alloc_queue(struct dasd_block *);
  45. static void dasd_setup_queue(struct dasd_block *);
  46. static void dasd_free_queue(struct dasd_block *);
  47. static void dasd_flush_request_queue(struct dasd_block *);
  48. static int dasd_flush_block_queue(struct dasd_block *);
  49. static void dasd_device_tasklet(struct dasd_device *);
  50. static void dasd_block_tasklet(struct dasd_block *);
  51. static void do_kick_device(struct work_struct *);
  52. static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
  53. static void dasd_device_timeout(unsigned long);
  54. static void dasd_block_timeout(unsigned long);
  55. /*
  56. * SECTION: Operations on the device structure.
  57. */
  58. static wait_queue_head_t dasd_init_waitq;
  59. static wait_queue_head_t dasd_flush_wq;
  60. static wait_queue_head_t generic_waitq;
  61. /*
  62. * Allocate memory for a new device structure.
  63. */
  64. struct dasd_device *dasd_alloc_device(void)
  65. {
  66. struct dasd_device *device;
  67. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  68. if (!device)
  69. return ERR_PTR(-ENOMEM);
  70. /* Get two pages for normal block device operations. */
  71. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  72. if (!device->ccw_mem) {
  73. kfree(device);
  74. return ERR_PTR(-ENOMEM);
  75. }
  76. /* Get one page for error recovery. */
  77. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  78. if (!device->erp_mem) {
  79. free_pages((unsigned long) device->ccw_mem, 1);
  80. kfree(device);
  81. return ERR_PTR(-ENOMEM);
  82. }
  83. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  84. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  85. spin_lock_init(&device->mem_lock);
  86. atomic_set(&device->tasklet_scheduled, 0);
  87. tasklet_init(&device->tasklet,
  88. (void (*)(unsigned long)) dasd_device_tasklet,
  89. (unsigned long) device);
  90. INIT_LIST_HEAD(&device->ccw_queue);
  91. init_timer(&device->timer);
  92. device->timer.function = dasd_device_timeout;
  93. device->timer.data = (unsigned long) device;
  94. INIT_WORK(&device->kick_work, do_kick_device);
  95. device->state = DASD_STATE_NEW;
  96. device->target = DASD_STATE_NEW;
  97. return device;
  98. }
  99. /*
  100. * Free memory of a device structure.
  101. */
  102. void dasd_free_device(struct dasd_device *device)
  103. {
  104. kfree(device->private);
  105. free_page((unsigned long) device->erp_mem);
  106. free_pages((unsigned long) device->ccw_mem, 1);
  107. kfree(device);
  108. }
  109. /*
  110. * Allocate memory for a new device structure.
  111. */
  112. struct dasd_block *dasd_alloc_block(void)
  113. {
  114. struct dasd_block *block;
  115. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  116. if (!block)
  117. return ERR_PTR(-ENOMEM);
  118. /* open_count = 0 means device online but not in use */
  119. atomic_set(&block->open_count, -1);
  120. spin_lock_init(&block->request_queue_lock);
  121. atomic_set(&block->tasklet_scheduled, 0);
  122. tasklet_init(&block->tasklet,
  123. (void (*)(unsigned long)) dasd_block_tasklet,
  124. (unsigned long) block);
  125. INIT_LIST_HEAD(&block->ccw_queue);
  126. spin_lock_init(&block->queue_lock);
  127. init_timer(&block->timer);
  128. block->timer.function = dasd_block_timeout;
  129. block->timer.data = (unsigned long) block;
  130. return block;
  131. }
  132. /*
  133. * Free memory of a device structure.
  134. */
  135. void dasd_free_block(struct dasd_block *block)
  136. {
  137. kfree(block);
  138. }
  139. /*
  140. * Make a new device known to the system.
  141. */
  142. static int dasd_state_new_to_known(struct dasd_device *device)
  143. {
  144. int rc;
  145. /*
  146. * As long as the device is not in state DASD_STATE_NEW we want to
  147. * keep the reference count > 0.
  148. */
  149. dasd_get_device(device);
  150. if (device->block) {
  151. rc = dasd_alloc_queue(device->block);
  152. if (rc) {
  153. dasd_put_device(device);
  154. return rc;
  155. }
  156. }
  157. device->state = DASD_STATE_KNOWN;
  158. return 0;
  159. }
  160. /*
  161. * Let the system forget about a device.
  162. */
  163. static int dasd_state_known_to_new(struct dasd_device *device)
  164. {
  165. /* Disable extended error reporting for this device. */
  166. dasd_eer_disable(device);
  167. /* Forget the discipline information. */
  168. if (device->discipline) {
  169. if (device->discipline->uncheck_device)
  170. device->discipline->uncheck_device(device);
  171. module_put(device->discipline->owner);
  172. }
  173. device->discipline = NULL;
  174. if (device->base_discipline)
  175. module_put(device->base_discipline->owner);
  176. device->base_discipline = NULL;
  177. device->state = DASD_STATE_NEW;
  178. if (device->block)
  179. dasd_free_queue(device->block);
  180. /* Give up reference we took in dasd_state_new_to_known. */
  181. dasd_put_device(device);
  182. return 0;
  183. }
  184. /*
  185. * Request the irq line for the device.
  186. */
  187. static int dasd_state_known_to_basic(struct dasd_device *device)
  188. {
  189. int rc;
  190. /* Allocate and register gendisk structure. */
  191. if (device->block) {
  192. rc = dasd_gendisk_alloc(device->block);
  193. if (rc)
  194. return rc;
  195. }
  196. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  197. device->debug_area = debug_register(dev_name(&device->cdev->dev), 1, 1,
  198. 8 * sizeof(long));
  199. debug_register_view(device->debug_area, &debug_sprintf_view);
  200. debug_set_level(device->debug_area, DBF_WARNING);
  201. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  202. device->state = DASD_STATE_BASIC;
  203. return 0;
  204. }
  205. /*
  206. * Release the irq line for the device. Terminate any running i/o.
  207. */
  208. static int dasd_state_basic_to_known(struct dasd_device *device)
  209. {
  210. int rc;
  211. if (device->block) {
  212. dasd_gendisk_free(device->block);
  213. dasd_block_clear_timer(device->block);
  214. }
  215. rc = dasd_flush_device_queue(device);
  216. if (rc)
  217. return rc;
  218. dasd_device_clear_timer(device);
  219. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  220. if (device->debug_area != NULL) {
  221. debug_unregister(device->debug_area);
  222. device->debug_area = NULL;
  223. }
  224. device->state = DASD_STATE_KNOWN;
  225. return 0;
  226. }
  227. /*
  228. * Do the initial analysis. The do_analysis function may return
  229. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  230. * until the discipline decides to continue the startup sequence
  231. * by calling the function dasd_change_state. The eckd disciplines
  232. * uses this to start a ccw that detects the format. The completion
  233. * interrupt for this detection ccw uses the kernel event daemon to
  234. * trigger the call to dasd_change_state. All this is done in the
  235. * discipline code, see dasd_eckd.c.
  236. * After the analysis ccw is done (do_analysis returned 0) the block
  237. * device is setup.
  238. * In case the analysis returns an error, the device setup is stopped
  239. * (a fake disk was already added to allow formatting).
  240. */
  241. static int dasd_state_basic_to_ready(struct dasd_device *device)
  242. {
  243. int rc;
  244. struct dasd_block *block;
  245. rc = 0;
  246. block = device->block;
  247. /* make disk known with correct capacity */
  248. if (block) {
  249. if (block->base->discipline->do_analysis != NULL)
  250. rc = block->base->discipline->do_analysis(block);
  251. if (rc) {
  252. if (rc != -EAGAIN)
  253. device->state = DASD_STATE_UNFMT;
  254. return rc;
  255. }
  256. dasd_setup_queue(block);
  257. set_capacity(block->gdp,
  258. block->blocks << block->s2b_shift);
  259. device->state = DASD_STATE_READY;
  260. rc = dasd_scan_partitions(block);
  261. if (rc)
  262. device->state = DASD_STATE_BASIC;
  263. } else {
  264. device->state = DASD_STATE_READY;
  265. }
  266. return rc;
  267. }
  268. /*
  269. * Remove device from block device layer. Destroy dirty buffers.
  270. * Forget format information. Check if the target level is basic
  271. * and if it is create fake disk for formatting.
  272. */
  273. static int dasd_state_ready_to_basic(struct dasd_device *device)
  274. {
  275. int rc;
  276. device->state = DASD_STATE_BASIC;
  277. if (device->block) {
  278. struct dasd_block *block = device->block;
  279. rc = dasd_flush_block_queue(block);
  280. if (rc) {
  281. device->state = DASD_STATE_READY;
  282. return rc;
  283. }
  284. dasd_destroy_partitions(block);
  285. dasd_flush_request_queue(block);
  286. block->blocks = 0;
  287. block->bp_block = 0;
  288. block->s2b_shift = 0;
  289. }
  290. return 0;
  291. }
  292. /*
  293. * Back to basic.
  294. */
  295. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  296. {
  297. device->state = DASD_STATE_BASIC;
  298. return 0;
  299. }
  300. /*
  301. * Make the device online and schedule the bottom half to start
  302. * the requeueing of requests from the linux request queue to the
  303. * ccw queue.
  304. */
  305. static int
  306. dasd_state_ready_to_online(struct dasd_device * device)
  307. {
  308. int rc;
  309. struct gendisk *disk;
  310. struct disk_part_iter piter;
  311. struct hd_struct *part;
  312. if (device->discipline->ready_to_online) {
  313. rc = device->discipline->ready_to_online(device);
  314. if (rc)
  315. return rc;
  316. }
  317. device->state = DASD_STATE_ONLINE;
  318. if (device->block) {
  319. dasd_schedule_block_bh(device->block);
  320. disk = device->block->bdev->bd_disk;
  321. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  322. while ((part = disk_part_iter_next(&piter)))
  323. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  324. disk_part_iter_exit(&piter);
  325. }
  326. return 0;
  327. }
  328. /*
  329. * Stop the requeueing of requests again.
  330. */
  331. static int dasd_state_online_to_ready(struct dasd_device *device)
  332. {
  333. int rc;
  334. struct gendisk *disk;
  335. struct disk_part_iter piter;
  336. struct hd_struct *part;
  337. if (device->discipline->online_to_ready) {
  338. rc = device->discipline->online_to_ready(device);
  339. if (rc)
  340. return rc;
  341. }
  342. device->state = DASD_STATE_READY;
  343. if (device->block) {
  344. disk = device->block->bdev->bd_disk;
  345. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
  346. while ((part = disk_part_iter_next(&piter)))
  347. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
  348. disk_part_iter_exit(&piter);
  349. }
  350. return 0;
  351. }
  352. /*
  353. * Device startup state changes.
  354. */
  355. static int dasd_increase_state(struct dasd_device *device)
  356. {
  357. int rc;
  358. rc = 0;
  359. if (device->state == DASD_STATE_NEW &&
  360. device->target >= DASD_STATE_KNOWN)
  361. rc = dasd_state_new_to_known(device);
  362. if (!rc &&
  363. device->state == DASD_STATE_KNOWN &&
  364. device->target >= DASD_STATE_BASIC)
  365. rc = dasd_state_known_to_basic(device);
  366. if (!rc &&
  367. device->state == DASD_STATE_BASIC &&
  368. device->target >= DASD_STATE_READY)
  369. rc = dasd_state_basic_to_ready(device);
  370. if (!rc &&
  371. device->state == DASD_STATE_UNFMT &&
  372. device->target > DASD_STATE_UNFMT)
  373. rc = -EPERM;
  374. if (!rc &&
  375. device->state == DASD_STATE_READY &&
  376. device->target >= DASD_STATE_ONLINE)
  377. rc = dasd_state_ready_to_online(device);
  378. return rc;
  379. }
  380. /*
  381. * Device shutdown state changes.
  382. */
  383. static int dasd_decrease_state(struct dasd_device *device)
  384. {
  385. int rc;
  386. rc = 0;
  387. if (device->state == DASD_STATE_ONLINE &&
  388. device->target <= DASD_STATE_READY)
  389. rc = dasd_state_online_to_ready(device);
  390. if (!rc &&
  391. device->state == DASD_STATE_READY &&
  392. device->target <= DASD_STATE_BASIC)
  393. rc = dasd_state_ready_to_basic(device);
  394. if (!rc &&
  395. device->state == DASD_STATE_UNFMT &&
  396. device->target <= DASD_STATE_BASIC)
  397. rc = dasd_state_unfmt_to_basic(device);
  398. if (!rc &&
  399. device->state == DASD_STATE_BASIC &&
  400. device->target <= DASD_STATE_KNOWN)
  401. rc = dasd_state_basic_to_known(device);
  402. if (!rc &&
  403. device->state == DASD_STATE_KNOWN &&
  404. device->target <= DASD_STATE_NEW)
  405. rc = dasd_state_known_to_new(device);
  406. return rc;
  407. }
  408. /*
  409. * This is the main startup/shutdown routine.
  410. */
  411. static void dasd_change_state(struct dasd_device *device)
  412. {
  413. int rc;
  414. if (device->state == device->target)
  415. /* Already where we want to go today... */
  416. return;
  417. if (device->state < device->target)
  418. rc = dasd_increase_state(device);
  419. else
  420. rc = dasd_decrease_state(device);
  421. if (rc && rc != -EAGAIN)
  422. device->target = device->state;
  423. if (device->state == device->target)
  424. wake_up(&dasd_init_waitq);
  425. /* let user-space know that the device status changed */
  426. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  427. }
  428. /*
  429. * Kick starter for devices that did not complete the startup/shutdown
  430. * procedure or were sleeping because of a pending state.
  431. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  432. * event daemon.
  433. */
  434. static void do_kick_device(struct work_struct *work)
  435. {
  436. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  437. dasd_change_state(device);
  438. dasd_schedule_device_bh(device);
  439. dasd_put_device(device);
  440. }
  441. void dasd_kick_device(struct dasd_device *device)
  442. {
  443. dasd_get_device(device);
  444. /* queue call to dasd_kick_device to the kernel event daemon. */
  445. schedule_work(&device->kick_work);
  446. }
  447. /*
  448. * Set the target state for a device and starts the state change.
  449. */
  450. void dasd_set_target_state(struct dasd_device *device, int target)
  451. {
  452. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  453. if (dasd_probeonly && target > DASD_STATE_READY)
  454. target = DASD_STATE_READY;
  455. if (device->target != target) {
  456. if (device->state == target)
  457. wake_up(&dasd_init_waitq);
  458. device->target = target;
  459. }
  460. if (device->state != device->target)
  461. dasd_change_state(device);
  462. }
  463. /*
  464. * Enable devices with device numbers in [from..to].
  465. */
  466. static inline int _wait_for_device(struct dasd_device *device)
  467. {
  468. return (device->state == device->target);
  469. }
  470. void dasd_enable_device(struct dasd_device *device)
  471. {
  472. dasd_set_target_state(device, DASD_STATE_ONLINE);
  473. if (device->state <= DASD_STATE_KNOWN)
  474. /* No discipline for device found. */
  475. dasd_set_target_state(device, DASD_STATE_NEW);
  476. /* Now wait for the devices to come up. */
  477. wait_event(dasd_init_waitq, _wait_for_device(device));
  478. }
  479. /*
  480. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  481. */
  482. #ifdef CONFIG_DASD_PROFILE
  483. struct dasd_profile_info_t dasd_global_profile;
  484. unsigned int dasd_profile_level = DASD_PROFILE_OFF;
  485. /*
  486. * Increments counter in global and local profiling structures.
  487. */
  488. #define dasd_profile_counter(value, counter, block) \
  489. { \
  490. int index; \
  491. for (index = 0; index < 31 && value >> (2+index); index++); \
  492. dasd_global_profile.counter[index]++; \
  493. block->profile.counter[index]++; \
  494. }
  495. /*
  496. * Add profiling information for cqr before execution.
  497. */
  498. static void dasd_profile_start(struct dasd_block *block,
  499. struct dasd_ccw_req *cqr,
  500. struct request *req)
  501. {
  502. struct list_head *l;
  503. unsigned int counter;
  504. if (dasd_profile_level != DASD_PROFILE_ON)
  505. return;
  506. /* count the length of the chanq for statistics */
  507. counter = 0;
  508. list_for_each(l, &block->ccw_queue)
  509. if (++counter >= 31)
  510. break;
  511. dasd_global_profile.dasd_io_nr_req[counter]++;
  512. block->profile.dasd_io_nr_req[counter]++;
  513. }
  514. /*
  515. * Add profiling information for cqr after execution.
  516. */
  517. static void dasd_profile_end(struct dasd_block *block,
  518. struct dasd_ccw_req *cqr,
  519. struct request *req)
  520. {
  521. long strtime, irqtime, endtime, tottime; /* in microseconds */
  522. long tottimeps, sectors;
  523. if (dasd_profile_level != DASD_PROFILE_ON)
  524. return;
  525. sectors = req->nr_sectors;
  526. if (!cqr->buildclk || !cqr->startclk ||
  527. !cqr->stopclk || !cqr->endclk ||
  528. !sectors)
  529. return;
  530. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  531. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  532. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  533. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  534. tottimeps = tottime / sectors;
  535. if (!dasd_global_profile.dasd_io_reqs)
  536. memset(&dasd_global_profile, 0,
  537. sizeof(struct dasd_profile_info_t));
  538. dasd_global_profile.dasd_io_reqs++;
  539. dasd_global_profile.dasd_io_sects += sectors;
  540. if (!block->profile.dasd_io_reqs)
  541. memset(&block->profile, 0,
  542. sizeof(struct dasd_profile_info_t));
  543. block->profile.dasd_io_reqs++;
  544. block->profile.dasd_io_sects += sectors;
  545. dasd_profile_counter(sectors, dasd_io_secs, block);
  546. dasd_profile_counter(tottime, dasd_io_times, block);
  547. dasd_profile_counter(tottimeps, dasd_io_timps, block);
  548. dasd_profile_counter(strtime, dasd_io_time1, block);
  549. dasd_profile_counter(irqtime, dasd_io_time2, block);
  550. dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
  551. dasd_profile_counter(endtime, dasd_io_time3, block);
  552. }
  553. #else
  554. #define dasd_profile_start(block, cqr, req) do {} while (0)
  555. #define dasd_profile_end(block, cqr, req) do {} while (0)
  556. #endif /* CONFIG_DASD_PROFILE */
  557. /*
  558. * Allocate memory for a channel program with 'cplength' channel
  559. * command words and 'datasize' additional space. There are two
  560. * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
  561. * memory and 2) dasd_smalloc_request uses the static ccw memory
  562. * that gets allocated for each device.
  563. */
  564. struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
  565. int datasize,
  566. struct dasd_device *device)
  567. {
  568. struct dasd_ccw_req *cqr;
  569. /* Sanity checks */
  570. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  571. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  572. cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
  573. if (cqr == NULL)
  574. return ERR_PTR(-ENOMEM);
  575. cqr->cpaddr = NULL;
  576. if (cplength > 0) {
  577. cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  578. GFP_ATOMIC | GFP_DMA);
  579. if (cqr->cpaddr == NULL) {
  580. kfree(cqr);
  581. return ERR_PTR(-ENOMEM);
  582. }
  583. }
  584. cqr->data = NULL;
  585. if (datasize > 0) {
  586. cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
  587. if (cqr->data == NULL) {
  588. kfree(cqr->cpaddr);
  589. kfree(cqr);
  590. return ERR_PTR(-ENOMEM);
  591. }
  592. }
  593. strncpy((char *) &cqr->magic, magic, 4);
  594. ASCEBC((char *) &cqr->magic, 4);
  595. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  596. dasd_get_device(device);
  597. return cqr;
  598. }
  599. struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
  600. int datasize,
  601. struct dasd_device *device)
  602. {
  603. unsigned long flags;
  604. struct dasd_ccw_req *cqr;
  605. char *data;
  606. int size;
  607. /* Sanity checks */
  608. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  609. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  610. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  611. if (cplength > 0)
  612. size += cplength * sizeof(struct ccw1);
  613. if (datasize > 0)
  614. size += datasize;
  615. spin_lock_irqsave(&device->mem_lock, flags);
  616. cqr = (struct dasd_ccw_req *)
  617. dasd_alloc_chunk(&device->ccw_chunks, size);
  618. spin_unlock_irqrestore(&device->mem_lock, flags);
  619. if (cqr == NULL)
  620. return ERR_PTR(-ENOMEM);
  621. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  622. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  623. cqr->cpaddr = NULL;
  624. if (cplength > 0) {
  625. cqr->cpaddr = (struct ccw1 *) data;
  626. data += cplength*sizeof(struct ccw1);
  627. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  628. }
  629. cqr->data = NULL;
  630. if (datasize > 0) {
  631. cqr->data = data;
  632. memset(cqr->data, 0, datasize);
  633. }
  634. strncpy((char *) &cqr->magic, magic, 4);
  635. ASCEBC((char *) &cqr->magic, 4);
  636. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  637. dasd_get_device(device);
  638. return cqr;
  639. }
  640. /*
  641. * Free memory of a channel program. This function needs to free all the
  642. * idal lists that might have been created by dasd_set_cda and the
  643. * struct dasd_ccw_req itself.
  644. */
  645. void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  646. {
  647. #ifdef CONFIG_64BIT
  648. struct ccw1 *ccw;
  649. /* Clear any idals used for the request. */
  650. ccw = cqr->cpaddr;
  651. do {
  652. clear_normalized_cda(ccw);
  653. } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
  654. #endif
  655. kfree(cqr->cpaddr);
  656. kfree(cqr->data);
  657. kfree(cqr);
  658. dasd_put_device(device);
  659. }
  660. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  661. {
  662. unsigned long flags;
  663. spin_lock_irqsave(&device->mem_lock, flags);
  664. dasd_free_chunk(&device->ccw_chunks, cqr);
  665. spin_unlock_irqrestore(&device->mem_lock, flags);
  666. dasd_put_device(device);
  667. }
  668. /*
  669. * Check discipline magic in cqr.
  670. */
  671. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  672. {
  673. struct dasd_device *device;
  674. if (cqr == NULL)
  675. return -EINVAL;
  676. device = cqr->startdev;
  677. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  678. DEV_MESSAGE(KERN_WARNING, device,
  679. " dasd_ccw_req 0x%08x magic doesn't match"
  680. " discipline 0x%08x",
  681. cqr->magic,
  682. *(unsigned int *) device->discipline->name);
  683. return -EINVAL;
  684. }
  685. return 0;
  686. }
  687. /*
  688. * Terminate the current i/o and set the request to clear_pending.
  689. * Timer keeps device runnig.
  690. * ccw_device_clear can fail if the i/o subsystem
  691. * is in a bad mood.
  692. */
  693. int dasd_term_IO(struct dasd_ccw_req *cqr)
  694. {
  695. struct dasd_device *device;
  696. int retries, rc;
  697. /* Check the cqr */
  698. rc = dasd_check_cqr(cqr);
  699. if (rc)
  700. return rc;
  701. retries = 0;
  702. device = (struct dasd_device *) cqr->startdev;
  703. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  704. rc = ccw_device_clear(device->cdev, (long) cqr);
  705. switch (rc) {
  706. case 0: /* termination successful */
  707. cqr->retries--;
  708. cqr->status = DASD_CQR_CLEAR_PENDING;
  709. cqr->stopclk = get_clock();
  710. cqr->starttime = 0;
  711. DBF_DEV_EVENT(DBF_DEBUG, device,
  712. "terminate cqr %p successful",
  713. cqr);
  714. break;
  715. case -ENODEV:
  716. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  717. "device gone, retry");
  718. break;
  719. case -EIO:
  720. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  721. "I/O error, retry");
  722. break;
  723. case -EINVAL:
  724. case -EBUSY:
  725. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  726. "device busy, retry later");
  727. break;
  728. default:
  729. DEV_MESSAGE(KERN_ERR, device,
  730. "line %d unknown RC=%d, please "
  731. "report to linux390@de.ibm.com",
  732. __LINE__, rc);
  733. BUG();
  734. break;
  735. }
  736. retries++;
  737. }
  738. dasd_schedule_device_bh(device);
  739. return rc;
  740. }
  741. /*
  742. * Start the i/o. This start_IO can fail if the channel is really busy.
  743. * In that case set up a timer to start the request later.
  744. */
  745. int dasd_start_IO(struct dasd_ccw_req *cqr)
  746. {
  747. struct dasd_device *device;
  748. int rc;
  749. /* Check the cqr */
  750. rc = dasd_check_cqr(cqr);
  751. if (rc)
  752. return rc;
  753. device = (struct dasd_device *) cqr->startdev;
  754. if (cqr->retries < 0) {
  755. DEV_MESSAGE(KERN_DEBUG, device,
  756. "start_IO: request %p (%02x/%i) - no retry left.",
  757. cqr, cqr->status, cqr->retries);
  758. cqr->status = DASD_CQR_ERROR;
  759. return -EIO;
  760. }
  761. cqr->startclk = get_clock();
  762. cqr->starttime = jiffies;
  763. cqr->retries--;
  764. rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
  765. cqr->lpm, 0);
  766. switch (rc) {
  767. case 0:
  768. cqr->status = DASD_CQR_IN_IO;
  769. DBF_DEV_EVENT(DBF_DEBUG, device,
  770. "start_IO: request %p started successful",
  771. cqr);
  772. break;
  773. case -EBUSY:
  774. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  775. "start_IO: device busy, retry later");
  776. break;
  777. case -ETIMEDOUT:
  778. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  779. "start_IO: request timeout, retry later");
  780. break;
  781. case -EACCES:
  782. /* -EACCES indicates that the request used only a
  783. * subset of the available pathes and all these
  784. * pathes are gone.
  785. * Do a retry with all available pathes.
  786. */
  787. cqr->lpm = LPM_ANYPATH;
  788. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  789. "start_IO: selected pathes gone,"
  790. " retry on all pathes");
  791. break;
  792. case -ENODEV:
  793. case -EIO:
  794. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  795. "start_IO: device gone, retry");
  796. break;
  797. default:
  798. DEV_MESSAGE(KERN_ERR, device,
  799. "line %d unknown RC=%d, please report"
  800. " to linux390@de.ibm.com", __LINE__, rc);
  801. BUG();
  802. break;
  803. }
  804. return rc;
  805. }
  806. /*
  807. * Timeout function for dasd devices. This is used for different purposes
  808. * 1) missing interrupt handler for normal operation
  809. * 2) delayed start of request where start_IO failed with -EBUSY
  810. * 3) timeout for missing state change interrupts
  811. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  812. * DASD_CQR_QUEUED for 2) and 3).
  813. */
  814. static void dasd_device_timeout(unsigned long ptr)
  815. {
  816. unsigned long flags;
  817. struct dasd_device *device;
  818. device = (struct dasd_device *) ptr;
  819. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  820. /* re-activate request queue */
  821. device->stopped &= ~DASD_STOPPED_PENDING;
  822. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  823. dasd_schedule_device_bh(device);
  824. }
  825. /*
  826. * Setup timeout for a device in jiffies.
  827. */
  828. void dasd_device_set_timer(struct dasd_device *device, int expires)
  829. {
  830. if (expires == 0)
  831. del_timer(&device->timer);
  832. else
  833. mod_timer(&device->timer, jiffies + expires);
  834. }
  835. /*
  836. * Clear timeout for a device.
  837. */
  838. void dasd_device_clear_timer(struct dasd_device *device)
  839. {
  840. del_timer(&device->timer);
  841. }
  842. static void dasd_handle_killed_request(struct ccw_device *cdev,
  843. unsigned long intparm)
  844. {
  845. struct dasd_ccw_req *cqr;
  846. struct dasd_device *device;
  847. if (!intparm)
  848. return;
  849. cqr = (struct dasd_ccw_req *) intparm;
  850. if (cqr->status != DASD_CQR_IN_IO) {
  851. MESSAGE(KERN_DEBUG,
  852. "invalid status in handle_killed_request: "
  853. "bus_id %s, status %02x",
  854. dev_name(&cdev->dev), cqr->status);
  855. return;
  856. }
  857. device = (struct dasd_device *) cqr->startdev;
  858. if (device == NULL ||
  859. device != dasd_device_from_cdev_locked(cdev) ||
  860. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  861. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  862. dev_name(&cdev->dev));
  863. return;
  864. }
  865. /* Schedule request to be retried. */
  866. cqr->status = DASD_CQR_QUEUED;
  867. dasd_device_clear_timer(device);
  868. dasd_schedule_device_bh(device);
  869. dasd_put_device(device);
  870. }
  871. void dasd_generic_handle_state_change(struct dasd_device *device)
  872. {
  873. /* First of all start sense subsystem status request. */
  874. dasd_eer_snss(device);
  875. device->stopped &= ~DASD_STOPPED_PENDING;
  876. dasd_schedule_device_bh(device);
  877. if (device->block)
  878. dasd_schedule_block_bh(device->block);
  879. }
  880. /*
  881. * Interrupt handler for "normal" ssch-io based dasd devices.
  882. */
  883. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  884. struct irb *irb)
  885. {
  886. struct dasd_ccw_req *cqr, *next;
  887. struct dasd_device *device;
  888. unsigned long long now;
  889. int expires;
  890. if (IS_ERR(irb)) {
  891. switch (PTR_ERR(irb)) {
  892. case -EIO:
  893. break;
  894. case -ETIMEDOUT:
  895. printk(KERN_WARNING"%s(%s): request timed out\n",
  896. __func__, dev_name(&cdev->dev));
  897. break;
  898. default:
  899. printk(KERN_WARNING"%s(%s): unknown error %ld\n",
  900. __func__, dev_name(&cdev->dev), PTR_ERR(irb));
  901. }
  902. dasd_handle_killed_request(cdev, intparm);
  903. return;
  904. }
  905. now = get_clock();
  906. DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
  907. dev_name(&cdev->dev), ((irb->scsw.cmd.cstat << 8) |
  908. irb->scsw.cmd.dstat), (unsigned int) intparm);
  909. /* check for unsolicited interrupts */
  910. cqr = (struct dasd_ccw_req *) intparm;
  911. if (!cqr || ((irb->scsw.cmd.cc == 1) &&
  912. (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
  913. (irb->scsw.cmd.stctl & SCSW_STCTL_STATUS_PEND))) {
  914. if (cqr && cqr->status == DASD_CQR_IN_IO)
  915. cqr->status = DASD_CQR_QUEUED;
  916. device = dasd_device_from_cdev_locked(cdev);
  917. if (!IS_ERR(device)) {
  918. dasd_device_clear_timer(device);
  919. device->discipline->handle_unsolicited_interrupt(device,
  920. irb);
  921. dasd_put_device(device);
  922. }
  923. return;
  924. }
  925. device = (struct dasd_device *) cqr->startdev;
  926. if (!device ||
  927. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  928. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  929. dev_name(&cdev->dev));
  930. return;
  931. }
  932. /* Check for clear pending */
  933. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  934. irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
  935. cqr->status = DASD_CQR_CLEARED;
  936. dasd_device_clear_timer(device);
  937. wake_up(&dasd_flush_wq);
  938. dasd_schedule_device_bh(device);
  939. return;
  940. }
  941. /* check status - the request might have been killed by dyn detach */
  942. if (cqr->status != DASD_CQR_IN_IO) {
  943. MESSAGE(KERN_DEBUG,
  944. "invalid status: bus_id %s, status %02x",
  945. dev_name(&cdev->dev), cqr->status);
  946. return;
  947. }
  948. DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
  949. ((irb->scsw.cmd.cstat << 8) | irb->scsw.cmd.dstat), cqr);
  950. next = NULL;
  951. expires = 0;
  952. if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  953. irb->scsw.cmd.cstat == 0 && !irb->esw.esw0.erw.cons) {
  954. /* request was completed successfully */
  955. cqr->status = DASD_CQR_SUCCESS;
  956. cqr->stopclk = now;
  957. /* Start first request on queue if possible -> fast_io. */
  958. if (cqr->devlist.next != &device->ccw_queue) {
  959. next = list_entry(cqr->devlist.next,
  960. struct dasd_ccw_req, devlist);
  961. }
  962. } else { /* error */
  963. memcpy(&cqr->irb, irb, sizeof(struct irb));
  964. if (device->features & DASD_FEATURE_ERPLOG) {
  965. dasd_log_sense(cqr, irb);
  966. }
  967. /*
  968. * If we don't want complex ERP for this request, then just
  969. * reset this and retry it in the fastpath
  970. */
  971. if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
  972. cqr->retries > 0) {
  973. DEV_MESSAGE(KERN_DEBUG, device,
  974. "default ERP in fastpath (%i retries left)",
  975. cqr->retries);
  976. cqr->lpm = LPM_ANYPATH;
  977. cqr->status = DASD_CQR_QUEUED;
  978. next = cqr;
  979. } else
  980. cqr->status = DASD_CQR_ERROR;
  981. }
  982. if (next && (next->status == DASD_CQR_QUEUED) &&
  983. (!device->stopped)) {
  984. if (device->discipline->start_IO(next) == 0)
  985. expires = next->expires;
  986. else
  987. DEV_MESSAGE(KERN_DEBUG, device, "%s",
  988. "Interrupt fastpath "
  989. "failed!");
  990. }
  991. if (expires != 0)
  992. dasd_device_set_timer(device, expires);
  993. else
  994. dasd_device_clear_timer(device);
  995. dasd_schedule_device_bh(device);
  996. }
  997. /*
  998. * If we have an error on a dasd_block layer request then we cancel
  999. * and return all further requests from the same dasd_block as well.
  1000. */
  1001. static void __dasd_device_recovery(struct dasd_device *device,
  1002. struct dasd_ccw_req *ref_cqr)
  1003. {
  1004. struct list_head *l, *n;
  1005. struct dasd_ccw_req *cqr;
  1006. /*
  1007. * only requeue request that came from the dasd_block layer
  1008. */
  1009. if (!ref_cqr->block)
  1010. return;
  1011. list_for_each_safe(l, n, &device->ccw_queue) {
  1012. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1013. if (cqr->status == DASD_CQR_QUEUED &&
  1014. ref_cqr->block == cqr->block) {
  1015. cqr->status = DASD_CQR_CLEARED;
  1016. }
  1017. }
  1018. };
  1019. /*
  1020. * Remove those ccw requests from the queue that need to be returned
  1021. * to the upper layer.
  1022. */
  1023. static void __dasd_device_process_ccw_queue(struct dasd_device *device,
  1024. struct list_head *final_queue)
  1025. {
  1026. struct list_head *l, *n;
  1027. struct dasd_ccw_req *cqr;
  1028. /* Process request with final status. */
  1029. list_for_each_safe(l, n, &device->ccw_queue) {
  1030. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1031. /* Stop list processing at the first non-final request. */
  1032. if (cqr->status == DASD_CQR_QUEUED ||
  1033. cqr->status == DASD_CQR_IN_IO ||
  1034. cqr->status == DASD_CQR_CLEAR_PENDING)
  1035. break;
  1036. if (cqr->status == DASD_CQR_ERROR) {
  1037. __dasd_device_recovery(device, cqr);
  1038. }
  1039. /* Rechain finished requests to final queue */
  1040. list_move_tail(&cqr->devlist, final_queue);
  1041. }
  1042. }
  1043. /*
  1044. * the cqrs from the final queue are returned to the upper layer
  1045. * by setting a dasd_block state and calling the callback function
  1046. */
  1047. static void __dasd_device_process_final_queue(struct dasd_device *device,
  1048. struct list_head *final_queue)
  1049. {
  1050. struct list_head *l, *n;
  1051. struct dasd_ccw_req *cqr;
  1052. struct dasd_block *block;
  1053. void (*callback)(struct dasd_ccw_req *, void *data);
  1054. void *callback_data;
  1055. list_for_each_safe(l, n, final_queue) {
  1056. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1057. list_del_init(&cqr->devlist);
  1058. block = cqr->block;
  1059. callback = cqr->callback;
  1060. callback_data = cqr->callback_data;
  1061. if (block)
  1062. spin_lock_bh(&block->queue_lock);
  1063. switch (cqr->status) {
  1064. case DASD_CQR_SUCCESS:
  1065. cqr->status = DASD_CQR_DONE;
  1066. break;
  1067. case DASD_CQR_ERROR:
  1068. cqr->status = DASD_CQR_NEED_ERP;
  1069. break;
  1070. case DASD_CQR_CLEARED:
  1071. cqr->status = DASD_CQR_TERMINATED;
  1072. break;
  1073. default:
  1074. DEV_MESSAGE(KERN_ERR, device,
  1075. "wrong cqr status in __dasd_process_final_queue "
  1076. "for cqr %p, status %x",
  1077. cqr, cqr->status);
  1078. BUG();
  1079. }
  1080. if (cqr->callback != NULL)
  1081. (callback)(cqr, callback_data);
  1082. if (block)
  1083. spin_unlock_bh(&block->queue_lock);
  1084. }
  1085. }
  1086. /*
  1087. * Take a look at the first request on the ccw queue and check
  1088. * if it reached its expire time. If so, terminate the IO.
  1089. */
  1090. static void __dasd_device_check_expire(struct dasd_device *device)
  1091. {
  1092. struct dasd_ccw_req *cqr;
  1093. if (list_empty(&device->ccw_queue))
  1094. return;
  1095. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1096. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1097. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1098. if (device->discipline->term_IO(cqr) != 0) {
  1099. /* Hmpf, try again in 5 sec */
  1100. DEV_MESSAGE(KERN_ERR, device,
  1101. "internal error - timeout (%is) expired "
  1102. "for cqr %p, termination failed, "
  1103. "retrying in 5s",
  1104. (cqr->expires/HZ), cqr);
  1105. cqr->expires += 5*HZ;
  1106. dasd_device_set_timer(device, 5*HZ);
  1107. } else {
  1108. DEV_MESSAGE(KERN_ERR, device,
  1109. "internal error - timeout (%is) expired "
  1110. "for cqr %p (%i retries left)",
  1111. (cqr->expires/HZ), cqr, cqr->retries);
  1112. }
  1113. }
  1114. }
  1115. /*
  1116. * Take a look at the first request on the ccw queue and check
  1117. * if it needs to be started.
  1118. */
  1119. static void __dasd_device_start_head(struct dasd_device *device)
  1120. {
  1121. struct dasd_ccw_req *cqr;
  1122. int rc;
  1123. if (list_empty(&device->ccw_queue))
  1124. return;
  1125. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1126. if (cqr->status != DASD_CQR_QUEUED)
  1127. return;
  1128. /* when device is stopped, return request to previous layer */
  1129. if (device->stopped) {
  1130. cqr->status = DASD_CQR_CLEARED;
  1131. dasd_schedule_device_bh(device);
  1132. return;
  1133. }
  1134. rc = device->discipline->start_IO(cqr);
  1135. if (rc == 0)
  1136. dasd_device_set_timer(device, cqr->expires);
  1137. else if (rc == -EACCES) {
  1138. dasd_schedule_device_bh(device);
  1139. } else
  1140. /* Hmpf, try again in 1/2 sec */
  1141. dasd_device_set_timer(device, 50);
  1142. }
  1143. /*
  1144. * Go through all request on the dasd_device request queue,
  1145. * terminate them on the cdev if necessary, and return them to the
  1146. * submitting layer via callback.
  1147. * Note:
  1148. * Make sure that all 'submitting layers' still exist when
  1149. * this function is called!. In other words, when 'device' is a base
  1150. * device then all block layer requests must have been removed before
  1151. * via dasd_flush_block_queue.
  1152. */
  1153. int dasd_flush_device_queue(struct dasd_device *device)
  1154. {
  1155. struct dasd_ccw_req *cqr, *n;
  1156. int rc;
  1157. struct list_head flush_queue;
  1158. INIT_LIST_HEAD(&flush_queue);
  1159. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1160. rc = 0;
  1161. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1162. /* Check status and move request to flush_queue */
  1163. switch (cqr->status) {
  1164. case DASD_CQR_IN_IO:
  1165. rc = device->discipline->term_IO(cqr);
  1166. if (rc) {
  1167. /* unable to terminate requeust */
  1168. DEV_MESSAGE(KERN_ERR, device,
  1169. "dasd flush ccw_queue is unable "
  1170. " to terminate request %p",
  1171. cqr);
  1172. /* stop flush processing */
  1173. goto finished;
  1174. }
  1175. break;
  1176. case DASD_CQR_QUEUED:
  1177. cqr->stopclk = get_clock();
  1178. cqr->status = DASD_CQR_CLEARED;
  1179. break;
  1180. default: /* no need to modify the others */
  1181. break;
  1182. }
  1183. list_move_tail(&cqr->devlist, &flush_queue);
  1184. }
  1185. finished:
  1186. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1187. /*
  1188. * After this point all requests must be in state CLEAR_PENDING,
  1189. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1190. * one of the others.
  1191. */
  1192. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1193. wait_event(dasd_flush_wq,
  1194. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1195. /*
  1196. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1197. * and call the callback function of flushed requests
  1198. */
  1199. __dasd_device_process_final_queue(device, &flush_queue);
  1200. return rc;
  1201. }
  1202. /*
  1203. * Acquire the device lock and process queues for the device.
  1204. */
  1205. static void dasd_device_tasklet(struct dasd_device *device)
  1206. {
  1207. struct list_head final_queue;
  1208. atomic_set (&device->tasklet_scheduled, 0);
  1209. INIT_LIST_HEAD(&final_queue);
  1210. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1211. /* Check expire time of first request on the ccw queue. */
  1212. __dasd_device_check_expire(device);
  1213. /* find final requests on ccw queue */
  1214. __dasd_device_process_ccw_queue(device, &final_queue);
  1215. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1216. /* Now call the callback function of requests with final status */
  1217. __dasd_device_process_final_queue(device, &final_queue);
  1218. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1219. /* Now check if the head of the ccw queue needs to be started. */
  1220. __dasd_device_start_head(device);
  1221. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1222. dasd_put_device(device);
  1223. }
  1224. /*
  1225. * Schedules a call to dasd_tasklet over the device tasklet.
  1226. */
  1227. void dasd_schedule_device_bh(struct dasd_device *device)
  1228. {
  1229. /* Protect against rescheduling. */
  1230. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1231. return;
  1232. dasd_get_device(device);
  1233. tasklet_hi_schedule(&device->tasklet);
  1234. }
  1235. /*
  1236. * Queue a request to the head of the device ccw_queue.
  1237. * Start the I/O if possible.
  1238. */
  1239. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1240. {
  1241. struct dasd_device *device;
  1242. unsigned long flags;
  1243. device = cqr->startdev;
  1244. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1245. cqr->status = DASD_CQR_QUEUED;
  1246. list_add(&cqr->devlist, &device->ccw_queue);
  1247. /* let the bh start the request to keep them in order */
  1248. dasd_schedule_device_bh(device);
  1249. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1250. }
  1251. /*
  1252. * Queue a request to the tail of the device ccw_queue.
  1253. * Start the I/O if possible.
  1254. */
  1255. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1256. {
  1257. struct dasd_device *device;
  1258. unsigned long flags;
  1259. device = cqr->startdev;
  1260. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1261. cqr->status = DASD_CQR_QUEUED;
  1262. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1263. /* let the bh start the request to keep them in order */
  1264. dasd_schedule_device_bh(device);
  1265. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1266. }
  1267. /*
  1268. * Wakeup helper for the 'sleep_on' functions.
  1269. */
  1270. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1271. {
  1272. wake_up((wait_queue_head_t *) data);
  1273. }
  1274. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1275. {
  1276. struct dasd_device *device;
  1277. int rc;
  1278. device = cqr->startdev;
  1279. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1280. rc = ((cqr->status == DASD_CQR_DONE ||
  1281. cqr->status == DASD_CQR_NEED_ERP ||
  1282. cqr->status == DASD_CQR_TERMINATED) &&
  1283. list_empty(&cqr->devlist));
  1284. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1285. return rc;
  1286. }
  1287. /*
  1288. * Queue a request to the tail of the device ccw_queue and wait for
  1289. * it's completion.
  1290. */
  1291. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1292. {
  1293. struct dasd_device *device;
  1294. int rc;
  1295. device = cqr->startdev;
  1296. cqr->callback = dasd_wakeup_cb;
  1297. cqr->callback_data = (void *) &generic_waitq;
  1298. dasd_add_request_tail(cqr);
  1299. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1300. /* Request status is either done or failed. */
  1301. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1302. return rc;
  1303. }
  1304. /*
  1305. * Queue a request to the tail of the device ccw_queue and wait
  1306. * interruptible for it's completion.
  1307. */
  1308. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1309. {
  1310. struct dasd_device *device;
  1311. int rc;
  1312. device = cqr->startdev;
  1313. cqr->callback = dasd_wakeup_cb;
  1314. cqr->callback_data = (void *) &generic_waitq;
  1315. dasd_add_request_tail(cqr);
  1316. rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr));
  1317. if (rc == -ERESTARTSYS) {
  1318. dasd_cancel_req(cqr);
  1319. /* wait (non-interruptible) for final status */
  1320. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1321. }
  1322. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1323. return rc;
  1324. }
  1325. /*
  1326. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1327. * for eckd devices) the currently running request has to be terminated
  1328. * and be put back to status queued, before the special request is added
  1329. * to the head of the queue. Then the special request is waited on normally.
  1330. */
  1331. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1332. {
  1333. struct dasd_ccw_req *cqr;
  1334. if (list_empty(&device->ccw_queue))
  1335. return 0;
  1336. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1337. return device->discipline->term_IO(cqr);
  1338. }
  1339. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1340. {
  1341. struct dasd_device *device;
  1342. int rc;
  1343. device = cqr->startdev;
  1344. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1345. rc = _dasd_term_running_cqr(device);
  1346. if (rc) {
  1347. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1348. return rc;
  1349. }
  1350. cqr->callback = dasd_wakeup_cb;
  1351. cqr->callback_data = (void *) &generic_waitq;
  1352. cqr->status = DASD_CQR_QUEUED;
  1353. list_add(&cqr->devlist, &device->ccw_queue);
  1354. /* let the bh start the request to keep them in order */
  1355. dasd_schedule_device_bh(device);
  1356. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1357. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1358. /* Request status is either done or failed. */
  1359. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1360. return rc;
  1361. }
  1362. /*
  1363. * Cancels a request that was started with dasd_sleep_on_req.
  1364. * This is useful to timeout requests. The request will be
  1365. * terminated if it is currently in i/o.
  1366. * Returns 1 if the request has been terminated.
  1367. * 0 if there was no need to terminate the request (not started yet)
  1368. * negative error code if termination failed
  1369. * Cancellation of a request is an asynchronous operation! The calling
  1370. * function has to wait until the request is properly returned via callback.
  1371. */
  1372. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1373. {
  1374. struct dasd_device *device = cqr->startdev;
  1375. unsigned long flags;
  1376. int rc;
  1377. rc = 0;
  1378. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1379. switch (cqr->status) {
  1380. case DASD_CQR_QUEUED:
  1381. /* request was not started - just set to cleared */
  1382. cqr->status = DASD_CQR_CLEARED;
  1383. break;
  1384. case DASD_CQR_IN_IO:
  1385. /* request in IO - terminate IO and release again */
  1386. rc = device->discipline->term_IO(cqr);
  1387. if (rc) {
  1388. DEV_MESSAGE(KERN_ERR, device,
  1389. "dasd_cancel_req is unable "
  1390. " to terminate request %p, rc = %d",
  1391. cqr, rc);
  1392. } else {
  1393. cqr->stopclk = get_clock();
  1394. rc = 1;
  1395. }
  1396. break;
  1397. default: /* already finished or clear pending - do nothing */
  1398. break;
  1399. }
  1400. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1401. dasd_schedule_device_bh(device);
  1402. return rc;
  1403. }
  1404. /*
  1405. * SECTION: Operations of the dasd_block layer.
  1406. */
  1407. /*
  1408. * Timeout function for dasd_block. This is used when the block layer
  1409. * is waiting for something that may not come reliably, (e.g. a state
  1410. * change interrupt)
  1411. */
  1412. static void dasd_block_timeout(unsigned long ptr)
  1413. {
  1414. unsigned long flags;
  1415. struct dasd_block *block;
  1416. block = (struct dasd_block *) ptr;
  1417. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  1418. /* re-activate request queue */
  1419. block->base->stopped &= ~DASD_STOPPED_PENDING;
  1420. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  1421. dasd_schedule_block_bh(block);
  1422. }
  1423. /*
  1424. * Setup timeout for a dasd_block in jiffies.
  1425. */
  1426. void dasd_block_set_timer(struct dasd_block *block, int expires)
  1427. {
  1428. if (expires == 0)
  1429. del_timer(&block->timer);
  1430. else
  1431. mod_timer(&block->timer, jiffies + expires);
  1432. }
  1433. /*
  1434. * Clear timeout for a dasd_block.
  1435. */
  1436. void dasd_block_clear_timer(struct dasd_block *block)
  1437. {
  1438. del_timer(&block->timer);
  1439. }
  1440. /*
  1441. * posts the buffer_cache about a finalized request
  1442. */
  1443. static inline void dasd_end_request(struct request *req, int error)
  1444. {
  1445. if (__blk_end_request(req, error, blk_rq_bytes(req)))
  1446. BUG();
  1447. }
  1448. /*
  1449. * Process finished error recovery ccw.
  1450. */
  1451. static inline void __dasd_block_process_erp(struct dasd_block *block,
  1452. struct dasd_ccw_req *cqr)
  1453. {
  1454. dasd_erp_fn_t erp_fn;
  1455. struct dasd_device *device = block->base;
  1456. if (cqr->status == DASD_CQR_DONE)
  1457. DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
  1458. else
  1459. DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
  1460. erp_fn = device->discipline->erp_postaction(cqr);
  1461. erp_fn(cqr);
  1462. }
  1463. /*
  1464. * Fetch requests from the block device queue.
  1465. */
  1466. static void __dasd_process_request_queue(struct dasd_block *block)
  1467. {
  1468. struct request_queue *queue;
  1469. struct request *req;
  1470. struct dasd_ccw_req *cqr;
  1471. struct dasd_device *basedev;
  1472. unsigned long flags;
  1473. queue = block->request_queue;
  1474. basedev = block->base;
  1475. /* No queue ? Then there is nothing to do. */
  1476. if (queue == NULL)
  1477. return;
  1478. /*
  1479. * We requeue request from the block device queue to the ccw
  1480. * queue only in two states. In state DASD_STATE_READY the
  1481. * partition detection is done and we need to requeue requests
  1482. * for that. State DASD_STATE_ONLINE is normal block device
  1483. * operation.
  1484. */
  1485. if (basedev->state < DASD_STATE_READY)
  1486. return;
  1487. /* Now we try to fetch requests from the request queue */
  1488. while (!blk_queue_plugged(queue) &&
  1489. elv_next_request(queue)) {
  1490. req = elv_next_request(queue);
  1491. if (basedev->features & DASD_FEATURE_READONLY &&
  1492. rq_data_dir(req) == WRITE) {
  1493. DBF_DEV_EVENT(DBF_ERR, basedev,
  1494. "Rejecting write request %p",
  1495. req);
  1496. blkdev_dequeue_request(req);
  1497. dasd_end_request(req, -EIO);
  1498. continue;
  1499. }
  1500. cqr = basedev->discipline->build_cp(basedev, block, req);
  1501. if (IS_ERR(cqr)) {
  1502. if (PTR_ERR(cqr) == -EBUSY)
  1503. break; /* normal end condition */
  1504. if (PTR_ERR(cqr) == -ENOMEM)
  1505. break; /* terminate request queue loop */
  1506. if (PTR_ERR(cqr) == -EAGAIN) {
  1507. /*
  1508. * The current request cannot be build right
  1509. * now, we have to try later. If this request
  1510. * is the head-of-queue we stop the device
  1511. * for 1/2 second.
  1512. */
  1513. if (!list_empty(&block->ccw_queue))
  1514. break;
  1515. spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
  1516. basedev->stopped |= DASD_STOPPED_PENDING;
  1517. spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
  1518. dasd_block_set_timer(block, HZ/2);
  1519. break;
  1520. }
  1521. DBF_DEV_EVENT(DBF_ERR, basedev,
  1522. "CCW creation failed (rc=%ld) "
  1523. "on request %p",
  1524. PTR_ERR(cqr), req);
  1525. blkdev_dequeue_request(req);
  1526. dasd_end_request(req, -EIO);
  1527. continue;
  1528. }
  1529. /*
  1530. * Note: callback is set to dasd_return_cqr_cb in
  1531. * __dasd_block_start_head to cover erp requests as well
  1532. */
  1533. cqr->callback_data = (void *) req;
  1534. cqr->status = DASD_CQR_FILLED;
  1535. blkdev_dequeue_request(req);
  1536. list_add_tail(&cqr->blocklist, &block->ccw_queue);
  1537. dasd_profile_start(block, cqr, req);
  1538. }
  1539. }
  1540. static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
  1541. {
  1542. struct request *req;
  1543. int status;
  1544. int error = 0;
  1545. req = (struct request *) cqr->callback_data;
  1546. dasd_profile_end(cqr->block, cqr, req);
  1547. status = cqr->block->base->discipline->free_cp(cqr, req);
  1548. if (status <= 0)
  1549. error = status ? status : -EIO;
  1550. dasd_end_request(req, error);
  1551. }
  1552. /*
  1553. * Process ccw request queue.
  1554. */
  1555. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  1556. struct list_head *final_queue)
  1557. {
  1558. struct list_head *l, *n;
  1559. struct dasd_ccw_req *cqr;
  1560. dasd_erp_fn_t erp_fn;
  1561. unsigned long flags;
  1562. struct dasd_device *base = block->base;
  1563. restart:
  1564. /* Process request with final status. */
  1565. list_for_each_safe(l, n, &block->ccw_queue) {
  1566. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1567. if (cqr->status != DASD_CQR_DONE &&
  1568. cqr->status != DASD_CQR_FAILED &&
  1569. cqr->status != DASD_CQR_NEED_ERP &&
  1570. cqr->status != DASD_CQR_TERMINATED)
  1571. continue;
  1572. if (cqr->status == DASD_CQR_TERMINATED) {
  1573. base->discipline->handle_terminated_request(cqr);
  1574. goto restart;
  1575. }
  1576. /* Process requests that may be recovered */
  1577. if (cqr->status == DASD_CQR_NEED_ERP) {
  1578. erp_fn = base->discipline->erp_action(cqr);
  1579. erp_fn(cqr);
  1580. goto restart;
  1581. }
  1582. /* log sense for fatal error */
  1583. if (cqr->status == DASD_CQR_FAILED) {
  1584. dasd_log_sense(cqr, &cqr->irb);
  1585. }
  1586. /* First of all call extended error reporting. */
  1587. if (dasd_eer_enabled(base) &&
  1588. cqr->status == DASD_CQR_FAILED) {
  1589. dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
  1590. /* restart request */
  1591. cqr->status = DASD_CQR_FILLED;
  1592. cqr->retries = 255;
  1593. spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
  1594. base->stopped |= DASD_STOPPED_QUIESCE;
  1595. spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
  1596. flags);
  1597. goto restart;
  1598. }
  1599. /* Process finished ERP request. */
  1600. if (cqr->refers) {
  1601. __dasd_block_process_erp(block, cqr);
  1602. goto restart;
  1603. }
  1604. /* Rechain finished requests to final queue */
  1605. cqr->endclk = get_clock();
  1606. list_move_tail(&cqr->blocklist, final_queue);
  1607. }
  1608. }
  1609. static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
  1610. {
  1611. dasd_schedule_block_bh(cqr->block);
  1612. }
  1613. static void __dasd_block_start_head(struct dasd_block *block)
  1614. {
  1615. struct dasd_ccw_req *cqr;
  1616. if (list_empty(&block->ccw_queue))
  1617. return;
  1618. /* We allways begin with the first requests on the queue, as some
  1619. * of previously started requests have to be enqueued on a
  1620. * dasd_device again for error recovery.
  1621. */
  1622. list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
  1623. if (cqr->status != DASD_CQR_FILLED)
  1624. continue;
  1625. /* Non-temporary stop condition will trigger fail fast */
  1626. if (block->base->stopped & ~DASD_STOPPED_PENDING &&
  1627. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  1628. (!dasd_eer_enabled(block->base))) {
  1629. cqr->status = DASD_CQR_FAILED;
  1630. dasd_schedule_block_bh(block);
  1631. continue;
  1632. }
  1633. /* Don't try to start requests if device is stopped */
  1634. if (block->base->stopped)
  1635. return;
  1636. /* just a fail safe check, should not happen */
  1637. if (!cqr->startdev)
  1638. cqr->startdev = block->base;
  1639. /* make sure that the requests we submit find their way back */
  1640. cqr->callback = dasd_return_cqr_cb;
  1641. dasd_add_request_tail(cqr);
  1642. }
  1643. }
  1644. /*
  1645. * Central dasd_block layer routine. Takes requests from the generic
  1646. * block layer request queue, creates ccw requests, enqueues them on
  1647. * a dasd_device and processes ccw requests that have been returned.
  1648. */
  1649. static void dasd_block_tasklet(struct dasd_block *block)
  1650. {
  1651. struct list_head final_queue;
  1652. struct list_head *l, *n;
  1653. struct dasd_ccw_req *cqr;
  1654. atomic_set(&block->tasklet_scheduled, 0);
  1655. INIT_LIST_HEAD(&final_queue);
  1656. spin_lock(&block->queue_lock);
  1657. /* Finish off requests on ccw queue */
  1658. __dasd_process_block_ccw_queue(block, &final_queue);
  1659. spin_unlock(&block->queue_lock);
  1660. /* Now call the callback function of requests with final status */
  1661. spin_lock_irq(&block->request_queue_lock);
  1662. list_for_each_safe(l, n, &final_queue) {
  1663. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1664. list_del_init(&cqr->blocklist);
  1665. __dasd_cleanup_cqr(cqr);
  1666. }
  1667. spin_lock(&block->queue_lock);
  1668. /* Get new request from the block device request queue */
  1669. __dasd_process_request_queue(block);
  1670. /* Now check if the head of the ccw queue needs to be started. */
  1671. __dasd_block_start_head(block);
  1672. spin_unlock(&block->queue_lock);
  1673. spin_unlock_irq(&block->request_queue_lock);
  1674. dasd_put_device(block->base);
  1675. }
  1676. static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
  1677. {
  1678. wake_up(&dasd_flush_wq);
  1679. }
  1680. /*
  1681. * Go through all request on the dasd_block request queue, cancel them
  1682. * on the respective dasd_device, and return them to the generic
  1683. * block layer.
  1684. */
  1685. static int dasd_flush_block_queue(struct dasd_block *block)
  1686. {
  1687. struct dasd_ccw_req *cqr, *n;
  1688. int rc, i;
  1689. struct list_head flush_queue;
  1690. INIT_LIST_HEAD(&flush_queue);
  1691. spin_lock_bh(&block->queue_lock);
  1692. rc = 0;
  1693. restart:
  1694. list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
  1695. /* if this request currently owned by a dasd_device cancel it */
  1696. if (cqr->status >= DASD_CQR_QUEUED)
  1697. rc = dasd_cancel_req(cqr);
  1698. if (rc < 0)
  1699. break;
  1700. /* Rechain request (including erp chain) so it won't be
  1701. * touched by the dasd_block_tasklet anymore.
  1702. * Replace the callback so we notice when the request
  1703. * is returned from the dasd_device layer.
  1704. */
  1705. cqr->callback = _dasd_wake_block_flush_cb;
  1706. for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
  1707. list_move_tail(&cqr->blocklist, &flush_queue);
  1708. if (i > 1)
  1709. /* moved more than one request - need to restart */
  1710. goto restart;
  1711. }
  1712. spin_unlock_bh(&block->queue_lock);
  1713. /* Now call the callback function of flushed requests */
  1714. restart_cb:
  1715. list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
  1716. wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
  1717. /* Process finished ERP request. */
  1718. if (cqr->refers) {
  1719. spin_lock_bh(&block->queue_lock);
  1720. __dasd_block_process_erp(block, cqr);
  1721. spin_unlock_bh(&block->queue_lock);
  1722. /* restart list_for_xx loop since dasd_process_erp
  1723. * might remove multiple elements */
  1724. goto restart_cb;
  1725. }
  1726. /* call the callback function */
  1727. spin_lock_irq(&block->request_queue_lock);
  1728. cqr->endclk = get_clock();
  1729. list_del_init(&cqr->blocklist);
  1730. __dasd_cleanup_cqr(cqr);
  1731. spin_unlock_irq(&block->request_queue_lock);
  1732. }
  1733. return rc;
  1734. }
  1735. /*
  1736. * Schedules a call to dasd_tasklet over the device tasklet.
  1737. */
  1738. void dasd_schedule_block_bh(struct dasd_block *block)
  1739. {
  1740. /* Protect against rescheduling. */
  1741. if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
  1742. return;
  1743. /* life cycle of block is bound to it's base device */
  1744. dasd_get_device(block->base);
  1745. tasklet_hi_schedule(&block->tasklet);
  1746. }
  1747. /*
  1748. * SECTION: external block device operations
  1749. * (request queue handling, open, release, etc.)
  1750. */
  1751. /*
  1752. * Dasd request queue function. Called from ll_rw_blk.c
  1753. */
  1754. static void do_dasd_request(struct request_queue *queue)
  1755. {
  1756. struct dasd_block *block;
  1757. block = queue->queuedata;
  1758. spin_lock(&block->queue_lock);
  1759. /* Get new request from the block device request queue */
  1760. __dasd_process_request_queue(block);
  1761. /* Now check if the head of the ccw queue needs to be started. */
  1762. __dasd_block_start_head(block);
  1763. spin_unlock(&block->queue_lock);
  1764. }
  1765. /*
  1766. * Allocate and initialize request queue and default I/O scheduler.
  1767. */
  1768. static int dasd_alloc_queue(struct dasd_block *block)
  1769. {
  1770. int rc;
  1771. block->request_queue = blk_init_queue(do_dasd_request,
  1772. &block->request_queue_lock);
  1773. if (block->request_queue == NULL)
  1774. return -ENOMEM;
  1775. block->request_queue->queuedata = block;
  1776. elevator_exit(block->request_queue->elevator);
  1777. block->request_queue->elevator = NULL;
  1778. rc = elevator_init(block->request_queue, "deadline");
  1779. if (rc) {
  1780. blk_cleanup_queue(block->request_queue);
  1781. return rc;
  1782. }
  1783. return 0;
  1784. }
  1785. /*
  1786. * Allocate and initialize request queue.
  1787. */
  1788. static void dasd_setup_queue(struct dasd_block *block)
  1789. {
  1790. int max;
  1791. blk_queue_hardsect_size(block->request_queue, block->bp_block);
  1792. max = block->base->discipline->max_blocks << block->s2b_shift;
  1793. blk_queue_max_sectors(block->request_queue, max);
  1794. blk_queue_max_phys_segments(block->request_queue, -1L);
  1795. blk_queue_max_hw_segments(block->request_queue, -1L);
  1796. blk_queue_max_segment_size(block->request_queue, -1L);
  1797. blk_queue_segment_boundary(block->request_queue, -1L);
  1798. blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL);
  1799. }
  1800. /*
  1801. * Deactivate and free request queue.
  1802. */
  1803. static void dasd_free_queue(struct dasd_block *block)
  1804. {
  1805. if (block->request_queue) {
  1806. blk_cleanup_queue(block->request_queue);
  1807. block->request_queue = NULL;
  1808. }
  1809. }
  1810. /*
  1811. * Flush request on the request queue.
  1812. */
  1813. static void dasd_flush_request_queue(struct dasd_block *block)
  1814. {
  1815. struct request *req;
  1816. if (!block->request_queue)
  1817. return;
  1818. spin_lock_irq(&block->request_queue_lock);
  1819. while ((req = elv_next_request(block->request_queue))) {
  1820. blkdev_dequeue_request(req);
  1821. dasd_end_request(req, -EIO);
  1822. }
  1823. spin_unlock_irq(&block->request_queue_lock);
  1824. }
  1825. static int dasd_open(struct block_device *bdev, fmode_t mode)
  1826. {
  1827. struct dasd_block *block = bdev->bd_disk->private_data;
  1828. struct dasd_device *base = block->base;
  1829. int rc;
  1830. atomic_inc(&block->open_count);
  1831. if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
  1832. rc = -ENODEV;
  1833. goto unlock;
  1834. }
  1835. if (!try_module_get(base->discipline->owner)) {
  1836. rc = -EINVAL;
  1837. goto unlock;
  1838. }
  1839. if (dasd_probeonly) {
  1840. DEV_MESSAGE(KERN_INFO, base, "%s",
  1841. "No access to device due to probeonly mode");
  1842. rc = -EPERM;
  1843. goto out;
  1844. }
  1845. if (base->state <= DASD_STATE_BASIC) {
  1846. DBF_DEV_EVENT(DBF_ERR, base, " %s",
  1847. " Cannot open unrecognized device");
  1848. rc = -ENODEV;
  1849. goto out;
  1850. }
  1851. return 0;
  1852. out:
  1853. module_put(base->discipline->owner);
  1854. unlock:
  1855. atomic_dec(&block->open_count);
  1856. return rc;
  1857. }
  1858. static int dasd_release(struct gendisk *disk, fmode_t mode)
  1859. {
  1860. struct dasd_block *block = disk->private_data;
  1861. atomic_dec(&block->open_count);
  1862. module_put(block->base->discipline->owner);
  1863. return 0;
  1864. }
  1865. /*
  1866. * Return disk geometry.
  1867. */
  1868. static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  1869. {
  1870. struct dasd_block *block;
  1871. struct dasd_device *base;
  1872. block = bdev->bd_disk->private_data;
  1873. base = block->base;
  1874. if (!block)
  1875. return -ENODEV;
  1876. if (!base->discipline ||
  1877. !base->discipline->fill_geometry)
  1878. return -EINVAL;
  1879. base->discipline->fill_geometry(block, geo);
  1880. geo->start = get_start_sect(bdev) >> block->s2b_shift;
  1881. return 0;
  1882. }
  1883. struct block_device_operations
  1884. dasd_device_operations = {
  1885. .owner = THIS_MODULE,
  1886. .open = dasd_open,
  1887. .release = dasd_release,
  1888. .locked_ioctl = dasd_ioctl,
  1889. .getgeo = dasd_getgeo,
  1890. };
  1891. /*******************************************************************************
  1892. * end of block device operations
  1893. */
  1894. static void
  1895. dasd_exit(void)
  1896. {
  1897. #ifdef CONFIG_PROC_FS
  1898. dasd_proc_exit();
  1899. #endif
  1900. dasd_eer_exit();
  1901. if (dasd_page_cache != NULL) {
  1902. kmem_cache_destroy(dasd_page_cache);
  1903. dasd_page_cache = NULL;
  1904. }
  1905. dasd_gendisk_exit();
  1906. dasd_devmap_exit();
  1907. if (dasd_debug_area != NULL) {
  1908. debug_unregister(dasd_debug_area);
  1909. dasd_debug_area = NULL;
  1910. }
  1911. }
  1912. /*
  1913. * SECTION: common functions for ccw_driver use
  1914. */
  1915. /*
  1916. * Initial attempt at a probe function. this can be simplified once
  1917. * the other detection code is gone.
  1918. */
  1919. int dasd_generic_probe(struct ccw_device *cdev,
  1920. struct dasd_discipline *discipline)
  1921. {
  1922. int ret;
  1923. ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
  1924. if (ret) {
  1925. printk(KERN_WARNING
  1926. "dasd_generic_probe: could not set ccw-device options "
  1927. "for %s\n", dev_name(&cdev->dev));
  1928. return ret;
  1929. }
  1930. ret = dasd_add_sysfs_files(cdev);
  1931. if (ret) {
  1932. printk(KERN_WARNING
  1933. "dasd_generic_probe: could not add sysfs entries "
  1934. "for %s\n", dev_name(&cdev->dev));
  1935. return ret;
  1936. }
  1937. cdev->handler = &dasd_int_handler;
  1938. /*
  1939. * Automatically online either all dasd devices (dasd_autodetect)
  1940. * or all devices specified with dasd= parameters during
  1941. * initial probe.
  1942. */
  1943. if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
  1944. (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
  1945. ret = ccw_device_set_online(cdev);
  1946. if (ret)
  1947. printk(KERN_WARNING
  1948. "dasd_generic_probe: could not initially "
  1949. "online ccw-device %s; return code: %d\n",
  1950. dev_name(&cdev->dev), ret);
  1951. return 0;
  1952. }
  1953. /*
  1954. * This will one day be called from a global not_oper handler.
  1955. * It is also used by driver_unregister during module unload.
  1956. */
  1957. void dasd_generic_remove(struct ccw_device *cdev)
  1958. {
  1959. struct dasd_device *device;
  1960. struct dasd_block *block;
  1961. cdev->handler = NULL;
  1962. dasd_remove_sysfs_files(cdev);
  1963. device = dasd_device_from_cdev(cdev);
  1964. if (IS_ERR(device))
  1965. return;
  1966. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  1967. /* Already doing offline processing */
  1968. dasd_put_device(device);
  1969. return;
  1970. }
  1971. /*
  1972. * This device is removed unconditionally. Set offline
  1973. * flag to prevent dasd_open from opening it while it is
  1974. * no quite down yet.
  1975. */
  1976. dasd_set_target_state(device, DASD_STATE_NEW);
  1977. /* dasd_delete_device destroys the device reference. */
  1978. block = device->block;
  1979. device->block = NULL;
  1980. dasd_delete_device(device);
  1981. /*
  1982. * life cycle of block is bound to device, so delete it after
  1983. * device was safely removed
  1984. */
  1985. if (block)
  1986. dasd_free_block(block);
  1987. }
  1988. /*
  1989. * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
  1990. * the device is detected for the first time and is supposed to be used
  1991. * or the user has started activation through sysfs.
  1992. */
  1993. int dasd_generic_set_online(struct ccw_device *cdev,
  1994. struct dasd_discipline *base_discipline)
  1995. {
  1996. struct dasd_discipline *discipline;
  1997. struct dasd_device *device;
  1998. int rc;
  1999. /* first online clears initial online feature flag */
  2000. dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
  2001. device = dasd_create_device(cdev);
  2002. if (IS_ERR(device))
  2003. return PTR_ERR(device);
  2004. discipline = base_discipline;
  2005. if (device->features & DASD_FEATURE_USEDIAG) {
  2006. if (!dasd_diag_discipline_pointer) {
  2007. printk (KERN_WARNING
  2008. "dasd_generic couldn't online device %s "
  2009. "- discipline DIAG not available\n",
  2010. dev_name(&cdev->dev));
  2011. dasd_delete_device(device);
  2012. return -ENODEV;
  2013. }
  2014. discipline = dasd_diag_discipline_pointer;
  2015. }
  2016. if (!try_module_get(base_discipline->owner)) {
  2017. dasd_delete_device(device);
  2018. return -EINVAL;
  2019. }
  2020. if (!try_module_get(discipline->owner)) {
  2021. module_put(base_discipline->owner);
  2022. dasd_delete_device(device);
  2023. return -EINVAL;
  2024. }
  2025. device->base_discipline = base_discipline;
  2026. device->discipline = discipline;
  2027. /* check_device will allocate block device if necessary */
  2028. rc = discipline->check_device(device);
  2029. if (rc) {
  2030. printk (KERN_WARNING
  2031. "dasd_generic couldn't online device %s "
  2032. "with discipline %s rc=%i\n",
  2033. dev_name(&cdev->dev), discipline->name, rc);
  2034. module_put(discipline->owner);
  2035. module_put(base_discipline->owner);
  2036. dasd_delete_device(device);
  2037. return rc;
  2038. }
  2039. dasd_set_target_state(device, DASD_STATE_ONLINE);
  2040. if (device->state <= DASD_STATE_KNOWN) {
  2041. printk (KERN_WARNING
  2042. "dasd_generic discipline not found for %s\n",
  2043. dev_name(&cdev->dev));
  2044. rc = -ENODEV;
  2045. dasd_set_target_state(device, DASD_STATE_NEW);
  2046. if (device->block)
  2047. dasd_free_block(device->block);
  2048. dasd_delete_device(device);
  2049. } else
  2050. pr_debug("dasd_generic device %s found\n",
  2051. dev_name(&cdev->dev));
  2052. /* FIXME: we have to wait for the root device but we don't want
  2053. * to wait for each single device but for all at once. */
  2054. wait_event(dasd_init_waitq, _wait_for_device(device));
  2055. dasd_put_device(device);
  2056. return rc;
  2057. }
  2058. int dasd_generic_set_offline(struct ccw_device *cdev)
  2059. {
  2060. struct dasd_device *device;
  2061. struct dasd_block *block;
  2062. int max_count, open_count;
  2063. device = dasd_device_from_cdev(cdev);
  2064. if (IS_ERR(device))
  2065. return PTR_ERR(device);
  2066. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2067. /* Already doing offline processing */
  2068. dasd_put_device(device);
  2069. return 0;
  2070. }
  2071. /*
  2072. * We must make sure that this device is currently not in use.
  2073. * The open_count is increased for every opener, that includes
  2074. * the blkdev_get in dasd_scan_partitions. We are only interested
  2075. * in the other openers.
  2076. */
  2077. if (device->block) {
  2078. max_count = device->block->bdev ? 0 : -1;
  2079. open_count = atomic_read(&device->block->open_count);
  2080. if (open_count > max_count) {
  2081. if (open_count > 0)
  2082. printk(KERN_WARNING "Can't offline dasd "
  2083. "device with open count = %i.\n",
  2084. open_count);
  2085. else
  2086. printk(KERN_WARNING "%s",
  2087. "Can't offline dasd device due "
  2088. "to internal use\n");
  2089. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  2090. dasd_put_device(device);
  2091. return -EBUSY;
  2092. }
  2093. }
  2094. dasd_set_target_state(device, DASD_STATE_NEW);
  2095. /* dasd_delete_device destroys the device reference. */
  2096. block = device->block;
  2097. device->block = NULL;
  2098. dasd_delete_device(device);
  2099. /*
  2100. * life cycle of block is bound to device, so delete it after
  2101. * device was safely removed
  2102. */
  2103. if (block)
  2104. dasd_free_block(block);
  2105. return 0;
  2106. }
  2107. int dasd_generic_notify(struct ccw_device *cdev, int event)
  2108. {
  2109. struct dasd_device *device;
  2110. struct dasd_ccw_req *cqr;
  2111. int ret;
  2112. device = dasd_device_from_cdev_locked(cdev);
  2113. if (IS_ERR(device))
  2114. return 0;
  2115. ret = 0;
  2116. switch (event) {
  2117. case CIO_GONE:
  2118. case CIO_NO_PATH:
  2119. /* First of all call extended error reporting. */
  2120. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  2121. if (device->state < DASD_STATE_BASIC)
  2122. break;
  2123. /* Device is active. We want to keep it. */
  2124. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  2125. if (cqr->status == DASD_CQR_IN_IO) {
  2126. cqr->status = DASD_CQR_QUEUED;
  2127. cqr->retries++;
  2128. }
  2129. device->stopped |= DASD_STOPPED_DC_WAIT;
  2130. dasd_device_clear_timer(device);
  2131. dasd_schedule_device_bh(device);
  2132. ret = 1;
  2133. break;
  2134. case CIO_OPER:
  2135. /* FIXME: add a sanity check. */
  2136. device->stopped &= ~DASD_STOPPED_DC_WAIT;
  2137. dasd_schedule_device_bh(device);
  2138. if (device->block)
  2139. dasd_schedule_block_bh(device->block);
  2140. ret = 1;
  2141. break;
  2142. }
  2143. dasd_put_device(device);
  2144. return ret;
  2145. }
  2146. static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
  2147. void *rdc_buffer,
  2148. int rdc_buffer_size,
  2149. char *magic)
  2150. {
  2151. struct dasd_ccw_req *cqr;
  2152. struct ccw1 *ccw;
  2153. cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
  2154. if (IS_ERR(cqr)) {
  2155. DEV_MESSAGE(KERN_WARNING, device, "%s",
  2156. "Could not allocate RDC request");
  2157. return cqr;
  2158. }
  2159. ccw = cqr->cpaddr;
  2160. ccw->cmd_code = CCW_CMD_RDC;
  2161. ccw->cda = (__u32)(addr_t)rdc_buffer;
  2162. ccw->count = rdc_buffer_size;
  2163. cqr->startdev = device;
  2164. cqr->memdev = device;
  2165. cqr->expires = 10*HZ;
  2166. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  2167. cqr->retries = 2;
  2168. cqr->buildclk = get_clock();
  2169. cqr->status = DASD_CQR_FILLED;
  2170. return cqr;
  2171. }
  2172. int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
  2173. void **rdc_buffer, int rdc_buffer_size)
  2174. {
  2175. int ret;
  2176. struct dasd_ccw_req *cqr;
  2177. cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
  2178. magic);
  2179. if (IS_ERR(cqr))
  2180. return PTR_ERR(cqr);
  2181. ret = dasd_sleep_on(cqr);
  2182. dasd_sfree_request(cqr, cqr->memdev);
  2183. return ret;
  2184. }
  2185. EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
  2186. static int __init dasd_init(void)
  2187. {
  2188. int rc;
  2189. init_waitqueue_head(&dasd_init_waitq);
  2190. init_waitqueue_head(&dasd_flush_wq);
  2191. init_waitqueue_head(&generic_waitq);
  2192. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2193. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2194. if (dasd_debug_area == NULL) {
  2195. rc = -ENOMEM;
  2196. goto failed;
  2197. }
  2198. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2199. debug_set_level(dasd_debug_area, DBF_WARNING);
  2200. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2201. dasd_diag_discipline_pointer = NULL;
  2202. rc = dasd_devmap_init();
  2203. if (rc)
  2204. goto failed;
  2205. rc = dasd_gendisk_init();
  2206. if (rc)
  2207. goto failed;
  2208. rc = dasd_parse();
  2209. if (rc)
  2210. goto failed;
  2211. rc = dasd_eer_init();
  2212. if (rc)
  2213. goto failed;
  2214. #ifdef CONFIG_PROC_FS
  2215. rc = dasd_proc_init();
  2216. if (rc)
  2217. goto failed;
  2218. #endif
  2219. return 0;
  2220. failed:
  2221. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2222. dasd_exit();
  2223. return rc;
  2224. }
  2225. module_init(dasd_init);
  2226. module_exit(dasd_exit);
  2227. EXPORT_SYMBOL(dasd_debug_area);
  2228. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2229. EXPORT_SYMBOL(dasd_add_request_head);
  2230. EXPORT_SYMBOL(dasd_add_request_tail);
  2231. EXPORT_SYMBOL(dasd_cancel_req);
  2232. EXPORT_SYMBOL(dasd_device_clear_timer);
  2233. EXPORT_SYMBOL(dasd_block_clear_timer);
  2234. EXPORT_SYMBOL(dasd_enable_device);
  2235. EXPORT_SYMBOL(dasd_int_handler);
  2236. EXPORT_SYMBOL(dasd_kfree_request);
  2237. EXPORT_SYMBOL(dasd_kick_device);
  2238. EXPORT_SYMBOL(dasd_kmalloc_request);
  2239. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2240. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2241. EXPORT_SYMBOL(dasd_set_target_state);
  2242. EXPORT_SYMBOL(dasd_device_set_timer);
  2243. EXPORT_SYMBOL(dasd_block_set_timer);
  2244. EXPORT_SYMBOL(dasd_sfree_request);
  2245. EXPORT_SYMBOL(dasd_sleep_on);
  2246. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2247. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2248. EXPORT_SYMBOL(dasd_smalloc_request);
  2249. EXPORT_SYMBOL(dasd_start_IO);
  2250. EXPORT_SYMBOL(dasd_term_IO);
  2251. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2252. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2253. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2254. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2255. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2256. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2257. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2258. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2259. EXPORT_SYMBOL_GPL(dasd_free_block);