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