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 int dasd_eckd_read_conf(struct dasd_device
*device
)
1038 int conf_len
, conf_data_saved
;
1041 struct dasd_eckd_private
*private, path_private
;
1042 struct dasd_path
*path_data
;
1043 struct dasd_uid
*uid
;
1044 char print_path_uid
[60], print_device_uid
[60];
1046 private = (struct dasd_eckd_private
*) device
->private;
1047 path_data
= &device
->path_data
;
1048 opm
= ccw_device_get_path_mask(device
->cdev
);
1049 conf_data_saved
= 0;
1051 /* get configuration data per operational path */
1052 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1055 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
1057 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
1058 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1059 "Read configuration data returned "
1063 if (conf_data
== NULL
) {
1064 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1065 "No configuration data "
1067 /* no further analysis possible */
1068 path_data
->opm
|= lpm
;
1069 continue; /* no error */
1071 /* save first valid configuration data */
1072 if (!conf_data_saved
) {
1073 kfree(private->conf_data
);
1074 private->conf_data
= conf_data
;
1075 private->conf_len
= conf_len
;
1076 if (dasd_eckd_identify_conf_parts(private)) {
1077 private->conf_data
= NULL
;
1078 private->conf_len
= 0;
1083 * build device UID that other path data
1084 * can be compared to it
1086 dasd_eckd_generate_uid(device
);
1089 path_private
.conf_data
= conf_data
;
1090 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1091 if (dasd_eckd_identify_conf_parts(
1093 path_private
.conf_data
= NULL
;
1094 path_private
.conf_len
= 0;
1099 if (dasd_eckd_compare_path_uid(
1100 device
, &path_private
)) {
1101 uid
= &path_private
.uid
;
1102 if (strlen(uid
->vduit
) > 0)
1103 snprintf(print_path_uid
,
1104 sizeof(print_path_uid
),
1105 "%s.%s.%04x.%02x.%s",
1106 uid
->vendor
, uid
->serial
,
1107 uid
->ssid
, uid
->real_unit_addr
,
1110 snprintf(print_path_uid
,
1111 sizeof(print_path_uid
),
1113 uid
->vendor
, uid
->serial
,
1115 uid
->real_unit_addr
);
1116 uid
= &private->uid
;
1117 if (strlen(uid
->vduit
) > 0)
1118 snprintf(print_device_uid
,
1119 sizeof(print_device_uid
),
1120 "%s.%s.%04x.%02x.%s",
1121 uid
->vendor
, uid
->serial
,
1122 uid
->ssid
, uid
->real_unit_addr
,
1125 snprintf(print_device_uid
,
1126 sizeof(print_device_uid
),
1128 uid
->vendor
, uid
->serial
,
1130 uid
->real_unit_addr
);
1131 dev_err(&device
->cdev
->dev
,
1132 "Not all channel paths lead to "
1133 "the same device, path %02X leads to "
1134 "device %s instead of %s\n", lpm
,
1135 print_path_uid
, print_device_uid
);
1137 path_data
->cablepm
|= lpm
;
1141 path_private
.conf_data
= NULL
;
1142 path_private
.conf_len
= 0;
1144 switch (dasd_eckd_path_access(conf_data
, conf_len
)) {
1146 path_data
->npm
|= lpm
;
1149 path_data
->ppm
|= lpm
;
1152 path_data
->opm
|= lpm
;
1154 * if the path is used
1155 * it should not be in one of the negative lists
1157 path_data
->cablepm
&= ~lpm
;
1158 path_data
->hpfpm
&= ~lpm
;
1159 path_data
->cuirpm
&= ~lpm
;
1161 if (conf_data
!= private->conf_data
)
1168 static int verify_fcx_max_data(struct dasd_device
*device
, __u8 lpm
)
1170 struct dasd_eckd_private
*private;
1174 private = (struct dasd_eckd_private
*) device
->private;
1175 if (private->fcx_max_data
) {
1176 mdc
= ccw_device_get_mdc(device
->cdev
, lpm
);
1178 dev_warn(&device
->cdev
->dev
,
1179 "Detecting the maximum data size for zHPF "
1180 "requests failed (rc=%d) for a new path %x\n",
1184 fcx_max_data
= mdc
* FCX_MAX_DATA_FACTOR
;
1185 if (fcx_max_data
< private->fcx_max_data
) {
1186 dev_warn(&device
->cdev
->dev
,
1187 "The maximum data size for zHPF requests %u "
1188 "on a new path %x is below the active maximum "
1189 "%u\n", fcx_max_data
, lpm
,
1190 private->fcx_max_data
);
1197 static int rebuild_device_uid(struct dasd_device
*device
,
1198 struct path_verification_work_data
*data
)
1200 struct dasd_eckd_private
*private;
1201 struct dasd_path
*path_data
;
1206 private = (struct dasd_eckd_private
*) device
->private;
1207 path_data
= &device
->path_data
;
1208 opm
= device
->path_data
.opm
;
1210 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1213 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1214 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1215 data
->cqr
.cpaddr
= &data
->ccw
;
1216 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1221 if (rc
== -EOPNOTSUPP
) /* -EOPNOTSUPP is ok */
1223 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1224 "Read configuration data "
1225 "returned error %d", rc
);
1228 memcpy(private->conf_data
, data
->rcd_buffer
,
1229 DASD_ECKD_RCD_DATA_SIZE
);
1230 if (dasd_eckd_identify_conf_parts(private)) {
1232 } else /* first valid path is enough */
1237 rc
= dasd_eckd_generate_uid(device
);
1242 static void do_path_verification_work(struct work_struct
*work
)
1244 struct path_verification_work_data
*data
;
1245 struct dasd_device
*device
;
1246 struct dasd_eckd_private path_private
;
1247 struct dasd_uid
*uid
;
1248 __u8 path_rcd_buf
[DASD_ECKD_RCD_DATA_SIZE
];
1249 __u8 lpm
, opm
, npm
, ppm
, epm
, hpfpm
, cablepm
;
1250 unsigned long flags
;
1254 data
= container_of(work
, struct path_verification_work_data
, worker
);
1255 device
= data
->device
;
1257 /* delay path verification until device was resumed */
1258 if (test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
1259 schedule_work(work
);
1270 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1271 if (!(lpm
& data
->tbvpm
))
1273 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1274 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1275 data
->cqr
.cpaddr
= &data
->ccw
;
1276 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1280 switch (dasd_eckd_path_access(data
->rcd_buffer
,
1281 DASD_ECKD_RCD_DATA_SIZE
)
1291 } else if (rc
== -EOPNOTSUPP
) {
1292 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1293 "path verification: No configuration "
1296 } else if (rc
== -EAGAIN
) {
1297 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1298 "path verification: device is stopped,"
1299 " try again later");
1302 dev_warn(&device
->cdev
->dev
,
1303 "Reading device feature codes failed "
1304 "(rc=%d) for new path %x\n", rc
, lpm
);
1307 if (verify_fcx_max_data(device
, lpm
)) {
1316 * save conf_data for comparison after
1317 * rebuild_device_uid may have changed
1320 memcpy(&path_rcd_buf
, data
->rcd_buffer
,
1321 DASD_ECKD_RCD_DATA_SIZE
);
1322 path_private
.conf_data
= (void *) &path_rcd_buf
;
1323 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1324 if (dasd_eckd_identify_conf_parts(&path_private
)) {
1325 path_private
.conf_data
= NULL
;
1326 path_private
.conf_len
= 0;
1331 * compare path UID with device UID only if at least
1332 * one valid path is left
1333 * in other case the device UID may have changed and
1334 * the first working path UID will be used as device UID
1336 if (device
->path_data
.opm
&&
1337 dasd_eckd_compare_path_uid(device
, &path_private
)) {
1339 * the comparison was not successful
1340 * rebuild the device UID with at least one
1341 * known path in case a z/VM hyperswap command
1342 * has changed the device
1344 * after this compare again
1346 * if either the rebuild or the recompare fails
1347 * the path can not be used
1349 if (rebuild_device_uid(device
, data
) ||
1350 dasd_eckd_compare_path_uid(
1351 device
, &path_private
)) {
1352 uid
= &path_private
.uid
;
1353 if (strlen(uid
->vduit
) > 0)
1354 snprintf(print_uid
, sizeof(print_uid
),
1355 "%s.%s.%04x.%02x.%s",
1356 uid
->vendor
, uid
->serial
,
1357 uid
->ssid
, uid
->real_unit_addr
,
1360 snprintf(print_uid
, sizeof(print_uid
),
1362 uid
->vendor
, uid
->serial
,
1364 uid
->real_unit_addr
);
1365 dev_err(&device
->cdev
->dev
,
1366 "The newly added channel path %02X "
1367 "will not be used because it leads "
1368 "to a different device %s\n",
1379 * There is a small chance that a path is lost again between
1380 * above path verification and the following modification of
1381 * the device opm mask. We could avoid that race here by using
1382 * yet another path mask, but we rather deal with this unlikely
1383 * situation in dasd_start_IO.
1385 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1386 if (!device
->path_data
.opm
&& opm
) {
1387 device
->path_data
.opm
= opm
;
1388 device
->path_data
.cablepm
&= ~opm
;
1389 device
->path_data
.cuirpm
&= ~opm
;
1390 device
->path_data
.hpfpm
&= ~opm
;
1391 dasd_generic_path_operational(device
);
1393 device
->path_data
.opm
|= opm
;
1394 device
->path_data
.cablepm
&= ~opm
;
1395 device
->path_data
.cuirpm
&= ~opm
;
1396 device
->path_data
.hpfpm
&= ~opm
;
1398 device
->path_data
.npm
|= npm
;
1399 device
->path_data
.ppm
|= ppm
;
1400 device
->path_data
.tbvpm
|= epm
;
1401 device
->path_data
.cablepm
|= cablepm
;
1402 device
->path_data
.hpfpm
|= hpfpm
;
1403 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1406 dasd_put_device(device
);
1408 mutex_unlock(&dasd_path_verification_mutex
);
1413 static int dasd_eckd_verify_path(struct dasd_device
*device
, __u8 lpm
)
1415 struct path_verification_work_data
*data
;
1417 data
= kmalloc(sizeof(*data
), GFP_ATOMIC
| GFP_DMA
);
1419 if (mutex_trylock(&dasd_path_verification_mutex
)) {
1420 data
= path_verification_worker
;
1425 memset(data
, 0, sizeof(*data
));
1428 INIT_WORK(&data
->worker
, do_path_verification_work
);
1429 dasd_get_device(device
);
1430 data
->device
= device
;
1432 schedule_work(&data
->worker
);
1436 static int dasd_eckd_read_features(struct dasd_device
*device
)
1438 struct dasd_psf_prssd_data
*prssdp
;
1439 struct dasd_rssd_features
*features
;
1440 struct dasd_ccw_req
*cqr
;
1443 struct dasd_eckd_private
*private;
1445 private = (struct dasd_eckd_private
*) device
->private;
1446 memset(&private->features
, 0, sizeof(struct dasd_rssd_features
));
1447 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
1448 (sizeof(struct dasd_psf_prssd_data
) +
1449 sizeof(struct dasd_rssd_features
)),
1452 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s", "Could not "
1453 "allocate initialization request");
1454 return PTR_ERR(cqr
);
1456 cqr
->startdev
= device
;
1457 cqr
->memdev
= device
;
1460 cqr
->expires
= 10 * HZ
;
1462 /* Prepare for Read Subsystem Data */
1463 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1464 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1465 prssdp
->order
= PSF_ORDER_PRSSD
;
1466 prssdp
->suborder
= 0x41; /* Read Feature Codes */
1467 /* all other bytes of prssdp must be zero */
1470 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1471 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1472 ccw
->flags
|= CCW_FLAG_CC
;
1473 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1475 /* Read Subsystem Data - feature codes */
1476 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1477 memset(features
, 0, sizeof(struct dasd_rssd_features
));
1480 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1481 ccw
->count
= sizeof(struct dasd_rssd_features
);
1482 ccw
->cda
= (__u32
)(addr_t
) features
;
1484 cqr
->buildclk
= get_tod_clock();
1485 cqr
->status
= DASD_CQR_FILLED
;
1486 rc
= dasd_sleep_on(cqr
);
1488 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1489 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1490 memcpy(&private->features
, features
,
1491 sizeof(struct dasd_rssd_features
));
1493 dev_warn(&device
->cdev
->dev
, "Reading device feature codes"
1494 " failed with rc=%d\n", rc
);
1495 dasd_sfree_request(cqr
, cqr
->memdev
);
1501 * Build CP for Perform Subsystem Function - SSC.
1503 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
,
1506 struct dasd_ccw_req
*cqr
;
1507 struct dasd_psf_ssc_data
*psf_ssc_data
;
1510 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
1511 sizeof(struct dasd_psf_ssc_data
),
1515 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1516 "Could not allocate PSF-SSC request");
1519 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
1520 psf_ssc_data
->order
= PSF_ORDER_SSC
;
1521 psf_ssc_data
->suborder
= 0xc0;
1523 psf_ssc_data
->suborder
|= 0x08;
1524 psf_ssc_data
->reserved
[0] = 0x88;
1527 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1528 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
1531 cqr
->startdev
= device
;
1532 cqr
->memdev
= device
;
1535 cqr
->expires
= 10*HZ
;
1536 cqr
->buildclk
= get_tod_clock();
1537 cqr
->status
= DASD_CQR_FILLED
;
1542 * Perform Subsystem Function.
1543 * It is necessary to trigger CIO for channel revalidation since this
1544 * call might change behaviour of DASD devices.
1547 dasd_eckd_psf_ssc(struct dasd_device
*device
, int enable_pav
,
1548 unsigned long flags
)
1550 struct dasd_ccw_req
*cqr
;
1553 cqr
= dasd_eckd_build_psf_ssc(device
, enable_pav
);
1555 return PTR_ERR(cqr
);
1558 * set flags e.g. turn on failfast, to prevent blocking
1559 * the calling function should handle failed requests
1561 cqr
->flags
|= flags
;
1563 rc
= dasd_sleep_on(cqr
);
1565 /* trigger CIO to reprobe devices */
1566 css_schedule_reprobe();
1567 else if (cqr
->intrc
== -EAGAIN
)
1570 dasd_sfree_request(cqr
, cqr
->memdev
);
1575 * Valide storage server of current device.
1577 static int dasd_eckd_validate_server(struct dasd_device
*device
,
1578 unsigned long flags
)
1581 struct dasd_eckd_private
*private;
1584 private = (struct dasd_eckd_private
*) device
->private;
1585 if (private->uid
.type
== UA_BASE_PAV_ALIAS
||
1586 private->uid
.type
== UA_HYPER_PAV_ALIAS
)
1588 if (dasd_nopav
|| MACHINE_IS_VM
)
1592 rc
= dasd_eckd_psf_ssc(device
, enable_pav
, flags
);
1594 /* may be requested feature is not available on server,
1595 * therefore just report error and go ahead */
1596 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "PSF-SSC for SSID %04x "
1597 "returned rc=%d", private->uid
.ssid
, rc
);
1602 * worker to do a validate server in case of a lost pathgroup
1604 static void dasd_eckd_do_validate_server(struct work_struct
*work
)
1606 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
1608 unsigned long flags
= 0;
1610 set_bit(DASD_CQR_FLAGS_FAILFAST
, &flags
);
1611 if (dasd_eckd_validate_server(device
, flags
)
1613 /* schedule worker again if failed */
1614 schedule_work(&device
->kick_validate
);
1618 dasd_put_device(device
);
1621 static void dasd_eckd_kick_validate_server(struct dasd_device
*device
)
1623 dasd_get_device(device
);
1624 /* exit if device not online or in offline processing */
1625 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1626 device
->state
< DASD_STATE_ONLINE
) {
1627 dasd_put_device(device
);
1630 /* queue call to do_validate_server to the kernel event daemon. */
1631 if (!schedule_work(&device
->kick_validate
))
1632 dasd_put_device(device
);
1635 static u32
get_fcx_max_data(struct dasd_device
*device
)
1638 int fcx_in_css
, fcx_in_gneq
, fcx_in_features
;
1639 struct dasd_eckd_private
*private;
1643 /* is transport mode supported? */
1644 private = (struct dasd_eckd_private
*) device
->private;
1645 fcx_in_css
= css_general_characteristics
.fcx
;
1646 fcx_in_gneq
= private->gneq
->reserved2
[7] & 0x04;
1647 fcx_in_features
= private->features
.feature
[40] & 0x80;
1648 tpm
= fcx_in_css
&& fcx_in_gneq
&& fcx_in_features
;
1653 mdc
= ccw_device_get_mdc(device
->cdev
, 0);
1655 dev_warn(&device
->cdev
->dev
, "Detecting the maximum supported"
1656 " data size for zHPF requests failed\n");
1659 return mdc
* FCX_MAX_DATA_FACTOR
;
1663 * Check device characteristics.
1664 * If the device is accessible using ECKD discipline, the device is enabled.
1667 dasd_eckd_check_characteristics(struct dasd_device
*device
)
1669 struct dasd_eckd_private
*private;
1670 struct dasd_block
*block
;
1671 struct dasd_uid temp_uid
;
1674 unsigned long value
;
1676 /* setup work queue for validate server*/
1677 INIT_WORK(&device
->kick_validate
, dasd_eckd_do_validate_server
);
1679 if (!ccw_device_is_pathgroup(device
->cdev
)) {
1680 dev_warn(&device
->cdev
->dev
,
1681 "A channel path group could not be established\n");
1684 if (!ccw_device_is_multipath(device
->cdev
)) {
1685 dev_info(&device
->cdev
->dev
,
1686 "The DASD is not operating in multipath mode\n");
1688 private = (struct dasd_eckd_private
*) device
->private;
1690 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
1692 dev_warn(&device
->cdev
->dev
,
1693 "Allocating memory for private DASD data "
1697 device
->private = (void *) private;
1699 memset(private, 0, sizeof(*private));
1701 /* Invalidate status of initial analysis. */
1702 private->init_cqr_status
= -1;
1703 /* Set default cache operations. */
1704 private->attrib
.operation
= DASD_NORMAL_CACHE
;
1705 private->attrib
.nr_cyl
= 0;
1707 /* Read Configuration Data */
1708 rc
= dasd_eckd_read_conf(device
);
1712 /* set default timeout */
1713 device
->default_expires
= DASD_EXPIRES
;
1714 /* set default retry count */
1715 device
->default_retries
= DASD_RETRIES
;
1717 if (private->gneq
) {
1719 for (i
= 0; i
< private->gneq
->timeout
.value
; i
++)
1721 value
= value
* private->gneq
->timeout
.number
;
1722 /* do not accept useless values */
1723 if (value
!= 0 && value
<= DASD_EXPIRES_MAX
)
1724 device
->default_expires
= value
;
1727 dasd_eckd_get_uid(device
, &temp_uid
);
1728 if (temp_uid
.type
== UA_BASE_DEVICE
) {
1729 block
= dasd_alloc_block();
1730 if (IS_ERR(block
)) {
1731 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1732 "could not allocate dasd "
1734 rc
= PTR_ERR(block
);
1737 device
->block
= block
;
1738 block
->base
= device
;
1741 /* register lcu with alias handling, enable PAV */
1742 rc
= dasd_alias_make_device_known_to_lcu(device
);
1746 dasd_eckd_validate_server(device
, 0);
1748 /* device may report different configuration data after LCU setup */
1749 rc
= dasd_eckd_read_conf(device
);
1753 /* Read Feature Codes */
1754 dasd_eckd_read_features(device
);
1756 /* Read Device Characteristics */
1757 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
1758 &private->rdc_data
, 64);
1760 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1761 "Read device characteristic failed, rc=%d", rc
);
1765 if ((device
->features
& DASD_FEATURE_USERAW
) &&
1766 !(private->rdc_data
.facilities
.RT_in_LR
)) {
1767 dev_err(&device
->cdev
->dev
, "The storage server does not "
1768 "support raw-track access\n");
1773 /* find the valid cylinder size */
1774 if (private->rdc_data
.no_cyl
== LV_COMPAT_CYL
&&
1775 private->rdc_data
.long_no_cyl
)
1776 private->real_cyl
= private->rdc_data
.long_no_cyl
;
1778 private->real_cyl
= private->rdc_data
.no_cyl
;
1780 private->fcx_max_data
= get_fcx_max_data(device
);
1782 readonly
= dasd_device_is_ro(device
);
1784 set_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
1786 dev_info(&device
->cdev
->dev
, "New DASD %04X/%02X (CU %04X/%02X) "
1787 "with %d cylinders, %d heads, %d sectors%s\n",
1788 private->rdc_data
.dev_type
,
1789 private->rdc_data
.dev_model
,
1790 private->rdc_data
.cu_type
,
1791 private->rdc_data
.cu_model
.model
,
1793 private->rdc_data
.trk_per_cyl
,
1794 private->rdc_data
.sec_per_trk
,
1795 readonly
? ", read-only device" : "");
1799 dasd_alias_disconnect_device_from_lcu(device
);
1801 dasd_free_block(device
->block
);
1802 device
->block
= NULL
;
1804 kfree(private->conf_data
);
1805 kfree(device
->private);
1806 device
->private = NULL
;
1810 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
1812 struct dasd_eckd_private
*private;
1814 private = (struct dasd_eckd_private
*) device
->private;
1815 dasd_alias_disconnect_device_from_lcu(device
);
1816 private->ned
= NULL
;
1817 private->sneq
= NULL
;
1818 private->vdsneq
= NULL
;
1819 private->gneq
= NULL
;
1820 private->conf_len
= 0;
1821 kfree(private->conf_data
);
1822 private->conf_data
= NULL
;
1825 static struct dasd_ccw_req
*
1826 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
1828 struct dasd_eckd_private
*private;
1829 struct eckd_count
*count_data
;
1830 struct LO_eckd_data
*LO_data
;
1831 struct dasd_ccw_req
*cqr
;
1833 int cplength
, datasize
;
1836 private = (struct dasd_eckd_private
*) device
->private;
1839 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
1840 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
1844 /* Define extent for the first 3 tracks. */
1845 define_extent(ccw
++, cqr
->data
, 0, 2,
1846 DASD_ECKD_CCW_READ_COUNT
, device
);
1847 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
1848 /* Locate record for the first 4 records on track 0. */
1849 ccw
[-1].flags
|= CCW_FLAG_CC
;
1850 locate_record(ccw
++, LO_data
++, 0, 0, 4,
1851 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1853 count_data
= private->count_area
;
1854 for (i
= 0; i
< 4; i
++) {
1855 ccw
[-1].flags
|= CCW_FLAG_CC
;
1856 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1859 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1864 /* Locate record for the first record on track 2. */
1865 ccw
[-1].flags
|= CCW_FLAG_CC
;
1866 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1867 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1868 /* Read count ccw. */
1869 ccw
[-1].flags
|= CCW_FLAG_CC
;
1870 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1873 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1876 cqr
->startdev
= device
;
1877 cqr
->memdev
= device
;
1879 cqr
->buildclk
= get_tod_clock();
1880 cqr
->status
= DASD_CQR_FILLED
;
1884 /* differentiate between 'no record found' and any other error */
1885 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req
*init_cqr
)
1888 if (init_cqr
->status
== DASD_CQR_DONE
)
1890 else if (init_cqr
->status
== DASD_CQR_NEED_ERP
||
1891 init_cqr
->status
== DASD_CQR_FAILED
) {
1892 sense
= dasd_get_sense(&init_cqr
->irb
);
1893 if (sense
&& (sense
[1] & SNS1_NO_REC_FOUND
))
1894 return INIT_CQR_UNFORMATTED
;
1896 return INIT_CQR_ERROR
;
1898 return INIT_CQR_ERROR
;
1902 * This is the callback function for the init_analysis cqr. It saves
1903 * the status of the initial analysis ccw before it frees it and kicks
1904 * the device to continue the startup sequence. This will call
1905 * dasd_eckd_do_analysis again (if the devices has not been marked
1906 * for deletion in the meantime).
1908 static void dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
,
1911 struct dasd_eckd_private
*private;
1912 struct dasd_device
*device
;
1914 device
= init_cqr
->startdev
;
1915 private = (struct dasd_eckd_private
*) device
->private;
1916 private->init_cqr_status
= dasd_eckd_analysis_evaluation(init_cqr
);
1917 dasd_sfree_request(init_cqr
, device
);
1918 dasd_kick_device(device
);
1921 static int dasd_eckd_start_analysis(struct dasd_block
*block
)
1923 struct dasd_ccw_req
*init_cqr
;
1925 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1926 if (IS_ERR(init_cqr
))
1927 return PTR_ERR(init_cqr
);
1928 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1929 init_cqr
->callback_data
= NULL
;
1930 init_cqr
->expires
= 5*HZ
;
1931 /* first try without ERP, so we can later handle unformatted
1932 * devices as special case
1934 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &init_cqr
->flags
);
1935 init_cqr
->retries
= 0;
1936 dasd_add_request_head(init_cqr
);
1940 static int dasd_eckd_end_analysis(struct dasd_block
*block
)
1942 struct dasd_device
*device
;
1943 struct dasd_eckd_private
*private;
1944 struct eckd_count
*count_area
;
1945 unsigned int sb
, blk_per_trk
;
1947 struct dasd_ccw_req
*init_cqr
;
1949 device
= block
->base
;
1950 private = (struct dasd_eckd_private
*) device
->private;
1951 status
= private->init_cqr_status
;
1952 private->init_cqr_status
= -1;
1953 if (status
== INIT_CQR_ERROR
) {
1954 /* try again, this time with full ERP */
1955 init_cqr
= dasd_eckd_analysis_ccw(device
);
1956 dasd_sleep_on(init_cqr
);
1957 status
= dasd_eckd_analysis_evaluation(init_cqr
);
1958 dasd_sfree_request(init_cqr
, device
);
1961 if (device
->features
& DASD_FEATURE_USERAW
) {
1962 block
->bp_block
= DASD_RAW_BLOCKSIZE
;
1963 blk_per_trk
= DASD_RAW_BLOCK_PER_TRACK
;
1964 block
->s2b_shift
= 3;
1968 if (status
== INIT_CQR_UNFORMATTED
) {
1969 dev_warn(&device
->cdev
->dev
, "The DASD is not formatted\n");
1970 return -EMEDIUMTYPE
;
1971 } else if (status
== INIT_CQR_ERROR
) {
1972 dev_err(&device
->cdev
->dev
,
1973 "Detecting the DASD disk layout failed because "
1974 "of an I/O error\n");
1978 private->uses_cdl
= 1;
1979 /* Check Track 0 for Compatible Disk Layout */
1981 for (i
= 0; i
< 3; i
++) {
1982 if (private->count_area
[i
].kl
!= 4 ||
1983 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4 ||
1984 private->count_area
[i
].cyl
!= 0 ||
1985 private->count_area
[i
].head
!= count_area_head
[i
] ||
1986 private->count_area
[i
].record
!= count_area_rec
[i
]) {
1987 private->uses_cdl
= 0;
1992 count_area
= &private->count_area
[4];
1994 if (private->uses_cdl
== 0) {
1995 for (i
= 0; i
< 5; i
++) {
1996 if ((private->count_area
[i
].kl
!= 0) ||
1997 (private->count_area
[i
].dl
!=
1998 private->count_area
[0].dl
) ||
1999 private->count_area
[i
].cyl
!= 0 ||
2000 private->count_area
[i
].head
!= count_area_head
[i
] ||
2001 private->count_area
[i
].record
!= count_area_rec
[i
])
2005 count_area
= &private->count_area
[0];
2007 if (private->count_area
[3].record
== 1)
2008 dev_warn(&device
->cdev
->dev
,
2009 "Track 0 has no records following the VTOC\n");
2012 if (count_area
!= NULL
&& count_area
->kl
== 0) {
2013 /* we found notthing violating our disk layout */
2014 if (dasd_check_blocksize(count_area
->dl
) == 0)
2015 block
->bp_block
= count_area
->dl
;
2017 if (block
->bp_block
== 0) {
2018 dev_warn(&device
->cdev
->dev
,
2019 "The disk layout of the DASD is not supported\n");
2020 return -EMEDIUMTYPE
;
2022 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
2023 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
2026 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
2029 block
->blocks
= (private->real_cyl
*
2030 private->rdc_data
.trk_per_cyl
*
2033 dev_info(&device
->cdev
->dev
,
2034 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2035 "%s\n", (block
->bp_block
>> 10),
2036 ((private->real_cyl
*
2037 private->rdc_data
.trk_per_cyl
*
2038 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
2039 ((blk_per_trk
* block
->bp_block
) >> 10),
2041 "compatible disk layout" : "linux disk layout");
2046 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
2048 struct dasd_eckd_private
*private;
2050 private = (struct dasd_eckd_private
*) block
->base
->private;
2051 if (private->init_cqr_status
< 0)
2052 return dasd_eckd_start_analysis(block
);
2054 return dasd_eckd_end_analysis(block
);
2057 static int dasd_eckd_basic_to_ready(struct dasd_device
*device
)
2059 return dasd_alias_add_device(device
);
2062 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
2064 cancel_work_sync(&device
->reload_device
);
2065 cancel_work_sync(&device
->kick_validate
);
2069 static int dasd_eckd_basic_to_known(struct dasd_device
*device
)
2071 return dasd_alias_remove_device(device
);
2075 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
2077 struct dasd_eckd_private
*private;
2079 private = (struct dasd_eckd_private
*) block
->base
->private;
2080 if (dasd_check_blocksize(block
->bp_block
) == 0) {
2081 geo
->sectors
= recs_per_track(&private->rdc_data
,
2082 0, block
->bp_block
);
2084 geo
->cylinders
= private->rdc_data
.no_cyl
;
2085 geo
->heads
= private->rdc_data
.trk_per_cyl
;
2089 static struct dasd_ccw_req
*
2090 dasd_eckd_build_format(struct dasd_device
*base
,
2091 struct format_data_t
*fdata
,
2094 struct dasd_eckd_private
*base_priv
;
2095 struct dasd_eckd_private
*start_priv
;
2096 struct dasd_device
*startdev
= NULL
;
2097 struct dasd_ccw_req
*fcp
;
2098 struct eckd_count
*ect
;
2099 struct ch_t address
;
2103 int cplength
, datasize
;
2111 startdev
= dasd_alias_get_start_dev(base
);
2116 start_priv
= (struct dasd_eckd_private
*) startdev
->private;
2117 base_priv
= (struct dasd_eckd_private
*) base
->private;
2119 rpt
= recs_per_track(&base_priv
->rdc_data
, 0, fdata
->blksize
);
2121 nr_tracks
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2124 * fdata->intensity is a bit string that tells us what to do:
2125 * Bit 0: write record zero
2126 * Bit 1: write home address, currently not supported
2127 * Bit 2: invalidate tracks
2128 * Bit 3: use OS/390 compatible disk layout (cdl)
2129 * Bit 4: do not allow storage subsystem to modify record zero
2130 * Only some bit combinations do make sense.
2132 if (fdata
->intensity
& 0x10) {
2134 intensity
= fdata
->intensity
& ~0x10;
2137 intensity
= fdata
->intensity
;
2140 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
2142 switch (intensity
) {
2143 case 0x00: /* Normal format */
2144 case 0x08: /* Normal format, use cdl. */
2145 cplength
= 2 + (rpt
*nr_tracks
);
2147 datasize
= sizeof(struct PFX_eckd_data
) +
2148 sizeof(struct LO_eckd_data
) +
2149 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2151 datasize
= sizeof(struct DE_eckd_data
) +
2152 sizeof(struct LO_eckd_data
) +
2153 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2155 case 0x01: /* Write record zero and format track. */
2156 case 0x09: /* Write record zero and format track, use cdl. */
2157 cplength
= 2 + rpt
* nr_tracks
;
2159 datasize
= sizeof(struct PFX_eckd_data
) +
2160 sizeof(struct LO_eckd_data
) +
2161 sizeof(struct eckd_count
) +
2162 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2164 datasize
= sizeof(struct DE_eckd_data
) +
2165 sizeof(struct LO_eckd_data
) +
2166 sizeof(struct eckd_count
) +
2167 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2169 case 0x04: /* Invalidate track. */
2170 case 0x0c: /* Invalidate track, use cdl. */
2173 datasize
= sizeof(struct PFX_eckd_data
) +
2174 sizeof(struct LO_eckd_data
) +
2175 sizeof(struct eckd_count
);
2177 datasize
= sizeof(struct DE_eckd_data
) +
2178 sizeof(struct LO_eckd_data
) +
2179 sizeof(struct eckd_count
);
2182 dev_warn(&startdev
->cdev
->dev
,
2183 "An I/O control call used incorrect flags 0x%x\n",
2185 return ERR_PTR(-EINVAL
);
2187 /* Allocate the format ccw request. */
2188 fcp
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
2189 datasize
, startdev
);
2193 start_priv
->count
++;
2197 switch (intensity
& ~0x08) {
2198 case 0x00: /* Normal format. */
2200 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2201 fdata
->start_unit
, fdata
->stop_unit
,
2202 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2203 /* grant subsystem permission to format R0 */
2205 ((struct PFX_eckd_data
*)data
)
2206 ->define_extent
.ga_extended
|= 0x04;
2207 data
+= sizeof(struct PFX_eckd_data
);
2209 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2210 fdata
->start_unit
, fdata
->stop_unit
,
2211 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2212 /* grant subsystem permission to format R0 */
2214 ((struct DE_eckd_data
*) data
)
2215 ->ga_extended
|= 0x04;
2216 data
+= sizeof(struct DE_eckd_data
);
2218 ccw
[-1].flags
|= CCW_FLAG_CC
;
2219 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2220 fdata
->start_unit
, 0, rpt
*nr_tracks
,
2221 DASD_ECKD_CCW_WRITE_CKD
, base
,
2223 data
+= sizeof(struct LO_eckd_data
);
2225 case 0x01: /* Write record zero + format track. */
2227 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2228 fdata
->start_unit
, fdata
->stop_unit
,
2229 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
2231 data
+= sizeof(struct PFX_eckd_data
);
2233 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2234 fdata
->start_unit
, fdata
->stop_unit
,
2235 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, startdev
);
2236 data
+= sizeof(struct DE_eckd_data
);
2238 ccw
[-1].flags
|= CCW_FLAG_CC
;
2239 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2240 fdata
->start_unit
, 0, rpt
* nr_tracks
+ 1,
2241 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, base
,
2242 base
->block
->bp_block
);
2243 data
+= sizeof(struct LO_eckd_data
);
2245 case 0x04: /* Invalidate track. */
2247 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2248 fdata
->start_unit
, fdata
->stop_unit
,
2249 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2250 data
+= sizeof(struct PFX_eckd_data
);
2252 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2253 fdata
->start_unit
, fdata
->stop_unit
,
2254 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2255 data
+= sizeof(struct DE_eckd_data
);
2257 ccw
[-1].flags
|= CCW_FLAG_CC
;
2258 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2259 fdata
->start_unit
, 0, 1,
2260 DASD_ECKD_CCW_WRITE_CKD
, base
, 8);
2261 data
+= sizeof(struct LO_eckd_data
);
2265 for (j
= 0; j
< nr_tracks
; j
++) {
2266 /* calculate cylinder and head for the current track */
2268 (fdata
->start_unit
+ j
) /
2269 base_priv
->rdc_data
.trk_per_cyl
,
2270 (fdata
->start_unit
+ j
) %
2271 base_priv
->rdc_data
.trk_per_cyl
);
2272 if (intensity
& 0x01) { /* write record zero */
2273 ect
= (struct eckd_count
*) data
;
2274 data
+= sizeof(struct eckd_count
);
2275 ect
->cyl
= address
.cyl
;
2276 ect
->head
= address
.head
;
2280 ccw
[-1].flags
|= CCW_FLAG_CC
;
2281 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
2282 ccw
->flags
= CCW_FLAG_SLI
;
2284 ccw
->cda
= (__u32
)(addr_t
) ect
;
2287 if ((intensity
& ~0x08) & 0x04) { /* erase track */
2288 ect
= (struct eckd_count
*) data
;
2289 data
+= sizeof(struct eckd_count
);
2290 ect
->cyl
= address
.cyl
;
2291 ect
->head
= address
.head
;
2295 ccw
[-1].flags
|= CCW_FLAG_CC
;
2296 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2297 ccw
->flags
= CCW_FLAG_SLI
;
2299 ccw
->cda
= (__u32
)(addr_t
) ect
;
2300 } else { /* write remaining records */
2301 for (i
= 0; i
< rpt
; i
++) {
2302 ect
= (struct eckd_count
*) data
;
2303 data
+= sizeof(struct eckd_count
);
2304 ect
->cyl
= address
.cyl
;
2305 ect
->head
= address
.head
;
2306 ect
->record
= i
+ 1;
2308 ect
->dl
= fdata
->blksize
;
2310 * Check for special tracks 0-1
2311 * when formatting CDL
2313 if ((intensity
& 0x08) &&
2314 fdata
->start_unit
== 0) {
2317 ect
->dl
= sizes_trk0
[i
] - 4;
2320 if ((intensity
& 0x08) &&
2321 fdata
->start_unit
== 1) {
2323 ect
->dl
= LABEL_SIZE
- 44;
2325 ccw
[-1].flags
|= CCW_FLAG_CC
;
2326 if (i
!= 0 || j
== 0)
2328 DASD_ECKD_CCW_WRITE_CKD
;
2331 DASD_ECKD_CCW_WRITE_CKD_MT
;
2332 ccw
->flags
= CCW_FLAG_SLI
;
2334 ccw
->cda
= (__u32
)(addr_t
) ect
;
2340 fcp
->startdev
= startdev
;
2341 fcp
->memdev
= startdev
;
2342 fcp
->basedev
= base
;
2344 fcp
->expires
= startdev
->default_expires
* HZ
;
2345 fcp
->buildclk
= get_tod_clock();
2346 fcp
->status
= DASD_CQR_FILLED
;
2352 dasd_eckd_format_device(struct dasd_device
*base
,
2353 struct format_data_t
*fdata
,
2356 struct dasd_ccw_req
*cqr
, *n
;
2357 struct dasd_block
*block
;
2358 struct dasd_eckd_private
*private;
2359 struct list_head format_queue
;
2360 struct dasd_device
*device
;
2361 int old_stop
, format_step
;
2362 int step
, rc
= 0, sleep_rc
;
2364 block
= base
->block
;
2365 private = (struct dasd_eckd_private
*) base
->private;
2367 /* Sanity checks. */
2368 if (fdata
->start_unit
>=
2369 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2370 dev_warn(&base
->cdev
->dev
,
2371 "Start track number %u used in formatting is too big\n",
2375 if (fdata
->stop_unit
>=
2376 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2377 dev_warn(&base
->cdev
->dev
,
2378 "Stop track number %u used in formatting is too big\n",
2382 if (fdata
->start_unit
> fdata
->stop_unit
) {
2383 dev_warn(&base
->cdev
->dev
,
2384 "Start track %u used in formatting exceeds end track\n",
2388 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
2389 dev_warn(&base
->cdev
->dev
,
2390 "The DASD cannot be formatted with block size %u\n",
2395 INIT_LIST_HEAD(&format_queue
);
2397 old_stop
= fdata
->stop_unit
;
2398 while (fdata
->start_unit
<= 1) {
2399 fdata
->stop_unit
= fdata
->start_unit
;
2400 cqr
= dasd_eckd_build_format(base
, fdata
, enable_pav
);
2401 list_add(&cqr
->blocklist
, &format_queue
);
2403 fdata
->stop_unit
= old_stop
;
2404 fdata
->start_unit
++;
2406 if (fdata
->start_unit
> fdata
->stop_unit
)
2411 format_step
= 255 / recs_per_track(&private->rdc_data
, 0,
2413 while (fdata
->start_unit
<= old_stop
) {
2414 step
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2415 if (step
> format_step
)
2416 fdata
->stop_unit
= fdata
->start_unit
+ format_step
- 1;
2418 cqr
= dasd_eckd_build_format(base
, fdata
, enable_pav
);
2420 if (PTR_ERR(cqr
) == -ENOMEM
) {
2422 * not enough memory available
2423 * go to out and start requests
2424 * retry after first requests were finished
2426 fdata
->stop_unit
= old_stop
;
2429 return PTR_ERR(cqr
);
2431 list_add(&cqr
->blocklist
, &format_queue
);
2433 fdata
->start_unit
= fdata
->stop_unit
+ 1;
2434 fdata
->stop_unit
= old_stop
;
2438 sleep_rc
= dasd_sleep_on_queue(&format_queue
);
2440 list_for_each_entry_safe(cqr
, n
, &format_queue
, blocklist
) {
2441 device
= cqr
->startdev
;
2442 private = (struct dasd_eckd_private
*) device
->private;
2443 if (cqr
->status
== DASD_CQR_FAILED
)
2445 list_del_init(&cqr
->blocklist
);
2446 dasd_sfree_request(cqr
, device
);
2454 * in case of ENOMEM we need to retry after
2455 * first requests are finished
2457 if (fdata
->start_unit
<= fdata
->stop_unit
)
2463 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
2465 if (cqr
->retries
< 0) {
2466 cqr
->status
= DASD_CQR_FAILED
;
2469 cqr
->status
= DASD_CQR_FILLED
;
2470 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
2471 dasd_eckd_reset_ccw_to_base_io(cqr
);
2472 cqr
->startdev
= cqr
->block
->base
;
2473 cqr
->lpm
= cqr
->block
->base
->path_data
.opm
;
2477 static dasd_erp_fn_t
2478 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
2480 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
2481 struct ccw_device
*cdev
= device
->cdev
;
2483 switch (cdev
->id
.cu_type
) {
2488 return dasd_3990_erp_action
;
2492 return dasd_default_erp_action
;
2496 static dasd_erp_fn_t
2497 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
2499 return dasd_default_erp_postaction
;
2502 static void dasd_eckd_check_for_device_change(struct dasd_device
*device
,
2503 struct dasd_ccw_req
*cqr
,
2508 struct dasd_eckd_private
*private;
2510 private = (struct dasd_eckd_private
*) device
->private;
2511 /* first of all check for state change pending interrupt */
2512 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
2513 if ((scsw_dstat(&irb
->scsw
) & mask
) == mask
) {
2515 * for alias only, not in offline processing
2516 * and only if not suspended
2518 if (!device
->block
&& private->lcu
&&
2519 device
->state
== DASD_STATE_ONLINE
&&
2520 !test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
2521 !test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
2523 * the state change could be caused by an alias
2524 * reassignment remove device from alias handling
2525 * to prevent new requests from being scheduled on
2526 * the wrong alias device
2528 dasd_alias_remove_device(device
);
2530 /* schedule worker to reload device */
2531 dasd_reload_device(device
);
2533 dasd_generic_handle_state_change(device
);
2537 sense
= dasd_get_sense(irb
);
2541 /* summary unit check */
2542 if ((sense
[27] & DASD_SENSE_BIT_0
) && (sense
[7] == 0x0D) &&
2543 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
)) {
2544 dasd_alias_handle_summary_unit_check(device
, irb
);
2548 /* service information message SIM */
2549 if (!cqr
&& !(sense
[27] & DASD_SENSE_BIT_0
) &&
2550 ((sense
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
)) {
2551 dasd_3990_erp_handle_sim(device
, sense
);
2555 /* loss of device reservation is handled via base devices only
2556 * as alias devices may be used with several bases
2558 if (device
->block
&& (sense
[27] & DASD_SENSE_BIT_0
) &&
2559 (sense
[7] == 0x3F) &&
2560 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
) &&
2561 test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
)) {
2562 if (device
->features
& DASD_FEATURE_FAILONSLCK
)
2563 set_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
2564 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
2565 dev_err(&device
->cdev
->dev
,
2566 "The device reservation was lost\n");
2570 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_single(
2571 struct dasd_device
*startdev
,
2572 struct dasd_block
*block
,
2573 struct request
*req
,
2578 unsigned int first_offs
,
2579 unsigned int last_offs
,
2580 unsigned int blk_per_trk
,
2581 unsigned int blksize
)
2583 struct dasd_eckd_private
*private;
2584 unsigned long *idaws
;
2585 struct LO_eckd_data
*LO_data
;
2586 struct dasd_ccw_req
*cqr
;
2588 struct req_iterator iter
;
2592 int count
, cidaw
, cplength
, datasize
;
2594 unsigned char cmd
, rcmd
;
2596 struct dasd_device
*basedev
;
2598 basedev
= block
->base
;
2599 private = (struct dasd_eckd_private
*) basedev
->private;
2600 if (rq_data_dir(req
) == READ
)
2601 cmd
= DASD_ECKD_CCW_READ_MT
;
2602 else if (rq_data_dir(req
) == WRITE
)
2603 cmd
= DASD_ECKD_CCW_WRITE_MT
;
2605 return ERR_PTR(-EINVAL
);
2607 /* Check struct bio and count the number of blocks for the request. */
2610 rq_for_each_segment(bv
, req
, iter
) {
2611 if (bv
.bv_len
& (blksize
- 1))
2612 /* Eckd can only do full blocks. */
2613 return ERR_PTR(-EINVAL
);
2614 count
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2615 if (idal_is_needed (page_address(bv
.bv_page
), bv
.bv_len
))
2616 cidaw
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2619 if (count
!= last_rec
- first_rec
+ 1)
2620 return ERR_PTR(-EINVAL
);
2622 /* use the prefix command if available */
2623 use_prefix
= private->features
.feature
[8] & 0x01;
2625 /* 1x prefix + number of blocks */
2626 cplength
= 2 + count
;
2627 /* 1x prefix + cidaws*sizeof(long) */
2628 datasize
= sizeof(struct PFX_eckd_data
) +
2629 sizeof(struct LO_eckd_data
) +
2630 cidaw
* sizeof(unsigned long);
2632 /* 1x define extent + 1x locate record + number of blocks */
2633 cplength
= 2 + count
;
2634 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2635 datasize
= sizeof(struct DE_eckd_data
) +
2636 sizeof(struct LO_eckd_data
) +
2637 cidaw
* sizeof(unsigned long);
2639 /* Find out the number of additional locate record ccws for cdl. */
2640 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
2641 if (last_rec
>= 2*blk_per_trk
)
2642 count
= 2*blk_per_trk
- first_rec
;
2644 datasize
+= count
*sizeof(struct LO_eckd_data
);
2646 /* Allocate the ccw request. */
2647 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2652 /* First ccw is define extent or prefix. */
2654 if (prefix(ccw
++, cqr
->data
, first_trk
,
2655 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
2656 /* Clock not in sync and XRC is enabled.
2659 dasd_sfree_request(cqr
, startdev
);
2660 return ERR_PTR(-EAGAIN
);
2662 idaws
= (unsigned long *) (cqr
->data
+
2663 sizeof(struct PFX_eckd_data
));
2665 if (define_extent(ccw
++, cqr
->data
, first_trk
,
2666 last_trk
, cmd
, basedev
) == -EAGAIN
) {
2667 /* Clock not in sync and XRC is enabled.
2670 dasd_sfree_request(cqr
, startdev
);
2671 return ERR_PTR(-EAGAIN
);
2673 idaws
= (unsigned long *) (cqr
->data
+
2674 sizeof(struct DE_eckd_data
));
2676 /* Build locate_record+read/write/ccws. */
2677 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
2679 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
2680 /* Only standard blocks so there is just one locate record. */
2681 ccw
[-1].flags
|= CCW_FLAG_CC
;
2682 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
2683 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
2685 rq_for_each_segment(bv
, req
, iter
) {
2686 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2687 if (dasd_page_cache
) {
2688 char *copy
= kmem_cache_alloc(dasd_page_cache
,
2689 GFP_DMA
| __GFP_NOWARN
);
2690 if (copy
&& rq_data_dir(req
) == WRITE
)
2691 memcpy(copy
+ bv
.bv_offset
, dst
, bv
.bv_len
);
2693 dst
= copy
+ bv
.bv_offset
;
2695 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
2696 sector_t trkid
= recid
;
2697 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
2700 /* Locate record for cdl special block ? */
2701 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
2702 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
2704 count
= dasd_eckd_cdl_reclen(recid
);
2705 if (count
< blksize
&&
2706 rq_data_dir(req
) == READ
)
2707 memset(dst
+ count
, 0xe5,
2710 ccw
[-1].flags
|= CCW_FLAG_CC
;
2711 locate_record(ccw
++, LO_data
++,
2713 1, rcmd
, basedev
, count
);
2715 /* Locate record for standard blocks ? */
2716 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
2717 ccw
[-1].flags
|= CCW_FLAG_CC
;
2718 locate_record(ccw
++, LO_data
++,
2720 last_rec
- recid
+ 1,
2721 cmd
, basedev
, count
);
2723 /* Read/write ccw. */
2724 ccw
[-1].flags
|= CCW_FLAG_CC
;
2725 ccw
->cmd_code
= rcmd
;
2727 if (idal_is_needed(dst
, blksize
)) {
2728 ccw
->cda
= (__u32
)(addr_t
) idaws
;
2729 ccw
->flags
= CCW_FLAG_IDA
;
2730 idaws
= idal_create_words(idaws
, dst
, blksize
);
2732 ccw
->cda
= (__u32
)(addr_t
) dst
;
2740 if (blk_noretry_request(req
) ||
2741 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2742 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2743 cqr
->startdev
= startdev
;
2744 cqr
->memdev
= startdev
;
2746 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2747 cqr
->lpm
= startdev
->path_data
.ppm
;
2748 cqr
->retries
= startdev
->default_retries
;
2749 cqr
->buildclk
= get_tod_clock();
2750 cqr
->status
= DASD_CQR_FILLED
;
2754 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_track(
2755 struct dasd_device
*startdev
,
2756 struct dasd_block
*block
,
2757 struct request
*req
,
2762 unsigned int first_offs
,
2763 unsigned int last_offs
,
2764 unsigned int blk_per_trk
,
2765 unsigned int blksize
)
2767 unsigned long *idaws
;
2768 struct dasd_ccw_req
*cqr
;
2770 struct req_iterator iter
;
2772 char *dst
, *idaw_dst
;
2773 unsigned int cidaw
, cplength
, datasize
;
2777 struct dasd_device
*basedev
;
2778 unsigned int trkcount
, count
, count_to_trk_end
;
2779 unsigned int idaw_len
, seg_len
, part_len
, len_to_track_end
;
2780 unsigned char new_track
, end_idaw
;
2782 unsigned int recoffs
;
2784 basedev
= block
->base
;
2785 if (rq_data_dir(req
) == READ
)
2786 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
2787 else if (rq_data_dir(req
) == WRITE
)
2788 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
2790 return ERR_PTR(-EINVAL
);
2792 /* Track based I/O needs IDAWs for each page, and not just for
2793 * 64 bit addresses. We need additional idals for pages
2794 * that get filled from two tracks, so we use the number
2795 * of records as upper limit.
2797 cidaw
= last_rec
- first_rec
+ 1;
2798 trkcount
= last_trk
- first_trk
+ 1;
2800 /* 1x prefix + one read/write ccw per track */
2801 cplength
= 1 + trkcount
;
2803 /* on 31-bit we need space for two 32 bit addresses per page
2804 * on 64-bit one 64 bit address
2806 datasize
= sizeof(struct PFX_eckd_data
) +
2807 cidaw
* sizeof(unsigned long long);
2809 /* Allocate the ccw request. */
2810 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2815 /* transfer length factor: how many bytes to read from the last track */
2816 if (first_trk
== last_trk
)
2817 tlf
= last_offs
- first_offs
+ 1;
2819 tlf
= last_offs
+ 1;
2822 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
,
2823 last_trk
, cmd
, basedev
, startdev
,
2824 1 /* format */, first_offs
+ 1,
2827 /* Clock not in sync and XRC is enabled.
2830 dasd_sfree_request(cqr
, startdev
);
2831 return ERR_PTR(-EAGAIN
);
2835 * The translation of request into ccw programs must meet the
2836 * following conditions:
2837 * - all idaws but the first and the last must address full pages
2838 * (or 2K blocks on 31-bit)
2839 * - the scope of a ccw and it's idal ends with the track boundaries
2841 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct PFX_eckd_data
));
2845 len_to_track_end
= 0;
2848 rq_for_each_segment(bv
, req
, iter
) {
2849 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2850 seg_len
= bv
.bv_len
;
2854 recoffs
= sector_div(trkid
, blk_per_trk
);
2855 count_to_trk_end
= blk_per_trk
- recoffs
;
2856 count
= min((last_rec
- recid
+ 1),
2857 (sector_t
)count_to_trk_end
);
2858 len_to_track_end
= count
* blksize
;
2859 ccw
[-1].flags
|= CCW_FLAG_CC
;
2860 ccw
->cmd_code
= cmd
;
2861 ccw
->count
= len_to_track_end
;
2862 ccw
->cda
= (__u32
)(addr_t
)idaws
;
2863 ccw
->flags
= CCW_FLAG_IDA
;
2867 /* first idaw for a ccw may start anywhere */
2871 /* If we start a new idaw, we must make sure that it
2872 * starts on an IDA_BLOCK_SIZE boundary.
2873 * If we continue an idaw, we must make sure that the
2874 * current segment begins where the so far accumulated
2878 if (__pa(dst
) & (IDA_BLOCK_SIZE
-1)) {
2879 dasd_sfree_request(cqr
, startdev
);
2880 return ERR_PTR(-ERANGE
);
2884 if ((idaw_dst
+ idaw_len
) != dst
) {
2885 dasd_sfree_request(cqr
, startdev
);
2886 return ERR_PTR(-ERANGE
);
2888 part_len
= min(seg_len
, len_to_track_end
);
2889 seg_len
-= part_len
;
2891 idaw_len
+= part_len
;
2892 len_to_track_end
-= part_len
;
2893 /* collected memory area ends on an IDA_BLOCK border,
2895 * idal_create_words will handle cases where idaw_len
2896 * is larger then IDA_BLOCK_SIZE
2898 if (!(__pa(idaw_dst
+ idaw_len
) & (IDA_BLOCK_SIZE
-1)))
2900 /* We also need to end the idaw at track end */
2901 if (!len_to_track_end
) {
2906 idaws
= idal_create_words(idaws
, idaw_dst
,
2915 if (blk_noretry_request(req
) ||
2916 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2917 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2918 cqr
->startdev
= startdev
;
2919 cqr
->memdev
= startdev
;
2921 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2922 cqr
->lpm
= startdev
->path_data
.ppm
;
2923 cqr
->retries
= startdev
->default_retries
;
2924 cqr
->buildclk
= get_tod_clock();
2925 cqr
->status
= DASD_CQR_FILLED
;
2929 static int prepare_itcw(struct itcw
*itcw
,
2930 unsigned int trk
, unsigned int totrk
, int cmd
,
2931 struct dasd_device
*basedev
,
2932 struct dasd_device
*startdev
,
2933 unsigned int rec_on_trk
, int count
,
2934 unsigned int blksize
,
2935 unsigned int total_data_size
,
2937 unsigned int blk_per_trk
)
2939 struct PFX_eckd_data pfxdata
;
2940 struct dasd_eckd_private
*basepriv
, *startpriv
;
2941 struct DE_eckd_data
*dedata
;
2942 struct LRE_eckd_data
*lredata
;
2946 u16 heads
, beghead
, endhead
;
2954 /* setup prefix data */
2955 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
2956 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
2957 dedata
= &pfxdata
.define_extent
;
2958 lredata
= &pfxdata
.locate_record
;
2960 memset(&pfxdata
, 0, sizeof(pfxdata
));
2961 pfxdata
.format
= 1; /* PFX with LRE */
2962 pfxdata
.base_address
= basepriv
->ned
->unit_addr
;
2963 pfxdata
.base_lss
= basepriv
->ned
->ID
;
2964 pfxdata
.validity
.define_extent
= 1;
2966 /* private uid is kept up to date, conf_data may be outdated */
2967 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
2968 pfxdata
.validity
.verify_base
= 1;
2969 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
2970 pfxdata
.validity
.hyper_pav
= 1;
2974 case DASD_ECKD_CCW_READ_TRACK_DATA
:
2975 dedata
->mask
.perm
= 0x1;
2976 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
2977 dedata
->blk_size
= blksize
;
2978 dedata
->ga_extended
|= 0x42;
2979 lredata
->operation
.orientation
= 0x0;
2980 lredata
->operation
.operation
= 0x0C;
2981 lredata
->auxiliary
.check_bytes
= 0x01;
2982 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
2984 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
2985 dedata
->mask
.perm
= 0x02;
2986 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
2987 dedata
->blk_size
= blksize
;
2988 rc
= check_XRC_on_prefix(&pfxdata
, basedev
);
2989 dedata
->ga_extended
|= 0x42;
2990 lredata
->operation
.orientation
= 0x0;
2991 lredata
->operation
.operation
= 0x3F;
2992 lredata
->extended_operation
= 0x23;
2993 lredata
->auxiliary
.check_bytes
= 0x2;
2994 pfx_cmd
= DASD_ECKD_CCW_PFX
;
2997 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2998 "prepare itcw, unknown opcode 0x%x", cmd
);
3005 dedata
->attributes
.mode
= 0x3; /* ECKD */
3007 heads
= basepriv
->rdc_data
.trk_per_cyl
;
3008 begcyl
= trk
/ heads
;
3009 beghead
= trk
% heads
;
3010 endcyl
= totrk
/ heads
;
3011 endhead
= totrk
% heads
;
3013 /* check for sequential prestage - enhance cylinder range */
3014 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
3015 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
3017 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
3018 endcyl
+= basepriv
->attrib
.nr_cyl
;
3020 endcyl
= (basepriv
->real_cyl
- 1);
3023 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
3024 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
3026 dedata
->ep_format
= 0x20; /* records per track is valid */
3027 dedata
->ep_rec_per_track
= blk_per_trk
;
3030 switch (basepriv
->rdc_data
.dev_type
) {
3032 dn
= ceil_quot(blksize
+ 6, 232);
3033 d
= 9 + ceil_quot(blksize
+ 6 * (dn
+ 1), 34);
3034 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
3037 d
= 7 + ceil_quot(blksize
+ 12, 32);
3038 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
3043 lredata
->auxiliary
.length_valid
= 1;
3044 lredata
->auxiliary
.length_scope
= 1;
3045 lredata
->auxiliary
.imbedded_ccw_valid
= 1;
3046 lredata
->length
= tlf
;
3047 lredata
->imbedded_ccw
= cmd
;
3048 lredata
->count
= count
;
3049 lredata
->sector
= sector
;
3050 set_ch_t(&lredata
->seek_addr
, begcyl
, beghead
);
3051 lredata
->search_arg
.cyl
= lredata
->seek_addr
.cyl
;
3052 lredata
->search_arg
.head
= lredata
->seek_addr
.head
;
3053 lredata
->search_arg
.record
= rec_on_trk
;
3055 dcw
= itcw_add_dcw(itcw
, pfx_cmd
, 0,
3056 &pfxdata
, sizeof(pfxdata
), total_data_size
);
3057 return PTR_RET(dcw
);
3060 static struct dasd_ccw_req
*dasd_eckd_build_cp_tpm_track(
3061 struct dasd_device
*startdev
,
3062 struct dasd_block
*block
,
3063 struct request
*req
,
3068 unsigned int first_offs
,
3069 unsigned int last_offs
,
3070 unsigned int blk_per_trk
,
3071 unsigned int blksize
)
3073 struct dasd_ccw_req
*cqr
;
3074 struct req_iterator iter
;
3077 unsigned int trkcount
, ctidaw
;
3079 struct dasd_device
*basedev
;
3082 struct tidaw
*last_tidaw
= NULL
;
3086 unsigned int seg_len
, part_len
, len_to_track_end
;
3087 unsigned char new_track
;
3088 sector_t recid
, trkid
;
3090 unsigned int count
, count_to_trk_end
;
3093 basedev
= block
->base
;
3094 if (rq_data_dir(req
) == READ
) {
3095 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
3096 itcw_op
= ITCW_OP_READ
;
3097 } else if (rq_data_dir(req
) == WRITE
) {
3098 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
3099 itcw_op
= ITCW_OP_WRITE
;
3101 return ERR_PTR(-EINVAL
);
3103 /* trackbased I/O needs address all memory via TIDAWs,
3104 * not just for 64 bit addresses. This allows us to map
3105 * each segment directly to one tidaw.
3106 * In the case of write requests, additional tidaws may
3107 * be needed when a segment crosses a track boundary.
3109 trkcount
= last_trk
- first_trk
+ 1;
3111 rq_for_each_segment(bv
, req
, iter
) {
3114 if (rq_data_dir(req
) == WRITE
)
3115 ctidaw
+= (last_trk
- first_trk
);
3117 /* Allocate the ccw request. */
3118 itcw_size
= itcw_calc_size(0, ctidaw
, 0);
3119 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
3123 /* transfer length factor: how many bytes to read from the last track */
3124 if (first_trk
== last_trk
)
3125 tlf
= last_offs
- first_offs
+ 1;
3127 tlf
= last_offs
+ 1;
3130 itcw
= itcw_init(cqr
->data
, itcw_size
, itcw_op
, 0, ctidaw
, 0);
3135 cqr
->cpaddr
= itcw_get_tcw(itcw
);
3136 if (prepare_itcw(itcw
, first_trk
, last_trk
,
3137 cmd
, basedev
, startdev
,
3140 (last_rec
- first_rec
+ 1) * blksize
,
3141 tlf
, blk_per_trk
) == -EAGAIN
) {
3142 /* Clock not in sync and XRC is enabled.
3148 len_to_track_end
= 0;
3150 * A tidaw can address 4k of memory, but must not cross page boundaries
3151 * We can let the block layer handle this by setting
3152 * blk_queue_segment_boundary to page boundaries and
3153 * blk_max_segment_size to page size when setting up the request queue.
3154 * For write requests, a TIDAW must not cross track boundaries, because
3155 * we have to set the CBC flag on the last tidaw for each track.
3157 if (rq_data_dir(req
) == WRITE
) {
3160 rq_for_each_segment(bv
, req
, iter
) {
3161 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3162 seg_len
= bv
.bv_len
;
3166 offs
= sector_div(trkid
, blk_per_trk
);
3167 count_to_trk_end
= blk_per_trk
- offs
;
3168 count
= min((last_rec
- recid
+ 1),
3169 (sector_t
)count_to_trk_end
);
3170 len_to_track_end
= count
* blksize
;
3174 part_len
= min(seg_len
, len_to_track_end
);
3175 seg_len
-= part_len
;
3176 len_to_track_end
-= part_len
;
3177 /* We need to end the tidaw at track end */
3178 if (!len_to_track_end
) {
3180 tidaw_flags
= TIDAW_FLAGS_INSERT_CBC
;
3183 last_tidaw
= itcw_add_tidaw(itcw
, tidaw_flags
,
3185 if (IS_ERR(last_tidaw
)) {
3193 rq_for_each_segment(bv
, req
, iter
) {
3194 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3195 last_tidaw
= itcw_add_tidaw(itcw
, 0x00,
3197 if (IS_ERR(last_tidaw
)) {
3203 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
3204 last_tidaw
->flags
&= ~TIDAW_FLAGS_INSERT_CBC
;
3205 itcw_finalize(itcw
);
3207 if (blk_noretry_request(req
) ||
3208 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3209 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3211 cqr
->startdev
= startdev
;
3212 cqr
->memdev
= startdev
;
3214 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3215 cqr
->lpm
= startdev
->path_data
.ppm
;
3216 cqr
->retries
= startdev
->default_retries
;
3217 cqr
->buildclk
= get_tod_clock();
3218 cqr
->status
= DASD_CQR_FILLED
;
3221 dasd_sfree_request(cqr
, startdev
);
3222 return ERR_PTR(ret
);
3225 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
3226 struct dasd_block
*block
,
3227 struct request
*req
)
3232 struct dasd_eckd_private
*private;
3233 struct dasd_device
*basedev
;
3234 sector_t first_rec
, last_rec
;
3235 sector_t first_trk
, last_trk
;
3236 unsigned int first_offs
, last_offs
;
3237 unsigned int blk_per_trk
, blksize
;
3239 unsigned int data_size
;
3240 struct dasd_ccw_req
*cqr
;
3242 basedev
= block
->base
;
3243 private = (struct dasd_eckd_private
*) basedev
->private;
3245 /* Calculate number of blocks/records per track. */
3246 blksize
= block
->bp_block
;
3247 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3248 if (blk_per_trk
== 0)
3249 return ERR_PTR(-EINVAL
);
3250 /* Calculate record id of first and last block. */
3251 first_rec
= first_trk
= blk_rq_pos(req
) >> block
->s2b_shift
;
3252 first_offs
= sector_div(first_trk
, blk_per_trk
);
3253 last_rec
= last_trk
=
3254 (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) >> block
->s2b_shift
;
3255 last_offs
= sector_div(last_trk
, blk_per_trk
);
3256 cdlspecial
= (private->uses_cdl
&& first_rec
< 2*blk_per_trk
);
3258 fcx_multitrack
= private->features
.feature
[40] & 0x20;
3259 data_size
= blk_rq_bytes(req
);
3260 if (data_size
% blksize
)
3261 return ERR_PTR(-EINVAL
);
3262 /* tpm write request add CBC data on each track boundary */
3263 if (rq_data_dir(req
) == WRITE
)
3264 data_size
+= (last_trk
- first_trk
) * 4;
3266 /* is read track data and write track data in command mode supported? */
3267 cmdrtd
= private->features
.feature
[9] & 0x20;
3268 cmdwtd
= private->features
.feature
[12] & 0x40;
3269 use_prefix
= private->features
.feature
[8] & 0x01;
3272 if (cdlspecial
|| dasd_page_cache
) {
3273 /* do nothing, just fall through to the cmd mode single case */
3274 } else if ((data_size
<= private->fcx_max_data
)
3275 && (fcx_multitrack
|| (first_trk
== last_trk
))) {
3276 cqr
= dasd_eckd_build_cp_tpm_track(startdev
, block
, req
,
3277 first_rec
, last_rec
,
3278 first_trk
, last_trk
,
3279 first_offs
, last_offs
,
3280 blk_per_trk
, blksize
);
3281 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3282 (PTR_ERR(cqr
) != -ENOMEM
))
3284 } else if (use_prefix
&&
3285 (((rq_data_dir(req
) == READ
) && cmdrtd
) ||
3286 ((rq_data_dir(req
) == WRITE
) && cmdwtd
))) {
3287 cqr
= dasd_eckd_build_cp_cmd_track(startdev
, block
, req
,
3288 first_rec
, last_rec
,
3289 first_trk
, last_trk
,
3290 first_offs
, last_offs
,
3291 blk_per_trk
, blksize
);
3292 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3293 (PTR_ERR(cqr
) != -ENOMEM
))
3297 cqr
= dasd_eckd_build_cp_cmd_single(startdev
, block
, req
,
3298 first_rec
, last_rec
,
3299 first_trk
, last_trk
,
3300 first_offs
, last_offs
,
3301 blk_per_trk
, blksize
);
3305 static struct dasd_ccw_req
*dasd_raw_build_cp(struct dasd_device
*startdev
,
3306 struct dasd_block
*block
,
3307 struct request
*req
)
3309 unsigned long *idaws
;
3310 struct dasd_device
*basedev
;
3311 struct dasd_ccw_req
*cqr
;
3313 struct req_iterator iter
;
3317 unsigned int trkcount
;
3318 unsigned int seg_len
, len_to_track_end
;
3319 unsigned int first_offs
;
3320 unsigned int cidaw
, cplength
, datasize
;
3321 sector_t first_trk
, last_trk
, sectors
;
3322 sector_t start_padding_sectors
, end_sector_offset
, end_padding_sectors
;
3323 unsigned int pfx_datasize
;
3326 * raw track access needs to be mutiple of 64k and on 64k boundary
3327 * For read requests we can fix an incorrect alignment by padding
3328 * the request with dummy pages.
3330 start_padding_sectors
= blk_rq_pos(req
) % DASD_RAW_SECTORS_PER_TRACK
;
3331 end_sector_offset
= (blk_rq_pos(req
) + blk_rq_sectors(req
)) %
3332 DASD_RAW_SECTORS_PER_TRACK
;
3333 end_padding_sectors
= (DASD_RAW_SECTORS_PER_TRACK
- end_sector_offset
) %
3334 DASD_RAW_SECTORS_PER_TRACK
;
3335 basedev
= block
->base
;
3336 if ((start_padding_sectors
|| end_padding_sectors
) &&
3337 (rq_data_dir(req
) == WRITE
)) {
3338 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3339 "raw write not track aligned (%lu,%lu) req %p",
3340 start_padding_sectors
, end_padding_sectors
, req
);
3341 cqr
= ERR_PTR(-EINVAL
);
3345 first_trk
= blk_rq_pos(req
) / DASD_RAW_SECTORS_PER_TRACK
;
3346 last_trk
= (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) /
3347 DASD_RAW_SECTORS_PER_TRACK
;
3348 trkcount
= last_trk
- first_trk
+ 1;
3351 if (rq_data_dir(req
) == READ
)
3352 cmd
= DASD_ECKD_CCW_READ_TRACK
;
3353 else if (rq_data_dir(req
) == WRITE
)
3354 cmd
= DASD_ECKD_CCW_WRITE_FULL_TRACK
;
3356 cqr
= ERR_PTR(-EINVAL
);
3361 * Raw track based I/O needs IDAWs for each page,
3362 * and not just for 64 bit addresses.
3364 cidaw
= trkcount
* DASD_RAW_BLOCK_PER_TRACK
;
3366 /* 1x prefix + one read/write ccw per track */
3367 cplength
= 1 + trkcount
;
3370 * struct PFX_eckd_data has up to 2 byte as extended parameter
3371 * this is needed for write full track and has to be mentioned
3373 * add 8 instead of 2 to keep 8 byte boundary
3375 pfx_datasize
= sizeof(struct PFX_eckd_data
) + 8;
3377 datasize
= pfx_datasize
+ cidaw
* sizeof(unsigned long long);
3379 /* Allocate the ccw request. */
3380 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
3381 datasize
, startdev
);
3386 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
,
3387 basedev
, startdev
, 1 /* format */, first_offs
+ 1,
3388 trkcount
, 0, 0) == -EAGAIN
) {
3389 /* Clock not in sync and XRC is enabled.
3392 dasd_sfree_request(cqr
, startdev
);
3393 cqr
= ERR_PTR(-EAGAIN
);
3397 idaws
= (unsigned long *)(cqr
->data
+ pfx_datasize
);
3398 len_to_track_end
= 0;
3399 if (start_padding_sectors
) {
3400 ccw
[-1].flags
|= CCW_FLAG_CC
;
3401 ccw
->cmd_code
= cmd
;
3402 /* maximum 3390 track size */
3404 /* 64k map to one track */
3405 len_to_track_end
= 65536 - start_padding_sectors
* 512;
3406 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3407 ccw
->flags
|= CCW_FLAG_IDA
;
3408 ccw
->flags
|= CCW_FLAG_SLI
;
3410 for (sectors
= 0; sectors
< start_padding_sectors
; sectors
+= 8)
3411 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3413 rq_for_each_segment(bv
, req
, iter
) {
3414 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3415 seg_len
= bv
.bv_len
;
3416 if (cmd
== DASD_ECKD_CCW_READ_TRACK
)
3417 memset(dst
, 0, seg_len
);
3418 if (!len_to_track_end
) {
3419 ccw
[-1].flags
|= CCW_FLAG_CC
;
3420 ccw
->cmd_code
= cmd
;
3421 /* maximum 3390 track size */
3423 /* 64k map to one track */
3424 len_to_track_end
= 65536;
3425 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3426 ccw
->flags
|= CCW_FLAG_IDA
;
3427 ccw
->flags
|= CCW_FLAG_SLI
;
3430 len_to_track_end
-= seg_len
;
3431 idaws
= idal_create_words(idaws
, dst
, seg_len
);
3433 for (sectors
= 0; sectors
< end_padding_sectors
; sectors
+= 8)
3434 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3435 if (blk_noretry_request(req
) ||
3436 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3437 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3438 cqr
->startdev
= startdev
;
3439 cqr
->memdev
= startdev
;
3441 cqr
->expires
= startdev
->default_expires
* HZ
;
3442 cqr
->lpm
= startdev
->path_data
.ppm
;
3443 cqr
->retries
= startdev
->default_retries
;
3444 cqr
->buildclk
= get_tod_clock();
3445 cqr
->status
= DASD_CQR_FILLED
;
3447 if (IS_ERR(cqr
) && PTR_ERR(cqr
) != -EAGAIN
)
3455 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
3457 struct dasd_eckd_private
*private;
3459 struct req_iterator iter
;
3462 unsigned int blksize
, blk_per_trk
, off
;
3466 if (!dasd_page_cache
)
3468 private = (struct dasd_eckd_private
*) cqr
->block
->base
->private;
3469 blksize
= cqr
->block
->bp_block
;
3470 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3471 recid
= blk_rq_pos(req
) >> cqr
->block
->s2b_shift
;
3473 /* Skip over define extent & locate record. */
3475 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
3477 rq_for_each_segment(bv
, req
, iter
) {
3478 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3479 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
3480 /* Skip locate record. */
3481 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
3484 if (ccw
->flags
& CCW_FLAG_IDA
)
3485 cda
= *((char **)((addr_t
) ccw
->cda
));
3487 cda
= (char *)((addr_t
) ccw
->cda
);
3489 if (rq_data_dir(req
) == READ
)
3490 memcpy(dst
, cda
, bv
.bv_len
);
3491 kmem_cache_free(dasd_page_cache
,
3492 (void *)((addr_t
)cda
& PAGE_MASK
));
3501 status
= cqr
->status
== DASD_CQR_DONE
;
3502 dasd_sfree_request(cqr
, cqr
->memdev
);
3507 * Modify ccw/tcw in cqr so it can be started on a base device.
3509 * Note that this is not enough to restart the cqr!
3510 * Either reset cqr->startdev as well (summary unit check handling)
3511 * or restart via separate cqr (as in ERP handling).
3513 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
3516 struct PFX_eckd_data
*pfxdata
;
3521 if (cqr
->cpmode
== 1) {
3523 tccb
= tcw_get_tccb(tcw
);
3524 dcw
= (struct dcw
*)&tccb
->tca
[0];
3525 pfxdata
= (struct PFX_eckd_data
*)&dcw
->cd
[0];
3526 pfxdata
->validity
.verify_base
= 0;
3527 pfxdata
->validity
.hyper_pav
= 0;
3530 pfxdata
= cqr
->data
;
3531 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
3532 pfxdata
->validity
.verify_base
= 0;
3533 pfxdata
->validity
.hyper_pav
= 0;
3538 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3540 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
3541 struct dasd_block
*block
,
3542 struct request
*req
)
3544 struct dasd_eckd_private
*private;
3545 struct dasd_device
*startdev
;
3546 unsigned long flags
;
3547 struct dasd_ccw_req
*cqr
;
3549 startdev
= dasd_alias_get_start_dev(base
);
3552 private = (struct dasd_eckd_private
*) startdev
->private;
3553 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
3554 return ERR_PTR(-EBUSY
);
3556 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
3558 if ((base
->features
& DASD_FEATURE_USERAW
))
3559 cqr
= dasd_raw_build_cp(startdev
, block
, req
);
3561 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
3564 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
3568 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
3569 struct request
*req
)
3571 struct dasd_eckd_private
*private;
3572 unsigned long flags
;
3574 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3575 private = (struct dasd_eckd_private
*) cqr
->memdev
->private;
3577 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3578 return dasd_eckd_free_cp(cqr
, req
);
3582 dasd_eckd_fill_info(struct dasd_device
* device
,
3583 struct dasd_information2_t
* info
)
3585 struct dasd_eckd_private
*private;
3587 private = (struct dasd_eckd_private
*) device
->private;
3588 info
->label_block
= 2;
3589 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
3590 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
3591 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
3592 memcpy(info
->characteristics
, &private->rdc_data
,
3593 sizeof(struct dasd_eckd_characteristics
));
3594 info
->confdata_size
= min((unsigned long)private->conf_len
,
3595 sizeof(info
->configuration_data
));
3596 memcpy(info
->configuration_data
, private->conf_data
,
3597 info
->confdata_size
);
3602 * SECTION: ioctl functions for eckd devices.
3606 * Release device ioctl.
3607 * Buils a channel programm to releases a prior reserved
3608 * (see dasd_eckd_reserve) device.
3611 dasd_eckd_release(struct dasd_device
*device
)
3613 struct dasd_ccw_req
*cqr
;
3618 if (!capable(CAP_SYS_ADMIN
))
3622 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3624 mutex_lock(&dasd_reserve_mutex
);
3626 cqr
= &dasd_reserve_req
->cqr
;
3627 memset(cqr
, 0, sizeof(*cqr
));
3628 memset(&dasd_reserve_req
->ccw
, 0,
3629 sizeof(dasd_reserve_req
->ccw
));
3630 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3631 cqr
->data
= &dasd_reserve_req
->data
;
3632 cqr
->magic
= DASD_ECKD_MAGIC
;
3635 ccw
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
3636 ccw
->flags
|= CCW_FLAG_SLI
;
3638 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3639 cqr
->startdev
= device
;
3640 cqr
->memdev
= device
;
3641 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3642 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3643 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3644 cqr
->expires
= 2 * HZ
;
3645 cqr
->buildclk
= get_tod_clock();
3646 cqr
->status
= DASD_CQR_FILLED
;
3648 rc
= dasd_sleep_on_immediatly(cqr
);
3650 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3653 mutex_unlock(&dasd_reserve_mutex
);
3655 dasd_sfree_request(cqr
, cqr
->memdev
);
3660 * Reserve device ioctl.
3661 * Options are set to 'synchronous wait for interrupt' and
3662 * 'timeout the request'. This leads to a terminate IO if
3663 * the interrupt is outstanding for a certain time.
3666 dasd_eckd_reserve(struct dasd_device
*device
)
3668 struct dasd_ccw_req
*cqr
;
3673 if (!capable(CAP_SYS_ADMIN
))
3677 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3679 mutex_lock(&dasd_reserve_mutex
);
3681 cqr
= &dasd_reserve_req
->cqr
;
3682 memset(cqr
, 0, sizeof(*cqr
));
3683 memset(&dasd_reserve_req
->ccw
, 0,
3684 sizeof(dasd_reserve_req
->ccw
));
3685 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3686 cqr
->data
= &dasd_reserve_req
->data
;
3687 cqr
->magic
= DASD_ECKD_MAGIC
;
3690 ccw
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
3691 ccw
->flags
|= CCW_FLAG_SLI
;
3693 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3694 cqr
->startdev
= device
;
3695 cqr
->memdev
= device
;
3696 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3697 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3698 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3699 cqr
->expires
= 2 * HZ
;
3700 cqr
->buildclk
= get_tod_clock();
3701 cqr
->status
= DASD_CQR_FILLED
;
3703 rc
= dasd_sleep_on_immediatly(cqr
);
3705 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3708 mutex_unlock(&dasd_reserve_mutex
);
3710 dasd_sfree_request(cqr
, cqr
->memdev
);
3715 * Steal lock ioctl - unconditional reserve device.
3716 * Buils a channel programm to break a device's reservation.
3717 * (unconditional reserve)
3720 dasd_eckd_steal_lock(struct dasd_device
*device
)
3722 struct dasd_ccw_req
*cqr
;
3727 if (!capable(CAP_SYS_ADMIN
))
3731 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3733 mutex_lock(&dasd_reserve_mutex
);
3735 cqr
= &dasd_reserve_req
->cqr
;
3736 memset(cqr
, 0, sizeof(*cqr
));
3737 memset(&dasd_reserve_req
->ccw
, 0,
3738 sizeof(dasd_reserve_req
->ccw
));
3739 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3740 cqr
->data
= &dasd_reserve_req
->data
;
3741 cqr
->magic
= DASD_ECKD_MAGIC
;
3744 ccw
->cmd_code
= DASD_ECKD_CCW_SLCK
;
3745 ccw
->flags
|= CCW_FLAG_SLI
;
3747 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3748 cqr
->startdev
= device
;
3749 cqr
->memdev
= device
;
3750 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3751 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3752 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3753 cqr
->expires
= 2 * HZ
;
3754 cqr
->buildclk
= get_tod_clock();
3755 cqr
->status
= DASD_CQR_FILLED
;
3757 rc
= dasd_sleep_on_immediatly(cqr
);
3759 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3762 mutex_unlock(&dasd_reserve_mutex
);
3764 dasd_sfree_request(cqr
, cqr
->memdev
);
3769 * SNID - Sense Path Group ID
3770 * This ioctl may be used in situations where I/O is stalled due to
3771 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3772 * preallocated dasd_reserve_req.
3774 static int dasd_eckd_snid(struct dasd_device
*device
,
3777 struct dasd_ccw_req
*cqr
;
3781 struct dasd_snid_ioctl_data usrparm
;
3783 if (!capable(CAP_SYS_ADMIN
))
3786 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3790 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1,
3791 sizeof(struct dasd_snid_data
), device
);
3793 mutex_lock(&dasd_reserve_mutex
);
3795 cqr
= &dasd_reserve_req
->cqr
;
3796 memset(cqr
, 0, sizeof(*cqr
));
3797 memset(&dasd_reserve_req
->ccw
, 0,
3798 sizeof(dasd_reserve_req
->ccw
));
3799 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3800 cqr
->data
= &dasd_reserve_req
->data
;
3801 cqr
->magic
= DASD_ECKD_MAGIC
;
3804 ccw
->cmd_code
= DASD_ECKD_CCW_SNID
;
3805 ccw
->flags
|= CCW_FLAG_SLI
;
3807 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3808 cqr
->startdev
= device
;
3809 cqr
->memdev
= device
;
3810 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3811 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3812 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
3814 cqr
->expires
= 10 * HZ
;
3815 cqr
->buildclk
= get_tod_clock();
3816 cqr
->status
= DASD_CQR_FILLED
;
3817 cqr
->lpm
= usrparm
.path_mask
;
3819 rc
= dasd_sleep_on_immediatly(cqr
);
3820 /* verify that I/O processing didn't modify the path mask */
3821 if (!rc
&& usrparm
.path_mask
&& (cqr
->lpm
!= usrparm
.path_mask
))
3824 usrparm
.data
= *((struct dasd_snid_data
*)cqr
->data
);
3825 if (copy_to_user(argp
, &usrparm
, sizeof(usrparm
)))
3830 mutex_unlock(&dasd_reserve_mutex
);
3832 dasd_sfree_request(cqr
, cqr
->memdev
);
3837 * Read performance statistics
3840 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
3842 struct dasd_psf_prssd_data
*prssdp
;
3843 struct dasd_rssd_perf_stats_t
*stats
;
3844 struct dasd_ccw_req
*cqr
;
3848 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
3849 (sizeof(struct dasd_psf_prssd_data
) +
3850 sizeof(struct dasd_rssd_perf_stats_t
)),
3853 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3854 "Could not allocate initialization request");
3855 return PTR_ERR(cqr
);
3857 cqr
->startdev
= device
;
3858 cqr
->memdev
= device
;
3860 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3861 cqr
->expires
= 10 * HZ
;
3863 /* Prepare for Read Subsystem Data */
3864 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3865 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
3866 prssdp
->order
= PSF_ORDER_PRSSD
;
3867 prssdp
->suborder
= 0x01; /* Performance Statistics */
3868 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
3871 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
3872 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
3873 ccw
->flags
|= CCW_FLAG_CC
;
3874 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
3876 /* Read Subsystem Data - Performance Statistics */
3877 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3878 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
3881 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
3882 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
3883 ccw
->cda
= (__u32
)(addr_t
) stats
;
3885 cqr
->buildclk
= get_tod_clock();
3886 cqr
->status
= DASD_CQR_FILLED
;
3887 rc
= dasd_sleep_on(cqr
);
3889 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3890 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3891 if (copy_to_user(argp
, stats
,
3892 sizeof(struct dasd_rssd_perf_stats_t
)))
3895 dasd_sfree_request(cqr
, cqr
->memdev
);
3900 * Get attributes (cache operations)
3901 * Returnes the cache attributes used in Define Extend (DE).
3904 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
3906 struct dasd_eckd_private
*private =
3907 (struct dasd_eckd_private
*)device
->private;
3908 struct attrib_data_t attrib
= private->attrib
;
3911 if (!capable(CAP_SYS_ADMIN
))
3917 if (copy_to_user(argp
, (long *) &attrib
,
3918 sizeof(struct attrib_data_t
)))
3925 * Set attributes (cache operations)
3926 * Stores the attributes for cache operation to be used in Define Extend (DE).
3929 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
3931 struct dasd_eckd_private
*private =
3932 (struct dasd_eckd_private
*)device
->private;
3933 struct attrib_data_t attrib
;
3935 if (!capable(CAP_SYS_ADMIN
))
3940 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
3942 private->attrib
= attrib
;
3944 dev_info(&device
->cdev
->dev
,
3945 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3946 private->attrib
.operation
, private->attrib
.nr_cyl
);
3951 * Issue syscall I/O to EMC Symmetrix array.
3952 * CCWs are PSF and RSSD
3954 static int dasd_symm_io(struct dasd_device
*device
, void __user
*argp
)
3956 struct dasd_symmio_parms usrparm
;
3957 char *psf_data
, *rssd_result
;
3958 struct dasd_ccw_req
*cqr
;
3963 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
3967 /* Copy parms from caller */
3969 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3971 if (is_compat_task() || sizeof(long) == 4) {
3972 /* Make sure pointers are sane even on 31 bit. */
3974 if ((usrparm
.psf_data
>> 32) != 0)
3976 if ((usrparm
.rssd_result
>> 32) != 0)
3978 usrparm
.psf_data
&= 0x7fffffffULL
;
3979 usrparm
.rssd_result
&= 0x7fffffffULL
;
3981 /* alloc I/O data area */
3982 psf_data
= kzalloc(usrparm
.psf_data_len
, GFP_KERNEL
| GFP_DMA
);
3983 rssd_result
= kzalloc(usrparm
.rssd_result_len
, GFP_KERNEL
| GFP_DMA
);
3984 if (!psf_data
|| !rssd_result
) {
3989 /* get syscall header from user space */
3991 if (copy_from_user(psf_data
,
3992 (void __user
*)(unsigned long) usrparm
.psf_data
,
3993 usrparm
.psf_data_len
))
3998 /* setup CCWs for PSF + RSSD */
3999 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 2 , 0, device
);
4001 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4002 "Could not allocate initialization request");
4007 cqr
->startdev
= device
;
4008 cqr
->memdev
= device
;
4010 cqr
->expires
= 10 * HZ
;
4011 cqr
->buildclk
= get_tod_clock();
4012 cqr
->status
= DASD_CQR_FILLED
;
4014 /* Build the ccws */
4018 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4019 ccw
->count
= usrparm
.psf_data_len
;
4020 ccw
->flags
|= CCW_FLAG_CC
;
4021 ccw
->cda
= (__u32
)(addr_t
) psf_data
;
4026 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4027 ccw
->count
= usrparm
.rssd_result_len
;
4028 ccw
->flags
= CCW_FLAG_SLI
;
4029 ccw
->cda
= (__u32
)(addr_t
) rssd_result
;
4031 rc
= dasd_sleep_on(cqr
);
4036 if (copy_to_user((void __user
*)(unsigned long) usrparm
.rssd_result
,
4037 rssd_result
, usrparm
.rssd_result_len
))
4042 dasd_sfree_request(cqr
, cqr
->memdev
);
4047 DBF_DEV_EVENT(DBF_WARNING
, device
,
4048 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4049 (int) psf0
, (int) psf1
, rc
);
4054 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
4056 struct dasd_device
*device
= block
->base
;
4060 return dasd_eckd_get_attrib(device
, argp
);
4062 return dasd_eckd_set_attrib(device
, argp
);
4064 return dasd_eckd_performance(device
, argp
);
4066 return dasd_eckd_release(device
);
4068 return dasd_eckd_reserve(device
);
4070 return dasd_eckd_steal_lock(device
);
4072 return dasd_eckd_snid(device
, argp
);
4074 return dasd_symm_io(device
, argp
);
4081 * Dump the range of CCWs into 'page' buffer
4082 * and return number of printed chars.
4085 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
4091 while (from
<= to
) {
4092 len
+= sprintf(page
+ len
, PRINTK_HEADER
4093 " CCW %p: %08X %08X DAT:",
4094 from
, ((int *) from
)[0], ((int *) from
)[1]);
4096 /* get pointer to data (consider IDALs) */
4097 if (from
->flags
& CCW_FLAG_IDA
)
4098 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
4100 datap
= (char *) ((addr_t
) from
->cda
);
4102 /* dump data (max 32 bytes) */
4103 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
4104 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
4105 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
4106 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
4108 len
+= sprintf(page
+ len
, "\n");
4115 dasd_eckd_dump_sense_dbf(struct dasd_device
*device
, struct irb
*irb
,
4121 sense
= (u64
*) dasd_get_sense(irb
);
4122 stat
= (u64
*) &irb
->scsw
;
4124 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : "
4125 "%016llx %016llx %016llx %016llx",
4126 reason
, *stat
, *((u32
*) (stat
+ 1)),
4127 sense
[0], sense
[1], sense
[2], sense
[3]);
4129 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : %s",
4130 reason
, *stat
, *((u32
*) (stat
+ 1)),
4136 * Print sense data and related channel program.
4137 * Parts are printed because printk buffer is only 1024 bytes.
4139 static void dasd_eckd_dump_sense_ccw(struct dasd_device
*device
,
4140 struct dasd_ccw_req
*req
, struct irb
*irb
)
4143 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
4146 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4148 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4149 "No memory to dump sense data\n");
4152 /* dump the sense data */
4153 len
= sprintf(page
, PRINTK_HEADER
4154 " I/O status report for device %s:\n",
4155 dev_name(&device
->cdev
->dev
));
4156 len
+= sprintf(page
+ len
, PRINTK_HEADER
4157 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4159 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4160 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4161 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4162 req
? req
->intrc
: 0);
4163 len
+= sprintf(page
+ len
, PRINTK_HEADER
4164 " device %s: Failing CCW: %p\n",
4165 dev_name(&device
->cdev
->dev
),
4166 (void *) (addr_t
) irb
->scsw
.cmd
.cpa
);
4167 if (irb
->esw
.esw0
.erw
.cons
) {
4168 for (sl
= 0; sl
< 4; sl
++) {
4169 len
+= sprintf(page
+ len
, PRINTK_HEADER
4170 " Sense(hex) %2d-%2d:",
4171 (8 * sl
), ((8 * sl
) + 7));
4173 for (sct
= 0; sct
< 8; sct
++) {
4174 len
+= sprintf(page
+ len
, " %02x",
4175 irb
->ecw
[8 * sl
+ sct
]);
4177 len
+= sprintf(page
+ len
, "\n");
4180 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
4181 /* 24 Byte Sense Data */
4182 sprintf(page
+ len
, PRINTK_HEADER
4183 " 24 Byte: %x MSG %x, "
4184 "%s MSGb to SYSOP\n",
4185 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
4186 irb
->ecw
[1] & 0x10 ? "" : "no");
4188 /* 32 Byte Sense Data */
4189 sprintf(page
+ len
, PRINTK_HEADER
4190 " 32 Byte: Format: %x "
4191 "Exception class %x\n",
4192 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
4195 sprintf(page
+ len
, PRINTK_HEADER
4196 " SORRY - NO VALID SENSE AVAILABLE\n");
4198 printk(KERN_ERR
"%s", page
);
4201 /* req == NULL for unsolicited interrupts */
4202 /* dump the Channel Program (max 140 Bytes per line) */
4203 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4204 first
= req
->cpaddr
;
4205 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
4206 to
= min(first
+ 6, last
);
4207 len
= sprintf(page
, PRINTK_HEADER
4208 " Related CP in req: %p\n", req
);
4209 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
4210 printk(KERN_ERR
"%s", page
);
4212 /* print failing CCW area (maximum 4) */
4213 /* scsw->cda is either valid or zero */
4216 fail
= (struct ccw1
*)(addr_t
)
4217 irb
->scsw
.cmd
.cpa
; /* failing CCW */
4218 if (from
< fail
- 2) {
4219 from
= fail
- 2; /* there is a gap - print header */
4220 len
+= sprintf(page
, PRINTK_HEADER
"......\n");
4222 to
= min(fail
+ 1, last
);
4223 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
4225 /* print last CCWs (maximum 2) */
4226 from
= max(from
, ++to
);
4227 if (from
< last
- 1) {
4228 from
= last
- 1; /* there is a gap - print header */
4229 len
+= sprintf(page
+ len
, PRINTK_HEADER
"......\n");
4231 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
4233 printk(KERN_ERR
"%s", page
);
4235 free_page((unsigned long) page
);
4240 * Print sense data from a tcw.
4242 static void dasd_eckd_dump_sense_tcw(struct dasd_device
*device
,
4243 struct dasd_ccw_req
*req
, struct irb
*irb
)
4246 int len
, sl
, sct
, residual
;
4250 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4252 DBF_DEV_EVENT(DBF_WARNING
, device
, " %s",
4253 "No memory to dump sense data");
4256 /* dump the sense data */
4257 len
= sprintf(page
, PRINTK_HEADER
4258 " I/O status report for device %s:\n",
4259 dev_name(&device
->cdev
->dev
));
4260 len
+= sprintf(page
+ len
, PRINTK_HEADER
4261 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4262 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4263 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4264 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4265 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4266 irb
->scsw
.tm
.fcxs
, irb
->scsw
.tm
.schxs
,
4267 req
? req
->intrc
: 0);
4268 len
+= sprintf(page
+ len
, PRINTK_HEADER
4269 " device %s: Failing TCW: %p\n",
4270 dev_name(&device
->cdev
->dev
),
4271 (void *) (addr_t
) irb
->scsw
.tm
.tcw
);
4275 if (irb
->scsw
.tm
.tcw
&& (irb
->scsw
.tm
.fcxs
& 0x01))
4277 (struct tcw
*)(unsigned long)irb
->scsw
.tm
.tcw
);
4280 len
+= sprintf(page
+ len
, PRINTK_HEADER
4281 " tsb->length %d\n", tsb
->length
);
4282 len
+= sprintf(page
+ len
, PRINTK_HEADER
4283 " tsb->flags %x\n", tsb
->flags
);
4284 len
+= sprintf(page
+ len
, PRINTK_HEADER
4285 " tsb->dcw_offset %d\n", tsb
->dcw_offset
);
4286 len
+= sprintf(page
+ len
, PRINTK_HEADER
4287 " tsb->count %d\n", tsb
->count
);
4288 residual
= tsb
->count
- 28;
4289 len
+= sprintf(page
+ len
, PRINTK_HEADER
4290 " residual %d\n", residual
);
4292 switch (tsb
->flags
& 0x07) {
4293 case 1: /* tsa_iostat */
4294 len
+= sprintf(page
+ len
, PRINTK_HEADER
4295 " tsb->tsa.iostat.dev_time %d\n",
4296 tsb
->tsa
.iostat
.dev_time
);
4297 len
+= sprintf(page
+ len
, PRINTK_HEADER
4298 " tsb->tsa.iostat.def_time %d\n",
4299 tsb
->tsa
.iostat
.def_time
);
4300 len
+= sprintf(page
+ len
, PRINTK_HEADER
4301 " tsb->tsa.iostat.queue_time %d\n",
4302 tsb
->tsa
.iostat
.queue_time
);
4303 len
+= sprintf(page
+ len
, PRINTK_HEADER
4304 " tsb->tsa.iostat.dev_busy_time %d\n",
4305 tsb
->tsa
.iostat
.dev_busy_time
);
4306 len
+= sprintf(page
+ len
, PRINTK_HEADER
4307 " tsb->tsa.iostat.dev_act_time %d\n",
4308 tsb
->tsa
.iostat
.dev_act_time
);
4309 sense
= tsb
->tsa
.iostat
.sense
;
4311 case 2: /* ts_ddpc */
4312 len
+= sprintf(page
+ len
, PRINTK_HEADER
4313 " tsb->tsa.ddpc.rc %d\n", tsb
->tsa
.ddpc
.rc
);
4314 for (sl
= 0; sl
< 2; sl
++) {
4315 len
+= sprintf(page
+ len
, PRINTK_HEADER
4316 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4317 (8 * sl
), ((8 * sl
) + 7));
4318 rcq
= tsb
->tsa
.ddpc
.rcq
;
4319 for (sct
= 0; sct
< 8; sct
++) {
4320 len
+= sprintf(page
+ len
, " %02x",
4323 len
+= sprintf(page
+ len
, "\n");
4325 sense
= tsb
->tsa
.ddpc
.sense
;
4327 case 3: /* tsa_intrg */
4328 len
+= sprintf(page
+ len
, PRINTK_HEADER
4329 " tsb->tsa.intrg.: not supportet yet\n");
4334 for (sl
= 0; sl
< 4; sl
++) {
4335 len
+= sprintf(page
+ len
, PRINTK_HEADER
4336 " Sense(hex) %2d-%2d:",
4337 (8 * sl
), ((8 * sl
) + 7));
4338 for (sct
= 0; sct
< 8; sct
++) {
4339 len
+= sprintf(page
+ len
, " %02x",
4340 sense
[8 * sl
+ sct
]);
4342 len
+= sprintf(page
+ len
, "\n");
4345 if (sense
[27] & DASD_SENSE_BIT_0
) {
4346 /* 24 Byte Sense Data */
4347 sprintf(page
+ len
, PRINTK_HEADER
4348 " 24 Byte: %x MSG %x, "
4349 "%s MSGb to SYSOP\n",
4350 sense
[7] >> 4, sense
[7] & 0x0f,
4351 sense
[1] & 0x10 ? "" : "no");
4353 /* 32 Byte Sense Data */
4354 sprintf(page
+ len
, PRINTK_HEADER
4355 " 32 Byte: Format: %x "
4356 "Exception class %x\n",
4357 sense
[6] & 0x0f, sense
[22] >> 4);
4360 sprintf(page
+ len
, PRINTK_HEADER
4361 " SORRY - NO VALID SENSE AVAILABLE\n");
4364 sprintf(page
+ len
, PRINTK_HEADER
4365 " SORRY - NO TSB DATA AVAILABLE\n");
4367 printk(KERN_ERR
"%s", page
);
4368 free_page((unsigned long) page
);
4371 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
4372 struct dasd_ccw_req
*req
, struct irb
*irb
)
4374 if (scsw_is_tm(&irb
->scsw
))
4375 dasd_eckd_dump_sense_tcw(device
, req
, irb
);
4377 dasd_eckd_dump_sense_ccw(device
, req
, irb
);
4380 static int dasd_eckd_pm_freeze(struct dasd_device
*device
)
4383 * the device should be disconnected from our LCU structure
4384 * on restore we will reconnect it and reread LCU specific
4385 * information like PAV support that might have changed
4387 dasd_alias_remove_device(device
);
4388 dasd_alias_disconnect_device_from_lcu(device
);
4393 static int dasd_eckd_restore_device(struct dasd_device
*device
)
4395 struct dasd_eckd_private
*private;
4396 struct dasd_eckd_characteristics temp_rdc_data
;
4398 struct dasd_uid temp_uid
;
4399 unsigned long flags
;
4400 unsigned long cqr_flags
= 0;
4402 private = (struct dasd_eckd_private
*) device
->private;
4404 /* Read Configuration Data */
4405 dasd_eckd_read_conf(device
);
4407 dasd_eckd_get_uid(device
, &temp_uid
);
4408 /* Generate device unique id */
4409 rc
= dasd_eckd_generate_uid(device
);
4410 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4411 if (memcmp(&private->uid
, &temp_uid
, sizeof(struct dasd_uid
)) != 0)
4412 dev_err(&device
->cdev
->dev
, "The UID of the DASD has "
4414 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4418 /* register lcu with alias handling, enable PAV if this is a new lcu */
4419 rc
= dasd_alias_make_device_known_to_lcu(device
);
4423 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr_flags
);
4424 dasd_eckd_validate_server(device
, cqr_flags
);
4426 /* RE-Read Configuration Data */
4427 dasd_eckd_read_conf(device
);
4429 /* Read Feature Codes */
4430 dasd_eckd_read_features(device
);
4432 /* Read Device Characteristics */
4433 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
4434 &temp_rdc_data
, 64);
4436 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4437 "Read device characteristic failed, rc=%d", rc
);
4440 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4441 memcpy(&private->rdc_data
, &temp_rdc_data
, sizeof(temp_rdc_data
));
4442 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4444 /* add device to alias management */
4445 dasd_alias_add_device(device
);
4453 static int dasd_eckd_reload_device(struct dasd_device
*device
)
4455 struct dasd_eckd_private
*private;
4458 struct dasd_uid uid
;
4459 unsigned long flags
;
4461 private = (struct dasd_eckd_private
*) device
->private;
4463 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4464 old_base
= private->uid
.base_unit_addr
;
4465 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4467 /* Read Configuration Data */
4468 rc
= dasd_eckd_read_conf(device
);
4472 rc
= dasd_eckd_generate_uid(device
);
4476 * update unit address configuration and
4477 * add device to alias management
4479 dasd_alias_update_add_device(device
);
4481 dasd_eckd_get_uid(device
, &uid
);
4483 if (old_base
!= uid
.base_unit_addr
) {
4484 if (strlen(uid
.vduit
) > 0)
4485 snprintf(print_uid
, sizeof(print_uid
),
4486 "%s.%s.%04x.%02x.%s", uid
.vendor
, uid
.serial
,
4487 uid
.ssid
, uid
.base_unit_addr
, uid
.vduit
);
4489 snprintf(print_uid
, sizeof(print_uid
),
4490 "%s.%s.%04x.%02x", uid
.vendor
, uid
.serial
,
4491 uid
.ssid
, uid
.base_unit_addr
);
4493 dev_info(&device
->cdev
->dev
,
4494 "An Alias device was reassigned to a new base device "
4495 "with UID: %s\n", print_uid
);
4503 static int dasd_eckd_read_message_buffer(struct dasd_device
*device
,
4504 struct dasd_rssd_messages
*messages
,
4507 struct dasd_rssd_messages
*message_buf
;
4508 struct dasd_psf_prssd_data
*prssdp
;
4509 struct dasd_eckd_private
*private;
4510 struct dasd_ccw_req
*cqr
;
4514 private = (struct dasd_eckd_private
*) device
->private;
4515 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
4516 (sizeof(struct dasd_psf_prssd_data
) +
4517 sizeof(struct dasd_rssd_messages
)),
4520 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
4521 "Could not allocate read message buffer request");
4522 return PTR_ERR(cqr
);
4525 cqr
->startdev
= device
;
4526 cqr
->memdev
= device
;
4529 cqr
->expires
= 10 * HZ
;
4531 /* we need to check for messages on exactly this path */
4532 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
4535 /* Prepare for Read Subsystem Data */
4536 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4537 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
4538 prssdp
->order
= PSF_ORDER_PRSSD
;
4539 prssdp
->suborder
= 0x03; /* Message Buffer */
4540 /* all other bytes of prssdp must be zero */
4543 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4544 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
4545 ccw
->flags
|= CCW_FLAG_CC
;
4546 ccw
->flags
|= CCW_FLAG_SLI
;
4547 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
4549 /* Read Subsystem Data - message buffer */
4550 message_buf
= (struct dasd_rssd_messages
*) (prssdp
+ 1);
4551 memset(message_buf
, 0, sizeof(struct dasd_rssd_messages
));
4554 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4555 ccw
->count
= sizeof(struct dasd_rssd_messages
);
4556 ccw
->flags
|= CCW_FLAG_SLI
;
4557 ccw
->cda
= (__u32
)(addr_t
) message_buf
;
4559 cqr
->buildclk
= get_tod_clock();
4560 cqr
->status
= DASD_CQR_FILLED
;
4561 rc
= dasd_sleep_on_immediatly(cqr
);
4563 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4564 message_buf
= (struct dasd_rssd_messages
*)
4566 memcpy(messages
, message_buf
,
4567 sizeof(struct dasd_rssd_messages
));
4569 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4570 "Reading messages failed with rc=%d\n"
4572 dasd_sfree_request(cqr
, cqr
->memdev
);
4577 * Perform Subsystem Function - CUIR response
4580 dasd_eckd_psf_cuir_response(struct dasd_device
*device
, int response
,
4582 struct channel_path_desc
*desc
,
4583 struct subchannel_id sch_id
)
4585 struct dasd_psf_cuir_response
*psf_cuir
;
4586 struct dasd_ccw_req
*cqr
;
4590 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
4591 sizeof(struct dasd_psf_cuir_response
),
4595 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4596 "Could not allocate PSF-CUIR request");
4597 return PTR_ERR(cqr
);
4600 psf_cuir
= (struct dasd_psf_cuir_response
*)cqr
->data
;
4601 psf_cuir
->order
= PSF_ORDER_CUIR_RESPONSE
;
4602 psf_cuir
->cc
= response
;
4604 psf_cuir
->chpid
= desc
->chpid
;
4605 psf_cuir
->message_id
= message_id
;
4606 psf_cuir
->cssid
= sch_id
.cssid
;
4607 psf_cuir
->ssid
= sch_id
.ssid
;
4610 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4611 ccw
->cda
= (__u32
)(addr_t
)psf_cuir
;
4612 ccw
->count
= sizeof(struct dasd_psf_cuir_response
);
4614 cqr
->startdev
= device
;
4615 cqr
->memdev
= device
;
4618 cqr
->expires
= 10*HZ
;
4619 cqr
->buildclk
= get_tod_clock();
4620 cqr
->status
= DASD_CQR_FILLED
;
4622 rc
= dasd_sleep_on(cqr
);
4624 dasd_sfree_request(cqr
, cqr
->memdev
);
4628 static int dasd_eckd_cuir_change_state(struct dasd_device
*device
, __u8 lpum
)
4630 unsigned long flags
;
4633 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4634 tbcpm
= device
->path_data
.opm
& ~lpum
;
4636 device
->path_data
.opm
= tbcpm
;
4637 device
->path_data
.cuirpm
|= lpum
;
4639 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4640 return tbcpm
? 0 : PSF_CUIR_LAST_PATH
;
4644 * walk through all devices and quiesce them
4645 * if it is the last path return error
4647 * if only part of the devices are quiesced and an error
4648 * occurs no onlining necessary, the storage server will
4649 * notify the already set offline devices again
4651 static int dasd_eckd_cuir_quiesce(struct dasd_device
*device
, __u8 lpum
,
4652 struct channel_path_desc
*desc
,
4653 struct subchannel_id sch_id
)
4655 struct alias_pav_group
*pavgroup
, *tempgroup
;
4656 struct dasd_eckd_private
*private;
4657 struct dasd_device
*dev
, *n
;
4660 private = (struct dasd_eckd_private
*) device
->private;
4663 /* active devices */
4664 list_for_each_entry_safe(dev
, n
,
4665 &private->lcu
->active_devices
,
4667 rc
= dasd_eckd_cuir_change_state(dev
, lpum
);
4672 /* inactive devices */
4673 list_for_each_entry_safe(dev
, n
,
4674 &private->lcu
->inactive_devices
,
4676 rc
= dasd_eckd_cuir_change_state(dev
, lpum
);
4681 /* devices in PAV groups */
4682 list_for_each_entry_safe(pavgroup
, tempgroup
,
4683 &private->lcu
->grouplist
, group
) {
4684 list_for_each_entry_safe(dev
, n
, &pavgroup
->baselist
,
4686 rc
= dasd_eckd_cuir_change_state(dev
, lpum
);
4690 list_for_each_entry_safe(dev
, n
, &pavgroup
->aliaslist
,
4692 rc
= dasd_eckd_cuir_change_state(dev
, lpum
);
4698 pr_warn("Service on the storage server caused path %x.%02x to go offline",
4699 sch_id
.cssid
, desc
? desc
->chpid
: 0);
4700 rc
= PSF_CUIR_COMPLETED
;
4705 static int dasd_eckd_cuir_resume(struct dasd_device
*device
, __u8 lpum
,
4706 struct channel_path_desc
*desc
,
4707 struct subchannel_id sch_id
)
4709 struct alias_pav_group
*pavgroup
, *tempgroup
;
4710 struct dasd_eckd_private
*private;
4711 struct dasd_device
*dev
, *n
;
4713 pr_info("Path %x.%02x is back online after service on the storage server",
4714 sch_id
.cssid
, desc
? desc
->chpid
: 0);
4715 private = (struct dasd_eckd_private
*) device
->private;
4718 * the path may have been added through a generic path event before
4719 * only trigger path verification if the path is not already in use
4722 list_for_each_entry_safe(dev
, n
,
4723 &private->lcu
->active_devices
,
4725 if (!(dev
->path_data
.opm
& lpum
)) {
4726 dev
->path_data
.tbvpm
|= lpum
;
4727 dasd_schedule_device_bh(dev
);
4731 list_for_each_entry_safe(dev
, n
,
4732 &private->lcu
->inactive_devices
,
4734 if (!(dev
->path_data
.opm
& lpum
)) {
4735 dev
->path_data
.tbvpm
|= lpum
;
4736 dasd_schedule_device_bh(dev
);
4740 /* devices in PAV groups */
4741 list_for_each_entry_safe(pavgroup
, tempgroup
,
4742 &private->lcu
->grouplist
,
4744 list_for_each_entry_safe(dev
, n
,
4745 &pavgroup
->baselist
,
4747 if (!(dev
->path_data
.opm
& lpum
)) {
4748 dev
->path_data
.tbvpm
|= lpum
;
4749 dasd_schedule_device_bh(dev
);
4752 list_for_each_entry_safe(dev
, n
,
4753 &pavgroup
->aliaslist
,
4755 if (!(dev
->path_data
.opm
& lpum
)) {
4756 dev
->path_data
.tbvpm
|= lpum
;
4757 dasd_schedule_device_bh(dev
);
4761 return PSF_CUIR_COMPLETED
;
4764 static void dasd_eckd_handle_cuir(struct dasd_device
*device
, void *messages
,
4767 struct dasd_cuir_message
*cuir
= messages
;
4768 struct channel_path_desc
*desc
;
4769 struct subchannel_id sch_id
;
4771 ccw_device_get_schid(device
->cdev
, &sch_id
);
4773 /* get position of path in mask */
4774 pos
= 8 - ffs(lpum
);
4775 /* get channel path descriptor from this position */
4776 desc
= ccw_device_get_chp_desc(device
->cdev
, pos
);
4778 if (cuir
->code
== CUIR_QUIESCE
) {
4780 response
= dasd_eckd_cuir_quiesce(device
, lpum
, desc
, sch_id
);
4781 } else if (cuir
->code
== CUIR_RESUME
) {
4783 response
= dasd_eckd_cuir_resume(device
, lpum
, desc
, sch_id
);
4785 response
= PSF_CUIR_NOT_SUPPORTED
;
4787 dasd_eckd_psf_cuir_response(device
, response
, cuir
->message_id
,
4790 /* free descriptor copy */
4794 static void dasd_eckd_check_attention_work(struct work_struct
*work
)
4796 struct check_attention_work_data
*data
;
4797 struct dasd_rssd_messages
*messages
;
4798 struct dasd_device
*device
;
4801 data
= container_of(work
, struct check_attention_work_data
, worker
);
4802 device
= data
->device
;
4804 messages
= kzalloc(sizeof(*messages
), GFP_KERNEL
);
4806 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4807 "Could not allocate attention message buffer");
4811 rc
= dasd_eckd_read_message_buffer(device
, messages
, data
->lpum
);
4815 if (messages
->length
== ATTENTION_LENGTH_CUIR
&&
4816 messages
->format
== ATTENTION_FORMAT_CUIR
)
4817 dasd_eckd_handle_cuir(device
, messages
, data
->lpum
);
4820 dasd_put_device(device
);
4825 static int dasd_eckd_check_attention(struct dasd_device
*device
, __u8 lpum
)
4827 struct check_attention_work_data
*data
;
4829 data
= kzalloc(sizeof(*data
), GFP_ATOMIC
);
4832 INIT_WORK(&data
->worker
, dasd_eckd_check_attention_work
);
4833 dasd_get_device(device
);
4834 data
->device
= device
;
4836 schedule_work(&data
->worker
);
4840 static struct ccw_driver dasd_eckd_driver
= {
4842 .name
= "dasd-eckd",
4843 .owner
= THIS_MODULE
,
4845 .ids
= dasd_eckd_ids
,
4846 .probe
= dasd_eckd_probe
,
4847 .remove
= dasd_generic_remove
,
4848 .set_offline
= dasd_generic_set_offline
,
4849 .set_online
= dasd_eckd_set_online
,
4850 .notify
= dasd_generic_notify
,
4851 .path_event
= dasd_generic_path_event
,
4852 .shutdown
= dasd_generic_shutdown
,
4853 .freeze
= dasd_generic_pm_freeze
,
4854 .thaw
= dasd_generic_restore_device
,
4855 .restore
= dasd_generic_restore_device
,
4856 .uc_handler
= dasd_generic_uc_handler
,
4857 .int_class
= IRQIO_DAS
,
4861 * max_blocks is dependent on the amount of storage that is available
4862 * in the static io buffer for each device. Currently each device has
4863 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4864 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4865 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4866 * addition we have one define extent ccw + 16 bytes of data and one
4867 * locate record ccw + 16 bytes of data. That makes:
4868 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4869 * We want to fit two into the available memory so that we can immediately
4870 * start the next request if one finishes off. That makes 249.5 blocks
4871 * for one request. Give a little safety and the result is 240.
4873 static struct dasd_discipline dasd_eckd_discipline
= {
4874 .owner
= THIS_MODULE
,
4878 .check_device
= dasd_eckd_check_characteristics
,
4879 .uncheck_device
= dasd_eckd_uncheck_device
,
4880 .do_analysis
= dasd_eckd_do_analysis
,
4881 .verify_path
= dasd_eckd_verify_path
,
4882 .basic_to_ready
= dasd_eckd_basic_to_ready
,
4883 .online_to_ready
= dasd_eckd_online_to_ready
,
4884 .basic_to_known
= dasd_eckd_basic_to_known
,
4885 .fill_geometry
= dasd_eckd_fill_geometry
,
4886 .start_IO
= dasd_start_IO
,
4887 .term_IO
= dasd_term_IO
,
4888 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
4889 .format_device
= dasd_eckd_format_device
,
4890 .erp_action
= dasd_eckd_erp_action
,
4891 .erp_postaction
= dasd_eckd_erp_postaction
,
4892 .check_for_device_change
= dasd_eckd_check_for_device_change
,
4893 .build_cp
= dasd_eckd_build_alias_cp
,
4894 .free_cp
= dasd_eckd_free_alias_cp
,
4895 .dump_sense
= dasd_eckd_dump_sense
,
4896 .dump_sense_dbf
= dasd_eckd_dump_sense_dbf
,
4897 .fill_info
= dasd_eckd_fill_info
,
4898 .ioctl
= dasd_eckd_ioctl
,
4899 .freeze
= dasd_eckd_pm_freeze
,
4900 .restore
= dasd_eckd_restore_device
,
4901 .reload
= dasd_eckd_reload_device
,
4902 .get_uid
= dasd_eckd_get_uid
,
4903 .kick_validate
= dasd_eckd_kick_validate_server
,
4904 .check_attention
= dasd_eckd_check_attention
,
4908 dasd_eckd_init(void)
4912 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
4913 dasd_reserve_req
= kmalloc(sizeof(*dasd_reserve_req
),
4914 GFP_KERNEL
| GFP_DMA
);
4915 if (!dasd_reserve_req
)
4917 path_verification_worker
= kmalloc(sizeof(*path_verification_worker
),
4918 GFP_KERNEL
| GFP_DMA
);
4919 if (!path_verification_worker
) {
4920 kfree(dasd_reserve_req
);
4923 rawpadpage
= (void *)__get_free_page(GFP_KERNEL
);
4925 kfree(path_verification_worker
);
4926 kfree(dasd_reserve_req
);
4929 ret
= ccw_driver_register(&dasd_eckd_driver
);
4931 wait_for_device_probe();
4933 kfree(path_verification_worker
);
4934 kfree(dasd_reserve_req
);
4935 free_page((unsigned long)rawpadpage
);
4941 dasd_eckd_cleanup(void)
4943 ccw_driver_unregister(&dasd_eckd_driver
);
4944 kfree(path_verification_worker
);
4945 kfree(dasd_reserve_req
);
4946 free_page((unsigned long)rawpadpage
);
4949 module_init(dasd_eckd_init
);
4950 module_exit(dasd_eckd_cleanup
);