]>
Commit | Line | Data |
---|---|---|
138c014d | 1 | /* |
1da177e4 LT |
2 | * File...........: linux/drivers/s390/block/dasd_diag.c |
3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> | |
4 | * Based on.......: linux/drivers/s390/block/mdisk.c | |
5 | * ...............: by Hartmunt Penner <hpenner@de.ibm.com> | |
6 | * Bugreports.to..: <Linux390@de.ibm.com> | |
7 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 | |
8 | * | |
1da177e4 LT |
9 | */ |
10 | ||
ea058544 | 11 | #define KMSG_COMPONENT "dasd" |
fc19f381 | 12 | |
052ff461 | 13 | #include <linux/kernel_stat.h> |
1da177e4 LT |
14 | #include <linux/stddef.h> |
15 | #include <linux/kernel.h> | |
16 | #include <linux/slab.h> | |
fd49f41a | 17 | #include <linux/hdreg.h> |
1da177e4 LT |
18 | #include <linux/bio.h> |
19 | #include <linux/module.h> | |
20 | #include <linux/init.h> | |
fd49f41a | 21 | #include <linux/jiffies.h> |
1da177e4 LT |
22 | |
23 | #include <asm/dasd.h> | |
24 | #include <asm/debug.h> | |
25 | #include <asm/ebcdic.h> | |
26 | #include <asm/io.h> | |
27 | #include <asm/s390_ext.h> | |
56dc6a88 | 28 | #include <asm/vtoc.h> |
0a87c5cf | 29 | #include <asm/diag.h> |
1da177e4 LT |
30 | |
31 | #include "dasd_int.h" | |
32 | #include "dasd_diag.h" | |
33 | ||
1da177e4 LT |
34 | #define PRINTK_HEADER "dasd(diag):" |
35 | ||
36 | MODULE_LICENSE("GPL"); | |
37 | ||
fd49f41a HH |
38 | /* The maximum number of blocks per request (max_blocks) is dependent on the |
39 | * amount of storage that is available in the static I/O buffer for each | |
40 | * device. Currently each device gets 2 pages. We want to fit two requests | |
41 | * into the available memory so that we can immediately start the next if one | |
42 | * finishes. */ | |
43 | #define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \ | |
44 | sizeof(struct dasd_diag_req)) / \ | |
45 | sizeof(struct dasd_diag_bio)) / 2) | |
46 | #define DIAG_MAX_RETRIES 32 | |
7c8faa86 | 47 | #define DIAG_TIMEOUT 50 |
fd49f41a | 48 | |
2b67fc46 | 49 | static struct dasd_discipline dasd_diag_discipline; |
1da177e4 LT |
50 | |
51 | struct dasd_diag_private { | |
52 | struct dasd_diag_characteristics rdc_data; | |
53 | struct dasd_diag_rw_io iob; | |
54 | struct dasd_diag_init_io iib; | |
fd49f41a | 55 | blocknum_t pt_block; |
9a92fe48 | 56 | struct ccw_dev_id dev_id; |
1da177e4 LT |
57 | }; |
58 | ||
59 | struct dasd_diag_req { | |
fd49f41a | 60 | unsigned int block_count; |
1da177e4 LT |
61 | struct dasd_diag_bio bio[0]; |
62 | }; | |
63 | ||
fd49f41a HH |
64 | static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */ |
65 | ||
66 | /* Perform DIAG250 call with block I/O parameter list iob (input and output) | |
67 | * and function code cmd. | |
68 | * In case of an exception return 3. Otherwise return result of bitwise OR of | |
69 | * resulting condition code and DIAG return code. */ | |
94c12cc7 | 70 | static inline int dia250(void *iob, int cmd) |
1da177e4 | 71 | { |
04439694 | 72 | register unsigned long reg2 asm ("2") = (unsigned long) iob; |
86b368a5 PO |
73 | typedef union { |
74 | struct dasd_diag_init_io init_io; | |
75 | struct dasd_diag_rw_io rw_io; | |
fd49f41a | 76 | } addr_type; |
1da177e4 LT |
77 | int rc; |
78 | ||
94c12cc7 MS |
79 | rc = 3; |
80 | asm volatile( | |
04439694 | 81 | " diag 2,%2,0x250\n" |
fd49f41a HH |
82 | "0: ipm %0\n" |
83 | " srl %0,28\n" | |
04439694 | 84 | " or %0,3\n" |
fd49f41a | 85 | "1:\n" |
94c12cc7 MS |
86 | EX_TABLE(0b,1b) |
87 | : "+d" (rc), "=m" (*(addr_type *) iob) | |
04439694 PO |
88 | : "d" (cmd), "d" (reg2), "m" (*(addr_type *) iob) |
89 | : "3", "cc"); | |
1da177e4 LT |
90 | return rc; |
91 | } | |
92 | ||
fd49f41a HH |
93 | /* Initialize block I/O to DIAG device using the specified blocksize and |
94 | * block offset. On success, return zero and set end_block to contain the | |
95 | * number of blocks on the device minus the specified offset. Return non-zero | |
96 | * otherwise. */ | |
4d284cac | 97 | static inline int |
fd49f41a HH |
98 | mdsk_init_io(struct dasd_device *device, unsigned int blocksize, |
99 | blocknum_t offset, blocknum_t *end_block) | |
1da177e4 LT |
100 | { |
101 | struct dasd_diag_private *private; | |
102 | struct dasd_diag_init_io *iib; | |
103 | int rc; | |
104 | ||
105 | private = (struct dasd_diag_private *) device->private; | |
106 | iib = &private->iib; | |
107 | memset(iib, 0, sizeof (struct dasd_diag_init_io)); | |
108 | ||
9a92fe48 | 109 | iib->dev_nr = private->dev_id.devno; |
1da177e4 LT |
110 | iib->block_size = blocksize; |
111 | iib->offset = offset; | |
fd49f41a | 112 | iib->flaga = DASD_DIAG_FLAGA_DEFAULT; |
1da177e4 LT |
113 | |
114 | rc = dia250(iib, INIT_BIO); | |
115 | ||
fd49f41a HH |
116 | if ((rc & 3) == 0 && end_block) |
117 | *end_block = iib->end_block; | |
118 | ||
119 | return rc; | |
1da177e4 LT |
120 | } |
121 | ||
fd49f41a HH |
122 | /* Remove block I/O environment for device. Return zero on success, non-zero |
123 | * otherwise. */ | |
4d284cac | 124 | static inline int |
1da177e4 LT |
125 | mdsk_term_io(struct dasd_device * device) |
126 | { | |
127 | struct dasd_diag_private *private; | |
128 | struct dasd_diag_init_io *iib; | |
129 | int rc; | |
130 | ||
131 | private = (struct dasd_diag_private *) device->private; | |
132 | iib = &private->iib; | |
133 | memset(iib, 0, sizeof (struct dasd_diag_init_io)); | |
9a92fe48 | 134 | iib->dev_nr = private->dev_id.devno; |
1da177e4 | 135 | rc = dia250(iib, TERM_BIO); |
fd49f41a HH |
136 | return rc; |
137 | } | |
138 | ||
139 | /* Error recovery for failed DIAG requests - try to reestablish the DIAG | |
140 | * environment. */ | |
141 | static void | |
142 | dasd_diag_erp(struct dasd_device *device) | |
143 | { | |
144 | int rc; | |
145 | ||
146 | mdsk_term_io(device); | |
8e09f215 | 147 | rc = mdsk_init_io(device, device->block->bp_block, 0, NULL); |
22825ab7 | 148 | if (rc == 4) { |
33b62a30 | 149 | if (!(test_and_set_bit(DASD_FLAG_DEVICE_RO, &device->flags))) |
ea058544 SH |
150 | pr_warning("%s: The access mode of a DIAG device " |
151 | "changed to read-only\n", | |
152 | dev_name(&device->cdev->dev)); | |
22825ab7 SW |
153 | rc = 0; |
154 | } | |
fd49f41a | 155 | if (rc) |
ea058544 SH |
156 | pr_warning("%s: DIAG ERP failed with " |
157 | "rc=%d\n", dev_name(&device->cdev->dev), rc); | |
1da177e4 LT |
158 | } |
159 | ||
fd49f41a HH |
160 | /* Start a given request at the device. Return zero on success, non-zero |
161 | * otherwise. */ | |
1da177e4 LT |
162 | static int |
163 | dasd_start_diag(struct dasd_ccw_req * cqr) | |
164 | { | |
165 | struct dasd_device *device; | |
166 | struct dasd_diag_private *private; | |
167 | struct dasd_diag_req *dreq; | |
168 | int rc; | |
169 | ||
8e09f215 | 170 | device = cqr->startdev; |
fd49f41a | 171 | if (cqr->retries < 0) { |
fc19f381 | 172 | DBF_DEV_EVENT(DBF_ERR, device, "DIAG start_IO: request %p " |
fd49f41a | 173 | "- no retry left)", cqr); |
8e09f215 | 174 | cqr->status = DASD_CQR_ERROR; |
fd49f41a HH |
175 | return -EIO; |
176 | } | |
1da177e4 LT |
177 | private = (struct dasd_diag_private *) device->private; |
178 | dreq = (struct dasd_diag_req *) cqr->data; | |
179 | ||
9a92fe48 | 180 | private->iob.dev_nr = private->dev_id.devno; |
1da177e4 | 181 | private->iob.key = 0; |
fd49f41a | 182 | private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; |
1da177e4 | 183 | private->iob.block_count = dreq->block_count; |
fd49f41a | 184 | private->iob.interrupt_params = (addr_t) cqr; |
86b368a5 | 185 | private->iob.bio_list = dreq->bio; |
fd49f41a | 186 | private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
1da177e4 LT |
187 | |
188 | cqr->startclk = get_clock(); | |
fd49f41a HH |
189 | cqr->starttime = jiffies; |
190 | cqr->retries--; | |
1da177e4 LT |
191 | |
192 | rc = dia250(&private->iob, RW_BIO); | |
fd49f41a HH |
193 | switch (rc) { |
194 | case 0: /* Synchronous I/O finished successfully */ | |
195 | cqr->stopclk = get_clock(); | |
8e09f215 | 196 | cqr->status = DASD_CQR_SUCCESS; |
fd49f41a HH |
197 | /* Indicate to calling function that only a dasd_schedule_bh() |
198 | and no timer is needed */ | |
199 | rc = -EACCES; | |
200 | break; | |
201 | case 8: /* Asynchronous I/O was started */ | |
1da177e4 LT |
202 | cqr->status = DASD_CQR_IN_IO; |
203 | rc = 0; | |
fd49f41a HH |
204 | break; |
205 | default: /* Error condition */ | |
206 | cqr->status = DASD_CQR_QUEUED; | |
fc19f381 | 207 | DBF_DEV_EVENT(DBF_WARNING, device, "dia250 returned rc=%d", rc); |
fd49f41a HH |
208 | dasd_diag_erp(device); |
209 | rc = -EIO; | |
210 | break; | |
1da177e4 | 211 | } |
6cc7f168 | 212 | cqr->intrc = rc; |
1da177e4 LT |
213 | return rc; |
214 | } | |
215 | ||
fd49f41a HH |
216 | /* Terminate given request at the device. */ |
217 | static int | |
218 | dasd_diag_term_IO(struct dasd_ccw_req * cqr) | |
219 | { | |
220 | struct dasd_device *device; | |
221 | ||
8e09f215 | 222 | device = cqr->startdev; |
fd49f41a | 223 | mdsk_term_io(device); |
8e09f215 SW |
224 | mdsk_init_io(device, device->block->bp_block, 0, NULL); |
225 | cqr->status = DASD_CQR_CLEAR_PENDING; | |
fd49f41a | 226 | cqr->stopclk = get_clock(); |
8e09f215 | 227 | dasd_schedule_device_bh(device); |
fd49f41a HH |
228 | return 0; |
229 | } | |
230 | ||
231 | /* Handle external interruption. */ | |
f6649a7e MS |
232 | static void dasd_ext_handler(unsigned int ext_int_code, |
233 | unsigned int param32, unsigned long param64) | |
1da177e4 LT |
234 | { |
235 | struct dasd_ccw_req *cqr, *next; | |
236 | struct dasd_device *device; | |
237 | unsigned long long expires; | |
238 | unsigned long flags; | |
fd49f41a HH |
239 | addr_t ip; |
240 | int rc; | |
1da177e4 | 241 | |
f6649a7e | 242 | switch (ext_int_code >> 24) { |
fd49f41a | 243 | case DASD_DIAG_CODE_31BIT: |
f6649a7e | 244 | ip = (addr_t) param32; |
fd49f41a HH |
245 | break; |
246 | case DASD_DIAG_CODE_64BIT: | |
f6649a7e | 247 | ip = (addr_t) param64; |
fd49f41a HH |
248 | break; |
249 | default: | |
250 | return; | |
251 | } | |
a9851832 | 252 | kstat_cpu(smp_processor_id()).irqs[EXTINT_DSD]++; |
1da177e4 | 253 | if (!ip) { /* no intparm: unsolicited interrupt */ |
fc19f381 SH |
254 | DBF_EVENT(DBF_NOTICE, "%s", "caught unsolicited " |
255 | "interrupt"); | |
1da177e4 LT |
256 | return; |
257 | } | |
fd49f41a | 258 | cqr = (struct dasd_ccw_req *) ip; |
8e09f215 | 259 | device = (struct dasd_device *) cqr->startdev; |
1da177e4 | 260 | if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
fc19f381 | 261 | DBF_DEV_EVENT(DBF_WARNING, device, |
1da177e4 LT |
262 | " magic number of dasd_ccw_req 0x%08X doesn't" |
263 | " match discipline 0x%08X", | |
264 | cqr->magic, *(int *) (&device->discipline->name)); | |
265 | return; | |
266 | } | |
267 | ||
268 | /* get irq lock to modify request queue */ | |
269 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
270 | ||
fd49f41a | 271 | /* Check for a pending clear operation */ |
8e09f215 SW |
272 | if (cqr->status == DASD_CQR_CLEAR_PENDING) { |
273 | cqr->status = DASD_CQR_CLEARED; | |
274 | dasd_device_clear_timer(device); | |
275 | dasd_schedule_device_bh(device); | |
fd49f41a HH |
276 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
277 | return; | |
278 | } | |
279 | ||
1da177e4 LT |
280 | cqr->stopclk = get_clock(); |
281 | ||
282 | expires = 0; | |
f6649a7e | 283 | if ((ext_int_code & 0xff0000) == 0) { |
8e09f215 | 284 | cqr->status = DASD_CQR_SUCCESS; |
1da177e4 LT |
285 | /* Start first request on queue if possible -> fast_io. */ |
286 | if (!list_empty(&device->ccw_queue)) { | |
287 | next = list_entry(device->ccw_queue.next, | |
8e09f215 | 288 | struct dasd_ccw_req, devlist); |
1da177e4 | 289 | if (next->status == DASD_CQR_QUEUED) { |
fd49f41a HH |
290 | rc = dasd_start_diag(next); |
291 | if (rc == 0) | |
1da177e4 | 292 | expires = next->expires; |
1da177e4 LT |
293 | } |
294 | } | |
fd49f41a HH |
295 | } else { |
296 | cqr->status = DASD_CQR_QUEUED; | |
fc19f381 | 297 | DBF_DEV_EVENT(DBF_DEBUG, device, "interrupt status for " |
f6649a7e MS |
298 | "request %p was %d (%d retries left)", cqr, |
299 | (ext_int_code >> 16) & 0xff, cqr->retries); | |
fd49f41a HH |
300 | dasd_diag_erp(device); |
301 | } | |
1da177e4 LT |
302 | |
303 | if (expires != 0) | |
8e09f215 | 304 | dasd_device_set_timer(device, expires); |
1da177e4 | 305 | else |
8e09f215 SW |
306 | dasd_device_clear_timer(device); |
307 | dasd_schedule_device_bh(device); | |
1da177e4 LT |
308 | |
309 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
310 | } | |
311 | ||
fd49f41a HH |
312 | /* Check whether device can be controlled by DIAG discipline. Return zero on |
313 | * success, non-zero otherwise. */ | |
1da177e4 LT |
314 | static int |
315 | dasd_diag_check_device(struct dasd_device *device) | |
316 | { | |
8e09f215 | 317 | struct dasd_block *block; |
1da177e4 LT |
318 | struct dasd_diag_private *private; |
319 | struct dasd_diag_characteristics *rdc_data; | |
320 | struct dasd_diag_bio bio; | |
56dc6a88 | 321 | struct vtoc_cms_label *label; |
fd49f41a HH |
322 | blocknum_t end_block; |
323 | unsigned int sb, bsize; | |
1da177e4 LT |
324 | int rc; |
325 | ||
326 | private = (struct dasd_diag_private *) device->private; | |
327 | if (private == NULL) { | |
138c014d | 328 | private = kzalloc(sizeof(struct dasd_diag_private),GFP_KERNEL); |
1da177e4 | 329 | if (private == NULL) { |
fc19f381 SH |
330 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
331 | "Allocating memory for private DASD data " | |
332 | "failed\n"); | |
1da177e4 LT |
333 | return -ENOMEM; |
334 | } | |
9a92fe48 | 335 | ccw_device_get_id(device->cdev, &private->dev_id); |
1da177e4 LT |
336 | device->private = (void *) private; |
337 | } | |
8e09f215 SW |
338 | block = dasd_alloc_block(); |
339 | if (IS_ERR(block)) { | |
fc19f381 | 340 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
8e09f215 | 341 | "could not allocate dasd block structure"); |
7337194f CH |
342 | device->private = NULL; |
343 | kfree(private); | |
8e09f215 SW |
344 | return PTR_ERR(block); |
345 | } | |
346 | device->block = block; | |
347 | block->base = device; | |
348 | ||
1da177e4 LT |
349 | /* Read Device Characteristics */ |
350 | rdc_data = (void *) &(private->rdc_data); | |
9a92fe48 | 351 | rdc_data->dev_nr = private->dev_id.devno; |
1da177e4 LT |
352 | rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); |
353 | ||
354 | rc = diag210((struct diag210 *) rdc_data); | |
fd49f41a | 355 | if (rc) { |
fc19f381 | 356 | DBF_DEV_EVENT(DBF_WARNING, device, "failed to retrieve device " |
fd49f41a | 357 | "information (rc=%d)", rc); |
8586cb60 | 358 | rc = -EOPNOTSUPP; |
7337194f | 359 | goto out; |
fd49f41a | 360 | } |
1da177e4 | 361 | |
7c8faa86 SH |
362 | device->default_expires = DIAG_TIMEOUT; |
363 | ||
1da177e4 LT |
364 | /* Figure out position of label block */ |
365 | switch (private->rdc_data.vdev_class) { | |
366 | case DEV_CLASS_FBA: | |
367 | private->pt_block = 1; | |
368 | break; | |
369 | case DEV_CLASS_ECKD: | |
370 | private->pt_block = 2; | |
371 | break; | |
372 | default: | |
ea058544 SH |
373 | pr_warning("%s: Device type %d is not supported " |
374 | "in DIAG mode\n", dev_name(&device->cdev->dev), | |
375 | private->rdc_data.vdev_class); | |
8586cb60 | 376 | rc = -EOPNOTSUPP; |
7337194f | 377 | goto out; |
1da177e4 LT |
378 | } |
379 | ||
380 | DBF_DEV_EVENT(DBF_INFO, device, | |
381 | "%04X: %04X on real %04X/%02X", | |
382 | rdc_data->dev_nr, | |
383 | rdc_data->vdev_type, | |
384 | rdc_data->rdev_type, rdc_data->rdev_model); | |
385 | ||
386 | /* terminate all outstanding operations */ | |
387 | mdsk_term_io(device); | |
388 | ||
389 | /* figure out blocksize of device */ | |
56dc6a88 | 390 | label = (struct vtoc_cms_label *) get_zeroed_page(GFP_KERNEL); |
1da177e4 | 391 | if (label == NULL) { |
fc19f381 | 392 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 | 393 | "No memory to allocate initialization request"); |
7337194f CH |
394 | rc = -ENOMEM; |
395 | goto out; | |
1da177e4 | 396 | } |
fd49f41a HH |
397 | rc = 0; |
398 | end_block = 0; | |
1da177e4 LT |
399 | /* try all sizes - needed for ECKD devices */ |
400 | for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) { | |
fd49f41a | 401 | mdsk_init_io(device, bsize, 0, &end_block); |
1da177e4 LT |
402 | memset(&bio, 0, sizeof (struct dasd_diag_bio)); |
403 | bio.type = MDSK_READ_REQ; | |
404 | bio.block_number = private->pt_block + 1; | |
86b368a5 | 405 | bio.buffer = label; |
1da177e4 LT |
406 | memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io)); |
407 | private->iob.dev_nr = rdc_data->dev_nr; | |
408 | private->iob.key = 0; | |
409 | private->iob.flags = 0; /* do synchronous io */ | |
410 | private->iob.block_count = 1; | |
411 | private->iob.interrupt_params = 0; | |
86b368a5 | 412 | private->iob.bio_list = &bio; |
fd49f41a HH |
413 | private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
414 | rc = dia250(&private->iob, RW_BIO); | |
1e0291ba | 415 | if (rc == 3) { |
ea058544 SH |
416 | pr_warning("%s: A 64-bit DIAG call failed\n", |
417 | dev_name(&device->cdev->dev)); | |
1e0291ba | 418 | rc = -EOPNOTSUPP; |
7337194f | 419 | goto out_label; |
1e0291ba | 420 | } |
1da177e4 | 421 | mdsk_term_io(device); |
1e0291ba PO |
422 | if (rc == 0) |
423 | break; | |
1da177e4 | 424 | } |
1e0291ba | 425 | if (bsize > PAGE_SIZE) { |
ea058544 SH |
426 | pr_warning("%s: Accessing the DASD failed because of an " |
427 | "incorrect format (rc=%d)\n", | |
428 | dev_name(&device->cdev->dev), rc); | |
fd49f41a | 429 | rc = -EIO; |
7337194f | 430 | goto out_label; |
1e0291ba PO |
431 | } |
432 | /* check for label block */ | |
433 | if (memcmp(label->label_id, DASD_DIAG_CMS1, | |
434 | sizeof(DASD_DIAG_CMS1)) == 0) { | |
435 | /* get formatted blocksize from label block */ | |
436 | bsize = (unsigned int) label->block_size; | |
8e09f215 | 437 | block->blocks = (unsigned long) label->block_count; |
1e0291ba | 438 | } else |
8e09f215 SW |
439 | block->blocks = end_block; |
440 | block->bp_block = bsize; | |
441 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ | |
1e0291ba | 442 | for (sb = 512; sb < bsize; sb = sb << 1) |
8e09f215 SW |
443 | block->s2b_shift++; |
444 | rc = mdsk_init_io(device, block->bp_block, 0, NULL); | |
22825ab7 | 445 | if (rc && (rc != 4)) { |
ea058544 SH |
446 | pr_warning("%s: DIAG initialization failed with rc=%d\n", |
447 | dev_name(&device->cdev->dev), rc); | |
1e0291ba | 448 | rc = -EIO; |
fd49f41a | 449 | } else { |
22825ab7 | 450 | if (rc == 4) |
33b62a30 | 451 | set_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
ea058544 SH |
452 | pr_info("%s: New DASD with %ld byte/block, total size %ld " |
453 | "KB%s\n", dev_name(&device->cdev->dev), | |
454 | (unsigned long) block->bp_block, | |
455 | (unsigned long) (block->blocks << | |
456 | block->s2b_shift) >> 1, | |
457 | (rc == 4) ? ", read-only device" : ""); | |
22825ab7 | 458 | rc = 0; |
1da177e4 | 459 | } |
7337194f | 460 | out_label: |
1da177e4 | 461 | free_page((long) label); |
7337194f CH |
462 | out: |
463 | if (rc) { | |
464 | device->block = NULL; | |
465 | dasd_free_block(block); | |
466 | device->private = NULL; | |
467 | kfree(private); | |
468 | } | |
1da177e4 LT |
469 | return rc; |
470 | } | |
471 | ||
fd49f41a HH |
472 | /* Fill in virtual disk geometry for device. Return zero on success, non-zero |
473 | * otherwise. */ | |
1da177e4 | 474 | static int |
8e09f215 | 475 | dasd_diag_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
1da177e4 | 476 | { |
8e09f215 | 477 | if (dasd_check_blocksize(block->bp_block) != 0) |
1da177e4 | 478 | return -EINVAL; |
8e09f215 | 479 | geo->cylinders = (block->blocks << block->s2b_shift) >> 10; |
1da177e4 | 480 | geo->heads = 16; |
8e09f215 | 481 | geo->sectors = 128 >> block->s2b_shift; |
1da177e4 LT |
482 | return 0; |
483 | } | |
484 | ||
1da177e4 LT |
485 | static dasd_erp_fn_t |
486 | dasd_diag_erp_action(struct dasd_ccw_req * cqr) | |
487 | { | |
488 | return dasd_default_erp_action; | |
489 | } | |
490 | ||
491 | static dasd_erp_fn_t | |
492 | dasd_diag_erp_postaction(struct dasd_ccw_req * cqr) | |
493 | { | |
494 | return dasd_default_erp_postaction; | |
495 | } | |
496 | ||
fd49f41a HH |
497 | /* Create DASD request from block device request. Return pointer to new |
498 | * request on success, ERR_PTR otherwise. */ | |
8e09f215 SW |
499 | static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev, |
500 | struct dasd_block *block, | |
501 | struct request *req) | |
1da177e4 LT |
502 | { |
503 | struct dasd_ccw_req *cqr; | |
504 | struct dasd_diag_req *dreq; | |
505 | struct dasd_diag_bio *dbio; | |
5705f702 | 506 | struct req_iterator iter; |
1da177e4 LT |
507 | struct bio_vec *bv; |
508 | char *dst; | |
fd49f41a | 509 | unsigned int count, datasize; |
1da177e4 | 510 | sector_t recid, first_rec, last_rec; |
fd49f41a | 511 | unsigned int blksize, off; |
1da177e4 | 512 | unsigned char rw_cmd; |
1da177e4 LT |
513 | |
514 | if (rq_data_dir(req) == READ) | |
515 | rw_cmd = MDSK_READ_REQ; | |
516 | else if (rq_data_dir(req) == WRITE) | |
517 | rw_cmd = MDSK_WRITE_REQ; | |
518 | else | |
519 | return ERR_PTR(-EINVAL); | |
8e09f215 | 520 | blksize = block->bp_block; |
1da177e4 | 521 | /* Calculate record id of first and last block. */ |
83096ebf TH |
522 | first_rec = blk_rq_pos(req) >> block->s2b_shift; |
523 | last_rec = | |
524 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; | |
1da177e4 LT |
525 | /* Check struct bio and count the number of blocks for the request. */ |
526 | count = 0; | |
5705f702 | 527 | rq_for_each_segment(bv, req, iter) { |
6c92e699 JA |
528 | if (bv->bv_len & (blksize - 1)) |
529 | /* Fba can only do full blocks. */ | |
530 | return ERR_PTR(-EINVAL); | |
8e09f215 | 531 | count += bv->bv_len >> (block->s2b_shift + 9); |
1da177e4 LT |
532 | } |
533 | /* Paranoia. */ | |
534 | if (count != last_rec - first_rec + 1) | |
535 | return ERR_PTR(-EINVAL); | |
536 | /* Build the request */ | |
537 | datasize = sizeof(struct dasd_diag_req) + | |
538 | count*sizeof(struct dasd_diag_bio); | |
68b781fe | 539 | cqr = dasd_smalloc_request(DASD_DIAG_MAGIC, 0, datasize, memdev); |
1da177e4 LT |
540 | if (IS_ERR(cqr)) |
541 | return cqr; | |
138c014d | 542 | |
1da177e4 LT |
543 | dreq = (struct dasd_diag_req *) cqr->data; |
544 | dreq->block_count = count; | |
545 | dbio = dreq->bio; | |
546 | recid = first_rec; | |
5705f702 | 547 | rq_for_each_segment(bv, req, iter) { |
6c92e699 JA |
548 | dst = page_address(bv->bv_page) + bv->bv_offset; |
549 | for (off = 0; off < bv->bv_len; off += blksize) { | |
550 | memset(dbio, 0, sizeof (struct dasd_diag_bio)); | |
551 | dbio->type = rw_cmd; | |
552 | dbio->block_number = recid + 1; | |
553 | dbio->buffer = dst; | |
554 | dbio++; | |
555 | dst += blksize; | |
556 | recid++; | |
557 | } | |
1da177e4 | 558 | } |
fd49f41a | 559 | cqr->retries = DIAG_MAX_RETRIES; |
1da177e4 | 560 | cqr->buildclk = get_clock(); |
13de227b HS |
561 | if (blk_noretry_request(req) || |
562 | block->base->features & DASD_FEATURE_FAILFAST) | |
1c01b8a5 | 563 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
8e09f215 SW |
564 | cqr->startdev = memdev; |
565 | cqr->memdev = memdev; | |
566 | cqr->block = block; | |
7c8faa86 | 567 | cqr->expires = memdev->default_expires * HZ; |
1da177e4 LT |
568 | cqr->status = DASD_CQR_FILLED; |
569 | return cqr; | |
570 | } | |
571 | ||
fd49f41a HH |
572 | /* Release DASD request. Return non-zero if request was successful, zero |
573 | * otherwise. */ | |
1da177e4 LT |
574 | static int |
575 | dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) | |
576 | { | |
577 | int status; | |
578 | ||
579 | status = cqr->status == DASD_CQR_DONE; | |
8e09f215 | 580 | dasd_sfree_request(cqr, cqr->memdev); |
1da177e4 LT |
581 | return status; |
582 | } | |
583 | ||
8e09f215 SW |
584 | static void dasd_diag_handle_terminated_request(struct dasd_ccw_req *cqr) |
585 | { | |
586 | cqr->status = DASD_CQR_FILLED; | |
587 | }; | |
588 | ||
fd49f41a | 589 | /* Fill in IOCTL data for device. */ |
1da177e4 LT |
590 | static int |
591 | dasd_diag_fill_info(struct dasd_device * device, | |
592 | struct dasd_information2_t * info) | |
593 | { | |
594 | struct dasd_diag_private *private; | |
595 | ||
596 | private = (struct dasd_diag_private *) device->private; | |
fd49f41a | 597 | info->label_block = (unsigned int) private->pt_block; |
1da177e4 LT |
598 | info->FBA_layout = 1; |
599 | info->format = DASD_FORMAT_LDL; | |
600 | info->characteristics_size = sizeof (struct dasd_diag_characteristics); | |
601 | memcpy(info->characteristics, | |
602 | &((struct dasd_diag_private *) device->private)->rdc_data, | |
603 | sizeof (struct dasd_diag_characteristics)); | |
604 | info->confdata_size = 0; | |
605 | return 0; | |
606 | } | |
607 | ||
608 | static void | |
609 | dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req, | |
610 | struct irb *stat) | |
611 | { | |
fc19f381 | 612 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 LT |
613 | "dump sense not available for DIAG data"); |
614 | } | |
615 | ||
2b67fc46 | 616 | static struct dasd_discipline dasd_diag_discipline = { |
1da177e4 LT |
617 | .owner = THIS_MODULE, |
618 | .name = "DIAG", | |
619 | .ebcname = "DIAG", | |
fd49f41a | 620 | .max_blocks = DIAG_MAX_BLOCKS, |
1da177e4 | 621 | .check_device = dasd_diag_check_device, |
a4d26c6a | 622 | .verify_path = dasd_generic_verify_path, |
1da177e4 LT |
623 | .fill_geometry = dasd_diag_fill_geometry, |
624 | .start_IO = dasd_start_diag, | |
fd49f41a | 625 | .term_IO = dasd_diag_term_IO, |
8e09f215 | 626 | .handle_terminated_request = dasd_diag_handle_terminated_request, |
1da177e4 LT |
627 | .erp_action = dasd_diag_erp_action, |
628 | .erp_postaction = dasd_diag_erp_postaction, | |
629 | .build_cp = dasd_diag_build_cp, | |
630 | .free_cp = dasd_diag_free_cp, | |
631 | .dump_sense = dasd_diag_dump_sense, | |
632 | .fill_info = dasd_diag_fill_info, | |
633 | }; | |
634 | ||
635 | static int __init | |
636 | dasd_diag_init(void) | |
637 | { | |
638 | if (!MACHINE_IS_VM) { | |
fc19f381 SH |
639 | pr_info("Discipline %s cannot be used without z/VM\n", |
640 | dasd_diag_discipline.name); | |
fd49f41a | 641 | return -ENODEV; |
1da177e4 LT |
642 | } |
643 | ASCEBC(dasd_diag_discipline.ebcname, 4); | |
644 | ||
645 | ctl_set_bit(0, 9); | |
646 | register_external_interrupt(0x2603, dasd_ext_handler); | |
647 | dasd_diag_discipline_pointer = &dasd_diag_discipline; | |
648 | return 0; | |
649 | } | |
650 | ||
651 | static void __exit | |
652 | dasd_diag_cleanup(void) | |
653 | { | |
1da177e4 LT |
654 | unregister_external_interrupt(0x2603, dasd_ext_handler); |
655 | ctl_clear_bit(0, 9); | |
656 | dasd_diag_discipline_pointer = NULL; | |
657 | } | |
658 | ||
659 | module_init(dasd_diag_init); | |
660 | module_exit(dasd_diag_cleanup); |