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