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. /*
  59. * Allocate memory for a new device structure.
  60. */
  61. struct dasd_device *dasd_alloc_device(void)
  62. {
  63. struct dasd_device *device;
  64. device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
  65. if (!device)
  66. return ERR_PTR(-ENOMEM);
  67. /* Get two pages for normal block device operations. */
  68. device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
  69. if (!device->ccw_mem) {
  70. kfree(device);
  71. return ERR_PTR(-ENOMEM);
  72. }
  73. /* Get one page for error recovery. */
  74. device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
  75. if (!device->erp_mem) {
  76. free_pages((unsigned long) device->ccw_mem, 1);
  77. kfree(device);
  78. return ERR_PTR(-ENOMEM);
  79. }
  80. dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
  81. dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
  82. spin_lock_init(&device->mem_lock);
  83. atomic_set(&device->tasklet_scheduled, 0);
  84. tasklet_init(&device->tasklet,
  85. (void (*)(unsigned long)) dasd_device_tasklet,
  86. (unsigned long) device);
  87. INIT_LIST_HEAD(&device->ccw_queue);
  88. init_timer(&device->timer);
  89. INIT_WORK(&device->kick_work, do_kick_device);
  90. device->state = DASD_STATE_NEW;
  91. device->target = DASD_STATE_NEW;
  92. return device;
  93. }
  94. /*
  95. * Free memory of a device structure.
  96. */
  97. void dasd_free_device(struct dasd_device *device)
  98. {
  99. kfree(device->private);
  100. free_page((unsigned long) device->erp_mem);
  101. free_pages((unsigned long) device->ccw_mem, 1);
  102. kfree(device);
  103. }
  104. /*
  105. * Allocate memory for a new device structure.
  106. */
  107. struct dasd_block *dasd_alloc_block(void)
  108. {
  109. struct dasd_block *block;
  110. block = kzalloc(sizeof(*block), GFP_ATOMIC);
  111. if (!block)
  112. return ERR_PTR(-ENOMEM);
  113. /* open_count = 0 means device online but not in use */
  114. atomic_set(&block->open_count, -1);
  115. spin_lock_init(&block->request_queue_lock);
  116. atomic_set(&block->tasklet_scheduled, 0);
  117. tasklet_init(&block->tasklet,
  118. (void (*)(unsigned long)) dasd_block_tasklet,
  119. (unsigned long) block);
  120. INIT_LIST_HEAD(&block->ccw_queue);
  121. spin_lock_init(&block->queue_lock);
  122. init_timer(&block->timer);
  123. return block;
  124. }
  125. /*
  126. * Free memory of a device structure.
  127. */
  128. void dasd_free_block(struct dasd_block *block)
  129. {
  130. kfree(block);
  131. }
  132. /*
  133. * Make a new device known to the system.
  134. */
  135. static int dasd_state_new_to_known(struct dasd_device *device)
  136. {
  137. int rc;
  138. /*
  139. * As long as the device is not in state DASD_STATE_NEW we want to
  140. * keep the reference count > 0.
  141. */
  142. dasd_get_device(device);
  143. if (device->block) {
  144. rc = dasd_alloc_queue(device->block);
  145. if (rc) {
  146. dasd_put_device(device);
  147. return rc;
  148. }
  149. }
  150. device->state = DASD_STATE_KNOWN;
  151. return 0;
  152. }
  153. /*
  154. * Let the system forget about a device.
  155. */
  156. static int dasd_state_known_to_new(struct dasd_device *device)
  157. {
  158. /* Disable extended error reporting for this device. */
  159. dasd_eer_disable(device);
  160. /* Forget the discipline information. */
  161. if (device->discipline) {
  162. if (device->discipline->uncheck_device)
  163. device->discipline->uncheck_device(device);
  164. module_put(device->discipline->owner);
  165. }
  166. device->discipline = NULL;
  167. if (device->base_discipline)
  168. module_put(device->base_discipline->owner);
  169. device->base_discipline = NULL;
  170. device->state = DASD_STATE_NEW;
  171. if (device->block)
  172. dasd_free_queue(device->block);
  173. /* Give up reference we took in dasd_state_new_to_known. */
  174. dasd_put_device(device);
  175. return 0;
  176. }
  177. /*
  178. * Request the irq line for the device.
  179. */
  180. static int dasd_state_known_to_basic(struct dasd_device *device)
  181. {
  182. int rc;
  183. /* Allocate and register gendisk structure. */
  184. if (device->block) {
  185. rc = dasd_gendisk_alloc(device->block);
  186. if (rc)
  187. return rc;
  188. }
  189. /* register 'device' debug area, used for all DBF_DEV_XXX calls */
  190. device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 1,
  191. 8 * sizeof(long));
  192. debug_register_view(device->debug_area, &debug_sprintf_view);
  193. debug_set_level(device->debug_area, DBF_WARNING);
  194. DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
  195. device->state = DASD_STATE_BASIC;
  196. return 0;
  197. }
  198. /*
  199. * Release the irq line for the device. Terminate any running i/o.
  200. */
  201. static int dasd_state_basic_to_known(struct dasd_device *device)
  202. {
  203. int rc;
  204. if (device->block) {
  205. dasd_gendisk_free(device->block);
  206. dasd_block_clear_timer(device->block);
  207. }
  208. rc = dasd_flush_device_queue(device);
  209. if (rc)
  210. return rc;
  211. dasd_device_clear_timer(device);
  212. DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
  213. if (device->debug_area != NULL) {
  214. debug_unregister(device->debug_area);
  215. device->debug_area = NULL;
  216. }
  217. device->state = DASD_STATE_KNOWN;
  218. return 0;
  219. }
  220. /*
  221. * Do the initial analysis. The do_analysis function may return
  222. * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
  223. * until the discipline decides to continue the startup sequence
  224. * by calling the function dasd_change_state. The eckd disciplines
  225. * uses this to start a ccw that detects the format. The completion
  226. * interrupt for this detection ccw uses the kernel event daemon to
  227. * trigger the call to dasd_change_state. All this is done in the
  228. * discipline code, see dasd_eckd.c.
  229. * After the analysis ccw is done (do_analysis returned 0) the block
  230. * device is setup.
  231. * In case the analysis returns an error, the device setup is stopped
  232. * (a fake disk was already added to allow formatting).
  233. */
  234. static int dasd_state_basic_to_ready(struct dasd_device *device)
  235. {
  236. int rc;
  237. struct dasd_block *block;
  238. rc = 0;
  239. block = device->block;
  240. /* make disk known with correct capacity */
  241. if (block) {
  242. if (block->base->discipline->do_analysis != NULL)
  243. rc = block->base->discipline->do_analysis(block);
  244. if (rc) {
  245. if (rc != -EAGAIN)
  246. device->state = DASD_STATE_UNFMT;
  247. return rc;
  248. }
  249. dasd_setup_queue(block);
  250. set_capacity(block->gdp,
  251. block->blocks << block->s2b_shift);
  252. device->state = DASD_STATE_READY;
  253. rc = dasd_scan_partitions(block);
  254. if (rc)
  255. device->state = DASD_STATE_BASIC;
  256. } else {
  257. device->state = DASD_STATE_READY;
  258. }
  259. return rc;
  260. }
  261. /*
  262. * Remove device from block device layer. Destroy dirty buffers.
  263. * Forget format information. Check if the target level is basic
  264. * and if it is create fake disk for formatting.
  265. */
  266. static int dasd_state_ready_to_basic(struct dasd_device *device)
  267. {
  268. int rc;
  269. device->state = DASD_STATE_BASIC;
  270. if (device->block) {
  271. struct dasd_block *block = device->block;
  272. rc = dasd_flush_block_queue(block);
  273. if (rc) {
  274. device->state = DASD_STATE_READY;
  275. return rc;
  276. }
  277. dasd_destroy_partitions(block);
  278. dasd_flush_request_queue(block);
  279. block->blocks = 0;
  280. block->bp_block = 0;
  281. block->s2b_shift = 0;
  282. }
  283. return 0;
  284. }
  285. /*
  286. * Back to basic.
  287. */
  288. static int dasd_state_unfmt_to_basic(struct dasd_device *device)
  289. {
  290. device->state = DASD_STATE_BASIC;
  291. return 0;
  292. }
  293. /*
  294. * Make the device online and schedule the bottom half to start
  295. * the requeueing of requests from the linux request queue to the
  296. * ccw queue.
  297. */
  298. static int
  299. dasd_state_ready_to_online(struct dasd_device * device)
  300. {
  301. int rc;
  302. if (device->discipline->ready_to_online) {
  303. rc = device->discipline->ready_to_online(device);
  304. if (rc)
  305. return rc;
  306. }
  307. device->state = DASD_STATE_ONLINE;
  308. if (device->block)
  309. dasd_schedule_block_bh(device->block);
  310. return 0;
  311. }
  312. /*
  313. * Stop the requeueing of requests again.
  314. */
  315. static int dasd_state_online_to_ready(struct dasd_device *device)
  316. {
  317. int rc;
  318. if (device->discipline->online_to_ready) {
  319. rc = device->discipline->online_to_ready(device);
  320. if (rc)
  321. return rc;
  322. }
  323. device->state = DASD_STATE_READY;
  324. return 0;
  325. }
  326. /*
  327. * Device startup state changes.
  328. */
  329. static int dasd_increase_state(struct dasd_device *device)
  330. {
  331. int rc;
  332. rc = 0;
  333. if (device->state == DASD_STATE_NEW &&
  334. device->target >= DASD_STATE_KNOWN)
  335. rc = dasd_state_new_to_known(device);
  336. if (!rc &&
  337. device->state == DASD_STATE_KNOWN &&
  338. device->target >= DASD_STATE_BASIC)
  339. rc = dasd_state_known_to_basic(device);
  340. if (!rc &&
  341. device->state == DASD_STATE_BASIC &&
  342. device->target >= DASD_STATE_READY)
  343. rc = dasd_state_basic_to_ready(device);
  344. if (!rc &&
  345. device->state == DASD_STATE_UNFMT &&
  346. device->target > DASD_STATE_UNFMT)
  347. rc = -EPERM;
  348. if (!rc &&
  349. device->state == DASD_STATE_READY &&
  350. device->target >= DASD_STATE_ONLINE)
  351. rc = dasd_state_ready_to_online(device);
  352. return rc;
  353. }
  354. /*
  355. * Device shutdown state changes.
  356. */
  357. static int dasd_decrease_state(struct dasd_device *device)
  358. {
  359. int rc;
  360. rc = 0;
  361. if (device->state == DASD_STATE_ONLINE &&
  362. device->target <= DASD_STATE_READY)
  363. rc = dasd_state_online_to_ready(device);
  364. if (!rc &&
  365. device->state == DASD_STATE_READY &&
  366. device->target <= DASD_STATE_BASIC)
  367. rc = dasd_state_ready_to_basic(device);
  368. if (!rc &&
  369. device->state == DASD_STATE_UNFMT &&
  370. device->target <= DASD_STATE_BASIC)
  371. rc = dasd_state_unfmt_to_basic(device);
  372. if (!rc &&
  373. device->state == DASD_STATE_BASIC &&
  374. device->target <= DASD_STATE_KNOWN)
  375. rc = dasd_state_basic_to_known(device);
  376. if (!rc &&
  377. device->state == DASD_STATE_KNOWN &&
  378. device->target <= DASD_STATE_NEW)
  379. rc = dasd_state_known_to_new(device);
  380. return rc;
  381. }
  382. /*
  383. * This is the main startup/shutdown routine.
  384. */
  385. static void dasd_change_state(struct dasd_device *device)
  386. {
  387. int rc;
  388. if (device->state == device->target)
  389. /* Already where we want to go today... */
  390. return;
  391. if (device->state < device->target)
  392. rc = dasd_increase_state(device);
  393. else
  394. rc = dasd_decrease_state(device);
  395. if (rc && rc != -EAGAIN)
  396. device->target = device->state;
  397. if (device->state == device->target)
  398. wake_up(&dasd_init_waitq);
  399. /* let user-space know that the device status changed */
  400. kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
  401. }
  402. /*
  403. * Kick starter for devices that did not complete the startup/shutdown
  404. * procedure or were sleeping because of a pending state.
  405. * dasd_kick_device will schedule a call do do_kick_device to the kernel
  406. * event daemon.
  407. */
  408. static void do_kick_device(struct work_struct *work)
  409. {
  410. struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
  411. dasd_change_state(device);
  412. dasd_schedule_device_bh(device);
  413. dasd_put_device(device);
  414. }
  415. void dasd_kick_device(struct dasd_device *device)
  416. {
  417. dasd_get_device(device);
  418. /* queue call to dasd_kick_device to the kernel event daemon. */
  419. schedule_work(&device->kick_work);
  420. }
  421. /*
  422. * Set the target state for a device and starts the state change.
  423. */
  424. void dasd_set_target_state(struct dasd_device *device, int target)
  425. {
  426. /* If we are in probeonly mode stop at DASD_STATE_READY. */
  427. if (dasd_probeonly && target > DASD_STATE_READY)
  428. target = DASD_STATE_READY;
  429. if (device->target != target) {
  430. if (device->state == target)
  431. wake_up(&dasd_init_waitq);
  432. device->target = target;
  433. }
  434. if (device->state != device->target)
  435. dasd_change_state(device);
  436. }
  437. /*
  438. * Enable devices with device numbers in [from..to].
  439. */
  440. static inline int _wait_for_device(struct dasd_device *device)
  441. {
  442. return (device->state == device->target);
  443. }
  444. void dasd_enable_device(struct dasd_device *device)
  445. {
  446. dasd_set_target_state(device, DASD_STATE_ONLINE);
  447. if (device->state <= DASD_STATE_KNOWN)
  448. /* No discipline for device found. */
  449. dasd_set_target_state(device, DASD_STATE_NEW);
  450. /* Now wait for the devices to come up. */
  451. wait_event(dasd_init_waitq, _wait_for_device(device));
  452. }
  453. /*
  454. * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
  455. */
  456. #ifdef CONFIG_DASD_PROFILE
  457. struct dasd_profile_info_t dasd_global_profile;
  458. unsigned int dasd_profile_level = DASD_PROFILE_OFF;
  459. /*
  460. * Increments counter in global and local profiling structures.
  461. */
  462. #define dasd_profile_counter(value, counter, block) \
  463. { \
  464. int index; \
  465. for (index = 0; index < 31 && value >> (2+index); index++); \
  466. dasd_global_profile.counter[index]++; \
  467. block->profile.counter[index]++; \
  468. }
  469. /*
  470. * Add profiling information for cqr before execution.
  471. */
  472. static void dasd_profile_start(struct dasd_block *block,
  473. struct dasd_ccw_req *cqr,
  474. struct request *req)
  475. {
  476. struct list_head *l;
  477. unsigned int counter;
  478. if (dasd_profile_level != DASD_PROFILE_ON)
  479. return;
  480. /* count the length of the chanq for statistics */
  481. counter = 0;
  482. list_for_each(l, &block->ccw_queue)
  483. if (++counter >= 31)
  484. break;
  485. dasd_global_profile.dasd_io_nr_req[counter]++;
  486. block->profile.dasd_io_nr_req[counter]++;
  487. }
  488. /*
  489. * Add profiling information for cqr after execution.
  490. */
  491. static void dasd_profile_end(struct dasd_block *block,
  492. struct dasd_ccw_req *cqr,
  493. struct request *req)
  494. {
  495. long strtime, irqtime, endtime, tottime; /* in microseconds */
  496. long tottimeps, sectors;
  497. if (dasd_profile_level != DASD_PROFILE_ON)
  498. return;
  499. sectors = req->nr_sectors;
  500. if (!cqr->buildclk || !cqr->startclk ||
  501. !cqr->stopclk || !cqr->endclk ||
  502. !sectors)
  503. return;
  504. strtime = ((cqr->startclk - cqr->buildclk) >> 12);
  505. irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
  506. endtime = ((cqr->endclk - cqr->stopclk) >> 12);
  507. tottime = ((cqr->endclk - cqr->buildclk) >> 12);
  508. tottimeps = tottime / sectors;
  509. if (!dasd_global_profile.dasd_io_reqs)
  510. memset(&dasd_global_profile, 0,
  511. sizeof(struct dasd_profile_info_t));
  512. dasd_global_profile.dasd_io_reqs++;
  513. dasd_global_profile.dasd_io_sects += sectors;
  514. if (!block->profile.dasd_io_reqs)
  515. memset(&block->profile, 0,
  516. sizeof(struct dasd_profile_info_t));
  517. block->profile.dasd_io_reqs++;
  518. block->profile.dasd_io_sects += sectors;
  519. dasd_profile_counter(sectors, dasd_io_secs, block);
  520. dasd_profile_counter(tottime, dasd_io_times, block);
  521. dasd_profile_counter(tottimeps, dasd_io_timps, block);
  522. dasd_profile_counter(strtime, dasd_io_time1, block);
  523. dasd_profile_counter(irqtime, dasd_io_time2, block);
  524. dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
  525. dasd_profile_counter(endtime, dasd_io_time3, block);
  526. }
  527. #else
  528. #define dasd_profile_start(block, cqr, req) do {} while (0)
  529. #define dasd_profile_end(block, cqr, req) do {} while (0)
  530. #endif /* CONFIG_DASD_PROFILE */
  531. /*
  532. * Allocate memory for a channel program with 'cplength' channel
  533. * command words and 'datasize' additional space. There are two
  534. * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
  535. * memory and 2) dasd_smalloc_request uses the static ccw memory
  536. * that gets allocated for each device.
  537. */
  538. struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
  539. int datasize,
  540. struct dasd_device *device)
  541. {
  542. struct dasd_ccw_req *cqr;
  543. /* Sanity checks */
  544. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  545. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  546. cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
  547. if (cqr == NULL)
  548. return ERR_PTR(-ENOMEM);
  549. cqr->cpaddr = NULL;
  550. if (cplength > 0) {
  551. cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  552. GFP_ATOMIC | GFP_DMA);
  553. if (cqr->cpaddr == NULL) {
  554. kfree(cqr);
  555. return ERR_PTR(-ENOMEM);
  556. }
  557. }
  558. cqr->data = NULL;
  559. if (datasize > 0) {
  560. cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
  561. if (cqr->data == NULL) {
  562. kfree(cqr->cpaddr);
  563. kfree(cqr);
  564. return ERR_PTR(-ENOMEM);
  565. }
  566. }
  567. strncpy((char *) &cqr->magic, magic, 4);
  568. ASCEBC((char *) &cqr->magic, 4);
  569. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  570. dasd_get_device(device);
  571. return cqr;
  572. }
  573. struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
  574. int datasize,
  575. struct dasd_device *device)
  576. {
  577. unsigned long flags;
  578. struct dasd_ccw_req *cqr;
  579. char *data;
  580. int size;
  581. /* Sanity checks */
  582. BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
  583. (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
  584. size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
  585. if (cplength > 0)
  586. size += cplength * sizeof(struct ccw1);
  587. if (datasize > 0)
  588. size += datasize;
  589. spin_lock_irqsave(&device->mem_lock, flags);
  590. cqr = (struct dasd_ccw_req *)
  591. dasd_alloc_chunk(&device->ccw_chunks, size);
  592. spin_unlock_irqrestore(&device->mem_lock, flags);
  593. if (cqr == NULL)
  594. return ERR_PTR(-ENOMEM);
  595. memset(cqr, 0, sizeof(struct dasd_ccw_req));
  596. data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
  597. cqr->cpaddr = NULL;
  598. if (cplength > 0) {
  599. cqr->cpaddr = (struct ccw1 *) data;
  600. data += cplength*sizeof(struct ccw1);
  601. memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
  602. }
  603. cqr->data = NULL;
  604. if (datasize > 0) {
  605. cqr->data = data;
  606. memset(cqr->data, 0, datasize);
  607. }
  608. strncpy((char *) &cqr->magic, magic, 4);
  609. ASCEBC((char *) &cqr->magic, 4);
  610. set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  611. dasd_get_device(device);
  612. return cqr;
  613. }
  614. /*
  615. * Free memory of a channel program. This function needs to free all the
  616. * idal lists that might have been created by dasd_set_cda and the
  617. * struct dasd_ccw_req itself.
  618. */
  619. void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  620. {
  621. #ifdef CONFIG_64BIT
  622. struct ccw1 *ccw;
  623. /* Clear any idals used for the request. */
  624. ccw = cqr->cpaddr;
  625. do {
  626. clear_normalized_cda(ccw);
  627. } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
  628. #endif
  629. kfree(cqr->cpaddr);
  630. kfree(cqr->data);
  631. kfree(cqr);
  632. dasd_put_device(device);
  633. }
  634. void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
  635. {
  636. unsigned long flags;
  637. spin_lock_irqsave(&device->mem_lock, flags);
  638. dasd_free_chunk(&device->ccw_chunks, cqr);
  639. spin_unlock_irqrestore(&device->mem_lock, flags);
  640. dasd_put_device(device);
  641. }
  642. /*
  643. * Check discipline magic in cqr.
  644. */
  645. static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
  646. {
  647. struct dasd_device *device;
  648. if (cqr == NULL)
  649. return -EINVAL;
  650. device = cqr->startdev;
  651. if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
  652. DEV_MESSAGE(KERN_WARNING, device,
  653. " dasd_ccw_req 0x%08x magic doesn't match"
  654. " discipline 0x%08x",
  655. cqr->magic,
  656. *(unsigned int *) device->discipline->name);
  657. return -EINVAL;
  658. }
  659. return 0;
  660. }
  661. /*
  662. * Terminate the current i/o and set the request to clear_pending.
  663. * Timer keeps device runnig.
  664. * ccw_device_clear can fail if the i/o subsystem
  665. * is in a bad mood.
  666. */
  667. int dasd_term_IO(struct dasd_ccw_req *cqr)
  668. {
  669. struct dasd_device *device;
  670. int retries, rc;
  671. /* Check the cqr */
  672. rc = dasd_check_cqr(cqr);
  673. if (rc)
  674. return rc;
  675. retries = 0;
  676. device = (struct dasd_device *) cqr->startdev;
  677. while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
  678. rc = ccw_device_clear(device->cdev, (long) cqr);
  679. switch (rc) {
  680. case 0: /* termination successful */
  681. cqr->retries--;
  682. cqr->status = DASD_CQR_CLEAR_PENDING;
  683. cqr->stopclk = get_clock();
  684. cqr->starttime = 0;
  685. DBF_DEV_EVENT(DBF_DEBUG, device,
  686. "terminate cqr %p successful",
  687. cqr);
  688. break;
  689. case -ENODEV:
  690. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  691. "device gone, retry");
  692. break;
  693. case -EIO:
  694. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  695. "I/O error, retry");
  696. break;
  697. case -EINVAL:
  698. case -EBUSY:
  699. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  700. "device busy, retry later");
  701. break;
  702. default:
  703. DEV_MESSAGE(KERN_ERR, device,
  704. "line %d unknown RC=%d, please "
  705. "report to linux390@de.ibm.com",
  706. __LINE__, rc);
  707. BUG();
  708. break;
  709. }
  710. retries++;
  711. }
  712. dasd_schedule_device_bh(device);
  713. return rc;
  714. }
  715. /*
  716. * Start the i/o. This start_IO can fail if the channel is really busy.
  717. * In that case set up a timer to start the request later.
  718. */
  719. int dasd_start_IO(struct dasd_ccw_req *cqr)
  720. {
  721. struct dasd_device *device;
  722. int rc;
  723. /* Check the cqr */
  724. rc = dasd_check_cqr(cqr);
  725. if (rc)
  726. return rc;
  727. device = (struct dasd_device *) cqr->startdev;
  728. if (cqr->retries < 0) {
  729. DEV_MESSAGE(KERN_DEBUG, device,
  730. "start_IO: request %p (%02x/%i) - no retry left.",
  731. cqr, cqr->status, cqr->retries);
  732. cqr->status = DASD_CQR_ERROR;
  733. return -EIO;
  734. }
  735. cqr->startclk = get_clock();
  736. cqr->starttime = jiffies;
  737. cqr->retries--;
  738. rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
  739. cqr->lpm, 0);
  740. switch (rc) {
  741. case 0:
  742. cqr->status = DASD_CQR_IN_IO;
  743. DBF_DEV_EVENT(DBF_DEBUG, device,
  744. "start_IO: request %p started successful",
  745. cqr);
  746. break;
  747. case -EBUSY:
  748. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  749. "start_IO: device busy, retry later");
  750. break;
  751. case -ETIMEDOUT:
  752. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  753. "start_IO: request timeout, retry later");
  754. break;
  755. case -EACCES:
  756. /* -EACCES indicates that the request used only a
  757. * subset of the available pathes and all these
  758. * pathes are gone.
  759. * Do a retry with all available pathes.
  760. */
  761. cqr->lpm = LPM_ANYPATH;
  762. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  763. "start_IO: selected pathes gone,"
  764. " retry on all pathes");
  765. break;
  766. case -ENODEV:
  767. case -EIO:
  768. DBF_DEV_EVENT(DBF_ERR, device, "%s",
  769. "start_IO: device gone, retry");
  770. break;
  771. default:
  772. DEV_MESSAGE(KERN_ERR, device,
  773. "line %d unknown RC=%d, please report"
  774. " to linux390@de.ibm.com", __LINE__, rc);
  775. BUG();
  776. break;
  777. }
  778. return rc;
  779. }
  780. /*
  781. * Timeout function for dasd devices. This is used for different purposes
  782. * 1) missing interrupt handler for normal operation
  783. * 2) delayed start of request where start_IO failed with -EBUSY
  784. * 3) timeout for missing state change interrupts
  785. * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
  786. * DASD_CQR_QUEUED for 2) and 3).
  787. */
  788. static void dasd_device_timeout(unsigned long ptr)
  789. {
  790. unsigned long flags;
  791. struct dasd_device *device;
  792. device = (struct dasd_device *) ptr;
  793. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  794. /* re-activate request queue */
  795. device->stopped &= ~DASD_STOPPED_PENDING;
  796. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  797. dasd_schedule_device_bh(device);
  798. }
  799. /*
  800. * Setup timeout for a device in jiffies.
  801. */
  802. void dasd_device_set_timer(struct dasd_device *device, int expires)
  803. {
  804. if (expires == 0) {
  805. if (timer_pending(&device->timer))
  806. del_timer(&device->timer);
  807. return;
  808. }
  809. if (timer_pending(&device->timer)) {
  810. if (mod_timer(&device->timer, jiffies + expires))
  811. return;
  812. }
  813. device->timer.function = dasd_device_timeout;
  814. device->timer.data = (unsigned long) device;
  815. device->timer.expires = jiffies + expires;
  816. add_timer(&device->timer);
  817. }
  818. /*
  819. * Clear timeout for a device.
  820. */
  821. void dasd_device_clear_timer(struct dasd_device *device)
  822. {
  823. if (timer_pending(&device->timer))
  824. del_timer(&device->timer);
  825. }
  826. static void dasd_handle_killed_request(struct ccw_device *cdev,
  827. unsigned long intparm)
  828. {
  829. struct dasd_ccw_req *cqr;
  830. struct dasd_device *device;
  831. cqr = (struct dasd_ccw_req *) intparm;
  832. if (cqr->status != DASD_CQR_IN_IO) {
  833. MESSAGE(KERN_DEBUG,
  834. "invalid status in handle_killed_request: "
  835. "bus_id %s, status %02x",
  836. cdev->dev.bus_id, cqr->status);
  837. return;
  838. }
  839. device = (struct dasd_device *) cqr->startdev;
  840. if (device == NULL ||
  841. device != dasd_device_from_cdev_locked(cdev) ||
  842. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  843. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  844. cdev->dev.bus_id);
  845. return;
  846. }
  847. /* Schedule request to be retried. */
  848. cqr->status = DASD_CQR_QUEUED;
  849. dasd_device_clear_timer(device);
  850. dasd_schedule_device_bh(device);
  851. dasd_put_device(device);
  852. }
  853. void dasd_generic_handle_state_change(struct dasd_device *device)
  854. {
  855. /* First of all start sense subsystem status request. */
  856. dasd_eer_snss(device);
  857. device->stopped &= ~DASD_STOPPED_PENDING;
  858. dasd_schedule_device_bh(device);
  859. if (device->block)
  860. dasd_schedule_block_bh(device->block);
  861. }
  862. /*
  863. * Interrupt handler for "normal" ssch-io based dasd devices.
  864. */
  865. void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
  866. struct irb *irb)
  867. {
  868. struct dasd_ccw_req *cqr, *next;
  869. struct dasd_device *device;
  870. unsigned long long now;
  871. int expires;
  872. if (IS_ERR(irb)) {
  873. switch (PTR_ERR(irb)) {
  874. case -EIO:
  875. dasd_handle_killed_request(cdev, intparm);
  876. break;
  877. case -ETIMEDOUT:
  878. printk(KERN_WARNING"%s(%s): request timed out\n",
  879. __FUNCTION__, cdev->dev.bus_id);
  880. //FIXME - dasd uses own timeout interface...
  881. break;
  882. default:
  883. printk(KERN_WARNING"%s(%s): unknown error %ld\n",
  884. __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
  885. }
  886. return;
  887. }
  888. now = get_clock();
  889. DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
  890. cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
  891. (unsigned int) intparm);
  892. /* check for unsolicited interrupts */
  893. cqr = (struct dasd_ccw_req *) intparm;
  894. if (!cqr || ((irb->scsw.cc == 1) &&
  895. (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
  896. (irb->scsw.stctl & SCSW_STCTL_STATUS_PEND)) ) {
  897. if (cqr && cqr->status == DASD_CQR_IN_IO)
  898. cqr->status = DASD_CQR_QUEUED;
  899. device = dasd_device_from_cdev_locked(cdev);
  900. if (!IS_ERR(device)) {
  901. dasd_device_clear_timer(device);
  902. device->discipline->handle_unsolicited_interrupt(device,
  903. irb);
  904. dasd_put_device(device);
  905. }
  906. return;
  907. }
  908. device = (struct dasd_device *) cqr->startdev;
  909. if (!device ||
  910. strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  911. MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
  912. cdev->dev.bus_id);
  913. return;
  914. }
  915. /* Check for clear pending */
  916. if (cqr->status == DASD_CQR_CLEAR_PENDING &&
  917. irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
  918. cqr->status = DASD_CQR_CLEARED;
  919. dasd_device_clear_timer(device);
  920. wake_up(&dasd_flush_wq);
  921. dasd_schedule_device_bh(device);
  922. return;
  923. }
  924. /* check status - the request might have been killed by dyn detach */
  925. if (cqr->status != DASD_CQR_IN_IO) {
  926. MESSAGE(KERN_DEBUG,
  927. "invalid status: bus_id %s, status %02x",
  928. cdev->dev.bus_id, cqr->status);
  929. return;
  930. }
  931. DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
  932. ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
  933. next = NULL;
  934. expires = 0;
  935. if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
  936. irb->scsw.cstat == 0 && !irb->esw.esw0.erw.cons) {
  937. /* request was completed successfully */
  938. cqr->status = DASD_CQR_SUCCESS;
  939. cqr->stopclk = now;
  940. /* Start first request on queue if possible -> fast_io. */
  941. if (cqr->devlist.next != &device->ccw_queue) {
  942. next = list_entry(cqr->devlist.next,
  943. struct dasd_ccw_req, devlist);
  944. }
  945. } else { /* error */
  946. memcpy(&cqr->irb, irb, sizeof(struct irb));
  947. if (device->features & DASD_FEATURE_ERPLOG) {
  948. dasd_log_sense(cqr, irb);
  949. }
  950. /* If we have no sense data, or we just don't want complex ERP
  951. * for this request, but if we have retries left, then just
  952. * reset this request and retry it in the fastpath
  953. */
  954. if (!(cqr->irb.esw.esw0.erw.cons &&
  955. 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. list_for_each_safe(l, n, final_queue) {
  1037. cqr = list_entry(l, struct dasd_ccw_req, devlist);
  1038. list_del_init(&cqr->devlist);
  1039. if (cqr->block)
  1040. spin_lock_bh(&cqr->block->queue_lock);
  1041. switch (cqr->status) {
  1042. case DASD_CQR_SUCCESS:
  1043. cqr->status = DASD_CQR_DONE;
  1044. break;
  1045. case DASD_CQR_ERROR:
  1046. cqr->status = DASD_CQR_NEED_ERP;
  1047. break;
  1048. case DASD_CQR_CLEARED:
  1049. cqr->status = DASD_CQR_TERMINATED;
  1050. break;
  1051. default:
  1052. DEV_MESSAGE(KERN_ERR, device,
  1053. "wrong cqr status in __dasd_process_final_queue "
  1054. "for cqr %p, status %x",
  1055. cqr, cqr->status);
  1056. BUG();
  1057. }
  1058. if (cqr->block)
  1059. spin_unlock_bh(&cqr->block->queue_lock);
  1060. if (cqr->callback != NULL)
  1061. (cqr->callback)(cqr, cqr->callback_data);
  1062. }
  1063. }
  1064. /*
  1065. * Take a look at the first request on the ccw queue and check
  1066. * if it reached its expire time. If so, terminate the IO.
  1067. */
  1068. static void __dasd_device_check_expire(struct dasd_device *device)
  1069. {
  1070. struct dasd_ccw_req *cqr;
  1071. if (list_empty(&device->ccw_queue))
  1072. return;
  1073. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1074. if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
  1075. (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
  1076. if (device->discipline->term_IO(cqr) != 0) {
  1077. /* Hmpf, try again in 5 sec */
  1078. DEV_MESSAGE(KERN_ERR, device,
  1079. "internal error - timeout (%is) expired "
  1080. "for cqr %p, termination failed, "
  1081. "retrying in 5s",
  1082. (cqr->expires/HZ), cqr);
  1083. cqr->expires += 5*HZ;
  1084. dasd_device_set_timer(device, 5*HZ);
  1085. } else {
  1086. DEV_MESSAGE(KERN_ERR, device,
  1087. "internal error - timeout (%is) expired "
  1088. "for cqr %p (%i retries left)",
  1089. (cqr->expires/HZ), cqr, cqr->retries);
  1090. }
  1091. }
  1092. }
  1093. /*
  1094. * Take a look at the first request on the ccw queue and check
  1095. * if it needs to be started.
  1096. */
  1097. static void __dasd_device_start_head(struct dasd_device *device)
  1098. {
  1099. struct dasd_ccw_req *cqr;
  1100. int rc;
  1101. if (list_empty(&device->ccw_queue))
  1102. return;
  1103. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1104. if (cqr->status != DASD_CQR_QUEUED)
  1105. return;
  1106. /* when device is stopped, return request to previous layer */
  1107. if (device->stopped) {
  1108. cqr->status = DASD_CQR_CLEARED;
  1109. dasd_schedule_device_bh(device);
  1110. return;
  1111. }
  1112. rc = device->discipline->start_IO(cqr);
  1113. if (rc == 0)
  1114. dasd_device_set_timer(device, cqr->expires);
  1115. else if (rc == -EACCES) {
  1116. dasd_schedule_device_bh(device);
  1117. } else
  1118. /* Hmpf, try again in 1/2 sec */
  1119. dasd_device_set_timer(device, 50);
  1120. }
  1121. /*
  1122. * Go through all request on the dasd_device request queue,
  1123. * terminate them on the cdev if necessary, and return them to the
  1124. * submitting layer via callback.
  1125. * Note:
  1126. * Make sure that all 'submitting layers' still exist when
  1127. * this function is called!. In other words, when 'device' is a base
  1128. * device then all block layer requests must have been removed before
  1129. * via dasd_flush_block_queue.
  1130. */
  1131. int dasd_flush_device_queue(struct dasd_device *device)
  1132. {
  1133. struct dasd_ccw_req *cqr, *n;
  1134. int rc;
  1135. struct list_head flush_queue;
  1136. INIT_LIST_HEAD(&flush_queue);
  1137. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1138. rc = 0;
  1139. list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
  1140. /* Check status and move request to flush_queue */
  1141. switch (cqr->status) {
  1142. case DASD_CQR_IN_IO:
  1143. rc = device->discipline->term_IO(cqr);
  1144. if (rc) {
  1145. /* unable to terminate requeust */
  1146. DEV_MESSAGE(KERN_ERR, device,
  1147. "dasd flush ccw_queue is unable "
  1148. " to terminate request %p",
  1149. cqr);
  1150. /* stop flush processing */
  1151. goto finished;
  1152. }
  1153. break;
  1154. case DASD_CQR_QUEUED:
  1155. cqr->stopclk = get_clock();
  1156. cqr->status = DASD_CQR_CLEARED;
  1157. break;
  1158. default: /* no need to modify the others */
  1159. break;
  1160. }
  1161. list_move_tail(&cqr->devlist, &flush_queue);
  1162. }
  1163. finished:
  1164. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1165. /*
  1166. * After this point all requests must be in state CLEAR_PENDING,
  1167. * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
  1168. * one of the others.
  1169. */
  1170. list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
  1171. wait_event(dasd_flush_wq,
  1172. (cqr->status != DASD_CQR_CLEAR_PENDING));
  1173. /*
  1174. * Now set each request back to TERMINATED, DONE or NEED_ERP
  1175. * and call the callback function of flushed requests
  1176. */
  1177. __dasd_device_process_final_queue(device, &flush_queue);
  1178. return rc;
  1179. }
  1180. /*
  1181. * Acquire the device lock and process queues for the device.
  1182. */
  1183. static void dasd_device_tasklet(struct dasd_device *device)
  1184. {
  1185. struct list_head final_queue;
  1186. atomic_set (&device->tasklet_scheduled, 0);
  1187. INIT_LIST_HEAD(&final_queue);
  1188. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1189. /* Check expire time of first request on the ccw queue. */
  1190. __dasd_device_check_expire(device);
  1191. /* find final requests on ccw queue */
  1192. __dasd_device_process_ccw_queue(device, &final_queue);
  1193. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1194. /* Now call the callback function of requests with final status */
  1195. __dasd_device_process_final_queue(device, &final_queue);
  1196. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1197. /* Now check if the head of the ccw queue needs to be started. */
  1198. __dasd_device_start_head(device);
  1199. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1200. dasd_put_device(device);
  1201. }
  1202. /*
  1203. * Schedules a call to dasd_tasklet over the device tasklet.
  1204. */
  1205. void dasd_schedule_device_bh(struct dasd_device *device)
  1206. {
  1207. /* Protect against rescheduling. */
  1208. if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
  1209. return;
  1210. dasd_get_device(device);
  1211. tasklet_hi_schedule(&device->tasklet);
  1212. }
  1213. /*
  1214. * Queue a request to the head of the device ccw_queue.
  1215. * Start the I/O if possible.
  1216. */
  1217. void dasd_add_request_head(struct dasd_ccw_req *cqr)
  1218. {
  1219. struct dasd_device *device;
  1220. unsigned long flags;
  1221. device = cqr->startdev;
  1222. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1223. cqr->status = DASD_CQR_QUEUED;
  1224. list_add(&cqr->devlist, &device->ccw_queue);
  1225. /* let the bh start the request to keep them in order */
  1226. dasd_schedule_device_bh(device);
  1227. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1228. }
  1229. /*
  1230. * Queue a request to the tail of the device ccw_queue.
  1231. * Start the I/O if possible.
  1232. */
  1233. void dasd_add_request_tail(struct dasd_ccw_req *cqr)
  1234. {
  1235. struct dasd_device *device;
  1236. unsigned long flags;
  1237. device = cqr->startdev;
  1238. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1239. cqr->status = DASD_CQR_QUEUED;
  1240. list_add_tail(&cqr->devlist, &device->ccw_queue);
  1241. /* let the bh start the request to keep them in order */
  1242. dasd_schedule_device_bh(device);
  1243. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1244. }
  1245. /*
  1246. * Wakeup helper for the 'sleep_on' functions.
  1247. */
  1248. static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
  1249. {
  1250. wake_up((wait_queue_head_t *) data);
  1251. }
  1252. static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
  1253. {
  1254. struct dasd_device *device;
  1255. int rc;
  1256. device = cqr->startdev;
  1257. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1258. rc = ((cqr->status == DASD_CQR_DONE ||
  1259. cqr->status == DASD_CQR_NEED_ERP ||
  1260. cqr->status == DASD_CQR_TERMINATED) &&
  1261. list_empty(&cqr->devlist));
  1262. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1263. return rc;
  1264. }
  1265. /*
  1266. * Queue a request to the tail of the device ccw_queue and wait for
  1267. * it's completion.
  1268. */
  1269. int dasd_sleep_on(struct dasd_ccw_req *cqr)
  1270. {
  1271. wait_queue_head_t wait_q;
  1272. struct dasd_device *device;
  1273. int rc;
  1274. device = cqr->startdev;
  1275. init_waitqueue_head (&wait_q);
  1276. cqr->callback = dasd_wakeup_cb;
  1277. cqr->callback_data = (void *) &wait_q;
  1278. dasd_add_request_tail(cqr);
  1279. wait_event(wait_q, _wait_for_wakeup(cqr));
  1280. /* Request status is either done or failed. */
  1281. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1282. return rc;
  1283. }
  1284. /*
  1285. * Queue a request to the tail of the device ccw_queue and wait
  1286. * interruptible for it's completion.
  1287. */
  1288. int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
  1289. {
  1290. wait_queue_head_t wait_q;
  1291. struct dasd_device *device;
  1292. int rc;
  1293. device = cqr->startdev;
  1294. init_waitqueue_head (&wait_q);
  1295. cqr->callback = dasd_wakeup_cb;
  1296. cqr->callback_data = (void *) &wait_q;
  1297. dasd_add_request_tail(cqr);
  1298. rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
  1299. if (rc == -ERESTARTSYS) {
  1300. dasd_cancel_req(cqr);
  1301. /* wait (non-interruptible) for final status */
  1302. wait_event(wait_q, _wait_for_wakeup(cqr));
  1303. }
  1304. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1305. return rc;
  1306. }
  1307. /*
  1308. * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
  1309. * for eckd devices) the currently running request has to be terminated
  1310. * and be put back to status queued, before the special request is added
  1311. * to the head of the queue. Then the special request is waited on normally.
  1312. */
  1313. static inline int _dasd_term_running_cqr(struct dasd_device *device)
  1314. {
  1315. struct dasd_ccw_req *cqr;
  1316. if (list_empty(&device->ccw_queue))
  1317. return 0;
  1318. cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
  1319. return device->discipline->term_IO(cqr);
  1320. }
  1321. int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
  1322. {
  1323. wait_queue_head_t wait_q;
  1324. struct dasd_device *device;
  1325. int rc;
  1326. device = cqr->startdev;
  1327. spin_lock_irq(get_ccwdev_lock(device->cdev));
  1328. rc = _dasd_term_running_cqr(device);
  1329. if (rc) {
  1330. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1331. return rc;
  1332. }
  1333. init_waitqueue_head (&wait_q);
  1334. cqr->callback = dasd_wakeup_cb;
  1335. cqr->callback_data = (void *) &wait_q;
  1336. cqr->status = DASD_CQR_QUEUED;
  1337. list_add(&cqr->devlist, &device->ccw_queue);
  1338. /* let the bh start the request to keep them in order */
  1339. dasd_schedule_device_bh(device);
  1340. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  1341. wait_event(wait_q, _wait_for_wakeup(cqr));
  1342. /* Request status is either done or failed. */
  1343. rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
  1344. return rc;
  1345. }
  1346. /*
  1347. * Cancels a request that was started with dasd_sleep_on_req.
  1348. * This is useful to timeout requests. The request will be
  1349. * terminated if it is currently in i/o.
  1350. * Returns 1 if the request has been terminated.
  1351. * 0 if there was no need to terminate the request (not started yet)
  1352. * negative error code if termination failed
  1353. * Cancellation of a request is an asynchronous operation! The calling
  1354. * function has to wait until the request is properly returned via callback.
  1355. */
  1356. int dasd_cancel_req(struct dasd_ccw_req *cqr)
  1357. {
  1358. struct dasd_device *device = cqr->startdev;
  1359. unsigned long flags;
  1360. int rc;
  1361. rc = 0;
  1362. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1363. switch (cqr->status) {
  1364. case DASD_CQR_QUEUED:
  1365. /* request was not started - just set to cleared */
  1366. cqr->status = DASD_CQR_CLEARED;
  1367. break;
  1368. case DASD_CQR_IN_IO:
  1369. /* request in IO - terminate IO and release again */
  1370. rc = device->discipline->term_IO(cqr);
  1371. if (rc) {
  1372. DEV_MESSAGE(KERN_ERR, device,
  1373. "dasd_cancel_req is unable "
  1374. " to terminate request %p, rc = %d",
  1375. cqr, rc);
  1376. } else {
  1377. cqr->stopclk = get_clock();
  1378. rc = 1;
  1379. }
  1380. break;
  1381. default: /* already finished or clear pending - do nothing */
  1382. break;
  1383. }
  1384. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1385. dasd_schedule_device_bh(device);
  1386. return rc;
  1387. }
  1388. /*
  1389. * SECTION: Operations of the dasd_block layer.
  1390. */
  1391. /*
  1392. * Timeout function for dasd_block. This is used when the block layer
  1393. * is waiting for something that may not come reliably, (e.g. a state
  1394. * change interrupt)
  1395. */
  1396. static void dasd_block_timeout(unsigned long ptr)
  1397. {
  1398. unsigned long flags;
  1399. struct dasd_block *block;
  1400. block = (struct dasd_block *) ptr;
  1401. spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
  1402. /* re-activate request queue */
  1403. block->base->stopped &= ~DASD_STOPPED_PENDING;
  1404. spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
  1405. dasd_schedule_block_bh(block);
  1406. }
  1407. /*
  1408. * Setup timeout for a dasd_block in jiffies.
  1409. */
  1410. void dasd_block_set_timer(struct dasd_block *block, int expires)
  1411. {
  1412. if (expires == 0) {
  1413. if (timer_pending(&block->timer))
  1414. del_timer(&block->timer);
  1415. return;
  1416. }
  1417. if (timer_pending(&block->timer)) {
  1418. if (mod_timer(&block->timer, jiffies + expires))
  1419. return;
  1420. }
  1421. block->timer.function = dasd_block_timeout;
  1422. block->timer.data = (unsigned long) block;
  1423. block->timer.expires = jiffies + expires;
  1424. add_timer(&block->timer);
  1425. }
  1426. /*
  1427. * Clear timeout for a dasd_block.
  1428. */
  1429. void dasd_block_clear_timer(struct dasd_block *block)
  1430. {
  1431. if (timer_pending(&block->timer))
  1432. del_timer(&block->timer);
  1433. }
  1434. /*
  1435. * posts the buffer_cache about a finalized request
  1436. */
  1437. static inline void dasd_end_request(struct request *req, int uptodate)
  1438. {
  1439. if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
  1440. BUG();
  1441. add_disk_randomness(req->rq_disk);
  1442. end_that_request_last(req, uptodate);
  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, 0);
  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, 0);
  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. req = (struct request *) cqr->callback_data;
  1541. dasd_profile_end(cqr->block, cqr, req);
  1542. status = cqr->memdev->discipline->free_cp(cqr, req);
  1543. dasd_end_request(req, status);
  1544. }
  1545. /*
  1546. * Process ccw request queue.
  1547. */
  1548. static void __dasd_process_block_ccw_queue(struct dasd_block *block,
  1549. struct list_head *final_queue)
  1550. {
  1551. struct list_head *l, *n;
  1552. struct dasd_ccw_req *cqr;
  1553. dasd_erp_fn_t erp_fn;
  1554. unsigned long flags;
  1555. struct dasd_device *base = block->base;
  1556. restart:
  1557. /* Process request with final status. */
  1558. list_for_each_safe(l, n, &block->ccw_queue) {
  1559. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1560. if (cqr->status != DASD_CQR_DONE &&
  1561. cqr->status != DASD_CQR_FAILED &&
  1562. cqr->status != DASD_CQR_NEED_ERP &&
  1563. cqr->status != DASD_CQR_TERMINATED)
  1564. continue;
  1565. if (cqr->status == DASD_CQR_TERMINATED) {
  1566. base->discipline->handle_terminated_request(cqr);
  1567. goto restart;
  1568. }
  1569. /* Process requests that may be recovered */
  1570. if (cqr->status == DASD_CQR_NEED_ERP) {
  1571. if (cqr->irb.esw.esw0.erw.cons &&
  1572. test_bit(DASD_CQR_FLAGS_USE_ERP,
  1573. &cqr->flags)) {
  1574. erp_fn = base->discipline->erp_action(cqr);
  1575. erp_fn(cqr);
  1576. }
  1577. goto restart;
  1578. }
  1579. /* First of all call extended error reporting. */
  1580. if (dasd_eer_enabled(base) &&
  1581. cqr->status == DASD_CQR_FAILED) {
  1582. dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
  1583. /* restart request */
  1584. cqr->status = DASD_CQR_FILLED;
  1585. cqr->retries = 255;
  1586. spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
  1587. base->stopped |= DASD_STOPPED_QUIESCE;
  1588. spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
  1589. flags);
  1590. goto restart;
  1591. }
  1592. /* Process finished ERP request. */
  1593. if (cqr->refers) {
  1594. __dasd_block_process_erp(block, cqr);
  1595. goto restart;
  1596. }
  1597. /* Rechain finished requests to final queue */
  1598. cqr->endclk = get_clock();
  1599. list_move_tail(&cqr->blocklist, final_queue);
  1600. }
  1601. }
  1602. static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
  1603. {
  1604. dasd_schedule_block_bh(cqr->block);
  1605. }
  1606. static void __dasd_block_start_head(struct dasd_block *block)
  1607. {
  1608. struct dasd_ccw_req *cqr;
  1609. if (list_empty(&block->ccw_queue))
  1610. return;
  1611. /* We allways begin with the first requests on the queue, as some
  1612. * of previously started requests have to be enqueued on a
  1613. * dasd_device again for error recovery.
  1614. */
  1615. list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
  1616. if (cqr->status != DASD_CQR_FILLED)
  1617. continue;
  1618. /* Non-temporary stop condition will trigger fail fast */
  1619. if (block->base->stopped & ~DASD_STOPPED_PENDING &&
  1620. test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
  1621. (!dasd_eer_enabled(block->base))) {
  1622. cqr->status = DASD_CQR_FAILED;
  1623. dasd_schedule_block_bh(block);
  1624. continue;
  1625. }
  1626. /* Don't try to start requests if device is stopped */
  1627. if (block->base->stopped)
  1628. return;
  1629. /* just a fail safe check, should not happen */
  1630. if (!cqr->startdev)
  1631. cqr->startdev = block->base;
  1632. /* make sure that the requests we submit find their way back */
  1633. cqr->callback = dasd_return_cqr_cb;
  1634. dasd_add_request_tail(cqr);
  1635. }
  1636. }
  1637. /*
  1638. * Central dasd_block layer routine. Takes requests from the generic
  1639. * block layer request queue, creates ccw requests, enqueues them on
  1640. * a dasd_device and processes ccw requests that have been returned.
  1641. */
  1642. static void dasd_block_tasklet(struct dasd_block *block)
  1643. {
  1644. struct list_head final_queue;
  1645. struct list_head *l, *n;
  1646. struct dasd_ccw_req *cqr;
  1647. atomic_set(&block->tasklet_scheduled, 0);
  1648. INIT_LIST_HEAD(&final_queue);
  1649. spin_lock(&block->queue_lock);
  1650. /* Finish off requests on ccw queue */
  1651. __dasd_process_block_ccw_queue(block, &final_queue);
  1652. spin_unlock(&block->queue_lock);
  1653. /* Now call the callback function of requests with final status */
  1654. spin_lock_irq(&block->request_queue_lock);
  1655. list_for_each_safe(l, n, &final_queue) {
  1656. cqr = list_entry(l, struct dasd_ccw_req, blocklist);
  1657. list_del_init(&cqr->blocklist);
  1658. __dasd_cleanup_cqr(cqr);
  1659. }
  1660. spin_lock(&block->queue_lock);
  1661. /* Get new request from the block device request queue */
  1662. __dasd_process_request_queue(block);
  1663. /* Now check if the head of the ccw queue needs to be started. */
  1664. __dasd_block_start_head(block);
  1665. spin_unlock(&block->queue_lock);
  1666. spin_unlock_irq(&block->request_queue_lock);
  1667. dasd_put_device(block->base);
  1668. }
  1669. static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
  1670. {
  1671. wake_up(&dasd_flush_wq);
  1672. }
  1673. /*
  1674. * Go through all request on the dasd_block request queue, cancel them
  1675. * on the respective dasd_device, and return them to the generic
  1676. * block layer.
  1677. */
  1678. static int dasd_flush_block_queue(struct dasd_block *block)
  1679. {
  1680. struct dasd_ccw_req *cqr, *n;
  1681. int rc, i;
  1682. struct list_head flush_queue;
  1683. INIT_LIST_HEAD(&flush_queue);
  1684. spin_lock_bh(&block->queue_lock);
  1685. rc = 0;
  1686. restart:
  1687. list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
  1688. /* if this request currently owned by a dasd_device cancel it */
  1689. if (cqr->status >= DASD_CQR_QUEUED)
  1690. rc = dasd_cancel_req(cqr);
  1691. if (rc < 0)
  1692. break;
  1693. /* Rechain request (including erp chain) so it won't be
  1694. * touched by the dasd_block_tasklet anymore.
  1695. * Replace the callback so we notice when the request
  1696. * is returned from the dasd_device layer.
  1697. */
  1698. cqr->callback = _dasd_wake_block_flush_cb;
  1699. for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
  1700. list_move_tail(&cqr->blocklist, &flush_queue);
  1701. if (i > 1)
  1702. /* moved more than one request - need to restart */
  1703. goto restart;
  1704. }
  1705. spin_unlock_bh(&block->queue_lock);
  1706. /* Now call the callback function of flushed requests */
  1707. restart_cb:
  1708. list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
  1709. wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
  1710. /* Process finished ERP request. */
  1711. if (cqr->refers) {
  1712. __dasd_block_process_erp(block, cqr);
  1713. /* restart list_for_xx loop since dasd_process_erp
  1714. * might remove multiple elements */
  1715. goto restart_cb;
  1716. }
  1717. /* call the callback function */
  1718. cqr->endclk = get_clock();
  1719. list_del_init(&cqr->blocklist);
  1720. __dasd_cleanup_cqr(cqr);
  1721. }
  1722. return rc;
  1723. }
  1724. /*
  1725. * Schedules a call to dasd_tasklet over the device tasklet.
  1726. */
  1727. void dasd_schedule_block_bh(struct dasd_block *block)
  1728. {
  1729. /* Protect against rescheduling. */
  1730. if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
  1731. return;
  1732. /* life cycle of block is bound to it's base device */
  1733. dasd_get_device(block->base);
  1734. tasklet_hi_schedule(&block->tasklet);
  1735. }
  1736. /*
  1737. * SECTION: external block device operations
  1738. * (request queue handling, open, release, etc.)
  1739. */
  1740. /*
  1741. * Dasd request queue function. Called from ll_rw_blk.c
  1742. */
  1743. static void do_dasd_request(struct request_queue *queue)
  1744. {
  1745. struct dasd_block *block;
  1746. block = queue->queuedata;
  1747. spin_lock(&block->queue_lock);
  1748. /* Get new request from the block device request queue */
  1749. __dasd_process_request_queue(block);
  1750. /* Now check if the head of the ccw queue needs to be started. */
  1751. __dasd_block_start_head(block);
  1752. spin_unlock(&block->queue_lock);
  1753. }
  1754. /*
  1755. * Allocate and initialize request queue and default I/O scheduler.
  1756. */
  1757. static int dasd_alloc_queue(struct dasd_block *block)
  1758. {
  1759. int rc;
  1760. block->request_queue = blk_init_queue(do_dasd_request,
  1761. &block->request_queue_lock);
  1762. if (block->request_queue == NULL)
  1763. return -ENOMEM;
  1764. block->request_queue->queuedata = block;
  1765. elevator_exit(block->request_queue->elevator);
  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, 0);
  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. struct dasd_block *block = device->block;
  2070. max_count = block->bdev ? 0 : -1;
  2071. open_count = (int) atomic_read(&block->open_count);
  2072. if (open_count > max_count) {
  2073. if (open_count > 0)
  2074. printk(KERN_WARNING "Can't offline dasd "
  2075. "device with open count = %i.\n",
  2076. open_count);
  2077. else
  2078. printk(KERN_WARNING "%s",
  2079. "Can't offline dasd device due "
  2080. "to internal use\n");
  2081. clear_bit(DASD_FLAG_OFFLINE, &device->flags);
  2082. dasd_put_device(device);
  2083. return -EBUSY;
  2084. }
  2085. }
  2086. dasd_set_target_state(device, DASD_STATE_NEW);
  2087. /* dasd_delete_device destroys the device reference. */
  2088. block = device->block;
  2089. device->block = NULL;
  2090. dasd_delete_device(device);
  2091. /*
  2092. * life cycle of block is bound to device, so delete it after
  2093. * device was safely removed
  2094. */
  2095. if (block)
  2096. dasd_free_block(block);
  2097. return 0;
  2098. }
  2099. int dasd_generic_notify(struct ccw_device *cdev, int event)
  2100. {
  2101. struct dasd_device *device;
  2102. struct dasd_ccw_req *cqr;
  2103. unsigned long flags;
  2104. int ret;
  2105. device = dasd_device_from_cdev(cdev);
  2106. if (IS_ERR(device))
  2107. return 0;
  2108. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  2109. ret = 0;
  2110. switch (event) {
  2111. case CIO_GONE:
  2112. case CIO_NO_PATH:
  2113. /* First of all call extended error reporting. */
  2114. dasd_eer_write(device, NULL, DASD_EER_NOPATH);
  2115. if (device->state < DASD_STATE_BASIC)
  2116. break;
  2117. /* Device is active. We want to keep it. */
  2118. list_for_each_entry(cqr, &device->ccw_queue, devlist)
  2119. if (cqr->status == DASD_CQR_IN_IO) {
  2120. cqr->status = DASD_CQR_QUEUED;
  2121. cqr->retries++;
  2122. }
  2123. device->stopped |= DASD_STOPPED_DC_WAIT;
  2124. dasd_device_clear_timer(device);
  2125. dasd_schedule_device_bh(device);
  2126. ret = 1;
  2127. break;
  2128. case CIO_OPER:
  2129. /* FIXME: add a sanity check. */
  2130. device->stopped &= ~DASD_STOPPED_DC_WAIT;
  2131. dasd_schedule_device_bh(device);
  2132. if (device->block)
  2133. dasd_schedule_block_bh(device->block);
  2134. ret = 1;
  2135. break;
  2136. }
  2137. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  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. /* register 'common' DASD debug area, used for all DBF_XXX calls */
  2187. dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
  2188. if (dasd_debug_area == NULL) {
  2189. rc = -ENOMEM;
  2190. goto failed;
  2191. }
  2192. debug_register_view(dasd_debug_area, &debug_sprintf_view);
  2193. debug_set_level(dasd_debug_area, DBF_WARNING);
  2194. DBF_EVENT(DBF_EMERG, "%s", "debug area created");
  2195. dasd_diag_discipline_pointer = NULL;
  2196. rc = dasd_devmap_init();
  2197. if (rc)
  2198. goto failed;
  2199. rc = dasd_gendisk_init();
  2200. if (rc)
  2201. goto failed;
  2202. rc = dasd_parse();
  2203. if (rc)
  2204. goto failed;
  2205. rc = dasd_eer_init();
  2206. if (rc)
  2207. goto failed;
  2208. #ifdef CONFIG_PROC_FS
  2209. rc = dasd_proc_init();
  2210. if (rc)
  2211. goto failed;
  2212. #endif
  2213. return 0;
  2214. failed:
  2215. MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
  2216. dasd_exit();
  2217. return rc;
  2218. }
  2219. module_init(dasd_init);
  2220. module_exit(dasd_exit);
  2221. EXPORT_SYMBOL(dasd_debug_area);
  2222. EXPORT_SYMBOL(dasd_diag_discipline_pointer);
  2223. EXPORT_SYMBOL(dasd_add_request_head);
  2224. EXPORT_SYMBOL(dasd_add_request_tail);
  2225. EXPORT_SYMBOL(dasd_cancel_req);
  2226. EXPORT_SYMBOL(dasd_device_clear_timer);
  2227. EXPORT_SYMBOL(dasd_block_clear_timer);
  2228. EXPORT_SYMBOL(dasd_enable_device);
  2229. EXPORT_SYMBOL(dasd_int_handler);
  2230. EXPORT_SYMBOL(dasd_kfree_request);
  2231. EXPORT_SYMBOL(dasd_kick_device);
  2232. EXPORT_SYMBOL(dasd_kmalloc_request);
  2233. EXPORT_SYMBOL(dasd_schedule_device_bh);
  2234. EXPORT_SYMBOL(dasd_schedule_block_bh);
  2235. EXPORT_SYMBOL(dasd_set_target_state);
  2236. EXPORT_SYMBOL(dasd_device_set_timer);
  2237. EXPORT_SYMBOL(dasd_block_set_timer);
  2238. EXPORT_SYMBOL(dasd_sfree_request);
  2239. EXPORT_SYMBOL(dasd_sleep_on);
  2240. EXPORT_SYMBOL(dasd_sleep_on_immediatly);
  2241. EXPORT_SYMBOL(dasd_sleep_on_interruptible);
  2242. EXPORT_SYMBOL(dasd_smalloc_request);
  2243. EXPORT_SYMBOL(dasd_start_IO);
  2244. EXPORT_SYMBOL(dasd_term_IO);
  2245. EXPORT_SYMBOL_GPL(dasd_generic_probe);
  2246. EXPORT_SYMBOL_GPL(dasd_generic_remove);
  2247. EXPORT_SYMBOL_GPL(dasd_generic_notify);
  2248. EXPORT_SYMBOL_GPL(dasd_generic_set_online);
  2249. EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
  2250. EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
  2251. EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
  2252. EXPORT_SYMBOL_GPL(dasd_alloc_block);
  2253. EXPORT_SYMBOL_GPL(dasd_free_block);