dasd_diag.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Based on.......: linux/drivers/s390/block/mdisk.c
  5. * ...............: by Hartmunt Penner <hpenner@de.ibm.com>
  6. * Bugreports.to..: <Linux390@de.ibm.com>
  7. * Copyright IBM Corp. 1999, 2000
  8. *
  9. */
  10. #define KMSG_COMPONENT "dasd"
  11. #include <linux/kernel_stat.h>
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/hdreg.h>
  16. #include <linux/bio.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/jiffies.h>
  20. #include <asm/dasd.h>
  21. #include <asm/debug.h>
  22. #include <asm/diag.h>
  23. #include <asm/ebcdic.h>
  24. #include <asm/io.h>
  25. #include <asm/irq.h>
  26. #include <asm/vtoc.h>
  27. #include "dasd_int.h"
  28. #include "dasd_diag.h"
  29. #define PRINTK_HEADER "dasd(diag):"
  30. MODULE_LICENSE("GPL");
  31. /* The maximum number of blocks per request (max_blocks) is dependent on the
  32. * amount of storage that is available in the static I/O buffer for each
  33. * device. Currently each device gets 2 pages. We want to fit two requests
  34. * into the available memory so that we can immediately start the next if one
  35. * finishes. */
  36. #define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \
  37. sizeof(struct dasd_diag_req)) / \
  38. sizeof(struct dasd_diag_bio)) / 2)
  39. #define DIAG_MAX_RETRIES 32
  40. #define DIAG_TIMEOUT 50
  41. static struct dasd_discipline dasd_diag_discipline;
  42. struct dasd_diag_private {
  43. struct dasd_diag_characteristics rdc_data;
  44. struct dasd_diag_rw_io iob;
  45. struct dasd_diag_init_io iib;
  46. blocknum_t pt_block;
  47. struct ccw_dev_id dev_id;
  48. };
  49. struct dasd_diag_req {
  50. unsigned int block_count;
  51. struct dasd_diag_bio bio[];
  52. };
  53. static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */
  54. /* Perform DIAG250 call with block I/O parameter list iob (input and output)
  55. * and function code cmd.
  56. * In case of an exception return 3. Otherwise return result of bitwise OR of
  57. * resulting condition code and DIAG return code. */
  58. static inline int __dia250(void *iob, int cmd)
  59. {
  60. register unsigned long reg2 asm ("2") = (unsigned long) iob;
  61. typedef union {
  62. struct dasd_diag_init_io init_io;
  63. struct dasd_diag_rw_io rw_io;
  64. } addr_type;
  65. int rc;
  66. rc = 3;
  67. asm volatile(
  68. " diag 2,%2,0x250\n"
  69. "0: ipm %0\n"
  70. " srl %0,28\n"
  71. " or %0,3\n"
  72. "1:\n"
  73. EX_TABLE(0b,1b)
  74. : "+d" (rc), "=m" (*(addr_type *) iob)
  75. : "d" (cmd), "d" (reg2), "m" (*(addr_type *) iob)
  76. : "3", "cc");
  77. return rc;
  78. }
  79. static inline int dia250(void *iob, int cmd)
  80. {
  81. diag_stat_inc(DIAG_STAT_X250);
  82. return __dia250(iob, cmd);
  83. }
  84. /* Initialize block I/O to DIAG device using the specified blocksize and
  85. * block offset. On success, return zero and set end_block to contain the
  86. * number of blocks on the device minus the specified offset. Return non-zero
  87. * otherwise. */
  88. static inline int
  89. mdsk_init_io(struct dasd_device *device, unsigned int blocksize,
  90. blocknum_t offset, blocknum_t *end_block)
  91. {
  92. struct dasd_diag_private *private = device->private;
  93. struct dasd_diag_init_io *iib = &private->iib;
  94. int rc;
  95. memset(iib, 0, sizeof (struct dasd_diag_init_io));
  96. iib->dev_nr = private->dev_id.devno;
  97. iib->block_size = blocksize;
  98. iib->offset = offset;
  99. iib->flaga = DASD_DIAG_FLAGA_DEFAULT;
  100. rc = dia250(iib, INIT_BIO);
  101. if ((rc & 3) == 0 && end_block)
  102. *end_block = iib->end_block;
  103. return rc;
  104. }
  105. /* Remove block I/O environment for device. Return zero on success, non-zero
  106. * otherwise. */
  107. static inline int
  108. mdsk_term_io(struct dasd_device * device)
  109. {
  110. struct dasd_diag_private *private = device->private;
  111. struct dasd_diag_init_io *iib = &private->iib;
  112. int rc;
  113. memset(iib, 0, sizeof (struct dasd_diag_init_io));
  114. iib->dev_nr = private->dev_id.devno;
  115. rc = dia250(iib, TERM_BIO);
  116. return rc;
  117. }
  118. /* Error recovery for failed DIAG requests - try to reestablish the DIAG
  119. * environment. */
  120. static void
  121. dasd_diag_erp(struct dasd_device *device)
  122. {
  123. int rc;
  124. mdsk_term_io(device);
  125. rc = mdsk_init_io(device, device->block->bp_block, 0, NULL);
  126. if (rc == 4) {
  127. if (!(test_and_set_bit(DASD_FLAG_DEVICE_RO, &device->flags)))
  128. pr_warn("%s: The access mode of a DIAG device changed to read-only\n",
  129. dev_name(&device->cdev->dev));
  130. rc = 0;
  131. }
  132. if (rc)
  133. pr_warn("%s: DIAG ERP failed with rc=%d\n",
  134. dev_name(&device->cdev->dev), rc);
  135. }
  136. /* Start a given request at the device. Return zero on success, non-zero
  137. * otherwise. */
  138. static int
  139. dasd_start_diag(struct dasd_ccw_req * cqr)
  140. {
  141. struct dasd_device *device;
  142. struct dasd_diag_private *private;
  143. struct dasd_diag_req *dreq;
  144. int rc;
  145. device = cqr->startdev;
  146. if (cqr->retries < 0) {
  147. DBF_DEV_EVENT(DBF_ERR, device, "DIAG start_IO: request %p "
  148. "- no retry left)", cqr);
  149. cqr->status = DASD_CQR_ERROR;
  150. return -EIO;
  151. }
  152. private = device->private;
  153. dreq = cqr->data;
  154. private->iob.dev_nr = private->dev_id.devno;
  155. private->iob.key = 0;
  156. private->iob.flags = DASD_DIAG_RWFLAG_ASYNC;
  157. private->iob.block_count = dreq->block_count;
  158. private->iob.interrupt_params = (addr_t) cqr;
  159. private->iob.bio_list = dreq->bio;
  160. private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
  161. cqr->startclk = get_tod_clock();
  162. cqr->starttime = jiffies;
  163. cqr->retries--;
  164. rc = dia250(&private->iob, RW_BIO);
  165. switch (rc) {
  166. case 0: /* Synchronous I/O finished successfully */
  167. cqr->stopclk = get_tod_clock();
  168. cqr->status = DASD_CQR_SUCCESS;
  169. /* Indicate to calling function that only a dasd_schedule_bh()
  170. and no timer is needed */
  171. rc = -EACCES;
  172. break;
  173. case 8: /* Asynchronous I/O was started */
  174. cqr->status = DASD_CQR_IN_IO;
  175. rc = 0;
  176. break;
  177. default: /* Error condition */
  178. cqr->status = DASD_CQR_QUEUED;
  179. DBF_DEV_EVENT(DBF_WARNING, device, "dia250 returned rc=%d", rc);
  180. dasd_diag_erp(device);
  181. rc = -EIO;
  182. break;
  183. }
  184. cqr->intrc = rc;
  185. return rc;
  186. }
  187. /* Terminate given request at the device. */
  188. static int
  189. dasd_diag_term_IO(struct dasd_ccw_req * cqr)
  190. {
  191. struct dasd_device *device;
  192. device = cqr->startdev;
  193. mdsk_term_io(device);
  194. mdsk_init_io(device, device->block->bp_block, 0, NULL);
  195. cqr->status = DASD_CQR_CLEAR_PENDING;
  196. cqr->stopclk = get_tod_clock();
  197. dasd_schedule_device_bh(device);
  198. return 0;
  199. }
  200. /* Handle external interruption. */
  201. static void dasd_ext_handler(struct ext_code ext_code,
  202. unsigned int param32, unsigned long param64)
  203. {
  204. struct dasd_ccw_req *cqr, *next;
  205. struct dasd_device *device;
  206. unsigned long expires;
  207. unsigned long flags;
  208. addr_t ip;
  209. int rc;
  210. switch (ext_code.subcode >> 8) {
  211. case DASD_DIAG_CODE_31BIT:
  212. ip = (addr_t) param32;
  213. break;
  214. case DASD_DIAG_CODE_64BIT:
  215. ip = (addr_t) param64;
  216. break;
  217. default:
  218. return;
  219. }
  220. inc_irq_stat(IRQEXT_DSD);
  221. if (!ip) { /* no intparm: unsolicited interrupt */
  222. DBF_EVENT(DBF_NOTICE, "%s", "caught unsolicited "
  223. "interrupt");
  224. return;
  225. }
  226. cqr = (struct dasd_ccw_req *) ip;
  227. device = (struct dasd_device *) cqr->startdev;
  228. if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
  229. DBF_DEV_EVENT(DBF_WARNING, device,
  230. " magic number of dasd_ccw_req 0x%08X doesn't"
  231. " match discipline 0x%08X",
  232. cqr->magic, *(int *) (&device->discipline->name));
  233. return;
  234. }
  235. /* get irq lock to modify request queue */
  236. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  237. /* Check for a pending clear operation */
  238. if (cqr->status == DASD_CQR_CLEAR_PENDING) {
  239. cqr->status = DASD_CQR_CLEARED;
  240. dasd_device_clear_timer(device);
  241. dasd_schedule_device_bh(device);
  242. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  243. return;
  244. }
  245. cqr->stopclk = get_tod_clock();
  246. expires = 0;
  247. if ((ext_code.subcode & 0xff) == 0) {
  248. cqr->status = DASD_CQR_SUCCESS;
  249. /* Start first request on queue if possible -> fast_io. */
  250. if (!list_empty(&device->ccw_queue)) {
  251. next = list_entry(device->ccw_queue.next,
  252. struct dasd_ccw_req, devlist);
  253. if (next->status == DASD_CQR_QUEUED) {
  254. rc = dasd_start_diag(next);
  255. if (rc == 0)
  256. expires = next->expires;
  257. }
  258. }
  259. } else {
  260. cqr->status = DASD_CQR_QUEUED;
  261. DBF_DEV_EVENT(DBF_DEBUG, device, "interrupt status for "
  262. "request %p was %d (%d retries left)", cqr,
  263. ext_code.subcode & 0xff, cqr->retries);
  264. dasd_diag_erp(device);
  265. }
  266. if (expires != 0)
  267. dasd_device_set_timer(device, expires);
  268. else
  269. dasd_device_clear_timer(device);
  270. dasd_schedule_device_bh(device);
  271. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  272. }
  273. /* Check whether device can be controlled by DIAG discipline. Return zero on
  274. * success, non-zero otherwise. */
  275. static int
  276. dasd_diag_check_device(struct dasd_device *device)
  277. {
  278. struct dasd_diag_private *private = device->private;
  279. struct dasd_diag_characteristics *rdc_data;
  280. struct vtoc_cms_label *label;
  281. struct dasd_block *block;
  282. struct dasd_diag_bio *bio;
  283. unsigned int sb, bsize;
  284. blocknum_t end_block;
  285. int rc;
  286. if (private == NULL) {
  287. private = kzalloc(sizeof(*private), GFP_KERNEL);
  288. if (private == NULL) {
  289. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  290. "Allocating memory for private DASD data "
  291. "failed\n");
  292. return -ENOMEM;
  293. }
  294. ccw_device_get_id(device->cdev, &private->dev_id);
  295. device->private = private;
  296. }
  297. block = dasd_alloc_block();
  298. if (IS_ERR(block)) {
  299. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  300. "could not allocate dasd block structure");
  301. device->private = NULL;
  302. kfree(private);
  303. return PTR_ERR(block);
  304. }
  305. device->block = block;
  306. block->base = device;
  307. /* Read Device Characteristics */
  308. rdc_data = &private->rdc_data;
  309. rdc_data->dev_nr = private->dev_id.devno;
  310. rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics);
  311. rc = diag210((struct diag210 *) rdc_data);
  312. if (rc) {
  313. DBF_DEV_EVENT(DBF_WARNING, device, "failed to retrieve device "
  314. "information (rc=%d)", rc);
  315. rc = -EOPNOTSUPP;
  316. goto out;
  317. }
  318. device->default_expires = DIAG_TIMEOUT;
  319. device->default_retries = DIAG_MAX_RETRIES;
  320. /* Figure out position of label block */
  321. switch (private->rdc_data.vdev_class) {
  322. case DEV_CLASS_FBA:
  323. private->pt_block = 1;
  324. break;
  325. case DEV_CLASS_ECKD:
  326. private->pt_block = 2;
  327. break;
  328. default:
  329. pr_warn("%s: Device type %d is not supported in DIAG mode\n",
  330. dev_name(&device->cdev->dev),
  331. private->rdc_data.vdev_class);
  332. rc = -EOPNOTSUPP;
  333. goto out;
  334. }
  335. DBF_DEV_EVENT(DBF_INFO, device,
  336. "%04X: %04X on real %04X/%02X",
  337. rdc_data->dev_nr,
  338. rdc_data->vdev_type,
  339. rdc_data->rdev_type, rdc_data->rdev_model);
  340. /* terminate all outstanding operations */
  341. mdsk_term_io(device);
  342. /* figure out blocksize of device */
  343. label = (struct vtoc_cms_label *) get_zeroed_page(GFP_KERNEL);
  344. if (label == NULL) {
  345. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  346. "No memory to allocate initialization request");
  347. rc = -ENOMEM;
  348. goto out;
  349. }
  350. bio = kzalloc(sizeof(*bio), GFP_KERNEL);
  351. if (bio == NULL) {
  352. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  353. "No memory to allocate initialization bio");
  354. rc = -ENOMEM;
  355. goto out_label;
  356. }
  357. rc = 0;
  358. end_block = 0;
  359. /* try all sizes - needed for ECKD devices */
  360. for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) {
  361. mdsk_init_io(device, bsize, 0, &end_block);
  362. memset(bio, 0, sizeof(*bio));
  363. bio->type = MDSK_READ_REQ;
  364. bio->block_number = private->pt_block + 1;
  365. bio->buffer = label;
  366. memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io));
  367. private->iob.dev_nr = rdc_data->dev_nr;
  368. private->iob.key = 0;
  369. private->iob.flags = 0; /* do synchronous io */
  370. private->iob.block_count = 1;
  371. private->iob.interrupt_params = 0;
  372. private->iob.bio_list = bio;
  373. private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
  374. rc = dia250(&private->iob, RW_BIO);
  375. if (rc == 3) {
  376. pr_warn("%s: A 64-bit DIAG call failed\n",
  377. dev_name(&device->cdev->dev));
  378. rc = -EOPNOTSUPP;
  379. goto out_bio;
  380. }
  381. mdsk_term_io(device);
  382. if (rc == 0)
  383. break;
  384. }
  385. if (bsize > PAGE_SIZE) {
  386. pr_warn("%s: Accessing the DASD failed because of an incorrect format (rc=%d)\n",
  387. dev_name(&device->cdev->dev), rc);
  388. rc = -EIO;
  389. goto out_bio;
  390. }
  391. /* check for label block */
  392. if (memcmp(label->label_id, DASD_DIAG_CMS1,
  393. sizeof(DASD_DIAG_CMS1)) == 0) {
  394. /* get formatted blocksize from label block */
  395. bsize = (unsigned int) label->block_size;
  396. block->blocks = (unsigned long) label->block_count;
  397. } else
  398. block->blocks = end_block;
  399. block->bp_block = bsize;
  400. block->s2b_shift = 0; /* bits to shift 512 to get a block */
  401. for (sb = 512; sb < bsize; sb = sb << 1)
  402. block->s2b_shift++;
  403. rc = mdsk_init_io(device, block->bp_block, 0, NULL);
  404. if (rc && (rc != 4)) {
  405. pr_warn("%s: DIAG initialization failed with rc=%d\n",
  406. dev_name(&device->cdev->dev), rc);
  407. rc = -EIO;
  408. } else {
  409. if (rc == 4)
  410. set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  411. pr_info("%s: New DASD with %ld byte/block, total size %ld "
  412. "KB%s\n", dev_name(&device->cdev->dev),
  413. (unsigned long) block->bp_block,
  414. (unsigned long) (block->blocks <<
  415. block->s2b_shift) >> 1,
  416. (rc == 4) ? ", read-only device" : "");
  417. rc = 0;
  418. }
  419. out_bio:
  420. kfree(bio);
  421. out_label:
  422. free_page((long) label);
  423. out:
  424. if (rc) {
  425. device->block = NULL;
  426. dasd_free_block(block);
  427. device->private = NULL;
  428. kfree(private);
  429. }
  430. return rc;
  431. }
  432. /* Fill in virtual disk geometry for device. Return zero on success, non-zero
  433. * otherwise. */
  434. static int
  435. dasd_diag_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
  436. {
  437. if (dasd_check_blocksize(block->bp_block) != 0)
  438. return -EINVAL;
  439. geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
  440. geo->heads = 16;
  441. geo->sectors = 128 >> block->s2b_shift;
  442. return 0;
  443. }
  444. static dasd_erp_fn_t
  445. dasd_diag_erp_action(struct dasd_ccw_req * cqr)
  446. {
  447. return dasd_default_erp_action;
  448. }
  449. static dasd_erp_fn_t
  450. dasd_diag_erp_postaction(struct dasd_ccw_req * cqr)
  451. {
  452. return dasd_default_erp_postaction;
  453. }
  454. /* Create DASD request from block device request. Return pointer to new
  455. * request on success, ERR_PTR otherwise. */
  456. static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev,
  457. struct dasd_block *block,
  458. struct request *req)
  459. {
  460. struct dasd_ccw_req *cqr;
  461. struct dasd_diag_req *dreq;
  462. struct dasd_diag_bio *dbio;
  463. struct req_iterator iter;
  464. struct bio_vec bv;
  465. char *dst;
  466. unsigned int count;
  467. sector_t recid, first_rec, last_rec;
  468. unsigned int blksize, off;
  469. unsigned char rw_cmd;
  470. if (rq_data_dir(req) == READ)
  471. rw_cmd = MDSK_READ_REQ;
  472. else if (rq_data_dir(req) == WRITE)
  473. rw_cmd = MDSK_WRITE_REQ;
  474. else
  475. return ERR_PTR(-EINVAL);
  476. blksize = block->bp_block;
  477. /* Calculate record id of first and last block. */
  478. first_rec = blk_rq_pos(req) >> block->s2b_shift;
  479. last_rec =
  480. (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
  481. /* Check struct bio and count the number of blocks for the request. */
  482. count = 0;
  483. rq_for_each_segment(bv, req, iter) {
  484. if (bv.bv_len & (blksize - 1))
  485. /* Fba can only do full blocks. */
  486. return ERR_PTR(-EINVAL);
  487. count += bv.bv_len >> (block->s2b_shift + 9);
  488. }
  489. /* Paranoia. */
  490. if (count != last_rec - first_rec + 1)
  491. return ERR_PTR(-EINVAL);
  492. /* Build the request */
  493. cqr = dasd_smalloc_request(DASD_DIAG_MAGIC, 0, struct_size(dreq, bio, count),
  494. memdev, blk_mq_rq_to_pdu(req));
  495. if (IS_ERR(cqr))
  496. return cqr;
  497. dreq = (struct dasd_diag_req *) cqr->data;
  498. dreq->block_count = count;
  499. dbio = dreq->bio;
  500. recid = first_rec;
  501. rq_for_each_segment(bv, req, iter) {
  502. dst = page_address(bv.bv_page) + bv.bv_offset;
  503. for (off = 0; off < bv.bv_len; off += blksize) {
  504. memset(dbio, 0, sizeof (struct dasd_diag_bio));
  505. dbio->type = rw_cmd;
  506. dbio->block_number = recid + 1;
  507. dbio->buffer = dst;
  508. dbio++;
  509. dst += blksize;
  510. recid++;
  511. }
  512. }
  513. cqr->retries = memdev->default_retries;
  514. cqr->buildclk = get_tod_clock();
  515. if (blk_noretry_request(req) ||
  516. block->base->features & DASD_FEATURE_FAILFAST)
  517. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  518. cqr->startdev = memdev;
  519. cqr->memdev = memdev;
  520. cqr->block = block;
  521. cqr->expires = memdev->default_expires * HZ;
  522. cqr->status = DASD_CQR_FILLED;
  523. return cqr;
  524. }
  525. /* Release DASD request. Return non-zero if request was successful, zero
  526. * otherwise. */
  527. static int
  528. dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  529. {
  530. int status;
  531. status = cqr->status == DASD_CQR_DONE;
  532. dasd_sfree_request(cqr, cqr->memdev);
  533. return status;
  534. }
  535. static void dasd_diag_handle_terminated_request(struct dasd_ccw_req *cqr)
  536. {
  537. if (cqr->retries < 0)
  538. cqr->status = DASD_CQR_FAILED;
  539. else
  540. cqr->status = DASD_CQR_FILLED;
  541. };
  542. /* Fill in IOCTL data for device. */
  543. static int
  544. dasd_diag_fill_info(struct dasd_device * device,
  545. struct dasd_information2_t * info)
  546. {
  547. struct dasd_diag_private *private = device->private;
  548. info->label_block = (unsigned int) private->pt_block;
  549. info->FBA_layout = 1;
  550. info->format = DASD_FORMAT_LDL;
  551. info->characteristics_size = sizeof(private->rdc_data);
  552. memcpy(info->characteristics, &private->rdc_data,
  553. sizeof(private->rdc_data));
  554. info->confdata_size = 0;
  555. return 0;
  556. }
  557. static void
  558. dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
  559. struct irb *stat)
  560. {
  561. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  562. "dump sense not available for DIAG data");
  563. }
  564. /*
  565. * Initialize block layer request queue.
  566. */
  567. static void dasd_diag_setup_blk_queue(struct dasd_block *block)
  568. {
  569. unsigned int logical_block_size = block->bp_block;
  570. struct request_queue *q = block->request_queue;
  571. int max;
  572. max = DIAG_MAX_BLOCKS << block->s2b_shift;
  573. blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
  574. q->limits.max_dev_sectors = max;
  575. blk_queue_logical_block_size(q, logical_block_size);
  576. blk_queue_max_hw_sectors(q, max);
  577. blk_queue_max_segments(q, USHRT_MAX);
  578. /* With page sized segments each segment can be translated into one idaw/tidaw */
  579. blk_queue_max_segment_size(q, PAGE_SIZE);
  580. blk_queue_segment_boundary(q, PAGE_SIZE - 1);
  581. }
  582. static struct dasd_discipline dasd_diag_discipline = {
  583. .owner = THIS_MODULE,
  584. .name = "DIAG",
  585. .ebcname = "DIAG",
  586. .check_device = dasd_diag_check_device,
  587. .verify_path = dasd_generic_verify_path,
  588. .fill_geometry = dasd_diag_fill_geometry,
  589. .setup_blk_queue = dasd_diag_setup_blk_queue,
  590. .start_IO = dasd_start_diag,
  591. .term_IO = dasd_diag_term_IO,
  592. .handle_terminated_request = dasd_diag_handle_terminated_request,
  593. .erp_action = dasd_diag_erp_action,
  594. .erp_postaction = dasd_diag_erp_postaction,
  595. .build_cp = dasd_diag_build_cp,
  596. .free_cp = dasd_diag_free_cp,
  597. .dump_sense = dasd_diag_dump_sense,
  598. .fill_info = dasd_diag_fill_info,
  599. };
  600. static int __init
  601. dasd_diag_init(void)
  602. {
  603. if (!MACHINE_IS_VM) {
  604. pr_info("Discipline %s cannot be used without z/VM\n",
  605. dasd_diag_discipline.name);
  606. return -ENODEV;
  607. }
  608. ASCEBC(dasd_diag_discipline.ebcname, 4);
  609. irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
  610. register_external_irq(EXT_IRQ_CP_SERVICE, dasd_ext_handler);
  611. dasd_diag_discipline_pointer = &dasd_diag_discipline;
  612. return 0;
  613. }
  614. static void __exit
  615. dasd_diag_cleanup(void)
  616. {
  617. unregister_external_irq(EXT_IRQ_CP_SERVICE, dasd_ext_handler);
  618. irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL);
  619. dasd_diag_discipline_pointer = NULL;
  620. }
  621. module_init(dasd_diag_init);
  622. module_exit(dasd_diag_cleanup);