]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/s390/block/dasd_eckd.c
s390/dasd: process all requests in the device tasklet
[mirror_ubuntu-hirsute-kernel.git] / drivers / s390 / block / dasd_eckd.c
CommitLineData
138c014d 1/*
1da177e4 2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
138c014d 3 * Horst Hummel <Horst.Hummel@de.ibm.com>
1da177e4
LT
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
d41dd122 7 * Copyright IBM Corp. 1999, 2009
ab1d848f
NH
8 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
9 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
1da177e4
LT
10 */
11
ca99dab0 12#define KMSG_COMPONENT "dasd-eckd"
fc19f381 13
1da177e4
LT
14#include <linux/stddef.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/hdreg.h> /* HDIO_GETGEO */
18#include <linux/bio.h>
19#include <linux/module.h>
048cd4e5 20#include <linux/compat.h>
1da177e4
LT
21#include <linux/init.h>
22
382b7366 23#include <asm/css_chars.h>
1da177e4
LT
24#include <asm/debug.h>
25#include <asm/idals.h>
26#include <asm/ebcdic.h>
27#include <asm/io.h>
1da177e4 28#include <asm/uaccess.h>
40545573 29#include <asm/cio.h>
1da177e4 30#include <asm/ccwdev.h>
f3eb5384 31#include <asm/itcw.h>
1da177e4
LT
32
33#include "dasd_int.h"
34#include "dasd_eckd.h"
35
36#ifdef PRINTK_HEADER
37#undef PRINTK_HEADER
38#endif /* PRINTK_HEADER */
39#define PRINTK_HEADER "dasd(eckd):"
40
41#define ECKD_C0(i) (i->home_bytes)
42#define ECKD_F(i) (i->formula)
43#define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
44 (i->factors.f_0x02.f1))
45#define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
46 (i->factors.f_0x02.f2))
47#define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
48 (i->factors.f_0x02.f3))
49#define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
50#define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
51#define ECKD_F6(i) (i->factor6)
52#define ECKD_F7(i) (i->factor7)
53#define ECKD_F8(i) (i->factor8)
54
e4dbb0f2
SH
55/*
56 * raw track access always map to 64k in memory
57 * so it maps to 16 blocks of 4k per track
58 */
59#define DASD_RAW_BLOCK_PER_TRACK 16
60#define DASD_RAW_BLOCKSIZE 4096
61/* 64k are 128 x 512 byte sectors */
62#define DASD_RAW_SECTORS_PER_TRACK 128
63
1da177e4
LT
64MODULE_LICENSE("GPL");
65
66static struct dasd_discipline dasd_eckd_discipline;
67
1da177e4
LT
68/* The ccw bus type uses this table to find devices that it sends to
69 * dasd_eckd_probe */
70static struct ccw_device_id dasd_eckd_ids[] = {
d2c993d8
HC
71 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
5da24b76 73 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
d2c993d8
HC
74 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
75 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
76 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
77 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
78 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
79 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
80 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
1da177e4
LT
81 { /* end of list */ },
82};
83
84MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
85
86static struct ccw_driver dasd_eckd_driver; /* see below */
87
eb6e199b
SW
88#define INIT_CQR_OK 0
89#define INIT_CQR_UNFORMATTED 1
90#define INIT_CQR_ERROR 2
91
f932bcea
SW
92/* emergency request for reserve/release */
93static struct {
94 struct dasd_ccw_req cqr;
95 struct ccw1 ccw;
96 char data[32];
97} *dasd_reserve_req;
98static DEFINE_MUTEX(dasd_reserve_mutex);
99
a4d26c6a
SW
100/* definitions for the path verification worker */
101struct path_verification_work_data {
102 struct work_struct worker;
103 struct dasd_device *device;
104 struct dasd_ccw_req cqr;
105 struct ccw1 ccw;
106 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
107 int isglobal;
108 __u8 tbvpm;
109};
110static struct path_verification_work_data *path_verification_worker;
111static DEFINE_MUTEX(dasd_path_verification_mutex);
eb6e199b 112
1da177e4
LT
113/* initial attempt at a probe function. this can be simplified once
114 * the other detection code is gone */
115static int
116dasd_eckd_probe (struct ccw_device *cdev)
117{
118 int ret;
119
40545573 120 /* set ECKD specific ccw-device options */
454e1fa1
PO
121 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
122 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
40545573 123 if (ret) {
b8ed5dd5
SH
124 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
125 "dasd_eckd_probe: could not set "
126 "ccw-device options");
1da177e4 127 return ret;
40545573
HH
128 }
129 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
130 return ret;
1da177e4
LT
131}
132
133static int
134dasd_eckd_set_online(struct ccw_device *cdev)
135{
40545573 136 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
1da177e4
LT
137}
138
1da177e4
LT
139static const int sizes_trk0[] = { 28, 148, 84 };
140#define LABEL_SIZE 140
141
3bc9fef9
SH
142/* head and record addresses of count_area read in analysis ccw */
143static const int count_area_head[] = { 0, 0, 0, 0, 2 };
144static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
145
1da177e4
LT
146static inline unsigned int
147round_up_multiple(unsigned int no, unsigned int mult)
148{
149 int rem = no % mult;
150 return (rem ? no - rem + mult : no);
151}
152
153static inline unsigned int
154ceil_quot(unsigned int d1, unsigned int d2)
155{
156 return (d1 + (d2 - 1)) / d2;
157}
158
4d284cac 159static unsigned int
1da177e4
LT
160recs_per_track(struct dasd_eckd_characteristics * rdc,
161 unsigned int kl, unsigned int dl)
162{
163 int dn, kn;
164
165 switch (rdc->dev_type) {
166 case 0x3380:
167 if (kl)
168 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
169 ceil_quot(dl + 12, 32));
170 else
171 return 1499 / (15 + ceil_quot(dl + 12, 32));
172 case 0x3390:
173 dn = ceil_quot(dl + 6, 232) + 1;
174 if (kl) {
175 kn = ceil_quot(kl + 6, 232) + 1;
176 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
177 9 + ceil_quot(dl + 6 * dn, 34));
178 } else
179 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
180 case 0x9345:
181 dn = ceil_quot(dl + 6, 232) + 1;
182 if (kl) {
183 kn = ceil_quot(kl + 6, 232) + 1;
184 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
185 ceil_quot(dl + 6 * dn, 34));
186 } else
187 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
188 }
189 return 0;
190}
191
b44b0ab3
SW
192static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
193{
194 geo->cyl = (__u16) cyl;
195 geo->head = cyl >> 16;
196 geo->head <<= 4;
197 geo->head |= head;
198}
199
4d284cac 200static int
1da177e4
LT
201check_XRC (struct ccw1 *de_ccw,
202 struct DE_eckd_data *data,
203 struct dasd_device *device)
204{
205 struct dasd_eckd_private *private;
d54853ef 206 int rc;
1da177e4
LT
207
208 private = (struct dasd_eckd_private *) device->private;
d54853ef
MS
209 if (!private->rdc_data.facilities.XRC_supported)
210 return 0;
1da177e4
LT
211
212 /* switch on System Time Stamp - needed for XRC Support */
d54853ef
MS
213 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
214 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
1da177e4 215
d54853ef
MS
216 rc = get_sync_clock(&data->ep_sys_time);
217 /* Ignore return code if sync clock is switched off. */
a8f6db4d 218 if (rc == -EOPNOTSUPP || rc == -EACCES)
d54853ef 219 rc = 0;
1da177e4 220
8e09f215 221 de_ccw->count = sizeof(struct DE_eckd_data);
d54853ef
MS
222 de_ccw->flags |= CCW_FLAG_SLI;
223 return rc;
224}
1da177e4 225
4d284cac 226static int
b44b0ab3
SW
227define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
228 unsigned int totrk, int cmd, struct dasd_device *device)
1da177e4
LT
229{
230 struct dasd_eckd_private *private;
b44b0ab3
SW
231 u32 begcyl, endcyl;
232 u16 heads, beghead, endhead;
d54853ef 233 int rc = 0;
1da177e4
LT
234
235 private = (struct dasd_eckd_private *) device->private;
236
237 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
238 ccw->flags = 0;
239 ccw->count = 16;
240 ccw->cda = (__u32) __pa(data);
241
8e09f215 242 memset(data, 0, sizeof(struct DE_eckd_data));
1da177e4
LT
243 switch (cmd) {
244 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
245 case DASD_ECKD_CCW_READ_RECORD_ZERO:
246 case DASD_ECKD_CCW_READ:
247 case DASD_ECKD_CCW_READ_MT:
248 case DASD_ECKD_CCW_READ_CKD:
249 case DASD_ECKD_CCW_READ_CKD_MT:
250 case DASD_ECKD_CCW_READ_KD:
251 case DASD_ECKD_CCW_READ_KD_MT:
252 case DASD_ECKD_CCW_READ_COUNT:
253 data->mask.perm = 0x1;
254 data->attributes.operation = private->attrib.operation;
255 break;
256 case DASD_ECKD_CCW_WRITE:
257 case DASD_ECKD_CCW_WRITE_MT:
258 case DASD_ECKD_CCW_WRITE_KD:
259 case DASD_ECKD_CCW_WRITE_KD_MT:
260 data->mask.perm = 0x02;
261 data->attributes.operation = private->attrib.operation;
d54853ef 262 rc = check_XRC (ccw, data, device);
1da177e4
LT
263 break;
264 case DASD_ECKD_CCW_WRITE_CKD:
265 case DASD_ECKD_CCW_WRITE_CKD_MT:
266 data->attributes.operation = DASD_BYPASS_CACHE;
d54853ef 267 rc = check_XRC (ccw, data, device);
1da177e4
LT
268 break;
269 case DASD_ECKD_CCW_ERASE:
270 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
271 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
272 data->mask.perm = 0x3;
273 data->mask.auth = 0x1;
274 data->attributes.operation = DASD_BYPASS_CACHE;
d54853ef 275 rc = check_XRC (ccw, data, device);
1da177e4
LT
276 break;
277 default:
fc19f381
SH
278 dev_err(&device->cdev->dev,
279 "0x%x is not a known command\n", cmd);
1da177e4
LT
280 break;
281 }
282
283 data->attributes.mode = 0x3; /* ECKD */
284
285 if ((private->rdc_data.cu_type == 0x2105 ||
286 private->rdc_data.cu_type == 0x2107 ||
287 private->rdc_data.cu_type == 0x1750)
288 && !(private->uses_cdl && trk < 2))
289 data->ga_extended |= 0x40; /* Regular Data Format Mode */
290
b44b0ab3
SW
291 heads = private->rdc_data.trk_per_cyl;
292 begcyl = trk / heads;
293 beghead = trk % heads;
294 endcyl = totrk / heads;
295 endhead = totrk % heads;
1da177e4
LT
296
297 /* check for sequential prestage - enhance cylinder range */
298 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
299 data->attributes.operation == DASD_SEQ_ACCESS) {
138c014d 300
b44b0ab3
SW
301 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
302 endcyl += private->attrib.nr_cyl;
1da177e4 303 else
b44b0ab3 304 endcyl = (private->real_cyl - 1);
1da177e4
LT
305 }
306
b44b0ab3
SW
307 set_ch_t(&data->beg_ext, begcyl, beghead);
308 set_ch_t(&data->end_ext, endcyl, endhead);
d54853ef 309 return rc;
1da177e4
LT
310}
311
8e09f215
SW
312static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
313 struct dasd_device *device)
314{
315 struct dasd_eckd_private *private;
316 int rc;
317
318 private = (struct dasd_eckd_private *) device->private;
319 if (!private->rdc_data.facilities.XRC_supported)
320 return 0;
321
322 /* switch on System Time Stamp - needed for XRC Support */
f3eb5384
SW
323 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
324 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
8e09f215
SW
325 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
326
f3eb5384 327 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
8e09f215 328 /* Ignore return code if sync clock is switched off. */
a8f6db4d 329 if (rc == -EOPNOTSUPP || rc == -EACCES)
8e09f215
SW
330 rc = 0;
331 return rc;
332}
333
f3eb5384
SW
334static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
335 unsigned int rec_on_trk, int count, int cmd,
336 struct dasd_device *device, unsigned int reclen,
337 unsigned int tlf)
338{
339 struct dasd_eckd_private *private;
340 int sector;
341 int dn, d;
342
343 private = (struct dasd_eckd_private *) device->private;
344
345 memset(data, 0, sizeof(*data));
346 sector = 0;
347 if (rec_on_trk) {
348 switch (private->rdc_data.dev_type) {
349 case 0x3390:
350 dn = ceil_quot(reclen + 6, 232);
351 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
352 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
353 break;
354 case 0x3380:
355 d = 7 + ceil_quot(reclen + 12, 32);
356 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
357 break;
358 }
359 }
360 data->sector = sector;
361 /* note: meaning of count depends on the operation
362 * for record based I/O it's the number of records, but for
363 * track based I/O it's the number of tracks
364 */
365 data->count = count;
366 switch (cmd) {
367 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
368 data->operation.orientation = 0x3;
369 data->operation.operation = 0x03;
370 break;
371 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
372 data->operation.orientation = 0x3;
373 data->operation.operation = 0x16;
374 break;
375 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
376 data->operation.orientation = 0x1;
377 data->operation.operation = 0x03;
378 data->count++;
379 break;
380 case DASD_ECKD_CCW_READ_RECORD_ZERO:
381 data->operation.orientation = 0x3;
382 data->operation.operation = 0x16;
383 data->count++;
384 break;
385 case DASD_ECKD_CCW_WRITE:
386 case DASD_ECKD_CCW_WRITE_MT:
387 case DASD_ECKD_CCW_WRITE_KD:
388 case DASD_ECKD_CCW_WRITE_KD_MT:
389 data->auxiliary.length_valid = 0x1;
390 data->length = reclen;
391 data->operation.operation = 0x01;
392 break;
393 case DASD_ECKD_CCW_WRITE_CKD:
394 case DASD_ECKD_CCW_WRITE_CKD_MT:
395 data->auxiliary.length_valid = 0x1;
396 data->length = reclen;
397 data->operation.operation = 0x03;
398 break;
e4dbb0f2
SH
399 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
400 data->operation.orientation = 0x0;
401 data->operation.operation = 0x3F;
402 data->extended_operation = 0x11;
403 data->length = 0;
404 data->extended_parameter_length = 0x02;
405 if (data->count > 8) {
406 data->extended_parameter[0] = 0xFF;
407 data->extended_parameter[1] = 0xFF;
408 data->extended_parameter[1] <<= (16 - count);
409 } else {
410 data->extended_parameter[0] = 0xFF;
411 data->extended_parameter[0] <<= (8 - count);
412 data->extended_parameter[1] = 0x00;
413 }
414 data->sector = 0xFF;
415 break;
f3eb5384
SW
416 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
417 data->auxiliary.length_valid = 0x1;
418 data->length = reclen; /* not tlf, as one might think */
419 data->operation.operation = 0x3F;
420 data->extended_operation = 0x23;
421 break;
422 case DASD_ECKD_CCW_READ:
423 case DASD_ECKD_CCW_READ_MT:
424 case DASD_ECKD_CCW_READ_KD:
425 case DASD_ECKD_CCW_READ_KD_MT:
426 data->auxiliary.length_valid = 0x1;
427 data->length = reclen;
428 data->operation.operation = 0x06;
429 break;
430 case DASD_ECKD_CCW_READ_CKD:
431 case DASD_ECKD_CCW_READ_CKD_MT:
432 data->auxiliary.length_valid = 0x1;
433 data->length = reclen;
434 data->operation.operation = 0x16;
435 break;
436 case DASD_ECKD_CCW_READ_COUNT:
437 data->operation.operation = 0x06;
438 break;
e4dbb0f2
SH
439 case DASD_ECKD_CCW_READ_TRACK:
440 data->operation.orientation = 0x1;
441 data->operation.operation = 0x0C;
442 data->extended_parameter_length = 0;
443 data->sector = 0xFF;
444 break;
f3eb5384
SW
445 case DASD_ECKD_CCW_READ_TRACK_DATA:
446 data->auxiliary.length_valid = 0x1;
447 data->length = tlf;
448 data->operation.operation = 0x0C;
449 break;
450 case DASD_ECKD_CCW_ERASE:
451 data->length = reclen;
452 data->auxiliary.length_valid = 0x1;
453 data->operation.operation = 0x0b;
454 break;
455 default:
456 DBF_DEV_EVENT(DBF_ERR, device,
457 "fill LRE unknown opcode 0x%x", cmd);
458 BUG();
459 }
460 set_ch_t(&data->seek_addr,
461 trk / private->rdc_data.trk_per_cyl,
462 trk % private->rdc_data.trk_per_cyl);
463 data->search_arg.cyl = data->seek_addr.cyl;
464 data->search_arg.head = data->seek_addr.head;
465 data->search_arg.record = rec_on_trk;
466}
467
468static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
469 unsigned int trk, unsigned int totrk, int cmd,
470 struct dasd_device *basedev, struct dasd_device *startdev,
471 unsigned char format, unsigned int rec_on_trk, int count,
472 unsigned int blksize, unsigned int tlf)
8e09f215
SW
473{
474 struct dasd_eckd_private *basepriv, *startpriv;
f3eb5384
SW
475 struct DE_eckd_data *dedata;
476 struct LRE_eckd_data *lredata;
b44b0ab3
SW
477 u32 begcyl, endcyl;
478 u16 heads, beghead, endhead;
8e09f215
SW
479 int rc = 0;
480
481 basepriv = (struct dasd_eckd_private *) basedev->private;
482 startpriv = (struct dasd_eckd_private *) startdev->private;
f3eb5384
SW
483 dedata = &pfxdata->define_extent;
484 lredata = &pfxdata->locate_record;
8e09f215
SW
485
486 ccw->cmd_code = DASD_ECKD_CCW_PFX;
487 ccw->flags = 0;
e4dbb0f2
SH
488 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
489 ccw->count = sizeof(*pfxdata) + 2;
490 ccw->cda = (__u32) __pa(pfxdata);
491 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
492 } else {
493 ccw->count = sizeof(*pfxdata);
494 ccw->cda = (__u32) __pa(pfxdata);
495 memset(pfxdata, 0, sizeof(*pfxdata));
496 }
8e09f215 497
8e09f215 498 /* prefix data */
f3eb5384
SW
499 if (format > 1) {
500 DBF_DEV_EVENT(DBF_ERR, basedev,
501 "PFX LRE unknown format 0x%x", format);
502 BUG();
503 return -EINVAL;
504 }
505 pfxdata->format = format;
4abb08c2
SW
506 pfxdata->base_address = basepriv->ned->unit_addr;
507 pfxdata->base_lss = basepriv->ned->ID;
f3eb5384 508 pfxdata->validity.define_extent = 1;
8e09f215
SW
509
510 /* private uid is kept up to date, conf_data may be outdated */
511 if (startpriv->uid.type != UA_BASE_DEVICE) {
512 pfxdata->validity.verify_base = 1;
513 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
514 pfxdata->validity.hyper_pav = 1;
515 }
516
517 /* define extend data (mostly)*/
518 switch (cmd) {
519 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
520 case DASD_ECKD_CCW_READ_RECORD_ZERO:
521 case DASD_ECKD_CCW_READ:
522 case DASD_ECKD_CCW_READ_MT:
523 case DASD_ECKD_CCW_READ_CKD:
524 case DASD_ECKD_CCW_READ_CKD_MT:
525 case DASD_ECKD_CCW_READ_KD:
526 case DASD_ECKD_CCW_READ_KD_MT:
527 case DASD_ECKD_CCW_READ_COUNT:
f3eb5384
SW
528 dedata->mask.perm = 0x1;
529 dedata->attributes.operation = basepriv->attrib.operation;
530 break;
e4dbb0f2 531 case DASD_ECKD_CCW_READ_TRACK:
f3eb5384
SW
532 case DASD_ECKD_CCW_READ_TRACK_DATA:
533 dedata->mask.perm = 0x1;
534 dedata->attributes.operation = basepriv->attrib.operation;
535 dedata->blk_size = 0;
8e09f215
SW
536 break;
537 case DASD_ECKD_CCW_WRITE:
538 case DASD_ECKD_CCW_WRITE_MT:
539 case DASD_ECKD_CCW_WRITE_KD:
540 case DASD_ECKD_CCW_WRITE_KD_MT:
f3eb5384
SW
541 dedata->mask.perm = 0x02;
542 dedata->attributes.operation = basepriv->attrib.operation;
8e09f215
SW
543 rc = check_XRC_on_prefix(pfxdata, basedev);
544 break;
545 case DASD_ECKD_CCW_WRITE_CKD:
546 case DASD_ECKD_CCW_WRITE_CKD_MT:
f3eb5384 547 dedata->attributes.operation = DASD_BYPASS_CACHE;
8e09f215
SW
548 rc = check_XRC_on_prefix(pfxdata, basedev);
549 break;
550 case DASD_ECKD_CCW_ERASE:
551 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
552 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
f3eb5384
SW
553 dedata->mask.perm = 0x3;
554 dedata->mask.auth = 0x1;
555 dedata->attributes.operation = DASD_BYPASS_CACHE;
8e09f215
SW
556 rc = check_XRC_on_prefix(pfxdata, basedev);
557 break;
e4dbb0f2
SH
558 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
559 dedata->mask.perm = 0x03;
560 dedata->attributes.operation = basepriv->attrib.operation;
561 dedata->blk_size = 0;
562 break;
f3eb5384
SW
563 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
564 dedata->mask.perm = 0x02;
565 dedata->attributes.operation = basepriv->attrib.operation;
566 dedata->blk_size = blksize;
567 rc = check_XRC_on_prefix(pfxdata, basedev);
8e09f215 568 break;
f3eb5384
SW
569 default:
570 DBF_DEV_EVENT(DBF_ERR, basedev,
571 "PFX LRE unknown opcode 0x%x", cmd);
572 BUG();
573 return -EINVAL;
8e09f215
SW
574 }
575
f3eb5384 576 dedata->attributes.mode = 0x3; /* ECKD */
8e09f215
SW
577
578 if ((basepriv->rdc_data.cu_type == 0x2105 ||
579 basepriv->rdc_data.cu_type == 0x2107 ||
580 basepriv->rdc_data.cu_type == 0x1750)
581 && !(basepriv->uses_cdl && trk < 2))
f3eb5384 582 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
8e09f215 583
b44b0ab3
SW
584 heads = basepriv->rdc_data.trk_per_cyl;
585 begcyl = trk / heads;
586 beghead = trk % heads;
587 endcyl = totrk / heads;
588 endhead = totrk % heads;
8e09f215
SW
589
590 /* check for sequential prestage - enhance cylinder range */
f3eb5384
SW
591 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
592 dedata->attributes.operation == DASD_SEQ_ACCESS) {
8e09f215 593
b44b0ab3
SW
594 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
595 endcyl += basepriv->attrib.nr_cyl;
8e09f215 596 else
b44b0ab3 597 endcyl = (basepriv->real_cyl - 1);
8e09f215
SW
598 }
599
f3eb5384
SW
600 set_ch_t(&dedata->beg_ext, begcyl, beghead);
601 set_ch_t(&dedata->end_ext, endcyl, endhead);
602
603 if (format == 1) {
604 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
605 basedev, blksize, tlf);
606 }
607
8e09f215
SW
608 return rc;
609}
610
f3eb5384
SW
611static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
612 unsigned int trk, unsigned int totrk, int cmd,
613 struct dasd_device *basedev, struct dasd_device *startdev)
614{
615 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
616 0, 0, 0, 0, 0);
617}
618
4d284cac 619static void
b44b0ab3
SW
620locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
621 unsigned int rec_on_trk, int no_rec, int cmd,
1da177e4
LT
622 struct dasd_device * device, int reclen)
623{
624 struct dasd_eckd_private *private;
625 int sector;
626 int dn, d;
138c014d 627
1da177e4
LT
628 private = (struct dasd_eckd_private *) device->private;
629
630 DBF_DEV_EVENT(DBF_INFO, device,
631 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
632 trk, rec_on_trk, no_rec, cmd, reclen);
633
634 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
635 ccw->flags = 0;
636 ccw->count = 16;
637 ccw->cda = (__u32) __pa(data);
638
8e09f215 639 memset(data, 0, sizeof(struct LO_eckd_data));
1da177e4
LT
640 sector = 0;
641 if (rec_on_trk) {
642 switch (private->rdc_data.dev_type) {
643 case 0x3390:
644 dn = ceil_quot(reclen + 6, 232);
645 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
646 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
647 break;
648 case 0x3380:
649 d = 7 + ceil_quot(reclen + 12, 32);
650 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
651 break;
652 }
653 }
654 data->sector = sector;
655 data->count = no_rec;
656 switch (cmd) {
657 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
658 data->operation.orientation = 0x3;
659 data->operation.operation = 0x03;
660 break;
661 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
662 data->operation.orientation = 0x3;
663 data->operation.operation = 0x16;
664 break;
665 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
666 data->operation.orientation = 0x1;
667 data->operation.operation = 0x03;
668 data->count++;
669 break;
670 case DASD_ECKD_CCW_READ_RECORD_ZERO:
671 data->operation.orientation = 0x3;
672 data->operation.operation = 0x16;
673 data->count++;
674 break;
675 case DASD_ECKD_CCW_WRITE:
676 case DASD_ECKD_CCW_WRITE_MT:
677 case DASD_ECKD_CCW_WRITE_KD:
678 case DASD_ECKD_CCW_WRITE_KD_MT:
679 data->auxiliary.last_bytes_used = 0x1;
680 data->length = reclen;
681 data->operation.operation = 0x01;
682 break;
683 case DASD_ECKD_CCW_WRITE_CKD:
684 case DASD_ECKD_CCW_WRITE_CKD_MT:
685 data->auxiliary.last_bytes_used = 0x1;
686 data->length = reclen;
687 data->operation.operation = 0x03;
688 break;
689 case DASD_ECKD_CCW_READ:
690 case DASD_ECKD_CCW_READ_MT:
691 case DASD_ECKD_CCW_READ_KD:
692 case DASD_ECKD_CCW_READ_KD_MT:
693 data->auxiliary.last_bytes_used = 0x1;
694 data->length = reclen;
695 data->operation.operation = 0x06;
696 break;
697 case DASD_ECKD_CCW_READ_CKD:
698 case DASD_ECKD_CCW_READ_CKD_MT:
699 data->auxiliary.last_bytes_used = 0x1;
700 data->length = reclen;
701 data->operation.operation = 0x16;
702 break;
703 case DASD_ECKD_CCW_READ_COUNT:
704 data->operation.operation = 0x06;
705 break;
706 case DASD_ECKD_CCW_ERASE:
707 data->length = reclen;
708 data->auxiliary.last_bytes_used = 0x1;
709 data->operation.operation = 0x0b;
710 break;
711 default:
fc19f381
SH
712 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
713 "opcode 0x%x", cmd);
1da177e4 714 }
b44b0ab3
SW
715 set_ch_t(&data->seek_addr,
716 trk / private->rdc_data.trk_per_cyl,
717 trk % private->rdc_data.trk_per_cyl);
718 data->search_arg.cyl = data->seek_addr.cyl;
719 data->search_arg.head = data->seek_addr.head;
1da177e4
LT
720 data->search_arg.record = rec_on_trk;
721}
722
723/*
724 * Returns 1 if the block is one of the special blocks that needs
725 * to get read/written with the KD variant of the command.
726 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
727 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
728 * Luckily the KD variants differ only by one bit (0x08) from the
729 * normal variant. So don't wonder about code like:
730 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
731 * ccw->cmd_code |= 0x8;
732 */
733static inline int
734dasd_eckd_cdl_special(int blk_per_trk, int recid)
735{
736 if (recid < 3)
737 return 1;
738 if (recid < blk_per_trk)
739 return 0;
740 if (recid < 2 * blk_per_trk)
741 return 1;
742 return 0;
743}
744
745/*
746 * Returns the record size for the special blocks of the cdl format.
747 * Only returns something useful if dasd_eckd_cdl_special is true
748 * for the recid.
749 */
750static inline int
751dasd_eckd_cdl_reclen(int recid)
752{
753 if (recid < 3)
754 return sizes_trk0[recid];
755 return LABEL_SIZE;
756}
b206181d
SH
757/* create unique id from private structure. */
758static void create_uid(struct dasd_eckd_private *private)
3d052595 759{
4abb08c2 760 int count;
b206181d 761 struct dasd_uid *uid;
3d052595 762
2dedf0d9 763 uid = &private->uid;
3d052595 764 memset(uid, 0, sizeof(struct dasd_uid));
4abb08c2 765 memcpy(uid->vendor, private->ned->HDA_manufacturer,
d0710c7c 766 sizeof(uid->vendor) - 1);
3d052595 767 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
4abb08c2 768 memcpy(uid->serial, private->ned->HDA_location,
d0710c7c 769 sizeof(uid->serial) - 1);
3d052595 770 EBCASC(uid->serial, sizeof(uid->serial) - 1);
4abb08c2 771 uid->ssid = private->gneq->subsystemID;
a419aef8 772 uid->real_unit_addr = private->ned->unit_addr;
4abb08c2
SW
773 if (private->sneq) {
774 uid->type = private->sneq->sua_flags;
8e09f215 775 if (uid->type == UA_BASE_PAV_ALIAS)
4abb08c2 776 uid->base_unit_addr = private->sneq->base_unit_addr;
8e09f215
SW
777 } else {
778 uid->type = UA_BASE_DEVICE;
779 }
4abb08c2
SW
780 if (private->vdsneq) {
781 for (count = 0; count < 16; count++) {
782 sprintf(uid->vduit+2*count, "%02x",
783 private->vdsneq->uit[count]);
784 }
785 }
b206181d
SH
786}
787
788/*
789 * Generate device unique id that specifies the physical device.
790 */
791static int dasd_eckd_generate_uid(struct dasd_device *device)
792{
793 struct dasd_eckd_private *private;
794 unsigned long flags;
795
796 private = (struct dasd_eckd_private *) device->private;
797 if (!private)
798 return -ENODEV;
799 if (!private->ned || !private->gneq)
800 return -ENODEV;
801 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
802 create_uid(private);
2dedf0d9 803 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3d052595
HH
804 return 0;
805}
806
2dedf0d9
SH
807static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
808{
809 struct dasd_eckd_private *private;
810 unsigned long flags;
811
812 if (device->private) {
813 private = (struct dasd_eckd_private *)device->private;
814 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
815 *uid = private->uid;
816 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
817 return 0;
818 }
819 return -EINVAL;
820}
821
b206181d
SH
822/*
823 * compare device UID with data of a given dasd_eckd_private structure
824 * return 0 for match
825 */
826static int dasd_eckd_compare_path_uid(struct dasd_device *device,
827 struct dasd_eckd_private *private)
828{
829 struct dasd_uid device_uid;
830
831 create_uid(private);
832 dasd_eckd_get_uid(device, &device_uid);
833
834 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
835}
836
a4d26c6a
SW
837static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
838 struct dasd_ccw_req *cqr,
839 __u8 *rcd_buffer,
840 __u8 lpm)
17283b56 841{
17283b56 842 struct ccw1 *ccw;
a4d26c6a
SW
843 /*
844 * buffer has to start with EBCDIC "V1.0" to show
845 * support for virtual device SNEQ
846 */
847 rcd_buffer[0] = 0xE5;
848 rcd_buffer[1] = 0xF1;
849 rcd_buffer[2] = 0x4B;
850 rcd_buffer[3] = 0xF0;
17283b56
CH
851
852 ccw = cqr->cpaddr;
a4d26c6a
SW
853 ccw->cmd_code = DASD_ECKD_CCW_RCD;
854 ccw->flags = 0;
17283b56 855 ccw->cda = (__u32)(addr_t)rcd_buffer;
a4d26c6a
SW
856 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
857 cqr->magic = DASD_ECKD_MAGIC;
17283b56 858
8e09f215
SW
859 cqr->startdev = device;
860 cqr->memdev = device;
861 cqr->block = NULL;
17283b56
CH
862 cqr->expires = 10*HZ;
863 cqr->lpm = lpm;
eb6e199b 864 cqr->retries = 256;
1aae0560 865 cqr->buildclk = get_tod_clock();
17283b56 866 cqr->status = DASD_CQR_FILLED;
a4d26c6a
SW
867 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
868}
869
5915a873
SH
870/*
871 * Wakeup helper for read_conf
872 * if the cqr is not done and needs some error recovery
873 * the buffer has to be re-initialized with the EBCDIC "V1.0"
874 * to show support for virtual device SNEQ
875 */
876static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
877{
878 struct ccw1 *ccw;
879 __u8 *rcd_buffer;
880
881 if (cqr->status != DASD_CQR_DONE) {
882 ccw = cqr->cpaddr;
883 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
884 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
885
886 rcd_buffer[0] = 0xE5;
887 rcd_buffer[1] = 0xF1;
888 rcd_buffer[2] = 0x4B;
889 rcd_buffer[3] = 0xF0;
890 }
891 dasd_wakeup_cb(cqr, data);
892}
893
a4d26c6a
SW
894static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
895 struct dasd_ccw_req *cqr,
896 __u8 *rcd_buffer,
897 __u8 lpm)
898{
899 struct ciw *ciw;
900 int rc;
901 /*
902 * sanity check: scan for RCD command in extended SenseID data
903 * some devices do not support RCD
904 */
905 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
906 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
907 return -EOPNOTSUPP;
908
909 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
910 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
5a27e60d 911 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
a4d26c6a 912 cqr->retries = 5;
5915a873 913 cqr->callback = read_conf_cb;
a4d26c6a
SW
914 rc = dasd_sleep_on_immediatly(cqr);
915 return rc;
17283b56
CH
916}
917
918static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
919 void **rcd_buffer,
920 int *rcd_buffer_size, __u8 lpm)
921{
922 struct ciw *ciw;
923 char *rcd_buf = NULL;
924 int ret;
925 struct dasd_ccw_req *cqr;
926
927 /*
a4d26c6a
SW
928 * sanity check: scan for RCD command in extended SenseID data
929 * some devices do not support RCD
17283b56
CH
930 */
931 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
a4d26c6a 932 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
17283b56
CH
933 ret = -EOPNOTSUPP;
934 goto out_error;
935 }
a4d26c6a 936 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
17283b56
CH
937 if (!rcd_buf) {
938 ret = -ENOMEM;
939 goto out_error;
940 }
a4d26c6a
SW
941 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
942 0, /* use rcd_buf as data ara */
943 device);
17283b56 944 if (IS_ERR(cqr)) {
a4d26c6a
SW
945 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
946 "Could not allocate RCD request");
947 ret = -ENOMEM;
17283b56
CH
948 goto out_error;
949 }
a4d26c6a 950 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
5915a873 951 cqr->callback = read_conf_cb;
17283b56
CH
952 ret = dasd_sleep_on(cqr);
953 /*
954 * on success we update the user input parms
955 */
8e09f215 956 dasd_sfree_request(cqr, cqr->memdev);
17283b56
CH
957 if (ret)
958 goto out_error;
959
a4d26c6a 960 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
17283b56
CH
961 *rcd_buffer = rcd_buf;
962 return 0;
963out_error:
964 kfree(rcd_buf);
965 *rcd_buffer = NULL;
966 *rcd_buffer_size = 0;
967 return ret;
968}
969
4abb08c2
SW
970static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
971{
972
973 struct dasd_sneq *sneq;
974 int i, count;
975
976 private->ned = NULL;
977 private->sneq = NULL;
978 private->vdsneq = NULL;
979 private->gneq = NULL;
980 count = private->conf_len / sizeof(struct dasd_sneq);
981 sneq = (struct dasd_sneq *)private->conf_data;
982 for (i = 0; i < count; ++i) {
983 if (sneq->flags.identifier == 1 && sneq->format == 1)
984 private->sneq = sneq;
985 else if (sneq->flags.identifier == 1 && sneq->format == 4)
986 private->vdsneq = (struct vd_sneq *)sneq;
987 else if (sneq->flags.identifier == 2)
988 private->gneq = (struct dasd_gneq *)sneq;
989 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
990 private->ned = (struct dasd_ned *)sneq;
991 sneq++;
992 }
993 if (!private->ned || !private->gneq) {
994 private->ned = NULL;
995 private->sneq = NULL;
996 private->vdsneq = NULL;
997 private->gneq = NULL;
998 return -EINVAL;
999 }
1000 return 0;
1001
1002};
1003
1004static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1005{
1006 struct dasd_gneq *gneq;
1007 int i, count, found;
1008
1009 count = conf_len / sizeof(*gneq);
1010 gneq = (struct dasd_gneq *)conf_data;
1011 found = 0;
1012 for (i = 0; i < count; ++i) {
1013 if (gneq->flags.identifier == 2) {
1014 found = 1;
1015 break;
1016 }
1017 gneq++;
1018 }
1019 if (found)
1020 return ((char *)gneq)[18] & 0x07;
1021 else
1022 return 0;
1023}
1024
1025static int dasd_eckd_read_conf(struct dasd_device *device)
1da177e4
LT
1026{
1027 void *conf_data;
1028 int conf_len, conf_data_saved;
55d3a85c 1029 int rc, path_err;
a4d26c6a 1030 __u8 lpm, opm;
b206181d 1031 struct dasd_eckd_private *private, path_private;
a4d26c6a 1032 struct dasd_path *path_data;
b206181d
SH
1033 struct dasd_uid *uid;
1034 char print_path_uid[60], print_device_uid[60];
1da177e4
LT
1035
1036 private = (struct dasd_eckd_private *) device->private;
a4d26c6a
SW
1037 path_data = &device->path_data;
1038 opm = ccw_device_get_path_mask(device->cdev);
1da177e4 1039 conf_data_saved = 0;
55d3a85c 1040 path_err = 0;
1da177e4
LT
1041 /* get configuration data per operational path */
1042 for (lpm = 0x80; lpm; lpm>>= 1) {
b206181d
SH
1043 if (!(lpm & opm))
1044 continue;
1045 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1046 &conf_len, lpm);
1047 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1048 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1049 "Read configuration data returned "
1050 "error %d", rc);
1051 return rc;
1052 }
1053 if (conf_data == NULL) {
1054 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1055 "No configuration data "
1056 "retrieved");
1057 /* no further analysis possible */
1058 path_data->opm |= lpm;
1059 continue; /* no error */
1060 }
1061 /* save first valid configuration data */
1062 if (!conf_data_saved) {
1063 kfree(private->conf_data);
1064 private->conf_data = conf_data;
1065 private->conf_len = conf_len;
1066 if (dasd_eckd_identify_conf_parts(private)) {
1067 private->conf_data = NULL;
1068 private->conf_len = 0;
1069 kfree(conf_data);
1070 continue;
1da177e4 1071 }
b206181d
SH
1072 /*
1073 * build device UID that other path data
1074 * can be compared to it
1075 */
1076 dasd_eckd_generate_uid(device);
1077 conf_data_saved++;
1078 } else {
1079 path_private.conf_data = conf_data;
1080 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1081 if (dasd_eckd_identify_conf_parts(
1082 &path_private)) {
1083 path_private.conf_data = NULL;
1084 path_private.conf_len = 0;
1085 kfree(conf_data);
1086 continue;
1da177e4 1087 }
b206181d
SH
1088
1089 if (dasd_eckd_compare_path_uid(
1090 device, &path_private)) {
1091 uid = &path_private.uid;
1092 if (strlen(uid->vduit) > 0)
1093 snprintf(print_path_uid,
1094 sizeof(print_path_uid),
1095 "%s.%s.%04x.%02x.%s",
1096 uid->vendor, uid->serial,
1097 uid->ssid, uid->real_unit_addr,
1098 uid->vduit);
1099 else
1100 snprintf(print_path_uid,
1101 sizeof(print_path_uid),
1102 "%s.%s.%04x.%02x",
1103 uid->vendor, uid->serial,
1104 uid->ssid,
1105 uid->real_unit_addr);
1106 uid = &private->uid;
1107 if (strlen(uid->vduit) > 0)
1108 snprintf(print_device_uid,
1109 sizeof(print_device_uid),
1110 "%s.%s.%04x.%02x.%s",
1111 uid->vendor, uid->serial,
1112 uid->ssid, uid->real_unit_addr,
1113 uid->vduit);
1114 else
1115 snprintf(print_device_uid,
1116 sizeof(print_device_uid),
1117 "%s.%s.%04x.%02x",
1118 uid->vendor, uid->serial,
1119 uid->ssid,
1120 uid->real_unit_addr);
1121 dev_err(&device->cdev->dev,
1122 "Not all channel paths lead to "
1123 "the same device, path %02X leads to "
1124 "device %s instead of %s\n", lpm,
1125 print_path_uid, print_device_uid);
55d3a85c
SH
1126 path_err = -EINVAL;
1127 continue;
1da177e4 1128 }
b206181d
SH
1129
1130 path_private.conf_data = NULL;
1131 path_private.conf_len = 0;
1132 }
1133 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1134 case 0x02:
1135 path_data->npm |= lpm;
1136 break;
1137 case 0x03:
1138 path_data->ppm |= lpm;
1139 break;
1da177e4 1140 }
b206181d
SH
1141 path_data->opm |= lpm;
1142
1143 if (conf_data != private->conf_data)
1144 kfree(conf_data);
1da177e4 1145 }
b206181d 1146
55d3a85c 1147 return path_err;
1da177e4
LT
1148}
1149
a4d26c6a
SW
1150static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1151{
1152 struct dasd_eckd_private *private;
1153 int mdc;
1154 u32 fcx_max_data;
1155
1156 private = (struct dasd_eckd_private *) device->private;
1157 if (private->fcx_max_data) {
1158 mdc = ccw_device_get_mdc(device->cdev, lpm);
1159 if ((mdc < 0)) {
1160 dev_warn(&device->cdev->dev,
1161 "Detecting the maximum data size for zHPF "
1162 "requests failed (rc=%d) for a new path %x\n",
1163 mdc, lpm);
1164 return mdc;
1165 }
1166 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1167 if (fcx_max_data < private->fcx_max_data) {
1168 dev_warn(&device->cdev->dev,
1169 "The maximum data size for zHPF requests %u "
1170 "on a new path %x is below the active maximum "
1171 "%u\n", fcx_max_data, lpm,
1172 private->fcx_max_data);
1173 return -EACCES;
1174 }
1175 }
1176 return 0;
1177}
1178
b206181d
SH
1179static int rebuild_device_uid(struct dasd_device *device,
1180 struct path_verification_work_data *data)
1181{
1182 struct dasd_eckd_private *private;
1183 struct dasd_path *path_data;
1184 __u8 lpm, opm;
1185 int rc;
1186
1187 rc = -ENODEV;
1188 private = (struct dasd_eckd_private *) device->private;
1189 path_data = &device->path_data;
1190 opm = device->path_data.opm;
1191
1192 for (lpm = 0x80; lpm; lpm >>= 1) {
1193 if (!(lpm & opm))
1194 continue;
1195 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1196 memset(&data->cqr, 0, sizeof(data->cqr));
1197 data->cqr.cpaddr = &data->ccw;
1198 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1199 data->rcd_buffer,
1200 lpm);
1201
1202 if (rc) {
1203 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1204 continue;
1205 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1206 "Read configuration data "
1207 "returned error %d", rc);
1208 break;
1209 }
1210 memcpy(private->conf_data, data->rcd_buffer,
1211 DASD_ECKD_RCD_DATA_SIZE);
1212 if (dasd_eckd_identify_conf_parts(private)) {
1213 rc = -ENODEV;
1214 } else /* first valid path is enough */
1215 break;
1216 }
1217
1218 if (!rc)
1219 rc = dasd_eckd_generate_uid(device);
1220
1221 return rc;
1222}
1223
a4d26c6a
SW
1224static void do_path_verification_work(struct work_struct *work)
1225{
1226 struct path_verification_work_data *data;
1227 struct dasd_device *device;
b206181d
SH
1228 struct dasd_eckd_private path_private;
1229 struct dasd_uid *uid;
1230 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
a4d26c6a
SW
1231 __u8 lpm, opm, npm, ppm, epm;
1232 unsigned long flags;
b206181d 1233 char print_uid[60];
a4d26c6a
SW
1234 int rc;
1235
1236 data = container_of(work, struct path_verification_work_data, worker);
1237 device = data->device;
1238
c8d1c0ff
SH
1239 /* delay path verification until device was resumed */
1240 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1241 schedule_work(work);
1242 return;
1243 }
1244
a4d26c6a
SW
1245 opm = 0;
1246 npm = 0;
1247 ppm = 0;
1248 epm = 0;
1249 for (lpm = 0x80; lpm; lpm >>= 1) {
b206181d
SH
1250 if (!(lpm & data->tbvpm))
1251 continue;
1252 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1253 memset(&data->cqr, 0, sizeof(data->cqr));
1254 data->cqr.cpaddr = &data->ccw;
1255 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1256 data->rcd_buffer,
1257 lpm);
1258 if (!rc) {
1259 switch (dasd_eckd_path_access(data->rcd_buffer,
1260 DASD_ECKD_RCD_DATA_SIZE)
1261 ) {
1262 case 0x02:
1263 npm |= lpm;
1264 break;
1265 case 0x03:
1266 ppm |= lpm;
1267 break;
1268 }
1269 opm |= lpm;
1270 } else if (rc == -EOPNOTSUPP) {
1271 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1272 "path verification: No configuration "
1273 "data retrieved");
1274 opm |= lpm;
1275 } else if (rc == -EAGAIN) {
1276 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
a4d26c6a
SW
1277 "path verification: device is stopped,"
1278 " try again later");
b206181d
SH
1279 epm |= lpm;
1280 } else {
1281 dev_warn(&device->cdev->dev,
1282 "Reading device feature codes failed "
1283 "(rc=%d) for new path %x\n", rc, lpm);
1284 continue;
1285 }
1286 if (verify_fcx_max_data(device, lpm)) {
1287 opm &= ~lpm;
1288 npm &= ~lpm;
1289 ppm &= ~lpm;
1290 continue;
1291 }
1292
1293 /*
1294 * save conf_data for comparison after
1295 * rebuild_device_uid may have changed
1296 * the original data
1297 */
1298 memcpy(&path_rcd_buf, data->rcd_buffer,
1299 DASD_ECKD_RCD_DATA_SIZE);
1300 path_private.conf_data = (void *) &path_rcd_buf;
1301 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1302 if (dasd_eckd_identify_conf_parts(&path_private)) {
1303 path_private.conf_data = NULL;
1304 path_private.conf_len = 0;
1305 continue;
1306 }
1307
1308 /*
1309 * compare path UID with device UID only if at least
1310 * one valid path is left
1311 * in other case the device UID may have changed and
1312 * the first working path UID will be used as device UID
1313 */
1314 if (device->path_data.opm &&
1315 dasd_eckd_compare_path_uid(device, &path_private)) {
1316 /*
1317 * the comparison was not successful
1318 * rebuild the device UID with at least one
1319 * known path in case a z/VM hyperswap command
1320 * has changed the device
1321 *
1322 * after this compare again
1323 *
1324 * if either the rebuild or the recompare fails
1325 * the path can not be used
1326 */
1327 if (rebuild_device_uid(device, data) ||
1328 dasd_eckd_compare_path_uid(
1329 device, &path_private)) {
1330 uid = &path_private.uid;
1331 if (strlen(uid->vduit) > 0)
1332 snprintf(print_uid, sizeof(print_uid),
1333 "%s.%s.%04x.%02x.%s",
1334 uid->vendor, uid->serial,
1335 uid->ssid, uid->real_unit_addr,
1336 uid->vduit);
1337 else
1338 snprintf(print_uid, sizeof(print_uid),
1339 "%s.%s.%04x.%02x",
1340 uid->vendor, uid->serial,
1341 uid->ssid,
1342 uid->real_unit_addr);
1343 dev_err(&device->cdev->dev,
1344 "The newly added channel path %02X "
1345 "will not be used because it leads "
1346 "to a different device %s\n",
1347 lpm, print_uid);
a4d26c6a
SW
1348 opm &= ~lpm;
1349 npm &= ~lpm;
1350 ppm &= ~lpm;
b206181d 1351 continue;
a4d26c6a
SW
1352 }
1353 }
b206181d
SH
1354
1355 /*
1356 * There is a small chance that a path is lost again between
1357 * above path verification and the following modification of
1358 * the device opm mask. We could avoid that race here by using
1359 * yet another path mask, but we rather deal with this unlikely
1360 * situation in dasd_start_IO.
1361 */
1362 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1363 if (!device->path_data.opm && opm) {
1364 device->path_data.opm = opm;
1365 dasd_generic_path_operational(device);
1366 } else
1367 device->path_data.opm |= opm;
1368 device->path_data.npm |= npm;
1369 device->path_data.ppm |= ppm;
1370 device->path_data.tbvpm |= epm;
1371 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
a4d26c6a 1372 }
a4d26c6a
SW
1373
1374 dasd_put_device(device);
1375 if (data->isglobal)
1376 mutex_unlock(&dasd_path_verification_mutex);
1377 else
1378 kfree(data);
1379}
1380
1381static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1382{
1383 struct path_verification_work_data *data;
1384
1385 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1386 if (!data) {
1387 if (mutex_trylock(&dasd_path_verification_mutex)) {
1388 data = path_verification_worker;
1389 data->isglobal = 1;
1390 } else
1391 return -ENOMEM;
1392 } else {
1393 memset(data, 0, sizeof(*data));
1394 data->isglobal = 0;
1395 }
1396 INIT_WORK(&data->worker, do_path_verification_work);
1397 dasd_get_device(device);
1398 data->device = device;
1399 data->tbvpm = lpm;
1400 schedule_work(&data->worker);
1401 return 0;
1402}
1403
8e09f215
SW
1404static int dasd_eckd_read_features(struct dasd_device *device)
1405{
1406 struct dasd_psf_prssd_data *prssdp;
1407 struct dasd_rssd_features *features;
1408 struct dasd_ccw_req *cqr;
1409 struct ccw1 *ccw;
1410 int rc;
1411 struct dasd_eckd_private *private;
1412
1413 private = (struct dasd_eckd_private *) device->private;
68d1e5f0 1414 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
68b781fe 1415 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
8e09f215
SW
1416 (sizeof(struct dasd_psf_prssd_data) +
1417 sizeof(struct dasd_rssd_features)),
1418 device);
1419 if (IS_ERR(cqr)) {
b8ed5dd5
SH
1420 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1421 "allocate initialization request");
8e09f215
SW
1422 return PTR_ERR(cqr);
1423 }
1424 cqr->startdev = device;
1425 cqr->memdev = device;
1426 cqr->block = NULL;
eb6e199b 1427 cqr->retries = 256;
8e09f215
SW
1428 cqr->expires = 10 * HZ;
1429
1430 /* Prepare for Read Subsystem Data */
1431 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1432 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1433 prssdp->order = PSF_ORDER_PRSSD;
1434 prssdp->suborder = 0x41; /* Read Feature Codes */
1435 /* all other bytes of prssdp must be zero */
1436
1437 ccw = cqr->cpaddr;
1438 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1439 ccw->count = sizeof(struct dasd_psf_prssd_data);
1440 ccw->flags |= CCW_FLAG_CC;
1441 ccw->cda = (__u32)(addr_t) prssdp;
1442
1443 /* Read Subsystem Data - feature codes */
1444 features = (struct dasd_rssd_features *) (prssdp + 1);
1445 memset(features, 0, sizeof(struct dasd_rssd_features));
1446
1447 ccw++;
1448 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1449 ccw->count = sizeof(struct dasd_rssd_features);
1450 ccw->cda = (__u32)(addr_t) features;
1451
1aae0560 1452 cqr->buildclk = get_tod_clock();
8e09f215
SW
1453 cqr->status = DASD_CQR_FILLED;
1454 rc = dasd_sleep_on(cqr);
1455 if (rc == 0) {
1456 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1457 features = (struct dasd_rssd_features *) (prssdp + 1);
1458 memcpy(&private->features, features,
1459 sizeof(struct dasd_rssd_features));
68d1e5f0
SW
1460 } else
1461 dev_warn(&device->cdev->dev, "Reading device feature codes"
1462 " failed with rc=%d\n", rc);
8e09f215
SW
1463 dasd_sfree_request(cqr, cqr->memdev);
1464 return rc;
1465}
1466
1467
40545573
HH
1468/*
1469 * Build CP for Perform Subsystem Function - SSC.
1470 */
f3eb5384
SW
1471static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1472 int enable_pav)
40545573 1473{
8e09f215
SW
1474 struct dasd_ccw_req *cqr;
1475 struct dasd_psf_ssc_data *psf_ssc_data;
1476 struct ccw1 *ccw;
40545573 1477
68b781fe 1478 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
40545573
HH
1479 sizeof(struct dasd_psf_ssc_data),
1480 device);
1481
8e09f215 1482 if (IS_ERR(cqr)) {
fc19f381 1483 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
40545573 1484 "Could not allocate PSF-SSC request");
8e09f215
SW
1485 return cqr;
1486 }
1487 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1488 psf_ssc_data->order = PSF_ORDER_SSC;
626350b6 1489 psf_ssc_data->suborder = 0xc0;
f3eb5384 1490 if (enable_pav) {
626350b6 1491 psf_ssc_data->suborder |= 0x08;
f3eb5384
SW
1492 psf_ssc_data->reserved[0] = 0x88;
1493 }
8e09f215
SW
1494 ccw = cqr->cpaddr;
1495 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1496 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1497 ccw->count = 66;
1498
1499 cqr->startdev = device;
1500 cqr->memdev = device;
1501 cqr->block = NULL;
eb6e199b 1502 cqr->retries = 256;
8e09f215 1503 cqr->expires = 10*HZ;
1aae0560 1504 cqr->buildclk = get_tod_clock();
8e09f215
SW
1505 cqr->status = DASD_CQR_FILLED;
1506 return cqr;
40545573
HH
1507}
1508
1509/*
1510 * Perform Subsystem Function.
1511 * It is necessary to trigger CIO for channel revalidation since this
1512 * call might change behaviour of DASD devices.
1513 */
1514static int
12d7b107
SH
1515dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1516 unsigned long flags)
40545573 1517{
8e09f215
SW
1518 struct dasd_ccw_req *cqr;
1519 int rc;
1520
f3eb5384 1521 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
8e09f215
SW
1522 if (IS_ERR(cqr))
1523 return PTR_ERR(cqr);
1524
12d7b107
SH
1525 /*
1526 * set flags e.g. turn on failfast, to prevent blocking
1527 * the calling function should handle failed requests
1528 */
1529 cqr->flags |= flags;
1530
8e09f215
SW
1531 rc = dasd_sleep_on(cqr);
1532 if (!rc)
1533 /* trigger CIO to reprobe devices */
1534 css_schedule_reprobe();
12d7b107
SH
1535 else if (cqr->intrc == -EAGAIN)
1536 rc = -EAGAIN;
1537
8e09f215
SW
1538 dasd_sfree_request(cqr, cqr->memdev);
1539 return rc;
40545573
HH
1540}
1541
1542/*
1543 * Valide storage server of current device.
1544 */
12d7b107
SH
1545static int dasd_eckd_validate_server(struct dasd_device *device,
1546 unsigned long flags)
40545573
HH
1547{
1548 int rc;
8e09f215 1549 struct dasd_eckd_private *private;
f3eb5384 1550 int enable_pav;
40545573 1551
f9f8d02f
SH
1552 private = (struct dasd_eckd_private *) device->private;
1553 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1554 private->uid.type == UA_HYPER_PAV_ALIAS)
12d7b107 1555 return 0;
40545573 1556 if (dasd_nopav || MACHINE_IS_VM)
f3eb5384
SW
1557 enable_pav = 0;
1558 else
1559 enable_pav = 1;
12d7b107 1560 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
eb6e199b 1561
8e79a441
HH
1562 /* may be requested feature is not available on server,
1563 * therefore just report error and go ahead */
b8ed5dd5
SH
1564 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1565 "returned rc=%d", private->uid.ssid, rc);
12d7b107 1566 return rc;
40545573
HH
1567}
1568
f1633031
SH
1569/*
1570 * worker to do a validate server in case of a lost pathgroup
1571 */
1572static void dasd_eckd_do_validate_server(struct work_struct *work)
1573{
1574 struct dasd_device *device = container_of(work, struct dasd_device,
1575 kick_validate);
ea4da6ea
SH
1576 unsigned long flags = 0;
1577
1578 set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1579 if (dasd_eckd_validate_server(device, flags)
12d7b107
SH
1580 == -EAGAIN) {
1581 /* schedule worker again if failed */
1582 schedule_work(&device->kick_validate);
1583 return;
1584 }
1585
f1633031
SH
1586 dasd_put_device(device);
1587}
1588
1589static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1590{
1591 dasd_get_device(device);
25e2cf1c
SH
1592 /* exit if device not online or in offline processing */
1593 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1594 device->state < DASD_STATE_ONLINE) {
1595 dasd_put_device(device);
1596 return;
1597 }
f1633031
SH
1598 /* queue call to do_validate_server to the kernel event daemon. */
1599 schedule_work(&device->kick_validate);
1600}
1601
ef19298b
SW
1602static u32 get_fcx_max_data(struct dasd_device *device)
1603{
1604#if defined(CONFIG_64BIT)
1605 int tpm, mdc;
1606 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1607 struct dasd_eckd_private *private;
1608
1609 if (dasd_nofcx)
1610 return 0;
1611 /* is transport mode supported? */
1612 private = (struct dasd_eckd_private *) device->private;
1613 fcx_in_css = css_general_characteristics.fcx;
1614 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1615 fcx_in_features = private->features.feature[40] & 0x80;
1616 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1617
1618 if (!tpm)
1619 return 0;
1620
1621 mdc = ccw_device_get_mdc(device->cdev, 0);
1622 if (mdc < 0) {
1623 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1624 " data size for zHPF requests failed\n");
1625 return 0;
1626 } else
1627 return mdc * FCX_MAX_DATA_FACTOR;
1628#else
1629 return 0;
1630#endif
1631}
1632
3d052595
HH
1633/*
1634 * Check device characteristics.
1635 * If the device is accessible using ECKD discipline, the device is enabled.
1636 */
1da177e4
LT
1637static int
1638dasd_eckd_check_characteristics(struct dasd_device *device)
1639{
1640 struct dasd_eckd_private *private;
8e09f215 1641 struct dasd_block *block;
2dedf0d9 1642 struct dasd_uid temp_uid;
f9f8d02f 1643 int rc, i;
33b62a30 1644 int readonly;
7c8faa86 1645 unsigned long value;
1da177e4 1646
f1633031
SH
1647 /* setup work queue for validate server*/
1648 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1649
454e1fa1
PO
1650 if (!ccw_device_is_pathgroup(device->cdev)) {
1651 dev_warn(&device->cdev->dev,
1652 "A channel path group could not be established\n");
1653 return -EIO;
1654 }
1655 if (!ccw_device_is_multipath(device->cdev)) {
1656 dev_info(&device->cdev->dev,
1657 "The DASD is not operating in multipath mode\n");
1658 }
1da177e4 1659 private = (struct dasd_eckd_private *) device->private;
92636b15
SO
1660 if (!private) {
1661 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1662 if (!private) {
fc19f381
SH
1663 dev_warn(&device->cdev->dev,
1664 "Allocating memory for private DASD data "
1665 "failed\n");
1da177e4
LT
1666 return -ENOMEM;
1667 }
1da177e4 1668 device->private = (void *) private;
92636b15
SO
1669 } else {
1670 memset(private, 0, sizeof(*private));
1da177e4
LT
1671 }
1672 /* Invalidate status of initial analysis. */
1673 private->init_cqr_status = -1;
1674 /* Set default cache operations. */
1675 private->attrib.operation = DASD_NORMAL_CACHE;
1676 private->attrib.nr_cyl = 0;
1677
40545573
HH
1678 /* Read Configuration Data */
1679 rc = dasd_eckd_read_conf(device);
1680 if (rc)
8e09f215 1681 goto out_err1;
40545573 1682
7c8faa86
SH
1683 /* set default timeout */
1684 device->default_expires = DASD_EXPIRES;
1f1ee9ad
HR
1685 /* set default retry count */
1686 device->default_retries = DASD_RETRIES;
1687
7c8faa86
SH
1688 if (private->gneq) {
1689 value = 1;
1690 for (i = 0; i < private->gneq->timeout.value; i++)
1691 value = 10 * value;
1692 value = value * private->gneq->timeout.number;
1693 /* do not accept useless values */
1694 if (value != 0 && value <= DASD_EXPIRES_MAX)
1695 device->default_expires = value;
1696 }
1697
2dedf0d9
SH
1698 dasd_eckd_get_uid(device, &temp_uid);
1699 if (temp_uid.type == UA_BASE_DEVICE) {
8e09f215
SW
1700 block = dasd_alloc_block();
1701 if (IS_ERR(block)) {
b8ed5dd5
SH
1702 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1703 "could not allocate dasd "
1704 "block structure");
8e09f215
SW
1705 rc = PTR_ERR(block);
1706 goto out_err1;
1707 }
1708 device->block = block;
1709 block->base = device;
1710 }
1711
f9f8d02f
SH
1712 /* register lcu with alias handling, enable PAV */
1713 rc = dasd_alias_make_device_known_to_lcu(device);
1714 if (rc)
8e09f215 1715 goto out_err2;
f9f8d02f 1716
12d7b107 1717 dasd_eckd_validate_server(device, 0);
f4ac1d02
SW
1718
1719 /* device may report different configuration data after LCU setup */
1720 rc = dasd_eckd_read_conf(device);
1721 if (rc)
1722 goto out_err3;
8e09f215
SW
1723
1724 /* Read Feature Codes */
68d1e5f0 1725 dasd_eckd_read_features(device);
40545573 1726
1da177e4 1727 /* Read Device Characteristics */
68b781fe
SH
1728 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1729 &private->rdc_data, 64);
8e09f215 1730 if (rc) {
b8ed5dd5
SH
1731 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1732 "Read device characteristic failed, rc=%d", rc);
8e09f215
SW
1733 goto out_err3;
1734 }
34cd551a
SH
1735
1736 if ((device->features & DASD_FEATURE_USERAW) &&
1737 !(private->rdc_data.facilities.RT_in_LR)) {
1738 dev_err(&device->cdev->dev, "The storage server does not "
1739 "support raw-track access\n");
1740 rc = -EINVAL;
1741 goto out_err3;
1742 }
1743
817f2c84 1744 /* find the valid cylinder size */
b44b0ab3
SW
1745 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1746 private->rdc_data.long_no_cyl)
1747 private->real_cyl = private->rdc_data.long_no_cyl;
1748 else
1749 private->real_cyl = private->rdc_data.no_cyl;
1750
ef19298b
SW
1751 private->fcx_max_data = get_fcx_max_data(device);
1752
33b62a30
SW
1753 readonly = dasd_device_is_ro(device);
1754 if (readonly)
1755 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1756
fc19f381 1757 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
33b62a30 1758 "with %d cylinders, %d heads, %d sectors%s\n",
fc19f381
SH
1759 private->rdc_data.dev_type,
1760 private->rdc_data.dev_model,
1761 private->rdc_data.cu_type,
1762 private->rdc_data.cu_model.model,
92636b15 1763 private->real_cyl,
fc19f381 1764 private->rdc_data.trk_per_cyl,
33b62a30
SW
1765 private->rdc_data.sec_per_trk,
1766 readonly ? ", read-only device" : "");
8e09f215
SW
1767 return 0;
1768
1769out_err3:
1770 dasd_alias_disconnect_device_from_lcu(device);
1771out_err2:
1772 dasd_free_block(device->block);
1773 device->block = NULL;
1774out_err1:
4abb08c2 1775 kfree(private->conf_data);
8e09f215
SW
1776 kfree(device->private);
1777 device->private = NULL;
3d052595 1778 return rc;
1da177e4
LT
1779}
1780
8e09f215
SW
1781static void dasd_eckd_uncheck_device(struct dasd_device *device)
1782{
4abb08c2
SW
1783 struct dasd_eckd_private *private;
1784
1785 private = (struct dasd_eckd_private *) device->private;
8e09f215 1786 dasd_alias_disconnect_device_from_lcu(device);
4abb08c2
SW
1787 private->ned = NULL;
1788 private->sneq = NULL;
1789 private->vdsneq = NULL;
1790 private->gneq = NULL;
1791 private->conf_len = 0;
1792 kfree(private->conf_data);
1793 private->conf_data = NULL;
8e09f215
SW
1794}
1795
1da177e4
LT
1796static struct dasd_ccw_req *
1797dasd_eckd_analysis_ccw(struct dasd_device *device)
1798{
1799 struct dasd_eckd_private *private;
1800 struct eckd_count *count_data;
1801 struct LO_eckd_data *LO_data;
1802 struct dasd_ccw_req *cqr;
1803 struct ccw1 *ccw;
1804 int cplength, datasize;
1805 int i;
1806
1807 private = (struct dasd_eckd_private *) device->private;
1808
1809 cplength = 8;
1810 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
68b781fe 1811 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1da177e4
LT
1812 if (IS_ERR(cqr))
1813 return cqr;
1814 ccw = cqr->cpaddr;
1815 /* Define extent for the first 3 tracks. */
1816 define_extent(ccw++, cqr->data, 0, 2,
1817 DASD_ECKD_CCW_READ_COUNT, device);
8e09f215 1818 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1da177e4
LT
1819 /* Locate record for the first 4 records on track 0. */
1820 ccw[-1].flags |= CCW_FLAG_CC;
1821 locate_record(ccw++, LO_data++, 0, 0, 4,
1822 DASD_ECKD_CCW_READ_COUNT, device, 0);
1823
1824 count_data = private->count_area;
1825 for (i = 0; i < 4; i++) {
1826 ccw[-1].flags |= CCW_FLAG_CC;
1827 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1828 ccw->flags = 0;
1829 ccw->count = 8;
1830 ccw->cda = (__u32)(addr_t) count_data;
1831 ccw++;
1832 count_data++;
1833 }
1834
1835 /* Locate record for the first record on track 2. */
1836 ccw[-1].flags |= CCW_FLAG_CC;
1837 locate_record(ccw++, LO_data++, 2, 0, 1,
1838 DASD_ECKD_CCW_READ_COUNT, device, 0);
1839 /* Read count ccw. */
1840 ccw[-1].flags |= CCW_FLAG_CC;
1841 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1842 ccw->flags = 0;
1843 ccw->count = 8;
1844 ccw->cda = (__u32)(addr_t) count_data;
1845
8e09f215
SW
1846 cqr->block = NULL;
1847 cqr->startdev = device;
1848 cqr->memdev = device;
eb6e199b 1849 cqr->retries = 255;
1aae0560 1850 cqr->buildclk = get_tod_clock();
1da177e4
LT
1851 cqr->status = DASD_CQR_FILLED;
1852 return cqr;
1853}
1854
eb6e199b
SW
1855/* differentiate between 'no record found' and any other error */
1856static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1857{
1858 char *sense;
1859 if (init_cqr->status == DASD_CQR_DONE)
1860 return INIT_CQR_OK;
1861 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1862 init_cqr->status == DASD_CQR_FAILED) {
1863 sense = dasd_get_sense(&init_cqr->irb);
1864 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1865 return INIT_CQR_UNFORMATTED;
1866 else
1867 return INIT_CQR_ERROR;
1868 } else
1869 return INIT_CQR_ERROR;
1870}
1871
1da177e4
LT
1872/*
1873 * This is the callback function for the init_analysis cqr. It saves
1874 * the status of the initial analysis ccw before it frees it and kicks
1875 * the device to continue the startup sequence. This will call
1876 * dasd_eckd_do_analysis again (if the devices has not been marked
1877 * for deletion in the meantime).
1878 */
eb6e199b
SW
1879static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1880 void *data)
1da177e4
LT
1881{
1882 struct dasd_eckd_private *private;
1883 struct dasd_device *device;
1884
8e09f215 1885 device = init_cqr->startdev;
1da177e4 1886 private = (struct dasd_eckd_private *) device->private;
eb6e199b 1887 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1da177e4
LT
1888 dasd_sfree_request(init_cqr, device);
1889 dasd_kick_device(device);
1890}
1891
eb6e199b 1892static int dasd_eckd_start_analysis(struct dasd_block *block)
1da177e4 1893{
1da177e4
LT
1894 struct dasd_ccw_req *init_cqr;
1895
8e09f215 1896 init_cqr = dasd_eckd_analysis_ccw(block->base);
1da177e4
LT
1897 if (IS_ERR(init_cqr))
1898 return PTR_ERR(init_cqr);
1899 init_cqr->callback = dasd_eckd_analysis_callback;
1900 init_cqr->callback_data = NULL;
1901 init_cqr->expires = 5*HZ;
eb6e199b
SW
1902 /* first try without ERP, so we can later handle unformatted
1903 * devices as special case
1904 */
1905 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1906 init_cqr->retries = 0;
1da177e4
LT
1907 dasd_add_request_head(init_cqr);
1908 return -EAGAIN;
1909}
1910
eb6e199b 1911static int dasd_eckd_end_analysis(struct dasd_block *block)
1da177e4 1912{
8e09f215 1913 struct dasd_device *device;
1da177e4
LT
1914 struct dasd_eckd_private *private;
1915 struct eckd_count *count_area;
1916 unsigned int sb, blk_per_trk;
1917 int status, i;
eb6e199b 1918 struct dasd_ccw_req *init_cqr;
1da177e4 1919
8e09f215 1920 device = block->base;
1da177e4
LT
1921 private = (struct dasd_eckd_private *) device->private;
1922 status = private->init_cqr_status;
1923 private->init_cqr_status = -1;
eb6e199b
SW
1924 if (status == INIT_CQR_ERROR) {
1925 /* try again, this time with full ERP */
1926 init_cqr = dasd_eckd_analysis_ccw(device);
1927 dasd_sleep_on(init_cqr);
1928 status = dasd_eckd_analysis_evaluation(init_cqr);
1929 dasd_sfree_request(init_cqr, device);
1930 }
1931
e4dbb0f2
SH
1932 if (device->features & DASD_FEATURE_USERAW) {
1933 block->bp_block = DASD_RAW_BLOCKSIZE;
1934 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1935 block->s2b_shift = 3;
1936 goto raw;
1937 }
1938
eb6e199b
SW
1939 if (status == INIT_CQR_UNFORMATTED) {
1940 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1da177e4 1941 return -EMEDIUMTYPE;
eb6e199b
SW
1942 } else if (status == INIT_CQR_ERROR) {
1943 dev_err(&device->cdev->dev,
1944 "Detecting the DASD disk layout failed because "
1945 "of an I/O error\n");
1946 return -EIO;
1da177e4
LT
1947 }
1948
1949 private->uses_cdl = 1;
1da177e4
LT
1950 /* Check Track 0 for Compatible Disk Layout */
1951 count_area = NULL;
1952 for (i = 0; i < 3; i++) {
1953 if (private->count_area[i].kl != 4 ||
3bc9fef9
SH
1954 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
1955 private->count_area[i].cyl != 0 ||
1956 private->count_area[i].head != count_area_head[i] ||
1957 private->count_area[i].record != count_area_rec[i]) {
1da177e4
LT
1958 private->uses_cdl = 0;
1959 break;
1960 }
1961 }
1962 if (i == 3)
1963 count_area = &private->count_area[4];
1964
1965 if (private->uses_cdl == 0) {
1966 for (i = 0; i < 5; i++) {
1967 if ((private->count_area[i].kl != 0) ||
1968 (private->count_area[i].dl !=
3bc9fef9
SH
1969 private->count_area[0].dl) ||
1970 private->count_area[i].cyl != 0 ||
1971 private->count_area[i].head != count_area_head[i] ||
1972 private->count_area[i].record != count_area_rec[i])
1da177e4
LT
1973 break;
1974 }
1975 if (i == 5)
1976 count_area = &private->count_area[0];
1977 } else {
1978 if (private->count_area[3].record == 1)
fc19f381
SH
1979 dev_warn(&device->cdev->dev,
1980 "Track 0 has no records following the VTOC\n");
1da177e4 1981 }
e4dbb0f2 1982
1da177e4
LT
1983 if (count_area != NULL && count_area->kl == 0) {
1984 /* we found notthing violating our disk layout */
1985 if (dasd_check_blocksize(count_area->dl) == 0)
8e09f215 1986 block->bp_block = count_area->dl;
1da177e4 1987 }
8e09f215 1988 if (block->bp_block == 0) {
fc19f381
SH
1989 dev_warn(&device->cdev->dev,
1990 "The disk layout of the DASD is not supported\n");
1da177e4
LT
1991 return -EMEDIUMTYPE;
1992 }
8e09f215
SW
1993 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1994 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1995 block->s2b_shift++;
1da177e4 1996
8e09f215 1997 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
e4dbb0f2
SH
1998
1999raw:
b44b0ab3 2000 block->blocks = (private->real_cyl *
1da177e4
LT
2001 private->rdc_data.trk_per_cyl *
2002 blk_per_trk);
2003
fc19f381
SH
2004 dev_info(&device->cdev->dev,
2005 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2006 "%s\n", (block->bp_block >> 10),
2007 ((private->real_cyl *
2008 private->rdc_data.trk_per_cyl *
2009 blk_per_trk * (block->bp_block >> 9)) >> 1),
2010 ((blk_per_trk * block->bp_block) >> 10),
2011 private->uses_cdl ?
2012 "compatible disk layout" : "linux disk layout");
1da177e4
LT
2013
2014 return 0;
2015}
2016
8e09f215 2017static int dasd_eckd_do_analysis(struct dasd_block *block)
1da177e4
LT
2018{
2019 struct dasd_eckd_private *private;
2020
8e09f215 2021 private = (struct dasd_eckd_private *) block->base->private;
1da177e4 2022 if (private->init_cqr_status < 0)
8e09f215 2023 return dasd_eckd_start_analysis(block);
1da177e4 2024 else
8e09f215 2025 return dasd_eckd_end_analysis(block);
1da177e4
LT
2026}
2027
d42e1712 2028static int dasd_eckd_basic_to_ready(struct dasd_device *device)
8e09f215
SW
2029{
2030 return dasd_alias_add_device(device);
2031};
2032
2033static int dasd_eckd_online_to_ready(struct dasd_device *device)
2034{
501183f2 2035 cancel_work_sync(&device->reload_device);
25e2cf1c 2036 cancel_work_sync(&device->kick_validate);
d42e1712
SH
2037 return 0;
2038};
2039
2040static int dasd_eckd_ready_to_basic(struct dasd_device *device)
2041{
8e09f215
SW
2042 return dasd_alias_remove_device(device);
2043};
2044
1da177e4 2045static int
8e09f215 2046dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1da177e4
LT
2047{
2048 struct dasd_eckd_private *private;
2049
8e09f215
SW
2050 private = (struct dasd_eckd_private *) block->base->private;
2051 if (dasd_check_blocksize(block->bp_block) == 0) {
1da177e4 2052 geo->sectors = recs_per_track(&private->rdc_data,
8e09f215 2053 0, block->bp_block);
1da177e4
LT
2054 }
2055 geo->cylinders = private->rdc_data.no_cyl;
2056 geo->heads = private->rdc_data.trk_per_cyl;
2057 return 0;
2058}
2059
2060static struct dasd_ccw_req *
d42e1712
SH
2061dasd_eckd_build_format(struct dasd_device *base,
2062 struct format_data_t *fdata)
1da177e4 2063{
d42e1712
SH
2064 struct dasd_eckd_private *base_priv;
2065 struct dasd_eckd_private *start_priv;
2066 struct dasd_device *startdev;
1da177e4
LT
2067 struct dasd_ccw_req *fcp;
2068 struct eckd_count *ect;
d42e1712 2069 struct ch_t address;
1da177e4
LT
2070 struct ccw1 *ccw;
2071 void *data;
b44b0ab3 2072 int rpt;
1da177e4 2073 int cplength, datasize;
d42e1712 2074 int i, j;
f9a28f7b
JBJ
2075 int intensity = 0;
2076 int r0_perm;
d42e1712 2077 int nr_tracks;
1da177e4 2078
d42e1712
SH
2079 startdev = dasd_alias_get_start_dev(base);
2080 if (!startdev)
2081 startdev = base;
1da177e4 2082
d42e1712
SH
2083 start_priv = (struct dasd_eckd_private *) startdev->private;
2084 base_priv = (struct dasd_eckd_private *) base->private;
2085
2086 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2087
2088 nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
1da177e4
LT
2089
2090 /*
2091 * fdata->intensity is a bit string that tells us what to do:
2092 * Bit 0: write record zero
2093 * Bit 1: write home address, currently not supported
2094 * Bit 2: invalidate tracks
2095 * Bit 3: use OS/390 compatible disk layout (cdl)
f9a28f7b 2096 * Bit 4: do not allow storage subsystem to modify record zero
1da177e4
LT
2097 * Only some bit combinations do make sense.
2098 */
f9a28f7b
JBJ
2099 if (fdata->intensity & 0x10) {
2100 r0_perm = 0;
2101 intensity = fdata->intensity & ~0x10;
2102 } else {
2103 r0_perm = 1;
2104 intensity = fdata->intensity;
2105 }
d42e1712 2106
f9a28f7b 2107 switch (intensity) {
1da177e4
LT
2108 case 0x00: /* Normal format */
2109 case 0x08: /* Normal format, use cdl. */
d42e1712
SH
2110 cplength = 2 + (rpt*nr_tracks);
2111 datasize = sizeof(struct PFX_eckd_data) +
1da177e4 2112 sizeof(struct LO_eckd_data) +
d42e1712 2113 rpt * nr_tracks * sizeof(struct eckd_count);
1da177e4
LT
2114 break;
2115 case 0x01: /* Write record zero and format track. */
2116 case 0x09: /* Write record zero and format track, use cdl. */
d42e1712
SH
2117 cplength = 2 + rpt * nr_tracks;
2118 datasize = sizeof(struct PFX_eckd_data) +
1da177e4
LT
2119 sizeof(struct LO_eckd_data) +
2120 sizeof(struct eckd_count) +
d42e1712 2121 rpt * nr_tracks * sizeof(struct eckd_count);
1da177e4
LT
2122 break;
2123 case 0x04: /* Invalidate track. */
2124 case 0x0c: /* Invalidate track, use cdl. */
2125 cplength = 3;
d42e1712 2126 datasize = sizeof(struct PFX_eckd_data) +
1da177e4
LT
2127 sizeof(struct LO_eckd_data) +
2128 sizeof(struct eckd_count);
2129 break;
2130 default:
d42e1712
SH
2131 dev_warn(&startdev->cdev->dev,
2132 "An I/O control call used incorrect flags 0x%x\n",
2133 fdata->intensity);
1da177e4
LT
2134 return ERR_PTR(-EINVAL);
2135 }
2136 /* Allocate the format ccw request. */
d42e1712
SH
2137 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2138 datasize, startdev);
1da177e4
LT
2139 if (IS_ERR(fcp))
2140 return fcp;
2141
d42e1712 2142 start_priv->count++;
1da177e4
LT
2143 data = fcp->data;
2144 ccw = fcp->cpaddr;
2145
f9a28f7b 2146 switch (intensity & ~0x08) {
1da177e4 2147 case 0x00: /* Normal format. */
d42e1712
SH
2148 prefix(ccw++, (struct PFX_eckd_data *) data,
2149 fdata->start_unit, fdata->stop_unit,
2150 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
f9a28f7b
JBJ
2151 /* grant subsystem permission to format R0 */
2152 if (r0_perm)
d42e1712
SH
2153 ((struct PFX_eckd_data *)data)
2154 ->define_extent.ga_extended |= 0x04;
2155 data += sizeof(struct PFX_eckd_data);
1da177e4
LT
2156 ccw[-1].flags |= CCW_FLAG_CC;
2157 locate_record(ccw++, (struct LO_eckd_data *) data,
d42e1712
SH
2158 fdata->start_unit, 0, rpt*nr_tracks,
2159 DASD_ECKD_CCW_WRITE_CKD, base,
1da177e4
LT
2160 fdata->blksize);
2161 data += sizeof(struct LO_eckd_data);
2162 break;
2163 case 0x01: /* Write record zero + format track. */
d42e1712
SH
2164 prefix(ccw++, (struct PFX_eckd_data *) data,
2165 fdata->start_unit, fdata->stop_unit,
2166 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2167 base, startdev);
2168 data += sizeof(struct PFX_eckd_data);
1da177e4
LT
2169 ccw[-1].flags |= CCW_FLAG_CC;
2170 locate_record(ccw++, (struct LO_eckd_data *) data,
d42e1712
SH
2171 fdata->start_unit, 0, rpt * nr_tracks + 1,
2172 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2173 base->block->bp_block);
1da177e4
LT
2174 data += sizeof(struct LO_eckd_data);
2175 break;
2176 case 0x04: /* Invalidate track. */
d42e1712
SH
2177 prefix(ccw++, (struct PFX_eckd_data *) data,
2178 fdata->start_unit, fdata->stop_unit,
2179 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2180 data += sizeof(struct PFX_eckd_data);
1da177e4
LT
2181 ccw[-1].flags |= CCW_FLAG_CC;
2182 locate_record(ccw++, (struct LO_eckd_data *) data,
2183 fdata->start_unit, 0, 1,
d42e1712 2184 DASD_ECKD_CCW_WRITE_CKD, base, 8);
1da177e4
LT
2185 data += sizeof(struct LO_eckd_data);
2186 break;
2187 }
d42e1712
SH
2188
2189 for (j = 0; j < nr_tracks; j++) {
2190 /* calculate cylinder and head for the current track */
2191 set_ch_t(&address,
2192 (fdata->start_unit + j) /
2193 base_priv->rdc_data.trk_per_cyl,
2194 (fdata->start_unit + j) %
2195 base_priv->rdc_data.trk_per_cyl);
2196 if (intensity & 0x01) { /* write record zero */
1da177e4
LT
2197 ect = (struct eckd_count *) data;
2198 data += sizeof(struct eckd_count);
b44b0ab3
SW
2199 ect->cyl = address.cyl;
2200 ect->head = address.head;
d42e1712 2201 ect->record = 0;
1da177e4 2202 ect->kl = 0;
d42e1712 2203 ect->dl = 8;
1da177e4 2204 ccw[-1].flags |= CCW_FLAG_CC;
d42e1712 2205 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1da177e4
LT
2206 ccw->flags = CCW_FLAG_SLI;
2207 ccw->count = 8;
2208 ccw->cda = (__u32)(addr_t) ect;
2209 ccw++;
2210 }
d42e1712
SH
2211 if ((intensity & ~0x08) & 0x04) { /* erase track */
2212 ect = (struct eckd_count *) data;
2213 data += sizeof(struct eckd_count);
2214 ect->cyl = address.cyl;
2215 ect->head = address.head;
2216 ect->record = 1;
2217 ect->kl = 0;
2218 ect->dl = 0;
2219 ccw[-1].flags |= CCW_FLAG_CC;
2220 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2221 ccw->flags = CCW_FLAG_SLI;
2222 ccw->count = 8;
2223 ccw->cda = (__u32)(addr_t) ect;
2224 } else { /* write remaining records */
2225 for (i = 0; i < rpt; i++) {
2226 ect = (struct eckd_count *) data;
2227 data += sizeof(struct eckd_count);
2228 ect->cyl = address.cyl;
2229 ect->head = address.head;
2230 ect->record = i + 1;
2231 ect->kl = 0;
2232 ect->dl = fdata->blksize;
2233 /*
2234 * Check for special tracks 0-1
2235 * when formatting CDL
2236 */
2237 if ((intensity & 0x08) &&
2238 fdata->start_unit == 0) {
2239 if (i < 3) {
2240 ect->kl = 4;
2241 ect->dl = sizes_trk0[i] - 4;
2242 }
2243 }
2244 if ((intensity & 0x08) &&
2245 fdata->start_unit == 1) {
2246 ect->kl = 44;
2247 ect->dl = LABEL_SIZE - 44;
2248 }
2249 ccw[-1].flags |= CCW_FLAG_CC;
2250 if (i != 0 || j == 0)
2251 ccw->cmd_code =
2252 DASD_ECKD_CCW_WRITE_CKD;
2253 else
2254 ccw->cmd_code =
2255 DASD_ECKD_CCW_WRITE_CKD_MT;
2256 ccw->flags = CCW_FLAG_SLI;
2257 ccw->count = 8;
2258 ccw->cda = (__u32)(addr_t) ect;
2259 ccw++;
2260 }
2261 }
1da177e4 2262 }
d42e1712
SH
2263
2264 fcp->startdev = startdev;
2265 fcp->memdev = startdev;
eb6e199b 2266 fcp->retries = 256;
d42e1712 2267 fcp->expires = startdev->default_expires * HZ;
1aae0560 2268 fcp->buildclk = get_tod_clock();
1da177e4 2269 fcp->status = DASD_CQR_FILLED;
d42e1712 2270
1da177e4
LT
2271 return fcp;
2272}
2273
d42e1712
SH
2274static int
2275dasd_eckd_format_device(struct dasd_device *base,
2276 struct format_data_t *fdata)
2277{
2278 struct dasd_ccw_req *cqr, *n;
2279 struct dasd_block *block;
2280 struct dasd_eckd_private *private;
2281 struct list_head format_queue;
2282 struct dasd_device *device;
2283 int old_stop, format_step;
2284 int step, rc = 0;
2285
2286 block = base->block;
2287 private = (struct dasd_eckd_private *) base->private;
2288
2289 /* Sanity checks. */
2290 if (fdata->start_unit >=
2291 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2292 dev_warn(&base->cdev->dev,
2293 "Start track number %u used in formatting is too big\n",
2294 fdata->start_unit);
2295 return -EINVAL;
2296 }
2297 if (fdata->stop_unit >=
2298 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2299 dev_warn(&base->cdev->dev,
2300 "Stop track number %u used in formatting is too big\n",
2301 fdata->stop_unit);
2302 return -EINVAL;
2303 }
2304 if (fdata->start_unit > fdata->stop_unit) {
2305 dev_warn(&base->cdev->dev,
2306 "Start track %u used in formatting exceeds end track\n",
2307 fdata->start_unit);
2308 return -EINVAL;
2309 }
2310 if (dasd_check_blocksize(fdata->blksize) != 0) {
2311 dev_warn(&base->cdev->dev,
2312 "The DASD cannot be formatted with block size %u\n",
2313 fdata->blksize);
2314 return -EINVAL;
2315 }
2316
2317 INIT_LIST_HEAD(&format_queue);
2318 old_stop = fdata->stop_unit;
2319
2320 while (fdata->start_unit <= 1) {
2321 fdata->stop_unit = fdata->start_unit;
2322 cqr = dasd_eckd_build_format(base, fdata);
2323 list_add(&cqr->blocklist, &format_queue);
2324
2325 fdata->stop_unit = old_stop;
2326 fdata->start_unit++;
2327
2328 if (fdata->start_unit > fdata->stop_unit)
2329 goto sleep;
2330 }
2331
2332retry:
2333 format_step = 255 / recs_per_track(&private->rdc_data, 0,
2334 fdata->blksize);
2335 while (fdata->start_unit <= old_stop) {
2336 step = fdata->stop_unit - fdata->start_unit + 1;
2337 if (step > format_step)
2338 fdata->stop_unit = fdata->start_unit + format_step - 1;
2339
2340 cqr = dasd_eckd_build_format(base, fdata);
2341 if (IS_ERR(cqr)) {
2342 if (PTR_ERR(cqr) == -ENOMEM) {
2343 /*
2344 * not enough memory available
2345 * go to out and start requests
2346 * retry after first requests were finished
2347 */
2348 fdata->stop_unit = old_stop;
2349 goto sleep;
2350 } else
2351 return PTR_ERR(cqr);
2352 }
2353 list_add(&cqr->blocklist, &format_queue);
2354
2355 fdata->start_unit = fdata->stop_unit + 1;
2356 fdata->stop_unit = old_stop;
2357 }
2358
2359sleep:
2360 dasd_sleep_on_queue(&format_queue);
2361
2362 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2363 device = cqr->startdev;
2364 private = (struct dasd_eckd_private *) device->private;
2365 if (cqr->status == DASD_CQR_FAILED)
2366 rc = -EIO;
2367 list_del_init(&cqr->blocklist);
2368 dasd_sfree_request(cqr, device);
2369 private->count--;
2370 }
2371
2372 /*
2373 * in case of ENOMEM we need to retry after
2374 * first requests are finished
2375 */
2376 if (fdata->start_unit <= fdata->stop_unit)
2377 goto retry;
2378
2379 return rc;
2380}
2381
8e09f215 2382static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
1da177e4 2383{
8e09f215
SW
2384 cqr->status = DASD_CQR_FILLED;
2385 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2386 dasd_eckd_reset_ccw_to_base_io(cqr);
2387 cqr->startdev = cqr->block->base;
a4d26c6a 2388 cqr->lpm = cqr->block->base->path_data.opm;
1da177e4 2389 }
8e09f215 2390};
1da177e4
LT
2391
2392static dasd_erp_fn_t
2393dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2394{
8e09f215 2395 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
1da177e4
LT
2396 struct ccw_device *cdev = device->cdev;
2397
2398 switch (cdev->id.cu_type) {
2399 case 0x3990:
2400 case 0x2105:
2401 case 0x2107:
2402 case 0x1750:
2403 return dasd_3990_erp_action;
2404 case 0x9343:
2405 case 0x3880:
2406 default:
2407 return dasd_default_erp_action;
2408 }
2409}
2410
2411static dasd_erp_fn_t
2412dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2413{
2414 return dasd_default_erp_postaction;
2415}
2416
5a27e60d
SW
2417static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2418 struct dasd_ccw_req *cqr,
2419 struct irb *irb)
8e09f215
SW
2420{
2421 char mask;
f3eb5384 2422 char *sense = NULL;
501183f2 2423 struct dasd_eckd_private *private;
8e09f215 2424
501183f2 2425 private = (struct dasd_eckd_private *) device->private;
8e09f215
SW
2426 /* first of all check for state change pending interrupt */
2427 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
f3eb5384 2428 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
c8d1c0ff
SH
2429 /*
2430 * for alias only, not in offline processing
2431 * and only if not suspended
2432 */
501183f2 2433 if (!device->block && private->lcu &&
25e2cf1c 2434 device->state == DASD_STATE_ONLINE &&
c8d1c0ff
SH
2435 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2436 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
501183f2
SH
2437 /*
2438 * the state change could be caused by an alias
2439 * reassignment remove device from alias handling
2440 * to prevent new requests from being scheduled on
2441 * the wrong alias device
2442 */
2443 dasd_alias_remove_device(device);
2444
2445 /* schedule worker to reload device */
2446 dasd_reload_device(device);
2447 }
8e09f215
SW
2448 dasd_generic_handle_state_change(device);
2449 return;
2450 }
2451
a5a0061f 2452 sense = dasd_get_sense(irb);
5a27e60d
SW
2453 if (!sense)
2454 return;
2455
2456 /* summary unit check */
c7a29e56 2457 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
a5a0061f 2458 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
8e09f215
SW
2459 dasd_alias_handle_summary_unit_check(device, irb);
2460 return;
2461 }
2462
f60c768c 2463 /* service information message SIM */
5a27e60d 2464 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
f3eb5384
SW
2465 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2466 dasd_3990_erp_handle_sim(device, sense);
f60c768c
SH
2467 return;
2468 }
2469
5a27e60d
SW
2470 /* loss of device reservation is handled via base devices only
2471 * as alias devices may be used with several bases
2472 */
c7a29e56
SW
2473 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
2474 (sense[7] == 0x3F) &&
5a27e60d
SW
2475 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2476 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2477 if (device->features & DASD_FEATURE_FAILONSLCK)
2478 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2479 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2480 dev_err(&device->cdev->dev,
2481 "The device reservation was lost\n");
ada3df91 2482 }
5a27e60d 2483}
f3eb5384
SW
2484
2485static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2486 struct dasd_device *startdev,
8e09f215 2487 struct dasd_block *block,
f3eb5384
SW
2488 struct request *req,
2489 sector_t first_rec,
2490 sector_t last_rec,
2491 sector_t first_trk,
2492 sector_t last_trk,
2493 unsigned int first_offs,
2494 unsigned int last_offs,
2495 unsigned int blk_per_trk,
2496 unsigned int blksize)
1da177e4
LT
2497{
2498 struct dasd_eckd_private *private;
2499 unsigned long *idaws;
2500 struct LO_eckd_data *LO_data;
2501 struct dasd_ccw_req *cqr;
2502 struct ccw1 *ccw;
5705f702 2503 struct req_iterator iter;
1da177e4
LT
2504 struct bio_vec *bv;
2505 char *dst;
f3eb5384 2506 unsigned int off;
1da177e4 2507 int count, cidaw, cplength, datasize;
f3eb5384 2508 sector_t recid;
1da177e4 2509 unsigned char cmd, rcmd;
8e09f215
SW
2510 int use_prefix;
2511 struct dasd_device *basedev;
1da177e4 2512
8e09f215
SW
2513 basedev = block->base;
2514 private = (struct dasd_eckd_private *) basedev->private;
1da177e4
LT
2515 if (rq_data_dir(req) == READ)
2516 cmd = DASD_ECKD_CCW_READ_MT;
2517 else if (rq_data_dir(req) == WRITE)
2518 cmd = DASD_ECKD_CCW_WRITE_MT;
2519 else
2520 return ERR_PTR(-EINVAL);
f3eb5384 2521
1da177e4
LT
2522 /* Check struct bio and count the number of blocks for the request. */
2523 count = 0;
2524 cidaw = 0;
5705f702 2525 rq_for_each_segment(bv, req, iter) {
6c92e699
JA
2526 if (bv->bv_len & (blksize - 1))
2527 /* Eckd can only do full blocks. */
2528 return ERR_PTR(-EINVAL);
8e09f215 2529 count += bv->bv_len >> (block->s2b_shift + 9);
347a8dc3 2530#if defined(CONFIG_64BIT)
6c92e699 2531 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
8e09f215 2532 cidaw += bv->bv_len >> (block->s2b_shift + 9);
1da177e4 2533#endif
1da177e4
LT
2534 }
2535 /* Paranoia. */
2536 if (count != last_rec - first_rec + 1)
2537 return ERR_PTR(-EINVAL);
8e09f215
SW
2538
2539 /* use the prefix command if available */
2540 use_prefix = private->features.feature[8] & 0x01;
2541 if (use_prefix) {
2542 /* 1x prefix + number of blocks */
2543 cplength = 2 + count;
2544 /* 1x prefix + cidaws*sizeof(long) */
2545 datasize = sizeof(struct PFX_eckd_data) +
2546 sizeof(struct LO_eckd_data) +
2547 cidaw * sizeof(unsigned long);
2548 } else {
2549 /* 1x define extent + 1x locate record + number of blocks */
2550 cplength = 2 + count;
2551 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2552 datasize = sizeof(struct DE_eckd_data) +
2553 sizeof(struct LO_eckd_data) +
2554 cidaw * sizeof(unsigned long);
2555 }
1da177e4
LT
2556 /* Find out the number of additional locate record ccws for cdl. */
2557 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2558 if (last_rec >= 2*blk_per_trk)
2559 count = 2*blk_per_trk - first_rec;
2560 cplength += count;
2561 datasize += count*sizeof(struct LO_eckd_data);
2562 }
2563 /* Allocate the ccw request. */
68b781fe
SH
2564 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2565 startdev);
1da177e4
LT
2566 if (IS_ERR(cqr))
2567 return cqr;
2568 ccw = cqr->cpaddr;
8e09f215
SW
2569 /* First ccw is define extent or prefix. */
2570 if (use_prefix) {
2571 if (prefix(ccw++, cqr->data, first_trk,
2572 last_trk, cmd, basedev, startdev) == -EAGAIN) {
2573 /* Clock not in sync and XRC is enabled.
2574 * Try again later.
2575 */
2576 dasd_sfree_request(cqr, startdev);
2577 return ERR_PTR(-EAGAIN);
2578 }
2579 idaws = (unsigned long *) (cqr->data +
2580 sizeof(struct PFX_eckd_data));
2581 } else {
2582 if (define_extent(ccw++, cqr->data, first_trk,
b38f27e8 2583 last_trk, cmd, basedev) == -EAGAIN) {
8e09f215
SW
2584 /* Clock not in sync and XRC is enabled.
2585 * Try again later.
2586 */
2587 dasd_sfree_request(cqr, startdev);
2588 return ERR_PTR(-EAGAIN);
2589 }
2590 idaws = (unsigned long *) (cqr->data +
2591 sizeof(struct DE_eckd_data));
d54853ef 2592 }
1da177e4 2593 /* Build locate_record+read/write/ccws. */
1da177e4
LT
2594 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2595 recid = first_rec;
2596 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2597 /* Only standard blocks so there is just one locate record. */
2598 ccw[-1].flags |= CCW_FLAG_CC;
2599 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
8e09f215 2600 last_rec - recid + 1, cmd, basedev, blksize);
1da177e4 2601 }
5705f702 2602 rq_for_each_segment(bv, req, iter) {
1da177e4
LT
2603 dst = page_address(bv->bv_page) + bv->bv_offset;
2604 if (dasd_page_cache) {
2605 char *copy = kmem_cache_alloc(dasd_page_cache,
441e143e 2606 GFP_DMA | __GFP_NOWARN);
1da177e4
LT
2607 if (copy && rq_data_dir(req) == WRITE)
2608 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
2609 if (copy)
2610 dst = copy + bv->bv_offset;
2611 }
2612 for (off = 0; off < bv->bv_len; off += blksize) {
2613 sector_t trkid = recid;
2614 unsigned int recoffs = sector_div(trkid, blk_per_trk);
2615 rcmd = cmd;
2616 count = blksize;
2617 /* Locate record for cdl special block ? */
2618 if (private->uses_cdl && recid < 2*blk_per_trk) {
2619 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2620 rcmd |= 0x8;
2621 count = dasd_eckd_cdl_reclen(recid);
ec5883ab
HH
2622 if (count < blksize &&
2623 rq_data_dir(req) == READ)
1da177e4
LT
2624 memset(dst + count, 0xe5,
2625 blksize - count);
2626 }
2627 ccw[-1].flags |= CCW_FLAG_CC;
2628 locate_record(ccw++, LO_data++,
2629 trkid, recoffs + 1,
8e09f215 2630 1, rcmd, basedev, count);
1da177e4
LT
2631 }
2632 /* Locate record for standard blocks ? */
2633 if (private->uses_cdl && recid == 2*blk_per_trk) {
2634 ccw[-1].flags |= CCW_FLAG_CC;
2635 locate_record(ccw++, LO_data++,
2636 trkid, recoffs + 1,
2637 last_rec - recid + 1,
8e09f215 2638 cmd, basedev, count);
1da177e4
LT
2639 }
2640 /* Read/write ccw. */
2641 ccw[-1].flags |= CCW_FLAG_CC;
2642 ccw->cmd_code = rcmd;
2643 ccw->count = count;
2644 if (idal_is_needed(dst, blksize)) {
2645 ccw->cda = (__u32)(addr_t) idaws;
2646 ccw->flags = CCW_FLAG_IDA;
2647 idaws = idal_create_words(idaws, dst, blksize);
2648 } else {
2649 ccw->cda = (__u32)(addr_t) dst;
2650 ccw->flags = 0;
2651 }
2652 ccw++;
2653 dst += blksize;
2654 recid++;
2655 }
2656 }
13de227b
HS
2657 if (blk_noretry_request(req) ||
2658 block->base->features & DASD_FEATURE_FAILFAST)
1c01b8a5 2659 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
8e09f215
SW
2660 cqr->startdev = startdev;
2661 cqr->memdev = startdev;
2662 cqr->block = block;
7c8faa86 2663 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
a4d26c6a 2664 cqr->lpm = startdev->path_data.ppm;
1f1ee9ad 2665 cqr->retries = startdev->default_retries;
1aae0560 2666 cqr->buildclk = get_tod_clock();
1da177e4
LT
2667 cqr->status = DASD_CQR_FILLED;
2668 return cqr;
2669}
2670
f3eb5384
SW
2671static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2672 struct dasd_device *startdev,
2673 struct dasd_block *block,
2674 struct request *req,
2675 sector_t first_rec,
2676 sector_t last_rec,
2677 sector_t first_trk,
2678 sector_t last_trk,
2679 unsigned int first_offs,
2680 unsigned int last_offs,
2681 unsigned int blk_per_trk,
2682 unsigned int blksize)
2683{
f3eb5384
SW
2684 unsigned long *idaws;
2685 struct dasd_ccw_req *cqr;
2686 struct ccw1 *ccw;
2687 struct req_iterator iter;
2688 struct bio_vec *bv;
2689 char *dst, *idaw_dst;
2690 unsigned int cidaw, cplength, datasize;
2691 unsigned int tlf;
2692 sector_t recid;
2693 unsigned char cmd;
2694 struct dasd_device *basedev;
2695 unsigned int trkcount, count, count_to_trk_end;
2696 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2697 unsigned char new_track, end_idaw;
2698 sector_t trkid;
2699 unsigned int recoffs;
2700
2701 basedev = block->base;
f3eb5384
SW
2702 if (rq_data_dir(req) == READ)
2703 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2704 else if (rq_data_dir(req) == WRITE)
2705 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2706 else
2707 return ERR_PTR(-EINVAL);
2708
2709 /* Track based I/O needs IDAWs for each page, and not just for
2710 * 64 bit addresses. We need additional idals for pages
2711 * that get filled from two tracks, so we use the number
2712 * of records as upper limit.
2713 */
2714 cidaw = last_rec - first_rec + 1;
2715 trkcount = last_trk - first_trk + 1;
2716
2717 /* 1x prefix + one read/write ccw per track */
2718 cplength = 1 + trkcount;
2719
2720 /* on 31-bit we need space for two 32 bit addresses per page
2721 * on 64-bit one 64 bit address
2722 */
2723 datasize = sizeof(struct PFX_eckd_data) +
2724 cidaw * sizeof(unsigned long long);
2725
2726 /* Allocate the ccw request. */
68b781fe
SH
2727 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2728 startdev);
f3eb5384
SW
2729 if (IS_ERR(cqr))
2730 return cqr;
2731 ccw = cqr->cpaddr;
2732 /* transfer length factor: how many bytes to read from the last track */
2733 if (first_trk == last_trk)
2734 tlf = last_offs - first_offs + 1;
2735 else
2736 tlf = last_offs + 1;
2737 tlf *= blksize;
2738
2739 if (prefix_LRE(ccw++, cqr->data, first_trk,
2740 last_trk, cmd, basedev, startdev,
2741 1 /* format */, first_offs + 1,
2742 trkcount, blksize,
2743 tlf) == -EAGAIN) {
2744 /* Clock not in sync and XRC is enabled.
2745 * Try again later.
2746 */
2747 dasd_sfree_request(cqr, startdev);
2748 return ERR_PTR(-EAGAIN);
2749 }
2750
2751 /*
2752 * The translation of request into ccw programs must meet the
2753 * following conditions:
2754 * - all idaws but the first and the last must address full pages
2755 * (or 2K blocks on 31-bit)
2756 * - the scope of a ccw and it's idal ends with the track boundaries
2757 */
2758 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2759 recid = first_rec;
2760 new_track = 1;
2761 end_idaw = 0;
2762 len_to_track_end = 0;
246ccea1 2763 idaw_dst = NULL;
f3eb5384
SW
2764 idaw_len = 0;
2765 rq_for_each_segment(bv, req, iter) {
2766 dst = page_address(bv->bv_page) + bv->bv_offset;
2767 seg_len = bv->bv_len;
2768 while (seg_len) {
2769 if (new_track) {
2770 trkid = recid;
2771 recoffs = sector_div(trkid, blk_per_trk);
2772 count_to_trk_end = blk_per_trk - recoffs;
2773 count = min((last_rec - recid + 1),
2774 (sector_t)count_to_trk_end);
2775 len_to_track_end = count * blksize;
2776 ccw[-1].flags |= CCW_FLAG_CC;
2777 ccw->cmd_code = cmd;
2778 ccw->count = len_to_track_end;
2779 ccw->cda = (__u32)(addr_t)idaws;
2780 ccw->flags = CCW_FLAG_IDA;
2781 ccw++;
2782 recid += count;
2783 new_track = 0;
52db45c3
SW
2784 /* first idaw for a ccw may start anywhere */
2785 if (!idaw_dst)
2786 idaw_dst = dst;
f3eb5384 2787 }
52db45c3
SW
2788 /* If we start a new idaw, we must make sure that it
2789 * starts on an IDA_BLOCK_SIZE boundary.
f3eb5384
SW
2790 * If we continue an idaw, we must make sure that the
2791 * current segment begins where the so far accumulated
2792 * idaw ends
2793 */
52db45c3
SW
2794 if (!idaw_dst) {
2795 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2796 dasd_sfree_request(cqr, startdev);
2797 return ERR_PTR(-ERANGE);
2798 } else
2799 idaw_dst = dst;
2800 }
f3eb5384
SW
2801 if ((idaw_dst + idaw_len) != dst) {
2802 dasd_sfree_request(cqr, startdev);
2803 return ERR_PTR(-ERANGE);
2804 }
2805 part_len = min(seg_len, len_to_track_end);
2806 seg_len -= part_len;
2807 dst += part_len;
2808 idaw_len += part_len;
2809 len_to_track_end -= part_len;
2810 /* collected memory area ends on an IDA_BLOCK border,
2811 * -> create an idaw
2812 * idal_create_words will handle cases where idaw_len
2813 * is larger then IDA_BLOCK_SIZE
2814 */
2815 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2816 end_idaw = 1;
2817 /* We also need to end the idaw at track end */
2818 if (!len_to_track_end) {
2819 new_track = 1;
2820 end_idaw = 1;
2821 }
2822 if (end_idaw) {
2823 idaws = idal_create_words(idaws, idaw_dst,
2824 idaw_len);
246ccea1 2825 idaw_dst = NULL;
f3eb5384
SW
2826 idaw_len = 0;
2827 end_idaw = 0;
2828 }
2829 }
2830 }
2831
2832 if (blk_noretry_request(req) ||
2833 block->base->features & DASD_FEATURE_FAILFAST)
2834 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2835 cqr->startdev = startdev;
2836 cqr->memdev = startdev;
2837 cqr->block = block;
7c8faa86 2838 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
a4d26c6a 2839 cqr->lpm = startdev->path_data.ppm;
1f1ee9ad 2840 cqr->retries = startdev->default_retries;
1aae0560 2841 cqr->buildclk = get_tod_clock();
f3eb5384
SW
2842 cqr->status = DASD_CQR_FILLED;
2843 return cqr;
2844}
2845
2846static int prepare_itcw(struct itcw *itcw,
2847 unsigned int trk, unsigned int totrk, int cmd,
2848 struct dasd_device *basedev,
2849 struct dasd_device *startdev,
2850 unsigned int rec_on_trk, int count,
2851 unsigned int blksize,
2852 unsigned int total_data_size,
2853 unsigned int tlf,
2854 unsigned int blk_per_trk)
2855{
2856 struct PFX_eckd_data pfxdata;
2857 struct dasd_eckd_private *basepriv, *startpriv;
2858 struct DE_eckd_data *dedata;
2859 struct LRE_eckd_data *lredata;
2860 struct dcw *dcw;
2861
2862 u32 begcyl, endcyl;
2863 u16 heads, beghead, endhead;
2864 u8 pfx_cmd;
2865
2866 int rc = 0;
2867 int sector = 0;
2868 int dn, d;
2869
2870
2871 /* setup prefix data */
2872 basepriv = (struct dasd_eckd_private *) basedev->private;
2873 startpriv = (struct dasd_eckd_private *) startdev->private;
2874 dedata = &pfxdata.define_extent;
2875 lredata = &pfxdata.locate_record;
2876
2877 memset(&pfxdata, 0, sizeof(pfxdata));
2878 pfxdata.format = 1; /* PFX with LRE */
2879 pfxdata.base_address = basepriv->ned->unit_addr;
2880 pfxdata.base_lss = basepriv->ned->ID;
2881 pfxdata.validity.define_extent = 1;
2882
2883 /* private uid is kept up to date, conf_data may be outdated */
2884 if (startpriv->uid.type != UA_BASE_DEVICE) {
2885 pfxdata.validity.verify_base = 1;
2886 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2887 pfxdata.validity.hyper_pav = 1;
2888 }
2889
2890 switch (cmd) {
2891 case DASD_ECKD_CCW_READ_TRACK_DATA:
2892 dedata->mask.perm = 0x1;
2893 dedata->attributes.operation = basepriv->attrib.operation;
2894 dedata->blk_size = blksize;
2895 dedata->ga_extended |= 0x42;
2896 lredata->operation.orientation = 0x0;
2897 lredata->operation.operation = 0x0C;
2898 lredata->auxiliary.check_bytes = 0x01;
2899 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2900 break;
2901 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2902 dedata->mask.perm = 0x02;
2903 dedata->attributes.operation = basepriv->attrib.operation;
2904 dedata->blk_size = blksize;
2905 rc = check_XRC_on_prefix(&pfxdata, basedev);
2906 dedata->ga_extended |= 0x42;
2907 lredata->operation.orientation = 0x0;
2908 lredata->operation.operation = 0x3F;
2909 lredata->extended_operation = 0x23;
2910 lredata->auxiliary.check_bytes = 0x2;
2911 pfx_cmd = DASD_ECKD_CCW_PFX;
2912 break;
2913 default:
2914 DBF_DEV_EVENT(DBF_ERR, basedev,
2915 "prepare itcw, unknown opcode 0x%x", cmd);
2916 BUG();
2917 break;
2918 }
2919 if (rc)
2920 return rc;
2921
2922 dedata->attributes.mode = 0x3; /* ECKD */
2923
2924 heads = basepriv->rdc_data.trk_per_cyl;
2925 begcyl = trk / heads;
2926 beghead = trk % heads;
2927 endcyl = totrk / heads;
2928 endhead = totrk % heads;
2929
2930 /* check for sequential prestage - enhance cylinder range */
2931 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2932 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2933
2934 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2935 endcyl += basepriv->attrib.nr_cyl;
2936 else
2937 endcyl = (basepriv->real_cyl - 1);
2938 }
2939
2940 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2941 set_ch_t(&dedata->end_ext, endcyl, endhead);
2942
2943 dedata->ep_format = 0x20; /* records per track is valid */
2944 dedata->ep_rec_per_track = blk_per_trk;
2945
2946 if (rec_on_trk) {
2947 switch (basepriv->rdc_data.dev_type) {
2948 case 0x3390:
2949 dn = ceil_quot(blksize + 6, 232);
2950 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2951 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2952 break;
2953 case 0x3380:
2954 d = 7 + ceil_quot(blksize + 12, 32);
2955 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2956 break;
2957 }
2958 }
2959
2960 lredata->auxiliary.length_valid = 1;
2961 lredata->auxiliary.length_scope = 1;
2962 lredata->auxiliary.imbedded_ccw_valid = 1;
2963 lredata->length = tlf;
2964 lredata->imbedded_ccw = cmd;
2965 lredata->count = count;
2966 lredata->sector = sector;
2967 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2968 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2969 lredata->search_arg.head = lredata->seek_addr.head;
2970 lredata->search_arg.record = rec_on_trk;
2971
2972 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2973 &pfxdata, sizeof(pfxdata), total_data_size);
82a7b955 2974 return PTR_RET(dcw);
f3eb5384
SW
2975}
2976
2977static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2978 struct dasd_device *startdev,
2979 struct dasd_block *block,
2980 struct request *req,
2981 sector_t first_rec,
2982 sector_t last_rec,
2983 sector_t first_trk,
2984 sector_t last_trk,
2985 unsigned int first_offs,
2986 unsigned int last_offs,
2987 unsigned int blk_per_trk,
2988 unsigned int blksize)
2989{
f3eb5384
SW
2990 struct dasd_ccw_req *cqr;
2991 struct req_iterator iter;
2992 struct bio_vec *bv;
2993 char *dst;
2994 unsigned int trkcount, ctidaw;
2995 unsigned char cmd;
2996 struct dasd_device *basedev;
2997 unsigned int tlf;
2998 struct itcw *itcw;
2999 struct tidaw *last_tidaw = NULL;
3000 int itcw_op;
3001 size_t itcw_size;
ef19298b
SW
3002 u8 tidaw_flags;
3003 unsigned int seg_len, part_len, len_to_track_end;
3004 unsigned char new_track;
3005 sector_t recid, trkid;
3006 unsigned int offs;
3007 unsigned int count, count_to_trk_end;
cd10502b 3008 int ret;
f3eb5384
SW
3009
3010 basedev = block->base;
f3eb5384
SW
3011 if (rq_data_dir(req) == READ) {
3012 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3013 itcw_op = ITCW_OP_READ;
3014 } else if (rq_data_dir(req) == WRITE) {
3015 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3016 itcw_op = ITCW_OP_WRITE;
3017 } else
3018 return ERR_PTR(-EINVAL);
3019
3020 /* trackbased I/O needs address all memory via TIDAWs,
3021 * not just for 64 bit addresses. This allows us to map
3022 * each segment directly to one tidaw.
ef19298b
SW
3023 * In the case of write requests, additional tidaws may
3024 * be needed when a segment crosses a track boundary.
f3eb5384
SW
3025 */
3026 trkcount = last_trk - first_trk + 1;
3027 ctidaw = 0;
3028 rq_for_each_segment(bv, req, iter) {
3029 ++ctidaw;
3030 }
ef19298b
SW
3031 if (rq_data_dir(req) == WRITE)
3032 ctidaw += (last_trk - first_trk);
f3eb5384
SW
3033
3034 /* Allocate the ccw request. */
3035 itcw_size = itcw_calc_size(0, ctidaw, 0);
68b781fe 3036 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
f3eb5384
SW
3037 if (IS_ERR(cqr))
3038 return cqr;
3039
f3eb5384
SW
3040 /* transfer length factor: how many bytes to read from the last track */
3041 if (first_trk == last_trk)
3042 tlf = last_offs - first_offs + 1;
3043 else
3044 tlf = last_offs + 1;
3045 tlf *= blksize;
3046
3047 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
ef19298b 3048 if (IS_ERR(itcw)) {
cd10502b
JL
3049 ret = -EINVAL;
3050 goto out_error;
ef19298b 3051 }
f3eb5384 3052 cqr->cpaddr = itcw_get_tcw(itcw);
f3eb5384
SW
3053 if (prepare_itcw(itcw, first_trk, last_trk,
3054 cmd, basedev, startdev,
3055 first_offs + 1,
3056 trkcount, blksize,
3057 (last_rec - first_rec + 1) * blksize,
3058 tlf, blk_per_trk) == -EAGAIN) {
3059 /* Clock not in sync and XRC is enabled.
3060 * Try again later.
3061 */
cd10502b
JL
3062 ret = -EAGAIN;
3063 goto out_error;
f3eb5384 3064 }
d54cddb6 3065 len_to_track_end = 0;
f3eb5384
SW
3066 /*
3067 * A tidaw can address 4k of memory, but must not cross page boundaries
3068 * We can let the block layer handle this by setting
3069 * blk_queue_segment_boundary to page boundaries and
3070 * blk_max_segment_size to page size when setting up the request queue.
ef19298b
SW
3071 * For write requests, a TIDAW must not cross track boundaries, because
3072 * we have to set the CBC flag on the last tidaw for each track.
f3eb5384 3073 */
ef19298b
SW
3074 if (rq_data_dir(req) == WRITE) {
3075 new_track = 1;
3076 recid = first_rec;
3077 rq_for_each_segment(bv, req, iter) {
3078 dst = page_address(bv->bv_page) + bv->bv_offset;
3079 seg_len = bv->bv_len;
3080 while (seg_len) {
3081 if (new_track) {
3082 trkid = recid;
3083 offs = sector_div(trkid, blk_per_trk);
3084 count_to_trk_end = blk_per_trk - offs;
3085 count = min((last_rec - recid + 1),
3086 (sector_t)count_to_trk_end);
3087 len_to_track_end = count * blksize;
3088 recid += count;
3089 new_track = 0;
3090 }
3091 part_len = min(seg_len, len_to_track_end);
3092 seg_len -= part_len;
3093 len_to_track_end -= part_len;
3094 /* We need to end the tidaw at track end */
3095 if (!len_to_track_end) {
3096 new_track = 1;
3097 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3098 } else
3099 tidaw_flags = 0;
3100 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3101 dst, part_len);
cd10502b
JL
3102 if (IS_ERR(last_tidaw)) {
3103 ret = -EINVAL;
3104 goto out_error;
3105 }
ef19298b
SW
3106 dst += part_len;
3107 }
3108 }
3109 } else {
3110 rq_for_each_segment(bv, req, iter) {
3111 dst = page_address(bv->bv_page) + bv->bv_offset;
3112 last_tidaw = itcw_add_tidaw(itcw, 0x00,
3113 dst, bv->bv_len);
cd10502b
JL
3114 if (IS_ERR(last_tidaw)) {
3115 ret = -EINVAL;
3116 goto out_error;
3117 }
ef19298b 3118 }
f3eb5384 3119 }
ef19298b
SW
3120 last_tidaw->flags |= TIDAW_FLAGS_LAST;
3121 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
f3eb5384
SW
3122 itcw_finalize(itcw);
3123
3124 if (blk_noretry_request(req) ||
3125 block->base->features & DASD_FEATURE_FAILFAST)
3126 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
ef19298b 3127 cqr->cpmode = 1;
f3eb5384
SW
3128 cqr->startdev = startdev;
3129 cqr->memdev = startdev;
3130 cqr->block = block;
7c8faa86 3131 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
a4d26c6a 3132 cqr->lpm = startdev->path_data.ppm;
1f1ee9ad 3133 cqr->retries = startdev->default_retries;
1aae0560 3134 cqr->buildclk = get_tod_clock();
f3eb5384
SW
3135 cqr->status = DASD_CQR_FILLED;
3136 return cqr;
cd10502b
JL
3137out_error:
3138 dasd_sfree_request(cqr, startdev);
3139 return ERR_PTR(ret);
f3eb5384
SW
3140}
3141
3142static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3143 struct dasd_block *block,
3144 struct request *req)
3145{
ef19298b 3146 int cmdrtd, cmdwtd;
f3eb5384 3147 int use_prefix;
ef19298b 3148 int fcx_multitrack;
45b44d76 3149 struct dasd_eckd_private *private;
f3eb5384
SW
3150 struct dasd_device *basedev;
3151 sector_t first_rec, last_rec;
3152 sector_t first_trk, last_trk;
3153 unsigned int first_offs, last_offs;
3154 unsigned int blk_per_trk, blksize;
3155 int cdlspecial;
ef19298b 3156 unsigned int data_size;
f3eb5384
SW
3157 struct dasd_ccw_req *cqr;
3158
3159 basedev = block->base;
3160 private = (struct dasd_eckd_private *) basedev->private;
3161
3162 /* Calculate number of blocks/records per track. */
3163 blksize = block->bp_block;
3164 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
6fca97a9
SH
3165 if (blk_per_trk == 0)
3166 return ERR_PTR(-EINVAL);
f3eb5384 3167 /* Calculate record id of first and last block. */
83096ebf 3168 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
f3eb5384
SW
3169 first_offs = sector_div(first_trk, blk_per_trk);
3170 last_rec = last_trk =
83096ebf 3171 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
f3eb5384
SW
3172 last_offs = sector_div(last_trk, blk_per_trk);
3173 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3174
ef19298b
SW
3175 fcx_multitrack = private->features.feature[40] & 0x20;
3176 data_size = blk_rq_bytes(req);
3177 /* tpm write request add CBC data on each track boundary */
3178 if (rq_data_dir(req) == WRITE)
3179 data_size += (last_trk - first_trk) * 4;
f3eb5384
SW
3180
3181 /* is read track data and write track data in command mode supported? */
3182 cmdrtd = private->features.feature[9] & 0x20;
3183 cmdwtd = private->features.feature[12] & 0x40;
3184 use_prefix = private->features.feature[8] & 0x01;
3185
3186 cqr = NULL;
3187 if (cdlspecial || dasd_page_cache) {
3188 /* do nothing, just fall through to the cmd mode single case */
ef19298b
SW
3189 } else if ((data_size <= private->fcx_max_data)
3190 && (fcx_multitrack || (first_trk == last_trk))) {
f3eb5384
SW
3191 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3192 first_rec, last_rec,
3193 first_trk, last_trk,
3194 first_offs, last_offs,
3195 blk_per_trk, blksize);
ef19298b
SW
3196 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3197 (PTR_ERR(cqr) != -ENOMEM))
f3eb5384
SW
3198 cqr = NULL;
3199 } else if (use_prefix &&
3200 (((rq_data_dir(req) == READ) && cmdrtd) ||
3201 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3202 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3203 first_rec, last_rec,
3204 first_trk, last_trk,
3205 first_offs, last_offs,
3206 blk_per_trk, blksize);
ef19298b
SW
3207 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3208 (PTR_ERR(cqr) != -ENOMEM))
f3eb5384
SW
3209 cqr = NULL;
3210 }
3211 if (!cqr)
3212 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3213 first_rec, last_rec,
3214 first_trk, last_trk,
3215 first_offs, last_offs,
3216 blk_per_trk, blksize);
3217 return cqr;
3218}
3219
e4dbb0f2
SH
3220static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3221 struct dasd_block *block,
3222 struct request *req)
3223{
e4dbb0f2
SH
3224 unsigned long *idaws;
3225 struct dasd_device *basedev;
3226 struct dasd_ccw_req *cqr;
3227 struct ccw1 *ccw;
3228 struct req_iterator iter;
3229 struct bio_vec *bv;
3230 char *dst;
3231 unsigned char cmd;
3232 unsigned int trkcount;
3233 unsigned int seg_len, len_to_track_end;
3234 unsigned int first_offs;
3235 unsigned int cidaw, cplength, datasize;
3236 sector_t first_trk, last_trk;
3237 unsigned int pfx_datasize;
3238
3239 /*
3240 * raw track access needs to be mutiple of 64k and on 64k boundary
3241 */
3242 if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
3243 cqr = ERR_PTR(-EINVAL);
3244 goto out;
3245 }
3246 if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
3247 DASD_RAW_SECTORS_PER_TRACK) != 0) {
3248 cqr = ERR_PTR(-EINVAL);
3249 goto out;
3250 }
3251
3252 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3253 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3254 DASD_RAW_SECTORS_PER_TRACK;
3255 trkcount = last_trk - first_trk + 1;
3256 first_offs = 0;
3257 basedev = block->base;
e4dbb0f2
SH
3258
3259 if (rq_data_dir(req) == READ)
3260 cmd = DASD_ECKD_CCW_READ_TRACK;
3261 else if (rq_data_dir(req) == WRITE)
3262 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3263 else {
3264 cqr = ERR_PTR(-EINVAL);
3265 goto out;
3266 }
3267
3268 /*
3269 * Raw track based I/O needs IDAWs for each page,
3270 * and not just for 64 bit addresses.
3271 */
3272 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3273
3274 /* 1x prefix + one read/write ccw per track */
3275 cplength = 1 + trkcount;
3276
3277 /*
3278 * struct PFX_eckd_data has up to 2 byte as extended parameter
3279 * this is needed for write full track and has to be mentioned
25985edc 3280 * separately
e4dbb0f2
SH
3281 * add 8 instead of 2 to keep 8 byte boundary
3282 */
3283 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3284
3285 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3286
3287 /* Allocate the ccw request. */
3288 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3289 datasize, startdev);
3290 if (IS_ERR(cqr))
3291 goto out;
3292 ccw = cqr->cpaddr;
3293
3294 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3295 basedev, startdev, 1 /* format */, first_offs + 1,
3296 trkcount, 0, 0) == -EAGAIN) {
3297 /* Clock not in sync and XRC is enabled.
3298 * Try again later.
3299 */
3300 dasd_sfree_request(cqr, startdev);
3301 cqr = ERR_PTR(-EAGAIN);
3302 goto out;
3303 }
3304
3305 idaws = (unsigned long *)(cqr->data + pfx_datasize);
3306
3307 len_to_track_end = 0;
3308
3309 rq_for_each_segment(bv, req, iter) {
3310 dst = page_address(bv->bv_page) + bv->bv_offset;
3311 seg_len = bv->bv_len;
3312 if (!len_to_track_end) {
3313 ccw[-1].flags |= CCW_FLAG_CC;
3314 ccw->cmd_code = cmd;
3315 /* maximum 3390 track size */
3316 ccw->count = 57326;
3317 /* 64k map to one track */
3318 len_to_track_end = 65536;
3319 ccw->cda = (__u32)(addr_t)idaws;
3320 ccw->flags |= CCW_FLAG_IDA;
3321 ccw->flags |= CCW_FLAG_SLI;
3322 ccw++;
3323 }
3324 len_to_track_end -= seg_len;
3325 idaws = idal_create_words(idaws, dst, seg_len);
3326 }
3327
3328 if (blk_noretry_request(req) ||
3329 block->base->features & DASD_FEATURE_FAILFAST)
3330 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3331 cqr->startdev = startdev;
3332 cqr->memdev = startdev;
3333 cqr->block = block;
3334 cqr->expires = startdev->default_expires * HZ;
3335 cqr->lpm = startdev->path_data.ppm;
1f1ee9ad 3336 cqr->retries = startdev->default_retries;
1aae0560 3337 cqr->buildclk = get_tod_clock();
e4dbb0f2
SH
3338 cqr->status = DASD_CQR_FILLED;
3339
3340 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3341 cqr = NULL;
3342out:
3343 return cqr;
3344}
3345
3346
1da177e4
LT
3347static int
3348dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3349{
3350 struct dasd_eckd_private *private;
3351 struct ccw1 *ccw;
5705f702 3352 struct req_iterator iter;
1da177e4
LT
3353 struct bio_vec *bv;
3354 char *dst, *cda;
3355 unsigned int blksize, blk_per_trk, off;
3356 sector_t recid;
5705f702 3357 int status;
1da177e4
LT
3358
3359 if (!dasd_page_cache)
3360 goto out;
8e09f215
SW
3361 private = (struct dasd_eckd_private *) cqr->block->base->private;
3362 blksize = cqr->block->bp_block;
1da177e4 3363 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
83096ebf 3364 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
1da177e4
LT
3365 ccw = cqr->cpaddr;
3366 /* Skip over define extent & locate record. */
3367 ccw++;
3368 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
3369 ccw++;
5705f702 3370 rq_for_each_segment(bv, req, iter) {
1da177e4
LT
3371 dst = page_address(bv->bv_page) + bv->bv_offset;
3372 for (off = 0; off < bv->bv_len; off += blksize) {
3373 /* Skip locate record. */
3374 if (private->uses_cdl && recid <= 2*blk_per_trk)
3375 ccw++;
3376 if (dst) {
3377 if (ccw->flags & CCW_FLAG_IDA)
3378 cda = *((char **)((addr_t) ccw->cda));
3379 else
3380 cda = (char *)((addr_t) ccw->cda);
3381 if (dst != cda) {
3382 if (rq_data_dir(req) == READ)
3383 memcpy(dst, cda, bv->bv_len);
3384 kmem_cache_free(dasd_page_cache,
3385 (void *)((addr_t)cda & PAGE_MASK));
3386 }
3387 dst = NULL;
3388 }
3389 ccw++;
3390 recid++;
3391 }
3392 }
3393out:
3394 status = cqr->status == DASD_CQR_DONE;
8e09f215 3395 dasd_sfree_request(cqr, cqr->memdev);
1da177e4
LT
3396 return status;
3397}
3398
8e09f215 3399/*
f3eb5384 3400 * Modify ccw/tcw in cqr so it can be started on a base device.
8e09f215
SW
3401 *
3402 * Note that this is not enough to restart the cqr!
3403 * Either reset cqr->startdev as well (summary unit check handling)
3404 * or restart via separate cqr (as in ERP handling).
3405 */
3406void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3407{
3408 struct ccw1 *ccw;
3409 struct PFX_eckd_data *pfxdata;
f3eb5384
SW
3410 struct tcw *tcw;
3411 struct tccb *tccb;
3412 struct dcw *dcw;
3413
3414 if (cqr->cpmode == 1) {
3415 tcw = cqr->cpaddr;
3416 tccb = tcw_get_tccb(tcw);
3417 dcw = (struct dcw *)&tccb->tca[0];
3418 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
8e09f215
SW
3419 pfxdata->validity.verify_base = 0;
3420 pfxdata->validity.hyper_pav = 0;
f3eb5384
SW
3421 } else {
3422 ccw = cqr->cpaddr;
3423 pfxdata = cqr->data;
3424 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3425 pfxdata->validity.verify_base = 0;
3426 pfxdata->validity.hyper_pav = 0;
3427 }
8e09f215
SW
3428 }
3429}
3430
3431#define DASD_ECKD_CHANQ_MAX_SIZE 4
3432
3433static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3434 struct dasd_block *block,
3435 struct request *req)
3436{
3437 struct dasd_eckd_private *private;
3438 struct dasd_device *startdev;
3439 unsigned long flags;
3440 struct dasd_ccw_req *cqr;
3441
3442 startdev = dasd_alias_get_start_dev(base);
3443 if (!startdev)
3444 startdev = base;
3445 private = (struct dasd_eckd_private *) startdev->private;
3446 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3447 return ERR_PTR(-EBUSY);
3448
3449 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3450 private->count++;
e4dbb0f2
SH
3451 if ((base->features & DASD_FEATURE_USERAW))
3452 cqr = dasd_raw_build_cp(startdev, block, req);
3453 else
3454 cqr = dasd_eckd_build_cp(startdev, block, req);
8e09f215
SW
3455 if (IS_ERR(cqr))
3456 private->count--;
3457 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3458 return cqr;
3459}
3460
3461static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3462 struct request *req)
3463{
3464 struct dasd_eckd_private *private;
3465 unsigned long flags;
3466
3467 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3468 private = (struct dasd_eckd_private *) cqr->memdev->private;
3469 private->count--;
3470 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3471 return dasd_eckd_free_cp(cqr, req);
3472}
3473
1da177e4
LT
3474static int
3475dasd_eckd_fill_info(struct dasd_device * device,
3476 struct dasd_information2_t * info)
3477{
3478 struct dasd_eckd_private *private;
3479
3480 private = (struct dasd_eckd_private *) device->private;
3481 info->label_block = 2;
3482 info->FBA_layout = private->uses_cdl ? 0 : 1;
3483 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3484 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3485 memcpy(info->characteristics, &private->rdc_data,
3486 sizeof(struct dasd_eckd_characteristics));
4abb08c2
SW
3487 info->confdata_size = min((unsigned long)private->conf_len,
3488 sizeof(info->configuration_data));
3489 memcpy(info->configuration_data, private->conf_data,
3490 info->confdata_size);
1da177e4
LT
3491 return 0;
3492}
3493
3494/*
3495 * SECTION: ioctl functions for eckd devices.
3496 */
3497
3498/*
3499 * Release device ioctl.
138c014d 3500 * Buils a channel programm to releases a prior reserved
1da177e4
LT
3501 * (see dasd_eckd_reserve) device.
3502 */
3503static int
1107ccfb 3504dasd_eckd_release(struct dasd_device *device)
1da177e4 3505{
1da177e4
LT
3506 struct dasd_ccw_req *cqr;
3507 int rc;
f3eb5384 3508 struct ccw1 *ccw;
f932bcea 3509 int useglobal;
1da177e4
LT
3510
3511 if (!capable(CAP_SYS_ADMIN))
3512 return -EACCES;
3513
f932bcea 3514 useglobal = 0;
68b781fe 3515 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
1da177e4 3516 if (IS_ERR(cqr)) {
f932bcea
SW
3517 mutex_lock(&dasd_reserve_mutex);
3518 useglobal = 1;
3519 cqr = &dasd_reserve_req->cqr;
3520 memset(cqr, 0, sizeof(*cqr));
3521 memset(&dasd_reserve_req->ccw, 0,
3522 sizeof(dasd_reserve_req->ccw));
3523 cqr->cpaddr = &dasd_reserve_req->ccw;
3524 cqr->data = &dasd_reserve_req->data;
3525 cqr->magic = DASD_ECKD_MAGIC;
1da177e4 3526 }
f3eb5384
SW
3527 ccw = cqr->cpaddr;
3528 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3529 ccw->flags |= CCW_FLAG_SLI;
3530 ccw->count = 32;
3531 ccw->cda = (__u32)(addr_t) cqr->data;
8e09f215
SW
3532 cqr->startdev = device;
3533 cqr->memdev = device;
1da177e4 3534 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1c01b8a5 3535 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
336c340b 3536 cqr->retries = 2; /* set retry counter to enable basic ERP */
1da177e4 3537 cqr->expires = 2 * HZ;
1aae0560 3538 cqr->buildclk = get_tod_clock();
1da177e4
LT
3539 cqr->status = DASD_CQR_FILLED;
3540
3541 rc = dasd_sleep_on_immediatly(cqr);
5a27e60d
SW
3542 if (!rc)
3543 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
1da177e4 3544
f932bcea
SW
3545 if (useglobal)
3546 mutex_unlock(&dasd_reserve_mutex);
3547 else
3548 dasd_sfree_request(cqr, cqr->memdev);
1da177e4
LT
3549 return rc;
3550}
3551
3552/*
3553 * Reserve device ioctl.
3554 * Options are set to 'synchronous wait for interrupt' and
138c014d
HH
3555 * 'timeout the request'. This leads to a terminate IO if
3556 * the interrupt is outstanding for a certain time.
1da177e4
LT
3557 */
3558static int
1107ccfb 3559dasd_eckd_reserve(struct dasd_device *device)
1da177e4 3560{
1da177e4
LT
3561 struct dasd_ccw_req *cqr;
3562 int rc;
f3eb5384 3563 struct ccw1 *ccw;
f932bcea 3564 int useglobal;
1da177e4
LT
3565
3566 if (!capable(CAP_SYS_ADMIN))
3567 return -EACCES;
3568
f932bcea 3569 useglobal = 0;
68b781fe 3570 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
1da177e4 3571 if (IS_ERR(cqr)) {
f932bcea
SW
3572 mutex_lock(&dasd_reserve_mutex);
3573 useglobal = 1;
3574 cqr = &dasd_reserve_req->cqr;
3575 memset(cqr, 0, sizeof(*cqr));
3576 memset(&dasd_reserve_req->ccw, 0,
3577 sizeof(dasd_reserve_req->ccw));
3578 cqr->cpaddr = &dasd_reserve_req->ccw;
3579 cqr->data = &dasd_reserve_req->data;
3580 cqr->magic = DASD_ECKD_MAGIC;
1da177e4 3581 }
f3eb5384
SW
3582 ccw = cqr->cpaddr;
3583 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3584 ccw->flags |= CCW_FLAG_SLI;
3585 ccw->count = 32;
3586 ccw->cda = (__u32)(addr_t) cqr->data;
8e09f215
SW
3587 cqr->startdev = device;
3588 cqr->memdev = device;
1da177e4 3589 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1c01b8a5 3590 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
336c340b 3591 cqr->retries = 2; /* set retry counter to enable basic ERP */
1da177e4 3592 cqr->expires = 2 * HZ;
1aae0560 3593 cqr->buildclk = get_tod_clock();
1da177e4
LT
3594 cqr->status = DASD_CQR_FILLED;
3595
3596 rc = dasd_sleep_on_immediatly(cqr);
5a27e60d
SW
3597 if (!rc)
3598 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
1da177e4 3599
f932bcea
SW
3600 if (useglobal)
3601 mutex_unlock(&dasd_reserve_mutex);
3602 else
3603 dasd_sfree_request(cqr, cqr->memdev);
1da177e4
LT
3604 return rc;
3605}
3606
3607/*
3608 * Steal lock ioctl - unconditional reserve device.
138c014d 3609 * Buils a channel programm to break a device's reservation.
1da177e4
LT
3610 * (unconditional reserve)
3611 */
3612static int
1107ccfb 3613dasd_eckd_steal_lock(struct dasd_device *device)
1da177e4 3614{
1da177e4
LT
3615 struct dasd_ccw_req *cqr;
3616 int rc;
f3eb5384 3617 struct ccw1 *ccw;
f932bcea 3618 int useglobal;
1da177e4
LT
3619
3620 if (!capable(CAP_SYS_ADMIN))
3621 return -EACCES;
3622
f932bcea 3623 useglobal = 0;
68b781fe 3624 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
1da177e4 3625 if (IS_ERR(cqr)) {
f932bcea
SW
3626 mutex_lock(&dasd_reserve_mutex);
3627 useglobal = 1;
3628 cqr = &dasd_reserve_req->cqr;
3629 memset(cqr, 0, sizeof(*cqr));
3630 memset(&dasd_reserve_req->ccw, 0,
3631 sizeof(dasd_reserve_req->ccw));
3632 cqr->cpaddr = &dasd_reserve_req->ccw;
3633 cqr->data = &dasd_reserve_req->data;
3634 cqr->magic = DASD_ECKD_MAGIC;
1da177e4 3635 }
f3eb5384
SW
3636 ccw = cqr->cpaddr;
3637 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3638 ccw->flags |= CCW_FLAG_SLI;
3639 ccw->count = 32;
3640 ccw->cda = (__u32)(addr_t) cqr->data;
8e09f215
SW
3641 cqr->startdev = device;
3642 cqr->memdev = device;
1da177e4 3643 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1c01b8a5 3644 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
336c340b 3645 cqr->retries = 2; /* set retry counter to enable basic ERP */
1da177e4 3646 cqr->expires = 2 * HZ;
1aae0560 3647 cqr->buildclk = get_tod_clock();
1da177e4
LT
3648 cqr->status = DASD_CQR_FILLED;
3649
3650 rc = dasd_sleep_on_immediatly(cqr);
5a27e60d
SW
3651 if (!rc)
3652 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
1da177e4 3653
f932bcea
SW
3654 if (useglobal)
3655 mutex_unlock(&dasd_reserve_mutex);
3656 else
3657 dasd_sfree_request(cqr, cqr->memdev);
1da177e4
LT
3658 return rc;
3659}
3660
196339f1
SW
3661/*
3662 * SNID - Sense Path Group ID
3663 * This ioctl may be used in situations where I/O is stalled due to
3664 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3665 * preallocated dasd_reserve_req.
3666 */
3667static int dasd_eckd_snid(struct dasd_device *device,
3668 void __user *argp)
3669{
3670 struct dasd_ccw_req *cqr;
3671 int rc;
3672 struct ccw1 *ccw;
3673 int useglobal;
3674 struct dasd_snid_ioctl_data usrparm;
3675
3676 if (!capable(CAP_SYS_ADMIN))
3677 return -EACCES;
3678
3679 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3680 return -EFAULT;
3681
3682 useglobal = 0;
3683 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3684 sizeof(struct dasd_snid_data), device);
3685 if (IS_ERR(cqr)) {
3686 mutex_lock(&dasd_reserve_mutex);
3687 useglobal = 1;
3688 cqr = &dasd_reserve_req->cqr;
3689 memset(cqr, 0, sizeof(*cqr));
3690 memset(&dasd_reserve_req->ccw, 0,
3691 sizeof(dasd_reserve_req->ccw));
3692 cqr->cpaddr = &dasd_reserve_req->ccw;
3693 cqr->data = &dasd_reserve_req->data;
3694 cqr->magic = DASD_ECKD_MAGIC;
3695 }
3696 ccw = cqr->cpaddr;
3697 ccw->cmd_code = DASD_ECKD_CCW_SNID;
3698 ccw->flags |= CCW_FLAG_SLI;
3699 ccw->count = 12;
3700 ccw->cda = (__u32)(addr_t) cqr->data;
3701 cqr->startdev = device;
3702 cqr->memdev = device;
3703 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3704 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
5a27e60d 3705 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
196339f1
SW
3706 cqr->retries = 5;
3707 cqr->expires = 10 * HZ;
1aae0560 3708 cqr->buildclk = get_tod_clock();
196339f1
SW
3709 cqr->status = DASD_CQR_FILLED;
3710 cqr->lpm = usrparm.path_mask;
3711
3712 rc = dasd_sleep_on_immediatly(cqr);
3713 /* verify that I/O processing didn't modify the path mask */
3714 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3715 rc = -EIO;
3716 if (!rc) {
3717 usrparm.data = *((struct dasd_snid_data *)cqr->data);
3718 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3719 rc = -EFAULT;
3720 }
3721
3722 if (useglobal)
3723 mutex_unlock(&dasd_reserve_mutex);
3724 else
3725 dasd_sfree_request(cqr, cqr->memdev);
3726 return rc;
3727}
3728
1da177e4
LT
3729/*
3730 * Read performance statistics
3731 */
3732static int
1107ccfb 3733dasd_eckd_performance(struct dasd_device *device, void __user *argp)
1da177e4 3734{
1da177e4
LT
3735 struct dasd_psf_prssd_data *prssdp;
3736 struct dasd_rssd_perf_stats_t *stats;
3737 struct dasd_ccw_req *cqr;
3738 struct ccw1 *ccw;
3739 int rc;
3740
68b781fe 3741 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
8e09f215
SW
3742 (sizeof(struct dasd_psf_prssd_data) +
3743 sizeof(struct dasd_rssd_perf_stats_t)),
1da177e4
LT
3744 device);
3745 if (IS_ERR(cqr)) {
fc19f381 3746 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1da177e4
LT
3747 "Could not allocate initialization request");
3748 return PTR_ERR(cqr);
3749 }
8e09f215
SW
3750 cqr->startdev = device;
3751 cqr->memdev = device;
1da177e4 3752 cqr->retries = 0;
eb6e199b 3753 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1da177e4
LT
3754 cqr->expires = 10 * HZ;
3755
3756 /* Prepare for Read Subsystem Data */
3757 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
8e09f215 3758 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1da177e4 3759 prssdp->order = PSF_ORDER_PRSSD;
5d67d164 3760 prssdp->suborder = 0x01; /* Performance Statistics */
1da177e4
LT
3761 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3762
3763 ccw = cqr->cpaddr;
3764 ccw->cmd_code = DASD_ECKD_CCW_PSF;
8e09f215 3765 ccw->count = sizeof(struct dasd_psf_prssd_data);
1da177e4
LT
3766 ccw->flags |= CCW_FLAG_CC;
3767 ccw->cda = (__u32)(addr_t) prssdp;
3768
3769 /* Read Subsystem Data - Performance Statistics */
3770 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
8e09f215 3771 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
1da177e4
LT
3772
3773 ccw++;
3774 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
8e09f215 3775 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
1da177e4
LT
3776 ccw->cda = (__u32)(addr_t) stats;
3777
1aae0560 3778 cqr->buildclk = get_tod_clock();
1da177e4
LT
3779 cqr->status = DASD_CQR_FILLED;
3780 rc = dasd_sleep_on(cqr);
3781 if (rc == 0) {
1da177e4
LT
3782 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3783 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1107ccfb
CH
3784 if (copy_to_user(argp, stats,
3785 sizeof(struct dasd_rssd_perf_stats_t)))
3786 rc = -EFAULT;
1da177e4 3787 }
8e09f215 3788 dasd_sfree_request(cqr, cqr->memdev);
1da177e4
LT
3789 return rc;
3790}
3791
3792/*
3793 * Get attributes (cache operations)
3794 * Returnes the cache attributes used in Define Extend (DE).
3795 */
3796static int
1107ccfb 3797dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
1da177e4 3798{
1107ccfb
CH
3799 struct dasd_eckd_private *private =
3800 (struct dasd_eckd_private *)device->private;
3801 struct attrib_data_t attrib = private->attrib;
1da177e4
LT
3802 int rc;
3803
3804 if (!capable(CAP_SYS_ADMIN))
3805 return -EACCES;
1107ccfb 3806 if (!argp)
1da177e4
LT
3807 return -EINVAL;
3808
1107ccfb
CH
3809 rc = 0;
3810 if (copy_to_user(argp, (long *) &attrib,
8e09f215 3811 sizeof(struct attrib_data_t)))
1107ccfb 3812 rc = -EFAULT;
1da177e4
LT
3813
3814 return rc;
3815}
3816
3817/*
3818 * Set attributes (cache operations)
3819 * Stores the attributes for cache operation to be used in Define Extend (DE).
3820 */
3821static int
1107ccfb 3822dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
1da177e4 3823{
1107ccfb
CH
3824 struct dasd_eckd_private *private =
3825 (struct dasd_eckd_private *)device->private;
1da177e4
LT
3826 struct attrib_data_t attrib;
3827
3828 if (!capable(CAP_SYS_ADMIN))
3829 return -EACCES;
1107ccfb 3830 if (!argp)
1da177e4
LT
3831 return -EINVAL;
3832
1107ccfb 3833 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
1da177e4 3834 return -EFAULT;
1da177e4
LT
3835 private->attrib = attrib;
3836
fc19f381
SH
3837 dev_info(&device->cdev->dev,
3838 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3839 private->attrib.operation, private->attrib.nr_cyl);
1da177e4
LT
3840 return 0;
3841}
3842
ab1d848f
NH
3843/*
3844 * Issue syscall I/O to EMC Symmetrix array.
3845 * CCWs are PSF and RSSD
3846 */
3847static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3848{
3849 struct dasd_symmio_parms usrparm;
3850 char *psf_data, *rssd_result;
3851 struct dasd_ccw_req *cqr;
3852 struct ccw1 *ccw;
52898025 3853 char psf0, psf1;
ab1d848f
NH
3854 int rc;
3855
52898025
NH
3856 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3857 return -EACCES;
3858 psf0 = psf1 = 0;
3859
ab1d848f
NH
3860 /* Copy parms from caller */
3861 rc = -EFAULT;
3862 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3863 goto out;
f8b06859
HC
3864 if (is_compat_task() || sizeof(long) == 4) {
3865 /* Make sure pointers are sane even on 31 bit. */
ab1d848f 3866 rc = -EINVAL;
f8b06859
HC
3867 if ((usrparm.psf_data >> 32) != 0)
3868 goto out;
3869 if ((usrparm.rssd_result >> 32) != 0)
3870 goto out;
3871 usrparm.psf_data &= 0x7fffffffULL;
3872 usrparm.rssd_result &= 0x7fffffffULL;
ab1d848f 3873 }
ab1d848f
NH
3874 /* alloc I/O data area */
3875 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3876 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3877 if (!psf_data || !rssd_result) {
3878 rc = -ENOMEM;
3879 goto out_free;
3880 }
3881
3882 /* get syscall header from user space */
3883 rc = -EFAULT;
3884 if (copy_from_user(psf_data,
3885 (void __user *)(unsigned long) usrparm.psf_data,
3886 usrparm.psf_data_len))
3887 goto out_free;
52898025
NH
3888 psf0 = psf_data[0];
3889 psf1 = psf_data[1];
ab1d848f
NH
3890
3891 /* setup CCWs for PSF + RSSD */
68b781fe 3892 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
ab1d848f 3893 if (IS_ERR(cqr)) {
fc19f381 3894 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
ab1d848f
NH
3895 "Could not allocate initialization request");
3896 rc = PTR_ERR(cqr);
3897 goto out_free;
3898 }
3899
3900 cqr->startdev = device;
3901 cqr->memdev = device;
3902 cqr->retries = 3;
3903 cqr->expires = 10 * HZ;
1aae0560 3904 cqr->buildclk = get_tod_clock();
ab1d848f
NH
3905 cqr->status = DASD_CQR_FILLED;
3906
3907 /* Build the ccws */
3908 ccw = cqr->cpaddr;
3909
3910 /* PSF ccw */
3911 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3912 ccw->count = usrparm.psf_data_len;
3913 ccw->flags |= CCW_FLAG_CC;
3914 ccw->cda = (__u32)(addr_t) psf_data;
3915
3916 ccw++;
3917
3918 /* RSSD ccw */
3919 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3920 ccw->count = usrparm.rssd_result_len;
3921 ccw->flags = CCW_FLAG_SLI ;
3922 ccw->cda = (__u32)(addr_t) rssd_result;
3923
3924 rc = dasd_sleep_on(cqr);
3925 if (rc)
3926 goto out_sfree;
3927
3928 rc = -EFAULT;
3929 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
3930 rssd_result, usrparm.rssd_result_len))
3931 goto out_sfree;
3932 rc = 0;
3933
3934out_sfree:
3935 dasd_sfree_request(cqr, cqr->memdev);
3936out_free:
3937 kfree(rssd_result);
3938 kfree(psf_data);
3939out:
52898025
NH
3940 DBF_DEV_EVENT(DBF_WARNING, device,
3941 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3942 (int) psf0, (int) psf1, rc);
ab1d848f
NH
3943 return rc;
3944}
3945
1107ccfb 3946static int
8e09f215 3947dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
1107ccfb 3948{
8e09f215
SW
3949 struct dasd_device *device = block->base;
3950
1107ccfb
CH
3951 switch (cmd) {
3952 case BIODASDGATTR:
3953 return dasd_eckd_get_attrib(device, argp);
3954 case BIODASDSATTR:
3955 return dasd_eckd_set_attrib(device, argp);
3956 case BIODASDPSRD:
3957 return dasd_eckd_performance(device, argp);
3958 case BIODASDRLSE:
3959 return dasd_eckd_release(device);
3960 case BIODASDRSRV:
3961 return dasd_eckd_reserve(device);
3962 case BIODASDSLCK:
3963 return dasd_eckd_steal_lock(device);
196339f1
SW
3964 case BIODASDSNID:
3965 return dasd_eckd_snid(device, argp);
ab1d848f
NH
3966 case BIODASDSYMMIO:
3967 return dasd_symm_io(device, argp);
1107ccfb 3968 default:
6b79d14e 3969 return -ENOTTY;
1107ccfb
CH
3970 }
3971}
3972
445b5b49
HH
3973/*
3974 * Dump the range of CCWs into 'page' buffer
3975 * and return number of printed chars.
3976 */
4d284cac 3977static int
445b5b49
HH
3978dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
3979{
3980 int len, count;
3981 char *datap;
3982
3983 len = 0;
3984 while (from <= to) {
773bab4a 3985 len += sprintf(page + len, PRINTK_HEADER
445b5b49
HH
3986 " CCW %p: %08X %08X DAT:",
3987 from, ((int *) from)[0], ((int *) from)[1]);
3988
3989 /* get pointer to data (consider IDALs) */
3990 if (from->flags & CCW_FLAG_IDA)
3991 datap = (char *) *((addr_t *) (addr_t) from->cda);
3992 else
3993 datap = (char *) ((addr_t) from->cda);
3994
3995 /* dump data (max 32 bytes) */
3996 for (count = 0; count < from->count && count < 32; count++) {
3997 if (count % 8 == 0) len += sprintf(page + len, " ");
3998 if (count % 4 == 0) len += sprintf(page + len, " ");
3999 len += sprintf(page + len, "%02x", datap[count]);
4000 }
4001 len += sprintf(page + len, "\n");
4002 from++;
4003 }
4004 return len;
4005}
4006
fc19f381 4007static void
aeec92ca
SH
4008dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4009 char *reason)
fc19f381
SH
4010{
4011 u64 *sense;
a5a0061f 4012 u64 *stat;
aeec92ca
SH
4013
4014 sense = (u64 *) dasd_get_sense(irb);
a5a0061f 4015 stat = (u64 *) &irb->scsw;
fc19f381 4016 if (sense) {
a5a0061f
SW
4017 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4018 "%016llx %016llx %016llx %016llx",
4019 reason, *stat, *((u32 *) (stat + 1)),
ed3640b2 4020 sense[0], sense[1], sense[2], sense[3]);
fc19f381 4021 } else {
a5a0061f
SW
4022 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4023 reason, *stat, *((u32 *) (stat + 1)),
4024 "NO VALID SENSE");
fc19f381
SH
4025 }
4026}
4027
1da177e4
LT
4028/*
4029 * Print sense data and related channel program.
4030 * Parts are printed because printk buffer is only 1024 bytes.
4031 */
f3eb5384 4032static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
8e09f215 4033 struct dasd_ccw_req *req, struct irb *irb)
1da177e4
LT
4034{
4035 char *page;
445b5b49
HH
4036 struct ccw1 *first, *last, *fail, *from, *to;
4037 int len, sl, sct;
1da177e4
LT
4038
4039 page = (char *) get_zeroed_page(GFP_ATOMIC);
4040 if (page == NULL) {
fc19f381
SH
4041 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4042 "No memory to dump sense data\n");
1da177e4
LT
4043 return;
4044 }
445b5b49 4045 /* dump the sense data */
773bab4a 4046 len = sprintf(page, PRINTK_HEADER
1da177e4 4047 " I/O status report for device %s:\n",
2a0217d5 4048 dev_name(&device->cdev->dev));
773bab4a 4049 len += sprintf(page + len, PRINTK_HEADER
a5a0061f
SW
4050 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4051 "CS:%02X RC:%d\n",
4052 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4053 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4054 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4055 req ? req->intrc : 0);
773bab4a 4056 len += sprintf(page + len, PRINTK_HEADER
1da177e4 4057 " device %s: Failing CCW: %p\n",
2a0217d5 4058 dev_name(&device->cdev->dev),
23d805b6 4059 (void *) (addr_t) irb->scsw.cmd.cpa);
1da177e4
LT
4060 if (irb->esw.esw0.erw.cons) {
4061 for (sl = 0; sl < 4; sl++) {
773bab4a 4062 len += sprintf(page + len, PRINTK_HEADER
1da177e4
LT
4063 " Sense(hex) %2d-%2d:",
4064 (8 * sl), ((8 * sl) + 7));
4065
4066 for (sct = 0; sct < 8; sct++) {
4067 len += sprintf(page + len, " %02x",
4068 irb->ecw[8 * sl + sct]);
4069 }
4070 len += sprintf(page + len, "\n");
4071 }
4072
4073 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4074 /* 24 Byte Sense Data */
773bab4a 4075 sprintf(page + len, PRINTK_HEADER
445b5b49
HH
4076 " 24 Byte: %x MSG %x, "
4077 "%s MSGb to SYSOP\n",
4078 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4079 irb->ecw[1] & 0x10 ? "" : "no");
1da177e4
LT
4080 } else {
4081 /* 32 Byte Sense Data */
773bab4a 4082 sprintf(page + len, PRINTK_HEADER
445b5b49
HH
4083 " 32 Byte: Format: %x "
4084 "Exception class %x\n",
4085 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
1da177e4
LT
4086 }
4087 } else {
773bab4a 4088 sprintf(page + len, PRINTK_HEADER
445b5b49 4089 " SORRY - NO VALID SENSE AVAILABLE\n");
1da177e4 4090 }
773bab4a 4091 printk(KERN_ERR "%s", page);
445b5b49 4092
8e09f215
SW
4093 if (req) {
4094 /* req == NULL for unsolicited interrupts */
4095 /* dump the Channel Program (max 140 Bytes per line) */
4096 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4097 first = req->cpaddr;
4098 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4099 to = min(first + 6, last);
773bab4a 4100 len = sprintf(page, PRINTK_HEADER
8e09f215
SW
4101 " Related CP in req: %p\n", req);
4102 dasd_eckd_dump_ccw_range(first, to, page + len);
773bab4a 4103 printk(KERN_ERR "%s", page);
1da177e4 4104
8e09f215
SW
4105 /* print failing CCW area (maximum 4) */
4106 /* scsw->cda is either valid or zero */
4107 len = 0;
4108 from = ++to;
23d805b6
PO
4109 fail = (struct ccw1 *)(addr_t)
4110 irb->scsw.cmd.cpa; /* failing CCW */
8e09f215
SW
4111 if (from < fail - 2) {
4112 from = fail - 2; /* there is a gap - print header */
773bab4a 4113 len += sprintf(page, PRINTK_HEADER "......\n");
8e09f215
SW
4114 }
4115 to = min(fail + 1, last);
4116 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4117
4118 /* print last CCWs (maximum 2) */
4119 from = max(from, ++to);
4120 if (from < last - 1) {
4121 from = last - 1; /* there is a gap - print header */
773bab4a 4122 len += sprintf(page + len, PRINTK_HEADER "......\n");
8e09f215
SW
4123 }
4124 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4125 if (len > 0)
773bab4a 4126 printk(KERN_ERR "%s", page);
1da177e4 4127 }
1da177e4
LT
4128 free_page((unsigned long) page);
4129}
4130
f3eb5384
SW
4131
4132/*
4133 * Print sense data from a tcw.
4134 */
4135static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4136 struct dasd_ccw_req *req, struct irb *irb)
4137{
4138 char *page;
4139 int len, sl, sct, residual;
f3eb5384 4140 struct tsb *tsb;
ef19298b 4141 u8 *sense, *rcq;
f3eb5384
SW
4142
4143 page = (char *) get_zeroed_page(GFP_ATOMIC);
4144 if (page == NULL) {
fc19f381 4145 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
f3eb5384
SW
4146 "No memory to dump sense data");
4147 return;
4148 }
4149 /* dump the sense data */
773bab4a 4150 len = sprintf(page, PRINTK_HEADER
f3eb5384
SW
4151 " I/O status report for device %s:\n",
4152 dev_name(&device->cdev->dev));
773bab4a 4153 len += sprintf(page + len, PRINTK_HEADER
a5a0061f
SW
4154 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4155 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4156 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4157 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4158 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4159 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
4160 req ? req->intrc : 0);
773bab4a 4161 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4162 " device %s: Failing TCW: %p\n",
4163 dev_name(&device->cdev->dev),
4164 (void *) (addr_t) irb->scsw.tm.tcw);
4165
4166 tsb = NULL;
4167 sense = NULL;
a5a0061f 4168 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
f3eb5384
SW
4169 tsb = tcw_get_tsb(
4170 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4171
b8fde722 4172 if (tsb) {
773bab4a 4173 len += sprintf(page + len, PRINTK_HEADER
f3eb5384 4174 " tsb->length %d\n", tsb->length);
773bab4a 4175 len += sprintf(page + len, PRINTK_HEADER
f3eb5384 4176 " tsb->flags %x\n", tsb->flags);
773bab4a 4177 len += sprintf(page + len, PRINTK_HEADER
f3eb5384 4178 " tsb->dcw_offset %d\n", tsb->dcw_offset);
773bab4a 4179 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4180 " tsb->count %d\n", tsb->count);
4181 residual = tsb->count - 28;
773bab4a 4182 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4183 " residual %d\n", residual);
4184
4185 switch (tsb->flags & 0x07) {
4186 case 1: /* tsa_iostat */
773bab4a 4187 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4188 " tsb->tsa.iostat.dev_time %d\n",
4189 tsb->tsa.iostat.dev_time);
773bab4a 4190 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4191 " tsb->tsa.iostat.def_time %d\n",
4192 tsb->tsa.iostat.def_time);
773bab4a 4193 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4194 " tsb->tsa.iostat.queue_time %d\n",
4195 tsb->tsa.iostat.queue_time);
773bab4a 4196 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4197 " tsb->tsa.iostat.dev_busy_time %d\n",
4198 tsb->tsa.iostat.dev_busy_time);
773bab4a 4199 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4200 " tsb->tsa.iostat.dev_act_time %d\n",
4201 tsb->tsa.iostat.dev_act_time);
4202 sense = tsb->tsa.iostat.sense;
4203 break;
4204 case 2: /* ts_ddpc */
773bab4a 4205 len += sprintf(page + len, PRINTK_HEADER
f3eb5384 4206 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
ef19298b 4207 for (sl = 0; sl < 2; sl++) {
773bab4a 4208 len += sprintf(page + len, PRINTK_HEADER
ef19298b
SW
4209 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4210 (8 * sl), ((8 * sl) + 7));
4211 rcq = tsb->tsa.ddpc.rcq;
f3eb5384
SW
4212 for (sct = 0; sct < 8; sct++) {
4213 len += sprintf(page + len, " %02x",
ef19298b 4214 rcq[8 * sl + sct]);
f3eb5384
SW
4215 }
4216 len += sprintf(page + len, "\n");
4217 }
4218 sense = tsb->tsa.ddpc.sense;
4219 break;
4220 case 3: /* tsa_intrg */
773bab4a
SO
4221 len += sprintf(page + len, PRINTK_HEADER
4222 " tsb->tsa.intrg.: not supportet yet\n");
f3eb5384
SW
4223 break;
4224 }
4225
4226 if (sense) {
4227 for (sl = 0; sl < 4; sl++) {
773bab4a 4228 len += sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4229 " Sense(hex) %2d-%2d:",
4230 (8 * sl), ((8 * sl) + 7));
4231 for (sct = 0; sct < 8; sct++) {
4232 len += sprintf(page + len, " %02x",
4233 sense[8 * sl + sct]);
4234 }
4235 len += sprintf(page + len, "\n");
4236 }
4237
4238 if (sense[27] & DASD_SENSE_BIT_0) {
4239 /* 24 Byte Sense Data */
773bab4a 4240 sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4241 " 24 Byte: %x MSG %x, "
4242 "%s MSGb to SYSOP\n",
4243 sense[7] >> 4, sense[7] & 0x0f,
4244 sense[1] & 0x10 ? "" : "no");
4245 } else {
4246 /* 32 Byte Sense Data */
773bab4a 4247 sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4248 " 32 Byte: Format: %x "
4249 "Exception class %x\n",
4250 sense[6] & 0x0f, sense[22] >> 4);
4251 }
4252 } else {
773bab4a 4253 sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4254 " SORRY - NO VALID SENSE AVAILABLE\n");
4255 }
4256 } else {
773bab4a 4257 sprintf(page + len, PRINTK_HEADER
f3eb5384
SW
4258 " SORRY - NO TSB DATA AVAILABLE\n");
4259 }
773bab4a 4260 printk(KERN_ERR "%s", page);
f3eb5384
SW
4261 free_page((unsigned long) page);
4262}
4263
4264static void dasd_eckd_dump_sense(struct dasd_device *device,
4265 struct dasd_ccw_req *req, struct irb *irb)
4266{
a5a0061f 4267 if (scsw_is_tm(&irb->scsw))
f3eb5384
SW
4268 dasd_eckd_dump_sense_tcw(device, req, irb);
4269 else
4270 dasd_eckd_dump_sense_ccw(device, req, irb);
4271}
4272
501183f2 4273static int dasd_eckd_pm_freeze(struct dasd_device *device)
d41dd122
SH
4274{
4275 /*
4276 * the device should be disconnected from our LCU structure
4277 * on restore we will reconnect it and reread LCU specific
4278 * information like PAV support that might have changed
4279 */
4280 dasd_alias_remove_device(device);
4281 dasd_alias_disconnect_device_from_lcu(device);
4282
4283 return 0;
4284}
4285
501183f2 4286static int dasd_eckd_restore_device(struct dasd_device *device)
d41dd122
SH
4287{
4288 struct dasd_eckd_private *private;
6fca97a9 4289 struct dasd_eckd_characteristics temp_rdc_data;
f9f8d02f 4290 int rc;
d41dd122 4291 struct dasd_uid temp_uid;
a7602f6c 4292 unsigned long flags;
ea4da6ea 4293 unsigned long cqr_flags = 0;
d41dd122 4294
d41dd122
SH
4295 private = (struct dasd_eckd_private *) device->private;
4296
4297 /* Read Configuration Data */
55d3a85c 4298 dasd_eckd_read_conf(device);
d41dd122 4299
2dedf0d9
SH
4300 dasd_eckd_get_uid(device, &temp_uid);
4301 /* Generate device unique id */
4302 rc = dasd_eckd_generate_uid(device);
4303 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
d41dd122 4304 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
a7602f6c
SH
4305 dev_err(&device->cdev->dev, "The UID of the DASD has "
4306 "changed\n");
2dedf0d9 4307 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
d41dd122
SH
4308 if (rc)
4309 goto out_err;
d41dd122
SH
4310
4311 /* register lcu with alias handling, enable PAV if this is a new lcu */
f9f8d02f
SH
4312 rc = dasd_alias_make_device_known_to_lcu(device);
4313 if (rc)
4314 return rc;
ea4da6ea
SH
4315
4316 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4317 dasd_eckd_validate_server(device, cqr_flags);
f4ac1d02
SW
4318
4319 /* RE-Read Configuration Data */
55d3a85c 4320 dasd_eckd_read_conf(device);
d41dd122
SH
4321
4322 /* Read Feature Codes */
68d1e5f0 4323 dasd_eckd_read_features(device);
d41dd122
SH
4324
4325 /* Read Device Characteristics */
68b781fe 4326 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
6fca97a9 4327 &temp_rdc_data, 64);
d41dd122 4328 if (rc) {
b8ed5dd5
SH
4329 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4330 "Read device characteristic failed, rc=%d", rc);
d41dd122
SH
4331 goto out_err;
4332 }
a7602f6c 4333 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
6fca97a9 4334 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
a7602f6c 4335 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
d41dd122
SH
4336
4337 /* add device to alias management */
4338 dasd_alias_add_device(device);
4339
4340 return 0;
4341
4342out_err:
e6125fba 4343 return -1;
d41dd122
SH
4344}
4345
501183f2
SH
4346static int dasd_eckd_reload_device(struct dasd_device *device)
4347{
4348 struct dasd_eckd_private *private;
4349 int rc, old_base;
2dedf0d9
SH
4350 char print_uid[60];
4351 struct dasd_uid uid;
4352 unsigned long flags;
501183f2
SH
4353
4354 private = (struct dasd_eckd_private *) device->private;
2dedf0d9
SH
4355
4356 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
501183f2 4357 old_base = private->uid.base_unit_addr;
2dedf0d9
SH
4358 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4359
501183f2
SH
4360 /* Read Configuration Data */
4361 rc = dasd_eckd_read_conf(device);
4362 if (rc)
4363 goto out_err;
4364
2dedf0d9 4365 rc = dasd_eckd_generate_uid(device);
501183f2
SH
4366 if (rc)
4367 goto out_err;
501183f2
SH
4368 /*
4369 * update unit address configuration and
4370 * add device to alias management
4371 */
4372 dasd_alias_update_add_device(device);
4373
2dedf0d9
SH
4374 dasd_eckd_get_uid(device, &uid);
4375
4376 if (old_base != uid.base_unit_addr) {
4377 if (strlen(uid.vduit) > 0)
4378 snprintf(print_uid, sizeof(print_uid),
4379 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
4380 uid.ssid, uid.base_unit_addr, uid.vduit);
501183f2 4381 else
2dedf0d9
SH
4382 snprintf(print_uid, sizeof(print_uid),
4383 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
4384 uid.ssid, uid.base_unit_addr);
501183f2
SH
4385
4386 dev_info(&device->cdev->dev,
4387 "An Alias device was reassigned to a new base device "
2dedf0d9 4388 "with UID: %s\n", print_uid);
501183f2
SH
4389 }
4390 return 0;
4391
4392out_err:
4393 return -1;
4394}
4395
d41dd122 4396static struct ccw_driver dasd_eckd_driver = {
3bda058b
SO
4397 .driver = {
4398 .name = "dasd-eckd",
4399 .owner = THIS_MODULE,
4400 },
d41dd122
SH
4401 .ids = dasd_eckd_ids,
4402 .probe = dasd_eckd_probe,
4403 .remove = dasd_generic_remove,
4404 .set_offline = dasd_generic_set_offline,
4405 .set_online = dasd_eckd_set_online,
4406 .notify = dasd_generic_notify,
a4d26c6a 4407 .path_event = dasd_generic_path_event,
4679e893 4408 .shutdown = dasd_generic_shutdown,
d41dd122
SH
4409 .freeze = dasd_generic_pm_freeze,
4410 .thaw = dasd_generic_restore_device,
4411 .restore = dasd_generic_restore_device,
a23ed009 4412 .uc_handler = dasd_generic_uc_handler,
420f42ec 4413 .int_class = IRQIO_DAS,
d41dd122 4414};
f3eb5384 4415
1da177e4
LT
4416/*
4417 * max_blocks is dependent on the amount of storage that is available
4418 * in the static io buffer for each device. Currently each device has
4419 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4420 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4421 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4422 * addition we have one define extent ccw + 16 bytes of data and one
4423 * locate record ccw + 16 bytes of data. That makes:
4424 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4425 * We want to fit two into the available memory so that we can immediately
4426 * start the next request if one finishes off. That makes 249.5 blocks
4427 * for one request. Give a little safety and the result is 240.
4428 */
4429static struct dasd_discipline dasd_eckd_discipline = {
4430 .owner = THIS_MODULE,
4431 .name = "ECKD",
4432 .ebcname = "ECKD",
ef19298b 4433 .max_blocks = 190,
1da177e4 4434 .check_device = dasd_eckd_check_characteristics,
8e09f215 4435 .uncheck_device = dasd_eckd_uncheck_device,
1da177e4 4436 .do_analysis = dasd_eckd_do_analysis,
a4d26c6a 4437 .verify_path = dasd_eckd_verify_path,
d42e1712 4438 .basic_to_ready = dasd_eckd_basic_to_ready,
8e09f215 4439 .online_to_ready = dasd_eckd_online_to_ready,
d42e1712 4440 .ready_to_basic = dasd_eckd_ready_to_basic,
1da177e4
LT
4441 .fill_geometry = dasd_eckd_fill_geometry,
4442 .start_IO = dasd_start_IO,
4443 .term_IO = dasd_term_IO,
8e09f215 4444 .handle_terminated_request = dasd_eckd_handle_terminated_request,
1da177e4 4445 .format_device = dasd_eckd_format_device,
1da177e4
LT
4446 .erp_action = dasd_eckd_erp_action,
4447 .erp_postaction = dasd_eckd_erp_postaction,
5a27e60d 4448 .check_for_device_change = dasd_eckd_check_for_device_change,
8e09f215
SW
4449 .build_cp = dasd_eckd_build_alias_cp,
4450 .free_cp = dasd_eckd_free_alias_cp,
1da177e4 4451 .dump_sense = dasd_eckd_dump_sense,
fc19f381 4452 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
1da177e4 4453 .fill_info = dasd_eckd_fill_info,
1107ccfb 4454 .ioctl = dasd_eckd_ioctl,
d41dd122
SH
4455 .freeze = dasd_eckd_pm_freeze,
4456 .restore = dasd_eckd_restore_device,
501183f2 4457 .reload = dasd_eckd_reload_device,
2dedf0d9 4458 .get_uid = dasd_eckd_get_uid,
f1633031 4459 .kick_validate = dasd_eckd_kick_validate_server,
1da177e4
LT
4460};
4461
4462static int __init
4463dasd_eckd_init(void)
4464{
736e6ea0
SO
4465 int ret;
4466
1da177e4 4467 ASCEBC(dasd_eckd_discipline.ebcname, 4);
f932bcea
SW
4468 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4469 GFP_KERNEL | GFP_DMA);
4470 if (!dasd_reserve_req)
4471 return -ENOMEM;
a4d26c6a
SW
4472 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4473 GFP_KERNEL | GFP_DMA);
4474 if (!path_verification_worker) {
4475 kfree(dasd_reserve_req);
4476 return -ENOMEM;
4477 }
736e6ea0
SO
4478 ret = ccw_driver_register(&dasd_eckd_driver);
4479 if (!ret)
4480 wait_for_device_probe();
a4d26c6a
SW
4481 else {
4482 kfree(path_verification_worker);
f932bcea 4483 kfree(dasd_reserve_req);
a4d26c6a 4484 }
736e6ea0 4485 return ret;
1da177e4
LT
4486}
4487
4488static void __exit
4489dasd_eckd_cleanup(void)
4490{
4491 ccw_driver_unregister(&dasd_eckd_driver);
a4d26c6a 4492 kfree(path_verification_worker);
f932bcea 4493 kfree(dasd_reserve_req);
1da177e4
LT
4494}
4495
4496module_init(dasd_eckd_init);
4497module_exit(dasd_eckd_cleanup);