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. __FUNCTION__, 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. __FUNCTION__, 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. list_for_each_safe(l, n, final_queue) {
  1036. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1037. list_del_init(&cqr->devlist);
  1038. if (cqr->block)
  1039. spin_lock_bh(&cqr->block->queue_lock);
  1040. switch (cqr->status) {
  1041. case DASD_CQR_SUCCESS:
  1042. cqr->status = DASD_CQR_DONE;
  1043. break;
  1044. case DASD_CQR_ERROR:
  1045. cqr->status = DASD_CQR_NEED_ERP;
  1046. break;
  1047. case DASD_CQR_CLEARED:
  1048. cqr->status = DASD_CQR_TERMINATED;
  1049. break;
  1050. default:
  1051. DEV_MESSAGE(KERN_ERR, device,
  1052. "wrong cqr status in __dasd_process_final_queue "
  1053. "for cqr %p, status %x",
  1054. cqr, cqr->status);
  1055. BUG();
  1056. }
  1057. if (cqr->block)
  1058. spin_unlock_bh(&cqr->block->queue_lock);
  1059. if (cqr->callback != NULL)
  1060. (cqr->callback)(cqr, cqr->callback_data);
  1061. }
  1062. }
  1063. /*
  1064. * Take a look at the first request on the ccw queue and check
  1065. * if it reached its expire time. If so, terminate the IO.
  1066. */
  1067. static void __dasd_device_check_expire(struct dasd_device *device)
  1068. {
  1069. struct dasd_ccw_req *cqr;
  1070. if (list_empty(&device->ccw_queue))
  1071. return;
  1072. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1073. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1074. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1075. if (device->discipline->term_IO(cqr) != 0) {
  1076. /* Hmpf, try again in 5 sec */
  1077. DEV_MESSAGE(KERN_ERR, device,
  1078. "internal error - timeout (%is) expired "
  1079. "for cqr %p, termination failed, "
  1080. "retrying in 5s",
  1081. (cqr->expires/HZ), cqr);
  1082. cqr->expires += 5*HZ;
  1083. dasd_device_set_timer(device, 5*HZ);
  1084. } else {
  1085. DEV_MESSAGE(KERN_ERR, device,
  1086. "internal error - timeout (%is) expired "
  1087. "for cqr %p (%i retries left)",
  1088. (cqr->expires/HZ), cqr, cqr->retries);
  1089. }
  1090. }
  1091. }
  1092. /*
  1093. * Take a look at the first request on the ccw queue and check
  1094. * if it needs to be started.
  1095. */
  1096. static void __dasd_device_start_head(struct dasd_device *device)
  1097. {
  1098. struct dasd_ccw_req *cqr;
  1099. int rc;
  1100. if (list_empty(&device->ccw_queue))
  1101. return;
  1102. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1103. if (cqr->status != DASD_CQR_QUEUED)
  1104. return;
  1105. /* when device is stopped, return request to previous layer */
  1106. if (device->stopped) {
  1107. cqr->status = DASD_CQR_CLEARED;
  1108. dasd_schedule_device_bh(device);
  1109. return;
  1110. }
  1111. rc = device->discipline->start_IO(cqr);
  1112. if (rc == 0)
  1113. dasd_device_set_timer(device, cqr->expires);
  1114. else if (rc == -EACCES) {
  1115. dasd_schedule_device_bh(device);
  1116. } else
  1117. /* Hmpf, try again in 1/2 sec */
  1118. dasd_device_set_timer(device, 50);
  1119. }
  1120. /*
  1121. * Go through all request on the dasd_device request queue,
  1122. * terminate them on the cdev if necessary, and return them to the
  1123. * submitting layer via callback.
  1124. * Note:
  1125. * Make sure that all 'submitting layers' still exist when
  1126. * this function is called!. In other words, when 'device' is a base
  1127. * device then all block layer requests must have been removed before
  1128. * via dasd_flush_block_queue.
  1129. */
  1130. int dasd_flush_device_queue(struct dasd_device *device)
  1131. {
  1132. struct dasd_ccw_req *cqr, *n;
  1133. int rc;
  1134. struct list_head flush_queue;
  1135. INIT_LIST_HEAD(&flush_queue);
  1136. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1137. rc = 0;
  1138. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1139. /* Check status and move request to flush_queue */
  1140. switch (cqr->status) {
  1141. case DASD_CQR_IN_IO:
  1142. rc = device->discipline->term_IO(cqr);
  1143. if (rc) {
  1144. /* unable to terminate requeust */
  1145. DEV_MESSAGE(KERN_ERR, device,
  1146. "dasd flush ccw_queue is unable "
  1147. " to terminate request %p",
  1148. cqr);
  1149. /* stop flush processing */
  1150. goto finished;
  1151. }
  1152. break;
  1153. case DASD_CQR_QUEUED:
  1154. cqr->stopclk = get_clock();
  1155. cqr->status = DASD_CQR_CLEARED;
  1156. break;
  1157. default: /* no need to modify the others */
  1158. break;
  1159. }
  1160. list_move_tail(&cqr->devlist, &flush_queue);
  1161. }
  1162. finished:
  1163. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1164. /*
  1165. * After this point all requests must be in state CLEAR_PENDING,
  1166. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1167. * one of the others.
  1168. */
  1169. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1170. wait_event(dasd_flush_wq,
  1171. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1172. /*
  1173. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1174. * and call the callback function of flushed requests
  1175. */
  1176. __dasd_device_process_final_queue(device, &flush_queue);
  1177. return rc;
  1178. }
  1179. /*
  1180. * Acquire the device lock and process queues for the device.
  1181. */
  1182. static void dasd_device_tasklet(struct dasd_device *device)
  1183. {
  1184. struct list_head final_queue;
  1185. atomic_set (&device->tasklet_scheduled, 0);
  1186. INIT_LIST_HEAD(&final_queue);
  1187. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1188. /* Check expire time of first request on the ccw queue. */
  1189. __dasd_device_check_expire(device);
  1190. /* find final requests on ccw queue */
  1191. __dasd_device_process_ccw_queue(device, &final_queue);
  1192. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1193. /* Now call the callback function of requests with final status */
  1194. __dasd_device_process_final_queue(device, &final_queue);
  1195. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1196. /* Now check if the head of the ccw queue needs to be started. */
  1197. __dasd_device_start_head(device);
  1198. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1199. dasd_put_device(device);
  1200. }
  1201. /*
  1202. * Schedules a call to dasd_tasklet over the device tasklet.
  1203. */
  1204. void dasd_schedule_device_bh(struct dasd_device *device)
  1205. {
  1206. /* Protect against rescheduling. */
  1207. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1208. return;
  1209. dasd_get_device(device);
  1210. tasklet_hi_schedule(&device->tasklet);
  1211. }
  1212. /*
  1213. * Queue a request to the head of the device ccw_queue.
  1214. * Start the I/O if possible.
  1215. */
  1216. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1217. {
  1218. struct dasd_device *device;
  1219. unsigned long flags;
  1220. device = cqr->startdev;
  1221. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1222. cqr->status = DASD_CQR_QUEUED;
  1223. list_add(&cqr->devlist, &device->ccw_queue);
  1224. /* let the bh start the request to keep them in order */
  1225. dasd_schedule_device_bh(device);
  1226. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1227. }
  1228. /*
  1229. * Queue a request to the tail of the device ccw_queue.
  1230. * Start the I/O if possible.
  1231. */
  1232. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1233. {
  1234. struct dasd_device *device;
  1235. unsigned long flags;
  1236. device = cqr->startdev;
  1237. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1238. cqr->status = DASD_CQR_QUEUED;
  1239. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1240. /* let the bh start the request to keep them in order */
  1241. dasd_schedule_device_bh(device);
  1242. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1243. }
  1244. /*
  1245. * Wakeup helper for the 'sleep_on' functions.
  1246. */
  1247. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1248. {
  1249. wake_up((wait_queue_head_t *) data);
  1250. }
  1251. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1252. {
  1253. struct dasd_device *device;
  1254. int rc;
  1255. device = cqr->startdev;
  1256. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1257. rc = ((cqr->status == DASD_CQR_DONE ||
  1258. cqr->status == DASD_CQR_NEED_ERP ||
  1259. cqr->status == DASD_CQR_TERMINATED) &&
  1260. list_empty(&cqr->devlist));
  1261. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1262. return rc;
  1263. }
  1264. /*
  1265. * Queue a request to the tail of the device ccw_queue and wait for
  1266. * it's completion.
  1267. */
  1268. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1269. {
  1270. wait_queue_head_t wait_q;
  1271. struct dasd_device *device;
  1272. int rc;
  1273. device = cqr->startdev;
  1274. init_waitqueue_head (&wait_q);
  1275. cqr->callback = dasd_wakeup_cb;
  1276. cqr->callback_data = (void *) &wait_q;
  1277. dasd_add_request_tail(cqr);
  1278. wait_event(wait_q, _wait_for_wakeup(cqr));
  1279. /* Request status is either done or failed. */
  1280. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1281. return rc;
  1282. }
  1283. /*
  1284. * Queue a request to the tail of the device ccw_queue and wait
  1285. * interruptible for it's completion.
  1286. */
  1287. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1288. {
  1289. wait_queue_head_t wait_q;
  1290. struct dasd_device *device;
  1291. int rc;
  1292. device = cqr->startdev;
  1293. init_waitqueue_head (&wait_q);
  1294. cqr->callback = dasd_wakeup_cb;
  1295. cqr->callback_data = (void *) &wait_q;
  1296. dasd_add_request_tail(cqr);
  1297. rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
  1298. if (rc == -ERESTARTSYS) {
  1299. dasd_cancel_req(cqr);
  1300. /* wait (non-interruptible) for final status */
  1301. wait_event(wait_q, _wait_for_wakeup(cqr));
  1302. }
  1303. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1304. return rc;
  1305. }
  1306. /*
  1307. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1308. * for eckd devices) the currently running request has to be terminated
  1309. * and be put back to status queued, before the special request is added
  1310. * to the head of the queue. Then the special request is waited on normally.
  1311. */
  1312. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1313. {
  1314. struct dasd_ccw_req *cqr;
  1315. if (list_empty(&device->ccw_queue))
  1316. return 0;
  1317. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1318. return device->discipline->term_IO(cqr);
  1319. }
  1320. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1321. {
  1322. wait_queue_head_t wait_q;
  1323. struct dasd_device *device;
  1324. int rc;
  1325. device = cqr->startdev;
  1326. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1327. rc = _dasd_term_running_cqr(device);
  1328. if (rc) {
  1329. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1330. return rc;
  1331. }
  1332. init_waitqueue_head (&wait_q);
  1333. cqr->callback = dasd_wakeup_cb;
  1334. cqr->callback_data = (void *) &wait_q;
  1335. cqr->status = DASD_CQR_QUEUED;
  1336. list_add(&cqr->devlist, &device->ccw_queue);
  1337. /* let the bh start the request to keep them in order */
  1338. dasd_schedule_device_bh(device);
  1339. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1340. wait_event(wait_q, _wait_for_wakeup(cqr));
  1341. /* Request status is either done or failed. */
  1342. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1343. return rc;
  1344. }
  1345. /*
  1346. * Cancels a request that was started with dasd_sleep_on_req.
  1347. * This is useful to timeout requests. The request will be
  1348. * terminated if it is currently in i/o.
  1349. * Returns 1 if the request has been terminated.
  1350. * 0 if there was no need to terminate the request (not started yet)
  1351. * negative error code if termination failed
  1352. * Cancellation of a request is an asynchronous operation! The calling
  1353. * function has to wait until the request is properly returned via callback.
  1354. */
  1355. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1356. {
  1357. struct dasd_device *device = cqr->startdev;
  1358. unsigned long flags;
  1359. int rc;
  1360. rc = 0;
  1361. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1362. switch (cqr->status) {
  1363. case DASD_CQR_QUEUED:
  1364. /* request was not started - just set to cleared */
  1365. cqr->status = DASD_CQR_CLEARED;
  1366. break;
  1367. case DASD_CQR_IN_IO:
  1368. /* request in IO - terminate IO and release again */
  1369. rc = device->discipline->term_IO(cqr);
  1370. if (rc) {
  1371. DEV_MESSAGE(KERN_ERR, device,
  1372. "dasd_cancel_req is unable "
  1373. " to terminate request %p, rc = %d",
  1374. cqr, rc);
  1375. } else {
  1376. cqr->stopclk = get_clock();
  1377. rc = 1;
  1378. }
  1379. break;
  1380. default: /* already finished or clear pending - do nothing */
  1381. break;
  1382. }
  1383. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1384. dasd_schedule_device_bh(device);
  1385. return rc;
  1386. }
  1387. /*
  1388. * SECTION: Operations of the dasd_block layer.
  1389. */
  1390. /*
  1391. * Timeout function for dasd_block. This is used when the block layer
  1392. * is waiting for something that may not come reliably, (e.g. a state
  1393. * change interrupt)
  1394. */
  1395. static void dasd_block_timeout(unsigned long ptr)
  1396. {
  1397. unsigned long flags;
  1398. struct dasd_block *block;
  1399. block = (struct dasd_block *) ptr;
  1400. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  1401. /* re-activate request queue */
  1402. block->base->stopped &= ~DASD_STOPPED_PENDING;
  1403. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  1404. dasd_schedule_block_bh(block);
  1405. }
  1406. /*
  1407. * Setup timeout for a dasd_block in jiffies.
  1408. */
  1409. void dasd_block_set_timer(struct dasd_block *block, int expires)
  1410. {
  1411. if (expires == 0) {
  1412. if (timer_pending(&block->timer))
  1413. del_timer(&block->timer);
  1414. return;
  1415. }
  1416. if (timer_pending(&block->timer)) {
  1417. if (mod_timer(&block->timer, jiffies + expires))
  1418. return;
  1419. }
  1420. block->timer.function = dasd_block_timeout;
  1421. block->timer.data = (unsigned long) block;
  1422. block->timer.expires = jiffies + expires;
  1423. add_timer(&block->timer);
  1424. }
  1425. /*
  1426. * Clear timeout for a dasd_block.
  1427. */
  1428. void dasd_block_clear_timer(struct dasd_block *block)
  1429. {
  1430. if (timer_pending(&block->timer))
  1431. del_timer(&block->timer);
  1432. }
  1433. /*
  1434. * posts the buffer_cache about a finalized request
  1435. */
  1436. static inline void dasd_end_request(struct request *req, int error)
  1437. {
  1438. if (__blk_end_request(req, error, blk_rq_bytes(req)))
  1439. BUG();
  1440. }
  1441. /*
  1442. * Process finished error recovery ccw.
  1443. */
  1444. static inline void __dasd_block_process_erp(struct dasd_block *block,
  1445. struct dasd_ccw_req *cqr)
  1446. {
  1447. dasd_erp_fn_t erp_fn;
  1448. struct dasd_device *device = block->base;
  1449. if (cqr->status == DASD_CQR_DONE)
  1450. DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
  1451. else
  1452. DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
  1453. erp_fn = device->discipline->erp_postaction(cqr);
  1454. erp_fn(cqr);
  1455. }
  1456. /*
  1457. * Fetch requests from the block device queue.
  1458. */
  1459. static void __dasd_process_request_queue(struct dasd_block *block)
  1460. {
  1461. struct request_queue *queue;
  1462. struct request *req;
  1463. struct dasd_ccw_req *cqr;
  1464. struct dasd_device *basedev;
  1465. unsigned long flags;
  1466. queue = block->request_queue;
  1467. basedev = block->base;
  1468. /* No queue ? Then there is nothing to do. */
  1469. if (queue == NULL)
  1470. return;
  1471. /*
  1472. * We requeue request from the block device queue to the ccw
  1473. * queue only in two states. In state DASD_STATE_READY the
  1474. * partition detection is done and we need to requeue requests
  1475. * for that. State DASD_STATE_ONLINE is normal block device
  1476. * operation.
  1477. */
  1478. if (basedev->state < DASD_STATE_READY)
  1479. return;
  1480. /* Now we try to fetch requests from the request queue */
  1481. while (!blk_queue_plugged(queue) &&
  1482. elv_next_request(queue)) {
  1483. req = elv_next_request(queue);
  1484. if (basedev->features & DASD_FEATURE_READONLY &&
  1485. rq_data_dir(req) == WRITE) {
  1486. DBF_DEV_EVENT(DBF_ERR, basedev,
  1487. "Rejecting write request %p",
  1488. req);
  1489. blkdev_dequeue_request(req);
  1490. dasd_end_request(req, -EIO);
  1491. continue;
  1492. }
  1493. cqr = basedev->discipline->build_cp(basedev, block, req);
  1494. if (IS_ERR(cqr)) {
  1495. if (PTR_ERR(cqr) == -EBUSY)
  1496. break; /* normal end condition */
  1497. if (PTR_ERR(cqr) == -ENOMEM)
  1498. break; /* terminate request queue loop */
  1499. if (PTR_ERR(cqr) == -EAGAIN) {
  1500. /*
  1501. * The current request cannot be build right
  1502. * now, we have to try later. If this request
  1503. * is the head-of-queue we stop the device
  1504. * for 1/2 second.
  1505. */
  1506. if (!list_empty(&block->ccw_queue))
  1507. break;
  1508. spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
  1509. basedev->stopped |= DASD_STOPPED_PENDING;
  1510. spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
  1511. dasd_block_set_timer(block, HZ/2);
  1512. break;
  1513. }
  1514. DBF_DEV_EVENT(DBF_ERR, basedev,
  1515. "CCW creation failed (rc=%ld) "
  1516. "on request %p",
  1517. PTR_ERR(cqr), req);
  1518. blkdev_dequeue_request(req);
  1519. dasd_end_request(req, -EIO);
  1520. continue;
  1521. }
  1522. /*
  1523. * Note: callback is set to dasd_return_cqr_cb in
  1524. * __dasd_block_start_head to cover erp requests as well
  1525. */
  1526. cqr->callback_data = (void *) req;
  1527. cqr->status = DASD_CQR_FILLED;
  1528. blkdev_dequeue_request(req);
  1529. list_add_tail(&cqr->blocklist, &block->ccw_queue);
  1530. dasd_profile_start(block, cqr, req);
  1531. }
  1532. }
  1533. static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
  1534. {
  1535. struct request *req;
  1536. int status;
  1537. int error = 0;
  1538. req = (struct request *) cqr->callback_data;
  1539. dasd_profile_end(cqr->block, cqr, req);
  1540. status = cqr->block->base->discipline->free_cp(cqr, req);
  1541. if (status <= 0)
  1542. error = status ? status : -EIO;
  1543. dasd_end_request(req, error);
  1544. }
  1545. /*
  1546. * Process ccw request queue.
  1547. */
  1548. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  1549. struct list_head *final_queue)
  1550. {
  1551. struct list_head *l, *n;
  1552. struct dasd_ccw_req *cqr;
  1553. dasd_erp_fn_t erp_fn;
  1554. unsigned long flags;
  1555. struct dasd_device *base = block->base;
  1556. restart:
  1557. /* Process request with final status. */
  1558. list_for_each_safe(l, n, &block->ccw_queue) {
  1559. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1560. if (cqr->status != DASD_CQR_DONE &&
  1561. cqr->status != DASD_CQR_FAILED &&
  1562. cqr->status != DASD_CQR_NEED_ERP &&
  1563. cqr->status != DASD_CQR_TERMINATED)
  1564. continue;
  1565. if (cqr->status == DASD_CQR_TERMINATED) {
  1566. base->discipline->handle_terminated_request(cqr);
  1567. goto restart;
  1568. }
  1569. /* Process requests that may be recovered */
  1570. if (cqr->status == DASD_CQR_NEED_ERP) {
  1571. erp_fn = base->discipline->erp_action(cqr);
  1572. erp_fn(cqr);
  1573. goto restart;
  1574. }
  1575. /* First of all call extended error reporting. */
  1576. if (dasd_eer_enabled(base) &&
  1577. cqr->status == DASD_CQR_FAILED) {
  1578. dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
  1579. /* restart request */
  1580. cqr->status = DASD_CQR_FILLED;
  1581. cqr->retries = 255;
  1582. spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
  1583. base->stopped |= DASD_STOPPED_QUIESCE;
  1584. spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
  1585. flags);
  1586. goto restart;
  1587. }
  1588. /* Process finished ERP request. */
  1589. if (cqr->refers) {
  1590. __dasd_block_process_erp(block, cqr);
  1591. goto restart;
  1592. }
  1593. /* Rechain finished requests to final queue */
  1594. cqr->endclk = get_clock();
  1595. list_move_tail(&cqr->blocklist, final_queue);
  1596. }
  1597. }
  1598. static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
  1599. {
  1600. dasd_schedule_block_bh(cqr->block);
  1601. }
  1602. static void __dasd_block_start_head(struct dasd_block *block)
  1603. {
  1604. struct dasd_ccw_req *cqr;
  1605. if (list_empty(&block->ccw_queue))
  1606. return;
  1607. /* We allways begin with the first requests on the queue, as some
  1608. * of previously started requests have to be enqueued on a
  1609. * dasd_device again for error recovery.
  1610. */
  1611. list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
  1612. if (cqr->status != DASD_CQR_FILLED)
  1613. continue;
  1614. /* Non-temporary stop condition will trigger fail fast */
  1615. if (block->base->stopped & ~DASD_STOPPED_PENDING &&
  1616. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  1617. (!dasd_eer_enabled(block->base))) {
  1618. cqr->status = DASD_CQR_FAILED;
  1619. dasd_schedule_block_bh(block);
  1620. continue;
  1621. }
  1622. /* Don't try to start requests if device is stopped */
  1623. if (block->base->stopped)
  1624. return;
  1625. /* just a fail safe check, should not happen */
  1626. if (!cqr->startdev)
  1627. cqr->startdev = block->base;
  1628. /* make sure that the requests we submit find their way back */
  1629. cqr->callback = dasd_return_cqr_cb;
  1630. dasd_add_request_tail(cqr);
  1631. }
  1632. }
  1633. /*
  1634. * Central dasd_block layer routine. Takes requests from the generic
  1635. * block layer request queue, creates ccw requests, enqueues them on
  1636. * a dasd_device and processes ccw requests that have been returned.
  1637. */
  1638. static void dasd_block_tasklet(struct dasd_block *block)
  1639. {
  1640. struct list_head final_queue;
  1641. struct list_head *l, *n;
  1642. struct dasd_ccw_req *cqr;
  1643. atomic_set(&block->tasklet_scheduled, 0);
  1644. INIT_LIST_HEAD(&final_queue);
  1645. spin_lock(&block->queue_lock);
  1646. /* Finish off requests on ccw queue */
  1647. __dasd_process_block_ccw_queue(block, &final_queue);
  1648. spin_unlock(&block->queue_lock);
  1649. /* Now call the callback function of requests with final status */
  1650. spin_lock_irq(&block->request_queue_lock);
  1651. list_for_each_safe(l, n, &final_queue) {
  1652. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1653. list_del_init(&cqr->blocklist);
  1654. __dasd_cleanup_cqr(cqr);
  1655. }
  1656. spin_lock(&block->queue_lock);
  1657. /* Get new request from the block device request queue */
  1658. __dasd_process_request_queue(block);
  1659. /* Now check if the head of the ccw queue needs to be started. */
  1660. __dasd_block_start_head(block);
  1661. spin_unlock(&block->queue_lock);
  1662. spin_unlock_irq(&block->request_queue_lock);
  1663. dasd_put_device(block->base);
  1664. }
  1665. static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
  1666. {
  1667. wake_up(&dasd_flush_wq);
  1668. }
  1669. /*
  1670. * Go through all request on the dasd_block request queue, cancel them
  1671. * on the respective dasd_device, and return them to the generic
  1672. * block layer.
  1673. */
  1674. static int dasd_flush_block_queue(struct dasd_block *block)
  1675. {
  1676. struct dasd_ccw_req *cqr, *n;
  1677. int rc, i;
  1678. struct list_head flush_queue;
  1679. INIT_LIST_HEAD(&flush_queue);
  1680. spin_lock_bh(&block->queue_lock);
  1681. rc = 0;
  1682. restart:
  1683. list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
  1684. /* if this request currently owned by a dasd_device cancel it */
  1685. if (cqr->status >= DASD_CQR_QUEUED)
  1686. rc = dasd_cancel_req(cqr);
  1687. if (rc < 0)
  1688. break;
  1689. /* Rechain request (including erp chain) so it won't be
  1690. * touched by the dasd_block_tasklet anymore.
  1691. * Replace the callback so we notice when the request
  1692. * is returned from the dasd_device layer.
  1693. */
  1694. cqr->callback = _dasd_wake_block_flush_cb;
  1695. for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
  1696. list_move_tail(&cqr->blocklist, &flush_queue);
  1697. if (i > 1)
  1698. /* moved more than one request - need to restart */
  1699. goto restart;
  1700. }
  1701. spin_unlock_bh(&block->queue_lock);
  1702. /* Now call the callback function of flushed requests */
  1703. restart_cb:
  1704. list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
  1705. wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
  1706. /* Process finished ERP request. */
  1707. if (cqr->refers) {
  1708. __dasd_block_process_erp(block, cqr);
  1709. /* restart list_for_xx loop since dasd_process_erp
  1710. * might remove multiple elements */
  1711. goto restart_cb;
  1712. }
  1713. /* call the callback function */
  1714. cqr->endclk = get_clock();
  1715. list_del_init(&cqr->blocklist);
  1716. __dasd_cleanup_cqr(cqr);
  1717. }
  1718. return rc;
  1719. }
  1720. /*
  1721. * Schedules a call to dasd_tasklet over the device tasklet.
  1722. */
  1723. void dasd_schedule_block_bh(struct dasd_block *block)
  1724. {
  1725. /* Protect against rescheduling. */
  1726. if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
  1727. return;
  1728. /* life cycle of block is bound to it's base device */
  1729. dasd_get_device(block->base);
  1730. tasklet_hi_schedule(&block->tasklet);
  1731. }
  1732. /*
  1733. * SECTION: external block device operations
  1734. * (request queue handling, open, release, etc.)
  1735. */
  1736. /*
  1737. * Dasd request queue function. Called from ll_rw_blk.c
  1738. */
  1739. static void do_dasd_request(struct request_queue *queue)
  1740. {
  1741. struct dasd_block *block;
  1742. block = queue->queuedata;
  1743. spin_lock(&block->queue_lock);
  1744. /* Get new request from the block device request queue */
  1745. __dasd_process_request_queue(block);
  1746. /* Now check if the head of the ccw queue needs to be started. */
  1747. __dasd_block_start_head(block);
  1748. spin_unlock(&block->queue_lock);
  1749. }
  1750. /*
  1751. * Allocate and initialize request queue and default I/O scheduler.
  1752. */
  1753. static int dasd_alloc_queue(struct dasd_block *block)
  1754. {
  1755. int rc;
  1756. block->request_queue = blk_init_queue(do_dasd_request,
  1757. &block->request_queue_lock);
  1758. if (block->request_queue == NULL)
  1759. return -ENOMEM;
  1760. block->request_queue->queuedata = block;
  1761. elevator_exit(block->request_queue->elevator);
  1762. rc = elevator_init(block->request_queue, "deadline");
  1763. if (rc) {
  1764. blk_cleanup_queue(block->request_queue);
  1765. return rc;
  1766. }
  1767. return 0;
  1768. }
  1769. /*
  1770. * Allocate and initialize request queue.
  1771. */
  1772. static void dasd_setup_queue(struct dasd_block *block)
  1773. {
  1774. int max;
  1775. blk_queue_hardsect_size(block->request_queue, block->bp_block);
  1776. max = block->base->discipline->max_blocks << block->s2b_shift;
  1777. blk_queue_max_sectors(block->request_queue, max);
  1778. blk_queue_max_phys_segments(block->request_queue, -1L);
  1779. blk_queue_max_hw_segments(block->request_queue, -1L);
  1780. blk_queue_max_segment_size(block->request_queue, -1L);
  1781. blk_queue_segment_boundary(block->request_queue, -1L);
  1782. blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL);
  1783. }
  1784. /*
  1785. * Deactivate and free request queue.
  1786. */
  1787. static void dasd_free_queue(struct dasd_block *block)
  1788. {
  1789. if (block->request_queue) {
  1790. blk_cleanup_queue(block->request_queue);
  1791. block->request_queue = NULL;
  1792. }
  1793. }
  1794. /*
  1795. * Flush request on the request queue.
  1796. */
  1797. static void dasd_flush_request_queue(struct dasd_block *block)
  1798. {
  1799. struct request *req;
  1800. if (!block->request_queue)
  1801. return;
  1802. spin_lock_irq(&block->request_queue_lock);
  1803. while ((req = elv_next_request(block->request_queue))) {
  1804. blkdev_dequeue_request(req);
  1805. dasd_end_request(req, -EIO);
  1806. }
  1807. spin_unlock_irq(&block->request_queue_lock);
  1808. }
  1809. static int dasd_open(struct inode *inp, struct file *filp)
  1810. {
  1811. struct gendisk *disk = inp->i_bdev->bd_disk;
  1812. struct dasd_block *block = disk->private_data;
  1813. struct dasd_device *base = block->base;
  1814. int rc;
  1815. atomic_inc(&block->open_count);
  1816. if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
  1817. rc = -ENODEV;
  1818. goto unlock;
  1819. }
  1820. if (!try_module_get(base->discipline->owner)) {
  1821. rc = -EINVAL;
  1822. goto unlock;
  1823. }
  1824. if (dasd_probeonly) {
  1825. DEV_MESSAGE(KERN_INFO, base, "%s",
  1826. "No access to device due to probeonly mode");
  1827. rc = -EPERM;
  1828. goto out;
  1829. }
  1830. if (base->state <= DASD_STATE_BASIC) {
  1831. DBF_DEV_EVENT(DBF_ERR, base, " %s",
  1832. " Cannot open unrecognized device");
  1833. rc = -ENODEV;
  1834. goto out;
  1835. }
  1836. return 0;
  1837. out:
  1838. module_put(base->discipline->owner);
  1839. unlock:
  1840. atomic_dec(&block->open_count);
  1841. return rc;
  1842. }
  1843. static int dasd_release(struct inode *inp, struct file *filp)
  1844. {
  1845. struct gendisk *disk = inp->i_bdev->bd_disk;
  1846. struct dasd_block *block = disk->private_data;
  1847. atomic_dec(&block->open_count);
  1848. module_put(block->base->discipline->owner);
  1849. return 0;
  1850. }
  1851. /*
  1852. * Return disk geometry.
  1853. */
  1854. static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  1855. {
  1856. struct dasd_block *block;
  1857. struct dasd_device *base;
  1858. block = bdev->bd_disk->private_data;
  1859. base = block->base;
  1860. if (!block)
  1861. return -ENODEV;
  1862. if (!base->discipline ||
  1863. !base->discipline->fill_geometry)
  1864. return -EINVAL;
  1865. base->discipline->fill_geometry(block, geo);
  1866. geo->start = get_start_sect(bdev) >> block->s2b_shift;
  1867. return 0;
  1868. }
  1869. struct block_device_operations
  1870. dasd_device_operations = {
  1871. .owner = THIS_MODULE,
  1872. .open = dasd_open,
  1873. .release = dasd_release,
  1874. .ioctl = dasd_ioctl,
  1875. .compat_ioctl = dasd_compat_ioctl,
  1876. .getgeo = dasd_getgeo,
  1877. };
  1878. /*******************************************************************************
  1879. * end of block device operations
  1880. */
  1881. static void
  1882. dasd_exit(void)
  1883. {
  1884. #ifdef CONFIG_PROC_FS
  1885. dasd_proc_exit();
  1886. #endif
  1887. dasd_eer_exit();
  1888. if (dasd_page_cache != NULL) {
  1889. kmem_cache_destroy(dasd_page_cache);
  1890. dasd_page_cache = NULL;
  1891. }
  1892. dasd_gendisk_exit();
  1893. dasd_devmap_exit();
  1894. if (dasd_debug_area != NULL) {
  1895. debug_unregister(dasd_debug_area);
  1896. dasd_debug_area = NULL;
  1897. }
  1898. }
  1899. /*
  1900. * SECTION: common functions for ccw_driver use
  1901. */
  1902. /*
  1903. * Initial attempt at a probe function. this can be simplified once
  1904. * the other detection code is gone.
  1905. */
  1906. int dasd_generic_probe(struct ccw_device *cdev,
  1907. struct dasd_discipline *discipline)
  1908. {
  1909. int ret;
  1910. ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
  1911. if (ret) {
  1912. printk(KERN_WARNING
  1913. "dasd_generic_probe: could not set ccw-device options "
  1914. "for %s\n", cdev->dev.bus_id);
  1915. return ret;
  1916. }
  1917. ret = dasd_add_sysfs_files(cdev);
  1918. if (ret) {
  1919. printk(KERN_WARNING
  1920. "dasd_generic_probe: could not add sysfs entries "
  1921. "for %s\n", cdev->dev.bus_id);
  1922. return ret;
  1923. }
  1924. cdev->handler = &dasd_int_handler;
  1925. /*
  1926. * Automatically online either all dasd devices (dasd_autodetect)
  1927. * or all devices specified with dasd= parameters during
  1928. * initial probe.
  1929. */
  1930. if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
  1931. (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
  1932. ret = ccw_device_set_online(cdev);
  1933. if (ret)
  1934. printk(KERN_WARNING
  1935. "dasd_generic_probe: could not initially "
  1936. "online ccw-device %s; return code: %d\n",
  1937. cdev->dev.bus_id, ret);
  1938. return 0;
  1939. }
  1940. /*
  1941. * This will one day be called from a global not_oper handler.
  1942. * It is also used by driver_unregister during module unload.
  1943. */
  1944. void dasd_generic_remove(struct ccw_device *cdev)
  1945. {
  1946. struct dasd_device *device;
  1947. struct dasd_block *block;
  1948. cdev->handler = NULL;
  1949. dasd_remove_sysfs_files(cdev);
  1950. device = dasd_device_from_cdev(cdev);
  1951. if (IS_ERR(device))
  1952. return;
  1953. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  1954. /* Already doing offline processing */
  1955. dasd_put_device(device);
  1956. return;
  1957. }
  1958. /*
  1959. * This device is removed unconditionally. Set offline
  1960. * flag to prevent dasd_open from opening it while it is
  1961. * no quite down yet.
  1962. */
  1963. dasd_set_target_state(device, DASD_STATE_NEW);
  1964. /* dasd_delete_device destroys the device reference. */
  1965. block = device->block;
  1966. device->block = NULL;
  1967. dasd_delete_device(device);
  1968. /*
  1969. * life cycle of block is bound to device, so delete it after
  1970. * device was safely removed
  1971. */
  1972. if (block)
  1973. dasd_free_block(block);
  1974. }
  1975. /*
  1976. * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
  1977. * the device is detected for the first time and is supposed to be used
  1978. * or the user has started activation through sysfs.
  1979. */
  1980. int dasd_generic_set_online(struct ccw_device *cdev,
  1981. struct dasd_discipline *base_discipline)
  1982. {
  1983. struct dasd_discipline *discipline;
  1984. struct dasd_device *device;
  1985. int rc;
  1986. /* first online clears initial online feature flag */
  1987. dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
  1988. device = dasd_create_device(cdev);
  1989. if (IS_ERR(device))
  1990. return PTR_ERR(device);
  1991. discipline = base_discipline;
  1992. if (device->features & DASD_FEATURE_USEDIAG) {
  1993. if (!dasd_diag_discipline_pointer) {
  1994. printk (KERN_WARNING
  1995. "dasd_generic couldn't online device %s "
  1996. "- discipline DIAG not available\n",
  1997. cdev->dev.bus_id);
  1998. dasd_delete_device(device);
  1999. return -ENODEV;
  2000. }
  2001. discipline = dasd_diag_discipline_pointer;
  2002. }
  2003. if (!try_module_get(base_discipline->owner)) {
  2004. dasd_delete_device(device);
  2005. return -EINVAL;
  2006. }
  2007. if (!try_module_get(discipline->owner)) {
  2008. module_put(base_discipline->owner);
  2009. dasd_delete_device(device);
  2010. return -EINVAL;
  2011. }
  2012. device->base_discipline = base_discipline;
  2013. device->discipline = discipline;
  2014. /* check_device will allocate block device if necessary */
  2015. rc = discipline->check_device(device);
  2016. if (rc) {
  2017. printk (KERN_WARNING
  2018. "dasd_generic couldn't online device %s "
  2019. "with discipline %s rc=%i\n",
  2020. cdev->dev.bus_id, discipline->name, rc);
  2021. module_put(discipline->owner);
  2022. module_put(base_discipline->owner);
  2023. dasd_delete_device(device);
  2024. return rc;
  2025. }
  2026. dasd_set_target_state(device, DASD_STATE_ONLINE);
  2027. if (device->state <= DASD_STATE_KNOWN) {
  2028. printk (KERN_WARNING
  2029. "dasd_generic discipline not found for %s\n",
  2030. cdev->dev.bus_id);
  2031. rc = -ENODEV;
  2032. dasd_set_target_state(device, DASD_STATE_NEW);
  2033. if (device->block)
  2034. dasd_free_block(device->block);
  2035. dasd_delete_device(device);
  2036. } else
  2037. pr_debug("dasd_generic device %s found\n",
  2038. cdev->dev.bus_id);
  2039. /* FIXME: we have to wait for the root device but we don't want
  2040. * to wait for each single device but for all at once. */
  2041. wait_event(dasd_init_waitq, _wait_for_device(device));
  2042. dasd_put_device(device);
  2043. return rc;
  2044. }
  2045. int dasd_generic_set_offline(struct ccw_device *cdev)
  2046. {
  2047. struct dasd_device *device;
  2048. struct dasd_block *block;
  2049. int max_count, open_count;
  2050. device = dasd_device_from_cdev(cdev);
  2051. if (IS_ERR(device))
  2052. return PTR_ERR(device);
  2053. if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2054. /* Already doing offline processing */
  2055. dasd_put_device(device);
  2056. return 0;
  2057. }
  2058. /*
  2059. * We must make sure that this device is currently not in use.
  2060. * The open_count is increased for every opener, that includes
  2061. * the blkdev_get in dasd_scan_partitions. We are only interested
  2062. * in the other openers.
  2063. */
  2064. if (device->block) {
  2065. struct dasd_block *block = device->block;
  2066. max_count = block->bdev ? 0 : -1;
  2067. open_count = (int) atomic_read(&block->open_count);
  2068. if (open_count > max_count) {
  2069. if (open_count > 0)
  2070. printk(KERN_WARNING "Can't offline dasd "
  2071. "device with open count = %i.\n",
  2072. open_count);
  2073. else
  2074. printk(KERN_WARNING "%s",
  2075. "Can't offline dasd device due "
  2076. "to internal use\n");
  2077. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  2078. dasd_put_device(device);
  2079. return -EBUSY;
  2080. }
  2081. }
  2082. dasd_set_target_state(device, DASD_STATE_NEW);
  2083. /* dasd_delete_device destroys the device reference. */
  2084. block = device->block;
  2085. device->block = NULL;
  2086. dasd_delete_device(device);
  2087. /*
  2088. * life cycle of block is bound to device, so delete it after
  2089. * device was safely removed
  2090. */
  2091. if (block)
  2092. dasd_free_block(block);
  2093. return 0;
  2094. }
  2095. int dasd_generic_notify(struct ccw_device *cdev, int event)
  2096. {
  2097. struct dasd_device *device;
  2098. struct dasd_ccw_req *cqr;
  2099. unsigned long flags;
  2100. int ret;
  2101. device = dasd_device_from_cdev(cdev);
  2102. if (IS_ERR(device))
  2103. return 0;
  2104. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  2105. ret = 0;
  2106. switch (event) {
  2107. case CIO_GONE:
  2108. case CIO_NO_PATH:
  2109. /* First of all call extended error reporting. */
  2110. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  2111. if (device->state < DASD_STATE_BASIC)
  2112. break;
  2113. /* Device is active. We want to keep it. */
  2114. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  2115. if (cqr->status == DASD_CQR_IN_IO) {
  2116. cqr->status = DASD_CQR_QUEUED;
  2117. cqr->retries++;
  2118. }
  2119. device->stopped |= DASD_STOPPED_DC_WAIT;
  2120. dasd_device_clear_timer(device);
  2121. dasd_schedule_device_bh(device);
  2122. ret = 1;
  2123. break;
  2124. case CIO_OPER:
  2125. /* FIXME: add a sanity check. */
  2126. device->stopped &= ~DASD_STOPPED_DC_WAIT;
  2127. dasd_schedule_device_bh(device);
  2128. if (device->block)
  2129. dasd_schedule_block_bh(device->block);
  2130. ret = 1;
  2131. break;
  2132. }
  2133. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  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. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2183. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2184. if (dasd_debug_area == NULL) {
  2185. rc = -ENOMEM;
  2186. goto failed;
  2187. }
  2188. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2189. debug_set_level(dasd_debug_area, DBF_WARNING);
  2190. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2191. dasd_diag_discipline_pointer = NULL;
  2192. rc = dasd_devmap_init();
  2193. if (rc)
  2194. goto failed;
  2195. rc = dasd_gendisk_init();
  2196. if (rc)
  2197. goto failed;
  2198. rc = dasd_parse();
  2199. if (rc)
  2200. goto failed;
  2201. rc = dasd_eer_init();
  2202. if (rc)
  2203. goto failed;
  2204. #ifdef CONFIG_PROC_FS
  2205. rc = dasd_proc_init();
  2206. if (rc)
  2207. goto failed;
  2208. #endif
  2209. return 0;
  2210. failed:
  2211. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2212. dasd_exit();
  2213. return rc;
  2214. }
  2215. module_init(dasd_init);
  2216. module_exit(dasd_exit);
  2217. EXPORT_SYMBOL(dasd_debug_area);
  2218. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2219. EXPORT_SYMBOL(dasd_add_request_head);
  2220. EXPORT_SYMBOL(dasd_add_request_tail);
  2221. EXPORT_SYMBOL(dasd_cancel_req);
  2222. EXPORT_SYMBOL(dasd_device_clear_timer);
  2223. EXPORT_SYMBOL(dasd_block_clear_timer);
  2224. EXPORT_SYMBOL(dasd_enable_device);
  2225. EXPORT_SYMBOL(dasd_int_handler);
  2226. EXPORT_SYMBOL(dasd_kfree_request);
  2227. EXPORT_SYMBOL(dasd_kick_device);
  2228. EXPORT_SYMBOL(dasd_kmalloc_request);
  2229. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2230. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2231. EXPORT_SYMBOL(dasd_set_target_state);
  2232. EXPORT_SYMBOL(dasd_device_set_timer);
  2233. EXPORT_SYMBOL(dasd_block_set_timer);
  2234. EXPORT_SYMBOL(dasd_sfree_request);
  2235. EXPORT_SYMBOL(dasd_sleep_on);
  2236. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2237. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2238. EXPORT_SYMBOL(dasd_smalloc_request);
  2239. EXPORT_SYMBOL(dasd_start_IO);
  2240. EXPORT_SYMBOL(dasd_term_IO);
  2241. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2242. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2243. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2244. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2245. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2246. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2247. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2248. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2249. EXPORT_SYMBOL_GPL(dasd_free_block);