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/init.h>
23
#include <asm/debug.h>
24
#include <asm/idals.h>
25
#include <asm/ebcdic.h>
26
#include <asm/compat.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];
757
* Generate device unique id that specifies the physical device.
759
static int dasd_eckd_generate_uid(struct dasd_device *device)
761
struct dasd_eckd_private *private;
762
struct dasd_uid *uid;
766
private = (struct dasd_eckd_private *) device->private;
769
if (!private->ned || !private->gneq)
772
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
773
memset(uid, 0, sizeof(struct dasd_uid));
774
memcpy(uid->vendor, private->ned->HDA_manufacturer,
775
sizeof(uid->vendor) - 1);
776
EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
777
memcpy(uid->serial, private->ned->HDA_location,
778
sizeof(uid->serial) - 1);
779
EBCASC(uid->serial, sizeof(uid->serial) - 1);
780
uid->ssid = private->gneq->subsystemID;
781
uid->real_unit_addr = private->ned->unit_addr;
783
uid->type = private->sneq->sua_flags;
784
if (uid->type == UA_BASE_PAV_ALIAS)
785
uid->base_unit_addr = private->sneq->base_unit_addr;
787
uid->type = UA_BASE_DEVICE;
789
if (private->vdsneq) {
790
for (count = 0; count < 16; count++) {
791
sprintf(uid->vduit+2*count, "%02x",
792
private->vdsneq->uit[count]);
795
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
799
static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
801
struct dasd_eckd_private *private;
804
if (device->private) {
805
private = (struct dasd_eckd_private *)device->private;
806
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
808
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
814
static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
815
struct dasd_ccw_req *cqr,
821
* buffer has to start with EBCDIC "V1.0" to show
822
* support for virtual device SNEQ
824
rcd_buffer[0] = 0xE5;
825
rcd_buffer[1] = 0xF1;
826
rcd_buffer[2] = 0x4B;
827
rcd_buffer[3] = 0xF0;
830
ccw->cmd_code = DASD_ECKD_CCW_RCD;
832
ccw->cda = (__u32)(addr_t)rcd_buffer;
833
ccw->count = DASD_ECKD_RCD_DATA_SIZE;
834
cqr->magic = DASD_ECKD_MAGIC;
836
cqr->startdev = device;
837
cqr->memdev = device;
839
cqr->expires = 10*HZ;
842
cqr->buildclk = get_clock();
843
cqr->status = DASD_CQR_FILLED;
844
set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
848
* Wakeup helper for read_conf
849
* if the cqr is not done and needs some error recovery
850
* the buffer has to be re-initialized with the EBCDIC "V1.0"
851
* to show support for virtual device SNEQ
853
static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
858
if (cqr->status != DASD_CQR_DONE) {
860
rcd_buffer = (__u8 *)((addr_t) ccw->cda);
861
memset(rcd_buffer, 0, sizeof(*rcd_buffer));
863
rcd_buffer[0] = 0xE5;
864
rcd_buffer[1] = 0xF1;
865
rcd_buffer[2] = 0x4B;
866
rcd_buffer[3] = 0xF0;
868
dasd_wakeup_cb(cqr, data);
871
static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
872
struct dasd_ccw_req *cqr,
879
* sanity check: scan for RCD command in extended SenseID data
880
* some devices do not support RCD
882
ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
883
if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
886
dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
887
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
888
set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
890
cqr->callback = read_conf_cb;
891
rc = dasd_sleep_on_immediatly(cqr);
895
static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
897
int *rcd_buffer_size, __u8 lpm)
900
char *rcd_buf = NULL;
902
struct dasd_ccw_req *cqr;
905
* sanity check: scan for RCD command in extended SenseID data
906
* some devices do not support RCD
908
ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
909
if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
913
rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
918
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
919
0, /* use rcd_buf as data ara */
922
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
923
"Could not allocate RCD request");
927
dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
928
cqr->callback = read_conf_cb;
929
ret = dasd_sleep_on(cqr);
931
* on success we update the user input parms
933
dasd_sfree_request(cqr, cqr->memdev);
937
*rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
938
*rcd_buffer = rcd_buf;
943
*rcd_buffer_size = 0;
947
static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
950
struct dasd_sneq *sneq;
954
private->sneq = NULL;
955
private->vdsneq = NULL;
956
private->gneq = NULL;
957
count = private->conf_len / sizeof(struct dasd_sneq);
958
sneq = (struct dasd_sneq *)private->conf_data;
959
for (i = 0; i < count; ++i) {
960
if (sneq->flags.identifier == 1 && sneq->format == 1)
961
private->sneq = sneq;
962
else if (sneq->flags.identifier == 1 && sneq->format == 4)
963
private->vdsneq = (struct vd_sneq *)sneq;
964
else if (sneq->flags.identifier == 2)
965
private->gneq = (struct dasd_gneq *)sneq;
966
else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
967
private->ned = (struct dasd_ned *)sneq;
970
if (!private->ned || !private->gneq) {
972
private->sneq = NULL;
973
private->vdsneq = NULL;
974
private->gneq = NULL;
981
static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
983
struct dasd_gneq *gneq;
986
count = conf_len / sizeof(*gneq);
987
gneq = (struct dasd_gneq *)conf_data;
989
for (i = 0; i < count; ++i) {
990
if (gneq->flags.identifier == 2) {
997
return ((char *)gneq)[18] & 0x07;
1002
static int dasd_eckd_read_conf(struct dasd_device *device)
1005
int conf_len, conf_data_saved;
1008
struct dasd_eckd_private *private;
1009
struct dasd_path *path_data;
1011
private = (struct dasd_eckd_private *) device->private;
1012
path_data = &device->path_data;
1013
opm = ccw_device_get_path_mask(device->cdev);
1015
conf_data_saved = 0;
1016
/* get configuration data per operational path */
1017
for (lpm = 0x80; lpm; lpm>>= 1) {
1019
rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1021
if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1022
DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1023
"Read configuration data returned "
1027
if (conf_data == NULL) {
1028
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1029
"No configuration data "
1031
/* no further analysis possible */
1032
path_data->opm |= lpm;
1033
continue; /* no error */
1035
/* save first valid configuration data */
1036
if (!conf_data_saved) {
1037
kfree(private->conf_data);
1038
private->conf_data = conf_data;
1039
private->conf_len = conf_len;
1040
if (dasd_eckd_identify_conf_parts(private)) {
1041
private->conf_data = NULL;
1042
private->conf_len = 0;
1048
switch (dasd_eckd_path_access(conf_data, conf_len)) {
1050
path_data->npm |= lpm;
1053
path_data->ppm |= lpm;
1056
path_data->opm |= lpm;
1057
if (conf_data != private->conf_data)
1064
static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1066
struct dasd_eckd_private *private;
1070
private = (struct dasd_eckd_private *) device->private;
1071
if (private->fcx_max_data) {
1072
mdc = ccw_device_get_mdc(device->cdev, lpm);
1074
dev_warn(&device->cdev->dev,
1075
"Detecting the maximum data size for zHPF "
1076
"requests failed (rc=%d) for a new path %x\n",
1080
fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1081
if (fcx_max_data < private->fcx_max_data) {
1082
dev_warn(&device->cdev->dev,
1083
"The maximum data size for zHPF requests %u "
1084
"on a new path %x is below the active maximum "
1085
"%u\n", fcx_max_data, lpm,
1086
private->fcx_max_data);
1093
static void do_path_verification_work(struct work_struct *work)
1095
struct path_verification_work_data *data;
1096
struct dasd_device *device;
1097
__u8 lpm, opm, npm, ppm, epm;
1098
unsigned long flags;
1101
data = container_of(work, struct path_verification_work_data, worker);
1102
device = data->device;
1104
/* delay path verification until device was resumed */
1105
if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1106
schedule_work(work);
1114
for (lpm = 0x80; lpm; lpm >>= 1) {
1115
if (lpm & data->tbvpm) {
1116
memset(data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1117
memset(&data->cqr, 0, sizeof(data->cqr));
1118
data->cqr.cpaddr = &data->ccw;
1119
rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1123
switch (dasd_eckd_path_access(data->rcd_buffer,
1124
DASD_ECKD_RCD_DATA_SIZE)) {
1133
} else if (rc == -EOPNOTSUPP) {
1134
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1135
"path verification: No configuration "
1138
} else if (rc == -EAGAIN) {
1139
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1140
"path verification: device is stopped,"
1141
" try again later");
1144
dev_warn(&device->cdev->dev,
1145
"Reading device feature codes failed "
1146
"(rc=%d) for new path %x\n", rc, lpm);
1149
if (verify_fcx_max_data(device, lpm)) {
1157
* There is a small chance that a path is lost again between
1158
* above path verification and the following modification of
1159
* the device opm mask. We could avoid that race here by using
1160
* yet another path mask, but we rather deal with this unlikely
1161
* situation in dasd_start_IO.
1163
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1164
if (!device->path_data.opm && opm) {
1165
device->path_data.opm = opm;
1166
dasd_generic_path_operational(device);
1168
device->path_data.opm |= opm;
1169
device->path_data.npm |= npm;
1170
device->path_data.ppm |= ppm;
1171
device->path_data.tbvpm |= epm;
1172
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1174
dasd_put_device(device);
1176
mutex_unlock(&dasd_path_verification_mutex);
1181
static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1183
struct path_verification_work_data *data;
1185
data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1187
if (mutex_trylock(&dasd_path_verification_mutex)) {
1188
data = path_verification_worker;
1193
memset(data, 0, sizeof(*data));
1196
INIT_WORK(&data->worker, do_path_verification_work);
1197
dasd_get_device(device);
1198
data->device = device;
1200
schedule_work(&data->worker);
1204
static int dasd_eckd_read_features(struct dasd_device *device)
1206
struct dasd_psf_prssd_data *prssdp;
1207
struct dasd_rssd_features *features;
1208
struct dasd_ccw_req *cqr;
1211
struct dasd_eckd_private *private;
1213
private = (struct dasd_eckd_private *) device->private;
1214
memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1215
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1216
(sizeof(struct dasd_psf_prssd_data) +
1217
sizeof(struct dasd_rssd_features)),
1220
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1221
"allocate initialization request");
1222
return PTR_ERR(cqr);
1224
cqr->startdev = device;
1225
cqr->memdev = device;
1228
cqr->expires = 10 * HZ;
1230
/* Prepare for Read Subsystem Data */
1231
prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1232
memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1233
prssdp->order = PSF_ORDER_PRSSD;
1234
prssdp->suborder = 0x41; /* Read Feature Codes */
1235
/* all other bytes of prssdp must be zero */
1238
ccw->cmd_code = DASD_ECKD_CCW_PSF;
1239
ccw->count = sizeof(struct dasd_psf_prssd_data);
1240
ccw->flags |= CCW_FLAG_CC;
1241
ccw->cda = (__u32)(addr_t) prssdp;
1243
/* Read Subsystem Data - feature codes */
1244
features = (struct dasd_rssd_features *) (prssdp + 1);
1245
memset(features, 0, sizeof(struct dasd_rssd_features));
1248
ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1249
ccw->count = sizeof(struct dasd_rssd_features);
1250
ccw->cda = (__u32)(addr_t) features;
1252
cqr->buildclk = get_clock();
1253
cqr->status = DASD_CQR_FILLED;
1254
rc = dasd_sleep_on(cqr);
1256
prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1257
features = (struct dasd_rssd_features *) (prssdp + 1);
1258
memcpy(&private->features, features,
1259
sizeof(struct dasd_rssd_features));
1261
dev_warn(&device->cdev->dev, "Reading device feature codes"
1262
" failed with rc=%d\n", rc);
1263
dasd_sfree_request(cqr, cqr->memdev);
1269
* Build CP for Perform Subsystem Function - SSC.
1271
static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1274
struct dasd_ccw_req *cqr;
1275
struct dasd_psf_ssc_data *psf_ssc_data;
1278
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1279
sizeof(struct dasd_psf_ssc_data),
1283
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1284
"Could not allocate PSF-SSC request");
1287
psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1288
psf_ssc_data->order = PSF_ORDER_SSC;
1289
psf_ssc_data->suborder = 0xc0;
1291
psf_ssc_data->suborder |= 0x08;
1292
psf_ssc_data->reserved[0] = 0x88;
1295
ccw->cmd_code = DASD_ECKD_CCW_PSF;
1296
ccw->cda = (__u32)(addr_t)psf_ssc_data;
1299
cqr->startdev = device;
1300
cqr->memdev = device;
1303
cqr->expires = 10*HZ;
1304
cqr->buildclk = get_clock();
1305
cqr->status = DASD_CQR_FILLED;
1310
* Perform Subsystem Function.
1311
* It is necessary to trigger CIO for channel revalidation since this
1312
* call might change behaviour of DASD devices.
1315
dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1317
struct dasd_ccw_req *cqr;
1320
cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1322
return PTR_ERR(cqr);
1324
rc = dasd_sleep_on(cqr);
1326
/* trigger CIO to reprobe devices */
1327
css_schedule_reprobe();
1328
dasd_sfree_request(cqr, cqr->memdev);
1333
* Valide storage server of current device.
1335
static void dasd_eckd_validate_server(struct dasd_device *device)
1338
struct dasd_eckd_private *private;
1341
if (dasd_nopav || MACHINE_IS_VM)
1345
rc = dasd_eckd_psf_ssc(device, enable_pav);
1347
/* may be requested feature is not available on server,
1348
* therefore just report error and go ahead */
1349
private = (struct dasd_eckd_private *) device->private;
1350
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1351
"returned rc=%d", private->uid.ssid, rc);
1354
static u32 get_fcx_max_data(struct dasd_device *device)
1356
#if defined(CONFIG_64BIT)
1358
int fcx_in_css, fcx_in_gneq, fcx_in_features;
1359
struct dasd_eckd_private *private;
1363
/* is transport mode supported? */
1364
private = (struct dasd_eckd_private *) device->private;
1365
fcx_in_css = css_general_characteristics.fcx;
1366
fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1367
fcx_in_features = private->features.feature[40] & 0x80;
1368
tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1373
mdc = ccw_device_get_mdc(device->cdev, 0);
1375
dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1376
" data size for zHPF requests failed\n");
1379
return mdc * FCX_MAX_DATA_FACTOR;
1386
* Check device characteristics.
1387
* If the device is accessible using ECKD discipline, the device is enabled.
1390
dasd_eckd_check_characteristics(struct dasd_device *device)
1392
struct dasd_eckd_private *private;
1393
struct dasd_block *block;
1394
struct dasd_uid temp_uid;
1395
int is_known, rc, i;
1397
unsigned long value;
1399
if (!ccw_device_is_pathgroup(device->cdev)) {
1400
dev_warn(&device->cdev->dev,
1401
"A channel path group could not be established\n");
1404
if (!ccw_device_is_multipath(device->cdev)) {
1405
dev_info(&device->cdev->dev,
1406
"The DASD is not operating in multipath mode\n");
1408
private = (struct dasd_eckd_private *) device->private;
1410
private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1412
dev_warn(&device->cdev->dev,
1413
"Allocating memory for private DASD data "
1417
device->private = (void *) private;
1419
memset(private, 0, sizeof(*private));
1421
/* Invalidate status of initial analysis. */
1422
private->init_cqr_status = -1;
1423
/* Set default cache operations. */
1424
private->attrib.operation = DASD_NORMAL_CACHE;
1425
private->attrib.nr_cyl = 0;
1427
/* Read Configuration Data */
1428
rc = dasd_eckd_read_conf(device);
1432
/* set default timeout */
1433
device->default_expires = DASD_EXPIRES;
1434
if (private->gneq) {
1436
for (i = 0; i < private->gneq->timeout.value; i++)
1438
value = value * private->gneq->timeout.number;
1439
/* do not accept useless values */
1440
if (value != 0 && value <= DASD_EXPIRES_MAX)
1441
device->default_expires = value;
1444
/* Generate device unique id */
1445
rc = dasd_eckd_generate_uid(device);
1449
dasd_eckd_get_uid(device, &temp_uid);
1450
if (temp_uid.type == UA_BASE_DEVICE) {
1451
block = dasd_alloc_block();
1452
if (IS_ERR(block)) {
1453
DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1454
"could not allocate dasd "
1456
rc = PTR_ERR(block);
1459
device->block = block;
1460
block->base = device;
1463
/* register lcu with alias handling, enable PAV if this is a new lcu */
1464
is_known = dasd_alias_make_device_known_to_lcu(device);
1470
* dasd_eckd_validate_server is done on the first device that
1471
* is found for an LCU. All later other devices have to wait
1472
* for it, so they will read the correct feature codes.
1475
dasd_eckd_validate_server(device);
1476
dasd_alias_lcu_setup_complete(device);
1478
dasd_alias_wait_for_lcu_setup(device);
1480
/* device may report different configuration data after LCU setup */
1481
rc = dasd_eckd_read_conf(device);
1485
/* Read Feature Codes */
1486
dasd_eckd_read_features(device);
1488
/* Read Device Characteristics */
1489
rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1490
&private->rdc_data, 64);
1492
DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1493
"Read device characteristic failed, rc=%d", rc);
1497
if ((device->features & DASD_FEATURE_USERAW) &&
1498
!(private->rdc_data.facilities.RT_in_LR)) {
1499
dev_err(&device->cdev->dev, "The storage server does not "
1500
"support raw-track access\n");
1505
/* find the valid cylinder size */
1506
if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1507
private->rdc_data.long_no_cyl)
1508
private->real_cyl = private->rdc_data.long_no_cyl;
1510
private->real_cyl = private->rdc_data.no_cyl;
1512
private->fcx_max_data = get_fcx_max_data(device);
1514
readonly = dasd_device_is_ro(device);
1516
set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1518
dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1519
"with %d cylinders, %d heads, %d sectors%s\n",
1520
private->rdc_data.dev_type,
1521
private->rdc_data.dev_model,
1522
private->rdc_data.cu_type,
1523
private->rdc_data.cu_model.model,
1525
private->rdc_data.trk_per_cyl,
1526
private->rdc_data.sec_per_trk,
1527
readonly ? ", read-only device" : "");
1531
dasd_alias_disconnect_device_from_lcu(device);
1533
dasd_free_block(device->block);
1534
device->block = NULL;
1536
kfree(private->conf_data);
1537
kfree(device->private);
1538
device->private = NULL;
1542
static void dasd_eckd_uncheck_device(struct dasd_device *device)
1544
struct dasd_eckd_private *private;
1546
private = (struct dasd_eckd_private *) device->private;
1547
dasd_alias_disconnect_device_from_lcu(device);
1548
private->ned = NULL;
1549
private->sneq = NULL;
1550
private->vdsneq = NULL;
1551
private->gneq = NULL;
1552
private->conf_len = 0;
1553
kfree(private->conf_data);
1554
private->conf_data = NULL;
1557
static struct dasd_ccw_req *
1558
dasd_eckd_analysis_ccw(struct dasd_device *device)
1560
struct dasd_eckd_private *private;
1561
struct eckd_count *count_data;
1562
struct LO_eckd_data *LO_data;
1563
struct dasd_ccw_req *cqr;
1565
int cplength, datasize;
1568
private = (struct dasd_eckd_private *) device->private;
1571
datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1572
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1576
/* Define extent for the first 3 tracks. */
1577
define_extent(ccw++, cqr->data, 0, 2,
1578
DASD_ECKD_CCW_READ_COUNT, device);
1579
LO_data = cqr->data + sizeof(struct DE_eckd_data);
1580
/* Locate record for the first 4 records on track 0. */
1581
ccw[-1].flags |= CCW_FLAG_CC;
1582
locate_record(ccw++, LO_data++, 0, 0, 4,
1583
DASD_ECKD_CCW_READ_COUNT, device, 0);
1585
count_data = private->count_area;
1586
for (i = 0; i < 4; i++) {
1587
ccw[-1].flags |= CCW_FLAG_CC;
1588
ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1591
ccw->cda = (__u32)(addr_t) count_data;
1596
/* Locate record for the first record on track 2. */
1597
ccw[-1].flags |= CCW_FLAG_CC;
1598
locate_record(ccw++, LO_data++, 2, 0, 1,
1599
DASD_ECKD_CCW_READ_COUNT, device, 0);
1600
/* Read count ccw. */
1601
ccw[-1].flags |= CCW_FLAG_CC;
1602
ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1605
ccw->cda = (__u32)(addr_t) count_data;
1608
cqr->startdev = device;
1609
cqr->memdev = device;
1611
cqr->buildclk = get_clock();
1612
cqr->status = DASD_CQR_FILLED;
1616
/* differentiate between 'no record found' and any other error */
1617
static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1620
if (init_cqr->status == DASD_CQR_DONE)
1622
else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1623
init_cqr->status == DASD_CQR_FAILED) {
1624
sense = dasd_get_sense(&init_cqr->irb);
1625
if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1626
return INIT_CQR_UNFORMATTED;
1628
return INIT_CQR_ERROR;
1630
return INIT_CQR_ERROR;
1634
* This is the callback function for the init_analysis cqr. It saves
1635
* the status of the initial analysis ccw before it frees it and kicks
1636
* the device to continue the startup sequence. This will call
1637
* dasd_eckd_do_analysis again (if the devices has not been marked
1638
* for deletion in the meantime).
1640
static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1643
struct dasd_eckd_private *private;
1644
struct dasd_device *device;
1646
device = init_cqr->startdev;
1647
private = (struct dasd_eckd_private *) device->private;
1648
private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1649
dasd_sfree_request(init_cqr, device);
1650
dasd_kick_device(device);
1653
static int dasd_eckd_start_analysis(struct dasd_block *block)
1655
struct dasd_ccw_req *init_cqr;
1657
init_cqr = dasd_eckd_analysis_ccw(block->base);
1658
if (IS_ERR(init_cqr))
1659
return PTR_ERR(init_cqr);
1660
init_cqr->callback = dasd_eckd_analysis_callback;
1661
init_cqr->callback_data = NULL;
1662
init_cqr->expires = 5*HZ;
1663
/* first try without ERP, so we can later handle unformatted
1664
* devices as special case
1666
clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1667
init_cqr->retries = 0;
1668
dasd_add_request_head(init_cqr);
1672
static int dasd_eckd_end_analysis(struct dasd_block *block)
1674
struct dasd_device *device;
1675
struct dasd_eckd_private *private;
1676
struct eckd_count *count_area;
1677
unsigned int sb, blk_per_trk;
1679
struct dasd_ccw_req *init_cqr;
1681
device = block->base;
1682
private = (struct dasd_eckd_private *) device->private;
1683
status = private->init_cqr_status;
1684
private->init_cqr_status = -1;
1685
if (status == INIT_CQR_ERROR) {
1686
/* try again, this time with full ERP */
1687
init_cqr = dasd_eckd_analysis_ccw(device);
1688
dasd_sleep_on(init_cqr);
1689
status = dasd_eckd_analysis_evaluation(init_cqr);
1690
dasd_sfree_request(init_cqr, device);
1693
if (device->features & DASD_FEATURE_USERAW) {
1694
block->bp_block = DASD_RAW_BLOCKSIZE;
1695
blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1696
block->s2b_shift = 3;
1700
if (status == INIT_CQR_UNFORMATTED) {
1701
dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1702
return -EMEDIUMTYPE;
1703
} else if (status == INIT_CQR_ERROR) {
1704
dev_err(&device->cdev->dev,
1705
"Detecting the DASD disk layout failed because "
1706
"of an I/O error\n");
1710
private->uses_cdl = 1;
1711
/* Check Track 0 for Compatible Disk Layout */
1713
for (i = 0; i < 3; i++) {
1714
if (private->count_area[i].kl != 4 ||
1715
private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1716
private->uses_cdl = 0;
1721
count_area = &private->count_area[4];
1723
if (private->uses_cdl == 0) {
1724
for (i = 0; i < 5; i++) {
1725
if ((private->count_area[i].kl != 0) ||
1726
(private->count_area[i].dl !=
1727
private->count_area[0].dl))
1731
count_area = &private->count_area[0];
1733
if (private->count_area[3].record == 1)
1734
dev_warn(&device->cdev->dev,
1735
"Track 0 has no records following the VTOC\n");
1738
if (count_area != NULL && count_area->kl == 0) {
1739
/* we found notthing violating our disk layout */
1740
if (dasd_check_blocksize(count_area->dl) == 0)
1741
block->bp_block = count_area->dl;
1743
if (block->bp_block == 0) {
1744
dev_warn(&device->cdev->dev,
1745
"The disk layout of the DASD is not supported\n");
1746
return -EMEDIUMTYPE;
1748
block->s2b_shift = 0; /* bits to shift 512 to get a block */
1749
for (sb = 512; sb < block->bp_block; sb = sb << 1)
1752
blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1755
block->blocks = (private->real_cyl *
1756
private->rdc_data.trk_per_cyl *
1759
dev_info(&device->cdev->dev,
1760
"DASD with %d KB/block, %d KB total size, %d KB/track, "
1761
"%s\n", (block->bp_block >> 10),
1762
((private->real_cyl *
1763
private->rdc_data.trk_per_cyl *
1764
blk_per_trk * (block->bp_block >> 9)) >> 1),
1765
((blk_per_trk * block->bp_block) >> 10),
1767
"compatible disk layout" : "linux disk layout");
1772
static int dasd_eckd_do_analysis(struct dasd_block *block)
1774
struct dasd_eckd_private *private;
1776
private = (struct dasd_eckd_private *) block->base->private;
1777
if (private->init_cqr_status < 0)
1778
return dasd_eckd_start_analysis(block);
1780
return dasd_eckd_end_analysis(block);
1783
static int dasd_eckd_ready_to_online(struct dasd_device *device)
1785
return dasd_alias_add_device(device);
1788
static int dasd_eckd_online_to_ready(struct dasd_device *device)
1790
cancel_work_sync(&device->reload_device);
1791
return dasd_alias_remove_device(device);
1795
dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1797
struct dasd_eckd_private *private;
1799
private = (struct dasd_eckd_private *) block->base->private;
1800
if (dasd_check_blocksize(block->bp_block) == 0) {
1801
geo->sectors = recs_per_track(&private->rdc_data,
1802
0, block->bp_block);
1804
geo->cylinders = private->rdc_data.no_cyl;
1805
geo->heads = private->rdc_data.trk_per_cyl;
1809
static struct dasd_ccw_req *
1810
dasd_eckd_format_device(struct dasd_device * device,
1811
struct format_data_t * fdata)
1813
struct dasd_eckd_private *private;
1814
struct dasd_ccw_req *fcp;
1815
struct eckd_count *ect;
1819
struct ch_t address;
1820
int cplength, datasize;
1825
private = (struct dasd_eckd_private *) device->private;
1826
rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1828
fdata->start_unit / private->rdc_data.trk_per_cyl,
1829
fdata->start_unit % private->rdc_data.trk_per_cyl);
1831
/* Sanity checks. */
1832
if (fdata->start_unit >=
1833
(private->real_cyl * private->rdc_data.trk_per_cyl)) {
1834
dev_warn(&device->cdev->dev, "Start track number %d used in "
1835
"formatting is too big\n", fdata->start_unit);
1836
return ERR_PTR(-EINVAL);
1838
if (fdata->start_unit > fdata->stop_unit) {
1839
dev_warn(&device->cdev->dev, "Start track %d used in "
1840
"formatting exceeds end track\n", fdata->start_unit);
1841
return ERR_PTR(-EINVAL);
1843
if (dasd_check_blocksize(fdata->blksize) != 0) {
1844
dev_warn(&device->cdev->dev,
1845
"The DASD cannot be formatted with block size %d\n",
1847
return ERR_PTR(-EINVAL);
1851
* fdata->intensity is a bit string that tells us what to do:
1852
* Bit 0: write record zero
1853
* Bit 1: write home address, currently not supported
1854
* Bit 2: invalidate tracks
1855
* Bit 3: use OS/390 compatible disk layout (cdl)
1856
* Bit 4: do not allow storage subsystem to modify record zero
1857
* Only some bit combinations do make sense.
1859
if (fdata->intensity & 0x10) {
1861
intensity = fdata->intensity & ~0x10;
1864
intensity = fdata->intensity;
1866
switch (intensity) {
1867
case 0x00: /* Normal format */
1868
case 0x08: /* Normal format, use cdl. */
1870
datasize = sizeof(struct DE_eckd_data) +
1871
sizeof(struct LO_eckd_data) +
1872
rpt * sizeof(struct eckd_count);
1874
case 0x01: /* Write record zero and format track. */
1875
case 0x09: /* Write record zero and format track, use cdl. */
1877
datasize = sizeof(struct DE_eckd_data) +
1878
sizeof(struct LO_eckd_data) +
1879
sizeof(struct eckd_count) +
1880
rpt * sizeof(struct eckd_count);
1882
case 0x04: /* Invalidate track. */
1883
case 0x0c: /* Invalidate track, use cdl. */
1885
datasize = sizeof(struct DE_eckd_data) +
1886
sizeof(struct LO_eckd_data) +
1887
sizeof(struct eckd_count);
1890
dev_warn(&device->cdev->dev, "An I/O control call used "
1891
"incorrect flags 0x%x\n", fdata->intensity);
1892
return ERR_PTR(-EINVAL);
1894
/* Allocate the format ccw request. */
1895
fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1902
switch (intensity & ~0x08) {
1903
case 0x00: /* Normal format. */
1904
define_extent(ccw++, (struct DE_eckd_data *) data,
1905
fdata->start_unit, fdata->start_unit,
1906
DASD_ECKD_CCW_WRITE_CKD, device);
1907
/* grant subsystem permission to format R0 */
1909
((struct DE_eckd_data *)data)->ga_extended |= 0x04;
1910
data += sizeof(struct DE_eckd_data);
1911
ccw[-1].flags |= CCW_FLAG_CC;
1912
locate_record(ccw++, (struct LO_eckd_data *) data,
1913
fdata->start_unit, 0, rpt,
1914
DASD_ECKD_CCW_WRITE_CKD, device,
1916
data += sizeof(struct LO_eckd_data);
1918
case 0x01: /* Write record zero + format track. */
1919
define_extent(ccw++, (struct DE_eckd_data *) data,
1920
fdata->start_unit, fdata->start_unit,
1921
DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1923
data += sizeof(struct DE_eckd_data);
1924
ccw[-1].flags |= CCW_FLAG_CC;
1925
locate_record(ccw++, (struct LO_eckd_data *) data,
1926
fdata->start_unit, 0, rpt + 1,
1927
DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1928
device->block->bp_block);
1929
data += sizeof(struct LO_eckd_data);
1931
case 0x04: /* Invalidate track. */
1932
define_extent(ccw++, (struct DE_eckd_data *) data,
1933
fdata->start_unit, fdata->start_unit,
1934
DASD_ECKD_CCW_WRITE_CKD, device);
1935
data += sizeof(struct DE_eckd_data);
1936
ccw[-1].flags |= CCW_FLAG_CC;
1937
locate_record(ccw++, (struct LO_eckd_data *) data,
1938
fdata->start_unit, 0, 1,
1939
DASD_ECKD_CCW_WRITE_CKD, device, 8);
1940
data += sizeof(struct LO_eckd_data);
1943
if (intensity & 0x01) { /* write record zero */
1944
ect = (struct eckd_count *) data;
1945
data += sizeof(struct eckd_count);
1946
ect->cyl = address.cyl;
1947
ect->head = address.head;
1951
ccw[-1].flags |= CCW_FLAG_CC;
1952
ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1953
ccw->flags = CCW_FLAG_SLI;
1955
ccw->cda = (__u32)(addr_t) ect;
1958
if ((intensity & ~0x08) & 0x04) { /* erase track */
1959
ect = (struct eckd_count *) data;
1960
data += sizeof(struct eckd_count);
1961
ect->cyl = address.cyl;
1962
ect->head = address.head;
1966
ccw[-1].flags |= CCW_FLAG_CC;
1967
ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1968
ccw->flags = CCW_FLAG_SLI;
1970
ccw->cda = (__u32)(addr_t) ect;
1971
} else { /* write remaining records */
1972
for (i = 0; i < rpt; i++) {
1973
ect = (struct eckd_count *) data;
1974
data += sizeof(struct eckd_count);
1975
ect->cyl = address.cyl;
1976
ect->head = address.head;
1977
ect->record = i + 1;
1979
ect->dl = fdata->blksize;
1980
/* Check for special tracks 0-1 when formatting CDL */
1981
if ((intensity & 0x08) &&
1982
fdata->start_unit == 0) {
1985
ect->dl = sizes_trk0[i] - 4;
1988
if ((intensity & 0x08) &&
1989
fdata->start_unit == 1) {
1991
ect->dl = LABEL_SIZE - 44;
1993
ccw[-1].flags |= CCW_FLAG_CC;
1994
ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1995
ccw->flags = CCW_FLAG_SLI;
1997
ccw->cda = (__u32)(addr_t) ect;
2001
fcp->startdev = device;
2002
fcp->memdev = device;
2004
fcp->buildclk = get_clock();
2005
fcp->status = DASD_CQR_FILLED;
2009
static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2011
cqr->status = DASD_CQR_FILLED;
2012
if (cqr->block && (cqr->startdev != cqr->block->base)) {
2013
dasd_eckd_reset_ccw_to_base_io(cqr);
2014
cqr->startdev = cqr->block->base;
2015
cqr->lpm = cqr->block->base->path_data.opm;
2019
static dasd_erp_fn_t
2020
dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2022
struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2023
struct ccw_device *cdev = device->cdev;
2025
switch (cdev->id.cu_type) {
2030
return dasd_3990_erp_action;
2034
return dasd_default_erp_action;
2038
static dasd_erp_fn_t
2039
dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2041
return dasd_default_erp_postaction;
2044
static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2045
struct dasd_ccw_req *cqr,
2050
struct dasd_eckd_private *private;
2052
private = (struct dasd_eckd_private *) device->private;
2053
/* first of all check for state change pending interrupt */
2054
mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
2055
if ((scsw_dstat(&irb->scsw) & mask) == mask) {
2057
* for alias only, not in offline processing
2058
* and only if not suspended
2060
if (!device->block && private->lcu &&
2061
!test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2062
!test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
2064
* the state change could be caused by an alias
2065
* reassignment remove device from alias handling
2066
* to prevent new requests from being scheduled on
2067
* the wrong alias device
2069
dasd_alias_remove_device(device);
2071
/* schedule worker to reload device */
2072
dasd_reload_device(device);
2074
dasd_generic_handle_state_change(device);
2078
sense = dasd_get_sense(irb);
2082
/* summary unit check */
2083
if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
2084
(scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
2085
dasd_alias_handle_summary_unit_check(device, irb);
2089
/* service information message SIM */
2090
if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
2091
((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2092
dasd_3990_erp_handle_sim(device, sense);
2096
/* loss of device reservation is handled via base devices only
2097
* as alias devices may be used with several bases
2099
if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
2100
(sense[7] == 0x3F) &&
2101
(scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2102
test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2103
if (device->features & DASD_FEATURE_FAILONSLCK)
2104
set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2105
clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2106
dev_err(&device->cdev->dev,
2107
"The device reservation was lost\n");
2111
static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2112
struct dasd_device *startdev,
2113
struct dasd_block *block,
2114
struct request *req,
2119
unsigned int first_offs,
2120
unsigned int last_offs,
2121
unsigned int blk_per_trk,
2122
unsigned int blksize)
2124
struct dasd_eckd_private *private;
2125
unsigned long *idaws;
2126
struct LO_eckd_data *LO_data;
2127
struct dasd_ccw_req *cqr;
2129
struct req_iterator iter;
2133
int count, cidaw, cplength, datasize;
2135
unsigned char cmd, rcmd;
2137
struct dasd_device *basedev;
2139
basedev = block->base;
2140
private = (struct dasd_eckd_private *) basedev->private;
2141
if (rq_data_dir(req) == READ)
2142
cmd = DASD_ECKD_CCW_READ_MT;
2143
else if (rq_data_dir(req) == WRITE)
2144
cmd = DASD_ECKD_CCW_WRITE_MT;
2146
return ERR_PTR(-EINVAL);
2148
/* Check struct bio and count the number of blocks for the request. */
2151
rq_for_each_segment(bv, req, iter) {
2152
if (bv->bv_len & (blksize - 1))
2153
/* Eckd can only do full blocks. */
2154
return ERR_PTR(-EINVAL);
2155
count += bv->bv_len >> (block->s2b_shift + 9);
2156
#if defined(CONFIG_64BIT)
2157
if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
2158
cidaw += bv->bv_len >> (block->s2b_shift + 9);
2162
if (count != last_rec - first_rec + 1)
2163
return ERR_PTR(-EINVAL);
2165
/* use the prefix command if available */
2166
use_prefix = private->features.feature[8] & 0x01;
2168
/* 1x prefix + number of blocks */
2169
cplength = 2 + count;
2170
/* 1x prefix + cidaws*sizeof(long) */
2171
datasize = sizeof(struct PFX_eckd_data) +
2172
sizeof(struct LO_eckd_data) +
2173
cidaw * sizeof(unsigned long);
2175
/* 1x define extent + 1x locate record + number of blocks */
2176
cplength = 2 + count;
2177
/* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2178
datasize = sizeof(struct DE_eckd_data) +
2179
sizeof(struct LO_eckd_data) +
2180
cidaw * sizeof(unsigned long);
2182
/* Find out the number of additional locate record ccws for cdl. */
2183
if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2184
if (last_rec >= 2*blk_per_trk)
2185
count = 2*blk_per_trk - first_rec;
2187
datasize += count*sizeof(struct LO_eckd_data);
2189
/* Allocate the ccw request. */
2190
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2195
/* First ccw is define extent or prefix. */
2197
if (prefix(ccw++, cqr->data, first_trk,
2198
last_trk, cmd, basedev, startdev) == -EAGAIN) {
2199
/* Clock not in sync and XRC is enabled.
2202
dasd_sfree_request(cqr, startdev);
2203
return ERR_PTR(-EAGAIN);
2205
idaws = (unsigned long *) (cqr->data +
2206
sizeof(struct PFX_eckd_data));
2208
if (define_extent(ccw++, cqr->data, first_trk,
2209
last_trk, cmd, startdev) == -EAGAIN) {
2210
/* Clock not in sync and XRC is enabled.
2213
dasd_sfree_request(cqr, startdev);
2214
return ERR_PTR(-EAGAIN);
2216
idaws = (unsigned long *) (cqr->data +
2217
sizeof(struct DE_eckd_data));
2219
/* Build locate_record+read/write/ccws. */
2220
LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2222
if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2223
/* Only standard blocks so there is just one locate record. */
2224
ccw[-1].flags |= CCW_FLAG_CC;
2225
locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
2226
last_rec - recid + 1, cmd, basedev, blksize);
2228
rq_for_each_segment(bv, req, iter) {
2229
dst = page_address(bv->bv_page) + bv->bv_offset;
2230
if (dasd_page_cache) {
2231
char *copy = kmem_cache_alloc(dasd_page_cache,
2232
GFP_DMA | __GFP_NOWARN);
2233
if (copy && rq_data_dir(req) == WRITE)
2234
memcpy(copy + bv->bv_offset, dst, bv->bv_len);
2236
dst = copy + bv->bv_offset;
2238
for (off = 0; off < bv->bv_len; off += blksize) {
2239
sector_t trkid = recid;
2240
unsigned int recoffs = sector_div(trkid, blk_per_trk);
2243
/* Locate record for cdl special block ? */
2244
if (private->uses_cdl && recid < 2*blk_per_trk) {
2245
if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2247
count = dasd_eckd_cdl_reclen(recid);
2248
if (count < blksize &&
2249
rq_data_dir(req) == READ)
2250
memset(dst + count, 0xe5,
2253
ccw[-1].flags |= CCW_FLAG_CC;
2254
locate_record(ccw++, LO_data++,
2256
1, rcmd, basedev, count);
2258
/* Locate record for standard blocks ? */
2259
if (private->uses_cdl && recid == 2*blk_per_trk) {
2260
ccw[-1].flags |= CCW_FLAG_CC;
2261
locate_record(ccw++, LO_data++,
2263
last_rec - recid + 1,
2264
cmd, basedev, count);
2266
/* Read/write ccw. */
2267
ccw[-1].flags |= CCW_FLAG_CC;
2268
ccw->cmd_code = rcmd;
2270
if (idal_is_needed(dst, blksize)) {
2271
ccw->cda = (__u32)(addr_t) idaws;
2272
ccw->flags = CCW_FLAG_IDA;
2273
idaws = idal_create_words(idaws, dst, blksize);
2275
ccw->cda = (__u32)(addr_t) dst;
2283
if (blk_noretry_request(req) ||
2284
block->base->features & DASD_FEATURE_FAILFAST)
2285
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2286
cqr->startdev = startdev;
2287
cqr->memdev = startdev;
2289
cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2290
cqr->lpm = startdev->path_data.ppm;
2292
cqr->buildclk = get_clock();
2293
cqr->status = DASD_CQR_FILLED;
2297
static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2298
struct dasd_device *startdev,
2299
struct dasd_block *block,
2300
struct request *req,
2305
unsigned int first_offs,
2306
unsigned int last_offs,
2307
unsigned int blk_per_trk,
2308
unsigned int blksize)
2310
unsigned long *idaws;
2311
struct dasd_ccw_req *cqr;
2313
struct req_iterator iter;
2315
char *dst, *idaw_dst;
2316
unsigned int cidaw, cplength, datasize;
2320
struct dasd_device *basedev;
2321
unsigned int trkcount, count, count_to_trk_end;
2322
unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2323
unsigned char new_track, end_idaw;
2325
unsigned int recoffs;
2327
basedev = block->base;
2328
if (rq_data_dir(req) == READ)
2329
cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2330
else if (rq_data_dir(req) == WRITE)
2331
cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2333
return ERR_PTR(-EINVAL);
2335
/* Track based I/O needs IDAWs for each page, and not just for
2336
* 64 bit addresses. We need additional idals for pages
2337
* that get filled from two tracks, so we use the number
2338
* of records as upper limit.
2340
cidaw = last_rec - first_rec + 1;
2341
trkcount = last_trk - first_trk + 1;
2343
/* 1x prefix + one read/write ccw per track */
2344
cplength = 1 + trkcount;
2346
/* on 31-bit we need space for two 32 bit addresses per page
2347
* on 64-bit one 64 bit address
2349
datasize = sizeof(struct PFX_eckd_data) +
2350
cidaw * sizeof(unsigned long long);
2352
/* Allocate the ccw request. */
2353
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2358
/* transfer length factor: how many bytes to read from the last track */
2359
if (first_trk == last_trk)
2360
tlf = last_offs - first_offs + 1;
2362
tlf = last_offs + 1;
2365
if (prefix_LRE(ccw++, cqr->data, first_trk,
2366
last_trk, cmd, basedev, startdev,
2367
1 /* format */, first_offs + 1,
2370
/* Clock not in sync and XRC is enabled.
2373
dasd_sfree_request(cqr, startdev);
2374
return ERR_PTR(-EAGAIN);
2378
* The translation of request into ccw programs must meet the
2379
* following conditions:
2380
* - all idaws but the first and the last must address full pages
2381
* (or 2K blocks on 31-bit)
2382
* - the scope of a ccw and it's idal ends with the track boundaries
2384
idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2388
len_to_track_end = 0;
2391
rq_for_each_segment(bv, req, iter) {
2392
dst = page_address(bv->bv_page) + bv->bv_offset;
2393
seg_len = bv->bv_len;
2397
recoffs = sector_div(trkid, blk_per_trk);
2398
count_to_trk_end = blk_per_trk - recoffs;
2399
count = min((last_rec - recid + 1),
2400
(sector_t)count_to_trk_end);
2401
len_to_track_end = count * blksize;
2402
ccw[-1].flags |= CCW_FLAG_CC;
2403
ccw->cmd_code = cmd;
2404
ccw->count = len_to_track_end;
2405
ccw->cda = (__u32)(addr_t)idaws;
2406
ccw->flags = CCW_FLAG_IDA;
2410
/* first idaw for a ccw may start anywhere */
2414
/* If we start a new idaw, we must make sure that it
2415
* starts on an IDA_BLOCK_SIZE boundary.
2416
* If we continue an idaw, we must make sure that the
2417
* current segment begins where the so far accumulated
2421
if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2422
dasd_sfree_request(cqr, startdev);
2423
return ERR_PTR(-ERANGE);
2427
if ((idaw_dst + idaw_len) != dst) {
2428
dasd_sfree_request(cqr, startdev);
2429
return ERR_PTR(-ERANGE);
2431
part_len = min(seg_len, len_to_track_end);
2432
seg_len -= part_len;
2434
idaw_len += part_len;
2435
len_to_track_end -= part_len;
2436
/* collected memory area ends on an IDA_BLOCK border,
2438
* idal_create_words will handle cases where idaw_len
2439
* is larger then IDA_BLOCK_SIZE
2441
if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2443
/* We also need to end the idaw at track end */
2444
if (!len_to_track_end) {
2449
idaws = idal_create_words(idaws, idaw_dst,
2458
if (blk_noretry_request(req) ||
2459
block->base->features & DASD_FEATURE_FAILFAST)
2460
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2461
cqr->startdev = startdev;
2462
cqr->memdev = startdev;
2464
cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2465
cqr->lpm = startdev->path_data.ppm;
2467
cqr->buildclk = get_clock();
2468
cqr->status = DASD_CQR_FILLED;
2472
static int prepare_itcw(struct itcw *itcw,
2473
unsigned int trk, unsigned int totrk, int cmd,
2474
struct dasd_device *basedev,
2475
struct dasd_device *startdev,
2476
unsigned int rec_on_trk, int count,
2477
unsigned int blksize,
2478
unsigned int total_data_size,
2480
unsigned int blk_per_trk)
2482
struct PFX_eckd_data pfxdata;
2483
struct dasd_eckd_private *basepriv, *startpriv;
2484
struct DE_eckd_data *dedata;
2485
struct LRE_eckd_data *lredata;
2489
u16 heads, beghead, endhead;
2497
/* setup prefix data */
2498
basepriv = (struct dasd_eckd_private *) basedev->private;
2499
startpriv = (struct dasd_eckd_private *) startdev->private;
2500
dedata = &pfxdata.define_extent;
2501
lredata = &pfxdata.locate_record;
2503
memset(&pfxdata, 0, sizeof(pfxdata));
2504
pfxdata.format = 1; /* PFX with LRE */
2505
pfxdata.base_address = basepriv->ned->unit_addr;
2506
pfxdata.base_lss = basepriv->ned->ID;
2507
pfxdata.validity.define_extent = 1;
2509
/* private uid is kept up to date, conf_data may be outdated */
2510
if (startpriv->uid.type != UA_BASE_DEVICE) {
2511
pfxdata.validity.verify_base = 1;
2512
if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2513
pfxdata.validity.hyper_pav = 1;
2517
case DASD_ECKD_CCW_READ_TRACK_DATA:
2518
dedata->mask.perm = 0x1;
2519
dedata->attributes.operation = basepriv->attrib.operation;
2520
dedata->blk_size = blksize;
2521
dedata->ga_extended |= 0x42;
2522
lredata->operation.orientation = 0x0;
2523
lredata->operation.operation = 0x0C;
2524
lredata->auxiliary.check_bytes = 0x01;
2525
pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2527
case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2528
dedata->mask.perm = 0x02;
2529
dedata->attributes.operation = basepriv->attrib.operation;
2530
dedata->blk_size = blksize;
2531
rc = check_XRC_on_prefix(&pfxdata, basedev);
2532
dedata->ga_extended |= 0x42;
2533
lredata->operation.orientation = 0x0;
2534
lredata->operation.operation = 0x3F;
2535
lredata->extended_operation = 0x23;
2536
lredata->auxiliary.check_bytes = 0x2;
2537
pfx_cmd = DASD_ECKD_CCW_PFX;
2540
DBF_DEV_EVENT(DBF_ERR, basedev,
2541
"prepare itcw, unknown opcode 0x%x", cmd);
2548
dedata->attributes.mode = 0x3; /* ECKD */
2550
heads = basepriv->rdc_data.trk_per_cyl;
2551
begcyl = trk / heads;
2552
beghead = trk % heads;
2553
endcyl = totrk / heads;
2554
endhead = totrk % heads;
2556
/* check for sequential prestage - enhance cylinder range */
2557
if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2558
dedata->attributes.operation == DASD_SEQ_ACCESS) {
2560
if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2561
endcyl += basepriv->attrib.nr_cyl;
2563
endcyl = (basepriv->real_cyl - 1);
2566
set_ch_t(&dedata->beg_ext, begcyl, beghead);
2567
set_ch_t(&dedata->end_ext, endcyl, endhead);
2569
dedata->ep_format = 0x20; /* records per track is valid */
2570
dedata->ep_rec_per_track = blk_per_trk;
2573
switch (basepriv->rdc_data.dev_type) {
2575
dn = ceil_quot(blksize + 6, 232);
2576
d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2577
sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2580
d = 7 + ceil_quot(blksize + 12, 32);
2581
sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2586
lredata->auxiliary.length_valid = 1;
2587
lredata->auxiliary.length_scope = 1;
2588
lredata->auxiliary.imbedded_ccw_valid = 1;
2589
lredata->length = tlf;
2590
lredata->imbedded_ccw = cmd;
2591
lredata->count = count;
2592
lredata->sector = sector;
2593
set_ch_t(&lredata->seek_addr, begcyl, beghead);
2594
lredata->search_arg.cyl = lredata->seek_addr.cyl;
2595
lredata->search_arg.head = lredata->seek_addr.head;
2596
lredata->search_arg.record = rec_on_trk;
2598
dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2599
&pfxdata, sizeof(pfxdata), total_data_size);
2600
return IS_ERR(dcw) ? PTR_ERR(dcw) : 0;
2603
static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2604
struct dasd_device *startdev,
2605
struct dasd_block *block,
2606
struct request *req,
2611
unsigned int first_offs,
2612
unsigned int last_offs,
2613
unsigned int blk_per_trk,
2614
unsigned int blksize)
2616
struct dasd_ccw_req *cqr;
2617
struct req_iterator iter;
2620
unsigned int trkcount, ctidaw;
2622
struct dasd_device *basedev;
2625
struct tidaw *last_tidaw = NULL;
2629
unsigned int seg_len, part_len, len_to_track_end;
2630
unsigned char new_track;
2631
sector_t recid, trkid;
2633
unsigned int count, count_to_trk_end;
2635
basedev = block->base;
2636
if (rq_data_dir(req) == READ) {
2637
cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2638
itcw_op = ITCW_OP_READ;
2639
} else if (rq_data_dir(req) == WRITE) {
2640
cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2641
itcw_op = ITCW_OP_WRITE;
2643
return ERR_PTR(-EINVAL);
2645
/* trackbased I/O needs address all memory via TIDAWs,
2646
* not just for 64 bit addresses. This allows us to map
2647
* each segment directly to one tidaw.
2648
* In the case of write requests, additional tidaws may
2649
* be needed when a segment crosses a track boundary.
2651
trkcount = last_trk - first_trk + 1;
2653
rq_for_each_segment(bv, req, iter) {
2656
if (rq_data_dir(req) == WRITE)
2657
ctidaw += (last_trk - first_trk);
2659
/* Allocate the ccw request. */
2660
itcw_size = itcw_calc_size(0, ctidaw, 0);
2661
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2665
/* transfer length factor: how many bytes to read from the last track */
2666
if (first_trk == last_trk)
2667
tlf = last_offs - first_offs + 1;
2669
tlf = last_offs + 1;
2672
itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2674
dasd_sfree_request(cqr, startdev);
2675
return ERR_PTR(-EINVAL);
2677
cqr->cpaddr = itcw_get_tcw(itcw);
2678
if (prepare_itcw(itcw, first_trk, last_trk,
2679
cmd, basedev, startdev,
2682
(last_rec - first_rec + 1) * blksize,
2683
tlf, blk_per_trk) == -EAGAIN) {
2684
/* Clock not in sync and XRC is enabled.
2687
dasd_sfree_request(cqr, startdev);
2688
return ERR_PTR(-EAGAIN);
2690
len_to_track_end = 0;
2692
* A tidaw can address 4k of memory, but must not cross page boundaries
2693
* We can let the block layer handle this by setting
2694
* blk_queue_segment_boundary to page boundaries and
2695
* blk_max_segment_size to page size when setting up the request queue.
2696
* For write requests, a TIDAW must not cross track boundaries, because
2697
* we have to set the CBC flag on the last tidaw for each track.
2699
if (rq_data_dir(req) == WRITE) {
2702
rq_for_each_segment(bv, req, iter) {
2703
dst = page_address(bv->bv_page) + bv->bv_offset;
2704
seg_len = bv->bv_len;
2708
offs = sector_div(trkid, blk_per_trk);
2709
count_to_trk_end = blk_per_trk - offs;
2710
count = min((last_rec - recid + 1),
2711
(sector_t)count_to_trk_end);
2712
len_to_track_end = count * blksize;
2716
part_len = min(seg_len, len_to_track_end);
2717
seg_len -= part_len;
2718
len_to_track_end -= part_len;
2719
/* We need to end the tidaw at track end */
2720
if (!len_to_track_end) {
2722
tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
2725
last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
2727
if (IS_ERR(last_tidaw))
2728
return ERR_PTR(-EINVAL);
2733
rq_for_each_segment(bv, req, iter) {
2734
dst = page_address(bv->bv_page) + bv->bv_offset;
2735
last_tidaw = itcw_add_tidaw(itcw, 0x00,
2737
if (IS_ERR(last_tidaw))
2738
return ERR_PTR(-EINVAL);
2741
last_tidaw->flags |= TIDAW_FLAGS_LAST;
2742
last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
2743
itcw_finalize(itcw);
2745
if (blk_noretry_request(req) ||
2746
block->base->features & DASD_FEATURE_FAILFAST)
2747
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2749
cqr->startdev = startdev;
2750
cqr->memdev = startdev;
2752
cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2753
cqr->lpm = startdev->path_data.ppm;
2755
cqr->buildclk = get_clock();
2756
cqr->status = DASD_CQR_FILLED;
2760
static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2761
struct dasd_block *block,
2762
struct request *req)
2767
struct dasd_eckd_private *private;
2768
struct dasd_device *basedev;
2769
sector_t first_rec, last_rec;
2770
sector_t first_trk, last_trk;
2771
unsigned int first_offs, last_offs;
2772
unsigned int blk_per_trk, blksize;
2774
unsigned int data_size;
2775
struct dasd_ccw_req *cqr;
2777
basedev = block->base;
2778
private = (struct dasd_eckd_private *) basedev->private;
2780
/* Calculate number of blocks/records per track. */
2781
blksize = block->bp_block;
2782
blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2783
if (blk_per_trk == 0)
2784
return ERR_PTR(-EINVAL);
2785
/* Calculate record id of first and last block. */
2786
first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
2787
first_offs = sector_div(first_trk, blk_per_trk);
2788
last_rec = last_trk =
2789
(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
2790
last_offs = sector_div(last_trk, blk_per_trk);
2791
cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2793
fcx_multitrack = private->features.feature[40] & 0x20;
2794
data_size = blk_rq_bytes(req);
2795
/* tpm write request add CBC data on each track boundary */
2796
if (rq_data_dir(req) == WRITE)
2797
data_size += (last_trk - first_trk) * 4;
2799
/* is read track data and write track data in command mode supported? */
2800
cmdrtd = private->features.feature[9] & 0x20;
2801
cmdwtd = private->features.feature[12] & 0x40;
2802
use_prefix = private->features.feature[8] & 0x01;
2805
if (cdlspecial || dasd_page_cache) {
2806
/* do nothing, just fall through to the cmd mode single case */
2807
} else if ((data_size <= private->fcx_max_data)
2808
&& (fcx_multitrack || (first_trk == last_trk))) {
2809
cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2810
first_rec, last_rec,
2811
first_trk, last_trk,
2812
first_offs, last_offs,
2813
blk_per_trk, blksize);
2814
if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
2815
(PTR_ERR(cqr) != -ENOMEM))
2817
} else if (use_prefix &&
2818
(((rq_data_dir(req) == READ) && cmdrtd) ||
2819
((rq_data_dir(req) == WRITE) && cmdwtd))) {
2820
cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2821
first_rec, last_rec,
2822
first_trk, last_trk,
2823
first_offs, last_offs,
2824
blk_per_trk, blksize);
2825
if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
2826
(PTR_ERR(cqr) != -ENOMEM))
2830
cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2831
first_rec, last_rec,
2832
first_trk, last_trk,
2833
first_offs, last_offs,
2834
blk_per_trk, blksize);
2838
static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
2839
struct dasd_block *block,
2840
struct request *req)
2842
unsigned long *idaws;
2843
struct dasd_device *basedev;
2844
struct dasd_ccw_req *cqr;
2846
struct req_iterator iter;
2850
unsigned int trkcount;
2851
unsigned int seg_len, len_to_track_end;
2852
unsigned int first_offs;
2853
unsigned int cidaw, cplength, datasize;
2854
sector_t first_trk, last_trk;
2855
unsigned int pfx_datasize;
2858
* raw track access needs to be mutiple of 64k and on 64k boundary
2860
if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
2861
cqr = ERR_PTR(-EINVAL);
2864
if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
2865
DASD_RAW_SECTORS_PER_TRACK) != 0) {
2866
cqr = ERR_PTR(-EINVAL);
2870
first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
2871
last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
2872
DASD_RAW_SECTORS_PER_TRACK;
2873
trkcount = last_trk - first_trk + 1;
2875
basedev = block->base;
2877
if (rq_data_dir(req) == READ)
2878
cmd = DASD_ECKD_CCW_READ_TRACK;
2879
else if (rq_data_dir(req) == WRITE)
2880
cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
2882
cqr = ERR_PTR(-EINVAL);
2887
* Raw track based I/O needs IDAWs for each page,
2888
* and not just for 64 bit addresses.
2890
cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
2892
/* 1x prefix + one read/write ccw per track */
2893
cplength = 1 + trkcount;
2896
* struct PFX_eckd_data has up to 2 byte as extended parameter
2897
* this is needed for write full track and has to be mentioned
2899
* add 8 instead of 2 to keep 8 byte boundary
2901
pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
2903
datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
2905
/* Allocate the ccw request. */
2906
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2907
datasize, startdev);
2912
if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
2913
basedev, startdev, 1 /* format */, first_offs + 1,
2914
trkcount, 0, 0) == -EAGAIN) {
2915
/* Clock not in sync and XRC is enabled.
2918
dasd_sfree_request(cqr, startdev);
2919
cqr = ERR_PTR(-EAGAIN);
2923
idaws = (unsigned long *)(cqr->data + pfx_datasize);
2925
len_to_track_end = 0;
2927
rq_for_each_segment(bv, req, iter) {
2928
dst = page_address(bv->bv_page) + bv->bv_offset;
2929
seg_len = bv->bv_len;
2930
if (!len_to_track_end) {
2931
ccw[-1].flags |= CCW_FLAG_CC;
2932
ccw->cmd_code = cmd;
2933
/* maximum 3390 track size */
2935
/* 64k map to one track */
2936
len_to_track_end = 65536;
2937
ccw->cda = (__u32)(addr_t)idaws;
2938
ccw->flags |= CCW_FLAG_IDA;
2939
ccw->flags |= CCW_FLAG_SLI;
2942
len_to_track_end -= seg_len;
2943
idaws = idal_create_words(idaws, dst, seg_len);
2946
if (blk_noretry_request(req) ||
2947
block->base->features & DASD_FEATURE_FAILFAST)
2948
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2949
cqr->startdev = startdev;
2950
cqr->memdev = startdev;
2952
cqr->expires = startdev->default_expires * HZ;
2953
cqr->lpm = startdev->path_data.ppm;
2955
cqr->buildclk = get_clock();
2956
cqr->status = DASD_CQR_FILLED;
2958
if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2966
dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2968
struct dasd_eckd_private *private;
2970
struct req_iterator iter;
2973
unsigned int blksize, blk_per_trk, off;
2977
if (!dasd_page_cache)
2979
private = (struct dasd_eckd_private *) cqr->block->base->private;
2980
blksize = cqr->block->bp_block;
2981
blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2982
recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
2984
/* Skip over define extent & locate record. */
2986
if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2988
rq_for_each_segment(bv, req, iter) {
2989
dst = page_address(bv->bv_page) + bv->bv_offset;
2990
for (off = 0; off < bv->bv_len; off += blksize) {
2991
/* Skip locate record. */
2992
if (private->uses_cdl && recid <= 2*blk_per_trk)
2995
if (ccw->flags & CCW_FLAG_IDA)
2996
cda = *((char **)((addr_t) ccw->cda));
2998
cda = (char *)((addr_t) ccw->cda);
3000
if (rq_data_dir(req) == READ)
3001
memcpy(dst, cda, bv->bv_len);
3002
kmem_cache_free(dasd_page_cache,
3003
(void *)((addr_t)cda & PAGE_MASK));
3012
status = cqr->status == DASD_CQR_DONE;
3013
dasd_sfree_request(cqr, cqr->memdev);
3018
* Modify ccw/tcw in cqr so it can be started on a base device.
3020
* Note that this is not enough to restart the cqr!
3021
* Either reset cqr->startdev as well (summary unit check handling)
3022
* or restart via separate cqr (as in ERP handling).
3024
void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3027
struct PFX_eckd_data *pfxdata;
3032
if (cqr->cpmode == 1) {
3034
tccb = tcw_get_tccb(tcw);
3035
dcw = (struct dcw *)&tccb->tca[0];
3036
pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
3037
pfxdata->validity.verify_base = 0;
3038
pfxdata->validity.hyper_pav = 0;
3041
pfxdata = cqr->data;
3042
if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3043
pfxdata->validity.verify_base = 0;
3044
pfxdata->validity.hyper_pav = 0;
3049
#define DASD_ECKD_CHANQ_MAX_SIZE 4
3051
static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3052
struct dasd_block *block,
3053
struct request *req)
3055
struct dasd_eckd_private *private;
3056
struct dasd_device *startdev;
3057
unsigned long flags;
3058
struct dasd_ccw_req *cqr;
3060
startdev = dasd_alias_get_start_dev(base);
3063
private = (struct dasd_eckd_private *) startdev->private;
3064
if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3065
return ERR_PTR(-EBUSY);
3067
spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3069
if ((base->features & DASD_FEATURE_USERAW))
3070
cqr = dasd_raw_build_cp(startdev, block, req);
3072
cqr = dasd_eckd_build_cp(startdev, block, req);
3075
spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3079
static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3080
struct request *req)
3082
struct dasd_eckd_private *private;
3083
unsigned long flags;
3085
spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3086
private = (struct dasd_eckd_private *) cqr->memdev->private;
3088
spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3089
return dasd_eckd_free_cp(cqr, req);
3093
dasd_eckd_fill_info(struct dasd_device * device,
3094
struct dasd_information2_t * info)
3096
struct dasd_eckd_private *private;
3098
private = (struct dasd_eckd_private *) device->private;
3099
info->label_block = 2;
3100
info->FBA_layout = private->uses_cdl ? 0 : 1;
3101
info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3102
info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3103
memcpy(info->characteristics, &private->rdc_data,
3104
sizeof(struct dasd_eckd_characteristics));
3105
info->confdata_size = min((unsigned long)private->conf_len,
3106
sizeof(info->configuration_data));
3107
memcpy(info->configuration_data, private->conf_data,
3108
info->confdata_size);
3113
* SECTION: ioctl functions for eckd devices.
3117
* Release device ioctl.
3118
* Buils a channel programm to releases a prior reserved
3119
* (see dasd_eckd_reserve) device.
3122
dasd_eckd_release(struct dasd_device *device)
3124
struct dasd_ccw_req *cqr;
3129
if (!capable(CAP_SYS_ADMIN))
3133
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3135
mutex_lock(&dasd_reserve_mutex);
3137
cqr = &dasd_reserve_req->cqr;
3138
memset(cqr, 0, sizeof(*cqr));
3139
memset(&dasd_reserve_req->ccw, 0,
3140
sizeof(dasd_reserve_req->ccw));
3141
cqr->cpaddr = &dasd_reserve_req->ccw;
3142
cqr->data = &dasd_reserve_req->data;
3143
cqr->magic = DASD_ECKD_MAGIC;
3146
ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3147
ccw->flags |= CCW_FLAG_SLI;
3149
ccw->cda = (__u32)(addr_t) cqr->data;
3150
cqr->startdev = device;
3151
cqr->memdev = device;
3152
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3153
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3154
cqr->retries = 2; /* set retry counter to enable basic ERP */
3155
cqr->expires = 2 * HZ;
3156
cqr->buildclk = get_clock();
3157
cqr->status = DASD_CQR_FILLED;
3159
rc = dasd_sleep_on_immediatly(cqr);
3161
clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3164
mutex_unlock(&dasd_reserve_mutex);
3166
dasd_sfree_request(cqr, cqr->memdev);
3171
* Reserve device ioctl.
3172
* Options are set to 'synchronous wait for interrupt' and
3173
* 'timeout the request'. This leads to a terminate IO if
3174
* the interrupt is outstanding for a certain time.
3177
dasd_eckd_reserve(struct dasd_device *device)
3179
struct dasd_ccw_req *cqr;
3184
if (!capable(CAP_SYS_ADMIN))
3188
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3190
mutex_lock(&dasd_reserve_mutex);
3192
cqr = &dasd_reserve_req->cqr;
3193
memset(cqr, 0, sizeof(*cqr));
3194
memset(&dasd_reserve_req->ccw, 0,
3195
sizeof(dasd_reserve_req->ccw));
3196
cqr->cpaddr = &dasd_reserve_req->ccw;
3197
cqr->data = &dasd_reserve_req->data;
3198
cqr->magic = DASD_ECKD_MAGIC;
3201
ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3202
ccw->flags |= CCW_FLAG_SLI;
3204
ccw->cda = (__u32)(addr_t) cqr->data;
3205
cqr->startdev = device;
3206
cqr->memdev = device;
3207
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3208
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3209
cqr->retries = 2; /* set retry counter to enable basic ERP */
3210
cqr->expires = 2 * HZ;
3211
cqr->buildclk = get_clock();
3212
cqr->status = DASD_CQR_FILLED;
3214
rc = dasd_sleep_on_immediatly(cqr);
3216
set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3219
mutex_unlock(&dasd_reserve_mutex);
3221
dasd_sfree_request(cqr, cqr->memdev);
3226
* Steal lock ioctl - unconditional reserve device.
3227
* Buils a channel programm to break a device's reservation.
3228
* (unconditional reserve)
3231
dasd_eckd_steal_lock(struct dasd_device *device)
3233
struct dasd_ccw_req *cqr;
3238
if (!capable(CAP_SYS_ADMIN))
3242
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3244
mutex_lock(&dasd_reserve_mutex);
3246
cqr = &dasd_reserve_req->cqr;
3247
memset(cqr, 0, sizeof(*cqr));
3248
memset(&dasd_reserve_req->ccw, 0,
3249
sizeof(dasd_reserve_req->ccw));
3250
cqr->cpaddr = &dasd_reserve_req->ccw;
3251
cqr->data = &dasd_reserve_req->data;
3252
cqr->magic = DASD_ECKD_MAGIC;
3255
ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3256
ccw->flags |= CCW_FLAG_SLI;
3258
ccw->cda = (__u32)(addr_t) cqr->data;
3259
cqr->startdev = device;
3260
cqr->memdev = device;
3261
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3262
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3263
cqr->retries = 2; /* set retry counter to enable basic ERP */
3264
cqr->expires = 2 * HZ;
3265
cqr->buildclk = get_clock();
3266
cqr->status = DASD_CQR_FILLED;
3268
rc = dasd_sleep_on_immediatly(cqr);
3270
set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3273
mutex_unlock(&dasd_reserve_mutex);
3275
dasd_sfree_request(cqr, cqr->memdev);
3280
* SNID - Sense Path Group ID
3281
* This ioctl may be used in situations where I/O is stalled due to
3282
* a reserve, so if the normal dasd_smalloc_request fails, we use the
3283
* preallocated dasd_reserve_req.
3285
static int dasd_eckd_snid(struct dasd_device *device,
3288
struct dasd_ccw_req *cqr;
3292
struct dasd_snid_ioctl_data usrparm;
3294
if (!capable(CAP_SYS_ADMIN))
3297
if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3301
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3302
sizeof(struct dasd_snid_data), device);
3304
mutex_lock(&dasd_reserve_mutex);
3306
cqr = &dasd_reserve_req->cqr;
3307
memset(cqr, 0, sizeof(*cqr));
3308
memset(&dasd_reserve_req->ccw, 0,
3309
sizeof(dasd_reserve_req->ccw));
3310
cqr->cpaddr = &dasd_reserve_req->ccw;
3311
cqr->data = &dasd_reserve_req->data;
3312
cqr->magic = DASD_ECKD_MAGIC;
3315
ccw->cmd_code = DASD_ECKD_CCW_SNID;
3316
ccw->flags |= CCW_FLAG_SLI;
3318
ccw->cda = (__u32)(addr_t) cqr->data;
3319
cqr->startdev = device;
3320
cqr->memdev = device;
3321
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3322
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3323
set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
3325
cqr->expires = 10 * HZ;
3326
cqr->buildclk = get_clock();
3327
cqr->status = DASD_CQR_FILLED;
3328
cqr->lpm = usrparm.path_mask;
3330
rc = dasd_sleep_on_immediatly(cqr);
3331
/* verify that I/O processing didn't modify the path mask */
3332
if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3335
usrparm.data = *((struct dasd_snid_data *)cqr->data);
3336
if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3341
mutex_unlock(&dasd_reserve_mutex);
3343
dasd_sfree_request(cqr, cqr->memdev);
3348
* Read performance statistics
3351
dasd_eckd_performance(struct dasd_device *device, void __user *argp)
3353
struct dasd_psf_prssd_data *prssdp;
3354
struct dasd_rssd_perf_stats_t *stats;
3355
struct dasd_ccw_req *cqr;
3359
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
3360
(sizeof(struct dasd_psf_prssd_data) +
3361
sizeof(struct dasd_rssd_perf_stats_t)),
3364
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3365
"Could not allocate initialization request");
3366
return PTR_ERR(cqr);
3368
cqr->startdev = device;
3369
cqr->memdev = device;
3371
clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3372
cqr->expires = 10 * HZ;
3374
/* Prepare for Read Subsystem Data */
3375
prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3376
memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
3377
prssdp->order = PSF_ORDER_PRSSD;
3378
prssdp->suborder = 0x01; /* Performance Statistics */
3379
prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3382
ccw->cmd_code = DASD_ECKD_CCW_PSF;
3383
ccw->count = sizeof(struct dasd_psf_prssd_data);
3384
ccw->flags |= CCW_FLAG_CC;
3385
ccw->cda = (__u32)(addr_t) prssdp;
3387
/* Read Subsystem Data - Performance Statistics */
3388
stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3389
memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
3392
ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3393
ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
3394
ccw->cda = (__u32)(addr_t) stats;
3396
cqr->buildclk = get_clock();
3397
cqr->status = DASD_CQR_FILLED;
3398
rc = dasd_sleep_on(cqr);
3400
prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3401
stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3402
if (copy_to_user(argp, stats,
3403
sizeof(struct dasd_rssd_perf_stats_t)))
3406
dasd_sfree_request(cqr, cqr->memdev);
3411
* Get attributes (cache operations)
3412
* Returnes the cache attributes used in Define Extend (DE).
3415
dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
3417
struct dasd_eckd_private *private =
3418
(struct dasd_eckd_private *)device->private;
3419
struct attrib_data_t attrib = private->attrib;
3422
if (!capable(CAP_SYS_ADMIN))
3428
if (copy_to_user(argp, (long *) &attrib,
3429
sizeof(struct attrib_data_t)))
3436
* Set attributes (cache operations)
3437
* Stores the attributes for cache operation to be used in Define Extend (DE).
3440
dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
3442
struct dasd_eckd_private *private =
3443
(struct dasd_eckd_private *)device->private;
3444
struct attrib_data_t attrib;
3446
if (!capable(CAP_SYS_ADMIN))
3451
if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
3453
private->attrib = attrib;
3455
dev_info(&device->cdev->dev,
3456
"The DASD cache mode was set to %x (%i cylinder prestage)\n",
3457
private->attrib.operation, private->attrib.nr_cyl);
3462
* Issue syscall I/O to EMC Symmetrix array.
3463
* CCWs are PSF and RSSD
3465
static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3467
struct dasd_symmio_parms usrparm;
3468
char *psf_data, *rssd_result;
3469
struct dasd_ccw_req *cqr;
3474
if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3478
/* Copy parms from caller */
3480
if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3482
if (is_compat_task() || sizeof(long) == 4) {
3483
/* Make sure pointers are sane even on 31 bit. */
3485
if ((usrparm.psf_data >> 32) != 0)
3487
if ((usrparm.rssd_result >> 32) != 0)
3489
usrparm.psf_data &= 0x7fffffffULL;
3490
usrparm.rssd_result &= 0x7fffffffULL;
3492
/* alloc I/O data area */
3493
psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3494
rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3495
if (!psf_data || !rssd_result) {
3500
/* get syscall header from user space */
3502
if (copy_from_user(psf_data,
3503
(void __user *)(unsigned long) usrparm.psf_data,
3504
usrparm.psf_data_len))
3509
/* setup CCWs for PSF + RSSD */
3510
cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
3512
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3513
"Could not allocate initialization request");
3518
cqr->startdev = device;
3519
cqr->memdev = device;
3521
cqr->expires = 10 * HZ;
3522
cqr->buildclk = get_clock();
3523
cqr->status = DASD_CQR_FILLED;
3525
/* Build the ccws */
3529
ccw->cmd_code = DASD_ECKD_CCW_PSF;
3530
ccw->count = usrparm.psf_data_len;
3531
ccw->flags |= CCW_FLAG_CC;
3532
ccw->cda = (__u32)(addr_t) psf_data;
3537
ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3538
ccw->count = usrparm.rssd_result_len;
3539
ccw->flags = CCW_FLAG_SLI ;
3540
ccw->cda = (__u32)(addr_t) rssd_result;
3542
rc = dasd_sleep_on(cqr);
3547
if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
3548
rssd_result, usrparm.rssd_result_len))
3553
dasd_sfree_request(cqr, cqr->memdev);
3558
DBF_DEV_EVENT(DBF_WARNING, device,
3559
"Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3560
(int) psf0, (int) psf1, rc);
3565
dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
3567
struct dasd_device *device = block->base;
3571
return dasd_eckd_get_attrib(device, argp);
3573
return dasd_eckd_set_attrib(device, argp);
3575
return dasd_eckd_performance(device, argp);
3577
return dasd_eckd_release(device);
3579
return dasd_eckd_reserve(device);
3581
return dasd_eckd_steal_lock(device);
3583
return dasd_eckd_snid(device, argp);
3585
return dasd_symm_io(device, argp);
3587
return -ENOIOCTLCMD;
3592
* Dump the range of CCWs into 'page' buffer
3593
* and return number of printed chars.
3596
dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
3602
while (from <= to) {
3603
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3604
" CCW %p: %08X %08X DAT:",
3605
from, ((int *) from)[0], ((int *) from)[1]);
3607
/* get pointer to data (consider IDALs) */
3608
if (from->flags & CCW_FLAG_IDA)
3609
datap = (char *) *((addr_t *) (addr_t) from->cda);
3611
datap = (char *) ((addr_t) from->cda);
3613
/* dump data (max 32 bytes) */
3614
for (count = 0; count < from->count && count < 32; count++) {
3615
if (count % 8 == 0) len += sprintf(page + len, " ");
3616
if (count % 4 == 0) len += sprintf(page + len, " ");
3617
len += sprintf(page + len, "%02x", datap[count]);
3619
len += sprintf(page + len, "\n");
3626
dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
3632
sense = (u64 *) dasd_get_sense(irb);
3633
stat = (u64 *) &irb->scsw;
3635
DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
3636
"%016llx %016llx %016llx %016llx",
3637
reason, *stat, *((u32 *) (stat + 1)),
3638
sense[0], sense[1], sense[2], sense[3]);
3640
DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
3641
reason, *stat, *((u32 *) (stat + 1)),
3647
* Print sense data and related channel program.
3648
* Parts are printed because printk buffer is only 1024 bytes.
3650
static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
3651
struct dasd_ccw_req *req, struct irb *irb)
3654
struct ccw1 *first, *last, *fail, *from, *to;
3657
page = (char *) get_zeroed_page(GFP_ATOMIC);
3659
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3660
"No memory to dump sense data\n");
3663
/* dump the sense data */
3664
len = sprintf(page, KERN_ERR PRINTK_HEADER
3665
" I/O status report for device %s:\n",
3666
dev_name(&device->cdev->dev));
3667
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3668
" in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3670
req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3671
scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3672
scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3673
req ? req->intrc : 0);
3674
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3675
" device %s: Failing CCW: %p\n",
3676
dev_name(&device->cdev->dev),
3677
(void *) (addr_t) irb->scsw.cmd.cpa);
3678
if (irb->esw.esw0.erw.cons) {
3679
for (sl = 0; sl < 4; sl++) {
3680
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3681
" Sense(hex) %2d-%2d:",
3682
(8 * sl), ((8 * sl) + 7));
3684
for (sct = 0; sct < 8; sct++) {
3685
len += sprintf(page + len, " %02x",
3686
irb->ecw[8 * sl + sct]);
3688
len += sprintf(page + len, "\n");
3691
if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3692
/* 24 Byte Sense Data */
3693
sprintf(page + len, KERN_ERR PRINTK_HEADER
3694
" 24 Byte: %x MSG %x, "
3695
"%s MSGb to SYSOP\n",
3696
irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3697
irb->ecw[1] & 0x10 ? "" : "no");
3699
/* 32 Byte Sense Data */
3700
sprintf(page + len, KERN_ERR PRINTK_HEADER
3701
" 32 Byte: Format: %x "
3702
"Exception class %x\n",
3703
irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
3706
sprintf(page + len, KERN_ERR PRINTK_HEADER
3707
" SORRY - NO VALID SENSE AVAILABLE\n");
3712
/* req == NULL for unsolicited interrupts */
3713
/* dump the Channel Program (max 140 Bytes per line) */
3714
/* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3715
first = req->cpaddr;
3716
for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3717
to = min(first + 6, last);
3718
len = sprintf(page, KERN_ERR PRINTK_HEADER
3719
" Related CP in req: %p\n", req);
3720
dasd_eckd_dump_ccw_range(first, to, page + len);
3723
/* print failing CCW area (maximum 4) */
3724
/* scsw->cda is either valid or zero */
3727
fail = (struct ccw1 *)(addr_t)
3728
irb->scsw.cmd.cpa; /* failing CCW */
3729
if (from < fail - 2) {
3730
from = fail - 2; /* there is a gap - print header */
3731
len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3733
to = min(fail + 1, last);
3734
len += dasd_eckd_dump_ccw_range(from, to, page + len);
3736
/* print last CCWs (maximum 2) */
3737
from = max(from, ++to);
3738
if (from < last - 1) {
3739
from = last - 1; /* there is a gap - print header */
3740
len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3742
len += dasd_eckd_dump_ccw_range(from, last, page + len);
3746
free_page((unsigned long) page);
3751
* Print sense data from a tcw.
3753
static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3754
struct dasd_ccw_req *req, struct irb *irb)
3757
int len, sl, sct, residual;
3761
page = (char *) get_zeroed_page(GFP_ATOMIC);
3763
DBF_DEV_EVENT(DBF_WARNING, device, " %s",
3764
"No memory to dump sense data");
3767
/* dump the sense data */
3768
len = sprintf(page, KERN_ERR PRINTK_HEADER
3769
" I/O status report for device %s:\n",
3770
dev_name(&device->cdev->dev));
3771
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3772
" in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3773
"CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
3774
req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3775
scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3776
scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3777
irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
3778
req ? req->intrc : 0);
3779
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3780
" device %s: Failing TCW: %p\n",
3781
dev_name(&device->cdev->dev),
3782
(void *) (addr_t) irb->scsw.tm.tcw);
3786
if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
3788
(struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3791
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3792
" tsb->length %d\n", tsb->length);
3793
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3794
" tsb->flags %x\n", tsb->flags);
3795
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3796
" tsb->dcw_offset %d\n", tsb->dcw_offset);
3797
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3798
" tsb->count %d\n", tsb->count);
3799
residual = tsb->count - 28;
3800
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3801
" residual %d\n", residual);
3803
switch (tsb->flags & 0x07) {
3804
case 1: /* tsa_iostat */
3805
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3806
" tsb->tsa.iostat.dev_time %d\n",
3807
tsb->tsa.iostat.dev_time);
3808
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3809
" tsb->tsa.iostat.def_time %d\n",
3810
tsb->tsa.iostat.def_time);
3811
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3812
" tsb->tsa.iostat.queue_time %d\n",
3813
tsb->tsa.iostat.queue_time);
3814
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3815
" tsb->tsa.iostat.dev_busy_time %d\n",
3816
tsb->tsa.iostat.dev_busy_time);
3817
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3818
" tsb->tsa.iostat.dev_act_time %d\n",
3819
tsb->tsa.iostat.dev_act_time);
3820
sense = tsb->tsa.iostat.sense;
3822
case 2: /* ts_ddpc */
3823
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3824
" tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3825
for (sl = 0; sl < 2; sl++) {
3826
len += sprintf(page + len,
3827
KERN_ERR PRINTK_HEADER
3828
" tsb->tsa.ddpc.rcq %2d-%2d: ",
3829
(8 * sl), ((8 * sl) + 7));
3830
rcq = tsb->tsa.ddpc.rcq;
3831
for (sct = 0; sct < 8; sct++) {
3832
len += sprintf(page + len, " %02x",
3835
len += sprintf(page + len, "\n");
3837
sense = tsb->tsa.ddpc.sense;
3839
case 3: /* tsa_intrg */
3840
len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3841
" tsb->tsa.intrg.: not supportet yet \n");
3846
for (sl = 0; sl < 4; sl++) {
3847
len += sprintf(page + len,
3848
KERN_ERR PRINTK_HEADER
3849
" Sense(hex) %2d-%2d:",
3850
(8 * sl), ((8 * sl) + 7));
3851
for (sct = 0; sct < 8; sct++) {
3852
len += sprintf(page + len, " %02x",
3853
sense[8 * sl + sct]);
3855
len += sprintf(page + len, "\n");
3858
if (sense[27] & DASD_SENSE_BIT_0) {
3859
/* 24 Byte Sense Data */
3860
sprintf(page + len, KERN_ERR PRINTK_HEADER
3861
" 24 Byte: %x MSG %x, "
3862
"%s MSGb to SYSOP\n",
3863
sense[7] >> 4, sense[7] & 0x0f,
3864
sense[1] & 0x10 ? "" : "no");
3866
/* 32 Byte Sense Data */
3867
sprintf(page + len, KERN_ERR PRINTK_HEADER
3868
" 32 Byte: Format: %x "
3869
"Exception class %x\n",
3870
sense[6] & 0x0f, sense[22] >> 4);
3873
sprintf(page + len, KERN_ERR PRINTK_HEADER
3874
" SORRY - NO VALID SENSE AVAILABLE\n");
3877
sprintf(page + len, KERN_ERR PRINTK_HEADER
3878
" SORRY - NO TSB DATA AVAILABLE\n");
3881
free_page((unsigned long) page);
3884
static void dasd_eckd_dump_sense(struct dasd_device *device,
3885
struct dasd_ccw_req *req, struct irb *irb)
3887
if (scsw_is_tm(&irb->scsw))
3888
dasd_eckd_dump_sense_tcw(device, req, irb);
3890
dasd_eckd_dump_sense_ccw(device, req, irb);
3893
static int dasd_eckd_pm_freeze(struct dasd_device *device)
3896
* the device should be disconnected from our LCU structure
3897
* on restore we will reconnect it and reread LCU specific
3898
* information like PAV support that might have changed
3900
dasd_alias_remove_device(device);
3901
dasd_alias_disconnect_device_from_lcu(device);
3906
static int dasd_eckd_restore_device(struct dasd_device *device)
3908
struct dasd_eckd_private *private;
3909
struct dasd_eckd_characteristics temp_rdc_data;
3911
struct dasd_uid temp_uid;
3912
unsigned long flags;
3914
private = (struct dasd_eckd_private *) device->private;
3916
/* Read Configuration Data */
3917
rc = dasd_eckd_read_conf(device);
3921
dasd_eckd_get_uid(device, &temp_uid);
3922
/* Generate device unique id */
3923
rc = dasd_eckd_generate_uid(device);
3924
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3925
if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
3926
dev_err(&device->cdev->dev, "The UID of the DASD has "
3928
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3932
/* register lcu with alias handling, enable PAV if this is a new lcu */
3933
is_known = dasd_alias_make_device_known_to_lcu(device);
3937
dasd_eckd_validate_server(device);
3938
dasd_alias_lcu_setup_complete(device);
3940
dasd_alias_wait_for_lcu_setup(device);
3942
/* RE-Read Configuration Data */
3943
rc = dasd_eckd_read_conf(device);
3947
/* Read Feature Codes */
3948
dasd_eckd_read_features(device);
3950
/* Read Device Characteristics */
3951
rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
3952
&temp_rdc_data, 64);
3954
DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
3955
"Read device characteristic failed, rc=%d", rc);
3958
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3959
memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
3960
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3962
/* add device to alias management */
3963
dasd_alias_add_device(device);
3971
static int dasd_eckd_reload_device(struct dasd_device *device)
3973
struct dasd_eckd_private *private;
3976
struct dasd_uid uid;
3977
unsigned long flags;
3979
private = (struct dasd_eckd_private *) device->private;
3981
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3982
old_base = private->uid.base_unit_addr;
3983
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3985
/* Read Configuration Data */
3986
rc = dasd_eckd_read_conf(device);
3990
rc = dasd_eckd_generate_uid(device);
3994
* update unit address configuration and
3995
* add device to alias management
3997
dasd_alias_update_add_device(device);
3999
dasd_eckd_get_uid(device, &uid);
4001
if (old_base != uid.base_unit_addr) {
4002
if (strlen(uid.vduit) > 0)
4003
snprintf(print_uid, sizeof(print_uid),
4004
"%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
4005
uid.ssid, uid.base_unit_addr, uid.vduit);
4007
snprintf(print_uid, sizeof(print_uid),
4008
"%s.%s.%04x.%02x", uid.vendor, uid.serial,
4009
uid.ssid, uid.base_unit_addr);
4011
dev_info(&device->cdev->dev,
4012
"An Alias device was reassigned to a new base device "
4013
"with UID: %s\n", print_uid);
4021
static struct ccw_driver dasd_eckd_driver = {
4023
.name = "dasd-eckd",
4024
.owner = THIS_MODULE,
4026
.ids = dasd_eckd_ids,
4027
.probe = dasd_eckd_probe,
4028
.remove = dasd_generic_remove,
4029
.set_offline = dasd_generic_set_offline,
4030
.set_online = dasd_eckd_set_online,
4031
.notify = dasd_generic_notify,
4032
.path_event = dasd_generic_path_event,
4033
.freeze = dasd_generic_pm_freeze,
4034
.thaw = dasd_generic_restore_device,
4035
.restore = dasd_generic_restore_device,
4036
.uc_handler = dasd_generic_uc_handler,
4037
.int_class = IOINT_DAS,
4041
* max_blocks is dependent on the amount of storage that is available
4042
* in the static io buffer for each device. Currently each device has
4043
* 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4044
* 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4045
* up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4046
* addition we have one define extent ccw + 16 bytes of data and one
4047
* locate record ccw + 16 bytes of data. That makes:
4048
* (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4049
* We want to fit two into the available memory so that we can immediately
4050
* start the next request if one finishes off. That makes 249.5 blocks
4051
* for one request. Give a little safety and the result is 240.
4053
static struct dasd_discipline dasd_eckd_discipline = {
4054
.owner = THIS_MODULE,
4058
.check_device = dasd_eckd_check_characteristics,
4059
.uncheck_device = dasd_eckd_uncheck_device,
4060
.do_analysis = dasd_eckd_do_analysis,
4061
.verify_path = dasd_eckd_verify_path,
4062
.ready_to_online = dasd_eckd_ready_to_online,
4063
.online_to_ready = dasd_eckd_online_to_ready,
4064
.fill_geometry = dasd_eckd_fill_geometry,
4065
.start_IO = dasd_start_IO,
4066
.term_IO = dasd_term_IO,
4067
.handle_terminated_request = dasd_eckd_handle_terminated_request,
4068
.format_device = dasd_eckd_format_device,
4069
.erp_action = dasd_eckd_erp_action,
4070
.erp_postaction = dasd_eckd_erp_postaction,
4071
.check_for_device_change = dasd_eckd_check_for_device_change,
4072
.build_cp = dasd_eckd_build_alias_cp,
4073
.free_cp = dasd_eckd_free_alias_cp,
4074
.dump_sense = dasd_eckd_dump_sense,
4075
.dump_sense_dbf = dasd_eckd_dump_sense_dbf,
4076
.fill_info = dasd_eckd_fill_info,
4077
.ioctl = dasd_eckd_ioctl,
4078
.freeze = dasd_eckd_pm_freeze,
4079
.restore = dasd_eckd_restore_device,
4080
.reload = dasd_eckd_reload_device,
4081
.get_uid = dasd_eckd_get_uid,
4085
dasd_eckd_init(void)
4089
ASCEBC(dasd_eckd_discipline.ebcname, 4);
4090
dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4091
GFP_KERNEL | GFP_DMA);
4092
if (!dasd_reserve_req)
4094
path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4095
GFP_KERNEL | GFP_DMA);
4096
if (!path_verification_worker) {
4097
kfree(dasd_reserve_req);
4100
ret = ccw_driver_register(&dasd_eckd_driver);
4102
wait_for_device_probe();
4104
kfree(path_verification_worker);
4105
kfree(dasd_reserve_req);
4111
dasd_eckd_cleanup(void)
4113
ccw_driver_unregister(&dasd_eckd_driver);
4114
kfree(path_verification_worker);
4115
kfree(dasd_reserve_req);
4118
module_init(dasd_eckd_init);
4119
module_exit(dasd_eckd_cleanup);