Merge branch 'davinci-next-2' of git://git.kernel.org/pub/scm/linux/kernel/git/khilma...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / s390 / block / dasd_eckd.c
bloba9fe23d5bd0f73417ab4f51013ec2654bce7d185
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/compat.h>
27 #include <asm/io.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)
58 * raw track access always map to 64k in memory
59 * so it maps to 16 blocks of 4k per track
61 #define DASD_RAW_BLOCK_PER_TRACK 16
62 #define DASD_RAW_BLOCKSIZE 4096
63 /* 64k are 128 x 512 byte sectors */
64 #define DASD_RAW_SECTORS_PER_TRACK 128
66 MODULE_LICENSE("GPL");
68 static struct dasd_discipline dasd_eckd_discipline;
70 /* The ccw bus type uses this table to find devices that it sends to
71 * dasd_eckd_probe */
72 static struct ccw_device_id dasd_eckd_ids[] = {
73 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
74 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
75 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
76 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
77 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
78 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
79 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
80 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
81 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
82 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
83 { /* end of list */ },
86 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
88 static struct ccw_driver dasd_eckd_driver; /* see below */
90 #define INIT_CQR_OK 0
91 #define INIT_CQR_UNFORMATTED 1
92 #define INIT_CQR_ERROR 2
94 /* emergency request for reserve/release */
95 static struct {
96 struct dasd_ccw_req cqr;
97 struct ccw1 ccw;
98 char data[32];
99 } *dasd_reserve_req;
100 static DEFINE_MUTEX(dasd_reserve_mutex);
102 /* definitions for the path verification worker */
103 struct path_verification_work_data {
104 struct work_struct worker;
105 struct dasd_device *device;
106 struct dasd_ccw_req cqr;
107 struct ccw1 ccw;
108 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
109 int isglobal;
110 __u8 tbvpm;
112 static struct path_verification_work_data *path_verification_worker;
113 static DEFINE_MUTEX(dasd_path_verification_mutex);
115 /* initial attempt at a probe function. this can be simplified once
116 * the other detection code is gone */
117 static int
118 dasd_eckd_probe (struct ccw_device *cdev)
120 int ret;
122 /* set ECKD specific ccw-device options */
123 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
124 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
125 if (ret) {
126 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
127 "dasd_eckd_probe: could not set "
128 "ccw-device options");
129 return ret;
131 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
132 return ret;
135 static int
136 dasd_eckd_set_online(struct ccw_device *cdev)
138 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
141 static const int sizes_trk0[] = { 28, 148, 84 };
142 #define LABEL_SIZE 140
144 static inline unsigned int
145 round_up_multiple(unsigned int no, unsigned int mult)
147 int rem = no % mult;
148 return (rem ? no - rem + mult : no);
151 static inline unsigned int
152 ceil_quot(unsigned int d1, unsigned int d2)
154 return (d1 + (d2 - 1)) / d2;
157 static unsigned int
158 recs_per_track(struct dasd_eckd_characteristics * rdc,
159 unsigned int kl, unsigned int dl)
161 int dn, kn;
163 switch (rdc->dev_type) {
164 case 0x3380:
165 if (kl)
166 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
167 ceil_quot(dl + 12, 32));
168 else
169 return 1499 / (15 + ceil_quot(dl + 12, 32));
170 case 0x3390:
171 dn = ceil_quot(dl + 6, 232) + 1;
172 if (kl) {
173 kn = ceil_quot(kl + 6, 232) + 1;
174 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
175 9 + ceil_quot(dl + 6 * dn, 34));
176 } else
177 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
178 case 0x9345:
179 dn = ceil_quot(dl + 6, 232) + 1;
180 if (kl) {
181 kn = ceil_quot(kl + 6, 232) + 1;
182 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
183 ceil_quot(dl + 6 * dn, 34));
184 } else
185 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
187 return 0;
190 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
192 geo->cyl = (__u16) cyl;
193 geo->head = cyl >> 16;
194 geo->head <<= 4;
195 geo->head |= head;
198 static int
199 check_XRC (struct ccw1 *de_ccw,
200 struct DE_eckd_data *data,
201 struct dasd_device *device)
203 struct dasd_eckd_private *private;
204 int rc;
206 private = (struct dasd_eckd_private *) device->private;
207 if (!private->rdc_data.facilities.XRC_supported)
208 return 0;
210 /* switch on System Time Stamp - needed for XRC Support */
211 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
212 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
214 rc = get_sync_clock(&data->ep_sys_time);
215 /* Ignore return code if sync clock is switched off. */
216 if (rc == -ENOSYS || rc == -EACCES)
217 rc = 0;
219 de_ccw->count = sizeof(struct DE_eckd_data);
220 de_ccw->flags |= CCW_FLAG_SLI;
221 return rc;
224 static int
225 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
226 unsigned int totrk, int cmd, struct dasd_device *device)
228 struct dasd_eckd_private *private;
229 u32 begcyl, endcyl;
230 u16 heads, beghead, endhead;
231 int rc = 0;
233 private = (struct dasd_eckd_private *) device->private;
235 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
236 ccw->flags = 0;
237 ccw->count = 16;
238 ccw->cda = (__u32) __pa(data);
240 memset(data, 0, sizeof(struct DE_eckd_data));
241 switch (cmd) {
242 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
243 case DASD_ECKD_CCW_READ_RECORD_ZERO:
244 case DASD_ECKD_CCW_READ:
245 case DASD_ECKD_CCW_READ_MT:
246 case DASD_ECKD_CCW_READ_CKD:
247 case DASD_ECKD_CCW_READ_CKD_MT:
248 case DASD_ECKD_CCW_READ_KD:
249 case DASD_ECKD_CCW_READ_KD_MT:
250 case DASD_ECKD_CCW_READ_COUNT:
251 data->mask.perm = 0x1;
252 data->attributes.operation = private->attrib.operation;
253 break;
254 case DASD_ECKD_CCW_WRITE:
255 case DASD_ECKD_CCW_WRITE_MT:
256 case DASD_ECKD_CCW_WRITE_KD:
257 case DASD_ECKD_CCW_WRITE_KD_MT:
258 data->mask.perm = 0x02;
259 data->attributes.operation = private->attrib.operation;
260 rc = check_XRC (ccw, data, device);
261 break;
262 case DASD_ECKD_CCW_WRITE_CKD:
263 case DASD_ECKD_CCW_WRITE_CKD_MT:
264 data->attributes.operation = DASD_BYPASS_CACHE;
265 rc = check_XRC (ccw, data, device);
266 break;
267 case DASD_ECKD_CCW_ERASE:
268 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
269 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
270 data->mask.perm = 0x3;
271 data->mask.auth = 0x1;
272 data->attributes.operation = DASD_BYPASS_CACHE;
273 rc = check_XRC (ccw, data, device);
274 break;
275 default:
276 dev_err(&device->cdev->dev,
277 "0x%x is not a known command\n", cmd);
278 break;
281 data->attributes.mode = 0x3; /* ECKD */
283 if ((private->rdc_data.cu_type == 0x2105 ||
284 private->rdc_data.cu_type == 0x2107 ||
285 private->rdc_data.cu_type == 0x1750)
286 && !(private->uses_cdl && trk < 2))
287 data->ga_extended |= 0x40; /* Regular Data Format Mode */
289 heads = private->rdc_data.trk_per_cyl;
290 begcyl = trk / heads;
291 beghead = trk % heads;
292 endcyl = totrk / heads;
293 endhead = totrk % heads;
295 /* check for sequential prestage - enhance cylinder range */
296 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
297 data->attributes.operation == DASD_SEQ_ACCESS) {
299 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
300 endcyl += private->attrib.nr_cyl;
301 else
302 endcyl = (private->real_cyl - 1);
305 set_ch_t(&data->beg_ext, begcyl, beghead);
306 set_ch_t(&data->end_ext, endcyl, endhead);
307 return rc;
310 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
311 struct dasd_device *device)
313 struct dasd_eckd_private *private;
314 int rc;
316 private = (struct dasd_eckd_private *) device->private;
317 if (!private->rdc_data.facilities.XRC_supported)
318 return 0;
320 /* switch on System Time Stamp - needed for XRC Support */
321 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
322 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
323 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
325 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
326 /* Ignore return code if sync clock is switched off. */
327 if (rc == -ENOSYS || rc == -EACCES)
328 rc = 0;
329 return rc;
332 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
333 unsigned int rec_on_trk, int count, int cmd,
334 struct dasd_device *device, unsigned int reclen,
335 unsigned int tlf)
337 struct dasd_eckd_private *private;
338 int sector;
339 int dn, d;
341 private = (struct dasd_eckd_private *) device->private;
343 memset(data, 0, sizeof(*data));
344 sector = 0;
345 if (rec_on_trk) {
346 switch (private->rdc_data.dev_type) {
347 case 0x3390:
348 dn = ceil_quot(reclen + 6, 232);
349 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
350 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
351 break;
352 case 0x3380:
353 d = 7 + ceil_quot(reclen + 12, 32);
354 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
355 break;
358 data->sector = sector;
359 /* note: meaning of count depends on the operation
360 * for record based I/O it's the number of records, but for
361 * track based I/O it's the number of tracks
363 data->count = count;
364 switch (cmd) {
365 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
366 data->operation.orientation = 0x3;
367 data->operation.operation = 0x03;
368 break;
369 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
370 data->operation.orientation = 0x3;
371 data->operation.operation = 0x16;
372 break;
373 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
374 data->operation.orientation = 0x1;
375 data->operation.operation = 0x03;
376 data->count++;
377 break;
378 case DASD_ECKD_CCW_READ_RECORD_ZERO:
379 data->operation.orientation = 0x3;
380 data->operation.operation = 0x16;
381 data->count++;
382 break;
383 case DASD_ECKD_CCW_WRITE:
384 case DASD_ECKD_CCW_WRITE_MT:
385 case DASD_ECKD_CCW_WRITE_KD:
386 case DASD_ECKD_CCW_WRITE_KD_MT:
387 data->auxiliary.length_valid = 0x1;
388 data->length = reclen;
389 data->operation.operation = 0x01;
390 break;
391 case DASD_ECKD_CCW_WRITE_CKD:
392 case DASD_ECKD_CCW_WRITE_CKD_MT:
393 data->auxiliary.length_valid = 0x1;
394 data->length = reclen;
395 data->operation.operation = 0x03;
396 break;
397 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
398 data->operation.orientation = 0x0;
399 data->operation.operation = 0x3F;
400 data->extended_operation = 0x11;
401 data->length = 0;
402 data->extended_parameter_length = 0x02;
403 if (data->count > 8) {
404 data->extended_parameter[0] = 0xFF;
405 data->extended_parameter[1] = 0xFF;
406 data->extended_parameter[1] <<= (16 - count);
407 } else {
408 data->extended_parameter[0] = 0xFF;
409 data->extended_parameter[0] <<= (8 - count);
410 data->extended_parameter[1] = 0x00;
412 data->sector = 0xFF;
413 break;
414 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
415 data->auxiliary.length_valid = 0x1;
416 data->length = reclen; /* not tlf, as one might think */
417 data->operation.operation = 0x3F;
418 data->extended_operation = 0x23;
419 break;
420 case DASD_ECKD_CCW_READ:
421 case DASD_ECKD_CCW_READ_MT:
422 case DASD_ECKD_CCW_READ_KD:
423 case DASD_ECKD_CCW_READ_KD_MT:
424 data->auxiliary.length_valid = 0x1;
425 data->length = reclen;
426 data->operation.operation = 0x06;
427 break;
428 case DASD_ECKD_CCW_READ_CKD:
429 case DASD_ECKD_CCW_READ_CKD_MT:
430 data->auxiliary.length_valid = 0x1;
431 data->length = reclen;
432 data->operation.operation = 0x16;
433 break;
434 case DASD_ECKD_CCW_READ_COUNT:
435 data->operation.operation = 0x06;
436 break;
437 case DASD_ECKD_CCW_READ_TRACK:
438 data->operation.orientation = 0x1;
439 data->operation.operation = 0x0C;
440 data->extended_parameter_length = 0;
441 data->sector = 0xFF;
442 break;
443 case DASD_ECKD_CCW_READ_TRACK_DATA:
444 data->auxiliary.length_valid = 0x1;
445 data->length = tlf;
446 data->operation.operation = 0x0C;
447 break;
448 case DASD_ECKD_CCW_ERASE:
449 data->length = reclen;
450 data->auxiliary.length_valid = 0x1;
451 data->operation.operation = 0x0b;
452 break;
453 default:
454 DBF_DEV_EVENT(DBF_ERR, device,
455 "fill LRE unknown opcode 0x%x", cmd);
456 BUG();
458 set_ch_t(&data->seek_addr,
459 trk / private->rdc_data.trk_per_cyl,
460 trk % private->rdc_data.trk_per_cyl);
461 data->search_arg.cyl = data->seek_addr.cyl;
462 data->search_arg.head = data->seek_addr.head;
463 data->search_arg.record = rec_on_trk;
466 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
467 unsigned int trk, unsigned int totrk, int cmd,
468 struct dasd_device *basedev, struct dasd_device *startdev,
469 unsigned char format, unsigned int rec_on_trk, int count,
470 unsigned int blksize, unsigned int tlf)
472 struct dasd_eckd_private *basepriv, *startpriv;
473 struct DE_eckd_data *dedata;
474 struct LRE_eckd_data *lredata;
475 u32 begcyl, endcyl;
476 u16 heads, beghead, endhead;
477 int rc = 0;
479 basepriv = (struct dasd_eckd_private *) basedev->private;
480 startpriv = (struct dasd_eckd_private *) startdev->private;
481 dedata = &pfxdata->define_extent;
482 lredata = &pfxdata->locate_record;
484 ccw->cmd_code = DASD_ECKD_CCW_PFX;
485 ccw->flags = 0;
486 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
487 ccw->count = sizeof(*pfxdata) + 2;
488 ccw->cda = (__u32) __pa(pfxdata);
489 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
490 } else {
491 ccw->count = sizeof(*pfxdata);
492 ccw->cda = (__u32) __pa(pfxdata);
493 memset(pfxdata, 0, sizeof(*pfxdata));
496 /* prefix data */
497 if (format > 1) {
498 DBF_DEV_EVENT(DBF_ERR, basedev,
499 "PFX LRE unknown format 0x%x", format);
500 BUG();
501 return -EINVAL;
503 pfxdata->format = format;
504 pfxdata->base_address = basepriv->ned->unit_addr;
505 pfxdata->base_lss = basepriv->ned->ID;
506 pfxdata->validity.define_extent = 1;
508 /* private uid is kept up to date, conf_data may be outdated */
509 if (startpriv->uid.type != UA_BASE_DEVICE) {
510 pfxdata->validity.verify_base = 1;
511 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
512 pfxdata->validity.hyper_pav = 1;
515 /* define extend data (mostly)*/
516 switch (cmd) {
517 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
518 case DASD_ECKD_CCW_READ_RECORD_ZERO:
519 case DASD_ECKD_CCW_READ:
520 case DASD_ECKD_CCW_READ_MT:
521 case DASD_ECKD_CCW_READ_CKD:
522 case DASD_ECKD_CCW_READ_CKD_MT:
523 case DASD_ECKD_CCW_READ_KD:
524 case DASD_ECKD_CCW_READ_KD_MT:
525 case DASD_ECKD_CCW_READ_COUNT:
526 dedata->mask.perm = 0x1;
527 dedata->attributes.operation = basepriv->attrib.operation;
528 break;
529 case DASD_ECKD_CCW_READ_TRACK:
530 case DASD_ECKD_CCW_READ_TRACK_DATA:
531 dedata->mask.perm = 0x1;
532 dedata->attributes.operation = basepriv->attrib.operation;
533 dedata->blk_size = 0;
534 break;
535 case DASD_ECKD_CCW_WRITE:
536 case DASD_ECKD_CCW_WRITE_MT:
537 case DASD_ECKD_CCW_WRITE_KD:
538 case DASD_ECKD_CCW_WRITE_KD_MT:
539 dedata->mask.perm = 0x02;
540 dedata->attributes.operation = basepriv->attrib.operation;
541 rc = check_XRC_on_prefix(pfxdata, basedev);
542 break;
543 case DASD_ECKD_CCW_WRITE_CKD:
544 case DASD_ECKD_CCW_WRITE_CKD_MT:
545 dedata->attributes.operation = DASD_BYPASS_CACHE;
546 rc = check_XRC_on_prefix(pfxdata, basedev);
547 break;
548 case DASD_ECKD_CCW_ERASE:
549 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
550 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
551 dedata->mask.perm = 0x3;
552 dedata->mask.auth = 0x1;
553 dedata->attributes.operation = DASD_BYPASS_CACHE;
554 rc = check_XRC_on_prefix(pfxdata, basedev);
555 break;
556 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
557 dedata->mask.perm = 0x03;
558 dedata->attributes.operation = basepriv->attrib.operation;
559 dedata->blk_size = 0;
560 break;
561 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
562 dedata->mask.perm = 0x02;
563 dedata->attributes.operation = basepriv->attrib.operation;
564 dedata->blk_size = blksize;
565 rc = check_XRC_on_prefix(pfxdata, basedev);
566 break;
567 default:
568 DBF_DEV_EVENT(DBF_ERR, basedev,
569 "PFX LRE unknown opcode 0x%x", cmd);
570 BUG();
571 return -EINVAL;
574 dedata->attributes.mode = 0x3; /* ECKD */
576 if ((basepriv->rdc_data.cu_type == 0x2105 ||
577 basepriv->rdc_data.cu_type == 0x2107 ||
578 basepriv->rdc_data.cu_type == 0x1750)
579 && !(basepriv->uses_cdl && trk < 2))
580 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
582 heads = basepriv->rdc_data.trk_per_cyl;
583 begcyl = trk / heads;
584 beghead = trk % heads;
585 endcyl = totrk / heads;
586 endhead = totrk % heads;
588 /* check for sequential prestage - enhance cylinder range */
589 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
590 dedata->attributes.operation == DASD_SEQ_ACCESS) {
592 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
593 endcyl += basepriv->attrib.nr_cyl;
594 else
595 endcyl = (basepriv->real_cyl - 1);
598 set_ch_t(&dedata->beg_ext, begcyl, beghead);
599 set_ch_t(&dedata->end_ext, endcyl, endhead);
601 if (format == 1) {
602 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
603 basedev, blksize, tlf);
606 return rc;
609 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
610 unsigned int trk, unsigned int totrk, int cmd,
611 struct dasd_device *basedev, struct dasd_device *startdev)
613 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
614 0, 0, 0, 0, 0);
617 static void
618 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
619 unsigned int rec_on_trk, int no_rec, int cmd,
620 struct dasd_device * device, int reclen)
622 struct dasd_eckd_private *private;
623 int sector;
624 int dn, d;
626 private = (struct dasd_eckd_private *) device->private;
628 DBF_DEV_EVENT(DBF_INFO, device,
629 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
630 trk, rec_on_trk, no_rec, cmd, reclen);
632 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
633 ccw->flags = 0;
634 ccw->count = 16;
635 ccw->cda = (__u32) __pa(data);
637 memset(data, 0, sizeof(struct LO_eckd_data));
638 sector = 0;
639 if (rec_on_trk) {
640 switch (private->rdc_data.dev_type) {
641 case 0x3390:
642 dn = ceil_quot(reclen + 6, 232);
643 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
644 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
645 break;
646 case 0x3380:
647 d = 7 + ceil_quot(reclen + 12, 32);
648 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
649 break;
652 data->sector = sector;
653 data->count = no_rec;
654 switch (cmd) {
655 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
656 data->operation.orientation = 0x3;
657 data->operation.operation = 0x03;
658 break;
659 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
660 data->operation.orientation = 0x3;
661 data->operation.operation = 0x16;
662 break;
663 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
664 data->operation.orientation = 0x1;
665 data->operation.operation = 0x03;
666 data->count++;
667 break;
668 case DASD_ECKD_CCW_READ_RECORD_ZERO:
669 data->operation.orientation = 0x3;
670 data->operation.operation = 0x16;
671 data->count++;
672 break;
673 case DASD_ECKD_CCW_WRITE:
674 case DASD_ECKD_CCW_WRITE_MT:
675 case DASD_ECKD_CCW_WRITE_KD:
676 case DASD_ECKD_CCW_WRITE_KD_MT:
677 data->auxiliary.last_bytes_used = 0x1;
678 data->length = reclen;
679 data->operation.operation = 0x01;
680 break;
681 case DASD_ECKD_CCW_WRITE_CKD:
682 case DASD_ECKD_CCW_WRITE_CKD_MT:
683 data->auxiliary.last_bytes_used = 0x1;
684 data->length = reclen;
685 data->operation.operation = 0x03;
686 break;
687 case DASD_ECKD_CCW_READ:
688 case DASD_ECKD_CCW_READ_MT:
689 case DASD_ECKD_CCW_READ_KD:
690 case DASD_ECKD_CCW_READ_KD_MT:
691 data->auxiliary.last_bytes_used = 0x1;
692 data->length = reclen;
693 data->operation.operation = 0x06;
694 break;
695 case DASD_ECKD_CCW_READ_CKD:
696 case DASD_ECKD_CCW_READ_CKD_MT:
697 data->auxiliary.last_bytes_used = 0x1;
698 data->length = reclen;
699 data->operation.operation = 0x16;
700 break;
701 case DASD_ECKD_CCW_READ_COUNT:
702 data->operation.operation = 0x06;
703 break;
704 case DASD_ECKD_CCW_ERASE:
705 data->length = reclen;
706 data->auxiliary.last_bytes_used = 0x1;
707 data->operation.operation = 0x0b;
708 break;
709 default:
710 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
711 "opcode 0x%x", cmd);
713 set_ch_t(&data->seek_addr,
714 trk / private->rdc_data.trk_per_cyl,
715 trk % private->rdc_data.trk_per_cyl);
716 data->search_arg.cyl = data->seek_addr.cyl;
717 data->search_arg.head = data->seek_addr.head;
718 data->search_arg.record = rec_on_trk;
722 * Returns 1 if the block is one of the special blocks that needs
723 * to get read/written with the KD variant of the command.
724 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
725 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
726 * Luckily the KD variants differ only by one bit (0x08) from the
727 * normal variant. So don't wonder about code like:
728 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
729 * ccw->cmd_code |= 0x8;
731 static inline int
732 dasd_eckd_cdl_special(int blk_per_trk, int recid)
734 if (recid < 3)
735 return 1;
736 if (recid < blk_per_trk)
737 return 0;
738 if (recid < 2 * blk_per_trk)
739 return 1;
740 return 0;
744 * Returns the record size for the special blocks of the cdl format.
745 * Only returns something useful if dasd_eckd_cdl_special is true
746 * for the recid.
748 static inline int
749 dasd_eckd_cdl_reclen(int recid)
751 if (recid < 3)
752 return sizes_trk0[recid];
753 return LABEL_SIZE;
757 * Generate device unique id that specifies the physical device.
759 static int dasd_eckd_generate_uid(struct dasd_device *device)
761 struct dasd_eckd_private *private;
762 struct dasd_uid *uid;
763 int count;
764 unsigned long flags;
766 private = (struct dasd_eckd_private *) device->private;
767 if (!private)
768 return -ENODEV;
769 if (!private->ned || !private->gneq)
770 return -ENODEV;
771 uid = &private->uid;
772 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
773 memset(uid, 0, sizeof(struct dasd_uid));
774 memcpy(uid->vendor, private->ned->HDA_manufacturer,
775 sizeof(uid->vendor) - 1);
776 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
777 memcpy(uid->serial, private->ned->HDA_location,
778 sizeof(uid->serial) - 1);
779 EBCASC(uid->serial, sizeof(uid->serial) - 1);
780 uid->ssid = private->gneq->subsystemID;
781 uid->real_unit_addr = private->ned->unit_addr;
782 if (private->sneq) {
783 uid->type = private->sneq->sua_flags;
784 if (uid->type == UA_BASE_PAV_ALIAS)
785 uid->base_unit_addr = private->sneq->base_unit_addr;
786 } else {
787 uid->type = UA_BASE_DEVICE;
789 if (private->vdsneq) {
790 for (count = 0; count < 16; count++) {
791 sprintf(uid->vduit+2*count, "%02x",
792 private->vdsneq->uit[count]);
795 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
796 return 0;
799 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
801 struct dasd_eckd_private *private;
802 unsigned long flags;
804 if (device->private) {
805 private = (struct dasd_eckd_private *)device->private;
806 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
807 *uid = private->uid;
808 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
809 return 0;
811 return -EINVAL;
814 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
815 struct dasd_ccw_req *cqr,
816 __u8 *rcd_buffer,
817 __u8 lpm)
819 struct ccw1 *ccw;
821 * buffer has to start with EBCDIC "V1.0" to show
822 * support for virtual device SNEQ
824 rcd_buffer[0] = 0xE5;
825 rcd_buffer[1] = 0xF1;
826 rcd_buffer[2] = 0x4B;
827 rcd_buffer[3] = 0xF0;
829 ccw = cqr->cpaddr;
830 ccw->cmd_code = DASD_ECKD_CCW_RCD;
831 ccw->flags = 0;
832 ccw->cda = (__u32)(addr_t)rcd_buffer;
833 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
834 cqr->magic = DASD_ECKD_MAGIC;
836 cqr->startdev = device;
837 cqr->memdev = device;
838 cqr->block = NULL;
839 cqr->expires = 10*HZ;
840 cqr->lpm = lpm;
841 cqr->retries = 256;
842 cqr->buildclk = get_clock();
843 cqr->status = DASD_CQR_FILLED;
844 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
847 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
848 struct dasd_ccw_req *cqr,
849 __u8 *rcd_buffer,
850 __u8 lpm)
852 struct ciw *ciw;
853 int rc;
855 * sanity check: scan for RCD command in extended SenseID data
856 * some devices do not support RCD
858 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
859 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
860 return -EOPNOTSUPP;
862 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
863 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
864 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
865 cqr->retries = 5;
866 rc = dasd_sleep_on_immediatly(cqr);
867 return rc;
870 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
871 void **rcd_buffer,
872 int *rcd_buffer_size, __u8 lpm)
874 struct ciw *ciw;
875 char *rcd_buf = NULL;
876 int ret;
877 struct dasd_ccw_req *cqr;
880 * sanity check: scan for RCD command in extended SenseID data
881 * some devices do not support RCD
883 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
884 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
885 ret = -EOPNOTSUPP;
886 goto out_error;
888 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
889 if (!rcd_buf) {
890 ret = -ENOMEM;
891 goto out_error;
893 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
894 0, /* use rcd_buf as data ara */
895 device);
896 if (IS_ERR(cqr)) {
897 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
898 "Could not allocate RCD request");
899 ret = -ENOMEM;
900 goto out_error;
902 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
903 ret = dasd_sleep_on(cqr);
905 * on success we update the user input parms
907 dasd_sfree_request(cqr, cqr->memdev);
908 if (ret)
909 goto out_error;
911 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
912 *rcd_buffer = rcd_buf;
913 return 0;
914 out_error:
915 kfree(rcd_buf);
916 *rcd_buffer = NULL;
917 *rcd_buffer_size = 0;
918 return ret;
921 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
924 struct dasd_sneq *sneq;
925 int i, count;
927 private->ned = NULL;
928 private->sneq = NULL;
929 private->vdsneq = NULL;
930 private->gneq = NULL;
931 count = private->conf_len / sizeof(struct dasd_sneq);
932 sneq = (struct dasd_sneq *)private->conf_data;
933 for (i = 0; i < count; ++i) {
934 if (sneq->flags.identifier == 1 && sneq->format == 1)
935 private->sneq = sneq;
936 else if (sneq->flags.identifier == 1 && sneq->format == 4)
937 private->vdsneq = (struct vd_sneq *)sneq;
938 else if (sneq->flags.identifier == 2)
939 private->gneq = (struct dasd_gneq *)sneq;
940 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
941 private->ned = (struct dasd_ned *)sneq;
942 sneq++;
944 if (!private->ned || !private->gneq) {
945 private->ned = NULL;
946 private->sneq = NULL;
947 private->vdsneq = NULL;
948 private->gneq = NULL;
949 return -EINVAL;
951 return 0;
955 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
957 struct dasd_gneq *gneq;
958 int i, count, found;
960 count = conf_len / sizeof(*gneq);
961 gneq = (struct dasd_gneq *)conf_data;
962 found = 0;
963 for (i = 0; i < count; ++i) {
964 if (gneq->flags.identifier == 2) {
965 found = 1;
966 break;
968 gneq++;
970 if (found)
971 return ((char *)gneq)[18] & 0x07;
972 else
973 return 0;
976 static int dasd_eckd_read_conf(struct dasd_device *device)
978 void *conf_data;
979 int conf_len, conf_data_saved;
980 int rc;
981 __u8 lpm, opm;
982 struct dasd_eckd_private *private;
983 struct dasd_path *path_data;
985 private = (struct dasd_eckd_private *) device->private;
986 path_data = &device->path_data;
987 opm = ccw_device_get_path_mask(device->cdev);
988 lpm = 0x80;
989 conf_data_saved = 0;
990 /* get configuration data per operational path */
991 for (lpm = 0x80; lpm; lpm>>= 1) {
992 if (lpm & opm) {
993 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
994 &conf_len, lpm);
995 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
996 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
997 "Read configuration data returned "
998 "error %d", rc);
999 return rc;
1001 if (conf_data == NULL) {
1002 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1003 "No configuration data "
1004 "retrieved");
1005 /* no further analysis possible */
1006 path_data->opm |= lpm;
1007 continue; /* no error */
1009 /* save first valid configuration data */
1010 if (!conf_data_saved) {
1011 kfree(private->conf_data);
1012 private->conf_data = conf_data;
1013 private->conf_len = conf_len;
1014 if (dasd_eckd_identify_conf_parts(private)) {
1015 private->conf_data = NULL;
1016 private->conf_len = 0;
1017 kfree(conf_data);
1018 continue;
1020 conf_data_saved++;
1022 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1023 case 0x02:
1024 path_data->npm |= lpm;
1025 break;
1026 case 0x03:
1027 path_data->ppm |= lpm;
1028 break;
1030 path_data->opm |= lpm;
1031 if (conf_data != private->conf_data)
1032 kfree(conf_data);
1035 return 0;
1038 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1040 struct dasd_eckd_private *private;
1041 int mdc;
1042 u32 fcx_max_data;
1044 private = (struct dasd_eckd_private *) device->private;
1045 if (private->fcx_max_data) {
1046 mdc = ccw_device_get_mdc(device->cdev, lpm);
1047 if ((mdc < 0)) {
1048 dev_warn(&device->cdev->dev,
1049 "Detecting the maximum data size for zHPF "
1050 "requests failed (rc=%d) for a new path %x\n",
1051 mdc, lpm);
1052 return mdc;
1054 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1055 if (fcx_max_data < private->fcx_max_data) {
1056 dev_warn(&device->cdev->dev,
1057 "The maximum data size for zHPF requests %u "
1058 "on a new path %x is below the active maximum "
1059 "%u\n", fcx_max_data, lpm,
1060 private->fcx_max_data);
1061 return -EACCES;
1064 return 0;
1067 static void do_path_verification_work(struct work_struct *work)
1069 struct path_verification_work_data *data;
1070 struct dasd_device *device;
1071 __u8 lpm, opm, npm, ppm, epm;
1072 unsigned long flags;
1073 int rc;
1075 data = container_of(work, struct path_verification_work_data, worker);
1076 device = data->device;
1078 opm = 0;
1079 npm = 0;
1080 ppm = 0;
1081 epm = 0;
1082 for (lpm = 0x80; lpm; lpm >>= 1) {
1083 if (lpm & data->tbvpm) {
1084 memset(data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1085 memset(&data->cqr, 0, sizeof(data->cqr));
1086 data->cqr.cpaddr = &data->ccw;
1087 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1088 data->rcd_buffer,
1089 lpm);
1090 if (!rc) {
1091 switch (dasd_eckd_path_access(data->rcd_buffer,
1092 DASD_ECKD_RCD_DATA_SIZE)) {
1093 case 0x02:
1094 npm |= lpm;
1095 break;
1096 case 0x03:
1097 ppm |= lpm;
1098 break;
1100 opm |= lpm;
1101 } else if (rc == -EOPNOTSUPP) {
1102 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1103 "path verification: No configuration "
1104 "data retrieved");
1105 opm |= lpm;
1106 } else if (rc == -EAGAIN) {
1107 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1108 "path verification: device is stopped,"
1109 " try again later");
1110 epm |= lpm;
1111 } else {
1112 dev_warn(&device->cdev->dev,
1113 "Reading device feature codes failed "
1114 "(rc=%d) for new path %x\n", rc, lpm);
1115 continue;
1117 if (verify_fcx_max_data(device, lpm)) {
1118 opm &= ~lpm;
1119 npm &= ~lpm;
1120 ppm &= ~lpm;
1125 * There is a small chance that a path is lost again between
1126 * above path verification and the following modification of
1127 * the device opm mask. We could avoid that race here by using
1128 * yet another path mask, but we rather deal with this unlikely
1129 * situation in dasd_start_IO.
1131 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1132 if (!device->path_data.opm && opm) {
1133 device->path_data.opm = opm;
1134 dasd_generic_path_operational(device);
1135 } else
1136 device->path_data.opm |= opm;
1137 device->path_data.npm |= npm;
1138 device->path_data.ppm |= ppm;
1139 device->path_data.tbvpm |= epm;
1140 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1142 dasd_put_device(device);
1143 if (data->isglobal)
1144 mutex_unlock(&dasd_path_verification_mutex);
1145 else
1146 kfree(data);
1149 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1151 struct path_verification_work_data *data;
1153 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1154 if (!data) {
1155 if (mutex_trylock(&dasd_path_verification_mutex)) {
1156 data = path_verification_worker;
1157 data->isglobal = 1;
1158 } else
1159 return -ENOMEM;
1160 } else {
1161 memset(data, 0, sizeof(*data));
1162 data->isglobal = 0;
1164 INIT_WORK(&data->worker, do_path_verification_work);
1165 dasd_get_device(device);
1166 data->device = device;
1167 data->tbvpm = lpm;
1168 schedule_work(&data->worker);
1169 return 0;
1172 static int dasd_eckd_read_features(struct dasd_device *device)
1174 struct dasd_psf_prssd_data *prssdp;
1175 struct dasd_rssd_features *features;
1176 struct dasd_ccw_req *cqr;
1177 struct ccw1 *ccw;
1178 int rc;
1179 struct dasd_eckd_private *private;
1181 private = (struct dasd_eckd_private *) device->private;
1182 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1183 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1184 (sizeof(struct dasd_psf_prssd_data) +
1185 sizeof(struct dasd_rssd_features)),
1186 device);
1187 if (IS_ERR(cqr)) {
1188 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1189 "allocate initialization request");
1190 return PTR_ERR(cqr);
1192 cqr->startdev = device;
1193 cqr->memdev = device;
1194 cqr->block = NULL;
1195 cqr->retries = 256;
1196 cqr->expires = 10 * HZ;
1198 /* Prepare for Read Subsystem Data */
1199 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1200 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1201 prssdp->order = PSF_ORDER_PRSSD;
1202 prssdp->suborder = 0x41; /* Read Feature Codes */
1203 /* all other bytes of prssdp must be zero */
1205 ccw = cqr->cpaddr;
1206 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1207 ccw->count = sizeof(struct dasd_psf_prssd_data);
1208 ccw->flags |= CCW_FLAG_CC;
1209 ccw->cda = (__u32)(addr_t) prssdp;
1211 /* Read Subsystem Data - feature codes */
1212 features = (struct dasd_rssd_features *) (prssdp + 1);
1213 memset(features, 0, sizeof(struct dasd_rssd_features));
1215 ccw++;
1216 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1217 ccw->count = sizeof(struct dasd_rssd_features);
1218 ccw->cda = (__u32)(addr_t) features;
1220 cqr->buildclk = get_clock();
1221 cqr->status = DASD_CQR_FILLED;
1222 rc = dasd_sleep_on(cqr);
1223 if (rc == 0) {
1224 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1225 features = (struct dasd_rssd_features *) (prssdp + 1);
1226 memcpy(&private->features, features,
1227 sizeof(struct dasd_rssd_features));
1228 } else
1229 dev_warn(&device->cdev->dev, "Reading device feature codes"
1230 " failed with rc=%d\n", rc);
1231 dasd_sfree_request(cqr, cqr->memdev);
1232 return rc;
1237 * Build CP for Perform Subsystem Function - SSC.
1239 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1240 int enable_pav)
1242 struct dasd_ccw_req *cqr;
1243 struct dasd_psf_ssc_data *psf_ssc_data;
1244 struct ccw1 *ccw;
1246 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1247 sizeof(struct dasd_psf_ssc_data),
1248 device);
1250 if (IS_ERR(cqr)) {
1251 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1252 "Could not allocate PSF-SSC request");
1253 return cqr;
1255 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1256 psf_ssc_data->order = PSF_ORDER_SSC;
1257 psf_ssc_data->suborder = 0xc0;
1258 if (enable_pav) {
1259 psf_ssc_data->suborder |= 0x08;
1260 psf_ssc_data->reserved[0] = 0x88;
1262 ccw = cqr->cpaddr;
1263 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1264 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1265 ccw->count = 66;
1267 cqr->startdev = device;
1268 cqr->memdev = device;
1269 cqr->block = NULL;
1270 cqr->retries = 256;
1271 cqr->expires = 10*HZ;
1272 cqr->buildclk = get_clock();
1273 cqr->status = DASD_CQR_FILLED;
1274 return cqr;
1278 * Perform Subsystem Function.
1279 * It is necessary to trigger CIO for channel revalidation since this
1280 * call might change behaviour of DASD devices.
1282 static int
1283 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1285 struct dasd_ccw_req *cqr;
1286 int rc;
1288 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1289 if (IS_ERR(cqr))
1290 return PTR_ERR(cqr);
1292 rc = dasd_sleep_on(cqr);
1293 if (!rc)
1294 /* trigger CIO to reprobe devices */
1295 css_schedule_reprobe();
1296 dasd_sfree_request(cqr, cqr->memdev);
1297 return rc;
1301 * Valide storage server of current device.
1303 static void dasd_eckd_validate_server(struct dasd_device *device)
1305 int rc;
1306 struct dasd_eckd_private *private;
1307 int enable_pav;
1309 if (dasd_nopav || MACHINE_IS_VM)
1310 enable_pav = 0;
1311 else
1312 enable_pav = 1;
1313 rc = dasd_eckd_psf_ssc(device, enable_pav);
1315 /* may be requested feature is not available on server,
1316 * therefore just report error and go ahead */
1317 private = (struct dasd_eckd_private *) device->private;
1318 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1319 "returned rc=%d", private->uid.ssid, rc);
1322 static u32 get_fcx_max_data(struct dasd_device *device)
1324 #if defined(CONFIG_64BIT)
1325 int tpm, mdc;
1326 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1327 struct dasd_eckd_private *private;
1329 if (dasd_nofcx)
1330 return 0;
1331 /* is transport mode supported? */
1332 private = (struct dasd_eckd_private *) device->private;
1333 fcx_in_css = css_general_characteristics.fcx;
1334 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1335 fcx_in_features = private->features.feature[40] & 0x80;
1336 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1338 if (!tpm)
1339 return 0;
1341 mdc = ccw_device_get_mdc(device->cdev, 0);
1342 if (mdc < 0) {
1343 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1344 " data size for zHPF requests failed\n");
1345 return 0;
1346 } else
1347 return mdc * FCX_MAX_DATA_FACTOR;
1348 #else
1349 return 0;
1350 #endif
1354 * Check device characteristics.
1355 * If the device is accessible using ECKD discipline, the device is enabled.
1357 static int
1358 dasd_eckd_check_characteristics(struct dasd_device *device)
1360 struct dasd_eckd_private *private;
1361 struct dasd_block *block;
1362 struct dasd_uid temp_uid;
1363 int is_known, rc, i;
1364 int readonly;
1365 unsigned long value;
1367 if (!ccw_device_is_pathgroup(device->cdev)) {
1368 dev_warn(&device->cdev->dev,
1369 "A channel path group could not be established\n");
1370 return -EIO;
1372 if (!ccw_device_is_multipath(device->cdev)) {
1373 dev_info(&device->cdev->dev,
1374 "The DASD is not operating in multipath mode\n");
1376 private = (struct dasd_eckd_private *) device->private;
1377 if (!private) {
1378 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1379 if (!private) {
1380 dev_warn(&device->cdev->dev,
1381 "Allocating memory for private DASD data "
1382 "failed\n");
1383 return -ENOMEM;
1385 device->private = (void *) private;
1386 } else {
1387 memset(private, 0, sizeof(*private));
1389 /* Invalidate status of initial analysis. */
1390 private->init_cqr_status = -1;
1391 /* Set default cache operations. */
1392 private->attrib.operation = DASD_NORMAL_CACHE;
1393 private->attrib.nr_cyl = 0;
1395 /* Read Configuration Data */
1396 rc = dasd_eckd_read_conf(device);
1397 if (rc)
1398 goto out_err1;
1400 /* set default timeout */
1401 device->default_expires = DASD_EXPIRES;
1402 if (private->gneq) {
1403 value = 1;
1404 for (i = 0; i < private->gneq->timeout.value; i++)
1405 value = 10 * value;
1406 value = value * private->gneq->timeout.number;
1407 /* do not accept useless values */
1408 if (value != 0 && value <= DASD_EXPIRES_MAX)
1409 device->default_expires = value;
1412 /* Generate device unique id */
1413 rc = dasd_eckd_generate_uid(device);
1414 if (rc)
1415 goto out_err1;
1417 dasd_eckd_get_uid(device, &temp_uid);
1418 if (temp_uid.type == UA_BASE_DEVICE) {
1419 block = dasd_alloc_block();
1420 if (IS_ERR(block)) {
1421 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1422 "could not allocate dasd "
1423 "block structure");
1424 rc = PTR_ERR(block);
1425 goto out_err1;
1427 device->block = block;
1428 block->base = device;
1431 /* register lcu with alias handling, enable PAV if this is a new lcu */
1432 is_known = dasd_alias_make_device_known_to_lcu(device);
1433 if (is_known < 0) {
1434 rc = is_known;
1435 goto out_err2;
1438 * dasd_eckd_validate_server is done on the first device that
1439 * is found for an LCU. All later other devices have to wait
1440 * for it, so they will read the correct feature codes.
1442 if (!is_known) {
1443 dasd_eckd_validate_server(device);
1444 dasd_alias_lcu_setup_complete(device);
1445 } else
1446 dasd_alias_wait_for_lcu_setup(device);
1448 /* device may report different configuration data after LCU setup */
1449 rc = dasd_eckd_read_conf(device);
1450 if (rc)
1451 goto out_err3;
1453 /* Read Feature Codes */
1454 dasd_eckd_read_features(device);
1456 /* Read Device Characteristics */
1457 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1458 &private->rdc_data, 64);
1459 if (rc) {
1460 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1461 "Read device characteristic failed, rc=%d", rc);
1462 goto out_err3;
1464 /* find the valid cylinder size */
1465 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1466 private->rdc_data.long_no_cyl)
1467 private->real_cyl = private->rdc_data.long_no_cyl;
1468 else
1469 private->real_cyl = private->rdc_data.no_cyl;
1471 private->fcx_max_data = get_fcx_max_data(device);
1473 readonly = dasd_device_is_ro(device);
1474 if (readonly)
1475 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1477 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1478 "with %d cylinders, %d heads, %d sectors%s\n",
1479 private->rdc_data.dev_type,
1480 private->rdc_data.dev_model,
1481 private->rdc_data.cu_type,
1482 private->rdc_data.cu_model.model,
1483 private->real_cyl,
1484 private->rdc_data.trk_per_cyl,
1485 private->rdc_data.sec_per_trk,
1486 readonly ? ", read-only device" : "");
1487 return 0;
1489 out_err3:
1490 dasd_alias_disconnect_device_from_lcu(device);
1491 out_err2:
1492 dasd_free_block(device->block);
1493 device->block = NULL;
1494 out_err1:
1495 kfree(private->conf_data);
1496 kfree(device->private);
1497 device->private = NULL;
1498 return rc;
1501 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1503 struct dasd_eckd_private *private;
1505 private = (struct dasd_eckd_private *) device->private;
1506 dasd_alias_disconnect_device_from_lcu(device);
1507 private->ned = NULL;
1508 private->sneq = NULL;
1509 private->vdsneq = NULL;
1510 private->gneq = NULL;
1511 private->conf_len = 0;
1512 kfree(private->conf_data);
1513 private->conf_data = NULL;
1516 static struct dasd_ccw_req *
1517 dasd_eckd_analysis_ccw(struct dasd_device *device)
1519 struct dasd_eckd_private *private;
1520 struct eckd_count *count_data;
1521 struct LO_eckd_data *LO_data;
1522 struct dasd_ccw_req *cqr;
1523 struct ccw1 *ccw;
1524 int cplength, datasize;
1525 int i;
1527 private = (struct dasd_eckd_private *) device->private;
1529 cplength = 8;
1530 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1531 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1532 if (IS_ERR(cqr))
1533 return cqr;
1534 ccw = cqr->cpaddr;
1535 /* Define extent for the first 3 tracks. */
1536 define_extent(ccw++, cqr->data, 0, 2,
1537 DASD_ECKD_CCW_READ_COUNT, device);
1538 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1539 /* Locate record for the first 4 records on track 0. */
1540 ccw[-1].flags |= CCW_FLAG_CC;
1541 locate_record(ccw++, LO_data++, 0, 0, 4,
1542 DASD_ECKD_CCW_READ_COUNT, device, 0);
1544 count_data = private->count_area;
1545 for (i = 0; i < 4; i++) {
1546 ccw[-1].flags |= CCW_FLAG_CC;
1547 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1548 ccw->flags = 0;
1549 ccw->count = 8;
1550 ccw->cda = (__u32)(addr_t) count_data;
1551 ccw++;
1552 count_data++;
1555 /* Locate record for the first record on track 2. */
1556 ccw[-1].flags |= CCW_FLAG_CC;
1557 locate_record(ccw++, LO_data++, 2, 0, 1,
1558 DASD_ECKD_CCW_READ_COUNT, device, 0);
1559 /* Read count ccw. */
1560 ccw[-1].flags |= CCW_FLAG_CC;
1561 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1562 ccw->flags = 0;
1563 ccw->count = 8;
1564 ccw->cda = (__u32)(addr_t) count_data;
1566 cqr->block = NULL;
1567 cqr->startdev = device;
1568 cqr->memdev = device;
1569 cqr->retries = 255;
1570 cqr->buildclk = get_clock();
1571 cqr->status = DASD_CQR_FILLED;
1572 return cqr;
1575 /* differentiate between 'no record found' and any other error */
1576 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1578 char *sense;
1579 if (init_cqr->status == DASD_CQR_DONE)
1580 return INIT_CQR_OK;
1581 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1582 init_cqr->status == DASD_CQR_FAILED) {
1583 sense = dasd_get_sense(&init_cqr->irb);
1584 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1585 return INIT_CQR_UNFORMATTED;
1586 else
1587 return INIT_CQR_ERROR;
1588 } else
1589 return INIT_CQR_ERROR;
1593 * This is the callback function for the init_analysis cqr. It saves
1594 * the status of the initial analysis ccw before it frees it and kicks
1595 * the device to continue the startup sequence. This will call
1596 * dasd_eckd_do_analysis again (if the devices has not been marked
1597 * for deletion in the meantime).
1599 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1600 void *data)
1602 struct dasd_eckd_private *private;
1603 struct dasd_device *device;
1605 device = init_cqr->startdev;
1606 private = (struct dasd_eckd_private *) device->private;
1607 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1608 dasd_sfree_request(init_cqr, device);
1609 dasd_kick_device(device);
1612 static int dasd_eckd_start_analysis(struct dasd_block *block)
1614 struct dasd_eckd_private *private;
1615 struct dasd_ccw_req *init_cqr;
1617 private = (struct dasd_eckd_private *) block->base->private;
1618 init_cqr = dasd_eckd_analysis_ccw(block->base);
1619 if (IS_ERR(init_cqr))
1620 return PTR_ERR(init_cqr);
1621 init_cqr->callback = dasd_eckd_analysis_callback;
1622 init_cqr->callback_data = NULL;
1623 init_cqr->expires = 5*HZ;
1624 /* first try without ERP, so we can later handle unformatted
1625 * devices as special case
1627 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1628 init_cqr->retries = 0;
1629 dasd_add_request_head(init_cqr);
1630 return -EAGAIN;
1633 static int dasd_eckd_end_analysis(struct dasd_block *block)
1635 struct dasd_device *device;
1636 struct dasd_eckd_private *private;
1637 struct eckd_count *count_area;
1638 unsigned int sb, blk_per_trk;
1639 int status, i;
1640 struct dasd_ccw_req *init_cqr;
1642 device = block->base;
1643 private = (struct dasd_eckd_private *) device->private;
1644 status = private->init_cqr_status;
1645 private->init_cqr_status = -1;
1646 if (status == INIT_CQR_ERROR) {
1647 /* try again, this time with full ERP */
1648 init_cqr = dasd_eckd_analysis_ccw(device);
1649 dasd_sleep_on(init_cqr);
1650 status = dasd_eckd_analysis_evaluation(init_cqr);
1651 dasd_sfree_request(init_cqr, device);
1654 if (device->features & DASD_FEATURE_USERAW) {
1655 block->bp_block = DASD_RAW_BLOCKSIZE;
1656 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1657 block->s2b_shift = 3;
1658 goto raw;
1661 if (status == INIT_CQR_UNFORMATTED) {
1662 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1663 return -EMEDIUMTYPE;
1664 } else if (status == INIT_CQR_ERROR) {
1665 dev_err(&device->cdev->dev,
1666 "Detecting the DASD disk layout failed because "
1667 "of an I/O error\n");
1668 return -EIO;
1671 private->uses_cdl = 1;
1672 /* Check Track 0 for Compatible Disk Layout */
1673 count_area = NULL;
1674 for (i = 0; i < 3; i++) {
1675 if (private->count_area[i].kl != 4 ||
1676 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1677 private->uses_cdl = 0;
1678 break;
1681 if (i == 3)
1682 count_area = &private->count_area[4];
1684 if (private->uses_cdl == 0) {
1685 for (i = 0; i < 5; i++) {
1686 if ((private->count_area[i].kl != 0) ||
1687 (private->count_area[i].dl !=
1688 private->count_area[0].dl))
1689 break;
1691 if (i == 5)
1692 count_area = &private->count_area[0];
1693 } else {
1694 if (private->count_area[3].record == 1)
1695 dev_warn(&device->cdev->dev,
1696 "Track 0 has no records following the VTOC\n");
1699 if (count_area != NULL && count_area->kl == 0) {
1700 /* we found notthing violating our disk layout */
1701 if (dasd_check_blocksize(count_area->dl) == 0)
1702 block->bp_block = count_area->dl;
1704 if (block->bp_block == 0) {
1705 dev_warn(&device->cdev->dev,
1706 "The disk layout of the DASD is not supported\n");
1707 return -EMEDIUMTYPE;
1709 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1710 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1711 block->s2b_shift++;
1713 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1715 raw:
1716 block->blocks = (private->real_cyl *
1717 private->rdc_data.trk_per_cyl *
1718 blk_per_trk);
1720 dev_info(&device->cdev->dev,
1721 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1722 "%s\n", (block->bp_block >> 10),
1723 ((private->real_cyl *
1724 private->rdc_data.trk_per_cyl *
1725 blk_per_trk * (block->bp_block >> 9)) >> 1),
1726 ((blk_per_trk * block->bp_block) >> 10),
1727 private->uses_cdl ?
1728 "compatible disk layout" : "linux disk layout");
1730 return 0;
1733 static int dasd_eckd_do_analysis(struct dasd_block *block)
1735 struct dasd_eckd_private *private;
1737 private = (struct dasd_eckd_private *) block->base->private;
1738 if (private->init_cqr_status < 0)
1739 return dasd_eckd_start_analysis(block);
1740 else
1741 return dasd_eckd_end_analysis(block);
1744 static int dasd_eckd_ready_to_online(struct dasd_device *device)
1746 return dasd_alias_add_device(device);
1749 static int dasd_eckd_online_to_ready(struct dasd_device *device)
1751 cancel_work_sync(&device->reload_device);
1752 return dasd_alias_remove_device(device);
1755 static int
1756 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1758 struct dasd_eckd_private *private;
1760 private = (struct dasd_eckd_private *) block->base->private;
1761 if (dasd_check_blocksize(block->bp_block) == 0) {
1762 geo->sectors = recs_per_track(&private->rdc_data,
1763 0, block->bp_block);
1765 geo->cylinders = private->rdc_data.no_cyl;
1766 geo->heads = private->rdc_data.trk_per_cyl;
1767 return 0;
1770 static struct dasd_ccw_req *
1771 dasd_eckd_format_device(struct dasd_device * device,
1772 struct format_data_t * fdata)
1774 struct dasd_eckd_private *private;
1775 struct dasd_ccw_req *fcp;
1776 struct eckd_count *ect;
1777 struct ccw1 *ccw;
1778 void *data;
1779 int rpt;
1780 struct ch_t address;
1781 int cplength, datasize;
1782 int i;
1783 int intensity = 0;
1784 int r0_perm;
1786 private = (struct dasd_eckd_private *) device->private;
1787 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1788 set_ch_t(&address,
1789 fdata->start_unit / private->rdc_data.trk_per_cyl,
1790 fdata->start_unit % private->rdc_data.trk_per_cyl);
1792 /* Sanity checks. */
1793 if (fdata->start_unit >=
1794 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
1795 dev_warn(&device->cdev->dev, "Start track number %d used in "
1796 "formatting is too big\n", fdata->start_unit);
1797 return ERR_PTR(-EINVAL);
1799 if (fdata->start_unit > fdata->stop_unit) {
1800 dev_warn(&device->cdev->dev, "Start track %d used in "
1801 "formatting exceeds end track\n", fdata->start_unit);
1802 return ERR_PTR(-EINVAL);
1804 if (dasd_check_blocksize(fdata->blksize) != 0) {
1805 dev_warn(&device->cdev->dev,
1806 "The DASD cannot be formatted with block size %d\n",
1807 fdata->blksize);
1808 return ERR_PTR(-EINVAL);
1812 * fdata->intensity is a bit string that tells us what to do:
1813 * Bit 0: write record zero
1814 * Bit 1: write home address, currently not supported
1815 * Bit 2: invalidate tracks
1816 * Bit 3: use OS/390 compatible disk layout (cdl)
1817 * Bit 4: do not allow storage subsystem to modify record zero
1818 * Only some bit combinations do make sense.
1820 if (fdata->intensity & 0x10) {
1821 r0_perm = 0;
1822 intensity = fdata->intensity & ~0x10;
1823 } else {
1824 r0_perm = 1;
1825 intensity = fdata->intensity;
1827 switch (intensity) {
1828 case 0x00: /* Normal format */
1829 case 0x08: /* Normal format, use cdl. */
1830 cplength = 2 + rpt;
1831 datasize = sizeof(struct DE_eckd_data) +
1832 sizeof(struct LO_eckd_data) +
1833 rpt * sizeof(struct eckd_count);
1834 break;
1835 case 0x01: /* Write record zero and format track. */
1836 case 0x09: /* Write record zero and format track, use cdl. */
1837 cplength = 3 + rpt;
1838 datasize = sizeof(struct DE_eckd_data) +
1839 sizeof(struct LO_eckd_data) +
1840 sizeof(struct eckd_count) +
1841 rpt * sizeof(struct eckd_count);
1842 break;
1843 case 0x04: /* Invalidate track. */
1844 case 0x0c: /* Invalidate track, use cdl. */
1845 cplength = 3;
1846 datasize = sizeof(struct DE_eckd_data) +
1847 sizeof(struct LO_eckd_data) +
1848 sizeof(struct eckd_count);
1849 break;
1850 default:
1851 dev_warn(&device->cdev->dev, "An I/O control call used "
1852 "incorrect flags 0x%x\n", fdata->intensity);
1853 return ERR_PTR(-EINVAL);
1855 /* Allocate the format ccw request. */
1856 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1857 if (IS_ERR(fcp))
1858 return fcp;
1860 data = fcp->data;
1861 ccw = fcp->cpaddr;
1863 switch (intensity & ~0x08) {
1864 case 0x00: /* Normal format. */
1865 define_extent(ccw++, (struct DE_eckd_data *) data,
1866 fdata->start_unit, fdata->start_unit,
1867 DASD_ECKD_CCW_WRITE_CKD, device);
1868 /* grant subsystem permission to format R0 */
1869 if (r0_perm)
1870 ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
1871 data += sizeof(struct DE_eckd_data);
1872 ccw[-1].flags |= CCW_FLAG_CC;
1873 locate_record(ccw++, (struct LO_eckd_data *) data,
1874 fdata->start_unit, 0, rpt,
1875 DASD_ECKD_CCW_WRITE_CKD, device,
1876 fdata->blksize);
1877 data += sizeof(struct LO_eckd_data);
1878 break;
1879 case 0x01: /* Write record zero + format track. */
1880 define_extent(ccw++, (struct DE_eckd_data *) data,
1881 fdata->start_unit, fdata->start_unit,
1882 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1883 device);
1884 data += sizeof(struct DE_eckd_data);
1885 ccw[-1].flags |= CCW_FLAG_CC;
1886 locate_record(ccw++, (struct LO_eckd_data *) data,
1887 fdata->start_unit, 0, rpt + 1,
1888 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1889 device->block->bp_block);
1890 data += sizeof(struct LO_eckd_data);
1891 break;
1892 case 0x04: /* Invalidate track. */
1893 define_extent(ccw++, (struct DE_eckd_data *) data,
1894 fdata->start_unit, fdata->start_unit,
1895 DASD_ECKD_CCW_WRITE_CKD, device);
1896 data += sizeof(struct DE_eckd_data);
1897 ccw[-1].flags |= CCW_FLAG_CC;
1898 locate_record(ccw++, (struct LO_eckd_data *) data,
1899 fdata->start_unit, 0, 1,
1900 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1901 data += sizeof(struct LO_eckd_data);
1902 break;
1904 if (intensity & 0x01) { /* write record zero */
1905 ect = (struct eckd_count *) data;
1906 data += sizeof(struct eckd_count);
1907 ect->cyl = address.cyl;
1908 ect->head = address.head;
1909 ect->record = 0;
1910 ect->kl = 0;
1911 ect->dl = 8;
1912 ccw[-1].flags |= CCW_FLAG_CC;
1913 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1914 ccw->flags = CCW_FLAG_SLI;
1915 ccw->count = 8;
1916 ccw->cda = (__u32)(addr_t) ect;
1917 ccw++;
1919 if ((intensity & ~0x08) & 0x04) { /* erase track */
1920 ect = (struct eckd_count *) data;
1921 data += sizeof(struct eckd_count);
1922 ect->cyl = address.cyl;
1923 ect->head = address.head;
1924 ect->record = 1;
1925 ect->kl = 0;
1926 ect->dl = 0;
1927 ccw[-1].flags |= CCW_FLAG_CC;
1928 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1929 ccw->flags = CCW_FLAG_SLI;
1930 ccw->count = 8;
1931 ccw->cda = (__u32)(addr_t) ect;
1932 } else { /* write remaining records */
1933 for (i = 0; i < rpt; i++) {
1934 ect = (struct eckd_count *) data;
1935 data += sizeof(struct eckd_count);
1936 ect->cyl = address.cyl;
1937 ect->head = address.head;
1938 ect->record = i + 1;
1939 ect->kl = 0;
1940 ect->dl = fdata->blksize;
1941 /* Check for special tracks 0-1 when formatting CDL */
1942 if ((intensity & 0x08) &&
1943 fdata->start_unit == 0) {
1944 if (i < 3) {
1945 ect->kl = 4;
1946 ect->dl = sizes_trk0[i] - 4;
1949 if ((intensity & 0x08) &&
1950 fdata->start_unit == 1) {
1951 ect->kl = 44;
1952 ect->dl = LABEL_SIZE - 44;
1954 ccw[-1].flags |= CCW_FLAG_CC;
1955 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1956 ccw->flags = CCW_FLAG_SLI;
1957 ccw->count = 8;
1958 ccw->cda = (__u32)(addr_t) ect;
1959 ccw++;
1962 fcp->startdev = device;
1963 fcp->memdev = device;
1964 fcp->retries = 256;
1965 fcp->buildclk = get_clock();
1966 fcp->status = DASD_CQR_FILLED;
1967 return fcp;
1970 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
1972 cqr->status = DASD_CQR_FILLED;
1973 if (cqr->block && (cqr->startdev != cqr->block->base)) {
1974 dasd_eckd_reset_ccw_to_base_io(cqr);
1975 cqr->startdev = cqr->block->base;
1976 cqr->lpm = cqr->block->base->path_data.opm;
1980 static dasd_erp_fn_t
1981 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1983 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
1984 struct ccw_device *cdev = device->cdev;
1986 switch (cdev->id.cu_type) {
1987 case 0x3990:
1988 case 0x2105:
1989 case 0x2107:
1990 case 0x1750:
1991 return dasd_3990_erp_action;
1992 case 0x9343:
1993 case 0x3880:
1994 default:
1995 return dasd_default_erp_action;
1999 static dasd_erp_fn_t
2000 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2002 return dasd_default_erp_postaction;
2005 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2006 struct dasd_ccw_req *cqr,
2007 struct irb *irb)
2009 char mask;
2010 char *sense = NULL;
2011 struct dasd_eckd_private *private;
2013 private = (struct dasd_eckd_private *) device->private;
2014 /* first of all check for state change pending interrupt */
2015 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
2016 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
2017 /* for alias only and not in offline processing*/
2018 if (!device->block && private->lcu &&
2019 !test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2021 * the state change could be caused by an alias
2022 * reassignment remove device from alias handling
2023 * to prevent new requests from being scheduled on
2024 * the wrong alias device
2026 dasd_alias_remove_device(device);
2028 /* schedule worker to reload device */
2029 dasd_reload_device(device);
2031 dasd_generic_handle_state_change(device);
2032 return;
2035 sense = dasd_get_sense(irb);
2036 if (!sense)
2037 return;
2039 /* summary unit check */
2040 if ((sense[7] == 0x0D) &&
2041 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
2042 dasd_alias_handle_summary_unit_check(device, irb);
2043 return;
2046 /* service information message SIM */
2047 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
2048 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2049 dasd_3990_erp_handle_sim(device, sense);
2050 return;
2053 /* loss of device reservation is handled via base devices only
2054 * as alias devices may be used with several bases
2056 if (device->block && (sense[7] == 0x3F) &&
2057 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2058 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2059 if (device->features & DASD_FEATURE_FAILONSLCK)
2060 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2061 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2062 dev_err(&device->cdev->dev,
2063 "The device reservation was lost\n");
2067 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2068 struct dasd_device *startdev,
2069 struct dasd_block *block,
2070 struct request *req,
2071 sector_t first_rec,
2072 sector_t last_rec,
2073 sector_t first_trk,
2074 sector_t last_trk,
2075 unsigned int first_offs,
2076 unsigned int last_offs,
2077 unsigned int blk_per_trk,
2078 unsigned int blksize)
2080 struct dasd_eckd_private *private;
2081 unsigned long *idaws;
2082 struct LO_eckd_data *LO_data;
2083 struct dasd_ccw_req *cqr;
2084 struct ccw1 *ccw;
2085 struct req_iterator iter;
2086 struct bio_vec *bv;
2087 char *dst;
2088 unsigned int off;
2089 int count, cidaw, cplength, datasize;
2090 sector_t recid;
2091 unsigned char cmd, rcmd;
2092 int use_prefix;
2093 struct dasd_device *basedev;
2095 basedev = block->base;
2096 private = (struct dasd_eckd_private *) basedev->private;
2097 if (rq_data_dir(req) == READ)
2098 cmd = DASD_ECKD_CCW_READ_MT;
2099 else if (rq_data_dir(req) == WRITE)
2100 cmd = DASD_ECKD_CCW_WRITE_MT;
2101 else
2102 return ERR_PTR(-EINVAL);
2104 /* Check struct bio and count the number of blocks for the request. */
2105 count = 0;
2106 cidaw = 0;
2107 rq_for_each_segment(bv, req, iter) {
2108 if (bv->bv_len & (blksize - 1))
2109 /* Eckd can only do full blocks. */
2110 return ERR_PTR(-EINVAL);
2111 count += bv->bv_len >> (block->s2b_shift + 9);
2112 #if defined(CONFIG_64BIT)
2113 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
2114 cidaw += bv->bv_len >> (block->s2b_shift + 9);
2115 #endif
2117 /* Paranoia. */
2118 if (count != last_rec - first_rec + 1)
2119 return ERR_PTR(-EINVAL);
2121 /* use the prefix command if available */
2122 use_prefix = private->features.feature[8] & 0x01;
2123 if (use_prefix) {
2124 /* 1x prefix + number of blocks */
2125 cplength = 2 + count;
2126 /* 1x prefix + cidaws*sizeof(long) */
2127 datasize = sizeof(struct PFX_eckd_data) +
2128 sizeof(struct LO_eckd_data) +
2129 cidaw * sizeof(unsigned long);
2130 } else {
2131 /* 1x define extent + 1x locate record + number of blocks */
2132 cplength = 2 + count;
2133 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2134 datasize = sizeof(struct DE_eckd_data) +
2135 sizeof(struct LO_eckd_data) +
2136 cidaw * sizeof(unsigned long);
2138 /* Find out the number of additional locate record ccws for cdl. */
2139 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2140 if (last_rec >= 2*blk_per_trk)
2141 count = 2*blk_per_trk - first_rec;
2142 cplength += count;
2143 datasize += count*sizeof(struct LO_eckd_data);
2145 /* Allocate the ccw request. */
2146 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2147 startdev);
2148 if (IS_ERR(cqr))
2149 return cqr;
2150 ccw = cqr->cpaddr;
2151 /* First ccw is define extent or prefix. */
2152 if (use_prefix) {
2153 if (prefix(ccw++, cqr->data, first_trk,
2154 last_trk, cmd, basedev, startdev) == -EAGAIN) {
2155 /* Clock not in sync and XRC is enabled.
2156 * Try again later.
2158 dasd_sfree_request(cqr, startdev);
2159 return ERR_PTR(-EAGAIN);
2161 idaws = (unsigned long *) (cqr->data +
2162 sizeof(struct PFX_eckd_data));
2163 } else {
2164 if (define_extent(ccw++, cqr->data, first_trk,
2165 last_trk, cmd, startdev) == -EAGAIN) {
2166 /* Clock not in sync and XRC is enabled.
2167 * Try again later.
2169 dasd_sfree_request(cqr, startdev);
2170 return ERR_PTR(-EAGAIN);
2172 idaws = (unsigned long *) (cqr->data +
2173 sizeof(struct DE_eckd_data));
2175 /* Build locate_record+read/write/ccws. */
2176 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2177 recid = first_rec;
2178 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2179 /* Only standard blocks so there is just one locate record. */
2180 ccw[-1].flags |= CCW_FLAG_CC;
2181 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
2182 last_rec - recid + 1, cmd, basedev, blksize);
2184 rq_for_each_segment(bv, req, iter) {
2185 dst = page_address(bv->bv_page) + bv->bv_offset;
2186 if (dasd_page_cache) {
2187 char *copy = kmem_cache_alloc(dasd_page_cache,
2188 GFP_DMA | __GFP_NOWARN);
2189 if (copy && rq_data_dir(req) == WRITE)
2190 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
2191 if (copy)
2192 dst = copy + bv->bv_offset;
2194 for (off = 0; off < bv->bv_len; off += blksize) {
2195 sector_t trkid = recid;
2196 unsigned int recoffs = sector_div(trkid, blk_per_trk);
2197 rcmd = cmd;
2198 count = blksize;
2199 /* Locate record for cdl special block ? */
2200 if (private->uses_cdl && recid < 2*blk_per_trk) {
2201 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2202 rcmd |= 0x8;
2203 count = dasd_eckd_cdl_reclen(recid);
2204 if (count < blksize &&
2205 rq_data_dir(req) == READ)
2206 memset(dst + count, 0xe5,
2207 blksize - count);
2209 ccw[-1].flags |= CCW_FLAG_CC;
2210 locate_record(ccw++, LO_data++,
2211 trkid, recoffs + 1,
2212 1, rcmd, basedev, count);
2214 /* Locate record for standard blocks ? */
2215 if (private->uses_cdl && recid == 2*blk_per_trk) {
2216 ccw[-1].flags |= CCW_FLAG_CC;
2217 locate_record(ccw++, LO_data++,
2218 trkid, recoffs + 1,
2219 last_rec - recid + 1,
2220 cmd, basedev, count);
2222 /* Read/write ccw. */
2223 ccw[-1].flags |= CCW_FLAG_CC;
2224 ccw->cmd_code = rcmd;
2225 ccw->count = count;
2226 if (idal_is_needed(dst, blksize)) {
2227 ccw->cda = (__u32)(addr_t) idaws;
2228 ccw->flags = CCW_FLAG_IDA;
2229 idaws = idal_create_words(idaws, dst, blksize);
2230 } else {
2231 ccw->cda = (__u32)(addr_t) dst;
2232 ccw->flags = 0;
2234 ccw++;
2235 dst += blksize;
2236 recid++;
2239 if (blk_noretry_request(req) ||
2240 block->base->features & DASD_FEATURE_FAILFAST)
2241 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2242 cqr->startdev = startdev;
2243 cqr->memdev = startdev;
2244 cqr->block = block;
2245 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2246 cqr->lpm = startdev->path_data.ppm;
2247 cqr->retries = 256;
2248 cqr->buildclk = get_clock();
2249 cqr->status = DASD_CQR_FILLED;
2250 return cqr;
2253 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2254 struct dasd_device *startdev,
2255 struct dasd_block *block,
2256 struct request *req,
2257 sector_t first_rec,
2258 sector_t last_rec,
2259 sector_t first_trk,
2260 sector_t last_trk,
2261 unsigned int first_offs,
2262 unsigned int last_offs,
2263 unsigned int blk_per_trk,
2264 unsigned int blksize)
2266 struct dasd_eckd_private *private;
2267 unsigned long *idaws;
2268 struct dasd_ccw_req *cqr;
2269 struct ccw1 *ccw;
2270 struct req_iterator iter;
2271 struct bio_vec *bv;
2272 char *dst, *idaw_dst;
2273 unsigned int cidaw, cplength, datasize;
2274 unsigned int tlf;
2275 sector_t recid;
2276 unsigned char cmd;
2277 struct dasd_device *basedev;
2278 unsigned int trkcount, count, count_to_trk_end;
2279 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2280 unsigned char new_track, end_idaw;
2281 sector_t trkid;
2282 unsigned int recoffs;
2284 basedev = block->base;
2285 private = (struct dasd_eckd_private *) basedev->private;
2286 if (rq_data_dir(req) == READ)
2287 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2288 else if (rq_data_dir(req) == WRITE)
2289 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2290 else
2291 return ERR_PTR(-EINVAL);
2293 /* Track based I/O needs IDAWs for each page, and not just for
2294 * 64 bit addresses. We need additional idals for pages
2295 * that get filled from two tracks, so we use the number
2296 * of records as upper limit.
2298 cidaw = last_rec - first_rec + 1;
2299 trkcount = last_trk - first_trk + 1;
2301 /* 1x prefix + one read/write ccw per track */
2302 cplength = 1 + trkcount;
2304 /* on 31-bit we need space for two 32 bit addresses per page
2305 * on 64-bit one 64 bit address
2307 datasize = sizeof(struct PFX_eckd_data) +
2308 cidaw * sizeof(unsigned long long);
2310 /* Allocate the ccw request. */
2311 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2312 startdev);
2313 if (IS_ERR(cqr))
2314 return cqr;
2315 ccw = cqr->cpaddr;
2316 /* transfer length factor: how many bytes to read from the last track */
2317 if (first_trk == last_trk)
2318 tlf = last_offs - first_offs + 1;
2319 else
2320 tlf = last_offs + 1;
2321 tlf *= blksize;
2323 if (prefix_LRE(ccw++, cqr->data, first_trk,
2324 last_trk, cmd, basedev, startdev,
2325 1 /* format */, first_offs + 1,
2326 trkcount, blksize,
2327 tlf) == -EAGAIN) {
2328 /* Clock not in sync and XRC is enabled.
2329 * Try again later.
2331 dasd_sfree_request(cqr, startdev);
2332 return ERR_PTR(-EAGAIN);
2336 * The translation of request into ccw programs must meet the
2337 * following conditions:
2338 * - all idaws but the first and the last must address full pages
2339 * (or 2K blocks on 31-bit)
2340 * - the scope of a ccw and it's idal ends with the track boundaries
2342 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2343 recid = first_rec;
2344 new_track = 1;
2345 end_idaw = 0;
2346 len_to_track_end = 0;
2347 idaw_dst = 0;
2348 idaw_len = 0;
2349 rq_for_each_segment(bv, req, iter) {
2350 dst = page_address(bv->bv_page) + bv->bv_offset;
2351 seg_len = bv->bv_len;
2352 while (seg_len) {
2353 if (new_track) {
2354 trkid = recid;
2355 recoffs = sector_div(trkid, blk_per_trk);
2356 count_to_trk_end = blk_per_trk - recoffs;
2357 count = min((last_rec - recid + 1),
2358 (sector_t)count_to_trk_end);
2359 len_to_track_end = count * blksize;
2360 ccw[-1].flags |= CCW_FLAG_CC;
2361 ccw->cmd_code = cmd;
2362 ccw->count = len_to_track_end;
2363 ccw->cda = (__u32)(addr_t)idaws;
2364 ccw->flags = CCW_FLAG_IDA;
2365 ccw++;
2366 recid += count;
2367 new_track = 0;
2368 /* first idaw for a ccw may start anywhere */
2369 if (!idaw_dst)
2370 idaw_dst = dst;
2372 /* If we start a new idaw, we must make sure that it
2373 * starts on an IDA_BLOCK_SIZE boundary.
2374 * If we continue an idaw, we must make sure that the
2375 * current segment begins where the so far accumulated
2376 * idaw ends
2378 if (!idaw_dst) {
2379 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2380 dasd_sfree_request(cqr, startdev);
2381 return ERR_PTR(-ERANGE);
2382 } else
2383 idaw_dst = dst;
2385 if ((idaw_dst + idaw_len) != dst) {
2386 dasd_sfree_request(cqr, startdev);
2387 return ERR_PTR(-ERANGE);
2389 part_len = min(seg_len, len_to_track_end);
2390 seg_len -= part_len;
2391 dst += part_len;
2392 idaw_len += part_len;
2393 len_to_track_end -= part_len;
2394 /* collected memory area ends on an IDA_BLOCK border,
2395 * -> create an idaw
2396 * idal_create_words will handle cases where idaw_len
2397 * is larger then IDA_BLOCK_SIZE
2399 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2400 end_idaw = 1;
2401 /* We also need to end the idaw at track end */
2402 if (!len_to_track_end) {
2403 new_track = 1;
2404 end_idaw = 1;
2406 if (end_idaw) {
2407 idaws = idal_create_words(idaws, idaw_dst,
2408 idaw_len);
2409 idaw_dst = 0;
2410 idaw_len = 0;
2411 end_idaw = 0;
2416 if (blk_noretry_request(req) ||
2417 block->base->features & DASD_FEATURE_FAILFAST)
2418 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2419 cqr->startdev = startdev;
2420 cqr->memdev = startdev;
2421 cqr->block = block;
2422 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2423 cqr->lpm = startdev->path_data.ppm;
2424 cqr->retries = 256;
2425 cqr->buildclk = get_clock();
2426 cqr->status = DASD_CQR_FILLED;
2427 return cqr;
2430 static int prepare_itcw(struct itcw *itcw,
2431 unsigned int trk, unsigned int totrk, int cmd,
2432 struct dasd_device *basedev,
2433 struct dasd_device *startdev,
2434 unsigned int rec_on_trk, int count,
2435 unsigned int blksize,
2436 unsigned int total_data_size,
2437 unsigned int tlf,
2438 unsigned int blk_per_trk)
2440 struct PFX_eckd_data pfxdata;
2441 struct dasd_eckd_private *basepriv, *startpriv;
2442 struct DE_eckd_data *dedata;
2443 struct LRE_eckd_data *lredata;
2444 struct dcw *dcw;
2446 u32 begcyl, endcyl;
2447 u16 heads, beghead, endhead;
2448 u8 pfx_cmd;
2450 int rc = 0;
2451 int sector = 0;
2452 int dn, d;
2455 /* setup prefix data */
2456 basepriv = (struct dasd_eckd_private *) basedev->private;
2457 startpriv = (struct dasd_eckd_private *) startdev->private;
2458 dedata = &pfxdata.define_extent;
2459 lredata = &pfxdata.locate_record;
2461 memset(&pfxdata, 0, sizeof(pfxdata));
2462 pfxdata.format = 1; /* PFX with LRE */
2463 pfxdata.base_address = basepriv->ned->unit_addr;
2464 pfxdata.base_lss = basepriv->ned->ID;
2465 pfxdata.validity.define_extent = 1;
2467 /* private uid is kept up to date, conf_data may be outdated */
2468 if (startpriv->uid.type != UA_BASE_DEVICE) {
2469 pfxdata.validity.verify_base = 1;
2470 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2471 pfxdata.validity.hyper_pav = 1;
2474 switch (cmd) {
2475 case DASD_ECKD_CCW_READ_TRACK_DATA:
2476 dedata->mask.perm = 0x1;
2477 dedata->attributes.operation = basepriv->attrib.operation;
2478 dedata->blk_size = blksize;
2479 dedata->ga_extended |= 0x42;
2480 lredata->operation.orientation = 0x0;
2481 lredata->operation.operation = 0x0C;
2482 lredata->auxiliary.check_bytes = 0x01;
2483 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2484 break;
2485 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2486 dedata->mask.perm = 0x02;
2487 dedata->attributes.operation = basepriv->attrib.operation;
2488 dedata->blk_size = blksize;
2489 rc = check_XRC_on_prefix(&pfxdata, basedev);
2490 dedata->ga_extended |= 0x42;
2491 lredata->operation.orientation = 0x0;
2492 lredata->operation.operation = 0x3F;
2493 lredata->extended_operation = 0x23;
2494 lredata->auxiliary.check_bytes = 0x2;
2495 pfx_cmd = DASD_ECKD_CCW_PFX;
2496 break;
2497 default:
2498 DBF_DEV_EVENT(DBF_ERR, basedev,
2499 "prepare itcw, unknown opcode 0x%x", cmd);
2500 BUG();
2501 break;
2503 if (rc)
2504 return rc;
2506 dedata->attributes.mode = 0x3; /* ECKD */
2508 heads = basepriv->rdc_data.trk_per_cyl;
2509 begcyl = trk / heads;
2510 beghead = trk % heads;
2511 endcyl = totrk / heads;
2512 endhead = totrk % heads;
2514 /* check for sequential prestage - enhance cylinder range */
2515 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2516 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2518 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2519 endcyl += basepriv->attrib.nr_cyl;
2520 else
2521 endcyl = (basepriv->real_cyl - 1);
2524 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2525 set_ch_t(&dedata->end_ext, endcyl, endhead);
2527 dedata->ep_format = 0x20; /* records per track is valid */
2528 dedata->ep_rec_per_track = blk_per_trk;
2530 if (rec_on_trk) {
2531 switch (basepriv->rdc_data.dev_type) {
2532 case 0x3390:
2533 dn = ceil_quot(blksize + 6, 232);
2534 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2535 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2536 break;
2537 case 0x3380:
2538 d = 7 + ceil_quot(blksize + 12, 32);
2539 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2540 break;
2544 lredata->auxiliary.length_valid = 1;
2545 lredata->auxiliary.length_scope = 1;
2546 lredata->auxiliary.imbedded_ccw_valid = 1;
2547 lredata->length = tlf;
2548 lredata->imbedded_ccw = cmd;
2549 lredata->count = count;
2550 lredata->sector = sector;
2551 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2552 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2553 lredata->search_arg.head = lredata->seek_addr.head;
2554 lredata->search_arg.record = rec_on_trk;
2556 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2557 &pfxdata, sizeof(pfxdata), total_data_size);
2559 return rc;
2562 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2563 struct dasd_device *startdev,
2564 struct dasd_block *block,
2565 struct request *req,
2566 sector_t first_rec,
2567 sector_t last_rec,
2568 sector_t first_trk,
2569 sector_t last_trk,
2570 unsigned int first_offs,
2571 unsigned int last_offs,
2572 unsigned int blk_per_trk,
2573 unsigned int blksize)
2575 struct dasd_eckd_private *private;
2576 struct dasd_ccw_req *cqr;
2577 struct req_iterator iter;
2578 struct bio_vec *bv;
2579 char *dst;
2580 unsigned int trkcount, ctidaw;
2581 unsigned char cmd;
2582 struct dasd_device *basedev;
2583 unsigned int tlf;
2584 struct itcw *itcw;
2585 struct tidaw *last_tidaw = NULL;
2586 int itcw_op;
2587 size_t itcw_size;
2588 u8 tidaw_flags;
2589 unsigned int seg_len, part_len, len_to_track_end;
2590 unsigned char new_track;
2591 sector_t recid, trkid;
2592 unsigned int offs;
2593 unsigned int count, count_to_trk_end;
2595 basedev = block->base;
2596 private = (struct dasd_eckd_private *) basedev->private;
2597 if (rq_data_dir(req) == READ) {
2598 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2599 itcw_op = ITCW_OP_READ;
2600 } else if (rq_data_dir(req) == WRITE) {
2601 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2602 itcw_op = ITCW_OP_WRITE;
2603 } else
2604 return ERR_PTR(-EINVAL);
2606 /* trackbased I/O needs address all memory via TIDAWs,
2607 * not just for 64 bit addresses. This allows us to map
2608 * each segment directly to one tidaw.
2609 * In the case of write requests, additional tidaws may
2610 * be needed when a segment crosses a track boundary.
2612 trkcount = last_trk - first_trk + 1;
2613 ctidaw = 0;
2614 rq_for_each_segment(bv, req, iter) {
2615 ++ctidaw;
2617 if (rq_data_dir(req) == WRITE)
2618 ctidaw += (last_trk - first_trk);
2620 /* Allocate the ccw request. */
2621 itcw_size = itcw_calc_size(0, ctidaw, 0);
2622 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2623 if (IS_ERR(cqr))
2624 return cqr;
2626 /* transfer length factor: how many bytes to read from the last track */
2627 if (first_trk == last_trk)
2628 tlf = last_offs - first_offs + 1;
2629 else
2630 tlf = last_offs + 1;
2631 tlf *= blksize;
2633 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2634 if (IS_ERR(itcw)) {
2635 dasd_sfree_request(cqr, startdev);
2636 return ERR_PTR(-EINVAL);
2638 cqr->cpaddr = itcw_get_tcw(itcw);
2639 if (prepare_itcw(itcw, first_trk, last_trk,
2640 cmd, basedev, startdev,
2641 first_offs + 1,
2642 trkcount, blksize,
2643 (last_rec - first_rec + 1) * blksize,
2644 tlf, blk_per_trk) == -EAGAIN) {
2645 /* Clock not in sync and XRC is enabled.
2646 * Try again later.
2648 dasd_sfree_request(cqr, startdev);
2649 return ERR_PTR(-EAGAIN);
2652 * A tidaw can address 4k of memory, but must not cross page boundaries
2653 * We can let the block layer handle this by setting
2654 * blk_queue_segment_boundary to page boundaries and
2655 * blk_max_segment_size to page size when setting up the request queue.
2656 * For write requests, a TIDAW must not cross track boundaries, because
2657 * we have to set the CBC flag on the last tidaw for each track.
2659 if (rq_data_dir(req) == WRITE) {
2660 new_track = 1;
2661 recid = first_rec;
2662 rq_for_each_segment(bv, req, iter) {
2663 dst = page_address(bv->bv_page) + bv->bv_offset;
2664 seg_len = bv->bv_len;
2665 while (seg_len) {
2666 if (new_track) {
2667 trkid = recid;
2668 offs = sector_div(trkid, blk_per_trk);
2669 count_to_trk_end = blk_per_trk - offs;
2670 count = min((last_rec - recid + 1),
2671 (sector_t)count_to_trk_end);
2672 len_to_track_end = count * blksize;
2673 recid += count;
2674 new_track = 0;
2676 part_len = min(seg_len, len_to_track_end);
2677 seg_len -= part_len;
2678 len_to_track_end -= part_len;
2679 /* We need to end the tidaw at track end */
2680 if (!len_to_track_end) {
2681 new_track = 1;
2682 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
2683 } else
2684 tidaw_flags = 0;
2685 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
2686 dst, part_len);
2687 if (IS_ERR(last_tidaw))
2688 return ERR_PTR(-EINVAL);
2689 dst += part_len;
2692 } else {
2693 rq_for_each_segment(bv, req, iter) {
2694 dst = page_address(bv->bv_page) + bv->bv_offset;
2695 last_tidaw = itcw_add_tidaw(itcw, 0x00,
2696 dst, bv->bv_len);
2697 if (IS_ERR(last_tidaw))
2698 return ERR_PTR(-EINVAL);
2701 last_tidaw->flags |= TIDAW_FLAGS_LAST;
2702 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
2703 itcw_finalize(itcw);
2705 if (blk_noretry_request(req) ||
2706 block->base->features & DASD_FEATURE_FAILFAST)
2707 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2708 cqr->cpmode = 1;
2709 cqr->startdev = startdev;
2710 cqr->memdev = startdev;
2711 cqr->block = block;
2712 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2713 cqr->lpm = startdev->path_data.ppm;
2714 cqr->retries = 256;
2715 cqr->buildclk = get_clock();
2716 cqr->status = DASD_CQR_FILLED;
2717 return cqr;
2720 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2721 struct dasd_block *block,
2722 struct request *req)
2724 int cmdrtd, cmdwtd;
2725 int use_prefix;
2726 int fcx_multitrack;
2727 struct dasd_eckd_private *private;
2728 struct dasd_device *basedev;
2729 sector_t first_rec, last_rec;
2730 sector_t first_trk, last_trk;
2731 unsigned int first_offs, last_offs;
2732 unsigned int blk_per_trk, blksize;
2733 int cdlspecial;
2734 unsigned int data_size;
2735 struct dasd_ccw_req *cqr;
2737 basedev = block->base;
2738 private = (struct dasd_eckd_private *) basedev->private;
2740 /* Calculate number of blocks/records per track. */
2741 blksize = block->bp_block;
2742 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2743 if (blk_per_trk == 0)
2744 return ERR_PTR(-EINVAL);
2745 /* Calculate record id of first and last block. */
2746 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
2747 first_offs = sector_div(first_trk, blk_per_trk);
2748 last_rec = last_trk =
2749 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
2750 last_offs = sector_div(last_trk, blk_per_trk);
2751 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2753 fcx_multitrack = private->features.feature[40] & 0x20;
2754 data_size = blk_rq_bytes(req);
2755 /* tpm write request add CBC data on each track boundary */
2756 if (rq_data_dir(req) == WRITE)
2757 data_size += (last_trk - first_trk) * 4;
2759 /* is read track data and write track data in command mode supported? */
2760 cmdrtd = private->features.feature[9] & 0x20;
2761 cmdwtd = private->features.feature[12] & 0x40;
2762 use_prefix = private->features.feature[8] & 0x01;
2764 cqr = NULL;
2765 if (cdlspecial || dasd_page_cache) {
2766 /* do nothing, just fall through to the cmd mode single case */
2767 } else if ((data_size <= private->fcx_max_data)
2768 && (fcx_multitrack || (first_trk == last_trk))) {
2769 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2770 first_rec, last_rec,
2771 first_trk, last_trk,
2772 first_offs, last_offs,
2773 blk_per_trk, blksize);
2774 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
2775 (PTR_ERR(cqr) != -ENOMEM))
2776 cqr = NULL;
2777 } else if (use_prefix &&
2778 (((rq_data_dir(req) == READ) && cmdrtd) ||
2779 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
2780 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2781 first_rec, last_rec,
2782 first_trk, last_trk,
2783 first_offs, last_offs,
2784 blk_per_trk, blksize);
2785 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
2786 (PTR_ERR(cqr) != -ENOMEM))
2787 cqr = NULL;
2789 if (!cqr)
2790 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2791 first_rec, last_rec,
2792 first_trk, last_trk,
2793 first_offs, last_offs,
2794 blk_per_trk, blksize);
2795 return cqr;
2798 static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
2799 struct dasd_block *block,
2800 struct request *req)
2802 struct dasd_eckd_private *private;
2803 unsigned long *idaws;
2804 struct dasd_device *basedev;
2805 struct dasd_ccw_req *cqr;
2806 struct ccw1 *ccw;
2807 struct req_iterator iter;
2808 struct bio_vec *bv;
2809 char *dst;
2810 unsigned char cmd;
2811 unsigned int trkcount;
2812 unsigned int seg_len, len_to_track_end;
2813 unsigned int first_offs;
2814 unsigned int cidaw, cplength, datasize;
2815 sector_t first_trk, last_trk;
2816 unsigned int pfx_datasize;
2819 * raw track access needs to be mutiple of 64k and on 64k boundary
2821 if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
2822 cqr = ERR_PTR(-EINVAL);
2823 goto out;
2825 if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
2826 DASD_RAW_SECTORS_PER_TRACK) != 0) {
2827 cqr = ERR_PTR(-EINVAL);
2828 goto out;
2831 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
2832 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
2833 DASD_RAW_SECTORS_PER_TRACK;
2834 trkcount = last_trk - first_trk + 1;
2835 first_offs = 0;
2836 basedev = block->base;
2837 private = (struct dasd_eckd_private *) basedev->private;
2839 if (rq_data_dir(req) == READ)
2840 cmd = DASD_ECKD_CCW_READ_TRACK;
2841 else if (rq_data_dir(req) == WRITE)
2842 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
2843 else {
2844 cqr = ERR_PTR(-EINVAL);
2845 goto out;
2849 * Raw track based I/O needs IDAWs for each page,
2850 * and not just for 64 bit addresses.
2852 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
2854 /* 1x prefix + one read/write ccw per track */
2855 cplength = 1 + trkcount;
2858 * struct PFX_eckd_data has up to 2 byte as extended parameter
2859 * this is needed for write full track and has to be mentioned
2860 * seperately
2861 * add 8 instead of 2 to keep 8 byte boundary
2863 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
2865 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
2867 /* Allocate the ccw request. */
2868 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2869 datasize, startdev);
2870 if (IS_ERR(cqr))
2871 goto out;
2872 ccw = cqr->cpaddr;
2874 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
2875 basedev, startdev, 1 /* format */, first_offs + 1,
2876 trkcount, 0, 0) == -EAGAIN) {
2877 /* Clock not in sync and XRC is enabled.
2878 * Try again later.
2880 dasd_sfree_request(cqr, startdev);
2881 cqr = ERR_PTR(-EAGAIN);
2882 goto out;
2885 idaws = (unsigned long *)(cqr->data + pfx_datasize);
2887 len_to_track_end = 0;
2889 rq_for_each_segment(bv, req, iter) {
2890 dst = page_address(bv->bv_page) + bv->bv_offset;
2891 seg_len = bv->bv_len;
2892 if (!len_to_track_end) {
2893 ccw[-1].flags |= CCW_FLAG_CC;
2894 ccw->cmd_code = cmd;
2895 /* maximum 3390 track size */
2896 ccw->count = 57326;
2897 /* 64k map to one track */
2898 len_to_track_end = 65536;
2899 ccw->cda = (__u32)(addr_t)idaws;
2900 ccw->flags |= CCW_FLAG_IDA;
2901 ccw->flags |= CCW_FLAG_SLI;
2902 ccw++;
2904 len_to_track_end -= seg_len;
2905 idaws = idal_create_words(idaws, dst, seg_len);
2908 if (blk_noretry_request(req) ||
2909 block->base->features & DASD_FEATURE_FAILFAST)
2910 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2911 cqr->startdev = startdev;
2912 cqr->memdev = startdev;
2913 cqr->block = block;
2914 cqr->expires = startdev->default_expires * HZ;
2915 cqr->lpm = startdev->path_data.ppm;
2916 cqr->retries = 256;
2917 cqr->buildclk = get_clock();
2918 cqr->status = DASD_CQR_FILLED;
2920 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2921 cqr = NULL;
2922 out:
2923 return cqr;
2927 static int
2928 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2930 struct dasd_eckd_private *private;
2931 struct ccw1 *ccw;
2932 struct req_iterator iter;
2933 struct bio_vec *bv;
2934 char *dst, *cda;
2935 unsigned int blksize, blk_per_trk, off;
2936 sector_t recid;
2937 int status;
2939 if (!dasd_page_cache)
2940 goto out;
2941 private = (struct dasd_eckd_private *) cqr->block->base->private;
2942 blksize = cqr->block->bp_block;
2943 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2944 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
2945 ccw = cqr->cpaddr;
2946 /* Skip over define extent & locate record. */
2947 ccw++;
2948 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2949 ccw++;
2950 rq_for_each_segment(bv, req, iter) {
2951 dst = page_address(bv->bv_page) + bv->bv_offset;
2952 for (off = 0; off < bv->bv_len; off += blksize) {
2953 /* Skip locate record. */
2954 if (private->uses_cdl && recid <= 2*blk_per_trk)
2955 ccw++;
2956 if (dst) {
2957 if (ccw->flags & CCW_FLAG_IDA)
2958 cda = *((char **)((addr_t) ccw->cda));
2959 else
2960 cda = (char *)((addr_t) ccw->cda);
2961 if (dst != cda) {
2962 if (rq_data_dir(req) == READ)
2963 memcpy(dst, cda, bv->bv_len);
2964 kmem_cache_free(dasd_page_cache,
2965 (void *)((addr_t)cda & PAGE_MASK));
2967 dst = NULL;
2969 ccw++;
2970 recid++;
2973 out:
2974 status = cqr->status == DASD_CQR_DONE;
2975 dasd_sfree_request(cqr, cqr->memdev);
2976 return status;
2980 * Modify ccw/tcw in cqr so it can be started on a base device.
2982 * Note that this is not enough to restart the cqr!
2983 * Either reset cqr->startdev as well (summary unit check handling)
2984 * or restart via separate cqr (as in ERP handling).
2986 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
2988 struct ccw1 *ccw;
2989 struct PFX_eckd_data *pfxdata;
2990 struct tcw *tcw;
2991 struct tccb *tccb;
2992 struct dcw *dcw;
2994 if (cqr->cpmode == 1) {
2995 tcw = cqr->cpaddr;
2996 tccb = tcw_get_tccb(tcw);
2997 dcw = (struct dcw *)&tccb->tca[0];
2998 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
2999 pfxdata->validity.verify_base = 0;
3000 pfxdata->validity.hyper_pav = 0;
3001 } else {
3002 ccw = cqr->cpaddr;
3003 pfxdata = cqr->data;
3004 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3005 pfxdata->validity.verify_base = 0;
3006 pfxdata->validity.hyper_pav = 0;
3011 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3013 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3014 struct dasd_block *block,
3015 struct request *req)
3017 struct dasd_eckd_private *private;
3018 struct dasd_device *startdev;
3019 unsigned long flags;
3020 struct dasd_ccw_req *cqr;
3022 startdev = dasd_alias_get_start_dev(base);
3023 if (!startdev)
3024 startdev = base;
3025 private = (struct dasd_eckd_private *) startdev->private;
3026 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3027 return ERR_PTR(-EBUSY);
3029 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3030 private->count++;
3031 if ((base->features & DASD_FEATURE_USERAW))
3032 cqr = dasd_raw_build_cp(startdev, block, req);
3033 else
3034 cqr = dasd_eckd_build_cp(startdev, block, req);
3035 if (IS_ERR(cqr))
3036 private->count--;
3037 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3038 return cqr;
3041 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3042 struct request *req)
3044 struct dasd_eckd_private *private;
3045 unsigned long flags;
3047 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3048 private = (struct dasd_eckd_private *) cqr->memdev->private;
3049 private->count--;
3050 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3051 return dasd_eckd_free_cp(cqr, req);
3054 static int
3055 dasd_eckd_fill_info(struct dasd_device * device,
3056 struct dasd_information2_t * info)
3058 struct dasd_eckd_private *private;
3060 private = (struct dasd_eckd_private *) device->private;
3061 info->label_block = 2;
3062 info->FBA_layout = private->uses_cdl ? 0 : 1;
3063 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3064 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3065 memcpy(info->characteristics, &private->rdc_data,
3066 sizeof(struct dasd_eckd_characteristics));
3067 info->confdata_size = min((unsigned long)private->conf_len,
3068 sizeof(info->configuration_data));
3069 memcpy(info->configuration_data, private->conf_data,
3070 info->confdata_size);
3071 return 0;
3075 * SECTION: ioctl functions for eckd devices.
3079 * Release device ioctl.
3080 * Buils a channel programm to releases a prior reserved
3081 * (see dasd_eckd_reserve) device.
3083 static int
3084 dasd_eckd_release(struct dasd_device *device)
3086 struct dasd_ccw_req *cqr;
3087 int rc;
3088 struct ccw1 *ccw;
3089 int useglobal;
3091 if (!capable(CAP_SYS_ADMIN))
3092 return -EACCES;
3094 useglobal = 0;
3095 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3096 if (IS_ERR(cqr)) {
3097 mutex_lock(&dasd_reserve_mutex);
3098 useglobal = 1;
3099 cqr = &dasd_reserve_req->cqr;
3100 memset(cqr, 0, sizeof(*cqr));
3101 memset(&dasd_reserve_req->ccw, 0,
3102 sizeof(dasd_reserve_req->ccw));
3103 cqr->cpaddr = &dasd_reserve_req->ccw;
3104 cqr->data = &dasd_reserve_req->data;
3105 cqr->magic = DASD_ECKD_MAGIC;
3107 ccw = cqr->cpaddr;
3108 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3109 ccw->flags |= CCW_FLAG_SLI;
3110 ccw->count = 32;
3111 ccw->cda = (__u32)(addr_t) cqr->data;
3112 cqr->startdev = device;
3113 cqr->memdev = device;
3114 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3115 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3116 cqr->retries = 2; /* set retry counter to enable basic ERP */
3117 cqr->expires = 2 * HZ;
3118 cqr->buildclk = get_clock();
3119 cqr->status = DASD_CQR_FILLED;
3121 rc = dasd_sleep_on_immediatly(cqr);
3122 if (!rc)
3123 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3125 if (useglobal)
3126 mutex_unlock(&dasd_reserve_mutex);
3127 else
3128 dasd_sfree_request(cqr, cqr->memdev);
3129 return rc;
3133 * Reserve device ioctl.
3134 * Options are set to 'synchronous wait for interrupt' and
3135 * 'timeout the request'. This leads to a terminate IO if
3136 * the interrupt is outstanding for a certain time.
3138 static int
3139 dasd_eckd_reserve(struct dasd_device *device)
3141 struct dasd_ccw_req *cqr;
3142 int rc;
3143 struct ccw1 *ccw;
3144 int useglobal;
3146 if (!capable(CAP_SYS_ADMIN))
3147 return -EACCES;
3149 useglobal = 0;
3150 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3151 if (IS_ERR(cqr)) {
3152 mutex_lock(&dasd_reserve_mutex);
3153 useglobal = 1;
3154 cqr = &dasd_reserve_req->cqr;
3155 memset(cqr, 0, sizeof(*cqr));
3156 memset(&dasd_reserve_req->ccw, 0,
3157 sizeof(dasd_reserve_req->ccw));
3158 cqr->cpaddr = &dasd_reserve_req->ccw;
3159 cqr->data = &dasd_reserve_req->data;
3160 cqr->magic = DASD_ECKD_MAGIC;
3162 ccw = cqr->cpaddr;
3163 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3164 ccw->flags |= CCW_FLAG_SLI;
3165 ccw->count = 32;
3166 ccw->cda = (__u32)(addr_t) cqr->data;
3167 cqr->startdev = device;
3168 cqr->memdev = device;
3169 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3170 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3171 cqr->retries = 2; /* set retry counter to enable basic ERP */
3172 cqr->expires = 2 * HZ;
3173 cqr->buildclk = get_clock();
3174 cqr->status = DASD_CQR_FILLED;
3176 rc = dasd_sleep_on_immediatly(cqr);
3177 if (!rc)
3178 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3180 if (useglobal)
3181 mutex_unlock(&dasd_reserve_mutex);
3182 else
3183 dasd_sfree_request(cqr, cqr->memdev);
3184 return rc;
3188 * Steal lock ioctl - unconditional reserve device.
3189 * Buils a channel programm to break a device's reservation.
3190 * (unconditional reserve)
3192 static int
3193 dasd_eckd_steal_lock(struct dasd_device *device)
3195 struct dasd_ccw_req *cqr;
3196 int rc;
3197 struct ccw1 *ccw;
3198 int useglobal;
3200 if (!capable(CAP_SYS_ADMIN))
3201 return -EACCES;
3203 useglobal = 0;
3204 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3205 if (IS_ERR(cqr)) {
3206 mutex_lock(&dasd_reserve_mutex);
3207 useglobal = 1;
3208 cqr = &dasd_reserve_req->cqr;
3209 memset(cqr, 0, sizeof(*cqr));
3210 memset(&dasd_reserve_req->ccw, 0,
3211 sizeof(dasd_reserve_req->ccw));
3212 cqr->cpaddr = &dasd_reserve_req->ccw;
3213 cqr->data = &dasd_reserve_req->data;
3214 cqr->magic = DASD_ECKD_MAGIC;
3216 ccw = cqr->cpaddr;
3217 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3218 ccw->flags |= CCW_FLAG_SLI;
3219 ccw->count = 32;
3220 ccw->cda = (__u32)(addr_t) cqr->data;
3221 cqr->startdev = device;
3222 cqr->memdev = device;
3223 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3224 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3225 cqr->retries = 2; /* set retry counter to enable basic ERP */
3226 cqr->expires = 2 * HZ;
3227 cqr->buildclk = get_clock();
3228 cqr->status = DASD_CQR_FILLED;
3230 rc = dasd_sleep_on_immediatly(cqr);
3231 if (!rc)
3232 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3234 if (useglobal)
3235 mutex_unlock(&dasd_reserve_mutex);
3236 else
3237 dasd_sfree_request(cqr, cqr->memdev);
3238 return rc;
3242 * SNID - Sense Path Group ID
3243 * This ioctl may be used in situations where I/O is stalled due to
3244 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3245 * preallocated dasd_reserve_req.
3247 static int dasd_eckd_snid(struct dasd_device *device,
3248 void __user *argp)
3250 struct dasd_ccw_req *cqr;
3251 int rc;
3252 struct ccw1 *ccw;
3253 int useglobal;
3254 struct dasd_snid_ioctl_data usrparm;
3256 if (!capable(CAP_SYS_ADMIN))
3257 return -EACCES;
3259 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3260 return -EFAULT;
3262 useglobal = 0;
3263 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3264 sizeof(struct dasd_snid_data), device);
3265 if (IS_ERR(cqr)) {
3266 mutex_lock(&dasd_reserve_mutex);
3267 useglobal = 1;
3268 cqr = &dasd_reserve_req->cqr;
3269 memset(cqr, 0, sizeof(*cqr));
3270 memset(&dasd_reserve_req->ccw, 0,
3271 sizeof(dasd_reserve_req->ccw));
3272 cqr->cpaddr = &dasd_reserve_req->ccw;
3273 cqr->data = &dasd_reserve_req->data;
3274 cqr->magic = DASD_ECKD_MAGIC;
3276 ccw = cqr->cpaddr;
3277 ccw->cmd_code = DASD_ECKD_CCW_SNID;
3278 ccw->flags |= CCW_FLAG_SLI;
3279 ccw->count = 12;
3280 ccw->cda = (__u32)(addr_t) cqr->data;
3281 cqr->startdev = device;
3282 cqr->memdev = device;
3283 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3284 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3285 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
3286 cqr->retries = 5;
3287 cqr->expires = 10 * HZ;
3288 cqr->buildclk = get_clock();
3289 cqr->status = DASD_CQR_FILLED;
3290 cqr->lpm = usrparm.path_mask;
3292 rc = dasd_sleep_on_immediatly(cqr);
3293 /* verify that I/O processing didn't modify the path mask */
3294 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3295 rc = -EIO;
3296 if (!rc) {
3297 usrparm.data = *((struct dasd_snid_data *)cqr->data);
3298 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3299 rc = -EFAULT;
3302 if (useglobal)
3303 mutex_unlock(&dasd_reserve_mutex);
3304 else
3305 dasd_sfree_request(cqr, cqr->memdev);
3306 return rc;
3310 * Read performance statistics
3312 static int
3313 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
3315 struct dasd_psf_prssd_data *prssdp;
3316 struct dasd_rssd_perf_stats_t *stats;
3317 struct dasd_ccw_req *cqr;
3318 struct ccw1 *ccw;
3319 int rc;
3321 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
3322 (sizeof(struct dasd_psf_prssd_data) +
3323 sizeof(struct dasd_rssd_perf_stats_t)),
3324 device);
3325 if (IS_ERR(cqr)) {
3326 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3327 "Could not allocate initialization request");
3328 return PTR_ERR(cqr);
3330 cqr->startdev = device;
3331 cqr->memdev = device;
3332 cqr->retries = 0;
3333 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3334 cqr->expires = 10 * HZ;
3336 /* Prepare for Read Subsystem Data */
3337 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3338 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
3339 prssdp->order = PSF_ORDER_PRSSD;
3340 prssdp->suborder = 0x01; /* Performance Statistics */
3341 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3343 ccw = cqr->cpaddr;
3344 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3345 ccw->count = sizeof(struct dasd_psf_prssd_data);
3346 ccw->flags |= CCW_FLAG_CC;
3347 ccw->cda = (__u32)(addr_t) prssdp;
3349 /* Read Subsystem Data - Performance Statistics */
3350 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3351 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
3353 ccw++;
3354 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3355 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
3356 ccw->cda = (__u32)(addr_t) stats;
3358 cqr->buildclk = get_clock();
3359 cqr->status = DASD_CQR_FILLED;
3360 rc = dasd_sleep_on(cqr);
3361 if (rc == 0) {
3362 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3363 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3364 if (copy_to_user(argp, stats,
3365 sizeof(struct dasd_rssd_perf_stats_t)))
3366 rc = -EFAULT;
3368 dasd_sfree_request(cqr, cqr->memdev);
3369 return rc;
3373 * Get attributes (cache operations)
3374 * Returnes the cache attributes used in Define Extend (DE).
3376 static int
3377 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
3379 struct dasd_eckd_private *private =
3380 (struct dasd_eckd_private *)device->private;
3381 struct attrib_data_t attrib = private->attrib;
3382 int rc;
3384 if (!capable(CAP_SYS_ADMIN))
3385 return -EACCES;
3386 if (!argp)
3387 return -EINVAL;
3389 rc = 0;
3390 if (copy_to_user(argp, (long *) &attrib,
3391 sizeof(struct attrib_data_t)))
3392 rc = -EFAULT;
3394 return rc;
3398 * Set attributes (cache operations)
3399 * Stores the attributes for cache operation to be used in Define Extend (DE).
3401 static int
3402 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
3404 struct dasd_eckd_private *private =
3405 (struct dasd_eckd_private *)device->private;
3406 struct attrib_data_t attrib;
3408 if (!capable(CAP_SYS_ADMIN))
3409 return -EACCES;
3410 if (!argp)
3411 return -EINVAL;
3413 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
3414 return -EFAULT;
3415 private->attrib = attrib;
3417 dev_info(&device->cdev->dev,
3418 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3419 private->attrib.operation, private->attrib.nr_cyl);
3420 return 0;
3424 * Issue syscall I/O to EMC Symmetrix array.
3425 * CCWs are PSF and RSSD
3427 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3429 struct dasd_symmio_parms usrparm;
3430 char *psf_data, *rssd_result;
3431 struct dasd_ccw_req *cqr;
3432 struct ccw1 *ccw;
3433 char psf0, psf1;
3434 int rc;
3436 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3437 return -EACCES;
3438 psf0 = psf1 = 0;
3440 /* Copy parms from caller */
3441 rc = -EFAULT;
3442 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3443 goto out;
3444 if (is_compat_task() || sizeof(long) == 4) {
3445 /* Make sure pointers are sane even on 31 bit. */
3446 rc = -EINVAL;
3447 if ((usrparm.psf_data >> 32) != 0)
3448 goto out;
3449 if ((usrparm.rssd_result >> 32) != 0)
3450 goto out;
3451 usrparm.psf_data &= 0x7fffffffULL;
3452 usrparm.rssd_result &= 0x7fffffffULL;
3454 /* alloc I/O data area */
3455 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3456 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3457 if (!psf_data || !rssd_result) {
3458 rc = -ENOMEM;
3459 goto out_free;
3462 /* get syscall header from user space */
3463 rc = -EFAULT;
3464 if (copy_from_user(psf_data,
3465 (void __user *)(unsigned long) usrparm.psf_data,
3466 usrparm.psf_data_len))
3467 goto out_free;
3468 psf0 = psf_data[0];
3469 psf1 = psf_data[1];
3471 /* setup CCWs for PSF + RSSD */
3472 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
3473 if (IS_ERR(cqr)) {
3474 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3475 "Could not allocate initialization request");
3476 rc = PTR_ERR(cqr);
3477 goto out_free;
3480 cqr->startdev = device;
3481 cqr->memdev = device;
3482 cqr->retries = 3;
3483 cqr->expires = 10 * HZ;
3484 cqr->buildclk = get_clock();
3485 cqr->status = DASD_CQR_FILLED;
3487 /* Build the ccws */
3488 ccw = cqr->cpaddr;
3490 /* PSF ccw */
3491 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3492 ccw->count = usrparm.psf_data_len;
3493 ccw->flags |= CCW_FLAG_CC;
3494 ccw->cda = (__u32)(addr_t) psf_data;
3496 ccw++;
3498 /* RSSD ccw */
3499 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3500 ccw->count = usrparm.rssd_result_len;
3501 ccw->flags = CCW_FLAG_SLI ;
3502 ccw->cda = (__u32)(addr_t) rssd_result;
3504 rc = dasd_sleep_on(cqr);
3505 if (rc)
3506 goto out_sfree;
3508 rc = -EFAULT;
3509 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
3510 rssd_result, usrparm.rssd_result_len))
3511 goto out_sfree;
3512 rc = 0;
3514 out_sfree:
3515 dasd_sfree_request(cqr, cqr->memdev);
3516 out_free:
3517 kfree(rssd_result);
3518 kfree(psf_data);
3519 out:
3520 DBF_DEV_EVENT(DBF_WARNING, device,
3521 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3522 (int) psf0, (int) psf1, rc);
3523 return rc;
3526 static int
3527 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
3529 struct dasd_device *device = block->base;
3531 switch (cmd) {
3532 case BIODASDGATTR:
3533 return dasd_eckd_get_attrib(device, argp);
3534 case BIODASDSATTR:
3535 return dasd_eckd_set_attrib(device, argp);
3536 case BIODASDPSRD:
3537 return dasd_eckd_performance(device, argp);
3538 case BIODASDRLSE:
3539 return dasd_eckd_release(device);
3540 case BIODASDRSRV:
3541 return dasd_eckd_reserve(device);
3542 case BIODASDSLCK:
3543 return dasd_eckd_steal_lock(device);
3544 case BIODASDSNID:
3545 return dasd_eckd_snid(device, argp);
3546 case BIODASDSYMMIO:
3547 return dasd_symm_io(device, argp);
3548 default:
3549 return -ENOIOCTLCMD;
3554 * Dump the range of CCWs into 'page' buffer
3555 * and return number of printed chars.
3557 static int
3558 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
3560 int len, count;
3561 char *datap;
3563 len = 0;
3564 while (from <= to) {
3565 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3566 " CCW %p: %08X %08X DAT:",
3567 from, ((int *) from)[0], ((int *) from)[1]);
3569 /* get pointer to data (consider IDALs) */
3570 if (from->flags & CCW_FLAG_IDA)
3571 datap = (char *) *((addr_t *) (addr_t) from->cda);
3572 else
3573 datap = (char *) ((addr_t) from->cda);
3575 /* dump data (max 32 bytes) */
3576 for (count = 0; count < from->count && count < 32; count++) {
3577 if (count % 8 == 0) len += sprintf(page + len, " ");
3578 if (count % 4 == 0) len += sprintf(page + len, " ");
3579 len += sprintf(page + len, "%02x", datap[count]);
3581 len += sprintf(page + len, "\n");
3582 from++;
3584 return len;
3587 static void
3588 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
3589 char *reason)
3591 u64 *sense;
3592 u64 *stat;
3594 sense = (u64 *) dasd_get_sense(irb);
3595 stat = (u64 *) &irb->scsw;
3596 if (sense) {
3597 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
3598 "%016llx %016llx %016llx %016llx",
3599 reason, *stat, *((u32 *) (stat + 1)),
3600 sense[0], sense[1], sense[2], sense[3]);
3601 } else {
3602 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
3603 reason, *stat, *((u32 *) (stat + 1)),
3604 "NO VALID SENSE");
3609 * Print sense data and related channel program.
3610 * Parts are printed because printk buffer is only 1024 bytes.
3612 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
3613 struct dasd_ccw_req *req, struct irb *irb)
3615 char *page;
3616 struct ccw1 *first, *last, *fail, *from, *to;
3617 int len, sl, sct;
3619 page = (char *) get_zeroed_page(GFP_ATOMIC);
3620 if (page == NULL) {
3621 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3622 "No memory to dump sense data\n");
3623 return;
3625 /* dump the sense data */
3626 len = sprintf(page, KERN_ERR PRINTK_HEADER
3627 " I/O status report for device %s:\n",
3628 dev_name(&device->cdev->dev));
3629 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3630 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3631 "CS:%02X RC:%d\n",
3632 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3633 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3634 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3635 req ? req->intrc : 0);
3636 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3637 " device %s: Failing CCW: %p\n",
3638 dev_name(&device->cdev->dev),
3639 (void *) (addr_t) irb->scsw.cmd.cpa);
3640 if (irb->esw.esw0.erw.cons) {
3641 for (sl = 0; sl < 4; sl++) {
3642 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3643 " Sense(hex) %2d-%2d:",
3644 (8 * sl), ((8 * sl) + 7));
3646 for (sct = 0; sct < 8; sct++) {
3647 len += sprintf(page + len, " %02x",
3648 irb->ecw[8 * sl + sct]);
3650 len += sprintf(page + len, "\n");
3653 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3654 /* 24 Byte Sense Data */
3655 sprintf(page + len, KERN_ERR PRINTK_HEADER
3656 " 24 Byte: %x MSG %x, "
3657 "%s MSGb to SYSOP\n",
3658 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3659 irb->ecw[1] & 0x10 ? "" : "no");
3660 } else {
3661 /* 32 Byte Sense Data */
3662 sprintf(page + len, KERN_ERR PRINTK_HEADER
3663 " 32 Byte: Format: %x "
3664 "Exception class %x\n",
3665 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
3667 } else {
3668 sprintf(page + len, KERN_ERR PRINTK_HEADER
3669 " SORRY - NO VALID SENSE AVAILABLE\n");
3671 printk("%s", page);
3673 if (req) {
3674 /* req == NULL for unsolicited interrupts */
3675 /* dump the Channel Program (max 140 Bytes per line) */
3676 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3677 first = req->cpaddr;
3678 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3679 to = min(first + 6, last);
3680 len = sprintf(page, KERN_ERR PRINTK_HEADER
3681 " Related CP in req: %p\n", req);
3682 dasd_eckd_dump_ccw_range(first, to, page + len);
3683 printk("%s", page);
3685 /* print failing CCW area (maximum 4) */
3686 /* scsw->cda is either valid or zero */
3687 len = 0;
3688 from = ++to;
3689 fail = (struct ccw1 *)(addr_t)
3690 irb->scsw.cmd.cpa; /* failing CCW */
3691 if (from < fail - 2) {
3692 from = fail - 2; /* there is a gap - print header */
3693 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3695 to = min(fail + 1, last);
3696 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3698 /* print last CCWs (maximum 2) */
3699 from = max(from, ++to);
3700 if (from < last - 1) {
3701 from = last - 1; /* there is a gap - print header */
3702 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3704 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3705 if (len > 0)
3706 printk("%s", page);
3708 free_page((unsigned long) page);
3713 * Print sense data from a tcw.
3715 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3716 struct dasd_ccw_req *req, struct irb *irb)
3718 char *page;
3719 int len, sl, sct, residual;
3720 struct tsb *tsb;
3721 u8 *sense, *rcq;
3723 page = (char *) get_zeroed_page(GFP_ATOMIC);
3724 if (page == NULL) {
3725 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
3726 "No memory to dump sense data");
3727 return;
3729 /* dump the sense data */
3730 len = sprintf(page, KERN_ERR PRINTK_HEADER
3731 " I/O status report for device %s:\n",
3732 dev_name(&device->cdev->dev));
3733 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3734 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3735 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
3736 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3737 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3738 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3739 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
3740 req ? req->intrc : 0);
3741 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3742 " device %s: Failing TCW: %p\n",
3743 dev_name(&device->cdev->dev),
3744 (void *) (addr_t) irb->scsw.tm.tcw);
3746 tsb = NULL;
3747 sense = NULL;
3748 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
3749 tsb = tcw_get_tsb(
3750 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3752 if (tsb) {
3753 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3754 " tsb->length %d\n", tsb->length);
3755 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3756 " tsb->flags %x\n", tsb->flags);
3757 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3758 " tsb->dcw_offset %d\n", tsb->dcw_offset);
3759 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3760 " tsb->count %d\n", tsb->count);
3761 residual = tsb->count - 28;
3762 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3763 " residual %d\n", residual);
3765 switch (tsb->flags & 0x07) {
3766 case 1: /* tsa_iostat */
3767 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3768 " tsb->tsa.iostat.dev_time %d\n",
3769 tsb->tsa.iostat.dev_time);
3770 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3771 " tsb->tsa.iostat.def_time %d\n",
3772 tsb->tsa.iostat.def_time);
3773 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3774 " tsb->tsa.iostat.queue_time %d\n",
3775 tsb->tsa.iostat.queue_time);
3776 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3777 " tsb->tsa.iostat.dev_busy_time %d\n",
3778 tsb->tsa.iostat.dev_busy_time);
3779 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3780 " tsb->tsa.iostat.dev_act_time %d\n",
3781 tsb->tsa.iostat.dev_act_time);
3782 sense = tsb->tsa.iostat.sense;
3783 break;
3784 case 2: /* ts_ddpc */
3785 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3786 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3787 for (sl = 0; sl < 2; sl++) {
3788 len += sprintf(page + len,
3789 KERN_ERR PRINTK_HEADER
3790 " tsb->tsa.ddpc.rcq %2d-%2d: ",
3791 (8 * sl), ((8 * sl) + 7));
3792 rcq = tsb->tsa.ddpc.rcq;
3793 for (sct = 0; sct < 8; sct++) {
3794 len += sprintf(page + len, " %02x",
3795 rcq[8 * sl + sct]);
3797 len += sprintf(page + len, "\n");
3799 sense = tsb->tsa.ddpc.sense;
3800 break;
3801 case 3: /* tsa_intrg */
3802 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3803 " tsb->tsa.intrg.: not supportet yet \n");
3804 break;
3807 if (sense) {
3808 for (sl = 0; sl < 4; sl++) {
3809 len += sprintf(page + len,
3810 KERN_ERR PRINTK_HEADER
3811 " Sense(hex) %2d-%2d:",
3812 (8 * sl), ((8 * sl) + 7));
3813 for (sct = 0; sct < 8; sct++) {
3814 len += sprintf(page + len, " %02x",
3815 sense[8 * sl + sct]);
3817 len += sprintf(page + len, "\n");
3820 if (sense[27] & DASD_SENSE_BIT_0) {
3821 /* 24 Byte Sense Data */
3822 sprintf(page + len, KERN_ERR PRINTK_HEADER
3823 " 24 Byte: %x MSG %x, "
3824 "%s MSGb to SYSOP\n",
3825 sense[7] >> 4, sense[7] & 0x0f,
3826 sense[1] & 0x10 ? "" : "no");
3827 } else {
3828 /* 32 Byte Sense Data */
3829 sprintf(page + len, KERN_ERR PRINTK_HEADER
3830 " 32 Byte: Format: %x "
3831 "Exception class %x\n",
3832 sense[6] & 0x0f, sense[22] >> 4);
3834 } else {
3835 sprintf(page + len, KERN_ERR PRINTK_HEADER
3836 " SORRY - NO VALID SENSE AVAILABLE\n");
3838 } else {
3839 sprintf(page + len, KERN_ERR PRINTK_HEADER
3840 " SORRY - NO TSB DATA AVAILABLE\n");
3842 printk("%s", page);
3843 free_page((unsigned long) page);
3846 static void dasd_eckd_dump_sense(struct dasd_device *device,
3847 struct dasd_ccw_req *req, struct irb *irb)
3849 if (scsw_is_tm(&irb->scsw))
3850 dasd_eckd_dump_sense_tcw(device, req, irb);
3851 else
3852 dasd_eckd_dump_sense_ccw(device, req, irb);
3855 static int dasd_eckd_pm_freeze(struct dasd_device *device)
3858 * the device should be disconnected from our LCU structure
3859 * on restore we will reconnect it and reread LCU specific
3860 * information like PAV support that might have changed
3862 dasd_alias_remove_device(device);
3863 dasd_alias_disconnect_device_from_lcu(device);
3865 return 0;
3868 static int dasd_eckd_restore_device(struct dasd_device *device)
3870 struct dasd_eckd_private *private;
3871 struct dasd_eckd_characteristics temp_rdc_data;
3872 int is_known, rc;
3873 struct dasd_uid temp_uid;
3874 unsigned long flags;
3876 private = (struct dasd_eckd_private *) device->private;
3878 /* Read Configuration Data */
3879 rc = dasd_eckd_read_conf(device);
3880 if (rc)
3881 goto out_err;
3883 dasd_eckd_get_uid(device, &temp_uid);
3884 /* Generate device unique id */
3885 rc = dasd_eckd_generate_uid(device);
3886 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3887 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
3888 dev_err(&device->cdev->dev, "The UID of the DASD has "
3889 "changed\n");
3890 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3891 if (rc)
3892 goto out_err;
3894 /* register lcu with alias handling, enable PAV if this is a new lcu */
3895 is_known = dasd_alias_make_device_known_to_lcu(device);
3896 if (is_known < 0)
3897 return is_known;
3898 if (!is_known) {
3899 dasd_eckd_validate_server(device);
3900 dasd_alias_lcu_setup_complete(device);
3901 } else
3902 dasd_alias_wait_for_lcu_setup(device);
3904 /* RE-Read Configuration Data */
3905 rc = dasd_eckd_read_conf(device);
3906 if (rc)
3907 goto out_err;
3909 /* Read Feature Codes */
3910 dasd_eckd_read_features(device);
3912 /* Read Device Characteristics */
3913 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
3914 &temp_rdc_data, 64);
3915 if (rc) {
3916 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
3917 "Read device characteristic failed, rc=%d", rc);
3918 goto out_err;
3920 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3921 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
3922 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3924 /* add device to alias management */
3925 dasd_alias_add_device(device);
3927 return 0;
3929 out_err:
3930 return -1;
3933 static int dasd_eckd_reload_device(struct dasd_device *device)
3935 struct dasd_eckd_private *private;
3936 int rc, old_base;
3937 char print_uid[60];
3938 struct dasd_uid uid;
3939 unsigned long flags;
3941 private = (struct dasd_eckd_private *) device->private;
3943 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3944 old_base = private->uid.base_unit_addr;
3945 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3947 /* Read Configuration Data */
3948 rc = dasd_eckd_read_conf(device);
3949 if (rc)
3950 goto out_err;
3952 rc = dasd_eckd_generate_uid(device);
3953 if (rc)
3954 goto out_err;
3956 * update unit address configuration and
3957 * add device to alias management
3959 dasd_alias_update_add_device(device);
3961 dasd_eckd_get_uid(device, &uid);
3963 if (old_base != uid.base_unit_addr) {
3964 if (strlen(uid.vduit) > 0)
3965 snprintf(print_uid, sizeof(print_uid),
3966 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
3967 uid.ssid, uid.base_unit_addr, uid.vduit);
3968 else
3969 snprintf(print_uid, sizeof(print_uid),
3970 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
3971 uid.ssid, uid.base_unit_addr);
3973 dev_info(&device->cdev->dev,
3974 "An Alias device was reassigned to a new base device "
3975 "with UID: %s\n", print_uid);
3977 return 0;
3979 out_err:
3980 return -1;
3983 static struct ccw_driver dasd_eckd_driver = {
3984 .name = "dasd-eckd",
3985 .owner = THIS_MODULE,
3986 .ids = dasd_eckd_ids,
3987 .probe = dasd_eckd_probe,
3988 .remove = dasd_generic_remove,
3989 .set_offline = dasd_generic_set_offline,
3990 .set_online = dasd_eckd_set_online,
3991 .notify = dasd_generic_notify,
3992 .path_event = dasd_generic_path_event,
3993 .freeze = dasd_generic_pm_freeze,
3994 .thaw = dasd_generic_restore_device,
3995 .restore = dasd_generic_restore_device,
3996 .uc_handler = dasd_generic_uc_handler,
4000 * max_blocks is dependent on the amount of storage that is available
4001 * in the static io buffer for each device. Currently each device has
4002 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4003 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4004 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4005 * addition we have one define extent ccw + 16 bytes of data and one
4006 * locate record ccw + 16 bytes of data. That makes:
4007 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4008 * We want to fit two into the available memory so that we can immediately
4009 * start the next request if one finishes off. That makes 249.5 blocks
4010 * for one request. Give a little safety and the result is 240.
4012 static struct dasd_discipline dasd_eckd_discipline = {
4013 .owner = THIS_MODULE,
4014 .name = "ECKD",
4015 .ebcname = "ECKD",
4016 .max_blocks = 190,
4017 .check_device = dasd_eckd_check_characteristics,
4018 .uncheck_device = dasd_eckd_uncheck_device,
4019 .do_analysis = dasd_eckd_do_analysis,
4020 .verify_path = dasd_eckd_verify_path,
4021 .ready_to_online = dasd_eckd_ready_to_online,
4022 .online_to_ready = dasd_eckd_online_to_ready,
4023 .fill_geometry = dasd_eckd_fill_geometry,
4024 .start_IO = dasd_start_IO,
4025 .term_IO = dasd_term_IO,
4026 .handle_terminated_request = dasd_eckd_handle_terminated_request,
4027 .format_device = dasd_eckd_format_device,
4028 .erp_action = dasd_eckd_erp_action,
4029 .erp_postaction = dasd_eckd_erp_postaction,
4030 .check_for_device_change = dasd_eckd_check_for_device_change,
4031 .build_cp = dasd_eckd_build_alias_cp,
4032 .free_cp = dasd_eckd_free_alias_cp,
4033 .dump_sense = dasd_eckd_dump_sense,
4034 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
4035 .fill_info = dasd_eckd_fill_info,
4036 .ioctl = dasd_eckd_ioctl,
4037 .freeze = dasd_eckd_pm_freeze,
4038 .restore = dasd_eckd_restore_device,
4039 .reload = dasd_eckd_reload_device,
4040 .get_uid = dasd_eckd_get_uid,
4043 static int __init
4044 dasd_eckd_init(void)
4046 int ret;
4048 ASCEBC(dasd_eckd_discipline.ebcname, 4);
4049 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4050 GFP_KERNEL | GFP_DMA);
4051 if (!dasd_reserve_req)
4052 return -ENOMEM;
4053 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4054 GFP_KERNEL | GFP_DMA);
4055 if (!path_verification_worker) {
4056 kfree(dasd_reserve_req);
4057 return -ENOMEM;
4059 ret = ccw_driver_register(&dasd_eckd_driver);
4060 if (!ret)
4061 wait_for_device_probe();
4062 else {
4063 kfree(path_verification_worker);
4064 kfree(dasd_reserve_req);
4066 return ret;
4069 static void __exit
4070 dasd_eckd_cleanup(void)
4072 ccw_driver_unregister(&dasd_eckd_driver);
4073 kfree(path_verification_worker);
4074 kfree(dasd_reserve_req);
4077 module_init(dasd_eckd_init);
4078 module_exit(dasd_eckd_cleanup);