dasd_fba.c 17.3 KB
Newer Older
1
/*
L
Linus Torvalds 已提交
2 3
 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
 * Bugreports.to..: <Linux390@de.ibm.com>
4
 * Copyright IBM Corp. 1999, 2009
L
Linus Torvalds 已提交
5 6
 */

7
#define KMSG_COMPONENT "dasd-fba"
S
Stefan Haberland 已提交
8

L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <asm/debug.h>

#include <linux/slab.h>
#include <linux/hdreg.h>	/* HDIO_GETGEO			    */
#include <linux/bio.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/idals.h>
#include <asm/ebcdic.h>
#include <asm/io.h>
#include <asm/ccwdev.h>

#include "dasd_int.h"
#include "dasd_fba.h"

#ifdef PRINTK_HEADER
#undef PRINTK_HEADER
#endif				/* PRINTK_HEADER */
#define PRINTK_HEADER "dasd(fba):"

32 33
#define FBA_DEFAULT_RETRIES 32

L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47
#define DASD_FBA_CCW_WRITE 0x41
#define DASD_FBA_CCW_READ 0x42
#define DASD_FBA_CCW_LOCATE 0x43
#define DASD_FBA_CCW_DEFINE_EXTENT 0x63

MODULE_LICENSE("GPL");

static struct dasd_discipline dasd_fba_discipline;

struct dasd_fba_private {
	struct dasd_fba_characteristics rdc_data;
};

static struct ccw_device_id dasd_fba_ids[] = {
H
Heiko Carstens 已提交
48 49
	{ CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
	{ CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57 58
	{ /* end of list */ },
};

MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);

static struct ccw_driver dasd_fba_driver; /* see below */
static int
dasd_fba_probe(struct ccw_device *cdev)
{
59
	return dasd_generic_probe(cdev, &dasd_fba_discipline);
L
Linus Torvalds 已提交
60 61 62 63 64
}

static int
dasd_fba_set_online(struct ccw_device *cdev)
{
65
	return dasd_generic_set_online(cdev, &dasd_fba_discipline);
L
Linus Torvalds 已提交
66 67 68
}

static struct ccw_driver dasd_fba_driver = {
69 70 71 72
	.driver = {
		.name	= "dasd-fba",
		.owner	= THIS_MODULE,
	},
L
Linus Torvalds 已提交
73 74 75 76 77 78
	.ids         = dasd_fba_ids,
	.probe       = dasd_fba_probe,
	.remove      = dasd_generic_remove,
	.set_offline = dasd_generic_set_offline,
	.set_online  = dasd_fba_set_online,
	.notify      = dasd_generic_notify,
79
	.path_event  = dasd_generic_path_event,
80 81 82
	.freeze      = dasd_generic_pm_freeze,
	.thaw	     = dasd_generic_restore_device,
	.restore     = dasd_generic_restore_device,
83
	.int_class   = IRQIO_DAS,
L
Linus Torvalds 已提交
84 85
};

86
static void
L
Linus Torvalds 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
	      int blksize, int beg, int nr)
{
	ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
	ccw->flags = 0;
	ccw->count = 16;
	ccw->cda = (__u32) __pa(data);
	memset(data, 0, sizeof (struct DE_fba_data));
	if (rw == WRITE)
		(data->mask).perm = 0x0;
	else if (rw == READ)
		(data->mask).perm = 0x1;
	else
		data->mask.perm = 0x2;
	data->blk_size = blksize;
	data->ext_loc = beg;
	data->ext_end = nr - 1;
}

106
static void
L
Linus Torvalds 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
	      int block_nr, int block_ct)
{
	ccw->cmd_code = DASD_FBA_CCW_LOCATE;
	ccw->flags = 0;
	ccw->count = 8;
	ccw->cda = (__u32) __pa(data);
	memset(data, 0, sizeof (struct LO_fba_data));
	if (rw == WRITE)
		data->operation.cmd = 0x5;
	else if (rw == READ)
		data->operation.cmd = 0x6;
	else
		data->operation.cmd = 0x8;
	data->blk_nr = block_nr;
	data->blk_ct = block_ct;
}

