blob: 462cab5d4302756659c8faf0e54bb6f10a83d38c [file] [log] [blame]
Horst Hummel138c0142006-06-29 14:58:12 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Bugreports.to..: <Linux390@de.ibm.com>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Stefan Haberlandca99dab2009-09-11 10:28:30 +02007#define KMSG_COMPONENT "dasd-fba"
Stefan Haberlandfc19f382009-03-26 15:23:49 +01008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/stddef.h>
10#include <linux/kernel.h>
11#include <asm/debug.h>
12
13#include <linux/slab.h>
14#include <linux/hdreg.h> /* HDIO_GETGEO */
15#include <linux/bio.h>
16#include <linux/module.h>
17#include <linux/init.h>
18
19#include <asm/idals.h>
20#include <asm/ebcdic.h>
21#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/ccwdev.h>
23
24#include "dasd_int.h"
25#include "dasd_fba.h"
26
27#ifdef PRINTK_HEADER
28#undef PRINTK_HEADER
29#endif /* PRINTK_HEADER */
30#define PRINTK_HEADER "dasd(fba):"
31
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +000032#define FBA_DEFAULT_RETRIES 32
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define DASD_FBA_CCW_WRITE 0x41
35#define DASD_FBA_CCW_READ 0x42
36#define DASD_FBA_CCW_LOCATE 0x43
37#define DASD_FBA_CCW_DEFINE_EXTENT 0x63
38
39MODULE_LICENSE("GPL");
40
41static struct dasd_discipline dasd_fba_discipline;
42
43struct dasd_fba_private {
44 struct dasd_fba_characteristics rdc_data;
45};
46
47static struct ccw_device_id dasd_fba_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020048 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
49 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 { /* end of list */ },
51};
52
53MODULE_DEVICE_TABLE(ccw, dasd_fba_ids);
54
55static struct ccw_driver dasd_fba_driver; /* see below */
56static int
57dasd_fba_probe(struct ccw_device *cdev)
58{
Horst Hummel40545572006-06-29 15:08:18 +020059 return dasd_generic_probe(cdev, &dasd_fba_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
62static int
63dasd_fba_set_online(struct ccw_device *cdev)
64{
Horst Hummel40545572006-06-29 15:08:18 +020065 return dasd_generic_set_online(cdev, &dasd_fba_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68static struct ccw_driver dasd_fba_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +010069 .driver = {
70 .name = "dasd-fba",
71 .owner = THIS_MODULE,
72 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .ids = dasd_fba_ids,
74 .probe = dasd_fba_probe,
75 .remove = dasd_generic_remove,
76 .set_offline = dasd_generic_set_offline,
77 .set_online = dasd_fba_set_online,
78 .notify = dasd_generic_notify,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +010079 .path_event = dasd_generic_path_event,
Stefan Haberlandd41dd122009-06-16 10:30:25 +020080 .freeze = dasd_generic_pm_freeze,
81 .thaw = dasd_generic_restore_device,
82 .restore = dasd_generic_restore_device,
Heiko Carstens420f42e2013-01-02 15:18:18 +010083 .int_class = IRQIO_DAS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
Heiko Carstens4d284ca2007-02-05 21:18:53 +010086static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070087define_extent(struct ccw1 * ccw, struct DE_fba_data *data, int rw,
88 int blksize, int beg, int nr)
89{
90 ccw->cmd_code = DASD_FBA_CCW_DEFINE_EXTENT;
91 ccw->flags = 0;
92 ccw->count = 16;
93 ccw->cda = (__u32) __pa(data);
94 memset(data, 0, sizeof (struct DE_fba_data));
95 if (rw == WRITE)
96 (data->mask).perm = 0x0;
97 else if (rw == READ)
98 (data->mask).perm = 0x1;
99 else
100 data->mask.perm = 0x2;
101 data->blk_size = blksize;
102 data->ext_loc = beg;
103 data->ext_end = nr - 1;
104}
105
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100106static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107locate_record(struct ccw1 * ccw, struct LO_fba_data *data, int rw,
108 int block_nr, int block_ct)
109{
110 ccw->cmd_code = DASD_FBA_CCW_LOCATE;
111 ccw->flags = 0;
112 ccw->count = 8;
113 ccw->cda = (__u32) __pa(data);
114 memset(data, 0, sizeof (struct LO_fba_data));
115 if (rw == WRITE)
116 data->operation.cmd = 0x5;
117 else if (rw == READ)
118 data->operation.cmd = 0x6;
119 else
120 data->operation.cmd = 0x8;
121 data->blk_nr = block_nr;
122 data->blk_ct = block_ct;
123}
124
125static int
126dasd_fba_check_characteristics(struct dasd_device *device)
127{
Sebastian Ott543691a42016-03-04 10:34:05 +0100128 struct dasd_fba_private *private = device->private;
Horst Hummel138c0142006-06-29 14:58:12 +0200129 struct ccw_device *cdev = device->cdev;
Sebastian Ott543691a42016-03-04 10:34:05 +0100130 struct dasd_block *block;
131 int readonly, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Sebastian Ott92636b12009-06-12 10:26:37 +0200133 if (!private) {
134 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
135 if (!private) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100136 dev_warn(&device->cdev->dev,
137 "Allocating memory for private DASD "
138 "data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return -ENOMEM;
140 }
Sebastian Ott543691a42016-03-04 10:34:05 +0100141 device->private = private;
Sebastian Ott92636b12009-06-12 10:26:37 +0200142 } else {
143 memset(private, 0, sizeof(*private));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100145 block = dasd_alloc_block();
146 if (IS_ERR(block)) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +0100147 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", "could not allocate "
148 "dasd block structure");
Cornelia Huck73371942008-07-17 17:16:43 +0200149 device->private = NULL;
150 kfree(private);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100151 return PTR_ERR(block);
152 }
153 device->block = block;
154 block->base = device;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +0200157 rc = dasd_generic_read_dev_chars(device, DASD_FBA_MAGIC,
158 &private->rdc_data, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (rc) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +0100160 DBF_EVENT_DEVID(DBF_WARNING, cdev, "Read device "
161 "characteristics returned error %d", rc);
Cornelia Huck73371942008-07-17 17:16:43 +0200162 device->block = NULL;
163 dasd_free_block(block);
164 device->private = NULL;
165 kfree(private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return rc;
167 }
168
Stefan Haberland7c8faa82010-08-09 18:13:00 +0200169 device->default_expires = DASD_EXPIRES;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +0000170 device->default_retries = FBA_DEFAULT_RETRIES;
Stefan Haberlandc9346152016-08-08 15:53:54 +0200171 dasd_path_set_opm(device, 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{
Sebastian Ott543691a42016-03-04 10:34:05 +0100193 struct dasd_fba_private *private = block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 int sb, rc;
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 rc = dasd_check_blocksize(private->rdc_data.blk_size);
197 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100198 DBF_DEV_EVENT(DBF_WARNING, block->base, "unknown blocksize %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 private->rdc_data.blk_size);
200 return rc;
201 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100202 block->blocks = private->rdc_data.blk_bdsa;
203 block->bp_block = private->rdc_data.blk_size;
204 block->s2b_shift = 0; /* bits to shift 512 to get a block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 for (sb = 512; sb < private->rdc_data.blk_size; sb = sb << 1)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100206 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return 0;
208}
209
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100210static int dasd_fba_fill_geometry(struct dasd_block *block,
211 struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100213 if (dasd_check_blocksize(block->bp_block) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100215 geo->cylinders = (block->blocks << block->s2b_shift) >> 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 geo->heads = 16;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100217 geo->sectors = 128 >> block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return 0;
219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static dasd_erp_fn_t
222dasd_fba_erp_action(struct dasd_ccw_req * cqr)
223{
224 return dasd_default_erp_action;
225}
226
227static dasd_erp_fn_t
228dasd_fba_erp_postaction(struct dasd_ccw_req * cqr)
229{
230 if (cqr->function == dasd_default_erp_action)
231 return dasd_default_erp_postaction;
232
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100233 DBF_DEV_EVENT(DBF_WARNING, cqr->startdev, "unknown ERP action %p",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 cqr->function);
235 return NULL;
236}
237
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100238static void dasd_fba_check_for_device_change(struct dasd_device *device,
239 struct dasd_ccw_req *cqr,
240 struct irb *irb)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100241{
242 char mask;
243
244 /* first of all check for state change pending interrupt */
245 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100246 if ((irb->scsw.cmd.dstat & mask) == mask)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100247 dasd_generic_handle_state_change(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100248};
249
250static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
251 struct dasd_block *block,
252 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Sebastian Ott543691a42016-03-04 10:34:05 +0100254 struct dasd_fba_private *private = block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 unsigned long *idaws;
256 struct LO_fba_data *LO_data;
257 struct dasd_ccw_req *cqr;
258 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200259 struct req_iterator iter;
Kent Overstreet79886132013-11-23 17:19:00 -0800260 struct bio_vec bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 char *dst;
262 int count, cidaw, cplength, datasize;
263 sector_t recid, first_rec, last_rec;
264 unsigned int blksize, off;
265 unsigned char cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 if (rq_data_dir(req) == READ) {
268 cmd = DASD_FBA_CCW_READ;
269 } else if (rq_data_dir(req) == WRITE) {
270 cmd = DASD_FBA_CCW_WRITE;
271 } else
272 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100273 blksize = block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 /* Calculate record id of first and last block. */
Tejun Heo83096eb2009-05-07 22:24:39 +0900275 first_rec = blk_rq_pos(req) >> block->s2b_shift;
276 last_rec =
277 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* Check struct bio and count the number of blocks for the request. */
279 count = 0;
280 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +0200281 rq_for_each_segment(bv, req, iter) {
Kent Overstreet79886132013-11-23 17:19:00 -0800282 if (bv.bv_len & (blksize - 1))
Jens Axboe6c92e692007-08-16 13:43:12 +0200283 /* Fba can only do full blocks. */
284 return ERR_PTR(-EINVAL);
Kent Overstreet79886132013-11-23 17:19:00 -0800285 count += bv.bv_len >> (block->s2b_shift + 9);
Kent Overstreet79886132013-11-23 17:19:00 -0800286 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
287 cidaw += bv.bv_len / blksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289 /* Paranoia. */
290 if (count != last_rec - first_rec + 1)
291 return ERR_PTR(-EINVAL);
292 /* 1x define extent + 1x locate record + number of blocks */
293 cplength = 2 + count;
294 /* 1x define extent + 1x locate record */
295 datasize = sizeof(struct DE_fba_data) + sizeof(struct LO_fba_data) +
296 cidaw * sizeof(unsigned long);
297 /*
298 * Find out number of additional locate record ccws if the device
299 * can't do data chaining.
300 */
301 if (private->rdc_data.mode.bits.data_chain == 0) {
302 cplength += count - 1;
303 datasize += (count - 1)*sizeof(struct LO_fba_data);
304 }
305 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +0200306 cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (IS_ERR(cqr))
308 return cqr;
309 ccw = cqr->cpaddr;
310 /* First ccw is define extent. */
311 define_extent(ccw++, cqr->data, rq_data_dir(req),
Tejun Heo83096eb2009-05-07 22:24:39 +0900312 block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 /* Build locate_record + read/write ccws. */
314 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
315 LO_data = (struct LO_fba_data *) (idaws + cidaw);
316 /* Locate record for all blocks for smart devices. */
317 if (private->rdc_data.mode.bits.data_chain != 0) {
318 ccw[-1].flags |= CCW_FLAG_CC;
319 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
320 }
321 recid = first_rec;
NeilBrown5705f702007-09-25 12:35:59 +0200322 rq_for_each_segment(bv, req, iter) {
Kent Overstreet79886132013-11-23 17:19:00 -0800323 dst = page_address(bv.bv_page) + bv.bv_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 if (dasd_page_cache) {
325 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -0800326 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 if (copy && rq_data_dir(req) == WRITE)
Kent Overstreet79886132013-11-23 17:19:00 -0800328 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (copy)
Kent Overstreet79886132013-11-23 17:19:00 -0800330 dst = copy + bv.bv_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
Kent Overstreet79886132013-11-23 17:19:00 -0800332 for (off = 0; off < bv.bv_len; off += blksize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /* Locate record for stupid devices. */
334 if (private->rdc_data.mode.bits.data_chain == 0) {
335 ccw[-1].flags |= CCW_FLAG_CC;
336 locate_record(ccw, LO_data++,
337 rq_data_dir(req),
338 recid - first_rec, 1);
339 ccw->flags = CCW_FLAG_CC;
340 ccw++;
341 } else {
342 if (recid > first_rec)
343 ccw[-1].flags |= CCW_FLAG_DC;
344 else
345 ccw[-1].flags |= CCW_FLAG_CC;
346 }
347 ccw->cmd_code = cmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100348 ccw->count = block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (idal_is_needed(dst, blksize)) {
350 ccw->cda = (__u32)(addr_t) idaws;
351 ccw->flags = CCW_FLAG_IDA;
352 idaws = idal_create_words(idaws, dst, blksize);
353 } else {
354 ccw->cda = (__u32)(addr_t) dst;
355 ccw->flags = 0;
356 }
357 ccw++;
358 dst += blksize;
359 recid++;
360 }
361 }
Holger Smolinski13de2272009-01-09 12:14:51 +0100362 if (blk_noretry_request(req) ||
363 block->base->features & DASD_FEATURE_FAILFAST)
Horst Hummel1c01b8a2006-01-06 00:19:15 -0800364 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100365 cqr->startdev = memdev;
366 cqr->memdev = memdev;
367 cqr->block = block;
Stefan Haberland7c8faa82010-08-09 18:13:00 +0200368 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +0000369 cqr->retries = memdev->default_retries;
Heiko Carstens1aae0562013-01-30 09:49:40 +0100370 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 cqr->status = DASD_CQR_FILLED;
372 return cqr;
373}
374
375static int
376dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
377{
Sebastian Ott543691a42016-03-04 10:34:05 +0100378 struct dasd_fba_private *private = cqr->block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200380 struct req_iterator iter;
Kent Overstreet79886132013-11-23 17:19:00 -0800381 struct bio_vec bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 char *dst, *cda;
383 unsigned int blksize, off;
NeilBrown5705f702007-09-25 12:35:59 +0200384 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 if (!dasd_page_cache)
387 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100388 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 ccw = cqr->cpaddr;
390 /* Skip over define extent & locate record. */
391 ccw++;
392 if (private->rdc_data.mode.bits.data_chain != 0)
393 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +0200394 rq_for_each_segment(bv, req, iter) {
Kent Overstreet79886132013-11-23 17:19:00 -0800395 dst = page_address(bv.bv_page) + bv.bv_offset;
396 for (off = 0; off < bv.bv_len; off += blksize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 /* Skip locate record. */
398 if (private->rdc_data.mode.bits.data_chain == 0)
399 ccw++;
400 if (dst) {
401 if (ccw->flags & CCW_FLAG_IDA)
402 cda = *((char **)((addr_t) ccw->cda));
403 else
404 cda = (char *)((addr_t) ccw->cda);
405 if (dst != cda) {
406 if (rq_data_dir(req) == READ)
Kent Overstreet79886132013-11-23 17:19:00 -0800407 memcpy(dst, cda, bv.bv_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 kmem_cache_free(dasd_page_cache,
409 (void *)((addr_t)cda & PAGE_MASK));
410 }
411 dst = NULL;
412 }
413 ccw++;
414 }
415 }
416out:
417 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100418 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return status;
420}
421
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100422static void dasd_fba_handle_terminated_request(struct dasd_ccw_req *cqr)
423{
Hannes Reineckea2ace462013-01-30 09:26:14 +0000424 if (cqr->retries < 0)
425 cqr->status = DASD_CQR_FAILED;
426 else
427 cqr->status = DASD_CQR_FILLED;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100428};
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430static int
431dasd_fba_fill_info(struct dasd_device * device,
432 struct dasd_information2_t * info)
433{
Sebastian Ott543691a42016-03-04 10:34:05 +0100434 struct dasd_fba_private *private = device->private;
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 info->label_block = 1;
437 info->FBA_layout = 1;
438 info->format = DASD_FORMAT_LDL;
Sebastian Ott543691a42016-03-04 10:34:05 +0100439 info->characteristics_size = sizeof(private->rdc_data);
440 memcpy(info->characteristics, &private->rdc_data,
441 sizeof(private->rdc_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 info->confdata_size = 0;
443 return 0;
444}
445
446static void
Stefan Haberlandaeec92c2009-07-07 16:37:06 +0200447dasd_fba_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
448 char *reason)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100449{
Stefan Haberlandaeec92c2009-07-07 16:37:06 +0200450 u64 *sense;
451
452 sense = (u64 *) dasd_get_sense(irb);
453 if (sense) {
454 DBF_DEV_EVENT(DBF_EMERG, device,
455 "%s: %s %02x%02x%02x %016llx %016llx %016llx "
456 "%016llx", reason,
457 scsw_is_tm(&irb->scsw) ? "t" : "c",
458 scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
459 scsw_dstat(&irb->scsw), sense[0], sense[1],
460 sense[2], sense[3]);
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100461 } else {
462 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
463 "SORRY - NO VALID SENSE AVAILABLE\n");
464 }
465}
466
467
468static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
470 struct irb *irb)
471{
472 char *page;
473 struct ccw1 *act, *end, *last;
474 int len, sl, sct, count;
475
476 page = (char *) get_zeroed_page(GFP_ATOMIC);
477 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100478 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 "No memory to dump sense data");
480 return;
481 }
Sebastian Ott773bab42012-10-23 20:28:37 +0200482 len = sprintf(page, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200484 dev_name(&device->cdev->dev));
Sebastian Ott773bab42012-10-23 20:28:37 +0200485 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200487 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Sebastian Ott773bab42012-10-23 20:28:37 +0200488 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200490 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200491 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (irb->esw.esw0.erw.cons) {
493 for (sl = 0; sl < 4; sl++) {
Sebastian Ott773bab42012-10-23 20:28:37 +0200494 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 " Sense(hex) %2d-%2d:",
496 (8 * sl), ((8 * sl) + 7));
497
498 for (sct = 0; sct < 8; sct++) {
499 len += sprintf(page + len, " %02x",
500 irb->ecw[8 * sl + sct]);
501 }
502 len += sprintf(page + len, "\n");
503 }
504 } else {
Sebastian Ott773bab42012-10-23 20:28:37 +0200505 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 " SORRY - NO VALID SENSE AVAILABLE\n");
507 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100508 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /* dump the Channel Program */
511 /* print first CCWs (maximum 8) */
512 act = req->cpaddr;
513 for (last = act; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
514 end = min(act + 8, last);
Sebastian Ott773bab42012-10-23 20:28:37 +0200515 len = sprintf(page, PRINTK_HEADER " Related CP in req: %p\n", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 while (act <= end) {
Sebastian Ott773bab42012-10-23 20:28:37 +0200517 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 " CCW %p: %08X %08X DAT:",
519 act, ((int *) act)[0], ((int *) act)[1]);
520 for (count = 0; count < 32 && count < act->count;
521 count += sizeof(int))
522 len += sprintf(page + len, " %08X",
523 ((int *) (addr_t) act->cda)
524 [(count>>2)]);
525 len += sprintf(page + len, "\n");
526 act++;
527 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100528 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530
531 /* print failing CCW area */
532 len = 0;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200533 if (act < ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
534 act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
Sebastian Ott773bab42012-10-23 20:28:37 +0200535 len += sprintf(page + len, PRINTK_HEADER "......\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200537 end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 while (act <= end) {
Sebastian Ott773bab42012-10-23 20:28:37 +0200539 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 " CCW %p: %08X %08X DAT:",
541 act, ((int *) act)[0], ((int *) act)[1]);
542 for (count = 0; count < 32 && count < act->count;
543 count += sizeof(int))
544 len += sprintf(page + len, " %08X",
545 ((int *) (addr_t) act->cda)
546 [(count>>2)]);
547 len += sprintf(page + len, "\n");
548 act++;
549 }
550
551 /* print last CCWs */
552 if (act < last - 2) {
553 act = last - 2;
Sebastian Ott773bab42012-10-23 20:28:37 +0200554 len += sprintf(page + len, PRINTK_HEADER "......\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556 while (act <= last) {
Sebastian Ott773bab42012-10-23 20:28:37 +0200557 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 " CCW %p: %08X %08X DAT:",
559 act, ((int *) act)[0], ((int *) act)[1]);
560 for (count = 0; count < 32 && count < act->count;
561 count += sizeof(int))
562 len += sprintf(page + len, " %08X",
563 ((int *) (addr_t) act->cda)
564 [(count>>2)]);
565 len += sprintf(page + len, "\n");
566 act++;
567 }
568 if (len > 0)
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100569 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 free_page((unsigned long) page);
571}
572
573/*
574 * max_blocks is dependent on the amount of storage that is available
575 * in the static io buffer for each device. Currently each device has
576 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
577 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
578 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
Horst Hummel138c0142006-06-29 14:58:12 +0200579 * addition we have one define extent ccw + 16 bytes of data and a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 * locate record ccw for each block (stupid devices!) + 16 bytes of data.
581 * That makes:
582 * (8192 - 24 - 136 - 8 - 16) / 40 = 200.2 blocks at maximum.
583 * We want to fit two into the available memory so that we can immediately
584 * start the next request if one finishes off. That makes 100.1 blocks
585 * for one request. Give a little safety and the result is 96.
586 */
587static struct dasd_discipline dasd_fba_discipline = {
588 .owner = THIS_MODULE,
589 .name = "FBA ",
590 .ebcname = "FBA ",
591 .max_blocks = 96,
592 .check_device = dasd_fba_check_characteristics,
593 .do_analysis = dasd_fba_do_analysis,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100594 .verify_path = dasd_generic_verify_path,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .fill_geometry = dasd_fba_fill_geometry,
596 .start_IO = dasd_start_IO,
597 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100598 .handle_terminated_request = dasd_fba_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .erp_action = dasd_fba_erp_action,
600 .erp_postaction = dasd_fba_erp_postaction,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100601 .check_for_device_change = dasd_fba_check_for_device_change,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .build_cp = dasd_fba_build_cp,
603 .free_cp = dasd_fba_free_cp,
604 .dump_sense = dasd_fba_dump_sense,
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100605 .dump_sense_dbf = dasd_fba_dump_sense_dbf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .fill_info = dasd_fba_fill_info,
607};
608
609static int __init
610dasd_fba_init(void)
611{
Sebastian Ott736e6ea2009-06-12 10:26:38 +0200612 int ret;
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 ASCEBC(dasd_fba_discipline.ebcname, 4);
Sebastian Ott736e6ea2009-06-12 10:26:38 +0200615 ret = ccw_driver_register(&dasd_fba_driver);
616 if (!ret)
617 wait_for_device_probe();
618
619 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
622static void __exit
623dasd_fba_cleanup(void)
624{
625 ccw_driver_unregister(&dasd_fba_driver);
626}
627
628module_init(dasd_fba_init);
629module_exit(dasd_fba_cleanup);