2 * File...........: linux/drivers/s390/block/dasd_diag.c
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 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/hdreg.h> /* HDIO_GETGEO */
17 #include <linux/bio.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
22 #include <asm/debug.h>
23 #include <asm/ebcdic.h>
25 #include <asm/s390_ext.h>
26 #include <asm/todclk.h>
29 #include "dasd_diag.h"
33 #endif /* PRINTK_HEADER */
34 #define PRINTK_HEADER "dasd(diag):"
36 MODULE_LICENSE("GPL");
38 struct dasd_discipline dasd_diag_discipline;
40 struct dasd_diag_private {
41 struct dasd_diag_characteristics rdc_data;
42 struct dasd_diag_rw_io iob;
43 struct dasd_diag_init_io iib;
44 unsigned int pt_block;
47 struct dasd_diag_req {
49 struct dasd_diag_bio bio[0];
53 dia250(void *iob, int cmd)
57 __asm__ __volatile__(" lhi %0,3\n"
64 #ifndef CONFIG_ARCH_S390X
65 ".section __ex_table,\"a\"\n"
70 ".section __ex_table,\"a\"\n"
76 : "d" (cmd), "d" ((void *) __pa(iob))
82 mdsk_init_io(struct dasd_device * device, int blocksize, int offset, int size)
84 struct dasd_diag_private *private;
85 struct dasd_diag_init_io *iib;
88 private = (struct dasd_diag_private *) device->private;
90 memset(iib, 0, sizeof (struct dasd_diag_init_io));
92 iib->dev_nr = _ccw_device_get_device_number(device->cdev);
93 iib->block_size = blocksize;
96 iib->end_block = size;
98 rc = dia250(iib, INIT_BIO);
103 static __inline__ int
104 mdsk_term_io(struct dasd_device * device)
106 struct dasd_diag_private *private;
107 struct dasd_diag_init_io *iib;
110 private = (struct dasd_diag_private *) device->private;
112 memset(iib, 0, sizeof (struct dasd_diag_init_io));
113 iib->dev_nr = _ccw_device_get_device_number(device->cdev);
114 rc = dia250(iib, TERM_BIO);
119 dasd_start_diag(struct dasd_ccw_req * cqr)
121 struct dasd_device *device;
122 struct dasd_diag_private *private;
123 struct dasd_diag_req *dreq;
126 device = cqr->device;
127 private = (struct dasd_diag_private *) device->private;
128 dreq = (struct dasd_diag_req *) cqr->data;
130 private->iob.dev_nr = _ccw_device_get_device_number(device->cdev);
131 private->iob.key = 0;
132 private->iob.flags = 2; /* do asynchronous io */
133 private->iob.block_count = dreq->block_count;
134 private->iob.interrupt_params = (u32)(addr_t) cqr;
135 private->iob.bio_list = __pa(dreq->bio);
137 cqr->startclk = get_clock();
139 rc = dia250(&private->iob, RW_BIO);
141 MESSAGE(KERN_WARNING, "dia250 returned CC %d", rc);
142 cqr->status = DASD_CQR_ERROR;
143 } else if (rc == 0) {
144 cqr->status = DASD_CQR_DONE;
145 dasd_schedule_bh(device);
147 cqr->status = DASD_CQR_IN_IO;
154 dasd_ext_handler(struct pt_regs *regs, __u16 code)
156 struct dasd_ccw_req *cqr, *next;
157 struct dasd_device *device;
158 unsigned long long expires;
164 * Get the external interruption subcode. VM stores
165 * this in the 'cpu address' field associated with
166 * the external interrupt. For diag 250 the subcode
169 if ((S390_lowcore.cpu_addr & 0xff00) != 0x0300)
171 status = *((char *) &S390_lowcore.ext_params + 5);
172 ip = S390_lowcore.ext_params;
174 cpu = smp_processor_id();
176 if (!ip) { /* no intparm: unsolicited interrupt */
177 MESSAGE(KERN_DEBUG, "%s", "caught unsolicited interrupt");
180 cqr = (struct dasd_ccw_req *)(addr_t) ip;
181 device = (struct dasd_device *) cqr->device;
182 if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
183 DEV_MESSAGE(KERN_WARNING, device,
184 " magic number of dasd_ccw_req 0x%08X doesn't"
185 " match discipline 0x%08X",
186 cqr->magic, *(int *) (&device->discipline->name));
190 /* get irq lock to modify request queue */
191 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
193 cqr->stopclk = get_clock();
197 cqr->status = DASD_CQR_DONE;
198 /* Start first request on queue if possible -> fast_io. */
199 if (!list_empty(&device->ccw_queue)) {
200 next = list_entry(device->ccw_queue.next,
201 struct dasd_ccw_req, list);
202 if (next->status == DASD_CQR_QUEUED) {
203 if (dasd_start_diag(next) == 0)
204 expires = next->expires;
206 MESSAGE(KERN_WARNING, "%s",
207 "Interrupt fastpath failed!");
211 cqr->status = DASD_CQR_FAILED;
214 dasd_set_timer(device, expires);
216 dasd_clear_timer(device);
217 dasd_schedule_bh(device);
219 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
223 dasd_diag_check_device(struct dasd_device *device)
225 struct dasd_diag_private *private;
226 struct dasd_diag_characteristics *rdc_data;
227 struct dasd_diag_bio bio;
232 private = (struct dasd_diag_private *) device->private;
233 if (private == NULL) {
234 private = kmalloc(sizeof(struct dasd_diag_private),GFP_KERNEL);
235 if (private == NULL) {
236 MESSAGE(KERN_WARNING, "%s",
237 "memory allocation failed for private data");
240 device->private = (void *) private;
242 /* Read Device Characteristics */
243 rdc_data = (void *) &(private->rdc_data);
244 rdc_data->dev_nr = _ccw_device_get_device_number(device->cdev);
245 rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics);
247 rc = diag210((struct diag210 *) rdc_data);
251 /* Figure out position of label block */
252 switch (private->rdc_data.vdev_class) {
254 private->pt_block = 1;
257 private->pt_block = 2;
264 "%04X: %04X on real %04X/%02X",
267 rdc_data->rdev_type, rdc_data->rdev_model);
269 /* terminate all outstanding operations */
270 mdsk_term_io(device);
272 /* figure out blocksize of device */
273 label = (long *) get_zeroed_page(GFP_KERNEL);
275 MESSAGE(KERN_WARNING, "%s",
276 "No memory to allocate initialization request");
279 for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) {
280 mdsk_init_io(device, bsize, 0, 64);
281 memset(&bio, 0, sizeof (struct dasd_diag_bio));
282 bio.type = MDSK_READ_REQ;
283 bio.block_number = private->pt_block + 1;
284 bio.buffer = __pa(label);
285 memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io));
286 private->iob.dev_nr = rdc_data->dev_nr;
287 private->iob.key = 0;
288 private->iob.flags = 0; /* do synchronous io */
289 private->iob.block_count = 1;
290 private->iob.interrupt_params = 0;
291 private->iob.bio_list = __pa(&bio);
292 if (dia250(&private->iob, RW_BIO) == 0)
294 mdsk_term_io(device);
296 if (bsize <= PAGE_SIZE && label[3] == bsize &&
297 label[0] == 0xc3d4e2f1) {
298 device->blocks = label[7];
299 device->bp_block = bsize;
300 device->s2b_shift = 0; /* bits to shift 512 to get a block */
301 for (sb = 512; sb < bsize; sb = sb << 1)
304 DEV_MESSAGE(KERN_INFO, device,
305 "capacity (%dkB blks): %ldkB",
306 (device->bp_block >> 10),
307 (device->blocks << device->s2b_shift) >> 1);
311 free_page((long) label);
316 dasd_diag_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
318 if (dasd_check_blocksize(device->bp_block) != 0)
320 geo->cylinders = (device->blocks << device->s2b_shift) >> 10;
322 geo->sectors = 128 >> device->s2b_shift;
327 dasd_diag_examine_error(struct dasd_ccw_req * cqr, struct irb * stat)
329 return dasd_era_fatal;
333 dasd_diag_erp_action(struct dasd_ccw_req * cqr)
335 return dasd_default_erp_action;
339 dasd_diag_erp_postaction(struct dasd_ccw_req * cqr)
341 return dasd_default_erp_postaction;
344 static struct dasd_ccw_req *
345 dasd_diag_build_cp(struct dasd_device * device, struct request *req)
347 struct dasd_ccw_req *cqr;
348 struct dasd_diag_req *dreq;
349 struct dasd_diag_bio *dbio;
354 sector_t recid, first_rec, last_rec;
355 unsigned blksize, off;
356 unsigned char rw_cmd;
359 if (rq_data_dir(req) == READ)
360 rw_cmd = MDSK_READ_REQ;
361 else if (rq_data_dir(req) == WRITE)
362 rw_cmd = MDSK_WRITE_REQ;
364 return ERR_PTR(-EINVAL);
365 blksize = device->bp_block;
366 /* Calculate record id of first and last block. */
367 first_rec = req->sector >> device->s2b_shift;
368 last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
369 /* Check struct bio and count the number of blocks for the request. */
371 rq_for_each_bio(bio, req) {
372 bio_for_each_segment(bv, bio, i) {
373 if (bv->bv_len & (blksize - 1))
374 /* Fba can only do full blocks. */
375 return ERR_PTR(-EINVAL);
376 count += bv->bv_len >> (device->s2b_shift + 9);
380 if (count != last_rec - first_rec + 1)
381 return ERR_PTR(-EINVAL);
382 /* Build the request */
383 datasize = sizeof(struct dasd_diag_req) +
384 count*sizeof(struct dasd_diag_bio);
385 cqr = dasd_smalloc_request(dasd_diag_discipline.name, 0,
390 dreq = (struct dasd_diag_req *) cqr->data;
391 dreq->block_count = count;
394 rq_for_each_bio(bio, req) {
395 bio_for_each_segment(bv, bio, i) {
396 dst = page_address(bv->bv_page) + bv->bv_offset;
397 for (off = 0; off < bv->bv_len; off += blksize) {
398 memset(dbio, 0, sizeof (struct dasd_diag_bio));
400 dbio->block_number = recid + 1;
401 dbio->buffer = __pa(dst);
408 cqr->buildclk = get_clock();
409 cqr->device = device;
410 cqr->expires = 50 * HZ; /* 50 seconds */
411 cqr->status = DASD_CQR_FILLED;
416 dasd_diag_fill_info(struct dasd_device * device,
417 struct dasd_information2_t * info)
419 struct dasd_diag_private *private;
421 private = (struct dasd_diag_private *) device->private;
422 info->label_block = private->pt_block;
423 info->FBA_layout = 1;
424 info->format = DASD_FORMAT_LDL;
425 info->characteristics_size = sizeof (struct dasd_diag_characteristics);
426 memcpy(info->characteristics,
427 &((struct dasd_diag_private *) device->private)->rdc_data,
428 sizeof (struct dasd_diag_characteristics));
429 info->confdata_size = 0;
434 dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
439 page = (char *) get_zeroed_page(GFP_KERNEL);
441 MESSAGE(KERN_ERR, "%s", "No memory to dump sense data");
444 sprintf(page, KERN_WARNING PRINTK_HEADER
445 "device %s: I/O status report:\n",
446 device->cdev->dev.bus_id);
448 MESSAGE(KERN_ERR, "Sense data:\n%s", page);
450 free_page((unsigned long) page);
454 * max_blocks is dependent on the amount of storage that is available
455 * in the static io buffer for each device. Currently each device has
456 * 8192 bytes (=2 pages). dasd diag is only relevant for 31 bit.
457 * The struct dasd_ccw_req has 96 bytes, the struct dasd_diag_req has
458 * 8 bytes and the struct dasd_diag_bio for each block has 16 bytes.
460 * (8192 - 96 - 8) / 16 = 505.5 blocks at maximum.
461 * We want to fit two into the available memory so that we can immediately
462 * start the next request if one finishes off. That makes 252.75 blocks
463 * for one request. Give a little safety and the result is 240.
465 struct dasd_discipline dasd_diag_discipline = {
466 .owner = THIS_MODULE,
470 .check_device = dasd_diag_check_device,
471 .fill_geometry = dasd_diag_fill_geometry,
472 .start_IO = dasd_start_diag,
473 .examine_error = dasd_diag_examine_error,
474 .erp_action = dasd_diag_erp_action,
475 .erp_postaction = dasd_diag_erp_postaction,
476 .build_cp = dasd_diag_build_cp,
477 .dump_sense = dasd_diag_dump_sense,
478 .fill_info = dasd_diag_fill_info,
484 if (!MACHINE_IS_VM) {
486 "Machine is not VM: %s discipline not initializing",
487 dasd_diag_discipline.name);
490 ASCEBC(dasd_diag_discipline.ebcname, 4);
493 register_external_interrupt(0x2603, dasd_ext_handler);
494 dasd_diag_discipline_pointer = &dasd_diag_discipline;
499 dasd_diag_cleanup(void)
501 if (!MACHINE_IS_VM) {
503 "Machine is not VM: %s discipline not initializing",
504 dasd_diag_discipline.name);
507 unregister_external_interrupt(0x2603, dasd_ext_handler);
509 dasd_diag_discipline_pointer = NULL;
512 module_init(dasd_diag_init);
513 module_exit(dasd_diag_cleanup);
516 * Overrides for Emacs so that we follow Linus's tabbing style.
517 * Emacs will notice this stuff at the end of the file and automatically
518 * adjust the settings for this buffer only. This must remain at the end
520 * ---------------------------------------------------------------------------
523 * c-brace-imaginary-offset: 0
525 * c-argdecl-indent: 4
527 * c-continued-statement-offset: 4
528 * c-continued-brace-offset: 0
529 * indent-tabs-mode: 1