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