static int
dasd_fba_check_characteristics(struct dasd_device *device)
{
128
	struct dasd_fba_private *private = device->private;
129
	struct ccw_device *cdev = device->cdev;
130 131
	struct dasd_block *block;
	int readonly, rc;
L
Linus Torvalds 已提交
132

133 134 135
	if (!private) {
		private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
		if (!private) {
S
Stefan Haberland 已提交
136 137 138
			dev_warn(&device->cdev->dev,
				 "Allocating memory for private DASD "
				 "data failed\n");
L
Linus Torvalds 已提交
139 140
			return -ENOMEM;
		}
141
		device->private = private;
142 143
	} else {
		memset(private, 0, sizeof(*private));
L
Linus Torvalds 已提交
144
	}
145 146
	block = dasd_alloc_block();
	if (IS_ERR(block)) {
147 148
		DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate "
				"dasd block structure");
149 150
		device->private = NULL;
		kfree(private);
151 152 153 154 155
		return PTR_ERR(block);
	}
	device->block = block;
	block->base = device;

L
Linus Torvalds 已提交
156
	/* Read Device Characteristics */
157 158
	rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC,
					 &private->rdc_data, 32);
L
Linus Torvalds 已提交
159
	if (rc) {
160 161
		DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device "
				"characteristics returned error %d", rc);
162 163 164 165
		device->block = NULL;
		dasd_free_block(block);
		device->private = NULL;
		kfree(private);
L
Linus Torvalds 已提交
166 167 168
		return rc;
	}

169
	device->default_expires = DASD_EXPIRES;
170
	device->default_retries = FBA_DEFAULT_RETRIES;
171
	device->path_data.opm = LPM_ANYPATH;
172

173 174 175 176
	readonly = dasd_device_is_ro(device);
	if (readonly)
		set_bit(DASD_FLAG_DEVICE_RO, &device->flags);

S
Stefan Haberland 已提交
177 178
	dev_info(&device->cdev->dev,
		 "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB "
179
		 "and %d B/blk%s\n",
S
Stefan Haberland 已提交
180 181 182 183 184 185
		 cdev->id.dev_type,
		 cdev->id.dev_model,
		 cdev->id.cu_type,
		 cdev->id.cu_model,
		 ((private->rdc_data.blk_bdsa *
		   (private->rdc_data.blk_size >> 9)) >> 11),
186 187
		 private->rdc_data.blk_size,
		 readonly ? ", read-only device" : "");
L
Linus Torvalds 已提交
188 189 190
	return 0;
}

191
static int dasd_fba_do_analysis(struct dasd_block *block)
L
Linus Torvalds 已提交
192
{
193
	struct dasd_fba_private *private = block->base->private;
L
Linus Torvalds 已提交
194 195 196 197
	int sb, rc;

	rc = dasd_check_blocksize(private->rdc_data.blk_size);
	if (rc) {
S
Stefan Haberland 已提交
198
		DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
L
Linus Torvalds 已提交
199 200 201
			    private->rdc_data.blk_size);
		return rc;
	}
202 203 204
	block->blocks = private->rdc_data.blk_bdsa;
	block->bp_block = private->rdc_data.blk_size;
	block->s2b_shift = 0;	/* bits to shift 512 to get a block */
L
Linus Torvalds 已提交
205
	for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
206
		block->s2b_shift++;
L
Linus Torvalds 已提交
207 208 209
	return 0;
}

210 211
static int dasd_fba_fill_geometry(struct dasd_block *block,
				  struct hd_geometry *geo)
L
Linus Torvalds 已提交
212
{
213
	if (dasd_check_blocksize(block->bp_block) != 0)
L
Linus Torvalds 已提交
214
		return -EINVAL;
215
	geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
L
Linus Torvalds 已提交
216
	geo->heads = 16;
217
	geo->sectors = 128 >> block->s2b_shift;
L
Linus Torvalds 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	return 0;
}

static dasd_erp_fn_t
dasd_fba_erp_action(struct dasd_ccw_req * cqr)
{
	return dasd_default_erp_action;
}

static dasd_erp_fn_t
dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
{
	if (cqr->function == dasd_default_erp_action)
		return dasd_default_erp_postaction;

S
Stefan Haberland 已提交
233
	DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
L
Linus Torvalds 已提交
234 235 236 237
		    cqr->function);
	return NULL;
}

