Use dentry_path() to create full path to inode object
[pohmelfs.git] / drivers / s390 / block / dasd_fba.c
bloba62a75358eb94ab7686373e7e166628e1eaf2773
1 /*
2 * File...........: linux/drivers/s390/block/dasd_fba.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Bugreports.to..: <Linux390@de.ibm.com>
5 * Copyright IBM Corp. 1999, 2009
6 */
8 #define KMSG_COMPONENT "dasd-fba"
10 #include <linux/stddef.h>
11 #include <linux/kernel.h>
12 #include <asm/debug.h>
14 #include <linux/slab.h>
15 #include <linux/hdreg.h> /* HDIO_GETGEO */
16 #include <linux/bio.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
20 #include <asm/idals.h>
21 #include <asm/ebcdic.h>
22 #include <asm/io.h>
23 #include <asm/ccwdev.h>
25 #include "dasd_int.h"
26 #include "dasd_fba.h"
28 #ifdef PRINTK_HEADER
29 #undef PRINTK_HEADER
30 #endif /* PRINTK_HEADER */
31 #define PRINTK_HEADER "dasd(fba):"
33 #define DASD_FBA_CCW_WRITE 0x41
34 #define DASD_FBA_CCW_READ 0x42
35 #define DASD_FBA_CCW_LOCATE 0x43
36 #define DASD_FBA_CCW_DEFINE_EXTENT 0x63
38 MODULE_LICENSE("GPL");
40 static struct dasd_discipline dasd_fba_discipline;
42 struct dasd_fba_private {
43 struct dasd_fba_characteristics rdc_data;
46 static struct ccw_device_id dasd_fba_ids[] = {
47 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
48 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
49 { /* end of list */ },
52 MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
54 static struct ccw_driver dasd_fba_driver; /* see below */
55 static int
56 dasd_fba_probe(struct ccw_device *cdev)
58 return dasd_generic_probe(cdev, &dasd_fba_discipline);
61 static int
62 dasd_fba_set_online(struct ccw_device *cdev)
64 return dasd_generic_set_online(cdev, &dasd_fba_discipline);
67 static struct ccw_driver dasd_fba_driver = {
68 .driver = {
69 .name = "dasd-fba",
70 .owner = THIS_MODULE,
72 .ids = dasd_fba_ids,
73 .probe = dasd_fba_probe,
74 .remove = dasd_generic_remove,
75 .set_offline = dasd_generic_set_offline,
76 .set_online = dasd_fba_set_online,
77 .notify = dasd_generic_notify,
78 .path_event = dasd_generic_path_event,
79 .freeze = dasd_generic_pm_freeze,
80 .thaw = dasd_generic_restore_device,
81 .restore = dasd_generic_restore_device,
82 .int_class = IOINT_DAS,
85 static void
86 define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
87 int blksize, int beg, int nr)
89 ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
90 ccw->flags = 0;
91 ccw->count = 16;
92 ccw->cda = (__u32) __pa(data);
93 memset(data, 0, sizeof (struct DE_fba_data));
94 if (rw == WRITE)
95 (data->mask).perm = 0x0;
96 else if (rw == READ)
97 (data->mask).perm = 0x1;
98 else
99 data->mask.perm = 0x2;
100 data->blk_size = blksize;
101 data->ext_loc = beg;
102 data->ext_end = nr - 1;
105 static void
106 locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
107 int block_nr, int block_ct)
109 ccw->cmd_code = DASD_FBA_CCW_LOCATE;
110 ccw->flags = 0;
111 ccw->count = 8;
112 ccw->cda = (__u32) __pa(data);
113 memset(data, 0, sizeof (struct LO_fba_data));
114 if (rw == WRITE)
115 data->operation.cmd = 0x5;
116 else if (rw == READ)
117 data->operation.cmd = 0x6;
118 else
119 data->operation.cmd = 0x8;
120 data->blk_nr = block_nr;
121 data->blk_ct = block_ct;
124 static int
125 dasd_fba_check_characteristics(struct dasd_device *device)
127 struct dasd_block *block;
128 struct dasd_fba_private *private;
129 struct ccw_device *cdev = device->cdev;
130 int rc;
131 int readonly;
133 private = (struct dasd_fba_private *) device->private;
134 if (!private) {
135 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
136 if (!private) {
137 dev_warn(&device->cdev->dev,
138 "Allocating memory for private DASD "
139 "data failed\n");
140 return -ENOMEM;
142 device->private = (void *) private;
143 } else {
144 memset(private, 0, sizeof(*private));
146 block = dasd_alloc_block();
147 if (IS_ERR(block)) {
148 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate "
149 "dasd block structure");
150 device->private = NULL;
151 kfree(private);
152 return PTR_ERR(block);
154 device->block = block;
155 block->base = device;
157 /* Read Device Characteristics */
158 rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC,
159 &private->rdc_data, 32);
160 if (rc) {
161 DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device "
162 "characteristics returned error %d", rc);
163 device->block = NULL;
164 dasd_free_block(block);
165 device->private = NULL;
166 kfree(private);
167 return rc;
170 device->default_expires = DASD_EXPIRES;
171 device->path_data.opm = LPM_ANYPATH;
173 readonly = dasd_device_is_ro(device);
174 if (readonly)
175 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
177 dev_info(&device->cdev->dev,
178 "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB "
179 "and %d B/blk%s\n",
180 cdev->id.dev_type,
181 cdev->id.dev_model,
182 cdev->id.cu_type,
183 cdev->id.cu_model,
184 ((private->rdc_data.blk_bdsa *
185 (private->rdc_data.blk_size >> 9)) >> 11),
186 private->rdc_data.blk_size,
187 readonly ? ", read-only device" : "");
188 return 0;
191 static int dasd_fba_do_analysis(struct dasd_block *block)
193 struct dasd_fba_private *private;
194 int sb, rc;
196 private = (struct dasd_fba_private *) block->base->private;
197 rc = dasd_check_blocksize(private->rdc_data.blk_size);
198 if (rc) {
199 DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
200 private->rdc_data.blk_size);
201 return rc;
203 block->blocks = private->rdc_data.blk_bdsa;
204 block->bp_block = private->rdc_data.blk_size;
205 block->s2b_shift = 0; /* bits to shift 512 to get a block */
206 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
207 block->s2b_shift++;
208 return 0;
211 static int dasd_fba_fill_geometry(struct dasd_block *block,
212 struct hd_geometry *geo)
214 if (dasd_check_blocksize(block->bp_block) != 0)
215 return -EINVAL;
216 geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
217 geo->heads = 16;
218 geo->sectors = 128 >> block->s2b_shift;
219 return 0;
222 static dasd_erp_fn_t
223 dasd_fba_erp_action(struct dasd_ccw_req * cqr)
225 return dasd_default_erp_action;
228 static dasd_erp_fn_t
229 dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
231 if (cqr->function == dasd_default_erp_action)
232 return dasd_default_erp_postaction;
234 DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
235 cqr->function);
236 return NULL;
239 static void dasd_fba_check_for_device_change(struct dasd_device *device,
240 struct dasd_ccw_req *cqr,
241 struct irb *irb)
243 char mask;
245 /* first of all check for state change pending interrupt */
246 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
247 if ((irb->scsw.cmd.dstat & mask) == mask)
248 dasd_generic_handle_state_change(device);
251 static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
252 struct dasd_block *block,
253 struct request *req)
255 struct dasd_fba_private *private;
256 unsigned long *idaws;
257 struct LO_fba_data *LO_data;
258 struct dasd_ccw_req *cqr;
259 struct ccw1 *ccw;
260 struct req_iterator iter;
261 struct bio_vec *bv;
262 char *dst;
263 int count, cidaw, cplength, datasize;
264 sector_t recid, first_rec, last_rec;
265 unsigned int blksize, off;
266 unsigned char cmd;
268 private = (struct dasd_fba_private *) block->base->private;
269 if (rq_data_dir(req) == READ) {
270 cmd = DASD_FBA_CCW_READ;
271 } else if (rq_data_dir(req) == WRITE) {
272 cmd = DASD_FBA_CCW_WRITE;
273 } else
274 return ERR_PTR(-EINVAL);
275 blksize = block->bp_block;
276 /* Calculate record id of first and last block. */
277 first_rec = blk_rq_pos(req) >> block->s2b_shift;
278 last_rec =
279 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
280 /* Check struct bio and count the number of blocks for the request. */
281 count = 0;
282 cidaw = 0;
283 rq_for_each_segment(bv, req, iter) {
284 if (bv->bv_len & (blksize - 1))
285 /* Fba can only do full blocks. */
286 return ERR_PTR(-EINVAL);
287 count += bv->bv_len >> (block->s2b_shift + 9);
288 #if defined(CONFIG_64BIT)
289 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
290 cidaw += bv->bv_len / blksize;
291 #endif
293 /* Paranoia. */
294 if (count != last_rec - first_rec + 1)
295 return ERR_PTR(-EINVAL);
296 /* 1x define extent + 1x locate record + number of blocks */
297 cplength = 2 + count;
298 /* 1x define extent + 1x locate record */
299 datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
300 cidaw * sizeof(unsigned long);
302 * Find out number of additional locate record ccws if the device
303 * can't do data chaining.
305 if (private->rdc_data.mode.bits.data_chain == 0) {
306 cplength += count - 1;
307 datasize += (count - 1)*sizeof(struct LO_fba_data);
309 /* Allocate the ccw request. */
310 cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev);
311 if (IS_ERR(cqr))
312 return cqr;
313 ccw = cqr->cpaddr;
314 /* First ccw is define extent. */
315 define_extent(ccw++, cqr->data, rq_data_dir(req),
316 block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
317 /* Build locate_record + read/write ccws. */
318 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
319 LO_data = (struct LO_fba_data *) (idaws + cidaw);
320 /* Locate record for all blocks for smart devices. */
321 if (private->rdc_data.mode.bits.data_chain != 0) {
322 ccw[-1].flags |= CCW_FLAG_CC;
323 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
325 recid = first_rec;
326 rq_for_each_segment(bv, req, iter) {
327 dst = page_address(bv->bv_page) + bv->bv_offset;
328 if (dasd_page_cache) {
329 char *copy = kmem_cache_alloc(dasd_page_cache,
330 GFP_DMA | __GFP_NOWARN);
331 if (copy && rq_data_dir(req) == WRITE)
332 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
333 if (copy)
334 dst = copy + bv->bv_offset;
336 for (off = 0; off < bv->bv_len; off += blksize) {
337 /* Locate record for stupid devices. */
338 if (private->rdc_data.mode.bits.data_chain == 0) {
339 ccw[-1].flags |= CCW_FLAG_CC;
340 locate_record(ccw, LO_data++,
341 rq_data_dir(req),
342 recid - first_rec, 1);
343 ccw->flags = CCW_FLAG_CC;
344 ccw++;
345 } else {
346 if (recid > first_rec)
347 ccw[-1].flags |= CCW_FLAG_DC;
348 else
349 ccw[-1].flags |= CCW_FLAG_CC;
351 ccw->cmd_code = cmd;
352 ccw->count = block->bp_block;
353 if (idal_is_needed(dst, blksize)) {
354 ccw->cda = (__u32)(addr_t) idaws;
355 ccw->flags = CCW_FLAG_IDA;
356 idaws = idal_create_words(idaws, dst, blksize);
357 } else {
358 ccw->cda = (__u32)(addr_t) dst;
359 ccw->flags = 0;
361 ccw++;
362 dst += blksize;
363 recid++;
366 if (blk_noretry_request(req) ||
367 block->base->features & DASD_FEATURE_FAILFAST)
368 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
369 cqr->startdev = memdev;
370 cqr->memdev = memdev;
371 cqr->block = block;
372 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
373 cqr->retries = 32;
374 cqr->buildclk = get_clock();
375 cqr->status = DASD_CQR_FILLED;
376 return cqr;
379 static int
380 dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
382 struct dasd_fba_private *private;
383 struct ccw1 *ccw;
384 struct req_iterator iter;
385 struct bio_vec *bv;
386 char *dst, *cda;
387 unsigned int blksize, off;
388 int status;
390 if (!dasd_page_cache)
391 goto out;
392 private = (struct dasd_fba_private *) cqr->block->base->private;
393 blksize = cqr->block->bp_block;
394 ccw = cqr->cpaddr;
395 /* Skip over define extent & locate record. */
396 ccw++;
397 if (private->rdc_data.mode.bits.data_chain != 0)
398 ccw++;
399 rq_for_each_segment(bv, req, iter) {
400 dst = page_address(bv->bv_page) + bv->bv_offset;
401 for (off = 0; off < bv->bv_len; off += blksize) {
402 /* Skip locate record. */
403 if (private->rdc_data.mode.bits.data_chain == 0)
404 ccw++;
405 if (dst) {
406 if (ccw->flags & CCW_FLAG_IDA)
407 cda = *((char **)((addr_t) ccw->cda));
408 else
409 cda = (char *)((addr_t) ccw->cda);
410 if (dst != cda) {
411 if (rq_data_dir(req) == READ)
412 memcpy(dst, cda, bv->bv_len);
413 kmem_cache_free(dasd_page_cache,
414 (void *)((addr_t)cda & PAGE_MASK));
416 dst = NULL;
418 ccw++;
421 out:
422 status = cqr->status == DASD_CQR_DONE;
423 dasd_sfree_request(cqr, cqr->memdev);
424 return status;
427 static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
429 cqr->status = DASD_CQR_FILLED;
432 static int
433 dasd_fba_fill_info(struct dasd_device * device,
434 struct dasd_information2_t * info)
436 info->label_block = 1;
437 info->FBA_layout = 1;
438 info->format = DASD_FORMAT_LDL;
439 info->characteristics_size = sizeof(struct dasd_fba_characteristics);
440 memcpy(info->characteristics,
441 &((struct dasd_fba_private *) device->private)->rdc_data,
442 sizeof (struct dasd_fba_characteristics));
443 info->confdata_size = 0;
444 return 0;
447 static void
448 dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
449 char *reason)
451 u64 *sense;
453 sense = (u64 *) dasd_get_sense(irb);
454 if (sense) {
455 DBF_DEV_EVENT(DBF_EMERG, device,
456 "%s: %s %02x%02x%02x %016llx %016llx %016llx "
457 "%016llx", reason,
458 scsw_is_tm(&irb->scsw) ? "t" : "c",
459 scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
460 scsw_dstat(&irb->scsw), sense[0], sense[1],
461 sense[2], sense[3]);
462 } else {
463 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
464 "SORRY - NO VALID SENSE AVAILABLE\n");
469 static void
470 dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
471 struct irb *irb)
473 char *page;
474 struct ccw1 *act, *end, *last;
475 int len, sl, sct, count;
477 page = (char *) get_zeroed_page(GFP_ATOMIC);
478 if (page == NULL) {
479 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
480 "No memory to dump sense data");
481 return;
483 len = sprintf(page, KERN_ERR PRINTK_HEADER
484 " I/O status report for device %s:\n",
485 dev_name(&device->cdev->dev));
486 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
487 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
488 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
489 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
490 " device %s: Failing CCW: %p\n",
491 dev_name(&device->cdev->dev),
492 (void *) (addr_t) irb->scsw.cmd.cpa);
493 if (irb->esw.esw0.erw.cons) {
494 for (sl = 0; sl < 4; sl++) {
495 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
496 " Sense(hex) %2d-%2d:",
497 (8 * sl), ((8 * sl) + 7));
499 for (sct = 0; sct < 8; sct++) {
500 len += sprintf(page + len, " %02x",
501 irb->ecw[8 * sl + sct]);
503 len += sprintf(page + len, "\n");
505 } else {
506 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
507 " SORRY - NO VALID SENSE AVAILABLE\n");
509 printk(KERN_ERR "%s", page);
511 /* dump the Channel Program */
512 /* print first CCWs (maximum 8) */
513 act = req->cpaddr;
514 for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
515 end = min(act + 8, last);
516 len = sprintf(page, KERN_ERR PRINTK_HEADER
517 " Related CP in req: %p\n", req);
518 while (act <= end) {
519 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
520 " CCW %p: %08X %08X DAT:",
521 act, ((int *) act)[0], ((int *) act)[1]);
522 for (count = 0; count < 32 && count < act->count;
523 count += sizeof(int))
524 len += sprintf(page + len, " %08X",
525 ((int *) (addr_t) act->cda)
526 [(count>>2)]);
527 len += sprintf(page + len, "\n");
528 act++;
530 printk(KERN_ERR "%s", page);
533 /* print failing CCW area */
534 len = 0;
535 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
536 act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
537 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
539 end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
540 while (act <= end) {
541 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
542 " CCW %p: %08X %08X DAT:",
543 act, ((int *) act)[0], ((int *) act)[1]);
544 for (count = 0; count < 32 && count < act->count;
545 count += sizeof(int))
546 len += sprintf(page + len, " %08X",
547 ((int *) (addr_t) act->cda)
548 [(count>>2)]);
549 len += sprintf(page + len, "\n");
550 act++;
553 /* print last CCWs */
554 if (act < last - 2) {
555 act = last - 2;
556 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
558 while (act <= last) {
559 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
560 " CCW %p: %08X %08X DAT:",
561 act, ((int *) act)[0], ((int *) act)[1]);
562 for (count = 0; count < 32 && count < act->count;
563 count += sizeof(int))
564 len += sprintf(page + len, " %08X",
565 ((int *) (addr_t) act->cda)
566 [(count>>2)]);
567 len += sprintf(page + len, "\n");
568 act++;
570 if (len > 0)
571 printk(KERN_ERR "%s", page);
572 free_page((unsigned long) page);
576 * max_blocks is dependent on the amount of storage that is available
577 * in the static io buffer for each device. Currently each device has
578 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
579 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
580 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
581 * addition we have one define extent ccw + 16 bytes of data and a
582 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
583 * That makes:
584 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
585 * We want to fit two into the available memory so that we can immediately
586 * start the next request if one finishes off. That makes 100.1 blocks
587 * for one request. Give a little safety and the result is 96.
589 static struct dasd_discipline dasd_fba_discipline = {
590 .owner = THIS_MODULE,
591 .name = "FBA ",
592 .ebcname = "FBA ",
593 .max_blocks = 96,
594 .check_device = dasd_fba_check_characteristics,
595 .do_analysis = dasd_fba_do_analysis,
596 .verify_path = dasd_generic_verify_path,
597 .fill_geometry = dasd_fba_fill_geometry,
598 .start_IO = dasd_start_IO,
599 .term_IO = dasd_term_IO,
600 .handle_terminated_request = dasd_fba_handle_terminated_request,
601 .erp_action = dasd_fba_erp_action,
602 .erp_postaction = dasd_fba_erp_postaction,
603 .check_for_device_change = dasd_fba_check_for_device_change,
604 .build_cp = dasd_fba_build_cp,
605 .free_cp = dasd_fba_free_cp,
606 .dump_sense = dasd_fba_dump_sense,
607 .dump_sense_dbf = dasd_fba_dump_sense_dbf,
608 .fill_info = dasd_fba_fill_info,
611 static int __init
612 dasd_fba_init(void)
614 int ret;
616 ASCEBC(dasd_fba_discipline.ebcname, 4);
617 ret = ccw_driver_register(&dasd_fba_driver);
618 if (!ret)
619 wait_for_device_probe();
621 return ret;
624 static void __exit
625 dasd_fba_cleanup(void)
627 ccw_driver_unregister(&dasd_fba_driver);
630 module_init(dasd_fba_init);
631 module_exit(dasd_fba_cleanup);