blob: a62a75358eb94ab7686373e7e166628e1eaf2773 [file] [log] [blame]
Horst Hummel138c0142006-06-29 14:58:12 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02005 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
Stefan Haberlandca99dab2009-09-11 10:28:30 +02008#define KMSG_COMPONENT "dasd-fba"
Stefan Haberlandfc19f382009-03-26 15:23:49 +01009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/stddef.h>
11#include <linux/kernel.h>
12#include <asm/debug.h>
13
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>
19
20#include <asm/idals.h>
21#include <asm/ebcdic.h>
22#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/ccwdev.h>
24
25#include "dasd_int.h"
26#include "dasd_fba.h"
27
28#ifdef PRINTK_HEADER
29#undef PRINTK_HEADER
30#endif /* PRINTK_HEADER */
31#define PRINTK_HEADER "dasd(fba):"
32
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
37
38MODULE_LICENSE("GPL");
39
40static struct dasd_discipline dasd_fba_discipline;
41
42struct dasd_fba_private {
43 struct dasd_fba_characteristics rdc_data;
44};
45
46static struct ccw_device_id dasd_fba_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020047 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
48 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 { /* end of list */ },
50};
51
52MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
53
54static struct ccw_driver dasd_fba_driver; /* see below */
55static int
56dasd_fba_probe(struct ccw_device *cdev)
57{
Horst Hummel40545572006-06-29 15:08:18 +020058 return dasd_generic_probe(cdev, &dasd_fba_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61static int
62dasd_fba_set_online(struct ccw_device *cdev)
63{
Horst Hummel40545572006-06-29 15:08:18 +020064 return dasd_generic_set_online(cdev, &dasd_fba_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67static struct ccw_driver dasd_fba_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +010068 .driver = {
69 .name = "dasd-fba",
70 .owner = THIS_MODULE,
71 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 .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,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +010078 .path_event = dasd_generic_path_event,
Stefan Haberlandd41dd122009-06-16 10:30:25 +020079 .freeze = dasd_generic_pm_freeze,
80 .thaw = dasd_generic_restore_device,
81 .restore = dasd_generic_restore_device,
Peter Oberparleiterde400d62011-10-30 15:16:04 +010082 .int_class = IOINT_DAS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
Heiko Carstens4d284ca2007-02-05 21:18:53 +010085static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070086define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
87 int blksize, int beg, int nr)
88{
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;
103}
104
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100105static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
107 int block_nr, int block_ct)
108{
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;
122}
123
124static int
125dasd_fba_check_characteristics(struct dasd_device *device)
126{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100127 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct dasd_fba_private *private;
Horst Hummel138c0142006-06-29 14:58:12 +0200129 struct ccw_device *cdev = device->cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 int rc;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100131 int readonly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 private = (struct dasd_fba_private *) device->private;
Sebastian Ott92636b12009-06-12 10:26:37 +0200134 if (!private) {
135 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
136 if (!private) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100137 dev_warn(&device->cdev->dev,
138 "Allocating memory for private DASD "
139 "data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return -ENOMEM;
141 }
142 device->private = (void *) private;
Sebastian Ott92636b12009-06-12 10:26:37 +0200143 } else {
144 memset(private, 0, sizeof(*private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100146 block = dasd_alloc_block();
147 if (IS_ERR(block)) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +0100148 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate "
149 "dasd block structure");
Cornelia Huck73371942008-07-17 17:16:43 +0200150 device->private = NULL;
151 kfree(private);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100152 return PTR_ERR(block);
153 }
154 device->block = block;
155 block->base = device;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +0200158 rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC,
159 &private->rdc_data, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (rc) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +0100161 DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device "
162 "characteristics returned error %d", rc);
Cornelia Huck73371942008-07-17 17:16:43 +0200163 device->block = NULL;
164 dasd_free_block(block);
165 device->private = NULL;
166 kfree(private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return rc;
168 }
169
Stefan Haberland7c8faa82010-08-09 18:13:00 +0200170 device->default_expires = DASD_EXPIRES;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100171 device->path_data.opm = LPM_ANYPATH;
Stefan Haberland7c8faa82010-08-09 18:13:00 +0200172
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100173 readonly = dasd_device_is_ro(device);
174 if (readonly)
175 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
176
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100177 dev_info(&device->cdev->dev,
178 "New FBA DASD %04X/%02X (CU %04X/%02X) with %d MB "
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100179 "and %d B/blk%s\n",
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100180 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),
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100186 private->rdc_data.blk_size,
187 readonly ? ", read-only device" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 return 0;
189}
190
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100191static int dasd_fba_do_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 struct dasd_fba_private *private;
194 int sb, rc;
195
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100196 private = (struct dasd_fba_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 rc = dasd_check_blocksize(private->rdc_data.blk_size);
198 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100199 DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 private->rdc_data.blk_size);
201 return rc;
202 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100203 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100207 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return 0;
209}
210
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100211static int dasd_fba_fill_geometry(struct dasd_block *block,
212 struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100214 if (dasd_check_blocksize(block->bp_block) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100216 geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 geo->heads = 16;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100218 geo->sectors = 128 >> block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return 0;
220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static dasd_erp_fn_t
223dasd_fba_erp_action(struct dasd_ccw_req * cqr)
224{
225 return dasd_default_erp_action;
226}
227
228static dasd_erp_fn_t
229dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
230{
231 if (cqr->function == dasd_default_erp_action)
232 return dasd_default_erp_postaction;
233
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100234 DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 cqr->function);
236 return NULL;
237}
238
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100239static void dasd_fba_check_for_device_change(struct dasd_device *device,
240 struct dasd_ccw_req *cqr,
241 struct irb *irb)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100242{
243 char mask;
244
245 /* first of all check for state change pending interrupt */
246 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100247 if ((irb->scsw.cmd.dstat & mask) == mask)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100248 dasd_generic_handle_state_change(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100249};
250
251static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
252 struct dasd_block *block,
253 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
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;
NeilBrown5705f702007-09-25 12:35:59 +0200260 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100268 private = (struct dasd_fba_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 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);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100275 blksize = block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* Calculate record id of first and last block. */
Tejun Heo83096eb2009-05-07 22:24:39 +0900277 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 /* Check struct bio and count the number of blocks for the request. */
281 count = 0;
282 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +0200283 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200284 if (bv->bv_len & (blksize - 1))
285 /* Fba can only do full blocks. */
286 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100287 count += bv->bv_len >> (block->s2b_shift + 9);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800288#if defined(CONFIG_64BIT)
Jens Axboe6c92e692007-08-16 13:43:12 +0200289 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
290 cidaw += bv->bv_len / blksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
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);
301 /*
302 * Find out number of additional locate record ccws if the device
303 * can't do data chaining.
304 */
305 if (private->rdc_data.mode.bits.data_chain == 0) {
306 cplength += count - 1;
307 datasize += (count - 1)*sizeof(struct LO_fba_data);
308 }
309 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +0200310 cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 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),
Tejun Heo83096eb2009-05-07 22:24:39 +0900316 block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /* 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);
324 }
325 recid = first_rec;
NeilBrown5705f702007-09-25 12:35:59 +0200326 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 dst = page_address(bv->bv_page) + bv->bv_offset;
328 if (dasd_page_cache) {
329 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -0800330 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 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;
335 }
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;
350 }
351 ccw->cmd_code = cmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100352 ccw->count = block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 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;
360 }
361 ccw++;
362 dst += blksize;
363 recid++;
364 }
365 }
Holger Smolinski13de2272009-01-09 12:14:51 +0100366 if (blk_noretry_request(req) ||
367 block->base->features & DASD_FEATURE_FAILFAST)
Horst Hummel1c01b8a2006-01-06 00:19:15 -0800368 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100369 cqr->startdev = memdev;
370 cqr->memdev = memdev;
371 cqr->block = block;
Stefan Haberland7c8faa82010-08-09 18:13:00 +0200372 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
Horst Hummeld61f6f32005-07-27 11:45:02 -0700373 cqr->retries = 32;
374 cqr->buildclk = get_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 cqr->status = DASD_CQR_FILLED;
376 return cqr;
377}
378
379static int
380dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
381{
382 struct dasd_fba_private *private;
383 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200384 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 struct bio_vec *bv;
386 char *dst, *cda;
387 unsigned int blksize, off;
NeilBrown5705f702007-09-25 12:35:59 +0200388 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 if (!dasd_page_cache)
391 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100392 private = (struct dasd_fba_private *) cqr->block->base->private;
393 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 ccw = cqr->cpaddr;
395 /* Skip over define extent & locate record. */
396 ccw++;
397 if (private->rdc_data.mode.bits.data_chain != 0)
398 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +0200399 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 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));
415 }
416 dst = NULL;
417 }
418 ccw++;
419 }
420 }
421out:
422 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100423 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 return status;
425}
426
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100427static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
428{
429 cqr->status = DASD_CQR_FILLED;
430};
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432static int
433dasd_fba_fill_info(struct dasd_device * device,
434 struct dasd_information2_t * info)
435{
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;
445}
446
447static void
Stefan Haberlandaeec92c2009-07-07 16:37:06 +0200448dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
449 char *reason)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100450{
Stefan Haberlandaeec92c2009-07-07 16:37:06 +0200451 u64 *sense;
452
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]);
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100462 } else {
463 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
464 "SORRY - NO VALID SENSE AVAILABLE\n");
465 }
466}
467
468
469static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
471 struct irb *irb)
472{
473 char *page;
474 struct ccw1 *act, *end, *last;
475 int len, sl, sct, count;
476
477 page = (char *) get_zeroed_page(GFP_ATOMIC);
478 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100479 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 "No memory to dump sense data");
481 return;
482 }
483 len = sprintf(page, KERN_ERR PRINTK_HEADER
484 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200485 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
487 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200488 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
490 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200491 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200492 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 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));
498
499 for (sct = 0; sct < 8; sct++) {
500 len += sprintf(page + len, " %02x",
501 irb->ecw[8 * sl + sct]);
502 }
503 len += sprintf(page + len, "\n");
504 }
505 } else {
506 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
507 " SORRY - NO VALID SENSE AVAILABLE\n");
508 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100509 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
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++;
529 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100530 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532
533 /* print failing CCW area */
534 len = 0;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200535 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
536 act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
538 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200539 end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 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++;
551 }
552
553 /* print last CCWs */
554 if (act < last - 2) {
555 act = last - 2;
556 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
557 }
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++;
569 }
570 if (len > 0)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100571 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 free_page((unsigned long) page);
573}
574
575/*
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
Horst Hummel138c0142006-06-29 14:58:12 +0200581 * addition we have one define extent ccw + 16 bytes of data and a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 * 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.
588 */
589static 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,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100596 .verify_path = dasd_generic_verify_path,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .fill_geometry = dasd_fba_fill_geometry,
598 .start_IO = dasd_start_IO,
599 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100600 .handle_terminated_request = dasd_fba_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .erp_action = dasd_fba_erp_action,
602 .erp_postaction = dasd_fba_erp_postaction,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100603 .check_for_device_change = dasd_fba_check_for_device_change,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .build_cp = dasd_fba_build_cp,
605 .free_cp = dasd_fba_free_cp,
606 .dump_sense = dasd_fba_dump_sense,
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100607 .dump_sense_dbf = dasd_fba_dump_sense_dbf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .fill_info = dasd_fba_fill_info,
609};
610
611static int __init
612dasd_fba_init(void)
613{
Sebastian Ott736e6ea2009-06-12 10:26:38 +0200614 int ret;
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 ASCEBC(dasd_fba_discipline.ebcname, 4);
Sebastian Ott736e6ea2009-06-12 10:26:38 +0200617 ret = ccw_driver_register(&dasd_fba_driver);
618 if (!ret)
619 wait_for_device_probe();
620
621 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
624static void __exit
625dasd_fba_cleanup(void)
626{
627 ccw_driver_unregister(&dasd_fba_driver);
628}
629
630module_init(dasd_fba_init);
631module_exit(dasd_fba_cleanup);