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