dasd.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
  9. *
  10. */
  11. #include <linux/kmod.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/ctype.h>
  15. #include <linux/major.h>
  16. #include <linux/slab.h>
  17. #include <linux/buffer_head.h>
  18. #include <linux/hdreg.h>
  19. #include <asm/ccwdev.h>
  20. #include <asm/ebcdic.h>
  21. #include <asm/idals.h>
  22. #include <asm/todclk.h>
  23. /* This is ugly... */
  24. #define PRINTK_HEADER "dasd:"
  25. #include "dasd_int.h"
  26. /*
  27. * SECTION: Constant definitions to be used within this file
  28. */
  29. #define DASD_CHANQ_MAX_SIZE 4
  30. /*
  31. * SECTION: exported variables of dasd.c
  32. */
  33. debug_info_t *dasd_debug_area;
  34. struct dasd_discipline *dasd_diag_discipline_pointer;
  35. void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
  36. MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
  37. MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
  38. " Copyright 2000 IBM Corporation");
  39. MODULE_SUPPORTED_DEVICE("dasd");
  40. MODULE_LICENSE("GPL");
  41. /*
  42. * SECTION: prototypes for static functions of dasd.c
  43. */
  44. static int dasd_alloc_queue(struct dasd_block *);
  45. static void dasd_setup_queue(struct dasd_block *);
  46. static void dasd_free_queue(struct dasd_block *);
  47. static void dasd_flush_request_queue(struct dasd_block *);
  48. static int dasd_flush_block_queue(struct dasd_block *);
  49. static void dasd_device_tasklet(struct dasd_device *);
  50. static void dasd_block_tasklet(struct dasd_block *);
  51. static void do_kick_device(struct work_struct *);
  52. static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
  53. /*
  54. * SECTION: Operations on the device structure.
  55. */
  56. static wait_queue_head_t dasd_init_waitq;
  57. static wait_queue_head_t dasd_flush_wq;
  58. static wait_queue_head_t generic_waitq;
  59. /*
  60. * Allocate memory for a new device structure.
  61. */
  62. struct dasd_device *dasd_alloc_device(void)
  63. {
  64. struct dasd_device *device;
  65. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  66. if (!device)
  67. return ERR_PTR(-ENOMEM);
  68. /* Get two pages for normal block device operations. */
  69. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  70. if (!device->ccw_mem) {
  71. kfree(device);
  72. return ERR_PTR(-ENOMEM);
  73. }
  74. /* Get one page for error recovery. */
  75. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  76. if (!device->erp_mem) {
  77. free_pages((unsigned long) device->ccw_mem, 1);
  78. kfree(device);
  79. return ERR_PTR(-ENOMEM);
  80. }
  81. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  82. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  83. spin_lock_init(&device->mem_lock);
  84. atomic_set(&device->tasklet_scheduled, 0);
  85. tasklet_init(&device->tasklet,
  86. (void (*)(unsigned long)) dasd_device_tasklet,
  87. (unsigned long) device);
  88. INIT_LIST_HEAD(&device->ccw_queue);
  89. init_timer(&device->timer);
  90. INIT_WORK(&device->kick_work, do_kick_device);
  91. device->state = DASD_STATE_NEW;
  92. device->target = DASD_STATE_NEW;
  93. return device;
  94. }
  95. /*
  96. * Free memory of a device structure.
  97. */
  98. void dasd_free_device(struct dasd_device *device)
  99. {
  100. kfree(device->private);
  101. free_page((unsigned long) device->erp_mem);
  102. free_pages((unsigned long) device->ccw_mem, 1);
  103. kfree(device);
  104. }
  105. /*
  106. * Allocate memory for a new device structure.
  107. */
  108. struct dasd_block *dasd_alloc_block(void)
  109. {
  110. struct dasd_block *block;
  111. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  112. if (!block)
  113. return ERR_PTR(-ENOMEM);
  114. /* open_count = 0 means device online but not in use */
  115. atomic_set(&block->open_count, -1);
  116. spin_lock_init(&block->request_queue_lock);
  117. atomic_set(&block->tasklet_scheduled, 0);
  118. tasklet_init(&block->tasklet,
  119. (void (*)(unsigned long)) dasd_block_tasklet,
  120. (unsigned long) block);
  121. INIT_LIST_HEAD(&block->ccw_queue);
  122. spin_lock_init(&block->queue_lock);
  123. init_timer(&block->timer);
  124. return block;
  125. }
  126. /*
  127. * Free memory of a device structure.
  128. */
  129. void dasd_free_block(struct dasd_block *block)
  130. {
  131. kfree(block);
  132. }
  133. /*
  134. * Make a new device known to the system.
  135. */
  136. static int dasd_state_new_to_known(struct dasd_device *device)
  137. {
  138. int rc;
  139. /*
  140. * As long as the device is not in state DASD_STATE_NEW we want to
  141. * keep the reference count > 0.
  142. */
  143. dasd_get_device(device);
  144. if (device->block) {
  145. rc = dasd_alloc_queue(device->block);
  146. if (rc) {
  147. dasd_put_device(device);
  148. return rc;
  149. }
  150. }
  151. device->state = DASD_STATE_KNOWN;
  152. return 0;
  153. }
  154. /*
  155. * Let the system forget about a device.
  156. */
  157. static int dasd_state_known_to_new(struct dasd_device *device)
  158. {
  159. /* Disable extended error reporting for this device. */
  160. dasd_eer_disable(device);
  161. /* Forget the discipline information. */
  162. if (device->discipline) {
  163. if (device->discipline->uncheck_device)
  164. device->discipline->uncheck_device(device);
  165. module_put(device->discipline->owner);
  166. }
  167. device->discipline = NULL;
  168. if (device->base_discipline)
  169. module_put(device->base_discipline->owner);
  170. device->base_discipline = NULL;
  171. device->state = DASD_STATE_NEW;
  172. if (device->block)
  173. dasd_free_queue(device->block);
  174. /* Give up reference we took in dasd_state_new_to_known. */
  175. dasd_put_device(device);
  176. return 0;
  177. }
  178. /*
  179. * Request the irq line for the device.
  180. */
  181. static int dasd_state_known_to_basic(struct dasd_device *device)
  182. {
  183. int rc;
  184. /* Allocate and register gendisk structure. */
  185. if (device->block) {
  186. rc = dasd_gendisk_alloc(device->block);
  187. if (rc)
  188. return rc;
  189. }
  190. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  191. device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 1,
  192. 8 * sizeof(long));
  193. debug_register_view(device->debug_area, &debug_sprintf_view);
  194. debug_set_level(device->debug_area, DBF_WARNING);
  195. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  196. device->state = DASD_STATE_BASIC;
  197. return 0;
  198. }
  199. /*
  200. * Release the irq line for the device. Terminate any running i/o.
  201. */
  202. static int dasd_state_basic_to_known(struct dasd_device *device)
  203. {
  204. int rc;
  205. if (device->block) {
  206. dasd_gendisk_free(device->block);
  207. dasd_block_clear_timer(device->block);
  208. }
  209. rc = dasd_flush_device_queue(device);
  210. if (rc)
  211. return rc;
  212. dasd_device_clear_timer(device);
  213. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  214. if (device->debug_area != NULL) {
  215. debug_unregister(device->debug_area);
  216. device->debug_area = NULL;
  217. }
  218. device->state = DASD_STATE_KNOWN;
  219. return 0;
  220. }
  221. /*
  222. * Do the initial analysis. The do_analysis function may return
  223. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  224. * until the discipline decides to continue the startup sequence
  225. * by calling the function dasd_change_state. The eckd disciplines
  226. * uses this to start a ccw that detects the format. The completion
  227. * interrupt for this detection ccw uses the kernel event daemon to
  228. * trigger the call to dasd_change_state. All this is done in the
  229. * discipline code, see dasd_eckd.c.
  230. * After the analysis ccw is done (do_analysis returned 0) the block
  231. * device is setup.
  232. * In case the analysis returns an error, the device setup is stopped
  233. * (a fake disk was already added to allow formatting).
  234. */
  235. static int dasd_state_basic_to_ready(struct dasd_device *device)
  236. {
  237. int rc;
  238. struct dasd_block *block;
  239. rc = 0;
  240. block = device->block;
  241. /* make disk known with correct capacity */
  242. if (block) {
  243. if (block->base->discipline->do_analysis != NULL)
  244. rc = block->base->discipline->do_analysis(block);
  245. if (rc) {
  246. if (rc != -EAGAIN)
  247. device->state = DASD_STATE_UNFMT;
  248. return rc;
  249. }
  250. dasd_setup_queue(block);
  251. set_capacity(block->gdp,
  252. block->blocks << block->s2b_shift);
  253. device->state = DASD_STATE_READY;
  254. rc = dasd_scan_partitions(block);
  255. if (rc)
  256. device->state = DASD_STATE_BASIC;
  257. } else {
  258. device->state = DASD_STATE_READY;
  259. }
  260. return rc;
  261. }
  262. /*
  263. * Remove device from block device layer. Destroy dirty buffers.
  264. * Forget format information. Check if the target level is basic
  265. * and if it is create fake disk for formatting.
  266. */
  267. static int dasd_state_ready_to_basic(struct dasd_device *device)
  268. {
  269. int rc;
  270. device->state = DASD_STATE_BASIC;
  271. if (device->block) {
  272. struct dasd_block *block = device->block;
  273. rc = dasd_flush_block_queue(block);
  274. if (rc) {
  275. device->state = DASD_STATE_READY;
  276. return rc;
  277. }
  278. dasd_destroy_partitions(block);
  279. dasd_flush_request_queue(block);
  280. block->blocks = 0;
  281. block->bp_block = 0;
  282. block->s2b_shift = 0;
  283. }
  284. return 0;
  285. }
  286. /*
  287. * Back to basic.
  288. */
  289. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  290. {
  291. device->state = DASD_STATE_BASIC;
  292. return 0;
  293. }
  294. /*
  295. * Make the device online and schedule the bottom half to start
  296. * the requeueing of requests from the linux request queue to the
  297. * ccw queue.
  298. */
  299. static int
  300. dasd_state_ready_to_online(struct dasd_device * device)
  301. {
  302. int rc;
  303. if (device->discipline->ready_to_online) {
  304. rc = device->discipline->ready_to_online(device);
  305. if (rc)
  306. return rc;
  307. }
  308. device->state = DASD_STATE_ONLINE;
  309. if (device->block)
  310. dasd_schedule_block_bh(device->block);
  311. return 0;
  312. }
  313. /*
  314. * Stop the requeueing of requests again.
  315. */
  316. static int dasd_state_online_to_ready(struct dasd_device *device)
  317. {
  318. int rc;
  319. if (device->discipline->online_to_ready) {
  320. rc = device->discipline->online_to_ready(device);
  321. if (rc)
  322. return rc;
  323. }
  324. device->state = DASD_STATE_READY;
  325. return 0;
  326. }
  327. /*
  328. * Device startup state changes.
  329. */
  330. static int dasd_increase_state(struct dasd_device *device)
  331. {
  332. int rc;
  333. rc = 0;
  334. if (device->state == DASD_STATE_NEW &&
  335. device->target >= DASD_STATE_KNOWN)
  336. rc = dasd_state_new_to_known(device);
  337. if (!rc &&
  338. device->state == DASD_STATE_KNOWN &&
  339. device->target >= DASD_STATE_BASIC)
  340. rc = dasd_state_known_to_basic(device);
  341. if (!rc &&
  342. device->state == DASD_STATE_BASIC &&
  343. device->target >= DASD_STATE_READY)
  344. rc = dasd_state_basic_to_ready(device);
  345. if (!rc &&
  346. device->state == DASD_STATE_UNFMT &&
  347. device->target > DASD_STATE_UNFMT)
  348. rc = -EPERM;
  349. if (!rc &&
  350. device->state == DASD_STATE_READY &&
  351. device->target >= DASD_STATE_ONLINE)
  352. rc = dasd_state_ready_to_online(device);
  353. return rc;
  354. }
  355. /*
  356. * Device shutdown state changes.
  357. */
  358. static int dasd_decrease_state(struct dasd_device *device)
  359. {
  360. int rc;
  361. rc = 0;
  362. if (device->state == DASD_STATE_ONLINE &&
  363. device->target <= DASD_STATE_READY)
  364. rc = dasd_state_online_to_ready(device);
  365. if (!rc &&
  366. device->state == DASD_STATE_READY &&
  367. device->target <= DASD_STATE_BASIC)
  368. rc = dasd_state_ready_to_basic(device);
  369. if (!rc &&
  370. device->state == DASD_STATE_UNFMT &&
  371. device->target <= DASD_STATE_BASIC)
  372. rc = dasd_state_unfmt_to_basic(device);
  373. if (!rc &&
  374. device->state == DASD_STATE_BASIC &&
  375. device->target <= DASD_STATE_KNOWN)
  376. rc = dasd_state_basic_to_known(device);
  377. if (!rc &&
  378. device->state == DASD_STATE_KNOWN &&
  379. device->target <= DASD_STATE_NEW)
  380. rc = dasd_state_known_to_new(device);
  381. return rc;
  382. }
  383. /*
  384. * This is the main startup/shutdown routine.
  385. */
  386. static void dasd_change_state(struct dasd_device *device)
  387. {
  388. int rc;
  389. if (device->state == device->target)
  390. /* Already where we want to go today... */
  391. return;
  392. if (device->state < device->target)
  393. rc = dasd_increase_state(device);
  394. else
  395. rc = dasd_decrease_state(device);
  396. if (rc && rc != -EAGAIN)
  397. device->target = device->state;
  398. if (device->state == device->target)
  399. wake_up(&dasd_init_waitq);
  400. /* let user-space know that the device status changed */
  401. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  402. }
  403. /*
  404. * Kick starter for devices that did not complete the startup/shutdown
  405. * procedure or were sleeping because of a pending state.
  406. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  407. * event daemon.
  408. */
  409. static void do_kick_device(struct work_struct *work)
  410. {
  411. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  412. dasd_change_state(device);
  413. dasd_schedule_device_bh(device);
  414. dasd_put_device(device);
  415. }
  416. void dasd_kick_device(struct dasd_device *device)
  417. {
  418. dasd_get_device(device);
  419. /* queue call to dasd_kick_device to the kernel event daemon. */
  420. schedule_work(&device->kick_work);
  421. }
  422. /*
  423. * Set the target state for a device and starts the state change.
  424. */
  425. void dasd_set_target_state(struct dasd_device *device, int target)
  426. {
  427. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  428. if (dasd_probeonly && target > DASD_STATE_READY)
  429. target = DASD_STATE_READY;
  430. if (device->target != target) {
  431. if (device->state == target)
  432. wake_up(&dasd_init_waitq);
  433. device->target = target;
  434. }
  435. if (device->state != device->target)
  436. dasd_change_state(device);
  437. }
  438. /*
  439. * Enable devices with device numbers in [from..to].
  440. */
  441. static inline int _wait_for_device(struct dasd_device *device)
  442. {
  443. return (device->state == device->target);
  444. }
  445. void dasd_enable_device(struct dasd_device *device)
  446. {
  447. dasd_set_target_state(device, DASD_STATE_ONLINE);
  448. if (device->state <= DASD_STATE_KNOWN)
  449. /* No discipline for device found. */
  450. dasd_set_target_state(device, DASD_STATE_NEW);
  451. /* Now wait for the devices to come up. */
  452. wait_event(dasd_init_waitq, _wait_for_device(device));
  453. }
  454. /*
  455. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  456. */
  457. #ifdef CONFIG_DASD_PROFILE
  458. struct dasd_profile_info_t dasd_global_profile;
  459. unsigned int dasd_profile_level = DASD_PROFILE_OFF;
  460. /*
  461. * Increments counter in global and local profiling structures.
  462. */
  463. #define dasd_profile_counter(value, counter, block) \
  464. { \
  465. int index; \
  466. for (index = 0; index < 31 && value >> (2+index); index++); \
  467. dasd_global_profile.counter[index]++; \
  468. block->profile.counter[index]++; \
  469. }
  470. /*
  471. * Add profiling information for cqr before execution.
  472. */
  473. static void dasd_profile_start(struct dasd_block *block,
  474. struct dasd_ccw_req *cqr,
  475. struct request *req)
  476. {
  477. struct list_head *l;
  478. unsigned int counter;
  479. if (dasd_profile_level != DASD_PROFILE_ON)
  480. return;
  481. /* count the length of the chanq for statistics */
  482. counter = 0;
  483. list_for_each(l, &block->ccw_queue)
  484. if (++counter >= 31)
  485. break;
  486. dasd_global_profile.dasd_io_nr_req[counter]++;
  487. block->profile.dasd_io_nr_req[counter]++;
  488. }
  489. /*
  490. * Add profiling information for cqr after execution.
  491. */
  492. static void dasd_profile_end(struct dasd_block *block,
  493. struct dasd_ccw_req *cqr,
  494. struct request *req)
  495. {
  496. long strtime, irqtime, endtime, tottime; /* in microseconds */
  497. long tottimeps, sectors;
  498. if (dasd_profile_level != DASD_PROFILE_ON)
  499. return;
  500. sectors = req->nr_sectors;
  501. if (!cqr->buildclk || !cqr->startclk ||
  502. !cqr->stopclk || !cqr->endclk ||
  503. !sectors)
  504. return;
  505. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  506. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  507. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  508. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  509. tottimeps = tottime / sectors;
  510. if (!dasd_global_profile.dasd_io_reqs)
  511. memset(&dasd_global_profile, 0,
  512. sizeof(struct dasd_profile_info_t));
  513. dasd_global_profile.dasd_io_reqs++;
  514. dasd_global_profile.dasd_io_sects += sectors;
  515. if (!block->profile.dasd_io_reqs)
  516. memset(&block->profile, 0,
  517. sizeof(struct dasd_profile_info_t));
  518. block->profile.dasd_io_reqs++;
  519. block->profile.dasd_io_sects += sectors;
  520. dasd_profile_counter(sectors, dasd_io_secs, block);
  521. dasd_profile_counter(tottime, dasd_io_times, block);
  522. dasd_profile_counter(tottimeps, dasd_io_timps, block);
  523. dasd_profile_counter(strtime, dasd_io_time1, block);
  524. dasd_profile_counter(irqtime, dasd_io_time2, block);
  525. dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
  526. dasd_profile_counter(endtime, dasd_io_time3, block);
  527. }
  528. #else
  529. #define dasd_profile_start(block, cqr, req) do {} while (0)
  530. #define dasd_profile_end(block, cqr, req) do {} while (0)
  531. #endif /* CONFIG_DASD_PROFILE */
  532. /*
  533. * Allocate memory for a channel program with 'cplength' channel
  534. * command words and 'datasize' additional space. There are two
  535. * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
  536. * memory and 2) dasd_smalloc_request uses the static ccw memory
  537. * that gets allocated for each device.
  538. */
  539. struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
  540. int datasize,
  541. struct dasd_device *device)
  542. {
  543. struct dasd_ccw_req *cqr;
  544. /* Sanity checks */
  545. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  546. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  547. cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
  548. if (cqr == NULL)
  549. return ERR_PTR(-ENOMEM);
  550. cqr->cpaddr = NULL;
  551. if (cplength > 0) {
  552. cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  553. GFP_ATOMIC | GFP_DMA);
  554. if (cqr->cpaddr == NULL) {
  555. kfree(cqr);
  556. return ERR_PTR(-ENOMEM);
  557. }
  558. }
  559. cqr->data = NULL;
  560. if (datasize > 0) {
  561. cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
  562. if (cqr->data == NULL) {
  563. kfree(cqr->cpaddr);
  564. kfree(cqr);
  565. return ERR_PTR(-ENOMEM);
  566. }
  567. }
  568. strncpy((char *) &cqr->magic, magic, 4);
  569. ASCEBC((char *) &cqr->magic, 4);
  570. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  571. dasd_get_device(device);
  572. return cqr;
  573. }
  574. struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
  575. int datasize,
  576. struct dasd_device *device)
  577. {
  578. unsigned long flags;
  579. struct dasd_ccw_req *cqr;
  580. char *data;
  581. int size;
  582. /* Sanity checks */
  583. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  584. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  585. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  586. if (cplength > 0)
  587. size += cplength * sizeof(struct ccw1);
  588. if (datasize > 0)
  589. size += datasize;
  590. spin_lock_irqsave(&device->mem_lock, flags);
  591. cqr = (struct dasd_ccw_req *)
  592. dasd_alloc_chunk(&device->ccw_chunks, size);
  593. spin_unlock_irqrestore(&device->mem_lock, flags);
  594. if (cqr == NULL)
  595. return ERR_PTR(-ENOMEM);
  596. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  597. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  598. cqr->cpaddr = NULL;
  599. if (cplength > 0) {
  600. cqr->cpaddr = (struct ccw1 *) data;
  601. data += cplength*sizeof(struct ccw1);
  602. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  603. }
  604. cqr->data = NULL;
  605. if (datasize > 0) {
  606. cqr->data = data;
  607. memset(cqr->data, 0, datasize);
  608. }
  609. strncpy((char *) &cqr->magic, magic, 4);
  610. ASCEBC((char *) &cqr->magic, 4);
  611. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  612. dasd_get_device(device);
  613. return cqr;
  614. }
  615. /*
  616. * Free memory of a channel program. This function needs to free all the
  617. * idal lists that might have been created by dasd_set_cda and the
  618. * struct dasd_ccw_req itself.
  619. */
  620. void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  621. {
  622. #ifdef CONFIG_64BIT
  623. struct ccw1 *ccw;
  624. /* Clear any idals used for the request. */
  625. ccw = cqr->cpaddr;
  626. do {
  627. clear_normalized_cda(ccw);
  628. } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
  629. #endif
  630. kfree(cqr->cpaddr);
  631. kfree(cqr->data);
  632. kfree(cqr);
  633. dasd_put_device(device);
  634. }
  635. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  636. {
  637. unsigned long flags;
  638. spin_lock_irqsave(&device->mem_lock, flags);
  639. dasd_free_chunk(&device->ccw_chunks, cqr);
  640. spin_unlock_irqrestore(&device->mem_lock, flags);
  641. dasd_put_device(device);
  642. }
  643. /*
  644. * Check discipline magic in cqr.
  645. */
  646. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  647. {
  648. struct dasd_device *device;
  649. if (cqr == NULL)
  650. return -EINVAL;
  651. device = cqr->startdev;
  652. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  653. DEV_MESSAGE(KERN_WARNING, device,
  654. " dasd_ccw_req 0x%08x magic doesn't match"
  655. " discipline 0x%08x",
  656. cqr->magic,
  657. *(unsigned int *) device->discipline->name);
  658. return -EINVAL;
  659. }
  660. return 0;
  661. }
  662. /*
  663. * Terminate the current i/o and set the request to clear_pending.
  664. * Timer keeps device runnig.
  665. * ccw_device_clear can fail if the i/o subsystem
  666. * is in a bad mood.
  667. */
  668. int dasd_term_IO(struct dasd_ccw_req *cqr)
  669. {
  670. struct dasd_device *device;
  671. int retries, rc;
  672. /* Check the cqr */
  673. rc = dasd_check_cqr(cqr);
  674. if (rc)
  675. return rc;
  676. retries = 0;
  677. device = (struct dasd_device *) cqr->startdev;
  678. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  679. rc = ccw_device_clear(device->cdev, (long) cqr);
  680. switch (rc) {
  681. case 0: /* termination successful */
  682. cqr->retries--;
  683. cqr->status = DASD_CQR_CLEAR_PENDING;
  684. cqr->stopclk = get_clock();
  685. cqr->starttime = 0;
  686. DBF_DEV_EVENT(DBF_DEBUG, device,
  687. "terminate cqr %p successful",
  688. cqr);
  689. break;
  690. case -ENODEV:
  691. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  692. "device gone, retry");
  693. break;
  694. case -EIO:
  695. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  696. "I/O error, retry");
  697. break;
  698. case -EINVAL:
  699. case -EBUSY:
  700. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  701. "device busy, retry later");
  702. break;
  703. default:
  704. DEV_MESSAGE(KERN_ERR, device,
  705. "line %d unknown RC=%d, please "
  706. "report to linux390@de.ibm.com",
  707. __LINE__, rc);
  708. BUG();
  709. break;
  710. }
  711. retries++;
  712. }
  713. dasd_schedule_device_bh(device);
  714. return rc;
  715. }
  716. /*
  717. * Start the i/o. This start_IO can fail if the channel is really busy.
  718. * In that case set up a timer to start the request later.
  719. */
  720. int dasd_start_IO(struct dasd_ccw_req *cqr)
  721. {
  722. struct dasd_device *device;
  723. int rc;
  724. /* Check the cqr */
  725. rc = dasd_check_cqr(cqr);
  726. if (rc)
  727. return rc;
  728. device = (struct dasd_device *) cqr->startdev;
  729. if (cqr->retries < 0) {
  730. DEV_MESSAGE(KERN_DEBUG, device,
  731. "start_IO: request %p (%02x/%i) - no retry left.",
  732. cqr, cqr->status, cqr->retries);
  733. cqr->status = DASD_CQR_ERROR;
  734. return -EIO;
  735. }
  736. cqr->startclk = get_clock();
  737. cqr->starttime = jiffies;
  738. cqr->retries--;
  739. rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
  740. cqr->lpm, 0);
  741. switch (rc) {
  742. case 0:
  743. cqr->status = DASD_CQR_IN_IO;
  744. DBF_DEV_EVENT(DBF_DEBUG, device,
  745. "start_IO: request %p started successful",
  746. cqr);
  747. break;
  748. case -EBUSY:
  749. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  750. "start_IO: device busy, retry later");
  751. break;
  752. case -ETIMEDOUT:
  753. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  754. "start_IO: request timeout, retry later");
  755. break;
  756. case -EACCES:
  757. /* -EACCES indicates that the request used only a
  758. * subset of the available pathes and all these
  759. * pathes are gone.
  760. * Do a retry with all available pathes.
  761. */
  762. cqr->lpm = LPM_ANYPATH;
  763. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  764. "start_IO: selected pathes gone,"
  765. " retry on all pathes");
  766. break;
  767. case -ENODEV:
  768. case -EIO:
  769. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  770. "start_IO: device gone, retry");
  771. break;
  772. default:
  773. DEV_MESSAGE(KERN_ERR, device,
  774. "line %d unknown RC=%d, please report"
  775. " to linux390@de.ibm.com", __LINE__, rc);
  776. BUG();
  777. break;
  778. }
  779. return rc;
  780. }
  781. /*
  782. * Timeout function for dasd devices. This is used for different purposes
  783. * 1) missing interrupt handler for normal operation
  784. * 2) delayed start of request where start_IO failed with -EBUSY
  785. * 3) timeout for missing state change interrupts
  786. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  787. * DASD_CQR_QUEUED for 2) and 3).
  788. */
  789. static void dasd_device_timeout(unsigned long ptr)
  790. {
  791. unsigned long flags;
  792. struct dasd_device *device;
  793. device = (struct dasd_device *) ptr;
  794. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  795. /* re-activate request queue */
  796. device->stopped &= ~DASD_STOPPED_PENDING;
  797. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  798. dasd_schedule_device_bh(device);
  799. }
  800. /*
  801. * Setup timeout for a device in jiffies.
  802. */
  803. void dasd_device_set_timer(struct dasd_device *device, int expires)
  804. {
  805. if (expires == 0) {
  806. if (timer_pending(&device->timer))
  807. del_timer(&device->timer);
  808. return;
  809. }
  810. if (timer_pending(&device->timer)) {
  811. if (mod_timer(&device->timer, jiffies + expires))
  812. return;
  813. }
  814. device->timer.function = dasd_device_timeout;
  815. device->timer.data = (unsigned long) device;
  816. device->timer.expires = jiffies + expires;
  817. add_timer(&device->timer);
  818. }
  819. /*
  820. * Clear timeout for a device.
  821. */
  822. void dasd_device_clear_timer(struct dasd_device *device)
  823. {
  824. if (timer_pending(&device->timer))
  825. del_timer(&device->timer);
  826. }
  827. static void dasd_handle_killed_request(struct ccw_device *cdev,
  828. unsigned long intparm)
  829. {
  830. struct dasd_ccw_req *cqr;
  831. struct dasd_device *device;
  832. if (!intparm)
  833. return;
  834. cqr = (struct dasd_ccw_req *) intparm;
  835. if (cqr->status != DASD_CQR_IN_IO) {
  836. MESSAGE(KERN_DEBUG,
  837. "invalid status in handle_killed_request: "
  838. "bus_id %s, status %02x",
  839. cdev->dev.bus_id, cqr->status);
  840. return;
  841. }
  842. device = (struct dasd_device *) cqr->startdev;
  843. if (device == NULL ||
  844. device != dasd_device_from_cdev_locked(cdev) ||
  845. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  846. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  847. cdev->dev.bus_id);
  848. return;
  849. }
  850. /* Schedule request to be retried. */
  851. cqr->status = DASD_CQR_QUEUED;
  852. dasd_device_clear_timer(device);
  853. dasd_schedule_device_bh(device);
  854. dasd_put_device(device);
  855. }
  856. void dasd_generic_handle_state_change(struct dasd_device *device)
  857. {
  858. /* First of all start sense subsystem status request. */
  859. dasd_eer_snss(device);
  860. device->stopped &= ~DASD_STOPPED_PENDING;
  861. dasd_schedule_device_bh(device);
  862. if (device->block)
  863. dasd_schedule_block_bh(device->block);
  864. }
  865. /*
  866. * Interrupt handler for "normal" ssch-io based dasd devices.
  867. */
  868. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  869. struct irb *irb)
  870. {
  871. struct dasd_ccw_req *cqr, *next;
  872. struct dasd_device *device;
  873. unsigned long long now;
  874. int expires;
  875. if (IS_ERR(irb)) {
  876. switch (PTR_ERR(irb)) {
  877. case -EIO:
  878. break;
  879. case -ETIMEDOUT:
  880. printk(KERN_WARNING"%s(%s): request timed out\n",
  881. __func__, cdev->dev.bus_id);
  882. break;
  883. default:
  884. printk(KERN_WARNING"%s(%s): unknown error %ld\n",
  885. __func__, cdev->dev.bus_id, PTR_ERR(irb));
  886. }
  887. dasd_handle_killed_request(cdev, intparm);
  888. return;
  889. }
  890. now = get_clock();
  891. DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
  892. cdev->dev.bus_id, ((irb->scsw.cmd.cstat << 8) |
  893. irb->scsw.cmd.dstat), (unsigned int) intparm);
  894. /* check for unsolicited interrupts */
  895. cqr = (struct dasd_ccw_req *) intparm;
  896. if (!cqr || ((irb->scsw.cmd.cc == 1) &&
  897. (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
  898. (irb->scsw.cmd.stctl & SCSW_STCTL_STATUS_PEND))) {
  899. if (cqr && cqr->status == DASD_CQR_IN_IO)
  900. cqr->status = DASD_CQR_QUEUED;
  901. device = dasd_device_from_cdev_locked(cdev);
  902. if (!IS_ERR(device)) {
  903. dasd_device_clear_timer(device);
  904. device->discipline->handle_unsolicited_interrupt(device,
  905. irb);
  906. dasd_put_device(device);
  907. }
  908. return;
  909. }
  910. device = (struct dasd_device *) cqr->startdev;
  911. if (!device ||
  912. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  913. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  914. cdev->dev.bus_id);
  915. return;
  916. }
  917. /* Check for clear pending */
  918. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  919. irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
  920. cqr->status = DASD_CQR_CLEARED;
  921. dasd_device_clear_timer(device);
  922. wake_up(&dasd_flush_wq);
  923. dasd_schedule_device_bh(device);
  924. return;
  925. }
  926. /* check status - the request might have been killed by dyn detach */
  927. if (cqr->status != DASD_CQR_IN_IO) {
  928. MESSAGE(KERN_DEBUG,
  929. "invalid status: bus_id %s, status %02x",
  930. cdev->dev.bus_id, cqr->status);
  931. return;
  932. }
  933. DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
  934. ((irb->scsw.cmd.cstat << 8) | irb->scsw.cmd.dstat), cqr);
  935. next = NULL;
  936. expires = 0;
  937. if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  938. irb->scsw.cmd.cstat == 0 && !irb->esw.esw0.erw.cons) {
  939. /* request was completed successfully */
  940. cqr->status = DASD_CQR_SUCCESS;
  941. cqr->stopclk = now;
  942. /* Start first request on queue if possible -> fast_io. */
  943. if (cqr->devlist.next != &device->ccw_queue) {
  944. next = list_entry(cqr->devlist.next,
  945. struct dasd_ccw_req, devlist);
  946. }
  947. } else { /* error */
  948. memcpy(&cqr->irb, irb, sizeof(struct irb));
  949. if (device->features & DASD_FEATURE_ERPLOG) {
  950. dasd_log_sense(cqr, irb);
  951. }
  952. /*
  953. * If we don't want complex ERP for this request, then just
  954. * reset this and retry it in the fastpath
  955. */
  956. if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
  957. cqr->retries > 0) {
  958. DEV_MESSAGE(KERN_DEBUG, device,
  959. "default ERP in fastpath (%i retries left)",
  960. cqr->retries);
  961. cqr->lpm = LPM_ANYPATH;
  962. cqr->status = DASD_CQR_QUEUED;
  963. next = cqr;
  964. } else
  965. cqr->status = DASD_CQR_ERROR;
  966. }
  967. if (next && (next->status == DASD_CQR_QUEUED) &&
  968. (!device->stopped)) {
  969. if (device->discipline->start_IO(next) == 0)
  970. expires = next->expires;
  971. else
  972. DEV_MESSAGE(KERN_DEBUG, device, "%s",
  973. "Interrupt fastpath "
  974. "failed!");
  975. }
  976. if (expires != 0)
  977. dasd_device_set_timer(device, expires);
  978. else
  979. dasd_device_clear_timer(device);
  980. dasd_schedule_device_bh(device);
  981. }
  982. /*
  983. * If we have an error on a dasd_block layer request then we cancel
  984. * and return all further requests from the same dasd_block as well.
  985. */
  986. static void __dasd_device_recovery(struct dasd_device *device,
  987. struct dasd_ccw_req *ref_cqr)
  988. {
  989. struct list_head *l, *n;
  990. struct dasd_ccw_req *cqr;
  991. /*
  992. * only requeue request that came from the dasd_block layer
  993. */
  994. if (!ref_cqr->block)
  995. return;
  996. list_for_each_safe(l, n, &device->ccw_queue) {
  997. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  998. if (cqr->status == DASD_CQR_QUEUED &&
  999. ref_cqr->block == cqr->block) {
  1000. cqr->status = DASD_CQR_CLEARED;
  1001. }
  1002. }
  1003. };
  1004. /*
  1005. * Remove those ccw requests from the queue that need to be returned
  1006. * to the upper layer.
  1007. */
  1008. static void __dasd_device_process_ccw_queue(struct dasd_device *device,
  1009. struct list_head *final_queue)
  1010. {
  1011. struct list_head *l, *n;
  1012. struct dasd_ccw_req *cqr;
  1013. /* Process request with final status. */
  1014. list_for_each_safe(l, n, &device->ccw_queue) {
  1015. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1016. /* Stop list processing at the first non-final request. */
  1017. if (cqr->status == DASD_CQR_QUEUED ||
  1018. cqr->status == DASD_CQR_IN_IO ||
  1019. cqr->status == DASD_CQR_CLEAR_PENDING)
  1020. break;
  1021. if (cqr->status == DASD_CQR_ERROR) {
  1022. __dasd_device_recovery(device, cqr);
  1023. }
  1024. /* Rechain finished requests to final queue */
  1025. list_move_tail(&cqr->devlist, final_queue);
  1026. }
  1027. }
  1028. /*
  1029. * the cqrs from the final queue are returned to the upper layer
  1030. * by setting a dasd_block state and calling the callback function
  1031. */
  1032. static void __dasd_device_process_final_queue(struct dasd_device *device,
  1033. struct list_head *final_queue)
  1034. {
  1035. struct list_head *l, *n;
  1036. struct dasd_ccw_req *cqr;
  1037. struct dasd_block *block;
  1038. void (*callback)(struct dasd_ccw_req *, void *data);
  1039. void *callback_data;
  1040. list_for_each_safe(l, n, final_queue) {
  1041. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1042. list_del_init(&cqr->devlist);
  1043. block = cqr->block;
  1044. callback = cqr->callback;
  1045. callback_data = cqr->callback_data;
  1046. if (block)
  1047. spin_lock_bh(&block->queue_lock);
  1048. switch (cqr->status) {
  1049. case DASD_CQR_SUCCESS:
  1050. cqr->status = DASD_CQR_DONE;
  1051. break;
  1052. case DASD_CQR_ERROR:
  1053. cqr->status = DASD_CQR_NEED_ERP;
  1054. break;
  1055. case DASD_CQR_CLEARED:
  1056. cqr->status = DASD_CQR_TERMINATED;
  1057. break;
  1058. default:
  1059. DEV_MESSAGE(KERN_ERR, device,
  1060. "wrong cqr status in __dasd_process_final_queue "
  1061. "for cqr %p, status %x",
  1062. cqr, cqr->status);
  1063. BUG();
  1064. }
  1065. if (cqr->callback != NULL)
  1066. (callback)(cqr, callback_data);
  1067. if (block)
  1068. spin_unlock_bh(&block->queue_lock);
  1069. }
  1070. }
  1071. /*
  1072. * Take a look at the first request on the ccw queue and check
  1073. * if it reached its expire time. If so, terminate the IO.
  1074. */
  1075. static void __dasd_device_check_expire(struct dasd_device *device)
  1076. {
  1077. struct dasd_ccw_req *cqr;
  1078. if (list_empty(&device->ccw_queue))
  1079. return;
  1080. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1081. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1082. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1083. if (device->discipline->term_IO(cqr) != 0) {
  1084. /* Hmpf, try again in 5 sec */
  1085. DEV_MESSAGE(KERN_ERR, device,
  1086. "internal error - timeout (%is) expired "
  1087. "for cqr %p, termination failed, "
  1088. "retrying in 5s",
  1089. (cqr->expires/HZ), cqr);
  1090. cqr->expires += 5*HZ;
  1091. dasd_device_set_timer(device, 5*HZ);
  1092. } else {
  1093. DEV_MESSAGE(KERN_ERR, device,
  1094. "internal error - timeout (%is) expired "
  1095. "for cqr %p (%i retries left)",
  1096. (cqr->expires/HZ), cqr, cqr->retries);
  1097. }
  1098. }
  1099. }
  1100. /*
  1101. * Take a look at the first request on the ccw queue and check
  1102. * if it needs to be started.
  1103. */
  1104. static void __dasd_device_start_head(struct dasd_device *device)
  1105. {
  1106. struct dasd_ccw_req *cqr;
  1107. int rc;
  1108. if (list_empty(&device->ccw_queue))
  1109. return;
  1110. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1111. if (cqr->status != DASD_CQR_QUEUED)
  1112. return;
  1113. /* when device is stopped, return request to previous layer */
  1114. if (device->stopped) {
  1115. cqr->status = DASD_CQR_CLEARED;
  1116. dasd_schedule_device_bh(device);
  1117. return;
  1118. }
  1119. rc = device->discipline->start_IO(cqr);
  1120. if (rc == 0)
  1121. dasd_device_set_timer(device, cqr->expires);
  1122. else if (rc == -EACCES) {
  1123. dasd_schedule_device_bh(device);
  1124. } else
  1125. /* Hmpf, try again in 1/2 sec */
  1126. dasd_device_set_timer(device, 50);
  1127. }
  1128. /*
  1129. * Go through all request on the dasd_device request queue,
  1130. * terminate them on the cdev if necessary, and return them to the
  1131. * submitting layer via callback.
  1132. * Note:
  1133. * Make sure that all 'submitting layers' still exist when
  1134. * this function is called!. In other words, when 'device' is a base
  1135. * device then all block layer requests must have been removed before
  1136. * via dasd_flush_block_queue.
  1137. */
  1138. int dasd_flush_device_queue(struct dasd_device *device)
  1139. {
  1140. struct dasd_ccw_req *cqr, *n;
  1141. int rc;
  1142. struct list_head flush_queue;
  1143. INIT_LIST_HEAD(&flush_queue);
  1144. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1145. rc = 0;
  1146. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1147. /* Check status and move request to flush_queue */
  1148. switch (cqr->status) {
  1149. case DASD_CQR_IN_IO:
  1150. rc = device->discipline->term_IO(cqr);
  1151. if (rc) {
  1152. /* unable to terminate requeust */
  1153. DEV_MESSAGE(KERN_ERR, device,
  1154. "dasd flush ccw_queue is unable "
  1155. " to terminate request %p",
  1156. cqr);
  1157. /* stop flush processing */
  1158. goto finished;
  1159. }
  1160. break;
  1161. case DASD_CQR_QUEUED:
  1162. cqr->stopclk = get_clock();
  1163. cqr->status = DASD_CQR_CLEARED;
  1164. break;
  1165. default: /* no need to modify the others */
  1166. break;
  1167. }
  1168. list_move_tail(&cqr->devlist, &flush_queue);
  1169. }
  1170. finished:
  1171. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1172. /*
  1173. * After this point all requests must be in state CLEAR_PENDING,
  1174. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1175. * one of the others.
  1176. */
  1177. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1178. wait_event(dasd_flush_wq,
  1179. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1180. /*
  1181. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1182. * and call the callback function of flushed requests
  1183. */
  1184. __dasd_device_process_final_queue(device, &flush_queue);
  1185. return rc;
  1186. }
  1187. /*
  1188. * Acquire the device lock and process queues for the device.
  1189. */
  1190. static void dasd_device_tasklet(struct dasd_device *device)
  1191. {
  1192. struct list_head final_queue;
  1193. atomic_set (&device->tasklet_scheduled, 0);
  1194. INIT_LIST_HEAD(&final_queue);
  1195. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1196. /* Check expire time of first request on the ccw queue. */
  1197. __dasd_device_check_expire(device);
  1198. /* find final requests on ccw queue */
  1199. __dasd_device_process_ccw_queue(device, &final_queue);
  1200. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1201. /* Now call the callback function of requests with final status */
  1202. __dasd_device_process_final_queue(device, &final_queue);
  1203. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1204. /* Now check if the head of the ccw queue needs to be started. */
  1205. __dasd_device_start_head(device);
  1206. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1207. dasd_put_device(device);
  1208. }
  1209. /*
  1210. * Schedules a call to dasd_tasklet over the device tasklet.
  1211. */
  1212. void dasd_schedule_device_bh(struct dasd_device *device)
  1213. {
  1214. /* Protect against rescheduling. */
  1215. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1216. return;
  1217. dasd_get_device(device);
  1218. tasklet_hi_schedule(&device->tasklet);
  1219. }
  1220. /*
  1221. * Queue a request to the head of the device ccw_queue.
  1222. * Start the I/O if possible.
  1223. */
  1224. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1225. {
  1226. struct dasd_device *device;
  1227. unsigned long flags;
  1228. device = cqr->startdev;
  1229. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1230. cqr->status = DASD_CQR_QUEUED;
  1231. list_add(&cqr->devlist, &device->ccw_queue);
  1232. /* let the bh start the request to keep them in order */
  1233. dasd_schedule_device_bh(device);
  1234. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1235. }
  1236. /*
  1237. * Queue a request to the tail of the device ccw_queue.
  1238. * Start the I/O if possible.
  1239. */
  1240. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1241. {
  1242. struct dasd_device *device;
  1243. unsigned long flags;
  1244. device = cqr->startdev;
  1245. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1246. cqr->status = DASD_CQR_QUEUED;
  1247. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1248. /* let the bh start the request to keep them in order */
  1249. dasd_schedule_device_bh(device);
  1250. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1251. }
  1252. /*
  1253. * Wakeup helper for the 'sleep_on' functions.
  1254. */
  1255. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1256. {
  1257. wake_up((wait_queue_head_t *) data);
  1258. }
  1259. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1260. {
  1261. struct dasd_device *device;
  1262. int rc;
  1263. device = cqr->startdev;
  1264. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1265. rc = ((cqr->status == DASD_CQR_DONE ||
  1266. cqr->status == DASD_CQR_NEED_ERP ||
  1267. cqr->status == DASD_CQR_TERMINATED) &&
  1268. list_empty(&cqr->devlist));
  1269. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1270. return rc;
  1271. }
  1272. /*
  1273. * Queue a request to the tail of the device ccw_queue and wait for
  1274. * it's completion.
  1275. */
  1276. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1277. {
  1278. struct dasd_device *device;
  1279. int rc;
  1280. device = cqr->startdev;
  1281. cqr->callback = dasd_wakeup_cb;
  1282. cqr->callback_data = (void *) &generic_waitq;
  1283. dasd_add_request_tail(cqr);
  1284. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1285. /* Request status is either done or failed. */
  1286. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1287. return rc;
  1288. }
  1289. /*
  1290. * Queue a request to the tail of the device ccw_queue and wait
  1291. * interruptible for it's completion.
  1292. */
  1293. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1294. {
  1295. struct dasd_device *device;
  1296. int rc;
  1297. device = cqr->startdev;
  1298. cqr->callback = dasd_wakeup_cb;
  1299. cqr->callback_data = (void *) &generic_waitq;
  1300. dasd_add_request_tail(cqr);
  1301. rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr));
  1302. if (rc == -ERESTARTSYS) {
  1303. dasd_cancel_req(cqr);
  1304. /* wait (non-interruptible) for final status */
  1305. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1306. }
  1307. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1308. return rc;
  1309. }
  1310. /*
  1311. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1312. * for eckd devices) the currently running request has to be terminated
  1313. * and be put back to status queued, before the special request is added
  1314. * to the head of the queue. Then the special request is waited on normally.
  1315. */
  1316. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1317. {
  1318. struct dasd_ccw_req *cqr;
  1319. if (list_empty(&device->ccw_queue))
  1320. return 0;
  1321. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1322. return device->discipline->term_IO(cqr);
  1323. }
  1324. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1325. {
  1326. struct dasd_device *device;
  1327. int rc;
  1328. device = cqr->startdev;
  1329. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1330. rc = _dasd_term_running_cqr(device);
  1331. if (rc) {
  1332. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1333. return rc;
  1334. }
  1335. cqr->callback = dasd_wakeup_cb;
  1336. cqr->callback_data = (void *) &generic_waitq;
  1337. cqr->status = DASD_CQR_QUEUED;
  1338. list_add(&cqr->devlist, &device->ccw_queue);
  1339. /* let the bh start the request to keep them in order */
  1340. dasd_schedule_device_bh(device);
  1341. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1342. wait_event(generic_waitq, _wait_for_wakeup(cqr));
  1343. /* Request status is either done or failed. */
  1344. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1345. return rc;
  1346. }
  1347. /*
  1348. * Cancels a request that was started with dasd_sleep_on_req.
  1349. * This is useful to timeout requests. The request will be
  1350. * terminated if it is currently in i/o.
  1351. * Returns 1 if the request has been terminated.
  1352. * 0 if there was no need to terminate the request (not started yet)
  1353. * negative error code if termination failed
  1354. * Cancellation of a request is an asynchronous operation! The calling
  1355. * function has to wait until the request is properly returned via callback.
  1356. */
  1357. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1358. {
  1359. struct dasd_device *device = cqr->startdev;
  1360. unsigned long flags;
  1361. int rc;
  1362. rc = 0;
  1363. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1364. switch (cqr->status) {
  1365. case DASD_CQR_QUEUED:
  1366. /* request was not started - just set to cleared */
  1367. cqr->status = DASD_CQR_CLEARED;
  1368. break;
  1369. case DASD_CQR_IN_IO:
  1370. /* request in IO - terminate IO and release again */
  1371. rc = device->discipline->term_IO(cqr);
  1372. if (rc) {
  1373. DEV_MESSAGE(KERN_ERR, device,
  1374. "dasd_cancel_req is unable "
  1375. " to terminate request %p, rc = %d",
  1376. cqr, rc);
  1377. } else {
  1378. cqr->stopclk = get_clock();
  1379. rc = 1;
  1380. }
  1381. break;
  1382. default: /* already finished or clear pending - do nothing */
  1383. break;
  1384. }
  1385. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1386. dasd_schedule_device_bh(device);
  1387. return rc;
  1388. }
  1389. /*
  1390. * SECTION: Operations of the dasd_block layer.
  1391. */
  1392. /*
  1393. * Timeout function for dasd_block. This is used when the block layer
  1394. * is waiting for something that may not come reliably, (e.g. a state
  1395. * change interrupt)
  1396. */
  1397. static void dasd_block_timeout(unsigned long ptr)
  1398. {
  1399. unsigned long flags;
  1400. struct dasd_block *block;
  1401. block = (struct dasd_block *) ptr;
  1402. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  1403. /* re-activate request queue */
  1404. block->base->stopped &= ~DASD_STOPPED_PENDING;
  1405. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  1406. dasd_schedule_block_bh(block);
  1407. }
  1408. /*
  1409. * Setup timeout for a dasd_block in jiffies.
  1410. */
  1411. void dasd_block_set_timer(struct dasd_block *block, int expires)
  1412. {
  1413. if (expires == 0) {
  1414. if (timer_pending(&block->timer))
  1415. del_timer(&block->timer);
  1416. return;
  1417. }
  1418. if (timer_pending(&block->timer)) {
  1419. if (mod_timer(&block->timer, jiffies + expires))
  1420. return;
  1421. }
  1422. block->timer.function = dasd_block_timeout;
  1423. block->timer.data = (unsigned long) block;
  1424. block->timer.expires = jiffies + expires;
  1425. add_timer(&block->timer);
  1426. }
  1427. /*
  1428. * Clear timeout for a dasd_block.
  1429. */
  1430. void dasd_block_clear_timer(struct dasd_block *block)
  1431. {
  1432. if (timer_pending(&block->timer))
  1433. del_timer(&block->timer);
  1434. }
  1435. /*
  1436. * posts the buffer_cache about a finalized request
  1437. */
  1438. static inline void dasd_end_request(struct request *req, int error)
  1439. {
  1440. if (__blk_end_request(req, error, blk_rq_bytes(req)))
  1441. BUG();
  1442. }
  1443. /*
  1444. * Process finished error recovery ccw.
  1445. */
  1446. static inline void __dasd_block_process_erp(struct dasd_block *block,
  1447. struct dasd_ccw_req *cqr)
  1448. {
  1449. dasd_erp_fn_t erp_fn;
  1450. struct dasd_device *device = block->base;
  1451. if (cqr->status == DASD_CQR_DONE)
  1452. DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
  1453. else
  1454. DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
  1455. erp_fn = device->discipline->erp_postaction(cqr);
  1456. erp_fn(cqr);
  1457. }
  1458. /*
  1459. * Fetch requests from the block device queue.
  1460. */
  1461. static void __dasd_process_request_queue(struct dasd_block *block)
  1462. {
  1463. struct request_queue *queue;
  1464. struct request *req;
  1465. struct dasd_ccw_req *cqr;
  1466. struct dasd_device *basedev;
  1467. unsigned long flags;
  1468. queue = block->request_queue;
  1469. basedev = block->base;
  1470. /* No queue ? Then there is nothing to do. */
  1471. if (queue == NULL)
  1472. return;
  1473. /*
  1474. * We requeue request from the block device queue to the ccw
  1475. * queue only in two states. In state DASD_STATE_READY the
  1476. * partition detection is done and we need to requeue requests
  1477. * for that. State DASD_STATE_ONLINE is normal block device
  1478. * operation.
  1479. */
  1480. if (basedev->state < DASD_STATE_READY)
  1481. return;
  1482. /* Now we try to fetch requests from the request queue */
  1483. while (!blk_queue_plugged(queue) &&
  1484. elv_next_request(queue)) {
  1485. req = elv_next_request(queue);
  1486. if (basedev->features & DASD_FEATURE_READONLY &&
  1487. rq_data_dir(req) == WRITE) {
  1488. DBF_DEV_EVENT(DBF_ERR, basedev,
  1489. "Rejecting write request %p",
  1490. req);
  1491. blkdev_dequeue_request(req);
  1492. dasd_end_request(req, -EIO);
  1493. continue;
  1494. }
  1495. cqr = basedev->discipline->build_cp(basedev, block, req);
  1496. if (IS_ERR(cqr)) {
  1497. if (PTR_ERR(cqr) == -EBUSY)
  1498. break; /* normal end condition */
  1499. if (PTR_ERR(cqr) == -ENOMEM)
  1500. break; /* terminate request queue loop */
  1501. if (PTR_ERR(cqr) == -EAGAIN) {
  1502. /*
  1503. * The current request cannot be build right
  1504. * now, we have to try later. If this request
  1505. * is the head-of-queue we stop the device
  1506. * for 1/2 second.
  1507. */
  1508. if (!list_empty(&block->ccw_queue))
  1509. break;
  1510. spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
  1511. basedev->stopped |= DASD_STOPPED_PENDING;
  1512. spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
  1513. dasd_block_set_timer(block, HZ/2);
  1514. break;
  1515. }
  1516. DBF_DEV_EVENT(DBF_ERR, basedev,
  1517. "CCW creation failed (rc=%ld) "
  1518. "on request %p",
  1519. PTR_ERR(cqr), req);
  1520. blkdev_dequeue_request(req);
  1521. dasd_end_request(req, -EIO);
  1522. continue;
  1523. }
  1524. /*
  1525. * Note: callback is set to dasd_return_cqr_cb in
  1526. * __dasd_block_start_head to cover erp requests as well
  1527. */
  1528. cqr->callback_data = (void *) req;
  1529. cqr->status = DASD_CQR_FILLED;
  1530. blkdev_dequeue_request(req);
  1531. list_add_tail(&cqr->blocklist, &block->ccw_queue);
  1532. dasd_profile_start(block, cqr, req);
  1533. }
  1534. }
  1535. static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
  1536. {
  1537. struct request *req;
  1538. int status;
  1539. int error = 0;
  1540. req = (struct request *) cqr->callback_data;
  1541. dasd_profile_end(cqr->block, cqr, req);
  1542. status = cqr->block->base->discipline->free_cp(cqr, req);
  1543. if (status <= 0)
  1544. error = status ? status : -EIO;
  1545. dasd_end_request(req, error);
  1546. }
  1547. /*
  1548. * Process ccw request queue.
  1549. */
  1550. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  1551. struct list_head *final_queue)
  1552. {
  1553. struct list_head *l, *n;
  1554. struct dasd_ccw_req *cqr;
  1555. dasd_erp_fn_t erp_fn;
  1556. unsigned long flags;
  1557. struct dasd_device *base = block->base;
  1558. restart:
  1559. /* Process request with final status. */
  1560. list_for_each_safe(l, n, &block->ccw_queue) {
  1561. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1562. if (cqr->status != DASD_CQR_DONE &&
  1563. cqr->status != DASD_CQR_FAILED &&
  1564. cqr->status != DASD_CQR_NEED_ERP &&
  1565. cqr->status != DASD_CQR_TERMINATED)
  1566. continue;
  1567. if (cqr->status == DASD_CQR_TERMINATED) {
  1568. base->discipline->handle_terminated_request(cqr);
  1569. goto restart;
  1570. }
  1571. /* Process requests that may be recovered */
  1572. if (cqr->status == DASD_CQR_NEED_ERP) {
  1573. erp_fn = base->discipline->erp_action(cqr);
  1574. erp_fn(cqr);
  1575. goto restart;
  1576. }
  1577. /* 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. init_waitqueue_head(&generic_waitq);
  2185. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2186. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2187. if (dasd_debug_area == NULL) {
  2188. rc = -ENOMEM;
  2189. goto failed;
  2190. }
  2191. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2192. debug_set_level(dasd_debug_area, DBF_WARNING);
  2193. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2194. dasd_diag_discipline_pointer = NULL;
  2195. rc = dasd_devmap_init();
  2196. if (rc)
  2197. goto failed;
  2198. rc = dasd_gendisk_init();
  2199. if (rc)
  2200. goto failed;
  2201. rc = dasd_parse();
  2202. if (rc)
  2203. goto failed;
  2204. rc = dasd_eer_init();
  2205. if (rc)
  2206. goto failed;
  2207. #ifdef CONFIG_PROC_FS
  2208. rc = dasd_proc_init();
  2209. if (rc)
  2210. goto failed;
  2211. #endif
  2212. return 0;
  2213. failed:
  2214. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2215. dasd_exit();
  2216. return rc;
  2217. }
  2218. module_init(dasd_init);
  2219. module_exit(dasd_exit);
  2220. EXPORT_SYMBOL(dasd_debug_area);
  2221. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2222. EXPORT_SYMBOL(dasd_add_request_head);
  2223. EXPORT_SYMBOL(dasd_add_request_tail);
  2224. EXPORT_SYMBOL(dasd_cancel_req);
  2225. EXPORT_SYMBOL(dasd_device_clear_timer);
  2226. EXPORT_SYMBOL(dasd_block_clear_timer);
  2227. EXPORT_SYMBOL(dasd_enable_device);
  2228. EXPORT_SYMBOL(dasd_int_handler);
  2229. EXPORT_SYMBOL(dasd_kfree_request);
  2230. EXPORT_SYMBOL(dasd_kick_device);
  2231. EXPORT_SYMBOL(dasd_kmalloc_request);
  2232. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2233. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2234. EXPORT_SYMBOL(dasd_set_target_state);
  2235. EXPORT_SYMBOL(dasd_device_set_timer);
  2236. EXPORT_SYMBOL(dasd_block_set_timer);
  2237. EXPORT_SYMBOL(dasd_sfree_request);
  2238. EXPORT_SYMBOL(dasd_sleep_on);
  2239. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2240. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2241. EXPORT_SYMBOL(dasd_smalloc_request);
  2242. EXPORT_SYMBOL(dasd_start_IO);
  2243. EXPORT_SYMBOL(dasd_term_IO);
  2244. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2245. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2246. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2247. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2248. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2249. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2250. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2251. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2252. EXPORT_SYMBOL_GPL(dasd_free_block);