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