2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2009
8 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
9 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
12 #define KMSG_COMPONENT "dasd-eckd"
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/hdreg.h> /* HDIO_GETGEO */
18 #include <linux/bio.h>
19 #include <linux/module.h>
20 #include <linux/compat.h>
21 #include <linux/init.h>
23 #include <asm/css_chars.h>
24 #include <asm/debug.h>
25 #include <asm/idals.h>
26 #include <asm/ebcdic.h>
28 #include <asm/uaccess.h>
30 #include <asm/ccwdev.h>
32 #include <asm/schid.h>
33 #include <asm/chpid.h>
36 #include "dasd_eckd.h"
40 #endif /* PRINTK_HEADER */
41 #define PRINTK_HEADER "dasd(eckd):"
43 #define ECKD_C0(i) (i->home_bytes)
44 #define ECKD_F(i) (i->formula)
45 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
46 (i->factors.f_0x02.f1))
47 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
48 (i->factors.f_0x02.f2))
49 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
50 (i->factors.f_0x02.f3))
51 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
52 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
53 #define ECKD_F6(i) (i->factor6)
54 #define ECKD_F7(i) (i->factor7)
55 #define ECKD_F8(i) (i->factor8)
58 * raw track access always map to 64k in memory
59 * so it maps to 16 blocks of 4k per track
61 #define DASD_RAW_BLOCK_PER_TRACK 16
62 #define DASD_RAW_BLOCKSIZE 4096
63 /* 64k are 128 x 512 byte sectors */
64 #define DASD_RAW_SECTORS_PER_TRACK 128
66 MODULE_LICENSE("GPL");
68 static struct dasd_discipline dasd_eckd_discipline
;
70 /* The ccw bus type uses this table to find devices that it sends to
72 static struct ccw_device_id dasd_eckd_ids
[] = {
73 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info
= 0x1},
74 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info
= 0x2},
75 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info
= 0x3},
76 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info
= 0x4},
77 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info
= 0x5},
78 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info
= 0x6},
79 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info
= 0x7},
80 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info
= 0x8},
81 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info
= 0x9},
82 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info
= 0xa},
83 { /* end of list */ },
86 MODULE_DEVICE_TABLE(ccw
, dasd_eckd_ids
);
88 static struct ccw_driver dasd_eckd_driver
; /* see below */
90 static void *rawpadpage
;
93 #define INIT_CQR_UNFORMATTED 1
94 #define INIT_CQR_ERROR 2
96 /* emergency request for reserve/release */
98 struct dasd_ccw_req cqr
;
102 static DEFINE_MUTEX(dasd_reserve_mutex
);
104 /* definitions for the path verification worker */
105 struct path_verification_work_data
{
106 struct work_struct worker
;
107 struct dasd_device
*device
;
108 struct dasd_ccw_req cqr
;
110 __u8 rcd_buffer
[DASD_ECKD_RCD_DATA_SIZE
];
114 static struct path_verification_work_data
*path_verification_worker
;
115 static DEFINE_MUTEX(dasd_path_verification_mutex
);
117 struct check_attention_work_data
{
118 struct work_struct worker
;
119 struct dasd_device
*device
;
123 /* initial attempt at a probe function. this can be simplified once
124 * the other detection code is gone */
126 dasd_eckd_probe (struct ccw_device
*cdev
)
130 /* set ECKD specific ccw-device options */
131 ret
= ccw_device_set_options(cdev
, CCWDEV_ALLOW_FORCE
|
132 CCWDEV_DO_PATHGROUP
| CCWDEV_DO_MULTIPATH
);
134 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
135 "dasd_eckd_probe: could not set "
136 "ccw-device options");
139 ret
= dasd_generic_probe(cdev
, &dasd_eckd_discipline
);
144 dasd_eckd_set_online(struct ccw_device
*cdev
)
146 return dasd_generic_set_online(cdev
, &dasd_eckd_discipline
);
149 static const int sizes_trk0
[] = { 28, 148, 84 };
150 #define LABEL_SIZE 140
152 /* head and record addresses of count_area read in analysis ccw */
153 static const int count_area_head
[] = { 0, 0, 0, 0, 2 };
154 static const int count_area_rec
[] = { 1, 2, 3, 4, 1 };
156 static inline unsigned int
157 round_up_multiple(unsigned int no
, unsigned int mult
)
160 return (rem
? no
- rem
+ mult
: no
);
163 static inline unsigned int
164 ceil_quot(unsigned int d1
, unsigned int d2
)
166 return (d1
+ (d2
- 1)) / d2
;
170 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
171 unsigned int kl
, unsigned int dl
)
175 switch (rdc
->dev_type
) {
178 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
179 ceil_quot(dl
+ 12, 32));
181 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
183 dn
= ceil_quot(dl
+ 6, 232) + 1;
185 kn
= ceil_quot(kl
+ 6, 232) + 1;
186 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
187 9 + ceil_quot(dl
+ 6 * dn
, 34));
189 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
191 dn
= ceil_quot(dl
+ 6, 232) + 1;
193 kn
= ceil_quot(kl
+ 6, 232) + 1;
194 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
195 ceil_quot(dl
+ 6 * dn
, 34));
197 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
202 static void set_ch_t(struct ch_t
*geo
, __u32 cyl
, __u8 head
)
204 geo
->cyl
= (__u16
) cyl
;
205 geo
->head
= cyl
>> 16;
211 check_XRC (struct ccw1
*de_ccw
,
212 struct DE_eckd_data
*data
,
213 struct dasd_device
*device
)
215 struct dasd_eckd_private
*private;
218 private = (struct dasd_eckd_private
*) device
->private;
219 if (!private->rdc_data
.facilities
.XRC_supported
)
222 /* switch on System Time Stamp - needed for XRC Support */
223 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
224 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
226 rc
= get_sync_clock(&data
->ep_sys_time
);
227 /* Ignore return code if sync clock is switched off. */
228 if (rc
== -EOPNOTSUPP
|| rc
== -EACCES
)
231 de_ccw
->count
= sizeof(struct DE_eckd_data
);
232 de_ccw
->flags
|= CCW_FLAG_SLI
;
237 define_extent(struct ccw1
*ccw
, struct DE_eckd_data
*data
, unsigned int trk
,
238 unsigned int totrk
, int cmd
, struct dasd_device
*device
)
240 struct dasd_eckd_private
*private;
242 u16 heads
, beghead
, endhead
;
245 private = (struct dasd_eckd_private
*) device
->private;
247 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
250 ccw
->cda
= (__u32
) __pa(data
);
252 memset(data
, 0, sizeof(struct DE_eckd_data
));
254 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
255 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
256 case DASD_ECKD_CCW_READ
:
257 case DASD_ECKD_CCW_READ_MT
:
258 case DASD_ECKD_CCW_READ_CKD
:
259 case DASD_ECKD_CCW_READ_CKD_MT
:
260 case DASD_ECKD_CCW_READ_KD
:
261 case DASD_ECKD_CCW_READ_KD_MT
:
262 case DASD_ECKD_CCW_READ_COUNT
:
263 data
->mask
.perm
= 0x1;
264 data
->attributes
.operation
= private->attrib
.operation
;
266 case DASD_ECKD_CCW_WRITE
:
267 case DASD_ECKD_CCW_WRITE_MT
:
268 case DASD_ECKD_CCW_WRITE_KD
:
269 case DASD_ECKD_CCW_WRITE_KD_MT
:
270 data
->mask
.perm
= 0x02;
271 data
->attributes
.operation
= private->attrib
.operation
;
272 rc
= check_XRC (ccw
, data
, device
);
274 case DASD_ECKD_CCW_WRITE_CKD
:
275 case DASD_ECKD_CCW_WRITE_CKD_MT
:
276 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
277 rc
= check_XRC (ccw
, data
, device
);
279 case DASD_ECKD_CCW_ERASE
:
280 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
281 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
282 data
->mask
.perm
= 0x3;
283 data
->mask
.auth
= 0x1;
284 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
285 rc
= check_XRC (ccw
, data
, device
);
288 dev_err(&device
->cdev
->dev
,
289 "0x%x is not a known command\n", cmd
);
293 data
->attributes
.mode
= 0x3; /* ECKD */
295 if ((private->rdc_data
.cu_type
== 0x2105 ||
296 private->rdc_data
.cu_type
== 0x2107 ||
297 private->rdc_data
.cu_type
== 0x1750)
298 && !(private->uses_cdl
&& trk
< 2))
299 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
301 heads
= private->rdc_data
.trk_per_cyl
;
302 begcyl
= trk
/ heads
;
303 beghead
= trk
% heads
;
304 endcyl
= totrk
/ heads
;
305 endhead
= totrk
% heads
;
307 /* check for sequential prestage - enhance cylinder range */
308 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
309 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
311 if (endcyl
+ private->attrib
.nr_cyl
< private->real_cyl
)
312 endcyl
+= private->attrib
.nr_cyl
;
314 endcyl
= (private->real_cyl
- 1);
317 set_ch_t(&data
->beg_ext
, begcyl
, beghead
);
318 set_ch_t(&data
->end_ext
, endcyl
, endhead
);
322 static int check_XRC_on_prefix(struct PFX_eckd_data
*pfxdata
,
323 struct dasd_device
*device
)
325 struct dasd_eckd_private
*private;
328 private = (struct dasd_eckd_private
*) device
->private;
329 if (!private->rdc_data
.facilities
.XRC_supported
)
332 /* switch on System Time Stamp - needed for XRC Support */
333 pfxdata
->define_extent
.ga_extended
|= 0x08; /* 'Time Stamp Valid' */
334 pfxdata
->define_extent
.ga_extended
|= 0x02; /* 'Extended Parameter' */
335 pfxdata
->validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
337 rc
= get_sync_clock(&pfxdata
->define_extent
.ep_sys_time
);
338 /* Ignore return code if sync clock is switched off. */
339 if (rc
== -EOPNOTSUPP
|| rc
== -EACCES
)
344 static void fill_LRE_data(struct LRE_eckd_data
*data
, unsigned int trk
,
345 unsigned int rec_on_trk
, int count
, int cmd
,
346 struct dasd_device
*device
, unsigned int reclen
,
349 struct dasd_eckd_private
*private;
353 private = (struct dasd_eckd_private
*) device
->private;
355 memset(data
, 0, sizeof(*data
));
358 switch (private->rdc_data
.dev_type
) {
360 dn
= ceil_quot(reclen
+ 6, 232);
361 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
362 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
365 d
= 7 + ceil_quot(reclen
+ 12, 32);
366 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
370 data
->sector
= sector
;
371 /* note: meaning of count depends on the operation
372 * for record based I/O it's the number of records, but for
373 * track based I/O it's the number of tracks
377 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
378 data
->operation
.orientation
= 0x3;
379 data
->operation
.operation
= 0x03;
381 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
382 data
->operation
.orientation
= 0x3;
383 data
->operation
.operation
= 0x16;
385 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
386 data
->operation
.orientation
= 0x1;
387 data
->operation
.operation
= 0x03;
390 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
391 data
->operation
.orientation
= 0x3;
392 data
->operation
.operation
= 0x16;
395 case DASD_ECKD_CCW_WRITE
:
396 case DASD_ECKD_CCW_WRITE_MT
:
397 case DASD_ECKD_CCW_WRITE_KD
:
398 case DASD_ECKD_CCW_WRITE_KD_MT
:
399 data
->auxiliary
.length_valid
= 0x1;
400 data
->length
= reclen
;
401 data
->operation
.operation
= 0x01;
403 case DASD_ECKD_CCW_WRITE_CKD
:
404 case DASD_ECKD_CCW_WRITE_CKD_MT
:
405 data
->auxiliary
.length_valid
= 0x1;
406 data
->length
= reclen
;
407 data
->operation
.operation
= 0x03;
409 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
410 data
->operation
.orientation
= 0x0;
411 data
->operation
.operation
= 0x3F;
412 data
->extended_operation
= 0x11;
414 data
->extended_parameter_length
= 0x02;
415 if (data
->count
> 8) {
416 data
->extended_parameter
[0] = 0xFF;
417 data
->extended_parameter
[1] = 0xFF;
418 data
->extended_parameter
[1] <<= (16 - count
);
420 data
->extended_parameter
[0] = 0xFF;
421 data
->extended_parameter
[0] <<= (8 - count
);
422 data
->extended_parameter
[1] = 0x00;
426 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
427 data
->auxiliary
.length_valid
= 0x1;
428 data
->length
= reclen
; /* not tlf, as one might think */
429 data
->operation
.operation
= 0x3F;
430 data
->extended_operation
= 0x23;
432 case DASD_ECKD_CCW_READ
:
433 case DASD_ECKD_CCW_READ_MT
:
434 case DASD_ECKD_CCW_READ_KD
:
435 case DASD_ECKD_CCW_READ_KD_MT
:
436 data
->auxiliary
.length_valid
= 0x1;
437 data
->length
= reclen
;
438 data
->operation
.operation
= 0x06;
440 case DASD_ECKD_CCW_READ_CKD
:
441 case DASD_ECKD_CCW_READ_CKD_MT
:
442 data
->auxiliary
.length_valid
= 0x1;
443 data
->length
= reclen
;
444 data
->operation
.operation
= 0x16;
446 case DASD_ECKD_CCW_READ_COUNT
:
447 data
->operation
.operation
= 0x06;
449 case DASD_ECKD_CCW_READ_TRACK
:
450 data
->operation
.orientation
= 0x1;
451 data
->operation
.operation
= 0x0C;
452 data
->extended_parameter_length
= 0;
455 case DASD_ECKD_CCW_READ_TRACK_DATA
:
456 data
->auxiliary
.length_valid
= 0x1;
458 data
->operation
.operation
= 0x0C;
460 case DASD_ECKD_CCW_ERASE
:
461 data
->length
= reclen
;
462 data
->auxiliary
.length_valid
= 0x1;
463 data
->operation
.operation
= 0x0b;
466 DBF_DEV_EVENT(DBF_ERR
, device
,
467 "fill LRE unknown opcode 0x%x", cmd
);
470 set_ch_t(&data
->seek_addr
,
471 trk
/ private->rdc_data
.trk_per_cyl
,
472 trk
% private->rdc_data
.trk_per_cyl
);
473 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
474 data
->search_arg
.head
= data
->seek_addr
.head
;
475 data
->search_arg
.record
= rec_on_trk
;
478 static int prefix_LRE(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
479 unsigned int trk
, unsigned int totrk
, int cmd
,
480 struct dasd_device
*basedev
, struct dasd_device
*startdev
,
481 unsigned char format
, unsigned int rec_on_trk
, int count
,
482 unsigned int blksize
, unsigned int tlf
)
484 struct dasd_eckd_private
*basepriv
, *startpriv
;
485 struct DE_eckd_data
*dedata
;
486 struct LRE_eckd_data
*lredata
;
488 u16 heads
, beghead
, endhead
;
491 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
492 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
493 dedata
= &pfxdata
->define_extent
;
494 lredata
= &pfxdata
->locate_record
;
496 ccw
->cmd_code
= DASD_ECKD_CCW_PFX
;
498 if (cmd
== DASD_ECKD_CCW_WRITE_FULL_TRACK
) {
499 ccw
->count
= sizeof(*pfxdata
) + 2;
500 ccw
->cda
= (__u32
) __pa(pfxdata
);
501 memset(pfxdata
, 0, sizeof(*pfxdata
) + 2);
503 ccw
->count
= sizeof(*pfxdata
);
504 ccw
->cda
= (__u32
) __pa(pfxdata
);
505 memset(pfxdata
, 0, sizeof(*pfxdata
));
510 DBF_DEV_EVENT(DBF_ERR
, basedev
,
511 "PFX LRE unknown format 0x%x", format
);
515 pfxdata
->format
= format
;
516 pfxdata
->base_address
= basepriv
->ned
->unit_addr
;
517 pfxdata
->base_lss
= basepriv
->ned
->ID
;
518 pfxdata
->validity
.define_extent
= 1;
520 /* private uid is kept up to date, conf_data may be outdated */
521 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
522 pfxdata
->validity
.verify_base
= 1;
523 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
524 pfxdata
->validity
.hyper_pav
= 1;
527 /* define extend data (mostly)*/
529 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
530 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
531 case DASD_ECKD_CCW_READ
:
532 case DASD_ECKD_CCW_READ_MT
:
533 case DASD_ECKD_CCW_READ_CKD
:
534 case DASD_ECKD_CCW_READ_CKD_MT
:
535 case DASD_ECKD_CCW_READ_KD
:
536 case DASD_ECKD_CCW_READ_KD_MT
:
537 case DASD_ECKD_CCW_READ_COUNT
:
538 dedata
->mask
.perm
= 0x1;
539 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
541 case DASD_ECKD_CCW_READ_TRACK
:
542 case DASD_ECKD_CCW_READ_TRACK_DATA
:
543 dedata
->mask
.perm
= 0x1;
544 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
545 dedata
->blk_size
= 0;
547 case DASD_ECKD_CCW_WRITE
:
548 case DASD_ECKD_CCW_WRITE_MT
:
549 case DASD_ECKD_CCW_WRITE_KD
:
550 case DASD_ECKD_CCW_WRITE_KD_MT
:
551 dedata
->mask
.perm
= 0x02;
552 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
553 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
555 case DASD_ECKD_CCW_WRITE_CKD
:
556 case DASD_ECKD_CCW_WRITE_CKD_MT
:
557 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
558 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
560 case DASD_ECKD_CCW_ERASE
:
561 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
562 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
563 dedata
->mask
.perm
= 0x3;
564 dedata
->mask
.auth
= 0x1;
565 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
566 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
568 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
569 dedata
->mask
.perm
= 0x03;
570 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
571 dedata
->blk_size
= 0;
573 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
574 dedata
->mask
.perm
= 0x02;
575 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
576 dedata
->blk_size
= blksize
;
577 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
580 DBF_DEV_EVENT(DBF_ERR
, basedev
,
581 "PFX LRE unknown opcode 0x%x", cmd
);
586 dedata
->attributes
.mode
= 0x3; /* ECKD */
588 if ((basepriv
->rdc_data
.cu_type
== 0x2105 ||
589 basepriv
->rdc_data
.cu_type
== 0x2107 ||
590 basepriv
->rdc_data
.cu_type
== 0x1750)
591 && !(basepriv
->uses_cdl
&& trk
< 2))
592 dedata
->ga_extended
|= 0x40; /* Regular Data Format Mode */
594 heads
= basepriv
->rdc_data
.trk_per_cyl
;
595 begcyl
= trk
/ heads
;
596 beghead
= trk
% heads
;
597 endcyl
= totrk
/ heads
;
598 endhead
= totrk
% heads
;
600 /* check for sequential prestage - enhance cylinder range */
601 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
602 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
604 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
605 endcyl
+= basepriv
->attrib
.nr_cyl
;
607 endcyl
= (basepriv
->real_cyl
- 1);
610 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
611 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
614 fill_LRE_data(lredata
, trk
, rec_on_trk
, count
, cmd
,
615 basedev
, blksize
, tlf
);
621 static int prefix(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
622 unsigned int trk
, unsigned int totrk
, int cmd
,
623 struct dasd_device
*basedev
, struct dasd_device
*startdev
)
625 return prefix_LRE(ccw
, pfxdata
, trk
, totrk
, cmd
, basedev
, startdev
,
630 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, unsigned int trk
,
631 unsigned int rec_on_trk
, int no_rec
, int cmd
,
632 struct dasd_device
* device
, int reclen
)
634 struct dasd_eckd_private
*private;
638 private = (struct dasd_eckd_private
*) device
->private;
640 DBF_DEV_EVENT(DBF_INFO
, device
,
641 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
642 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
644 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
647 ccw
->cda
= (__u32
) __pa(data
);
649 memset(data
, 0, sizeof(struct LO_eckd_data
));
652 switch (private->rdc_data
.dev_type
) {
654 dn
= ceil_quot(reclen
+ 6, 232);
655 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
656 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
659 d
= 7 + ceil_quot(reclen
+ 12, 32);
660 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
664 data
->sector
= sector
;
665 data
->count
= no_rec
;
667 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
668 data
->operation
.orientation
= 0x3;
669 data
->operation
.operation
= 0x03;
671 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
672 data
->operation
.orientation
= 0x3;
673 data
->operation
.operation
= 0x16;
675 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
676 data
->operation
.orientation
= 0x1;
677 data
->operation
.operation
= 0x03;
680 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
681 data
->operation
.orientation
= 0x3;
682 data
->operation
.operation
= 0x16;
685 case DASD_ECKD_CCW_WRITE
:
686 case DASD_ECKD_CCW_WRITE_MT
:
687 case DASD_ECKD_CCW_WRITE_KD
:
688 case DASD_ECKD_CCW_WRITE_KD_MT
:
689 data
->auxiliary
.last_bytes_used
= 0x1;
690 data
->length
= reclen
;
691 data
->operation
.operation
= 0x01;
693 case DASD_ECKD_CCW_WRITE_CKD
:
694 case DASD_ECKD_CCW_WRITE_CKD_MT
:
695 data
->auxiliary
.last_bytes_used
= 0x1;
696 data
->length
= reclen
;
697 data
->operation
.operation
= 0x03;
699 case DASD_ECKD_CCW_READ
:
700 case DASD_ECKD_CCW_READ_MT
:
701 case DASD_ECKD_CCW_READ_KD
:
702 case DASD_ECKD_CCW_READ_KD_MT
:
703 data
->auxiliary
.last_bytes_used
= 0x1;
704 data
->length
= reclen
;
705 data
->operation
.operation
= 0x06;
707 case DASD_ECKD_CCW_READ_CKD
:
708 case DASD_ECKD_CCW_READ_CKD_MT
:
709 data
->auxiliary
.last_bytes_used
= 0x1;
710 data
->length
= reclen
;
711 data
->operation
.operation
= 0x16;
713 case DASD_ECKD_CCW_READ_COUNT
:
714 data
->operation
.operation
= 0x06;
716 case DASD_ECKD_CCW_ERASE
:
717 data
->length
= reclen
;
718 data
->auxiliary
.last_bytes_used
= 0x1;
719 data
->operation
.operation
= 0x0b;
722 DBF_DEV_EVENT(DBF_ERR
, device
, "unknown locate record "
725 set_ch_t(&data
->seek_addr
,
726 trk
/ private->rdc_data
.trk_per_cyl
,
727 trk
% private->rdc_data
.trk_per_cyl
);
728 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
729 data
->search_arg
.head
= data
->seek_addr
.head
;
730 data
->search_arg
.record
= rec_on_trk
;
734 * Returns 1 if the block is one of the special blocks that needs
735 * to get read/written with the KD variant of the command.
736 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
737 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
738 * Luckily the KD variants differ only by one bit (0x08) from the
739 * normal variant. So don't wonder about code like:
740 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
741 * ccw->cmd_code |= 0x8;
744 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
748 if (recid
< blk_per_trk
)
750 if (recid
< 2 * blk_per_trk
)
756 * Returns the record size for the special blocks of the cdl format.
757 * Only returns something useful if dasd_eckd_cdl_special is true
761 dasd_eckd_cdl_reclen(int recid
)
764 return sizes_trk0
[recid
];
767 /* create unique id from private structure. */
768 static void create_uid(struct dasd_eckd_private
*private)
771 struct dasd_uid
*uid
;
774 memset(uid
, 0, sizeof(struct dasd_uid
));
775 memcpy(uid
->vendor
, private->ned
->HDA_manufacturer
,
776 sizeof(uid
->vendor
) - 1);
777 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
778 memcpy(uid
->serial
, private->ned
->HDA_location
,
779 sizeof(uid
->serial
) - 1);
780 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
781 uid
->ssid
= private->gneq
->subsystemID
;
782 uid
->real_unit_addr
= private->ned
->unit_addr
;
784 uid
->type
= private->sneq
->sua_flags
;
785 if (uid
->type
== UA_BASE_PAV_ALIAS
)
786 uid
->base_unit_addr
= private->sneq
->base_unit_addr
;
788 uid
->type
= UA_BASE_DEVICE
;
790 if (private->vdsneq
) {
791 for (count
= 0; count
< 16; count
++) {
792 sprintf(uid
->vduit
+2*count
, "%02x",
793 private->vdsneq
->uit
[count
]);
799 * Generate device unique id that specifies the physical device.
801 static int dasd_eckd_generate_uid(struct dasd_device
*device
)
803 struct dasd_eckd_private
*private;
806 private = (struct dasd_eckd_private
*) device
->private;
809 if (!private->ned
|| !private->gneq
)
811 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
813 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
817 static int dasd_eckd_get_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
819 struct dasd_eckd_private
*private;
822 if (device
->private) {
823 private = (struct dasd_eckd_private
*)device
->private;
824 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
826 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
833 * compare device UID with data of a given dasd_eckd_private structure
836 static int dasd_eckd_compare_path_uid(struct dasd_device
*device
,
837 struct dasd_eckd_private
*private)
839 struct dasd_uid device_uid
;
842 dasd_eckd_get_uid(device
, &device_uid
);
844 return memcmp(&device_uid
, &private->uid
, sizeof(struct dasd_uid
));
847 static void dasd_eckd_fill_rcd_cqr(struct dasd_device
*device
,
848 struct dasd_ccw_req
*cqr
,
854 * buffer has to start with EBCDIC "V1.0" to show
855 * support for virtual device SNEQ
857 rcd_buffer
[0] = 0xE5;
858 rcd_buffer
[1] = 0xF1;
859 rcd_buffer
[2] = 0x4B;
860 rcd_buffer
[3] = 0xF0;
863 ccw
->cmd_code
= DASD_ECKD_CCW_RCD
;
865 ccw
->cda
= (__u32
)(addr_t
)rcd_buffer
;
866 ccw
->count
= DASD_ECKD_RCD_DATA_SIZE
;
867 cqr
->magic
= DASD_ECKD_MAGIC
;
869 cqr
->startdev
= device
;
870 cqr
->memdev
= device
;
872 cqr
->expires
= 10*HZ
;
875 cqr
->buildclk
= get_tod_clock();
876 cqr
->status
= DASD_CQR_FILLED
;
877 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
881 * Wakeup helper for read_conf
882 * if the cqr is not done and needs some error recovery
883 * the buffer has to be re-initialized with the EBCDIC "V1.0"
884 * to show support for virtual device SNEQ
886 static void read_conf_cb(struct dasd_ccw_req
*cqr
, void *data
)
891 if (cqr
->status
!= DASD_CQR_DONE
) {
893 rcd_buffer
= (__u8
*)((addr_t
) ccw
->cda
);
894 memset(rcd_buffer
, 0, sizeof(*rcd_buffer
));
896 rcd_buffer
[0] = 0xE5;
897 rcd_buffer
[1] = 0xF1;
898 rcd_buffer
[2] = 0x4B;
899 rcd_buffer
[3] = 0xF0;
901 dasd_wakeup_cb(cqr
, data
);
904 static int dasd_eckd_read_conf_immediately(struct dasd_device
*device
,
905 struct dasd_ccw_req
*cqr
,
912 * sanity check: scan for RCD command in extended SenseID data
913 * some devices do not support RCD
915 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
916 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
)
919 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buffer
, lpm
);
920 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
921 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
923 cqr
->callback
= read_conf_cb
;
924 rc
= dasd_sleep_on_immediatly(cqr
);
928 static int dasd_eckd_read_conf_lpm(struct dasd_device
*device
,
930 int *rcd_buffer_size
, __u8 lpm
)
933 char *rcd_buf
= NULL
;
935 struct dasd_ccw_req
*cqr
;
938 * sanity check: scan for RCD command in extended SenseID data
939 * some devices do not support RCD
941 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
942 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
) {
946 rcd_buf
= kzalloc(DASD_ECKD_RCD_DATA_SIZE
, GFP_KERNEL
| GFP_DMA
);
951 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* RCD */,
952 0, /* use rcd_buf as data ara */
955 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
956 "Could not allocate RCD request");
960 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buf
, lpm
);
961 cqr
->callback
= read_conf_cb
;
962 ret
= dasd_sleep_on(cqr
);
964 * on success we update the user input parms
966 dasd_sfree_request(cqr
, cqr
->memdev
);
970 *rcd_buffer_size
= DASD_ECKD_RCD_DATA_SIZE
;
971 *rcd_buffer
= rcd_buf
;
976 *rcd_buffer_size
= 0;
980 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private
*private)
983 struct dasd_sneq
*sneq
;
987 private->sneq
= NULL
;
988 private->vdsneq
= NULL
;
989 private->gneq
= NULL
;
990 count
= private->conf_len
/ sizeof(struct dasd_sneq
);
991 sneq
= (struct dasd_sneq
*)private->conf_data
;
992 for (i
= 0; i
< count
; ++i
) {
993 if (sneq
->flags
.identifier
== 1 && sneq
->format
== 1)
994 private->sneq
= sneq
;
995 else if (sneq
->flags
.identifier
== 1 && sneq
->format
== 4)
996 private->vdsneq
= (struct vd_sneq
*)sneq
;
997 else if (sneq
->flags
.identifier
== 2)
998 private->gneq
= (struct dasd_gneq
*)sneq
;
999 else if (sneq
->flags
.identifier
== 3 && sneq
->res1
== 1)
1000 private->ned
= (struct dasd_ned
*)sneq
;
1003 if (!private->ned
|| !private->gneq
) {
1004 private->ned
= NULL
;
1005 private->sneq
= NULL
;
1006 private->vdsneq
= NULL
;
1007 private->gneq
= NULL
;
1014 static unsigned char dasd_eckd_path_access(void *conf_data
, int conf_len
)
1016 struct dasd_gneq
*gneq
;
1017 int i
, count
, found
;
1019 count
= conf_len
/ sizeof(*gneq
);
1020 gneq
= (struct dasd_gneq
*)conf_data
;
1022 for (i
= 0; i
< count
; ++i
) {
1023 if (gneq
->flags
.identifier
== 2) {
1030 return ((char *)gneq
)[18] & 0x07;
1035 static void dasd_eckd_clear_conf_data(struct dasd_device
*device
)
1037 struct dasd_eckd_private
*private;
1040 private = (struct dasd_eckd_private
*) device
->private;
1041 private->conf_data
= NULL
;
1042 private->conf_len
= 0;
1043 for (i
= 0; i
< 8; i
++) {
1044 kfree(private->path_conf_data
[i
]);
1045 private->path_conf_data
[i
] = NULL
;
1050 static int dasd_eckd_read_conf(struct dasd_device
*device
)
1053 int conf_len
, conf_data_saved
;
1054 int rc
, path_err
, pos
;
1056 struct dasd_eckd_private
*private, path_private
;
1057 struct dasd_path
*path_data
;
1058 struct dasd_uid
*uid
;
1059 char print_path_uid
[60], print_device_uid
[60];
1061 private = (struct dasd_eckd_private
*) device
->private;
1062 path_data
= &device
->path_data
;
1063 opm
= ccw_device_get_path_mask(device
->cdev
);
1064 conf_data_saved
= 0;
1066 /* get configuration data per operational path */
1067 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1070 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
1072 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
1073 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1074 "Read configuration data returned "
1078 if (conf_data
== NULL
) {
1079 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1080 "No configuration data "
1082 /* no further analysis possible */
1083 path_data
->opm
|= lpm
;
1084 continue; /* no error */
1086 /* save first valid configuration data */
1087 if (!conf_data_saved
) {
1088 /* initially clear previously stored conf_data */
1089 dasd_eckd_clear_conf_data(device
);
1090 private->conf_data
= conf_data
;
1091 private->conf_len
= conf_len
;
1092 if (dasd_eckd_identify_conf_parts(private)) {
1093 private->conf_data
= NULL
;
1094 private->conf_len
= 0;
1098 pos
= pathmask_to_pos(lpm
);
1099 /* store per path conf_data */
1100 private->path_conf_data
[pos
] =
1101 (struct dasd_conf_data
*) conf_data
;
1103 * build device UID that other path data
1104 * can be compared to it
1106 dasd_eckd_generate_uid(device
);
1109 path_private
.conf_data
= conf_data
;
1110 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1111 if (dasd_eckd_identify_conf_parts(
1113 path_private
.conf_data
= NULL
;
1114 path_private
.conf_len
= 0;
1118 if (dasd_eckd_compare_path_uid(
1119 device
, &path_private
)) {
1120 uid
= &path_private
.uid
;
1121 if (strlen(uid
->vduit
) > 0)
1122 snprintf(print_path_uid
,
1123 sizeof(print_path_uid
),
1124 "%s.%s.%04x.%02x.%s",
1125 uid
->vendor
, uid
->serial
,
1126 uid
->ssid
, uid
->real_unit_addr
,
1129 snprintf(print_path_uid
,
1130 sizeof(print_path_uid
),
1132 uid
->vendor
, uid
->serial
,
1134 uid
->real_unit_addr
);
1135 uid
= &private->uid
;
1136 if (strlen(uid
->vduit
) > 0)
1137 snprintf(print_device_uid
,
1138 sizeof(print_device_uid
),
1139 "%s.%s.%04x.%02x.%s",
1140 uid
->vendor
, uid
->serial
,
1141 uid
->ssid
, uid
->real_unit_addr
,
1144 snprintf(print_device_uid
,
1145 sizeof(print_device_uid
),
1147 uid
->vendor
, uid
->serial
,
1149 uid
->real_unit_addr
);
1150 dev_err(&device
->cdev
->dev
,
1151 "Not all channel paths lead to "
1152 "the same device, path %02X leads to "
1153 "device %s instead of %s\n", lpm
,
1154 print_path_uid
, print_device_uid
);
1156 path_data
->cablepm
|= lpm
;
1159 pos
= pathmask_to_pos(lpm
);
1160 /* store per path conf_data */
1161 private->path_conf_data
[pos
] =
1162 (struct dasd_conf_data
*) conf_data
;
1163 path_private
.conf_data
= NULL
;
1164 path_private
.conf_len
= 0;
1166 switch (dasd_eckd_path_access(conf_data
, conf_len
)) {
1168 path_data
->npm
|= lpm
;
1171 path_data
->ppm
|= lpm
;
1174 if (!path_data
->opm
) {
1175 path_data
->opm
= lpm
;
1176 dasd_generic_path_operational(device
);
1178 path_data
->opm
|= lpm
;
1181 * if the path is used
1182 * it should not be in one of the negative lists
1184 path_data
->cablepm
&= ~lpm
;
1185 path_data
->hpfpm
&= ~lpm
;
1186 path_data
->cuirpm
&= ~lpm
;
1192 static int verify_fcx_max_data(struct dasd_device
*device
, __u8 lpm
)
1194 struct dasd_eckd_private
*private;
1198 private = (struct dasd_eckd_private
*) device
->private;
1199 if (private->fcx_max_data
) {
1200 mdc
= ccw_device_get_mdc(device
->cdev
, lpm
);
1202 dev_warn(&device
->cdev
->dev
,
1203 "Detecting the maximum data size for zHPF "
1204 "requests failed (rc=%d) for a new path %x\n",
1208 fcx_max_data
= mdc
* FCX_MAX_DATA_FACTOR
;
1209 if (fcx_max_data
< private->fcx_max_data
) {
1210 dev_warn(&device
->cdev
->dev
,
1211 "The maximum data size for zHPF requests %u "
1212 "on a new path %x is below the active maximum "
1213 "%u\n", fcx_max_data
, lpm
,
1214 private->fcx_max_data
);
1221 static int rebuild_device_uid(struct dasd_device
*device
,
1222 struct path_verification_work_data
*data
)
1224 struct dasd_eckd_private
*private;
1225 struct dasd_path
*path_data
;
1230 private = (struct dasd_eckd_private
*) device
->private;
1231 path_data
= &device
->path_data
;
1232 opm
= device
->path_data
.opm
;
1234 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1237 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1238 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1239 data
->cqr
.cpaddr
= &data
->ccw
;
1240 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1245 if (rc
== -EOPNOTSUPP
) /* -EOPNOTSUPP is ok */
1247 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1248 "Read configuration data "
1249 "returned error %d", rc
);
1252 memcpy(private->conf_data
, data
->rcd_buffer
,
1253 DASD_ECKD_RCD_DATA_SIZE
);
1254 if (dasd_eckd_identify_conf_parts(private)) {
1256 } else /* first valid path is enough */
1261 rc
= dasd_eckd_generate_uid(device
);
1266 static void do_path_verification_work(struct work_struct
*work
)
1268 struct path_verification_work_data
*data
;
1269 struct dasd_device
*device
;
1270 struct dasd_eckd_private path_private
;
1271 struct dasd_uid
*uid
;
1272 __u8 path_rcd_buf
[DASD_ECKD_RCD_DATA_SIZE
];
1273 __u8 lpm
, opm
, npm
, ppm
, epm
, hpfpm
, cablepm
;
1274 unsigned long flags
;
1278 data
= container_of(work
, struct path_verification_work_data
, worker
);
1279 device
= data
->device
;
1281 /* delay path verification until device was resumed */
1282 if (test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
1283 schedule_work(work
);
1286 /* check if path verification already running and delay if so */
1287 if (test_and_set_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
)) {
1288 schedule_work(work
);
1298 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1299 if (!(lpm
& data
->tbvpm
))
1301 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1302 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1303 data
->cqr
.cpaddr
= &data
->ccw
;
1304 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1308 switch (dasd_eckd_path_access(data
->rcd_buffer
,
1309 DASD_ECKD_RCD_DATA_SIZE
)
1319 } else if (rc
== -EOPNOTSUPP
) {
1320 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1321 "path verification: No configuration "
1324 } else if (rc
== -EAGAIN
) {
1325 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1326 "path verification: device is stopped,"
1327 " try again later");
1330 dev_warn(&device
->cdev
->dev
,
1331 "Reading device feature codes failed "
1332 "(rc=%d) for new path %x\n", rc
, lpm
);
1335 if (verify_fcx_max_data(device
, lpm
)) {
1344 * save conf_data for comparison after
1345 * rebuild_device_uid may have changed
1348 memcpy(&path_rcd_buf
, data
->rcd_buffer
,
1349 DASD_ECKD_RCD_DATA_SIZE
);
1350 path_private
.conf_data
= (void *) &path_rcd_buf
;
1351 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1352 if (dasd_eckd_identify_conf_parts(&path_private
)) {
1353 path_private
.conf_data
= NULL
;
1354 path_private
.conf_len
= 0;
1359 * compare path UID with device UID only if at least
1360 * one valid path is left
1361 * in other case the device UID may have changed and
1362 * the first working path UID will be used as device UID
1364 if (device
->path_data
.opm
&&
1365 dasd_eckd_compare_path_uid(device
, &path_private
)) {
1367 * the comparison was not successful
1368 * rebuild the device UID with at least one
1369 * known path in case a z/VM hyperswap command
1370 * has changed the device
1372 * after this compare again
1374 * if either the rebuild or the recompare fails
1375 * the path can not be used
1377 if (rebuild_device_uid(device
, data
) ||
1378 dasd_eckd_compare_path_uid(
1379 device
, &path_private
)) {
1380 uid
= &path_private
.uid
;
1381 if (strlen(uid
->vduit
) > 0)
1382 snprintf(print_uid
, sizeof(print_uid
),
1383 "%s.%s.%04x.%02x.%s",
1384 uid
->vendor
, uid
->serial
,
1385 uid
->ssid
, uid
->real_unit_addr
,
1388 snprintf(print_uid
, sizeof(print_uid
),
1390 uid
->vendor
, uid
->serial
,
1392 uid
->real_unit_addr
);
1393 dev_err(&device
->cdev
->dev
,
1394 "The newly added channel path %02X "
1395 "will not be used because it leads "
1396 "to a different device %s\n",
1407 * There is a small chance that a path is lost again between
1408 * above path verification and the following modification of
1409 * the device opm mask. We could avoid that race here by using
1410 * yet another path mask, but we rather deal with this unlikely
1411 * situation in dasd_start_IO.
1413 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1414 if (!device
->path_data
.opm
&& opm
) {
1415 device
->path_data
.opm
= opm
;
1416 device
->path_data
.cablepm
&= ~opm
;
1417 device
->path_data
.cuirpm
&= ~opm
;
1418 device
->path_data
.hpfpm
&= ~opm
;
1419 dasd_generic_path_operational(device
);
1421 device
->path_data
.opm
|= opm
;
1422 device
->path_data
.cablepm
&= ~opm
;
1423 device
->path_data
.cuirpm
&= ~opm
;
1424 device
->path_data
.hpfpm
&= ~opm
;
1426 device
->path_data
.npm
|= npm
;
1427 device
->path_data
.ppm
|= ppm
;
1428 device
->path_data
.tbvpm
|= epm
;
1429 device
->path_data
.cablepm
|= cablepm
;
1430 device
->path_data
.hpfpm
|= hpfpm
;
1431 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1433 clear_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
);
1434 dasd_put_device(device
);
1436 mutex_unlock(&dasd_path_verification_mutex
);
1441 static int dasd_eckd_verify_path(struct dasd_device
*device
, __u8 lpm
)
1443 struct path_verification_work_data
*data
;
1445 data
= kmalloc(sizeof(*data
), GFP_ATOMIC
| GFP_DMA
);
1447 if (mutex_trylock(&dasd_path_verification_mutex
)) {
1448 data
= path_verification_worker
;
1453 memset(data
, 0, sizeof(*data
));
1456 INIT_WORK(&data
->worker
, do_path_verification_work
);
1457 dasd_get_device(device
);
1458 data
->device
= device
;
1460 schedule_work(&data
->worker
);
1464 static int dasd_eckd_read_features(struct dasd_device
*device
)
1466 struct dasd_psf_prssd_data
*prssdp
;
1467 struct dasd_rssd_features
*features
;
1468 struct dasd_ccw_req
*cqr
;
1471 struct dasd_eckd_private
*private;
1473 private = (struct dasd_eckd_private
*) device
->private;
1474 memset(&private->features
, 0, sizeof(struct dasd_rssd_features
));
1475 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
1476 (sizeof(struct dasd_psf_prssd_data
) +
1477 sizeof(struct dasd_rssd_features
)),
1480 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s", "Could not "
1481 "allocate initialization request");
1482 return PTR_ERR(cqr
);
1484 cqr
->startdev
= device
;
1485 cqr
->memdev
= device
;
1488 cqr
->expires
= 10 * HZ
;
1490 /* Prepare for Read Subsystem Data */
1491 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1492 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1493 prssdp
->order
= PSF_ORDER_PRSSD
;
1494 prssdp
->suborder
= 0x41; /* Read Feature Codes */
1495 /* all other bytes of prssdp must be zero */
1498 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1499 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1500 ccw
->flags
|= CCW_FLAG_CC
;
1501 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1503 /* Read Subsystem Data - feature codes */
1504 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1505 memset(features
, 0, sizeof(struct dasd_rssd_features
));
1508 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1509 ccw
->count
= sizeof(struct dasd_rssd_features
);
1510 ccw
->cda
= (__u32
)(addr_t
) features
;
1512 cqr
->buildclk
= get_tod_clock();
1513 cqr
->status
= DASD_CQR_FILLED
;
1514 rc
= dasd_sleep_on(cqr
);
1516 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1517 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1518 memcpy(&private->features
, features
,
1519 sizeof(struct dasd_rssd_features
));
1521 dev_warn(&device
->cdev
->dev
, "Reading device feature codes"
1522 " failed with rc=%d\n", rc
);
1523 dasd_sfree_request(cqr
, cqr
->memdev
);
1529 * Build CP for Perform Subsystem Function - SSC.
1531 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
,
1534 struct dasd_ccw_req
*cqr
;
1535 struct dasd_psf_ssc_data
*psf_ssc_data
;
1538 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
1539 sizeof(struct dasd_psf_ssc_data
),
1543 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1544 "Could not allocate PSF-SSC request");
1547 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
1548 psf_ssc_data
->order
= PSF_ORDER_SSC
;
1549 psf_ssc_data
->suborder
= 0xc0;
1551 psf_ssc_data
->suborder
|= 0x08;
1552 psf_ssc_data
->reserved
[0] = 0x88;
1555 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1556 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
1559 cqr
->startdev
= device
;
1560 cqr
->memdev
= device
;
1563 cqr
->expires
= 10*HZ
;
1564 cqr
->buildclk
= get_tod_clock();
1565 cqr
->status
= DASD_CQR_FILLED
;
1570 * Perform Subsystem Function.
1571 * It is necessary to trigger CIO for channel revalidation since this
1572 * call might change behaviour of DASD devices.
1575 dasd_eckd_psf_ssc(struct dasd_device
*device
, int enable_pav
,
1576 unsigned long flags
)
1578 struct dasd_ccw_req
*cqr
;
1581 cqr
= dasd_eckd_build_psf_ssc(device
, enable_pav
);
1583 return PTR_ERR(cqr
);
1586 * set flags e.g. turn on failfast, to prevent blocking
1587 * the calling function should handle failed requests
1589 cqr
->flags
|= flags
;
1591 rc
= dasd_sleep_on(cqr
);
1593 /* trigger CIO to reprobe devices */
1594 css_schedule_reprobe();
1595 else if (cqr
->intrc
== -EAGAIN
)
1598 dasd_sfree_request(cqr
, cqr
->memdev
);
1603 * Valide storage server of current device.
1605 static int dasd_eckd_validate_server(struct dasd_device
*device
,
1606 unsigned long flags
)
1609 struct dasd_eckd_private
*private;
1612 private = (struct dasd_eckd_private
*) device
->private;
1613 if (private->uid
.type
== UA_BASE_PAV_ALIAS
||
1614 private->uid
.type
== UA_HYPER_PAV_ALIAS
)
1616 if (dasd_nopav
|| MACHINE_IS_VM
)
1620 rc
= dasd_eckd_psf_ssc(device
, enable_pav
, flags
);
1622 /* may be requested feature is not available on server,
1623 * therefore just report error and go ahead */
1624 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "PSF-SSC for SSID %04x "
1625 "returned rc=%d", private->uid
.ssid
, rc
);
1630 * worker to do a validate server in case of a lost pathgroup
1632 static void dasd_eckd_do_validate_server(struct work_struct
*work
)
1634 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
1636 unsigned long flags
= 0;
1638 set_bit(DASD_CQR_FLAGS_FAILFAST
, &flags
);
1639 if (dasd_eckd_validate_server(device
, flags
)
1641 /* schedule worker again if failed */
1642 schedule_work(&device
->kick_validate
);
1646 dasd_put_device(device
);
1649 static void dasd_eckd_kick_validate_server(struct dasd_device
*device
)
1651 dasd_get_device(device
);
1652 /* exit if device not online or in offline processing */
1653 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1654 device
->state
< DASD_STATE_ONLINE
) {
1655 dasd_put_device(device
);
1658 /* queue call to do_validate_server to the kernel event daemon. */
1659 if (!schedule_work(&device
->kick_validate
))
1660 dasd_put_device(device
);
1663 static u32
get_fcx_max_data(struct dasd_device
*device
)
1666 int fcx_in_css
, fcx_in_gneq
, fcx_in_features
;
1667 struct dasd_eckd_private
*private;
1671 /* is transport mode supported? */
1672 private = (struct dasd_eckd_private
*) device
->private;
1673 fcx_in_css
= css_general_characteristics
.fcx
;
1674 fcx_in_gneq
= private->gneq
->reserved2
[7] & 0x04;
1675 fcx_in_features
= private->features
.feature
[40] & 0x80;
1676 tpm
= fcx_in_css
&& fcx_in_gneq
&& fcx_in_features
;
1681 mdc
= ccw_device_get_mdc(device
->cdev
, 0);
1683 dev_warn(&device
->cdev
->dev
, "Detecting the maximum supported"
1684 " data size for zHPF requests failed\n");
1687 return mdc
* FCX_MAX_DATA_FACTOR
;
1691 * Check device characteristics.
1692 * If the device is accessible using ECKD discipline, the device is enabled.
1695 dasd_eckd_check_characteristics(struct dasd_device
*device
)
1697 struct dasd_eckd_private
*private;
1698 struct dasd_block
*block
;
1699 struct dasd_uid temp_uid
;
1702 unsigned long value
;
1704 /* setup work queue for validate server*/
1705 INIT_WORK(&device
->kick_validate
, dasd_eckd_do_validate_server
);
1707 if (!ccw_device_is_pathgroup(device
->cdev
)) {
1708 dev_warn(&device
->cdev
->dev
,
1709 "A channel path group could not be established\n");
1712 if (!ccw_device_is_multipath(device
->cdev
)) {
1713 dev_info(&device
->cdev
->dev
,
1714 "The DASD is not operating in multipath mode\n");
1716 private = (struct dasd_eckd_private
*) device
->private;
1718 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
1720 dev_warn(&device
->cdev
->dev
,
1721 "Allocating memory for private DASD data "
1725 device
->private = (void *) private;
1727 memset(private, 0, sizeof(*private));
1729 /* Invalidate status of initial analysis. */
1730 private->init_cqr_status
= -1;
1731 /* Set default cache operations. */
1732 private->attrib
.operation
= DASD_NORMAL_CACHE
;
1733 private->attrib
.nr_cyl
= 0;
1735 /* Read Configuration Data */
1736 rc
= dasd_eckd_read_conf(device
);
1740 /* set default timeout */
1741 device
->default_expires
= DASD_EXPIRES
;
1742 /* set default retry count */
1743 device
->default_retries
= DASD_RETRIES
;
1745 if (private->gneq
) {
1747 for (i
= 0; i
< private->gneq
->timeout
.value
; i
++)
1749 value
= value
* private->gneq
->timeout
.number
;
1750 /* do not accept useless values */
1751 if (value
!= 0 && value
<= DASD_EXPIRES_MAX
)
1752 device
->default_expires
= value
;
1755 dasd_eckd_get_uid(device
, &temp_uid
);
1756 if (temp_uid
.type
== UA_BASE_DEVICE
) {
1757 block
= dasd_alloc_block();
1758 if (IS_ERR(block
)) {
1759 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1760 "could not allocate dasd "
1762 rc
= PTR_ERR(block
);
1765 device
->block
= block
;
1766 block
->base
= device
;
1769 /* register lcu with alias handling, enable PAV */
1770 rc
= dasd_alias_make_device_known_to_lcu(device
);
1774 dasd_eckd_validate_server(device
, 0);
1776 /* device may report different configuration data after LCU setup */
1777 rc
= dasd_eckd_read_conf(device
);
1781 /* Read Feature Codes */
1782 dasd_eckd_read_features(device
);
1784 /* Read Device Characteristics */
1785 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
1786 &private->rdc_data
, 64);
1788 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1789 "Read device characteristic failed, rc=%d", rc
);
1793 if ((device
->features
& DASD_FEATURE_USERAW
) &&
1794 !(private->rdc_data
.facilities
.RT_in_LR
)) {
1795 dev_err(&device
->cdev
->dev
, "The storage server does not "
1796 "support raw-track access\n");
1801 /* find the valid cylinder size */
1802 if (private->rdc_data
.no_cyl
== LV_COMPAT_CYL
&&
1803 private->rdc_data
.long_no_cyl
)
1804 private->real_cyl
= private->rdc_data
.long_no_cyl
;
1806 private->real_cyl
= private->rdc_data
.no_cyl
;
1808 private->fcx_max_data
= get_fcx_max_data(device
);
1810 readonly
= dasd_device_is_ro(device
);
1812 set_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
1814 dev_info(&device
->cdev
->dev
, "New DASD %04X/%02X (CU %04X/%02X) "
1815 "with %d cylinders, %d heads, %d sectors%s\n",
1816 private->rdc_data
.dev_type
,
1817 private->rdc_data
.dev_model
,
1818 private->rdc_data
.cu_type
,
1819 private->rdc_data
.cu_model
.model
,
1821 private->rdc_data
.trk_per_cyl
,
1822 private->rdc_data
.sec_per_trk
,
1823 readonly
? ", read-only device" : "");
1827 dasd_alias_disconnect_device_from_lcu(device
);
1829 dasd_free_block(device
->block
);
1830 device
->block
= NULL
;
1832 kfree(private->conf_data
);
1833 kfree(device
->private);
1834 device
->private = NULL
;
1838 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
1840 struct dasd_eckd_private
*private;
1843 private = (struct dasd_eckd_private
*) device
->private;
1844 dasd_alias_disconnect_device_from_lcu(device
);
1845 private->ned
= NULL
;
1846 private->sneq
= NULL
;
1847 private->vdsneq
= NULL
;
1848 private->gneq
= NULL
;
1849 private->conf_len
= 0;
1850 for (i
= 0; i
< 8; i
++) {
1851 kfree(private->path_conf_data
[i
]);
1852 if ((__u8
*)private->path_conf_data
[i
] ==
1853 private->conf_data
) {
1854 private->conf_data
= NULL
;
1855 private->conf_len
= 0;
1857 private->path_conf_data
[i
] = NULL
;
1859 kfree(private->conf_data
);
1860 private->conf_data
= NULL
;
1863 static struct dasd_ccw_req
*
1864 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
1866 struct dasd_eckd_private
*private;
1867 struct eckd_count
*count_data
;
1868 struct LO_eckd_data
*LO_data
;
1869 struct dasd_ccw_req
*cqr
;
1871 int cplength
, datasize
;
1874 private = (struct dasd_eckd_private
*) device
->private;
1877 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
1878 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
1882 /* Define extent for the first 3 tracks. */
1883 define_extent(ccw
++, cqr
->data
, 0, 2,
1884 DASD_ECKD_CCW_READ_COUNT
, device
);
1885 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
1886 /* Locate record for the first 4 records on track 0. */
1887 ccw
[-1].flags
|= CCW_FLAG_CC
;
1888 locate_record(ccw
++, LO_data
++, 0, 0, 4,
1889 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1891 count_data
= private->count_area
;
1892 for (i
= 0; i
< 4; i
++) {
1893 ccw
[-1].flags
|= CCW_FLAG_CC
;
1894 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1897 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1902 /* Locate record for the first record on track 2. */
1903 ccw
[-1].flags
|= CCW_FLAG_CC
;
1904 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1905 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1906 /* Read count ccw. */
1907 ccw
[-1].flags
|= CCW_FLAG_CC
;
1908 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1911 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1914 cqr
->startdev
= device
;
1915 cqr
->memdev
= device
;
1917 cqr
->buildclk
= get_tod_clock();
1918 cqr
->status
= DASD_CQR_FILLED
;
1922 /* differentiate between 'no record found' and any other error */
1923 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req
*init_cqr
)
1926 if (init_cqr
->status
== DASD_CQR_DONE
)
1928 else if (init_cqr
->status
== DASD_CQR_NEED_ERP
||
1929 init_cqr
->status
== DASD_CQR_FAILED
) {
1930 sense
= dasd_get_sense(&init_cqr
->irb
);
1931 if (sense
&& (sense
[1] & SNS1_NO_REC_FOUND
))
1932 return INIT_CQR_UNFORMATTED
;
1934 return INIT_CQR_ERROR
;
1936 return INIT_CQR_ERROR
;
1940 * This is the callback function for the init_analysis cqr. It saves
1941 * the status of the initial analysis ccw before it frees it and kicks
1942 * the device to continue the startup sequence. This will call
1943 * dasd_eckd_do_analysis again (if the devices has not been marked
1944 * for deletion in the meantime).
1946 static void dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
,
1949 struct dasd_eckd_private
*private;
1950 struct dasd_device
*device
;
1952 device
= init_cqr
->startdev
;
1953 private = (struct dasd_eckd_private
*) device
->private;
1954 private->init_cqr_status
= dasd_eckd_analysis_evaluation(init_cqr
);
1955 dasd_sfree_request(init_cqr
, device
);
1956 dasd_kick_device(device
);
1959 static int dasd_eckd_start_analysis(struct dasd_block
*block
)
1961 struct dasd_ccw_req
*init_cqr
;
1963 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1964 if (IS_ERR(init_cqr
))
1965 return PTR_ERR(init_cqr
);
1966 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1967 init_cqr
->callback_data
= NULL
;
1968 init_cqr
->expires
= 5*HZ
;
1969 /* first try without ERP, so we can later handle unformatted
1970 * devices as special case
1972 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &init_cqr
->flags
);
1973 init_cqr
->retries
= 0;
1974 dasd_add_request_head(init_cqr
);
1978 static int dasd_eckd_end_analysis(struct dasd_block
*block
)
1980 struct dasd_device
*device
;
1981 struct dasd_eckd_private
*private;
1982 struct eckd_count
*count_area
;
1983 unsigned int sb
, blk_per_trk
;
1985 struct dasd_ccw_req
*init_cqr
;
1987 device
= block
->base
;
1988 private = (struct dasd_eckd_private
*) device
->private;
1989 status
= private->init_cqr_status
;
1990 private->init_cqr_status
= -1;
1991 if (status
== INIT_CQR_ERROR
) {
1992 /* try again, this time with full ERP */
1993 init_cqr
= dasd_eckd_analysis_ccw(device
);
1994 dasd_sleep_on(init_cqr
);
1995 status
= dasd_eckd_analysis_evaluation(init_cqr
);
1996 dasd_sfree_request(init_cqr
, device
);
1999 if (device
->features
& DASD_FEATURE_USERAW
) {
2000 block
->bp_block
= DASD_RAW_BLOCKSIZE
;
2001 blk_per_trk
= DASD_RAW_BLOCK_PER_TRACK
;
2002 block
->s2b_shift
= 3;
2006 if (status
== INIT_CQR_UNFORMATTED
) {
2007 dev_warn(&device
->cdev
->dev
, "The DASD is not formatted\n");
2008 return -EMEDIUMTYPE
;
2009 } else if (status
== INIT_CQR_ERROR
) {
2010 dev_err(&device
->cdev
->dev
,
2011 "Detecting the DASD disk layout failed because "
2012 "of an I/O error\n");
2016 private->uses_cdl
= 1;
2017 /* Check Track 0 for Compatible Disk Layout */
2019 for (i
= 0; i
< 3; i
++) {
2020 if (private->count_area
[i
].kl
!= 4 ||
2021 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4 ||
2022 private->count_area
[i
].cyl
!= 0 ||
2023 private->count_area
[i
].head
!= count_area_head
[i
] ||
2024 private->count_area
[i
].record
!= count_area_rec
[i
]) {
2025 private->uses_cdl
= 0;
2030 count_area
= &private->count_area
[4];
2032 if (private->uses_cdl
== 0) {
2033 for (i
= 0; i
< 5; i
++) {
2034 if ((private->count_area
[i
].kl
!= 0) ||
2035 (private->count_area
[i
].dl
!=
2036 private->count_area
[0].dl
) ||
2037 private->count_area
[i
].cyl
!= 0 ||
2038 private->count_area
[i
].head
!= count_area_head
[i
] ||
2039 private->count_area
[i
].record
!= count_area_rec
[i
])
2043 count_area
= &private->count_area
[0];
2045 if (private->count_area
[3].record
== 1)
2046 dev_warn(&device
->cdev
->dev
,
2047 "Track 0 has no records following the VTOC\n");
2050 if (count_area
!= NULL
&& count_area
->kl
== 0) {
2051 /* we found notthing violating our disk layout */
2052 if (dasd_check_blocksize(count_area
->dl
) == 0)
2053 block
->bp_block
= count_area
->dl
;
2055 if (block
->bp_block
== 0) {
2056 dev_warn(&device
->cdev
->dev
,
2057 "The disk layout of the DASD is not supported\n");
2058 return -EMEDIUMTYPE
;
2060 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
2061 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
2064 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
2067 block
->blocks
= (private->real_cyl
*
2068 private->rdc_data
.trk_per_cyl
*
2071 dev_info(&device
->cdev
->dev
,
2072 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2073 "%s\n", (block
->bp_block
>> 10),
2074 ((private->real_cyl
*
2075 private->rdc_data
.trk_per_cyl
*
2076 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
2077 ((blk_per_trk
* block
->bp_block
) >> 10),
2079 "compatible disk layout" : "linux disk layout");
2084 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
2086 struct dasd_eckd_private
*private;
2088 private = (struct dasd_eckd_private
*) block
->base
->private;
2089 if (private->init_cqr_status
< 0)
2090 return dasd_eckd_start_analysis(block
);
2092 return dasd_eckd_end_analysis(block
);
2095 static int dasd_eckd_basic_to_ready(struct dasd_device
*device
)
2097 return dasd_alias_add_device(device
);
2100 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
2102 cancel_work_sync(&device
->reload_device
);
2103 cancel_work_sync(&device
->kick_validate
);
2107 static int dasd_eckd_basic_to_known(struct dasd_device
*device
)
2109 return dasd_alias_remove_device(device
);
2113 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
2115 struct dasd_eckd_private
*private;
2117 private = (struct dasd_eckd_private
*) block
->base
->private;
2118 if (dasd_check_blocksize(block
->bp_block
) == 0) {
2119 geo
->sectors
= recs_per_track(&private->rdc_data
,
2120 0, block
->bp_block
);
2122 geo
->cylinders
= private->rdc_data
.no_cyl
;
2123 geo
->heads
= private->rdc_data
.trk_per_cyl
;
2127 static struct dasd_ccw_req
*
2128 dasd_eckd_build_format(struct dasd_device
*base
,
2129 struct format_data_t
*fdata
,
2132 struct dasd_eckd_private
*base_priv
;
2133 struct dasd_eckd_private
*start_priv
;
2134 struct dasd_device
*startdev
= NULL
;
2135 struct dasd_ccw_req
*fcp
;
2136 struct eckd_count
*ect
;
2137 struct ch_t address
;
2141 int cplength
, datasize
;
2149 startdev
= dasd_alias_get_start_dev(base
);
2154 start_priv
= (struct dasd_eckd_private
*) startdev
->private;
2155 base_priv
= (struct dasd_eckd_private
*) base
->private;
2157 rpt
= recs_per_track(&base_priv
->rdc_data
, 0, fdata
->blksize
);
2159 nr_tracks
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2162 * fdata->intensity is a bit string that tells us what to do:
2163 * Bit 0: write record zero
2164 * Bit 1: write home address, currently not supported
2165 * Bit 2: invalidate tracks
2166 * Bit 3: use OS/390 compatible disk layout (cdl)
2167 * Bit 4: do not allow storage subsystem to modify record zero
2168 * Only some bit combinations do make sense.
2170 if (fdata
->intensity
& 0x10) {
2172 intensity
= fdata
->intensity
& ~0x10;
2175 intensity
= fdata
->intensity
;
2178 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
2180 switch (intensity
) {
2181 case 0x00: /* Normal format */
2182 case 0x08: /* Normal format, use cdl. */
2183 cplength
= 2 + (rpt
*nr_tracks
);
2185 datasize
= sizeof(struct PFX_eckd_data
) +
2186 sizeof(struct LO_eckd_data
) +
2187 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2189 datasize
= sizeof(struct DE_eckd_data
) +
2190 sizeof(struct LO_eckd_data
) +
2191 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2193 case 0x01: /* Write record zero and format track. */
2194 case 0x09: /* Write record zero and format track, use cdl. */
2195 cplength
= 2 + rpt
* nr_tracks
;
2197 datasize
= sizeof(struct PFX_eckd_data
) +
2198 sizeof(struct LO_eckd_data
) +
2199 sizeof(struct eckd_count
) +
2200 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2202 datasize
= sizeof(struct DE_eckd_data
) +
2203 sizeof(struct LO_eckd_data
) +
2204 sizeof(struct eckd_count
) +
2205 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2207 case 0x04: /* Invalidate track. */
2208 case 0x0c: /* Invalidate track, use cdl. */
2211 datasize
= sizeof(struct PFX_eckd_data
) +
2212 sizeof(struct LO_eckd_data
) +
2213 sizeof(struct eckd_count
);
2215 datasize
= sizeof(struct DE_eckd_data
) +
2216 sizeof(struct LO_eckd_data
) +
2217 sizeof(struct eckd_count
);
2220 dev_warn(&startdev
->cdev
->dev
,
2221 "An I/O control call used incorrect flags 0x%x\n",
2223 return ERR_PTR(-EINVAL
);
2225 /* Allocate the format ccw request. */
2226 fcp
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
2227 datasize
, startdev
);
2231 start_priv
->count
++;
2235 switch (intensity
& ~0x08) {
2236 case 0x00: /* Normal format. */
2238 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2239 fdata
->start_unit
, fdata
->stop_unit
,
2240 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2241 /* grant subsystem permission to format R0 */
2243 ((struct PFX_eckd_data
*)data
)
2244 ->define_extent
.ga_extended
|= 0x04;
2245 data
+= sizeof(struct PFX_eckd_data
);
2247 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2248 fdata
->start_unit
, fdata
->stop_unit
,
2249 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2250 /* grant subsystem permission to format R0 */
2252 ((struct DE_eckd_data
*) data
)
2253 ->ga_extended
|= 0x04;
2254 data
+= sizeof(struct DE_eckd_data
);
2256 ccw
[-1].flags
|= CCW_FLAG_CC
;
2257 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2258 fdata
->start_unit
, 0, rpt
*nr_tracks
,
2259 DASD_ECKD_CCW_WRITE_CKD
, base
,
2261 data
+= sizeof(struct LO_eckd_data
);
2263 case 0x01: /* Write record zero + format track. */
2265 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2266 fdata
->start_unit
, fdata
->stop_unit
,
2267 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
2269 data
+= sizeof(struct PFX_eckd_data
);
2271 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2272 fdata
->start_unit
, fdata
->stop_unit
,
2273 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, startdev
);
2274 data
+= sizeof(struct DE_eckd_data
);
2276 ccw
[-1].flags
|= CCW_FLAG_CC
;
2277 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2278 fdata
->start_unit
, 0, rpt
* nr_tracks
+ 1,
2279 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, base
,
2280 base
->block
->bp_block
);
2281 data
+= sizeof(struct LO_eckd_data
);
2283 case 0x04: /* Invalidate track. */
2285 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2286 fdata
->start_unit
, fdata
->stop_unit
,
2287 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2288 data
+= sizeof(struct PFX_eckd_data
);
2290 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2291 fdata
->start_unit
, fdata
->stop_unit
,
2292 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2293 data
+= sizeof(struct DE_eckd_data
);
2295 ccw
[-1].flags
|= CCW_FLAG_CC
;
2296 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2297 fdata
->start_unit
, 0, 1,
2298 DASD_ECKD_CCW_WRITE_CKD
, base
, 8);
2299 data
+= sizeof(struct LO_eckd_data
);
2303 for (j
= 0; j
< nr_tracks
; j
++) {
2304 /* calculate cylinder and head for the current track */
2306 (fdata
->start_unit
+ j
) /
2307 base_priv
->rdc_data
.trk_per_cyl
,
2308 (fdata
->start_unit
+ j
) %
2309 base_priv
->rdc_data
.trk_per_cyl
);
2310 if (intensity
& 0x01) { /* write record zero */
2311 ect
= (struct eckd_count
*) data
;
2312 data
+= sizeof(struct eckd_count
);
2313 ect
->cyl
= address
.cyl
;
2314 ect
->head
= address
.head
;
2318 ccw
[-1].flags
|= CCW_FLAG_CC
;
2319 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
2320 ccw
->flags
= CCW_FLAG_SLI
;
2322 ccw
->cda
= (__u32
)(addr_t
) ect
;
2325 if ((intensity
& ~0x08) & 0x04) { /* erase track */
2326 ect
= (struct eckd_count
*) data
;
2327 data
+= sizeof(struct eckd_count
);
2328 ect
->cyl
= address
.cyl
;
2329 ect
->head
= address
.head
;
2333 ccw
[-1].flags
|= CCW_FLAG_CC
;
2334 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2335 ccw
->flags
= CCW_FLAG_SLI
;
2337 ccw
->cda
= (__u32
)(addr_t
) ect
;
2338 } else { /* write remaining records */
2339 for (i
= 0; i
< rpt
; i
++) {
2340 ect
= (struct eckd_count
*) data
;
2341 data
+= sizeof(struct eckd_count
);
2342 ect
->cyl
= address
.cyl
;
2343 ect
->head
= address
.head
;
2344 ect
->record
= i
+ 1;
2346 ect
->dl
= fdata
->blksize
;
2348 * Check for special tracks 0-1
2349 * when formatting CDL
2351 if ((intensity
& 0x08) &&
2352 fdata
->start_unit
== 0) {
2355 ect
->dl
= sizes_trk0
[i
] - 4;
2358 if ((intensity
& 0x08) &&
2359 fdata
->start_unit
== 1) {
2361 ect
->dl
= LABEL_SIZE
- 44;
2363 ccw
[-1].flags
|= CCW_FLAG_CC
;
2364 if (i
!= 0 || j
== 0)
2366 DASD_ECKD_CCW_WRITE_CKD
;
2369 DASD_ECKD_CCW_WRITE_CKD_MT
;
2370 ccw
->flags
= CCW_FLAG_SLI
;
2372 ccw
->cda
= (__u32
)(addr_t
) ect
;
2378 fcp
->startdev
= startdev
;
2379 fcp
->memdev
= startdev
;
2380 fcp
->basedev
= base
;
2382 fcp
->expires
= startdev
->default_expires
* HZ
;
2383 fcp
->buildclk
= get_tod_clock();
2384 fcp
->status
= DASD_CQR_FILLED
;
2390 dasd_eckd_format_device(struct dasd_device
*base
,
2391 struct format_data_t
*fdata
,
2394 struct dasd_ccw_req
*cqr
, *n
;
2395 struct dasd_block
*block
;
2396 struct dasd_eckd_private
*private;
2397 struct list_head format_queue
;
2398 struct dasd_device
*device
;
2399 int old_stop
, format_step
;
2400 int step
, rc
= 0, sleep_rc
;
2402 block
= base
->block
;
2403 private = (struct dasd_eckd_private
*) base
->private;
2405 /* Sanity checks. */
2406 if (fdata
->start_unit
>=
2407 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2408 dev_warn(&base
->cdev
->dev
,
2409 "Start track number %u used in formatting is too big\n",
2413 if (fdata
->stop_unit
>=
2414 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2415 dev_warn(&base
->cdev
->dev
,
2416 "Stop track number %u used in formatting is too big\n",
2420 if (fdata
->start_unit
> fdata
->stop_unit
) {
2421 dev_warn(&base
->cdev
->dev
,
2422 "Start track %u used in formatting exceeds end track\n",
2426 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
2427 dev_warn(&base
->cdev
->dev
,
2428 "The DASD cannot be formatted with block size %u\n",
2433 INIT_LIST_HEAD(&format_queue
);
2435 old_stop
= fdata
->stop_unit
;
2436 while (fdata
->start_unit
<= 1) {
2437 fdata
->stop_unit
= fdata
->start_unit
;
2438 cqr
= dasd_eckd_build_format(base
, fdata
, enable_pav
);
2439 list_add(&cqr
->blocklist
, &format_queue
);
2441 fdata
->stop_unit
= old_stop
;
2442 fdata
->start_unit
++;
2444 if (fdata
->start_unit
> fdata
->stop_unit
)
2449 format_step
= 255 / recs_per_track(&private->rdc_data
, 0,
2451 while (fdata
->start_unit
<= old_stop
) {
2452 step
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2453 if (step
> format_step
)
2454 fdata
->stop_unit
= fdata
->start_unit
+ format_step
- 1;
2456 cqr
= dasd_eckd_build_format(base
, fdata
, enable_pav
);
2458 if (PTR_ERR(cqr
) == -ENOMEM
) {
2460 * not enough memory available
2461 * go to out and start requests
2462 * retry after first requests were finished
2464 fdata
->stop_unit
= old_stop
;
2467 return PTR_ERR(cqr
);
2469 list_add(&cqr
->blocklist
, &format_queue
);
2471 fdata
->start_unit
= fdata
->stop_unit
+ 1;
2472 fdata
->stop_unit
= old_stop
;
2476 sleep_rc
= dasd_sleep_on_queue(&format_queue
);
2478 list_for_each_entry_safe(cqr
, n
, &format_queue
, blocklist
) {
2479 device
= cqr
->startdev
;
2480 private = (struct dasd_eckd_private
*) device
->private;
2481 if (cqr
->status
== DASD_CQR_FAILED
)
2483 list_del_init(&cqr
->blocklist
);
2484 dasd_sfree_request(cqr
, device
);
2492 * in case of ENOMEM we need to retry after
2493 * first requests are finished
2495 if (fdata
->start_unit
<= fdata
->stop_unit
)
2501 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
2503 if (cqr
->retries
< 0) {
2504 cqr
->status
= DASD_CQR_FAILED
;
2507 cqr
->status
= DASD_CQR_FILLED
;
2508 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
2509 dasd_eckd_reset_ccw_to_base_io(cqr
);
2510 cqr
->startdev
= cqr
->block
->base
;
2511 cqr
->lpm
= cqr
->block
->base
->path_data
.opm
;
2515 static dasd_erp_fn_t
2516 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
2518 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
2519 struct ccw_device
*cdev
= device
->cdev
;
2521 switch (cdev
->id
.cu_type
) {
2526 return dasd_3990_erp_action
;
2530 return dasd_default_erp_action
;
2534 static dasd_erp_fn_t
2535 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
2537 return dasd_default_erp_postaction
;
2540 static void dasd_eckd_check_for_device_change(struct dasd_device
*device
,
2541 struct dasd_ccw_req
*cqr
,
2546 struct dasd_eckd_private
*private;
2548 private = (struct dasd_eckd_private
*) device
->private;
2549 /* first of all check for state change pending interrupt */
2550 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
2551 if ((scsw_dstat(&irb
->scsw
) & mask
) == mask
) {
2553 * for alias only, not in offline processing
2554 * and only if not suspended
2556 if (!device
->block
&& private->lcu
&&
2557 device
->state
== DASD_STATE_ONLINE
&&
2558 !test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
2559 !test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
2561 * the state change could be caused by an alias
2562 * reassignment remove device from alias handling
2563 * to prevent new requests from being scheduled on
2564 * the wrong alias device
2566 dasd_alias_remove_device(device
);
2568 /* schedule worker to reload device */
2569 dasd_reload_device(device
);
2571 dasd_generic_handle_state_change(device
);
2575 sense
= dasd_get_sense(irb
);
2579 /* summary unit check */
2580 if ((sense
[27] & DASD_SENSE_BIT_0
) && (sense
[7] == 0x0D) &&
2581 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
)) {
2582 dasd_alias_handle_summary_unit_check(device
, irb
);
2586 /* service information message SIM */
2587 if (!cqr
&& !(sense
[27] & DASD_SENSE_BIT_0
) &&
2588 ((sense
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
)) {
2589 dasd_3990_erp_handle_sim(device
, sense
);
2593 /* loss of device reservation is handled via base devices only
2594 * as alias devices may be used with several bases
2596 if (device
->block
&& (sense
[27] & DASD_SENSE_BIT_0
) &&
2597 (sense
[7] == 0x3F) &&
2598 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
) &&
2599 test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
)) {
2600 if (device
->features
& DASD_FEATURE_FAILONSLCK
)
2601 set_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
2602 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
2603 dev_err(&device
->cdev
->dev
,
2604 "The device reservation was lost\n");
2608 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_single(
2609 struct dasd_device
*startdev
,
2610 struct dasd_block
*block
,
2611 struct request
*req
,
2616 unsigned int first_offs
,
2617 unsigned int last_offs
,
2618 unsigned int blk_per_trk
,
2619 unsigned int blksize
)
2621 struct dasd_eckd_private
*private;
2622 unsigned long *idaws
;
2623 struct LO_eckd_data
*LO_data
;
2624 struct dasd_ccw_req
*cqr
;
2626 struct req_iterator iter
;
2630 int count
, cidaw
, cplength
, datasize
;
2632 unsigned char cmd
, rcmd
;
2634 struct dasd_device
*basedev
;
2636 basedev
= block
->base
;
2637 private = (struct dasd_eckd_private
*) basedev
->private;
2638 if (rq_data_dir(req
) == READ
)
2639 cmd
= DASD_ECKD_CCW_READ_MT
;
2640 else if (rq_data_dir(req
) == WRITE
)
2641 cmd
= DASD_ECKD_CCW_WRITE_MT
;
2643 return ERR_PTR(-EINVAL
);
2645 /* Check struct bio and count the number of blocks for the request. */
2648 rq_for_each_segment(bv
, req
, iter
) {
2649 if (bv
.bv_len
& (blksize
- 1))
2650 /* Eckd can only do full blocks. */
2651 return ERR_PTR(-EINVAL
);
2652 count
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2653 if (idal_is_needed (page_address(bv
.bv_page
), bv
.bv_len
))
2654 cidaw
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2657 if (count
!= last_rec
- first_rec
+ 1)
2658 return ERR_PTR(-EINVAL
);
2660 /* use the prefix command if available */
2661 use_prefix
= private->features
.feature
[8] & 0x01;
2663 /* 1x prefix + number of blocks */
2664 cplength
= 2 + count
;
2665 /* 1x prefix + cidaws*sizeof(long) */
2666 datasize
= sizeof(struct PFX_eckd_data
) +
2667 sizeof(struct LO_eckd_data
) +
2668 cidaw
* sizeof(unsigned long);
2670 /* 1x define extent + 1x locate record + number of blocks */
2671 cplength
= 2 + count
;
2672 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2673 datasize
= sizeof(struct DE_eckd_data
) +
2674 sizeof(struct LO_eckd_data
) +
2675 cidaw
* sizeof(unsigned long);
2677 /* Find out the number of additional locate record ccws for cdl. */
2678 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
2679 if (last_rec
>= 2*blk_per_trk
)
2680 count
= 2*blk_per_trk
- first_rec
;
2682 datasize
+= count
*sizeof(struct LO_eckd_data
);
2684 /* Allocate the ccw request. */
2685 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2690 /* First ccw is define extent or prefix. */
2692 if (prefix(ccw
++, cqr
->data
, first_trk
,
2693 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
2694 /* Clock not in sync and XRC is enabled.
2697 dasd_sfree_request(cqr
, startdev
);
2698 return ERR_PTR(-EAGAIN
);
2700 idaws
= (unsigned long *) (cqr
->data
+
2701 sizeof(struct PFX_eckd_data
));
2703 if (define_extent(ccw
++, cqr
->data
, first_trk
,
2704 last_trk
, cmd
, basedev
) == -EAGAIN
) {
2705 /* Clock not in sync and XRC is enabled.
2708 dasd_sfree_request(cqr
, startdev
);
2709 return ERR_PTR(-EAGAIN
);
2711 idaws
= (unsigned long *) (cqr
->data
+
2712 sizeof(struct DE_eckd_data
));
2714 /* Build locate_record+read/write/ccws. */
2715 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
2717 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
2718 /* Only standard blocks so there is just one locate record. */
2719 ccw
[-1].flags
|= CCW_FLAG_CC
;
2720 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
2721 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
2723 rq_for_each_segment(bv
, req
, iter
) {
2724 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2725 if (dasd_page_cache
) {
2726 char *copy
= kmem_cache_alloc(dasd_page_cache
,
2727 GFP_DMA
| __GFP_NOWARN
);
2728 if (copy
&& rq_data_dir(req
) == WRITE
)
2729 memcpy(copy
+ bv
.bv_offset
, dst
, bv
.bv_len
);
2731 dst
= copy
+ bv
.bv_offset
;
2733 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
2734 sector_t trkid
= recid
;
2735 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
2738 /* Locate record for cdl special block ? */
2739 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
2740 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
2742 count
= dasd_eckd_cdl_reclen(recid
);
2743 if (count
< blksize
&&
2744 rq_data_dir(req
) == READ
)
2745 memset(dst
+ count
, 0xe5,
2748 ccw
[-1].flags
|= CCW_FLAG_CC
;
2749 locate_record(ccw
++, LO_data
++,
2751 1, rcmd
, basedev
, count
);
2753 /* Locate record for standard blocks ? */
2754 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
2755 ccw
[-1].flags
|= CCW_FLAG_CC
;
2756 locate_record(ccw
++, LO_data
++,
2758 last_rec
- recid
+ 1,
2759 cmd
, basedev
, count
);
2761 /* Read/write ccw. */
2762 ccw
[-1].flags
|= CCW_FLAG_CC
;
2763 ccw
->cmd_code
= rcmd
;
2765 if (idal_is_needed(dst
, blksize
)) {
2766 ccw
->cda
= (__u32
)(addr_t
) idaws
;
2767 ccw
->flags
= CCW_FLAG_IDA
;
2768 idaws
= idal_create_words(idaws
, dst
, blksize
);
2770 ccw
->cda
= (__u32
)(addr_t
) dst
;
2778 if (blk_noretry_request(req
) ||
2779 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2780 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2781 cqr
->startdev
= startdev
;
2782 cqr
->memdev
= startdev
;
2784 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2785 cqr
->lpm
= startdev
->path_data
.ppm
;
2786 cqr
->retries
= startdev
->default_retries
;
2787 cqr
->buildclk
= get_tod_clock();
2788 cqr
->status
= DASD_CQR_FILLED
;
2792 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_track(
2793 struct dasd_device
*startdev
,
2794 struct dasd_block
*block
,
2795 struct request
*req
,
2800 unsigned int first_offs
,
2801 unsigned int last_offs
,
2802 unsigned int blk_per_trk
,
2803 unsigned int blksize
)
2805 unsigned long *idaws
;
2806 struct dasd_ccw_req
*cqr
;
2808 struct req_iterator iter
;
2810 char *dst
, *idaw_dst
;
2811 unsigned int cidaw
, cplength
, datasize
;
2815 struct dasd_device
*basedev
;
2816 unsigned int trkcount
, count
, count_to_trk_end
;
2817 unsigned int idaw_len
, seg_len
, part_len
, len_to_track_end
;
2818 unsigned char new_track
, end_idaw
;
2820 unsigned int recoffs
;
2822 basedev
= block
->base
;
2823 if (rq_data_dir(req
) == READ
)
2824 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
2825 else if (rq_data_dir(req
) == WRITE
)
2826 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
2828 return ERR_PTR(-EINVAL
);
2830 /* Track based I/O needs IDAWs for each page, and not just for
2831 * 64 bit addresses. We need additional idals for pages
2832 * that get filled from two tracks, so we use the number
2833 * of records as upper limit.
2835 cidaw
= last_rec
- first_rec
+ 1;
2836 trkcount
= last_trk
- first_trk
+ 1;
2838 /* 1x prefix + one read/write ccw per track */
2839 cplength
= 1 + trkcount
;
2841 /* on 31-bit we need space for two 32 bit addresses per page
2842 * on 64-bit one 64 bit address
2844 datasize
= sizeof(struct PFX_eckd_data
) +
2845 cidaw
* sizeof(unsigned long long);
2847 /* Allocate the ccw request. */
2848 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2853 /* transfer length factor: how many bytes to read from the last track */
2854 if (first_trk
== last_trk
)
2855 tlf
= last_offs
- first_offs
+ 1;
2857 tlf
= last_offs
+ 1;
2860 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
,
2861 last_trk
, cmd
, basedev
, startdev
,
2862 1 /* format */, first_offs
+ 1,
2865 /* Clock not in sync and XRC is enabled.
2868 dasd_sfree_request(cqr
, startdev
);
2869 return ERR_PTR(-EAGAIN
);
2873 * The translation of request into ccw programs must meet the
2874 * following conditions:
2875 * - all idaws but the first and the last must address full pages
2876 * (or 2K blocks on 31-bit)
2877 * - the scope of a ccw and it's idal ends with the track boundaries
2879 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct PFX_eckd_data
));
2883 len_to_track_end
= 0;
2886 rq_for_each_segment(bv
, req
, iter
) {
2887 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2888 seg_len
= bv
.bv_len
;
2892 recoffs
= sector_div(trkid
, blk_per_trk
);
2893 count_to_trk_end
= blk_per_trk
- recoffs
;
2894 count
= min((last_rec
- recid
+ 1),
2895 (sector_t
)count_to_trk_end
);
2896 len_to_track_end
= count
* blksize
;
2897 ccw
[-1].flags
|= CCW_FLAG_CC
;
2898 ccw
->cmd_code
= cmd
;
2899 ccw
->count
= len_to_track_end
;
2900 ccw
->cda
= (__u32
)(addr_t
)idaws
;
2901 ccw
->flags
= CCW_FLAG_IDA
;
2905 /* first idaw for a ccw may start anywhere */
2909 /* If we start a new idaw, we must make sure that it
2910 * starts on an IDA_BLOCK_SIZE boundary.
2911 * If we continue an idaw, we must make sure that the
2912 * current segment begins where the so far accumulated
2916 if (__pa(dst
) & (IDA_BLOCK_SIZE
-1)) {
2917 dasd_sfree_request(cqr
, startdev
);
2918 return ERR_PTR(-ERANGE
);
2922 if ((idaw_dst
+ idaw_len
) != dst
) {
2923 dasd_sfree_request(cqr
, startdev
);
2924 return ERR_PTR(-ERANGE
);
2926 part_len
= min(seg_len
, len_to_track_end
);
2927 seg_len
-= part_len
;
2929 idaw_len
+= part_len
;
2930 len_to_track_end
-= part_len
;
2931 /* collected memory area ends on an IDA_BLOCK border,
2933 * idal_create_words will handle cases where idaw_len
2934 * is larger then IDA_BLOCK_SIZE
2936 if (!(__pa(idaw_dst
+ idaw_len
) & (IDA_BLOCK_SIZE
-1)))
2938 /* We also need to end the idaw at track end */
2939 if (!len_to_track_end
) {
2944 idaws
= idal_create_words(idaws
, idaw_dst
,
2953 if (blk_noretry_request(req
) ||
2954 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2955 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2956 cqr
->startdev
= startdev
;
2957 cqr
->memdev
= startdev
;
2959 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2960 cqr
->lpm
= startdev
->path_data
.ppm
;
2961 cqr
->retries
= startdev
->default_retries
;
2962 cqr
->buildclk
= get_tod_clock();
2963 cqr
->status
= DASD_CQR_FILLED
;
2967 static int prepare_itcw(struct itcw
*itcw
,
2968 unsigned int trk
, unsigned int totrk
, int cmd
,
2969 struct dasd_device
*basedev
,
2970 struct dasd_device
*startdev
,
2971 unsigned int rec_on_trk
, int count
,
2972 unsigned int blksize
,
2973 unsigned int total_data_size
,
2975 unsigned int blk_per_trk
)
2977 struct PFX_eckd_data pfxdata
;
2978 struct dasd_eckd_private
*basepriv
, *startpriv
;
2979 struct DE_eckd_data
*dedata
;
2980 struct LRE_eckd_data
*lredata
;
2984 u16 heads
, beghead
, endhead
;
2992 /* setup prefix data */
2993 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
2994 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
2995 dedata
= &pfxdata
.define_extent
;
2996 lredata
= &pfxdata
.locate_record
;
2998 memset(&pfxdata
, 0, sizeof(pfxdata
));
2999 pfxdata
.format
= 1; /* PFX with LRE */
3000 pfxdata
.base_address
= basepriv
->ned
->unit_addr
;
3001 pfxdata
.base_lss
= basepriv
->ned
->ID
;
3002 pfxdata
.validity
.define_extent
= 1;
3004 /* private uid is kept up to date, conf_data may be outdated */
3005 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
3006 pfxdata
.validity
.verify_base
= 1;
3007 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
3008 pfxdata
.validity
.hyper_pav
= 1;
3012 case DASD_ECKD_CCW_READ_TRACK_DATA
:
3013 dedata
->mask
.perm
= 0x1;
3014 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3015 dedata
->blk_size
= blksize
;
3016 dedata
->ga_extended
|= 0x42;
3017 lredata
->operation
.orientation
= 0x0;
3018 lredata
->operation
.operation
= 0x0C;
3019 lredata
->auxiliary
.check_bytes
= 0x01;
3020 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
3022 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
3023 dedata
->mask
.perm
= 0x02;
3024 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3025 dedata
->blk_size
= blksize
;
3026 rc
= check_XRC_on_prefix(&pfxdata
, basedev
);
3027 dedata
->ga_extended
|= 0x42;
3028 lredata
->operation
.orientation
= 0x0;
3029 lredata
->operation
.operation
= 0x3F;
3030 lredata
->extended_operation
= 0x23;
3031 lredata
->auxiliary
.check_bytes
= 0x2;
3032 pfx_cmd
= DASD_ECKD_CCW_PFX
;
3035 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3036 "prepare itcw, unknown opcode 0x%x", cmd
);
3043 dedata
->attributes
.mode
= 0x3; /* ECKD */
3045 heads
= basepriv
->rdc_data
.trk_per_cyl
;
3046 begcyl
= trk
/ heads
;
3047 beghead
= trk
% heads
;
3048 endcyl
= totrk
/ heads
;
3049 endhead
= totrk
% heads
;
3051 /* check for sequential prestage - enhance cylinder range */
3052 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
3053 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
3055 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
3056 endcyl
+= basepriv
->attrib
.nr_cyl
;
3058 endcyl
= (basepriv
->real_cyl
- 1);
3061 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
3062 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
3064 dedata
->ep_format
= 0x20; /* records per track is valid */
3065 dedata
->ep_rec_per_track
= blk_per_trk
;
3068 switch (basepriv
->rdc_data
.dev_type
) {
3070 dn
= ceil_quot(blksize
+ 6, 232);
3071 d
= 9 + ceil_quot(blksize
+ 6 * (dn
+ 1), 34);
3072 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
3075 d
= 7 + ceil_quot(blksize
+ 12, 32);
3076 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
3081 lredata
->auxiliary
.length_valid
= 1;
3082 lredata
->auxiliary
.length_scope
= 1;
3083 lredata
->auxiliary
.imbedded_ccw_valid
= 1;
3084 lredata
->length
= tlf
;
3085 lredata
->imbedded_ccw
= cmd
;
3086 lredata
->count
= count
;
3087 lredata
->sector
= sector
;
3088 set_ch_t(&lredata
->seek_addr
, begcyl
, beghead
);
3089 lredata
->search_arg
.cyl
= lredata
->seek_addr
.cyl
;
3090 lredata
->search_arg
.head
= lredata
->seek_addr
.head
;
3091 lredata
->search_arg
.record
= rec_on_trk
;
3093 dcw
= itcw_add_dcw(itcw
, pfx_cmd
, 0,
3094 &pfxdata
, sizeof(pfxdata
), total_data_size
);
3095 return PTR_RET(dcw
);
3098 static struct dasd_ccw_req
*dasd_eckd_build_cp_tpm_track(
3099 struct dasd_device
*startdev
,
3100 struct dasd_block
*block
,
3101 struct request
*req
,
3106 unsigned int first_offs
,
3107 unsigned int last_offs
,
3108 unsigned int blk_per_trk
,
3109 unsigned int blksize
)
3111 struct dasd_ccw_req
*cqr
;
3112 struct req_iterator iter
;
3115 unsigned int trkcount
, ctidaw
;
3117 struct dasd_device
*basedev
;
3120 struct tidaw
*last_tidaw
= NULL
;
3124 unsigned int seg_len
, part_len
, len_to_track_end
;
3125 unsigned char new_track
;
3126 sector_t recid
, trkid
;
3128 unsigned int count
, count_to_trk_end
;
3131 basedev
= block
->base
;
3132 if (rq_data_dir(req
) == READ
) {
3133 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
3134 itcw_op
= ITCW_OP_READ
;
3135 } else if (rq_data_dir(req
) == WRITE
) {
3136 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
3137 itcw_op
= ITCW_OP_WRITE
;
3139 return ERR_PTR(-EINVAL
);
3141 /* trackbased I/O needs address all memory via TIDAWs,
3142 * not just for 64 bit addresses. This allows us to map
3143 * each segment directly to one tidaw.
3144 * In the case of write requests, additional tidaws may
3145 * be needed when a segment crosses a track boundary.
3147 trkcount
= last_trk
- first_trk
+ 1;
3149 rq_for_each_segment(bv
, req
, iter
) {
3152 if (rq_data_dir(req
) == WRITE
)
3153 ctidaw
+= (last_trk
- first_trk
);
3155 /* Allocate the ccw request. */
3156 itcw_size
= itcw_calc_size(0, ctidaw
, 0);
3157 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
3161 /* transfer length factor: how many bytes to read from the last track */
3162 if (first_trk
== last_trk
)
3163 tlf
= last_offs
- first_offs
+ 1;
3165 tlf
= last_offs
+ 1;
3168 itcw
= itcw_init(cqr
->data
, itcw_size
, itcw_op
, 0, ctidaw
, 0);
3173 cqr
->cpaddr
= itcw_get_tcw(itcw
);
3174 if (prepare_itcw(itcw
, first_trk
, last_trk
,
3175 cmd
, basedev
, startdev
,
3178 (last_rec
- first_rec
+ 1) * blksize
,
3179 tlf
, blk_per_trk
) == -EAGAIN
) {
3180 /* Clock not in sync and XRC is enabled.
3186 len_to_track_end
= 0;
3188 * A tidaw can address 4k of memory, but must not cross page boundaries
3189 * We can let the block layer handle this by setting
3190 * blk_queue_segment_boundary to page boundaries and
3191 * blk_max_segment_size to page size when setting up the request queue.
3192 * For write requests, a TIDAW must not cross track boundaries, because
3193 * we have to set the CBC flag on the last tidaw for each track.
3195 if (rq_data_dir(req
) == WRITE
) {
3198 rq_for_each_segment(bv
, req
, iter
) {
3199 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3200 seg_len
= bv
.bv_len
;
3204 offs
= sector_div(trkid
, blk_per_trk
);
3205 count_to_trk_end
= blk_per_trk
- offs
;
3206 count
= min((last_rec
- recid
+ 1),
3207 (sector_t
)count_to_trk_end
);
3208 len_to_track_end
= count
* blksize
;
3212 part_len
= min(seg_len
, len_to_track_end
);
3213 seg_len
-= part_len
;
3214 len_to_track_end
-= part_len
;
3215 /* We need to end the tidaw at track end */
3216 if (!len_to_track_end
) {
3218 tidaw_flags
= TIDAW_FLAGS_INSERT_CBC
;
3221 last_tidaw
= itcw_add_tidaw(itcw
, tidaw_flags
,
3223 if (IS_ERR(last_tidaw
)) {
3231 rq_for_each_segment(bv
, req
, iter
) {
3232 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3233 last_tidaw
= itcw_add_tidaw(itcw
, 0x00,
3235 if (IS_ERR(last_tidaw
)) {
3241 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
3242 last_tidaw
->flags
&= ~TIDAW_FLAGS_INSERT_CBC
;
3243 itcw_finalize(itcw
);
3245 if (blk_noretry_request(req
) ||
3246 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3247 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3249 cqr
->startdev
= startdev
;
3250 cqr
->memdev
= startdev
;
3252 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3253 cqr
->lpm
= startdev
->path_data
.ppm
;
3254 cqr
->retries
= startdev
->default_retries
;
3255 cqr
->buildclk
= get_tod_clock();
3256 cqr
->status
= DASD_CQR_FILLED
;
3259 dasd_sfree_request(cqr
, startdev
);
3260 return ERR_PTR(ret
);
3263 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
3264 struct dasd_block
*block
,
3265 struct request
*req
)
3270 struct dasd_eckd_private
*private;
3271 struct dasd_device
*basedev
;
3272 sector_t first_rec
, last_rec
;
3273 sector_t first_trk
, last_trk
;
3274 unsigned int first_offs
, last_offs
;
3275 unsigned int blk_per_trk
, blksize
;
3277 unsigned int data_size
;
3278 struct dasd_ccw_req
*cqr
;
3280 basedev
= block
->base
;
3281 private = (struct dasd_eckd_private
*) basedev
->private;
3283 /* Calculate number of blocks/records per track. */
3284 blksize
= block
->bp_block
;
3285 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3286 if (blk_per_trk
== 0)
3287 return ERR_PTR(-EINVAL
);
3288 /* Calculate record id of first and last block. */
3289 first_rec
= first_trk
= blk_rq_pos(req
) >> block
->s2b_shift
;
3290 first_offs
= sector_div(first_trk
, blk_per_trk
);
3291 last_rec
= last_trk
=
3292 (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) >> block
->s2b_shift
;
3293 last_offs
= sector_div(last_trk
, blk_per_trk
);
3294 cdlspecial
= (private->uses_cdl
&& first_rec
< 2*blk_per_trk
);
3296 fcx_multitrack
= private->features
.feature
[40] & 0x20;
3297 data_size
= blk_rq_bytes(req
);
3298 if (data_size
% blksize
)
3299 return ERR_PTR(-EINVAL
);
3300 /* tpm write request add CBC data on each track boundary */
3301 if (rq_data_dir(req
) == WRITE
)
3302 data_size
+= (last_trk
- first_trk
) * 4;
3304 /* is read track data and write track data in command mode supported? */
3305 cmdrtd
= private->features
.feature
[9] & 0x20;
3306 cmdwtd
= private->features
.feature
[12] & 0x40;
3307 use_prefix
= private->features
.feature
[8] & 0x01;
3310 if (cdlspecial
|| dasd_page_cache
) {
3311 /* do nothing, just fall through to the cmd mode single case */
3312 } else if ((data_size
<= private->fcx_max_data
)
3313 && (fcx_multitrack
|| (first_trk
== last_trk
))) {
3314 cqr
= dasd_eckd_build_cp_tpm_track(startdev
, block
, req
,
3315 first_rec
, last_rec
,
3316 first_trk
, last_trk
,
3317 first_offs
, last_offs
,
3318 blk_per_trk
, blksize
);
3319 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3320 (PTR_ERR(cqr
) != -ENOMEM
))
3322 } else if (use_prefix
&&
3323 (((rq_data_dir(req
) == READ
) && cmdrtd
) ||
3324 ((rq_data_dir(req
) == WRITE
) && cmdwtd
))) {
3325 cqr
= dasd_eckd_build_cp_cmd_track(startdev
, block
, req
,
3326 first_rec
, last_rec
,
3327 first_trk
, last_trk
,
3328 first_offs
, last_offs
,
3329 blk_per_trk
, blksize
);
3330 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3331 (PTR_ERR(cqr
) != -ENOMEM
))
3335 cqr
= dasd_eckd_build_cp_cmd_single(startdev
, block
, req
,
3336 first_rec
, last_rec
,
3337 first_trk
, last_trk
,
3338 first_offs
, last_offs
,
3339 blk_per_trk
, blksize
);
3343 static struct dasd_ccw_req
*dasd_raw_build_cp(struct dasd_device
*startdev
,
3344 struct dasd_block
*block
,
3345 struct request
*req
)
3347 unsigned long *idaws
;
3348 struct dasd_device
*basedev
;
3349 struct dasd_ccw_req
*cqr
;
3351 struct req_iterator iter
;
3355 unsigned int trkcount
;
3356 unsigned int seg_len
, len_to_track_end
;
3357 unsigned int first_offs
;
3358 unsigned int cidaw
, cplength
, datasize
;
3359 sector_t first_trk
, last_trk
, sectors
;
3360 sector_t start_padding_sectors
, end_sector_offset
, end_padding_sectors
;
3361 unsigned int pfx_datasize
;
3364 * raw track access needs to be mutiple of 64k and on 64k boundary
3365 * For read requests we can fix an incorrect alignment by padding
3366 * the request with dummy pages.
3368 start_padding_sectors
= blk_rq_pos(req
) % DASD_RAW_SECTORS_PER_TRACK
;
3369 end_sector_offset
= (blk_rq_pos(req
) + blk_rq_sectors(req
)) %
3370 DASD_RAW_SECTORS_PER_TRACK
;
3371 end_padding_sectors
= (DASD_RAW_SECTORS_PER_TRACK
- end_sector_offset
) %
3372 DASD_RAW_SECTORS_PER_TRACK
;
3373 basedev
= block
->base
;
3374 if ((start_padding_sectors
|| end_padding_sectors
) &&
3375 (rq_data_dir(req
) == WRITE
)) {
3376 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3377 "raw write not track aligned (%lu,%lu) req %p",
3378 start_padding_sectors
, end_padding_sectors
, req
);
3379 cqr
= ERR_PTR(-EINVAL
);
3383 first_trk
= blk_rq_pos(req
) / DASD_RAW_SECTORS_PER_TRACK
;
3384 last_trk
= (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) /
3385 DASD_RAW_SECTORS_PER_TRACK
;
3386 trkcount
= last_trk
- first_trk
+ 1;
3389 if (rq_data_dir(req
) == READ
)
3390 cmd
= DASD_ECKD_CCW_READ_TRACK
;
3391 else if (rq_data_dir(req
) == WRITE
)
3392 cmd
= DASD_ECKD_CCW_WRITE_FULL_TRACK
;
3394 cqr
= ERR_PTR(-EINVAL
);
3399 * Raw track based I/O needs IDAWs for each page,
3400 * and not just for 64 bit addresses.
3402 cidaw
= trkcount
* DASD_RAW_BLOCK_PER_TRACK
;
3404 /* 1x prefix + one read/write ccw per track */
3405 cplength
= 1 + trkcount
;
3408 * struct PFX_eckd_data has up to 2 byte as extended parameter
3409 * this is needed for write full track and has to be mentioned
3411 * add 8 instead of 2 to keep 8 byte boundary
3413 pfx_datasize
= sizeof(struct PFX_eckd_data
) + 8;
3415 datasize
= pfx_datasize
+ cidaw
* sizeof(unsigned long long);
3417 /* Allocate the ccw request. */
3418 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
3419 datasize
, startdev
);
3424 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
,
3425 basedev
, startdev
, 1 /* format */, first_offs
+ 1,
3426 trkcount
, 0, 0) == -EAGAIN
) {
3427 /* Clock not in sync and XRC is enabled.
3430 dasd_sfree_request(cqr
, startdev
);
3431 cqr
= ERR_PTR(-EAGAIN
);
3435 idaws
= (unsigned long *)(cqr
->data
+ pfx_datasize
);
3436 len_to_track_end
= 0;
3437 if (start_padding_sectors
) {
3438 ccw
[-1].flags
|= CCW_FLAG_CC
;
3439 ccw
->cmd_code
= cmd
;
3440 /* maximum 3390 track size */
3442 /* 64k map to one track */
3443 len_to_track_end
= 65536 - start_padding_sectors
* 512;
3444 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3445 ccw
->flags
|= CCW_FLAG_IDA
;
3446 ccw
->flags
|= CCW_FLAG_SLI
;
3448 for (sectors
= 0; sectors
< start_padding_sectors
; sectors
+= 8)
3449 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3451 rq_for_each_segment(bv
, req
, iter
) {
3452 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3453 seg_len
= bv
.bv_len
;
3454 if (cmd
== DASD_ECKD_CCW_READ_TRACK
)
3455 memset(dst
, 0, seg_len
);
3456 if (!len_to_track_end
) {
3457 ccw
[-1].flags
|= CCW_FLAG_CC
;
3458 ccw
->cmd_code
= cmd
;
3459 /* maximum 3390 track size */
3461 /* 64k map to one track */
3462 len_to_track_end
= 65536;
3463 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3464 ccw
->flags
|= CCW_FLAG_IDA
;
3465 ccw
->flags
|= CCW_FLAG_SLI
;
3468 len_to_track_end
-= seg_len
;
3469 idaws
= idal_create_words(idaws
, dst
, seg_len
);
3471 for (sectors
= 0; sectors
< end_padding_sectors
; sectors
+= 8)
3472 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3473 if (blk_noretry_request(req
) ||
3474 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3475 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3476 cqr
->startdev
= startdev
;
3477 cqr
->memdev
= startdev
;
3479 cqr
->expires
= startdev
->default_expires
* HZ
;
3480 cqr
->lpm
= startdev
->path_data
.ppm
;
3481 cqr
->retries
= startdev
->default_retries
;
3482 cqr
->buildclk
= get_tod_clock();
3483 cqr
->status
= DASD_CQR_FILLED
;
3485 if (IS_ERR(cqr
) && PTR_ERR(cqr
) != -EAGAIN
)
3493 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
3495 struct dasd_eckd_private
*private;
3497 struct req_iterator iter
;
3500 unsigned int blksize
, blk_per_trk
, off
;
3504 if (!dasd_page_cache
)
3506 private = (struct dasd_eckd_private
*) cqr
->block
->base
->private;
3507 blksize
= cqr
->block
->bp_block
;
3508 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3509 recid
= blk_rq_pos(req
) >> cqr
->block
->s2b_shift
;
3511 /* Skip over define extent & locate record. */
3513 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
3515 rq_for_each_segment(bv
, req
, iter
) {
3516 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3517 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
3518 /* Skip locate record. */
3519 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
3522 if (ccw
->flags
& CCW_FLAG_IDA
)
3523 cda
= *((char **)((addr_t
) ccw
->cda
));
3525 cda
= (char *)((addr_t
) ccw
->cda
);
3527 if (rq_data_dir(req
) == READ
)
3528 memcpy(dst
, cda
, bv
.bv_len
);
3529 kmem_cache_free(dasd_page_cache
,
3530 (void *)((addr_t
)cda
& PAGE_MASK
));
3539 status
= cqr
->status
== DASD_CQR_DONE
;
3540 dasd_sfree_request(cqr
, cqr
->memdev
);
3545 * Modify ccw/tcw in cqr so it can be started on a base device.
3547 * Note that this is not enough to restart the cqr!
3548 * Either reset cqr->startdev as well (summary unit check handling)
3549 * or restart via separate cqr (as in ERP handling).
3551 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
3554 struct PFX_eckd_data
*pfxdata
;
3559 if (cqr
->cpmode
== 1) {
3561 tccb
= tcw_get_tccb(tcw
);
3562 dcw
= (struct dcw
*)&tccb
->tca
[0];
3563 pfxdata
= (struct PFX_eckd_data
*)&dcw
->cd
[0];
3564 pfxdata
->validity
.verify_base
= 0;
3565 pfxdata
->validity
.hyper_pav
= 0;
3568 pfxdata
= cqr
->data
;
3569 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
3570 pfxdata
->validity
.verify_base
= 0;
3571 pfxdata
->validity
.hyper_pav
= 0;
3576 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3578 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
3579 struct dasd_block
*block
,
3580 struct request
*req
)
3582 struct dasd_eckd_private
*private;
3583 struct dasd_device
*startdev
;
3584 unsigned long flags
;
3585 struct dasd_ccw_req
*cqr
;
3587 startdev
= dasd_alias_get_start_dev(base
);
3590 private = (struct dasd_eckd_private
*) startdev
->private;
3591 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
3592 return ERR_PTR(-EBUSY
);
3594 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
3596 if ((base
->features
& DASD_FEATURE_USERAW
))
3597 cqr
= dasd_raw_build_cp(startdev
, block
, req
);
3599 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
3602 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
3606 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
3607 struct request
*req
)
3609 struct dasd_eckd_private
*private;
3610 unsigned long flags
;
3612 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3613 private = (struct dasd_eckd_private
*) cqr
->memdev
->private;
3615 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3616 return dasd_eckd_free_cp(cqr
, req
);
3620 dasd_eckd_fill_info(struct dasd_device
* device
,
3621 struct dasd_information2_t
* info
)
3623 struct dasd_eckd_private
*private;
3625 private = (struct dasd_eckd_private
*) device
->private;
3626 info
->label_block
= 2;
3627 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
3628 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
3629 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
3630 memcpy(info
->characteristics
, &private->rdc_data
,
3631 sizeof(struct dasd_eckd_characteristics
));
3632 info
->confdata_size
= min((unsigned long)private->conf_len
,
3633 sizeof(info
->configuration_data
));
3634 memcpy(info
->configuration_data
, private->conf_data
,
3635 info
->confdata_size
);
3640 * SECTION: ioctl functions for eckd devices.
3644 * Release device ioctl.
3645 * Buils a channel programm to releases a prior reserved
3646 * (see dasd_eckd_reserve) device.
3649 dasd_eckd_release(struct dasd_device
*device
)
3651 struct dasd_ccw_req
*cqr
;
3656 if (!capable(CAP_SYS_ADMIN
))
3660 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3662 mutex_lock(&dasd_reserve_mutex
);
3664 cqr
= &dasd_reserve_req
->cqr
;
3665 memset(cqr
, 0, sizeof(*cqr
));
3666 memset(&dasd_reserve_req
->ccw
, 0,
3667 sizeof(dasd_reserve_req
->ccw
));
3668 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3669 cqr
->data
= &dasd_reserve_req
->data
;
3670 cqr
->magic
= DASD_ECKD_MAGIC
;
3673 ccw
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
3674 ccw
->flags
|= CCW_FLAG_SLI
;
3676 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3677 cqr
->startdev
= device
;
3678 cqr
->memdev
= device
;
3679 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3680 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3681 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3682 cqr
->expires
= 2 * HZ
;
3683 cqr
->buildclk
= get_tod_clock();
3684 cqr
->status
= DASD_CQR_FILLED
;
3686 rc
= dasd_sleep_on_immediatly(cqr
);
3688 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3691 mutex_unlock(&dasd_reserve_mutex
);
3693 dasd_sfree_request(cqr
, cqr
->memdev
);
3698 * Reserve device ioctl.
3699 * Options are set to 'synchronous wait for interrupt' and
3700 * 'timeout the request'. This leads to a terminate IO if
3701 * the interrupt is outstanding for a certain time.
3704 dasd_eckd_reserve(struct dasd_device
*device
)
3706 struct dasd_ccw_req
*cqr
;
3711 if (!capable(CAP_SYS_ADMIN
))
3715 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3717 mutex_lock(&dasd_reserve_mutex
);
3719 cqr
= &dasd_reserve_req
->cqr
;
3720 memset(cqr
, 0, sizeof(*cqr
));
3721 memset(&dasd_reserve_req
->ccw
, 0,
3722 sizeof(dasd_reserve_req
->ccw
));
3723 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3724 cqr
->data
= &dasd_reserve_req
->data
;
3725 cqr
->magic
= DASD_ECKD_MAGIC
;
3728 ccw
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
3729 ccw
->flags
|= CCW_FLAG_SLI
;
3731 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3732 cqr
->startdev
= device
;
3733 cqr
->memdev
= device
;
3734 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3735 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3736 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3737 cqr
->expires
= 2 * HZ
;
3738 cqr
->buildclk
= get_tod_clock();
3739 cqr
->status
= DASD_CQR_FILLED
;
3741 rc
= dasd_sleep_on_immediatly(cqr
);
3743 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3746 mutex_unlock(&dasd_reserve_mutex
);
3748 dasd_sfree_request(cqr
, cqr
->memdev
);
3753 * Steal lock ioctl - unconditional reserve device.
3754 * Buils a channel programm to break a device's reservation.
3755 * (unconditional reserve)
3758 dasd_eckd_steal_lock(struct dasd_device
*device
)
3760 struct dasd_ccw_req
*cqr
;
3765 if (!capable(CAP_SYS_ADMIN
))
3769 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3771 mutex_lock(&dasd_reserve_mutex
);
3773 cqr
= &dasd_reserve_req
->cqr
;
3774 memset(cqr
, 0, sizeof(*cqr
));
3775 memset(&dasd_reserve_req
->ccw
, 0,
3776 sizeof(dasd_reserve_req
->ccw
));
3777 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3778 cqr
->data
= &dasd_reserve_req
->data
;
3779 cqr
->magic
= DASD_ECKD_MAGIC
;
3782 ccw
->cmd_code
= DASD_ECKD_CCW_SLCK
;
3783 ccw
->flags
|= CCW_FLAG_SLI
;
3785 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3786 cqr
->startdev
= device
;
3787 cqr
->memdev
= device
;
3788 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3789 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3790 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3791 cqr
->expires
= 2 * HZ
;
3792 cqr
->buildclk
= get_tod_clock();
3793 cqr
->status
= DASD_CQR_FILLED
;
3795 rc
= dasd_sleep_on_immediatly(cqr
);
3797 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3800 mutex_unlock(&dasd_reserve_mutex
);
3802 dasd_sfree_request(cqr
, cqr
->memdev
);
3807 * SNID - Sense Path Group ID
3808 * This ioctl may be used in situations where I/O is stalled due to
3809 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3810 * preallocated dasd_reserve_req.
3812 static int dasd_eckd_snid(struct dasd_device
*device
,
3815 struct dasd_ccw_req
*cqr
;
3819 struct dasd_snid_ioctl_data usrparm
;
3821 if (!capable(CAP_SYS_ADMIN
))
3824 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3828 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1,
3829 sizeof(struct dasd_snid_data
), device
);
3831 mutex_lock(&dasd_reserve_mutex
);
3833 cqr
= &dasd_reserve_req
->cqr
;
3834 memset(cqr
, 0, sizeof(*cqr
));
3835 memset(&dasd_reserve_req
->ccw
, 0,
3836 sizeof(dasd_reserve_req
->ccw
));
3837 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3838 cqr
->data
= &dasd_reserve_req
->data
;
3839 cqr
->magic
= DASD_ECKD_MAGIC
;
3842 ccw
->cmd_code
= DASD_ECKD_CCW_SNID
;
3843 ccw
->flags
|= CCW_FLAG_SLI
;
3845 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3846 cqr
->startdev
= device
;
3847 cqr
->memdev
= device
;
3848 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3849 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3850 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
3852 cqr
->expires
= 10 * HZ
;
3853 cqr
->buildclk
= get_tod_clock();
3854 cqr
->status
= DASD_CQR_FILLED
;
3855 cqr
->lpm
= usrparm
.path_mask
;
3857 rc
= dasd_sleep_on_immediatly(cqr
);
3858 /* verify that I/O processing didn't modify the path mask */
3859 if (!rc
&& usrparm
.path_mask
&& (cqr
->lpm
!= usrparm
.path_mask
))
3862 usrparm
.data
= *((struct dasd_snid_data
*)cqr
->data
);
3863 if (copy_to_user(argp
, &usrparm
, sizeof(usrparm
)))
3868 mutex_unlock(&dasd_reserve_mutex
);
3870 dasd_sfree_request(cqr
, cqr
->memdev
);
3875 * Read performance statistics
3878 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
3880 struct dasd_psf_prssd_data
*prssdp
;
3881 struct dasd_rssd_perf_stats_t
*stats
;
3882 struct dasd_ccw_req
*cqr
;
3886 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
3887 (sizeof(struct dasd_psf_prssd_data
) +
3888 sizeof(struct dasd_rssd_perf_stats_t
)),
3891 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3892 "Could not allocate initialization request");
3893 return PTR_ERR(cqr
);
3895 cqr
->startdev
= device
;
3896 cqr
->memdev
= device
;
3898 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3899 cqr
->expires
= 10 * HZ
;
3901 /* Prepare for Read Subsystem Data */
3902 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3903 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
3904 prssdp
->order
= PSF_ORDER_PRSSD
;
3905 prssdp
->suborder
= 0x01; /* Performance Statistics */
3906 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
3909 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
3910 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
3911 ccw
->flags
|= CCW_FLAG_CC
;
3912 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
3914 /* Read Subsystem Data - Performance Statistics */
3915 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3916 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
3919 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
3920 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
3921 ccw
->cda
= (__u32
)(addr_t
) stats
;
3923 cqr
->buildclk
= get_tod_clock();
3924 cqr
->status
= DASD_CQR_FILLED
;
3925 rc
= dasd_sleep_on(cqr
);
3927 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3928 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3929 if (copy_to_user(argp
, stats
,
3930 sizeof(struct dasd_rssd_perf_stats_t
)))
3933 dasd_sfree_request(cqr
, cqr
->memdev
);
3938 * Get attributes (cache operations)
3939 * Returnes the cache attributes used in Define Extend (DE).
3942 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
3944 struct dasd_eckd_private
*private =
3945 (struct dasd_eckd_private
*)device
->private;
3946 struct attrib_data_t attrib
= private->attrib
;
3949 if (!capable(CAP_SYS_ADMIN
))
3955 if (copy_to_user(argp
, (long *) &attrib
,
3956 sizeof(struct attrib_data_t
)))
3963 * Set attributes (cache operations)
3964 * Stores the attributes for cache operation to be used in Define Extend (DE).
3967 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
3969 struct dasd_eckd_private
*private =
3970 (struct dasd_eckd_private
*)device
->private;
3971 struct attrib_data_t attrib
;
3973 if (!capable(CAP_SYS_ADMIN
))
3978 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
3980 private->attrib
= attrib
;
3982 dev_info(&device
->cdev
->dev
,
3983 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3984 private->attrib
.operation
, private->attrib
.nr_cyl
);
3989 * Issue syscall I/O to EMC Symmetrix array.
3990 * CCWs are PSF and RSSD
3992 static int dasd_symm_io(struct dasd_device
*device
, void __user
*argp
)
3994 struct dasd_symmio_parms usrparm
;
3995 char *psf_data
, *rssd_result
;
3996 struct dasd_ccw_req
*cqr
;
4001 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
4005 /* Copy parms from caller */
4007 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
4009 if (is_compat_task()) {
4010 /* Make sure pointers are sane even on 31 bit. */
4012 if ((usrparm
.psf_data
>> 32) != 0)
4014 if ((usrparm
.rssd_result
>> 32) != 0)
4016 usrparm
.psf_data
&= 0x7fffffffULL
;
4017 usrparm
.rssd_result
&= 0x7fffffffULL
;
4019 /* alloc I/O data area */
4020 psf_data
= kzalloc(usrparm
.psf_data_len
, GFP_KERNEL
| GFP_DMA
);
4021 rssd_result
= kzalloc(usrparm
.rssd_result_len
, GFP_KERNEL
| GFP_DMA
);
4022 if (!psf_data
|| !rssd_result
) {
4027 /* get syscall header from user space */
4029 if (copy_from_user(psf_data
,
4030 (void __user
*)(unsigned long) usrparm
.psf_data
,
4031 usrparm
.psf_data_len
))
4036 /* setup CCWs for PSF + RSSD */
4037 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 2 , 0, device
);
4039 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4040 "Could not allocate initialization request");
4045 cqr
->startdev
= device
;
4046 cqr
->memdev
= device
;
4048 cqr
->expires
= 10 * HZ
;
4049 cqr
->buildclk
= get_tod_clock();
4050 cqr
->status
= DASD_CQR_FILLED
;
4052 /* Build the ccws */
4056 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4057 ccw
->count
= usrparm
.psf_data_len
;
4058 ccw
->flags
|= CCW_FLAG_CC
;
4059 ccw
->cda
= (__u32
)(addr_t
) psf_data
;
4064 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4065 ccw
->count
= usrparm
.rssd_result_len
;
4066 ccw
->flags
= CCW_FLAG_SLI
;
4067 ccw
->cda
= (__u32
)(addr_t
) rssd_result
;
4069 rc
= dasd_sleep_on(cqr
);
4074 if (copy_to_user((void __user
*)(unsigned long) usrparm
.rssd_result
,
4075 rssd_result
, usrparm
.rssd_result_len
))
4080 dasd_sfree_request(cqr
, cqr
->memdev
);
4085 DBF_DEV_EVENT(DBF_WARNING
, device
,
4086 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4087 (int) psf0
, (int) psf1
, rc
);
4092 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
4094 struct dasd_device
*device
= block
->base
;
4098 return dasd_eckd_get_attrib(device
, argp
);
4100 return dasd_eckd_set_attrib(device
, argp
);
4102 return dasd_eckd_performance(device
, argp
);
4104 return dasd_eckd_release(device
);
4106 return dasd_eckd_reserve(device
);
4108 return dasd_eckd_steal_lock(device
);
4110 return dasd_eckd_snid(device
, argp
);
4112 return dasd_symm_io(device
, argp
);
4119 * Dump the range of CCWs into 'page' buffer
4120 * and return number of printed chars.
4123 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
4129 while (from
<= to
) {
4130 len
+= sprintf(page
+ len
, PRINTK_HEADER
4131 " CCW %p: %08X %08X DAT:",
4132 from
, ((int *) from
)[0], ((int *) from
)[1]);
4134 /* get pointer to data (consider IDALs) */
4135 if (from
->flags
& CCW_FLAG_IDA
)
4136 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
4138 datap
= (char *) ((addr_t
) from
->cda
);
4140 /* dump data (max 32 bytes) */
4141 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
4142 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
4143 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
4144 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
4146 len
+= sprintf(page
+ len
, "\n");
4153 dasd_eckd_dump_sense_dbf(struct dasd_device
*device
, struct irb
*irb
,
4159 sense
= (u64
*) dasd_get_sense(irb
);
4160 stat
= (u64
*) &irb
->scsw
;
4162 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : "
4163 "%016llx %016llx %016llx %016llx",
4164 reason
, *stat
, *((u32
*) (stat
+ 1)),
4165 sense
[0], sense
[1], sense
[2], sense
[3]);
4167 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : %s",
4168 reason
, *stat
, *((u32
*) (stat
+ 1)),
4174 * Print sense data and related channel program.
4175 * Parts are printed because printk buffer is only 1024 bytes.
4177 static void dasd_eckd_dump_sense_ccw(struct dasd_device
*device
,
4178 struct dasd_ccw_req
*req
, struct irb
*irb
)
4181 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
4184 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4186 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4187 "No memory to dump sense data\n");
4190 /* dump the sense data */
4191 len
= sprintf(page
, PRINTK_HEADER
4192 " I/O status report for device %s:\n",
4193 dev_name(&device
->cdev
->dev
));
4194 len
+= sprintf(page
+ len
, PRINTK_HEADER
4195 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4197 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4198 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4199 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4200 req
? req
->intrc
: 0);
4201 len
+= sprintf(page
+ len
, PRINTK_HEADER
4202 " device %s: Failing CCW: %p\n",
4203 dev_name(&device
->cdev
->dev
),
4204 (void *) (addr_t
) irb
->scsw
.cmd
.cpa
);
4205 if (irb
->esw
.esw0
.erw
.cons
) {
4206 for (sl
= 0; sl
< 4; sl
++) {
4207 len
+= sprintf(page
+ len
, PRINTK_HEADER
4208 " Sense(hex) %2d-%2d:",
4209 (8 * sl
), ((8 * sl
) + 7));
4211 for (sct
= 0; sct
< 8; sct
++) {
4212 len
+= sprintf(page
+ len
, " %02x",
4213 irb
->ecw
[8 * sl
+ sct
]);
4215 len
+= sprintf(page
+ len
, "\n");
4218 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
4219 /* 24 Byte Sense Data */
4220 sprintf(page
+ len
, PRINTK_HEADER
4221 " 24 Byte: %x MSG %x, "
4222 "%s MSGb to SYSOP\n",
4223 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
4224 irb
->ecw
[1] & 0x10 ? "" : "no");
4226 /* 32 Byte Sense Data */
4227 sprintf(page
+ len
, PRINTK_HEADER
4228 " 32 Byte: Format: %x "
4229 "Exception class %x\n",
4230 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
4233 sprintf(page
+ len
, PRINTK_HEADER
4234 " SORRY - NO VALID SENSE AVAILABLE\n");
4236 printk(KERN_ERR
"%s", page
);
4239 /* req == NULL for unsolicited interrupts */
4240 /* dump the Channel Program (max 140 Bytes per line) */
4241 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4242 first
= req
->cpaddr
;
4243 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
4244 to
= min(first
+ 6, last
);
4245 len
= sprintf(page
, PRINTK_HEADER
4246 " Related CP in req: %p\n", req
);
4247 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
4248 printk(KERN_ERR
"%s", page
);
4250 /* print failing CCW area (maximum 4) */
4251 /* scsw->cda is either valid or zero */
4254 fail
= (struct ccw1
*)(addr_t
)
4255 irb
->scsw
.cmd
.cpa
; /* failing CCW */
4256 if (from
< fail
- 2) {
4257 from
= fail
- 2; /* there is a gap - print header */
4258 len
+= sprintf(page
, PRINTK_HEADER
"......\n");
4260 to
= min(fail
+ 1, last
);
4261 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
4263 /* print last CCWs (maximum 2) */
4264 from
= max(from
, ++to
);
4265 if (from
< last
- 1) {
4266 from
= last
- 1; /* there is a gap - print header */
4267 len
+= sprintf(page
+ len
, PRINTK_HEADER
"......\n");
4269 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
4271 printk(KERN_ERR
"%s", page
);
4273 free_page((unsigned long) page
);
4278 * Print sense data from a tcw.
4280 static void dasd_eckd_dump_sense_tcw(struct dasd_device
*device
,
4281 struct dasd_ccw_req
*req
, struct irb
*irb
)
4284 int len
, sl
, sct
, residual
;
4288 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4290 DBF_DEV_EVENT(DBF_WARNING
, device
, " %s",
4291 "No memory to dump sense data");
4294 /* dump the sense data */
4295 len
= sprintf(page
, PRINTK_HEADER
4296 " I/O status report for device %s:\n",
4297 dev_name(&device
->cdev
->dev
));
4298 len
+= sprintf(page
+ len
, PRINTK_HEADER
4299 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4300 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4301 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4302 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4303 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4304 irb
->scsw
.tm
.fcxs
, irb
->scsw
.tm
.schxs
,
4305 req
? req
->intrc
: 0);
4306 len
+= sprintf(page
+ len
, PRINTK_HEADER
4307 " device %s: Failing TCW: %p\n",
4308 dev_name(&device
->cdev
->dev
),
4309 (void *) (addr_t
) irb
->scsw
.tm
.tcw
);
4313 if (irb
->scsw
.tm
.tcw
&& (irb
->scsw
.tm
.fcxs
& 0x01))
4315 (struct tcw
*)(unsigned long)irb
->scsw
.tm
.tcw
);
4318 len
+= sprintf(page
+ len
, PRINTK_HEADER
4319 " tsb->length %d\n", tsb
->length
);
4320 len
+= sprintf(page
+ len
, PRINTK_HEADER
4321 " tsb->flags %x\n", tsb
->flags
);
4322 len
+= sprintf(page
+ len
, PRINTK_HEADER
4323 " tsb->dcw_offset %d\n", tsb
->dcw_offset
);
4324 len
+= sprintf(page
+ len
, PRINTK_HEADER
4325 " tsb->count %d\n", tsb
->count
);
4326 residual
= tsb
->count
- 28;
4327 len
+= sprintf(page
+ len
, PRINTK_HEADER
4328 " residual %d\n", residual
);
4330 switch (tsb
->flags
& 0x07) {
4331 case 1: /* tsa_iostat */
4332 len
+= sprintf(page
+ len
, PRINTK_HEADER
4333 " tsb->tsa.iostat.dev_time %d\n",
4334 tsb
->tsa
.iostat
.dev_time
);
4335 len
+= sprintf(page
+ len
, PRINTK_HEADER
4336 " tsb->tsa.iostat.def_time %d\n",
4337 tsb
->tsa
.iostat
.def_time
);
4338 len
+= sprintf(page
+ len
, PRINTK_HEADER
4339 " tsb->tsa.iostat.queue_time %d\n",
4340 tsb
->tsa
.iostat
.queue_time
);
4341 len
+= sprintf(page
+ len
, PRINTK_HEADER
4342 " tsb->tsa.iostat.dev_busy_time %d\n",
4343 tsb
->tsa
.iostat
.dev_busy_time
);
4344 len
+= sprintf(page
+ len
, PRINTK_HEADER
4345 " tsb->tsa.iostat.dev_act_time %d\n",
4346 tsb
->tsa
.iostat
.dev_act_time
);
4347 sense
= tsb
->tsa
.iostat
.sense
;
4349 case 2: /* ts_ddpc */
4350 len
+= sprintf(page
+ len
, PRINTK_HEADER
4351 " tsb->tsa.ddpc.rc %d\n", tsb
->tsa
.ddpc
.rc
);
4352 for (sl
= 0; sl
< 2; sl
++) {
4353 len
+= sprintf(page
+ len
, PRINTK_HEADER
4354 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4355 (8 * sl
), ((8 * sl
) + 7));
4356 rcq
= tsb
->tsa
.ddpc
.rcq
;
4357 for (sct
= 0; sct
< 8; sct
++) {
4358 len
+= sprintf(page
+ len
, " %02x",
4361 len
+= sprintf(page
+ len
, "\n");
4363 sense
= tsb
->tsa
.ddpc
.sense
;
4365 case 3: /* tsa_intrg */
4366 len
+= sprintf(page
+ len
, PRINTK_HEADER
4367 " tsb->tsa.intrg.: not supportet yet\n");
4372 for (sl
= 0; sl
< 4; sl
++) {
4373 len
+= sprintf(page
+ len
, PRINTK_HEADER
4374 " Sense(hex) %2d-%2d:",
4375 (8 * sl
), ((8 * sl
) + 7));
4376 for (sct
= 0; sct
< 8; sct
++) {
4377 len
+= sprintf(page
+ len
, " %02x",
4378 sense
[8 * sl
+ sct
]);
4380 len
+= sprintf(page
+ len
, "\n");
4383 if (sense
[27] & DASD_SENSE_BIT_0
) {
4384 /* 24 Byte Sense Data */
4385 sprintf(page
+ len
, PRINTK_HEADER
4386 " 24 Byte: %x MSG %x, "
4387 "%s MSGb to SYSOP\n",
4388 sense
[7] >> 4, sense
[7] & 0x0f,
4389 sense
[1] & 0x10 ? "" : "no");
4391 /* 32 Byte Sense Data */
4392 sprintf(page
+ len
, PRINTK_HEADER
4393 " 32 Byte: Format: %x "
4394 "Exception class %x\n",
4395 sense
[6] & 0x0f, sense
[22] >> 4);
4398 sprintf(page
+ len
, PRINTK_HEADER
4399 " SORRY - NO VALID SENSE AVAILABLE\n");
4402 sprintf(page
+ len
, PRINTK_HEADER
4403 " SORRY - NO TSB DATA AVAILABLE\n");
4405 printk(KERN_ERR
"%s", page
);
4406 free_page((unsigned long) page
);
4409 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
4410 struct dasd_ccw_req
*req
, struct irb
*irb
)
4412 if (scsw_is_tm(&irb
->scsw
))
4413 dasd_eckd_dump_sense_tcw(device
, req
, irb
);
4415 dasd_eckd_dump_sense_ccw(device
, req
, irb
);
4418 static int dasd_eckd_pm_freeze(struct dasd_device
*device
)
4421 * the device should be disconnected from our LCU structure
4422 * on restore we will reconnect it and reread LCU specific
4423 * information like PAV support that might have changed
4425 dasd_alias_remove_device(device
);
4426 dasd_alias_disconnect_device_from_lcu(device
);
4431 static int dasd_eckd_restore_device(struct dasd_device
*device
)
4433 struct dasd_eckd_private
*private;
4434 struct dasd_eckd_characteristics temp_rdc_data
;
4436 struct dasd_uid temp_uid
;
4437 unsigned long flags
;
4438 unsigned long cqr_flags
= 0;
4440 private = (struct dasd_eckd_private
*) device
->private;
4442 /* Read Configuration Data */
4443 rc
= dasd_eckd_read_conf(device
);
4445 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4446 "Read configuration data failed, rc=%d", rc
);
4450 dasd_eckd_get_uid(device
, &temp_uid
);
4451 /* Generate device unique id */
4452 rc
= dasd_eckd_generate_uid(device
);
4453 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4454 if (memcmp(&private->uid
, &temp_uid
, sizeof(struct dasd_uid
)) != 0)
4455 dev_err(&device
->cdev
->dev
, "The UID of the DASD has "
4457 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4461 /* register lcu with alias handling, enable PAV if this is a new lcu */
4462 rc
= dasd_alias_make_device_known_to_lcu(device
);
4466 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr_flags
);
4467 dasd_eckd_validate_server(device
, cqr_flags
);
4469 /* RE-Read Configuration Data */
4470 rc
= dasd_eckd_read_conf(device
);
4472 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4473 "Read configuration data failed, rc=%d", rc
);
4477 /* Read Feature Codes */
4478 dasd_eckd_read_features(device
);
4480 /* Read Device Characteristics */
4481 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
4482 &temp_rdc_data
, 64);
4484 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4485 "Read device characteristic failed, rc=%d", rc
);
4488 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4489 memcpy(&private->rdc_data
, &temp_rdc_data
, sizeof(temp_rdc_data
));
4490 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4492 /* add device to alias management */
4493 dasd_alias_add_device(device
);
4498 dasd_alias_disconnect_device_from_lcu(device
);
4503 static int dasd_eckd_reload_device(struct dasd_device
*device
)
4505 struct dasd_eckd_private
*private;
4508 struct dasd_uid uid
;
4509 unsigned long flags
;
4511 private = (struct dasd_eckd_private
*) device
->private;
4513 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4514 old_base
= private->uid
.base_unit_addr
;
4515 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4517 /* Read Configuration Data */
4518 rc
= dasd_eckd_read_conf(device
);
4522 rc
= dasd_eckd_generate_uid(device
);
4526 * update unit address configuration and
4527 * add device to alias management
4529 dasd_alias_update_add_device(device
);
4531 dasd_eckd_get_uid(device
, &uid
);
4533 if (old_base
!= uid
.base_unit_addr
) {
4534 if (strlen(uid
.vduit
) > 0)
4535 snprintf(print_uid
, sizeof(print_uid
),
4536 "%s.%s.%04x.%02x.%s", uid
.vendor
, uid
.serial
,
4537 uid
.ssid
, uid
.base_unit_addr
, uid
.vduit
);
4539 snprintf(print_uid
, sizeof(print_uid
),
4540 "%s.%s.%04x.%02x", uid
.vendor
, uid
.serial
,
4541 uid
.ssid
, uid
.base_unit_addr
);
4543 dev_info(&device
->cdev
->dev
,
4544 "An Alias device was reassigned to a new base device "
4545 "with UID: %s\n", print_uid
);
4553 static int dasd_eckd_read_message_buffer(struct dasd_device
*device
,
4554 struct dasd_rssd_messages
*messages
,
4557 struct dasd_rssd_messages
*message_buf
;
4558 struct dasd_psf_prssd_data
*prssdp
;
4559 struct dasd_eckd_private
*private;
4560 struct dasd_ccw_req
*cqr
;
4564 private = (struct dasd_eckd_private
*) device
->private;
4565 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
4566 (sizeof(struct dasd_psf_prssd_data
) +
4567 sizeof(struct dasd_rssd_messages
)),
4570 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
4571 "Could not allocate read message buffer request");
4572 return PTR_ERR(cqr
);
4575 cqr
->startdev
= device
;
4576 cqr
->memdev
= device
;
4578 cqr
->expires
= 10 * HZ
;
4579 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
4580 /* dasd_sleep_on_immediatly does not do complex error
4581 * recovery so clear erp flag and set retry counter to
4583 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4586 /* Prepare for Read Subsystem Data */
4587 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4588 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
4589 prssdp
->order
= PSF_ORDER_PRSSD
;
4590 prssdp
->suborder
= 0x03; /* Message Buffer */
4591 /* all other bytes of prssdp must be zero */
4594 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4595 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
4596 ccw
->flags
|= CCW_FLAG_CC
;
4597 ccw
->flags
|= CCW_FLAG_SLI
;
4598 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
4600 /* Read Subsystem Data - message buffer */
4601 message_buf
= (struct dasd_rssd_messages
*) (prssdp
+ 1);
4602 memset(message_buf
, 0, sizeof(struct dasd_rssd_messages
));
4605 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4606 ccw
->count
= sizeof(struct dasd_rssd_messages
);
4607 ccw
->flags
|= CCW_FLAG_SLI
;
4608 ccw
->cda
= (__u32
)(addr_t
) message_buf
;
4610 cqr
->buildclk
= get_tod_clock();
4611 cqr
->status
= DASD_CQR_FILLED
;
4612 rc
= dasd_sleep_on_immediatly(cqr
);
4614 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4615 message_buf
= (struct dasd_rssd_messages
*)
4617 memcpy(messages
, message_buf
,
4618 sizeof(struct dasd_rssd_messages
));
4620 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4621 "Reading messages failed with rc=%d\n"
4623 dasd_sfree_request(cqr
, cqr
->memdev
);
4628 * Perform Subsystem Function - CUIR response
4631 dasd_eckd_psf_cuir_response(struct dasd_device
*device
, int response
,
4633 struct channel_path_desc
*desc
,
4634 struct subchannel_id sch_id
)
4636 struct dasd_psf_cuir_response
*psf_cuir
;
4637 struct dasd_ccw_req
*cqr
;
4641 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
4642 sizeof(struct dasd_psf_cuir_response
),
4646 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4647 "Could not allocate PSF-CUIR request");
4648 return PTR_ERR(cqr
);
4651 psf_cuir
= (struct dasd_psf_cuir_response
*)cqr
->data
;
4652 psf_cuir
->order
= PSF_ORDER_CUIR_RESPONSE
;
4653 psf_cuir
->cc
= response
;
4655 psf_cuir
->chpid
= desc
->chpid
;
4656 psf_cuir
->message_id
= message_id
;
4657 psf_cuir
->cssid
= sch_id
.cssid
;
4658 psf_cuir
->ssid
= sch_id
.ssid
;
4660 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4661 ccw
->cda
= (__u32
)(addr_t
)psf_cuir
;
4662 ccw
->flags
= CCW_FLAG_SLI
;
4663 ccw
->count
= sizeof(struct dasd_psf_cuir_response
);
4665 cqr
->startdev
= device
;
4666 cqr
->memdev
= device
;
4669 cqr
->expires
= 10*HZ
;
4670 cqr
->buildclk
= get_tod_clock();
4671 cqr
->status
= DASD_CQR_FILLED
;
4672 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
4674 rc
= dasd_sleep_on(cqr
);
4676 dasd_sfree_request(cqr
, cqr
->memdev
);
4681 * return configuration data that is referenced by record selector
4682 * if a record selector is specified or per default return the
4683 * conf_data pointer for the path specified by lpum
4685 static struct dasd_conf_data
*dasd_eckd_get_ref_conf(struct dasd_device
*device
,
4687 struct dasd_cuir_message
*cuir
)
4689 struct dasd_eckd_private
*private;
4690 struct dasd_conf_data
*conf_data
;
4693 private = (struct dasd_eckd_private
*) device
->private;
4694 if (cuir
->record_selector
== 0)
4696 for (path
= 0x80, pos
= 0; path
; path
>>= 1, pos
++) {
4697 conf_data
= private->path_conf_data
[pos
];
4698 if (conf_data
->gneq
.record_selector
==
4699 cuir
->record_selector
)
4703 return private->path_conf_data
[pathmask_to_pos(lpum
)];
4707 * This function determines the scope of a reconfiguration request by
4708 * analysing the path and device selection data provided in the CUIR request.
4709 * Returns a path mask containing CUIR affected paths for the give device.
4711 * If the CUIR request does not contain the required information return the
4712 * path mask of the path the attention message for the CUIR request was reveived
4715 static int dasd_eckd_cuir_scope(struct dasd_device
*device
, __u8 lpum
,
4716 struct dasd_cuir_message
*cuir
)
4718 struct dasd_conf_data
*ref_conf_data
;
4719 unsigned long bitmask
= 0, mask
= 0;
4720 struct dasd_eckd_private
*private;
4721 struct dasd_conf_data
*conf_data
;
4722 unsigned int pos
, path
;
4723 char *ref_gneq
, *gneq
;
4724 char *ref_ned
, *ned
;
4727 /* if CUIR request does not specify the scope use the path
4728 the attention message was presented on */
4729 if (!cuir
->ned_map
||
4730 !(cuir
->neq_map
[0] | cuir
->neq_map
[1] | cuir
->neq_map
[2]))
4733 private = (struct dasd_eckd_private
*) device
->private;
4734 /* get reference conf data */
4735 ref_conf_data
= dasd_eckd_get_ref_conf(device
, lpum
, cuir
);
4736 /* reference ned is determined by ned_map field */
4737 pos
= 8 - ffs(cuir
->ned_map
);
4738 ref_ned
= (char *)&ref_conf_data
->neds
[pos
];
4739 ref_gneq
= (char *)&ref_conf_data
->gneq
;
4740 /* transfer 24 bit neq_map to mask */
4741 mask
= cuir
->neq_map
[2];
4742 mask
|= cuir
->neq_map
[1] << 8;
4743 mask
|= cuir
->neq_map
[0] << 16;
4745 for (path
= 0x80; path
; path
>>= 1) {
4746 /* initialise data per path */
4748 pos
= pathmask_to_pos(path
);
4749 conf_data
= private->path_conf_data
[pos
];
4750 pos
= 8 - ffs(cuir
->ned_map
);
4751 ned
= (char *) &conf_data
->neds
[pos
];
4752 /* compare reference ned and per path ned */
4753 if (memcmp(ref_ned
, ned
, sizeof(*ned
)) != 0)
4755 gneq
= (char *)&conf_data
->gneq
;
4756 /* compare reference gneq and per_path gneq under
4757 24 bit mask where mask bit 0 equals byte 7 of
4758 the gneq and mask bit 24 equals byte 31 */
4760 pos
= ffs(bitmask
) - 1;
4761 if (memcmp(&ref_gneq
[31 - pos
], &gneq
[31 - pos
], 1)
4764 clear_bit(pos
, &bitmask
);
4768 /* device and path match the reference values
4769 add path to CUIR scope */
4775 static void dasd_eckd_cuir_notify_user(struct dasd_device
*device
,
4776 unsigned long paths
,
4777 struct subchannel_id sch_id
, int action
)
4779 struct channel_path_desc
*desc
;
4783 /* get position of bit in mask */
4784 pos
= ffs(paths
) - 1;
4785 /* get channel path descriptor from this position */
4786 desc
= ccw_device_get_chp_desc(device
->cdev
, 7 - pos
);
4787 if (action
== CUIR_QUIESCE
)
4788 pr_warn("Service on the storage server caused path "
4789 "%x.%02x to go offline", sch_id
.cssid
,
4790 desc
? desc
->chpid
: 0);
4791 else if (action
== CUIR_RESUME
)
4792 pr_info("Path %x.%02x is back online after service "
4793 "on the storage server", sch_id
.cssid
,
4794 desc
? desc
->chpid
: 0);
4796 clear_bit(pos
, &paths
);
4800 static int dasd_eckd_cuir_remove_path(struct dasd_device
*device
, __u8 lpum
,
4801 struct dasd_cuir_message
*cuir
)
4803 unsigned long tbcpm
;
4805 tbcpm
= dasd_eckd_cuir_scope(device
, lpum
, cuir
);
4806 /* nothing to do if path is not in use */
4807 if (!(device
->path_data
.opm
& tbcpm
))
4809 if (!(device
->path_data
.opm
& ~tbcpm
)) {
4810 /* no path would be left if the CUIR action is taken
4814 /* remove device from operational path mask */
4815 device
->path_data
.opm
&= ~tbcpm
;
4816 device
->path_data
.cuirpm
|= tbcpm
;
4821 * walk through all devices and build a path mask to quiesce them
4822 * return an error if the last path to a device would be removed
4824 * if only part of the devices are quiesced and an error
4825 * occurs no onlining necessary, the storage server will
4826 * notify the already set offline devices again
4828 static int dasd_eckd_cuir_quiesce(struct dasd_device
*device
, __u8 lpum
,
4829 struct subchannel_id sch_id
,
4830 struct dasd_cuir_message
*cuir
)
4832 struct alias_pav_group
*pavgroup
, *tempgroup
;
4833 struct dasd_eckd_private
*private;
4834 struct dasd_device
*dev
, *n
;
4835 unsigned long paths
= 0;
4836 unsigned long flags
;
4839 private = (struct dasd_eckd_private
*) device
->private;
4840 /* active devices */
4841 list_for_each_entry_safe(dev
, n
, &private->lcu
->active_devices
,
4843 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4844 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4845 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
4850 /* inactive devices */
4851 list_for_each_entry_safe(dev
, n
, &private->lcu
->inactive_devices
,
4853 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4854 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4855 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
4860 /* devices in PAV groups */
4861 list_for_each_entry_safe(pavgroup
, tempgroup
,
4862 &private->lcu
->grouplist
, group
) {
4863 list_for_each_entry_safe(dev
, n
, &pavgroup
->baselist
,
4865 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4866 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4867 spin_unlock_irqrestore(
4868 get_ccwdev_lock(dev
->cdev
), flags
);
4873 list_for_each_entry_safe(dev
, n
, &pavgroup
->aliaslist
,
4875 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4876 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4877 spin_unlock_irqrestore(
4878 get_ccwdev_lock(dev
->cdev
), flags
);
4884 /* notify user about all paths affected by CUIR action */
4885 dasd_eckd_cuir_notify_user(device
, paths
, sch_id
, CUIR_QUIESCE
);
4891 static int dasd_eckd_cuir_resume(struct dasd_device
*device
, __u8 lpum
,
4892 struct subchannel_id sch_id
,
4893 struct dasd_cuir_message
*cuir
)
4895 struct alias_pav_group
*pavgroup
, *tempgroup
;
4896 struct dasd_eckd_private
*private;
4897 struct dasd_device
*dev
, *n
;
4898 unsigned long paths
= 0;
4901 private = (struct dasd_eckd_private
*) device
->private;
4903 * the path may have been added through a generic path event before
4904 * only trigger path verification if the path is not already in use
4906 list_for_each_entry_safe(dev
, n
,
4907 &private->lcu
->active_devices
,
4909 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4911 if (!(dev
->path_data
.opm
& tbcpm
)) {
4912 dev
->path_data
.tbvpm
|= tbcpm
;
4913 dasd_schedule_device_bh(dev
);
4916 list_for_each_entry_safe(dev
, n
,
4917 &private->lcu
->inactive_devices
,
4919 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4921 if (!(dev
->path_data
.opm
& tbcpm
)) {
4922 dev
->path_data
.tbvpm
|= tbcpm
;
4923 dasd_schedule_device_bh(dev
);
4926 /* devices in PAV groups */
4927 list_for_each_entry_safe(pavgroup
, tempgroup
,
4928 &private->lcu
->grouplist
,
4930 list_for_each_entry_safe(dev
, n
,
4931 &pavgroup
->baselist
,
4933 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4935 if (!(dev
->path_data
.opm
& tbcpm
)) {
4936 dev
->path_data
.tbvpm
|= tbcpm
;
4937 dasd_schedule_device_bh(dev
);
4940 list_for_each_entry_safe(dev
, n
,
4941 &pavgroup
->aliaslist
,
4943 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4945 if (!(dev
->path_data
.opm
& tbcpm
)) {
4946 dev
->path_data
.tbvpm
|= tbcpm
;
4947 dasd_schedule_device_bh(dev
);
4951 /* notify user about all paths affected by CUIR action */
4952 dasd_eckd_cuir_notify_user(device
, paths
, sch_id
, CUIR_RESUME
);
4956 static void dasd_eckd_handle_cuir(struct dasd_device
*device
, void *messages
,
4959 struct dasd_cuir_message
*cuir
= messages
;
4960 struct channel_path_desc
*desc
;
4961 struct subchannel_id sch_id
;
4964 DBF_DEV_EVENT(DBF_WARNING
, device
,
4965 "CUIR request: %016llx %016llx %016llx %08x",
4966 ((u64
*)cuir
)[0], ((u64
*)cuir
)[1], ((u64
*)cuir
)[2],
4968 ccw_device_get_schid(device
->cdev
, &sch_id
);
4969 pos
= pathmask_to_pos(lpum
);
4970 desc
= ccw_device_get_chp_desc(device
->cdev
, pos
);
4972 if (cuir
->code
== CUIR_QUIESCE
) {
4974 if (dasd_eckd_cuir_quiesce(device
, lpum
, sch_id
, cuir
))
4975 response
= PSF_CUIR_LAST_PATH
;
4977 response
= PSF_CUIR_COMPLETED
;
4978 } else if (cuir
->code
== CUIR_RESUME
) {
4980 dasd_eckd_cuir_resume(device
, lpum
, sch_id
, cuir
);
4981 response
= PSF_CUIR_COMPLETED
;
4983 response
= PSF_CUIR_NOT_SUPPORTED
;
4985 dasd_eckd_psf_cuir_response(device
, response
,
4986 cuir
->message_id
, desc
, sch_id
);
4987 DBF_DEV_EVENT(DBF_WARNING
, device
,
4988 "CUIR response: %d on message ID %08x", response
,
4990 /* free descriptor copy */
4992 /* to make sure there is no attention left schedule work again */
4993 device
->discipline
->check_attention(device
, lpum
);
4996 static void dasd_eckd_check_attention_work(struct work_struct
*work
)
4998 struct check_attention_work_data
*data
;
4999 struct dasd_rssd_messages
*messages
;
5000 struct dasd_device
*device
;
5003 data
= container_of(work
, struct check_attention_work_data
, worker
);
5004 device
= data
->device
;
5005 messages
= kzalloc(sizeof(*messages
), GFP_KERNEL
);
5007 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
5008 "Could not allocate attention message buffer");
5011 rc
= dasd_eckd_read_message_buffer(device
, messages
, data
->lpum
);
5014 if (messages
->length
== ATTENTION_LENGTH_CUIR
&&
5015 messages
->format
== ATTENTION_FORMAT_CUIR
)
5016 dasd_eckd_handle_cuir(device
, messages
, data
->lpum
);
5018 dasd_put_device(device
);
5023 static int dasd_eckd_check_attention(struct dasd_device
*device
, __u8 lpum
)
5025 struct check_attention_work_data
*data
;
5027 data
= kzalloc(sizeof(*data
), GFP_ATOMIC
);
5030 INIT_WORK(&data
->worker
, dasd_eckd_check_attention_work
);
5031 dasd_get_device(device
);
5032 data
->device
= device
;
5034 schedule_work(&data
->worker
);
5038 static struct ccw_driver dasd_eckd_driver
= {
5040 .name
= "dasd-eckd",
5041 .owner
= THIS_MODULE
,
5043 .ids
= dasd_eckd_ids
,
5044 .probe
= dasd_eckd_probe
,
5045 .remove
= dasd_generic_remove
,
5046 .set_offline
= dasd_generic_set_offline
,
5047 .set_online
= dasd_eckd_set_online
,
5048 .notify
= dasd_generic_notify
,
5049 .path_event
= dasd_generic_path_event
,
5050 .shutdown
= dasd_generic_shutdown
,
5051 .freeze
= dasd_generic_pm_freeze
,
5052 .thaw
= dasd_generic_restore_device
,
5053 .restore
= dasd_generic_restore_device
,
5054 .uc_handler
= dasd_generic_uc_handler
,
5055 .int_class
= IRQIO_DAS
,
5059 * max_blocks is dependent on the amount of storage that is available
5060 * in the static io buffer for each device. Currently each device has
5061 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5062 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5063 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5064 * addition we have one define extent ccw + 16 bytes of data and one
5065 * locate record ccw + 16 bytes of data. That makes:
5066 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5067 * We want to fit two into the available memory so that we can immediately
5068 * start the next request if one finishes off. That makes 249.5 blocks
5069 * for one request. Give a little safety and the result is 240.
5071 static struct dasd_discipline dasd_eckd_discipline
= {
5072 .owner
= THIS_MODULE
,
5076 .check_device
= dasd_eckd_check_characteristics
,
5077 .uncheck_device
= dasd_eckd_uncheck_device
,
5078 .do_analysis
= dasd_eckd_do_analysis
,
5079 .verify_path
= dasd_eckd_verify_path
,
5080 .basic_to_ready
= dasd_eckd_basic_to_ready
,
5081 .online_to_ready
= dasd_eckd_online_to_ready
,
5082 .basic_to_known
= dasd_eckd_basic_to_known
,
5083 .fill_geometry
= dasd_eckd_fill_geometry
,
5084 .start_IO
= dasd_start_IO
,
5085 .term_IO
= dasd_term_IO
,
5086 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
5087 .format_device
= dasd_eckd_format_device
,
5088 .erp_action
= dasd_eckd_erp_action
,
5089 .erp_postaction
= dasd_eckd_erp_postaction
,
5090 .check_for_device_change
= dasd_eckd_check_for_device_change
,
5091 .build_cp
= dasd_eckd_build_alias_cp
,
5092 .free_cp
= dasd_eckd_free_alias_cp
,
5093 .dump_sense
= dasd_eckd_dump_sense
,
5094 .dump_sense_dbf
= dasd_eckd_dump_sense_dbf
,
5095 .fill_info
= dasd_eckd_fill_info
,
5096 .ioctl
= dasd_eckd_ioctl
,
5097 .freeze
= dasd_eckd_pm_freeze
,
5098 .restore
= dasd_eckd_restore_device
,
5099 .reload
= dasd_eckd_reload_device
,
5100 .get_uid
= dasd_eckd_get_uid
,
5101 .kick_validate
= dasd_eckd_kick_validate_server
,
5102 .check_attention
= dasd_eckd_check_attention
,
5106 dasd_eckd_init(void)
5110 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
5111 dasd_reserve_req
= kmalloc(sizeof(*dasd_reserve_req
),
5112 GFP_KERNEL
| GFP_DMA
);
5113 if (!dasd_reserve_req
)
5115 path_verification_worker
= kmalloc(sizeof(*path_verification_worker
),
5116 GFP_KERNEL
| GFP_DMA
);
5117 if (!path_verification_worker
) {
5118 kfree(dasd_reserve_req
);
5121 rawpadpage
= (void *)__get_free_page(GFP_KERNEL
);
5123 kfree(path_verification_worker
);
5124 kfree(dasd_reserve_req
);
5127 ret
= ccw_driver_register(&dasd_eckd_driver
);
5129 wait_for_device_probe();
5131 kfree(path_verification_worker
);
5132 kfree(dasd_reserve_req
);
5133 free_page((unsigned long)rawpadpage
);
5139 dasd_eckd_cleanup(void)
5141 ccw_driver_unregister(&dasd_eckd_driver
);
5142 kfree(path_verification_worker
);
5143 kfree(dasd_reserve_req
);
5144 free_page((unsigned long)rawpadpage
);
5147 module_init(dasd_eckd_init
);
5148 module_exit(dasd_eckd_cleanup
);