238 239 240
static void dasd_fba_check_for_device_change(struct dasd_device *device,
					     struct dasd_ccw_req *cqr,
					     struct irb *irb)
241 242 243 244 245
{
	char mask;

	/* first of all check for state change pending interrupt */
	mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
246
	if ((irb->scsw.cmd.dstat & mask) == mask)
247 248 249 250 251 252
		dasd_generic_handle_state_change(device);
};

static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
					      struct dasd_block *block,
					      struct request *req)
L
Linus Torvalds 已提交
253
{
254
	struct dasd_fba_private *private = block->base->private;
L
Linus Torvalds 已提交
255 256 257 258
	unsigned long *idaws;
	struct LO_fba_data *LO_data;
	struct dasd_ccw_req *cqr;
	struct ccw1 *ccw;
259
	struct req_iterator iter;
260
	struct bio_vec bv;
L
Linus Torvalds 已提交
261 262 263 264 265 266 267 268 269 270 271 272
	char *dst;
	int count, cidaw, cplength, datasize;
	sector_t recid, first_rec, last_rec;
	unsigned int blksize, off;
	unsigned char cmd;

	if (rq_data_dir(req) == READ) {
		cmd = DASD_FBA_CCW_READ;
	} else if (rq_data_dir(req) == WRITE) {
		cmd = DASD_FBA_CCW_WRITE;
	} else
		return ERR_PTR(-EINVAL);
273
	blksize = block->bp_block;
L
Linus Torvalds 已提交
274
	/* Calculate record id of first and last block. */
275 276 277
	first_rec = blk_rq_pos(req) >> block->s2b_shift;
	last_rec =
		(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
L
Linus Torvalds 已提交
278 279 280
	/* Check struct bio and count the number of blocks for the request. */
	count = 0;
	cidaw = 0;
281
	rq_for_each_segment(bv, req, iter) {
282
		if (bv.bv_len & (blksize - 1))
283 284
			/* Fba can only do full blocks. */
			return ERR_PTR(-EINVAL);
285 286 287
		count += bv.bv_len >> (block->s2b_shift + 9);
		if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
			cidaw += bv.bv_len / blksize;
L
Linus Torvalds 已提交
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
	}
	/* Paranoia. */
	if (count != last_rec - first_rec + 1)
		return ERR_PTR(-EINVAL);
	/* 1x define extent + 1x locate record + number of blocks */
	cplength = 2 + count;
	/* 1x define extent + 1x locate record */
	datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
		cidaw * sizeof(unsigned long);
	/*
	 * Find out number of additional locate record ccws if the device
	 * can't do data chaining.
	 */
	if (private->rdc_data.mode.bits.data_chain == 0) {
		cplength += count - 1;
		datasize += (count - 1)*sizeof(struct LO_fba_data);
	}
	/* Allocate the ccw request. */
306
	cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev);
L
Linus Torvalds 已提交
307 308 309 310 311
	if (IS_ERR(cqr))
		return cqr;
	ccw = cqr->cpaddr;
	/* First ccw is define extent. */
	define_extent(ccw++, cqr->data, rq_data_dir(req),
312
		      block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
L
Linus Torvalds 已提交
313 314 315 316 317 318 319 320 321
	/* Build locate_record + read/write ccws. */
	idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
	LO_data = (struct LO_fba_data *) (idaws + cidaw);
	/* Locate record for all blocks for smart devices. */
	if (private->rdc_data.mode.bits.data_chain != 0) {
		ccw[-1].flags |= CCW_FLAG_CC;
		locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
	}
	recid = first_rec;
322
	rq_for_each_segment(bv, req, iter) {
323
		dst = page_address(bv.bv_page) + bv.bv_offset;
L
Linus Torvalds 已提交
324 325
		if (dasd_page_cache) {
			char *copy = kmem_cache_alloc(dasd_page_cache,
C
Christoph Lameter 已提交
326
						      GFP_DMA | __GFP_NOWARN);
L
Linus Torvalds 已提交
327
			if (copy && rq_data_dir(req) == WRITE)
328
				memcpy(copy + bv.bv_offset, dst, bv.bv_len);
L
Linus Torvalds 已提交
329
			if (copy)
330
				dst = copy + bv.bv_offset;
L
Linus Torvalds 已提交
331
		}
332
		for (off = 0; off < bv.bv_len; off += blksize) {
L
Linus Torvalds 已提交
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
			/* Locate record for stupid devices. */
			if (private->rdc_data.mode.bits.data_chain == 0) {
				ccw[-1].flags |= CCW_FLAG_CC;
				locate_record(ccw, LO_data++,
					      rq_data_dir(req),
					      recid - first_rec, 1);
				ccw->flags = CCW_FLAG_CC;
				ccw++;
			} else {
				if (recid > first_rec)
					ccw[-1].flags |= CCW_FLAG_DC;
				else
					ccw[-1].flags |= CCW_FLAG_CC;
			}
			ccw->cmd_code = cmd;
348
			ccw->count = block->bp_block;
L
Linus Torvalds 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361
			if (idal_is_needed(dst, blksize)) {
				ccw->cda = (__u32)(addr_t) idaws;
				ccw->flags = CCW_FLAG_IDA;
				idaws = idal_create_words(idaws, dst, blksize);
			} else {
				ccw->cda = (__u32)(addr_t) dst;
				ccw->flags = 0;
			}
			ccw++;
			dst += blksize;
			recid++;
		}
	}
362 363
	if (blk_noretry_request(req) ||
	    block->base->features & DASD_FEATURE_FAILFAST)
364
		set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
365 366 367
	cqr->startdev = memdev;
	cqr->memdev = memdev;
	cqr->block = block;
368
	cqr->expires = memdev->default_expires * HZ;	/* default 5 minutes */
369
	cqr->retries = memdev->default_retries;
370
	cqr->buildclk = get_tod_clock();
L
Linus Torvalds 已提交
371 372 373 374 375 376 377
	cqr->status = DASD_CQR_FILLED;
	return cqr;
}

static int
dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
{
378
	struct dasd_fba_private *private = cqr->block->base->private;
L
Linus Torvalds 已提交
379
	struct ccw1 *ccw;
380
	struct req_iterator iter;
381
	struct bio_vec bv;
L
Linus Torvalds 已提交
382 383
	char *dst, *cda;
	unsigned int blksize, off;
384
	int status;
L
Linus Torvalds 已提交
385 386 387

	if (!dasd_page_cache)
		goto out;
388
	blksize = cqr->block->bp_block;
L
Linus Torvalds 已提交
389 390 391 392 393
	ccw = cqr->cpaddr;
	/* Skip over define extent & locate record. */
	ccw++;
	if (private->rdc_data.mode.bits.data_chain != 0)
		ccw++;
394
	rq_for_each_segment(bv, req, iter) {
395 396
		dst = page_address(bv.bv_page) + bv.bv_offset;
		for (off = 0; off < bv.bv_len; off += blksize) {
L
Linus Torvalds 已提交
397 398 399 400 401 402 403 404 405 406
			/* Skip locate record. */
			if (private->rdc_data.mode.bits.data_chain == 0)
				ccw++;
			if (dst) {
				if (ccw->flags & CCW_FLAG_IDA)
					cda = *((char **)((addr_t) ccw->cda));
				else
					cda = (char *)((addr_t) ccw->cda);
				if (dst != cda) {
					if (rq_data_dir(req) == READ)
407
						memcpy(dst, cda, bv.bv_len);
L
Linus Torvalds 已提交
408 409 410 411 412 413 414 415 416 417
					kmem_cache_free(dasd_page_cache,
					    (void *)((addr_t)cda & PAGE_MASK));
				}
				dst = NULL;
			}
			ccw++;
		}
	}
out:
	status = cqr->status == DASD_CQR_DONE;
418
	dasd_sfree_request(cqr, cqr->memdev);
L
Linus Torvalds 已提交
419 420 421
	return status;
}

422 423
static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
{
424 425 426 427
	if (cqr->retries < 0)
		cqr->status = DASD_CQR_FAILED;
	else
		cqr->status = DASD_CQR_FILLED;
428 429
};

L
Linus Torvalds 已提交
430 431 432 433
static int
dasd_fba_fill_info(struct dasd_device * device,
		   struct dasd_information2_t * info)
{
434 435
	struct dasd_fba_private *private = device->private;

L
Linus Torvalds 已提交
436 437 438
	info->label_block = 1;
	info->FBA_layout = 1;
	info->format = DASD_FORMAT_LDL;
439 440 441
	info->characteristics_size = sizeof(private->rdc_data);
	memcpy(info->characteristics, &private->rdc_data,
	       sizeof(private->rdc_data));
L
Linus Torvalds 已提交
442 443 444 445
	info->confdata_size = 0;
	return 0;
}

S
Stefan Haberland 已提交
446
static void
447 448
dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
			char *reason)
