dasd.c 66 KB

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