dasd.c 66 KB

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