S
Stefan Haberland 已提交
449
{
450 451 452 453 454 455 456 457 458 459 460
	u64 *sense;

	sense = (u64 *) dasd_get_sense(irb);
	if (sense) {
		DBF_DEV_EVENT(DBF_EMERG, device,
			      "%s: %s %02x%02x%02x %016llx %016llx %016llx "
			      "%016llx", reason,
			      scsw_is_tm(&irb->scsw) ? "t" : "c",
			      scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
			      scsw_dstat(&irb->scsw), sense[0], sense[1],
			      sense[2], sense[3]);
S
Stefan Haberland 已提交
461 462 463 464 465 466 467
	} else {
		DBF_DEV_EVENT(DBF_EMERG, device, "%s",
			      "SORRY - NO VALID SENSE AVAILABLE\n");
	}
}


L
Linus Torvalds 已提交
468 469 470 471 472 473 474 475 476 477
static void
dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
		    struct irb *irb)
{
	char *page;
	struct ccw1 *act, *end, *last;
	int len, sl, sct, count;

	page = (char *) get_zeroed_page(GFP_ATOMIC);
	if (page == NULL) {
S
Stefan Haberland 已提交
478
		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
L
Linus Torvalds 已提交
479 480 481
			    "No memory to dump sense data");
		return;
	}
