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 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/hdreg.h> /* HDIO_GETGEO */
16 #include <linux/bio.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
20 #include <asm/debug.h>
21 #include <asm/idals.h>
22 #include <asm/ebcdic.h>
24 #include <asm/todclk.h>
25 #include <asm/uaccess.h>
27 #include <asm/ccwdev.h>
30 #include "dasd_eckd.h"
34 #endif /* PRINTK_HEADER */
35 #define PRINTK_HEADER "dasd(eckd):"
37 #define ECKD_C0(i) (i->home_bytes)
38 #define ECKD_F(i) (i->formula)
39 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
40 (i->factors.f_0x02.f1))
41 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
42 (i->factors.f_0x02.f2))
43 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
44 (i->factors.f_0x02.f3))
45 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
46 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
47 #define ECKD_F6(i) (i->factor6)
48 #define ECKD_F7(i) (i->factor7)
49 #define ECKD_F8(i) (i->factor8)
51 MODULE_LICENSE("GPL");
53 static struct dasd_discipline dasd_eckd_discipline
;
55 /* The ccw bus type uses this table to find devices that it sends to
57 static struct ccw_device_id dasd_eckd_ids
[] = {
58 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info
= 0x1},
59 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info
= 0x2},
60 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info
= 0x3},
61 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info
= 0x4},
62 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info
= 0x5},
63 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info
= 0x6},
64 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info
= 0x7},
65 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info
= 0x8},
66 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info
= 0x9},
67 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info
= 0xa},
68 { /* end of list */ },
71 MODULE_DEVICE_TABLE(ccw
, dasd_eckd_ids
);
73 static struct ccw_driver dasd_eckd_driver
; /* see below */
75 /* initial attempt at a probe function. this can be simplified once
76 * the other detection code is gone */
78 dasd_eckd_probe (struct ccw_device
*cdev
)
82 /* set ECKD specific ccw-device options */
83 ret
= ccw_device_set_options(cdev
, CCWDEV_ALLOW_FORCE
);
86 "dasd_eckd_probe: could not set ccw-device options "
87 "for %s\n", cdev
->dev
.bus_id
);
90 ret
= dasd_generic_probe(cdev
, &dasd_eckd_discipline
);
95 dasd_eckd_set_online(struct ccw_device
*cdev
)
97 return dasd_generic_set_online(cdev
, &dasd_eckd_discipline
);
100 static struct ccw_driver dasd_eckd_driver
= {
102 .owner
= THIS_MODULE
,
103 .ids
= dasd_eckd_ids
,
104 .probe
= dasd_eckd_probe
,
105 .remove
= dasd_generic_remove
,
106 .set_offline
= dasd_generic_set_offline
,
107 .set_online
= dasd_eckd_set_online
,
108 .notify
= dasd_generic_notify
,
111 static const int sizes_trk0
[] = { 28, 148, 84 };
112 #define LABEL_SIZE 140
114 static inline unsigned int
115 round_up_multiple(unsigned int no
, unsigned int mult
)
118 return (rem
? no
- rem
+ mult
: no
);
121 static inline unsigned int
122 ceil_quot(unsigned int d1
, unsigned int d2
)
124 return (d1
+ (d2
- 1)) / d2
;
128 recs_per_track(struct dasd_eckd_characteristics
* rdc
,
129 unsigned int kl
, unsigned int dl
)
133 switch (rdc
->dev_type
) {
136 return 1499 / (15 + 7 + ceil_quot(kl
+ 12, 32) +
137 ceil_quot(dl
+ 12, 32));
139 return 1499 / (15 + ceil_quot(dl
+ 12, 32));
141 dn
= ceil_quot(dl
+ 6, 232) + 1;
143 kn
= ceil_quot(kl
+ 6, 232) + 1;
144 return 1729 / (10 + 9 + ceil_quot(kl
+ 6 * kn
, 34) +
145 9 + ceil_quot(dl
+ 6 * dn
, 34));
147 return 1729 / (10 + 9 + ceil_quot(dl
+ 6 * dn
, 34));
149 dn
= ceil_quot(dl
+ 6, 232) + 1;
151 kn
= ceil_quot(kl
+ 6, 232) + 1;
152 return 1420 / (18 + 7 + ceil_quot(kl
+ 6 * kn
, 34) +
153 ceil_quot(dl
+ 6 * dn
, 34));
155 return 1420 / (18 + 7 + ceil_quot(dl
+ 6 * dn
, 34));
161 check_XRC (struct ccw1
*de_ccw
,
162 struct DE_eckd_data
*data
,
163 struct dasd_device
*device
)
165 struct dasd_eckd_private
*private;
168 private = (struct dasd_eckd_private
*) device
->private;
169 if (!private->rdc_data
.facilities
.XRC_supported
)
172 /* switch on System Time Stamp - needed for XRC Support */
173 data
->ga_extended
|= 0x08; /* switch on 'Time Stamp Valid' */
174 data
->ga_extended
|= 0x02; /* switch on 'Extended Parameter' */
176 rc
= get_sync_clock(&data
->ep_sys_time
);
177 /* Ignore return code if sync clock is switched off. */
178 if (rc
== -ENOSYS
|| rc
== -EACCES
)
181 de_ccw
->count
= sizeof(struct DE_eckd_data
);
182 de_ccw
->flags
|= CCW_FLAG_SLI
;
187 define_extent(struct ccw1
* ccw
, struct DE_eckd_data
* data
, int trk
,
188 int totrk
, int cmd
, struct dasd_device
* device
)
190 struct dasd_eckd_private
*private;
191 struct ch_t geo
, beg
, end
;
194 private = (struct dasd_eckd_private
*) device
->private;
196 ccw
->cmd_code
= DASD_ECKD_CCW_DEFINE_EXTENT
;
199 ccw
->cda
= (__u32
) __pa(data
);
201 memset(data
, 0, sizeof(struct DE_eckd_data
));
203 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
204 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
205 case DASD_ECKD_CCW_READ
:
206 case DASD_ECKD_CCW_READ_MT
:
207 case DASD_ECKD_CCW_READ_CKD
:
208 case DASD_ECKD_CCW_READ_CKD_MT
:
209 case DASD_ECKD_CCW_READ_KD
:
210 case DASD_ECKD_CCW_READ_KD_MT
:
211 case DASD_ECKD_CCW_READ_COUNT
:
212 data
->mask
.perm
= 0x1;
213 data
->attributes
.operation
= private->attrib
.operation
;
215 case DASD_ECKD_CCW_WRITE
:
216 case DASD_ECKD_CCW_WRITE_MT
:
217 case DASD_ECKD_CCW_WRITE_KD
:
218 case DASD_ECKD_CCW_WRITE_KD_MT
:
219 data
->mask
.perm
= 0x02;
220 data
->attributes
.operation
= private->attrib
.operation
;
221 rc
= check_XRC (ccw
, data
, device
);
223 case DASD_ECKD_CCW_WRITE_CKD
:
224 case DASD_ECKD_CCW_WRITE_CKD_MT
:
225 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
226 rc
= check_XRC (ccw
, data
, device
);
228 case DASD_ECKD_CCW_ERASE
:
229 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
230 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
231 data
->mask
.perm
= 0x3;
232 data
->mask
.auth
= 0x1;
233 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
234 rc
= check_XRC (ccw
, data
, device
);
237 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
241 data
->attributes
.mode
= 0x3; /* ECKD */
243 if ((private->rdc_data
.cu_type
== 0x2105 ||
244 private->rdc_data
.cu_type
== 0x2107 ||
245 private->rdc_data
.cu_type
== 0x1750)
246 && !(private->uses_cdl
&& trk
< 2))
247 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
249 geo
.cyl
= private->rdc_data
.no_cyl
;
250 geo
.head
= private->rdc_data
.trk_per_cyl
;
251 beg
.cyl
= trk
/ geo
.head
;
252 beg
.head
= trk
% geo
.head
;
253 end
.cyl
= totrk
/ geo
.head
;
254 end
.head
= totrk
% geo
.head
;
256 /* check for sequential prestage - enhance cylinder range */
257 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
258 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
260 if (end
.cyl
+ private->attrib
.nr_cyl
< geo
.cyl
)
261 end
.cyl
+= private->attrib
.nr_cyl
;
263 end
.cyl
= (geo
.cyl
- 1);
266 data
->beg_ext
.cyl
= beg
.cyl
;
267 data
->beg_ext
.head
= beg
.head
;
268 data
->end_ext
.cyl
= end
.cyl
;
269 data
->end_ext
.head
= end
.head
;
273 static int check_XRC_on_prefix(struct PFX_eckd_data
*pfxdata
,
274 struct dasd_device
*device
)
276 struct dasd_eckd_private
*private;
279 private = (struct dasd_eckd_private
*) device
->private;
280 if (!private->rdc_data
.facilities
.XRC_supported
)
283 /* switch on System Time Stamp - needed for XRC Support */
284 pfxdata
->define_extend
.ga_extended
|= 0x08; /* 'Time Stamp Valid' */
285 pfxdata
->define_extend
.ga_extended
|= 0x02; /* 'Extended Parameter' */
286 pfxdata
->validity
.time_stamp
= 1; /* 'Time Stamp Valid' */
288 rc
= get_sync_clock(&pfxdata
->define_extend
.ep_sys_time
);
289 /* Ignore return code if sync clock is switched off. */
290 if (rc
== -ENOSYS
|| rc
== -EACCES
)
295 static int prefix(struct ccw1
*ccw
, struct PFX_eckd_data
*pfxdata
, int trk
,
296 int totrk
, int cmd
, struct dasd_device
*basedev
,
297 struct dasd_device
*startdev
)
299 struct dasd_eckd_private
*basepriv
, *startpriv
;
300 struct DE_eckd_data
*data
;
301 struct ch_t geo
, beg
, end
;
304 basepriv
= (struct dasd_eckd_private
*) basedev
->private;
305 startpriv
= (struct dasd_eckd_private
*) startdev
->private;
306 data
= &pfxdata
->define_extend
;
308 ccw
->cmd_code
= DASD_ECKD_CCW_PFX
;
310 ccw
->count
= sizeof(*pfxdata
);
311 ccw
->cda
= (__u32
) __pa(pfxdata
);
313 memset(pfxdata
, 0, sizeof(*pfxdata
));
316 pfxdata
->base_address
= basepriv
->conf_data
.ned1
.unit_addr
;
317 pfxdata
->base_lss
= basepriv
->conf_data
.ned1
.ID
;
318 pfxdata
->validity
.define_extend
= 1;
320 /* private uid is kept up to date, conf_data may be outdated */
321 if (startpriv
->uid
.type
!= UA_BASE_DEVICE
) {
322 pfxdata
->validity
.verify_base
= 1;
323 if (startpriv
->uid
.type
== UA_HYPER_PAV_ALIAS
)
324 pfxdata
->validity
.hyper_pav
= 1;
327 /* define extend data (mostly)*/
329 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
330 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
331 case DASD_ECKD_CCW_READ
:
332 case DASD_ECKD_CCW_READ_MT
:
333 case DASD_ECKD_CCW_READ_CKD
:
334 case DASD_ECKD_CCW_READ_CKD_MT
:
335 case DASD_ECKD_CCW_READ_KD
:
336 case DASD_ECKD_CCW_READ_KD_MT
:
337 case DASD_ECKD_CCW_READ_COUNT
:
338 data
->mask
.perm
= 0x1;
339 data
->attributes
.operation
= basepriv
->attrib
.operation
;
341 case DASD_ECKD_CCW_WRITE
:
342 case DASD_ECKD_CCW_WRITE_MT
:
343 case DASD_ECKD_CCW_WRITE_KD
:
344 case DASD_ECKD_CCW_WRITE_KD_MT
:
345 data
->mask
.perm
= 0x02;
346 data
->attributes
.operation
= basepriv
->attrib
.operation
;
347 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
349 case DASD_ECKD_CCW_WRITE_CKD
:
350 case DASD_ECKD_CCW_WRITE_CKD_MT
:
351 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
352 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
354 case DASD_ECKD_CCW_ERASE
:
355 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
356 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
357 data
->mask
.perm
= 0x3;
358 data
->mask
.auth
= 0x1;
359 data
->attributes
.operation
= DASD_BYPASS_CACHE
;
360 rc
= check_XRC_on_prefix(pfxdata
, basedev
);
363 DEV_MESSAGE(KERN_ERR
, basedev
, "unknown opcode 0x%x", cmd
);
367 data
->attributes
.mode
= 0x3; /* ECKD */
369 if ((basepriv
->rdc_data
.cu_type
== 0x2105 ||
370 basepriv
->rdc_data
.cu_type
== 0x2107 ||
371 basepriv
->rdc_data
.cu_type
== 0x1750)
372 && !(basepriv
->uses_cdl
&& trk
< 2))
373 data
->ga_extended
|= 0x40; /* Regular Data Format Mode */
375 geo
.cyl
= basepriv
->rdc_data
.no_cyl
;
376 geo
.head
= basepriv
->rdc_data
.trk_per_cyl
;
377 beg
.cyl
= trk
/ geo
.head
;
378 beg
.head
= trk
% geo
.head
;
379 end
.cyl
= totrk
/ geo
.head
;
380 end
.head
= totrk
% geo
.head
;
382 /* check for sequential prestage - enhance cylinder range */
383 if (data
->attributes
.operation
== DASD_SEQ_PRESTAGE
||
384 data
->attributes
.operation
== DASD_SEQ_ACCESS
) {
386 if (end
.cyl
+ basepriv
->attrib
.nr_cyl
< geo
.cyl
)
387 end
.cyl
+= basepriv
->attrib
.nr_cyl
;
389 end
.cyl
= (geo
.cyl
- 1);
392 data
->beg_ext
.cyl
= beg
.cyl
;
393 data
->beg_ext
.head
= beg
.head
;
394 data
->end_ext
.cyl
= end
.cyl
;
395 data
->end_ext
.head
= end
.head
;
400 locate_record(struct ccw1
*ccw
, struct LO_eckd_data
*data
, int trk
,
401 int rec_on_trk
, int no_rec
, int cmd
,
402 struct dasd_device
* device
, int reclen
)
404 struct dasd_eckd_private
*private;
408 private = (struct dasd_eckd_private
*) device
->private;
410 DBF_DEV_EVENT(DBF_INFO
, device
,
411 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
412 trk
, rec_on_trk
, no_rec
, cmd
, reclen
);
414 ccw
->cmd_code
= DASD_ECKD_CCW_LOCATE_RECORD
;
417 ccw
->cda
= (__u32
) __pa(data
);
419 memset(data
, 0, sizeof(struct LO_eckd_data
));
422 switch (private->rdc_data
.dev_type
) {
424 dn
= ceil_quot(reclen
+ 6, 232);
425 d
= 9 + ceil_quot(reclen
+ 6 * (dn
+ 1), 34);
426 sector
= (49 + (rec_on_trk
- 1) * (10 + d
)) / 8;
429 d
= 7 + ceil_quot(reclen
+ 12, 32);
430 sector
= (39 + (rec_on_trk
- 1) * (8 + d
)) / 7;
434 data
->sector
= sector
;
435 data
->count
= no_rec
;
437 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS
:
438 data
->operation
.orientation
= 0x3;
439 data
->operation
.operation
= 0x03;
441 case DASD_ECKD_CCW_READ_HOME_ADDRESS
:
442 data
->operation
.orientation
= 0x3;
443 data
->operation
.operation
= 0x16;
445 case DASD_ECKD_CCW_WRITE_RECORD_ZERO
:
446 data
->operation
.orientation
= 0x1;
447 data
->operation
.operation
= 0x03;
450 case DASD_ECKD_CCW_READ_RECORD_ZERO
:
451 data
->operation
.orientation
= 0x3;
452 data
->operation
.operation
= 0x16;
455 case DASD_ECKD_CCW_WRITE
:
456 case DASD_ECKD_CCW_WRITE_MT
:
457 case DASD_ECKD_CCW_WRITE_KD
:
458 case DASD_ECKD_CCW_WRITE_KD_MT
:
459 data
->auxiliary
.last_bytes_used
= 0x1;
460 data
->length
= reclen
;
461 data
->operation
.operation
= 0x01;
463 case DASD_ECKD_CCW_WRITE_CKD
:
464 case DASD_ECKD_CCW_WRITE_CKD_MT
:
465 data
->auxiliary
.last_bytes_used
= 0x1;
466 data
->length
= reclen
;
467 data
->operation
.operation
= 0x03;
469 case DASD_ECKD_CCW_READ
:
470 case DASD_ECKD_CCW_READ_MT
:
471 case DASD_ECKD_CCW_READ_KD
:
472 case DASD_ECKD_CCW_READ_KD_MT
:
473 data
->auxiliary
.last_bytes_used
= 0x1;
474 data
->length
= reclen
;
475 data
->operation
.operation
= 0x06;
477 case DASD_ECKD_CCW_READ_CKD
:
478 case DASD_ECKD_CCW_READ_CKD_MT
:
479 data
->auxiliary
.last_bytes_used
= 0x1;
480 data
->length
= reclen
;
481 data
->operation
.operation
= 0x16;
483 case DASD_ECKD_CCW_READ_COUNT
:
484 data
->operation
.operation
= 0x06;
486 case DASD_ECKD_CCW_ERASE
:
487 data
->length
= reclen
;
488 data
->auxiliary
.last_bytes_used
= 0x1;
489 data
->operation
.operation
= 0x0b;
492 DEV_MESSAGE(KERN_ERR
, device
, "unknown opcode 0x%x", cmd
);
494 data
->seek_addr
.cyl
= data
->search_arg
.cyl
=
495 trk
/ private->rdc_data
.trk_per_cyl
;
496 data
->seek_addr
.head
= data
->search_arg
.head
=
497 trk
% private->rdc_data
.trk_per_cyl
;
498 data
->search_arg
.record
= rec_on_trk
;
502 * Returns 1 if the block is one of the special blocks that needs
503 * to get read/written with the KD variant of the command.
504 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
505 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
506 * Luckily the KD variants differ only by one bit (0x08) from the
507 * normal variant. So don't wonder about code like:
508 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
509 * ccw->cmd_code |= 0x8;
512 dasd_eckd_cdl_special(int blk_per_trk
, int recid
)
516 if (recid
< blk_per_trk
)
518 if (recid
< 2 * blk_per_trk
)
524 * Returns the record size for the special blocks of the cdl format.
525 * Only returns something useful if dasd_eckd_cdl_special is true
529 dasd_eckd_cdl_reclen(int recid
)
532 return sizes_trk0
[recid
];
537 * Generate device unique id that specifies the physical device.
540 dasd_eckd_generate_uid(struct dasd_device
*device
, struct dasd_uid
*uid
)
542 struct dasd_eckd_private
*private;
543 struct dasd_eckd_confdata
*confdata
;
545 private = (struct dasd_eckd_private
*) device
->private;
548 confdata
= &private->conf_data
;
552 memset(uid
, 0, sizeof(struct dasd_uid
));
553 memcpy(uid
->vendor
, confdata
->ned1
.HDA_manufacturer
,
554 sizeof(uid
->vendor
) - 1);
555 EBCASC(uid
->vendor
, sizeof(uid
->vendor
) - 1);
556 memcpy(uid
->serial
, confdata
->ned1
.HDA_location
,
557 sizeof(uid
->serial
) - 1);
558 EBCASC(uid
->serial
, sizeof(uid
->serial
) - 1);
559 uid
->ssid
= confdata
->neq
.subsystemID
;
560 uid
->real_unit_addr
= confdata
->ned1
.unit_addr
;
561 if (confdata
->ned2
.sneq
.flags
== 0x40 &&
562 confdata
->ned2
.sneq
.format
== 0x0001) {
563 uid
->type
= confdata
->ned2
.sneq
.sua_flags
;
564 if (uid
->type
== UA_BASE_PAV_ALIAS
)
565 uid
->base_unit_addr
= confdata
->ned2
.sneq
.base_unit_addr
;
567 uid
->type
= UA_BASE_DEVICE
;
572 static struct dasd_ccw_req
*dasd_eckd_build_rcd_lpm(struct dasd_device
*device
,
574 struct ciw
*ciw
, __u8 lpm
)
576 struct dasd_ccw_req
*cqr
;
579 cqr
= dasd_smalloc_request("ECKD", 1 /* RCD */, ciw
->count
, device
);
582 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
583 "Could not allocate RCD request");
588 ccw
->cmd_code
= ciw
->cmd
;
589 ccw
->cda
= (__u32
)(addr_t
)rcd_buffer
;
590 ccw
->count
= ciw
->count
;
592 cqr
->startdev
= device
;
593 cqr
->memdev
= device
;
595 cqr
->expires
= 10*HZ
;
597 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
599 cqr
->buildclk
= get_clock();
600 cqr
->status
= DASD_CQR_FILLED
;
604 static int dasd_eckd_read_conf_lpm(struct dasd_device
*device
,
606 int *rcd_buffer_size
, __u8 lpm
)
609 char *rcd_buf
= NULL
;
611 struct dasd_ccw_req
*cqr
;
614 * scan for RCD command in extended SenseID data
616 ciw
= ccw_device_get_ciw(device
->cdev
, CIW_TYPE_RCD
);
617 if (!ciw
|| ciw
->cmd
== 0) {
621 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
626 cqr
= dasd_eckd_build_rcd_lpm(device
, rcd_buf
, ciw
, lpm
);
631 ret
= dasd_sleep_on(cqr
);
633 * on success we update the user input parms
635 dasd_sfree_request(cqr
, cqr
->memdev
);
639 *rcd_buffer_size
= ciw
->count
;
640 *rcd_buffer
= rcd_buf
;
645 *rcd_buffer_size
= 0;
650 dasd_eckd_read_conf(struct dasd_device
*device
)
653 int conf_len
, conf_data_saved
;
656 struct dasd_eckd_private
*private;
657 struct dasd_eckd_path
*path_data
;
659 private = (struct dasd_eckd_private
*) device
->private;
660 path_data
= (struct dasd_eckd_path
*) &private->path_data
;
661 path_data
->opm
= ccw_device_get_path_mask(device
->cdev
);
665 /* get configuration data per operational path */
666 for (lpm
= 0x80; lpm
; lpm
>>= 1) {
667 if (lpm
& path_data
->opm
){
668 rc
= dasd_eckd_read_conf_lpm(device
, &conf_data
,
670 if (rc
&& rc
!= -EOPNOTSUPP
) { /* -EOPNOTSUPP is ok */
671 MESSAGE(KERN_WARNING
,
672 "Read configuration data returned "
676 if (conf_data
== NULL
) {
677 MESSAGE(KERN_WARNING
, "%s", "No configuration "
679 continue; /* no error */
681 if (conf_len
!= sizeof(struct dasd_eckd_confdata
)) {
682 MESSAGE(KERN_WARNING
,
683 "sizes of configuration data mismatch"
684 "%d (read) vs %ld (expected)",
686 sizeof(struct dasd_eckd_confdata
));
688 continue; /* no error */
690 /* save first valid configuration data */
691 if (!conf_data_saved
){
692 memcpy(&private->conf_data
, conf_data
,
693 sizeof(struct dasd_eckd_confdata
));
696 switch (((char *)conf_data
)[242] & 0x07){
698 path_data
->npm
|= lpm
;
701 path_data
->ppm
|= lpm
;
710 static int dasd_eckd_read_features(struct dasd_device
*device
)
712 struct dasd_psf_prssd_data
*prssdp
;
713 struct dasd_rssd_features
*features
;
714 struct dasd_ccw_req
*cqr
;
717 struct dasd_eckd_private
*private;
719 private = (struct dasd_eckd_private
*) device
->private;
720 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
721 1 /* PSF */ + 1 /* RSSD */ ,
722 (sizeof(struct dasd_psf_prssd_data
) +
723 sizeof(struct dasd_rssd_features
)),
726 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
727 "Could not allocate initialization request");
730 cqr
->startdev
= device
;
731 cqr
->memdev
= device
;
733 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
735 cqr
->expires
= 10 * HZ
;
737 /* Prepare for Read Subsystem Data */
738 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
739 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
740 prssdp
->order
= PSF_ORDER_PRSSD
;
741 prssdp
->suborder
= 0x41; /* Read Feature Codes */
742 /* all other bytes of prssdp must be zero */
745 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
746 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
747 ccw
->flags
|= CCW_FLAG_CC
;
748 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
750 /* Read Subsystem Data - feature codes */
751 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
752 memset(features
, 0, sizeof(struct dasd_rssd_features
));
755 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
756 ccw
->count
= sizeof(struct dasd_rssd_features
);
757 ccw
->cda
= (__u32
)(addr_t
) features
;
759 cqr
->buildclk
= get_clock();
760 cqr
->status
= DASD_CQR_FILLED
;
761 rc
= dasd_sleep_on(cqr
);
763 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
764 features
= (struct dasd_rssd_features
*) (prssdp
+ 1);
765 memcpy(&private->features
, features
,
766 sizeof(struct dasd_rssd_features
));
768 dasd_sfree_request(cqr
, cqr
->memdev
);
774 * Build CP for Perform Subsystem Function - SSC.
776 static struct dasd_ccw_req
*dasd_eckd_build_psf_ssc(struct dasd_device
*device
)
778 struct dasd_ccw_req
*cqr
;
779 struct dasd_psf_ssc_data
*psf_ssc_data
;
782 cqr
= dasd_smalloc_request("ECKD", 1 /* PSF */ ,
783 sizeof(struct dasd_psf_ssc_data
),
787 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
788 "Could not allocate PSF-SSC request");
791 psf_ssc_data
= (struct dasd_psf_ssc_data
*)cqr
->data
;
792 psf_ssc_data
->order
= PSF_ORDER_SSC
;
793 psf_ssc_data
->suborder
= 0x88;
794 psf_ssc_data
->reserved
[0] = 0x88;
797 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
798 ccw
->cda
= (__u32
)(addr_t
)psf_ssc_data
;
801 cqr
->startdev
= device
;
802 cqr
->memdev
= device
;
804 cqr
->expires
= 10*HZ
;
805 cqr
->buildclk
= get_clock();
806 cqr
->status
= DASD_CQR_FILLED
;
811 * Perform Subsystem Function.
812 * It is necessary to trigger CIO for channel revalidation since this
813 * call might change behaviour of DASD devices.
816 dasd_eckd_psf_ssc(struct dasd_device
*device
)
818 struct dasd_ccw_req
*cqr
;
821 cqr
= dasd_eckd_build_psf_ssc(device
);
825 rc
= dasd_sleep_on(cqr
);
827 /* trigger CIO to reprobe devices */
828 css_schedule_reprobe();
829 dasd_sfree_request(cqr
, cqr
->memdev
);
834 * Valide storage server of current device.
836 static int dasd_eckd_validate_server(struct dasd_device
*device
)
839 struct dasd_eckd_private
*private;
841 /* Currently PAV is the only reason to 'validate' server on LPAR */
842 if (dasd_nopav
|| MACHINE_IS_VM
)
845 rc
= dasd_eckd_psf_ssc(device
);
846 /* may be requested feature is not available on server,
847 * therefore just report error and go ahead */
848 private = (struct dasd_eckd_private
*) device
->private;
849 DEV_MESSAGE(KERN_INFO
, device
,
850 "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
851 private->uid
.vendor
, private->uid
.serial
,
852 private->uid
.ssid
, rc
);
853 /* RE-Read Configuration Data */
854 return dasd_eckd_read_conf(device
);
858 * Check device characteristics.
859 * If the device is accessible using ECKD discipline, the device is enabled.
862 dasd_eckd_check_characteristics(struct dasd_device
*device
)
864 struct dasd_eckd_private
*private;
865 struct dasd_block
*block
;
869 private = (struct dasd_eckd_private
*) device
->private;
870 if (private == NULL
) {
871 private = kzalloc(sizeof(struct dasd_eckd_private
),
872 GFP_KERNEL
| GFP_DMA
);
873 if (private == NULL
) {
874 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
875 "memory allocation failed for private "
879 device
->private = (void *) private;
881 /* Invalidate status of initial analysis. */
882 private->init_cqr_status
= -1;
883 /* Set default cache operations. */
884 private->attrib
.operation
= DASD_NORMAL_CACHE
;
885 private->attrib
.nr_cyl
= 0;
887 /* Read Configuration Data */
888 rc
= dasd_eckd_read_conf(device
);
892 /* Generate device unique id and register in devmap */
893 rc
= dasd_eckd_generate_uid(device
, &private->uid
);
896 dasd_set_uid(device
->cdev
, &private->uid
);
898 if (private->uid
.type
== UA_BASE_DEVICE
) {
899 block
= dasd_alloc_block();
901 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
902 "could not allocate dasd block structure");
906 device
->block
= block
;
907 block
->base
= device
;
910 /* register lcu with alias handling, enable PAV if this is a new lcu */
911 is_known
= dasd_alias_make_device_known_to_lcu(device
);
918 rc
= dasd_eckd_validate_server(device
); /* will switch pav on */
923 /* Read Feature Codes */
924 rc
= dasd_eckd_read_features(device
);
928 /* Read Device Characteristics */
929 rdc_data
= (void *) &(private->rdc_data
);
930 memset(rdc_data
, 0, sizeof(rdc_data
));
931 rc
= dasd_generic_read_dev_chars(device
, "ECKD", &rdc_data
, 64);
933 DEV_MESSAGE(KERN_WARNING
, device
,
934 "Read device characteristics returned "
938 DEV_MESSAGE(KERN_INFO
, device
,
939 "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
940 private->rdc_data
.dev_type
,
941 private->rdc_data
.dev_model
,
942 private->rdc_data
.cu_type
,
943 private->rdc_data
.cu_model
.model
,
944 private->rdc_data
.no_cyl
,
945 private->rdc_data
.trk_per_cyl
,
946 private->rdc_data
.sec_per_trk
);
950 dasd_alias_disconnect_device_from_lcu(device
);
952 dasd_free_block(device
->block
);
953 device
->block
= NULL
;
955 kfree(device
->private);
956 device
->private = NULL
;
960 static void dasd_eckd_uncheck_device(struct dasd_device
*device
)
962 dasd_alias_disconnect_device_from_lcu(device
);
965 static struct dasd_ccw_req
*
966 dasd_eckd_analysis_ccw(struct dasd_device
*device
)
968 struct dasd_eckd_private
*private;
969 struct eckd_count
*count_data
;
970 struct LO_eckd_data
*LO_data
;
971 struct dasd_ccw_req
*cqr
;
973 int cplength
, datasize
;
976 private = (struct dasd_eckd_private
*) device
->private;
979 datasize
= sizeof(struct DE_eckd_data
) + 2*sizeof(struct LO_eckd_data
);
980 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
981 cplength
, datasize
, device
);
985 /* Define extent for the first 3 tracks. */
986 define_extent(ccw
++, cqr
->data
, 0, 2,
987 DASD_ECKD_CCW_READ_COUNT
, device
);
988 LO_data
= cqr
->data
+ sizeof(struct DE_eckd_data
);
989 /* Locate record for the first 4 records on track 0. */
990 ccw
[-1].flags
|= CCW_FLAG_CC
;
991 locate_record(ccw
++, LO_data
++, 0, 0, 4,
992 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
994 count_data
= private->count_area
;
995 for (i
= 0; i
< 4; i
++) {
996 ccw
[-1].flags
|= CCW_FLAG_CC
;
997 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1000 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1005 /* Locate record for the first record on track 2. */
1006 ccw
[-1].flags
|= CCW_FLAG_CC
;
1007 locate_record(ccw
++, LO_data
++, 2, 0, 1,
1008 DASD_ECKD_CCW_READ_COUNT
, device
, 0);
1009 /* Read count ccw. */
1010 ccw
[-1].flags
|= CCW_FLAG_CC
;
1011 ccw
->cmd_code
= DASD_ECKD_CCW_READ_COUNT
;
1014 ccw
->cda
= (__u32
)(addr_t
) count_data
;
1017 cqr
->startdev
= device
;
1018 cqr
->memdev
= device
;
1020 cqr
->buildclk
= get_clock();
1021 cqr
->status
= DASD_CQR_FILLED
;
1026 * This is the callback function for the init_analysis cqr. It saves
1027 * the status of the initial analysis ccw before it frees it and kicks
1028 * the device to continue the startup sequence. This will call
1029 * dasd_eckd_do_analysis again (if the devices has not been marked
1030 * for deletion in the meantime).
1033 dasd_eckd_analysis_callback(struct dasd_ccw_req
*init_cqr
, void *data
)
1035 struct dasd_eckd_private
*private;
1036 struct dasd_device
*device
;
1038 device
= init_cqr
->startdev
;
1039 private = (struct dasd_eckd_private
*) device
->private;
1040 private->init_cqr_status
= init_cqr
->status
;
1041 dasd_sfree_request(init_cqr
, device
);
1042 dasd_kick_device(device
);
1046 dasd_eckd_start_analysis(struct dasd_block
*block
)
1048 struct dasd_eckd_private
*private;
1049 struct dasd_ccw_req
*init_cqr
;
1051 private = (struct dasd_eckd_private
*) block
->base
->private;
1052 init_cqr
= dasd_eckd_analysis_ccw(block
->base
);
1053 if (IS_ERR(init_cqr
))
1054 return PTR_ERR(init_cqr
);
1055 init_cqr
->callback
= dasd_eckd_analysis_callback
;
1056 init_cqr
->callback_data
= NULL
;
1057 init_cqr
->expires
= 5*HZ
;
1058 dasd_add_request_head(init_cqr
);
1063 dasd_eckd_end_analysis(struct dasd_block
*block
)
1065 struct dasd_device
*device
;
1066 struct dasd_eckd_private
*private;
1067 struct eckd_count
*count_area
;
1068 unsigned int sb
, blk_per_trk
;
1071 device
= block
->base
;
1072 private = (struct dasd_eckd_private
*) device
->private;
1073 status
= private->init_cqr_status
;
1074 private->init_cqr_status
= -1;
1075 if (status
!= DASD_CQR_DONE
) {
1076 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1077 "volume analysis returned unformatted disk");
1078 return -EMEDIUMTYPE
;
1081 private->uses_cdl
= 1;
1082 /* Calculate number of blocks/records per track. */
1083 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
1084 /* Check Track 0 for Compatible Disk Layout */
1086 for (i
= 0; i
< 3; i
++) {
1087 if (private->count_area
[i
].kl
!= 4 ||
1088 private->count_area
[i
].dl
!= dasd_eckd_cdl_reclen(i
) - 4) {
1089 private->uses_cdl
= 0;
1094 count_area
= &private->count_area
[4];
1096 if (private->uses_cdl
== 0) {
1097 for (i
= 0; i
< 5; i
++) {
1098 if ((private->count_area
[i
].kl
!= 0) ||
1099 (private->count_area
[i
].dl
!=
1100 private->count_area
[0].dl
))
1104 count_area
= &private->count_area
[0];
1106 if (private->count_area
[3].record
== 1)
1107 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1108 "Trk 0: no records after VTOC!");
1110 if (count_area
!= NULL
&& count_area
->kl
== 0) {
1111 /* we found notthing violating our disk layout */
1112 if (dasd_check_blocksize(count_area
->dl
) == 0)
1113 block
->bp_block
= count_area
->dl
;
1115 if (block
->bp_block
== 0) {
1116 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1117 "Volume has incompatible disk layout");
1118 return -EMEDIUMTYPE
;
1120 block
->s2b_shift
= 0; /* bits to shift 512 to get a block */
1121 for (sb
= 512; sb
< block
->bp_block
; sb
= sb
<< 1)
1124 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, block
->bp_block
);
1125 block
->blocks
= (private->rdc_data
.no_cyl
*
1126 private->rdc_data
.trk_per_cyl
*
1129 DEV_MESSAGE(KERN_INFO
, device
,
1130 "(%dkB blks): %dkB at %dkB/trk %s",
1131 (block
->bp_block
>> 10),
1132 ((private->rdc_data
.no_cyl
*
1133 private->rdc_data
.trk_per_cyl
*
1134 blk_per_trk
* (block
->bp_block
>> 9)) >> 1),
1135 ((blk_per_trk
* block
->bp_block
) >> 10),
1137 "compatible disk layout" : "linux disk layout");
1142 static int dasd_eckd_do_analysis(struct dasd_block
*block
)
1144 struct dasd_eckd_private
*private;
1146 private = (struct dasd_eckd_private
*) block
->base
->private;
1147 if (private->init_cqr_status
< 0)
1148 return dasd_eckd_start_analysis(block
);
1150 return dasd_eckd_end_analysis(block
);
1153 static int dasd_eckd_ready_to_online(struct dasd_device
*device
)
1155 return dasd_alias_add_device(device
);
1158 static int dasd_eckd_online_to_ready(struct dasd_device
*device
)
1160 return dasd_alias_remove_device(device
);
1164 dasd_eckd_fill_geometry(struct dasd_block
*block
, struct hd_geometry
*geo
)
1166 struct dasd_eckd_private
*private;
1168 private = (struct dasd_eckd_private
*) block
->base
->private;
1169 if (dasd_check_blocksize(block
->bp_block
) == 0) {
1170 geo
->sectors
= recs_per_track(&private->rdc_data
,
1171 0, block
->bp_block
);
1173 geo
->cylinders
= private->rdc_data
.no_cyl
;
1174 geo
->heads
= private->rdc_data
.trk_per_cyl
;
1178 static struct dasd_ccw_req
*
1179 dasd_eckd_format_device(struct dasd_device
* device
,
1180 struct format_data_t
* fdata
)
1182 struct dasd_eckd_private
*private;
1183 struct dasd_ccw_req
*fcp
;
1184 struct eckd_count
*ect
;
1188 int cplength
, datasize
;
1191 private = (struct dasd_eckd_private
*) device
->private;
1192 rpt
= recs_per_track(&private->rdc_data
, 0, fdata
->blksize
);
1193 cyl
= fdata
->start_unit
/ private->rdc_data
.trk_per_cyl
;
1194 head
= fdata
->start_unit
% private->rdc_data
.trk_per_cyl
;
1196 /* Sanity checks. */
1197 if (fdata
->start_unit
>=
1198 (private->rdc_data
.no_cyl
* private->rdc_data
.trk_per_cyl
)) {
1199 DEV_MESSAGE(KERN_INFO
, device
, "Track no %d too big!",
1201 return ERR_PTR(-EINVAL
);
1203 if (fdata
->start_unit
> fdata
->stop_unit
) {
1204 DEV_MESSAGE(KERN_INFO
, device
, "Track %d reached! ending.",
1206 return ERR_PTR(-EINVAL
);
1208 if (dasd_check_blocksize(fdata
->blksize
) != 0) {
1209 DEV_MESSAGE(KERN_WARNING
, device
,
1210 "Invalid blocksize %d...terminating!",
1212 return ERR_PTR(-EINVAL
);
1216 * fdata->intensity is a bit string that tells us what to do:
1217 * Bit 0: write record zero
1218 * Bit 1: write home address, currently not supported
1219 * Bit 2: invalidate tracks
1220 * Bit 3: use OS/390 compatible disk layout (cdl)
1221 * Only some bit combinations do make sense.
1223 switch (fdata
->intensity
) {
1224 case 0x00: /* Normal format */
1225 case 0x08: /* Normal format, use cdl. */
1227 datasize
= sizeof(struct DE_eckd_data
) +
1228 sizeof(struct LO_eckd_data
) +
1229 rpt
* sizeof(struct eckd_count
);
1231 case 0x01: /* Write record zero and format track. */
1232 case 0x09: /* Write record zero and format track, use cdl. */
1234 datasize
= sizeof(struct DE_eckd_data
) +
1235 sizeof(struct LO_eckd_data
) +
1236 sizeof(struct eckd_count
) +
1237 rpt
* sizeof(struct eckd_count
);
1239 case 0x04: /* Invalidate track. */
1240 case 0x0c: /* Invalidate track, use cdl. */
1242 datasize
= sizeof(struct DE_eckd_data
) +
1243 sizeof(struct LO_eckd_data
) +
1244 sizeof(struct eckd_count
);
1247 DEV_MESSAGE(KERN_WARNING
, device
, "Invalid flags 0x%x.",
1249 return ERR_PTR(-EINVAL
);
1251 /* Allocate the format ccw request. */
1252 fcp
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1253 cplength
, datasize
, device
);
1260 switch (fdata
->intensity
& ~0x08) {
1261 case 0x00: /* Normal format. */
1262 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
1263 fdata
->start_unit
, fdata
->start_unit
,
1264 DASD_ECKD_CCW_WRITE_CKD
, device
);
1265 data
+= sizeof(struct DE_eckd_data
);
1266 ccw
[-1].flags
|= CCW_FLAG_CC
;
1267 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
1268 fdata
->start_unit
, 0, rpt
,
1269 DASD_ECKD_CCW_WRITE_CKD
, device
,
1271 data
+= sizeof(struct LO_eckd_data
);
1273 case 0x01: /* Write record zero + format track. */
1274 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
1275 fdata
->start_unit
, fdata
->start_unit
,
1276 DASD_ECKD_CCW_WRITE_RECORD_ZERO
,
1278 data
+= sizeof(struct DE_eckd_data
);
1279 ccw
[-1].flags
|= CCW_FLAG_CC
;
1280 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
1281 fdata
->start_unit
, 0, rpt
+ 1,
1282 DASD_ECKD_CCW_WRITE_RECORD_ZERO
, device
,
1283 device
->block
->bp_block
);
1284 data
+= sizeof(struct LO_eckd_data
);
1286 case 0x04: /* Invalidate track. */
1287 define_extent(ccw
++, (struct DE_eckd_data
*) data
,
1288 fdata
->start_unit
, fdata
->start_unit
,
1289 DASD_ECKD_CCW_WRITE_CKD
, device
);
1290 data
+= sizeof(struct DE_eckd_data
);
1291 ccw
[-1].flags
|= CCW_FLAG_CC
;
1292 locate_record(ccw
++, (struct LO_eckd_data
*) data
,
1293 fdata
->start_unit
, 0, 1,
1294 DASD_ECKD_CCW_WRITE_CKD
, device
, 8);
1295 data
+= sizeof(struct LO_eckd_data
);
1298 if (fdata
->intensity
& 0x01) { /* write record zero */
1299 ect
= (struct eckd_count
*) data
;
1300 data
+= sizeof(struct eckd_count
);
1306 ccw
[-1].flags
|= CCW_FLAG_CC
;
1307 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_RECORD_ZERO
;
1308 ccw
->flags
= CCW_FLAG_SLI
;
1310 ccw
->cda
= (__u32
)(addr_t
) ect
;
1313 if ((fdata
->intensity
& ~0x08) & 0x04) { /* erase track */
1314 ect
= (struct eckd_count
*) data
;
1315 data
+= sizeof(struct eckd_count
);
1321 ccw
[-1].flags
|= CCW_FLAG_CC
;
1322 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
1323 ccw
->flags
= CCW_FLAG_SLI
;
1325 ccw
->cda
= (__u32
)(addr_t
) ect
;
1326 } else { /* write remaining records */
1327 for (i
= 0; i
< rpt
; i
++) {
1328 ect
= (struct eckd_count
*) data
;
1329 data
+= sizeof(struct eckd_count
);
1332 ect
->record
= i
+ 1;
1334 ect
->dl
= fdata
->blksize
;
1335 /* Check for special tracks 0-1 when formatting CDL */
1336 if ((fdata
->intensity
& 0x08) &&
1337 fdata
->start_unit
== 0) {
1340 ect
->dl
= sizes_trk0
[i
] - 4;
1343 if ((fdata
->intensity
& 0x08) &&
1344 fdata
->start_unit
== 1) {
1346 ect
->dl
= LABEL_SIZE
- 44;
1348 ccw
[-1].flags
|= CCW_FLAG_CC
;
1349 ccw
->cmd_code
= DASD_ECKD_CCW_WRITE_CKD
;
1350 ccw
->flags
= CCW_FLAG_SLI
;
1352 ccw
->cda
= (__u32
)(addr_t
) ect
;
1356 fcp
->startdev
= device
;
1357 fcp
->memdev
= device
;
1358 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &fcp
->flags
);
1359 fcp
->retries
= 5; /* set retry counter to enable default ERP */
1360 fcp
->buildclk
= get_clock();
1361 fcp
->status
= DASD_CQR_FILLED
;
1365 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req
*cqr
)
1367 cqr
->status
= DASD_CQR_FILLED
;
1368 if (cqr
->block
&& (cqr
->startdev
!= cqr
->block
->base
)) {
1369 dasd_eckd_reset_ccw_to_base_io(cqr
);
1370 cqr
->startdev
= cqr
->block
->base
;
1374 static dasd_erp_fn_t
1375 dasd_eckd_erp_action(struct dasd_ccw_req
* cqr
)
1377 struct dasd_device
*device
= (struct dasd_device
*) cqr
->startdev
;
1378 struct ccw_device
*cdev
= device
->cdev
;
1380 switch (cdev
->id
.cu_type
) {
1385 return dasd_3990_erp_action
;
1389 return dasd_default_erp_action
;
1393 static dasd_erp_fn_t
1394 dasd_eckd_erp_postaction(struct dasd_ccw_req
* cqr
)
1396 return dasd_default_erp_postaction
;
1400 static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device
*device
,
1405 /* first of all check for state change pending interrupt */
1406 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
1407 if ((irb
->scsw
.dstat
& mask
) == mask
) {
1408 dasd_generic_handle_state_change(device
);
1412 /* summary unit check */
1413 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) && irb
->ecw
[7] == 0x0D) {
1414 dasd_alias_handle_summary_unit_check(device
, irb
);
1419 /* service information message SIM */
1420 if ((irb
->ecw
[6] & DASD_SIM_SENSE
) == DASD_SIM_SENSE
) {
1421 dasd_3990_erp_handle_sim(device
, irb
->ecw
);
1425 /* just report other unsolicited interrupts */
1426 DEV_MESSAGE(KERN_DEBUG
, device
, "%s",
1427 "unsolicited interrupt received");
1428 device
->discipline
->dump_sense(device
, NULL
, irb
);
1429 dasd_schedule_device_bh(device
);
1434 static struct dasd_ccw_req
*dasd_eckd_build_cp(struct dasd_device
*startdev
,
1435 struct dasd_block
*block
,
1436 struct request
*req
)
1438 struct dasd_eckd_private
*private;
1439 unsigned long *idaws
;
1440 struct LO_eckd_data
*LO_data
;
1441 struct dasd_ccw_req
*cqr
;
1443 struct req_iterator iter
;
1446 unsigned int blksize
, blk_per_trk
, off
;
1447 int count
, cidaw
, cplength
, datasize
;
1448 sector_t recid
, first_rec
, last_rec
;
1449 sector_t first_trk
, last_trk
;
1450 unsigned int first_offs
, last_offs
;
1451 unsigned char cmd
, rcmd
;
1453 struct dasd_device
*basedev
;
1455 basedev
= block
->base
;
1456 private = (struct dasd_eckd_private
*) basedev
->private;
1457 if (rq_data_dir(req
) == READ
)
1458 cmd
= DASD_ECKD_CCW_READ_MT
;
1459 else if (rq_data_dir(req
) == WRITE
)
1460 cmd
= DASD_ECKD_CCW_WRITE_MT
;
1462 return ERR_PTR(-EINVAL
);
1463 /* Calculate number of blocks/records per track. */
1464 blksize
= block
->bp_block
;
1465 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1466 /* Calculate record id of first and last block. */
1467 first_rec
= first_trk
= req
->sector
>> block
->s2b_shift
;
1468 first_offs
= sector_div(first_trk
, blk_per_trk
);
1469 last_rec
= last_trk
=
1470 (req
->sector
+ req
->nr_sectors
- 1) >> block
->s2b_shift
;
1471 last_offs
= sector_div(last_trk
, blk_per_trk
);
1472 /* Check struct bio and count the number of blocks for the request. */
1475 rq_for_each_segment(bv
, req
, iter
) {
1476 if (bv
->bv_len
& (blksize
- 1))
1477 /* Eckd can only do full blocks. */
1478 return ERR_PTR(-EINVAL
);
1479 count
+= bv
->bv_len
>> (block
->s2b_shift
+ 9);
1480 #if defined(CONFIG_64BIT)
1481 if (idal_is_needed (page_address(bv
->bv_page
), bv
->bv_len
))
1482 cidaw
+= bv
->bv_len
>> (block
->s2b_shift
+ 9);
1486 if (count
!= last_rec
- first_rec
+ 1)
1487 return ERR_PTR(-EINVAL
);
1489 /* use the prefix command if available */
1490 use_prefix
= private->features
.feature
[8] & 0x01;
1492 /* 1x prefix + number of blocks */
1493 cplength
= 2 + count
;
1494 /* 1x prefix + cidaws*sizeof(long) */
1495 datasize
= sizeof(struct PFX_eckd_data
) +
1496 sizeof(struct LO_eckd_data
) +
1497 cidaw
* sizeof(unsigned long);
1499 /* 1x define extent + 1x locate record + number of blocks */
1500 cplength
= 2 + count
;
1501 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1502 datasize
= sizeof(struct DE_eckd_data
) +
1503 sizeof(struct LO_eckd_data
) +
1504 cidaw
* sizeof(unsigned long);
1506 /* Find out the number of additional locate record ccws for cdl. */
1507 if (private->uses_cdl
&& first_rec
< 2*blk_per_trk
) {
1508 if (last_rec
>= 2*blk_per_trk
)
1509 count
= 2*blk_per_trk
- first_rec
;
1511 datasize
+= count
*sizeof(struct LO_eckd_data
);
1513 /* Allocate the ccw request. */
1514 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1515 cplength
, datasize
, startdev
);
1519 /* First ccw is define extent or prefix. */
1521 if (prefix(ccw
++, cqr
->data
, first_trk
,
1522 last_trk
, cmd
, basedev
, startdev
) == -EAGAIN
) {
1523 /* Clock not in sync and XRC is enabled.
1526 dasd_sfree_request(cqr
, startdev
);
1527 return ERR_PTR(-EAGAIN
);
1529 idaws
= (unsigned long *) (cqr
->data
+
1530 sizeof(struct PFX_eckd_data
));
1532 if (define_extent(ccw
++, cqr
->data
, first_trk
,
1533 last_trk
, cmd
, startdev
) == -EAGAIN
) {
1534 /* Clock not in sync and XRC is enabled.
1537 dasd_sfree_request(cqr
, startdev
);
1538 return ERR_PTR(-EAGAIN
);
1540 idaws
= (unsigned long *) (cqr
->data
+
1541 sizeof(struct DE_eckd_data
));
1543 /* Build locate_record+read/write/ccws. */
1544 LO_data
= (struct LO_eckd_data
*) (idaws
+ cidaw
);
1546 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
) {
1547 /* Only standard blocks so there is just one locate record. */
1548 ccw
[-1].flags
|= CCW_FLAG_CC
;
1549 locate_record(ccw
++, LO_data
++, first_trk
, first_offs
+ 1,
1550 last_rec
- recid
+ 1, cmd
, basedev
, blksize
);
1552 rq_for_each_segment(bv
, req
, iter
) {
1553 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1554 if (dasd_page_cache
) {
1555 char *copy
= kmem_cache_alloc(dasd_page_cache
,
1556 GFP_DMA
| __GFP_NOWARN
);
1557 if (copy
&& rq_data_dir(req
) == WRITE
)
1558 memcpy(copy
+ bv
->bv_offset
, dst
, bv
->bv_len
);
1560 dst
= copy
+ bv
->bv_offset
;
1562 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1563 sector_t trkid
= recid
;
1564 unsigned int recoffs
= sector_div(trkid
, blk_per_trk
);
1567 /* Locate record for cdl special block ? */
1568 if (private->uses_cdl
&& recid
< 2*blk_per_trk
) {
1569 if (dasd_eckd_cdl_special(blk_per_trk
, recid
)){
1571 count
= dasd_eckd_cdl_reclen(recid
);
1572 if (count
< blksize
&&
1573 rq_data_dir(req
) == READ
)
1574 memset(dst
+ count
, 0xe5,
1577 ccw
[-1].flags
|= CCW_FLAG_CC
;
1578 locate_record(ccw
++, LO_data
++,
1580 1, rcmd
, basedev
, count
);
1582 /* Locate record for standard blocks ? */
1583 if (private->uses_cdl
&& recid
== 2*blk_per_trk
) {
1584 ccw
[-1].flags
|= CCW_FLAG_CC
;
1585 locate_record(ccw
++, LO_data
++,
1587 last_rec
- recid
+ 1,
1588 cmd
, basedev
, count
);
1590 /* Read/write ccw. */
1591 ccw
[-1].flags
|= CCW_FLAG_CC
;
1592 ccw
->cmd_code
= rcmd
;
1594 if (idal_is_needed(dst
, blksize
)) {
1595 ccw
->cda
= (__u32
)(addr_t
) idaws
;
1596 ccw
->flags
= CCW_FLAG_IDA
;
1597 idaws
= idal_create_words(idaws
, dst
, blksize
);
1599 ccw
->cda
= (__u32
)(addr_t
) dst
;
1607 if (req
->cmd_flags
& REQ_FAILFAST
)
1608 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1609 cqr
->startdev
= startdev
;
1610 cqr
->memdev
= startdev
;
1612 cqr
->expires
= 5 * 60 * HZ
; /* 5 minutes */
1613 cqr
->lpm
= private->path_data
.ppm
;
1615 cqr
->buildclk
= get_clock();
1616 cqr
->status
= DASD_CQR_FILLED
;
1621 dasd_eckd_free_cp(struct dasd_ccw_req
*cqr
, struct request
*req
)
1623 struct dasd_eckd_private
*private;
1625 struct req_iterator iter
;
1628 unsigned int blksize
, blk_per_trk
, off
;
1632 if (!dasd_page_cache
)
1634 private = (struct dasd_eckd_private
*) cqr
->block
->base
->private;
1635 blksize
= cqr
->block
->bp_block
;
1636 blk_per_trk
= recs_per_track(&private->rdc_data
, 0, blksize
);
1637 recid
= req
->sector
>> cqr
->block
->s2b_shift
;
1639 /* Skip over define extent & locate record. */
1641 if (private->uses_cdl
== 0 || recid
> 2*blk_per_trk
)
1643 rq_for_each_segment(bv
, req
, iter
) {
1644 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
1645 for (off
= 0; off
< bv
->bv_len
; off
+= blksize
) {
1646 /* Skip locate record. */
1647 if (private->uses_cdl
&& recid
<= 2*blk_per_trk
)
1650 if (ccw
->flags
& CCW_FLAG_IDA
)
1651 cda
= *((char **)((addr_t
) ccw
->cda
));
1653 cda
= (char *)((addr_t
) ccw
->cda
);
1655 if (rq_data_dir(req
) == READ
)
1656 memcpy(dst
, cda
, bv
->bv_len
);
1657 kmem_cache_free(dasd_page_cache
,
1658 (void *)((addr_t
)cda
& PAGE_MASK
));
1667 status
= cqr
->status
== DASD_CQR_DONE
;
1668 dasd_sfree_request(cqr
, cqr
->memdev
);
1673 * Modify ccw chain in cqr so it can be started on a base device.
1675 * Note that this is not enough to restart the cqr!
1676 * Either reset cqr->startdev as well (summary unit check handling)
1677 * or restart via separate cqr (as in ERP handling).
1679 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req
*cqr
)
1682 struct PFX_eckd_data
*pfxdata
;
1685 pfxdata
= cqr
->data
;
1687 if (ccw
->cmd_code
== DASD_ECKD_CCW_PFX
) {
1688 pfxdata
->validity
.verify_base
= 0;
1689 pfxdata
->validity
.hyper_pav
= 0;
1693 #define DASD_ECKD_CHANQ_MAX_SIZE 4
1695 static struct dasd_ccw_req
*dasd_eckd_build_alias_cp(struct dasd_device
*base
,
1696 struct dasd_block
*block
,
1697 struct request
*req
)
1699 struct dasd_eckd_private
*private;
1700 struct dasd_device
*startdev
;
1701 unsigned long flags
;
1702 struct dasd_ccw_req
*cqr
;
1704 startdev
= dasd_alias_get_start_dev(base
);
1707 private = (struct dasd_eckd_private
*) startdev
->private;
1708 if (private->count
>= DASD_ECKD_CHANQ_MAX_SIZE
)
1709 return ERR_PTR(-EBUSY
);
1711 spin_lock_irqsave(get_ccwdev_lock(startdev
->cdev
), flags
);
1713 cqr
= dasd_eckd_build_cp(startdev
, block
, req
);
1716 spin_unlock_irqrestore(get_ccwdev_lock(startdev
->cdev
), flags
);
1720 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req
*cqr
,
1721 struct request
*req
)
1723 struct dasd_eckd_private
*private;
1724 unsigned long flags
;
1726 spin_lock_irqsave(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
1727 private = (struct dasd_eckd_private
*) cqr
->memdev
->private;
1729 spin_unlock_irqrestore(get_ccwdev_lock(cqr
->memdev
->cdev
), flags
);
1730 return dasd_eckd_free_cp(cqr
, req
);
1734 dasd_eckd_fill_info(struct dasd_device
* device
,
1735 struct dasd_information2_t
* info
)
1737 struct dasd_eckd_private
*private;
1739 private = (struct dasd_eckd_private
*) device
->private;
1740 info
->label_block
= 2;
1741 info
->FBA_layout
= private->uses_cdl
? 0 : 1;
1742 info
->format
= private->uses_cdl
? DASD_FORMAT_CDL
: DASD_FORMAT_LDL
;
1743 info
->characteristics_size
= sizeof(struct dasd_eckd_characteristics
);
1744 memcpy(info
->characteristics
, &private->rdc_data
,
1745 sizeof(struct dasd_eckd_characteristics
));
1746 info
->confdata_size
= sizeof(struct dasd_eckd_confdata
);
1747 memcpy(info
->configuration_data
, &private->conf_data
,
1748 sizeof(struct dasd_eckd_confdata
));
1753 * SECTION: ioctl functions for eckd devices.
1757 * Release device ioctl.
1758 * Buils a channel programm to releases a prior reserved
1759 * (see dasd_eckd_reserve) device.
1762 dasd_eckd_release(struct dasd_device
*device
)
1764 struct dasd_ccw_req
*cqr
;
1767 if (!capable(CAP_SYS_ADMIN
))
1770 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1773 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1774 "Could not allocate initialization request");
1775 return PTR_ERR(cqr
);
1777 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RELEASE
;
1778 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1779 cqr
->cpaddr
->count
= 32;
1780 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1781 cqr
->startdev
= device
;
1782 cqr
->memdev
= device
;
1783 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1784 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1785 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
1786 cqr
->expires
= 2 * HZ
;
1787 cqr
->buildclk
= get_clock();
1788 cqr
->status
= DASD_CQR_FILLED
;
1790 rc
= dasd_sleep_on_immediatly(cqr
);
1792 dasd_sfree_request(cqr
, cqr
->memdev
);
1797 * Reserve device ioctl.
1798 * Options are set to 'synchronous wait for interrupt' and
1799 * 'timeout the request'. This leads to a terminate IO if
1800 * the interrupt is outstanding for a certain time.
1803 dasd_eckd_reserve(struct dasd_device
*device
)
1805 struct dasd_ccw_req
*cqr
;
1808 if (!capable(CAP_SYS_ADMIN
))
1811 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1814 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1815 "Could not allocate initialization request");
1816 return PTR_ERR(cqr
);
1818 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_RESERVE
;
1819 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1820 cqr
->cpaddr
->count
= 32;
1821 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1822 cqr
->startdev
= device
;
1823 cqr
->memdev
= device
;
1824 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1825 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1826 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
1827 cqr
->expires
= 2 * HZ
;
1828 cqr
->buildclk
= get_clock();
1829 cqr
->status
= DASD_CQR_FILLED
;
1831 rc
= dasd_sleep_on_immediatly(cqr
);
1833 dasd_sfree_request(cqr
, cqr
->memdev
);
1838 * Steal lock ioctl - unconditional reserve device.
1839 * Buils a channel programm to break a device's reservation.
1840 * (unconditional reserve)
1843 dasd_eckd_steal_lock(struct dasd_device
*device
)
1845 struct dasd_ccw_req
*cqr
;
1848 if (!capable(CAP_SYS_ADMIN
))
1851 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1854 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1855 "Could not allocate initialization request");
1856 return PTR_ERR(cqr
);
1858 cqr
->cpaddr
->cmd_code
= DASD_ECKD_CCW_SLCK
;
1859 cqr
->cpaddr
->flags
|= CCW_FLAG_SLI
;
1860 cqr
->cpaddr
->count
= 32;
1861 cqr
->cpaddr
->cda
= (__u32
)(addr_t
) cqr
->data
;
1862 cqr
->startdev
= device
;
1863 cqr
->memdev
= device
;
1864 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1865 set_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
);
1866 cqr
->retries
= 2; /* set retry counter to enable basic ERP */
1867 cqr
->expires
= 2 * HZ
;
1868 cqr
->buildclk
= get_clock();
1869 cqr
->status
= DASD_CQR_FILLED
;
1871 rc
= dasd_sleep_on_immediatly(cqr
);
1873 dasd_sfree_request(cqr
, cqr
->memdev
);
1878 * Read performance statistics
1881 dasd_eckd_performance(struct dasd_device
*device
, void __user
*argp
)
1883 struct dasd_psf_prssd_data
*prssdp
;
1884 struct dasd_rssd_perf_stats_t
*stats
;
1885 struct dasd_ccw_req
*cqr
;
1889 cqr
= dasd_smalloc_request(dasd_eckd_discipline
.name
,
1890 1 /* PSF */ + 1 /* RSSD */ ,
1891 (sizeof(struct dasd_psf_prssd_data
) +
1892 sizeof(struct dasd_rssd_perf_stats_t
)),
1895 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
1896 "Could not allocate initialization request");
1897 return PTR_ERR(cqr
);
1899 cqr
->startdev
= device
;
1900 cqr
->memdev
= device
;
1902 cqr
->expires
= 10 * HZ
;
1904 /* Prepare for Read Subsystem Data */
1905 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1906 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
1907 prssdp
->order
= PSF_ORDER_PRSSD
;
1908 prssdp
->suborder
= 0x01; /* Performance Statistics */
1909 prssdp
->varies
[1] = 0x01; /* Perf Statistics for the Subsystem */
1912 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
1913 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
1914 ccw
->flags
|= CCW_FLAG_CC
;
1915 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
1917 /* Read Subsystem Data - Performance Statistics */
1918 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1919 memset(stats
, 0, sizeof(struct dasd_rssd_perf_stats_t
));
1922 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
1923 ccw
->count
= sizeof(struct dasd_rssd_perf_stats_t
);
1924 ccw
->cda
= (__u32
)(addr_t
) stats
;
1926 cqr
->buildclk
= get_clock();
1927 cqr
->status
= DASD_CQR_FILLED
;
1928 rc
= dasd_sleep_on(cqr
);
1930 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
1931 stats
= (struct dasd_rssd_perf_stats_t
*) (prssdp
+ 1);
1932 if (copy_to_user(argp
, stats
,
1933 sizeof(struct dasd_rssd_perf_stats_t
)))
1936 dasd_sfree_request(cqr
, cqr
->memdev
);
1941 * Get attributes (cache operations)
1942 * Returnes the cache attributes used in Define Extend (DE).
1945 dasd_eckd_get_attrib(struct dasd_device
*device
, void __user
*argp
)
1947 struct dasd_eckd_private
*private =
1948 (struct dasd_eckd_private
*)device
->private;
1949 struct attrib_data_t attrib
= private->attrib
;
1952 if (!capable(CAP_SYS_ADMIN
))
1958 if (copy_to_user(argp
, (long *) &attrib
,
1959 sizeof(struct attrib_data_t
)))
1966 * Set attributes (cache operations)
1967 * Stores the attributes for cache operation to be used in Define Extend (DE).
1970 dasd_eckd_set_attrib(struct dasd_device
*device
, void __user
*argp
)
1972 struct dasd_eckd_private
*private =
1973 (struct dasd_eckd_private
*)device
->private;
1974 struct attrib_data_t attrib
;
1976 if (!capable(CAP_SYS_ADMIN
))
1981 if (copy_from_user(&attrib
, argp
, sizeof(struct attrib_data_t
)))
1983 private->attrib
= attrib
;
1985 DEV_MESSAGE(KERN_INFO
, device
,
1986 "cache operation mode set to %x (%i cylinder prestage)",
1987 private->attrib
.operation
, private->attrib
.nr_cyl
);
1992 dasd_eckd_ioctl(struct dasd_block
*block
, unsigned int cmd
, void __user
*argp
)
1994 struct dasd_device
*device
= block
->base
;
1998 return dasd_eckd_get_attrib(device
, argp
);
2000 return dasd_eckd_set_attrib(device
, argp
);
2002 return dasd_eckd_performance(device
, argp
);
2004 return dasd_eckd_release(device
);
2006 return dasd_eckd_reserve(device
);
2008 return dasd_eckd_steal_lock(device
);
2010 return -ENOIOCTLCMD
;
2015 * Dump the range of CCWs into 'page' buffer
2016 * and return number of printed chars.
2019 dasd_eckd_dump_ccw_range(struct ccw1
*from
, struct ccw1
*to
, char *page
)
2025 while (from
<= to
) {
2026 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2027 " CCW %p: %08X %08X DAT:",
2028 from
, ((int *) from
)[0], ((int *) from
)[1]);
2030 /* get pointer to data (consider IDALs) */
2031 if (from
->flags
& CCW_FLAG_IDA
)
2032 datap
= (char *) *((addr_t
*) (addr_t
) from
->cda
);
2034 datap
= (char *) ((addr_t
) from
->cda
);
2036 /* dump data (max 32 bytes) */
2037 for (count
= 0; count
< from
->count
&& count
< 32; count
++) {
2038 if (count
% 8 == 0) len
+= sprintf(page
+ len
, " ");
2039 if (count
% 4 == 0) len
+= sprintf(page
+ len
, " ");
2040 len
+= sprintf(page
+ len
, "%02x", datap
[count
]);
2042 len
+= sprintf(page
+ len
, "\n");
2049 * Print sense data and related channel program.
2050 * Parts are printed because printk buffer is only 1024 bytes.
2052 static void dasd_eckd_dump_sense(struct dasd_device
*device
,
2053 struct dasd_ccw_req
*req
, struct irb
*irb
)
2056 struct ccw1
*first
, *last
, *fail
, *from
, *to
;
2059 page
= (char *) get_zeroed_page(GFP_ATOMIC
);
2061 DEV_MESSAGE(KERN_ERR
, device
, " %s",
2062 "No memory to dump sense data");
2065 /* dump the sense data */
2066 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
2067 " I/O status report for device %s:\n",
2068 device
->cdev
->dev
.bus_id
);
2069 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2070 " in req: %p CS: 0x%02X DS: 0x%02X\n", req
,
2071 irb
->scsw
.cstat
, irb
->scsw
.dstat
);
2072 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2073 " device %s: Failing CCW: %p\n",
2074 device
->cdev
->dev
.bus_id
,
2075 (void *) (addr_t
) irb
->scsw
.cpa
);
2076 if (irb
->esw
.esw0
.erw
.cons
) {
2077 for (sl
= 0; sl
< 4; sl
++) {
2078 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2079 " Sense(hex) %2d-%2d:",
2080 (8 * sl
), ((8 * sl
) + 7));
2082 for (sct
= 0; sct
< 8; sct
++) {
2083 len
+= sprintf(page
+ len
, " %02x",
2084 irb
->ecw
[8 * sl
+ sct
]);
2086 len
+= sprintf(page
+ len
, "\n");
2089 if (irb
->ecw
[27] & DASD_SENSE_BIT_0
) {
2090 /* 24 Byte Sense Data */
2091 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2092 " 24 Byte: %x MSG %x, "
2093 "%s MSGb to SYSOP\n",
2094 irb
->ecw
[7] >> 4, irb
->ecw
[7] & 0x0f,
2095 irb
->ecw
[1] & 0x10 ? "" : "no");
2097 /* 32 Byte Sense Data */
2098 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2099 " 32 Byte: Format: %x "
2100 "Exception class %x\n",
2101 irb
->ecw
[6] & 0x0f, irb
->ecw
[22] >> 4);
2104 sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
2105 " SORRY - NO VALID SENSE AVAILABLE\n");
2110 /* req == NULL for unsolicited interrupts */
2111 /* dump the Channel Program (max 140 Bytes per line) */
2112 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
2113 first
= req
->cpaddr
;
2114 for (last
= first
; last
->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
); last
++);
2115 to
= min(first
+ 6, last
);
2116 len
= sprintf(page
, KERN_ERR PRINTK_HEADER
2117 " Related CP in req: %p\n", req
);
2118 dasd_eckd_dump_ccw_range(first
, to
, page
+ len
);
2121 /* print failing CCW area (maximum 4) */
2122 /* scsw->cda is either valid or zero */
2125 fail
= (struct ccw1
*)(addr_t
) irb
->scsw
.cpa
; /* failing CCW */
2126 if (from
< fail
- 2) {
2127 from
= fail
- 2; /* there is a gap - print header */
2128 len
+= sprintf(page
, KERN_ERR PRINTK_HEADER
"......\n");
2130 to
= min(fail
+ 1, last
);
2131 len
+= dasd_eckd_dump_ccw_range(from
, to
, page
+ len
);
2133 /* print last CCWs (maximum 2) */
2134 from
= max(from
, ++to
);
2135 if (from
< last
- 1) {
2136 from
= last
- 1; /* there is a gap - print header */
2137 len
+= sprintf(page
+ len
, KERN_ERR PRINTK_HEADER
"......\n");
2139 len
+= dasd_eckd_dump_ccw_range(from
, last
, page
+ len
);
2143 free_page((unsigned long) page
);
2147 * max_blocks is dependent on the amount of storage that is available
2148 * in the static io buffer for each device. Currently each device has
2149 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
2150 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
2151 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
2152 * addition we have one define extent ccw + 16 bytes of data and one
2153 * locate record ccw + 16 bytes of data. That makes:
2154 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
2155 * We want to fit two into the available memory so that we can immediately
2156 * start the next request if one finishes off. That makes 249.5 blocks
2157 * for one request. Give a little safety and the result is 240.
2159 static struct dasd_discipline dasd_eckd_discipline
= {
2160 .owner
= THIS_MODULE
,
2164 .check_device
= dasd_eckd_check_characteristics
,
2165 .uncheck_device
= dasd_eckd_uncheck_device
,
2166 .do_analysis
= dasd_eckd_do_analysis
,
2167 .ready_to_online
= dasd_eckd_ready_to_online
,
2168 .online_to_ready
= dasd_eckd_online_to_ready
,
2169 .fill_geometry
= dasd_eckd_fill_geometry
,
2170 .start_IO
= dasd_start_IO
,
2171 .term_IO
= dasd_term_IO
,
2172 .handle_terminated_request
= dasd_eckd_handle_terminated_request
,
2173 .format_device
= dasd_eckd_format_device
,
2174 .erp_action
= dasd_eckd_erp_action
,
2175 .erp_postaction
= dasd_eckd_erp_postaction
,
2176 .handle_unsolicited_interrupt
= dasd_eckd_handle_unsolicited_interrupt
,
2177 .build_cp
= dasd_eckd_build_alias_cp
,
2178 .free_cp
= dasd_eckd_free_alias_cp
,
2179 .dump_sense
= dasd_eckd_dump_sense
,
2180 .fill_info
= dasd_eckd_fill_info
,
2181 .ioctl
= dasd_eckd_ioctl
,
2185 dasd_eckd_init(void)
2187 ASCEBC(dasd_eckd_discipline
.ebcname
, 4);
2188 return ccw_driver_register(&dasd_eckd_driver
);
2192 dasd_eckd_cleanup(void)
2194 ccw_driver_unregister(&dasd_eckd_driver
);
2197 module_init(dasd_eckd_init
);
2198 module_exit(dasd_eckd_cleanup
);