dasd.c 68 KB

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