482
	len = sprintf(page, PRINTK_HEADER
L
Linus Torvalds 已提交
483
		      " I/O status report for device %s:\n",
484
		      dev_name(&device->cdev->dev));
485
	len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
486
		       " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
487
		       irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
488
	len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
489
		       " device %s: Failing CCW: %p\n",
490
		       dev_name(&device->cdev->dev),
491
		       (void *) (addr_t) irb->scsw.cmd.cpa);
L
Linus Torvalds 已提交
492 493
	if (irb->esw.esw0.erw.cons) {
		for (sl = 0; sl < 4; sl++) {
494
			len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
495 496 497 498 499 500 501 502 503 504
				       " Sense(hex) %2d-%2d:",
				       (8 * sl), ((8 * sl) + 7));

			for (sct = 0; sct < 8; sct++) {
				len += sprintf(page + len, " %02x",
					       irb->ecw[8 * sl + sct]);
			}
			len += sprintf(page + len, "\n");
		}
	} else {
505
		len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
506 507
			       " SORRY - NO VALID SENSE AVAILABLE\n");
	}
S
Stefan Haberland 已提交
508
	printk(KERN_ERR "%s", page);
L
Linus Torvalds 已提交
509 510 511 512 513 514

	/* dump the Channel Program */
	/* print first CCWs (maximum 8) */
	act = req->cpaddr;
        for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
	end = min(act + 8, last);
515
	len = sprintf(page, PRINTK_HEADER " Related CP in req: %p\n", req);
L
Linus Torvalds 已提交
516
	while (act <= end) {
517
		len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
518 519 520 521 522 523 524 525 526 527
			       " CCW %p: %08X %08X DAT:",
			       act, ((int *) act)[0], ((int *) act)[1]);
		for (count = 0; count < 32 && count < act->count;
		     count += sizeof(int))
			len += sprintf(page + len, " %08X",
				       ((int *) (addr_t) act->cda)
				       [(count>>2)]);
		len += sprintf(page + len, "\n");
		act++;
	}
S
Stefan Haberland 已提交
528
	printk(KERN_ERR "%s", page);
L
Linus Torvalds 已提交
529 530 531 532


	/* print failing CCW area */
	len = 0;
