xref: /openbmc/linux/drivers/s390/block/dasd_fba.c (revision 138c014d)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * File...........: linux/drivers/s390/block/dasd_fba.c
31da177e4SLinus Torvalds  * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
41da177e4SLinus Torvalds  * Bugreports.to..: <Linux390@de.ibm.com>
51da177e4SLinus Torvalds  * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #include <linux/config.h>
101da177e4SLinus Torvalds #include <linux/stddef.h>
111da177e4SLinus Torvalds #include <linux/kernel.h>
121da177e4SLinus Torvalds #include <asm/debug.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/slab.h>
151da177e4SLinus Torvalds #include <linux/hdreg.h>	/* HDIO_GETGEO			    */
161da177e4SLinus Torvalds #include <linux/bio.h>
171da177e4SLinus Torvalds #include <linux/module.h>
181da177e4SLinus Torvalds #include <linux/init.h>
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds #include <asm/idals.h>
211da177e4SLinus Torvalds #include <asm/ebcdic.h>
221da177e4SLinus Torvalds #include <asm/io.h>
231da177e4SLinus Torvalds #include <asm/todclk.h>
241da177e4SLinus Torvalds #include <asm/ccwdev.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include "dasd_int.h"
271da177e4SLinus Torvalds #include "dasd_fba.h"
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #ifdef PRINTK_HEADER
301da177e4SLinus Torvalds #undef PRINTK_HEADER
311da177e4SLinus Torvalds #endif				/* PRINTK_HEADER */
321da177e4SLinus Torvalds #define PRINTK_HEADER "dasd(fba):"
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds #define DASD_FBA_CCW_WRITE 0x41
351da177e4SLinus Torvalds #define DASD_FBA_CCW_READ 0x42
361da177e4SLinus Torvalds #define DASD_FBA_CCW_LOCATE 0x43
371da177e4SLinus Torvalds #define DASD_FBA_CCW_DEFINE_EXTENT 0x63
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds MODULE_LICENSE("GPL");
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds static struct dasd_discipline dasd_fba_discipline;
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds struct dasd_fba_private {
441da177e4SLinus Torvalds 	struct dasd_fba_characteristics rdc_data;
451da177e4SLinus Torvalds };
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds static struct ccw_device_id dasd_fba_ids[] = {
481da177e4SLinus Torvalds 	{ CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), driver_info: 0x1},
491da177e4SLinus Torvalds 	{ CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), driver_info: 0x2},
501da177e4SLinus Torvalds 	{ /* end of list */ },
511da177e4SLinus Torvalds };
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds static struct ccw_driver dasd_fba_driver; /* see below */
561da177e4SLinus Torvalds static int
571da177e4SLinus Torvalds dasd_fba_probe(struct ccw_device *cdev)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds 	int ret;
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds 	ret = dasd_generic_probe (cdev, &dasd_fba_discipline);
621da177e4SLinus Torvalds 	if (ret)
631da177e4SLinus Torvalds 		return ret;
641da177e4SLinus Torvalds 	ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
651da177e4SLinus Torvalds 	return 0;
661da177e4SLinus Torvalds }
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds static int
691da177e4SLinus Torvalds dasd_fba_set_online(struct ccw_device *cdev)
701da177e4SLinus Torvalds {
711da177e4SLinus Torvalds 	return dasd_generic_set_online (cdev, &dasd_fba_discipline);
721da177e4SLinus Torvalds }
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds static struct ccw_driver dasd_fba_driver = {
751da177e4SLinus Torvalds 	.name        = "dasd-fba",
761da177e4SLinus Torvalds 	.owner       = THIS_MODULE,
771da177e4SLinus Torvalds 	.ids         = dasd_fba_ids,
781da177e4SLinus Torvalds 	.probe       = dasd_fba_probe,
791da177e4SLinus Torvalds 	.remove      = dasd_generic_remove,
801da177e4SLinus Torvalds 	.set_offline = dasd_generic_set_offline,
811da177e4SLinus Torvalds 	.set_online  = dasd_fba_set_online,
821da177e4SLinus Torvalds 	.notify      = dasd_generic_notify,
831da177e4SLinus Torvalds };
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds static inline void
861da177e4SLinus Torvalds define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
871da177e4SLinus Torvalds 	      int blksize, int beg, int nr)
881da177e4SLinus Torvalds {
891da177e4SLinus Torvalds 	ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
901da177e4SLinus Torvalds 	ccw->flags = 0;
911da177e4SLinus Torvalds 	ccw->count = 16;
921da177e4SLinus Torvalds 	ccw->cda = (__u32) __pa(data);
931da177e4SLinus Torvalds 	memset(data, 0, sizeof (struct DE_fba_data));
941da177e4SLinus Torvalds 	if (rw == WRITE)
951da177e4SLinus Torvalds 		(data->mask).perm = 0x0;
961da177e4SLinus Torvalds 	else if (rw == READ)
971da177e4SLinus Torvalds 		(data->mask).perm = 0x1;
981da177e4SLinus Torvalds 	else
991da177e4SLinus Torvalds 		data->mask.perm = 0x2;
1001da177e4SLinus Torvalds 	data->blk_size = blksize;
1011da177e4SLinus Torvalds 	data->ext_loc = beg;
1021da177e4SLinus Torvalds 	data->ext_end = nr - 1;
1031da177e4SLinus Torvalds }
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds static inline void
1061da177e4SLinus Torvalds locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
1071da177e4SLinus Torvalds 	      int block_nr, int block_ct)
1081da177e4SLinus Torvalds {
1091da177e4SLinus Torvalds 	ccw->cmd_code = DASD_FBA_CCW_LOCATE;
1101da177e4SLinus Torvalds 	ccw->flags = 0;
1111da177e4SLinus Torvalds 	ccw->count = 8;
1121da177e4SLinus Torvalds 	ccw->cda = (__u32) __pa(data);
1131da177e4SLinus Torvalds 	memset(data, 0, sizeof (struct LO_fba_data));
1141da177e4SLinus Torvalds 	if (rw == WRITE)
1151da177e4SLinus Torvalds 		data->operation.cmd = 0x5;
1161da177e4SLinus Torvalds 	else if (rw == READ)
1171da177e4SLinus Torvalds 		data->operation.cmd = 0x6;
1181da177e4SLinus Torvalds 	else
1191da177e4SLinus Torvalds 		data->operation.cmd = 0x8;
1201da177e4SLinus Torvalds 	data->blk_nr = block_nr;
1211da177e4SLinus Torvalds 	data->blk_ct = block_ct;
1221da177e4SLinus Torvalds }
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds static int
1251da177e4SLinus Torvalds dasd_fba_check_characteristics(struct dasd_device *device)
1261da177e4SLinus Torvalds {
1271da177e4SLinus Torvalds 	struct dasd_fba_private *private;
1281da177e4SLinus Torvalds 	struct ccw_device *cdev = device->cdev;
1291da177e4SLinus Torvalds 	void *rdc_data;
1301da177e4SLinus Torvalds 	int rc;
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds 	private = (struct dasd_fba_private *) device->private;
1331da177e4SLinus Torvalds 	if (private == NULL) {
134138c014dSHorst Hummel 		private = kzalloc(sizeof(struct dasd_fba_private), GFP_KERNEL);
1351da177e4SLinus Torvalds 		if (private == NULL) {
1361da177e4SLinus Torvalds 			DEV_MESSAGE(KERN_WARNING, device, "%s",
1371da177e4SLinus Torvalds 				    "memory allocation failed for private "
1381da177e4SLinus Torvalds 				    "data");
1391da177e4SLinus Torvalds 			return -ENOMEM;
1401da177e4SLinus Torvalds 		}
1411da177e4SLinus Torvalds 		device->private = (void *) private;
1421da177e4SLinus Torvalds 	}
1431da177e4SLinus Torvalds 	/* Read Device Characteristics */
1441da177e4SLinus Torvalds 	rdc_data = (void *) &(private->rdc_data);
1451da177e4SLinus Torvalds 	rc = read_dev_chars(device->cdev, &rdc_data, 32);
1461da177e4SLinus Torvalds 	if (rc) {
1471da177e4SLinus Torvalds 		DEV_MESSAGE(KERN_WARNING, device,
1481da177e4SLinus Torvalds 			    "Read device characteristics returned error %d",
1491da177e4SLinus Torvalds 			    rc);
1501da177e4SLinus Torvalds 		return rc;
1511da177e4SLinus Torvalds 	}
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	DEV_MESSAGE(KERN_INFO, device,
1541da177e4SLinus Torvalds 		    "%04X/%02X(CU:%04X/%02X) %dMB at(%d B/blk)",
1551da177e4SLinus Torvalds 		    cdev->id.dev_type,
1561da177e4SLinus Torvalds 		    cdev->id.dev_model,
1571da177e4SLinus Torvalds 		    cdev->id.cu_type,
1581da177e4SLinus Torvalds 		    cdev->id.cu_model,
1591da177e4SLinus Torvalds 		    ((private->rdc_data.blk_bdsa *
1601da177e4SLinus Torvalds 		      (private->rdc_data.blk_size >> 9)) >> 11),
1611da177e4SLinus Torvalds 		    private->rdc_data.blk_size);
1621da177e4SLinus Torvalds 	return 0;
1631da177e4SLinus Torvalds }
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds static int
1661da177e4SLinus Torvalds dasd_fba_do_analysis(struct dasd_device *device)
1671da177e4SLinus Torvalds {
1681da177e4SLinus Torvalds 	struct dasd_fba_private *private;
1691da177e4SLinus Torvalds 	int sb, rc;
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds 	private = (struct dasd_fba_private *) device->private;
1721da177e4SLinus Torvalds 	rc = dasd_check_blocksize(private->rdc_data.blk_size);
1731da177e4SLinus Torvalds 	if (rc) {
1741da177e4SLinus Torvalds 		DEV_MESSAGE(KERN_INFO, device, "unknown blocksize %d",
1751da177e4SLinus Torvalds 			    private->rdc_data.blk_size);
1761da177e4SLinus Torvalds 		return rc;
1771da177e4SLinus Torvalds 	}
1781da177e4SLinus Torvalds 	device->blocks = private->rdc_data.blk_bdsa;
1791da177e4SLinus Torvalds 	device->bp_block = private->rdc_data.blk_size;
1801da177e4SLinus Torvalds 	device->s2b_shift = 0;	/* bits to shift 512 to get a block */
1811da177e4SLinus Torvalds 	for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
1821da177e4SLinus Torvalds 		device->s2b_shift++;
1831da177e4SLinus Torvalds 	return 0;
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds static int
1871da177e4SLinus Torvalds dasd_fba_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
1881da177e4SLinus Torvalds {
1891da177e4SLinus Torvalds 	if (dasd_check_blocksize(device->bp_block) != 0)
1901da177e4SLinus Torvalds 		return -EINVAL;
1911da177e4SLinus Torvalds 	geo->cylinders = (device->blocks << device->s2b_shift) >> 10;
1921da177e4SLinus Torvalds 	geo->heads = 16;
1931da177e4SLinus Torvalds 	geo->sectors = 128 >> device->s2b_shift;
1941da177e4SLinus Torvalds 	return 0;
1951da177e4SLinus Torvalds }
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds static dasd_era_t
1981da177e4SLinus Torvalds dasd_fba_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
1991da177e4SLinus Torvalds {
2001da177e4SLinus Torvalds 	struct dasd_device *device;
2011da177e4SLinus Torvalds 	struct ccw_device *cdev;
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 	device = (struct dasd_device *) cqr->device;
2041da177e4SLinus Torvalds 	if (irb->scsw.cstat == 0x00 &&
2051da177e4SLinus Torvalds 	    irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
2061da177e4SLinus Torvalds 		return dasd_era_none;
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds 	cdev = device->cdev;
2091da177e4SLinus Torvalds 	switch (cdev->id.dev_type) {
2101da177e4SLinus Torvalds 	case 0x3370:
2111da177e4SLinus Torvalds 		return dasd_3370_erp_examine(cqr, irb);
2121da177e4SLinus Torvalds 	case 0x9336:
2131da177e4SLinus Torvalds 		return dasd_9336_erp_examine(cqr, irb);
2141da177e4SLinus Torvalds 	default:
2151da177e4SLinus Torvalds 		return dasd_era_recover;
2161da177e4SLinus Torvalds 	}
2171da177e4SLinus Torvalds }
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds static dasd_erp_fn_t
2201da177e4SLinus Torvalds dasd_fba_erp_action(struct dasd_ccw_req * cqr)
2211da177e4SLinus Torvalds {
2221da177e4SLinus Torvalds 	return dasd_default_erp_action;
2231da177e4SLinus Torvalds }
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds static dasd_erp_fn_t
2261da177e4SLinus Torvalds dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
2271da177e4SLinus Torvalds {
2281da177e4SLinus Torvalds 	if (cqr->function == dasd_default_erp_action)
2291da177e4SLinus Torvalds 		return dasd_default_erp_postaction;
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	DEV_MESSAGE(KERN_WARNING, cqr->device, "unknown ERP action %p",
2321da177e4SLinus Torvalds 		    cqr->function);
2331da177e4SLinus Torvalds 	return NULL;
2341da177e4SLinus Torvalds }
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds static struct dasd_ccw_req *
2371da177e4SLinus Torvalds dasd_fba_build_cp(struct dasd_device * device, struct request *req)
2381da177e4SLinus Torvalds {
2391da177e4SLinus Torvalds 	struct dasd_fba_private *private;
2401da177e4SLinus Torvalds 	unsigned long *idaws;
2411da177e4SLinus Torvalds 	struct LO_fba_data *LO_data;
2421da177e4SLinus Torvalds 	struct dasd_ccw_req *cqr;
2431da177e4SLinus Torvalds 	struct ccw1 *ccw;
2441da177e4SLinus Torvalds 	struct bio *bio;
2451da177e4SLinus Torvalds 	struct bio_vec *bv;
2461da177e4SLinus Torvalds 	char *dst;
2471da177e4SLinus Torvalds 	int count, cidaw, cplength, datasize;
2481da177e4SLinus Torvalds 	sector_t recid, first_rec, last_rec;
2491da177e4SLinus Torvalds 	unsigned int blksize, off;
2501da177e4SLinus Torvalds 	unsigned char cmd;
2511da177e4SLinus Torvalds 	int i;
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	private = (struct dasd_fba_private *) device->private;
2541da177e4SLinus Torvalds 	if (rq_data_dir(req) == READ) {
2551da177e4SLinus Torvalds 		cmd = DASD_FBA_CCW_READ;
2561da177e4SLinus Torvalds 	} else if (rq_data_dir(req) == WRITE) {
2571da177e4SLinus Torvalds 		cmd = DASD_FBA_CCW_WRITE;
2581da177e4SLinus Torvalds 	} else
2591da177e4SLinus Torvalds 		return ERR_PTR(-EINVAL);
2601da177e4SLinus Torvalds 	blksize = device->bp_block;
2611da177e4SLinus Torvalds 	/* Calculate record id of first and last block. */
2621da177e4SLinus Torvalds 	first_rec = req->sector >> device->s2b_shift;
2631da177e4SLinus Torvalds 	last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
2641da177e4SLinus Torvalds 	/* Check struct bio and count the number of blocks for the request. */
2651da177e4SLinus Torvalds 	count = 0;
2661da177e4SLinus Torvalds 	cidaw = 0;
2671da177e4SLinus Torvalds 	rq_for_each_bio(bio, req) {
2681da177e4SLinus Torvalds 		bio_for_each_segment(bv, bio, i) {
2691da177e4SLinus Torvalds 			if (bv->bv_len & (blksize - 1))
2701da177e4SLinus Torvalds 				/* Fba can only do full blocks. */
2711da177e4SLinus Torvalds 				return ERR_PTR(-EINVAL);
2721da177e4SLinus Torvalds 			count += bv->bv_len >> (device->s2b_shift + 9);
273347a8dc3SMartin Schwidefsky #if defined(CONFIG_64BIT)
2741da177e4SLinus Torvalds 			if (idal_is_needed (page_address(bv->bv_page),
2751da177e4SLinus Torvalds 					    bv->bv_len))
2761da177e4SLinus Torvalds 				cidaw += bv->bv_len / blksize;
2771da177e4SLinus Torvalds #endif
2781da177e4SLinus Torvalds 		}
2791da177e4SLinus Torvalds 	}
2801da177e4SLinus Torvalds 	/* Paranoia. */
2811da177e4SLinus Torvalds 	if (count != last_rec - first_rec + 1)
2821da177e4SLinus Torvalds 		return ERR_PTR(-EINVAL);
2831da177e4SLinus Torvalds 	/* 1x define extent + 1x locate record + number of blocks */
2841da177e4SLinus Torvalds 	cplength = 2 + count;
2851da177e4SLinus Torvalds 	/* 1x define extent + 1x locate record */
2861da177e4SLinus Torvalds 	datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
2871da177e4SLinus Torvalds 		cidaw * sizeof(unsigned long);
2881da177e4SLinus Torvalds 	/*
2891da177e4SLinus Torvalds 	 * Find out number of additional locate record ccws if the device
2901da177e4SLinus Torvalds 	 * can't do data chaining.
2911da177e4SLinus Torvalds 	 */
2921da177e4SLinus Torvalds 	if (private->rdc_data.mode.bits.data_chain == 0) {
2931da177e4SLinus Torvalds 		cplength += count - 1;
2941da177e4SLinus Torvalds 		datasize += (count - 1)*sizeof(struct LO_fba_data);
2951da177e4SLinus Torvalds 	}
2961da177e4SLinus Torvalds 	/* Allocate the ccw request. */
2971da177e4SLinus Torvalds 	cqr = dasd_smalloc_request(dasd_fba_discipline.name,
2981da177e4SLinus Torvalds 				   cplength, datasize, device);
2991da177e4SLinus Torvalds 	if (IS_ERR(cqr))
3001da177e4SLinus Torvalds 		return cqr;
3011da177e4SLinus Torvalds 	ccw = cqr->cpaddr;
3021da177e4SLinus Torvalds 	/* First ccw is define extent. */
3031da177e4SLinus Torvalds 	define_extent(ccw++, cqr->data, rq_data_dir(req),
3041da177e4SLinus Torvalds 		      device->bp_block, req->sector, req->nr_sectors);
3051da177e4SLinus Torvalds 	/* Build locate_record + read/write ccws. */
3061da177e4SLinus Torvalds 	idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
3071da177e4SLinus Torvalds 	LO_data = (struct LO_fba_data *) (idaws + cidaw);
3081da177e4SLinus Torvalds 	/* Locate record for all blocks for smart devices. */
3091da177e4SLinus Torvalds 	if (private->rdc_data.mode.bits.data_chain != 0) {
3101da177e4SLinus Torvalds 		ccw[-1].flags |= CCW_FLAG_CC;
3111da177e4SLinus Torvalds 		locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
3121da177e4SLinus Torvalds 	}
3131da177e4SLinus Torvalds 	recid = first_rec;
3141da177e4SLinus Torvalds 	rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
3151da177e4SLinus Torvalds 		dst = page_address(bv->bv_page) + bv->bv_offset;
3161da177e4SLinus Torvalds 		if (dasd_page_cache) {
3171da177e4SLinus Torvalds 			char *copy = kmem_cache_alloc(dasd_page_cache,
3181da177e4SLinus Torvalds 						      SLAB_DMA | __GFP_NOWARN);
3191da177e4SLinus Torvalds 			if (copy && rq_data_dir(req) == WRITE)
3201da177e4SLinus Torvalds 				memcpy(copy + bv->bv_offset, dst, bv->bv_len);
3211da177e4SLinus Torvalds 			if (copy)
3221da177e4SLinus Torvalds 				dst = copy + bv->bv_offset;
3231da177e4SLinus Torvalds 		}
3241da177e4SLinus Torvalds 		for (off = 0; off < bv->bv_len; off += blksize) {
3251da177e4SLinus Torvalds 			/* Locate record for stupid devices. */
3261da177e4SLinus Torvalds 			if (private->rdc_data.mode.bits.data_chain == 0) {
3271da177e4SLinus Torvalds 				ccw[-1].flags |= CCW_FLAG_CC;
3281da177e4SLinus Torvalds 				locate_record(ccw, LO_data++,
3291da177e4SLinus Torvalds 					      rq_data_dir(req),
3301da177e4SLinus Torvalds 					      recid - first_rec, 1);
3311da177e4SLinus Torvalds 				ccw->flags = CCW_FLAG_CC;
3321da177e4SLinus Torvalds 				ccw++;
3331da177e4SLinus Torvalds 			} else {
3341da177e4SLinus Torvalds 				if (recid > first_rec)
3351da177e4SLinus Torvalds 					ccw[-1].flags |= CCW_FLAG_DC;
3361da177e4SLinus Torvalds 				else
3371da177e4SLinus Torvalds 					ccw[-1].flags |= CCW_FLAG_CC;
3381da177e4SLinus Torvalds 			}
3391da177e4SLinus Torvalds 			ccw->cmd_code = cmd;
3401da177e4SLinus Torvalds 			ccw->count = device->bp_block;
3411da177e4SLinus Torvalds 			if (idal_is_needed(dst, blksize)) {
3421da177e4SLinus Torvalds 				ccw->cda = (__u32)(addr_t) idaws;
3431da177e4SLinus Torvalds 				ccw->flags = CCW_FLAG_IDA;
3441da177e4SLinus Torvalds 				idaws = idal_create_words(idaws, dst, blksize);
3451da177e4SLinus Torvalds 			} else {
3461da177e4SLinus Torvalds 				ccw->cda = (__u32)(addr_t) dst;
3471da177e4SLinus Torvalds 				ccw->flags = 0;
3481da177e4SLinus Torvalds 			}
3491da177e4SLinus Torvalds 			ccw++;
3501da177e4SLinus Torvalds 			dst += blksize;
3511da177e4SLinus Torvalds 			recid++;
3521da177e4SLinus Torvalds 		}
3531da177e4SLinus Torvalds 	}
3541c01b8a5SHorst Hummel 	if (req->flags & REQ_FAILFAST)
3551c01b8a5SHorst Hummel 		set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3561da177e4SLinus Torvalds 	cqr->device = device;
3571da177e4SLinus Torvalds 	cqr->expires = 5 * 60 * HZ;	/* 5 minutes */
358d61f6f3dSHorst Hummel 	cqr->retries = 32;
359d61f6f3dSHorst Hummel 	cqr->buildclk = get_clock();
3601da177e4SLinus Torvalds 	cqr->status = DASD_CQR_FILLED;
3611da177e4SLinus Torvalds 	return cqr;
3621da177e4SLinus Torvalds }
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds static int
3651da177e4SLinus Torvalds dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3661da177e4SLinus Torvalds {
3671da177e4SLinus Torvalds 	struct dasd_fba_private *private;
3681da177e4SLinus Torvalds 	struct ccw1 *ccw;
3691da177e4SLinus Torvalds 	struct bio *bio;
3701da177e4SLinus Torvalds 	struct bio_vec *bv;
3711da177e4SLinus Torvalds 	char *dst, *cda;
3721da177e4SLinus Torvalds 	unsigned int blksize, off;
3731da177e4SLinus Torvalds 	int i, status;
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds 	if (!dasd_page_cache)
3761da177e4SLinus Torvalds 		goto out;
3771da177e4SLinus Torvalds 	private = (struct dasd_fba_private *) cqr->device->private;
3781da177e4SLinus Torvalds 	blksize = cqr->device->bp_block;
3791da177e4SLinus Torvalds 	ccw = cqr->cpaddr;
3801da177e4SLinus Torvalds 	/* Skip over define extent & locate record. */
3811da177e4SLinus Torvalds 	ccw++;
3821da177e4SLinus Torvalds 	if (private->rdc_data.mode.bits.data_chain != 0)
3831da177e4SLinus Torvalds 		ccw++;
3841da177e4SLinus Torvalds 	rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
3851da177e4SLinus Torvalds 		dst = page_address(bv->bv_page) + bv->bv_offset;
3861da177e4SLinus Torvalds 		for (off = 0; off < bv->bv_len; off += blksize) {
3871da177e4SLinus Torvalds 			/* Skip locate record. */
3881da177e4SLinus Torvalds 			if (private->rdc_data.mode.bits.data_chain == 0)
3891da177e4SLinus Torvalds 				ccw++;
3901da177e4SLinus Torvalds 			if (dst) {
3911da177e4SLinus Torvalds 				if (ccw->flags & CCW_FLAG_IDA)
3921da177e4SLinus Torvalds 					cda = *((char **)((addr_t) ccw->cda));
3931da177e4SLinus Torvalds 				else
3941da177e4SLinus Torvalds 					cda = (char *)((addr_t) ccw->cda);
3951da177e4SLinus Torvalds 				if (dst != cda) {
3961da177e4SLinus Torvalds 					if (rq_data_dir(req) == READ)
3971da177e4SLinus Torvalds 						memcpy(dst, cda, bv->bv_len);
3981da177e4SLinus Torvalds 					kmem_cache_free(dasd_page_cache,
3991da177e4SLinus Torvalds 					    (void *)((addr_t)cda & PAGE_MASK));
4001da177e4SLinus Torvalds 				}
4011da177e4SLinus Torvalds 				dst = NULL;
4021da177e4SLinus Torvalds 			}
4031da177e4SLinus Torvalds 			ccw++;
4041da177e4SLinus Torvalds 		}
4051da177e4SLinus Torvalds 	}
4061da177e4SLinus Torvalds out:
4071da177e4SLinus Torvalds 	status = cqr->status == DASD_CQR_DONE;
4081da177e4SLinus Torvalds 	dasd_sfree_request(cqr, cqr->device);
4091da177e4SLinus Torvalds 	return status;
4101da177e4SLinus Torvalds }
4111da177e4SLinus Torvalds 
4121da177e4SLinus Torvalds static int
4131da177e4SLinus Torvalds dasd_fba_fill_info(struct dasd_device * device,
4141da177e4SLinus Torvalds 		   struct dasd_information2_t * info)
4151da177e4SLinus Torvalds {
4161da177e4SLinus Torvalds 	info->label_block = 1;
4171da177e4SLinus Torvalds 	info->FBA_layout = 1;
4181da177e4SLinus Torvalds 	info->format = DASD_FORMAT_LDL;
4191da177e4SLinus Torvalds 	info->characteristics_size = sizeof(struct dasd_fba_characteristics);
4201da177e4SLinus Torvalds 	memcpy(info->characteristics,
4211da177e4SLinus Torvalds 	       &((struct dasd_fba_private *) device->private)->rdc_data,
4221da177e4SLinus Torvalds 	       sizeof (struct dasd_fba_characteristics));
4231da177e4SLinus Torvalds 	info->confdata_size = 0;
4241da177e4SLinus Torvalds 	return 0;
4251da177e4SLinus Torvalds }
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds static void
4281da177e4SLinus Torvalds dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
4291da177e4SLinus Torvalds 		    struct irb *irb)
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds 	char *page;
4321da177e4SLinus Torvalds 	struct ccw1 *act, *end, *last;
4331da177e4SLinus Torvalds 	int len, sl, sct, count;
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds 	page = (char *) get_zeroed_page(GFP_ATOMIC);
4361da177e4SLinus Torvalds 	if (page == NULL) {
4371da177e4SLinus Torvalds 		DEV_MESSAGE(KERN_ERR, device, " %s",
4381da177e4SLinus Torvalds 			    "No memory to dump sense data");
4391da177e4SLinus Torvalds 		return;
4401da177e4SLinus Torvalds 	}
4411da177e4SLinus Torvalds 	len = sprintf(page, KERN_ERR PRINTK_HEADER
4421da177e4SLinus Torvalds 		      " I/O status report for device %s:\n",
4431da177e4SLinus Torvalds 		      device->cdev->dev.bus_id);
4441da177e4SLinus Torvalds 	len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4451da177e4SLinus Torvalds 		       " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
4461da177e4SLinus Torvalds 		       irb->scsw.cstat, irb->scsw.dstat);
4471da177e4SLinus Torvalds 	len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4481da177e4SLinus Torvalds 		       " device %s: Failing CCW: %p\n",
4491da177e4SLinus Torvalds 		       device->cdev->dev.bus_id,
4501da177e4SLinus Torvalds 		       (void *) (addr_t) irb->scsw.cpa);
4511da177e4SLinus Torvalds 	if (irb->esw.esw0.erw.cons) {
4521da177e4SLinus Torvalds 		for (sl = 0; sl < 4; sl++) {
4531da177e4SLinus Torvalds 			len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4541da177e4SLinus Torvalds 				       " Sense(hex) %2d-%2d:",
4551da177e4SLinus Torvalds 				       (8 * sl), ((8 * sl) + 7));
4561da177e4SLinus Torvalds 
4571da177e4SLinus Torvalds 			for (sct = 0; sct < 8; sct++) {
4581da177e4SLinus Torvalds 				len += sprintf(page + len, " %02x",
4591da177e4SLinus Torvalds 					       irb->ecw[8 * sl + sct]);
4601da177e4SLinus Torvalds 			}
4611da177e4SLinus Torvalds 			len += sprintf(page + len, "\n");
4621da177e4SLinus Torvalds 		}
4631da177e4SLinus Torvalds 	} else {
4641da177e4SLinus Torvalds 	        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4651da177e4SLinus Torvalds 			       " SORRY - NO VALID SENSE AVAILABLE\n");
4661da177e4SLinus Torvalds 	}
4671da177e4SLinus Torvalds 	MESSAGE_LOG(KERN_ERR, "%s",
4681da177e4SLinus Torvalds 		    page + sizeof(KERN_ERR PRINTK_HEADER));
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds 	/* dump the Channel Program */
4711da177e4SLinus Torvalds 	/* print first CCWs (maximum 8) */
4721da177e4SLinus Torvalds 	act = req->cpaddr;
4731da177e4SLinus Torvalds         for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4741da177e4SLinus Torvalds 	end = min(act + 8, last);
4751da177e4SLinus Torvalds 	len = sprintf(page, KERN_ERR PRINTK_HEADER
4761da177e4SLinus Torvalds 		      " Related CP in req: %p\n", req);
4771da177e4SLinus Torvalds 	while (act <= end) {
4781da177e4SLinus Torvalds 		len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4791da177e4SLinus Torvalds 			       " CCW %p: %08X %08X DAT:",
4801da177e4SLinus Torvalds 			       act, ((int *) act)[0], ((int *) act)[1]);
4811da177e4SLinus Torvalds 		for (count = 0; count < 32 && count < act->count;
4821da177e4SLinus Torvalds 		     count += sizeof(int))
4831da177e4SLinus Torvalds 			len += sprintf(page + len, " %08X",
4841da177e4SLinus Torvalds 				       ((int *) (addr_t) act->cda)
4851da177e4SLinus Torvalds 				       [(count>>2)]);
4861da177e4SLinus Torvalds 		len += sprintf(page + len, "\n");
4871da177e4SLinus Torvalds 		act++;
4881da177e4SLinus Torvalds 	}
4891da177e4SLinus Torvalds 	MESSAGE_LOG(KERN_ERR, "%s",
4901da177e4SLinus Torvalds 		    page + sizeof(KERN_ERR PRINTK_HEADER));
4911da177e4SLinus Torvalds 
4921da177e4SLinus Torvalds 
4931da177e4SLinus Torvalds 	/* print failing CCW area */
4941da177e4SLinus Torvalds 	len = 0;
4951da177e4SLinus Torvalds 	if (act <  ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2) {
4961da177e4SLinus Torvalds 		act = ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2;
4971da177e4SLinus Torvalds 		len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
4981da177e4SLinus Torvalds 	}
4991da177e4SLinus Torvalds 	end = min((struct ccw1 *)(addr_t) irb->scsw.cpa + 2, last);
5001da177e4SLinus Torvalds 	while (act <= end) {
5011da177e4SLinus Torvalds 		len += sprintf(page + len, KERN_ERR PRINTK_HEADER
5021da177e4SLinus Torvalds 			       " CCW %p: %08X %08X DAT:",
5031da177e4SLinus Torvalds 			       act, ((int *) act)[0], ((int *) act)[1]);
5041da177e4SLinus Torvalds 		for (count = 0; count < 32 && count < act->count;
5051da177e4SLinus Torvalds 		     count += sizeof(int))
5061da177e4SLinus Torvalds 			len += sprintf(page + len, " %08X",
5071da177e4SLinus Torvalds 				       ((int *) (addr_t) act->cda)
5081da177e4SLinus Torvalds 				       [(count>>2)]);
5091da177e4SLinus Torvalds 		len += sprintf(page + len, "\n");
5101da177e4SLinus Torvalds 		act++;
5111da177e4SLinus Torvalds 	}
5121da177e4SLinus Torvalds 
5131da177e4SLinus Torvalds 	/* print last CCWs */
5141da177e4SLinus Torvalds 	if (act <  last - 2) {
5151da177e4SLinus Torvalds 		act = last - 2;
5161da177e4SLinus Torvalds 		len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
5171da177e4SLinus Torvalds 	}
5181da177e4SLinus Torvalds 	while (act <= last) {
5191da177e4SLinus Torvalds 		len += sprintf(page + len, KERN_ERR PRINTK_HEADER
5201da177e4SLinus Torvalds 			       " CCW %p: %08X %08X DAT:",
5211da177e4SLinus Torvalds 			       act, ((int *) act)[0], ((int *) act)[1]);
5221da177e4SLinus Torvalds 		for (count = 0; count < 32 && count < act->count;
5231da177e4SLinus Torvalds 		     count += sizeof(int))
5241da177e4SLinus Torvalds 			len += sprintf(page + len, " %08X",
5251da177e4SLinus Torvalds 				       ((int *) (addr_t) act->cda)
5261da177e4SLinus Torvalds 				       [(count>>2)]);
5271da177e4SLinus Torvalds 		len += sprintf(page + len, "\n");
5281da177e4SLinus Torvalds 		act++;
5291da177e4SLinus Torvalds 	}
5301da177e4SLinus Torvalds 	if (len > 0)
5311da177e4SLinus Torvalds 		MESSAGE_LOG(KERN_ERR, "%s",
5321da177e4SLinus Torvalds 			    page + sizeof(KERN_ERR PRINTK_HEADER));
5331da177e4SLinus Torvalds 	free_page((unsigned long) page);
5341da177e4SLinus Torvalds }
5351da177e4SLinus Torvalds 
5361da177e4SLinus Torvalds /*
5371da177e4SLinus Torvalds  * max_blocks is dependent on the amount of storage that is available
5381da177e4SLinus Torvalds  * in the static io buffer for each device. Currently each device has
5391da177e4SLinus Torvalds  * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5401da177e4SLinus Torvalds  * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5411da177e4SLinus Torvalds  * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5421da177e4SLinus Torvalds  * addition we have one define extent ccw + 16 bytes of data and a
5431da177e4SLinus Torvalds  * locate record ccw for each block (stupid devices!) + 16 bytes of data.
5441da177e4SLinus Torvalds  * That makes:
5451da177e4SLinus Torvalds  * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
5461da177e4SLinus Torvalds  * We want to fit two into the available memory so that we can immediately
5471da177e4SLinus Torvalds  * start the next request if one finishes off. That makes 100.1 blocks
5481da177e4SLinus Torvalds  * for one request. Give a little safety and the result is 96.
5491da177e4SLinus Torvalds  */
5501da177e4SLinus Torvalds static struct dasd_discipline dasd_fba_discipline = {
5511da177e4SLinus Torvalds 	.owner = THIS_MODULE,
5521da177e4SLinus Torvalds 	.name = "FBA ",
5531da177e4SLinus Torvalds 	.ebcname = "FBA ",
5541da177e4SLinus Torvalds 	.max_blocks = 96,
5551da177e4SLinus Torvalds 	.check_device = dasd_fba_check_characteristics,
5561da177e4SLinus Torvalds 	.do_analysis = dasd_fba_do_analysis,
5571da177e4SLinus Torvalds 	.fill_geometry = dasd_fba_fill_geometry,
5581da177e4SLinus Torvalds 	.start_IO = dasd_start_IO,
5591da177e4SLinus Torvalds 	.term_IO = dasd_term_IO,
5601da177e4SLinus Torvalds 	.examine_error = dasd_fba_examine_error,
5611da177e4SLinus Torvalds 	.erp_action = dasd_fba_erp_action,
5621da177e4SLinus Torvalds 	.erp_postaction = dasd_fba_erp_postaction,
5631da177e4SLinus Torvalds 	.build_cp = dasd_fba_build_cp,
5641da177e4SLinus Torvalds 	.free_cp = dasd_fba_free_cp,
5651da177e4SLinus Torvalds 	.dump_sense = dasd_fba_dump_sense,
5661da177e4SLinus Torvalds 	.fill_info = dasd_fba_fill_info,
5671da177e4SLinus Torvalds };
5681da177e4SLinus Torvalds 
5691da177e4SLinus Torvalds static int __init
5701da177e4SLinus Torvalds dasd_fba_init(void)
5711da177e4SLinus Torvalds {
5721da177e4SLinus Torvalds 	int ret;
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds 	ASCEBC(dasd_fba_discipline.ebcname, 4);
5751da177e4SLinus Torvalds 
5761da177e4SLinus Torvalds 	ret = ccw_driver_register(&dasd_fba_driver);
5771da177e4SLinus Torvalds 	if (ret)
5781da177e4SLinus Torvalds 		return ret;
5791da177e4SLinus Torvalds 
5801da177e4SLinus Torvalds 	dasd_generic_auto_online(&dasd_fba_driver);
5811da177e4SLinus Torvalds 	return 0;
5821da177e4SLinus Torvalds }
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds static void __exit
5851da177e4SLinus Torvalds dasd_fba_cleanup(void)
5861da177e4SLinus Torvalds {
5871da177e4SLinus Torvalds 	ccw_driver_unregister(&dasd_fba_driver);
5881da177e4SLinus Torvalds }
5891da177e4SLinus Torvalds 
5901da177e4SLinus Torvalds module_init(dasd_fba_init);
5911da177e4SLinus Torvalds module_exit(dasd_fba_cleanup);
592