1 // SPDX-License-Identifier: GPL-2.0
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/compat.h>
22 #include <linux/init.h>
23 #include <linux/seq_file.h>
25 #include <asm/css_chars.h>
26 #include <asm/debug.h>
27 #include <asm/idals.h>
28 #include <asm/ebcdic.h>
30 #include <linux/uaccess.h>
32 #include <asm/ccwdev.h>
34 #include <asm/schid.h>
35 #include <asm/chpid.h>
38 #include "dasd_eckd.h"
42 #endif /* PRINTK_HEADER */
43 #define PRINTK_HEADER "dasd(eckd):"
45 #define ECKD_C0(i) (i->home_bytes)
46 #define ECKD_F(i) (i->formula)
47 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
48 (i->factors.f_0x02.f1))
49 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
50 (i->factors.f_0x02.f2))
51 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
52 (i->factors.f_0x02.f3))
53 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
54 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
55 #define ECKD_F6(i) (i->factor6)
56 #define ECKD_F7(i) (i->factor7)
57 #define ECKD_F8(i) (i->factor8)
60 * raw track access always map to 64k in memory
61 * so it maps to 16 blocks of 4k per track
63 #define DASD_RAW_BLOCK_PER_TRACK 16
64 #define DASD_RAW_BLOCKSIZE 4096
65 /* 64k are 128 x 512 byte sectors */
66 #define DASD_RAW_SECTORS_PER_TRACK 128
68 MODULE_LICENSE("GPL");
70 static struct dasd_discipline dasd_eckd_discipline
;
72 /* The ccw bus type uses this table to find devices that it sends to
74 static struct ccw_device_id dasd_eckd_ids
[] = {
75 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info
= 0x1},
76 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info
= 0x2},
77 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info
= 0x3},
78 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info
= 0x4},
79 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info
= 0x5},
80 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info
= 0x6},
81 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info
= 0x7},
82 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info
= 0x8},
83 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info
= 0x9},
84 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info
= 0xa},
85 { /* end of list */ },
88 MODULE_DEVICE_TABLE(ccw
, dasd_eckd_ids
);
90 static struct ccw_driver dasd_eckd_driver
; /* see below */
92 static void *rawpadpage
;
95 #define INIT_CQR_UNFORMATTED 1
96 #define INIT_CQR_ERROR 2
98 /* emergency request for reserve/release */
100 struct dasd_ccw_req cqr
;
104 static DEFINE_MUTEX(dasd_reserve_mutex
);
106 /* definitions for the path verification worker */
107 struct path_verification_work_data
{
108 struct work_struct worker
;
109 struct dasd_device
*device
;
110 struct dasd_ccw_req cqr
;
112 __u8 rcd_buffer
[DASD_ECKD_RCD_DATA_SIZE
];
116 static struct path_verification_work_data
*path_verification_worker
;
117 static DEFINE_MUTEX(dasd_path_verification_mutex
);
119 struct check_attention_work_data
{
120 struct work_struct worker
;
121 struct dasd_device
*device
;
125 static int prepare_itcw(struct itcw
*, unsigned int, unsigned int, int,
126 struct dasd_device
*, struct dasd_device
*,
127 unsigned int, int, unsigned int, unsigned int,
128 unsigned int, unsigned int);
130 /* initial attempt at a probe function. this can be simplified once
131 * the other detection code is gone */
133 dasd_eckd_probe (struct ccw_device
*cdev
)
137 /* set ECKD specific ccw-device options */
138 ret
= ccw_device_set_options(cdev
, CCWDEV_ALLOW_FORCE
|
139 CCWDEV_DO_PATHGROUP
| CCWDEV_DO_MULTIPATH
);
141 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
142 "dasd_eckd_probe: could not set "
143 "ccw-device options");
146 ret
= dasd_generic_probe(cdev
, &dasd_eckd_discipline
);
151 dasd_eckd_set_online(struct ccw_device
*cdev
)
153 return dasd_generic_set_online(cdev
, &dasd_eckd_discipline
);
156 static const int sizes_trk0
[] = { 28, 148, 84 };
157 #define LABEL_SIZE 140
159 /* head and record addresses of count_area read in analysis ccw */
160 static const int count_area_head
[] = { 0, 0, 0, 0, 2 };
161 static const int count_area_rec
[] = { 1, 2, 3, 4, 1 };
163 static inline unsigned int
164 round_up_multiple(unsigned int no
, unsigned int mult
)
167 return (rem
? no
- rem
+ mult
: no
);
170 static inline unsigned int
171 ceil_quot(unsigned int d1
, unsigned int d2
)
173 return (d1
+ (d2
- 1)) / d2
;
177 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
178 unsigned int kl
, unsigned int dl
)
182 switch (rdc
->dev_type
) {
185 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
186 ceil_quot(dl
+ 12, 32));
188 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
190 dn
= ceil_quot(dl
+ 6, 232) + 1;
192 kn
= ceil_quot(kl
+ 6, 232) + 1;
193 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
194 9 + ceil_quot(dl
+ 6 * dn
, 34));
196 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
198 dn
= ceil_quot(dl
+ 6, 232) + 1;
200 kn
= ceil_quot(kl
+ 6, 232) + 1;
201 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
202 ceil_quot(dl
+ 6 * dn
, 34));
204 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
209 static void set_ch_t(struct ch_t
*geo
, __u32 cyl
, __u8 head
)
211 geo
->cyl
= (__u16
) cyl
;
212 geo
->head
= cyl
>> 16;
217 static int check_XRC(struct ccw1
*ccw
, struct DE_eckd_data
*data
,
218 struct dasd_device
*device
)
220 struct dasd_eckd_private
*private = device
->private;
223 if (!private->rdc_data
.facilities
.XRC_supported
)
226 /* switch on System Time Stamp - needed for XRC Support */
227 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
228 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
230 rc
= get_phys_clock(&data
->ep_sys_time
);
231 /* Ignore return code if sync clock is switched off. */
232 if (rc
== -EOPNOTSUPP
|| rc
== -EACCES
)
236 ccw
->count
= sizeof(struct DE_eckd_data
);
237 ccw
->flags
|= CCW_FLAG_SLI
;
244 define_extent(struct ccw1
*ccw
, struct DE_eckd_data
*data
, unsigned int trk
,
245 unsigned int totrk
, int cmd
, struct dasd_device
*device
,
248 struct dasd_eckd_private
*private = device
->private;
249 u16 heads
, beghead
, endhead
;
254 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
257 ccw
->cda
= (__u32
)__pa(data
);
260 memset(data
, 0, sizeof(struct DE_eckd_data
));
262 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
263 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
264 case DASD_ECKD_CCW_READ
:
265 case DASD_ECKD_CCW_READ_MT
:
266 case DASD_ECKD_CCW_READ_CKD
:
267 case DASD_ECKD_CCW_READ_CKD_MT
:
268 case DASD_ECKD_CCW_READ_KD
:
269 case DASD_ECKD_CCW_READ_KD_MT
:
270 data
->mask
.perm
= 0x1;
271 data
->attributes
.operation
= private->attrib
.operation
;
273 case DASD_ECKD_CCW_READ_COUNT
:
274 data
->mask
.perm
= 0x1;
275 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
277 case DASD_ECKD_CCW_READ_TRACK
:
278 case DASD_ECKD_CCW_READ_TRACK_DATA
:
279 data
->mask
.perm
= 0x1;
280 data
->attributes
.operation
= private->attrib
.operation
;
283 case DASD_ECKD_CCW_WRITE
:
284 case DASD_ECKD_CCW_WRITE_MT
:
285 case DASD_ECKD_CCW_WRITE_KD
:
286 case DASD_ECKD_CCW_WRITE_KD_MT
:
287 data
->mask
.perm
= 0x02;
288 data
->attributes
.operation
= private->attrib
.operation
;
289 rc
= check_XRC(ccw
, data
, device
);
291 case DASD_ECKD_CCW_WRITE_CKD
:
292 case DASD_ECKD_CCW_WRITE_CKD_MT
:
293 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
294 rc
= check_XRC(ccw
, data
, device
);
296 case DASD_ECKD_CCW_ERASE
:
297 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
298 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
299 data
->mask
.perm
= 0x3;
300 data
->mask
.auth
= 0x1;
301 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
302 rc
= check_XRC(ccw
, data
, device
);
304 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
305 data
->mask
.perm
= 0x03;
306 data
->attributes
.operation
= private->attrib
.operation
;
309 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
310 data
->mask
.perm
= 0x02;
311 data
->attributes
.operation
= private->attrib
.operation
;
312 data
->blk_size
= blksize
;
313 rc
= check_XRC(ccw
, data
, device
);
316 dev_err(&device
->cdev
->dev
,
317 "0x%x is not a known command\n", cmd
);
321 data
->attributes
.mode
= 0x3; /* ECKD */
323 if ((private->rdc_data
.cu_type
== 0x2105 ||
324 private->rdc_data
.cu_type
== 0x2107 ||
325 private->rdc_data
.cu_type
== 0x1750)
326 && !(private->uses_cdl
&& trk
< 2))
327 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
329 heads
= private->rdc_data
.trk_per_cyl
;
330 begcyl
= trk
/ heads
;
331 beghead
= trk
% heads
;
332 endcyl
= totrk
/ heads
;
333 endhead
= totrk
% heads
;
335 /* check for sequential prestage - enhance cylinder range */
336 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
337 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
339 if (endcyl
+ private->attrib
.nr_cyl
< private->real_cyl
)
340 endcyl
+= private->attrib
.nr_cyl
;
342 endcyl
= (private->real_cyl
- 1);
345 set_ch_t(&data
->beg_ext
, begcyl
, beghead
);
346 set_ch_t(&data
->end_ext
, endcyl
, endhead
);
351 static void locate_record_ext(struct ccw1
*ccw
, struct LRE_eckd_data
*data
,
352 unsigned int trk
, unsigned int rec_on_trk
,
353 int count
, int cmd
, struct dasd_device
*device
,
354 unsigned int reclen
, unsigned int tlf
)
356 struct dasd_eckd_private
*private = device
->private;
361 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD_EXT
;
363 if (cmd
== DASD_ECKD_CCW_WRITE_FULL_TRACK
)
367 ccw
->cda
= (__u32
)__pa(data
);
370 memset(data
, 0, sizeof(*data
));
373 switch (private->rdc_data
.dev_type
) {
375 dn
= ceil_quot(reclen
+ 6, 232);
376 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
377 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
380 d
= 7 + ceil_quot(reclen
+ 12, 32);
381 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
385 data
->sector
= sector
;
386 /* note: meaning of count depends on the operation
387 * for record based I/O it's the number of records, but for
388 * track based I/O it's the number of tracks
392 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
393 data
->operation
.orientation
= 0x3;
394 data
->operation
.operation
= 0x03;
396 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
397 data
->operation
.orientation
= 0x3;
398 data
->operation
.operation
= 0x16;
400 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
401 data
->operation
.orientation
= 0x1;
402 data
->operation
.operation
= 0x03;
405 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
406 data
->operation
.orientation
= 0x3;
407 data
->operation
.operation
= 0x16;
410 case DASD_ECKD_CCW_WRITE
:
411 case DASD_ECKD_CCW_WRITE_MT
:
412 case DASD_ECKD_CCW_WRITE_KD
:
413 case DASD_ECKD_CCW_WRITE_KD_MT
:
414 data
->auxiliary
.length_valid
= 0x1;
415 data
->length
= reclen
;
416 data
->operation
.operation
= 0x01;
418 case DASD_ECKD_CCW_WRITE_CKD
:
419 case DASD_ECKD_CCW_WRITE_CKD_MT
:
420 data
->auxiliary
.length_valid
= 0x1;
421 data
->length
= reclen
;
422 data
->operation
.operation
= 0x03;
424 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
425 data
->operation
.orientation
= 0x0;
426 data
->operation
.operation
= 0x3F;
427 data
->extended_operation
= 0x11;
429 data
->extended_parameter_length
= 0x02;
430 if (data
->count
> 8) {
431 data
->extended_parameter
[0] = 0xFF;
432 data
->extended_parameter
[1] = 0xFF;
433 data
->extended_parameter
[1] <<= (16 - count
);
435 data
->extended_parameter
[0] = 0xFF;
436 data
->extended_parameter
[0] <<= (8 - count
);
437 data
->extended_parameter
[1] = 0x00;
441 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
442 data
->auxiliary
.length_valid
= 0x1;
443 data
->length
= reclen
; /* not tlf, as one might think */
444 data
->operation
.operation
= 0x3F;
445 data
->extended_operation
= 0x23;
447 case DASD_ECKD_CCW_READ
:
448 case DASD_ECKD_CCW_READ_MT
:
449 case DASD_ECKD_CCW_READ_KD
:
450 case DASD_ECKD_CCW_READ_KD_MT
:
451 data
->auxiliary
.length_valid
= 0x1;
452 data
->length
= reclen
;
453 data
->operation
.operation
= 0x06;
455 case DASD_ECKD_CCW_READ_CKD
:
456 case DASD_ECKD_CCW_READ_CKD_MT
:
457 data
->auxiliary
.length_valid
= 0x1;
458 data
->length
= reclen
;
459 data
->operation
.operation
= 0x16;
461 case DASD_ECKD_CCW_READ_COUNT
:
462 data
->operation
.operation
= 0x06;
464 case DASD_ECKD_CCW_READ_TRACK
:
465 data
->operation
.orientation
= 0x1;
466 data
->operation
.operation
= 0x0C;
467 data
->extended_parameter_length
= 0;
470 case DASD_ECKD_CCW_READ_TRACK_DATA
:
471 data
->auxiliary
.length_valid
= 0x1;
473 data
->operation
.operation
= 0x0C;
475 case DASD_ECKD_CCW_ERASE
:
476 data
->length
= reclen
;
477 data
->auxiliary
.length_valid
= 0x1;
478 data
->operation
.operation
= 0x0b;
481 DBF_DEV_EVENT(DBF_ERR
, device
,
482 "fill LRE unknown opcode 0x%x", cmd
);
485 set_ch_t(&data
->seek_addr
,
486 trk
/ private->rdc_data
.trk_per_cyl
,
487 trk
% private->rdc_data
.trk_per_cyl
);
488 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
489 data
->search_arg
.head
= data
->seek_addr
.head
;
490 data
->search_arg
.record
= rec_on_trk
;
493 static int prefix_LRE(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
494 unsigned int trk
, unsigned int totrk
, int cmd
,
495 struct dasd_device
*basedev
, struct dasd_device
*startdev
,
496 unsigned int format
, unsigned int rec_on_trk
, int count
,
497 unsigned int blksize
, unsigned int tlf
)
499 struct dasd_eckd_private
*basepriv
, *startpriv
;
500 struct LRE_eckd_data
*lredata
;
501 struct DE_eckd_data
*dedata
;
504 basepriv
= basedev
->private;
505 startpriv
= startdev
->private;
506 dedata
= &pfxdata
->define_extent
;
507 lredata
= &pfxdata
->locate_record
;
509 ccw
->cmd_code
= DASD_ECKD_CCW_PFX
;
511 if (cmd
== DASD_ECKD_CCW_WRITE_FULL_TRACK
) {
512 ccw
->count
= sizeof(*pfxdata
) + 2;
513 ccw
->cda
= (__u32
) __pa(pfxdata
);
514 memset(pfxdata
, 0, sizeof(*pfxdata
) + 2);
516 ccw
->count
= sizeof(*pfxdata
);
517 ccw
->cda
= (__u32
) __pa(pfxdata
);
518 memset(pfxdata
, 0, sizeof(*pfxdata
));
523 DBF_DEV_EVENT(DBF_ERR
, basedev
,
524 "PFX LRE unknown format 0x%x", format
);
528 pfxdata
->format
= format
;
529 pfxdata
->base_address
= basepriv
->ned
->unit_addr
;
530 pfxdata
->base_lss
= basepriv
->ned
->ID
;
531 pfxdata
->validity
.define_extent
= 1;
533 /* private uid is kept up to date, conf_data may be outdated */
534 if (startpriv
->uid
.type
== UA_BASE_PAV_ALIAS
)
535 pfxdata
->validity
.verify_base
= 1;
537 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
) {
538 pfxdata
->validity
.verify_base
= 1;
539 pfxdata
->validity
.hyper_pav
= 1;
542 rc
= define_extent(NULL
, dedata
, trk
, totrk
, cmd
, basedev
, blksize
);
545 * For some commands the System Time Stamp is set in the define extent
546 * data when XRC is supported. The validity of the time stamp must be
547 * reflected in the prefix data as well.
549 if (dedata
->ga_extended
& 0x08 && dedata
->ga_extended
& 0x02)
550 pfxdata
->validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
553 locate_record_ext(NULL
, lredata
, trk
, rec_on_trk
, count
, cmd
,
554 basedev
, blksize
, tlf
);
560 static int prefix(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
561 unsigned int trk
, unsigned int totrk
, int cmd
,
562 struct dasd_device
*basedev
, struct dasd_device
*startdev
)
564 return prefix_LRE(ccw
, pfxdata
, trk
, totrk
, cmd
, basedev
, startdev
,
569 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, unsigned int trk
,
570 unsigned int rec_on_trk
, int no_rec
, int cmd
,
571 struct dasd_device
* device
, int reclen
)
573 struct dasd_eckd_private
*private = device
->private;
577 DBF_DEV_EVENT(DBF_INFO
, device
,
578 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
579 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
581 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
584 ccw
->cda
= (__u32
) __pa(data
);
586 memset(data
, 0, sizeof(struct LO_eckd_data
));
589 switch (private->rdc_data
.dev_type
) {
591 dn
= ceil_quot(reclen
+ 6, 232);
592 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
593 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
596 d
= 7 + ceil_quot(reclen
+ 12, 32);
597 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
601 data
->sector
= sector
;
602 data
->count
= no_rec
;
604 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
605 data
->operation
.orientation
= 0x3;
606 data
->operation
.operation
= 0x03;
608 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
609 data
->operation
.orientation
= 0x3;
610 data
->operation
.operation
= 0x16;
612 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
613 data
->operation
.orientation
= 0x1;
614 data
->operation
.operation
= 0x03;
617 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
618 data
->operation
.orientation
= 0x3;
619 data
->operation
.operation
= 0x16;
622 case DASD_ECKD_CCW_WRITE
:
623 case DASD_ECKD_CCW_WRITE_MT
:
624 case DASD_ECKD_CCW_WRITE_KD
:
625 case DASD_ECKD_CCW_WRITE_KD_MT
:
626 data
->auxiliary
.last_bytes_used
= 0x1;
627 data
->length
= reclen
;
628 data
->operation
.operation
= 0x01;
630 case DASD_ECKD_CCW_WRITE_CKD
:
631 case DASD_ECKD_CCW_WRITE_CKD_MT
:
632 data
->auxiliary
.last_bytes_used
= 0x1;
633 data
->length
= reclen
;
634 data
->operation
.operation
= 0x03;
636 case DASD_ECKD_CCW_READ
:
637 case DASD_ECKD_CCW_READ_MT
:
638 case DASD_ECKD_CCW_READ_KD
:
639 case DASD_ECKD_CCW_READ_KD_MT
:
640 data
->auxiliary
.last_bytes_used
= 0x1;
641 data
->length
= reclen
;
642 data
->operation
.operation
= 0x06;
644 case DASD_ECKD_CCW_READ_CKD
:
645 case DASD_ECKD_CCW_READ_CKD_MT
:
646 data
->auxiliary
.last_bytes_used
= 0x1;
647 data
->length
= reclen
;
648 data
->operation
.operation
= 0x16;
650 case DASD_ECKD_CCW_READ_COUNT
:
651 data
->operation
.operation
= 0x06;
653 case DASD_ECKD_CCW_ERASE
:
654 data
->length
= reclen
;
655 data
->auxiliary
.last_bytes_used
= 0x1;
656 data
->operation
.operation
= 0x0b;
659 DBF_DEV_EVENT(DBF_ERR
, device
, "unknown locate record "
662 set_ch_t(&data
->seek_addr
,
663 trk
/ private->rdc_data
.trk_per_cyl
,
664 trk
% private->rdc_data
.trk_per_cyl
);
665 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
666 data
->search_arg
.head
= data
->seek_addr
.head
;
667 data
->search_arg
.record
= rec_on_trk
;
671 * Returns 1 if the block is one of the special blocks that needs
672 * to get read/written with the KD variant of the command.
673 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
674 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
675 * Luckily the KD variants differ only by one bit (0x08) from the
676 * normal variant. So don't wonder about code like:
677 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
678 * ccw->cmd_code |= 0x8;
681 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
685 if (recid
< blk_per_trk
)
687 if (recid
< 2 * blk_per_trk
)
693 * Returns the record size for the special blocks of the cdl format.
694 * Only returns something useful if dasd_eckd_cdl_special is true
698 dasd_eckd_cdl_reclen(int recid
)
701 return sizes_trk0
[recid
];
704 /* create unique id from private structure. */
705 static void create_uid(struct dasd_eckd_private
*private)
708 struct dasd_uid
*uid
;
711 memset(uid
, 0, sizeof(struct dasd_uid
));
712 memcpy(uid
->vendor
, private->ned
->HDA_manufacturer
,
713 sizeof(uid
->vendor
) - 1);
714 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
715 memcpy(uid
->serial
, private->ned
->HDA_location
,
716 sizeof(uid
->serial
) - 1);
717 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
718 uid
->ssid
= private->gneq
->subsystemID
;
719 uid
->real_unit_addr
= private->ned
->unit_addr
;
721 uid
->type
= private->sneq
->sua_flags
;
722 if (uid
->type
== UA_BASE_PAV_ALIAS
)
723 uid
->base_unit_addr
= private->sneq
->base_unit_addr
;
725 uid
->type
= UA_BASE_DEVICE
;
727 if (private->vdsneq
) {
728 for (count
= 0; count
< 16; count
++) {
729 sprintf(uid
->vduit
+2*count
, "%02x",
730 private->vdsneq
->uit
[count
]);
736 * Generate device unique id that specifies the physical device.
738 static int dasd_eckd_generate_uid(struct dasd_device
*device
)
740 struct dasd_eckd_private
*private = device
->private;
745 if (!private->ned
|| !private->gneq
)
747 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
749 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
753 static int dasd_eckd_get_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
755 struct dasd_eckd_private
*private = device
->private;
759 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
761 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
768 * compare device UID with data of a given dasd_eckd_private structure
771 static int dasd_eckd_compare_path_uid(struct dasd_device
*device
,
772 struct dasd_eckd_private
*private)
774 struct dasd_uid device_uid
;
777 dasd_eckd_get_uid(device
, &device_uid
);
779 return memcmp(&device_uid
, &private->uid
, sizeof(struct dasd_uid
));
782 static void dasd_eckd_fill_rcd_cqr(struct dasd_device
*device
,
783 struct dasd_ccw_req
*cqr
,
789 * buffer has to start with EBCDIC "V1.0" to show
790 * support for virtual device SNEQ
792 rcd_buffer
[0] = 0xE5;
793 rcd_buffer
[1] = 0xF1;
794 rcd_buffer
[2] = 0x4B;
795 rcd_buffer
[3] = 0xF0;
798 ccw
->cmd_code
= DASD_ECKD_CCW_RCD
;
800 ccw
->cda
= (__u32
)(addr_t
)rcd_buffer
;
801 ccw
->count
= DASD_ECKD_RCD_DATA_SIZE
;
802 cqr
->magic
= DASD_ECKD_MAGIC
;
804 cqr
->startdev
= device
;
805 cqr
->memdev
= device
;
807 cqr
->expires
= 10*HZ
;
810 cqr
->buildclk
= get_tod_clock();
811 cqr
->status
= DASD_CQR_FILLED
;
812 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
816 * Wakeup helper for read_conf
817 * if the cqr is not done and needs some error recovery
818 * the buffer has to be re-initialized with the EBCDIC "V1.0"
819 * to show support for virtual device SNEQ
821 static void read_conf_cb(struct dasd_ccw_req
*cqr
, void *data
)
826 if (cqr
->status
!= DASD_CQR_DONE
) {
828 rcd_buffer
= (__u8
*)((addr_t
) ccw
->cda
);
829 memset(rcd_buffer
, 0, sizeof(*rcd_buffer
));
831 rcd_buffer
[0] = 0xE5;
832 rcd_buffer
[1] = 0xF1;
833 rcd_buffer
[2] = 0x4B;
834 rcd_buffer
[3] = 0xF0;
836 dasd_wakeup_cb(cqr
, data
);
839 static int dasd_eckd_read_conf_immediately(struct dasd_device
*device
,
840 struct dasd_ccw_req
*cqr
,
847 * sanity check: scan for RCD command in extended SenseID data
848 * some devices do not support RCD
850 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
851 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
)
854 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buffer
, lpm
);
855 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
856 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
858 cqr
->callback
= read_conf_cb
;
859 rc
= dasd_sleep_on_immediatly(cqr
);
863 static int dasd_eckd_read_conf_lpm(struct dasd_device
*device
,
865 int *rcd_buffer_size
, __u8 lpm
)
868 char *rcd_buf
= NULL
;
870 struct dasd_ccw_req
*cqr
;
873 * sanity check: scan for RCD command in extended SenseID data
874 * some devices do not support RCD
876 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
877 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
) {
881 rcd_buf
= kzalloc(DASD_ECKD_RCD_DATA_SIZE
, GFP_KERNEL
| GFP_DMA
);
886 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* RCD */,
887 0, /* use rcd_buf as data ara */
890 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
891 "Could not allocate RCD request");
895 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buf
, lpm
);
896 cqr
->callback
= read_conf_cb
;
897 ret
= dasd_sleep_on(cqr
);
899 * on success we update the user input parms
901 dasd_sfree_request(cqr
, cqr
->memdev
);
905 *rcd_buffer_size
= DASD_ECKD_RCD_DATA_SIZE
;
906 *rcd_buffer
= rcd_buf
;
911 *rcd_buffer_size
= 0;
915 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private
*private)
918 struct dasd_sneq
*sneq
;
922 private->sneq
= NULL
;
923 private->vdsneq
= NULL
;
924 private->gneq
= NULL
;
925 count
= private->conf_len
/ sizeof(struct dasd_sneq
);
926 sneq
= (struct dasd_sneq
*)private->conf_data
;
927 for (i
= 0; i
< count
; ++i
) {
928 if (sneq
->flags
.identifier
== 1 && sneq
->format
== 1)
929 private->sneq
= sneq
;
930 else if (sneq
->flags
.identifier
== 1 && sneq
->format
== 4)
931 private->vdsneq
= (struct vd_sneq
*)sneq
;
932 else if (sneq
->flags
.identifier
== 2)
933 private->gneq
= (struct dasd_gneq
*)sneq
;
934 else if (sneq
->flags
.identifier
== 3 && sneq
->res1
== 1)
935 private->ned
= (struct dasd_ned
*)sneq
;
938 if (!private->ned
|| !private->gneq
) {
940 private->sneq
= NULL
;
941 private->vdsneq
= NULL
;
942 private->gneq
= NULL
;
949 static unsigned char dasd_eckd_path_access(void *conf_data
, int conf_len
)
951 struct dasd_gneq
*gneq
;
954 count
= conf_len
/ sizeof(*gneq
);
955 gneq
= (struct dasd_gneq
*)conf_data
;
957 for (i
= 0; i
< count
; ++i
) {
958 if (gneq
->flags
.identifier
== 2) {
965 return ((char *)gneq
)[18] & 0x07;
970 static void dasd_eckd_clear_conf_data(struct dasd_device
*device
)
972 struct dasd_eckd_private
*private = device
->private;
975 private->conf_data
= NULL
;
976 private->conf_len
= 0;
977 for (i
= 0; i
< 8; i
++) {
978 kfree(device
->path
[i
].conf_data
);
979 device
->path
[i
].conf_data
= NULL
;
980 device
->path
[i
].cssid
= 0;
981 device
->path
[i
].ssid
= 0;
982 device
->path
[i
].chpid
= 0;
987 static int dasd_eckd_read_conf(struct dasd_device
*device
)
990 int conf_len
, conf_data_saved
;
991 int rc
, path_err
, pos
;
993 struct dasd_eckd_private
*private, path_private
;
994 struct dasd_uid
*uid
;
995 char print_path_uid
[60], print_device_uid
[60];
996 struct channel_path_desc
*chp_desc
;
997 struct subchannel_id sch_id
;
999 private = device
->private;
1000 opm
= ccw_device_get_path_mask(device
->cdev
);
1001 ccw_device_get_schid(device
->cdev
, &sch_id
);
1002 conf_data_saved
= 0;
1004 /* get configuration data per operational path */
1005 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1008 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
1010 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
1011 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1012 "Read configuration data returned "
1016 if (conf_data
== NULL
) {
1017 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1018 "No configuration data "
1020 /* no further analysis possible */
1021 dasd_path_add_opm(device
, opm
);
1022 continue; /* no error */
1024 /* save first valid configuration data */
1025 if (!conf_data_saved
) {
1026 /* initially clear previously stored conf_data */
1027 dasd_eckd_clear_conf_data(device
);
1028 private->conf_data
= conf_data
;
1029 private->conf_len
= conf_len
;
1030 if (dasd_eckd_identify_conf_parts(private)) {
1031 private->conf_data
= NULL
;
1032 private->conf_len
= 0;
1036 pos
= pathmask_to_pos(lpm
);
1037 /* store per path conf_data */
1038 device
->path
[pos
].conf_data
= conf_data
;
1039 device
->path
[pos
].cssid
= sch_id
.cssid
;
1040 device
->path
[pos
].ssid
= sch_id
.ssid
;
1041 chp_desc
= ccw_device_get_chp_desc(device
->cdev
, pos
);
1043 device
->path
[pos
].chpid
= chp_desc
->chpid
;
1046 * build device UID that other path data
1047 * can be compared to it
1049 dasd_eckd_generate_uid(device
);
1052 path_private
.conf_data
= conf_data
;
1053 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1054 if (dasd_eckd_identify_conf_parts(
1056 path_private
.conf_data
= NULL
;
1057 path_private
.conf_len
= 0;
1061 if (dasd_eckd_compare_path_uid(
1062 device
, &path_private
)) {
1063 uid
= &path_private
.uid
;
1064 if (strlen(uid
->vduit
) > 0)
1065 snprintf(print_path_uid
,
1066 sizeof(print_path_uid
),
1067 "%s.%s.%04x.%02x.%s",
1068 uid
->vendor
, uid
->serial
,
1069 uid
->ssid
, uid
->real_unit_addr
,
1072 snprintf(print_path_uid
,
1073 sizeof(print_path_uid
),
1075 uid
->vendor
, uid
->serial
,
1077 uid
->real_unit_addr
);
1078 uid
= &private->uid
;
1079 if (strlen(uid
->vduit
) > 0)
1080 snprintf(print_device_uid
,
1081 sizeof(print_device_uid
),
1082 "%s.%s.%04x.%02x.%s",
1083 uid
->vendor
, uid
->serial
,
1084 uid
->ssid
, uid
->real_unit_addr
,
1087 snprintf(print_device_uid
,
1088 sizeof(print_device_uid
),
1090 uid
->vendor
, uid
->serial
,
1092 uid
->real_unit_addr
);
1093 dev_err(&device
->cdev
->dev
,
1094 "Not all channel paths lead to "
1095 "the same device, path %02X leads to "
1096 "device %s instead of %s\n", lpm
,
1097 print_path_uid
, print_device_uid
);
1099 dasd_path_add_cablepm(device
, lpm
);
1102 pos
= pathmask_to_pos(lpm
);
1103 /* store per path conf_data */
1104 device
->path
[pos
].conf_data
= conf_data
;
1105 device
->path
[pos
].cssid
= sch_id
.cssid
;
1106 device
->path
[pos
].ssid
= sch_id
.ssid
;
1107 chp_desc
= ccw_device_get_chp_desc(device
->cdev
, pos
);
1109 device
->path
[pos
].chpid
= chp_desc
->chpid
;
1111 path_private
.conf_data
= NULL
;
1112 path_private
.conf_len
= 0;
1114 switch (dasd_eckd_path_access(conf_data
, conf_len
)) {
1116 dasd_path_add_nppm(device
, lpm
);
1119 dasd_path_add_ppm(device
, lpm
);
1122 if (!dasd_path_get_opm(device
)) {
1123 dasd_path_set_opm(device
, lpm
);
1124 dasd_generic_path_operational(device
);
1126 dasd_path_add_opm(device
, lpm
);
1133 static u32
get_fcx_max_data(struct dasd_device
*device
)
1135 struct dasd_eckd_private
*private = device
->private;
1136 int fcx_in_css
, fcx_in_gneq
, fcx_in_features
;
1141 /* is transport mode supported? */
1142 fcx_in_css
= css_general_characteristics
.fcx
;
1143 fcx_in_gneq
= private->gneq
->reserved2
[7] & 0x04;
1144 fcx_in_features
= private->features
.feature
[40] & 0x80;
1145 tpm
= fcx_in_css
&& fcx_in_gneq
&& fcx_in_features
;
1150 mdc
= ccw_device_get_mdc(device
->cdev
, 0);
1152 dev_warn(&device
->cdev
->dev
, "Detecting the maximum supported data size for zHPF requests failed\n");
1155 return (u32
)mdc
* FCX_MAX_DATA_FACTOR
;
1159 static int verify_fcx_max_data(struct dasd_device
*device
, __u8 lpm
)
1161 struct dasd_eckd_private
*private = device
->private;
1165 if (private->fcx_max_data
) {
1166 mdc
= ccw_device_get_mdc(device
->cdev
, lpm
);
1168 dev_warn(&device
->cdev
->dev
,
1169 "Detecting the maximum data size for zHPF "
1170 "requests failed (rc=%d) for a new path %x\n",
1174 fcx_max_data
= (u32
)mdc
* FCX_MAX_DATA_FACTOR
;
1175 if (fcx_max_data
< private->fcx_max_data
) {
1176 dev_warn(&device
->cdev
->dev
,
1177 "The maximum data size for zHPF requests %u "
1178 "on a new path %x is below the active maximum "
1179 "%u\n", fcx_max_data
, lpm
,
1180 private->fcx_max_data
);
1187 static int rebuild_device_uid(struct dasd_device
*device
,
1188 struct path_verification_work_data
*data
)
1190 struct dasd_eckd_private
*private = device
->private;
1191 __u8 lpm
, opm
= dasd_path_get_opm(device
);
1194 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1197 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1198 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1199 data
->cqr
.cpaddr
= &data
->ccw
;
1200 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1205 if (rc
== -EOPNOTSUPP
) /* -EOPNOTSUPP is ok */
1207 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1208 "Read configuration data "
1209 "returned error %d", rc
);
1212 memcpy(private->conf_data
, data
->rcd_buffer
,
1213 DASD_ECKD_RCD_DATA_SIZE
);
1214 if (dasd_eckd_identify_conf_parts(private)) {
1216 } else /* first valid path is enough */
1221 rc
= dasd_eckd_generate_uid(device
);
1226 static void do_path_verification_work(struct work_struct
*work
)
1228 struct path_verification_work_data
*data
;
1229 struct dasd_device
*device
;
1230 struct dasd_eckd_private path_private
;
1231 struct dasd_uid
*uid
;
1232 __u8 path_rcd_buf
[DASD_ECKD_RCD_DATA_SIZE
];
1233 __u8 lpm
, opm
, npm
, ppm
, epm
, hpfpm
, cablepm
;
1234 unsigned long flags
;
1238 data
= container_of(work
, struct path_verification_work_data
, worker
);
1239 device
= data
->device
;
1241 /* delay path verification until device was resumed */
1242 if (test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
1243 schedule_work(work
);
1246 /* check if path verification already running and delay if so */
1247 if (test_and_set_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
)) {
1248 schedule_work(work
);
1258 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1259 if (!(lpm
& data
->tbvpm
))
1261 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1262 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1263 data
->cqr
.cpaddr
= &data
->ccw
;
1264 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1268 switch (dasd_eckd_path_access(data
->rcd_buffer
,
1269 DASD_ECKD_RCD_DATA_SIZE
)
1279 } else if (rc
== -EOPNOTSUPP
) {
1280 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1281 "path verification: No configuration "
1284 } else if (rc
== -EAGAIN
) {
1285 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1286 "path verification: device is stopped,"
1287 " try again later");
1290 dev_warn(&device
->cdev
->dev
,
1291 "Reading device feature codes failed "
1292 "(rc=%d) for new path %x\n", rc
, lpm
);
1295 if (verify_fcx_max_data(device
, lpm
)) {
1304 * save conf_data for comparison after
1305 * rebuild_device_uid may have changed
1308 memcpy(&path_rcd_buf
, data
->rcd_buffer
,
1309 DASD_ECKD_RCD_DATA_SIZE
);
1310 path_private
.conf_data
= (void *) &path_rcd_buf
;
1311 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1312 if (dasd_eckd_identify_conf_parts(&path_private
)) {
1313 path_private
.conf_data
= NULL
;
1314 path_private
.conf_len
= 0;
1319 * compare path UID with device UID only if at least
1320 * one valid path is left
1321 * in other case the device UID may have changed and
1322 * the first working path UID will be used as device UID
1324 if (dasd_path_get_opm(device
) &&
1325 dasd_eckd_compare_path_uid(device
, &path_private
)) {
1327 * the comparison was not successful
1328 * rebuild the device UID with at least one
1329 * known path in case a z/VM hyperswap command
1330 * has changed the device
1332 * after this compare again
1334 * if either the rebuild or the recompare fails
1335 * the path can not be used
1337 if (rebuild_device_uid(device
, data
) ||
1338 dasd_eckd_compare_path_uid(
1339 device
, &path_private
)) {
1340 uid
= &path_private
.uid
;
1341 if (strlen(uid
->vduit
) > 0)
1342 snprintf(print_uid
, sizeof(print_uid
),
1343 "%s.%s.%04x.%02x.%s",
1344 uid
->vendor
, uid
->serial
,
1345 uid
->ssid
, uid
->real_unit_addr
,
1348 snprintf(print_uid
, sizeof(print_uid
),
1350 uid
->vendor
, uid
->serial
,
1352 uid
->real_unit_addr
);
1353 dev_err(&device
->cdev
->dev
,
1354 "The newly added channel path %02X "
1355 "will not be used because it leads "
1356 "to a different device %s\n",
1367 * There is a small chance that a path is lost again between
1368 * above path verification and the following modification of
1369 * the device opm mask. We could avoid that race here by using
1370 * yet another path mask, but we rather deal with this unlikely
1371 * situation in dasd_start_IO.
1373 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1374 if (!dasd_path_get_opm(device
) && opm
) {
1375 dasd_path_set_opm(device
, opm
);
1376 dasd_generic_path_operational(device
);
1378 dasd_path_add_opm(device
, opm
);
1380 dasd_path_add_nppm(device
, npm
);
1381 dasd_path_add_ppm(device
, ppm
);
1382 dasd_path_add_tbvpm(device
, epm
);
1383 dasd_path_add_cablepm(device
, cablepm
);
1384 dasd_path_add_nohpfpm(device
, hpfpm
);
1385 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1387 clear_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
);
1388 dasd_put_device(device
);
1390 mutex_unlock(&dasd_path_verification_mutex
);
1395 static int dasd_eckd_verify_path(struct dasd_device
*device
, __u8 lpm
)
1397 struct path_verification_work_data
*data
;
1399 data
= kmalloc(sizeof(*data
), GFP_ATOMIC
| GFP_DMA
);
1401 if (mutex_trylock(&dasd_path_verification_mutex
)) {
1402 data
= path_verification_worker
;
1407 memset(data
, 0, sizeof(*data
));
1410 INIT_WORK(&data
->worker
, do_path_verification_work
);
1411 dasd_get_device(device
);
1412 data
->device
= device
;
1414 schedule_work(&data
->worker
);
1418 static void dasd_eckd_reset_path(struct dasd_device
*device
, __u8 pm
)
1420 struct dasd_eckd_private
*private = device
->private;
1421 unsigned long flags
;
1423 if (!private->fcx_max_data
)
1424 private->fcx_max_data
= get_fcx_max_data(device
);
1425 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1426 dasd_path_set_tbvpm(device
, pm
? : dasd_path_get_notoperpm(device
));
1427 dasd_schedule_device_bh(device
);
1428 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1431 static int dasd_eckd_read_features(struct dasd_device
*device
)
1433 struct dasd_eckd_private
*private = device
->private;
1434 struct dasd_psf_prssd_data
*prssdp
;
1435 struct dasd_rssd_features
*features
;
1436 struct dasd_ccw_req
*cqr
;
1440 memset(&private->features
, 0, sizeof(struct dasd_rssd_features
));
1441 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
1442 (sizeof(struct dasd_psf_prssd_data
) +
1443 sizeof(struct dasd_rssd_features
)),
1446 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s", "Could not "
1447 "allocate initialization request");
1448 return PTR_ERR(cqr
);
1450 cqr
->startdev
= device
;
1451 cqr
->memdev
= device
;
1454 cqr
->expires
= 10 * HZ
;
1456 /* Prepare for Read Subsystem Data */
1457 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1458 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1459 prssdp
->order
= PSF_ORDER_PRSSD
;
1460 prssdp
->suborder
= 0x41; /* Read Feature Codes */
1461 /* all other bytes of prssdp must be zero */
1464 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1465 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1466 ccw
->flags
|= CCW_FLAG_CC
;
1467 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1469 /* Read Subsystem Data - feature codes */
1470 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1471 memset(features
, 0, sizeof(struct dasd_rssd_features
));
1474 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1475 ccw
->count
= sizeof(struct dasd_rssd_features
);
1476 ccw
->cda
= (__u32
)(addr_t
) features
;
1478 cqr
->buildclk
= get_tod_clock();
1479 cqr
->status
= DASD_CQR_FILLED
;
1480 rc
= dasd_sleep_on(cqr
);
1482 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1483 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1484 memcpy(&private->features
, features
,
1485 sizeof(struct dasd_rssd_features
));
1487 dev_warn(&device
->cdev
->dev
, "Reading device feature codes"
1488 " failed with rc=%d\n", rc
);
1489 dasd_sfree_request(cqr
, cqr
->memdev
);
1495 * Build CP for Perform Subsystem Function - SSC.
1497 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
,
1500 struct dasd_ccw_req
*cqr
;
1501 struct dasd_psf_ssc_data
*psf_ssc_data
;
1504 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
1505 sizeof(struct dasd_psf_ssc_data
),
1509 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1510 "Could not allocate PSF-SSC request");
1513 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
1514 psf_ssc_data
->order
= PSF_ORDER_SSC
;
1515 psf_ssc_data
->suborder
= 0xc0;
1517 psf_ssc_data
->suborder
|= 0x08;
1518 psf_ssc_data
->reserved
[0] = 0x88;
1521 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1522 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
1525 cqr
->startdev
= device
;
1526 cqr
->memdev
= device
;
1529 cqr
->expires
= 10*HZ
;
1530 cqr
->buildclk
= get_tod_clock();
1531 cqr
->status
= DASD_CQR_FILLED
;
1536 * Perform Subsystem Function.
1537 * It is necessary to trigger CIO for channel revalidation since this
1538 * call might change behaviour of DASD devices.
1541 dasd_eckd_psf_ssc(struct dasd_device
*device
, int enable_pav
,
1542 unsigned long flags
)
1544 struct dasd_ccw_req
*cqr
;
1547 cqr
= dasd_eckd_build_psf_ssc(device
, enable_pav
);
1549 return PTR_ERR(cqr
);
1552 * set flags e.g. turn on failfast, to prevent blocking
1553 * the calling function should handle failed requests
1555 cqr
->flags
|= flags
;
1557 rc
= dasd_sleep_on(cqr
);
1559 /* trigger CIO to reprobe devices */
1560 css_schedule_reprobe();
1561 else if (cqr
->intrc
== -EAGAIN
)
1564 dasd_sfree_request(cqr
, cqr
->memdev
);
1569 * Valide storage server of current device.
1571 static int dasd_eckd_validate_server(struct dasd_device
*device
,
1572 unsigned long flags
)
1574 struct dasd_eckd_private
*private = device
->private;
1577 if (private->uid
.type
== UA_BASE_PAV_ALIAS
||
1578 private->uid
.type
== UA_HYPER_PAV_ALIAS
)
1580 if (dasd_nopav
|| MACHINE_IS_VM
)
1584 rc
= dasd_eckd_psf_ssc(device
, enable_pav
, flags
);
1586 /* may be requested feature is not available on server,
1587 * therefore just report error and go ahead */
1588 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "PSF-SSC for SSID %04x "
1589 "returned rc=%d", private->uid
.ssid
, rc
);
1594 * worker to do a validate server in case of a lost pathgroup
1596 static void dasd_eckd_do_validate_server(struct work_struct
*work
)
1598 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
1600 unsigned long flags
= 0;
1602 set_bit(DASD_CQR_FLAGS_FAILFAST
, &flags
);
1603 if (dasd_eckd_validate_server(device
, flags
)
1605 /* schedule worker again if failed */
1606 schedule_work(&device
->kick_validate
);
1610 dasd_put_device(device
);
1613 static void dasd_eckd_kick_validate_server(struct dasd_device
*device
)
1615 dasd_get_device(device
);
1616 /* exit if device not online or in offline processing */
1617 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1618 device
->state
< DASD_STATE_ONLINE
) {
1619 dasd_put_device(device
);
1622 /* queue call to do_validate_server to the kernel event daemon. */
1623 if (!schedule_work(&device
->kick_validate
))
1624 dasd_put_device(device
);
1628 * Check device characteristics.
1629 * If the device is accessible using ECKD discipline, the device is enabled.
1632 dasd_eckd_check_characteristics(struct dasd_device
*device
)
1634 struct dasd_eckd_private
*private = device
->private;
1635 struct dasd_block
*block
;
1636 struct dasd_uid temp_uid
;
1639 unsigned long value
;
1641 /* setup work queue for validate server*/
1642 INIT_WORK(&device
->kick_validate
, dasd_eckd_do_validate_server
);
1643 /* setup work queue for summary unit check */
1644 INIT_WORK(&device
->suc_work
, dasd_alias_handle_summary_unit_check
);
1646 if (!ccw_device_is_pathgroup(device
->cdev
)) {
1647 dev_warn(&device
->cdev
->dev
,
1648 "A channel path group could not be established\n");
1651 if (!ccw_device_is_multipath(device
->cdev
)) {
1652 dev_info(&device
->cdev
->dev
,
1653 "The DASD is not operating in multipath mode\n");
1656 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
1658 dev_warn(&device
->cdev
->dev
,
1659 "Allocating memory for private DASD data "
1663 device
->private = private;
1665 memset(private, 0, sizeof(*private));
1667 /* Invalidate status of initial analysis. */
1668 private->init_cqr_status
= -1;
1669 /* Set default cache operations. */
1670 private->attrib
.operation
= DASD_NORMAL_CACHE
;
1671 private->attrib
.nr_cyl
= 0;
1673 /* Read Configuration Data */
1674 rc
= dasd_eckd_read_conf(device
);
1678 /* set some default values */
1679 device
->default_expires
= DASD_EXPIRES
;
1680 device
->default_retries
= DASD_RETRIES
;
1681 device
->path_thrhld
= DASD_ECKD_PATH_THRHLD
;
1682 device
->path_interval
= DASD_ECKD_PATH_INTERVAL
;
1684 if (private->gneq
) {
1686 for (i
= 0; i
< private->gneq
->timeout
.value
; i
++)
1688 value
= value
* private->gneq
->timeout
.number
;
1689 /* do not accept useless values */
1690 if (value
!= 0 && value
<= DASD_EXPIRES_MAX
)
1691 device
->default_expires
= value
;
1694 dasd_eckd_get_uid(device
, &temp_uid
);
1695 if (temp_uid
.type
== UA_BASE_DEVICE
) {
1696 block
= dasd_alloc_block();
1697 if (IS_ERR(block
)) {
1698 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1699 "could not allocate dasd "
1701 rc
= PTR_ERR(block
);
1704 device
->block
= block
;
1705 block
->base
= device
;
1708 /* register lcu with alias handling, enable PAV */
1709 rc
= dasd_alias_make_device_known_to_lcu(device
);
1713 dasd_eckd_validate_server(device
, 0);
1715 /* device may report different configuration data after LCU setup */
1716 rc
= dasd_eckd_read_conf(device
);
1720 /* Read Feature Codes */
1721 dasd_eckd_read_features(device
);
1723 /* Read Device Characteristics */
1724 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
1725 &private->rdc_data
, 64);
1727 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1728 "Read device characteristic failed, rc=%d", rc
);
1732 if ((device
->features
& DASD_FEATURE_USERAW
) &&
1733 !(private->rdc_data
.facilities
.RT_in_LR
)) {
1734 dev_err(&device
->cdev
->dev
, "The storage server does not "
1735 "support raw-track access\n");
1740 /* find the valid cylinder size */
1741 if (private->rdc_data
.no_cyl
== LV_COMPAT_CYL
&&
1742 private->rdc_data
.long_no_cyl
)
1743 private->real_cyl
= private->rdc_data
.long_no_cyl
;
1745 private->real_cyl
= private->rdc_data
.no_cyl
;
1747 private->fcx_max_data
= get_fcx_max_data(device
);
1749 readonly
= dasd_device_is_ro(device
);
1751 set_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
1753 dev_info(&device
->cdev
->dev
, "New DASD %04X/%02X (CU %04X/%02X) "
1754 "with %d cylinders, %d heads, %d sectors%s\n",
1755 private->rdc_data
.dev_type
,
1756 private->rdc_data
.dev_model
,
1757 private->rdc_data
.cu_type
,
1758 private->rdc_data
.cu_model
.model
,
1760 private->rdc_data
.trk_per_cyl
,
1761 private->rdc_data
.sec_per_trk
,
1762 readonly
? ", read-only device" : "");
1766 dasd_alias_disconnect_device_from_lcu(device
);
1768 dasd_free_block(device
->block
);
1769 device
->block
= NULL
;
1771 kfree(private->conf_data
);
1772 kfree(device
->private);
1773 device
->private = NULL
;
1777 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
1779 struct dasd_eckd_private
*private = device
->private;
1782 dasd_alias_disconnect_device_from_lcu(device
);
1783 private->ned
= NULL
;
1784 private->sneq
= NULL
;
1785 private->vdsneq
= NULL
;
1786 private->gneq
= NULL
;
1787 private->conf_len
= 0;
1788 for (i
= 0; i
< 8; i
++) {
1789 kfree(device
->path
[i
].conf_data
);
1790 if ((__u8
*)device
->path
[i
].conf_data
==
1791 private->conf_data
) {
1792 private->conf_data
= NULL
;
1793 private->conf_len
= 0;
1795 device
->path
[i
].conf_data
= NULL
;
1796 device
->path
[i
].cssid
= 0;
1797 device
->path
[i
].ssid
= 0;
1798 device
->path
[i
].chpid
= 0;
1800 kfree(private->conf_data
);
1801 private->conf_data
= NULL
;
1804 static struct dasd_ccw_req
*
1805 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
1807 struct dasd_eckd_private
*private = device
->private;
1808 struct eckd_count
*count_data
;
1809 struct LO_eckd_data
*LO_data
;
1810 struct dasd_ccw_req
*cqr
;
1812 int cplength
, datasize
;
1816 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
1817 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
1821 /* Define extent for the first 3 tracks. */
1822 define_extent(ccw
++, cqr
->data
, 0, 2,
1823 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1824 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
1825 /* Locate record for the first 4 records on track 0. */
1826 ccw
[-1].flags
|= CCW_FLAG_CC
;
1827 locate_record(ccw
++, LO_data
++, 0, 0, 4,
1828 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1830 count_data
= private->count_area
;
1831 for (i
= 0; i
< 4; i
++) {
1832 ccw
[-1].flags
|= CCW_FLAG_CC
;
1833 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1836 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1841 /* Locate record for the first record on track 2. */
1842 ccw
[-1].flags
|= CCW_FLAG_CC
;
1843 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1844 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1845 /* Read count ccw. */
1846 ccw
[-1].flags
|= CCW_FLAG_CC
;
1847 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1850 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1853 cqr
->startdev
= device
;
1854 cqr
->memdev
= device
;
1856 cqr
->buildclk
= get_tod_clock();
1857 cqr
->status
= DASD_CQR_FILLED
;
1861 /* differentiate between 'no record found' and any other error */
1862 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req
*init_cqr
)
1865 if (init_cqr
->status
== DASD_CQR_DONE
)
1867 else if (init_cqr
->status
== DASD_CQR_NEED_ERP
||
1868 init_cqr
->status
== DASD_CQR_FAILED
) {
1869 sense
= dasd_get_sense(&init_cqr
->irb
);
1870 if (sense
&& (sense
[1] & SNS1_NO_REC_FOUND
))
1871 return INIT_CQR_UNFORMATTED
;
1873 return INIT_CQR_ERROR
;
1875 return INIT_CQR_ERROR
;
1879 * This is the callback function for the init_analysis cqr. It saves
1880 * the status of the initial analysis ccw before it frees it and kicks
1881 * the device to continue the startup sequence. This will call
1882 * dasd_eckd_do_analysis again (if the devices has not been marked
1883 * for deletion in the meantime).
1885 static void dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
,
1888 struct dasd_device
*device
= init_cqr
->startdev
;
1889 struct dasd_eckd_private
*private = device
->private;
1891 private->init_cqr_status
= dasd_eckd_analysis_evaluation(init_cqr
);
1892 dasd_sfree_request(init_cqr
, device
);
1893 dasd_kick_device(device
);
1896 static int dasd_eckd_start_analysis(struct dasd_block
*block
)
1898 struct dasd_ccw_req
*init_cqr
;
1900 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1901 if (IS_ERR(init_cqr
))
1902 return PTR_ERR(init_cqr
);
1903 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1904 init_cqr
->callback_data
= NULL
;
1905 init_cqr
->expires
= 5*HZ
;
1906 /* first try without ERP, so we can later handle unformatted
1907 * devices as special case
1909 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &init_cqr
->flags
);
1910 init_cqr
->retries
= 0;
1911 dasd_add_request_head(init_cqr
);
1915 static int dasd_eckd_end_analysis(struct dasd_block
*block
)
1917 struct dasd_device
*device
= block
->base
;
1918 struct dasd_eckd_private
*private = device
->private;
1919 struct eckd_count
*count_area
;
1920 unsigned int sb
, blk_per_trk
;
1922 struct dasd_ccw_req
*init_cqr
;
1924 status
= private->init_cqr_status
;
1925 private->init_cqr_status
= -1;
1926 if (status
== INIT_CQR_ERROR
) {
1927 /* try again, this time with full ERP */
1928 init_cqr
= dasd_eckd_analysis_ccw(device
);
1929 dasd_sleep_on(init_cqr
);
1930 status
= dasd_eckd_analysis_evaluation(init_cqr
);
1931 dasd_sfree_request(init_cqr
, device
);
1934 if (device
->features
& DASD_FEATURE_USERAW
) {
1935 block
->bp_block
= DASD_RAW_BLOCKSIZE
;
1936 blk_per_trk
= DASD_RAW_BLOCK_PER_TRACK
;
1937 block
->s2b_shift
= 3;
1941 if (status
== INIT_CQR_UNFORMATTED
) {
1942 dev_warn(&device
->cdev
->dev
, "The DASD is not formatted\n");
1943 return -EMEDIUMTYPE
;
1944 } else if (status
== INIT_CQR_ERROR
) {
1945 dev_err(&device
->cdev
->dev
,
1946 "Detecting the DASD disk layout failed because "
1947 "of an I/O error\n");
1951 private->uses_cdl
= 1;
1952 /* Check Track 0 for Compatible Disk Layout */
1954 for (i
= 0; i
< 3; i
++) {
1955 if (private->count_area
[i
].kl
!= 4 ||
1956 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4 ||
1957 private->count_area
[i
].cyl
!= 0 ||
1958 private->count_area
[i
].head
!= count_area_head
[i
] ||
1959 private->count_area
[i
].record
!= count_area_rec
[i
]) {
1960 private->uses_cdl
= 0;
1965 count_area
= &private->count_area
[4];
1967 if (private->uses_cdl
== 0) {
1968 for (i
= 0; i
< 5; i
++) {
1969 if ((private->count_area
[i
].kl
!= 0) ||
1970 (private->count_area
[i
].dl
!=
1971 private->count_area
[0].dl
) ||
1972 private->count_area
[i
].cyl
!= 0 ||
1973 private->count_area
[i
].head
!= count_area_head
[i
] ||
1974 private->count_area
[i
].record
!= count_area_rec
[i
])
1978 count_area
= &private->count_area
[0];
1980 if (private->count_area
[3].record
== 1)
1981 dev_warn(&device
->cdev
->dev
,
1982 "Track 0 has no records following the VTOC\n");
1985 if (count_area
!= NULL
&& count_area
->kl
== 0) {
1986 /* we found notthing violating our disk layout */
1987 if (dasd_check_blocksize(count_area
->dl
) == 0)
1988 block
->bp_block
= count_area
->dl
;
1990 if (block
->bp_block
== 0) {
1991 dev_warn(&device
->cdev
->dev
,
1992 "The disk layout of the DASD is not supported\n");
1993 return -EMEDIUMTYPE
;
1995 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
1996 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
1999 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
2002 block
->blocks
= (private->real_cyl
*
2003 private->rdc_data
.trk_per_cyl
*
2006 dev_info(&device
->cdev
->dev
,
2007 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2008 "%s\n", (block
->bp_block
>> 10),
2009 ((private->real_cyl
*
2010 private->rdc_data
.trk_per_cyl
*
2011 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
2012 ((blk_per_trk
* block
->bp_block
) >> 10),
2014 "compatible disk layout" : "linux disk layout");
2019 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
2021 struct dasd_eckd_private
*private = block
->base
->private;
2023 if (private->init_cqr_status
< 0)
2024 return dasd_eckd_start_analysis(block
);
2026 return dasd_eckd_end_analysis(block
);
2029 static int dasd_eckd_basic_to_ready(struct dasd_device
*device
)
2031 return dasd_alias_add_device(device
);
2034 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
2036 cancel_work_sync(&device
->reload_device
);
2037 cancel_work_sync(&device
->kick_validate
);
2041 static int dasd_eckd_basic_to_known(struct dasd_device
*device
)
2043 return dasd_alias_remove_device(device
);
2047 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
2049 struct dasd_eckd_private
*private = block
->base
->private;
2051 if (dasd_check_blocksize(block
->bp_block
) == 0) {
2052 geo
->sectors
= recs_per_track(&private->rdc_data
,
2053 0, block
->bp_block
);
2055 geo
->cylinders
= private->rdc_data
.no_cyl
;
2056 geo
->heads
= private->rdc_data
.trk_per_cyl
;
2061 * Build the TCW request for the format check
2063 static struct dasd_ccw_req
*
2064 dasd_eckd_build_check_tcw(struct dasd_device
*base
, struct format_data_t
*fdata
,
2065 int enable_pav
, struct eckd_count
*fmt_buffer
,
2068 struct dasd_eckd_private
*start_priv
;
2069 struct dasd_device
*startdev
= NULL
;
2070 struct tidaw
*last_tidaw
= NULL
;
2071 struct dasd_ccw_req
*cqr
;
2079 startdev
= dasd_alias_get_start_dev(base
);
2084 start_priv
= startdev
->private;
2086 count
= rpt
* (fdata
->stop_unit
- fdata
->start_unit
+ 1);
2089 * we're adding 'count' amount of tidaw to the itcw.
2090 * calculate the corresponding itcw_size
2092 itcw_size
= itcw_calc_size(0, count
, 0);
2094 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
2098 start_priv
->count
++;
2100 itcw
= itcw_init(cqr
->data
, itcw_size
, ITCW_OP_READ
, 0, count
, 0);
2106 cqr
->cpaddr
= itcw_get_tcw(itcw
);
2107 rc
= prepare_itcw(itcw
, fdata
->start_unit
, fdata
->stop_unit
,
2108 DASD_ECKD_CCW_READ_COUNT_MT
, base
, startdev
, 0, count
,
2109 sizeof(struct eckd_count
),
2110 count
* sizeof(struct eckd_count
), 0, rpt
);
2114 for (i
= 0; i
< count
; i
++) {
2115 last_tidaw
= itcw_add_tidaw(itcw
, 0, fmt_buffer
++,
2116 sizeof(struct eckd_count
));
2117 if (IS_ERR(last_tidaw
)) {
2123 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
2124 itcw_finalize(itcw
);
2127 cqr
->startdev
= startdev
;
2128 cqr
->memdev
= startdev
;
2129 cqr
->basedev
= base
;
2130 cqr
->retries
= startdev
->default_retries
;
2131 cqr
->expires
= startdev
->default_expires
* HZ
;
2132 cqr
->buildclk
= get_tod_clock();
2133 cqr
->status
= DASD_CQR_FILLED
;
2134 /* Set flags to suppress output for expected errors */
2135 set_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
);
2136 set_bit(DASD_CQR_SUPPRESS_IL
, &cqr
->flags
);
2141 dasd_sfree_request(cqr
, startdev
);
2147 * Build the CCW request for the format check
2149 static struct dasd_ccw_req
*
2150 dasd_eckd_build_check(struct dasd_device
*base
, struct format_data_t
*fdata
,
2151 int enable_pav
, struct eckd_count
*fmt_buffer
, int rpt
)
2153 struct dasd_eckd_private
*start_priv
;
2154 struct dasd_eckd_private
*base_priv
;
2155 struct dasd_device
*startdev
= NULL
;
2156 struct dasd_ccw_req
*cqr
;
2159 int cplength
, datasize
;
2165 startdev
= dasd_alias_get_start_dev(base
);
2170 start_priv
= startdev
->private;
2171 base_priv
= base
->private;
2173 count
= rpt
* (fdata
->stop_unit
- fdata
->start_unit
+ 1);
2175 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
2179 datasize
= sizeof(struct PFX_eckd_data
);
2182 datasize
= sizeof(struct DE_eckd_data
) +
2183 sizeof(struct LO_eckd_data
);
2187 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2192 start_priv
->count
++;
2197 prefix_LRE(ccw
++, data
, fdata
->start_unit
, fdata
->stop_unit
,
2198 DASD_ECKD_CCW_READ_COUNT
, base
, startdev
, 1, 0,
2201 define_extent(ccw
++, data
, fdata
->start_unit
, fdata
->stop_unit
,
2202 DASD_ECKD_CCW_READ_COUNT
, startdev
, 0);
2204 data
+= sizeof(struct DE_eckd_data
);
2205 ccw
[-1].flags
|= CCW_FLAG_CC
;
2207 locate_record(ccw
++, data
, fdata
->start_unit
, 0, count
,
2208 DASD_ECKD_CCW_READ_COUNT
, base
, 0);
2211 for (i
= 0; i
< count
; i
++) {
2212 ccw
[-1].flags
|= CCW_FLAG_CC
;
2213 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
2214 ccw
->flags
= CCW_FLAG_SLI
;
2216 ccw
->cda
= (__u32
)(addr_t
) fmt_buffer
;
2221 cqr
->startdev
= startdev
;
2222 cqr
->memdev
= startdev
;
2223 cqr
->basedev
= base
;
2224 cqr
->retries
= DASD_RETRIES
;
2225 cqr
->expires
= startdev
->default_expires
* HZ
;
2226 cqr
->buildclk
= get_tod_clock();
2227 cqr
->status
= DASD_CQR_FILLED
;
2228 /* Set flags to suppress output for expected errors */
2229 set_bit(DASD_CQR_SUPPRESS_NRF
, &cqr
->flags
);
2234 static struct dasd_ccw_req
*
2235 dasd_eckd_build_format(struct dasd_device
*base
,
2236 struct format_data_t
*fdata
,
2239 struct dasd_eckd_private
*base_priv
;
2240 struct dasd_eckd_private
*start_priv
;
2241 struct dasd_device
*startdev
= NULL
;
2242 struct dasd_ccw_req
*fcp
;
2243 struct eckd_count
*ect
;
2244 struct ch_t address
;
2248 int cplength
, datasize
;
2256 startdev
= dasd_alias_get_start_dev(base
);
2261 start_priv
= startdev
->private;
2262 base_priv
= base
->private;
2264 rpt
= recs_per_track(&base_priv
->rdc_data
, 0, fdata
->blksize
);
2266 nr_tracks
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2269 * fdata->intensity is a bit string that tells us what to do:
2270 * Bit 0: write record zero
2271 * Bit 1: write home address, currently not supported
2272 * Bit 2: invalidate tracks
2273 * Bit 3: use OS/390 compatible disk layout (cdl)
2274 * Bit 4: do not allow storage subsystem to modify record zero
2275 * Only some bit combinations do make sense.
2277 if (fdata
->intensity
& 0x10) {
2279 intensity
= fdata
->intensity
& ~0x10;
2282 intensity
= fdata
->intensity
;
2285 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
2287 switch (intensity
) {
2288 case 0x00: /* Normal format */
2289 case 0x08: /* Normal format, use cdl. */
2290 cplength
= 2 + (rpt
*nr_tracks
);
2292 datasize
= sizeof(struct PFX_eckd_data
) +
2293 sizeof(struct LO_eckd_data
) +
2294 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2296 datasize
= sizeof(struct DE_eckd_data
) +
2297 sizeof(struct LO_eckd_data
) +
2298 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2300 case 0x01: /* Write record zero and format track. */
2301 case 0x09: /* Write record zero and format track, use cdl. */
2302 cplength
= 2 + rpt
* nr_tracks
;
2304 datasize
= sizeof(struct PFX_eckd_data
) +
2305 sizeof(struct LO_eckd_data
) +
2306 sizeof(struct eckd_count
) +
2307 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2309 datasize
= sizeof(struct DE_eckd_data
) +
2310 sizeof(struct LO_eckd_data
) +
2311 sizeof(struct eckd_count
) +
2312 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2314 case 0x04: /* Invalidate track. */
2315 case 0x0c: /* Invalidate track, use cdl. */
2318 datasize
= sizeof(struct PFX_eckd_data
) +
2319 sizeof(struct LO_eckd_data
) +
2320 sizeof(struct eckd_count
);
2322 datasize
= sizeof(struct DE_eckd_data
) +
2323 sizeof(struct LO_eckd_data
) +
2324 sizeof(struct eckd_count
);
2327 dev_warn(&startdev
->cdev
->dev
,
2328 "An I/O control call used incorrect flags 0x%x\n",
2330 return ERR_PTR(-EINVAL
);
2332 /* Allocate the format ccw request. */
2333 fcp
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
2334 datasize
, startdev
);
2338 start_priv
->count
++;
2342 switch (intensity
& ~0x08) {
2343 case 0x00: /* Normal format. */
2345 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2346 fdata
->start_unit
, fdata
->stop_unit
,
2347 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2348 /* grant subsystem permission to format R0 */
2350 ((struct PFX_eckd_data
*)data
)
2351 ->define_extent
.ga_extended
|= 0x04;
2352 data
+= sizeof(struct PFX_eckd_data
);
2354 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2355 fdata
->start_unit
, fdata
->stop_unit
,
2356 DASD_ECKD_CCW_WRITE_CKD
, startdev
, 0);
2357 /* grant subsystem permission to format R0 */
2359 ((struct DE_eckd_data
*) data
)
2360 ->ga_extended
|= 0x04;
2361 data
+= sizeof(struct DE_eckd_data
);
2363 ccw
[-1].flags
|= CCW_FLAG_CC
;
2364 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2365 fdata
->start_unit
, 0, rpt
*nr_tracks
,
2366 DASD_ECKD_CCW_WRITE_CKD
, base
,
2368 data
+= sizeof(struct LO_eckd_data
);
2370 case 0x01: /* Write record zero + format track. */
2372 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2373 fdata
->start_unit
, fdata
->stop_unit
,
2374 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
2376 data
+= sizeof(struct PFX_eckd_data
);
2378 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2379 fdata
->start_unit
, fdata
->stop_unit
,
2380 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, startdev
, 0);
2381 data
+= sizeof(struct DE_eckd_data
);
2383 ccw
[-1].flags
|= CCW_FLAG_CC
;
2384 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2385 fdata
->start_unit
, 0, rpt
* nr_tracks
+ 1,
2386 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, base
,
2387 base
->block
->bp_block
);
2388 data
+= sizeof(struct LO_eckd_data
);
2390 case 0x04: /* Invalidate track. */
2392 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2393 fdata
->start_unit
, fdata
->stop_unit
,
2394 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2395 data
+= sizeof(struct PFX_eckd_data
);
2397 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2398 fdata
->start_unit
, fdata
->stop_unit
,
2399 DASD_ECKD_CCW_WRITE_CKD
, startdev
, 0);
2400 data
+= sizeof(struct DE_eckd_data
);
2402 ccw
[-1].flags
|= CCW_FLAG_CC
;
2403 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2404 fdata
->start_unit
, 0, 1,
2405 DASD_ECKD_CCW_WRITE_CKD
, base
, 8);
2406 data
+= sizeof(struct LO_eckd_data
);
2410 for (j
= 0; j
< nr_tracks
; j
++) {
2411 /* calculate cylinder and head for the current track */
2413 (fdata
->start_unit
+ j
) /
2414 base_priv
->rdc_data
.trk_per_cyl
,
2415 (fdata
->start_unit
+ j
) %
2416 base_priv
->rdc_data
.trk_per_cyl
);
2417 if (intensity
& 0x01) { /* write record zero */
2418 ect
= (struct eckd_count
*) data
;
2419 data
+= sizeof(struct eckd_count
);
2420 ect
->cyl
= address
.cyl
;
2421 ect
->head
= address
.head
;
2425 ccw
[-1].flags
|= CCW_FLAG_CC
;
2426 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
2427 ccw
->flags
= CCW_FLAG_SLI
;
2429 ccw
->cda
= (__u32
)(addr_t
) ect
;
2432 if ((intensity
& ~0x08) & 0x04) { /* erase track */
2433 ect
= (struct eckd_count
*) data
;
2434 data
+= sizeof(struct eckd_count
);
2435 ect
->cyl
= address
.cyl
;
2436 ect
->head
= address
.head
;
2440 ccw
[-1].flags
|= CCW_FLAG_CC
;
2441 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2442 ccw
->flags
= CCW_FLAG_SLI
;
2444 ccw
->cda
= (__u32
)(addr_t
) ect
;
2445 } else { /* write remaining records */
2446 for (i
= 0; i
< rpt
; i
++) {
2447 ect
= (struct eckd_count
*) data
;
2448 data
+= sizeof(struct eckd_count
);
2449 ect
->cyl
= address
.cyl
;
2450 ect
->head
= address
.head
;
2451 ect
->record
= i
+ 1;
2453 ect
->dl
= fdata
->blksize
;
2455 * Check for special tracks 0-1
2456 * when formatting CDL
2458 if ((intensity
& 0x08) &&
2459 address
.cyl
== 0 && address
.head
== 0) {
2462 ect
->dl
= sizes_trk0
[i
] - 4;
2465 if ((intensity
& 0x08) &&
2466 address
.cyl
== 0 && address
.head
== 1) {
2468 ect
->dl
= LABEL_SIZE
- 44;
2470 ccw
[-1].flags
|= CCW_FLAG_CC
;
2471 if (i
!= 0 || j
== 0)
2473 DASD_ECKD_CCW_WRITE_CKD
;
2476 DASD_ECKD_CCW_WRITE_CKD_MT
;
2477 ccw
->flags
= CCW_FLAG_SLI
;
2479 ccw
->cda
= (__u32
)(addr_t
) ect
;
2485 fcp
->startdev
= startdev
;
2486 fcp
->memdev
= startdev
;
2487 fcp
->basedev
= base
;
2489 fcp
->expires
= startdev
->default_expires
* HZ
;
2490 fcp
->buildclk
= get_tod_clock();
2491 fcp
->status
= DASD_CQR_FILLED
;
2497 * Wrapper function to build a CCW request depending on input data
2499 static struct dasd_ccw_req
*
2500 dasd_eckd_format_build_ccw_req(struct dasd_device
*base
,
2501 struct format_data_t
*fdata
, int enable_pav
,
2502 int tpm
, struct eckd_count
*fmt_buffer
, int rpt
)
2504 struct dasd_ccw_req
*ccw_req
;
2507 ccw_req
= dasd_eckd_build_format(base
, fdata
, enable_pav
);
2510 ccw_req
= dasd_eckd_build_check_tcw(base
, fdata
,
2514 ccw_req
= dasd_eckd_build_check(base
, fdata
, enable_pav
,
2522 * Sanity checks on format_data
2524 static int dasd_eckd_format_sanity_checks(struct dasd_device
*base
,
2525 struct format_data_t
*fdata
)
2527 struct dasd_eckd_private
*private = base
->private;
2529 if (fdata
->start_unit
>=
2530 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2531 dev_warn(&base
->cdev
->dev
,
2532 "Start track number %u used in formatting is too big\n",
2536 if (fdata
->stop_unit
>=
2537 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2538 dev_warn(&base
->cdev
->dev
,
2539 "Stop track number %u used in formatting is too big\n",
2543 if (fdata
->start_unit
> fdata
->stop_unit
) {
2544 dev_warn(&base
->cdev
->dev
,
2545 "Start track %u used in formatting exceeds end track\n",
2549 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
2550 dev_warn(&base
->cdev
->dev
,
2551 "The DASD cannot be formatted with block size %u\n",
2559 * This function will process format_data originally coming from an IOCTL
2561 static int dasd_eckd_format_process_data(struct dasd_device
*base
,
2562 struct format_data_t
*fdata
,
2563 int enable_pav
, int tpm
,
2564 struct eckd_count
*fmt_buffer
, int rpt
,
2567 struct dasd_eckd_private
*private = base
->private;
2568 struct dasd_ccw_req
*cqr
, *n
;
2569 struct list_head format_queue
;
2570 struct dasd_device
*device
;
2572 int old_start
, old_stop
, format_step
;
2576 rc
= dasd_eckd_format_sanity_checks(base
, fdata
);
2580 INIT_LIST_HEAD(&format_queue
);
2582 old_start
= fdata
->start_unit
;
2583 old_stop
= fdata
->stop_unit
;
2585 if (!tpm
&& fmt_buffer
!= NULL
) {
2586 /* Command Mode / Format Check */
2588 } else if (tpm
&& fmt_buffer
!= NULL
) {
2589 /* Transport Mode / Format Check */
2590 format_step
= DASD_CQR_MAX_CCW
/ rpt
;
2592 /* Normal Formatting */
2593 format_step
= DASD_CQR_MAX_CCW
/
2594 recs_per_track(&private->rdc_data
, 0, fdata
->blksize
);
2599 while (fdata
->start_unit
<= old_stop
) {
2600 step
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2601 if (step
> format_step
) {
2603 fdata
->start_unit
+ format_step
- 1;
2606 cqr
= dasd_eckd_format_build_ccw_req(base
, fdata
,
2611 if (rc
== -ENOMEM
) {
2612 if (list_empty(&format_queue
))
2615 * not enough memory available, start
2616 * requests retry after first requests
2624 list_add_tail(&cqr
->blocklist
, &format_queue
);
2627 step
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2628 fmt_buffer
+= rpt
* step
;
2630 fdata
->start_unit
= fdata
->stop_unit
+ 1;
2631 fdata
->stop_unit
= old_stop
;
2634 rc
= dasd_sleep_on_queue(&format_queue
);
2637 list_for_each_entry_safe(cqr
, n
, &format_queue
, blocklist
) {
2638 device
= cqr
->startdev
;
2639 private = device
->private;
2641 if (cqr
->status
== DASD_CQR_FAILED
) {
2643 * Only get sense data if called by format
2646 if (fmt_buffer
&& irb
) {
2647 sense
= dasd_get_sense(&cqr
->irb
);
2648 memcpy(irb
, &cqr
->irb
, sizeof(*irb
));
2652 list_del_init(&cqr
->blocklist
);
2653 dasd_sfree_request(cqr
, device
);
2657 if (rc
&& rc
!= -EIO
)
2661 * In case fewer than the expected records are on the
2662 * track, we will most likely get a 'No Record Found'
2663 * error (in command mode) or a 'File Protected' error
2664 * (in transport mode). Those particular cases shouldn't
2665 * pass the -EIO to the IOCTL, therefore reset the rc
2669 (sense
[1] & SNS1_NO_REC_FOUND
||
2670 sense
[1] & SNS1_FILE_PROTECTED
))
2679 fdata
->start_unit
= old_start
;
2680 fdata
->stop_unit
= old_stop
;
2685 static int dasd_eckd_format_device(struct dasd_device
*base
,
2686 struct format_data_t
*fdata
, int enable_pav
)
2688 return dasd_eckd_format_process_data(base
, fdata
, enable_pav
, 0, NULL
,
2693 * Helper function to count consecutive records of a single track.
2695 static int dasd_eckd_count_records(struct eckd_count
*fmt_buffer
, int start
,
2701 head
= fmt_buffer
[start
].head
;
2704 * There are 3 conditions where we stop counting:
2705 * - if data reoccurs (same head and record may reoccur), which may
2706 * happen due to the way DASD_ECKD_CCW_READ_COUNT works
2707 * - when the head changes, because we're iterating over several tracks
2708 * then (DASD_ECKD_CCW_READ_COUNT_MT)
2709 * - when we've reached the end of sensible data in the buffer (the
2710 * record will be 0 then)
2712 for (i
= start
; i
< max
; i
++) {
2714 if ((fmt_buffer
[i
].head
== head
&&
2715 fmt_buffer
[i
].record
== 1) ||
2716 fmt_buffer
[i
].head
!= head
||
2717 fmt_buffer
[i
].record
== 0)
2726 * Evaluate a given range of tracks. Data like number of records, blocksize,
2727 * record ids, and key length are compared with expected data.
2729 * If a mismatch occurs, the corresponding error bit is set, as well as
2730 * additional information, depending on the error.
2732 static void dasd_eckd_format_evaluate_tracks(struct eckd_count
*fmt_buffer
,
2733 struct format_check_t
*cdata
,
2734 int rpt_max
, int rpt_exp
,
2735 int trk_per_cyl
, int tpm
)
2746 trkcount
= cdata
->expect
.stop_unit
- cdata
->expect
.start_unit
+ 1;
2747 max_entries
= trkcount
* rpt_max
;
2749 for (i
= cdata
->expect
.start_unit
; i
<= cdata
->expect
.stop_unit
; i
++) {
2750 /* Calculate the correct next starting position in the buffer */
2752 while (fmt_buffer
[pos
].record
== 0 &&
2753 fmt_buffer
[pos
].dl
== 0) {
2754 if (pos
++ > max_entries
)
2758 if (i
!= cdata
->expect
.start_unit
)
2759 pos
+= rpt_max
- count
;
2762 /* Calculate the expected geo values for the current track */
2763 set_ch_t(&geo
, i
/ trk_per_cyl
, i
% trk_per_cyl
);
2765 /* Count and check number of records */
2766 count
= dasd_eckd_count_records(fmt_buffer
, pos
, pos
+ rpt_max
);
2768 if (count
< rpt_exp
) {
2769 cdata
->result
= DASD_FMT_ERR_TOO_FEW_RECORDS
;
2772 if (count
> rpt_exp
) {
2773 cdata
->result
= DASD_FMT_ERR_TOO_MANY_RECORDS
;
2777 for (j
= 0; j
< count
; j
++, pos
++) {
2778 blksize
= cdata
->expect
.blksize
;
2782 * Set special values when checking CDL formatted
2785 if ((cdata
->expect
.intensity
& 0x08) &&
2786 geo
.cyl
== 0 && geo
.head
== 0) {
2788 blksize
= sizes_trk0
[j
] - 4;
2792 if ((cdata
->expect
.intensity
& 0x08) &&
2793 geo
.cyl
== 0 && geo
.head
== 1) {
2794 blksize
= LABEL_SIZE
- 44;
2798 /* Check blocksize */
2799 if (fmt_buffer
[pos
].dl
!= blksize
) {
2800 cdata
->result
= DASD_FMT_ERR_BLKSIZE
;
2803 /* Check if key length is 0 */
2804 if (fmt_buffer
[pos
].kl
!= kl
) {
2805 cdata
->result
= DASD_FMT_ERR_KEY_LENGTH
;
2808 /* Check if record_id is correct */
2809 if (fmt_buffer
[pos
].cyl
!= geo
.cyl
||
2810 fmt_buffer
[pos
].head
!= geo
.head
||
2811 fmt_buffer
[pos
].record
!= (j
+ 1)) {
2812 cdata
->result
= DASD_FMT_ERR_RECORD_ID
;
2820 * In case of no errors, we need to decrease by one
2821 * to get the correct positions.
2823 if (!cdata
->result
) {
2829 cdata
->num_records
= count
;
2830 cdata
->rec
= fmt_buffer
[pos
].record
;
2831 cdata
->blksize
= fmt_buffer
[pos
].dl
;
2832 cdata
->key_length
= fmt_buffer
[pos
].kl
;
2836 * Check the format of a range of tracks of a DASD.
2838 static int dasd_eckd_check_device_format(struct dasd_device
*base
,
2839 struct format_check_t
*cdata
,
2842 struct dasd_eckd_private
*private = base
->private;
2843 struct eckd_count
*fmt_buffer
;
2845 int rpt_max
, rpt_exp
;
2846 int fmt_buffer_size
;
2852 trk_per_cyl
= private->rdc_data
.trk_per_cyl
;
2854 /* Get maximum and expected amount of records per track */
2855 rpt_max
= recs_per_track(&private->rdc_data
, 0, 512) + 1;
2856 rpt_exp
= recs_per_track(&private->rdc_data
, 0, cdata
->expect
.blksize
);
2858 trkcount
= cdata
->expect
.stop_unit
- cdata
->expect
.start_unit
+ 1;
2859 fmt_buffer_size
= trkcount
* rpt_max
* sizeof(struct eckd_count
);
2861 fmt_buffer
= kzalloc(fmt_buffer_size
, GFP_KERNEL
| GFP_DMA
);
2866 * A certain FICON feature subset is needed to operate in transport
2867 * mode. Additionally, the support for transport mode is implicitly
2868 * checked by comparing the buffer size with fcx_max_data. As long as
2869 * the buffer size is smaller we can operate in transport mode and
2870 * process multiple tracks. If not, only one track at once is being
2871 * processed using command mode.
2873 if ((private->features
.feature
[40] & 0x04) &&
2874 fmt_buffer_size
<= private->fcx_max_data
)
2877 rc
= dasd_eckd_format_process_data(base
, &cdata
->expect
, enable_pav
,
2878 tpm
, fmt_buffer
, rpt_max
, &irb
);
2879 if (rc
&& rc
!= -EIO
)
2883 * If our first attempt with transport mode enabled comes back
2884 * with an incorrect length error, we're going to retry the
2885 * check with command mode.
2887 if (tpm
&& scsw_cstat(&irb
.scsw
) == 0x40) {
2889 rc
= dasd_eckd_format_process_data(base
, &cdata
->expect
,
2891 fmt_buffer
, rpt_max
,
2900 dasd_eckd_format_evaluate_tracks(fmt_buffer
, cdata
, rpt_max
, rpt_exp
,
2909 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
2911 if (cqr
->retries
< 0) {
2912 cqr
->status
= DASD_CQR_FAILED
;
2915 cqr
->status
= DASD_CQR_FILLED
;
2916 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
2917 dasd_eckd_reset_ccw_to_base_io(cqr
);
2918 cqr
->startdev
= cqr
->block
->base
;
2919 cqr
->lpm
= dasd_path_get_opm(cqr
->block
->base
);
2923 static dasd_erp_fn_t
2924 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
2926 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
2927 struct ccw_device
*cdev
= device
->cdev
;
2929 switch (cdev
->id
.cu_type
) {
2934 return dasd_3990_erp_action
;
2938 return dasd_default_erp_action
;
2942 static dasd_erp_fn_t
2943 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
2945 return dasd_default_erp_postaction
;
2948 static void dasd_eckd_check_for_device_change(struct dasd_device
*device
,
2949 struct dasd_ccw_req
*cqr
,
2954 struct dasd_eckd_private
*private = device
->private;
2956 /* first of all check for state change pending interrupt */
2957 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
2958 if ((scsw_dstat(&irb
->scsw
) & mask
) == mask
) {
2960 * for alias only, not in offline processing
2961 * and only if not suspended
2963 if (!device
->block
&& private->lcu
&&
2964 device
->state
== DASD_STATE_ONLINE
&&
2965 !test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
2966 !test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
2967 /* schedule worker to reload device */
2968 dasd_reload_device(device
);
2970 dasd_generic_handle_state_change(device
);
2974 sense
= dasd_get_sense(irb
);
2978 /* summary unit check */
2979 if ((sense
[27] & DASD_SENSE_BIT_0
) && (sense
[7] == 0x0D) &&
2980 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
)) {
2981 if (test_and_set_bit(DASD_FLAG_SUC
, &device
->flags
)) {
2982 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
2983 "eckd suc: device already notified");
2986 sense
= dasd_get_sense(irb
);
2988 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
2989 "eckd suc: no reason code available");
2990 clear_bit(DASD_FLAG_SUC
, &device
->flags
);
2994 private->suc_reason
= sense
[8];
2995 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
2996 "eckd handle summary unit check: reason",
2997 private->suc_reason
);
2998 dasd_get_device(device
);
2999 if (!schedule_work(&device
->suc_work
))
3000 dasd_put_device(device
);
3005 /* service information message SIM */
3006 if (!cqr
&& !(sense
[27] & DASD_SENSE_BIT_0
) &&
3007 ((sense
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
)) {
3008 dasd_3990_erp_handle_sim(device
, sense
);
3012 /* loss of device reservation is handled via base devices only
3013 * as alias devices may be used with several bases
3015 if (device
->block
&& (sense
[27] & DASD_SENSE_BIT_0
) &&
3016 (sense
[7] == 0x3F) &&
3017 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
) &&
3018 test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
)) {
3019 if (device
->features
& DASD_FEATURE_FAILONSLCK
)
3020 set_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
3021 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3022 dev_err(&device
->cdev
->dev
,
3023 "The device reservation was lost\n");
3027 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_single(
3028 struct dasd_device
*startdev
,
3029 struct dasd_block
*block
,
3030 struct request
*req
,
3035 unsigned int first_offs
,
3036 unsigned int last_offs
,
3037 unsigned int blk_per_trk
,
3038 unsigned int blksize
)
3040 struct dasd_eckd_private
*private;
3041 unsigned long *idaws
;
3042 struct LO_eckd_data
*LO_data
;
3043 struct dasd_ccw_req
*cqr
;
3045 struct req_iterator iter
;
3049 int count
, cidaw
, cplength
, datasize
;
3051 unsigned char cmd
, rcmd
;
3053 struct dasd_device
*basedev
;
3055 basedev
= block
->base
;
3056 private = basedev
->private;
3057 if (rq_data_dir(req
) == READ
)
3058 cmd
= DASD_ECKD_CCW_READ_MT
;
3059 else if (rq_data_dir(req
) == WRITE
)
3060 cmd
= DASD_ECKD_CCW_WRITE_MT
;
3062 return ERR_PTR(-EINVAL
);
3064 /* Check struct bio and count the number of blocks for the request. */
3067 rq_for_each_segment(bv
, req
, iter
) {
3068 if (bv
.bv_len
& (blksize
- 1))
3069 /* Eckd can only do full blocks. */
3070 return ERR_PTR(-EINVAL
);
3071 count
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
3072 if (idal_is_needed (page_address(bv
.bv_page
), bv
.bv_len
))
3073 cidaw
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
3076 if (count
!= last_rec
- first_rec
+ 1)
3077 return ERR_PTR(-EINVAL
);
3079 /* use the prefix command if available */
3080 use_prefix
= private->features
.feature
[8] & 0x01;
3082 /* 1x prefix + number of blocks */
3083 cplength
= 2 + count
;
3084 /* 1x prefix + cidaws*sizeof(long) */
3085 datasize
= sizeof(struct PFX_eckd_data
) +
3086 sizeof(struct LO_eckd_data
) +
3087 cidaw
* sizeof(unsigned long);
3089 /* 1x define extent + 1x locate record + number of blocks */
3090 cplength
= 2 + count
;
3091 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
3092 datasize
= sizeof(struct DE_eckd_data
) +
3093 sizeof(struct LO_eckd_data
) +
3094 cidaw
* sizeof(unsigned long);
3096 /* Find out the number of additional locate record ccws for cdl. */
3097 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
3098 if (last_rec
>= 2*blk_per_trk
)
3099 count
= 2*blk_per_trk
- first_rec
;
3101 datasize
+= count
*sizeof(struct LO_eckd_data
);
3103 /* Allocate the ccw request. */
3104 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
3109 /* First ccw is define extent or prefix. */
3111 if (prefix(ccw
++, cqr
->data
, first_trk
,
3112 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
3113 /* Clock not in sync and XRC is enabled.
3116 dasd_sfree_request(cqr
, startdev
);
3117 return ERR_PTR(-EAGAIN
);
3119 idaws
= (unsigned long *) (cqr
->data
+
3120 sizeof(struct PFX_eckd_data
));
3122 if (define_extent(ccw
++, cqr
->data
, first_trk
,
3123 last_trk
, cmd
, basedev
, 0) == -EAGAIN
) {
3124 /* Clock not in sync and XRC is enabled.
3127 dasd_sfree_request(cqr
, startdev
);
3128 return ERR_PTR(-EAGAIN
);
3130 idaws
= (unsigned long *) (cqr
->data
+
3131 sizeof(struct DE_eckd_data
));
3133 /* Build locate_record+read/write/ccws. */
3134 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
3136 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
3137 /* Only standard blocks so there is just one locate record. */
3138 ccw
[-1].flags
|= CCW_FLAG_CC
;
3139 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
3140 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
3142 rq_for_each_segment(bv
, req
, iter
) {
3143 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3144 if (dasd_page_cache
) {
3145 char *copy
= kmem_cache_alloc(dasd_page_cache
,
3146 GFP_DMA
| __GFP_NOWARN
);
3147 if (copy
&& rq_data_dir(req
) == WRITE
)
3148 memcpy(copy
+ bv
.bv_offset
, dst
, bv
.bv_len
);
3150 dst
= copy
+ bv
.bv_offset
;
3152 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
3153 sector_t trkid
= recid
;
3154 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
3157 /* Locate record for cdl special block ? */
3158 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
3159 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
3161 count
= dasd_eckd_cdl_reclen(recid
);
3162 if (count
< blksize
&&
3163 rq_data_dir(req
) == READ
)
3164 memset(dst
+ count
, 0xe5,
3167 ccw
[-1].flags
|= CCW_FLAG_CC
;
3168 locate_record(ccw
++, LO_data
++,
3170 1, rcmd
, basedev
, count
);
3172 /* Locate record for standard blocks ? */
3173 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
3174 ccw
[-1].flags
|= CCW_FLAG_CC
;
3175 locate_record(ccw
++, LO_data
++,
3177 last_rec
- recid
+ 1,
3178 cmd
, basedev
, count
);
3180 /* Read/write ccw. */
3181 ccw
[-1].flags
|= CCW_FLAG_CC
;
3182 ccw
->cmd_code
= rcmd
;
3184 if (idal_is_needed(dst
, blksize
)) {
3185 ccw
->cda
= (__u32
)(addr_t
) idaws
;
3186 ccw
->flags
= CCW_FLAG_IDA
;
3187 idaws
= idal_create_words(idaws
, dst
, blksize
);
3189 ccw
->cda
= (__u32
)(addr_t
) dst
;
3197 if (blk_noretry_request(req
) ||
3198 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3199 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3200 cqr
->startdev
= startdev
;
3201 cqr
->memdev
= startdev
;
3203 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3204 cqr
->lpm
= dasd_path_get_ppm(startdev
);
3205 cqr
->retries
= startdev
->default_retries
;
3206 cqr
->buildclk
= get_tod_clock();
3207 cqr
->status
= DASD_CQR_FILLED
;
3211 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_track(
3212 struct dasd_device
*startdev
,
3213 struct dasd_block
*block
,
3214 struct request
*req
,
3219 unsigned int first_offs
,
3220 unsigned int last_offs
,
3221 unsigned int blk_per_trk
,
3222 unsigned int blksize
)
3224 unsigned long *idaws
;
3225 struct dasd_ccw_req
*cqr
;
3227 struct req_iterator iter
;
3229 char *dst
, *idaw_dst
;
3230 unsigned int cidaw
, cplength
, datasize
;
3234 struct dasd_device
*basedev
;
3235 unsigned int trkcount
, count
, count_to_trk_end
;
3236 unsigned int idaw_len
, seg_len
, part_len
, len_to_track_end
;
3237 unsigned char new_track
, end_idaw
;
3239 unsigned int recoffs
;
3241 basedev
= block
->base
;
3242 if (rq_data_dir(req
) == READ
)
3243 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
3244 else if (rq_data_dir(req
) == WRITE
)
3245 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
3247 return ERR_PTR(-EINVAL
);
3249 /* Track based I/O needs IDAWs for each page, and not just for
3250 * 64 bit addresses. We need additional idals for pages
3251 * that get filled from two tracks, so we use the number
3252 * of records as upper limit.
3254 cidaw
= last_rec
- first_rec
+ 1;
3255 trkcount
= last_trk
- first_trk
+ 1;
3257 /* 1x prefix + one read/write ccw per track */
3258 cplength
= 1 + trkcount
;
3260 datasize
= sizeof(struct PFX_eckd_data
) + cidaw
* sizeof(unsigned long);
3262 /* Allocate the ccw request. */
3263 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
3268 /* transfer length factor: how many bytes to read from the last track */
3269 if (first_trk
== last_trk
)
3270 tlf
= last_offs
- first_offs
+ 1;
3272 tlf
= last_offs
+ 1;
3275 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
,
3276 last_trk
, cmd
, basedev
, startdev
,
3277 1 /* format */, first_offs
+ 1,
3280 /* Clock not in sync and XRC is enabled.
3283 dasd_sfree_request(cqr
, startdev
);
3284 return ERR_PTR(-EAGAIN
);
3288 * The translation of request into ccw programs must meet the
3289 * following conditions:
3290 * - all idaws but the first and the last must address full pages
3291 * (or 2K blocks on 31-bit)
3292 * - the scope of a ccw and it's idal ends with the track boundaries
3294 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct PFX_eckd_data
));
3298 len_to_track_end
= 0;
3301 rq_for_each_segment(bv
, req
, iter
) {
3302 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3303 seg_len
= bv
.bv_len
;
3307 recoffs
= sector_div(trkid
, blk_per_trk
);
3308 count_to_trk_end
= blk_per_trk
- recoffs
;
3309 count
= min((last_rec
- recid
+ 1),
3310 (sector_t
)count_to_trk_end
);
3311 len_to_track_end
= count
* blksize
;
3312 ccw
[-1].flags
|= CCW_FLAG_CC
;
3313 ccw
->cmd_code
= cmd
;
3314 ccw
->count
= len_to_track_end
;
3315 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3316 ccw
->flags
= CCW_FLAG_IDA
;
3320 /* first idaw for a ccw may start anywhere */
3324 /* If we start a new idaw, we must make sure that it
3325 * starts on an IDA_BLOCK_SIZE boundary.
3326 * If we continue an idaw, we must make sure that the
3327 * current segment begins where the so far accumulated
3331 if (__pa(dst
) & (IDA_BLOCK_SIZE
-1)) {
3332 dasd_sfree_request(cqr
, startdev
);
3333 return ERR_PTR(-ERANGE
);
3337 if ((idaw_dst
+ idaw_len
) != dst
) {
3338 dasd_sfree_request(cqr
, startdev
);
3339 return ERR_PTR(-ERANGE
);
3341 part_len
= min(seg_len
, len_to_track_end
);
3342 seg_len
-= part_len
;
3344 idaw_len
+= part_len
;
3345 len_to_track_end
-= part_len
;
3346 /* collected memory area ends on an IDA_BLOCK border,
3348 * idal_create_words will handle cases where idaw_len
3349 * is larger then IDA_BLOCK_SIZE
3351 if (!(__pa(idaw_dst
+ idaw_len
) & (IDA_BLOCK_SIZE
-1)))
3353 /* We also need to end the idaw at track end */
3354 if (!len_to_track_end
) {
3359 idaws
= idal_create_words(idaws
, idaw_dst
,
3368 if (blk_noretry_request(req
) ||
3369 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3370 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3371 cqr
->startdev
= startdev
;
3372 cqr
->memdev
= startdev
;
3374 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3375 cqr
->lpm
= dasd_path_get_ppm(startdev
);
3376 cqr
->retries
= startdev
->default_retries
;
3377 cqr
->buildclk
= get_tod_clock();
3378 cqr
->status
= DASD_CQR_FILLED
;
3382 static int prepare_itcw(struct itcw
*itcw
,
3383 unsigned int trk
, unsigned int totrk
, int cmd
,
3384 struct dasd_device
*basedev
,
3385 struct dasd_device
*startdev
,
3386 unsigned int rec_on_trk
, int count
,
3387 unsigned int blksize
,
3388 unsigned int total_data_size
,
3390 unsigned int blk_per_trk
)
3392 struct PFX_eckd_data pfxdata
;
3393 struct dasd_eckd_private
*basepriv
, *startpriv
;
3394 struct DE_eckd_data
*dedata
;
3395 struct LRE_eckd_data
*lredata
;
3399 u16 heads
, beghead
, endhead
;
3407 /* setup prefix data */
3408 basepriv
= basedev
->private;
3409 startpriv
= startdev
->private;
3410 dedata
= &pfxdata
.define_extent
;
3411 lredata
= &pfxdata
.locate_record
;
3413 memset(&pfxdata
, 0, sizeof(pfxdata
));
3414 pfxdata
.format
= 1; /* PFX with LRE */
3415 pfxdata
.base_address
= basepriv
->ned
->unit_addr
;
3416 pfxdata
.base_lss
= basepriv
->ned
->ID
;
3417 pfxdata
.validity
.define_extent
= 1;
3419 /* private uid is kept up to date, conf_data may be outdated */
3420 if (startpriv
->uid
.type
== UA_BASE_PAV_ALIAS
)
3421 pfxdata
.validity
.verify_base
= 1;
3423 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
) {
3424 pfxdata
.validity
.verify_base
= 1;
3425 pfxdata
.validity
.hyper_pav
= 1;
3429 case DASD_ECKD_CCW_READ_TRACK_DATA
:
3430 dedata
->mask
.perm
= 0x1;
3431 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3432 dedata
->blk_size
= blksize
;
3433 dedata
->ga_extended
|= 0x42;
3434 lredata
->operation
.orientation
= 0x0;
3435 lredata
->operation
.operation
= 0x0C;
3436 lredata
->auxiliary
.check_bytes
= 0x01;
3437 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
3439 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
3440 dedata
->mask
.perm
= 0x02;
3441 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3442 dedata
->blk_size
= blksize
;
3443 rc
= check_XRC(NULL
, dedata
, basedev
);
3444 dedata
->ga_extended
|= 0x42;
3445 lredata
->operation
.orientation
= 0x0;
3446 lredata
->operation
.operation
= 0x3F;
3447 lredata
->extended_operation
= 0x23;
3448 lredata
->auxiliary
.check_bytes
= 0x2;
3450 * If XRC is supported the System Time Stamp is set. The
3451 * validity of the time stamp must be reflected in the prefix
3454 if (dedata
->ga_extended
& 0x08 && dedata
->ga_extended
& 0x02)
3455 pfxdata
.validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
3456 pfx_cmd
= DASD_ECKD_CCW_PFX
;
3458 case DASD_ECKD_CCW_READ_COUNT_MT
:
3459 dedata
->mask
.perm
= 0x1;
3460 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
3461 dedata
->ga_extended
|= 0x42;
3462 dedata
->blk_size
= blksize
;
3463 lredata
->operation
.orientation
= 0x2;
3464 lredata
->operation
.operation
= 0x16;
3465 lredata
->auxiliary
.check_bytes
= 0x01;
3466 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
3469 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3470 "prepare itcw, unknown opcode 0x%x", cmd
);
3477 dedata
->attributes
.mode
= 0x3; /* ECKD */
3479 heads
= basepriv
->rdc_data
.trk_per_cyl
;
3480 begcyl
= trk
/ heads
;
3481 beghead
= trk
% heads
;
3482 endcyl
= totrk
/ heads
;
3483 endhead
= totrk
% heads
;
3485 /* check for sequential prestage - enhance cylinder range */
3486 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
3487 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
3489 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
3490 endcyl
+= basepriv
->attrib
.nr_cyl
;
3492 endcyl
= (basepriv
->real_cyl
- 1);
3495 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
3496 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
3498 dedata
->ep_format
= 0x20; /* records per track is valid */
3499 dedata
->ep_rec_per_track
= blk_per_trk
;
3502 switch (basepriv
->rdc_data
.dev_type
) {
3504 dn
= ceil_quot(blksize
+ 6, 232);
3505 d
= 9 + ceil_quot(blksize
+ 6 * (dn
+ 1), 34);
3506 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
3509 d
= 7 + ceil_quot(blksize
+ 12, 32);
3510 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
3515 if (cmd
== DASD_ECKD_CCW_READ_COUNT_MT
) {
3516 lredata
->auxiliary
.length_valid
= 0;
3517 lredata
->auxiliary
.length_scope
= 0;
3518 lredata
->sector
= 0xff;
3520 lredata
->auxiliary
.length_valid
= 1;
3521 lredata
->auxiliary
.length_scope
= 1;
3522 lredata
->sector
= sector
;
3524 lredata
->auxiliary
.imbedded_ccw_valid
= 1;
3525 lredata
->length
= tlf
;
3526 lredata
->imbedded_ccw
= cmd
;
3527 lredata
->count
= count
;
3528 set_ch_t(&lredata
->seek_addr
, begcyl
, beghead
);
3529 lredata
->search_arg
.cyl
= lredata
->seek_addr
.cyl
;
3530 lredata
->search_arg
.head
= lredata
->seek_addr
.head
;
3531 lredata
->search_arg
.record
= rec_on_trk
;
3533 dcw
= itcw_add_dcw(itcw
, pfx_cmd
, 0,
3534 &pfxdata
, sizeof(pfxdata
), total_data_size
);
3535 return PTR_RET(dcw
);
3538 static struct dasd_ccw_req
*dasd_eckd_build_cp_tpm_track(
3539 struct dasd_device
*startdev
,
3540 struct dasd_block
*block
,
3541 struct request
*req
,
3546 unsigned int first_offs
,
3547 unsigned int last_offs
,
3548 unsigned int blk_per_trk
,
3549 unsigned int blksize
)
3551 struct dasd_ccw_req
*cqr
;
3552 struct req_iterator iter
;
3555 unsigned int trkcount
, ctidaw
;
3557 struct dasd_device
*basedev
;
3560 struct tidaw
*last_tidaw
= NULL
;
3564 unsigned int seg_len
, part_len
, len_to_track_end
;
3565 unsigned char new_track
;
3566 sector_t recid
, trkid
;
3568 unsigned int count
, count_to_trk_end
;
3571 basedev
= block
->base
;
3572 if (rq_data_dir(req
) == READ
) {
3573 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
3574 itcw_op
= ITCW_OP_READ
;
3575 } else if (rq_data_dir(req
) == WRITE
) {
3576 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
3577 itcw_op
= ITCW_OP_WRITE
;
3579 return ERR_PTR(-EINVAL
);
3581 /* trackbased I/O needs address all memory via TIDAWs,
3582 * not just for 64 bit addresses. This allows us to map
3583 * each segment directly to one tidaw.
3584 * In the case of write requests, additional tidaws may
3585 * be needed when a segment crosses a track boundary.
3587 trkcount
= last_trk
- first_trk
+ 1;
3589 rq_for_each_segment(bv
, req
, iter
) {
3592 if (rq_data_dir(req
) == WRITE
)
3593 ctidaw
+= (last_trk
- first_trk
);
3595 /* Allocate the ccw request. */
3596 itcw_size
= itcw_calc_size(0, ctidaw
, 0);
3597 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
3601 /* transfer length factor: how many bytes to read from the last track */
3602 if (first_trk
== last_trk
)
3603 tlf
= last_offs
- first_offs
+ 1;
3605 tlf
= last_offs
+ 1;
3608 itcw
= itcw_init(cqr
->data
, itcw_size
, itcw_op
, 0, ctidaw
, 0);
3613 cqr
->cpaddr
= itcw_get_tcw(itcw
);
3614 if (prepare_itcw(itcw
, first_trk
, last_trk
,
3615 cmd
, basedev
, startdev
,
3618 (last_rec
- first_rec
+ 1) * blksize
,
3619 tlf
, blk_per_trk
) == -EAGAIN
) {
3620 /* Clock not in sync and XRC is enabled.
3626 len_to_track_end
= 0;
3628 * A tidaw can address 4k of memory, but must not cross page boundaries
3629 * We can let the block layer handle this by setting
3630 * blk_queue_segment_boundary to page boundaries and
3631 * blk_max_segment_size to page size when setting up the request queue.
3632 * For write requests, a TIDAW must not cross track boundaries, because
3633 * we have to set the CBC flag on the last tidaw for each track.
3635 if (rq_data_dir(req
) == WRITE
) {
3638 rq_for_each_segment(bv
, req
, iter
) {
3639 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3640 seg_len
= bv
.bv_len
;
3644 offs
= sector_div(trkid
, blk_per_trk
);
3645 count_to_trk_end
= blk_per_trk
- offs
;
3646 count
= min((last_rec
- recid
+ 1),
3647 (sector_t
)count_to_trk_end
);
3648 len_to_track_end
= count
* blksize
;
3652 part_len
= min(seg_len
, len_to_track_end
);
3653 seg_len
-= part_len
;
3654 len_to_track_end
-= part_len
;
3655 /* We need to end the tidaw at track end */
3656 if (!len_to_track_end
) {
3658 tidaw_flags
= TIDAW_FLAGS_INSERT_CBC
;
3661 last_tidaw
= itcw_add_tidaw(itcw
, tidaw_flags
,
3663 if (IS_ERR(last_tidaw
)) {
3671 rq_for_each_segment(bv
, req
, iter
) {
3672 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3673 last_tidaw
= itcw_add_tidaw(itcw
, 0x00,
3675 if (IS_ERR(last_tidaw
)) {
3681 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
3682 last_tidaw
->flags
&= ~TIDAW_FLAGS_INSERT_CBC
;
3683 itcw_finalize(itcw
);
3685 if (blk_noretry_request(req
) ||
3686 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3687 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3689 cqr
->startdev
= startdev
;
3690 cqr
->memdev
= startdev
;
3692 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3693 cqr
->lpm
= dasd_path_get_ppm(startdev
);
3694 cqr
->retries
= startdev
->default_retries
;
3695 cqr
->buildclk
= get_tod_clock();
3696 cqr
->status
= DASD_CQR_FILLED
;
3699 dasd_sfree_request(cqr
, startdev
);
3700 return ERR_PTR(ret
);
3703 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
3704 struct dasd_block
*block
,
3705 struct request
*req
)
3710 struct dasd_eckd_private
*private;
3711 struct dasd_device
*basedev
;
3712 sector_t first_rec
, last_rec
;
3713 sector_t first_trk
, last_trk
;
3714 unsigned int first_offs
, last_offs
;
3715 unsigned int blk_per_trk
, blksize
;
3717 unsigned int data_size
;
3718 struct dasd_ccw_req
*cqr
;
3720 basedev
= block
->base
;
3721 private = basedev
->private;
3723 /* Calculate number of blocks/records per track. */
3724 blksize
= block
->bp_block
;
3725 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3726 if (blk_per_trk
== 0)
3727 return ERR_PTR(-EINVAL
);
3728 /* Calculate record id of first and last block. */
3729 first_rec
= first_trk
= blk_rq_pos(req
) >> block
->s2b_shift
;
3730 first_offs
= sector_div(first_trk
, blk_per_trk
);
3731 last_rec
= last_trk
=
3732 (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) >> block
->s2b_shift
;
3733 last_offs
= sector_div(last_trk
, blk_per_trk
);
3734 cdlspecial
= (private->uses_cdl
&& first_rec
< 2*blk_per_trk
);
3736 fcx_multitrack
= private->features
.feature
[40] & 0x20;
3737 data_size
= blk_rq_bytes(req
);
3738 if (data_size
% blksize
)
3739 return ERR_PTR(-EINVAL
);
3740 /* tpm write request add CBC data on each track boundary */
3741 if (rq_data_dir(req
) == WRITE
)
3742 data_size
+= (last_trk
- first_trk
) * 4;
3744 /* is read track data and write track data in command mode supported? */
3745 cmdrtd
= private->features
.feature
[9] & 0x20;
3746 cmdwtd
= private->features
.feature
[12] & 0x40;
3747 use_prefix
= private->features
.feature
[8] & 0x01;
3750 if (cdlspecial
|| dasd_page_cache
) {
3751 /* do nothing, just fall through to the cmd mode single case */
3752 } else if ((data_size
<= private->fcx_max_data
)
3753 && (fcx_multitrack
|| (first_trk
== last_trk
))) {
3754 cqr
= dasd_eckd_build_cp_tpm_track(startdev
, block
, req
,
3755 first_rec
, last_rec
,
3756 first_trk
, last_trk
,
3757 first_offs
, last_offs
,
3758 blk_per_trk
, blksize
);
3759 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3760 (PTR_ERR(cqr
) != -ENOMEM
))
3762 } else if (use_prefix
&&
3763 (((rq_data_dir(req
) == READ
) && cmdrtd
) ||
3764 ((rq_data_dir(req
) == WRITE
) && cmdwtd
))) {
3765 cqr
= dasd_eckd_build_cp_cmd_track(startdev
, block
, req
,
3766 first_rec
, last_rec
,
3767 first_trk
, last_trk
,
3768 first_offs
, last_offs
,
3769 blk_per_trk
, blksize
);
3770 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3771 (PTR_ERR(cqr
) != -ENOMEM
))
3775 cqr
= dasd_eckd_build_cp_cmd_single(startdev
, block
, req
,
3776 first_rec
, last_rec
,
3777 first_trk
, last_trk
,
3778 first_offs
, last_offs
,
3779 blk_per_trk
, blksize
);
3783 static struct dasd_ccw_req
*dasd_eckd_build_cp_raw(struct dasd_device
*startdev
,
3784 struct dasd_block
*block
,
3785 struct request
*req
)
3787 sector_t start_padding_sectors
, end_sector_offset
, end_padding_sectors
;
3788 unsigned int seg_len
, len_to_track_end
;
3789 unsigned int cidaw
, cplength
, datasize
;
3790 sector_t first_trk
, last_trk
, sectors
;
3791 struct dasd_eckd_private
*base_priv
;
3792 struct dasd_device
*basedev
;
3793 struct req_iterator iter
;
3794 struct dasd_ccw_req
*cqr
;
3795 unsigned int first_offs
;
3796 unsigned int trkcount
;
3797 unsigned long *idaws
;
3807 * raw track access needs to be mutiple of 64k and on 64k boundary
3808 * For read requests we can fix an incorrect alignment by padding
3809 * the request with dummy pages.
3811 start_padding_sectors
= blk_rq_pos(req
) % DASD_RAW_SECTORS_PER_TRACK
;
3812 end_sector_offset
= (blk_rq_pos(req
) + blk_rq_sectors(req
)) %
3813 DASD_RAW_SECTORS_PER_TRACK
;
3814 end_padding_sectors
= (DASD_RAW_SECTORS_PER_TRACK
- end_sector_offset
) %
3815 DASD_RAW_SECTORS_PER_TRACK
;
3816 basedev
= block
->base
;
3817 if ((start_padding_sectors
|| end_padding_sectors
) &&
3818 (rq_data_dir(req
) == WRITE
)) {
3819 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3820 "raw write not track aligned (%lu,%lu) req %p",
3821 start_padding_sectors
, end_padding_sectors
, req
);
3822 return ERR_PTR(-EINVAL
);
3825 first_trk
= blk_rq_pos(req
) / DASD_RAW_SECTORS_PER_TRACK
;
3826 last_trk
= (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) /
3827 DASD_RAW_SECTORS_PER_TRACK
;
3828 trkcount
= last_trk
- first_trk
+ 1;
3831 if (rq_data_dir(req
) == READ
)
3832 cmd
= DASD_ECKD_CCW_READ_TRACK
;
3833 else if (rq_data_dir(req
) == WRITE
)
3834 cmd
= DASD_ECKD_CCW_WRITE_FULL_TRACK
;
3836 return ERR_PTR(-EINVAL
);
3839 * Raw track based I/O needs IDAWs for each page,
3840 * and not just for 64 bit addresses.
3842 cidaw
= trkcount
* DASD_RAW_BLOCK_PER_TRACK
;
3845 * struct PFX_eckd_data and struct LRE_eckd_data can have up to 2 bytes
3846 * of extended parameter. This is needed for write full track.
3848 base_priv
= basedev
->private;
3849 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
3851 cplength
= 1 + trkcount
;
3852 size
= sizeof(struct PFX_eckd_data
) + 2;
3854 cplength
= 2 + trkcount
;
3855 size
= sizeof(struct DE_eckd_data
) +
3856 sizeof(struct LRE_eckd_data
) + 2;
3858 size
= ALIGN(size
, 8);
3860 datasize
= size
+ cidaw
* sizeof(unsigned long);
3862 /* Allocate the ccw request. */
3863 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
3864 datasize
, startdev
);
3872 prefix_LRE(ccw
++, data
, first_trk
, last_trk
, cmd
, basedev
,
3873 startdev
, 1, first_offs
+ 1, trkcount
, 0, 0);
3875 define_extent(ccw
++, data
, first_trk
, last_trk
, cmd
, basedev
, 0);
3876 ccw
[-1].flags
|= CCW_FLAG_CC
;
3878 data
+= sizeof(struct DE_eckd_data
);
3879 locate_record_ext(ccw
++, data
, first_trk
, first_offs
+ 1,
3880 trkcount
, cmd
, basedev
, 0, 0);
3883 idaws
= (unsigned long *)(cqr
->data
+ size
);
3884 len_to_track_end
= 0;
3885 if (start_padding_sectors
) {
3886 ccw
[-1].flags
|= CCW_FLAG_CC
;
3887 ccw
->cmd_code
= cmd
;
3888 /* maximum 3390 track size */
3890 /* 64k map to one track */
3891 len_to_track_end
= 65536 - start_padding_sectors
* 512;
3892 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3893 ccw
->flags
|= CCW_FLAG_IDA
;
3894 ccw
->flags
|= CCW_FLAG_SLI
;
3896 for (sectors
= 0; sectors
< start_padding_sectors
; sectors
+= 8)
3897 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3899 rq_for_each_segment(bv
, req
, iter
) {
3900 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3901 seg_len
= bv
.bv_len
;
3902 if (cmd
== DASD_ECKD_CCW_READ_TRACK
)
3903 memset(dst
, 0, seg_len
);
3904 if (!len_to_track_end
) {
3905 ccw
[-1].flags
|= CCW_FLAG_CC
;
3906 ccw
->cmd_code
= cmd
;
3907 /* maximum 3390 track size */
3909 /* 64k map to one track */
3910 len_to_track_end
= 65536;
3911 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3912 ccw
->flags
|= CCW_FLAG_IDA
;
3913 ccw
->flags
|= CCW_FLAG_SLI
;
3916 len_to_track_end
-= seg_len
;
3917 idaws
= idal_create_words(idaws
, dst
, seg_len
);
3919 for (sectors
= 0; sectors
< end_padding_sectors
; sectors
+= 8)
3920 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3921 if (blk_noretry_request(req
) ||
3922 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3923 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3924 cqr
->startdev
= startdev
;
3925 cqr
->memdev
= startdev
;
3927 cqr
->expires
= startdev
->default_expires
* HZ
;
3928 cqr
->lpm
= dasd_path_get_ppm(startdev
);
3929 cqr
->retries
= startdev
->default_retries
;
3930 cqr
->buildclk
= get_tod_clock();
3931 cqr
->status
= DASD_CQR_FILLED
;
3938 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
3940 struct dasd_eckd_private
*private;
3942 struct req_iterator iter
;
3945 unsigned int blksize
, blk_per_trk
, off
;
3949 if (!dasd_page_cache
)
3951 private = cqr
->block
->base
->private;
3952 blksize
= cqr
->block
->bp_block
;
3953 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3954 recid
= blk_rq_pos(req
) >> cqr
->block
->s2b_shift
;
3956 /* Skip over define extent & locate record. */
3958 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
3960 rq_for_each_segment(bv
, req
, iter
) {
3961 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3962 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
3963 /* Skip locate record. */
3964 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
3967 if (ccw
->flags
& CCW_FLAG_IDA
)
3968 cda
= *((char **)((addr_t
) ccw
->cda
));
3970 cda
= (char *)((addr_t
) ccw
->cda
);
3972 if (rq_data_dir(req
) == READ
)
3973 memcpy(dst
, cda
, bv
.bv_len
);
3974 kmem_cache_free(dasd_page_cache
,
3975 (void *)((addr_t
)cda
& PAGE_MASK
));
3984 status
= cqr
->status
== DASD_CQR_DONE
;
3985 dasd_sfree_request(cqr
, cqr
->memdev
);
3990 * Modify ccw/tcw in cqr so it can be started on a base device.
3992 * Note that this is not enough to restart the cqr!
3993 * Either reset cqr->startdev as well (summary unit check handling)
3994 * or restart via separate cqr (as in ERP handling).
3996 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
3999 struct PFX_eckd_data
*pfxdata
;
4004 if (cqr
->cpmode
== 1) {
4006 tccb
= tcw_get_tccb(tcw
);
4007 dcw
= (struct dcw
*)&tccb
->tca
[0];
4008 pfxdata
= (struct PFX_eckd_data
*)&dcw
->cd
[0];
4009 pfxdata
->validity
.verify_base
= 0;
4010 pfxdata
->validity
.hyper_pav
= 0;
4013 pfxdata
= cqr
->data
;
4014 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
4015 pfxdata
->validity
.verify_base
= 0;
4016 pfxdata
->validity
.hyper_pav
= 0;
4021 #define DASD_ECKD_CHANQ_MAX_SIZE 4
4023 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
4024 struct dasd_block
*block
,
4025 struct request
*req
)
4027 struct dasd_eckd_private
*private;
4028 struct dasd_device
*startdev
;
4029 unsigned long flags
;
4030 struct dasd_ccw_req
*cqr
;
4032 startdev
= dasd_alias_get_start_dev(base
);
4035 private = startdev
->private;
4036 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
4037 return ERR_PTR(-EBUSY
);
4039 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
4041 if ((base
->features
& DASD_FEATURE_USERAW
))
4042 cqr
= dasd_eckd_build_cp_raw(startdev
, block
, req
);
4044 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
4047 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
4051 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
4052 struct request
*req
)
4054 struct dasd_eckd_private
*private;
4055 unsigned long flags
;
4057 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
4058 private = cqr
->memdev
->private;
4060 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
4061 return dasd_eckd_free_cp(cqr
, req
);
4065 dasd_eckd_fill_info(struct dasd_device
* device
,
4066 struct dasd_information2_t
* info
)
4068 struct dasd_eckd_private
*private = device
->private;
4070 info
->label_block
= 2;
4071 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
4072 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
4073 info
->characteristics_size
= sizeof(private->rdc_data
);
4074 memcpy(info
->characteristics
, &private->rdc_data
,
4075 sizeof(private->rdc_data
));
4076 info
->confdata_size
= min((unsigned long)private->conf_len
,
4077 sizeof(info
->configuration_data
));
4078 memcpy(info
->configuration_data
, private->conf_data
,
4079 info
->confdata_size
);
4084 * SECTION: ioctl functions for eckd devices.
4088 * Release device ioctl.
4089 * Buils a channel programm to releases a prior reserved
4090 * (see dasd_eckd_reserve) device.
4093 dasd_eckd_release(struct dasd_device
*device
)
4095 struct dasd_ccw_req
*cqr
;
4100 if (!capable(CAP_SYS_ADMIN
))
4104 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
4106 mutex_lock(&dasd_reserve_mutex
);
4108 cqr
= &dasd_reserve_req
->cqr
;
4109 memset(cqr
, 0, sizeof(*cqr
));
4110 memset(&dasd_reserve_req
->ccw
, 0,
4111 sizeof(dasd_reserve_req
->ccw
));
4112 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
4113 cqr
->data
= &dasd_reserve_req
->data
;
4114 cqr
->magic
= DASD_ECKD_MAGIC
;
4117 ccw
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
4118 ccw
->flags
|= CCW_FLAG_SLI
;
4120 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
4121 cqr
->startdev
= device
;
4122 cqr
->memdev
= device
;
4123 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4124 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
4125 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
4126 cqr
->expires
= 2 * HZ
;
4127 cqr
->buildclk
= get_tod_clock();
4128 cqr
->status
= DASD_CQR_FILLED
;
4130 rc
= dasd_sleep_on_immediatly(cqr
);
4132 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
4135 mutex_unlock(&dasd_reserve_mutex
);
4137 dasd_sfree_request(cqr
, cqr
->memdev
);
4142 * Reserve device ioctl.
4143 * Options are set to 'synchronous wait for interrupt' and
4144 * 'timeout the request'. This leads to a terminate IO if
4145 * the interrupt is outstanding for a certain time.
4148 dasd_eckd_reserve(struct dasd_device
*device
)
4150 struct dasd_ccw_req
*cqr
;
4155 if (!capable(CAP_SYS_ADMIN
))
4159 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
4161 mutex_lock(&dasd_reserve_mutex
);
4163 cqr
= &dasd_reserve_req
->cqr
;
4164 memset(cqr
, 0, sizeof(*cqr
));
4165 memset(&dasd_reserve_req
->ccw
, 0,
4166 sizeof(dasd_reserve_req
->ccw
));
4167 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
4168 cqr
->data
= &dasd_reserve_req
->data
;
4169 cqr
->magic
= DASD_ECKD_MAGIC
;
4172 ccw
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
4173 ccw
->flags
|= CCW_FLAG_SLI
;
4175 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
4176 cqr
->startdev
= device
;
4177 cqr
->memdev
= device
;
4178 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4179 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
4180 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
4181 cqr
->expires
= 2 * HZ
;
4182 cqr
->buildclk
= get_tod_clock();
4183 cqr
->status
= DASD_CQR_FILLED
;
4185 rc
= dasd_sleep_on_immediatly(cqr
);
4187 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
4190 mutex_unlock(&dasd_reserve_mutex
);
4192 dasd_sfree_request(cqr
, cqr
->memdev
);
4197 * Steal lock ioctl - unconditional reserve device.
4198 * Buils a channel programm to break a device's reservation.
4199 * (unconditional reserve)
4202 dasd_eckd_steal_lock(struct dasd_device
*device
)
4204 struct dasd_ccw_req
*cqr
;
4209 if (!capable(CAP_SYS_ADMIN
))
4213 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
4215 mutex_lock(&dasd_reserve_mutex
);
4217 cqr
= &dasd_reserve_req
->cqr
;
4218 memset(cqr
, 0, sizeof(*cqr
));
4219 memset(&dasd_reserve_req
->ccw
, 0,
4220 sizeof(dasd_reserve_req
->ccw
));
4221 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
4222 cqr
->data
= &dasd_reserve_req
->data
;
4223 cqr
->magic
= DASD_ECKD_MAGIC
;
4226 ccw
->cmd_code
= DASD_ECKD_CCW_SLCK
;
4227 ccw
->flags
|= CCW_FLAG_SLI
;
4229 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
4230 cqr
->startdev
= device
;
4231 cqr
->memdev
= device
;
4232 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4233 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
4234 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
4235 cqr
->expires
= 2 * HZ
;
4236 cqr
->buildclk
= get_tod_clock();
4237 cqr
->status
= DASD_CQR_FILLED
;
4239 rc
= dasd_sleep_on_immediatly(cqr
);
4241 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
4244 mutex_unlock(&dasd_reserve_mutex
);
4246 dasd_sfree_request(cqr
, cqr
->memdev
);
4251 * SNID - Sense Path Group ID
4252 * This ioctl may be used in situations where I/O is stalled due to
4253 * a reserve, so if the normal dasd_smalloc_request fails, we use the
4254 * preallocated dasd_reserve_req.
4256 static int dasd_eckd_snid(struct dasd_device
*device
,
4259 struct dasd_ccw_req
*cqr
;
4263 struct dasd_snid_ioctl_data usrparm
;
4265 if (!capable(CAP_SYS_ADMIN
))
4268 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
4272 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1,
4273 sizeof(struct dasd_snid_data
), device
);
4275 mutex_lock(&dasd_reserve_mutex
);
4277 cqr
= &dasd_reserve_req
->cqr
;
4278 memset(cqr
, 0, sizeof(*cqr
));
4279 memset(&dasd_reserve_req
->ccw
, 0,
4280 sizeof(dasd_reserve_req
->ccw
));
4281 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
4282 cqr
->data
= &dasd_reserve_req
->data
;
4283 cqr
->magic
= DASD_ECKD_MAGIC
;
4286 ccw
->cmd_code
= DASD_ECKD_CCW_SNID
;
4287 ccw
->flags
|= CCW_FLAG_SLI
;
4289 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
4290 cqr
->startdev
= device
;
4291 cqr
->memdev
= device
;
4292 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4293 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
4294 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
4296 cqr
->expires
= 10 * HZ
;
4297 cqr
->buildclk
= get_tod_clock();
4298 cqr
->status
= DASD_CQR_FILLED
;
4299 cqr
->lpm
= usrparm
.path_mask
;
4301 rc
= dasd_sleep_on_immediatly(cqr
);
4302 /* verify that I/O processing didn't modify the path mask */
4303 if (!rc
&& usrparm
.path_mask
&& (cqr
->lpm
!= usrparm
.path_mask
))
4306 usrparm
.data
= *((struct dasd_snid_data
*)cqr
->data
);
4307 if (copy_to_user(argp
, &usrparm
, sizeof(usrparm
)))
4312 mutex_unlock(&dasd_reserve_mutex
);
4314 dasd_sfree_request(cqr
, cqr
->memdev
);
4319 * Read performance statistics
4322 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
4324 struct dasd_psf_prssd_data
*prssdp
;
4325 struct dasd_rssd_perf_stats_t
*stats
;
4326 struct dasd_ccw_req
*cqr
;
4330 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
4331 (sizeof(struct dasd_psf_prssd_data
) +
4332 sizeof(struct dasd_rssd_perf_stats_t
)),
4335 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4336 "Could not allocate initialization request");
4337 return PTR_ERR(cqr
);
4339 cqr
->startdev
= device
;
4340 cqr
->memdev
= device
;
4342 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4343 cqr
->expires
= 10 * HZ
;
4345 /* Prepare for Read Subsystem Data */
4346 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4347 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
4348 prssdp
->order
= PSF_ORDER_PRSSD
;
4349 prssdp
->suborder
= 0x01; /* Performance Statistics */
4350 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
4353 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4354 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
4355 ccw
->flags
|= CCW_FLAG_CC
;
4356 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
4358 /* Read Subsystem Data - Performance Statistics */
4359 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
4360 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
4363 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4364 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
4365 ccw
->cda
= (__u32
)(addr_t
) stats
;
4367 cqr
->buildclk
= get_tod_clock();
4368 cqr
->status
= DASD_CQR_FILLED
;
4369 rc
= dasd_sleep_on(cqr
);
4371 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4372 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
4373 if (copy_to_user(argp
, stats
,
4374 sizeof(struct dasd_rssd_perf_stats_t
)))
4377 dasd_sfree_request(cqr
, cqr
->memdev
);
4382 * Get attributes (cache operations)
4383 * Returnes the cache attributes used in Define Extend (DE).
4386 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
4388 struct dasd_eckd_private
*private = device
->private;
4389 struct attrib_data_t attrib
= private->attrib
;
4392 if (!capable(CAP_SYS_ADMIN
))
4398 if (copy_to_user(argp
, (long *) &attrib
,
4399 sizeof(struct attrib_data_t
)))
4406 * Set attributes (cache operations)
4407 * Stores the attributes for cache operation to be used in Define Extend (DE).
4410 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
4412 struct dasd_eckd_private
*private = device
->private;
4413 struct attrib_data_t attrib
;
4415 if (!capable(CAP_SYS_ADMIN
))
4420 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
4422 private->attrib
= attrib
;
4424 dev_info(&device
->cdev
->dev
,
4425 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
4426 private->attrib
.operation
, private->attrib
.nr_cyl
);
4431 * Issue syscall I/O to EMC Symmetrix array.
4432 * CCWs are PSF and RSSD
4434 static int dasd_symm_io(struct dasd_device
*device
, void __user
*argp
)
4436 struct dasd_symmio_parms usrparm
;
4437 char *psf_data
, *rssd_result
;
4438 struct dasd_ccw_req
*cqr
;
4443 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
4447 /* Copy parms from caller */
4449 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
4451 if (is_compat_task()) {
4452 /* Make sure pointers are sane even on 31 bit. */
4454 if ((usrparm
.psf_data
>> 32) != 0)
4456 if ((usrparm
.rssd_result
>> 32) != 0)
4458 usrparm
.psf_data
&= 0x7fffffffULL
;
4459 usrparm
.rssd_result
&= 0x7fffffffULL
;
4461 /* alloc I/O data area */
4462 psf_data
= kzalloc(usrparm
.psf_data_len
, GFP_KERNEL
| GFP_DMA
);
4463 rssd_result
= kzalloc(usrparm
.rssd_result_len
, GFP_KERNEL
| GFP_DMA
);
4464 if (!psf_data
|| !rssd_result
) {
4469 /* get syscall header from user space */
4471 if (copy_from_user(psf_data
,
4472 (void __user
*)(unsigned long) usrparm
.psf_data
,
4473 usrparm
.psf_data_len
))
4478 /* setup CCWs for PSF + RSSD */
4479 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 2 , 0, device
);
4481 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4482 "Could not allocate initialization request");
4487 cqr
->startdev
= device
;
4488 cqr
->memdev
= device
;
4490 cqr
->expires
= 10 * HZ
;
4491 cqr
->buildclk
= get_tod_clock();
4492 cqr
->status
= DASD_CQR_FILLED
;
4494 /* Build the ccws */
4498 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4499 ccw
->count
= usrparm
.psf_data_len
;
4500 ccw
->flags
|= CCW_FLAG_CC
;
4501 ccw
->cda
= (__u32
)(addr_t
) psf_data
;
4506 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4507 ccw
->count
= usrparm
.rssd_result_len
;
4508 ccw
->flags
= CCW_FLAG_SLI
;
4509 ccw
->cda
= (__u32
)(addr_t
) rssd_result
;
4511 rc
= dasd_sleep_on(cqr
);
4516 if (copy_to_user((void __user
*)(unsigned long) usrparm
.rssd_result
,
4517 rssd_result
, usrparm
.rssd_result_len
))
4522 dasd_sfree_request(cqr
, cqr
->memdev
);
4527 DBF_DEV_EVENT(DBF_WARNING
, device
,
4528 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4529 (int) psf0
, (int) psf1
, rc
);
4534 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
4536 struct dasd_device
*device
= block
->base
;
4540 return dasd_eckd_get_attrib(device
, argp
);
4542 return dasd_eckd_set_attrib(device
, argp
);
4544 return dasd_eckd_performance(device
, argp
);
4546 return dasd_eckd_release(device
);
4548 return dasd_eckd_reserve(device
);
4550 return dasd_eckd_steal_lock(device
);
4552 return dasd_eckd_snid(device
, argp
);
4554 return dasd_symm_io(device
, argp
);
4561 * Dump the range of CCWs into 'page' buffer
4562 * and return number of printed chars.
4565 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
4571 while (from
<= to
) {
4572 len
+= sprintf(page
+ len
, PRINTK_HEADER
4573 " CCW %p: %08X %08X DAT:",
4574 from
, ((int *) from
)[0], ((int *) from
)[1]);
4576 /* get pointer to data (consider IDALs) */
4577 if (from
->flags
& CCW_FLAG_IDA
)
4578 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
4580 datap
= (char *) ((addr_t
) from
->cda
);
4582 /* dump data (max 32 bytes) */
4583 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
4584 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
4585 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
4586 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
4588 len
+= sprintf(page
+ len
, "\n");
4595 dasd_eckd_dump_sense_dbf(struct dasd_device
*device
, struct irb
*irb
,
4601 sense
= (u64
*) dasd_get_sense(irb
);
4602 stat
= (u64
*) &irb
->scsw
;
4604 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : "
4605 "%016llx %016llx %016llx %016llx",
4606 reason
, *stat
, *((u32
*) (stat
+ 1)),
4607 sense
[0], sense
[1], sense
[2], sense
[3]);
4609 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : %s",
4610 reason
, *stat
, *((u32
*) (stat
+ 1)),
4616 * Print sense data and related channel program.
4617 * Parts are printed because printk buffer is only 1024 bytes.
4619 static void dasd_eckd_dump_sense_ccw(struct dasd_device
*device
,
4620 struct dasd_ccw_req
*req
, struct irb
*irb
)
4623 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
4626 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4628 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4629 "No memory to dump sense data\n");
4632 /* dump the sense data */
4633 len
= sprintf(page
, PRINTK_HEADER
4634 " I/O status report for device %s:\n",
4635 dev_name(&device
->cdev
->dev
));
4636 len
+= sprintf(page
+ len
, PRINTK_HEADER
4637 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4639 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4640 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4641 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4642 req
? req
->intrc
: 0);
4643 len
+= sprintf(page
+ len
, PRINTK_HEADER
4644 " device %s: Failing CCW: %p\n",
4645 dev_name(&device
->cdev
->dev
),
4646 (void *) (addr_t
) irb
->scsw
.cmd
.cpa
);
4647 if (irb
->esw
.esw0
.erw
.cons
) {
4648 for (sl
= 0; sl
< 4; sl
++) {
4649 len
+= sprintf(page
+ len
, PRINTK_HEADER
4650 " Sense(hex) %2d-%2d:",
4651 (8 * sl
), ((8 * sl
) + 7));
4653 for (sct
= 0; sct
< 8; sct
++) {
4654 len
+= sprintf(page
+ len
, " %02x",
4655 irb
->ecw
[8 * sl
+ sct
]);
4657 len
+= sprintf(page
+ len
, "\n");
4660 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
4661 /* 24 Byte Sense Data */
4662 sprintf(page
+ len
, PRINTK_HEADER
4663 " 24 Byte: %x MSG %x, "
4664 "%s MSGb to SYSOP\n",
4665 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
4666 irb
->ecw
[1] & 0x10 ? "" : "no");
4668 /* 32 Byte Sense Data */
4669 sprintf(page
+ len
, PRINTK_HEADER
4670 " 32 Byte: Format: %x "
4671 "Exception class %x\n",
4672 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
4675 sprintf(page
+ len
, PRINTK_HEADER
4676 " SORRY - NO VALID SENSE AVAILABLE\n");
4678 printk(KERN_ERR
"%s", page
);
4681 /* req == NULL for unsolicited interrupts */
4682 /* dump the Channel Program (max 140 Bytes per line) */
4683 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4684 first
= req
->cpaddr
;
4685 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
4686 to
= min(first
+ 6, last
);
4687 len
= sprintf(page
, PRINTK_HEADER
4688 " Related CP in req: %p\n", req
);
4689 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
4690 printk(KERN_ERR
"%s", page
);
4692 /* print failing CCW area (maximum 4) */
4693 /* scsw->cda is either valid or zero */
4696 fail
= (struct ccw1
*)(addr_t
)
4697 irb
->scsw
.cmd
.cpa
; /* failing CCW */
4698 if (from
< fail
- 2) {
4699 from
= fail
- 2; /* there is a gap - print header */
4700 len
+= sprintf(page
, PRINTK_HEADER
"......\n");
4702 to
= min(fail
+ 1, last
);
4703 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
4705 /* print last CCWs (maximum 2) */
4706 from
= max(from
, ++to
);
4707 if (from
< last
- 1) {
4708 from
= last
- 1; /* there is a gap - print header */
4709 len
+= sprintf(page
+ len
, PRINTK_HEADER
"......\n");
4711 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
4713 printk(KERN_ERR
"%s", page
);
4715 free_page((unsigned long) page
);
4720 * Print sense data from a tcw.
4722 static void dasd_eckd_dump_sense_tcw(struct dasd_device
*device
,
4723 struct dasd_ccw_req
*req
, struct irb
*irb
)
4726 int len
, sl
, sct
, residual
;
4730 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4732 DBF_DEV_EVENT(DBF_WARNING
, device
, " %s",
4733 "No memory to dump sense data");
4736 /* dump the sense data */
4737 len
= sprintf(page
, PRINTK_HEADER
4738 " I/O status report for device %s:\n",
4739 dev_name(&device
->cdev
->dev
));
4740 len
+= sprintf(page
+ len
, PRINTK_HEADER
4741 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4742 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4743 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4744 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4745 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4747 (irb
->scsw
.tm
.ifob
<< 7) | irb
->scsw
.tm
.sesq
,
4748 req
? req
->intrc
: 0);
4749 len
+= sprintf(page
+ len
, PRINTK_HEADER
4750 " device %s: Failing TCW: %p\n",
4751 dev_name(&device
->cdev
->dev
),
4752 (void *) (addr_t
) irb
->scsw
.tm
.tcw
);
4756 if (irb
->scsw
.tm
.tcw
&& (irb
->scsw
.tm
.fcxs
& 0x01))
4758 (struct tcw
*)(unsigned long)irb
->scsw
.tm
.tcw
);
4761 len
+= sprintf(page
+ len
, PRINTK_HEADER
4762 " tsb->length %d\n", tsb
->length
);
4763 len
+= sprintf(page
+ len
, PRINTK_HEADER
4764 " tsb->flags %x\n", tsb
->flags
);
4765 len
+= sprintf(page
+ len
, PRINTK_HEADER
4766 " tsb->dcw_offset %d\n", tsb
->dcw_offset
);
4767 len
+= sprintf(page
+ len
, PRINTK_HEADER
4768 " tsb->count %d\n", tsb
->count
);
4769 residual
= tsb
->count
- 28;
4770 len
+= sprintf(page
+ len
, PRINTK_HEADER
4771 " residual %d\n", residual
);
4773 switch (tsb
->flags
& 0x07) {
4774 case 1: /* tsa_iostat */
4775 len
+= sprintf(page
+ len
, PRINTK_HEADER
4776 " tsb->tsa.iostat.dev_time %d\n",
4777 tsb
->tsa
.iostat
.dev_time
);
4778 len
+= sprintf(page
+ len
, PRINTK_HEADER
4779 " tsb->tsa.iostat.def_time %d\n",
4780 tsb
->tsa
.iostat
.def_time
);
4781 len
+= sprintf(page
+ len
, PRINTK_HEADER
4782 " tsb->tsa.iostat.queue_time %d\n",
4783 tsb
->tsa
.iostat
.queue_time
);
4784 len
+= sprintf(page
+ len
, PRINTK_HEADER
4785 " tsb->tsa.iostat.dev_busy_time %d\n",
4786 tsb
->tsa
.iostat
.dev_busy_time
);
4787 len
+= sprintf(page
+ len
, PRINTK_HEADER
4788 " tsb->tsa.iostat.dev_act_time %d\n",
4789 tsb
->tsa
.iostat
.dev_act_time
);
4790 sense
= tsb
->tsa
.iostat
.sense
;
4792 case 2: /* ts_ddpc */
4793 len
+= sprintf(page
+ len
, PRINTK_HEADER
4794 " tsb->tsa.ddpc.rc %d\n", tsb
->tsa
.ddpc
.rc
);
4795 for (sl
= 0; sl
< 2; sl
++) {
4796 len
+= sprintf(page
+ len
, PRINTK_HEADER
4797 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4798 (8 * sl
), ((8 * sl
) + 7));
4799 rcq
= tsb
->tsa
.ddpc
.rcq
;
4800 for (sct
= 0; sct
< 8; sct
++) {
4801 len
+= sprintf(page
+ len
, " %02x",
4804 len
+= sprintf(page
+ len
, "\n");
4806 sense
= tsb
->tsa
.ddpc
.sense
;
4808 case 3: /* tsa_intrg */
4809 len
+= sprintf(page
+ len
, PRINTK_HEADER
4810 " tsb->tsa.intrg.: not supported yet\n");
4815 for (sl
= 0; sl
< 4; sl
++) {
4816 len
+= sprintf(page
+ len
, PRINTK_HEADER
4817 " Sense(hex) %2d-%2d:",
4818 (8 * sl
), ((8 * sl
) + 7));
4819 for (sct
= 0; sct
< 8; sct
++) {
4820 len
+= sprintf(page
+ len
, " %02x",
4821 sense
[8 * sl
+ sct
]);
4823 len
+= sprintf(page
+ len
, "\n");
4826 if (sense
[27] & DASD_SENSE_BIT_0
) {
4827 /* 24 Byte Sense Data */
4828 sprintf(page
+ len
, PRINTK_HEADER
4829 " 24 Byte: %x MSG %x, "
4830 "%s MSGb to SYSOP\n",
4831 sense
[7] >> 4, sense
[7] & 0x0f,
4832 sense
[1] & 0x10 ? "" : "no");
4834 /* 32 Byte Sense Data */
4835 sprintf(page
+ len
, PRINTK_HEADER
4836 " 32 Byte: Format: %x "
4837 "Exception class %x\n",
4838 sense
[6] & 0x0f, sense
[22] >> 4);
4841 sprintf(page
+ len
, PRINTK_HEADER
4842 " SORRY - NO VALID SENSE AVAILABLE\n");
4845 sprintf(page
+ len
, PRINTK_HEADER
4846 " SORRY - NO TSB DATA AVAILABLE\n");
4848 printk(KERN_ERR
"%s", page
);
4849 free_page((unsigned long) page
);
4852 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
4853 struct dasd_ccw_req
*req
, struct irb
*irb
)
4855 u8
*sense
= dasd_get_sense(irb
);
4857 if (scsw_is_tm(&irb
->scsw
)) {
4859 * In some cases the 'File Protected' or 'Incorrect Length'
4860 * error might be expected and log messages shouldn't be written
4861 * then. Check if the according suppress bit is set.
4863 if (sense
&& (sense
[1] & SNS1_FILE_PROTECTED
) &&
4864 test_bit(DASD_CQR_SUPPRESS_FP
, &req
->flags
))
4866 if (scsw_cstat(&irb
->scsw
) == 0x40 &&
4867 test_bit(DASD_CQR_SUPPRESS_IL
, &req
->flags
))
4870 dasd_eckd_dump_sense_tcw(device
, req
, irb
);
4873 * In some cases the 'Command Reject' or 'No Record Found'
4874 * error might be expected and log messages shouldn't be
4875 * written then. Check if the according suppress bit is set.
4877 if (sense
&& sense
[0] & SNS0_CMD_REJECT
&&
4878 test_bit(DASD_CQR_SUPPRESS_CR
, &req
->flags
))
4881 if (sense
&& sense
[1] & SNS1_NO_REC_FOUND
&&
4882 test_bit(DASD_CQR_SUPPRESS_NRF
, &req
->flags
))
4885 dasd_eckd_dump_sense_ccw(device
, req
, irb
);
4889 static int dasd_eckd_pm_freeze(struct dasd_device
*device
)
4892 * the device should be disconnected from our LCU structure
4893 * on restore we will reconnect it and reread LCU specific
4894 * information like PAV support that might have changed
4896 dasd_alias_remove_device(device
);
4897 dasd_alias_disconnect_device_from_lcu(device
);
4902 static int dasd_eckd_restore_device(struct dasd_device
*device
)
4904 struct dasd_eckd_private
*private = device
->private;
4905 struct dasd_eckd_characteristics temp_rdc_data
;
4907 struct dasd_uid temp_uid
;
4908 unsigned long flags
;
4909 unsigned long cqr_flags
= 0;
4911 /* Read Configuration Data */
4912 rc
= dasd_eckd_read_conf(device
);
4914 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4915 "Read configuration data failed, rc=%d", rc
);
4919 dasd_eckd_get_uid(device
, &temp_uid
);
4920 /* Generate device unique id */
4921 rc
= dasd_eckd_generate_uid(device
);
4922 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4923 if (memcmp(&private->uid
, &temp_uid
, sizeof(struct dasd_uid
)) != 0)
4924 dev_err(&device
->cdev
->dev
, "The UID of the DASD has "
4926 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4930 /* register lcu with alias handling, enable PAV if this is a new lcu */
4931 rc
= dasd_alias_make_device_known_to_lcu(device
);
4935 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr_flags
);
4936 dasd_eckd_validate_server(device
, cqr_flags
);
4938 /* RE-Read Configuration Data */
4939 rc
= dasd_eckd_read_conf(device
);
4941 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4942 "Read configuration data failed, rc=%d", rc
);
4946 /* Read Feature Codes */
4947 dasd_eckd_read_features(device
);
4949 /* Read Device Characteristics */
4950 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
4951 &temp_rdc_data
, 64);
4953 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4954 "Read device characteristic failed, rc=%d", rc
);
4957 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4958 memcpy(&private->rdc_data
, &temp_rdc_data
, sizeof(temp_rdc_data
));
4959 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4961 /* add device to alias management */
4962 dasd_alias_add_device(device
);
4967 dasd_alias_disconnect_device_from_lcu(device
);
4972 static int dasd_eckd_reload_device(struct dasd_device
*device
)
4974 struct dasd_eckd_private
*private = device
->private;
4977 struct dasd_uid uid
;
4978 unsigned long flags
;
4981 * remove device from alias handling to prevent new requests
4982 * from being scheduled on the wrong alias device
4984 dasd_alias_remove_device(device
);
4986 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4987 old_base
= private->uid
.base_unit_addr
;
4988 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4990 /* Read Configuration Data */
4991 rc
= dasd_eckd_read_conf(device
);
4995 rc
= dasd_eckd_generate_uid(device
);
4999 * update unit address configuration and
5000 * add device to alias management
5002 dasd_alias_update_add_device(device
);
5004 dasd_eckd_get_uid(device
, &uid
);
5006 if (old_base
!= uid
.base_unit_addr
) {
5007 if (strlen(uid
.vduit
) > 0)
5008 snprintf(print_uid
, sizeof(print_uid
),
5009 "%s.%s.%04x.%02x.%s", uid
.vendor
, uid
.serial
,
5010 uid
.ssid
, uid
.base_unit_addr
, uid
.vduit
);
5012 snprintf(print_uid
, sizeof(print_uid
),
5013 "%s.%s.%04x.%02x", uid
.vendor
, uid
.serial
,
5014 uid
.ssid
, uid
.base_unit_addr
);
5016 dev_info(&device
->cdev
->dev
,
5017 "An Alias device was reassigned to a new base device "
5018 "with UID: %s\n", print_uid
);
5026 static int dasd_eckd_read_message_buffer(struct dasd_device
*device
,
5027 struct dasd_rssd_messages
*messages
,
5030 struct dasd_rssd_messages
*message_buf
;
5031 struct dasd_psf_prssd_data
*prssdp
;
5032 struct dasd_ccw_req
*cqr
;
5036 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
5037 (sizeof(struct dasd_psf_prssd_data
) +
5038 sizeof(struct dasd_rssd_messages
)),
5041 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
5042 "Could not allocate read message buffer request");
5043 return PTR_ERR(cqr
);
5048 cqr
->startdev
= device
;
5049 cqr
->memdev
= device
;
5051 cqr
->expires
= 10 * HZ
;
5052 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
5053 /* dasd_sleep_on_immediatly does not do complex error
5054 * recovery so clear erp flag and set retry counter to
5056 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
5059 /* Prepare for Read Subsystem Data */
5060 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
5061 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
5062 prssdp
->order
= PSF_ORDER_PRSSD
;
5063 prssdp
->suborder
= 0x03; /* Message Buffer */
5064 /* all other bytes of prssdp must be zero */
5067 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
5068 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
5069 ccw
->flags
|= CCW_FLAG_CC
;
5070 ccw
->flags
|= CCW_FLAG_SLI
;
5071 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
5073 /* Read Subsystem Data - message buffer */
5074 message_buf
= (struct dasd_rssd_messages
*) (prssdp
+ 1);
5075 memset(message_buf
, 0, sizeof(struct dasd_rssd_messages
));
5078 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
5079 ccw
->count
= sizeof(struct dasd_rssd_messages
);
5080 ccw
->flags
|= CCW_FLAG_SLI
;
5081 ccw
->cda
= (__u32
)(addr_t
) message_buf
;
5083 cqr
->buildclk
= get_tod_clock();
5084 cqr
->status
= DASD_CQR_FILLED
;
5085 rc
= dasd_sleep_on_immediatly(cqr
);
5087 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
5088 message_buf
= (struct dasd_rssd_messages
*)
5090 memcpy(messages
, message_buf
,
5091 sizeof(struct dasd_rssd_messages
));
5092 } else if (cqr
->lpm
) {
5094 * on z/VM we might not be able to do I/O on the requested path
5095 * but instead we get the required information on any path
5096 * so retry with open path mask
5101 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
5102 "Reading messages failed with rc=%d\n"
5104 dasd_sfree_request(cqr
, cqr
->memdev
);
5108 static int dasd_eckd_query_host_access(struct dasd_device
*device
,
5109 struct dasd_psf_query_host_access
*data
)
5111 struct dasd_eckd_private
*private = device
->private;
5112 struct dasd_psf_query_host_access
*host_access
;
5113 struct dasd_psf_prssd_data
*prssdp
;
5114 struct dasd_ccw_req
*cqr
;
5118 /* not available for HYPER PAV alias devices */
5119 if (!device
->block
&& private->lcu
->pav
== HYPER_PAV
)
5122 /* may not be supported by the storage server */
5123 if (!(private->features
.feature
[14] & 0x80))
5126 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
5127 sizeof(struct dasd_psf_prssd_data
) + 1,
5130 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
5131 "Could not allocate read message buffer request");
5132 return PTR_ERR(cqr
);
5134 host_access
= kzalloc(sizeof(*host_access
), GFP_KERNEL
| GFP_DMA
);
5136 dasd_sfree_request(cqr
, device
);
5137 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
5138 "Could not allocate host_access buffer");
5141 cqr
->startdev
= device
;
5142 cqr
->memdev
= device
;
5145 cqr
->expires
= 10 * HZ
;
5147 /* Prepare for Read Subsystem Data */
5148 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
5149 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
5150 prssdp
->order
= PSF_ORDER_PRSSD
;
5151 prssdp
->suborder
= PSF_SUBORDER_QHA
; /* query host access */
5152 /* LSS and Volume that will be queried */
5153 prssdp
->lss
= private->ned
->ID
;
5154 prssdp
->volume
= private->ned
->unit_addr
;
5155 /* all other bytes of prssdp must be zero */
5158 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
5159 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
5160 ccw
->flags
|= CCW_FLAG_CC
;
5161 ccw
->flags
|= CCW_FLAG_SLI
;
5162 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
5164 /* Read Subsystem Data - query host access */
5166 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
5167 ccw
->count
= sizeof(struct dasd_psf_query_host_access
);
5168 ccw
->flags
|= CCW_FLAG_SLI
;
5169 ccw
->cda
= (__u32
)(addr_t
) host_access
;
5171 cqr
->buildclk
= get_tod_clock();
5172 cqr
->status
= DASD_CQR_FILLED
;
5173 /* the command might not be supported, suppress error message */
5174 __set_bit(DASD_CQR_SUPPRESS_CR
, &cqr
->flags
);
5175 rc
= dasd_sleep_on_interruptible(cqr
);
5177 *data
= *host_access
;
5179 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
5180 "Reading host access data failed with rc=%d\n",
5185 dasd_sfree_request(cqr
, cqr
->memdev
);
5190 * return number of grouped devices
5192 static int dasd_eckd_host_access_count(struct dasd_device
*device
)
5194 struct dasd_psf_query_host_access
*access
;
5195 struct dasd_ckd_path_group_entry
*entry
;
5196 struct dasd_ckd_host_information
*info
;
5200 access
= kzalloc(sizeof(*access
), GFP_NOIO
);
5202 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
5203 "Could not allocate access buffer");
5206 rc
= dasd_eckd_query_host_access(device
, access
);
5212 info
= (struct dasd_ckd_host_information
*)
5213 access
->host_access_information
;
5214 for (i
= 0; i
< info
->entry_count
; i
++) {
5215 entry
= (struct dasd_ckd_path_group_entry
*)
5216 (info
->entry
+ i
* info
->entry_size
);
5217 if (entry
->status_flags
& DASD_ECKD_PG_GROUPED
)
5226 * write host access information to a sequential file
5228 static int dasd_hosts_print(struct dasd_device
*device
, struct seq_file
*m
)
5230 struct dasd_psf_query_host_access
*access
;
5231 struct dasd_ckd_path_group_entry
*entry
;
5232 struct dasd_ckd_host_information
*info
;
5233 char sysplex
[9] = "";
5236 access
= kzalloc(sizeof(*access
), GFP_NOIO
);
5238 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
5239 "Could not allocate access buffer");
5242 rc
= dasd_eckd_query_host_access(device
, access
);
5248 info
= (struct dasd_ckd_host_information
*)
5249 access
->host_access_information
;
5250 for (i
= 0; i
< info
->entry_count
; i
++) {
5251 entry
= (struct dasd_ckd_path_group_entry
*)
5252 (info
->entry
+ i
* info
->entry_size
);
5254 seq_printf(m
, "pgid %*phN\n", 11, entry
->pgid
);
5256 seq_printf(m
, "status_flags %02x\n", entry
->status_flags
);
5258 memcpy(&sysplex
, &entry
->sysplex_name
, sizeof(sysplex
) - 1);
5259 EBCASC(sysplex
, sizeof(sysplex
));
5260 seq_printf(m
, "sysplex_name %8s\n", sysplex
);
5261 /* SUPPORTED CYLINDER */
5262 seq_printf(m
, "supported_cylinder %d\n", entry
->cylinder
);
5264 seq_printf(m
, "timestamp %lu\n", (unsigned long)
5273 * Perform Subsystem Function - CUIR response
5276 dasd_eckd_psf_cuir_response(struct dasd_device
*device
, int response
,
5277 __u32 message_id
, __u8 lpum
)
5279 struct dasd_psf_cuir_response
*psf_cuir
;
5280 int pos
= pathmask_to_pos(lpum
);
5281 struct dasd_ccw_req
*cqr
;
5285 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
5286 sizeof(struct dasd_psf_cuir_response
),
5290 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
5291 "Could not allocate PSF-CUIR request");
5292 return PTR_ERR(cqr
);
5295 psf_cuir
= (struct dasd_psf_cuir_response
*)cqr
->data
;
5296 psf_cuir
->order
= PSF_ORDER_CUIR_RESPONSE
;
5297 psf_cuir
->cc
= response
;
5298 psf_cuir
->chpid
= device
->path
[pos
].chpid
;
5299 psf_cuir
->message_id
= message_id
;
5300 psf_cuir
->cssid
= device
->path
[pos
].cssid
;
5301 psf_cuir
->ssid
= device
->path
[pos
].ssid
;
5303 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
5304 ccw
->cda
= (__u32
)(addr_t
)psf_cuir
;
5305 ccw
->flags
= CCW_FLAG_SLI
;
5306 ccw
->count
= sizeof(struct dasd_psf_cuir_response
);
5308 cqr
->startdev
= device
;
5309 cqr
->memdev
= device
;
5312 cqr
->expires
= 10*HZ
;
5313 cqr
->buildclk
= get_tod_clock();
5314 cqr
->status
= DASD_CQR_FILLED
;
5315 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
5317 rc
= dasd_sleep_on(cqr
);
5319 dasd_sfree_request(cqr
, cqr
->memdev
);
5324 * return configuration data that is referenced by record selector
5325 * if a record selector is specified or per default return the
5326 * conf_data pointer for the path specified by lpum
5328 static struct dasd_conf_data
*dasd_eckd_get_ref_conf(struct dasd_device
*device
,
5330 struct dasd_cuir_message
*cuir
)
5332 struct dasd_conf_data
*conf_data
;
5335 if (cuir
->record_selector
== 0)
5337 for (path
= 0x80, pos
= 0; path
; path
>>= 1, pos
++) {
5338 conf_data
= device
->path
[pos
].conf_data
;
5339 if (conf_data
->gneq
.record_selector
==
5340 cuir
->record_selector
)
5344 return device
->path
[pathmask_to_pos(lpum
)].conf_data
;
5348 * This function determines the scope of a reconfiguration request by
5349 * analysing the path and device selection data provided in the CUIR request.
5350 * Returns a path mask containing CUIR affected paths for the give device.
5352 * If the CUIR request does not contain the required information return the
5353 * path mask of the path the attention message for the CUIR request was reveived
5356 static int dasd_eckd_cuir_scope(struct dasd_device
*device
, __u8 lpum
,
5357 struct dasd_cuir_message
*cuir
)
5359 struct dasd_conf_data
*ref_conf_data
;
5360 unsigned long bitmask
= 0, mask
= 0;
5361 struct dasd_conf_data
*conf_data
;
5362 unsigned int pos
, path
;
5363 char *ref_gneq
, *gneq
;
5364 char *ref_ned
, *ned
;
5367 /* if CUIR request does not specify the scope use the path
5368 the attention message was presented on */
5369 if (!cuir
->ned_map
||
5370 !(cuir
->neq_map
[0] | cuir
->neq_map
[1] | cuir
->neq_map
[2]))
5373 /* get reference conf data */
5374 ref_conf_data
= dasd_eckd_get_ref_conf(device
, lpum
, cuir
);
5375 /* reference ned is determined by ned_map field */
5376 pos
= 8 - ffs(cuir
->ned_map
);
5377 ref_ned
= (char *)&ref_conf_data
->neds
[pos
];
5378 ref_gneq
= (char *)&ref_conf_data
->gneq
;
5379 /* transfer 24 bit neq_map to mask */
5380 mask
= cuir
->neq_map
[2];
5381 mask
|= cuir
->neq_map
[1] << 8;
5382 mask
|= cuir
->neq_map
[0] << 16;
5384 for (path
= 0; path
< 8; path
++) {
5385 /* initialise data per path */
5387 conf_data
= device
->path
[path
].conf_data
;
5388 pos
= 8 - ffs(cuir
->ned_map
);
5389 ned
= (char *) &conf_data
->neds
[pos
];
5390 /* compare reference ned and per path ned */
5391 if (memcmp(ref_ned
, ned
, sizeof(*ned
)) != 0)
5393 gneq
= (char *)&conf_data
->gneq
;
5394 /* compare reference gneq and per_path gneq under
5395 24 bit mask where mask bit 0 equals byte 7 of
5396 the gneq and mask bit 24 equals byte 31 */
5398 pos
= ffs(bitmask
) - 1;
5399 if (memcmp(&ref_gneq
[31 - pos
], &gneq
[31 - pos
], 1)
5402 clear_bit(pos
, &bitmask
);
5406 /* device and path match the reference values
5407 add path to CUIR scope */
5408 tbcpm
|= 0x80 >> path
;
5413 static void dasd_eckd_cuir_notify_user(struct dasd_device
*device
,
5414 unsigned long paths
, int action
)
5419 /* get position of bit in mask */
5420 pos
= 8 - ffs(paths
);
5421 /* get channel path descriptor from this position */
5422 if (action
== CUIR_QUIESCE
)
5423 pr_warn("Service on the storage server caused path %x.%02x to go offline",
5424 device
->path
[pos
].cssid
,
5425 device
->path
[pos
].chpid
);
5426 else if (action
== CUIR_RESUME
)
5427 pr_info("Path %x.%02x is back online after service on the storage server",
5428 device
->path
[pos
].cssid
,
5429 device
->path
[pos
].chpid
);
5430 clear_bit(7 - pos
, &paths
);
5434 static int dasd_eckd_cuir_remove_path(struct dasd_device
*device
, __u8 lpum
,
5435 struct dasd_cuir_message
*cuir
)
5437 unsigned long tbcpm
;
5439 tbcpm
= dasd_eckd_cuir_scope(device
, lpum
, cuir
);
5440 /* nothing to do if path is not in use */
5441 if (!(dasd_path_get_opm(device
) & tbcpm
))
5443 if (!(dasd_path_get_opm(device
) & ~tbcpm
)) {
5444 /* no path would be left if the CUIR action is taken
5448 /* remove device from operational path mask */
5449 dasd_path_remove_opm(device
, tbcpm
);
5450 dasd_path_add_cuirpm(device
, tbcpm
);
5455 * walk through all devices and build a path mask to quiesce them
5456 * return an error if the last path to a device would be removed
5458 * if only part of the devices are quiesced and an error
5459 * occurs no onlining necessary, the storage server will
5460 * notify the already set offline devices again
5462 static int dasd_eckd_cuir_quiesce(struct dasd_device
*device
, __u8 lpum
,
5463 struct dasd_cuir_message
*cuir
)
5465 struct dasd_eckd_private
*private = device
->private;
5466 struct alias_pav_group
*pavgroup
, *tempgroup
;
5467 struct dasd_device
*dev
, *n
;
5468 unsigned long paths
= 0;
5469 unsigned long flags
;
5472 /* active devices */
5473 list_for_each_entry_safe(dev
, n
, &private->lcu
->active_devices
,
5475 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
5476 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
5477 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
5482 /* inactive devices */
5483 list_for_each_entry_safe(dev
, n
, &private->lcu
->inactive_devices
,
5485 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
5486 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
5487 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
5492 /* devices in PAV groups */
5493 list_for_each_entry_safe(pavgroup
, tempgroup
,
5494 &private->lcu
->grouplist
, group
) {
5495 list_for_each_entry_safe(dev
, n
, &pavgroup
->baselist
,
5497 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
5498 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
5499 spin_unlock_irqrestore(
5500 get_ccwdev_lock(dev
->cdev
), flags
);
5505 list_for_each_entry_safe(dev
, n
, &pavgroup
->aliaslist
,
5507 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
5508 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
5509 spin_unlock_irqrestore(
5510 get_ccwdev_lock(dev
->cdev
), flags
);
5516 /* notify user about all paths affected by CUIR action */
5517 dasd_eckd_cuir_notify_user(device
, paths
, CUIR_QUIESCE
);
5523 static int dasd_eckd_cuir_resume(struct dasd_device
*device
, __u8 lpum
,
5524 struct dasd_cuir_message
*cuir
)
5526 struct dasd_eckd_private
*private = device
->private;
5527 struct alias_pav_group
*pavgroup
, *tempgroup
;
5528 struct dasd_device
*dev
, *n
;
5529 unsigned long paths
= 0;
5533 * the path may have been added through a generic path event before
5534 * only trigger path verification if the path is not already in use
5536 list_for_each_entry_safe(dev
, n
,
5537 &private->lcu
->active_devices
,
5539 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
5541 if (!(dasd_path_get_opm(dev
) & tbcpm
)) {
5542 dasd_path_add_tbvpm(dev
, tbcpm
);
5543 dasd_schedule_device_bh(dev
);
5546 list_for_each_entry_safe(dev
, n
,
5547 &private->lcu
->inactive_devices
,
5549 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
5551 if (!(dasd_path_get_opm(dev
) & tbcpm
)) {
5552 dasd_path_add_tbvpm(dev
, tbcpm
);
5553 dasd_schedule_device_bh(dev
);
5556 /* devices in PAV groups */
5557 list_for_each_entry_safe(pavgroup
, tempgroup
,
5558 &private->lcu
->grouplist
,
5560 list_for_each_entry_safe(dev
, n
,
5561 &pavgroup
->baselist
,
5563 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
5565 if (!(dasd_path_get_opm(dev
) & tbcpm
)) {
5566 dasd_path_add_tbvpm(dev
, tbcpm
);
5567 dasd_schedule_device_bh(dev
);
5570 list_for_each_entry_safe(dev
, n
,
5571 &pavgroup
->aliaslist
,
5573 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
5575 if (!(dasd_path_get_opm(dev
) & tbcpm
)) {
5576 dasd_path_add_tbvpm(dev
, tbcpm
);
5577 dasd_schedule_device_bh(dev
);
5581 /* notify user about all paths affected by CUIR action */
5582 dasd_eckd_cuir_notify_user(device
, paths
, CUIR_RESUME
);
5586 static void dasd_eckd_handle_cuir(struct dasd_device
*device
, void *messages
,
5589 struct dasd_cuir_message
*cuir
= messages
;
5592 DBF_DEV_EVENT(DBF_WARNING
, device
,
5593 "CUIR request: %016llx %016llx %016llx %08x",
5594 ((u64
*)cuir
)[0], ((u64
*)cuir
)[1], ((u64
*)cuir
)[2],
5597 if (cuir
->code
== CUIR_QUIESCE
) {
5599 if (dasd_eckd_cuir_quiesce(device
, lpum
, cuir
))
5600 response
= PSF_CUIR_LAST_PATH
;
5602 response
= PSF_CUIR_COMPLETED
;
5603 } else if (cuir
->code
== CUIR_RESUME
) {
5605 dasd_eckd_cuir_resume(device
, lpum
, cuir
);
5606 response
= PSF_CUIR_COMPLETED
;
5608 response
= PSF_CUIR_NOT_SUPPORTED
;
5610 dasd_eckd_psf_cuir_response(device
, response
,
5611 cuir
->message_id
, lpum
);
5612 DBF_DEV_EVENT(DBF_WARNING
, device
,
5613 "CUIR response: %d on message ID %08x", response
,
5615 /* to make sure there is no attention left schedule work again */
5616 device
->discipline
->check_attention(device
, lpum
);
5619 static void dasd_eckd_check_attention_work(struct work_struct
*work
)
5621 struct check_attention_work_data
*data
;
5622 struct dasd_rssd_messages
*messages
;
5623 struct dasd_device
*device
;
5626 data
= container_of(work
, struct check_attention_work_data
, worker
);
5627 device
= data
->device
;
5628 messages
= kzalloc(sizeof(*messages
), GFP_KERNEL
);
5630 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
5631 "Could not allocate attention message buffer");
5634 rc
= dasd_eckd_read_message_buffer(device
, messages
, data
->lpum
);
5637 if (messages
->length
== ATTENTION_LENGTH_CUIR
&&
5638 messages
->format
== ATTENTION_FORMAT_CUIR
)
5639 dasd_eckd_handle_cuir(device
, messages
, data
->lpum
);
5641 dasd_put_device(device
);
5646 static int dasd_eckd_check_attention(struct dasd_device
*device
, __u8 lpum
)
5648 struct check_attention_work_data
*data
;
5650 data
= kzalloc(sizeof(*data
), GFP_ATOMIC
);
5653 INIT_WORK(&data
->worker
, dasd_eckd_check_attention_work
);
5654 dasd_get_device(device
);
5655 data
->device
= device
;
5657 schedule_work(&data
->worker
);
5661 static int dasd_eckd_disable_hpf_path(struct dasd_device
*device
, __u8 lpum
)
5663 if (~lpum
& dasd_path_get_opm(device
)) {
5664 dasd_path_add_nohpfpm(device
, lpum
);
5665 dasd_path_remove_opm(device
, lpum
);
5666 dev_err(&device
->cdev
->dev
,
5667 "Channel path %02X lost HPF functionality and is disabled\n",
5674 static void dasd_eckd_disable_hpf_device(struct dasd_device
*device
)
5676 struct dasd_eckd_private
*private = device
->private;
5678 dev_err(&device
->cdev
->dev
,
5679 "High Performance FICON disabled\n");
5680 private->fcx_max_data
= 0;
5683 static int dasd_eckd_hpf_enabled(struct dasd_device
*device
)
5685 struct dasd_eckd_private
*private = device
->private;
5687 return private->fcx_max_data
? 1 : 0;
5690 static void dasd_eckd_handle_hpf_error(struct dasd_device
*device
,
5693 struct dasd_eckd_private
*private = device
->private;
5695 if (!private->fcx_max_data
) {
5696 /* sanity check for no HPF, the error makes no sense */
5697 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
5698 "Trying to disable HPF for a non HPF device");
5701 if (irb
->scsw
.tm
.sesq
== SCSW_SESQ_DEV_NOFCX
) {
5702 dasd_eckd_disable_hpf_device(device
);
5703 } else if (irb
->scsw
.tm
.sesq
== SCSW_SESQ_PATH_NOFCX
) {
5704 if (dasd_eckd_disable_hpf_path(device
, irb
->esw
.esw1
.lpum
))
5706 dasd_eckd_disable_hpf_device(device
);
5707 dasd_path_set_tbvpm(device
,
5708 dasd_path_get_hpfpm(device
));
5711 * prevent that any new I/O ist started on the device and schedule a
5712 * requeue of existing requests
5714 dasd_device_set_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
5715 dasd_schedule_requeue(device
);
5718 static struct ccw_driver dasd_eckd_driver
= {
5720 .name
= "dasd-eckd",
5721 .owner
= THIS_MODULE
,
5723 .ids
= dasd_eckd_ids
,
5724 .probe
= dasd_eckd_probe
,
5725 .remove
= dasd_generic_remove
,
5726 .set_offline
= dasd_generic_set_offline
,
5727 .set_online
= dasd_eckd_set_online
,
5728 .notify
= dasd_generic_notify
,
5729 .path_event
= dasd_generic_path_event
,
5730 .shutdown
= dasd_generic_shutdown
,
5731 .freeze
= dasd_generic_pm_freeze
,
5732 .thaw
= dasd_generic_restore_device
,
5733 .restore
= dasd_generic_restore_device
,
5734 .uc_handler
= dasd_generic_uc_handler
,
5735 .int_class
= IRQIO_DAS
,
5739 * max_blocks is dependent on the amount of storage that is available
5740 * in the static io buffer for each device. Currently each device has
5741 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5742 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5743 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5744 * addition we have one define extent ccw + 16 bytes of data and one
5745 * locate record ccw + 16 bytes of data. That makes:
5746 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5747 * We want to fit two into the available memory so that we can immediately
5748 * start the next request if one finishes off. That makes 249.5 blocks
5749 * for one request. Give a little safety and the result is 240.
5751 static struct dasd_discipline dasd_eckd_discipline
= {
5752 .owner
= THIS_MODULE
,
5756 .check_device
= dasd_eckd_check_characteristics
,
5757 .uncheck_device
= dasd_eckd_uncheck_device
,
5758 .do_analysis
= dasd_eckd_do_analysis
,
5759 .verify_path
= dasd_eckd_verify_path
,
5760 .basic_to_ready
= dasd_eckd_basic_to_ready
,
5761 .online_to_ready
= dasd_eckd_online_to_ready
,
5762 .basic_to_known
= dasd_eckd_basic_to_known
,
5763 .fill_geometry
= dasd_eckd_fill_geometry
,
5764 .start_IO
= dasd_start_IO
,
5765 .term_IO
= dasd_term_IO
,
5766 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
5767 .format_device
= dasd_eckd_format_device
,
5768 .check_device_format
= dasd_eckd_check_device_format
,
5769 .erp_action
= dasd_eckd_erp_action
,
5770 .erp_postaction
= dasd_eckd_erp_postaction
,
5771 .check_for_device_change
= dasd_eckd_check_for_device_change
,
5772 .build_cp
= dasd_eckd_build_alias_cp
,
5773 .free_cp
= dasd_eckd_free_alias_cp
,
5774 .dump_sense
= dasd_eckd_dump_sense
,
5775 .dump_sense_dbf
= dasd_eckd_dump_sense_dbf
,
5776 .fill_info
= dasd_eckd_fill_info
,
5777 .ioctl
= dasd_eckd_ioctl
,
5778 .freeze
= dasd_eckd_pm_freeze
,
5779 .restore
= dasd_eckd_restore_device
,
5780 .reload
= dasd_eckd_reload_device
,
5781 .get_uid
= dasd_eckd_get_uid
,
5782 .kick_validate
= dasd_eckd_kick_validate_server
,
5783 .check_attention
= dasd_eckd_check_attention
,
5784 .host_access_count
= dasd_eckd_host_access_count
,
5785 .hosts_print
= dasd_hosts_print
,
5786 .handle_hpf_error
= dasd_eckd_handle_hpf_error
,
5787 .disable_hpf
= dasd_eckd_disable_hpf_device
,
5788 .hpf_enabled
= dasd_eckd_hpf_enabled
,
5789 .reset_path
= dasd_eckd_reset_path
,
5793 dasd_eckd_init(void)
5797 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
5798 dasd_reserve_req
= kmalloc(sizeof(*dasd_reserve_req
),
5799 GFP_KERNEL
| GFP_DMA
);
5800 if (!dasd_reserve_req
)
5802 path_verification_worker
= kmalloc(sizeof(*path_verification_worker
),
5803 GFP_KERNEL
| GFP_DMA
);
5804 if (!path_verification_worker
) {
5805 kfree(dasd_reserve_req
);
5808 rawpadpage
= (void *)__get_free_page(GFP_KERNEL
);
5810 kfree(path_verification_worker
);
5811 kfree(dasd_reserve_req
);
5814 ret
= ccw_driver_register(&dasd_eckd_driver
);
5816 wait_for_device_probe();
5818 kfree(path_verification_worker
);
5819 kfree(dasd_reserve_req
);
5820 free_page((unsigned long)rawpadpage
);
5826 dasd_eckd_cleanup(void)
5828 ccw_driver_unregister(&dasd_eckd_driver
);
5829 kfree(path_verification_worker
);
5830 kfree(dasd_reserve_req
);
5831 free_page((unsigned long)rawpadpage
);
5834 module_init(dasd_eckd_init
);
5835 module_exit(dasd_eckd_cleanup
);