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 = device
->private;
218 if (!private->rdc_data
.facilities
.XRC_supported
)
221 /* switch on System Time Stamp - needed for XRC Support */
222 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
223 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
225 rc
= get_sync_clock(&data
->ep_sys_time
);
226 /* Ignore return code if sync clock is switched off. */
227 if (rc
== -EOPNOTSUPP
|| rc
== -EACCES
)
230 de_ccw
->count
= sizeof(struct DE_eckd_data
);
231 de_ccw
->flags
|= CCW_FLAG_SLI
;
236 define_extent(struct ccw1
*ccw
, struct DE_eckd_data
*data
, unsigned int trk
,
237 unsigned int totrk
, int cmd
, struct dasd_device
*device
)
239 struct dasd_eckd_private
*private = device
->private;
241 u16 heads
, beghead
, endhead
;
244 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
247 ccw
->cda
= (__u32
) __pa(data
);
249 memset(data
, 0, sizeof(struct DE_eckd_data
));
251 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
252 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
253 case DASD_ECKD_CCW_READ
:
254 case DASD_ECKD_CCW_READ_MT
:
255 case DASD_ECKD_CCW_READ_CKD
:
256 case DASD_ECKD_CCW_READ_CKD_MT
:
257 case DASD_ECKD_CCW_READ_KD
:
258 case DASD_ECKD_CCW_READ_KD_MT
:
259 case DASD_ECKD_CCW_READ_COUNT
:
260 data
->mask
.perm
= 0x1;
261 data
->attributes
.operation
= private->attrib
.operation
;
263 case DASD_ECKD_CCW_WRITE
:
264 case DASD_ECKD_CCW_WRITE_MT
:
265 case DASD_ECKD_CCW_WRITE_KD
:
266 case DASD_ECKD_CCW_WRITE_KD_MT
:
267 data
->mask
.perm
= 0x02;
268 data
->attributes
.operation
= private->attrib
.operation
;
269 rc
= check_XRC (ccw
, data
, device
);
271 case DASD_ECKD_CCW_WRITE_CKD
:
272 case DASD_ECKD_CCW_WRITE_CKD_MT
:
273 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
274 rc
= check_XRC (ccw
, data
, device
);
276 case DASD_ECKD_CCW_ERASE
:
277 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
278 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
279 data
->mask
.perm
= 0x3;
280 data
->mask
.auth
= 0x1;
281 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
282 rc
= check_XRC (ccw
, data
, device
);
285 dev_err(&device
->cdev
->dev
,
286 "0x%x is not a known command\n", cmd
);
290 data
->attributes
.mode
= 0x3; /* ECKD */
292 if ((private->rdc_data
.cu_type
== 0x2105 ||
293 private->rdc_data
.cu_type
== 0x2107 ||
294 private->rdc_data
.cu_type
== 0x1750)
295 && !(private->uses_cdl
&& trk
< 2))
296 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
298 heads
= private->rdc_data
.trk_per_cyl
;
299 begcyl
= trk
/ heads
;
300 beghead
= trk
% heads
;
301 endcyl
= totrk
/ heads
;
302 endhead
= totrk
% heads
;
304 /* check for sequential prestage - enhance cylinder range */
305 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
306 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
308 if (endcyl
+ private->attrib
.nr_cyl
< private->real_cyl
)
309 endcyl
+= private->attrib
.nr_cyl
;
311 endcyl
= (private->real_cyl
- 1);
314 set_ch_t(&data
->beg_ext
, begcyl
, beghead
);
315 set_ch_t(&data
->end_ext
, endcyl
, endhead
);
319 static int check_XRC_on_prefix(struct PFX_eckd_data
*pfxdata
,
320 struct dasd_device
*device
)
322 struct dasd_eckd_private
*private = device
->private;
325 if (!private->rdc_data
.facilities
.XRC_supported
)
328 /* switch on System Time Stamp - needed for XRC Support */
329 pfxdata
->define_extent
.ga_extended
|= 0x08; /* 'Time Stamp Valid' */
330 pfxdata
->define_extent
.ga_extended
|= 0x02; /* 'Extended Parameter' */
331 pfxdata
->validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
333 rc
= get_sync_clock(&pfxdata
->define_extent
.ep_sys_time
);
334 /* Ignore return code if sync clock is switched off. */
335 if (rc
== -EOPNOTSUPP
|| rc
== -EACCES
)
340 static void fill_LRE_data(struct LRE_eckd_data
*data
, unsigned int trk
,
341 unsigned int rec_on_trk
, int count
, int cmd
,
342 struct dasd_device
*device
, unsigned int reclen
,
345 struct dasd_eckd_private
*private = device
->private;
349 memset(data
, 0, sizeof(*data
));
352 switch (private->rdc_data
.dev_type
) {
354 dn
= ceil_quot(reclen
+ 6, 232);
355 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
356 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
359 d
= 7 + ceil_quot(reclen
+ 12, 32);
360 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
364 data
->sector
= sector
;
365 /* note: meaning of count depends on the operation
366 * for record based I/O it's the number of records, but for
367 * track based I/O it's the number of tracks
371 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
372 data
->operation
.orientation
= 0x3;
373 data
->operation
.operation
= 0x03;
375 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
376 data
->operation
.orientation
= 0x3;
377 data
->operation
.operation
= 0x16;
379 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
380 data
->operation
.orientation
= 0x1;
381 data
->operation
.operation
= 0x03;
384 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
385 data
->operation
.orientation
= 0x3;
386 data
->operation
.operation
= 0x16;
389 case DASD_ECKD_CCW_WRITE
:
390 case DASD_ECKD_CCW_WRITE_MT
:
391 case DASD_ECKD_CCW_WRITE_KD
:
392 case DASD_ECKD_CCW_WRITE_KD_MT
:
393 data
->auxiliary
.length_valid
= 0x1;
394 data
->length
= reclen
;
395 data
->operation
.operation
= 0x01;
397 case DASD_ECKD_CCW_WRITE_CKD
:
398 case DASD_ECKD_CCW_WRITE_CKD_MT
:
399 data
->auxiliary
.length_valid
= 0x1;
400 data
->length
= reclen
;
401 data
->operation
.operation
= 0x03;
403 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
404 data
->operation
.orientation
= 0x0;
405 data
->operation
.operation
= 0x3F;
406 data
->extended_operation
= 0x11;
408 data
->extended_parameter_length
= 0x02;
409 if (data
->count
> 8) {
410 data
->extended_parameter
[0] = 0xFF;
411 data
->extended_parameter
[1] = 0xFF;
412 data
->extended_parameter
[1] <<= (16 - count
);
414 data
->extended_parameter
[0] = 0xFF;
415 data
->extended_parameter
[0] <<= (8 - count
);
416 data
->extended_parameter
[1] = 0x00;
420 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
421 data
->auxiliary
.length_valid
= 0x1;
422 data
->length
= reclen
; /* not tlf, as one might think */
423 data
->operation
.operation
= 0x3F;
424 data
->extended_operation
= 0x23;
426 case DASD_ECKD_CCW_READ
:
427 case DASD_ECKD_CCW_READ_MT
:
428 case DASD_ECKD_CCW_READ_KD
:
429 case DASD_ECKD_CCW_READ_KD_MT
:
430 data
->auxiliary
.length_valid
= 0x1;
431 data
->length
= reclen
;
432 data
->operation
.operation
= 0x06;
434 case DASD_ECKD_CCW_READ_CKD
:
435 case DASD_ECKD_CCW_READ_CKD_MT
:
436 data
->auxiliary
.length_valid
= 0x1;
437 data
->length
= reclen
;
438 data
->operation
.operation
= 0x16;
440 case DASD_ECKD_CCW_READ_COUNT
:
441 data
->operation
.operation
= 0x06;
443 case DASD_ECKD_CCW_READ_TRACK
:
444 data
->operation
.orientation
= 0x1;
445 data
->operation
.operation
= 0x0C;
446 data
->extended_parameter_length
= 0;
449 case DASD_ECKD_CCW_READ_TRACK_DATA
:
450 data
->auxiliary
.length_valid
= 0x1;
452 data
->operation
.operation
= 0x0C;
454 case DASD_ECKD_CCW_ERASE
:
455 data
->length
= reclen
;
456 data
->auxiliary
.length_valid
= 0x1;
457 data
->operation
.operation
= 0x0b;
460 DBF_DEV_EVENT(DBF_ERR
, device
,
461 "fill LRE unknown opcode 0x%x", cmd
);
464 set_ch_t(&data
->seek_addr
,
465 trk
/ private->rdc_data
.trk_per_cyl
,
466 trk
% private->rdc_data
.trk_per_cyl
);
467 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
468 data
->search_arg
.head
= data
->seek_addr
.head
;
469 data
->search_arg
.record
= rec_on_trk
;
472 static int prefix_LRE(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
473 unsigned int trk
, unsigned int totrk
, int cmd
,
474 struct dasd_device
*basedev
, struct dasd_device
*startdev
,
475 unsigned char format
, unsigned int rec_on_trk
, int count
,
476 unsigned int blksize
, unsigned int tlf
)
478 struct dasd_eckd_private
*basepriv
, *startpriv
;
479 struct DE_eckd_data
*dedata
;
480 struct LRE_eckd_data
*lredata
;
482 u16 heads
, beghead
, endhead
;
485 basepriv
= basedev
->private;
486 startpriv
= startdev
->private;
487 dedata
= &pfxdata
->define_extent
;
488 lredata
= &pfxdata
->locate_record
;
490 ccw
->cmd_code
= DASD_ECKD_CCW_PFX
;
492 if (cmd
== DASD_ECKD_CCW_WRITE_FULL_TRACK
) {
493 ccw
->count
= sizeof(*pfxdata
) + 2;
494 ccw
->cda
= (__u32
) __pa(pfxdata
);
495 memset(pfxdata
, 0, sizeof(*pfxdata
) + 2);
497 ccw
->count
= sizeof(*pfxdata
);
498 ccw
->cda
= (__u32
) __pa(pfxdata
);
499 memset(pfxdata
, 0, sizeof(*pfxdata
));
504 DBF_DEV_EVENT(DBF_ERR
, basedev
,
505 "PFX LRE unknown format 0x%x", format
);
509 pfxdata
->format
= format
;
510 pfxdata
->base_address
= basepriv
->ned
->unit_addr
;
511 pfxdata
->base_lss
= basepriv
->ned
->ID
;
512 pfxdata
->validity
.define_extent
= 1;
514 /* private uid is kept up to date, conf_data may be outdated */
515 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
516 pfxdata
->validity
.verify_base
= 1;
517 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
518 pfxdata
->validity
.hyper_pav
= 1;
521 /* define extend data (mostly)*/
523 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
524 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
525 case DASD_ECKD_CCW_READ
:
526 case DASD_ECKD_CCW_READ_MT
:
527 case DASD_ECKD_CCW_READ_CKD
:
528 case DASD_ECKD_CCW_READ_CKD_MT
:
529 case DASD_ECKD_CCW_READ_KD
:
530 case DASD_ECKD_CCW_READ_KD_MT
:
531 case DASD_ECKD_CCW_READ_COUNT
:
532 dedata
->mask
.perm
= 0x1;
533 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
535 case DASD_ECKD_CCW_READ_TRACK
:
536 case DASD_ECKD_CCW_READ_TRACK_DATA
:
537 dedata
->mask
.perm
= 0x1;
538 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
539 dedata
->blk_size
= 0;
541 case DASD_ECKD_CCW_WRITE
:
542 case DASD_ECKD_CCW_WRITE_MT
:
543 case DASD_ECKD_CCW_WRITE_KD
:
544 case DASD_ECKD_CCW_WRITE_KD_MT
:
545 dedata
->mask
.perm
= 0x02;
546 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
547 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
549 case DASD_ECKD_CCW_WRITE_CKD
:
550 case DASD_ECKD_CCW_WRITE_CKD_MT
:
551 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
552 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
554 case DASD_ECKD_CCW_ERASE
:
555 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
556 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
557 dedata
->mask
.perm
= 0x3;
558 dedata
->mask
.auth
= 0x1;
559 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
560 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
562 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
563 dedata
->mask
.perm
= 0x03;
564 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
565 dedata
->blk_size
= 0;
567 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
568 dedata
->mask
.perm
= 0x02;
569 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
570 dedata
->blk_size
= blksize
;
571 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
574 DBF_DEV_EVENT(DBF_ERR
, basedev
,
575 "PFX LRE unknown opcode 0x%x", cmd
);
580 dedata
->attributes
.mode
= 0x3; /* ECKD */
582 if ((basepriv
->rdc_data
.cu_type
== 0x2105 ||
583 basepriv
->rdc_data
.cu_type
== 0x2107 ||
584 basepriv
->rdc_data
.cu_type
== 0x1750)
585 && !(basepriv
->uses_cdl
&& trk
< 2))
586 dedata
->ga_extended
|= 0x40; /* Regular Data Format Mode */
588 heads
= basepriv
->rdc_data
.trk_per_cyl
;
589 begcyl
= trk
/ heads
;
590 beghead
= trk
% heads
;
591 endcyl
= totrk
/ heads
;
592 endhead
= totrk
% heads
;
594 /* check for sequential prestage - enhance cylinder range */
595 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
596 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
598 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
599 endcyl
+= basepriv
->attrib
.nr_cyl
;
601 endcyl
= (basepriv
->real_cyl
- 1);
604 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
605 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
608 fill_LRE_data(lredata
, trk
, rec_on_trk
, count
, cmd
,
609 basedev
, blksize
, tlf
);
615 static int prefix(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
616 unsigned int trk
, unsigned int totrk
, int cmd
,
617 struct dasd_device
*basedev
, struct dasd_device
*startdev
)
619 return prefix_LRE(ccw
, pfxdata
, trk
, totrk
, cmd
, basedev
, startdev
,
624 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, unsigned int trk
,
625 unsigned int rec_on_trk
, int no_rec
, int cmd
,
626 struct dasd_device
* device
, int reclen
)
628 struct dasd_eckd_private
*private = device
->private;
632 DBF_DEV_EVENT(DBF_INFO
, device
,
633 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
634 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
636 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
639 ccw
->cda
= (__u32
) __pa(data
);
641 memset(data
, 0, sizeof(struct LO_eckd_data
));
644 switch (private->rdc_data
.dev_type
) {
646 dn
= ceil_quot(reclen
+ 6, 232);
647 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
648 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
651 d
= 7 + ceil_quot(reclen
+ 12, 32);
652 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
656 data
->sector
= sector
;
657 data
->count
= no_rec
;
659 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
660 data
->operation
.orientation
= 0x3;
661 data
->operation
.operation
= 0x03;
663 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
664 data
->operation
.orientation
= 0x3;
665 data
->operation
.operation
= 0x16;
667 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
668 data
->operation
.orientation
= 0x1;
669 data
->operation
.operation
= 0x03;
672 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
673 data
->operation
.orientation
= 0x3;
674 data
->operation
.operation
= 0x16;
677 case DASD_ECKD_CCW_WRITE
:
678 case DASD_ECKD_CCW_WRITE_MT
:
679 case DASD_ECKD_CCW_WRITE_KD
:
680 case DASD_ECKD_CCW_WRITE_KD_MT
:
681 data
->auxiliary
.last_bytes_used
= 0x1;
682 data
->length
= reclen
;
683 data
->operation
.operation
= 0x01;
685 case DASD_ECKD_CCW_WRITE_CKD
:
686 case DASD_ECKD_CCW_WRITE_CKD_MT
:
687 data
->auxiliary
.last_bytes_used
= 0x1;
688 data
->length
= reclen
;
689 data
->operation
.operation
= 0x03;
691 case DASD_ECKD_CCW_READ
:
692 case DASD_ECKD_CCW_READ_MT
:
693 case DASD_ECKD_CCW_READ_KD
:
694 case DASD_ECKD_CCW_READ_KD_MT
:
695 data
->auxiliary
.last_bytes_used
= 0x1;
696 data
->length
= reclen
;
697 data
->operation
.operation
= 0x06;
699 case DASD_ECKD_CCW_READ_CKD
:
700 case DASD_ECKD_CCW_READ_CKD_MT
:
701 data
->auxiliary
.last_bytes_used
= 0x1;
702 data
->length
= reclen
;
703 data
->operation
.operation
= 0x16;
705 case DASD_ECKD_CCW_READ_COUNT
:
706 data
->operation
.operation
= 0x06;
708 case DASD_ECKD_CCW_ERASE
:
709 data
->length
= reclen
;
710 data
->auxiliary
.last_bytes_used
= 0x1;
711 data
->operation
.operation
= 0x0b;
714 DBF_DEV_EVENT(DBF_ERR
, device
, "unknown locate record "
717 set_ch_t(&data
->seek_addr
,
718 trk
/ private->rdc_data
.trk_per_cyl
,
719 trk
% private->rdc_data
.trk_per_cyl
);
720 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
721 data
->search_arg
.head
= data
->seek_addr
.head
;
722 data
->search_arg
.record
= rec_on_trk
;
726 * Returns 1 if the block is one of the special blocks that needs
727 * to get read/written with the KD variant of the command.
728 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
729 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
730 * Luckily the KD variants differ only by one bit (0x08) from the
731 * normal variant. So don't wonder about code like:
732 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
733 * ccw->cmd_code |= 0x8;
736 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
740 if (recid
< blk_per_trk
)
742 if (recid
< 2 * blk_per_trk
)
748 * Returns the record size for the special blocks of the cdl format.
749 * Only returns something useful if dasd_eckd_cdl_special is true
753 dasd_eckd_cdl_reclen(int recid
)
756 return sizes_trk0
[recid
];
759 /* create unique id from private structure. */
760 static void create_uid(struct dasd_eckd_private
*private)
763 struct dasd_uid
*uid
;
766 memset(uid
, 0, sizeof(struct dasd_uid
));
767 memcpy(uid
->vendor
, private->ned
->HDA_manufacturer
,
768 sizeof(uid
->vendor
) - 1);
769 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
770 memcpy(uid
->serial
, private->ned
->HDA_location
,
771 sizeof(uid
->serial
) - 1);
772 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
773 uid
->ssid
= private->gneq
->subsystemID
;
774 uid
->real_unit_addr
= private->ned
->unit_addr
;
776 uid
->type
= private->sneq
->sua_flags
;
777 if (uid
->type
== UA_BASE_PAV_ALIAS
)
778 uid
->base_unit_addr
= private->sneq
->base_unit_addr
;
780 uid
->type
= UA_BASE_DEVICE
;
782 if (private->vdsneq
) {
783 for (count
= 0; count
< 16; count
++) {
784 sprintf(uid
->vduit
+2*count
, "%02x",
785 private->vdsneq
->uit
[count
]);
791 * Generate device unique id that specifies the physical device.
793 static int dasd_eckd_generate_uid(struct dasd_device
*device
)
795 struct dasd_eckd_private
*private = device
->private;
800 if (!private->ned
|| !private->gneq
)
802 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
804 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
808 static int dasd_eckd_get_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
810 struct dasd_eckd_private
*private = device
->private;
814 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
816 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
823 * compare device UID with data of a given dasd_eckd_private structure
826 static int dasd_eckd_compare_path_uid(struct dasd_device
*device
,
827 struct dasd_eckd_private
*private)
829 struct dasd_uid device_uid
;
832 dasd_eckd_get_uid(device
, &device_uid
);
834 return memcmp(&device_uid
, &private->uid
, sizeof(struct dasd_uid
));
837 static void dasd_eckd_fill_rcd_cqr(struct dasd_device
*device
,
838 struct dasd_ccw_req
*cqr
,
844 * buffer has to start with EBCDIC "V1.0" to show
845 * support for virtual device SNEQ
847 rcd_buffer
[0] = 0xE5;
848 rcd_buffer
[1] = 0xF1;
849 rcd_buffer
[2] = 0x4B;
850 rcd_buffer
[3] = 0xF0;
853 ccw
->cmd_code
= DASD_ECKD_CCW_RCD
;
855 ccw
->cda
= (__u32
)(addr_t
)rcd_buffer
;
856 ccw
->count
= DASD_ECKD_RCD_DATA_SIZE
;
857 cqr
->magic
= DASD_ECKD_MAGIC
;
859 cqr
->startdev
= device
;
860 cqr
->memdev
= device
;
862 cqr
->expires
= 10*HZ
;
865 cqr
->buildclk
= get_tod_clock();
866 cqr
->status
= DASD_CQR_FILLED
;
867 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
871 * Wakeup helper for read_conf
872 * if the cqr is not done and needs some error recovery
873 * the buffer has to be re-initialized with the EBCDIC "V1.0"
874 * to show support for virtual device SNEQ
876 static void read_conf_cb(struct dasd_ccw_req
*cqr
, void *data
)
881 if (cqr
->status
!= DASD_CQR_DONE
) {
883 rcd_buffer
= (__u8
*)((addr_t
) ccw
->cda
);
884 memset(rcd_buffer
, 0, sizeof(*rcd_buffer
));
886 rcd_buffer
[0] = 0xE5;
887 rcd_buffer
[1] = 0xF1;
888 rcd_buffer
[2] = 0x4B;
889 rcd_buffer
[3] = 0xF0;
891 dasd_wakeup_cb(cqr
, data
);
894 static int dasd_eckd_read_conf_immediately(struct dasd_device
*device
,
895 struct dasd_ccw_req
*cqr
,
902 * sanity check: scan for RCD command in extended SenseID data
903 * some devices do not support RCD
905 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
906 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
)
909 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buffer
, lpm
);
910 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
911 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
913 cqr
->callback
= read_conf_cb
;
914 rc
= dasd_sleep_on_immediatly(cqr
);
918 static int dasd_eckd_read_conf_lpm(struct dasd_device
*device
,
920 int *rcd_buffer_size
, __u8 lpm
)
923 char *rcd_buf
= NULL
;
925 struct dasd_ccw_req
*cqr
;
928 * sanity check: scan for RCD command in extended SenseID data
929 * some devices do not support RCD
931 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
932 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
) {
936 rcd_buf
= kzalloc(DASD_ECKD_RCD_DATA_SIZE
, GFP_KERNEL
| GFP_DMA
);
941 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* RCD */,
942 0, /* use rcd_buf as data ara */
945 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
946 "Could not allocate RCD request");
950 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buf
, lpm
);
951 cqr
->callback
= read_conf_cb
;
952 ret
= dasd_sleep_on(cqr
);
954 * on success we update the user input parms
956 dasd_sfree_request(cqr
, cqr
->memdev
);
960 *rcd_buffer_size
= DASD_ECKD_RCD_DATA_SIZE
;
961 *rcd_buffer
= rcd_buf
;
966 *rcd_buffer_size
= 0;
970 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private
*private)
973 struct dasd_sneq
*sneq
;
977 private->sneq
= NULL
;
978 private->vdsneq
= NULL
;
979 private->gneq
= NULL
;
980 count
= private->conf_len
/ sizeof(struct dasd_sneq
);
981 sneq
= (struct dasd_sneq
*)private->conf_data
;
982 for (i
= 0; i
< count
; ++i
) {
983 if (sneq
->flags
.identifier
== 1 && sneq
->format
== 1)
984 private->sneq
= sneq
;
985 else if (sneq
->flags
.identifier
== 1 && sneq
->format
== 4)
986 private->vdsneq
= (struct vd_sneq
*)sneq
;
987 else if (sneq
->flags
.identifier
== 2)
988 private->gneq
= (struct dasd_gneq
*)sneq
;
989 else if (sneq
->flags
.identifier
== 3 && sneq
->res1
== 1)
990 private->ned
= (struct dasd_ned
*)sneq
;
993 if (!private->ned
|| !private->gneq
) {
995 private->sneq
= NULL
;
996 private->vdsneq
= NULL
;
997 private->gneq
= NULL
;
1004 static unsigned char dasd_eckd_path_access(void *conf_data
, int conf_len
)
1006 struct dasd_gneq
*gneq
;
1007 int i
, count
, found
;
1009 count
= conf_len
/ sizeof(*gneq
);
1010 gneq
= (struct dasd_gneq
*)conf_data
;
1012 for (i
= 0; i
< count
; ++i
) {
1013 if (gneq
->flags
.identifier
== 2) {
1020 return ((char *)gneq
)[18] & 0x07;
1025 static void dasd_eckd_clear_conf_data(struct dasd_device
*device
)
1027 struct dasd_eckd_private
*private = device
->private;
1030 private->conf_data
= NULL
;
1031 private->conf_len
= 0;
1032 for (i
= 0; i
< 8; i
++) {
1033 kfree(private->path_conf_data
[i
]);
1034 private->path_conf_data
[i
] = NULL
;
1039 static int dasd_eckd_read_conf(struct dasd_device
*device
)
1042 int conf_len
, conf_data_saved
;
1043 int rc
, path_err
, pos
;
1045 struct dasd_eckd_private
*private, path_private
;
1046 struct dasd_path
*path_data
;
1047 struct dasd_uid
*uid
;
1048 char print_path_uid
[60], print_device_uid
[60];
1050 private = device
->private;
1051 path_data
= &device
->path_data
;
1052 opm
= ccw_device_get_path_mask(device
->cdev
);
1053 conf_data_saved
= 0;
1055 /* get configuration data per operational path */
1056 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1059 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
1061 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
1062 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1063 "Read configuration data returned "
1067 if (conf_data
== NULL
) {
1068 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1069 "No configuration data "
1071 /* no further analysis possible */
1072 path_data
->opm
|= lpm
;
1073 continue; /* no error */
1075 /* save first valid configuration data */
1076 if (!conf_data_saved
) {
1077 /* initially clear previously stored conf_data */
1078 dasd_eckd_clear_conf_data(device
);
1079 private->conf_data
= conf_data
;
1080 private->conf_len
= conf_len
;
1081 if (dasd_eckd_identify_conf_parts(private)) {
1082 private->conf_data
= NULL
;
1083 private->conf_len
= 0;
1087 pos
= pathmask_to_pos(lpm
);
1088 /* store per path conf_data */
1089 private->path_conf_data
[pos
] =
1090 (struct dasd_conf_data
*) conf_data
;
1092 * build device UID that other path data
1093 * can be compared to it
1095 dasd_eckd_generate_uid(device
);
1098 path_private
.conf_data
= conf_data
;
1099 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1100 if (dasd_eckd_identify_conf_parts(
1102 path_private
.conf_data
= NULL
;
1103 path_private
.conf_len
= 0;
1107 if (dasd_eckd_compare_path_uid(
1108 device
, &path_private
)) {
1109 uid
= &path_private
.uid
;
1110 if (strlen(uid
->vduit
) > 0)
1111 snprintf(print_path_uid
,
1112 sizeof(print_path_uid
),
1113 "%s.%s.%04x.%02x.%s",
1114 uid
->vendor
, uid
->serial
,
1115 uid
->ssid
, uid
->real_unit_addr
,
1118 snprintf(print_path_uid
,
1119 sizeof(print_path_uid
),
1121 uid
->vendor
, uid
->serial
,
1123 uid
->real_unit_addr
);
1124 uid
= &private->uid
;
1125 if (strlen(uid
->vduit
) > 0)
1126 snprintf(print_device_uid
,
1127 sizeof(print_device_uid
),
1128 "%s.%s.%04x.%02x.%s",
1129 uid
->vendor
, uid
->serial
,
1130 uid
->ssid
, uid
->real_unit_addr
,
1133 snprintf(print_device_uid
,
1134 sizeof(print_device_uid
),
1136 uid
->vendor
, uid
->serial
,
1138 uid
->real_unit_addr
);
1139 dev_err(&device
->cdev
->dev
,
1140 "Not all channel paths lead to "
1141 "the same device, path %02X leads to "
1142 "device %s instead of %s\n", lpm
,
1143 print_path_uid
, print_device_uid
);
1145 path_data
->cablepm
|= lpm
;
1148 pos
= pathmask_to_pos(lpm
);
1149 /* store per path conf_data */
1150 private->path_conf_data
[pos
] =
1151 (struct dasd_conf_data
*) conf_data
;
1152 path_private
.conf_data
= NULL
;
1153 path_private
.conf_len
= 0;
1155 switch (dasd_eckd_path_access(conf_data
, conf_len
)) {
1157 path_data
->npm
|= lpm
;
1160 path_data
->ppm
|= lpm
;
1163 if (!path_data
->opm
) {
1164 path_data
->opm
= lpm
;
1165 dasd_generic_path_operational(device
);
1167 path_data
->opm
|= lpm
;
1170 * if the path is used
1171 * it should not be in one of the negative lists
1173 path_data
->cablepm
&= ~lpm
;
1174 path_data
->hpfpm
&= ~lpm
;
1175 path_data
->cuirpm
&= ~lpm
;
1181 static int verify_fcx_max_data(struct dasd_device
*device
, __u8 lpm
)
1183 struct dasd_eckd_private
*private = device
->private;
1187 if (private->fcx_max_data
) {
1188 mdc
= ccw_device_get_mdc(device
->cdev
, lpm
);
1190 dev_warn(&device
->cdev
->dev
,
1191 "Detecting the maximum data size for zHPF "
1192 "requests failed (rc=%d) for a new path %x\n",
1196 fcx_max_data
= mdc
* FCX_MAX_DATA_FACTOR
;
1197 if (fcx_max_data
< private->fcx_max_data
) {
1198 dev_warn(&device
->cdev
->dev
,
1199 "The maximum data size for zHPF requests %u "
1200 "on a new path %x is below the active maximum "
1201 "%u\n", fcx_max_data
, lpm
,
1202 private->fcx_max_data
);
1209 static int rebuild_device_uid(struct dasd_device
*device
,
1210 struct path_verification_work_data
*data
)
1212 struct dasd_eckd_private
*private = device
->private;
1213 struct dasd_path
*path_data
= &device
->path_data
;
1214 __u8 lpm
, opm
= path_data
->opm
;
1217 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1220 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1221 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1222 data
->cqr
.cpaddr
= &data
->ccw
;
1223 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1228 if (rc
== -EOPNOTSUPP
) /* -EOPNOTSUPP is ok */
1230 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1231 "Read configuration data "
1232 "returned error %d", rc
);
1235 memcpy(private->conf_data
, data
->rcd_buffer
,
1236 DASD_ECKD_RCD_DATA_SIZE
);
1237 if (dasd_eckd_identify_conf_parts(private)) {
1239 } else /* first valid path is enough */
1244 rc
= dasd_eckd_generate_uid(device
);
1249 static void do_path_verification_work(struct work_struct
*work
)
1251 struct path_verification_work_data
*data
;
1252 struct dasd_device
*device
;
1253 struct dasd_eckd_private path_private
;
1254 struct dasd_uid
*uid
;
1255 __u8 path_rcd_buf
[DASD_ECKD_RCD_DATA_SIZE
];
1256 __u8 lpm
, opm
, npm
, ppm
, epm
, hpfpm
, cablepm
;
1257 unsigned long flags
;
1261 data
= container_of(work
, struct path_verification_work_data
, worker
);
1262 device
= data
->device
;
1264 /* delay path verification until device was resumed */
1265 if (test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
1266 schedule_work(work
);
1269 /* check if path verification already running and delay if so */
1270 if (test_and_set_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
)) {
1271 schedule_work(work
);
1281 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1282 if (!(lpm
& data
->tbvpm
))
1284 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1285 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1286 data
->cqr
.cpaddr
= &data
->ccw
;
1287 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1291 switch (dasd_eckd_path_access(data
->rcd_buffer
,
1292 DASD_ECKD_RCD_DATA_SIZE
)
1302 } else if (rc
== -EOPNOTSUPP
) {
1303 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1304 "path verification: No configuration "
1307 } else if (rc
== -EAGAIN
) {
1308 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1309 "path verification: device is stopped,"
1310 " try again later");
1313 dev_warn(&device
->cdev
->dev
,
1314 "Reading device feature codes failed "
1315 "(rc=%d) for new path %x\n", rc
, lpm
);
1318 if (verify_fcx_max_data(device
, lpm
)) {
1327 * save conf_data for comparison after
1328 * rebuild_device_uid may have changed
1331 memcpy(&path_rcd_buf
, data
->rcd_buffer
,
1332 DASD_ECKD_RCD_DATA_SIZE
);
1333 path_private
.conf_data
= (void *) &path_rcd_buf
;
1334 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1335 if (dasd_eckd_identify_conf_parts(&path_private
)) {
1336 path_private
.conf_data
= NULL
;
1337 path_private
.conf_len
= 0;
1342 * compare path UID with device UID only if at least
1343 * one valid path is left
1344 * in other case the device UID may have changed and
1345 * the first working path UID will be used as device UID
1347 if (device
->path_data
.opm
&&
1348 dasd_eckd_compare_path_uid(device
, &path_private
)) {
1350 * the comparison was not successful
1351 * rebuild the device UID with at least one
1352 * known path in case a z/VM hyperswap command
1353 * has changed the device
1355 * after this compare again
1357 * if either the rebuild or the recompare fails
1358 * the path can not be used
1360 if (rebuild_device_uid(device
, data
) ||
1361 dasd_eckd_compare_path_uid(
1362 device
, &path_private
)) {
1363 uid
= &path_private
.uid
;
1364 if (strlen(uid
->vduit
) > 0)
1365 snprintf(print_uid
, sizeof(print_uid
),
1366 "%s.%s.%04x.%02x.%s",
1367 uid
->vendor
, uid
->serial
,
1368 uid
->ssid
, uid
->real_unit_addr
,
1371 snprintf(print_uid
, sizeof(print_uid
),
1373 uid
->vendor
, uid
->serial
,
1375 uid
->real_unit_addr
);
1376 dev_err(&device
->cdev
->dev
,
1377 "The newly added channel path %02X "
1378 "will not be used because it leads "
1379 "to a different device %s\n",
1390 * There is a small chance that a path is lost again between
1391 * above path verification and the following modification of
1392 * the device opm mask. We could avoid that race here by using
1393 * yet another path mask, but we rather deal with this unlikely
1394 * situation in dasd_start_IO.
1396 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1397 if (!device
->path_data
.opm
&& opm
) {
1398 device
->path_data
.opm
= opm
;
1399 device
->path_data
.cablepm
&= ~opm
;
1400 device
->path_data
.cuirpm
&= ~opm
;
1401 device
->path_data
.hpfpm
&= ~opm
;
1402 dasd_generic_path_operational(device
);
1404 device
->path_data
.opm
|= opm
;
1405 device
->path_data
.cablepm
&= ~opm
;
1406 device
->path_data
.cuirpm
&= ~opm
;
1407 device
->path_data
.hpfpm
&= ~opm
;
1409 device
->path_data
.npm
|= npm
;
1410 device
->path_data
.ppm
|= ppm
;
1411 device
->path_data
.tbvpm
|= epm
;
1412 device
->path_data
.cablepm
|= cablepm
;
1413 device
->path_data
.hpfpm
|= hpfpm
;
1414 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1416 clear_bit(DASD_FLAG_PATH_VERIFY
, &device
->flags
);
1417 dasd_put_device(device
);
1419 mutex_unlock(&dasd_path_verification_mutex
);
1424 static int dasd_eckd_verify_path(struct dasd_device
*device
, __u8 lpm
)
1426 struct path_verification_work_data
*data
;
1428 data
= kmalloc(sizeof(*data
), GFP_ATOMIC
| GFP_DMA
);
1430 if (mutex_trylock(&dasd_path_verification_mutex
)) {
1431 data
= path_verification_worker
;
1436 memset(data
, 0, sizeof(*data
));
1439 INIT_WORK(&data
->worker
, do_path_verification_work
);
1440 dasd_get_device(device
);
1441 data
->device
= device
;
1443 schedule_work(&data
->worker
);
1447 static int dasd_eckd_read_features(struct dasd_device
*device
)
1449 struct dasd_eckd_private
*private = device
->private;
1450 struct dasd_psf_prssd_data
*prssdp
;
1451 struct dasd_rssd_features
*features
;
1452 struct dasd_ccw_req
*cqr
;
1456 memset(&private->features
, 0, sizeof(struct dasd_rssd_features
));
1457 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
1458 (sizeof(struct dasd_psf_prssd_data
) +
1459 sizeof(struct dasd_rssd_features
)),
1462 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s", "Could not "
1463 "allocate initialization request");
1464 return PTR_ERR(cqr
);
1466 cqr
->startdev
= device
;
1467 cqr
->memdev
= device
;
1470 cqr
->expires
= 10 * HZ
;
1472 /* Prepare for Read Subsystem Data */
1473 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1474 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1475 prssdp
->order
= PSF_ORDER_PRSSD
;
1476 prssdp
->suborder
= 0x41; /* Read Feature Codes */
1477 /* all other bytes of prssdp must be zero */
1480 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1481 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1482 ccw
->flags
|= CCW_FLAG_CC
;
1483 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1485 /* Read Subsystem Data - feature codes */
1486 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1487 memset(features
, 0, sizeof(struct dasd_rssd_features
));
1490 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1491 ccw
->count
= sizeof(struct dasd_rssd_features
);
1492 ccw
->cda
= (__u32
)(addr_t
) features
;
1494 cqr
->buildclk
= get_tod_clock();
1495 cqr
->status
= DASD_CQR_FILLED
;
1496 rc
= dasd_sleep_on(cqr
);
1498 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1499 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1500 memcpy(&private->features
, features
,
1501 sizeof(struct dasd_rssd_features
));
1503 dev_warn(&device
->cdev
->dev
, "Reading device feature codes"
1504 " failed with rc=%d\n", rc
);
1505 dasd_sfree_request(cqr
, cqr
->memdev
);
1511 * Build CP for Perform Subsystem Function - SSC.
1513 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
,
1516 struct dasd_ccw_req
*cqr
;
1517 struct dasd_psf_ssc_data
*psf_ssc_data
;
1520 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
1521 sizeof(struct dasd_psf_ssc_data
),
1525 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1526 "Could not allocate PSF-SSC request");
1529 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
1530 psf_ssc_data
->order
= PSF_ORDER_SSC
;
1531 psf_ssc_data
->suborder
= 0xc0;
1533 psf_ssc_data
->suborder
|= 0x08;
1534 psf_ssc_data
->reserved
[0] = 0x88;
1537 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1538 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
1541 cqr
->startdev
= device
;
1542 cqr
->memdev
= device
;
1545 cqr
->expires
= 10*HZ
;
1546 cqr
->buildclk
= get_tod_clock();
1547 cqr
->status
= DASD_CQR_FILLED
;
1552 * Perform Subsystem Function.
1553 * It is necessary to trigger CIO for channel revalidation since this
1554 * call might change behaviour of DASD devices.
1557 dasd_eckd_psf_ssc(struct dasd_device
*device
, int enable_pav
,
1558 unsigned long flags
)
1560 struct dasd_ccw_req
*cqr
;
1563 cqr
= dasd_eckd_build_psf_ssc(device
, enable_pav
);
1565 return PTR_ERR(cqr
);
1568 * set flags e.g. turn on failfast, to prevent blocking
1569 * the calling function should handle failed requests
1571 cqr
->flags
|= flags
;
1573 rc
= dasd_sleep_on(cqr
);
1575 /* trigger CIO to reprobe devices */
1576 css_schedule_reprobe();
1577 else if (cqr
->intrc
== -EAGAIN
)
1580 dasd_sfree_request(cqr
, cqr
->memdev
);
1585 * Valide storage server of current device.
1587 static int dasd_eckd_validate_server(struct dasd_device
*device
,
1588 unsigned long flags
)
1590 struct dasd_eckd_private
*private = device
->private;
1593 if (private->uid
.type
== UA_BASE_PAV_ALIAS
||
1594 private->uid
.type
== UA_HYPER_PAV_ALIAS
)
1596 if (dasd_nopav
|| MACHINE_IS_VM
)
1600 rc
= dasd_eckd_psf_ssc(device
, enable_pav
, flags
);
1602 /* may be requested feature is not available on server,
1603 * therefore just report error and go ahead */
1604 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "PSF-SSC for SSID %04x "
1605 "returned rc=%d", private->uid
.ssid
, rc
);
1610 * worker to do a validate server in case of a lost pathgroup
1612 static void dasd_eckd_do_validate_server(struct work_struct
*work
)
1614 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
1616 unsigned long flags
= 0;
1618 set_bit(DASD_CQR_FLAGS_FAILFAST
, &flags
);
1619 if (dasd_eckd_validate_server(device
, flags
)
1621 /* schedule worker again if failed */
1622 schedule_work(&device
->kick_validate
);
1626 dasd_put_device(device
);
1629 static void dasd_eckd_kick_validate_server(struct dasd_device
*device
)
1631 dasd_get_device(device
);
1632 /* exit if device not online or in offline processing */
1633 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1634 device
->state
< DASD_STATE_ONLINE
) {
1635 dasd_put_device(device
);
1638 /* queue call to do_validate_server to the kernel event daemon. */
1639 if (!schedule_work(&device
->kick_validate
))
1640 dasd_put_device(device
);
1643 static u32
get_fcx_max_data(struct dasd_device
*device
)
1645 struct dasd_eckd_private
*private = device
->private;
1646 int fcx_in_css
, fcx_in_gneq
, fcx_in_features
;
1651 /* is transport mode supported? */
1652 fcx_in_css
= css_general_characteristics
.fcx
;
1653 fcx_in_gneq
= private->gneq
->reserved2
[7] & 0x04;
1654 fcx_in_features
= private->features
.feature
[40] & 0x80;
1655 tpm
= fcx_in_css
&& fcx_in_gneq
&& fcx_in_features
;
1660 mdc
= ccw_device_get_mdc(device
->cdev
, 0);
1662 dev_warn(&device
->cdev
->dev
, "Detecting the maximum supported"
1663 " data size for zHPF requests failed\n");
1666 return mdc
* FCX_MAX_DATA_FACTOR
;
1670 * Check device characteristics.
1671 * If the device is accessible using ECKD discipline, the device is enabled.
1674 dasd_eckd_check_characteristics(struct dasd_device
*device
)
1676 struct dasd_eckd_private
*private = device
->private;
1677 struct dasd_block
*block
;
1678 struct dasd_uid temp_uid
;
1681 unsigned long value
;
1683 /* setup work queue for validate server*/
1684 INIT_WORK(&device
->kick_validate
, dasd_eckd_do_validate_server
);
1685 /* setup work queue for summary unit check */
1686 INIT_WORK(&device
->suc_work
, dasd_alias_handle_summary_unit_check
);
1688 if (!ccw_device_is_pathgroup(device
->cdev
)) {
1689 dev_warn(&device
->cdev
->dev
,
1690 "A channel path group could not be established\n");
1693 if (!ccw_device_is_multipath(device
->cdev
)) {
1694 dev_info(&device
->cdev
->dev
,
1695 "The DASD is not operating in multipath mode\n");
1698 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
1700 dev_warn(&device
->cdev
->dev
,
1701 "Allocating memory for private DASD data "
1705 device
->private = private;
1707 memset(private, 0, sizeof(*private));
1709 /* Invalidate status of initial analysis. */
1710 private->init_cqr_status
= -1;
1711 /* Set default cache operations. */
1712 private->attrib
.operation
= DASD_NORMAL_CACHE
;
1713 private->attrib
.nr_cyl
= 0;
1715 /* Read Configuration Data */
1716 rc
= dasd_eckd_read_conf(device
);
1720 /* set default timeout */
1721 device
->default_expires
= DASD_EXPIRES
;
1722 /* set default retry count */
1723 device
->default_retries
= DASD_RETRIES
;
1725 if (private->gneq
) {
1727 for (i
= 0; i
< private->gneq
->timeout
.value
; i
++)
1729 value
= value
* private->gneq
->timeout
.number
;
1730 /* do not accept useless values */
1731 if (value
!= 0 && value
<= DASD_EXPIRES_MAX
)
1732 device
->default_expires
= value
;
1735 dasd_eckd_get_uid(device
, &temp_uid
);
1736 if (temp_uid
.type
== UA_BASE_DEVICE
) {
1737 block
= dasd_alloc_block();
1738 if (IS_ERR(block
)) {
1739 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1740 "could not allocate dasd "
1742 rc
= PTR_ERR(block
);
1745 device
->block
= block
;
1746 block
->base
= device
;
1749 /* register lcu with alias handling, enable PAV */
1750 rc
= dasd_alias_make_device_known_to_lcu(device
);
1754 dasd_eckd_validate_server(device
, 0);
1756 /* device may report different configuration data after LCU setup */
1757 rc
= dasd_eckd_read_conf(device
);
1761 /* Read Feature Codes */
1762 dasd_eckd_read_features(device
);
1764 /* Read Device Characteristics */
1765 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
1766 &private->rdc_data
, 64);
1768 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1769 "Read device characteristic failed, rc=%d", rc
);
1773 if ((device
->features
& DASD_FEATURE_USERAW
) &&
1774 !(private->rdc_data
.facilities
.RT_in_LR
)) {
1775 dev_err(&device
->cdev
->dev
, "The storage server does not "
1776 "support raw-track access\n");
1781 /* find the valid cylinder size */
1782 if (private->rdc_data
.no_cyl
== LV_COMPAT_CYL
&&
1783 private->rdc_data
.long_no_cyl
)
1784 private->real_cyl
= private->rdc_data
.long_no_cyl
;
1786 private->real_cyl
= private->rdc_data
.no_cyl
;
1788 private->fcx_max_data
= get_fcx_max_data(device
);
1790 readonly
= dasd_device_is_ro(device
);
1792 set_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
1794 dev_info(&device
->cdev
->dev
, "New DASD %04X/%02X (CU %04X/%02X) "
1795 "with %d cylinders, %d heads, %d sectors%s\n",
1796 private->rdc_data
.dev_type
,
1797 private->rdc_data
.dev_model
,
1798 private->rdc_data
.cu_type
,
1799 private->rdc_data
.cu_model
.model
,
1801 private->rdc_data
.trk_per_cyl
,
1802 private->rdc_data
.sec_per_trk
,
1803 readonly
? ", read-only device" : "");
1807 dasd_alias_disconnect_device_from_lcu(device
);
1809 dasd_free_block(device
->block
);
1810 device
->block
= NULL
;
1812 kfree(private->conf_data
);
1813 kfree(device
->private);
1814 device
->private = NULL
;
1818 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
1820 struct dasd_eckd_private
*private = device
->private;
1823 dasd_alias_disconnect_device_from_lcu(device
);
1824 private->ned
= NULL
;
1825 private->sneq
= NULL
;
1826 private->vdsneq
= NULL
;
1827 private->gneq
= NULL
;
1828 private->conf_len
= 0;
1829 for (i
= 0; i
< 8; i
++) {
1830 kfree(private->path_conf_data
[i
]);
1831 if ((__u8
*)private->path_conf_data
[i
] ==
1832 private->conf_data
) {
1833 private->conf_data
= NULL
;
1834 private->conf_len
= 0;
1836 private->path_conf_data
[i
] = NULL
;
1838 kfree(private->conf_data
);
1839 private->conf_data
= NULL
;
1842 static struct dasd_ccw_req
*
1843 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
1845 struct dasd_eckd_private
*private = device
->private;
1846 struct eckd_count
*count_data
;
1847 struct LO_eckd_data
*LO_data
;
1848 struct dasd_ccw_req
*cqr
;
1850 int cplength
, datasize
;
1854 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
1855 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
1859 /* Define extent for the first 3 tracks. */
1860 define_extent(ccw
++, cqr
->data
, 0, 2,
1861 DASD_ECKD_CCW_READ_COUNT
, device
);
1862 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
1863 /* Locate record for the first 4 records on track 0. */
1864 ccw
[-1].flags
|= CCW_FLAG_CC
;
1865 locate_record(ccw
++, LO_data
++, 0, 0, 4,
1866 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1868 count_data
= private->count_area
;
1869 for (i
= 0; i
< 4; i
++) {
1870 ccw
[-1].flags
|= CCW_FLAG_CC
;
1871 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1874 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1879 /* Locate record for the first record on track 2. */
1880 ccw
[-1].flags
|= CCW_FLAG_CC
;
1881 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1882 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1883 /* Read count ccw. */
1884 ccw
[-1].flags
|= CCW_FLAG_CC
;
1885 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1888 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1891 cqr
->startdev
= device
;
1892 cqr
->memdev
= device
;
1894 cqr
->buildclk
= get_tod_clock();
1895 cqr
->status
= DASD_CQR_FILLED
;
1899 /* differentiate between 'no record found' and any other error */
1900 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req
*init_cqr
)
1903 if (init_cqr
->status
== DASD_CQR_DONE
)
1905 else if (init_cqr
->status
== DASD_CQR_NEED_ERP
||
1906 init_cqr
->status
== DASD_CQR_FAILED
) {
1907 sense
= dasd_get_sense(&init_cqr
->irb
);
1908 if (sense
&& (sense
[1] & SNS1_NO_REC_FOUND
))
1909 return INIT_CQR_UNFORMATTED
;
1911 return INIT_CQR_ERROR
;
1913 return INIT_CQR_ERROR
;
1917 * This is the callback function for the init_analysis cqr. It saves
1918 * the status of the initial analysis ccw before it frees it and kicks
1919 * the device to continue the startup sequence. This will call
1920 * dasd_eckd_do_analysis again (if the devices has not been marked
1921 * for deletion in the meantime).
1923 static void dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
,
1926 struct dasd_device
*device
= init_cqr
->startdev
;
1927 struct dasd_eckd_private
*private = device
->private;
1929 private->init_cqr_status
= dasd_eckd_analysis_evaluation(init_cqr
);
1930 dasd_sfree_request(init_cqr
, device
);
1931 dasd_kick_device(device
);
1934 static int dasd_eckd_start_analysis(struct dasd_block
*block
)
1936 struct dasd_ccw_req
*init_cqr
;
1938 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1939 if (IS_ERR(init_cqr
))
1940 return PTR_ERR(init_cqr
);
1941 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1942 init_cqr
->callback_data
= NULL
;
1943 init_cqr
->expires
= 5*HZ
;
1944 /* first try without ERP, so we can later handle unformatted
1945 * devices as special case
1947 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &init_cqr
->flags
);
1948 init_cqr
->retries
= 0;
1949 dasd_add_request_head(init_cqr
);
1953 static int dasd_eckd_end_analysis(struct dasd_block
*block
)
1955 struct dasd_device
*device
= block
->base
;
1956 struct dasd_eckd_private
*private = device
->private;
1957 struct eckd_count
*count_area
;
1958 unsigned int sb
, blk_per_trk
;
1960 struct dasd_ccw_req
*init_cqr
;
1962 status
= private->init_cqr_status
;
1963 private->init_cqr_status
= -1;
1964 if (status
== INIT_CQR_ERROR
) {
1965 /* try again, this time with full ERP */
1966 init_cqr
= dasd_eckd_analysis_ccw(device
);
1967 dasd_sleep_on(init_cqr
);
1968 status
= dasd_eckd_analysis_evaluation(init_cqr
);
1969 dasd_sfree_request(init_cqr
, device
);
1972 if (device
->features
& DASD_FEATURE_USERAW
) {
1973 block
->bp_block
= DASD_RAW_BLOCKSIZE
;
1974 blk_per_trk
= DASD_RAW_BLOCK_PER_TRACK
;
1975 block
->s2b_shift
= 3;
1979 if (status
== INIT_CQR_UNFORMATTED
) {
1980 dev_warn(&device
->cdev
->dev
, "The DASD is not formatted\n");
1981 return -EMEDIUMTYPE
;
1982 } else if (status
== INIT_CQR_ERROR
) {
1983 dev_err(&device
->cdev
->dev
,
1984 "Detecting the DASD disk layout failed because "
1985 "of an I/O error\n");
1989 private->uses_cdl
= 1;
1990 /* Check Track 0 for Compatible Disk Layout */
1992 for (i
= 0; i
< 3; i
++) {
1993 if (private->count_area
[i
].kl
!= 4 ||
1994 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4 ||
1995 private->count_area
[i
].cyl
!= 0 ||
1996 private->count_area
[i
].head
!= count_area_head
[i
] ||
1997 private->count_area
[i
].record
!= count_area_rec
[i
]) {
1998 private->uses_cdl
= 0;
2003 count_area
= &private->count_area
[4];
2005 if (private->uses_cdl
== 0) {
2006 for (i
= 0; i
< 5; i
++) {
2007 if ((private->count_area
[i
].kl
!= 0) ||
2008 (private->count_area
[i
].dl
!=
2009 private->count_area
[0].dl
) ||
2010 private->count_area
[i
].cyl
!= 0 ||
2011 private->count_area
[i
].head
!= count_area_head
[i
] ||
2012 private->count_area
[i
].record
!= count_area_rec
[i
])
2016 count_area
= &private->count_area
[0];
2018 if (private->count_area
[3].record
== 1)
2019 dev_warn(&device
->cdev
->dev
,
2020 "Track 0 has no records following the VTOC\n");
2023 if (count_area
!= NULL
&& count_area
->kl
== 0) {
2024 /* we found notthing violating our disk layout */
2025 if (dasd_check_blocksize(count_area
->dl
) == 0)
2026 block
->bp_block
= count_area
->dl
;
2028 if (block
->bp_block
== 0) {
2029 dev_warn(&device
->cdev
->dev
,
2030 "The disk layout of the DASD is not supported\n");
2031 return -EMEDIUMTYPE
;
2033 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
2034 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
2037 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
2040 block
->blocks
= (private->real_cyl
*
2041 private->rdc_data
.trk_per_cyl
*
2044 dev_info(&device
->cdev
->dev
,
2045 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2046 "%s\n", (block
->bp_block
>> 10),
2047 ((private->real_cyl
*
2048 private->rdc_data
.trk_per_cyl
*
2049 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
2050 ((blk_per_trk
* block
->bp_block
) >> 10),
2052 "compatible disk layout" : "linux disk layout");
2057 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
2059 struct dasd_eckd_private
*private = block
->base
->private;
2061 if (private->init_cqr_status
< 0)
2062 return dasd_eckd_start_analysis(block
);
2064 return dasd_eckd_end_analysis(block
);
2067 static int dasd_eckd_basic_to_ready(struct dasd_device
*device
)
2069 return dasd_alias_add_device(device
);
2072 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
2074 cancel_work_sync(&device
->reload_device
);
2075 cancel_work_sync(&device
->kick_validate
);
2079 static int dasd_eckd_basic_to_known(struct dasd_device
*device
)
2081 return dasd_alias_remove_device(device
);
2085 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
2087 struct dasd_eckd_private
*private = block
->base
->private;
2089 if (dasd_check_blocksize(block
->bp_block
) == 0) {
2090 geo
->sectors
= recs_per_track(&private->rdc_data
,
2091 0, block
->bp_block
);
2093 geo
->cylinders
= private->rdc_data
.no_cyl
;
2094 geo
->heads
= private->rdc_data
.trk_per_cyl
;
2098 static struct dasd_ccw_req
*
2099 dasd_eckd_build_format(struct dasd_device
*base
,
2100 struct format_data_t
*fdata
,
2103 struct dasd_eckd_private
*base_priv
;
2104 struct dasd_eckd_private
*start_priv
;
2105 struct dasd_device
*startdev
= NULL
;
2106 struct dasd_ccw_req
*fcp
;
2107 struct eckd_count
*ect
;
2108 struct ch_t address
;
2112 int cplength
, datasize
;
2120 startdev
= dasd_alias_get_start_dev(base
);
2125 start_priv
= startdev
->private;
2126 base_priv
= base
->private;
2128 rpt
= recs_per_track(&base_priv
->rdc_data
, 0, fdata
->blksize
);
2130 nr_tracks
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2133 * fdata->intensity is a bit string that tells us what to do:
2134 * Bit 0: write record zero
2135 * Bit 1: write home address, currently not supported
2136 * Bit 2: invalidate tracks
2137 * Bit 3: use OS/390 compatible disk layout (cdl)
2138 * Bit 4: do not allow storage subsystem to modify record zero
2139 * Only some bit combinations do make sense.
2141 if (fdata
->intensity
& 0x10) {
2143 intensity
= fdata
->intensity
& ~0x10;
2146 intensity
= fdata
->intensity
;
2149 use_prefix
= base_priv
->features
.feature
[8] & 0x01;
2151 switch (intensity
) {
2152 case 0x00: /* Normal format */
2153 case 0x08: /* Normal format, use cdl. */
2154 cplength
= 2 + (rpt
*nr_tracks
);
2156 datasize
= sizeof(struct PFX_eckd_data
) +
2157 sizeof(struct LO_eckd_data
) +
2158 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2160 datasize
= sizeof(struct DE_eckd_data
) +
2161 sizeof(struct LO_eckd_data
) +
2162 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2164 case 0x01: /* Write record zero and format track. */
2165 case 0x09: /* Write record zero and format track, use cdl. */
2166 cplength
= 2 + rpt
* nr_tracks
;
2168 datasize
= sizeof(struct PFX_eckd_data
) +
2169 sizeof(struct LO_eckd_data
) +
2170 sizeof(struct eckd_count
) +
2171 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2173 datasize
= sizeof(struct DE_eckd_data
) +
2174 sizeof(struct LO_eckd_data
) +
2175 sizeof(struct eckd_count
) +
2176 rpt
* nr_tracks
* sizeof(struct eckd_count
);
2178 case 0x04: /* Invalidate track. */
2179 case 0x0c: /* Invalidate track, use cdl. */
2182 datasize
= sizeof(struct PFX_eckd_data
) +
2183 sizeof(struct LO_eckd_data
) +
2184 sizeof(struct eckd_count
);
2186 datasize
= sizeof(struct DE_eckd_data
) +
2187 sizeof(struct LO_eckd_data
) +
2188 sizeof(struct eckd_count
);
2191 dev_warn(&startdev
->cdev
->dev
,
2192 "An I/O control call used incorrect flags 0x%x\n",
2194 return ERR_PTR(-EINVAL
);
2196 /* Allocate the format ccw request. */
2197 fcp
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
2198 datasize
, startdev
);
2202 start_priv
->count
++;
2206 switch (intensity
& ~0x08) {
2207 case 0x00: /* Normal format. */
2209 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2210 fdata
->start_unit
, fdata
->stop_unit
,
2211 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2212 /* grant subsystem permission to format R0 */
2214 ((struct PFX_eckd_data
*)data
)
2215 ->define_extent
.ga_extended
|= 0x04;
2216 data
+= sizeof(struct PFX_eckd_data
);
2218 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2219 fdata
->start_unit
, fdata
->stop_unit
,
2220 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2221 /* grant subsystem permission to format R0 */
2223 ((struct DE_eckd_data
*) data
)
2224 ->ga_extended
|= 0x04;
2225 data
+= sizeof(struct DE_eckd_data
);
2227 ccw
[-1].flags
|= CCW_FLAG_CC
;
2228 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2229 fdata
->start_unit
, 0, rpt
*nr_tracks
,
2230 DASD_ECKD_CCW_WRITE_CKD
, base
,
2232 data
+= sizeof(struct LO_eckd_data
);
2234 case 0x01: /* Write record zero + format track. */
2236 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2237 fdata
->start_unit
, fdata
->stop_unit
,
2238 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
2240 data
+= sizeof(struct PFX_eckd_data
);
2242 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2243 fdata
->start_unit
, fdata
->stop_unit
,
2244 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, startdev
);
2245 data
+= sizeof(struct DE_eckd_data
);
2247 ccw
[-1].flags
|= CCW_FLAG_CC
;
2248 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2249 fdata
->start_unit
, 0, rpt
* nr_tracks
+ 1,
2250 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, base
,
2251 base
->block
->bp_block
);
2252 data
+= sizeof(struct LO_eckd_data
);
2254 case 0x04: /* Invalidate track. */
2256 prefix(ccw
++, (struct PFX_eckd_data
*) data
,
2257 fdata
->start_unit
, fdata
->stop_unit
,
2258 DASD_ECKD_CCW_WRITE_CKD
, base
, startdev
);
2259 data
+= sizeof(struct PFX_eckd_data
);
2261 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2262 fdata
->start_unit
, fdata
->stop_unit
,
2263 DASD_ECKD_CCW_WRITE_CKD
, startdev
);
2264 data
+= sizeof(struct DE_eckd_data
);
2266 ccw
[-1].flags
|= CCW_FLAG_CC
;
2267 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2268 fdata
->start_unit
, 0, 1,
2269 DASD_ECKD_CCW_WRITE_CKD
, base
, 8);
2270 data
+= sizeof(struct LO_eckd_data
);
2274 for (j
= 0; j
< nr_tracks
; j
++) {
2275 /* calculate cylinder and head for the current track */
2277 (fdata
->start_unit
+ j
) /
2278 base_priv
->rdc_data
.trk_per_cyl
,
2279 (fdata
->start_unit
+ j
) %
2280 base_priv
->rdc_data
.trk_per_cyl
);
2281 if (intensity
& 0x01) { /* write record zero */
2282 ect
= (struct eckd_count
*) data
;
2283 data
+= sizeof(struct eckd_count
);
2284 ect
->cyl
= address
.cyl
;
2285 ect
->head
= address
.head
;
2289 ccw
[-1].flags
|= CCW_FLAG_CC
;
2290 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
2291 ccw
->flags
= CCW_FLAG_SLI
;
2293 ccw
->cda
= (__u32
)(addr_t
) ect
;
2296 if ((intensity
& ~0x08) & 0x04) { /* erase track */
2297 ect
= (struct eckd_count
*) data
;
2298 data
+= sizeof(struct eckd_count
);
2299 ect
->cyl
= address
.cyl
;
2300 ect
->head
= address
.head
;
2304 ccw
[-1].flags
|= CCW_FLAG_CC
;
2305 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2306 ccw
->flags
= CCW_FLAG_SLI
;
2308 ccw
->cda
= (__u32
)(addr_t
) ect
;
2309 } else { /* write remaining records */
2310 for (i
= 0; i
< rpt
; i
++) {
2311 ect
= (struct eckd_count
*) data
;
2312 data
+= sizeof(struct eckd_count
);
2313 ect
->cyl
= address
.cyl
;
2314 ect
->head
= address
.head
;
2315 ect
->record
= i
+ 1;
2317 ect
->dl
= fdata
->blksize
;
2319 * Check for special tracks 0-1
2320 * when formatting CDL
2322 if ((intensity
& 0x08) &&
2323 address
.cyl
== 0 && address
.head
== 0) {
2326 ect
->dl
= sizes_trk0
[i
] - 4;
2329 if ((intensity
& 0x08) &&
2330 address
.cyl
== 0 && address
.head
== 1) {
2332 ect
->dl
= LABEL_SIZE
- 44;
2334 ccw
[-1].flags
|= CCW_FLAG_CC
;
2335 if (i
!= 0 || j
== 0)
2337 DASD_ECKD_CCW_WRITE_CKD
;
2340 DASD_ECKD_CCW_WRITE_CKD_MT
;
2341 ccw
->flags
= CCW_FLAG_SLI
;
2343 ccw
->cda
= (__u32
)(addr_t
) ect
;
2349 fcp
->startdev
= startdev
;
2350 fcp
->memdev
= startdev
;
2351 fcp
->basedev
= base
;
2353 fcp
->expires
= startdev
->default_expires
* HZ
;
2354 fcp
->buildclk
= get_tod_clock();
2355 fcp
->status
= DASD_CQR_FILLED
;
2361 * Wrapper function to build a CCW request depending on input data
2363 static struct dasd_ccw_req
*
2364 dasd_eckd_format_build_ccw_req(struct dasd_device
*base
,
2365 struct format_data_t
*fdata
, int enable_pav
)
2367 return dasd_eckd_build_format(base
, fdata
, enable_pav
);
2371 * Sanity checks on format_data
2373 static int dasd_eckd_format_sanity_checks(struct dasd_device
*base
,
2374 struct format_data_t
*fdata
)
2376 struct dasd_eckd_private
*private = base
->private;
2378 if (fdata
->start_unit
>=
2379 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2380 dev_warn(&base
->cdev
->dev
,
2381 "Start track number %u used in formatting is too big\n",
2385 if (fdata
->stop_unit
>=
2386 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2387 dev_warn(&base
->cdev
->dev
,
2388 "Stop track number %u used in formatting is too big\n",
2392 if (fdata
->start_unit
> fdata
->stop_unit
) {
2393 dev_warn(&base
->cdev
->dev
,
2394 "Start track %u used in formatting exceeds end track\n",
2398 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
2399 dev_warn(&base
->cdev
->dev
,
2400 "The DASD cannot be formatted with block size %u\n",
2408 * This function will process format_data originally coming from an IOCTL
2410 static int dasd_eckd_format_process_data(struct dasd_device
*base
,
2411 struct format_data_t
*fdata
,
2414 struct dasd_eckd_private
*private = base
->private;
2415 struct dasd_ccw_req
*cqr
, *n
;
2416 struct list_head format_queue
;
2417 struct dasd_device
*device
;
2418 int old_start
, old_stop
, format_step
;
2422 rc
= dasd_eckd_format_sanity_checks(base
, fdata
);
2426 INIT_LIST_HEAD(&format_queue
);
2428 old_start
= fdata
->start_unit
;
2429 old_stop
= fdata
->stop_unit
;
2431 format_step
= DASD_CQR_MAX_CCW
/ recs_per_track(&private->rdc_data
, 0,
2435 while (fdata
->start_unit
<= old_stop
) {
2436 step
= fdata
->stop_unit
- fdata
->start_unit
+ 1;
2437 if (step
> format_step
) {
2439 fdata
->start_unit
+ format_step
- 1;
2442 cqr
= dasd_eckd_format_build_ccw_req(base
, fdata
,
2446 if (rc
== -ENOMEM
) {
2447 if (list_empty(&format_queue
))
2450 * not enough memory available, start
2451 * requests retry after first requests
2459 list_add_tail(&cqr
->blocklist
, &format_queue
);
2461 fdata
->start_unit
= fdata
->stop_unit
+ 1;
2462 fdata
->stop_unit
= old_stop
;
2465 rc
= dasd_sleep_on_queue(&format_queue
);
2468 list_for_each_entry_safe(cqr
, n
, &format_queue
, blocklist
) {
2469 device
= cqr
->startdev
;
2470 private = device
->private;
2471 if (cqr
->status
== DASD_CQR_FAILED
)
2473 list_del_init(&cqr
->blocklist
);
2474 dasd_sfree_request(cqr
, device
);
2484 fdata
->start_unit
= old_start
;
2485 fdata
->stop_unit
= old_stop
;
2490 static int dasd_eckd_format_device(struct dasd_device
*base
,
2491 struct format_data_t
*fdata
, int enable_pav
)
2493 return dasd_eckd_format_process_data(base
, fdata
, enable_pav
);
2496 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
2498 if (cqr
->retries
< 0) {
2499 cqr
->status
= DASD_CQR_FAILED
;
2502 cqr
->status
= DASD_CQR_FILLED
;
2503 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
2504 dasd_eckd_reset_ccw_to_base_io(cqr
);
2505 cqr
->startdev
= cqr
->block
->base
;
2506 cqr
->lpm
= cqr
->block
->base
->path_data
.opm
;
2510 static dasd_erp_fn_t
2511 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
2513 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
2514 struct ccw_device
*cdev
= device
->cdev
;
2516 switch (cdev
->id
.cu_type
) {
2521 return dasd_3990_erp_action
;
2525 return dasd_default_erp_action
;
2529 static dasd_erp_fn_t
2530 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
2532 return dasd_default_erp_postaction
;
2535 static void dasd_eckd_check_for_device_change(struct dasd_device
*device
,
2536 struct dasd_ccw_req
*cqr
,
2541 struct dasd_eckd_private
*private = device
->private;
2543 /* first of all check for state change pending interrupt */
2544 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
2545 if ((scsw_dstat(&irb
->scsw
) & mask
) == mask
) {
2547 * for alias only, not in offline processing
2548 * and only if not suspended
2550 if (!device
->block
&& private->lcu
&&
2551 device
->state
== DASD_STATE_ONLINE
&&
2552 !test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
2553 !test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
2554 /* schedule worker to reload device */
2555 dasd_reload_device(device
);
2557 dasd_generic_handle_state_change(device
);
2561 sense
= dasd_get_sense(irb
);
2565 /* summary unit check */
2566 if ((sense
[27] & DASD_SENSE_BIT_0
) && (sense
[7] == 0x0D) &&
2567 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
)) {
2568 if (test_and_set_bit(DASD_FLAG_SUC
, &device
->flags
)) {
2569 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
2570 "eckd suc: device already notified");
2573 sense
= dasd_get_sense(irb
);
2575 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
2576 "eckd suc: no reason code available");
2577 clear_bit(DASD_FLAG_SUC
, &device
->flags
);
2581 private->suc_reason
= sense
[8];
2582 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
2583 "eckd handle summary unit check: reason",
2584 private->suc_reason
);
2585 dasd_get_device(device
);
2586 if (!schedule_work(&device
->suc_work
))
2587 dasd_put_device(device
);
2592 /* service information message SIM */
2593 if (!cqr
&& !(sense
[27] & DASD_SENSE_BIT_0
) &&
2594 ((sense
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
)) {
2595 dasd_3990_erp_handle_sim(device
, sense
);
2599 /* loss of device reservation is handled via base devices only
2600 * as alias devices may be used with several bases
2602 if (device
->block
&& (sense
[27] & DASD_SENSE_BIT_0
) &&
2603 (sense
[7] == 0x3F) &&
2604 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
) &&
2605 test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
)) {
2606 if (device
->features
& DASD_FEATURE_FAILONSLCK
)
2607 set_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
2608 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
2609 dev_err(&device
->cdev
->dev
,
2610 "The device reservation was lost\n");
2614 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_single(
2615 struct dasd_device
*startdev
,
2616 struct dasd_block
*block
,
2617 struct request
*req
,
2622 unsigned int first_offs
,
2623 unsigned int last_offs
,
2624 unsigned int blk_per_trk
,
2625 unsigned int blksize
)
2627 struct dasd_eckd_private
*private;
2628 unsigned long *idaws
;
2629 struct LO_eckd_data
*LO_data
;
2630 struct dasd_ccw_req
*cqr
;
2632 struct req_iterator iter
;
2636 int count
, cidaw
, cplength
, datasize
;
2638 unsigned char cmd
, rcmd
;
2640 struct dasd_device
*basedev
;
2642 basedev
= block
->base
;
2643 private = basedev
->private;
2644 if (rq_data_dir(req
) == READ
)
2645 cmd
= DASD_ECKD_CCW_READ_MT
;
2646 else if (rq_data_dir(req
) == WRITE
)
2647 cmd
= DASD_ECKD_CCW_WRITE_MT
;
2649 return ERR_PTR(-EINVAL
);
2651 /* Check struct bio and count the number of blocks for the request. */
2654 rq_for_each_segment(bv
, req
, iter
) {
2655 if (bv
.bv_len
& (blksize
- 1))
2656 /* Eckd can only do full blocks. */
2657 return ERR_PTR(-EINVAL
);
2658 count
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2659 if (idal_is_needed (page_address(bv
.bv_page
), bv
.bv_len
))
2660 cidaw
+= bv
.bv_len
>> (block
->s2b_shift
+ 9);
2663 if (count
!= last_rec
- first_rec
+ 1)
2664 return ERR_PTR(-EINVAL
);
2666 /* use the prefix command if available */
2667 use_prefix
= private->features
.feature
[8] & 0x01;
2669 /* 1x prefix + number of blocks */
2670 cplength
= 2 + count
;
2671 /* 1x prefix + cidaws*sizeof(long) */
2672 datasize
= sizeof(struct PFX_eckd_data
) +
2673 sizeof(struct LO_eckd_data
) +
2674 cidaw
* sizeof(unsigned long);
2676 /* 1x define extent + 1x locate record + number of blocks */
2677 cplength
= 2 + count
;
2678 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2679 datasize
= sizeof(struct DE_eckd_data
) +
2680 sizeof(struct LO_eckd_data
) +
2681 cidaw
* sizeof(unsigned long);
2683 /* Find out the number of additional locate record ccws for cdl. */
2684 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
2685 if (last_rec
>= 2*blk_per_trk
)
2686 count
= 2*blk_per_trk
- first_rec
;
2688 datasize
+= count
*sizeof(struct LO_eckd_data
);
2690 /* Allocate the ccw request. */
2691 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2696 /* First ccw is define extent or prefix. */
2698 if (prefix(ccw
++, cqr
->data
, first_trk
,
2699 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
2700 /* Clock not in sync and XRC is enabled.
2703 dasd_sfree_request(cqr
, startdev
);
2704 return ERR_PTR(-EAGAIN
);
2706 idaws
= (unsigned long *) (cqr
->data
+
2707 sizeof(struct PFX_eckd_data
));
2709 if (define_extent(ccw
++, cqr
->data
, first_trk
,
2710 last_trk
, cmd
, basedev
) == -EAGAIN
) {
2711 /* Clock not in sync and XRC is enabled.
2714 dasd_sfree_request(cqr
, startdev
);
2715 return ERR_PTR(-EAGAIN
);
2717 idaws
= (unsigned long *) (cqr
->data
+
2718 sizeof(struct DE_eckd_data
));
2720 /* Build locate_record+read/write/ccws. */
2721 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
2723 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
2724 /* Only standard blocks so there is just one locate record. */
2725 ccw
[-1].flags
|= CCW_FLAG_CC
;
2726 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
2727 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
2729 rq_for_each_segment(bv
, req
, iter
) {
2730 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2731 if (dasd_page_cache
) {
2732 char *copy
= kmem_cache_alloc(dasd_page_cache
,
2733 GFP_DMA
| __GFP_NOWARN
);
2734 if (copy
&& rq_data_dir(req
) == WRITE
)
2735 memcpy(copy
+ bv
.bv_offset
, dst
, bv
.bv_len
);
2737 dst
= copy
+ bv
.bv_offset
;
2739 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
2740 sector_t trkid
= recid
;
2741 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
2744 /* Locate record for cdl special block ? */
2745 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
2746 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
2748 count
= dasd_eckd_cdl_reclen(recid
);
2749 if (count
< blksize
&&
2750 rq_data_dir(req
) == READ
)
2751 memset(dst
+ count
, 0xe5,
2754 ccw
[-1].flags
|= CCW_FLAG_CC
;
2755 locate_record(ccw
++, LO_data
++,
2757 1, rcmd
, basedev
, count
);
2759 /* Locate record for standard blocks ? */
2760 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
2761 ccw
[-1].flags
|= CCW_FLAG_CC
;
2762 locate_record(ccw
++, LO_data
++,
2764 last_rec
- recid
+ 1,
2765 cmd
, basedev
, count
);
2767 /* Read/write ccw. */
2768 ccw
[-1].flags
|= CCW_FLAG_CC
;
2769 ccw
->cmd_code
= rcmd
;
2771 if (idal_is_needed(dst
, blksize
)) {
2772 ccw
->cda
= (__u32
)(addr_t
) idaws
;
2773 ccw
->flags
= CCW_FLAG_IDA
;
2774 idaws
= idal_create_words(idaws
, dst
, blksize
);
2776 ccw
->cda
= (__u32
)(addr_t
) dst
;
2784 if (blk_noretry_request(req
) ||
2785 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2786 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2787 cqr
->startdev
= startdev
;
2788 cqr
->memdev
= startdev
;
2790 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2791 cqr
->lpm
= startdev
->path_data
.ppm
;
2792 cqr
->retries
= startdev
->default_retries
;
2793 cqr
->buildclk
= get_tod_clock();
2794 cqr
->status
= DASD_CQR_FILLED
;
2798 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_track(
2799 struct dasd_device
*startdev
,
2800 struct dasd_block
*block
,
2801 struct request
*req
,
2806 unsigned int first_offs
,
2807 unsigned int last_offs
,
2808 unsigned int blk_per_trk
,
2809 unsigned int blksize
)
2811 unsigned long *idaws
;
2812 struct dasd_ccw_req
*cqr
;
2814 struct req_iterator iter
;
2816 char *dst
, *idaw_dst
;
2817 unsigned int cidaw
, cplength
, datasize
;
2821 struct dasd_device
*basedev
;
2822 unsigned int trkcount
, count
, count_to_trk_end
;
2823 unsigned int idaw_len
, seg_len
, part_len
, len_to_track_end
;
2824 unsigned char new_track
, end_idaw
;
2826 unsigned int recoffs
;
2828 basedev
= block
->base
;
2829 if (rq_data_dir(req
) == READ
)
2830 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
2831 else if (rq_data_dir(req
) == WRITE
)
2832 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
2834 return ERR_PTR(-EINVAL
);
2836 /* Track based I/O needs IDAWs for each page, and not just for
2837 * 64 bit addresses. We need additional idals for pages
2838 * that get filled from two tracks, so we use the number
2839 * of records as upper limit.
2841 cidaw
= last_rec
- first_rec
+ 1;
2842 trkcount
= last_trk
- first_trk
+ 1;
2844 /* 1x prefix + one read/write ccw per track */
2845 cplength
= 1 + trkcount
;
2847 /* on 31-bit we need space for two 32 bit addresses per page
2848 * on 64-bit one 64 bit address
2850 datasize
= sizeof(struct PFX_eckd_data
) +
2851 cidaw
* sizeof(unsigned long long);
2853 /* Allocate the ccw request. */
2854 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2859 /* transfer length factor: how many bytes to read from the last track */
2860 if (first_trk
== last_trk
)
2861 tlf
= last_offs
- first_offs
+ 1;
2863 tlf
= last_offs
+ 1;
2866 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
,
2867 last_trk
, cmd
, basedev
, startdev
,
2868 1 /* format */, first_offs
+ 1,
2871 /* Clock not in sync and XRC is enabled.
2874 dasd_sfree_request(cqr
, startdev
);
2875 return ERR_PTR(-EAGAIN
);
2879 * The translation of request into ccw programs must meet the
2880 * following conditions:
2881 * - all idaws but the first and the last must address full pages
2882 * (or 2K blocks on 31-bit)
2883 * - the scope of a ccw and it's idal ends with the track boundaries
2885 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct PFX_eckd_data
));
2889 len_to_track_end
= 0;
2892 rq_for_each_segment(bv
, req
, iter
) {
2893 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
2894 seg_len
= bv
.bv_len
;
2898 recoffs
= sector_div(trkid
, blk_per_trk
);
2899 count_to_trk_end
= blk_per_trk
- recoffs
;
2900 count
= min((last_rec
- recid
+ 1),
2901 (sector_t
)count_to_trk_end
);
2902 len_to_track_end
= count
* blksize
;
2903 ccw
[-1].flags
|= CCW_FLAG_CC
;
2904 ccw
->cmd_code
= cmd
;
2905 ccw
->count
= len_to_track_end
;
2906 ccw
->cda
= (__u32
)(addr_t
)idaws
;
2907 ccw
->flags
= CCW_FLAG_IDA
;
2911 /* first idaw for a ccw may start anywhere */
2915 /* If we start a new idaw, we must make sure that it
2916 * starts on an IDA_BLOCK_SIZE boundary.
2917 * If we continue an idaw, we must make sure that the
2918 * current segment begins where the so far accumulated
2922 if (__pa(dst
) & (IDA_BLOCK_SIZE
-1)) {
2923 dasd_sfree_request(cqr
, startdev
);
2924 return ERR_PTR(-ERANGE
);
2928 if ((idaw_dst
+ idaw_len
) != dst
) {
2929 dasd_sfree_request(cqr
, startdev
);
2930 return ERR_PTR(-ERANGE
);
2932 part_len
= min(seg_len
, len_to_track_end
);
2933 seg_len
-= part_len
;
2935 idaw_len
+= part_len
;
2936 len_to_track_end
-= part_len
;
2937 /* collected memory area ends on an IDA_BLOCK border,
2939 * idal_create_words will handle cases where idaw_len
2940 * is larger then IDA_BLOCK_SIZE
2942 if (!(__pa(idaw_dst
+ idaw_len
) & (IDA_BLOCK_SIZE
-1)))
2944 /* We also need to end the idaw at track end */
2945 if (!len_to_track_end
) {
2950 idaws
= idal_create_words(idaws
, idaw_dst
,
2959 if (blk_noretry_request(req
) ||
2960 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2961 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2962 cqr
->startdev
= startdev
;
2963 cqr
->memdev
= startdev
;
2965 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2966 cqr
->lpm
= startdev
->path_data
.ppm
;
2967 cqr
->retries
= startdev
->default_retries
;
2968 cqr
->buildclk
= get_tod_clock();
2969 cqr
->status
= DASD_CQR_FILLED
;
2973 static int prepare_itcw(struct itcw
*itcw
,
2974 unsigned int trk
, unsigned int totrk
, int cmd
,
2975 struct dasd_device
*basedev
,
2976 struct dasd_device
*startdev
,
2977 unsigned int rec_on_trk
, int count
,
2978 unsigned int blksize
,
2979 unsigned int total_data_size
,
2981 unsigned int blk_per_trk
)
2983 struct PFX_eckd_data pfxdata
;
2984 struct dasd_eckd_private
*basepriv
, *startpriv
;
2985 struct DE_eckd_data
*dedata
;
2986 struct LRE_eckd_data
*lredata
;
2990 u16 heads
, beghead
, endhead
;
2998 /* setup prefix data */
2999 basepriv
= basedev
->private;
3000 startpriv
= startdev
->private;
3001 dedata
= &pfxdata
.define_extent
;
3002 lredata
= &pfxdata
.locate_record
;
3004 memset(&pfxdata
, 0, sizeof(pfxdata
));
3005 pfxdata
.format
= 1; /* PFX with LRE */
3006 pfxdata
.base_address
= basepriv
->ned
->unit_addr
;
3007 pfxdata
.base_lss
= basepriv
->ned
->ID
;
3008 pfxdata
.validity
.define_extent
= 1;
3010 /* private uid is kept up to date, conf_data may be outdated */
3011 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
3012 pfxdata
.validity
.verify_base
= 1;
3013 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
3014 pfxdata
.validity
.hyper_pav
= 1;
3018 case DASD_ECKD_CCW_READ_TRACK_DATA
:
3019 dedata
->mask
.perm
= 0x1;
3020 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3021 dedata
->blk_size
= blksize
;
3022 dedata
->ga_extended
|= 0x42;
3023 lredata
->operation
.orientation
= 0x0;
3024 lredata
->operation
.operation
= 0x0C;
3025 lredata
->auxiliary
.check_bytes
= 0x01;
3026 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
3028 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
3029 dedata
->mask
.perm
= 0x02;
3030 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
3031 dedata
->blk_size
= blksize
;
3032 rc
= check_XRC_on_prefix(&pfxdata
, basedev
);
3033 dedata
->ga_extended
|= 0x42;
3034 lredata
->operation
.orientation
= 0x0;
3035 lredata
->operation
.operation
= 0x3F;
3036 lredata
->extended_operation
= 0x23;
3037 lredata
->auxiliary
.check_bytes
= 0x2;
3038 pfx_cmd
= DASD_ECKD_CCW_PFX
;
3041 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3042 "prepare itcw, unknown opcode 0x%x", cmd
);
3049 dedata
->attributes
.mode
= 0x3; /* ECKD */
3051 heads
= basepriv
->rdc_data
.trk_per_cyl
;
3052 begcyl
= trk
/ heads
;
3053 beghead
= trk
% heads
;
3054 endcyl
= totrk
/ heads
;
3055 endhead
= totrk
% heads
;
3057 /* check for sequential prestage - enhance cylinder range */
3058 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
3059 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
3061 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
3062 endcyl
+= basepriv
->attrib
.nr_cyl
;
3064 endcyl
= (basepriv
->real_cyl
- 1);
3067 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
3068 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
3070 dedata
->ep_format
= 0x20; /* records per track is valid */
3071 dedata
->ep_rec_per_track
= blk_per_trk
;
3074 switch (basepriv
->rdc_data
.dev_type
) {
3076 dn
= ceil_quot(blksize
+ 6, 232);
3077 d
= 9 + ceil_quot(blksize
+ 6 * (dn
+ 1), 34);
3078 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
3081 d
= 7 + ceil_quot(blksize
+ 12, 32);
3082 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
3087 lredata
->auxiliary
.length_valid
= 1;
3088 lredata
->auxiliary
.length_scope
= 1;
3089 lredata
->auxiliary
.imbedded_ccw_valid
= 1;
3090 lredata
->length
= tlf
;
3091 lredata
->imbedded_ccw
= cmd
;
3092 lredata
->count
= count
;
3093 lredata
->sector
= sector
;
3094 set_ch_t(&lredata
->seek_addr
, begcyl
, beghead
);
3095 lredata
->search_arg
.cyl
= lredata
->seek_addr
.cyl
;
3096 lredata
->search_arg
.head
= lredata
->seek_addr
.head
;
3097 lredata
->search_arg
.record
= rec_on_trk
;
3099 dcw
= itcw_add_dcw(itcw
, pfx_cmd
, 0,
3100 &pfxdata
, sizeof(pfxdata
), total_data_size
);
3101 return PTR_RET(dcw
);
3104 static struct dasd_ccw_req
*dasd_eckd_build_cp_tpm_track(
3105 struct dasd_device
*startdev
,
3106 struct dasd_block
*block
,
3107 struct request
*req
,
3112 unsigned int first_offs
,
3113 unsigned int last_offs
,
3114 unsigned int blk_per_trk
,
3115 unsigned int blksize
)
3117 struct dasd_ccw_req
*cqr
;
3118 struct req_iterator iter
;
3121 unsigned int trkcount
, ctidaw
;
3123 struct dasd_device
*basedev
;
3126 struct tidaw
*last_tidaw
= NULL
;
3130 unsigned int seg_len
, part_len
, len_to_track_end
;
3131 unsigned char new_track
;
3132 sector_t recid
, trkid
;
3134 unsigned int count
, count_to_trk_end
;
3137 basedev
= block
->base
;
3138 if (rq_data_dir(req
) == READ
) {
3139 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
3140 itcw_op
= ITCW_OP_READ
;
3141 } else if (rq_data_dir(req
) == WRITE
) {
3142 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
3143 itcw_op
= ITCW_OP_WRITE
;
3145 return ERR_PTR(-EINVAL
);
3147 /* trackbased I/O needs address all memory via TIDAWs,
3148 * not just for 64 bit addresses. This allows us to map
3149 * each segment directly to one tidaw.
3150 * In the case of write requests, additional tidaws may
3151 * be needed when a segment crosses a track boundary.
3153 trkcount
= last_trk
- first_trk
+ 1;
3155 rq_for_each_segment(bv
, req
, iter
) {
3158 if (rq_data_dir(req
) == WRITE
)
3159 ctidaw
+= (last_trk
- first_trk
);
3161 /* Allocate the ccw request. */
3162 itcw_size
= itcw_calc_size(0, ctidaw
, 0);
3163 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
3167 /* transfer length factor: how many bytes to read from the last track */
3168 if (first_trk
== last_trk
)
3169 tlf
= last_offs
- first_offs
+ 1;
3171 tlf
= last_offs
+ 1;
3174 itcw
= itcw_init(cqr
->data
, itcw_size
, itcw_op
, 0, ctidaw
, 0);
3179 cqr
->cpaddr
= itcw_get_tcw(itcw
);
3180 if (prepare_itcw(itcw
, first_trk
, last_trk
,
3181 cmd
, basedev
, startdev
,
3184 (last_rec
- first_rec
+ 1) * blksize
,
3185 tlf
, blk_per_trk
) == -EAGAIN
) {
3186 /* Clock not in sync and XRC is enabled.
3192 len_to_track_end
= 0;
3194 * A tidaw can address 4k of memory, but must not cross page boundaries
3195 * We can let the block layer handle this by setting
3196 * blk_queue_segment_boundary to page boundaries and
3197 * blk_max_segment_size to page size when setting up the request queue.
3198 * For write requests, a TIDAW must not cross track boundaries, because
3199 * we have to set the CBC flag on the last tidaw for each track.
3201 if (rq_data_dir(req
) == WRITE
) {
3204 rq_for_each_segment(bv
, req
, iter
) {
3205 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3206 seg_len
= bv
.bv_len
;
3210 offs
= sector_div(trkid
, blk_per_trk
);
3211 count_to_trk_end
= blk_per_trk
- offs
;
3212 count
= min((last_rec
- recid
+ 1),
3213 (sector_t
)count_to_trk_end
);
3214 len_to_track_end
= count
* blksize
;
3218 part_len
= min(seg_len
, len_to_track_end
);
3219 seg_len
-= part_len
;
3220 len_to_track_end
-= part_len
;
3221 /* We need to end the tidaw at track end */
3222 if (!len_to_track_end
) {
3224 tidaw_flags
= TIDAW_FLAGS_INSERT_CBC
;
3227 last_tidaw
= itcw_add_tidaw(itcw
, tidaw_flags
,
3229 if (IS_ERR(last_tidaw
)) {
3237 rq_for_each_segment(bv
, req
, iter
) {
3238 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3239 last_tidaw
= itcw_add_tidaw(itcw
, 0x00,
3241 if (IS_ERR(last_tidaw
)) {
3247 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
3248 last_tidaw
->flags
&= ~TIDAW_FLAGS_INSERT_CBC
;
3249 itcw_finalize(itcw
);
3251 if (blk_noretry_request(req
) ||
3252 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3253 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3255 cqr
->startdev
= startdev
;
3256 cqr
->memdev
= startdev
;
3258 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
3259 cqr
->lpm
= startdev
->path_data
.ppm
;
3260 cqr
->retries
= startdev
->default_retries
;
3261 cqr
->buildclk
= get_tod_clock();
3262 cqr
->status
= DASD_CQR_FILLED
;
3265 dasd_sfree_request(cqr
, startdev
);
3266 return ERR_PTR(ret
);
3269 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
3270 struct dasd_block
*block
,
3271 struct request
*req
)
3276 struct dasd_eckd_private
*private;
3277 struct dasd_device
*basedev
;
3278 sector_t first_rec
, last_rec
;
3279 sector_t first_trk
, last_trk
;
3280 unsigned int first_offs
, last_offs
;
3281 unsigned int blk_per_trk
, blksize
;
3283 unsigned int data_size
;
3284 struct dasd_ccw_req
*cqr
;
3286 basedev
= block
->base
;
3287 private = basedev
->private;
3289 /* Calculate number of blocks/records per track. */
3290 blksize
= block
->bp_block
;
3291 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3292 if (blk_per_trk
== 0)
3293 return ERR_PTR(-EINVAL
);
3294 /* Calculate record id of first and last block. */
3295 first_rec
= first_trk
= blk_rq_pos(req
) >> block
->s2b_shift
;
3296 first_offs
= sector_div(first_trk
, blk_per_trk
);
3297 last_rec
= last_trk
=
3298 (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) >> block
->s2b_shift
;
3299 last_offs
= sector_div(last_trk
, blk_per_trk
);
3300 cdlspecial
= (private->uses_cdl
&& first_rec
< 2*blk_per_trk
);
3302 fcx_multitrack
= private->features
.feature
[40] & 0x20;
3303 data_size
= blk_rq_bytes(req
);
3304 if (data_size
% blksize
)
3305 return ERR_PTR(-EINVAL
);
3306 /* tpm write request add CBC data on each track boundary */
3307 if (rq_data_dir(req
) == WRITE
)
3308 data_size
+= (last_trk
- first_trk
) * 4;
3310 /* is read track data and write track data in command mode supported? */
3311 cmdrtd
= private->features
.feature
[9] & 0x20;
3312 cmdwtd
= private->features
.feature
[12] & 0x40;
3313 use_prefix
= private->features
.feature
[8] & 0x01;
3316 if (cdlspecial
|| dasd_page_cache
) {
3317 /* do nothing, just fall through to the cmd mode single case */
3318 } else if ((data_size
<= private->fcx_max_data
)
3319 && (fcx_multitrack
|| (first_trk
== last_trk
))) {
3320 cqr
= dasd_eckd_build_cp_tpm_track(startdev
, block
, req
,
3321 first_rec
, last_rec
,
3322 first_trk
, last_trk
,
3323 first_offs
, last_offs
,
3324 blk_per_trk
, blksize
);
3325 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3326 (PTR_ERR(cqr
) != -ENOMEM
))
3328 } else if (use_prefix
&&
3329 (((rq_data_dir(req
) == READ
) && cmdrtd
) ||
3330 ((rq_data_dir(req
) == WRITE
) && cmdwtd
))) {
3331 cqr
= dasd_eckd_build_cp_cmd_track(startdev
, block
, req
,
3332 first_rec
, last_rec
,
3333 first_trk
, last_trk
,
3334 first_offs
, last_offs
,
3335 blk_per_trk
, blksize
);
3336 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3337 (PTR_ERR(cqr
) != -ENOMEM
))
3341 cqr
= dasd_eckd_build_cp_cmd_single(startdev
, block
, req
,
3342 first_rec
, last_rec
,
3343 first_trk
, last_trk
,
3344 first_offs
, last_offs
,
3345 blk_per_trk
, blksize
);
3349 static struct dasd_ccw_req
*dasd_raw_build_cp(struct dasd_device
*startdev
,
3350 struct dasd_block
*block
,
3351 struct request
*req
)
3353 unsigned long *idaws
;
3354 struct dasd_device
*basedev
;
3355 struct dasd_ccw_req
*cqr
;
3357 struct req_iterator iter
;
3361 unsigned int trkcount
;
3362 unsigned int seg_len
, len_to_track_end
;
3363 unsigned int first_offs
;
3364 unsigned int cidaw
, cplength
, datasize
;
3365 sector_t first_trk
, last_trk
, sectors
;
3366 sector_t start_padding_sectors
, end_sector_offset
, end_padding_sectors
;
3367 unsigned int pfx_datasize
;
3370 * raw track access needs to be mutiple of 64k and on 64k boundary
3371 * For read requests we can fix an incorrect alignment by padding
3372 * the request with dummy pages.
3374 start_padding_sectors
= blk_rq_pos(req
) % DASD_RAW_SECTORS_PER_TRACK
;
3375 end_sector_offset
= (blk_rq_pos(req
) + blk_rq_sectors(req
)) %
3376 DASD_RAW_SECTORS_PER_TRACK
;
3377 end_padding_sectors
= (DASD_RAW_SECTORS_PER_TRACK
- end_sector_offset
) %
3378 DASD_RAW_SECTORS_PER_TRACK
;
3379 basedev
= block
->base
;
3380 if ((start_padding_sectors
|| end_padding_sectors
) &&
3381 (rq_data_dir(req
) == WRITE
)) {
3382 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3383 "raw write not track aligned (%lu,%lu) req %p",
3384 start_padding_sectors
, end_padding_sectors
, req
);
3385 cqr
= ERR_PTR(-EINVAL
);
3389 first_trk
= blk_rq_pos(req
) / DASD_RAW_SECTORS_PER_TRACK
;
3390 last_trk
= (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) /
3391 DASD_RAW_SECTORS_PER_TRACK
;
3392 trkcount
= last_trk
- first_trk
+ 1;
3395 if (rq_data_dir(req
) == READ
)
3396 cmd
= DASD_ECKD_CCW_READ_TRACK
;
3397 else if (rq_data_dir(req
) == WRITE
)
3398 cmd
= DASD_ECKD_CCW_WRITE_FULL_TRACK
;
3400 cqr
= ERR_PTR(-EINVAL
);
3405 * Raw track based I/O needs IDAWs for each page,
3406 * and not just for 64 bit addresses.
3408 cidaw
= trkcount
* DASD_RAW_BLOCK_PER_TRACK
;
3410 /* 1x prefix + one read/write ccw per track */
3411 cplength
= 1 + trkcount
;
3414 * struct PFX_eckd_data has up to 2 byte as extended parameter
3415 * this is needed for write full track and has to be mentioned
3417 * add 8 instead of 2 to keep 8 byte boundary
3419 pfx_datasize
= sizeof(struct PFX_eckd_data
) + 8;
3421 datasize
= pfx_datasize
+ cidaw
* sizeof(unsigned long long);
3423 /* Allocate the ccw request. */
3424 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
3425 datasize
, startdev
);
3430 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
,
3431 basedev
, startdev
, 1 /* format */, first_offs
+ 1,
3432 trkcount
, 0, 0) == -EAGAIN
) {
3433 /* Clock not in sync and XRC is enabled.
3436 dasd_sfree_request(cqr
, startdev
);
3437 cqr
= ERR_PTR(-EAGAIN
);
3441 idaws
= (unsigned long *)(cqr
->data
+ pfx_datasize
);
3442 len_to_track_end
= 0;
3443 if (start_padding_sectors
) {
3444 ccw
[-1].flags
|= CCW_FLAG_CC
;
3445 ccw
->cmd_code
= cmd
;
3446 /* maximum 3390 track size */
3448 /* 64k map to one track */
3449 len_to_track_end
= 65536 - start_padding_sectors
* 512;
3450 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3451 ccw
->flags
|= CCW_FLAG_IDA
;
3452 ccw
->flags
|= CCW_FLAG_SLI
;
3454 for (sectors
= 0; sectors
< start_padding_sectors
; sectors
+= 8)
3455 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3457 rq_for_each_segment(bv
, req
, iter
) {
3458 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3459 seg_len
= bv
.bv_len
;
3460 if (cmd
== DASD_ECKD_CCW_READ_TRACK
)
3461 memset(dst
, 0, seg_len
);
3462 if (!len_to_track_end
) {
3463 ccw
[-1].flags
|= CCW_FLAG_CC
;
3464 ccw
->cmd_code
= cmd
;
3465 /* maximum 3390 track size */
3467 /* 64k map to one track */
3468 len_to_track_end
= 65536;
3469 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3470 ccw
->flags
|= CCW_FLAG_IDA
;
3471 ccw
->flags
|= CCW_FLAG_SLI
;
3474 len_to_track_end
-= seg_len
;
3475 idaws
= idal_create_words(idaws
, dst
, seg_len
);
3477 for (sectors
= 0; sectors
< end_padding_sectors
; sectors
+= 8)
3478 idaws
= idal_create_words(idaws
, rawpadpage
, PAGE_SIZE
);
3479 if (blk_noretry_request(req
) ||
3480 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3481 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3482 cqr
->startdev
= startdev
;
3483 cqr
->memdev
= startdev
;
3485 cqr
->expires
= startdev
->default_expires
* HZ
;
3486 cqr
->lpm
= startdev
->path_data
.ppm
;
3487 cqr
->retries
= startdev
->default_retries
;
3488 cqr
->buildclk
= get_tod_clock();
3489 cqr
->status
= DASD_CQR_FILLED
;
3491 if (IS_ERR(cqr
) && PTR_ERR(cqr
) != -EAGAIN
)
3499 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
3501 struct dasd_eckd_private
*private;
3503 struct req_iterator iter
;
3506 unsigned int blksize
, blk_per_trk
, off
;
3510 if (!dasd_page_cache
)
3512 private = cqr
->block
->base
->private;
3513 blksize
= cqr
->block
->bp_block
;
3514 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3515 recid
= blk_rq_pos(req
) >> cqr
->block
->s2b_shift
;
3517 /* Skip over define extent & locate record. */
3519 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
3521 rq_for_each_segment(bv
, req
, iter
) {
3522 dst
= page_address(bv
.bv_page
) + bv
.bv_offset
;
3523 for (off
= 0; off
< bv
.bv_len
; off
+= blksize
) {
3524 /* Skip locate record. */
3525 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
3528 if (ccw
->flags
& CCW_FLAG_IDA
)
3529 cda
= *((char **)((addr_t
) ccw
->cda
));
3531 cda
= (char *)((addr_t
) ccw
->cda
);
3533 if (rq_data_dir(req
) == READ
)
3534 memcpy(dst
, cda
, bv
.bv_len
);
3535 kmem_cache_free(dasd_page_cache
,
3536 (void *)((addr_t
)cda
& PAGE_MASK
));
3545 status
= cqr
->status
== DASD_CQR_DONE
;
3546 dasd_sfree_request(cqr
, cqr
->memdev
);
3551 * Modify ccw/tcw in cqr so it can be started on a base device.
3553 * Note that this is not enough to restart the cqr!
3554 * Either reset cqr->startdev as well (summary unit check handling)
3555 * or restart via separate cqr (as in ERP handling).
3557 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
3560 struct PFX_eckd_data
*pfxdata
;
3565 if (cqr
->cpmode
== 1) {
3567 tccb
= tcw_get_tccb(tcw
);
3568 dcw
= (struct dcw
*)&tccb
->tca
[0];
3569 pfxdata
= (struct PFX_eckd_data
*)&dcw
->cd
[0];
3570 pfxdata
->validity
.verify_base
= 0;
3571 pfxdata
->validity
.hyper_pav
= 0;
3574 pfxdata
= cqr
->data
;
3575 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
3576 pfxdata
->validity
.verify_base
= 0;
3577 pfxdata
->validity
.hyper_pav
= 0;
3582 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3584 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
3585 struct dasd_block
*block
,
3586 struct request
*req
)
3588 struct dasd_eckd_private
*private;
3589 struct dasd_device
*startdev
;
3590 unsigned long flags
;
3591 struct dasd_ccw_req
*cqr
;
3593 startdev
= dasd_alias_get_start_dev(base
);
3596 private = startdev
->private;
3597 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
3598 return ERR_PTR(-EBUSY
);
3600 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
3602 if ((base
->features
& DASD_FEATURE_USERAW
))
3603 cqr
= dasd_raw_build_cp(startdev
, block
, req
);
3605 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
3608 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
3612 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
3613 struct request
*req
)
3615 struct dasd_eckd_private
*private;
3616 unsigned long flags
;
3618 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3619 private = cqr
->memdev
->private;
3621 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3622 return dasd_eckd_free_cp(cqr
, req
);
3626 dasd_eckd_fill_info(struct dasd_device
* device
,
3627 struct dasd_information2_t
* info
)
3629 struct dasd_eckd_private
*private = device
->private;
3631 info
->label_block
= 2;
3632 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
3633 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
3634 info
->characteristics_size
= sizeof(private->rdc_data
);
3635 memcpy(info
->characteristics
, &private->rdc_data
,
3636 sizeof(private->rdc_data
));
3637 info
->confdata_size
= min((unsigned long)private->conf_len
,
3638 sizeof(info
->configuration_data
));
3639 memcpy(info
->configuration_data
, private->conf_data
,
3640 info
->confdata_size
);
3645 * SECTION: ioctl functions for eckd devices.
3649 * Release device ioctl.
3650 * Buils a channel programm to releases a prior reserved
3651 * (see dasd_eckd_reserve) device.
3654 dasd_eckd_release(struct dasd_device
*device
)
3656 struct dasd_ccw_req
*cqr
;
3661 if (!capable(CAP_SYS_ADMIN
))
3665 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3667 mutex_lock(&dasd_reserve_mutex
);
3669 cqr
= &dasd_reserve_req
->cqr
;
3670 memset(cqr
, 0, sizeof(*cqr
));
3671 memset(&dasd_reserve_req
->ccw
, 0,
3672 sizeof(dasd_reserve_req
->ccw
));
3673 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3674 cqr
->data
= &dasd_reserve_req
->data
;
3675 cqr
->magic
= DASD_ECKD_MAGIC
;
3678 ccw
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
3679 ccw
->flags
|= CCW_FLAG_SLI
;
3681 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3682 cqr
->startdev
= device
;
3683 cqr
->memdev
= device
;
3684 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3685 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3686 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3687 cqr
->expires
= 2 * HZ
;
3688 cqr
->buildclk
= get_tod_clock();
3689 cqr
->status
= DASD_CQR_FILLED
;
3691 rc
= dasd_sleep_on_immediatly(cqr
);
3693 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3696 mutex_unlock(&dasd_reserve_mutex
);
3698 dasd_sfree_request(cqr
, cqr
->memdev
);
3703 * Reserve device ioctl.
3704 * Options are set to 'synchronous wait for interrupt' and
3705 * 'timeout the request'. This leads to a terminate IO if
3706 * the interrupt is outstanding for a certain time.
3709 dasd_eckd_reserve(struct dasd_device
*device
)
3711 struct dasd_ccw_req
*cqr
;
3716 if (!capable(CAP_SYS_ADMIN
))
3720 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3722 mutex_lock(&dasd_reserve_mutex
);
3724 cqr
= &dasd_reserve_req
->cqr
;
3725 memset(cqr
, 0, sizeof(*cqr
));
3726 memset(&dasd_reserve_req
->ccw
, 0,
3727 sizeof(dasd_reserve_req
->ccw
));
3728 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3729 cqr
->data
= &dasd_reserve_req
->data
;
3730 cqr
->magic
= DASD_ECKD_MAGIC
;
3733 ccw
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
3734 ccw
->flags
|= CCW_FLAG_SLI
;
3736 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3737 cqr
->startdev
= device
;
3738 cqr
->memdev
= device
;
3739 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3740 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3741 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3742 cqr
->expires
= 2 * HZ
;
3743 cqr
->buildclk
= get_tod_clock();
3744 cqr
->status
= DASD_CQR_FILLED
;
3746 rc
= dasd_sleep_on_immediatly(cqr
);
3748 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3751 mutex_unlock(&dasd_reserve_mutex
);
3753 dasd_sfree_request(cqr
, cqr
->memdev
);
3758 * Steal lock ioctl - unconditional reserve device.
3759 * Buils a channel programm to break a device's reservation.
3760 * (unconditional reserve)
3763 dasd_eckd_steal_lock(struct dasd_device
*device
)
3765 struct dasd_ccw_req
*cqr
;
3770 if (!capable(CAP_SYS_ADMIN
))
3774 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3776 mutex_lock(&dasd_reserve_mutex
);
3778 cqr
= &dasd_reserve_req
->cqr
;
3779 memset(cqr
, 0, sizeof(*cqr
));
3780 memset(&dasd_reserve_req
->ccw
, 0,
3781 sizeof(dasd_reserve_req
->ccw
));
3782 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3783 cqr
->data
= &dasd_reserve_req
->data
;
3784 cqr
->magic
= DASD_ECKD_MAGIC
;
3787 ccw
->cmd_code
= DASD_ECKD_CCW_SLCK
;
3788 ccw
->flags
|= CCW_FLAG_SLI
;
3790 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3791 cqr
->startdev
= device
;
3792 cqr
->memdev
= device
;
3793 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3794 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3795 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3796 cqr
->expires
= 2 * HZ
;
3797 cqr
->buildclk
= get_tod_clock();
3798 cqr
->status
= DASD_CQR_FILLED
;
3800 rc
= dasd_sleep_on_immediatly(cqr
);
3802 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3805 mutex_unlock(&dasd_reserve_mutex
);
3807 dasd_sfree_request(cqr
, cqr
->memdev
);
3812 * SNID - Sense Path Group ID
3813 * This ioctl may be used in situations where I/O is stalled due to
3814 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3815 * preallocated dasd_reserve_req.
3817 static int dasd_eckd_snid(struct dasd_device
*device
,
3820 struct dasd_ccw_req
*cqr
;
3824 struct dasd_snid_ioctl_data usrparm
;
3826 if (!capable(CAP_SYS_ADMIN
))
3829 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3833 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1,
3834 sizeof(struct dasd_snid_data
), device
);
3836 mutex_lock(&dasd_reserve_mutex
);
3838 cqr
= &dasd_reserve_req
->cqr
;
3839 memset(cqr
, 0, sizeof(*cqr
));
3840 memset(&dasd_reserve_req
->ccw
, 0,
3841 sizeof(dasd_reserve_req
->ccw
));
3842 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3843 cqr
->data
= &dasd_reserve_req
->data
;
3844 cqr
->magic
= DASD_ECKD_MAGIC
;
3847 ccw
->cmd_code
= DASD_ECKD_CCW_SNID
;
3848 ccw
->flags
|= CCW_FLAG_SLI
;
3850 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3851 cqr
->startdev
= device
;
3852 cqr
->memdev
= device
;
3853 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3854 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3855 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
3857 cqr
->expires
= 10 * HZ
;
3858 cqr
->buildclk
= get_tod_clock();
3859 cqr
->status
= DASD_CQR_FILLED
;
3860 cqr
->lpm
= usrparm
.path_mask
;
3862 rc
= dasd_sleep_on_immediatly(cqr
);
3863 /* verify that I/O processing didn't modify the path mask */
3864 if (!rc
&& usrparm
.path_mask
&& (cqr
->lpm
!= usrparm
.path_mask
))
3867 usrparm
.data
= *((struct dasd_snid_data
*)cqr
->data
);
3868 if (copy_to_user(argp
, &usrparm
, sizeof(usrparm
)))
3873 mutex_unlock(&dasd_reserve_mutex
);
3875 dasd_sfree_request(cqr
, cqr
->memdev
);
3880 * Read performance statistics
3883 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
3885 struct dasd_psf_prssd_data
*prssdp
;
3886 struct dasd_rssd_perf_stats_t
*stats
;
3887 struct dasd_ccw_req
*cqr
;
3891 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
3892 (sizeof(struct dasd_psf_prssd_data
) +
3893 sizeof(struct dasd_rssd_perf_stats_t
)),
3896 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3897 "Could not allocate initialization request");
3898 return PTR_ERR(cqr
);
3900 cqr
->startdev
= device
;
3901 cqr
->memdev
= device
;
3903 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3904 cqr
->expires
= 10 * HZ
;
3906 /* Prepare for Read Subsystem Data */
3907 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3908 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
3909 prssdp
->order
= PSF_ORDER_PRSSD
;
3910 prssdp
->suborder
= 0x01; /* Performance Statistics */
3911 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
3914 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
3915 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
3916 ccw
->flags
|= CCW_FLAG_CC
;
3917 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
3919 /* Read Subsystem Data - Performance Statistics */
3920 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3921 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
3924 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
3925 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
3926 ccw
->cda
= (__u32
)(addr_t
) stats
;
3928 cqr
->buildclk
= get_tod_clock();
3929 cqr
->status
= DASD_CQR_FILLED
;
3930 rc
= dasd_sleep_on(cqr
);
3932 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3933 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3934 if (copy_to_user(argp
, stats
,
3935 sizeof(struct dasd_rssd_perf_stats_t
)))
3938 dasd_sfree_request(cqr
, cqr
->memdev
);
3943 * Get attributes (cache operations)
3944 * Returnes the cache attributes used in Define Extend (DE).
3947 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
3949 struct dasd_eckd_private
*private = device
->private;
3950 struct attrib_data_t attrib
= private->attrib
;
3953 if (!capable(CAP_SYS_ADMIN
))
3959 if (copy_to_user(argp
, (long *) &attrib
,
3960 sizeof(struct attrib_data_t
)))
3967 * Set attributes (cache operations)
3968 * Stores the attributes for cache operation to be used in Define Extend (DE).
3971 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
3973 struct dasd_eckd_private
*private = device
->private;
3974 struct attrib_data_t attrib
;
3976 if (!capable(CAP_SYS_ADMIN
))
3981 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
3983 private->attrib
= attrib
;
3985 dev_info(&device
->cdev
->dev
,
3986 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3987 private->attrib
.operation
, private->attrib
.nr_cyl
);
3992 * Issue syscall I/O to EMC Symmetrix array.
3993 * CCWs are PSF and RSSD
3995 static int dasd_symm_io(struct dasd_device
*device
, void __user
*argp
)
3997 struct dasd_symmio_parms usrparm
;
3998 char *psf_data
, *rssd_result
;
3999 struct dasd_ccw_req
*cqr
;
4004 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
4008 /* Copy parms from caller */
4010 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
4012 if (is_compat_task()) {
4013 /* Make sure pointers are sane even on 31 bit. */
4015 if ((usrparm
.psf_data
>> 32) != 0)
4017 if ((usrparm
.rssd_result
>> 32) != 0)
4019 usrparm
.psf_data
&= 0x7fffffffULL
;
4020 usrparm
.rssd_result
&= 0x7fffffffULL
;
4022 /* alloc I/O data area */
4023 psf_data
= kzalloc(usrparm
.psf_data_len
, GFP_KERNEL
| GFP_DMA
);
4024 rssd_result
= kzalloc(usrparm
.rssd_result_len
, GFP_KERNEL
| GFP_DMA
);
4025 if (!psf_data
|| !rssd_result
) {
4030 /* get syscall header from user space */
4032 if (copy_from_user(psf_data
,
4033 (void __user
*)(unsigned long) usrparm
.psf_data
,
4034 usrparm
.psf_data_len
))
4039 /* setup CCWs for PSF + RSSD */
4040 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 2 , 0, device
);
4042 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4043 "Could not allocate initialization request");
4048 cqr
->startdev
= device
;
4049 cqr
->memdev
= device
;
4051 cqr
->expires
= 10 * HZ
;
4052 cqr
->buildclk
= get_tod_clock();
4053 cqr
->status
= DASD_CQR_FILLED
;
4055 /* Build the ccws */
4059 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4060 ccw
->count
= usrparm
.psf_data_len
;
4061 ccw
->flags
|= CCW_FLAG_CC
;
4062 ccw
->cda
= (__u32
)(addr_t
) psf_data
;
4067 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4068 ccw
->count
= usrparm
.rssd_result_len
;
4069 ccw
->flags
= CCW_FLAG_SLI
;
4070 ccw
->cda
= (__u32
)(addr_t
) rssd_result
;
4072 rc
= dasd_sleep_on(cqr
);
4077 if (copy_to_user((void __user
*)(unsigned long) usrparm
.rssd_result
,
4078 rssd_result
, usrparm
.rssd_result_len
))
4083 dasd_sfree_request(cqr
, cqr
->memdev
);
4088 DBF_DEV_EVENT(DBF_WARNING
, device
,
4089 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4090 (int) psf0
, (int) psf1
, rc
);
4095 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
4097 struct dasd_device
*device
= block
->base
;
4101 return dasd_eckd_get_attrib(device
, argp
);
4103 return dasd_eckd_set_attrib(device
, argp
);
4105 return dasd_eckd_performance(device
, argp
);
4107 return dasd_eckd_release(device
);
4109 return dasd_eckd_reserve(device
);
4111 return dasd_eckd_steal_lock(device
);
4113 return dasd_eckd_snid(device
, argp
);
4115 return dasd_symm_io(device
, argp
);
4122 * Dump the range of CCWs into 'page' buffer
4123 * and return number of printed chars.
4126 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
4132 while (from
<= to
) {
4133 len
+= sprintf(page
+ len
, PRINTK_HEADER
4134 " CCW %p: %08X %08X DAT:",
4135 from
, ((int *) from
)[0], ((int *) from
)[1]);
4137 /* get pointer to data (consider IDALs) */
4138 if (from
->flags
& CCW_FLAG_IDA
)
4139 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
4141 datap
= (char *) ((addr_t
) from
->cda
);
4143 /* dump data (max 32 bytes) */
4144 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
4145 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
4146 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
4147 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
4149 len
+= sprintf(page
+ len
, "\n");
4156 dasd_eckd_dump_sense_dbf(struct dasd_device
*device
, struct irb
*irb
,
4162 sense
= (u64
*) dasd_get_sense(irb
);
4163 stat
= (u64
*) &irb
->scsw
;
4165 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : "
4166 "%016llx %016llx %016llx %016llx",
4167 reason
, *stat
, *((u32
*) (stat
+ 1)),
4168 sense
[0], sense
[1], sense
[2], sense
[3]);
4170 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : %s",
4171 reason
, *stat
, *((u32
*) (stat
+ 1)),
4177 * Print sense data and related channel program.
4178 * Parts are printed because printk buffer is only 1024 bytes.
4180 static void dasd_eckd_dump_sense_ccw(struct dasd_device
*device
,
4181 struct dasd_ccw_req
*req
, struct irb
*irb
)
4184 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
4187 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4189 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4190 "No memory to dump sense data\n");
4193 /* dump the sense data */
4194 len
= sprintf(page
, PRINTK_HEADER
4195 " I/O status report for device %s:\n",
4196 dev_name(&device
->cdev
->dev
));
4197 len
+= sprintf(page
+ len
, PRINTK_HEADER
4198 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4200 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4201 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4202 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4203 req
? req
->intrc
: 0);
4204 len
+= sprintf(page
+ len
, PRINTK_HEADER
4205 " device %s: Failing CCW: %p\n",
4206 dev_name(&device
->cdev
->dev
),
4207 (void *) (addr_t
) irb
->scsw
.cmd
.cpa
);
4208 if (irb
->esw
.esw0
.erw
.cons
) {
4209 for (sl
= 0; sl
< 4; sl
++) {
4210 len
+= sprintf(page
+ len
, PRINTK_HEADER
4211 " Sense(hex) %2d-%2d:",
4212 (8 * sl
), ((8 * sl
) + 7));
4214 for (sct
= 0; sct
< 8; sct
++) {
4215 len
+= sprintf(page
+ len
, " %02x",
4216 irb
->ecw
[8 * sl
+ sct
]);
4218 len
+= sprintf(page
+ len
, "\n");
4221 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
4222 /* 24 Byte Sense Data */
4223 sprintf(page
+ len
, PRINTK_HEADER
4224 " 24 Byte: %x MSG %x, "
4225 "%s MSGb to SYSOP\n",
4226 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
4227 irb
->ecw
[1] & 0x10 ? "" : "no");
4229 /* 32 Byte Sense Data */
4230 sprintf(page
+ len
, PRINTK_HEADER
4231 " 32 Byte: Format: %x "
4232 "Exception class %x\n",
4233 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
4236 sprintf(page
+ len
, PRINTK_HEADER
4237 " SORRY - NO VALID SENSE AVAILABLE\n");
4239 printk(KERN_ERR
"%s", page
);
4242 /* req == NULL for unsolicited interrupts */
4243 /* dump the Channel Program (max 140 Bytes per line) */
4244 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4245 first
= req
->cpaddr
;
4246 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
4247 to
= min(first
+ 6, last
);
4248 len
= sprintf(page
, PRINTK_HEADER
4249 " Related CP in req: %p\n", req
);
4250 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
4251 printk(KERN_ERR
"%s", page
);
4253 /* print failing CCW area (maximum 4) */
4254 /* scsw->cda is either valid or zero */
4257 fail
= (struct ccw1
*)(addr_t
)
4258 irb
->scsw
.cmd
.cpa
; /* failing CCW */
4259 if (from
< fail
- 2) {
4260 from
= fail
- 2; /* there is a gap - print header */
4261 len
+= sprintf(page
, PRINTK_HEADER
"......\n");
4263 to
= min(fail
+ 1, last
);
4264 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
4266 /* print last CCWs (maximum 2) */
4267 from
= max(from
, ++to
);
4268 if (from
< last
- 1) {
4269 from
= last
- 1; /* there is a gap - print header */
4270 len
+= sprintf(page
+ len
, PRINTK_HEADER
"......\n");
4272 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
4274 printk(KERN_ERR
"%s", page
);
4276 free_page((unsigned long) page
);
4281 * Print sense data from a tcw.
4283 static void dasd_eckd_dump_sense_tcw(struct dasd_device
*device
,
4284 struct dasd_ccw_req
*req
, struct irb
*irb
)
4287 int len
, sl
, sct
, residual
;
4291 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
4293 DBF_DEV_EVENT(DBF_WARNING
, device
, " %s",
4294 "No memory to dump sense data");
4297 /* dump the sense data */
4298 len
= sprintf(page
, PRINTK_HEADER
4299 " I/O status report for device %s:\n",
4300 dev_name(&device
->cdev
->dev
));
4301 len
+= sprintf(page
+ len
, PRINTK_HEADER
4302 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4303 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4304 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
4305 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
4306 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
4307 irb
->scsw
.tm
.fcxs
, irb
->scsw
.tm
.schxs
,
4308 req
? req
->intrc
: 0);
4309 len
+= sprintf(page
+ len
, PRINTK_HEADER
4310 " device %s: Failing TCW: %p\n",
4311 dev_name(&device
->cdev
->dev
),
4312 (void *) (addr_t
) irb
->scsw
.tm
.tcw
);
4316 if (irb
->scsw
.tm
.tcw
&& (irb
->scsw
.tm
.fcxs
& 0x01))
4318 (struct tcw
*)(unsigned long)irb
->scsw
.tm
.tcw
);
4321 len
+= sprintf(page
+ len
, PRINTK_HEADER
4322 " tsb->length %d\n", tsb
->length
);
4323 len
+= sprintf(page
+ len
, PRINTK_HEADER
4324 " tsb->flags %x\n", tsb
->flags
);
4325 len
+= sprintf(page
+ len
, PRINTK_HEADER
4326 " tsb->dcw_offset %d\n", tsb
->dcw_offset
);
4327 len
+= sprintf(page
+ len
, PRINTK_HEADER
4328 " tsb->count %d\n", tsb
->count
);
4329 residual
= tsb
->count
- 28;
4330 len
+= sprintf(page
+ len
, PRINTK_HEADER
4331 " residual %d\n", residual
);
4333 switch (tsb
->flags
& 0x07) {
4334 case 1: /* tsa_iostat */
4335 len
+= sprintf(page
+ len
, PRINTK_HEADER
4336 " tsb->tsa.iostat.dev_time %d\n",
4337 tsb
->tsa
.iostat
.dev_time
);
4338 len
+= sprintf(page
+ len
, PRINTK_HEADER
4339 " tsb->tsa.iostat.def_time %d\n",
4340 tsb
->tsa
.iostat
.def_time
);
4341 len
+= sprintf(page
+ len
, PRINTK_HEADER
4342 " tsb->tsa.iostat.queue_time %d\n",
4343 tsb
->tsa
.iostat
.queue_time
);
4344 len
+= sprintf(page
+ len
, PRINTK_HEADER
4345 " tsb->tsa.iostat.dev_busy_time %d\n",
4346 tsb
->tsa
.iostat
.dev_busy_time
);
4347 len
+= sprintf(page
+ len
, PRINTK_HEADER
4348 " tsb->tsa.iostat.dev_act_time %d\n",
4349 tsb
->tsa
.iostat
.dev_act_time
);
4350 sense
= tsb
->tsa
.iostat
.sense
;
4352 case 2: /* ts_ddpc */
4353 len
+= sprintf(page
+ len
, PRINTK_HEADER
4354 " tsb->tsa.ddpc.rc %d\n", tsb
->tsa
.ddpc
.rc
);
4355 for (sl
= 0; sl
< 2; sl
++) {
4356 len
+= sprintf(page
+ len
, PRINTK_HEADER
4357 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4358 (8 * sl
), ((8 * sl
) + 7));
4359 rcq
= tsb
->tsa
.ddpc
.rcq
;
4360 for (sct
= 0; sct
< 8; sct
++) {
4361 len
+= sprintf(page
+ len
, " %02x",
4364 len
+= sprintf(page
+ len
, "\n");
4366 sense
= tsb
->tsa
.ddpc
.sense
;
4368 case 3: /* tsa_intrg */
4369 len
+= sprintf(page
+ len
, PRINTK_HEADER
4370 " tsb->tsa.intrg.: not supportet yet\n");
4375 for (sl
= 0; sl
< 4; sl
++) {
4376 len
+= sprintf(page
+ len
, PRINTK_HEADER
4377 " Sense(hex) %2d-%2d:",
4378 (8 * sl
), ((8 * sl
) + 7));
4379 for (sct
= 0; sct
< 8; sct
++) {
4380 len
+= sprintf(page
+ len
, " %02x",
4381 sense
[8 * sl
+ sct
]);
4383 len
+= sprintf(page
+ len
, "\n");
4386 if (sense
[27] & DASD_SENSE_BIT_0
) {
4387 /* 24 Byte Sense Data */
4388 sprintf(page
+ len
, PRINTK_HEADER
4389 " 24 Byte: %x MSG %x, "
4390 "%s MSGb to SYSOP\n",
4391 sense
[7] >> 4, sense
[7] & 0x0f,
4392 sense
[1] & 0x10 ? "" : "no");
4394 /* 32 Byte Sense Data */
4395 sprintf(page
+ len
, PRINTK_HEADER
4396 " 32 Byte: Format: %x "
4397 "Exception class %x\n",
4398 sense
[6] & 0x0f, sense
[22] >> 4);
4401 sprintf(page
+ len
, PRINTK_HEADER
4402 " SORRY - NO VALID SENSE AVAILABLE\n");
4405 sprintf(page
+ len
, PRINTK_HEADER
4406 " SORRY - NO TSB DATA AVAILABLE\n");
4408 printk(KERN_ERR
"%s", page
);
4409 free_page((unsigned long) page
);
4412 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
4413 struct dasd_ccw_req
*req
, struct irb
*irb
)
4415 if (scsw_is_tm(&irb
->scsw
))
4416 dasd_eckd_dump_sense_tcw(device
, req
, irb
);
4418 dasd_eckd_dump_sense_ccw(device
, req
, irb
);
4421 static int dasd_eckd_pm_freeze(struct dasd_device
*device
)
4424 * the device should be disconnected from our LCU structure
4425 * on restore we will reconnect it and reread LCU specific
4426 * information like PAV support that might have changed
4428 dasd_alias_remove_device(device
);
4429 dasd_alias_disconnect_device_from_lcu(device
);
4434 static int dasd_eckd_restore_device(struct dasd_device
*device
)
4436 struct dasd_eckd_private
*private = device
->private;
4437 struct dasd_eckd_characteristics temp_rdc_data
;
4439 struct dasd_uid temp_uid
;
4440 unsigned long flags
;
4441 unsigned long cqr_flags
= 0;
4443 /* Read Configuration Data */
4444 rc
= dasd_eckd_read_conf(device
);
4446 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4447 "Read configuration data failed, rc=%d", rc
);
4451 dasd_eckd_get_uid(device
, &temp_uid
);
4452 /* Generate device unique id */
4453 rc
= dasd_eckd_generate_uid(device
);
4454 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4455 if (memcmp(&private->uid
, &temp_uid
, sizeof(struct dasd_uid
)) != 0)
4456 dev_err(&device
->cdev
->dev
, "The UID of the DASD has "
4458 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4462 /* register lcu with alias handling, enable PAV if this is a new lcu */
4463 rc
= dasd_alias_make_device_known_to_lcu(device
);
4467 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr_flags
);
4468 dasd_eckd_validate_server(device
, cqr_flags
);
4470 /* RE-Read Configuration Data */
4471 rc
= dasd_eckd_read_conf(device
);
4473 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4474 "Read configuration data failed, rc=%d", rc
);
4478 /* Read Feature Codes */
4479 dasd_eckd_read_features(device
);
4481 /* Read Device Characteristics */
4482 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
4483 &temp_rdc_data
, 64);
4485 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4486 "Read device characteristic failed, rc=%d", rc
);
4489 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4490 memcpy(&private->rdc_data
, &temp_rdc_data
, sizeof(temp_rdc_data
));
4491 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4493 /* add device to alias management */
4494 dasd_alias_add_device(device
);
4499 dasd_alias_disconnect_device_from_lcu(device
);
4504 static int dasd_eckd_reload_device(struct dasd_device
*device
)
4506 struct dasd_eckd_private
*private = device
->private;
4509 struct dasd_uid uid
;
4510 unsigned long flags
;
4513 * remove device from alias handling to prevent new requests
4514 * from being scheduled on the wrong alias device
4516 dasd_alias_remove_device(device
);
4518 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4519 old_base
= private->uid
.base_unit_addr
;
4520 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4522 /* Read Configuration Data */
4523 rc
= dasd_eckd_read_conf(device
);
4527 rc
= dasd_eckd_generate_uid(device
);
4531 * update unit address configuration and
4532 * add device to alias management
4534 dasd_alias_update_add_device(device
);
4536 dasd_eckd_get_uid(device
, &uid
);
4538 if (old_base
!= uid
.base_unit_addr
) {
4539 if (strlen(uid
.vduit
) > 0)
4540 snprintf(print_uid
, sizeof(print_uid
),
4541 "%s.%s.%04x.%02x.%s", uid
.vendor
, uid
.serial
,
4542 uid
.ssid
, uid
.base_unit_addr
, uid
.vduit
);
4544 snprintf(print_uid
, sizeof(print_uid
),
4545 "%s.%s.%04x.%02x", uid
.vendor
, uid
.serial
,
4546 uid
.ssid
, uid
.base_unit_addr
);
4548 dev_info(&device
->cdev
->dev
,
4549 "An Alias device was reassigned to a new base device "
4550 "with UID: %s\n", print_uid
);
4558 static int dasd_eckd_read_message_buffer(struct dasd_device
*device
,
4559 struct dasd_rssd_messages
*messages
,
4562 struct dasd_rssd_messages
*message_buf
;
4563 struct dasd_psf_prssd_data
*prssdp
;
4564 struct dasd_ccw_req
*cqr
;
4568 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
4569 (sizeof(struct dasd_psf_prssd_data
) +
4570 sizeof(struct dasd_rssd_messages
)),
4573 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
4574 "Could not allocate read message buffer request");
4575 return PTR_ERR(cqr
);
4578 cqr
->startdev
= device
;
4579 cqr
->memdev
= device
;
4581 cqr
->expires
= 10 * HZ
;
4582 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
4583 /* dasd_sleep_on_immediatly does not do complex error
4584 * recovery so clear erp flag and set retry counter to
4586 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
4589 /* Prepare for Read Subsystem Data */
4590 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4591 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
4592 prssdp
->order
= PSF_ORDER_PRSSD
;
4593 prssdp
->suborder
= 0x03; /* Message Buffer */
4594 /* all other bytes of prssdp must be zero */
4597 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4598 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
4599 ccw
->flags
|= CCW_FLAG_CC
;
4600 ccw
->flags
|= CCW_FLAG_SLI
;
4601 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
4603 /* Read Subsystem Data - message buffer */
4604 message_buf
= (struct dasd_rssd_messages
*) (prssdp
+ 1);
4605 memset(message_buf
, 0, sizeof(struct dasd_rssd_messages
));
4608 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
4609 ccw
->count
= sizeof(struct dasd_rssd_messages
);
4610 ccw
->flags
|= CCW_FLAG_SLI
;
4611 ccw
->cda
= (__u32
)(addr_t
) message_buf
;
4613 cqr
->buildclk
= get_tod_clock();
4614 cqr
->status
= DASD_CQR_FILLED
;
4615 rc
= dasd_sleep_on_immediatly(cqr
);
4617 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
4618 message_buf
= (struct dasd_rssd_messages
*)
4620 memcpy(messages
, message_buf
,
4621 sizeof(struct dasd_rssd_messages
));
4623 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4624 "Reading messages failed with rc=%d\n"
4626 dasd_sfree_request(cqr
, cqr
->memdev
);
4631 * Perform Subsystem Function - CUIR response
4634 dasd_eckd_psf_cuir_response(struct dasd_device
*device
, int response
,
4636 struct channel_path_desc
*desc
,
4637 struct subchannel_id sch_id
)
4639 struct dasd_psf_cuir_response
*psf_cuir
;
4640 struct dasd_ccw_req
*cqr
;
4644 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
4645 sizeof(struct dasd_psf_cuir_response
),
4649 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
4650 "Could not allocate PSF-CUIR request");
4651 return PTR_ERR(cqr
);
4654 psf_cuir
= (struct dasd_psf_cuir_response
*)cqr
->data
;
4655 psf_cuir
->order
= PSF_ORDER_CUIR_RESPONSE
;
4656 psf_cuir
->cc
= response
;
4658 psf_cuir
->chpid
= desc
->chpid
;
4659 psf_cuir
->message_id
= message_id
;
4660 psf_cuir
->cssid
= sch_id
.cssid
;
4661 psf_cuir
->ssid
= sch_id
.ssid
;
4663 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
4664 ccw
->cda
= (__u32
)(addr_t
)psf_cuir
;
4665 ccw
->flags
= CCW_FLAG_SLI
;
4666 ccw
->count
= sizeof(struct dasd_psf_cuir_response
);
4668 cqr
->startdev
= device
;
4669 cqr
->memdev
= device
;
4672 cqr
->expires
= 10*HZ
;
4673 cqr
->buildclk
= get_tod_clock();
4674 cqr
->status
= DASD_CQR_FILLED
;
4675 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
4677 rc
= dasd_sleep_on(cqr
);
4679 dasd_sfree_request(cqr
, cqr
->memdev
);
4684 * return configuration data that is referenced by record selector
4685 * if a record selector is specified or per default return the
4686 * conf_data pointer for the path specified by lpum
4688 static struct dasd_conf_data
*dasd_eckd_get_ref_conf(struct dasd_device
*device
,
4690 struct dasd_cuir_message
*cuir
)
4692 struct dasd_eckd_private
*private = device
->private;
4693 struct dasd_conf_data
*conf_data
;
4696 if (cuir
->record_selector
== 0)
4698 for (path
= 0x80, pos
= 0; path
; path
>>= 1, pos
++) {
4699 conf_data
= private->path_conf_data
[pos
];
4700 if (conf_data
->gneq
.record_selector
==
4701 cuir
->record_selector
)
4705 return private->path_conf_data
[pathmask_to_pos(lpum
)];
4709 * This function determines the scope of a reconfiguration request by
4710 * analysing the path and device selection data provided in the CUIR request.
4711 * Returns a path mask containing CUIR affected paths for the give device.
4713 * If the CUIR request does not contain the required information return the
4714 * path mask of the path the attention message for the CUIR request was reveived
4717 static int dasd_eckd_cuir_scope(struct dasd_device
*device
, __u8 lpum
,
4718 struct dasd_cuir_message
*cuir
)
4720 struct dasd_eckd_private
*private = device
->private;
4721 struct dasd_conf_data
*ref_conf_data
;
4722 unsigned long bitmask
= 0, mask
= 0;
4723 struct dasd_conf_data
*conf_data
;
4724 unsigned int pos
, path
;
4725 char *ref_gneq
, *gneq
;
4726 char *ref_ned
, *ned
;
4729 /* if CUIR request does not specify the scope use the path
4730 the attention message was presented on */
4731 if (!cuir
->ned_map
||
4732 !(cuir
->neq_map
[0] | cuir
->neq_map
[1] | cuir
->neq_map
[2]))
4735 /* get reference conf data */
4736 ref_conf_data
= dasd_eckd_get_ref_conf(device
, lpum
, cuir
);
4737 /* reference ned is determined by ned_map field */
4738 pos
= 8 - ffs(cuir
->ned_map
);
4739 ref_ned
= (char *)&ref_conf_data
->neds
[pos
];
4740 ref_gneq
= (char *)&ref_conf_data
->gneq
;
4741 /* transfer 24 bit neq_map to mask */
4742 mask
= cuir
->neq_map
[2];
4743 mask
|= cuir
->neq_map
[1] << 8;
4744 mask
|= cuir
->neq_map
[0] << 16;
4746 for (path
= 0x80; path
; path
>>= 1) {
4747 /* initialise data per path */
4749 pos
= pathmask_to_pos(path
);
4750 conf_data
= private->path_conf_data
[pos
];
4751 pos
= 8 - ffs(cuir
->ned_map
);
4752 ned
= (char *) &conf_data
->neds
[pos
];
4753 /* compare reference ned and per path ned */
4754 if (memcmp(ref_ned
, ned
, sizeof(*ned
)) != 0)
4756 gneq
= (char *)&conf_data
->gneq
;
4757 /* compare reference gneq and per_path gneq under
4758 24 bit mask where mask bit 0 equals byte 7 of
4759 the gneq and mask bit 24 equals byte 31 */
4761 pos
= ffs(bitmask
) - 1;
4762 if (memcmp(&ref_gneq
[31 - pos
], &gneq
[31 - pos
], 1)
4765 clear_bit(pos
, &bitmask
);
4769 /* device and path match the reference values
4770 add path to CUIR scope */
4776 static void dasd_eckd_cuir_notify_user(struct dasd_device
*device
,
4777 unsigned long paths
,
4778 struct subchannel_id sch_id
, int action
)
4780 struct channel_path_desc
*desc
;
4784 /* get position of bit in mask */
4785 pos
= ffs(paths
) - 1;
4786 /* get channel path descriptor from this position */
4787 desc
= ccw_device_get_chp_desc(device
->cdev
, 7 - pos
);
4788 if (action
== CUIR_QUIESCE
)
4789 pr_warn("Service on the storage server caused path "
4790 "%x.%02x to go offline", sch_id
.cssid
,
4791 desc
? desc
->chpid
: 0);
4792 else if (action
== CUIR_RESUME
)
4793 pr_info("Path %x.%02x is back online after service "
4794 "on the storage server", sch_id
.cssid
,
4795 desc
? desc
->chpid
: 0);
4797 clear_bit(pos
, &paths
);
4801 static int dasd_eckd_cuir_remove_path(struct dasd_device
*device
, __u8 lpum
,
4802 struct dasd_cuir_message
*cuir
)
4804 unsigned long tbcpm
;
4806 tbcpm
= dasd_eckd_cuir_scope(device
, lpum
, cuir
);
4807 /* nothing to do if path is not in use */
4808 if (!(device
->path_data
.opm
& tbcpm
))
4810 if (!(device
->path_data
.opm
& ~tbcpm
)) {
4811 /* no path would be left if the CUIR action is taken
4815 /* remove device from operational path mask */
4816 device
->path_data
.opm
&= ~tbcpm
;
4817 device
->path_data
.cuirpm
|= tbcpm
;
4822 * walk through all devices and build a path mask to quiesce them
4823 * return an error if the last path to a device would be removed
4825 * if only part of the devices are quiesced and an error
4826 * occurs no onlining necessary, the storage server will
4827 * notify the already set offline devices again
4829 static int dasd_eckd_cuir_quiesce(struct dasd_device
*device
, __u8 lpum
,
4830 struct subchannel_id sch_id
,
4831 struct dasd_cuir_message
*cuir
)
4833 struct dasd_eckd_private
*private = device
->private;
4834 struct alias_pav_group
*pavgroup
, *tempgroup
;
4835 struct dasd_device
*dev
, *n
;
4836 unsigned long paths
= 0;
4837 unsigned long flags
;
4840 /* active devices */
4841 list_for_each_entry_safe(dev
, n
, &private->lcu
->active_devices
,
4843 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4844 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4845 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
4850 /* inactive devices */
4851 list_for_each_entry_safe(dev
, n
, &private->lcu
->inactive_devices
,
4853 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4854 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4855 spin_unlock_irqrestore(get_ccwdev_lock(dev
->cdev
), flags
);
4860 /* devices in PAV groups */
4861 list_for_each_entry_safe(pavgroup
, tempgroup
,
4862 &private->lcu
->grouplist
, group
) {
4863 list_for_each_entry_safe(dev
, n
, &pavgroup
->baselist
,
4865 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4866 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4867 spin_unlock_irqrestore(
4868 get_ccwdev_lock(dev
->cdev
), flags
);
4873 list_for_each_entry_safe(dev
, n
, &pavgroup
->aliaslist
,
4875 spin_lock_irqsave(get_ccwdev_lock(dev
->cdev
), flags
);
4876 tbcpm
= dasd_eckd_cuir_remove_path(dev
, lpum
, cuir
);
4877 spin_unlock_irqrestore(
4878 get_ccwdev_lock(dev
->cdev
), flags
);
4884 /* notify user about all paths affected by CUIR action */
4885 dasd_eckd_cuir_notify_user(device
, paths
, sch_id
, CUIR_QUIESCE
);
4891 static int dasd_eckd_cuir_resume(struct dasd_device
*device
, __u8 lpum
,
4892 struct subchannel_id sch_id
,
4893 struct dasd_cuir_message
*cuir
)
4895 struct dasd_eckd_private
*private = device
->private;
4896 struct alias_pav_group
*pavgroup
, *tempgroup
;
4897 struct dasd_device
*dev
, *n
;
4898 unsigned long paths
= 0;
4902 * the path may have been added through a generic path event before
4903 * only trigger path verification if the path is not already in use
4905 list_for_each_entry_safe(dev
, n
,
4906 &private->lcu
->active_devices
,
4908 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4910 if (!(dev
->path_data
.opm
& tbcpm
)) {
4911 dev
->path_data
.tbvpm
|= tbcpm
;
4912 dasd_schedule_device_bh(dev
);
4915 list_for_each_entry_safe(dev
, n
,
4916 &private->lcu
->inactive_devices
,
4918 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4920 if (!(dev
->path_data
.opm
& tbcpm
)) {
4921 dev
->path_data
.tbvpm
|= tbcpm
;
4922 dasd_schedule_device_bh(dev
);
4925 /* devices in PAV groups */
4926 list_for_each_entry_safe(pavgroup
, tempgroup
,
4927 &private->lcu
->grouplist
,
4929 list_for_each_entry_safe(dev
, n
,
4930 &pavgroup
->baselist
,
4932 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4934 if (!(dev
->path_data
.opm
& tbcpm
)) {
4935 dev
->path_data
.tbvpm
|= tbcpm
;
4936 dasd_schedule_device_bh(dev
);
4939 list_for_each_entry_safe(dev
, n
,
4940 &pavgroup
->aliaslist
,
4942 tbcpm
= dasd_eckd_cuir_scope(dev
, lpum
, cuir
);
4944 if (!(dev
->path_data
.opm
& tbcpm
)) {
4945 dev
->path_data
.tbvpm
|= tbcpm
;
4946 dasd_schedule_device_bh(dev
);
4950 /* notify user about all paths affected by CUIR action */
4951 dasd_eckd_cuir_notify_user(device
, paths
, sch_id
, CUIR_RESUME
);
4955 static void dasd_eckd_handle_cuir(struct dasd_device
*device
, void *messages
,
4958 struct dasd_cuir_message
*cuir
= messages
;
4959 struct channel_path_desc
*desc
;
4960 struct subchannel_id sch_id
;
4963 DBF_DEV_EVENT(DBF_WARNING
, device
,
4964 "CUIR request: %016llx %016llx %016llx %08x",
4965 ((u64
*)cuir
)[0], ((u64
*)cuir
)[1], ((u64
*)cuir
)[2],
4967 ccw_device_get_schid(device
->cdev
, &sch_id
);
4968 pos
= pathmask_to_pos(lpum
);
4969 desc
= ccw_device_get_chp_desc(device
->cdev
, pos
);
4971 if (cuir
->code
== CUIR_QUIESCE
) {
4973 if (dasd_eckd_cuir_quiesce(device
, lpum
, sch_id
, cuir
))
4974 response
= PSF_CUIR_LAST_PATH
;
4976 response
= PSF_CUIR_COMPLETED
;
4977 } else if (cuir
->code
== CUIR_RESUME
) {
4979 dasd_eckd_cuir_resume(device
, lpum
, sch_id
, cuir
);
4980 response
= PSF_CUIR_COMPLETED
;
4982 response
= PSF_CUIR_NOT_SUPPORTED
;
4984 dasd_eckd_psf_cuir_response(device
, response
,
4985 cuir
->message_id
, desc
, sch_id
);
4986 DBF_DEV_EVENT(DBF_WARNING
, device
,
4987 "CUIR response: %d on message ID %08x", response
,
4989 /* free descriptor copy */
4991 /* to make sure there is no attention left schedule work again */
4992 device
->discipline
->check_attention(device
, lpum
);
4995 static void dasd_eckd_check_attention_work(struct work_struct
*work
)
4997 struct check_attention_work_data
*data
;
4998 struct dasd_rssd_messages
*messages
;
4999 struct dasd_device
*device
;
5002 data
= container_of(work
, struct check_attention_work_data
, worker
);
5003 device
= data
->device
;
5004 messages
= kzalloc(sizeof(*messages
), GFP_KERNEL
);
5006 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
5007 "Could not allocate attention message buffer");
5010 rc
= dasd_eckd_read_message_buffer(device
, messages
, data
->lpum
);
5013 if (messages
->length
== ATTENTION_LENGTH_CUIR
&&
5014 messages
->format
== ATTENTION_FORMAT_CUIR
)
5015 dasd_eckd_handle_cuir(device
, messages
, data
->lpum
);
5017 dasd_put_device(device
);
5022 static int dasd_eckd_check_attention(struct dasd_device
*device
, __u8 lpum
)
5024 struct check_attention_work_data
*data
;
5026 data
= kzalloc(sizeof(*data
), GFP_ATOMIC
);
5029 INIT_WORK(&data
->worker
, dasd_eckd_check_attention_work
);
5030 dasd_get_device(device
);
5031 data
->device
= device
;
5033 schedule_work(&data
->worker
);
5037 static struct ccw_driver dasd_eckd_driver
= {
5039 .name
= "dasd-eckd",
5040 .owner
= THIS_MODULE
,
5042 .ids
= dasd_eckd_ids
,
5043 .probe
= dasd_eckd_probe
,
5044 .remove
= dasd_generic_remove
,
5045 .set_offline
= dasd_generic_set_offline
,
5046 .set_online
= dasd_eckd_set_online
,
5047 .notify
= dasd_generic_notify
,
5048 .path_event
= dasd_generic_path_event
,
5049 .shutdown
= dasd_generic_shutdown
,
5050 .freeze
= dasd_generic_pm_freeze
,
5051 .thaw
= dasd_generic_restore_device
,
5052 .restore
= dasd_generic_restore_device
,
5053 .uc_handler
= dasd_generic_uc_handler
,
5054 .int_class
= IRQIO_DAS
,
5058 * max_blocks is dependent on the amount of storage that is available
5059 * in the static io buffer for each device. Currently each device has
5060 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5061 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5062 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5063 * addition we have one define extent ccw + 16 bytes of data and one
5064 * locate record ccw + 16 bytes of data. That makes:
5065 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5066 * We want to fit two into the available memory so that we can immediately
5067 * start the next request if one finishes off. That makes 249.5 blocks
5068 * for one request. Give a little safety and the result is 240.
5070 static struct dasd_discipline dasd_eckd_discipline
= {
5071 .owner
= THIS_MODULE
,
5075 .check_device
= dasd_eckd_check_characteristics
,
5076 .uncheck_device
= dasd_eckd_uncheck_device
,
5077 .do_analysis
= dasd_eckd_do_analysis
,
5078 .verify_path
= dasd_eckd_verify_path
,
5079 .basic_to_ready
= dasd_eckd_basic_to_ready
,
5080 .online_to_ready
= dasd_eckd_online_to_ready
,
5081 .basic_to_known
= dasd_eckd_basic_to_known
,
5082 .fill_geometry
= dasd_eckd_fill_geometry
,
5083 .start_IO
= dasd_start_IO
,
5084 .term_IO
= dasd_term_IO
,
5085 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
5086 .format_device
= dasd_eckd_format_device
,
5087 .erp_action
= dasd_eckd_erp_action
,
5088 .erp_postaction
= dasd_eckd_erp_postaction
,
5089 .check_for_device_change
= dasd_eckd_check_for_device_change
,
5090 .build_cp
= dasd_eckd_build_alias_cp
,
5091 .free_cp
= dasd_eckd_free_alias_cp
,
5092 .dump_sense
= dasd_eckd_dump_sense
,
5093 .dump_sense_dbf
= dasd_eckd_dump_sense_dbf
,
5094 .fill_info
= dasd_eckd_fill_info
,
5095 .ioctl
= dasd_eckd_ioctl
,
5096 .freeze
= dasd_eckd_pm_freeze
,
5097 .restore
= dasd_eckd_restore_device
,
5098 .reload
= dasd_eckd_reload_device
,
5099 .get_uid
= dasd_eckd_get_uid
,
5100 .kick_validate
= dasd_eckd_kick_validate_server
,
5101 .check_attention
= dasd_eckd_check_attention
,
5105 dasd_eckd_init(void)
5109 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
5110 dasd_reserve_req
= kmalloc(sizeof(*dasd_reserve_req
),
5111 GFP_KERNEL
| GFP_DMA
);
5112 if (!dasd_reserve_req
)
5114 path_verification_worker
= kmalloc(sizeof(*path_verification_worker
),
5115 GFP_KERNEL
| GFP_DMA
);
5116 if (!path_verification_worker
) {
5117 kfree(dasd_reserve_req
);
5120 rawpadpage
= (void *)__get_free_page(GFP_KERNEL
);
5122 kfree(path_verification_worker
);
5123 kfree(dasd_reserve_req
);
5126 ret
= ccw_driver_register(&dasd_eckd_driver
);
5128 wait_for_device_probe();
5130 kfree(path_verification_worker
);
5131 kfree(dasd_reserve_req
);
5132 free_page((unsigned long)rawpadpage
);
5138 dasd_eckd_cleanup(void)
5140 ccw_driver_unregister(&dasd_eckd_driver
);
5141 kfree(path_verification_worker
);
5142 kfree(dasd_reserve_req
);
5143 free_page((unsigned long)rawpadpage
);
5146 module_init(dasd_eckd_init
);
5147 module_exit(dasd_eckd_cleanup
);