[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / s390 / block / dasd_eckd.c
blob417b97cd3f9495cee6ba74116dcfaa0bb836d9f2
1 /*
2 * File...........: linux/drivers/s390/block/dasd_eckd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
9 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
13 #define KMSG_COMPONENT "dasd-eckd"
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/hdreg.h> /* HDIO_GETGEO */
19 #include <linux/bio.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
23 #include <asm/debug.h>
24 #include <asm/idals.h>
25 #include <asm/ebcdic.h>
26 #include <asm/io.h>
27 #include <asm/todclk.h>
28 #include <asm/uaccess.h>
29 #include <asm/cio.h>
30 #include <asm/ccwdev.h>
31 #include <asm/itcw.h>
33 #include "dasd_int.h"
34 #include "dasd_eckd.h"
35 #include "../cio/chsc.h"
38 #ifdef PRINTK_HEADER
39 #undef PRINTK_HEADER
40 #endif /* PRINTK_HEADER */
41 #define PRINTK_HEADER "dasd(eckd):"
43 #define ECKD_C0(i) (i->home_bytes)
44 #define ECKD_F(i) (i->formula)
45 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
46 (i->factors.f_0x02.f1))
47 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
48 (i->factors.f_0x02.f2))
49 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
50 (i->factors.f_0x02.f3))
51 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
52 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
53 #define ECKD_F6(i) (i->factor6)
54 #define ECKD_F7(i) (i->factor7)
55 #define ECKD_F8(i) (i->factor8)
57 MODULE_LICENSE("GPL");
59 static struct dasd_discipline dasd_eckd_discipline;
61 /* The ccw bus type uses this table to find devices that it sends to
62 * dasd_eckd_probe */
63 static struct ccw_device_id dasd_eckd_ids[] = {
64 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
65 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
66 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
67 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
68 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
69 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
70 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
71 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
72 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
73 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
74 { /* end of list */ },
77 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
79 static struct ccw_driver dasd_eckd_driver; /* see below */
81 /* initial attempt at a probe function. this can be simplified once
82 * the other detection code is gone */
83 static int
84 dasd_eckd_probe (struct ccw_device *cdev)
86 int ret;
88 /* set ECKD specific ccw-device options */
89 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
90 if (ret) {
91 DBF_EVENT(DBF_WARNING,
92 "dasd_eckd_probe: could not set ccw-device options "
93 "for %s\n", dev_name(&cdev->dev));
94 return ret;
96 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
97 return ret;
100 static int
101 dasd_eckd_set_online(struct ccw_device *cdev)
103 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
106 static const int sizes_trk0[] = { 28, 148, 84 };
107 #define LABEL_SIZE 140
109 static inline unsigned int
110 round_up_multiple(unsigned int no, unsigned int mult)
112 int rem = no % mult;
113 return (rem ? no - rem + mult : no);
116 static inline unsigned int
117 ceil_quot(unsigned int d1, unsigned int d2)
119 return (d1 + (d2 - 1)) / d2;
122 static unsigned int
123 recs_per_track(struct dasd_eckd_characteristics * rdc,
124 unsigned int kl, unsigned int dl)
126 int dn, kn;
128 switch (rdc->dev_type) {
129 case 0x3380:
130 if (kl)
131 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
132 ceil_quot(dl + 12, 32));
133 else
134 return 1499 / (15 + ceil_quot(dl + 12, 32));
135 case 0x3390:
136 dn = ceil_quot(dl + 6, 232) + 1;
137 if (kl) {
138 kn = ceil_quot(kl + 6, 232) + 1;
139 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
140 9 + ceil_quot(dl + 6 * dn, 34));
141 } else
142 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
143 case 0x9345:
144 dn = ceil_quot(dl + 6, 232) + 1;
145 if (kl) {
146 kn = ceil_quot(kl + 6, 232) + 1;
147 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
148 ceil_quot(dl + 6 * dn, 34));
149 } else
150 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
152 return 0;
155 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
157 geo->cyl = (__u16) cyl;
158 geo->head = cyl >> 16;
159 geo->head <<= 4;
160 geo->head |= head;
163 static int
164 check_XRC (struct ccw1 *de_ccw,
165 struct DE_eckd_data *data,
166 struct dasd_device *device)
168 struct dasd_eckd_private *private;
169 int rc;
171 private = (struct dasd_eckd_private *) device->private;
172 if (!private->rdc_data.facilities.XRC_supported)
173 return 0;
175 /* switch on System Time Stamp - needed for XRC Support */
176 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
177 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
179 rc = get_sync_clock(&data->ep_sys_time);
180 /* Ignore return code if sync clock is switched off. */
181 if (rc == -ENOSYS || rc == -EACCES)
182 rc = 0;
184 de_ccw->count = sizeof(struct DE_eckd_data);
185 de_ccw->flags |= CCW_FLAG_SLI;
186 return rc;
189 static int
190 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
191 unsigned int totrk, int cmd, struct dasd_device *device)
193 struct dasd_eckd_private *private;
194 u32 begcyl, endcyl;
195 u16 heads, beghead, endhead;
196 int rc = 0;
198 private = (struct dasd_eckd_private *) device->private;
200 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
201 ccw->flags = 0;
202 ccw->count = 16;
203 ccw->cda = (__u32) __pa(data);
205 memset(data, 0, sizeof(struct DE_eckd_data));
206 switch (cmd) {
207 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
208 case DASD_ECKD_CCW_READ_RECORD_ZERO:
209 case DASD_ECKD_CCW_READ:
210 case DASD_ECKD_CCW_READ_MT:
211 case DASD_ECKD_CCW_READ_CKD:
212 case DASD_ECKD_CCW_READ_CKD_MT:
213 case DASD_ECKD_CCW_READ_KD:
214 case DASD_ECKD_CCW_READ_KD_MT:
215 case DASD_ECKD_CCW_READ_COUNT:
216 data->mask.perm = 0x1;
217 data->attributes.operation = private->attrib.operation;
218 break;
219 case DASD_ECKD_CCW_WRITE:
220 case DASD_ECKD_CCW_WRITE_MT:
221 case DASD_ECKD_CCW_WRITE_KD:
222 case DASD_ECKD_CCW_WRITE_KD_MT:
223 data->mask.perm = 0x02;
224 data->attributes.operation = private->attrib.operation;
225 rc = check_XRC (ccw, data, device);
226 break;
227 case DASD_ECKD_CCW_WRITE_CKD:
228 case DASD_ECKD_CCW_WRITE_CKD_MT:
229 data->attributes.operation = DASD_BYPASS_CACHE;
230 rc = check_XRC (ccw, data, device);
231 break;
232 case DASD_ECKD_CCW_ERASE:
233 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
234 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
235 data->mask.perm = 0x3;
236 data->mask.auth = 0x1;
237 data->attributes.operation = DASD_BYPASS_CACHE;
238 rc = check_XRC (ccw, data, device);
239 break;
240 default:
241 dev_err(&device->cdev->dev,
242 "0x%x is not a known command\n", cmd);
243 break;
246 data->attributes.mode = 0x3; /* ECKD */
248 if ((private->rdc_data.cu_type == 0x2105 ||
249 private->rdc_data.cu_type == 0x2107 ||
250 private->rdc_data.cu_type == 0x1750)
251 && !(private->uses_cdl && trk < 2))
252 data->ga_extended |= 0x40; /* Regular Data Format Mode */
254 heads = private->rdc_data.trk_per_cyl;
255 begcyl = trk / heads;
256 beghead = trk % heads;
257 endcyl = totrk / heads;
258 endhead = totrk % heads;
260 /* check for sequential prestage - enhance cylinder range */
261 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
262 data->attributes.operation == DASD_SEQ_ACCESS) {
264 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
265 endcyl += private->attrib.nr_cyl;
266 else
267 endcyl = (private->real_cyl - 1);
270 set_ch_t(&data->beg_ext, begcyl, beghead);
271 set_ch_t(&data->end_ext, endcyl, endhead);
272 return rc;
275 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
276 struct dasd_device *device)
278 struct dasd_eckd_private *private;
279 int rc;
281 private = (struct dasd_eckd_private *) device->private;
282 if (!private->rdc_data.facilities.XRC_supported)
283 return 0;
285 /* switch on System Time Stamp - needed for XRC Support */
286 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
287 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
288 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
290 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
291 /* Ignore return code if sync clock is switched off. */
292 if (rc == -ENOSYS || rc == -EACCES)
293 rc = 0;
294 return rc;
297 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
298 unsigned int rec_on_trk, int count, int cmd,
299 struct dasd_device *device, unsigned int reclen,
300 unsigned int tlf)
302 struct dasd_eckd_private *private;
303 int sector;
304 int dn, d;
306 private = (struct dasd_eckd_private *) device->private;
308 memset(data, 0, sizeof(*data));
309 sector = 0;
310 if (rec_on_trk) {
311 switch (private->rdc_data.dev_type) {
312 case 0x3390:
313 dn = ceil_quot(reclen + 6, 232);
314 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
315 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
316 break;
317 case 0x3380:
318 d = 7 + ceil_quot(reclen + 12, 32);
319 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
320 break;
323 data->sector = sector;
324 /* note: meaning of count depends on the operation
325 * for record based I/O it's the number of records, but for
326 * track based I/O it's the number of tracks
328 data->count = count;
329 switch (cmd) {
330 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
331 data->operation.orientation = 0x3;
332 data->operation.operation = 0x03;
333 break;
334 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
335 data->operation.orientation = 0x3;
336 data->operation.operation = 0x16;
337 break;
338 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
339 data->operation.orientation = 0x1;
340 data->operation.operation = 0x03;
341 data->count++;
342 break;
343 case DASD_ECKD_CCW_READ_RECORD_ZERO:
344 data->operation.orientation = 0x3;
345 data->operation.operation = 0x16;
346 data->count++;
347 break;
348 case DASD_ECKD_CCW_WRITE:
349 case DASD_ECKD_CCW_WRITE_MT:
350 case DASD_ECKD_CCW_WRITE_KD:
351 case DASD_ECKD_CCW_WRITE_KD_MT:
352 data->auxiliary.length_valid = 0x1;
353 data->length = reclen;
354 data->operation.operation = 0x01;
355 break;
356 case DASD_ECKD_CCW_WRITE_CKD:
357 case DASD_ECKD_CCW_WRITE_CKD_MT:
358 data->auxiliary.length_valid = 0x1;
359 data->length = reclen;
360 data->operation.operation = 0x03;
361 break;
362 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
363 data->auxiliary.length_valid = 0x1;
364 data->length = reclen; /* not tlf, as one might think */
365 data->operation.operation = 0x3F;
366 data->extended_operation = 0x23;
367 break;
368 case DASD_ECKD_CCW_READ:
369 case DASD_ECKD_CCW_READ_MT:
370 case DASD_ECKD_CCW_READ_KD:
371 case DASD_ECKD_CCW_READ_KD_MT:
372 data->auxiliary.length_valid = 0x1;
373 data->length = reclen;
374 data->operation.operation = 0x06;
375 break;
376 case DASD_ECKD_CCW_READ_CKD:
377 case DASD_ECKD_CCW_READ_CKD_MT:
378 data->auxiliary.length_valid = 0x1;
379 data->length = reclen;
380 data->operation.operation = 0x16;
381 break;
382 case DASD_ECKD_CCW_READ_COUNT:
383 data->operation.operation = 0x06;
384 break;
385 case DASD_ECKD_CCW_READ_TRACK_DATA:
386 data->auxiliary.length_valid = 0x1;
387 data->length = tlf;
388 data->operation.operation = 0x0C;
389 break;
390 case DASD_ECKD_CCW_ERASE:
391 data->length = reclen;
392 data->auxiliary.length_valid = 0x1;
393 data->operation.operation = 0x0b;
394 break;
395 default:
396 DBF_DEV_EVENT(DBF_ERR, device,
397 "fill LRE unknown opcode 0x%x", cmd);
398 BUG();
400 set_ch_t(&data->seek_addr,
401 trk / private->rdc_data.trk_per_cyl,
402 trk % private->rdc_data.trk_per_cyl);
403 data->search_arg.cyl = data->seek_addr.cyl;
404 data->search_arg.head = data->seek_addr.head;
405 data->search_arg.record = rec_on_trk;
408 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
409 unsigned int trk, unsigned int totrk, int cmd,
410 struct dasd_device *basedev, struct dasd_device *startdev,
411 unsigned char format, unsigned int rec_on_trk, int count,
412 unsigned int blksize, unsigned int tlf)
414 struct dasd_eckd_private *basepriv, *startpriv;
415 struct DE_eckd_data *dedata;
416 struct LRE_eckd_data *lredata;
417 u32 begcyl, endcyl;
418 u16 heads, beghead, endhead;
419 int rc = 0;
421 basepriv = (struct dasd_eckd_private *) basedev->private;
422 startpriv = (struct dasd_eckd_private *) startdev->private;
423 dedata = &pfxdata->define_extent;
424 lredata = &pfxdata->locate_record;
426 ccw->cmd_code = DASD_ECKD_CCW_PFX;
427 ccw->flags = 0;
428 ccw->count = sizeof(*pfxdata);
429 ccw->cda = (__u32) __pa(pfxdata);
431 memset(pfxdata, 0, sizeof(*pfxdata));
432 /* prefix data */
433 if (format > 1) {
434 DBF_DEV_EVENT(DBF_ERR, basedev,
435 "PFX LRE unknown format 0x%x", format);
436 BUG();
437 return -EINVAL;
439 pfxdata->format = format;
440 pfxdata->base_address = basepriv->ned->unit_addr;
441 pfxdata->base_lss = basepriv->ned->ID;
442 pfxdata->validity.define_extent = 1;
444 /* private uid is kept up to date, conf_data may be outdated */
445 if (startpriv->uid.type != UA_BASE_DEVICE) {
446 pfxdata->validity.verify_base = 1;
447 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
448 pfxdata->validity.hyper_pav = 1;
451 /* define extend data (mostly)*/
452 switch (cmd) {
453 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
454 case DASD_ECKD_CCW_READ_RECORD_ZERO:
455 case DASD_ECKD_CCW_READ:
456 case DASD_ECKD_CCW_READ_MT:
457 case DASD_ECKD_CCW_READ_CKD:
458 case DASD_ECKD_CCW_READ_CKD_MT:
459 case DASD_ECKD_CCW_READ_KD:
460 case DASD_ECKD_CCW_READ_KD_MT:
461 case DASD_ECKD_CCW_READ_COUNT:
462 dedata->mask.perm = 0x1;
463 dedata->attributes.operation = basepriv->attrib.operation;
464 break;
465 case DASD_ECKD_CCW_READ_TRACK_DATA:
466 dedata->mask.perm = 0x1;
467 dedata->attributes.operation = basepriv->attrib.operation;
468 dedata->blk_size = 0;
469 break;
470 case DASD_ECKD_CCW_WRITE:
471 case DASD_ECKD_CCW_WRITE_MT:
472 case DASD_ECKD_CCW_WRITE_KD:
473 case DASD_ECKD_CCW_WRITE_KD_MT:
474 dedata->mask.perm = 0x02;
475 dedata->attributes.operation = basepriv->attrib.operation;
476 rc = check_XRC_on_prefix(pfxdata, basedev);
477 break;
478 case DASD_ECKD_CCW_WRITE_CKD:
479 case DASD_ECKD_CCW_WRITE_CKD_MT:
480 dedata->attributes.operation = DASD_BYPASS_CACHE;
481 rc = check_XRC_on_prefix(pfxdata, basedev);
482 break;
483 case DASD_ECKD_CCW_ERASE:
484 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
485 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
486 dedata->mask.perm = 0x3;
487 dedata->mask.auth = 0x1;
488 dedata->attributes.operation = DASD_BYPASS_CACHE;
489 rc = check_XRC_on_prefix(pfxdata, basedev);
490 break;
491 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
492 dedata->mask.perm = 0x02;
493 dedata->attributes.operation = basepriv->attrib.operation;
494 dedata->blk_size = blksize;
495 rc = check_XRC_on_prefix(pfxdata, basedev);
496 break;
497 default:
498 DBF_DEV_EVENT(DBF_ERR, basedev,
499 "PFX LRE unknown opcode 0x%x", cmd);
500 BUG();
501 return -EINVAL;
504 dedata->attributes.mode = 0x3; /* ECKD */
506 if ((basepriv->rdc_data.cu_type == 0x2105 ||
507 basepriv->rdc_data.cu_type == 0x2107 ||
508 basepriv->rdc_data.cu_type == 0x1750)
509 && !(basepriv->uses_cdl && trk < 2))
510 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
512 heads = basepriv->rdc_data.trk_per_cyl;
513 begcyl = trk / heads;
514 beghead = trk % heads;
515 endcyl = totrk / heads;
516 endhead = totrk % heads;
518 /* check for sequential prestage - enhance cylinder range */
519 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
520 dedata->attributes.operation == DASD_SEQ_ACCESS) {
522 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
523 endcyl += basepriv->attrib.nr_cyl;
524 else
525 endcyl = (basepriv->real_cyl - 1);
528 set_ch_t(&dedata->beg_ext, begcyl, beghead);
529 set_ch_t(&dedata->end_ext, endcyl, endhead);
531 if (format == 1) {
532 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
533 basedev, blksize, tlf);
536 return rc;
539 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
540 unsigned int trk, unsigned int totrk, int cmd,
541 struct dasd_device *basedev, struct dasd_device *startdev)
543 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
544 0, 0, 0, 0, 0);
547 static void
548 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
549 unsigned int rec_on_trk, int no_rec, int cmd,
550 struct dasd_device * device, int reclen)
552 struct dasd_eckd_private *private;
553 int sector;
554 int dn, d;
556 private = (struct dasd_eckd_private *) device->private;
558 DBF_DEV_EVENT(DBF_INFO, device,
559 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
560 trk, rec_on_trk, no_rec, cmd, reclen);
562 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
563 ccw->flags = 0;
564 ccw->count = 16;
565 ccw->cda = (__u32) __pa(data);
567 memset(data, 0, sizeof(struct LO_eckd_data));
568 sector = 0;
569 if (rec_on_trk) {
570 switch (private->rdc_data.dev_type) {
571 case 0x3390:
572 dn = ceil_quot(reclen + 6, 232);
573 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
574 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
575 break;
576 case 0x3380:
577 d = 7 + ceil_quot(reclen + 12, 32);
578 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
579 break;
582 data->sector = sector;
583 data->count = no_rec;
584 switch (cmd) {
585 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
586 data->operation.orientation = 0x3;
587 data->operation.operation = 0x03;
588 break;
589 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
590 data->operation.orientation = 0x3;
591 data->operation.operation = 0x16;
592 break;
593 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
594 data->operation.orientation = 0x1;
595 data->operation.operation = 0x03;
596 data->count++;
597 break;
598 case DASD_ECKD_CCW_READ_RECORD_ZERO:
599 data->operation.orientation = 0x3;
600 data->operation.operation = 0x16;
601 data->count++;
602 break;
603 case DASD_ECKD_CCW_WRITE:
604 case DASD_ECKD_CCW_WRITE_MT:
605 case DASD_ECKD_CCW_WRITE_KD:
606 case DASD_ECKD_CCW_WRITE_KD_MT:
607 data->auxiliary.last_bytes_used = 0x1;
608 data->length = reclen;
609 data->operation.operation = 0x01;
610 break;
611 case DASD_ECKD_CCW_WRITE_CKD:
612 case DASD_ECKD_CCW_WRITE_CKD_MT:
613 data->auxiliary.last_bytes_used = 0x1;
614 data->length = reclen;
615 data->operation.operation = 0x03;
616 break;
617 case DASD_ECKD_CCW_READ:
618 case DASD_ECKD_CCW_READ_MT:
619 case DASD_ECKD_CCW_READ_KD:
620 case DASD_ECKD_CCW_READ_KD_MT:
621 data->auxiliary.last_bytes_used = 0x1;
622 data->length = reclen;
623 data->operation.operation = 0x06;
624 break;
625 case DASD_ECKD_CCW_READ_CKD:
626 case DASD_ECKD_CCW_READ_CKD_MT:
627 data->auxiliary.last_bytes_used = 0x1;
628 data->length = reclen;
629 data->operation.operation = 0x16;
630 break;
631 case DASD_ECKD_CCW_READ_COUNT:
632 data->operation.operation = 0x06;
633 break;
634 case DASD_ECKD_CCW_ERASE:
635 data->length = reclen;
636 data->auxiliary.last_bytes_used = 0x1;
637 data->operation.operation = 0x0b;
638 break;
639 default:
640 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
641 "opcode 0x%x", cmd);
643 set_ch_t(&data->seek_addr,
644 trk / private->rdc_data.trk_per_cyl,
645 trk % private->rdc_data.trk_per_cyl);
646 data->search_arg.cyl = data->seek_addr.cyl;
647 data->search_arg.head = data->seek_addr.head;
648 data->search_arg.record = rec_on_trk;
652 * Returns 1 if the block is one of the special blocks that needs
653 * to get read/written with the KD variant of the command.
654 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
655 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
656 * Luckily the KD variants differ only by one bit (0x08) from the
657 * normal variant. So don't wonder about code like:
658 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
659 * ccw->cmd_code |= 0x8;
661 static inline int
662 dasd_eckd_cdl_special(int blk_per_trk, int recid)
664 if (recid < 3)
665 return 1;
666 if (recid < blk_per_trk)
667 return 0;
668 if (recid < 2 * blk_per_trk)
669 return 1;
670 return 0;
674 * Returns the record size for the special blocks of the cdl format.
675 * Only returns something useful if dasd_eckd_cdl_special is true
676 * for the recid.
678 static inline int
679 dasd_eckd_cdl_reclen(int recid)
681 if (recid < 3)
682 return sizes_trk0[recid];
683 return LABEL_SIZE;
687 * Generate device unique id that specifies the physical device.
689 static int dasd_eckd_generate_uid(struct dasd_device *device,
690 struct dasd_uid *uid)
692 struct dasd_eckd_private *private;
693 int count;
695 private = (struct dasd_eckd_private *) device->private;
696 if (!private)
697 return -ENODEV;
698 if (!private->ned || !private->gneq)
699 return -ENODEV;
701 memset(uid, 0, sizeof(struct dasd_uid));
702 memcpy(uid->vendor, private->ned->HDA_manufacturer,
703 sizeof(uid->vendor) - 1);
704 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
705 memcpy(uid->serial, private->ned->HDA_location,
706 sizeof(uid->serial) - 1);
707 EBCASC(uid->serial, sizeof(uid->serial) - 1);
708 uid->ssid = private->gneq->subsystemID;
709 uid->real_unit_addr = private->ned->unit_addr;
710 if (private->sneq) {
711 uid->type = private->sneq->sua_flags;
712 if (uid->type == UA_BASE_PAV_ALIAS)
713 uid->base_unit_addr = private->sneq->base_unit_addr;
714 } else {
715 uid->type = UA_BASE_DEVICE;
717 if (private->vdsneq) {
718 for (count = 0; count < 16; count++) {
719 sprintf(uid->vduit+2*count, "%02x",
720 private->vdsneq->uit[count]);
723 return 0;
726 static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
727 void *rcd_buffer,
728 struct ciw *ciw, __u8 lpm)
730 struct dasd_ccw_req *cqr;
731 struct ccw1 *ccw;
733 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, ciw->count,
734 device);
736 if (IS_ERR(cqr)) {
737 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
738 "Could not allocate RCD request");
739 return cqr;
742 ccw = cqr->cpaddr;
743 ccw->cmd_code = ciw->cmd;
744 ccw->cda = (__u32)(addr_t)rcd_buffer;
745 ccw->count = ciw->count;
747 cqr->startdev = device;
748 cqr->memdev = device;
749 cqr->block = NULL;
750 cqr->expires = 10*HZ;
751 cqr->lpm = lpm;
752 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
753 cqr->retries = 2;
754 cqr->buildclk = get_clock();
755 cqr->status = DASD_CQR_FILLED;
756 return cqr;
759 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
760 void **rcd_buffer,
761 int *rcd_buffer_size, __u8 lpm)
763 struct ciw *ciw;
764 char *rcd_buf = NULL;
765 int ret;
766 struct dasd_ccw_req *cqr;
769 * scan for RCD command in extended SenseID data
771 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
772 if (!ciw || ciw->cmd == 0) {
773 ret = -EOPNOTSUPP;
774 goto out_error;
776 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
777 if (!rcd_buf) {
778 ret = -ENOMEM;
779 goto out_error;
783 * buffer has to start with EBCDIC "V1.0" to show
784 * support for virtual device SNEQ
786 rcd_buf[0] = 0xE5;
787 rcd_buf[1] = 0xF1;
788 rcd_buf[2] = 0x4B;
789 rcd_buf[3] = 0xF0;
790 cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
791 if (IS_ERR(cqr)) {
792 ret = PTR_ERR(cqr);
793 goto out_error;
795 ret = dasd_sleep_on(cqr);
797 * on success we update the user input parms
799 dasd_sfree_request(cqr, cqr->memdev);
800 if (ret)
801 goto out_error;
803 *rcd_buffer_size = ciw->count;
804 *rcd_buffer = rcd_buf;
805 return 0;
806 out_error:
807 kfree(rcd_buf);
808 *rcd_buffer = NULL;
809 *rcd_buffer_size = 0;
810 return ret;
813 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
816 struct dasd_sneq *sneq;
817 int i, count;
819 private->ned = NULL;
820 private->sneq = NULL;
821 private->vdsneq = NULL;
822 private->gneq = NULL;
823 count = private->conf_len / sizeof(struct dasd_sneq);
824 sneq = (struct dasd_sneq *)private->conf_data;
825 for (i = 0; i < count; ++i) {
826 if (sneq->flags.identifier == 1 && sneq->format == 1)
827 private->sneq = sneq;
828 else if (sneq->flags.identifier == 1 && sneq->format == 4)
829 private->vdsneq = (struct vd_sneq *)sneq;
830 else if (sneq->flags.identifier == 2)
831 private->gneq = (struct dasd_gneq *)sneq;
832 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
833 private->ned = (struct dasd_ned *)sneq;
834 sneq++;
836 if (!private->ned || !private->gneq) {
837 private->ned = NULL;
838 private->sneq = NULL;
839 private->vdsneq = NULL;
840 private->gneq = NULL;
841 return -EINVAL;
843 return 0;
847 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
849 struct dasd_gneq *gneq;
850 int i, count, found;
852 count = conf_len / sizeof(*gneq);
853 gneq = (struct dasd_gneq *)conf_data;
854 found = 0;
855 for (i = 0; i < count; ++i) {
856 if (gneq->flags.identifier == 2) {
857 found = 1;
858 break;
860 gneq++;
862 if (found)
863 return ((char *)gneq)[18] & 0x07;
864 else
865 return 0;
868 static int dasd_eckd_read_conf(struct dasd_device *device)
870 void *conf_data;
871 int conf_len, conf_data_saved;
872 int rc;
873 __u8 lpm;
874 struct dasd_eckd_private *private;
875 struct dasd_eckd_path *path_data;
877 private = (struct dasd_eckd_private *) device->private;
878 path_data = (struct dasd_eckd_path *) &private->path_data;
879 path_data->opm = ccw_device_get_path_mask(device->cdev);
880 lpm = 0x80;
881 conf_data_saved = 0;
882 /* get configuration data per operational path */
883 for (lpm = 0x80; lpm; lpm>>= 1) {
884 if (lpm & path_data->opm){
885 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
886 &conf_len, lpm);
887 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
888 DBF_EVENT(DBF_WARNING,
889 "Read configuration data returned "
890 "error %d for device: %s", rc,
891 dev_name(&device->cdev->dev));
892 return rc;
894 if (conf_data == NULL) {
895 DBF_EVENT(DBF_WARNING, "No configuration "
896 "data retrieved for device: %s",
897 dev_name(&device->cdev->dev));
898 continue; /* no error */
900 /* save first valid configuration data */
901 if (!conf_data_saved) {
902 kfree(private->conf_data);
903 private->conf_data = conf_data;
904 private->conf_len = conf_len;
905 if (dasd_eckd_identify_conf_parts(private)) {
906 private->conf_data = NULL;
907 private->conf_len = 0;
908 kfree(conf_data);
909 continue;
911 conf_data_saved++;
913 switch (dasd_eckd_path_access(conf_data, conf_len)) {
914 case 0x02:
915 path_data->npm |= lpm;
916 break;
917 case 0x03:
918 path_data->ppm |= lpm;
919 break;
921 if (conf_data != private->conf_data)
922 kfree(conf_data);
925 return 0;
928 static int dasd_eckd_read_features(struct dasd_device *device)
930 struct dasd_psf_prssd_data *prssdp;
931 struct dasd_rssd_features *features;
932 struct dasd_ccw_req *cqr;
933 struct ccw1 *ccw;
934 int rc;
935 struct dasd_eckd_private *private;
937 private = (struct dasd_eckd_private *) device->private;
938 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
939 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
940 (sizeof(struct dasd_psf_prssd_data) +
941 sizeof(struct dasd_rssd_features)),
942 device);
943 if (IS_ERR(cqr)) {
944 DBF_EVENT(DBF_WARNING, "Could not allocate initialization "
945 "request for device: %s",
946 dev_name(&device->cdev->dev));
947 return PTR_ERR(cqr);
949 cqr->startdev = device;
950 cqr->memdev = device;
951 cqr->block = NULL;
952 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
953 cqr->retries = 5;
954 cqr->expires = 10 * HZ;
956 /* Prepare for Read Subsystem Data */
957 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
958 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
959 prssdp->order = PSF_ORDER_PRSSD;
960 prssdp->suborder = 0x41; /* Read Feature Codes */
961 /* all other bytes of prssdp must be zero */
963 ccw = cqr->cpaddr;
964 ccw->cmd_code = DASD_ECKD_CCW_PSF;
965 ccw->count = sizeof(struct dasd_psf_prssd_data);
966 ccw->flags |= CCW_FLAG_CC;
967 ccw->cda = (__u32)(addr_t) prssdp;
969 /* Read Subsystem Data - feature codes */
970 features = (struct dasd_rssd_features *) (prssdp + 1);
971 memset(features, 0, sizeof(struct dasd_rssd_features));
973 ccw++;
974 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
975 ccw->count = sizeof(struct dasd_rssd_features);
976 ccw->cda = (__u32)(addr_t) features;
978 cqr->buildclk = get_clock();
979 cqr->status = DASD_CQR_FILLED;
980 rc = dasd_sleep_on(cqr);
981 if (rc == 0) {
982 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
983 features = (struct dasd_rssd_features *) (prssdp + 1);
984 memcpy(&private->features, features,
985 sizeof(struct dasd_rssd_features));
986 } else
987 dev_warn(&device->cdev->dev, "Reading device feature codes"
988 " failed with rc=%d\n", rc);
989 dasd_sfree_request(cqr, cqr->memdev);
990 return rc;
995 * Build CP for Perform Subsystem Function - SSC.
997 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
998 int enable_pav)
1000 struct dasd_ccw_req *cqr;
1001 struct dasd_psf_ssc_data *psf_ssc_data;
1002 struct ccw1 *ccw;
1004 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1005 sizeof(struct dasd_psf_ssc_data),
1006 device);
1008 if (IS_ERR(cqr)) {
1009 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1010 "Could not allocate PSF-SSC request");
1011 return cqr;
1013 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1014 psf_ssc_data->order = PSF_ORDER_SSC;
1015 psf_ssc_data->suborder = 0x40;
1016 if (enable_pav) {
1017 psf_ssc_data->suborder |= 0x88;
1018 psf_ssc_data->reserved[0] = 0x88;
1020 ccw = cqr->cpaddr;
1021 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1022 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1023 ccw->count = 66;
1025 cqr->startdev = device;
1026 cqr->memdev = device;
1027 cqr->block = NULL;
1028 cqr->expires = 10*HZ;
1029 cqr->buildclk = get_clock();
1030 cqr->status = DASD_CQR_FILLED;
1031 return cqr;
1035 * Perform Subsystem Function.
1036 * It is necessary to trigger CIO for channel revalidation since this
1037 * call might change behaviour of DASD devices.
1039 static int
1040 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1042 struct dasd_ccw_req *cqr;
1043 int rc;
1045 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1046 if (IS_ERR(cqr))
1047 return PTR_ERR(cqr);
1049 rc = dasd_sleep_on(cqr);
1050 if (!rc)
1051 /* trigger CIO to reprobe devices */
1052 css_schedule_reprobe();
1053 dasd_sfree_request(cqr, cqr->memdev);
1054 return rc;
1058 * Valide storage server of current device.
1060 static int dasd_eckd_validate_server(struct dasd_device *device)
1062 int rc;
1063 struct dasd_eckd_private *private;
1064 int enable_pav;
1066 if (dasd_nopav || MACHINE_IS_VM)
1067 enable_pav = 0;
1068 else
1069 enable_pav = 1;
1070 rc = dasd_eckd_psf_ssc(device, enable_pav);
1071 /* may be requested feature is not available on server,
1072 * therefore just report error and go ahead */
1073 private = (struct dasd_eckd_private *) device->private;
1074 DBF_EVENT(DBF_WARNING, "PSF-SSC on storage subsystem %s.%s.%04x "
1075 "returned rc=%d for device: %s",
1076 private->uid.vendor, private->uid.serial,
1077 private->uid.ssid, rc, dev_name(&device->cdev->dev));
1078 /* RE-Read Configuration Data */
1079 return dasd_eckd_read_conf(device);
1083 * Check device characteristics.
1084 * If the device is accessible using ECKD discipline, the device is enabled.
1086 static int
1087 dasd_eckd_check_characteristics(struct dasd_device *device)
1089 struct dasd_eckd_private *private;
1090 struct dasd_block *block;
1091 int is_known, rc;
1093 private = (struct dasd_eckd_private *) device->private;
1094 if (!private) {
1095 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1096 if (!private) {
1097 dev_warn(&device->cdev->dev,
1098 "Allocating memory for private DASD data "
1099 "failed\n");
1100 return -ENOMEM;
1102 device->private = (void *) private;
1103 } else {
1104 memset(private, 0, sizeof(*private));
1106 /* Invalidate status of initial analysis. */
1107 private->init_cqr_status = -1;
1108 /* Set default cache operations. */
1109 private->attrib.operation = DASD_NORMAL_CACHE;
1110 private->attrib.nr_cyl = 0;
1112 /* Read Configuration Data */
1113 rc = dasd_eckd_read_conf(device);
1114 if (rc)
1115 goto out_err1;
1117 /* Generate device unique id and register in devmap */
1118 rc = dasd_eckd_generate_uid(device, &private->uid);
1119 if (rc)
1120 goto out_err1;
1121 dasd_set_uid(device->cdev, &private->uid);
1123 if (private->uid.type == UA_BASE_DEVICE) {
1124 block = dasd_alloc_block();
1125 if (IS_ERR(block)) {
1126 DBF_EVENT(DBF_WARNING, "could not allocate dasd "
1127 "block structure for device: %s",
1128 dev_name(&device->cdev->dev));
1129 rc = PTR_ERR(block);
1130 goto out_err1;
1132 device->block = block;
1133 block->base = device;
1136 /* register lcu with alias handling, enable PAV if this is a new lcu */
1137 is_known = dasd_alias_make_device_known_to_lcu(device);
1138 if (is_known < 0) {
1139 rc = is_known;
1140 goto out_err2;
1142 if (!is_known) {
1143 /* new lcu found */
1144 rc = dasd_eckd_validate_server(device); /* will switch pav on */
1145 if (rc)
1146 goto out_err3;
1149 /* Read Feature Codes */
1150 dasd_eckd_read_features(device);
1152 /* Read Device Characteristics */
1153 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1154 &private->rdc_data, 64);
1155 if (rc) {
1156 DBF_EVENT(DBF_WARNING,
1157 "Read device characteristics failed, rc=%d for "
1158 "device: %s", rc, dev_name(&device->cdev->dev));
1159 goto out_err3;
1161 /* find the vaild cylinder size */
1162 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1163 private->rdc_data.long_no_cyl)
1164 private->real_cyl = private->rdc_data.long_no_cyl;
1165 else
1166 private->real_cyl = private->rdc_data.no_cyl;
1168 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1169 "with %d cylinders, %d heads, %d sectors\n",
1170 private->rdc_data.dev_type,
1171 private->rdc_data.dev_model,
1172 private->rdc_data.cu_type,
1173 private->rdc_data.cu_model.model,
1174 private->real_cyl,
1175 private->rdc_data.trk_per_cyl,
1176 private->rdc_data.sec_per_trk);
1177 return 0;
1179 out_err3:
1180 dasd_alias_disconnect_device_from_lcu(device);
1181 out_err2:
1182 dasd_free_block(device->block);
1183 device->block = NULL;
1184 out_err1:
1185 kfree(private->conf_data);
1186 kfree(device->private);
1187 device->private = NULL;
1188 return rc;
1191 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1193 struct dasd_eckd_private *private;
1195 private = (struct dasd_eckd_private *) device->private;
1196 dasd_alias_disconnect_device_from_lcu(device);
1197 private->ned = NULL;
1198 private->sneq = NULL;
1199 private->vdsneq = NULL;
1200 private->gneq = NULL;
1201 private->conf_len = 0;
1202 kfree(private->conf_data);
1203 private->conf_data = NULL;
1206 static struct dasd_ccw_req *
1207 dasd_eckd_analysis_ccw(struct dasd_device *device)
1209 struct dasd_eckd_private *private;
1210 struct eckd_count *count_data;
1211 struct LO_eckd_data *LO_data;
1212 struct dasd_ccw_req *cqr;
1213 struct ccw1 *ccw;
1214 int cplength, datasize;
1215 int i;
1217 private = (struct dasd_eckd_private *) device->private;
1219 cplength = 8;
1220 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1221 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1222 if (IS_ERR(cqr))
1223 return cqr;
1224 ccw = cqr->cpaddr;
1225 /* Define extent for the first 3 tracks. */
1226 define_extent(ccw++, cqr->data, 0, 2,
1227 DASD_ECKD_CCW_READ_COUNT, device);
1228 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1229 /* Locate record for the first 4 records on track 0. */
1230 ccw[-1].flags |= CCW_FLAG_CC;
1231 locate_record(ccw++, LO_data++, 0, 0, 4,
1232 DASD_ECKD_CCW_READ_COUNT, device, 0);
1234 count_data = private->count_area;
1235 for (i = 0; i < 4; i++) {
1236 ccw[-1].flags |= CCW_FLAG_CC;
1237 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1238 ccw->flags = 0;
1239 ccw->count = 8;
1240 ccw->cda = (__u32)(addr_t) count_data;
1241 ccw++;
1242 count_data++;
1245 /* Locate record for the first record on track 2. */
1246 ccw[-1].flags |= CCW_FLAG_CC;
1247 locate_record(ccw++, LO_data++, 2, 0, 1,
1248 DASD_ECKD_CCW_READ_COUNT, device, 0);
1249 /* Read count ccw. */
1250 ccw[-1].flags |= CCW_FLAG_CC;
1251 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1252 ccw->flags = 0;
1253 ccw->count = 8;
1254 ccw->cda = (__u32)(addr_t) count_data;
1256 cqr->block = NULL;
1257 cqr->startdev = device;
1258 cqr->memdev = device;
1259 cqr->retries = 0;
1260 cqr->buildclk = get_clock();
1261 cqr->status = DASD_CQR_FILLED;
1262 return cqr;
1266 * This is the callback function for the init_analysis cqr. It saves
1267 * the status of the initial analysis ccw before it frees it and kicks
1268 * the device to continue the startup sequence. This will call
1269 * dasd_eckd_do_analysis again (if the devices has not been marked
1270 * for deletion in the meantime).
1272 static void
1273 dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
1275 struct dasd_eckd_private *private;
1276 struct dasd_device *device;
1278 device = init_cqr->startdev;
1279 private = (struct dasd_eckd_private *) device->private;
1280 private->init_cqr_status = init_cqr->status;
1281 dasd_sfree_request(init_cqr, device);
1282 dasd_kick_device(device);
1285 static int
1286 dasd_eckd_start_analysis(struct dasd_block *block)
1288 struct dasd_eckd_private *private;
1289 struct dasd_ccw_req *init_cqr;
1291 private = (struct dasd_eckd_private *) block->base->private;
1292 init_cqr = dasd_eckd_analysis_ccw(block->base);
1293 if (IS_ERR(init_cqr))
1294 return PTR_ERR(init_cqr);
1295 init_cqr->callback = dasd_eckd_analysis_callback;
1296 init_cqr->callback_data = NULL;
1297 init_cqr->expires = 5*HZ;
1298 dasd_add_request_head(init_cqr);
1299 return -EAGAIN;
1302 static int
1303 dasd_eckd_end_analysis(struct dasd_block *block)
1305 struct dasd_device *device;
1306 struct dasd_eckd_private *private;
1307 struct eckd_count *count_area;
1308 unsigned int sb, blk_per_trk;
1309 int status, i;
1311 device = block->base;
1312 private = (struct dasd_eckd_private *) device->private;
1313 status = private->init_cqr_status;
1314 private->init_cqr_status = -1;
1315 if (status != DASD_CQR_DONE) {
1316 dev_warn(&device->cdev->dev,
1317 "The DASD is not formatted\n");
1318 return -EMEDIUMTYPE;
1321 private->uses_cdl = 1;
1322 /* Check Track 0 for Compatible Disk Layout */
1323 count_area = NULL;
1324 for (i = 0; i < 3; i++) {
1325 if (private->count_area[i].kl != 4 ||
1326 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1327 private->uses_cdl = 0;
1328 break;
1331 if (i == 3)
1332 count_area = &private->count_area[4];
1334 if (private->uses_cdl == 0) {
1335 for (i = 0; i < 5; i++) {
1336 if ((private->count_area[i].kl != 0) ||
1337 (private->count_area[i].dl !=
1338 private->count_area[0].dl))
1339 break;
1341 if (i == 5)
1342 count_area = &private->count_area[0];
1343 } else {
1344 if (private->count_area[3].record == 1)
1345 dev_warn(&device->cdev->dev,
1346 "Track 0 has no records following the VTOC\n");
1348 if (count_area != NULL && count_area->kl == 0) {
1349 /* we found notthing violating our disk layout */
1350 if (dasd_check_blocksize(count_area->dl) == 0)
1351 block->bp_block = count_area->dl;
1353 if (block->bp_block == 0) {
1354 dev_warn(&device->cdev->dev,
1355 "The disk layout of the DASD is not supported\n");
1356 return -EMEDIUMTYPE;
1358 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1359 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1360 block->s2b_shift++;
1362 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1363 block->blocks = (private->real_cyl *
1364 private->rdc_data.trk_per_cyl *
1365 blk_per_trk);
1367 dev_info(&device->cdev->dev,
1368 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1369 "%s\n", (block->bp_block >> 10),
1370 ((private->real_cyl *
1371 private->rdc_data.trk_per_cyl *
1372 blk_per_trk * (block->bp_block >> 9)) >> 1),
1373 ((blk_per_trk * block->bp_block) >> 10),
1374 private->uses_cdl ?
1375 "compatible disk layout" : "linux disk layout");
1377 return 0;
1380 static int dasd_eckd_do_analysis(struct dasd_block *block)
1382 struct dasd_eckd_private *private;
1384 private = (struct dasd_eckd_private *) block->base->private;
1385 if (private->init_cqr_status < 0)
1386 return dasd_eckd_start_analysis(block);
1387 else
1388 return dasd_eckd_end_analysis(block);
1391 static int dasd_eckd_ready_to_online(struct dasd_device *device)
1393 return dasd_alias_add_device(device);
1396 static int dasd_eckd_online_to_ready(struct dasd_device *device)
1398 return dasd_alias_remove_device(device);
1401 static int
1402 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1404 struct dasd_eckd_private *private;
1406 private = (struct dasd_eckd_private *) block->base->private;
1407 if (dasd_check_blocksize(block->bp_block) == 0) {
1408 geo->sectors = recs_per_track(&private->rdc_data,
1409 0, block->bp_block);
1411 geo->cylinders = private->rdc_data.no_cyl;
1412 geo->heads = private->rdc_data.trk_per_cyl;
1413 return 0;
1416 static struct dasd_ccw_req *
1417 dasd_eckd_format_device(struct dasd_device * device,
1418 struct format_data_t * fdata)
1420 struct dasd_eckd_private *private;
1421 struct dasd_ccw_req *fcp;
1422 struct eckd_count *ect;
1423 struct ccw1 *ccw;
1424 void *data;
1425 int rpt;
1426 struct ch_t address;
1427 int cplength, datasize;
1428 int i;
1429 int intensity = 0;
1430 int r0_perm;
1432 private = (struct dasd_eckd_private *) device->private;
1433 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1434 set_ch_t(&address,
1435 fdata->start_unit / private->rdc_data.trk_per_cyl,
1436 fdata->start_unit % private->rdc_data.trk_per_cyl);
1438 /* Sanity checks. */
1439 if (fdata->start_unit >=
1440 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
1441 dev_warn(&device->cdev->dev, "Start track number %d used in "
1442 "formatting is too big\n", fdata->start_unit);
1443 return ERR_PTR(-EINVAL);
1445 if (fdata->start_unit > fdata->stop_unit) {
1446 dev_warn(&device->cdev->dev, "Start track %d used in "
1447 "formatting exceeds end track\n", fdata->start_unit);
1448 return ERR_PTR(-EINVAL);
1450 if (dasd_check_blocksize(fdata->blksize) != 0) {
1451 dev_warn(&device->cdev->dev,
1452 "The DASD cannot be formatted with block size %d\n",
1453 fdata->blksize);
1454 return ERR_PTR(-EINVAL);
1458 * fdata->intensity is a bit string that tells us what to do:
1459 * Bit 0: write record zero
1460 * Bit 1: write home address, currently not supported
1461 * Bit 2: invalidate tracks
1462 * Bit 3: use OS/390 compatible disk layout (cdl)
1463 * Bit 4: do not allow storage subsystem to modify record zero
1464 * Only some bit combinations do make sense.
1466 if (fdata->intensity & 0x10) {
1467 r0_perm = 0;
1468 intensity = fdata->intensity & ~0x10;
1469 } else {
1470 r0_perm = 1;
1471 intensity = fdata->intensity;
1473 switch (intensity) {
1474 case 0x00: /* Normal format */
1475 case 0x08: /* Normal format, use cdl. */
1476 cplength = 2 + rpt;
1477 datasize = sizeof(struct DE_eckd_data) +
1478 sizeof(struct LO_eckd_data) +
1479 rpt * sizeof(struct eckd_count);
1480 break;
1481 case 0x01: /* Write record zero and format track. */
1482 case 0x09: /* Write record zero and format track, use cdl. */
1483 cplength = 3 + rpt;
1484 datasize = sizeof(struct DE_eckd_data) +
1485 sizeof(struct LO_eckd_data) +
1486 sizeof(struct eckd_count) +
1487 rpt * sizeof(struct eckd_count);
1488 break;
1489 case 0x04: /* Invalidate track. */
1490 case 0x0c: /* Invalidate track, use cdl. */
1491 cplength = 3;
1492 datasize = sizeof(struct DE_eckd_data) +
1493 sizeof(struct LO_eckd_data) +
1494 sizeof(struct eckd_count);
1495 break;
1496 default:
1497 dev_warn(&device->cdev->dev, "An I/O control call used "
1498 "incorrect flags 0x%x\n", fdata->intensity);
1499 return ERR_PTR(-EINVAL);
1501 /* Allocate the format ccw request. */
1502 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1503 if (IS_ERR(fcp))
1504 return fcp;
1506 data = fcp->data;
1507 ccw = fcp->cpaddr;
1509 switch (intensity & ~0x08) {
1510 case 0x00: /* Normal format. */
1511 define_extent(ccw++, (struct DE_eckd_data *) data,
1512 fdata->start_unit, fdata->start_unit,
1513 DASD_ECKD_CCW_WRITE_CKD, device);
1514 /* grant subsystem permission to format R0 */
1515 if (r0_perm)
1516 ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
1517 data += sizeof(struct DE_eckd_data);
1518 ccw[-1].flags |= CCW_FLAG_CC;
1519 locate_record(ccw++, (struct LO_eckd_data *) data,
1520 fdata->start_unit, 0, rpt,
1521 DASD_ECKD_CCW_WRITE_CKD, device,
1522 fdata->blksize);
1523 data += sizeof(struct LO_eckd_data);
1524 break;
1525 case 0x01: /* Write record zero + format track. */
1526 define_extent(ccw++, (struct DE_eckd_data *) data,
1527 fdata->start_unit, fdata->start_unit,
1528 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1529 device);
1530 data += sizeof(struct DE_eckd_data);
1531 ccw[-1].flags |= CCW_FLAG_CC;
1532 locate_record(ccw++, (struct LO_eckd_data *) data,
1533 fdata->start_unit, 0, rpt + 1,
1534 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1535 device->block->bp_block);
1536 data += sizeof(struct LO_eckd_data);
1537 break;
1538 case 0x04: /* Invalidate track. */
1539 define_extent(ccw++, (struct DE_eckd_data *) data,
1540 fdata->start_unit, fdata->start_unit,
1541 DASD_ECKD_CCW_WRITE_CKD, device);
1542 data += sizeof(struct DE_eckd_data);
1543 ccw[-1].flags |= CCW_FLAG_CC;
1544 locate_record(ccw++, (struct LO_eckd_data *) data,
1545 fdata->start_unit, 0, 1,
1546 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1547 data += sizeof(struct LO_eckd_data);
1548 break;
1550 if (intensity & 0x01) { /* write record zero */
1551 ect = (struct eckd_count *) data;
1552 data += sizeof(struct eckd_count);
1553 ect->cyl = address.cyl;
1554 ect->head = address.head;
1555 ect->record = 0;
1556 ect->kl = 0;
1557 ect->dl = 8;
1558 ccw[-1].flags |= CCW_FLAG_CC;
1559 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1560 ccw->flags = CCW_FLAG_SLI;
1561 ccw->count = 8;
1562 ccw->cda = (__u32)(addr_t) ect;
1563 ccw++;
1565 if ((intensity & ~0x08) & 0x04) { /* erase track */
1566 ect = (struct eckd_count *) data;
1567 data += sizeof(struct eckd_count);
1568 ect->cyl = address.cyl;
1569 ect->head = address.head;
1570 ect->record = 1;
1571 ect->kl = 0;
1572 ect->dl = 0;
1573 ccw[-1].flags |= CCW_FLAG_CC;
1574 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1575 ccw->flags = CCW_FLAG_SLI;
1576 ccw->count = 8;
1577 ccw->cda = (__u32)(addr_t) ect;
1578 } else { /* write remaining records */
1579 for (i = 0; i < rpt; i++) {
1580 ect = (struct eckd_count *) data;
1581 data += sizeof(struct eckd_count);
1582 ect->cyl = address.cyl;
1583 ect->head = address.head;
1584 ect->record = i + 1;
1585 ect->kl = 0;
1586 ect->dl = fdata->blksize;
1587 /* Check for special tracks 0-1 when formatting CDL */
1588 if ((intensity & 0x08) &&
1589 fdata->start_unit == 0) {
1590 if (i < 3) {
1591 ect->kl = 4;
1592 ect->dl = sizes_trk0[i] - 4;
1595 if ((intensity & 0x08) &&
1596 fdata->start_unit == 1) {
1597 ect->kl = 44;
1598 ect->dl = LABEL_SIZE - 44;
1600 ccw[-1].flags |= CCW_FLAG_CC;
1601 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1602 ccw->flags = CCW_FLAG_SLI;
1603 ccw->count = 8;
1604 ccw->cda = (__u32)(addr_t) ect;
1605 ccw++;
1608 fcp->startdev = device;
1609 fcp->memdev = device;
1610 clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags);
1611 fcp->retries = 5; /* set retry counter to enable default ERP */
1612 fcp->buildclk = get_clock();
1613 fcp->status = DASD_CQR_FILLED;
1614 return fcp;
1617 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
1619 cqr->status = DASD_CQR_FILLED;
1620 if (cqr->block && (cqr->startdev != cqr->block->base)) {
1621 dasd_eckd_reset_ccw_to_base_io(cqr);
1622 cqr->startdev = cqr->block->base;
1626 static dasd_erp_fn_t
1627 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1629 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
1630 struct ccw_device *cdev = device->cdev;
1632 switch (cdev->id.cu_type) {
1633 case 0x3990:
1634 case 0x2105:
1635 case 0x2107:
1636 case 0x1750:
1637 return dasd_3990_erp_action;
1638 case 0x9343:
1639 case 0x3880:
1640 default:
1641 return dasd_default_erp_action;
1645 static dasd_erp_fn_t
1646 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1648 return dasd_default_erp_postaction;
1652 static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1653 struct irb *irb)
1655 char mask;
1656 char *sense = NULL;
1658 /* first of all check for state change pending interrupt */
1659 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
1660 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
1661 dasd_generic_handle_state_change(device);
1662 return;
1665 /* summary unit check */
1666 if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
1667 (irb->ecw[7] == 0x0D)) {
1668 dasd_alias_handle_summary_unit_check(device, irb);
1669 return;
1672 sense = dasd_get_sense(irb);
1673 /* service information message SIM */
1674 if (sense && !(sense[27] & DASD_SENSE_BIT_0) &&
1675 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
1676 dasd_3990_erp_handle_sim(device, sense);
1677 dasd_schedule_device_bh(device);
1678 return;
1681 if ((scsw_cc(&irb->scsw) == 1) &&
1682 (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
1683 (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) &&
1684 (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) {
1685 /* fake irb do nothing, they are handled elsewhere */
1686 dasd_schedule_device_bh(device);
1687 return;
1690 if (!sense) {
1691 /* just report other unsolicited interrupts */
1692 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1693 "unsolicited interrupt received");
1694 } else {
1695 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1696 "unsolicited interrupt received "
1697 "(sense available)");
1698 device->discipline->dump_sense_dbf(device, irb, "unsolicited");
1701 dasd_schedule_device_bh(device);
1702 return;
1706 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
1707 struct dasd_device *startdev,
1708 struct dasd_block *block,
1709 struct request *req,
1710 sector_t first_rec,
1711 sector_t last_rec,
1712 sector_t first_trk,
1713 sector_t last_trk,
1714 unsigned int first_offs,
1715 unsigned int last_offs,
1716 unsigned int blk_per_trk,
1717 unsigned int blksize)
1719 struct dasd_eckd_private *private;
1720 unsigned long *idaws;
1721 struct LO_eckd_data *LO_data;
1722 struct dasd_ccw_req *cqr;
1723 struct ccw1 *ccw;
1724 struct req_iterator iter;
1725 struct bio_vec *bv;
1726 char *dst;
1727 unsigned int off;
1728 int count, cidaw, cplength, datasize;
1729 sector_t recid;
1730 unsigned char cmd, rcmd;
1731 int use_prefix;
1732 struct dasd_device *basedev;
1734 basedev = block->base;
1735 private = (struct dasd_eckd_private *) basedev->private;
1736 if (rq_data_dir(req) == READ)
1737 cmd = DASD_ECKD_CCW_READ_MT;
1738 else if (rq_data_dir(req) == WRITE)
1739 cmd = DASD_ECKD_CCW_WRITE_MT;
1740 else
1741 return ERR_PTR(-EINVAL);
1743 /* Check struct bio and count the number of blocks for the request. */
1744 count = 0;
1745 cidaw = 0;
1746 rq_for_each_segment(bv, req, iter) {
1747 if (bv->bv_len & (blksize - 1))
1748 /* Eckd can only do full blocks. */
1749 return ERR_PTR(-EINVAL);
1750 count += bv->bv_len >> (block->s2b_shift + 9);
1751 #if defined(CONFIG_64BIT)
1752 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
1753 cidaw += bv->bv_len >> (block->s2b_shift + 9);
1754 #endif
1756 /* Paranoia. */
1757 if (count != last_rec - first_rec + 1)
1758 return ERR_PTR(-EINVAL);
1760 /* use the prefix command if available */
1761 use_prefix = private->features.feature[8] & 0x01;
1762 if (use_prefix) {
1763 /* 1x prefix + number of blocks */
1764 cplength = 2 + count;
1765 /* 1x prefix + cidaws*sizeof(long) */
1766 datasize = sizeof(struct PFX_eckd_data) +
1767 sizeof(struct LO_eckd_data) +
1768 cidaw * sizeof(unsigned long);
1769 } else {
1770 /* 1x define extent + 1x locate record + number of blocks */
1771 cplength = 2 + count;
1772 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1773 datasize = sizeof(struct DE_eckd_data) +
1774 sizeof(struct LO_eckd_data) +
1775 cidaw * sizeof(unsigned long);
1777 /* Find out the number of additional locate record ccws for cdl. */
1778 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1779 if (last_rec >= 2*blk_per_trk)
1780 count = 2*blk_per_trk - first_rec;
1781 cplength += count;
1782 datasize += count*sizeof(struct LO_eckd_data);
1784 /* Allocate the ccw request. */
1785 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
1786 startdev);
1787 if (IS_ERR(cqr))
1788 return cqr;
1789 ccw = cqr->cpaddr;
1790 /* First ccw is define extent or prefix. */
1791 if (use_prefix) {
1792 if (prefix(ccw++, cqr->data, first_trk,
1793 last_trk, cmd, basedev, startdev) == -EAGAIN) {
1794 /* Clock not in sync and XRC is enabled.
1795 * Try again later.
1797 dasd_sfree_request(cqr, startdev);
1798 return ERR_PTR(-EAGAIN);
1800 idaws = (unsigned long *) (cqr->data +
1801 sizeof(struct PFX_eckd_data));
1802 } else {
1803 if (define_extent(ccw++, cqr->data, first_trk,
1804 last_trk, cmd, startdev) == -EAGAIN) {
1805 /* Clock not in sync and XRC is enabled.
1806 * Try again later.
1808 dasd_sfree_request(cqr, startdev);
1809 return ERR_PTR(-EAGAIN);
1811 idaws = (unsigned long *) (cqr->data +
1812 sizeof(struct DE_eckd_data));
1814 /* Build locate_record+read/write/ccws. */
1815 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1816 recid = first_rec;
1817 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1818 /* Only standard blocks so there is just one locate record. */
1819 ccw[-1].flags |= CCW_FLAG_CC;
1820 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1821 last_rec - recid + 1, cmd, basedev, blksize);
1823 rq_for_each_segment(bv, req, iter) {
1824 dst = page_address(bv->bv_page) + bv->bv_offset;
1825 if (dasd_page_cache) {
1826 char *copy = kmem_cache_alloc(dasd_page_cache,
1827 GFP_DMA | __GFP_NOWARN);
1828 if (copy && rq_data_dir(req) == WRITE)
1829 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1830 if (copy)
1831 dst = copy + bv->bv_offset;
1833 for (off = 0; off < bv->bv_len; off += blksize) {
1834 sector_t trkid = recid;
1835 unsigned int recoffs = sector_div(trkid, blk_per_trk);
1836 rcmd = cmd;
1837 count = blksize;
1838 /* Locate record for cdl special block ? */
1839 if (private->uses_cdl && recid < 2*blk_per_trk) {
1840 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1841 rcmd |= 0x8;
1842 count = dasd_eckd_cdl_reclen(recid);
1843 if (count < blksize &&
1844 rq_data_dir(req) == READ)
1845 memset(dst + count, 0xe5,
1846 blksize - count);
1848 ccw[-1].flags |= CCW_FLAG_CC;
1849 locate_record(ccw++, LO_data++,
1850 trkid, recoffs + 1,
1851 1, rcmd, basedev, count);
1853 /* Locate record for standard blocks ? */
1854 if (private->uses_cdl && recid == 2*blk_per_trk) {
1855 ccw[-1].flags |= CCW_FLAG_CC;
1856 locate_record(ccw++, LO_data++,
1857 trkid, recoffs + 1,
1858 last_rec - recid + 1,
1859 cmd, basedev, count);
1861 /* Read/write ccw. */
1862 ccw[-1].flags |= CCW_FLAG_CC;
1863 ccw->cmd_code = rcmd;
1864 ccw->count = count;
1865 if (idal_is_needed(dst, blksize)) {
1866 ccw->cda = (__u32)(addr_t) idaws;
1867 ccw->flags = CCW_FLAG_IDA;
1868 idaws = idal_create_words(idaws, dst, blksize);
1869 } else {
1870 ccw->cda = (__u32)(addr_t) dst;
1871 ccw->flags = 0;
1873 ccw++;
1874 dst += blksize;
1875 recid++;
1878 if (blk_noretry_request(req) ||
1879 block->base->features & DASD_FEATURE_FAILFAST)
1880 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1881 cqr->startdev = startdev;
1882 cqr->memdev = startdev;
1883 cqr->block = block;
1884 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
1885 cqr->lpm = private->path_data.ppm;
1886 cqr->retries = 256;
1887 cqr->buildclk = get_clock();
1888 cqr->status = DASD_CQR_FILLED;
1889 return cqr;
1892 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
1893 struct dasd_device *startdev,
1894 struct dasd_block *block,
1895 struct request *req,
1896 sector_t first_rec,
1897 sector_t last_rec,
1898 sector_t first_trk,
1899 sector_t last_trk,
1900 unsigned int first_offs,
1901 unsigned int last_offs,
1902 unsigned int blk_per_trk,
1903 unsigned int blksize)
1905 struct dasd_eckd_private *private;
1906 unsigned long *idaws;
1907 struct dasd_ccw_req *cqr;
1908 struct ccw1 *ccw;
1909 struct req_iterator iter;
1910 struct bio_vec *bv;
1911 char *dst, *idaw_dst;
1912 unsigned int cidaw, cplength, datasize;
1913 unsigned int tlf;
1914 sector_t recid;
1915 unsigned char cmd;
1916 struct dasd_device *basedev;
1917 unsigned int trkcount, count, count_to_trk_end;
1918 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
1919 unsigned char new_track, end_idaw;
1920 sector_t trkid;
1921 unsigned int recoffs;
1923 basedev = block->base;
1924 private = (struct dasd_eckd_private *) basedev->private;
1925 if (rq_data_dir(req) == READ)
1926 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
1927 else if (rq_data_dir(req) == WRITE)
1928 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
1929 else
1930 return ERR_PTR(-EINVAL);
1932 /* Track based I/O needs IDAWs for each page, and not just for
1933 * 64 bit addresses. We need additional idals for pages
1934 * that get filled from two tracks, so we use the number
1935 * of records as upper limit.
1937 cidaw = last_rec - first_rec + 1;
1938 trkcount = last_trk - first_trk + 1;
1940 /* 1x prefix + one read/write ccw per track */
1941 cplength = 1 + trkcount;
1943 /* on 31-bit we need space for two 32 bit addresses per page
1944 * on 64-bit one 64 bit address
1946 datasize = sizeof(struct PFX_eckd_data) +
1947 cidaw * sizeof(unsigned long long);
1949 /* Allocate the ccw request. */
1950 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
1951 startdev);
1952 if (IS_ERR(cqr))
1953 return cqr;
1954 ccw = cqr->cpaddr;
1955 /* transfer length factor: how many bytes to read from the last track */
1956 if (first_trk == last_trk)
1957 tlf = last_offs - first_offs + 1;
1958 else
1959 tlf = last_offs + 1;
1960 tlf *= blksize;
1962 if (prefix_LRE(ccw++, cqr->data, first_trk,
1963 last_trk, cmd, basedev, startdev,
1964 1 /* format */, first_offs + 1,
1965 trkcount, blksize,
1966 tlf) == -EAGAIN) {
1967 /* Clock not in sync and XRC is enabled.
1968 * Try again later.
1970 dasd_sfree_request(cqr, startdev);
1971 return ERR_PTR(-EAGAIN);
1975 * The translation of request into ccw programs must meet the
1976 * following conditions:
1977 * - all idaws but the first and the last must address full pages
1978 * (or 2K blocks on 31-bit)
1979 * - the scope of a ccw and it's idal ends with the track boundaries
1981 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
1982 recid = first_rec;
1983 new_track = 1;
1984 end_idaw = 0;
1985 len_to_track_end = 0;
1986 idaw_dst = 0;
1987 idaw_len = 0;
1988 rq_for_each_segment(bv, req, iter) {
1989 dst = page_address(bv->bv_page) + bv->bv_offset;
1990 seg_len = bv->bv_len;
1991 while (seg_len) {
1992 if (new_track) {
1993 trkid = recid;
1994 recoffs = sector_div(trkid, blk_per_trk);
1995 count_to_trk_end = blk_per_trk - recoffs;
1996 count = min((last_rec - recid + 1),
1997 (sector_t)count_to_trk_end);
1998 len_to_track_end = count * blksize;
1999 ccw[-1].flags |= CCW_FLAG_CC;
2000 ccw->cmd_code = cmd;
2001 ccw->count = len_to_track_end;
2002 ccw->cda = (__u32)(addr_t)idaws;
2003 ccw->flags = CCW_FLAG_IDA;
2004 ccw++;
2005 recid += count;
2006 new_track = 0;
2007 /* first idaw for a ccw may start anywhere */
2008 if (!idaw_dst)
2009 idaw_dst = dst;
2011 /* If we start a new idaw, we must make sure that it
2012 * starts on an IDA_BLOCK_SIZE boundary.
2013 * If we continue an idaw, we must make sure that the
2014 * current segment begins where the so far accumulated
2015 * idaw ends
2017 if (!idaw_dst) {
2018 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2019 dasd_sfree_request(cqr, startdev);
2020 return ERR_PTR(-ERANGE);
2021 } else
2022 idaw_dst = dst;
2024 if ((idaw_dst + idaw_len) != dst) {
2025 dasd_sfree_request(cqr, startdev);
2026 return ERR_PTR(-ERANGE);
2028 part_len = min(seg_len, len_to_track_end);
2029 seg_len -= part_len;
2030 dst += part_len;
2031 idaw_len += part_len;
2032 len_to_track_end -= part_len;
2033 /* collected memory area ends on an IDA_BLOCK border,
2034 * -> create an idaw
2035 * idal_create_words will handle cases where idaw_len
2036 * is larger then IDA_BLOCK_SIZE
2038 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2039 end_idaw = 1;
2040 /* We also need to end the idaw at track end */
2041 if (!len_to_track_end) {
2042 new_track = 1;
2043 end_idaw = 1;
2045 if (end_idaw) {
2046 idaws = idal_create_words(idaws, idaw_dst,
2047 idaw_len);
2048 idaw_dst = 0;
2049 idaw_len = 0;
2050 end_idaw = 0;
2055 if (blk_noretry_request(req) ||
2056 block->base->features & DASD_FEATURE_FAILFAST)
2057 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2058 cqr->startdev = startdev;
2059 cqr->memdev = startdev;
2060 cqr->block = block;
2061 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2062 cqr->lpm = private->path_data.ppm;
2063 cqr->retries = 256;
2064 cqr->buildclk = get_clock();
2065 cqr->status = DASD_CQR_FILLED;
2066 return cqr;
2069 static int prepare_itcw(struct itcw *itcw,
2070 unsigned int trk, unsigned int totrk, int cmd,
2071 struct dasd_device *basedev,
2072 struct dasd_device *startdev,
2073 unsigned int rec_on_trk, int count,
2074 unsigned int blksize,
2075 unsigned int total_data_size,
2076 unsigned int tlf,
2077 unsigned int blk_per_trk)
2079 struct PFX_eckd_data pfxdata;
2080 struct dasd_eckd_private *basepriv, *startpriv;
2081 struct DE_eckd_data *dedata;
2082 struct LRE_eckd_data *lredata;
2083 struct dcw *dcw;
2085 u32 begcyl, endcyl;
2086 u16 heads, beghead, endhead;
2087 u8 pfx_cmd;
2089 int rc = 0;
2090 int sector = 0;
2091 int dn, d;
2094 /* setup prefix data */
2095 basepriv = (struct dasd_eckd_private *) basedev->private;
2096 startpriv = (struct dasd_eckd_private *) startdev->private;
2097 dedata = &pfxdata.define_extent;
2098 lredata = &pfxdata.locate_record;
2100 memset(&pfxdata, 0, sizeof(pfxdata));
2101 pfxdata.format = 1; /* PFX with LRE */
2102 pfxdata.base_address = basepriv->ned->unit_addr;
2103 pfxdata.base_lss = basepriv->ned->ID;
2104 pfxdata.validity.define_extent = 1;
2106 /* private uid is kept up to date, conf_data may be outdated */
2107 if (startpriv->uid.type != UA_BASE_DEVICE) {
2108 pfxdata.validity.verify_base = 1;
2109 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2110 pfxdata.validity.hyper_pav = 1;
2113 switch (cmd) {
2114 case DASD_ECKD_CCW_READ_TRACK_DATA:
2115 dedata->mask.perm = 0x1;
2116 dedata->attributes.operation = basepriv->attrib.operation;
2117 dedata->blk_size = blksize;
2118 dedata->ga_extended |= 0x42;
2119 lredata->operation.orientation = 0x0;
2120 lredata->operation.operation = 0x0C;
2121 lredata->auxiliary.check_bytes = 0x01;
2122 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2123 break;
2124 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2125 dedata->mask.perm = 0x02;
2126 dedata->attributes.operation = basepriv->attrib.operation;
2127 dedata->blk_size = blksize;
2128 rc = check_XRC_on_prefix(&pfxdata, basedev);
2129 dedata->ga_extended |= 0x42;
2130 lredata->operation.orientation = 0x0;
2131 lredata->operation.operation = 0x3F;
2132 lredata->extended_operation = 0x23;
2133 lredata->auxiliary.check_bytes = 0x2;
2134 pfx_cmd = DASD_ECKD_CCW_PFX;
2135 break;
2136 default:
2137 DBF_DEV_EVENT(DBF_ERR, basedev,
2138 "prepare itcw, unknown opcode 0x%x", cmd);
2139 BUG();
2140 break;
2142 if (rc)
2143 return rc;
2145 dedata->attributes.mode = 0x3; /* ECKD */
2147 heads = basepriv->rdc_data.trk_per_cyl;
2148 begcyl = trk / heads;
2149 beghead = trk % heads;
2150 endcyl = totrk / heads;
2151 endhead = totrk % heads;
2153 /* check for sequential prestage - enhance cylinder range */
2154 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2155 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2157 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2158 endcyl += basepriv->attrib.nr_cyl;
2159 else
2160 endcyl = (basepriv->real_cyl - 1);
2163 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2164 set_ch_t(&dedata->end_ext, endcyl, endhead);
2166 dedata->ep_format = 0x20; /* records per track is valid */
2167 dedata->ep_rec_per_track = blk_per_trk;
2169 if (rec_on_trk) {
2170 switch (basepriv->rdc_data.dev_type) {
2171 case 0x3390:
2172 dn = ceil_quot(blksize + 6, 232);
2173 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2174 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2175 break;
2176 case 0x3380:
2177 d = 7 + ceil_quot(blksize + 12, 32);
2178 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2179 break;
2183 lredata->auxiliary.length_valid = 1;
2184 lredata->auxiliary.length_scope = 1;
2185 lredata->auxiliary.imbedded_ccw_valid = 1;
2186 lredata->length = tlf;
2187 lredata->imbedded_ccw = cmd;
2188 lredata->count = count;
2189 lredata->sector = sector;
2190 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2191 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2192 lredata->search_arg.head = lredata->seek_addr.head;
2193 lredata->search_arg.record = rec_on_trk;
2195 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2196 &pfxdata, sizeof(pfxdata), total_data_size);
2198 return rc;
2201 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2202 struct dasd_device *startdev,
2203 struct dasd_block *block,
2204 struct request *req,
2205 sector_t first_rec,
2206 sector_t last_rec,
2207 sector_t first_trk,
2208 sector_t last_trk,
2209 unsigned int first_offs,
2210 unsigned int last_offs,
2211 unsigned int blk_per_trk,
2212 unsigned int blksize)
2214 struct dasd_eckd_private *private;
2215 struct dasd_ccw_req *cqr;
2216 struct req_iterator iter;
2217 struct bio_vec *bv;
2218 char *dst;
2219 unsigned int trkcount, ctidaw;
2220 unsigned char cmd;
2221 struct dasd_device *basedev;
2222 unsigned int tlf;
2223 struct itcw *itcw;
2224 struct tidaw *last_tidaw = NULL;
2225 int itcw_op;
2226 size_t itcw_size;
2228 basedev = block->base;
2229 private = (struct dasd_eckd_private *) basedev->private;
2230 if (rq_data_dir(req) == READ) {
2231 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2232 itcw_op = ITCW_OP_READ;
2233 } else if (rq_data_dir(req) == WRITE) {
2234 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2235 itcw_op = ITCW_OP_WRITE;
2236 } else
2237 return ERR_PTR(-EINVAL);
2239 /* trackbased I/O needs address all memory via TIDAWs,
2240 * not just for 64 bit addresses. This allows us to map
2241 * each segment directly to one tidaw.
2243 trkcount = last_trk - first_trk + 1;
2244 ctidaw = 0;
2245 rq_for_each_segment(bv, req, iter) {
2246 ++ctidaw;
2249 /* Allocate the ccw request. */
2250 itcw_size = itcw_calc_size(0, ctidaw, 0);
2251 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2252 if (IS_ERR(cqr))
2253 return cqr;
2255 cqr->cpmode = 1;
2256 cqr->startdev = startdev;
2257 cqr->memdev = startdev;
2258 cqr->block = block;
2259 cqr->expires = 100*HZ;
2260 cqr->buildclk = get_clock();
2261 cqr->status = DASD_CQR_FILLED;
2262 cqr->retries = 10;
2264 /* transfer length factor: how many bytes to read from the last track */
2265 if (first_trk == last_trk)
2266 tlf = last_offs - first_offs + 1;
2267 else
2268 tlf = last_offs + 1;
2269 tlf *= blksize;
2271 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2272 cqr->cpaddr = itcw_get_tcw(itcw);
2274 if (prepare_itcw(itcw, first_trk, last_trk,
2275 cmd, basedev, startdev,
2276 first_offs + 1,
2277 trkcount, blksize,
2278 (last_rec - first_rec + 1) * blksize,
2279 tlf, blk_per_trk) == -EAGAIN) {
2280 /* Clock not in sync and XRC is enabled.
2281 * Try again later.
2283 dasd_sfree_request(cqr, startdev);
2284 return ERR_PTR(-EAGAIN);
2288 * A tidaw can address 4k of memory, but must not cross page boundaries
2289 * We can let the block layer handle this by setting
2290 * blk_queue_segment_boundary to page boundaries and
2291 * blk_max_segment_size to page size when setting up the request queue.
2293 rq_for_each_segment(bv, req, iter) {
2294 dst = page_address(bv->bv_page) + bv->bv_offset;
2295 last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len);
2296 if (IS_ERR(last_tidaw))
2297 return (struct dasd_ccw_req *)last_tidaw;
2300 last_tidaw->flags |= 0x80;
2301 itcw_finalize(itcw);
2303 if (blk_noretry_request(req) ||
2304 block->base->features & DASD_FEATURE_FAILFAST)
2305 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2306 cqr->startdev = startdev;
2307 cqr->memdev = startdev;
2308 cqr->block = block;
2309 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2310 cqr->lpm = private->path_data.ppm;
2311 cqr->retries = 256;
2312 cqr->buildclk = get_clock();
2313 cqr->status = DASD_CQR_FILLED;
2314 return cqr;
2317 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2318 struct dasd_block *block,
2319 struct request *req)
2321 int tpm, cmdrtd, cmdwtd;
2322 int use_prefix;
2323 #if defined(CONFIG_64BIT)
2324 int fcx_in_css, fcx_in_gneq, fcx_in_features;
2325 #endif
2326 struct dasd_eckd_private *private;
2327 struct dasd_device *basedev;
2328 sector_t first_rec, last_rec;
2329 sector_t first_trk, last_trk;
2330 unsigned int first_offs, last_offs;
2331 unsigned int blk_per_trk, blksize;
2332 int cdlspecial;
2333 struct dasd_ccw_req *cqr;
2335 basedev = block->base;
2336 private = (struct dasd_eckd_private *) basedev->private;
2338 /* Calculate number of blocks/records per track. */
2339 blksize = block->bp_block;
2340 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2341 if (blk_per_trk == 0)
2342 return ERR_PTR(-EINVAL);
2343 /* Calculate record id of first and last block. */
2344 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
2345 first_offs = sector_div(first_trk, blk_per_trk);
2346 last_rec = last_trk =
2347 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
2348 last_offs = sector_div(last_trk, blk_per_trk);
2349 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2351 /* is transport mode supported? */
2352 #if defined(CONFIG_64BIT)
2353 fcx_in_css = css_general_characteristics.fcx;
2354 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
2355 fcx_in_features = private->features.feature[40] & 0x80;
2356 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
2357 #else
2358 tpm = 0;
2359 #endif
2361 /* is read track data and write track data in command mode supported? */
2362 cmdrtd = private->features.feature[9] & 0x20;
2363 cmdwtd = private->features.feature[12] & 0x40;
2364 use_prefix = private->features.feature[8] & 0x01;
2366 cqr = NULL;
2367 if (cdlspecial || dasd_page_cache) {
2368 /* do nothing, just fall through to the cmd mode single case */
2369 } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) {
2370 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2371 first_rec, last_rec,
2372 first_trk, last_trk,
2373 first_offs, last_offs,
2374 blk_per_trk, blksize);
2375 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2376 cqr = NULL;
2377 } else if (use_prefix &&
2378 (((rq_data_dir(req) == READ) && cmdrtd) ||
2379 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
2380 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2381 first_rec, last_rec,
2382 first_trk, last_trk,
2383 first_offs, last_offs,
2384 blk_per_trk, blksize);
2385 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2386 cqr = NULL;
2388 if (!cqr)
2389 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2390 first_rec, last_rec,
2391 first_trk, last_trk,
2392 first_offs, last_offs,
2393 blk_per_trk, blksize);
2394 return cqr;
2397 static int
2398 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2400 struct dasd_eckd_private *private;
2401 struct ccw1 *ccw;
2402 struct req_iterator iter;
2403 struct bio_vec *bv;
2404 char *dst, *cda;
2405 unsigned int blksize, blk_per_trk, off;
2406 sector_t recid;
2407 int status;
2409 if (!dasd_page_cache)
2410 goto out;
2411 private = (struct dasd_eckd_private *) cqr->block->base->private;
2412 blksize = cqr->block->bp_block;
2413 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2414 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
2415 ccw = cqr->cpaddr;
2416 /* Skip over define extent & locate record. */
2417 ccw++;
2418 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2419 ccw++;
2420 rq_for_each_segment(bv, req, iter) {
2421 dst = page_address(bv->bv_page) + bv->bv_offset;
2422 for (off = 0; off < bv->bv_len; off += blksize) {
2423 /* Skip locate record. */
2424 if (private->uses_cdl && recid <= 2*blk_per_trk)
2425 ccw++;
2426 if (dst) {
2427 if (ccw->flags & CCW_FLAG_IDA)
2428 cda = *((char **)((addr_t) ccw->cda));
2429 else
2430 cda = (char *)((addr_t) ccw->cda);
2431 if (dst != cda) {
2432 if (rq_data_dir(req) == READ)
2433 memcpy(dst, cda, bv->bv_len);
2434 kmem_cache_free(dasd_page_cache,
2435 (void *)((addr_t)cda & PAGE_MASK));
2437 dst = NULL;
2439 ccw++;
2440 recid++;
2443 out:
2444 status = cqr->status == DASD_CQR_DONE;
2445 dasd_sfree_request(cqr, cqr->memdev);
2446 return status;
2450 * Modify ccw/tcw in cqr so it can be started on a base device.
2452 * Note that this is not enough to restart the cqr!
2453 * Either reset cqr->startdev as well (summary unit check handling)
2454 * or restart via separate cqr (as in ERP handling).
2456 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
2458 struct ccw1 *ccw;
2459 struct PFX_eckd_data *pfxdata;
2460 struct tcw *tcw;
2461 struct tccb *tccb;
2462 struct dcw *dcw;
2464 if (cqr->cpmode == 1) {
2465 tcw = cqr->cpaddr;
2466 tccb = tcw_get_tccb(tcw);
2467 dcw = (struct dcw *)&tccb->tca[0];
2468 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
2469 pfxdata->validity.verify_base = 0;
2470 pfxdata->validity.hyper_pav = 0;
2471 } else {
2472 ccw = cqr->cpaddr;
2473 pfxdata = cqr->data;
2474 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
2475 pfxdata->validity.verify_base = 0;
2476 pfxdata->validity.hyper_pav = 0;
2481 #define DASD_ECKD_CHANQ_MAX_SIZE 4
2483 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
2484 struct dasd_block *block,
2485 struct request *req)
2487 struct dasd_eckd_private *private;
2488 struct dasd_device *startdev;
2489 unsigned long flags;
2490 struct dasd_ccw_req *cqr;
2492 startdev = dasd_alias_get_start_dev(base);
2493 if (!startdev)
2494 startdev = base;
2495 private = (struct dasd_eckd_private *) startdev->private;
2496 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
2497 return ERR_PTR(-EBUSY);
2499 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
2500 private->count++;
2501 cqr = dasd_eckd_build_cp(startdev, block, req);
2502 if (IS_ERR(cqr))
2503 private->count--;
2504 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
2505 return cqr;
2508 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
2509 struct request *req)
2511 struct dasd_eckd_private *private;
2512 unsigned long flags;
2514 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
2515 private = (struct dasd_eckd_private *) cqr->memdev->private;
2516 private->count--;
2517 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
2518 return dasd_eckd_free_cp(cqr, req);
2521 static int
2522 dasd_eckd_fill_info(struct dasd_device * device,
2523 struct dasd_information2_t * info)
2525 struct dasd_eckd_private *private;
2527 private = (struct dasd_eckd_private *) device->private;
2528 info->label_block = 2;
2529 info->FBA_layout = private->uses_cdl ? 0 : 1;
2530 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
2531 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
2532 memcpy(info->characteristics, &private->rdc_data,
2533 sizeof(struct dasd_eckd_characteristics));
2534 info->confdata_size = min((unsigned long)private->conf_len,
2535 sizeof(info->configuration_data));
2536 memcpy(info->configuration_data, private->conf_data,
2537 info->confdata_size);
2538 return 0;
2542 * SECTION: ioctl functions for eckd devices.
2546 * Release device ioctl.
2547 * Buils a channel programm to releases a prior reserved
2548 * (see dasd_eckd_reserve) device.
2550 static int
2551 dasd_eckd_release(struct dasd_device *device)
2553 struct dasd_ccw_req *cqr;
2554 int rc;
2555 struct ccw1 *ccw;
2557 if (!capable(CAP_SYS_ADMIN))
2558 return -EACCES;
2560 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2561 if (IS_ERR(cqr)) {
2562 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2563 "Could not allocate initialization request");
2564 return PTR_ERR(cqr);
2566 ccw = cqr->cpaddr;
2567 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
2568 ccw->flags |= CCW_FLAG_SLI;
2569 ccw->count = 32;
2570 ccw->cda = (__u32)(addr_t) cqr->data;
2571 cqr->startdev = device;
2572 cqr->memdev = device;
2573 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2574 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2575 cqr->retries = 2; /* set retry counter to enable basic ERP */
2576 cqr->expires = 2 * HZ;
2577 cqr->buildclk = get_clock();
2578 cqr->status = DASD_CQR_FILLED;
2580 rc = dasd_sleep_on_immediatly(cqr);
2582 dasd_sfree_request(cqr, cqr->memdev);
2583 return rc;
2587 * Reserve device ioctl.
2588 * Options are set to 'synchronous wait for interrupt' and
2589 * 'timeout the request'. This leads to a terminate IO if
2590 * the interrupt is outstanding for a certain time.
2592 static int
2593 dasd_eckd_reserve(struct dasd_device *device)
2595 struct dasd_ccw_req *cqr;
2596 int rc;
2597 struct ccw1 *ccw;
2599 if (!capable(CAP_SYS_ADMIN))
2600 return -EACCES;
2602 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2603 if (IS_ERR(cqr)) {
2604 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2605 "Could not allocate initialization request");
2606 return PTR_ERR(cqr);
2608 ccw = cqr->cpaddr;
2609 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
2610 ccw->flags |= CCW_FLAG_SLI;
2611 ccw->count = 32;
2612 ccw->cda = (__u32)(addr_t) cqr->data;
2613 cqr->startdev = device;
2614 cqr->memdev = device;
2615 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2616 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2617 cqr->retries = 2; /* set retry counter to enable basic ERP */
2618 cqr->expires = 2 * HZ;
2619 cqr->buildclk = get_clock();
2620 cqr->status = DASD_CQR_FILLED;
2622 rc = dasd_sleep_on_immediatly(cqr);
2624 dasd_sfree_request(cqr, cqr->memdev);
2625 return rc;
2629 * Steal lock ioctl - unconditional reserve device.
2630 * Buils a channel programm to break a device's reservation.
2631 * (unconditional reserve)
2633 static int
2634 dasd_eckd_steal_lock(struct dasd_device *device)
2636 struct dasd_ccw_req *cqr;
2637 int rc;
2638 struct ccw1 *ccw;
2640 if (!capable(CAP_SYS_ADMIN))
2641 return -EACCES;
2643 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2644 if (IS_ERR(cqr)) {
2645 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2646 "Could not allocate initialization request");
2647 return PTR_ERR(cqr);
2649 ccw = cqr->cpaddr;
2650 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
2651 ccw->flags |= CCW_FLAG_SLI;
2652 ccw->count = 32;
2653 ccw->cda = (__u32)(addr_t) cqr->data;
2654 cqr->startdev = device;
2655 cqr->memdev = device;
2656 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2657 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2658 cqr->retries = 2; /* set retry counter to enable basic ERP */
2659 cqr->expires = 2 * HZ;
2660 cqr->buildclk = get_clock();
2661 cqr->status = DASD_CQR_FILLED;
2663 rc = dasd_sleep_on_immediatly(cqr);
2665 dasd_sfree_request(cqr, cqr->memdev);
2666 return rc;
2670 * Read performance statistics
2672 static int
2673 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
2675 struct dasd_psf_prssd_data *prssdp;
2676 struct dasd_rssd_perf_stats_t *stats;
2677 struct dasd_ccw_req *cqr;
2678 struct ccw1 *ccw;
2679 int rc;
2681 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
2682 (sizeof(struct dasd_psf_prssd_data) +
2683 sizeof(struct dasd_rssd_perf_stats_t)),
2684 device);
2685 if (IS_ERR(cqr)) {
2686 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2687 "Could not allocate initialization request");
2688 return PTR_ERR(cqr);
2690 cqr->startdev = device;
2691 cqr->memdev = device;
2692 cqr->retries = 0;
2693 cqr->expires = 10 * HZ;
2695 /* Prepare for Read Subsystem Data */
2696 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2697 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
2698 prssdp->order = PSF_ORDER_PRSSD;
2699 prssdp->suborder = 0x01; /* Performance Statistics */
2700 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
2702 ccw = cqr->cpaddr;
2703 ccw->cmd_code = DASD_ECKD_CCW_PSF;
2704 ccw->count = sizeof(struct dasd_psf_prssd_data);
2705 ccw->flags |= CCW_FLAG_CC;
2706 ccw->cda = (__u32)(addr_t) prssdp;
2708 /* Read Subsystem Data - Performance Statistics */
2709 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2710 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
2712 ccw++;
2713 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2714 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
2715 ccw->cda = (__u32)(addr_t) stats;
2717 cqr->buildclk = get_clock();
2718 cqr->status = DASD_CQR_FILLED;
2719 rc = dasd_sleep_on(cqr);
2720 if (rc == 0) {
2721 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2722 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2723 if (copy_to_user(argp, stats,
2724 sizeof(struct dasd_rssd_perf_stats_t)))
2725 rc = -EFAULT;
2727 dasd_sfree_request(cqr, cqr->memdev);
2728 return rc;
2732 * Get attributes (cache operations)
2733 * Returnes the cache attributes used in Define Extend (DE).
2735 static int
2736 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
2738 struct dasd_eckd_private *private =
2739 (struct dasd_eckd_private *)device->private;
2740 struct attrib_data_t attrib = private->attrib;
2741 int rc;
2743 if (!capable(CAP_SYS_ADMIN))
2744 return -EACCES;
2745 if (!argp)
2746 return -EINVAL;
2748 rc = 0;
2749 if (copy_to_user(argp, (long *) &attrib,
2750 sizeof(struct attrib_data_t)))
2751 rc = -EFAULT;
2753 return rc;
2757 * Set attributes (cache operations)
2758 * Stores the attributes for cache operation to be used in Define Extend (DE).
2760 static int
2761 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
2763 struct dasd_eckd_private *private =
2764 (struct dasd_eckd_private *)device->private;
2765 struct attrib_data_t attrib;
2767 if (!capable(CAP_SYS_ADMIN))
2768 return -EACCES;
2769 if (!argp)
2770 return -EINVAL;
2772 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
2773 return -EFAULT;
2774 private->attrib = attrib;
2776 dev_info(&device->cdev->dev,
2777 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
2778 private->attrib.operation, private->attrib.nr_cyl);
2779 return 0;
2783 * Issue syscall I/O to EMC Symmetrix array.
2784 * CCWs are PSF and RSSD
2786 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2788 struct dasd_symmio_parms usrparm;
2789 char *psf_data, *rssd_result;
2790 struct dasd_ccw_req *cqr;
2791 struct ccw1 *ccw;
2792 int rc;
2794 /* Copy parms from caller */
2795 rc = -EFAULT;
2796 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2797 goto out;
2798 #ifndef CONFIG_64BIT
2799 /* Make sure pointers are sane even on 31 bit. */
2800 if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) {
2801 rc = -EINVAL;
2802 goto out;
2804 #endif
2805 /* alloc I/O data area */
2806 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2807 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2808 if (!psf_data || !rssd_result) {
2809 rc = -ENOMEM;
2810 goto out_free;
2813 /* get syscall header from user space */
2814 rc = -EFAULT;
2815 if (copy_from_user(psf_data,
2816 (void __user *)(unsigned long) usrparm.psf_data,
2817 usrparm.psf_data_len))
2818 goto out_free;
2820 /* sanity check on syscall header */
2821 if (psf_data[0] != 0x17 && psf_data[1] != 0xce) {
2822 rc = -EINVAL;
2823 goto out_free;
2826 /* setup CCWs for PSF + RSSD */
2827 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
2828 if (IS_ERR(cqr)) {
2829 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2830 "Could not allocate initialization request");
2831 rc = PTR_ERR(cqr);
2832 goto out_free;
2835 cqr->startdev = device;
2836 cqr->memdev = device;
2837 cqr->retries = 3;
2838 cqr->expires = 10 * HZ;
2839 cqr->buildclk = get_clock();
2840 cqr->status = DASD_CQR_FILLED;
2842 /* Build the ccws */
2843 ccw = cqr->cpaddr;
2845 /* PSF ccw */
2846 ccw->cmd_code = DASD_ECKD_CCW_PSF;
2847 ccw->count = usrparm.psf_data_len;
2848 ccw->flags |= CCW_FLAG_CC;
2849 ccw->cda = (__u32)(addr_t) psf_data;
2851 ccw++;
2853 /* RSSD ccw */
2854 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2855 ccw->count = usrparm.rssd_result_len;
2856 ccw->flags = CCW_FLAG_SLI ;
2857 ccw->cda = (__u32)(addr_t) rssd_result;
2859 rc = dasd_sleep_on(cqr);
2860 if (rc)
2861 goto out_sfree;
2863 rc = -EFAULT;
2864 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
2865 rssd_result, usrparm.rssd_result_len))
2866 goto out_sfree;
2867 rc = 0;
2869 out_sfree:
2870 dasd_sfree_request(cqr, cqr->memdev);
2871 out_free:
2872 kfree(rssd_result);
2873 kfree(psf_data);
2874 out:
2875 DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc);
2876 return rc;
2879 static int
2880 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
2882 struct dasd_device *device = block->base;
2884 switch (cmd) {
2885 case BIODASDGATTR:
2886 return dasd_eckd_get_attrib(device, argp);
2887 case BIODASDSATTR:
2888 return dasd_eckd_set_attrib(device, argp);
2889 case BIODASDPSRD:
2890 return dasd_eckd_performance(device, argp);
2891 case BIODASDRLSE:
2892 return dasd_eckd_release(device);
2893 case BIODASDRSRV:
2894 return dasd_eckd_reserve(device);
2895 case BIODASDSLCK:
2896 return dasd_eckd_steal_lock(device);
2897 case BIODASDSYMMIO:
2898 return dasd_symm_io(device, argp);
2899 default:
2900 return -ENOIOCTLCMD;
2905 * Dump the range of CCWs into 'page' buffer
2906 * and return number of printed chars.
2908 static int
2909 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
2911 int len, count;
2912 char *datap;
2914 len = 0;
2915 while (from <= to) {
2916 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2917 " CCW %p: %08X %08X DAT:",
2918 from, ((int *) from)[0], ((int *) from)[1]);
2920 /* get pointer to data (consider IDALs) */
2921 if (from->flags & CCW_FLAG_IDA)
2922 datap = (char *) *((addr_t *) (addr_t) from->cda);
2923 else
2924 datap = (char *) ((addr_t) from->cda);
2926 /* dump data (max 32 bytes) */
2927 for (count = 0; count < from->count && count < 32; count++) {
2928 if (count % 8 == 0) len += sprintf(page + len, " ");
2929 if (count % 4 == 0) len += sprintf(page + len, " ");
2930 len += sprintf(page + len, "%02x", datap[count]);
2932 len += sprintf(page + len, "\n");
2933 from++;
2935 return len;
2938 static void
2939 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
2940 char *reason)
2942 u64 *sense;
2944 sense = (u64 *) dasd_get_sense(irb);
2945 if (sense) {
2946 DBF_DEV_EVENT(DBF_EMERG, device,
2947 "%s: %s %02x%02x%02x %016llx %016llx %016llx "
2948 "%016llx", reason,
2949 scsw_is_tm(&irb->scsw) ? "t" : "c",
2950 scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
2951 scsw_dstat(&irb->scsw), sense[0], sense[1],
2952 sense[2], sense[3]);
2953 } else {
2954 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
2955 "SORRY - NO VALID SENSE AVAILABLE\n");
2960 * Print sense data and related channel program.
2961 * Parts are printed because printk buffer is only 1024 bytes.
2963 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
2964 struct dasd_ccw_req *req, struct irb *irb)
2966 char *page;
2967 struct ccw1 *first, *last, *fail, *from, *to;
2968 int len, sl, sct;
2970 page = (char *) get_zeroed_page(GFP_ATOMIC);
2971 if (page == NULL) {
2972 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2973 "No memory to dump sense data\n");
2974 return;
2976 /* dump the sense data */
2977 len = sprintf(page, KERN_ERR PRINTK_HEADER
2978 " I/O status report for device %s:\n",
2979 dev_name(&device->cdev->dev));
2980 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2981 " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d\n",
2982 req, scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
2983 scsw_cc(&irb->scsw), req->intrc);
2984 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2985 " device %s: Failing CCW: %p\n",
2986 dev_name(&device->cdev->dev),
2987 (void *) (addr_t) irb->scsw.cmd.cpa);
2988 if (irb->esw.esw0.erw.cons) {
2989 for (sl = 0; sl < 4; sl++) {
2990 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2991 " Sense(hex) %2d-%2d:",
2992 (8 * sl), ((8 * sl) + 7));
2994 for (sct = 0; sct < 8; sct++) {
2995 len += sprintf(page + len, " %02x",
2996 irb->ecw[8 * sl + sct]);
2998 len += sprintf(page + len, "\n");
3001 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3002 /* 24 Byte Sense Data */
3003 sprintf(page + len, KERN_ERR PRINTK_HEADER
3004 " 24 Byte: %x MSG %x, "
3005 "%s MSGb to SYSOP\n",
3006 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3007 irb->ecw[1] & 0x10 ? "" : "no");
3008 } else {
3009 /* 32 Byte Sense Data */
3010 sprintf(page + len, KERN_ERR PRINTK_HEADER
3011 " 32 Byte: Format: %x "
3012 "Exception class %x\n",
3013 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
3015 } else {
3016 sprintf(page + len, KERN_ERR PRINTK_HEADER
3017 " SORRY - NO VALID SENSE AVAILABLE\n");
3019 printk("%s", page);
3021 if (req) {
3022 /* req == NULL for unsolicited interrupts */
3023 /* dump the Channel Program (max 140 Bytes per line) */
3024 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3025 first = req->cpaddr;
3026 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3027 to = min(first + 6, last);
3028 len = sprintf(page, KERN_ERR PRINTK_HEADER
3029 " Related CP in req: %p\n", req);
3030 dasd_eckd_dump_ccw_range(first, to, page + len);
3031 printk("%s", page);
3033 /* print failing CCW area (maximum 4) */
3034 /* scsw->cda is either valid or zero */
3035 len = 0;
3036 from = ++to;
3037 fail = (struct ccw1 *)(addr_t)
3038 irb->scsw.cmd.cpa; /* failing CCW */
3039 if (from < fail - 2) {
3040 from = fail - 2; /* there is a gap - print header */
3041 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3043 to = min(fail + 1, last);
3044 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3046 /* print last CCWs (maximum 2) */
3047 from = max(from, ++to);
3048 if (from < last - 1) {
3049 from = last - 1; /* there is a gap - print header */
3050 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3052 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3053 if (len > 0)
3054 printk("%s", page);
3056 free_page((unsigned long) page);
3061 * Print sense data from a tcw.
3063 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3064 struct dasd_ccw_req *req, struct irb *irb)
3066 char *page;
3067 int len, sl, sct, residual;
3069 struct tsb *tsb;
3070 u8 *sense;
3073 page = (char *) get_zeroed_page(GFP_ATOMIC);
3074 if (page == NULL) {
3075 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
3076 "No memory to dump sense data");
3077 return;
3079 /* dump the sense data */
3080 len = sprintf(page, KERN_ERR PRINTK_HEADER
3081 " I/O status report for device %s:\n",
3082 dev_name(&device->cdev->dev));
3083 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3084 " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d "
3085 "fcxs: 0x%02X schxs: 0x%02X\n", req,
3086 scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
3087 scsw_cc(&irb->scsw), req->intrc,
3088 irb->scsw.tm.fcxs, irb->scsw.tm.schxs);
3089 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3090 " device %s: Failing TCW: %p\n",
3091 dev_name(&device->cdev->dev),
3092 (void *) (addr_t) irb->scsw.tm.tcw);
3094 tsb = NULL;
3095 sense = NULL;
3096 if (irb->scsw.tm.tcw)
3097 tsb = tcw_get_tsb(
3098 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3100 if (tsb && (irb->scsw.tm.fcxs == 0x01)) {
3101 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3102 " tsb->length %d\n", tsb->length);
3103 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3104 " tsb->flags %x\n", tsb->flags);
3105 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3106 " tsb->dcw_offset %d\n", tsb->dcw_offset);
3107 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3108 " tsb->count %d\n", tsb->count);
3109 residual = tsb->count - 28;
3110 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3111 " residual %d\n", residual);
3113 switch (tsb->flags & 0x07) {
3114 case 1: /* tsa_iostat */
3115 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3116 " tsb->tsa.iostat.dev_time %d\n",
3117 tsb->tsa.iostat.dev_time);
3118 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3119 " tsb->tsa.iostat.def_time %d\n",
3120 tsb->tsa.iostat.def_time);
3121 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3122 " tsb->tsa.iostat.queue_time %d\n",
3123 tsb->tsa.iostat.queue_time);
3124 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3125 " tsb->tsa.iostat.dev_busy_time %d\n",
3126 tsb->tsa.iostat.dev_busy_time);
3127 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3128 " tsb->tsa.iostat.dev_act_time %d\n",
3129 tsb->tsa.iostat.dev_act_time);
3130 sense = tsb->tsa.iostat.sense;
3131 break;
3132 case 2: /* ts_ddpc */
3133 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3134 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3135 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3136 " tsb->tsa.ddpc.rcq: ");
3137 for (sl = 0; sl < 16; sl++) {
3138 for (sct = 0; sct < 8; sct++) {
3139 len += sprintf(page + len, " %02x",
3140 tsb->tsa.ddpc.rcq[sl]);
3142 len += sprintf(page + len, "\n");
3144 sense = tsb->tsa.ddpc.sense;
3145 break;
3146 case 3: /* tsa_intrg */
3147 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3148 " tsb->tsa.intrg.: not supportet yet \n");
3149 break;
3152 if (sense) {
3153 for (sl = 0; sl < 4; sl++) {
3154 len += sprintf(page + len,
3155 KERN_ERR PRINTK_HEADER
3156 " Sense(hex) %2d-%2d:",
3157 (8 * sl), ((8 * sl) + 7));
3158 for (sct = 0; sct < 8; sct++) {
3159 len += sprintf(page + len, " %02x",
3160 sense[8 * sl + sct]);
3162 len += sprintf(page + len, "\n");
3165 if (sense[27] & DASD_SENSE_BIT_0) {
3166 /* 24 Byte Sense Data */
3167 sprintf(page + len, KERN_ERR PRINTK_HEADER
3168 " 24 Byte: %x MSG %x, "
3169 "%s MSGb to SYSOP\n",
3170 sense[7] >> 4, sense[7] & 0x0f,
3171 sense[1] & 0x10 ? "" : "no");
3172 } else {
3173 /* 32 Byte Sense Data */
3174 sprintf(page + len, KERN_ERR PRINTK_HEADER
3175 " 32 Byte: Format: %x "
3176 "Exception class %x\n",
3177 sense[6] & 0x0f, sense[22] >> 4);
3179 } else {
3180 sprintf(page + len, KERN_ERR PRINTK_HEADER
3181 " SORRY - NO VALID SENSE AVAILABLE\n");
3183 } else {
3184 sprintf(page + len, KERN_ERR PRINTK_HEADER
3185 " SORRY - NO TSB DATA AVAILABLE\n");
3187 printk("%s", page);
3188 free_page((unsigned long) page);
3191 static void dasd_eckd_dump_sense(struct dasd_device *device,
3192 struct dasd_ccw_req *req, struct irb *irb)
3194 if (req && scsw_is_tm(&req->irb.scsw))
3195 dasd_eckd_dump_sense_tcw(device, req, irb);
3196 else
3197 dasd_eckd_dump_sense_ccw(device, req, irb);
3200 int dasd_eckd_pm_freeze(struct dasd_device *device)
3203 * the device should be disconnected from our LCU structure
3204 * on restore we will reconnect it and reread LCU specific
3205 * information like PAV support that might have changed
3207 dasd_alias_remove_device(device);
3208 dasd_alias_disconnect_device_from_lcu(device);
3210 return 0;
3213 int dasd_eckd_restore_device(struct dasd_device *device)
3215 struct dasd_eckd_private *private;
3216 struct dasd_eckd_characteristics temp_rdc_data;
3217 int is_known, rc;
3218 struct dasd_uid temp_uid;
3219 unsigned long flags;
3221 private = (struct dasd_eckd_private *) device->private;
3223 /* Read Configuration Data */
3224 rc = dasd_eckd_read_conf(device);
3225 if (rc)
3226 goto out_err;
3228 /* Generate device unique id and register in devmap */
3229 rc = dasd_eckd_generate_uid(device, &private->uid);
3230 dasd_get_uid(device->cdev, &temp_uid);
3231 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
3232 dev_err(&device->cdev->dev, "The UID of the DASD has "
3233 "changed\n");
3234 if (rc)
3235 goto out_err;
3236 dasd_set_uid(device->cdev, &private->uid);
3238 /* register lcu with alias handling, enable PAV if this is a new lcu */
3239 is_known = dasd_alias_make_device_known_to_lcu(device);
3240 if (is_known < 0)
3241 return is_known;
3242 if (!is_known) {
3243 /* new lcu found */
3244 rc = dasd_eckd_validate_server(device); /* will switch pav on */
3245 if (rc)
3246 goto out_err;
3249 /* Read Feature Codes */
3250 dasd_eckd_read_features(device);
3252 /* Read Device Characteristics */
3253 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
3254 &temp_rdc_data, 64);
3255 if (rc) {
3256 DBF_EVENT(DBF_WARNING,
3257 "Read device characteristics failed, rc=%d for "
3258 "device: %s", rc, dev_name(&device->cdev->dev));
3259 goto out_err;
3261 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3262 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
3263 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3265 /* add device to alias management */
3266 dasd_alias_add_device(device);
3268 return 0;
3270 out_err:
3271 return -1;
3274 static struct ccw_driver dasd_eckd_driver = {
3275 .name = "dasd-eckd",
3276 .owner = THIS_MODULE,
3277 .ids = dasd_eckd_ids,
3278 .probe = dasd_eckd_probe,
3279 .remove = dasd_generic_remove,
3280 .set_offline = dasd_generic_set_offline,
3281 .set_online = dasd_eckd_set_online,
3282 .notify = dasd_generic_notify,
3283 .freeze = dasd_generic_pm_freeze,
3284 .thaw = dasd_generic_restore_device,
3285 .restore = dasd_generic_restore_device,
3289 * max_blocks is dependent on the amount of storage that is available
3290 * in the static io buffer for each device. Currently each device has
3291 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
3292 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
3293 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
3294 * addition we have one define extent ccw + 16 bytes of data and one
3295 * locate record ccw + 16 bytes of data. That makes:
3296 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
3297 * We want to fit two into the available memory so that we can immediately
3298 * start the next request if one finishes off. That makes 249.5 blocks
3299 * for one request. Give a little safety and the result is 240.
3301 static struct dasd_discipline dasd_eckd_discipline = {
3302 .owner = THIS_MODULE,
3303 .name = "ECKD",
3304 .ebcname = "ECKD",
3305 .max_blocks = 240,
3306 .check_device = dasd_eckd_check_characteristics,
3307 .uncheck_device = dasd_eckd_uncheck_device,
3308 .do_analysis = dasd_eckd_do_analysis,
3309 .ready_to_online = dasd_eckd_ready_to_online,
3310 .online_to_ready = dasd_eckd_online_to_ready,
3311 .fill_geometry = dasd_eckd_fill_geometry,
3312 .start_IO = dasd_start_IO,
3313 .term_IO = dasd_term_IO,
3314 .handle_terminated_request = dasd_eckd_handle_terminated_request,
3315 .format_device = dasd_eckd_format_device,
3316 .erp_action = dasd_eckd_erp_action,
3317 .erp_postaction = dasd_eckd_erp_postaction,
3318 .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
3319 .build_cp = dasd_eckd_build_alias_cp,
3320 .free_cp = dasd_eckd_free_alias_cp,
3321 .dump_sense = dasd_eckd_dump_sense,
3322 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
3323 .fill_info = dasd_eckd_fill_info,
3324 .ioctl = dasd_eckd_ioctl,
3325 .freeze = dasd_eckd_pm_freeze,
3326 .restore = dasd_eckd_restore_device,
3329 static int __init
3330 dasd_eckd_init(void)
3332 int ret;
3334 ASCEBC(dasd_eckd_discipline.ebcname, 4);
3335 ret = ccw_driver_register(&dasd_eckd_driver);
3336 if (!ret)
3337 wait_for_device_probe();
3339 return ret;
3342 static void __exit
3343 dasd_eckd_cleanup(void)
3345 ccw_driver_unregister(&dasd_eckd_driver);
3348 module_init(dasd_eckd_init);
3349 module_exit(dasd_eckd_cleanup);