533 534
	if (act <  ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
		act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
535
		len += sprintf(page + len, PRINTK_HEADER "......\n");
L
Linus Torvalds 已提交
536
	}
537
	end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
L
Linus Torvalds 已提交
538
	while (act <= end) {
539
		len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
540 541 542 543 544 545 546 547 548 549 550 551 552 553
			       " CCW %p: %08X %08X DAT:",
			       act, ((int *) act)[0], ((int *) act)[1]);
		for (count = 0; count < 32 && count < act->count;
		     count += sizeof(int))
			len += sprintf(page + len, " %08X",
				       ((int *) (addr_t) act->cda)
				       [(count>>2)]);
		len += sprintf(page + len, "\n");
		act++;
	}

	/* print last CCWs */
	if (act <  last - 2) {
		act = last - 2;
554
		len += sprintf(page + len, PRINTK_HEADER "......\n");
L
Linus Torvalds 已提交
555 556
	}
	while (act <= last) {
557
		len += sprintf(page + len, PRINTK_HEADER
L
Linus Torvalds 已提交
558 559 560 561 562 563 564 565 566 567 568
			       " CCW %p: %08X %08X DAT:",
			       act, ((int *) act)[0], ((int *) act)[1]);
		for (count = 0; count < 32 && count < act->count;
		     count += sizeof(int))
			len += sprintf(page + len, " %08X",
				       ((int *) (addr_t) act->cda)
				       [(count>>2)]);
		len += sprintf(page + len, "\n");
		act++;
	}
	if (len > 0)
S
Stefan Haberland 已提交
569
		printk(KERN_ERR "%s", page);
L
Linus Torvalds 已提交
570 571 572 573 574 575 576 577 578
	free_page((unsigned long) page);
}

/*
 * max_blocks is dependent on the amount of storage that is available
 * in the static io buffer for each device. Currently each device has
 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
579
 * addition we have one define extent ccw + 16 bytes of data and a
L
Linus Torvalds 已提交
580 581 582 583 584 585 586 587 588 589 590 591 592 593
 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
 * That makes:
 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
 * We want to fit two into the available memory so that we can immediately
 * start the next request if one finishes off. That makes 100.1 blocks
 * for one request. Give a little safety and the result is 96.
 */
static struct dasd_discipline dasd_fba_discipline = {
	.owner = THIS_MODULE,
	.name = "FBA ",
	.ebcname = "FBA ",
	.max_blocks = 96,
	.check_device = dasd_fba_check_characteristics,
	.do_analysis = dasd_fba_do_analysis,
594
	.verify_path = dasd_generic_verify_path,
L
Linus Torvalds 已提交
595 596 597
	.fill_geometry = dasd_fba_fill_geometry,
	.start_IO = dasd_start_IO,
	.term_IO = dasd_term_IO,
598
	.handle_terminated_request = dasd_fba_handle_terminated_request,
L
Linus Torvalds 已提交
599 600
	.erp_action = dasd_fba_erp_action,
	.erp_postaction = dasd_fba_erp_postaction,
601
	.check_for_device_change = dasd_fba_check_for_device_change,
L
Linus Torvalds 已提交
602 603 604
	.build_cp = dasd_fba_build_cp,
	.free_cp = dasd_fba_free_cp,
	.dump_sense = dasd_fba_dump_sense,
S
Stefan Haberland 已提交
605
	.dump_sense_dbf = dasd_fba_dump_sense_dbf,
L
Linus Torvalds 已提交
606 607 608 609 610 611
	.fill_info = dasd_fba_fill_info,
};

static int __init
dasd_fba_init(void)
{
612 613
	int ret;

L
Linus Torvalds 已提交
614
	ASCEBC(dasd_fba_discipline.ebcname, 4);
615 616 617 618 619
	ret = ccw_driver_register(&dasd_fba_driver);
	if (!ret)
		wait_for_device_probe();

	return ret;
L
Linus Torvalds 已提交
620 621 622 623 624 625 626 627 628 629
}

static void __exit
dasd_fba_cleanup(void)
{
	ccw_driver_unregister(&dasd_fba_driver);
}

module_init(dasd_fba_init);
module_exit(dasd_fba_cleanup);