2 * File...........: linux/drivers/s390/block/dasd_eckd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
9 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
13 #define KMSG_COMPONENT "dasd-eckd"
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/hdreg.h> /* HDIO_GETGEO */
19 #include <linux/bio.h>
20 #include <linux/module.h>
21 #include <linux/compat.h>
22 #include <linux/init.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>
34 #include "dasd_eckd.h"
35 #include "../cio/chsc.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 */
91 #define INIT_CQR_UNFORMATTED 1
92 #define INIT_CQR_ERROR 2
94 /* emergency request for reserve/release */
96 struct dasd_ccw_req cqr
;
100 static DEFINE_MUTEX(dasd_reserve_mutex
);
102 /* definitions for the path verification worker */
103 struct path_verification_work_data
{
104 struct work_struct worker
;
105 struct dasd_device
*device
;
106 struct dasd_ccw_req cqr
;
108 __u8 rcd_buffer
[DASD_ECKD_RCD_DATA_SIZE
];
112 static struct path_verification_work_data
*path_verification_worker
;
113 static DEFINE_MUTEX(dasd_path_verification_mutex
);
115 /* initial attempt at a probe function. this can be simplified once
116 * the other detection code is gone */
118 dasd_eckd_probe (struct ccw_device
*cdev
)
122 /* set ECKD specific ccw-device options */
123 ret
= ccw_device_set_options(cdev
, CCWDEV_ALLOW_FORCE
|
124 CCWDEV_DO_PATHGROUP
| CCWDEV_DO_MULTIPATH
);
126 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
127 "dasd_eckd_probe: could not set "
128 "ccw-device options");
131 ret
= dasd_generic_probe(cdev
, &dasd_eckd_discipline
);
136 dasd_eckd_set_online(struct ccw_device
*cdev
)
138 return dasd_generic_set_online(cdev
, &dasd_eckd_discipline
);
141 static const int sizes_trk0
[] = { 28, 148, 84 };
142 #define LABEL_SIZE 140
144 static inline unsigned int
145 round_up_multiple(unsigned int no
, unsigned int mult
)
148 return (rem
? no
- rem
+ mult
: no
);
151 static inline unsigned int
152 ceil_quot(unsigned int d1
, unsigned int d2
)
154 return (d1
+ (d2
- 1)) / d2
;
158 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
159 unsigned int kl
, unsigned int dl
)
163 switch (rdc
->dev_type
) {
166 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
167 ceil_quot(dl
+ 12, 32));
169 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
171 dn
= ceil_quot(dl
+ 6, 232) + 1;
173 kn
= ceil_quot(kl
+ 6, 232) + 1;
174 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
175 9 + ceil_quot(dl
+ 6 * dn
, 34));
177 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
179 dn
= ceil_quot(dl
+ 6, 232) + 1;
181 kn
= ceil_quot(kl
+ 6, 232) + 1;
182 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
183 ceil_quot(dl
+ 6 * dn
, 34));
185 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
190 static void set_ch_t(struct ch_t
*geo
, __u32 cyl
, __u8 head
)
192 geo
->cyl
= (__u16
) cyl
;
193 geo
->head
= cyl
>> 16;
199 check_XRC (struct ccw1
*de_ccw
,
200 struct DE_eckd_data
*data
,
201 struct dasd_device
*device
)
203 struct dasd_eckd_private
*private;
206 private = (struct dasd_eckd_private
*) device
->private;
207 if (!private->rdc_data
.facilities
.XRC_supported
)
210 /* switch on System Time Stamp - needed for XRC Support */
211 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
212 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
214 rc
= get_sync_clock(&data
->ep_sys_time
);
215 /* Ignore return code if sync clock is switched off. */
216 if (rc
== -ENOSYS
|| rc
== -EACCES
)
219 de_ccw
->count
= sizeof(struct DE_eckd_data
);
220 de_ccw
->flags
|= CCW_FLAG_SLI
;
225 define_extent(struct ccw1
*ccw
, struct DE_eckd_data
*data
, unsigned int trk
,
226 unsigned int totrk
, int cmd
, struct dasd_device
*device
)
228 struct dasd_eckd_private
*private;
230 u16 heads
, beghead
, endhead
;
233 private = (struct dasd_eckd_private
*) device
->private;
235 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
238 ccw
->cda
= (__u32
) __pa(data
);
240 memset(data
, 0, sizeof(struct DE_eckd_data
));
242 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
243 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
244 case DASD_ECKD_CCW_READ
:
245 case DASD_ECKD_CCW_READ_MT
:
246 case DASD_ECKD_CCW_READ_CKD
:
247 case DASD_ECKD_CCW_READ_CKD_MT
:
248 case DASD_ECKD_CCW_READ_KD
:
249 case DASD_ECKD_CCW_READ_KD_MT
:
250 case DASD_ECKD_CCW_READ_COUNT
:
251 data
->mask
.perm
= 0x1;
252 data
->attributes
.operation
= private->attrib
.operation
;
254 case DASD_ECKD_CCW_WRITE
:
255 case DASD_ECKD_CCW_WRITE_MT
:
256 case DASD_ECKD_CCW_WRITE_KD
:
257 case DASD_ECKD_CCW_WRITE_KD_MT
:
258 data
->mask
.perm
= 0x02;
259 data
->attributes
.operation
= private->attrib
.operation
;
260 rc
= check_XRC (ccw
, data
, device
);
262 case DASD_ECKD_CCW_WRITE_CKD
:
263 case DASD_ECKD_CCW_WRITE_CKD_MT
:
264 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
265 rc
= check_XRC (ccw
, data
, device
);
267 case DASD_ECKD_CCW_ERASE
:
268 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
269 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
270 data
->mask
.perm
= 0x3;
271 data
->mask
.auth
= 0x1;
272 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
273 rc
= check_XRC (ccw
, data
, device
);
276 dev_err(&device
->cdev
->dev
,
277 "0x%x is not a known command\n", cmd
);
281 data
->attributes
.mode
= 0x3; /* ECKD */
283 if ((private->rdc_data
.cu_type
== 0x2105 ||
284 private->rdc_data
.cu_type
== 0x2107 ||
285 private->rdc_data
.cu_type
== 0x1750)
286 && !(private->uses_cdl
&& trk
< 2))
287 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
289 heads
= private->rdc_data
.trk_per_cyl
;
290 begcyl
= trk
/ heads
;
291 beghead
= trk
% heads
;
292 endcyl
= totrk
/ heads
;
293 endhead
= totrk
% heads
;
295 /* check for sequential prestage - enhance cylinder range */
296 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
297 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
299 if (endcyl
+ private->attrib
.nr_cyl
< private->real_cyl
)
300 endcyl
+= private->attrib
.nr_cyl
;
302 endcyl
= (private->real_cyl
- 1);
305 set_ch_t(&data
->beg_ext
, begcyl
, beghead
);
306 set_ch_t(&data
->end_ext
, endcyl
, endhead
);
310 static int check_XRC_on_prefix(struct PFX_eckd_data
*pfxdata
,
311 struct dasd_device
*device
)
313 struct dasd_eckd_private
*private;
316 private = (struct dasd_eckd_private
*) device
->private;
317 if (!private->rdc_data
.facilities
.XRC_supported
)
320 /* switch on System Time Stamp - needed for XRC Support */
321 pfxdata
->define_extent
.ga_extended
|= 0x08; /* 'Time Stamp Valid' */
322 pfxdata
->define_extent
.ga_extended
|= 0x02; /* 'Extended Parameter' */
323 pfxdata
->validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
325 rc
= get_sync_clock(&pfxdata
->define_extent
.ep_sys_time
);
326 /* Ignore return code if sync clock is switched off. */
327 if (rc
== -ENOSYS
|| rc
== -EACCES
)
332 static void fill_LRE_data(struct LRE_eckd_data
*data
, unsigned int trk
,
333 unsigned int rec_on_trk
, int count
, int cmd
,
334 struct dasd_device
*device
, unsigned int reclen
,
337 struct dasd_eckd_private
*private;
341 private = (struct dasd_eckd_private
*) device
->private;
343 memset(data
, 0, sizeof(*data
));
346 switch (private->rdc_data
.dev_type
) {
348 dn
= ceil_quot(reclen
+ 6, 232);
349 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
350 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
353 d
= 7 + ceil_quot(reclen
+ 12, 32);
354 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
358 data
->sector
= sector
;
359 /* note: meaning of count depends on the operation
360 * for record based I/O it's the number of records, but for
361 * track based I/O it's the number of tracks
365 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
366 data
->operation
.orientation
= 0x3;
367 data
->operation
.operation
= 0x03;
369 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
370 data
->operation
.orientation
= 0x3;
371 data
->operation
.operation
= 0x16;
373 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
374 data
->operation
.orientation
= 0x1;
375 data
->operation
.operation
= 0x03;
378 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
379 data
->operation
.orientation
= 0x3;
380 data
->operation
.operation
= 0x16;
383 case DASD_ECKD_CCW_WRITE
:
384 case DASD_ECKD_CCW_WRITE_MT
:
385 case DASD_ECKD_CCW_WRITE_KD
:
386 case DASD_ECKD_CCW_WRITE_KD_MT
:
387 data
->auxiliary
.length_valid
= 0x1;
388 data
->length
= reclen
;
389 data
->operation
.operation
= 0x01;
391 case DASD_ECKD_CCW_WRITE_CKD
:
392 case DASD_ECKD_CCW_WRITE_CKD_MT
:
393 data
->auxiliary
.length_valid
= 0x1;
394 data
->length
= reclen
;
395 data
->operation
.operation
= 0x03;
397 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
398 data
->operation
.orientation
= 0x0;
399 data
->operation
.operation
= 0x3F;
400 data
->extended_operation
= 0x11;
402 data
->extended_parameter_length
= 0x02;
403 if (data
->count
> 8) {
404 data
->extended_parameter
[0] = 0xFF;
405 data
->extended_parameter
[1] = 0xFF;
406 data
->extended_parameter
[1] <<= (16 - count
);
408 data
->extended_parameter
[0] = 0xFF;
409 data
->extended_parameter
[0] <<= (8 - count
);
410 data
->extended_parameter
[1] = 0x00;
414 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
415 data
->auxiliary
.length_valid
= 0x1;
416 data
->length
= reclen
; /* not tlf, as one might think */
417 data
->operation
.operation
= 0x3F;
418 data
->extended_operation
= 0x23;
420 case DASD_ECKD_CCW_READ
:
421 case DASD_ECKD_CCW_READ_MT
:
422 case DASD_ECKD_CCW_READ_KD
:
423 case DASD_ECKD_CCW_READ_KD_MT
:
424 data
->auxiliary
.length_valid
= 0x1;
425 data
->length
= reclen
;
426 data
->operation
.operation
= 0x06;
428 case DASD_ECKD_CCW_READ_CKD
:
429 case DASD_ECKD_CCW_READ_CKD_MT
:
430 data
->auxiliary
.length_valid
= 0x1;
431 data
->length
= reclen
;
432 data
->operation
.operation
= 0x16;
434 case DASD_ECKD_CCW_READ_COUNT
:
435 data
->operation
.operation
= 0x06;
437 case DASD_ECKD_CCW_READ_TRACK
:
438 data
->operation
.orientation
= 0x1;
439 data
->operation
.operation
= 0x0C;
440 data
->extended_parameter_length
= 0;
443 case DASD_ECKD_CCW_READ_TRACK_DATA
:
444 data
->auxiliary
.length_valid
= 0x1;
446 data
->operation
.operation
= 0x0C;
448 case DASD_ECKD_CCW_ERASE
:
449 data
->length
= reclen
;
450 data
->auxiliary
.length_valid
= 0x1;
451 data
->operation
.operation
= 0x0b;
454 DBF_DEV_EVENT(DBF_ERR
, device
,
455 "fill LRE unknown opcode 0x%x", cmd
);
458 set_ch_t(&data
->seek_addr
,
459 trk
/ private->rdc_data
.trk_per_cyl
,
460 trk
% private->rdc_data
.trk_per_cyl
);
461 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
462 data
->search_arg
.head
= data
->seek_addr
.head
;
463 data
->search_arg
.record
= rec_on_trk
;
466 static int prefix_LRE(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
467 unsigned int trk
, unsigned int totrk
, int cmd
,
468 struct dasd_device
*basedev
, struct dasd_device
*startdev
,
469 unsigned char format
, unsigned int rec_on_trk
, int count
,
470 unsigned int blksize
, unsigned int tlf
)
472 struct dasd_eckd_private
*basepriv
, *startpriv
;
473 struct DE_eckd_data
*dedata
;
474 struct LRE_eckd_data
*lredata
;
476 u16 heads
, beghead
, endhead
;
479 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
480 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
481 dedata
= &pfxdata
->define_extent
;
482 lredata
= &pfxdata
->locate_record
;
484 ccw
->cmd_code
= DASD_ECKD_CCW_PFX
;
486 if (cmd
== DASD_ECKD_CCW_WRITE_FULL_TRACK
) {
487 ccw
->count
= sizeof(*pfxdata
) + 2;
488 ccw
->cda
= (__u32
) __pa(pfxdata
);
489 memset(pfxdata
, 0, sizeof(*pfxdata
) + 2);
491 ccw
->count
= sizeof(*pfxdata
);
492 ccw
->cda
= (__u32
) __pa(pfxdata
);
493 memset(pfxdata
, 0, sizeof(*pfxdata
));
498 DBF_DEV_EVENT(DBF_ERR
, basedev
,
499 "PFX LRE unknown format 0x%x", format
);
503 pfxdata
->format
= format
;
504 pfxdata
->base_address
= basepriv
->ned
->unit_addr
;
505 pfxdata
->base_lss
= basepriv
->ned
->ID
;
506 pfxdata
->validity
.define_extent
= 1;
508 /* private uid is kept up to date, conf_data may be outdated */
509 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
510 pfxdata
->validity
.verify_base
= 1;
511 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
512 pfxdata
->validity
.hyper_pav
= 1;
515 /* define extend data (mostly)*/
517 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
518 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
519 case DASD_ECKD_CCW_READ
:
520 case DASD_ECKD_CCW_READ_MT
:
521 case DASD_ECKD_CCW_READ_CKD
:
522 case DASD_ECKD_CCW_READ_CKD_MT
:
523 case DASD_ECKD_CCW_READ_KD
:
524 case DASD_ECKD_CCW_READ_KD_MT
:
525 case DASD_ECKD_CCW_READ_COUNT
:
526 dedata
->mask
.perm
= 0x1;
527 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
529 case DASD_ECKD_CCW_READ_TRACK
:
530 case DASD_ECKD_CCW_READ_TRACK_DATA
:
531 dedata
->mask
.perm
= 0x1;
532 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
533 dedata
->blk_size
= 0;
535 case DASD_ECKD_CCW_WRITE
:
536 case DASD_ECKD_CCW_WRITE_MT
:
537 case DASD_ECKD_CCW_WRITE_KD
:
538 case DASD_ECKD_CCW_WRITE_KD_MT
:
539 dedata
->mask
.perm
= 0x02;
540 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
541 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
543 case DASD_ECKD_CCW_WRITE_CKD
:
544 case DASD_ECKD_CCW_WRITE_CKD_MT
:
545 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
546 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
548 case DASD_ECKD_CCW_ERASE
:
549 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
550 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
551 dedata
->mask
.perm
= 0x3;
552 dedata
->mask
.auth
= 0x1;
553 dedata
->attributes
.operation
= DASD_BYPASS_CACHE
;
554 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
556 case DASD_ECKD_CCW_WRITE_FULL_TRACK
:
557 dedata
->mask
.perm
= 0x03;
558 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
559 dedata
->blk_size
= 0;
561 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
562 dedata
->mask
.perm
= 0x02;
563 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
564 dedata
->blk_size
= blksize
;
565 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
568 DBF_DEV_EVENT(DBF_ERR
, basedev
,
569 "PFX LRE unknown opcode 0x%x", cmd
);
574 dedata
->attributes
.mode
= 0x3; /* ECKD */
576 if ((basepriv
->rdc_data
.cu_type
== 0x2105 ||
577 basepriv
->rdc_data
.cu_type
== 0x2107 ||
578 basepriv
->rdc_data
.cu_type
== 0x1750)
579 && !(basepriv
->uses_cdl
&& trk
< 2))
580 dedata
->ga_extended
|= 0x40; /* Regular Data Format Mode */
582 heads
= basepriv
->rdc_data
.trk_per_cyl
;
583 begcyl
= trk
/ heads
;
584 beghead
= trk
% heads
;
585 endcyl
= totrk
/ heads
;
586 endhead
= totrk
% heads
;
588 /* check for sequential prestage - enhance cylinder range */
589 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
590 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
592 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
593 endcyl
+= basepriv
->attrib
.nr_cyl
;
595 endcyl
= (basepriv
->real_cyl
- 1);
598 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
599 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
602 fill_LRE_data(lredata
, trk
, rec_on_trk
, count
, cmd
,
603 basedev
, blksize
, tlf
);
609 static int prefix(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
,
610 unsigned int trk
, unsigned int totrk
, int cmd
,
611 struct dasd_device
*basedev
, struct dasd_device
*startdev
)
613 return prefix_LRE(ccw
, pfxdata
, trk
, totrk
, cmd
, basedev
, startdev
,
618 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, unsigned int trk
,
619 unsigned int rec_on_trk
, int no_rec
, int cmd
,
620 struct dasd_device
* device
, int reclen
)
622 struct dasd_eckd_private
*private;
626 private = (struct dasd_eckd_private
*) device
->private;
628 DBF_DEV_EVENT(DBF_INFO
, device
,
629 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
630 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
632 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
635 ccw
->cda
= (__u32
) __pa(data
);
637 memset(data
, 0, sizeof(struct LO_eckd_data
));
640 switch (private->rdc_data
.dev_type
) {
642 dn
= ceil_quot(reclen
+ 6, 232);
643 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
644 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
647 d
= 7 + ceil_quot(reclen
+ 12, 32);
648 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
652 data
->sector
= sector
;
653 data
->count
= no_rec
;
655 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
656 data
->operation
.orientation
= 0x3;
657 data
->operation
.operation
= 0x03;
659 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
660 data
->operation
.orientation
= 0x3;
661 data
->operation
.operation
= 0x16;
663 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
664 data
->operation
.orientation
= 0x1;
665 data
->operation
.operation
= 0x03;
668 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
669 data
->operation
.orientation
= 0x3;
670 data
->operation
.operation
= 0x16;
673 case DASD_ECKD_CCW_WRITE
:
674 case DASD_ECKD_CCW_WRITE_MT
:
675 case DASD_ECKD_CCW_WRITE_KD
:
676 case DASD_ECKD_CCW_WRITE_KD_MT
:
677 data
->auxiliary
.last_bytes_used
= 0x1;
678 data
->length
= reclen
;
679 data
->operation
.operation
= 0x01;
681 case DASD_ECKD_CCW_WRITE_CKD
:
682 case DASD_ECKD_CCW_WRITE_CKD_MT
:
683 data
->auxiliary
.last_bytes_used
= 0x1;
684 data
->length
= reclen
;
685 data
->operation
.operation
= 0x03;
687 case DASD_ECKD_CCW_READ
:
688 case DASD_ECKD_CCW_READ_MT
:
689 case DASD_ECKD_CCW_READ_KD
:
690 case DASD_ECKD_CCW_READ_KD_MT
:
691 data
->auxiliary
.last_bytes_used
= 0x1;
692 data
->length
= reclen
;
693 data
->operation
.operation
= 0x06;
695 case DASD_ECKD_CCW_READ_CKD
:
696 case DASD_ECKD_CCW_READ_CKD_MT
:
697 data
->auxiliary
.last_bytes_used
= 0x1;
698 data
->length
= reclen
;
699 data
->operation
.operation
= 0x16;
701 case DASD_ECKD_CCW_READ_COUNT
:
702 data
->operation
.operation
= 0x06;
704 case DASD_ECKD_CCW_ERASE
:
705 data
->length
= reclen
;
706 data
->auxiliary
.last_bytes_used
= 0x1;
707 data
->operation
.operation
= 0x0b;
710 DBF_DEV_EVENT(DBF_ERR
, device
, "unknown locate record "
713 set_ch_t(&data
->seek_addr
,
714 trk
/ private->rdc_data
.trk_per_cyl
,
715 trk
% private->rdc_data
.trk_per_cyl
);
716 data
->search_arg
.cyl
= data
->seek_addr
.cyl
;
717 data
->search_arg
.head
= data
->seek_addr
.head
;
718 data
->search_arg
.record
= rec_on_trk
;
722 * Returns 1 if the block is one of the special blocks that needs
723 * to get read/written with the KD variant of the command.
724 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
725 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
726 * Luckily the KD variants differ only by one bit (0x08) from the
727 * normal variant. So don't wonder about code like:
728 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
729 * ccw->cmd_code |= 0x8;
732 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
736 if (recid
< blk_per_trk
)
738 if (recid
< 2 * blk_per_trk
)
744 * Returns the record size for the special blocks of the cdl format.
745 * Only returns something useful if dasd_eckd_cdl_special is true
749 dasd_eckd_cdl_reclen(int recid
)
752 return sizes_trk0
[recid
];
755 /* create unique id from private structure. */
756 static void create_uid(struct dasd_eckd_private
*private)
759 struct dasd_uid
*uid
;
762 memset(uid
, 0, sizeof(struct dasd_uid
));
763 memcpy(uid
->vendor
, private->ned
->HDA_manufacturer
,
764 sizeof(uid
->vendor
) - 1);
765 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
766 memcpy(uid
->serial
, private->ned
->HDA_location
,
767 sizeof(uid
->serial
) - 1);
768 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
769 uid
->ssid
= private->gneq
->subsystemID
;
770 uid
->real_unit_addr
= private->ned
->unit_addr
;
772 uid
->type
= private->sneq
->sua_flags
;
773 if (uid
->type
== UA_BASE_PAV_ALIAS
)
774 uid
->base_unit_addr
= private->sneq
->base_unit_addr
;
776 uid
->type
= UA_BASE_DEVICE
;
778 if (private->vdsneq
) {
779 for (count
= 0; count
< 16; count
++) {
780 sprintf(uid
->vduit
+2*count
, "%02x",
781 private->vdsneq
->uit
[count
]);
787 * Generate device unique id that specifies the physical device.
789 static int dasd_eckd_generate_uid(struct dasd_device
*device
)
791 struct dasd_eckd_private
*private;
794 private = (struct dasd_eckd_private
*) device
->private;
797 if (!private->ned
|| !private->gneq
)
799 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
801 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
805 static int dasd_eckd_get_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
807 struct dasd_eckd_private
*private;
810 if (device
->private) {
811 private = (struct dasd_eckd_private
*)device
->private;
812 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
814 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
821 * compare device UID with data of a given dasd_eckd_private structure
824 static int dasd_eckd_compare_path_uid(struct dasd_device
*device
,
825 struct dasd_eckd_private
*private)
827 struct dasd_uid device_uid
;
830 dasd_eckd_get_uid(device
, &device_uid
);
832 return memcmp(&device_uid
, &private->uid
, sizeof(struct dasd_uid
));
835 static void dasd_eckd_fill_rcd_cqr(struct dasd_device
*device
,
836 struct dasd_ccw_req
*cqr
,
842 * buffer has to start with EBCDIC "V1.0" to show
843 * support for virtual device SNEQ
845 rcd_buffer
[0] = 0xE5;
846 rcd_buffer
[1] = 0xF1;
847 rcd_buffer
[2] = 0x4B;
848 rcd_buffer
[3] = 0xF0;
851 ccw
->cmd_code
= DASD_ECKD_CCW_RCD
;
853 ccw
->cda
= (__u32
)(addr_t
)rcd_buffer
;
854 ccw
->count
= DASD_ECKD_RCD_DATA_SIZE
;
855 cqr
->magic
= DASD_ECKD_MAGIC
;
857 cqr
->startdev
= device
;
858 cqr
->memdev
= device
;
860 cqr
->expires
= 10*HZ
;
863 cqr
->buildclk
= get_clock();
864 cqr
->status
= DASD_CQR_FILLED
;
865 set_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
);
869 * Wakeup helper for read_conf
870 * if the cqr is not done and needs some error recovery
871 * the buffer has to be re-initialized with the EBCDIC "V1.0"
872 * to show support for virtual device SNEQ
874 static void read_conf_cb(struct dasd_ccw_req
*cqr
, void *data
)
879 if (cqr
->status
!= DASD_CQR_DONE
) {
881 rcd_buffer
= (__u8
*)((addr_t
) ccw
->cda
);
882 memset(rcd_buffer
, 0, sizeof(*rcd_buffer
));
884 rcd_buffer
[0] = 0xE5;
885 rcd_buffer
[1] = 0xF1;
886 rcd_buffer
[2] = 0x4B;
887 rcd_buffer
[3] = 0xF0;
889 dasd_wakeup_cb(cqr
, data
);
892 static int dasd_eckd_read_conf_immediately(struct dasd_device
*device
,
893 struct dasd_ccw_req
*cqr
,
900 * sanity check: scan for RCD command in extended SenseID data
901 * some devices do not support RCD
903 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
904 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
)
907 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buffer
, lpm
);
908 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
909 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
911 cqr
->callback
= read_conf_cb
;
912 rc
= dasd_sleep_on_immediatly(cqr
);
916 static int dasd_eckd_read_conf_lpm(struct dasd_device
*device
,
918 int *rcd_buffer_size
, __u8 lpm
)
921 char *rcd_buf
= NULL
;
923 struct dasd_ccw_req
*cqr
;
926 * sanity check: scan for RCD command in extended SenseID data
927 * some devices do not support RCD
929 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
930 if (!ciw
|| ciw
->cmd
!= DASD_ECKD_CCW_RCD
) {
934 rcd_buf
= kzalloc(DASD_ECKD_RCD_DATA_SIZE
, GFP_KERNEL
| GFP_DMA
);
939 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* RCD */,
940 0, /* use rcd_buf as data ara */
943 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
944 "Could not allocate RCD request");
948 dasd_eckd_fill_rcd_cqr(device
, cqr
, rcd_buf
, lpm
);
949 cqr
->callback
= read_conf_cb
;
950 ret
= dasd_sleep_on(cqr
);
952 * on success we update the user input parms
954 dasd_sfree_request(cqr
, cqr
->memdev
);
958 *rcd_buffer_size
= DASD_ECKD_RCD_DATA_SIZE
;
959 *rcd_buffer
= rcd_buf
;
964 *rcd_buffer_size
= 0;
968 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private
*private)
971 struct dasd_sneq
*sneq
;
975 private->sneq
= NULL
;
976 private->vdsneq
= NULL
;
977 private->gneq
= NULL
;
978 count
= private->conf_len
/ sizeof(struct dasd_sneq
);
979 sneq
= (struct dasd_sneq
*)private->conf_data
;
980 for (i
= 0; i
< count
; ++i
) {
981 if (sneq
->flags
.identifier
== 1 && sneq
->format
== 1)
982 private->sneq
= sneq
;
983 else if (sneq
->flags
.identifier
== 1 && sneq
->format
== 4)
984 private->vdsneq
= (struct vd_sneq
*)sneq
;
985 else if (sneq
->flags
.identifier
== 2)
986 private->gneq
= (struct dasd_gneq
*)sneq
;
987 else if (sneq
->flags
.identifier
== 3 && sneq
->res1
== 1)
988 private->ned
= (struct dasd_ned
*)sneq
;
991 if (!private->ned
|| !private->gneq
) {
993 private->sneq
= NULL
;
994 private->vdsneq
= NULL
;
995 private->gneq
= NULL
;
1002 static unsigned char dasd_eckd_path_access(void *conf_data
, int conf_len
)
1004 struct dasd_gneq
*gneq
;
1005 int i
, count
, found
;
1007 count
= conf_len
/ sizeof(*gneq
);
1008 gneq
= (struct dasd_gneq
*)conf_data
;
1010 for (i
= 0; i
< count
; ++i
) {
1011 if (gneq
->flags
.identifier
== 2) {
1018 return ((char *)gneq
)[18] & 0x07;
1023 static int dasd_eckd_read_conf(struct dasd_device
*device
)
1026 int conf_len
, conf_data_saved
;
1029 struct dasd_eckd_private
*private, path_private
;
1030 struct dasd_path
*path_data
;
1031 struct dasd_uid
*uid
;
1032 char print_path_uid
[60], print_device_uid
[60];
1034 private = (struct dasd_eckd_private
*) device
->private;
1035 path_data
= &device
->path_data
;
1036 opm
= ccw_device_get_path_mask(device
->cdev
);
1037 conf_data_saved
= 0;
1038 /* get configuration data per operational path */
1039 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1042 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
1044 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
1045 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1046 "Read configuration data returned "
1050 if (conf_data
== NULL
) {
1051 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1052 "No configuration data "
1054 /* no further analysis possible */
1055 path_data
->opm
|= lpm
;
1056 continue; /* no error */
1058 /* save first valid configuration data */
1059 if (!conf_data_saved
) {
1060 kfree(private->conf_data
);
1061 private->conf_data
= conf_data
;
1062 private->conf_len
= conf_len
;
1063 if (dasd_eckd_identify_conf_parts(private)) {
1064 private->conf_data
= NULL
;
1065 private->conf_len
= 0;
1070 * build device UID that other path data
1071 * can be compared to it
1073 dasd_eckd_generate_uid(device
);
1076 path_private
.conf_data
= conf_data
;
1077 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1078 if (dasd_eckd_identify_conf_parts(
1080 path_private
.conf_data
= NULL
;
1081 path_private
.conf_len
= 0;
1086 if (dasd_eckd_compare_path_uid(
1087 device
, &path_private
)) {
1088 uid
= &path_private
.uid
;
1089 if (strlen(uid
->vduit
) > 0)
1090 snprintf(print_path_uid
,
1091 sizeof(print_path_uid
),
1092 "%s.%s.%04x.%02x.%s",
1093 uid
->vendor
, uid
->serial
,
1094 uid
->ssid
, uid
->real_unit_addr
,
1097 snprintf(print_path_uid
,
1098 sizeof(print_path_uid
),
1100 uid
->vendor
, uid
->serial
,
1102 uid
->real_unit_addr
);
1103 uid
= &private->uid
;
1104 if (strlen(uid
->vduit
) > 0)
1105 snprintf(print_device_uid
,
1106 sizeof(print_device_uid
),
1107 "%s.%s.%04x.%02x.%s",
1108 uid
->vendor
, uid
->serial
,
1109 uid
->ssid
, uid
->real_unit_addr
,
1112 snprintf(print_device_uid
,
1113 sizeof(print_device_uid
),
1115 uid
->vendor
, uid
->serial
,
1117 uid
->real_unit_addr
);
1118 dev_err(&device
->cdev
->dev
,
1119 "Not all channel paths lead to "
1120 "the same device, path %02X leads to "
1121 "device %s instead of %s\n", lpm
,
1122 print_path_uid
, print_device_uid
);
1126 path_private
.conf_data
= NULL
;
1127 path_private
.conf_len
= 0;
1129 switch (dasd_eckd_path_access(conf_data
, conf_len
)) {
1131 path_data
->npm
|= lpm
;
1134 path_data
->ppm
|= lpm
;
1137 path_data
->opm
|= lpm
;
1139 if (conf_data
!= private->conf_data
)
1146 static int verify_fcx_max_data(struct dasd_device
*device
, __u8 lpm
)
1148 struct dasd_eckd_private
*private;
1152 private = (struct dasd_eckd_private
*) device
->private;
1153 if (private->fcx_max_data
) {
1154 mdc
= ccw_device_get_mdc(device
->cdev
, lpm
);
1156 dev_warn(&device
->cdev
->dev
,
1157 "Detecting the maximum data size for zHPF "
1158 "requests failed (rc=%d) for a new path %x\n",
1162 fcx_max_data
= mdc
* FCX_MAX_DATA_FACTOR
;
1163 if (fcx_max_data
< private->fcx_max_data
) {
1164 dev_warn(&device
->cdev
->dev
,
1165 "The maximum data size for zHPF requests %u "
1166 "on a new path %x is below the active maximum "
1167 "%u\n", fcx_max_data
, lpm
,
1168 private->fcx_max_data
);
1175 static int rebuild_device_uid(struct dasd_device
*device
,
1176 struct path_verification_work_data
*data
)
1178 struct dasd_eckd_private
*private;
1179 struct dasd_path
*path_data
;
1184 private = (struct dasd_eckd_private
*) device
->private;
1185 path_data
= &device
->path_data
;
1186 opm
= device
->path_data
.opm
;
1188 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1191 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1192 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1193 data
->cqr
.cpaddr
= &data
->ccw
;
1194 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1199 if (rc
== -EOPNOTSUPP
) /* -EOPNOTSUPP is ok */
1201 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1202 "Read configuration data "
1203 "returned error %d", rc
);
1206 memcpy(private->conf_data
, data
->rcd_buffer
,
1207 DASD_ECKD_RCD_DATA_SIZE
);
1208 if (dasd_eckd_identify_conf_parts(private)) {
1210 } else /* first valid path is enough */
1215 rc
= dasd_eckd_generate_uid(device
);
1220 static void do_path_verification_work(struct work_struct
*work
)
1222 struct path_verification_work_data
*data
;
1223 struct dasd_device
*device
;
1224 struct dasd_eckd_private path_private
;
1225 struct dasd_uid
*uid
;
1226 __u8 path_rcd_buf
[DASD_ECKD_RCD_DATA_SIZE
];
1227 __u8 lpm
, opm
, npm
, ppm
, epm
;
1228 unsigned long flags
;
1232 data
= container_of(work
, struct path_verification_work_data
, worker
);
1233 device
= data
->device
;
1235 /* delay path verification until device was resumed */
1236 if (test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
1237 schedule_work(work
);
1245 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
1246 if (!(lpm
& data
->tbvpm
))
1248 memset(&data
->rcd_buffer
, 0, sizeof(data
->rcd_buffer
));
1249 memset(&data
->cqr
, 0, sizeof(data
->cqr
));
1250 data
->cqr
.cpaddr
= &data
->ccw
;
1251 rc
= dasd_eckd_read_conf_immediately(device
, &data
->cqr
,
1255 switch (dasd_eckd_path_access(data
->rcd_buffer
,
1256 DASD_ECKD_RCD_DATA_SIZE
)
1266 } else if (rc
== -EOPNOTSUPP
) {
1267 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1268 "path verification: No configuration "
1271 } else if (rc
== -EAGAIN
) {
1272 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1273 "path verification: device is stopped,"
1274 " try again later");
1277 dev_warn(&device
->cdev
->dev
,
1278 "Reading device feature codes failed "
1279 "(rc=%d) for new path %x\n", rc
, lpm
);
1282 if (verify_fcx_max_data(device
, lpm
)) {
1290 * save conf_data for comparison after
1291 * rebuild_device_uid may have changed
1294 memcpy(&path_rcd_buf
, data
->rcd_buffer
,
1295 DASD_ECKD_RCD_DATA_SIZE
);
1296 path_private
.conf_data
= (void *) &path_rcd_buf
;
1297 path_private
.conf_len
= DASD_ECKD_RCD_DATA_SIZE
;
1298 if (dasd_eckd_identify_conf_parts(&path_private
)) {
1299 path_private
.conf_data
= NULL
;
1300 path_private
.conf_len
= 0;
1305 * compare path UID with device UID only if at least
1306 * one valid path is left
1307 * in other case the device UID may have changed and
1308 * the first working path UID will be used as device UID
1310 if (device
->path_data
.opm
&&
1311 dasd_eckd_compare_path_uid(device
, &path_private
)) {
1313 * the comparison was not successful
1314 * rebuild the device UID with at least one
1315 * known path in case a z/VM hyperswap command
1316 * has changed the device
1318 * after this compare again
1320 * if either the rebuild or the recompare fails
1321 * the path can not be used
1323 if (rebuild_device_uid(device
, data
) ||
1324 dasd_eckd_compare_path_uid(
1325 device
, &path_private
)) {
1326 uid
= &path_private
.uid
;
1327 if (strlen(uid
->vduit
) > 0)
1328 snprintf(print_uid
, sizeof(print_uid
),
1329 "%s.%s.%04x.%02x.%s",
1330 uid
->vendor
, uid
->serial
,
1331 uid
->ssid
, uid
->real_unit_addr
,
1334 snprintf(print_uid
, sizeof(print_uid
),
1336 uid
->vendor
, uid
->serial
,
1338 uid
->real_unit_addr
);
1339 dev_err(&device
->cdev
->dev
,
1340 "The newly added channel path %02X "
1341 "will not be used because it leads "
1342 "to a different device %s\n",
1352 * There is a small chance that a path is lost again between
1353 * above path verification and the following modification of
1354 * the device opm mask. We could avoid that race here by using
1355 * yet another path mask, but we rather deal with this unlikely
1356 * situation in dasd_start_IO.
1358 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1359 if (!device
->path_data
.opm
&& opm
) {
1360 device
->path_data
.opm
= opm
;
1361 dasd_generic_path_operational(device
);
1363 device
->path_data
.opm
|= opm
;
1364 device
->path_data
.npm
|= npm
;
1365 device
->path_data
.ppm
|= ppm
;
1366 device
->path_data
.tbvpm
|= epm
;
1367 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1370 dasd_put_device(device
);
1372 mutex_unlock(&dasd_path_verification_mutex
);
1377 static int dasd_eckd_verify_path(struct dasd_device
*device
, __u8 lpm
)
1379 struct path_verification_work_data
*data
;
1381 data
= kmalloc(sizeof(*data
), GFP_ATOMIC
| GFP_DMA
);
1383 if (mutex_trylock(&dasd_path_verification_mutex
)) {
1384 data
= path_verification_worker
;
1389 memset(data
, 0, sizeof(*data
));
1392 INIT_WORK(&data
->worker
, do_path_verification_work
);
1393 dasd_get_device(device
);
1394 data
->device
= device
;
1396 schedule_work(&data
->worker
);
1400 static int dasd_eckd_read_features(struct dasd_device
*device
)
1402 struct dasd_psf_prssd_data
*prssdp
;
1403 struct dasd_rssd_features
*features
;
1404 struct dasd_ccw_req
*cqr
;
1407 struct dasd_eckd_private
*private;
1409 private = (struct dasd_eckd_private
*) device
->private;
1410 memset(&private->features
, 0, sizeof(struct dasd_rssd_features
));
1411 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
1412 (sizeof(struct dasd_psf_prssd_data
) +
1413 sizeof(struct dasd_rssd_features
)),
1416 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s", "Could not "
1417 "allocate initialization request");
1418 return PTR_ERR(cqr
);
1420 cqr
->startdev
= device
;
1421 cqr
->memdev
= device
;
1424 cqr
->expires
= 10 * HZ
;
1426 /* Prepare for Read Subsystem Data */
1427 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1428 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1429 prssdp
->order
= PSF_ORDER_PRSSD
;
1430 prssdp
->suborder
= 0x41; /* Read Feature Codes */
1431 /* all other bytes of prssdp must be zero */
1434 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1435 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1436 ccw
->flags
|= CCW_FLAG_CC
;
1437 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1439 /* Read Subsystem Data - feature codes */
1440 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1441 memset(features
, 0, sizeof(struct dasd_rssd_features
));
1444 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1445 ccw
->count
= sizeof(struct dasd_rssd_features
);
1446 ccw
->cda
= (__u32
)(addr_t
) features
;
1448 cqr
->buildclk
= get_clock();
1449 cqr
->status
= DASD_CQR_FILLED
;
1450 rc
= dasd_sleep_on(cqr
);
1452 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1453 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
1454 memcpy(&private->features
, features
,
1455 sizeof(struct dasd_rssd_features
));
1457 dev_warn(&device
->cdev
->dev
, "Reading device feature codes"
1458 " failed with rc=%d\n", rc
);
1459 dasd_sfree_request(cqr
, cqr
->memdev
);
1465 * Build CP for Perform Subsystem Function - SSC.
1467 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
,
1470 struct dasd_ccw_req
*cqr
;
1471 struct dasd_psf_ssc_data
*psf_ssc_data
;
1474 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ ,
1475 sizeof(struct dasd_psf_ssc_data
),
1479 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1480 "Could not allocate PSF-SSC request");
1483 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
1484 psf_ssc_data
->order
= PSF_ORDER_SSC
;
1485 psf_ssc_data
->suborder
= 0xc0;
1487 psf_ssc_data
->suborder
|= 0x08;
1488 psf_ssc_data
->reserved
[0] = 0x88;
1491 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1492 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
1495 cqr
->startdev
= device
;
1496 cqr
->memdev
= device
;
1499 cqr
->expires
= 10*HZ
;
1500 cqr
->buildclk
= get_clock();
1501 cqr
->status
= DASD_CQR_FILLED
;
1506 * Perform Subsystem Function.
1507 * It is necessary to trigger CIO for channel revalidation since this
1508 * call might change behaviour of DASD devices.
1511 dasd_eckd_psf_ssc(struct dasd_device
*device
, int enable_pav
)
1513 struct dasd_ccw_req
*cqr
;
1516 cqr
= dasd_eckd_build_psf_ssc(device
, enable_pav
);
1518 return PTR_ERR(cqr
);
1520 rc
= dasd_sleep_on(cqr
);
1522 /* trigger CIO to reprobe devices */
1523 css_schedule_reprobe();
1524 dasd_sfree_request(cqr
, cqr
->memdev
);
1529 * Valide storage server of current device.
1531 static void dasd_eckd_validate_server(struct dasd_device
*device
)
1534 struct dasd_eckd_private
*private;
1537 private = (struct dasd_eckd_private
*) device
->private;
1538 if (private->uid
.type
== UA_BASE_PAV_ALIAS
||
1539 private->uid
.type
== UA_HYPER_PAV_ALIAS
)
1541 if (dasd_nopav
|| MACHINE_IS_VM
)
1545 rc
= dasd_eckd_psf_ssc(device
, enable_pav
);
1547 /* may be requested feature is not available on server,
1548 * therefore just report error and go ahead */
1549 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "PSF-SSC for SSID %04x "
1550 "returned rc=%d", private->uid
.ssid
, rc
);
1554 * worker to do a validate server in case of a lost pathgroup
1556 static void dasd_eckd_do_validate_server(struct work_struct
*work
)
1558 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
1560 dasd_eckd_validate_server(device
);
1561 dasd_put_device(device
);
1564 static void dasd_eckd_kick_validate_server(struct dasd_device
*device
)
1566 dasd_get_device(device
);
1567 /* exit if device not online or in offline processing */
1568 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1569 device
->state
< DASD_STATE_ONLINE
) {
1570 dasd_put_device(device
);
1573 /* queue call to do_validate_server to the kernel event daemon. */
1574 schedule_work(&device
->kick_validate
);
1577 static u32
get_fcx_max_data(struct dasd_device
*device
)
1579 #if defined(CONFIG_64BIT)
1581 int fcx_in_css
, fcx_in_gneq
, fcx_in_features
;
1582 struct dasd_eckd_private
*private;
1586 /* is transport mode supported? */
1587 private = (struct dasd_eckd_private
*) device
->private;
1588 fcx_in_css
= css_general_characteristics
.fcx
;
1589 fcx_in_gneq
= private->gneq
->reserved2
[7] & 0x04;
1590 fcx_in_features
= private->features
.feature
[40] & 0x80;
1591 tpm
= fcx_in_css
&& fcx_in_gneq
&& fcx_in_features
;
1596 mdc
= ccw_device_get_mdc(device
->cdev
, 0);
1598 dev_warn(&device
->cdev
->dev
, "Detecting the maximum supported"
1599 " data size for zHPF requests failed\n");
1602 return mdc
* FCX_MAX_DATA_FACTOR
;
1609 * Check device characteristics.
1610 * If the device is accessible using ECKD discipline, the device is enabled.
1613 dasd_eckd_check_characteristics(struct dasd_device
*device
)
1615 struct dasd_eckd_private
*private;
1616 struct dasd_block
*block
;
1617 struct dasd_uid temp_uid
;
1620 unsigned long value
;
1622 /* setup work queue for validate server*/
1623 INIT_WORK(&device
->kick_validate
, dasd_eckd_do_validate_server
);
1625 if (!ccw_device_is_pathgroup(device
->cdev
)) {
1626 dev_warn(&device
->cdev
->dev
,
1627 "A channel path group could not be established\n");
1630 if (!ccw_device_is_multipath(device
->cdev
)) {
1631 dev_info(&device
->cdev
->dev
,
1632 "The DASD is not operating in multipath mode\n");
1634 private = (struct dasd_eckd_private
*) device
->private;
1636 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
1638 dev_warn(&device
->cdev
->dev
,
1639 "Allocating memory for private DASD data "
1643 device
->private = (void *) private;
1645 memset(private, 0, sizeof(*private));
1647 /* Invalidate status of initial analysis. */
1648 private->init_cqr_status
= -1;
1649 /* Set default cache operations. */
1650 private->attrib
.operation
= DASD_NORMAL_CACHE
;
1651 private->attrib
.nr_cyl
= 0;
1653 /* Read Configuration Data */
1654 rc
= dasd_eckd_read_conf(device
);
1658 /* set default timeout */
1659 device
->default_expires
= DASD_EXPIRES
;
1660 if (private->gneq
) {
1662 for (i
= 0; i
< private->gneq
->timeout
.value
; i
++)
1664 value
= value
* private->gneq
->timeout
.number
;
1665 /* do not accept useless values */
1666 if (value
!= 0 && value
<= DASD_EXPIRES_MAX
)
1667 device
->default_expires
= value
;
1670 dasd_eckd_get_uid(device
, &temp_uid
);
1671 if (temp_uid
.type
== UA_BASE_DEVICE
) {
1672 block
= dasd_alloc_block();
1673 if (IS_ERR(block
)) {
1674 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
, "%s",
1675 "could not allocate dasd "
1677 rc
= PTR_ERR(block
);
1680 device
->block
= block
;
1681 block
->base
= device
;
1684 /* register lcu with alias handling, enable PAV */
1685 rc
= dasd_alias_make_device_known_to_lcu(device
);
1689 dasd_eckd_validate_server(device
);
1691 /* device may report different configuration data after LCU setup */
1692 rc
= dasd_eckd_read_conf(device
);
1696 /* Read Feature Codes */
1697 dasd_eckd_read_features(device
);
1699 /* Read Device Characteristics */
1700 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
1701 &private->rdc_data
, 64);
1703 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
1704 "Read device characteristic failed, rc=%d", rc
);
1708 if ((device
->features
& DASD_FEATURE_USERAW
) &&
1709 !(private->rdc_data
.facilities
.RT_in_LR
)) {
1710 dev_err(&device
->cdev
->dev
, "The storage server does not "
1711 "support raw-track access\n");
1716 /* find the valid cylinder size */
1717 if (private->rdc_data
.no_cyl
== LV_COMPAT_CYL
&&
1718 private->rdc_data
.long_no_cyl
)
1719 private->real_cyl
= private->rdc_data
.long_no_cyl
;
1721 private->real_cyl
= private->rdc_data
.no_cyl
;
1723 private->fcx_max_data
= get_fcx_max_data(device
);
1725 readonly
= dasd_device_is_ro(device
);
1727 set_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
1729 dev_info(&device
->cdev
->dev
, "New DASD %04X/%02X (CU %04X/%02X) "
1730 "with %d cylinders, %d heads, %d sectors%s\n",
1731 private->rdc_data
.dev_type
,
1732 private->rdc_data
.dev_model
,
1733 private->rdc_data
.cu_type
,
1734 private->rdc_data
.cu_model
.model
,
1736 private->rdc_data
.trk_per_cyl
,
1737 private->rdc_data
.sec_per_trk
,
1738 readonly
? ", read-only device" : "");
1742 dasd_alias_disconnect_device_from_lcu(device
);
1744 dasd_free_block(device
->block
);
1745 device
->block
= NULL
;
1747 kfree(private->conf_data
);
1748 kfree(device
->private);
1749 device
->private = NULL
;
1753 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
1755 struct dasd_eckd_private
*private;
1757 private = (struct dasd_eckd_private
*) device
->private;
1758 dasd_alias_disconnect_device_from_lcu(device
);
1759 private->ned
= NULL
;
1760 private->sneq
= NULL
;
1761 private->vdsneq
= NULL
;
1762 private->gneq
= NULL
;
1763 private->conf_len
= 0;
1764 kfree(private->conf_data
);
1765 private->conf_data
= NULL
;
1768 static struct dasd_ccw_req
*
1769 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
1771 struct dasd_eckd_private
*private;
1772 struct eckd_count
*count_data
;
1773 struct LO_eckd_data
*LO_data
;
1774 struct dasd_ccw_req
*cqr
;
1776 int cplength
, datasize
;
1779 private = (struct dasd_eckd_private
*) device
->private;
1782 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
1783 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
1787 /* Define extent for the first 3 tracks. */
1788 define_extent(ccw
++, cqr
->data
, 0, 2,
1789 DASD_ECKD_CCW_READ_COUNT
, device
);
1790 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
1791 /* Locate record for the first 4 records on track 0. */
1792 ccw
[-1].flags
|= CCW_FLAG_CC
;
1793 locate_record(ccw
++, LO_data
++, 0, 0, 4,
1794 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1796 count_data
= private->count_area
;
1797 for (i
= 0; i
< 4; i
++) {
1798 ccw
[-1].flags
|= CCW_FLAG_CC
;
1799 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1802 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1807 /* Locate record for the first record on track 2. */
1808 ccw
[-1].flags
|= CCW_FLAG_CC
;
1809 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1810 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1811 /* Read count ccw. */
1812 ccw
[-1].flags
|= CCW_FLAG_CC
;
1813 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1816 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1819 cqr
->startdev
= device
;
1820 cqr
->memdev
= device
;
1822 cqr
->buildclk
= get_clock();
1823 cqr
->status
= DASD_CQR_FILLED
;
1827 /* differentiate between 'no record found' and any other error */
1828 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req
*init_cqr
)
1831 if (init_cqr
->status
== DASD_CQR_DONE
)
1833 else if (init_cqr
->status
== DASD_CQR_NEED_ERP
||
1834 init_cqr
->status
== DASD_CQR_FAILED
) {
1835 sense
= dasd_get_sense(&init_cqr
->irb
);
1836 if (sense
&& (sense
[1] & SNS1_NO_REC_FOUND
))
1837 return INIT_CQR_UNFORMATTED
;
1839 return INIT_CQR_ERROR
;
1841 return INIT_CQR_ERROR
;
1845 * This is the callback function for the init_analysis cqr. It saves
1846 * the status of the initial analysis ccw before it frees it and kicks
1847 * the device to continue the startup sequence. This will call
1848 * dasd_eckd_do_analysis again (if the devices has not been marked
1849 * for deletion in the meantime).
1851 static void dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
,
1854 struct dasd_eckd_private
*private;
1855 struct dasd_device
*device
;
1857 device
= init_cqr
->startdev
;
1858 private = (struct dasd_eckd_private
*) device
->private;
1859 private->init_cqr_status
= dasd_eckd_analysis_evaluation(init_cqr
);
1860 dasd_sfree_request(init_cqr
, device
);
1861 dasd_kick_device(device
);
1864 static int dasd_eckd_start_analysis(struct dasd_block
*block
)
1866 struct dasd_ccw_req
*init_cqr
;
1868 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1869 if (IS_ERR(init_cqr
))
1870 return PTR_ERR(init_cqr
);
1871 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1872 init_cqr
->callback_data
= NULL
;
1873 init_cqr
->expires
= 5*HZ
;
1874 /* first try without ERP, so we can later handle unformatted
1875 * devices as special case
1877 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &init_cqr
->flags
);
1878 init_cqr
->retries
= 0;
1879 dasd_add_request_head(init_cqr
);
1883 static int dasd_eckd_end_analysis(struct dasd_block
*block
)
1885 struct dasd_device
*device
;
1886 struct dasd_eckd_private
*private;
1887 struct eckd_count
*count_area
;
1888 unsigned int sb
, blk_per_trk
;
1890 struct dasd_ccw_req
*init_cqr
;
1892 device
= block
->base
;
1893 private = (struct dasd_eckd_private
*) device
->private;
1894 status
= private->init_cqr_status
;
1895 private->init_cqr_status
= -1;
1896 if (status
== INIT_CQR_ERROR
) {
1897 /* try again, this time with full ERP */
1898 init_cqr
= dasd_eckd_analysis_ccw(device
);
1899 dasd_sleep_on(init_cqr
);
1900 status
= dasd_eckd_analysis_evaluation(init_cqr
);
1901 dasd_sfree_request(init_cqr
, device
);
1904 if (device
->features
& DASD_FEATURE_USERAW
) {
1905 block
->bp_block
= DASD_RAW_BLOCKSIZE
;
1906 blk_per_trk
= DASD_RAW_BLOCK_PER_TRACK
;
1907 block
->s2b_shift
= 3;
1911 if (status
== INIT_CQR_UNFORMATTED
) {
1912 dev_warn(&device
->cdev
->dev
, "The DASD is not formatted\n");
1913 return -EMEDIUMTYPE
;
1914 } else if (status
== INIT_CQR_ERROR
) {
1915 dev_err(&device
->cdev
->dev
,
1916 "Detecting the DASD disk layout failed because "
1917 "of an I/O error\n");
1921 private->uses_cdl
= 1;
1922 /* Check Track 0 for Compatible Disk Layout */
1924 for (i
= 0; i
< 3; i
++) {
1925 if (private->count_area
[i
].kl
!= 4 ||
1926 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4) {
1927 private->uses_cdl
= 0;
1932 count_area
= &private->count_area
[4];
1934 if (private->uses_cdl
== 0) {
1935 for (i
= 0; i
< 5; i
++) {
1936 if ((private->count_area
[i
].kl
!= 0) ||
1937 (private->count_area
[i
].dl
!=
1938 private->count_area
[0].dl
))
1942 count_area
= &private->count_area
[0];
1944 if (private->count_area
[3].record
== 1)
1945 dev_warn(&device
->cdev
->dev
,
1946 "Track 0 has no records following the VTOC\n");
1949 if (count_area
!= NULL
&& count_area
->kl
== 0) {
1950 /* we found notthing violating our disk layout */
1951 if (dasd_check_blocksize(count_area
->dl
) == 0)
1952 block
->bp_block
= count_area
->dl
;
1954 if (block
->bp_block
== 0) {
1955 dev_warn(&device
->cdev
->dev
,
1956 "The disk layout of the DASD is not supported\n");
1957 return -EMEDIUMTYPE
;
1959 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
1960 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
1963 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
1966 block
->blocks
= (private->real_cyl
*
1967 private->rdc_data
.trk_per_cyl
*
1970 dev_info(&device
->cdev
->dev
,
1971 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1972 "%s\n", (block
->bp_block
>> 10),
1973 ((private->real_cyl
*
1974 private->rdc_data
.trk_per_cyl
*
1975 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
1976 ((blk_per_trk
* block
->bp_block
) >> 10),
1978 "compatible disk layout" : "linux disk layout");
1983 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
1985 struct dasd_eckd_private
*private;
1987 private = (struct dasd_eckd_private
*) block
->base
->private;
1988 if (private->init_cqr_status
< 0)
1989 return dasd_eckd_start_analysis(block
);
1991 return dasd_eckd_end_analysis(block
);
1994 static int dasd_eckd_ready_to_online(struct dasd_device
*device
)
1996 return dasd_alias_add_device(device
);
1999 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
2001 cancel_work_sync(&device
->reload_device
);
2002 cancel_work_sync(&device
->kick_validate
);
2003 return dasd_alias_remove_device(device
);
2007 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
2009 struct dasd_eckd_private
*private;
2011 private = (struct dasd_eckd_private
*) block
->base
->private;
2012 if (dasd_check_blocksize(block
->bp_block
) == 0) {
2013 geo
->sectors
= recs_per_track(&private->rdc_data
,
2014 0, block
->bp_block
);
2016 geo
->cylinders
= private->rdc_data
.no_cyl
;
2017 geo
->heads
= private->rdc_data
.trk_per_cyl
;
2021 static struct dasd_ccw_req
*
2022 dasd_eckd_format_device(struct dasd_device
* device
,
2023 struct format_data_t
* fdata
)
2025 struct dasd_eckd_private
*private;
2026 struct dasd_ccw_req
*fcp
;
2027 struct eckd_count
*ect
;
2031 struct ch_t address
;
2032 int cplength
, datasize
;
2037 private = (struct dasd_eckd_private
*) device
->private;
2038 rpt
= recs_per_track(&private->rdc_data
, 0, fdata
->blksize
);
2040 fdata
->start_unit
/ private->rdc_data
.trk_per_cyl
,
2041 fdata
->start_unit
% private->rdc_data
.trk_per_cyl
);
2043 /* Sanity checks. */
2044 if (fdata
->start_unit
>=
2045 (private->real_cyl
* private->rdc_data
.trk_per_cyl
)) {
2046 dev_warn(&device
->cdev
->dev
, "Start track number %d used in "
2047 "formatting is too big\n", fdata
->start_unit
);
2048 return ERR_PTR(-EINVAL
);
2050 if (fdata
->start_unit
> fdata
->stop_unit
) {
2051 dev_warn(&device
->cdev
->dev
, "Start track %d used in "
2052 "formatting exceeds end track\n", fdata
->start_unit
);
2053 return ERR_PTR(-EINVAL
);
2055 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
2056 dev_warn(&device
->cdev
->dev
,
2057 "The DASD cannot be formatted with block size %d\n",
2059 return ERR_PTR(-EINVAL
);
2063 * fdata->intensity is a bit string that tells us what to do:
2064 * Bit 0: write record zero
2065 * Bit 1: write home address, currently not supported
2066 * Bit 2: invalidate tracks
2067 * Bit 3: use OS/390 compatible disk layout (cdl)
2068 * Bit 4: do not allow storage subsystem to modify record zero
2069 * Only some bit combinations do make sense.
2071 if (fdata
->intensity
& 0x10) {
2073 intensity
= fdata
->intensity
& ~0x10;
2076 intensity
= fdata
->intensity
;
2078 switch (intensity
) {
2079 case 0x00: /* Normal format */
2080 case 0x08: /* Normal format, use cdl. */
2082 datasize
= sizeof(struct DE_eckd_data
) +
2083 sizeof(struct LO_eckd_data
) +
2084 rpt
* sizeof(struct eckd_count
);
2086 case 0x01: /* Write record zero and format track. */
2087 case 0x09: /* Write record zero and format track, use cdl. */
2089 datasize
= sizeof(struct DE_eckd_data
) +
2090 sizeof(struct LO_eckd_data
) +
2091 sizeof(struct eckd_count
) +
2092 rpt
* sizeof(struct eckd_count
);
2094 case 0x04: /* Invalidate track. */
2095 case 0x0c: /* Invalidate track, use cdl. */
2097 datasize
= sizeof(struct DE_eckd_data
) +
2098 sizeof(struct LO_eckd_data
) +
2099 sizeof(struct eckd_count
);
2102 dev_warn(&device
->cdev
->dev
, "An I/O control call used "
2103 "incorrect flags 0x%x\n", fdata
->intensity
);
2104 return ERR_PTR(-EINVAL
);
2106 /* Allocate the format ccw request. */
2107 fcp
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
, device
);
2114 switch (intensity
& ~0x08) {
2115 case 0x00: /* Normal format. */
2116 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2117 fdata
->start_unit
, fdata
->start_unit
,
2118 DASD_ECKD_CCW_WRITE_CKD
, device
);
2119 /* grant subsystem permission to format R0 */
2121 ((struct DE_eckd_data
*)data
)->ga_extended
|= 0x04;
2122 data
+= sizeof(struct DE_eckd_data
);
2123 ccw
[-1].flags
|= CCW_FLAG_CC
;
2124 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2125 fdata
->start_unit
, 0, rpt
,
2126 DASD_ECKD_CCW_WRITE_CKD
, device
,
2128 data
+= sizeof(struct LO_eckd_data
);
2130 case 0x01: /* Write record zero + format track. */
2131 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2132 fdata
->start_unit
, fdata
->start_unit
,
2133 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
2135 data
+= sizeof(struct DE_eckd_data
);
2136 ccw
[-1].flags
|= CCW_FLAG_CC
;
2137 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2138 fdata
->start_unit
, 0, rpt
+ 1,
2139 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, device
,
2140 device
->block
->bp_block
);
2141 data
+= sizeof(struct LO_eckd_data
);
2143 case 0x04: /* Invalidate track. */
2144 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
2145 fdata
->start_unit
, fdata
->start_unit
,
2146 DASD_ECKD_CCW_WRITE_CKD
, device
);
2147 data
+= sizeof(struct DE_eckd_data
);
2148 ccw
[-1].flags
|= CCW_FLAG_CC
;
2149 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
2150 fdata
->start_unit
, 0, 1,
2151 DASD_ECKD_CCW_WRITE_CKD
, device
, 8);
2152 data
+= sizeof(struct LO_eckd_data
);
2155 if (intensity
& 0x01) { /* write record zero */
2156 ect
= (struct eckd_count
*) data
;
2157 data
+= sizeof(struct eckd_count
);
2158 ect
->cyl
= address
.cyl
;
2159 ect
->head
= address
.head
;
2163 ccw
[-1].flags
|= CCW_FLAG_CC
;
2164 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
2165 ccw
->flags
= CCW_FLAG_SLI
;
2167 ccw
->cda
= (__u32
)(addr_t
) ect
;
2170 if ((intensity
& ~0x08) & 0x04) { /* erase track */
2171 ect
= (struct eckd_count
*) data
;
2172 data
+= sizeof(struct eckd_count
);
2173 ect
->cyl
= address
.cyl
;
2174 ect
->head
= address
.head
;
2178 ccw
[-1].flags
|= CCW_FLAG_CC
;
2179 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2180 ccw
->flags
= CCW_FLAG_SLI
;
2182 ccw
->cda
= (__u32
)(addr_t
) ect
;
2183 } else { /* write remaining records */
2184 for (i
= 0; i
< rpt
; i
++) {
2185 ect
= (struct eckd_count
*) data
;
2186 data
+= sizeof(struct eckd_count
);
2187 ect
->cyl
= address
.cyl
;
2188 ect
->head
= address
.head
;
2189 ect
->record
= i
+ 1;
2191 ect
->dl
= fdata
->blksize
;
2192 /* Check for special tracks 0-1 when formatting CDL */
2193 if ((intensity
& 0x08) &&
2194 fdata
->start_unit
== 0) {
2197 ect
->dl
= sizes_trk0
[i
] - 4;
2200 if ((intensity
& 0x08) &&
2201 fdata
->start_unit
== 1) {
2203 ect
->dl
= LABEL_SIZE
- 44;
2205 ccw
[-1].flags
|= CCW_FLAG_CC
;
2206 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
2207 ccw
->flags
= CCW_FLAG_SLI
;
2209 ccw
->cda
= (__u32
)(addr_t
) ect
;
2213 fcp
->startdev
= device
;
2214 fcp
->memdev
= device
;
2216 fcp
->buildclk
= get_clock();
2217 fcp
->status
= DASD_CQR_FILLED
;
2221 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
2223 cqr
->status
= DASD_CQR_FILLED
;
2224 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
2225 dasd_eckd_reset_ccw_to_base_io(cqr
);
2226 cqr
->startdev
= cqr
->block
->base
;
2227 cqr
->lpm
= cqr
->block
->base
->path_data
.opm
;
2231 static dasd_erp_fn_t
2232 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
2234 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
2235 struct ccw_device
*cdev
= device
->cdev
;
2237 switch (cdev
->id
.cu_type
) {
2242 return dasd_3990_erp_action
;
2246 return dasd_default_erp_action
;
2250 static dasd_erp_fn_t
2251 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
2253 return dasd_default_erp_postaction
;
2256 static void dasd_eckd_check_for_device_change(struct dasd_device
*device
,
2257 struct dasd_ccw_req
*cqr
,
2262 struct dasd_eckd_private
*private;
2264 private = (struct dasd_eckd_private
*) device
->private;
2265 /* first of all check for state change pending interrupt */
2266 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
2267 if ((scsw_dstat(&irb
->scsw
) & mask
) == mask
) {
2269 * for alias only, not in offline processing
2270 * and only if not suspended
2272 if (!device
->block
&& private->lcu
&&
2273 device
->state
== DASD_STATE_ONLINE
&&
2274 !test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
2275 !test_bit(DASD_FLAG_SUSPENDED
, &device
->flags
)) {
2277 * the state change could be caused by an alias
2278 * reassignment remove device from alias handling
2279 * to prevent new requests from being scheduled on
2280 * the wrong alias device
2282 dasd_alias_remove_device(device
);
2284 /* schedule worker to reload device */
2285 dasd_reload_device(device
);
2287 dasd_generic_handle_state_change(device
);
2291 sense
= dasd_get_sense(irb
);
2295 /* summary unit check */
2296 if ((sense
[27] & DASD_SENSE_BIT_0
) && (sense
[7] == 0x0D) &&
2297 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
)) {
2298 dasd_alias_handle_summary_unit_check(device
, irb
);
2302 /* service information message SIM */
2303 if (!cqr
&& !(sense
[27] & DASD_SENSE_BIT_0
) &&
2304 ((sense
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
)) {
2305 dasd_3990_erp_handle_sim(device
, sense
);
2309 /* loss of device reservation is handled via base devices only
2310 * as alias devices may be used with several bases
2312 if (device
->block
&& (sense
[27] & DASD_SENSE_BIT_0
) &&
2313 (sense
[7] == 0x3F) &&
2314 (scsw_dstat(&irb
->scsw
) & DEV_STAT_UNIT_CHECK
) &&
2315 test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
)) {
2316 if (device
->features
& DASD_FEATURE_FAILONSLCK
)
2317 set_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
2318 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
2319 dev_err(&device
->cdev
->dev
,
2320 "The device reservation was lost\n");
2324 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_single(
2325 struct dasd_device
*startdev
,
2326 struct dasd_block
*block
,
2327 struct request
*req
,
2332 unsigned int first_offs
,
2333 unsigned int last_offs
,
2334 unsigned int blk_per_trk
,
2335 unsigned int blksize
)
2337 struct dasd_eckd_private
*private;
2338 unsigned long *idaws
;
2339 struct LO_eckd_data
*LO_data
;
2340 struct dasd_ccw_req
*cqr
;
2342 struct req_iterator iter
;
2346 int count
, cidaw
, cplength
, datasize
;
2348 unsigned char cmd
, rcmd
;
2350 struct dasd_device
*basedev
;
2352 basedev
= block
->base
;
2353 private = (struct dasd_eckd_private
*) basedev
->private;
2354 if (rq_data_dir(req
) == READ
)
2355 cmd
= DASD_ECKD_CCW_READ_MT
;
2356 else if (rq_data_dir(req
) == WRITE
)
2357 cmd
= DASD_ECKD_CCW_WRITE_MT
;
2359 return ERR_PTR(-EINVAL
);
2361 /* Check struct bio and count the number of blocks for the request. */
2364 rq_for_each_segment(bv
, req
, iter
) {
2365 if (bv
->bv_len
& (blksize
- 1))
2366 /* Eckd can only do full blocks. */
2367 return ERR_PTR(-EINVAL
);
2368 count
+= bv
->bv_len
>> (block
->s2b_shift
+ 9);
2369 #if defined(CONFIG_64BIT)
2370 if (idal_is_needed (page_address(bv
->bv_page
), bv
->bv_len
))
2371 cidaw
+= bv
->bv_len
>> (block
->s2b_shift
+ 9);
2375 if (count
!= last_rec
- first_rec
+ 1)
2376 return ERR_PTR(-EINVAL
);
2378 /* use the prefix command if available */
2379 use_prefix
= private->features
.feature
[8] & 0x01;
2381 /* 1x prefix + number of blocks */
2382 cplength
= 2 + count
;
2383 /* 1x prefix + cidaws*sizeof(long) */
2384 datasize
= sizeof(struct PFX_eckd_data
) +
2385 sizeof(struct LO_eckd_data
) +
2386 cidaw
* sizeof(unsigned long);
2388 /* 1x define extent + 1x locate record + number of blocks */
2389 cplength
= 2 + count
;
2390 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2391 datasize
= sizeof(struct DE_eckd_data
) +
2392 sizeof(struct LO_eckd_data
) +
2393 cidaw
* sizeof(unsigned long);
2395 /* Find out the number of additional locate record ccws for cdl. */
2396 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
2397 if (last_rec
>= 2*blk_per_trk
)
2398 count
= 2*blk_per_trk
- first_rec
;
2400 datasize
+= count
*sizeof(struct LO_eckd_data
);
2402 /* Allocate the ccw request. */
2403 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2408 /* First ccw is define extent or prefix. */
2410 if (prefix(ccw
++, cqr
->data
, first_trk
,
2411 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
2412 /* Clock not in sync and XRC is enabled.
2415 dasd_sfree_request(cqr
, startdev
);
2416 return ERR_PTR(-EAGAIN
);
2418 idaws
= (unsigned long *) (cqr
->data
+
2419 sizeof(struct PFX_eckd_data
));
2421 if (define_extent(ccw
++, cqr
->data
, first_trk
,
2422 last_trk
, cmd
, basedev
) == -EAGAIN
) {
2423 /* Clock not in sync and XRC is enabled.
2426 dasd_sfree_request(cqr
, startdev
);
2427 return ERR_PTR(-EAGAIN
);
2429 idaws
= (unsigned long *) (cqr
->data
+
2430 sizeof(struct DE_eckd_data
));
2432 /* Build locate_record+read/write/ccws. */
2433 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
2435 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
2436 /* Only standard blocks so there is just one locate record. */
2437 ccw
[-1].flags
|= CCW_FLAG_CC
;
2438 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
2439 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
2441 rq_for_each_segment(bv
, req
, iter
) {
2442 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
2443 if (dasd_page_cache
) {
2444 char *copy
= kmem_cache_alloc(dasd_page_cache
,
2445 GFP_DMA
| __GFP_NOWARN
);
2446 if (copy
&& rq_data_dir(req
) == WRITE
)
2447 memcpy(copy
+ bv
->bv_offset
, dst
, bv
->bv_len
);
2449 dst
= copy
+ bv
->bv_offset
;
2451 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
2452 sector_t trkid
= recid
;
2453 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
2456 /* Locate record for cdl special block ? */
2457 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
2458 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
2460 count
= dasd_eckd_cdl_reclen(recid
);
2461 if (count
< blksize
&&
2462 rq_data_dir(req
) == READ
)
2463 memset(dst
+ count
, 0xe5,
2466 ccw
[-1].flags
|= CCW_FLAG_CC
;
2467 locate_record(ccw
++, LO_data
++,
2469 1, rcmd
, basedev
, count
);
2471 /* Locate record for standard blocks ? */
2472 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
2473 ccw
[-1].flags
|= CCW_FLAG_CC
;
2474 locate_record(ccw
++, LO_data
++,
2476 last_rec
- recid
+ 1,
2477 cmd
, basedev
, count
);
2479 /* Read/write ccw. */
2480 ccw
[-1].flags
|= CCW_FLAG_CC
;
2481 ccw
->cmd_code
= rcmd
;
2483 if (idal_is_needed(dst
, blksize
)) {
2484 ccw
->cda
= (__u32
)(addr_t
) idaws
;
2485 ccw
->flags
= CCW_FLAG_IDA
;
2486 idaws
= idal_create_words(idaws
, dst
, blksize
);
2488 ccw
->cda
= (__u32
)(addr_t
) dst
;
2496 if (blk_noretry_request(req
) ||
2497 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2498 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2499 cqr
->startdev
= startdev
;
2500 cqr
->memdev
= startdev
;
2502 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2503 cqr
->lpm
= startdev
->path_data
.ppm
;
2505 cqr
->buildclk
= get_clock();
2506 cqr
->status
= DASD_CQR_FILLED
;
2510 static struct dasd_ccw_req
*dasd_eckd_build_cp_cmd_track(
2511 struct dasd_device
*startdev
,
2512 struct dasd_block
*block
,
2513 struct request
*req
,
2518 unsigned int first_offs
,
2519 unsigned int last_offs
,
2520 unsigned int blk_per_trk
,
2521 unsigned int blksize
)
2523 unsigned long *idaws
;
2524 struct dasd_ccw_req
*cqr
;
2526 struct req_iterator iter
;
2528 char *dst
, *idaw_dst
;
2529 unsigned int cidaw
, cplength
, datasize
;
2533 struct dasd_device
*basedev
;
2534 unsigned int trkcount
, count
, count_to_trk_end
;
2535 unsigned int idaw_len
, seg_len
, part_len
, len_to_track_end
;
2536 unsigned char new_track
, end_idaw
;
2538 unsigned int recoffs
;
2540 basedev
= block
->base
;
2541 if (rq_data_dir(req
) == READ
)
2542 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
2543 else if (rq_data_dir(req
) == WRITE
)
2544 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
2546 return ERR_PTR(-EINVAL
);
2548 /* Track based I/O needs IDAWs for each page, and not just for
2549 * 64 bit addresses. We need additional idals for pages
2550 * that get filled from two tracks, so we use the number
2551 * of records as upper limit.
2553 cidaw
= last_rec
- first_rec
+ 1;
2554 trkcount
= last_trk
- first_trk
+ 1;
2556 /* 1x prefix + one read/write ccw per track */
2557 cplength
= 1 + trkcount
;
2559 /* on 31-bit we need space for two 32 bit addresses per page
2560 * on 64-bit one 64 bit address
2562 datasize
= sizeof(struct PFX_eckd_data
) +
2563 cidaw
* sizeof(unsigned long long);
2565 /* Allocate the ccw request. */
2566 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
, datasize
,
2571 /* transfer length factor: how many bytes to read from the last track */
2572 if (first_trk
== last_trk
)
2573 tlf
= last_offs
- first_offs
+ 1;
2575 tlf
= last_offs
+ 1;
2578 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
,
2579 last_trk
, cmd
, basedev
, startdev
,
2580 1 /* format */, first_offs
+ 1,
2583 /* Clock not in sync and XRC is enabled.
2586 dasd_sfree_request(cqr
, startdev
);
2587 return ERR_PTR(-EAGAIN
);
2591 * The translation of request into ccw programs must meet the
2592 * following conditions:
2593 * - all idaws but the first and the last must address full pages
2594 * (or 2K blocks on 31-bit)
2595 * - the scope of a ccw and it's idal ends with the track boundaries
2597 idaws
= (unsigned long *) (cqr
->data
+ sizeof(struct PFX_eckd_data
));
2601 len_to_track_end
= 0;
2604 rq_for_each_segment(bv
, req
, iter
) {
2605 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
2606 seg_len
= bv
->bv_len
;
2610 recoffs
= sector_div(trkid
, blk_per_trk
);
2611 count_to_trk_end
= blk_per_trk
- recoffs
;
2612 count
= min((last_rec
- recid
+ 1),
2613 (sector_t
)count_to_trk_end
);
2614 len_to_track_end
= count
* blksize
;
2615 ccw
[-1].flags
|= CCW_FLAG_CC
;
2616 ccw
->cmd_code
= cmd
;
2617 ccw
->count
= len_to_track_end
;
2618 ccw
->cda
= (__u32
)(addr_t
)idaws
;
2619 ccw
->flags
= CCW_FLAG_IDA
;
2623 /* first idaw for a ccw may start anywhere */
2627 /* If we start a new idaw, we must make sure that it
2628 * starts on an IDA_BLOCK_SIZE boundary.
2629 * If we continue an idaw, we must make sure that the
2630 * current segment begins where the so far accumulated
2634 if (__pa(dst
) & (IDA_BLOCK_SIZE
-1)) {
2635 dasd_sfree_request(cqr
, startdev
);
2636 return ERR_PTR(-ERANGE
);
2640 if ((idaw_dst
+ idaw_len
) != dst
) {
2641 dasd_sfree_request(cqr
, startdev
);
2642 return ERR_PTR(-ERANGE
);
2644 part_len
= min(seg_len
, len_to_track_end
);
2645 seg_len
-= part_len
;
2647 idaw_len
+= part_len
;
2648 len_to_track_end
-= part_len
;
2649 /* collected memory area ends on an IDA_BLOCK border,
2651 * idal_create_words will handle cases where idaw_len
2652 * is larger then IDA_BLOCK_SIZE
2654 if (!(__pa(idaw_dst
+ idaw_len
) & (IDA_BLOCK_SIZE
-1)))
2656 /* We also need to end the idaw at track end */
2657 if (!len_to_track_end
) {
2662 idaws
= idal_create_words(idaws
, idaw_dst
,
2671 if (blk_noretry_request(req
) ||
2672 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2673 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2674 cqr
->startdev
= startdev
;
2675 cqr
->memdev
= startdev
;
2677 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2678 cqr
->lpm
= startdev
->path_data
.ppm
;
2680 cqr
->buildclk
= get_clock();
2681 cqr
->status
= DASD_CQR_FILLED
;
2685 static int prepare_itcw(struct itcw
*itcw
,
2686 unsigned int trk
, unsigned int totrk
, int cmd
,
2687 struct dasd_device
*basedev
,
2688 struct dasd_device
*startdev
,
2689 unsigned int rec_on_trk
, int count
,
2690 unsigned int blksize
,
2691 unsigned int total_data_size
,
2693 unsigned int blk_per_trk
)
2695 struct PFX_eckd_data pfxdata
;
2696 struct dasd_eckd_private
*basepriv
, *startpriv
;
2697 struct DE_eckd_data
*dedata
;
2698 struct LRE_eckd_data
*lredata
;
2702 u16 heads
, beghead
, endhead
;
2710 /* setup prefix data */
2711 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
2712 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
2713 dedata
= &pfxdata
.define_extent
;
2714 lredata
= &pfxdata
.locate_record
;
2716 memset(&pfxdata
, 0, sizeof(pfxdata
));
2717 pfxdata
.format
= 1; /* PFX with LRE */
2718 pfxdata
.base_address
= basepriv
->ned
->unit_addr
;
2719 pfxdata
.base_lss
= basepriv
->ned
->ID
;
2720 pfxdata
.validity
.define_extent
= 1;
2722 /* private uid is kept up to date, conf_data may be outdated */
2723 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
2724 pfxdata
.validity
.verify_base
= 1;
2725 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
2726 pfxdata
.validity
.hyper_pav
= 1;
2730 case DASD_ECKD_CCW_READ_TRACK_DATA
:
2731 dedata
->mask
.perm
= 0x1;
2732 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
2733 dedata
->blk_size
= blksize
;
2734 dedata
->ga_extended
|= 0x42;
2735 lredata
->operation
.orientation
= 0x0;
2736 lredata
->operation
.operation
= 0x0C;
2737 lredata
->auxiliary
.check_bytes
= 0x01;
2738 pfx_cmd
= DASD_ECKD_CCW_PFX_READ
;
2740 case DASD_ECKD_CCW_WRITE_TRACK_DATA
:
2741 dedata
->mask
.perm
= 0x02;
2742 dedata
->attributes
.operation
= basepriv
->attrib
.operation
;
2743 dedata
->blk_size
= blksize
;
2744 rc
= check_XRC_on_prefix(&pfxdata
, basedev
);
2745 dedata
->ga_extended
|= 0x42;
2746 lredata
->operation
.orientation
= 0x0;
2747 lredata
->operation
.operation
= 0x3F;
2748 lredata
->extended_operation
= 0x23;
2749 lredata
->auxiliary
.check_bytes
= 0x2;
2750 pfx_cmd
= DASD_ECKD_CCW_PFX
;
2753 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2754 "prepare itcw, unknown opcode 0x%x", cmd
);
2761 dedata
->attributes
.mode
= 0x3; /* ECKD */
2763 heads
= basepriv
->rdc_data
.trk_per_cyl
;
2764 begcyl
= trk
/ heads
;
2765 beghead
= trk
% heads
;
2766 endcyl
= totrk
/ heads
;
2767 endhead
= totrk
% heads
;
2769 /* check for sequential prestage - enhance cylinder range */
2770 if (dedata
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
2771 dedata
->attributes
.operation
== DASD_SEQ_ACCESS
) {
2773 if (endcyl
+ basepriv
->attrib
.nr_cyl
< basepriv
->real_cyl
)
2774 endcyl
+= basepriv
->attrib
.nr_cyl
;
2776 endcyl
= (basepriv
->real_cyl
- 1);
2779 set_ch_t(&dedata
->beg_ext
, begcyl
, beghead
);
2780 set_ch_t(&dedata
->end_ext
, endcyl
, endhead
);
2782 dedata
->ep_format
= 0x20; /* records per track is valid */
2783 dedata
->ep_rec_per_track
= blk_per_trk
;
2786 switch (basepriv
->rdc_data
.dev_type
) {
2788 dn
= ceil_quot(blksize
+ 6, 232);
2789 d
= 9 + ceil_quot(blksize
+ 6 * (dn
+ 1), 34);
2790 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
2793 d
= 7 + ceil_quot(blksize
+ 12, 32);
2794 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
2799 lredata
->auxiliary
.length_valid
= 1;
2800 lredata
->auxiliary
.length_scope
= 1;
2801 lredata
->auxiliary
.imbedded_ccw_valid
= 1;
2802 lredata
->length
= tlf
;
2803 lredata
->imbedded_ccw
= cmd
;
2804 lredata
->count
= count
;
2805 lredata
->sector
= sector
;
2806 set_ch_t(&lredata
->seek_addr
, begcyl
, beghead
);
2807 lredata
->search_arg
.cyl
= lredata
->seek_addr
.cyl
;
2808 lredata
->search_arg
.head
= lredata
->seek_addr
.head
;
2809 lredata
->search_arg
.record
= rec_on_trk
;
2811 dcw
= itcw_add_dcw(itcw
, pfx_cmd
, 0,
2812 &pfxdata
, sizeof(pfxdata
), total_data_size
);
2813 return IS_ERR(dcw
) ? PTR_ERR(dcw
) : 0;
2816 static struct dasd_ccw_req
*dasd_eckd_build_cp_tpm_track(
2817 struct dasd_device
*startdev
,
2818 struct dasd_block
*block
,
2819 struct request
*req
,
2824 unsigned int first_offs
,
2825 unsigned int last_offs
,
2826 unsigned int blk_per_trk
,
2827 unsigned int blksize
)
2829 struct dasd_ccw_req
*cqr
;
2830 struct req_iterator iter
;
2833 unsigned int trkcount
, ctidaw
;
2835 struct dasd_device
*basedev
;
2838 struct tidaw
*last_tidaw
= NULL
;
2842 unsigned int seg_len
, part_len
, len_to_track_end
;
2843 unsigned char new_track
;
2844 sector_t recid
, trkid
;
2846 unsigned int count
, count_to_trk_end
;
2849 basedev
= block
->base
;
2850 if (rq_data_dir(req
) == READ
) {
2851 cmd
= DASD_ECKD_CCW_READ_TRACK_DATA
;
2852 itcw_op
= ITCW_OP_READ
;
2853 } else if (rq_data_dir(req
) == WRITE
) {
2854 cmd
= DASD_ECKD_CCW_WRITE_TRACK_DATA
;
2855 itcw_op
= ITCW_OP_WRITE
;
2857 return ERR_PTR(-EINVAL
);
2859 /* trackbased I/O needs address all memory via TIDAWs,
2860 * not just for 64 bit addresses. This allows us to map
2861 * each segment directly to one tidaw.
2862 * In the case of write requests, additional tidaws may
2863 * be needed when a segment crosses a track boundary.
2865 trkcount
= last_trk
- first_trk
+ 1;
2867 rq_for_each_segment(bv
, req
, iter
) {
2870 if (rq_data_dir(req
) == WRITE
)
2871 ctidaw
+= (last_trk
- first_trk
);
2873 /* Allocate the ccw request. */
2874 itcw_size
= itcw_calc_size(0, ctidaw
, 0);
2875 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 0, itcw_size
, startdev
);
2879 /* transfer length factor: how many bytes to read from the last track */
2880 if (first_trk
== last_trk
)
2881 tlf
= last_offs
- first_offs
+ 1;
2883 tlf
= last_offs
+ 1;
2886 itcw
= itcw_init(cqr
->data
, itcw_size
, itcw_op
, 0, ctidaw
, 0);
2891 cqr
->cpaddr
= itcw_get_tcw(itcw
);
2892 if (prepare_itcw(itcw
, first_trk
, last_trk
,
2893 cmd
, basedev
, startdev
,
2896 (last_rec
- first_rec
+ 1) * blksize
,
2897 tlf
, blk_per_trk
) == -EAGAIN
) {
2898 /* Clock not in sync and XRC is enabled.
2904 len_to_track_end
= 0;
2906 * A tidaw can address 4k of memory, but must not cross page boundaries
2907 * We can let the block layer handle this by setting
2908 * blk_queue_segment_boundary to page boundaries and
2909 * blk_max_segment_size to page size when setting up the request queue.
2910 * For write requests, a TIDAW must not cross track boundaries, because
2911 * we have to set the CBC flag on the last tidaw for each track.
2913 if (rq_data_dir(req
) == WRITE
) {
2916 rq_for_each_segment(bv
, req
, iter
) {
2917 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
2918 seg_len
= bv
->bv_len
;
2922 offs
= sector_div(trkid
, blk_per_trk
);
2923 count_to_trk_end
= blk_per_trk
- offs
;
2924 count
= min((last_rec
- recid
+ 1),
2925 (sector_t
)count_to_trk_end
);
2926 len_to_track_end
= count
* blksize
;
2930 part_len
= min(seg_len
, len_to_track_end
);
2931 seg_len
-= part_len
;
2932 len_to_track_end
-= part_len
;
2933 /* We need to end the tidaw at track end */
2934 if (!len_to_track_end
) {
2936 tidaw_flags
= TIDAW_FLAGS_INSERT_CBC
;
2939 last_tidaw
= itcw_add_tidaw(itcw
, tidaw_flags
,
2941 if (IS_ERR(last_tidaw
)) {
2949 rq_for_each_segment(bv
, req
, iter
) {
2950 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
2951 last_tidaw
= itcw_add_tidaw(itcw
, 0x00,
2953 if (IS_ERR(last_tidaw
)) {
2959 last_tidaw
->flags
|= TIDAW_FLAGS_LAST
;
2960 last_tidaw
->flags
&= ~TIDAW_FLAGS_INSERT_CBC
;
2961 itcw_finalize(itcw
);
2963 if (blk_noretry_request(req
) ||
2964 block
->base
->features
& DASD_FEATURE_FAILFAST
)
2965 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
2967 cqr
->startdev
= startdev
;
2968 cqr
->memdev
= startdev
;
2970 cqr
->expires
= startdev
->default_expires
* HZ
; /* default 5 minutes */
2971 cqr
->lpm
= startdev
->path_data
.ppm
;
2973 cqr
->buildclk
= get_clock();
2974 cqr
->status
= DASD_CQR_FILLED
;
2977 dasd_sfree_request(cqr
, startdev
);
2978 return ERR_PTR(ret
);
2981 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
2982 struct dasd_block
*block
,
2983 struct request
*req
)
2988 struct dasd_eckd_private
*private;
2989 struct dasd_device
*basedev
;
2990 sector_t first_rec
, last_rec
;
2991 sector_t first_trk
, last_trk
;
2992 unsigned int first_offs
, last_offs
;
2993 unsigned int blk_per_trk
, blksize
;
2995 unsigned int data_size
;
2996 struct dasd_ccw_req
*cqr
;
2998 basedev
= block
->base
;
2999 private = (struct dasd_eckd_private
*) basedev
->private;
3001 /* Calculate number of blocks/records per track. */
3002 blksize
= block
->bp_block
;
3003 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3004 if (blk_per_trk
== 0)
3005 return ERR_PTR(-EINVAL
);
3006 /* Calculate record id of first and last block. */
3007 first_rec
= first_trk
= blk_rq_pos(req
) >> block
->s2b_shift
;
3008 first_offs
= sector_div(first_trk
, blk_per_trk
);
3009 last_rec
= last_trk
=
3010 (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) >> block
->s2b_shift
;
3011 last_offs
= sector_div(last_trk
, blk_per_trk
);
3012 cdlspecial
= (private->uses_cdl
&& first_rec
< 2*blk_per_trk
);
3014 fcx_multitrack
= private->features
.feature
[40] & 0x20;
3015 data_size
= blk_rq_bytes(req
);
3016 /* tpm write request add CBC data on each track boundary */
3017 if (rq_data_dir(req
) == WRITE
)
3018 data_size
+= (last_trk
- first_trk
) * 4;
3020 /* is read track data and write track data in command mode supported? */
3021 cmdrtd
= private->features
.feature
[9] & 0x20;
3022 cmdwtd
= private->features
.feature
[12] & 0x40;
3023 use_prefix
= private->features
.feature
[8] & 0x01;
3026 if (cdlspecial
|| dasd_page_cache
) {
3027 /* do nothing, just fall through to the cmd mode single case */
3028 } else if ((data_size
<= private->fcx_max_data
)
3029 && (fcx_multitrack
|| (first_trk
== last_trk
))) {
3030 cqr
= dasd_eckd_build_cp_tpm_track(startdev
, block
, req
,
3031 first_rec
, last_rec
,
3032 first_trk
, last_trk
,
3033 first_offs
, last_offs
,
3034 blk_per_trk
, blksize
);
3035 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3036 (PTR_ERR(cqr
) != -ENOMEM
))
3038 } else if (use_prefix
&&
3039 (((rq_data_dir(req
) == READ
) && cmdrtd
) ||
3040 ((rq_data_dir(req
) == WRITE
) && cmdwtd
))) {
3041 cqr
= dasd_eckd_build_cp_cmd_track(startdev
, block
, req
,
3042 first_rec
, last_rec
,
3043 first_trk
, last_trk
,
3044 first_offs
, last_offs
,
3045 blk_per_trk
, blksize
);
3046 if (IS_ERR(cqr
) && (PTR_ERR(cqr
) != -EAGAIN
) &&
3047 (PTR_ERR(cqr
) != -ENOMEM
))
3051 cqr
= dasd_eckd_build_cp_cmd_single(startdev
, block
, req
,
3052 first_rec
, last_rec
,
3053 first_trk
, last_trk
,
3054 first_offs
, last_offs
,
3055 blk_per_trk
, blksize
);
3059 static struct dasd_ccw_req
*dasd_raw_build_cp(struct dasd_device
*startdev
,
3060 struct dasd_block
*block
,
3061 struct request
*req
)
3063 unsigned long *idaws
;
3064 struct dasd_device
*basedev
;
3065 struct dasd_ccw_req
*cqr
;
3067 struct req_iterator iter
;
3071 unsigned int trkcount
;
3072 unsigned int seg_len
, len_to_track_end
;
3073 unsigned int first_offs
;
3074 unsigned int cidaw
, cplength
, datasize
;
3075 sector_t first_trk
, last_trk
;
3076 unsigned int pfx_datasize
;
3079 * raw track access needs to be mutiple of 64k and on 64k boundary
3081 if ((blk_rq_pos(req
) % DASD_RAW_SECTORS_PER_TRACK
) != 0) {
3082 cqr
= ERR_PTR(-EINVAL
);
3085 if (((blk_rq_pos(req
) + blk_rq_sectors(req
)) %
3086 DASD_RAW_SECTORS_PER_TRACK
) != 0) {
3087 cqr
= ERR_PTR(-EINVAL
);
3091 first_trk
= blk_rq_pos(req
) / DASD_RAW_SECTORS_PER_TRACK
;
3092 last_trk
= (blk_rq_pos(req
) + blk_rq_sectors(req
) - 1) /
3093 DASD_RAW_SECTORS_PER_TRACK
;
3094 trkcount
= last_trk
- first_trk
+ 1;
3096 basedev
= block
->base
;
3098 if (rq_data_dir(req
) == READ
)
3099 cmd
= DASD_ECKD_CCW_READ_TRACK
;
3100 else if (rq_data_dir(req
) == WRITE
)
3101 cmd
= DASD_ECKD_CCW_WRITE_FULL_TRACK
;
3103 cqr
= ERR_PTR(-EINVAL
);
3108 * Raw track based I/O needs IDAWs for each page,
3109 * and not just for 64 bit addresses.
3111 cidaw
= trkcount
* DASD_RAW_BLOCK_PER_TRACK
;
3113 /* 1x prefix + one read/write ccw per track */
3114 cplength
= 1 + trkcount
;
3117 * struct PFX_eckd_data has up to 2 byte as extended parameter
3118 * this is needed for write full track and has to be mentioned
3120 * add 8 instead of 2 to keep 8 byte boundary
3122 pfx_datasize
= sizeof(struct PFX_eckd_data
) + 8;
3124 datasize
= pfx_datasize
+ cidaw
* sizeof(unsigned long long);
3126 /* Allocate the ccw request. */
3127 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, cplength
,
3128 datasize
, startdev
);
3133 if (prefix_LRE(ccw
++, cqr
->data
, first_trk
, last_trk
, cmd
,
3134 basedev
, startdev
, 1 /* format */, first_offs
+ 1,
3135 trkcount
, 0, 0) == -EAGAIN
) {
3136 /* Clock not in sync and XRC is enabled.
3139 dasd_sfree_request(cqr
, startdev
);
3140 cqr
= ERR_PTR(-EAGAIN
);
3144 idaws
= (unsigned long *)(cqr
->data
+ pfx_datasize
);
3146 len_to_track_end
= 0;
3148 rq_for_each_segment(bv
, req
, iter
) {
3149 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
3150 seg_len
= bv
->bv_len
;
3151 if (!len_to_track_end
) {
3152 ccw
[-1].flags
|= CCW_FLAG_CC
;
3153 ccw
->cmd_code
= cmd
;
3154 /* maximum 3390 track size */
3156 /* 64k map to one track */
3157 len_to_track_end
= 65536;
3158 ccw
->cda
= (__u32
)(addr_t
)idaws
;
3159 ccw
->flags
|= CCW_FLAG_IDA
;
3160 ccw
->flags
|= CCW_FLAG_SLI
;
3163 len_to_track_end
-= seg_len
;
3164 idaws
= idal_create_words(idaws
, dst
, seg_len
);
3167 if (blk_noretry_request(req
) ||
3168 block
->base
->features
& DASD_FEATURE_FAILFAST
)
3169 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3170 cqr
->startdev
= startdev
;
3171 cqr
->memdev
= startdev
;
3173 cqr
->expires
= startdev
->default_expires
* HZ
;
3174 cqr
->lpm
= startdev
->path_data
.ppm
;
3176 cqr
->buildclk
= get_clock();
3177 cqr
->status
= DASD_CQR_FILLED
;
3179 if (IS_ERR(cqr
) && PTR_ERR(cqr
) != -EAGAIN
)
3187 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
3189 struct dasd_eckd_private
*private;
3191 struct req_iterator iter
;
3194 unsigned int blksize
, blk_per_trk
, off
;
3198 if (!dasd_page_cache
)
3200 private = (struct dasd_eckd_private
*) cqr
->block
->base
->private;
3201 blksize
= cqr
->block
->bp_block
;
3202 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
3203 recid
= blk_rq_pos(req
) >> cqr
->block
->s2b_shift
;
3205 /* Skip over define extent & locate record. */
3207 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
3209 rq_for_each_segment(bv
, req
, iter
) {
3210 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
3211 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
3212 /* Skip locate record. */
3213 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
3216 if (ccw
->flags
& CCW_FLAG_IDA
)
3217 cda
= *((char **)((addr_t
) ccw
->cda
));
3219 cda
= (char *)((addr_t
) ccw
->cda
);
3221 if (rq_data_dir(req
) == READ
)
3222 memcpy(dst
, cda
, bv
->bv_len
);
3223 kmem_cache_free(dasd_page_cache
,
3224 (void *)((addr_t
)cda
& PAGE_MASK
));
3233 status
= cqr
->status
== DASD_CQR_DONE
;
3234 dasd_sfree_request(cqr
, cqr
->memdev
);
3239 * Modify ccw/tcw in cqr so it can be started on a base device.
3241 * Note that this is not enough to restart the cqr!
3242 * Either reset cqr->startdev as well (summary unit check handling)
3243 * or restart via separate cqr (as in ERP handling).
3245 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
3248 struct PFX_eckd_data
*pfxdata
;
3253 if (cqr
->cpmode
== 1) {
3255 tccb
= tcw_get_tccb(tcw
);
3256 dcw
= (struct dcw
*)&tccb
->tca
[0];
3257 pfxdata
= (struct PFX_eckd_data
*)&dcw
->cd
[0];
3258 pfxdata
->validity
.verify_base
= 0;
3259 pfxdata
->validity
.hyper_pav
= 0;
3262 pfxdata
= cqr
->data
;
3263 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
3264 pfxdata
->validity
.verify_base
= 0;
3265 pfxdata
->validity
.hyper_pav
= 0;
3270 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3272 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
3273 struct dasd_block
*block
,
3274 struct request
*req
)
3276 struct dasd_eckd_private
*private;
3277 struct dasd_device
*startdev
;
3278 unsigned long flags
;
3279 struct dasd_ccw_req
*cqr
;
3281 startdev
= dasd_alias_get_start_dev(base
);
3284 private = (struct dasd_eckd_private
*) startdev
->private;
3285 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
3286 return ERR_PTR(-EBUSY
);
3288 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
3290 if ((base
->features
& DASD_FEATURE_USERAW
))
3291 cqr
= dasd_raw_build_cp(startdev
, block
, req
);
3293 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
3296 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
3300 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
3301 struct request
*req
)
3303 struct dasd_eckd_private
*private;
3304 unsigned long flags
;
3306 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3307 private = (struct dasd_eckd_private
*) cqr
->memdev
->private;
3309 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
3310 return dasd_eckd_free_cp(cqr
, req
);
3314 dasd_eckd_fill_info(struct dasd_device
* device
,
3315 struct dasd_information2_t
* info
)
3317 struct dasd_eckd_private
*private;
3319 private = (struct dasd_eckd_private
*) device
->private;
3320 info
->label_block
= 2;
3321 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
3322 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
3323 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
3324 memcpy(info
->characteristics
, &private->rdc_data
,
3325 sizeof(struct dasd_eckd_characteristics
));
3326 info
->confdata_size
= min((unsigned long)private->conf_len
,
3327 sizeof(info
->configuration_data
));
3328 memcpy(info
->configuration_data
, private->conf_data
,
3329 info
->confdata_size
);
3334 * SECTION: ioctl functions for eckd devices.
3338 * Release device ioctl.
3339 * Buils a channel programm to releases a prior reserved
3340 * (see dasd_eckd_reserve) device.
3343 dasd_eckd_release(struct dasd_device
*device
)
3345 struct dasd_ccw_req
*cqr
;
3350 if (!capable(CAP_SYS_ADMIN
))
3354 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3356 mutex_lock(&dasd_reserve_mutex
);
3358 cqr
= &dasd_reserve_req
->cqr
;
3359 memset(cqr
, 0, sizeof(*cqr
));
3360 memset(&dasd_reserve_req
->ccw
, 0,
3361 sizeof(dasd_reserve_req
->ccw
));
3362 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3363 cqr
->data
= &dasd_reserve_req
->data
;
3364 cqr
->magic
= DASD_ECKD_MAGIC
;
3367 ccw
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
3368 ccw
->flags
|= CCW_FLAG_SLI
;
3370 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3371 cqr
->startdev
= device
;
3372 cqr
->memdev
= device
;
3373 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3374 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3375 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3376 cqr
->expires
= 2 * HZ
;
3377 cqr
->buildclk
= get_clock();
3378 cqr
->status
= DASD_CQR_FILLED
;
3380 rc
= dasd_sleep_on_immediatly(cqr
);
3382 clear_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3385 mutex_unlock(&dasd_reserve_mutex
);
3387 dasd_sfree_request(cqr
, cqr
->memdev
);
3392 * Reserve device ioctl.
3393 * Options are set to 'synchronous wait for interrupt' and
3394 * 'timeout the request'. This leads to a terminate IO if
3395 * the interrupt is outstanding for a certain time.
3398 dasd_eckd_reserve(struct dasd_device
*device
)
3400 struct dasd_ccw_req
*cqr
;
3405 if (!capable(CAP_SYS_ADMIN
))
3409 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3411 mutex_lock(&dasd_reserve_mutex
);
3413 cqr
= &dasd_reserve_req
->cqr
;
3414 memset(cqr
, 0, sizeof(*cqr
));
3415 memset(&dasd_reserve_req
->ccw
, 0,
3416 sizeof(dasd_reserve_req
->ccw
));
3417 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3418 cqr
->data
= &dasd_reserve_req
->data
;
3419 cqr
->magic
= DASD_ECKD_MAGIC
;
3422 ccw
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
3423 ccw
->flags
|= CCW_FLAG_SLI
;
3425 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3426 cqr
->startdev
= device
;
3427 cqr
->memdev
= device
;
3428 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3429 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3430 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3431 cqr
->expires
= 2 * HZ
;
3432 cqr
->buildclk
= get_clock();
3433 cqr
->status
= DASD_CQR_FILLED
;
3435 rc
= dasd_sleep_on_immediatly(cqr
);
3437 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3440 mutex_unlock(&dasd_reserve_mutex
);
3442 dasd_sfree_request(cqr
, cqr
->memdev
);
3447 * Steal lock ioctl - unconditional reserve device.
3448 * Buils a channel programm to break a device's reservation.
3449 * (unconditional reserve)
3452 dasd_eckd_steal_lock(struct dasd_device
*device
)
3454 struct dasd_ccw_req
*cqr
;
3459 if (!capable(CAP_SYS_ADMIN
))
3463 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1, 32, device
);
3465 mutex_lock(&dasd_reserve_mutex
);
3467 cqr
= &dasd_reserve_req
->cqr
;
3468 memset(cqr
, 0, sizeof(*cqr
));
3469 memset(&dasd_reserve_req
->ccw
, 0,
3470 sizeof(dasd_reserve_req
->ccw
));
3471 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3472 cqr
->data
= &dasd_reserve_req
->data
;
3473 cqr
->magic
= DASD_ECKD_MAGIC
;
3476 ccw
->cmd_code
= DASD_ECKD_CCW_SLCK
;
3477 ccw
->flags
|= CCW_FLAG_SLI
;
3479 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3480 cqr
->startdev
= device
;
3481 cqr
->memdev
= device
;
3482 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3483 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3484 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
3485 cqr
->expires
= 2 * HZ
;
3486 cqr
->buildclk
= get_clock();
3487 cqr
->status
= DASD_CQR_FILLED
;
3489 rc
= dasd_sleep_on_immediatly(cqr
);
3491 set_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
);
3494 mutex_unlock(&dasd_reserve_mutex
);
3496 dasd_sfree_request(cqr
, cqr
->memdev
);
3501 * SNID - Sense Path Group ID
3502 * This ioctl may be used in situations where I/O is stalled due to
3503 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3504 * preallocated dasd_reserve_req.
3506 static int dasd_eckd_snid(struct dasd_device
*device
,
3509 struct dasd_ccw_req
*cqr
;
3513 struct dasd_snid_ioctl_data usrparm
;
3515 if (!capable(CAP_SYS_ADMIN
))
3518 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3522 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1,
3523 sizeof(struct dasd_snid_data
), device
);
3525 mutex_lock(&dasd_reserve_mutex
);
3527 cqr
= &dasd_reserve_req
->cqr
;
3528 memset(cqr
, 0, sizeof(*cqr
));
3529 memset(&dasd_reserve_req
->ccw
, 0,
3530 sizeof(dasd_reserve_req
->ccw
));
3531 cqr
->cpaddr
= &dasd_reserve_req
->ccw
;
3532 cqr
->data
= &dasd_reserve_req
->data
;
3533 cqr
->magic
= DASD_ECKD_MAGIC
;
3536 ccw
->cmd_code
= DASD_ECKD_CCW_SNID
;
3537 ccw
->flags
|= CCW_FLAG_SLI
;
3539 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
3540 cqr
->startdev
= device
;
3541 cqr
->memdev
= device
;
3542 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3543 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
3544 set_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
);
3546 cqr
->expires
= 10 * HZ
;
3547 cqr
->buildclk
= get_clock();
3548 cqr
->status
= DASD_CQR_FILLED
;
3549 cqr
->lpm
= usrparm
.path_mask
;
3551 rc
= dasd_sleep_on_immediatly(cqr
);
3552 /* verify that I/O processing didn't modify the path mask */
3553 if (!rc
&& usrparm
.path_mask
&& (cqr
->lpm
!= usrparm
.path_mask
))
3556 usrparm
.data
= *((struct dasd_snid_data
*)cqr
->data
);
3557 if (copy_to_user(argp
, &usrparm
, sizeof(usrparm
)))
3562 mutex_unlock(&dasd_reserve_mutex
);
3564 dasd_sfree_request(cqr
, cqr
->memdev
);
3569 * Read performance statistics
3572 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
3574 struct dasd_psf_prssd_data
*prssdp
;
3575 struct dasd_rssd_perf_stats_t
*stats
;
3576 struct dasd_ccw_req
*cqr
;
3580 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
3581 (sizeof(struct dasd_psf_prssd_data
) +
3582 sizeof(struct dasd_rssd_perf_stats_t
)),
3585 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3586 "Could not allocate initialization request");
3587 return PTR_ERR(cqr
);
3589 cqr
->startdev
= device
;
3590 cqr
->memdev
= device
;
3592 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
3593 cqr
->expires
= 10 * HZ
;
3595 /* Prepare for Read Subsystem Data */
3596 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3597 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
3598 prssdp
->order
= PSF_ORDER_PRSSD
;
3599 prssdp
->suborder
= 0x01; /* Performance Statistics */
3600 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
3603 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
3604 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
3605 ccw
->flags
|= CCW_FLAG_CC
;
3606 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
3608 /* Read Subsystem Data - Performance Statistics */
3609 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3610 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
3613 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
3614 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
3615 ccw
->cda
= (__u32
)(addr_t
) stats
;
3617 cqr
->buildclk
= get_clock();
3618 cqr
->status
= DASD_CQR_FILLED
;
3619 rc
= dasd_sleep_on(cqr
);
3621 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
3622 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
3623 if (copy_to_user(argp
, stats
,
3624 sizeof(struct dasd_rssd_perf_stats_t
)))
3627 dasd_sfree_request(cqr
, cqr
->memdev
);
3632 * Get attributes (cache operations)
3633 * Returnes the cache attributes used in Define Extend (DE).
3636 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
3638 struct dasd_eckd_private
*private =
3639 (struct dasd_eckd_private
*)device
->private;
3640 struct attrib_data_t attrib
= private->attrib
;
3643 if (!capable(CAP_SYS_ADMIN
))
3649 if (copy_to_user(argp
, (long *) &attrib
,
3650 sizeof(struct attrib_data_t
)))
3657 * Set attributes (cache operations)
3658 * Stores the attributes for cache operation to be used in Define Extend (DE).
3661 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
3663 struct dasd_eckd_private
*private =
3664 (struct dasd_eckd_private
*)device
->private;
3665 struct attrib_data_t attrib
;
3667 if (!capable(CAP_SYS_ADMIN
))
3672 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
3674 private->attrib
= attrib
;
3676 dev_info(&device
->cdev
->dev
,
3677 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3678 private->attrib
.operation
, private->attrib
.nr_cyl
);
3683 * Issue syscall I/O to EMC Symmetrix array.
3684 * CCWs are PSF and RSSD
3686 static int dasd_symm_io(struct dasd_device
*device
, void __user
*argp
)
3688 struct dasd_symmio_parms usrparm
;
3689 char *psf_data
, *rssd_result
;
3690 struct dasd_ccw_req
*cqr
;
3695 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
3699 /* Copy parms from caller */
3701 if (copy_from_user(&usrparm
, argp
, sizeof(usrparm
)))
3703 if (is_compat_task() || sizeof(long) == 4) {
3704 /* Make sure pointers are sane even on 31 bit. */
3706 if ((usrparm
.psf_data
>> 32) != 0)
3708 if ((usrparm
.rssd_result
>> 32) != 0)
3710 usrparm
.psf_data
&= 0x7fffffffULL
;
3711 usrparm
.rssd_result
&= 0x7fffffffULL
;
3713 /* alloc I/O data area */
3714 psf_data
= kzalloc(usrparm
.psf_data_len
, GFP_KERNEL
| GFP_DMA
);
3715 rssd_result
= kzalloc(usrparm
.rssd_result_len
, GFP_KERNEL
| GFP_DMA
);
3716 if (!psf_data
|| !rssd_result
) {
3721 /* get syscall header from user space */
3723 if (copy_from_user(psf_data
,
3724 (void __user
*)(unsigned long) usrparm
.psf_data
,
3725 usrparm
.psf_data_len
))
3730 /* setup CCWs for PSF + RSSD */
3731 cqr
= dasd_smalloc_request(DASD_ECKD_MAGIC
, 2 , 0, device
);
3733 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3734 "Could not allocate initialization request");
3739 cqr
->startdev
= device
;
3740 cqr
->memdev
= device
;
3742 cqr
->expires
= 10 * HZ
;
3743 cqr
->buildclk
= get_clock();
3744 cqr
->status
= DASD_CQR_FILLED
;
3746 /* Build the ccws */
3750 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
3751 ccw
->count
= usrparm
.psf_data_len
;
3752 ccw
->flags
|= CCW_FLAG_CC
;
3753 ccw
->cda
= (__u32
)(addr_t
) psf_data
;
3758 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
3759 ccw
->count
= usrparm
.rssd_result_len
;
3760 ccw
->flags
= CCW_FLAG_SLI
;
3761 ccw
->cda
= (__u32
)(addr_t
) rssd_result
;
3763 rc
= dasd_sleep_on(cqr
);
3768 if (copy_to_user((void __user
*)(unsigned long) usrparm
.rssd_result
,
3769 rssd_result
, usrparm
.rssd_result_len
))
3774 dasd_sfree_request(cqr
, cqr
->memdev
);
3779 DBF_DEV_EVENT(DBF_WARNING
, device
,
3780 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3781 (int) psf0
, (int) psf1
, rc
);
3786 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
3788 struct dasd_device
*device
= block
->base
;
3792 return dasd_eckd_get_attrib(device
, argp
);
3794 return dasd_eckd_set_attrib(device
, argp
);
3796 return dasd_eckd_performance(device
, argp
);
3798 return dasd_eckd_release(device
);
3800 return dasd_eckd_reserve(device
);
3802 return dasd_eckd_steal_lock(device
);
3804 return dasd_eckd_snid(device
, argp
);
3806 return dasd_symm_io(device
, argp
);
3808 return -ENOIOCTLCMD
;
3813 * Dump the range of CCWs into 'page' buffer
3814 * and return number of printed chars.
3817 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
3823 while (from
<= to
) {
3824 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3825 " CCW %p: %08X %08X DAT:",
3826 from
, ((int *) from
)[0], ((int *) from
)[1]);
3828 /* get pointer to data (consider IDALs) */
3829 if (from
->flags
& CCW_FLAG_IDA
)
3830 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
3832 datap
= (char *) ((addr_t
) from
->cda
);
3834 /* dump data (max 32 bytes) */
3835 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
3836 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
3837 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
3838 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
3840 len
+= sprintf(page
+ len
, "\n");
3847 dasd_eckd_dump_sense_dbf(struct dasd_device
*device
, struct irb
*irb
,
3853 sense
= (u64
*) dasd_get_sense(irb
);
3854 stat
= (u64
*) &irb
->scsw
;
3856 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : "
3857 "%016llx %016llx %016llx %016llx",
3858 reason
, *stat
, *((u32
*) (stat
+ 1)),
3859 sense
[0], sense
[1], sense
[2], sense
[3]);
3861 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s: %016llx %08x : %s",
3862 reason
, *stat
, *((u32
*) (stat
+ 1)),
3868 * Print sense data and related channel program.
3869 * Parts are printed because printk buffer is only 1024 bytes.
3871 static void dasd_eckd_dump_sense_ccw(struct dasd_device
*device
,
3872 struct dasd_ccw_req
*req
, struct irb
*irb
)
3875 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
3878 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
3880 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3881 "No memory to dump sense data\n");
3884 /* dump the sense data */
3885 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
3886 " I/O status report for device %s:\n",
3887 dev_name(&device
->cdev
->dev
));
3888 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3889 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3891 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
3892 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
3893 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
3894 req
? req
->intrc
: 0);
3895 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3896 " device %s: Failing CCW: %p\n",
3897 dev_name(&device
->cdev
->dev
),
3898 (void *) (addr_t
) irb
->scsw
.cmd
.cpa
);
3899 if (irb
->esw
.esw0
.erw
.cons
) {
3900 for (sl
= 0; sl
< 4; sl
++) {
3901 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3902 " Sense(hex) %2d-%2d:",
3903 (8 * sl
), ((8 * sl
) + 7));
3905 for (sct
= 0; sct
< 8; sct
++) {
3906 len
+= sprintf(page
+ len
, " %02x",
3907 irb
->ecw
[8 * sl
+ sct
]);
3909 len
+= sprintf(page
+ len
, "\n");
3912 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
3913 /* 24 Byte Sense Data */
3914 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3915 " 24 Byte: %x MSG %x, "
3916 "%s MSGb to SYSOP\n",
3917 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
3918 irb
->ecw
[1] & 0x10 ? "" : "no");
3920 /* 32 Byte Sense Data */
3921 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3922 " 32 Byte: Format: %x "
3923 "Exception class %x\n",
3924 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
3927 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3928 " SORRY - NO VALID SENSE AVAILABLE\n");
3933 /* req == NULL for unsolicited interrupts */
3934 /* dump the Channel Program (max 140 Bytes per line) */
3935 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3936 first
= req
->cpaddr
;
3937 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
3938 to
= min(first
+ 6, last
);
3939 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
3940 " Related CP in req: %p\n", req
);
3941 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
3944 /* print failing CCW area (maximum 4) */
3945 /* scsw->cda is either valid or zero */
3948 fail
= (struct ccw1
*)(addr_t
)
3949 irb
->scsw
.cmd
.cpa
; /* failing CCW */
3950 if (from
< fail
- 2) {
3951 from
= fail
- 2; /* there is a gap - print header */
3952 len
+= sprintf(page
, KERN_ERR PRINTK_HEADER
"......\n");
3954 to
= min(fail
+ 1, last
);
3955 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
3957 /* print last CCWs (maximum 2) */
3958 from
= max(from
, ++to
);
3959 if (from
< last
- 1) {
3960 from
= last
- 1; /* there is a gap - print header */
3961 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
3963 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
3967 free_page((unsigned long) page
);
3972 * Print sense data from a tcw.
3974 static void dasd_eckd_dump_sense_tcw(struct dasd_device
*device
,
3975 struct dasd_ccw_req
*req
, struct irb
*irb
)
3978 int len
, sl
, sct
, residual
;
3982 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
3984 DBF_DEV_EVENT(DBF_WARNING
, device
, " %s",
3985 "No memory to dump sense data");
3988 /* dump the sense data */
3989 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
3990 " I/O status report for device %s:\n",
3991 dev_name(&device
->cdev
->dev
));
3992 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
3993 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3994 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
3995 req
, scsw_cc(&irb
->scsw
), scsw_fctl(&irb
->scsw
),
3996 scsw_actl(&irb
->scsw
), scsw_stctl(&irb
->scsw
),
3997 scsw_dstat(&irb
->scsw
), scsw_cstat(&irb
->scsw
),
3998 irb
->scsw
.tm
.fcxs
, irb
->scsw
.tm
.schxs
,
3999 req
? req
->intrc
: 0);
4000 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4001 " device %s: Failing TCW: %p\n",
4002 dev_name(&device
->cdev
->dev
),
4003 (void *) (addr_t
) irb
->scsw
.tm
.tcw
);
4007 if (irb
->scsw
.tm
.tcw
&& (irb
->scsw
.tm
.fcxs
& 0x01))
4009 (struct tcw
*)(unsigned long)irb
->scsw
.tm
.tcw
);
4012 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4013 " tsb->length %d\n", tsb
->length
);
4014 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4015 " tsb->flags %x\n", tsb
->flags
);
4016 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4017 " tsb->dcw_offset %d\n", tsb
->dcw_offset
);
4018 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4019 " tsb->count %d\n", tsb
->count
);
4020 residual
= tsb
->count
- 28;
4021 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4022 " residual %d\n", residual
);
4024 switch (tsb
->flags
& 0x07) {
4025 case 1: /* tsa_iostat */
4026 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4027 " tsb->tsa.iostat.dev_time %d\n",
4028 tsb
->tsa
.iostat
.dev_time
);
4029 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4030 " tsb->tsa.iostat.def_time %d\n",
4031 tsb
->tsa
.iostat
.def_time
);
4032 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4033 " tsb->tsa.iostat.queue_time %d\n",
4034 tsb
->tsa
.iostat
.queue_time
);
4035 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4036 " tsb->tsa.iostat.dev_busy_time %d\n",
4037 tsb
->tsa
.iostat
.dev_busy_time
);
4038 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4039 " tsb->tsa.iostat.dev_act_time %d\n",
4040 tsb
->tsa
.iostat
.dev_act_time
);
4041 sense
= tsb
->tsa
.iostat
.sense
;
4043 case 2: /* ts_ddpc */
4044 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4045 " tsb->tsa.ddpc.rc %d\n", tsb
->tsa
.ddpc
.rc
);
4046 for (sl
= 0; sl
< 2; sl
++) {
4047 len
+= sprintf(page
+ len
,
4048 KERN_ERR PRINTK_HEADER
4049 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4050 (8 * sl
), ((8 * sl
) + 7));
4051 rcq
= tsb
->tsa
.ddpc
.rcq
;
4052 for (sct
= 0; sct
< 8; sct
++) {
4053 len
+= sprintf(page
+ len
, " %02x",
4056 len
+= sprintf(page
+ len
, "\n");
4058 sense
= tsb
->tsa
.ddpc
.sense
;
4060 case 3: /* tsa_intrg */
4061 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4062 " tsb->tsa.intrg.: not supportet yet \n");
4067 for (sl
= 0; sl
< 4; sl
++) {
4068 len
+= sprintf(page
+ len
,
4069 KERN_ERR PRINTK_HEADER
4070 " Sense(hex) %2d-%2d:",
4071 (8 * sl
), ((8 * sl
) + 7));
4072 for (sct
= 0; sct
< 8; sct
++) {
4073 len
+= sprintf(page
+ len
, " %02x",
4074 sense
[8 * sl
+ sct
]);
4076 len
+= sprintf(page
+ len
, "\n");
4079 if (sense
[27] & DASD_SENSE_BIT_0
) {
4080 /* 24 Byte Sense Data */
4081 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4082 " 24 Byte: %x MSG %x, "
4083 "%s MSGb to SYSOP\n",
4084 sense
[7] >> 4, sense
[7] & 0x0f,
4085 sense
[1] & 0x10 ? "" : "no");
4087 /* 32 Byte Sense Data */
4088 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4089 " 32 Byte: Format: %x "
4090 "Exception class %x\n",
4091 sense
[6] & 0x0f, sense
[22] >> 4);
4094 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4095 " SORRY - NO VALID SENSE AVAILABLE\n");
4098 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
4099 " SORRY - NO TSB DATA AVAILABLE\n");
4102 free_page((unsigned long) page
);
4105 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
4106 struct dasd_ccw_req
*req
, struct irb
*irb
)
4108 if (scsw_is_tm(&irb
->scsw
))
4109 dasd_eckd_dump_sense_tcw(device
, req
, irb
);
4111 dasd_eckd_dump_sense_ccw(device
, req
, irb
);
4114 static int dasd_eckd_pm_freeze(struct dasd_device
*device
)
4117 * the device should be disconnected from our LCU structure
4118 * on restore we will reconnect it and reread LCU specific
4119 * information like PAV support that might have changed
4121 dasd_alias_remove_device(device
);
4122 dasd_alias_disconnect_device_from_lcu(device
);
4127 static int dasd_eckd_restore_device(struct dasd_device
*device
)
4129 struct dasd_eckd_private
*private;
4130 struct dasd_eckd_characteristics temp_rdc_data
;
4132 struct dasd_uid temp_uid
;
4133 unsigned long flags
;
4135 private = (struct dasd_eckd_private
*) device
->private;
4137 /* Read Configuration Data */
4138 rc
= dasd_eckd_read_conf(device
);
4142 dasd_eckd_get_uid(device
, &temp_uid
);
4143 /* Generate device unique id */
4144 rc
= dasd_eckd_generate_uid(device
);
4145 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4146 if (memcmp(&private->uid
, &temp_uid
, sizeof(struct dasd_uid
)) != 0)
4147 dev_err(&device
->cdev
->dev
, "The UID of the DASD has "
4149 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4153 /* register lcu with alias handling, enable PAV if this is a new lcu */
4154 rc
= dasd_alias_make_device_known_to_lcu(device
);
4157 dasd_eckd_validate_server(device
);
4159 /* RE-Read Configuration Data */
4160 rc
= dasd_eckd_read_conf(device
);
4164 /* Read Feature Codes */
4165 dasd_eckd_read_features(device
);
4167 /* Read Device Characteristics */
4168 rc
= dasd_generic_read_dev_chars(device
, DASD_ECKD_MAGIC
,
4169 &temp_rdc_data
, 64);
4171 DBF_EVENT_DEVID(DBF_WARNING
, device
->cdev
,
4172 "Read device characteristic failed, rc=%d", rc
);
4175 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4176 memcpy(&private->rdc_data
, &temp_rdc_data
, sizeof(temp_rdc_data
));
4177 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4179 /* add device to alias management */
4180 dasd_alias_add_device(device
);
4188 static int dasd_eckd_reload_device(struct dasd_device
*device
)
4190 struct dasd_eckd_private
*private;
4193 struct dasd_uid uid
;
4194 unsigned long flags
;
4196 private = (struct dasd_eckd_private
*) device
->private;
4198 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
4199 old_base
= private->uid
.base_unit_addr
;
4200 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
4202 /* Read Configuration Data */
4203 rc
= dasd_eckd_read_conf(device
);
4207 rc
= dasd_eckd_generate_uid(device
);
4211 * update unit address configuration and
4212 * add device to alias management
4214 dasd_alias_update_add_device(device
);
4216 dasd_eckd_get_uid(device
, &uid
);
4218 if (old_base
!= uid
.base_unit_addr
) {
4219 if (strlen(uid
.vduit
) > 0)
4220 snprintf(print_uid
, sizeof(print_uid
),
4221 "%s.%s.%04x.%02x.%s", uid
.vendor
, uid
.serial
,
4222 uid
.ssid
, uid
.base_unit_addr
, uid
.vduit
);
4224 snprintf(print_uid
, sizeof(print_uid
),
4225 "%s.%s.%04x.%02x", uid
.vendor
, uid
.serial
,
4226 uid
.ssid
, uid
.base_unit_addr
);
4228 dev_info(&device
->cdev
->dev
,
4229 "An Alias device was reassigned to a new base device "
4230 "with UID: %s\n", print_uid
);
4238 static struct ccw_driver dasd_eckd_driver
= {
4240 .name
= "dasd-eckd",
4241 .owner
= THIS_MODULE
,
4243 .ids
= dasd_eckd_ids
,
4244 .probe
= dasd_eckd_probe
,
4245 .remove
= dasd_generic_remove
,
4246 .set_offline
= dasd_generic_set_offline
,
4247 .set_online
= dasd_eckd_set_online
,
4248 .notify
= dasd_generic_notify
,
4249 .path_event
= dasd_generic_path_event
,
4250 .freeze
= dasd_generic_pm_freeze
,
4251 .thaw
= dasd_generic_restore_device
,
4252 .restore
= dasd_generic_restore_device
,
4253 .uc_handler
= dasd_generic_uc_handler
,
4254 .int_class
= IOINT_DAS
,
4258 * max_blocks is dependent on the amount of storage that is available
4259 * in the static io buffer for each device. Currently each device has
4260 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4261 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4262 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4263 * addition we have one define extent ccw + 16 bytes of data and one
4264 * locate record ccw + 16 bytes of data. That makes:
4265 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4266 * We want to fit two into the available memory so that we can immediately
4267 * start the next request if one finishes off. That makes 249.5 blocks
4268 * for one request. Give a little safety and the result is 240.
4270 static struct dasd_discipline dasd_eckd_discipline
= {
4271 .owner
= THIS_MODULE
,
4275 .check_device
= dasd_eckd_check_characteristics
,
4276 .uncheck_device
= dasd_eckd_uncheck_device
,
4277 .do_analysis
= dasd_eckd_do_analysis
,
4278 .verify_path
= dasd_eckd_verify_path
,
4279 .ready_to_online
= dasd_eckd_ready_to_online
,
4280 .online_to_ready
= dasd_eckd_online_to_ready
,
4281 .fill_geometry
= dasd_eckd_fill_geometry
,
4282 .start_IO
= dasd_start_IO
,
4283 .term_IO
= dasd_term_IO
,
4284 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
4285 .format_device
= dasd_eckd_format_device
,
4286 .erp_action
= dasd_eckd_erp_action
,
4287 .erp_postaction
= dasd_eckd_erp_postaction
,
4288 .check_for_device_change
= dasd_eckd_check_for_device_change
,
4289 .build_cp
= dasd_eckd_build_alias_cp
,
4290 .free_cp
= dasd_eckd_free_alias_cp
,
4291 .dump_sense
= dasd_eckd_dump_sense
,
4292 .dump_sense_dbf
= dasd_eckd_dump_sense_dbf
,
4293 .fill_info
= dasd_eckd_fill_info
,
4294 .ioctl
= dasd_eckd_ioctl
,
4295 .freeze
= dasd_eckd_pm_freeze
,
4296 .restore
= dasd_eckd_restore_device
,
4297 .reload
= dasd_eckd_reload_device
,
4298 .get_uid
= dasd_eckd_get_uid
,
4299 .kick_validate
= dasd_eckd_kick_validate_server
,
4303 dasd_eckd_init(void)
4307 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
4308 dasd_reserve_req
= kmalloc(sizeof(*dasd_reserve_req
),
4309 GFP_KERNEL
| GFP_DMA
);
4310 if (!dasd_reserve_req
)
4312 path_verification_worker
= kmalloc(sizeof(*path_verification_worker
),
4313 GFP_KERNEL
| GFP_DMA
);
4314 if (!path_verification_worker
) {
4315 kfree(dasd_reserve_req
);
4318 ret
= ccw_driver_register(&dasd_eckd_driver
);
4320 wait_for_device_probe();
4322 kfree(path_verification_worker
);
4323 kfree(dasd_reserve_req
);
4329 dasd_eckd_cleanup(void)
4331 ccw_driver_unregister(&dasd_eckd_driver
);
4332 kfree(path_verification_worker
);
4333 kfree(dasd_reserve_req
);
4336 module_init(dasd_eckd_init
);
4337 module_exit(dasd_eckd_cleanup
);