blob: bd2c52e20762e3593cb531be9b77552db0a2089a [file] [log] [blame]
Horst Hummel138c0142006-06-29 14:58:12 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * File...........: linux/drivers/s390/block/dasd_eckd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
Horst Hummel138c0142006-06-29 14:58:12 +02004 * Horst Hummel <Horst.Hummel@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
Nigel Hislopab1d8482008-10-10 21:33:25 +02009 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/stddef.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/hdreg.h> /* HDIO_GETGEO */
18#include <linux/bio.h>
19#include <linux/module.h>
20#include <linux/init.h>
21
22#include <asm/debug.h>
23#include <asm/idals.h>
24#include <asm/ebcdic.h>
25#include <asm/io.h>
26#include <asm/todclk.h>
27#include <asm/uaccess.h>
Horst Hummel40545572006-06-29 15:08:18 +020028#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/ccwdev.h>
30
31#include "dasd_int.h"
32#include "dasd_eckd.h"
33
34#ifdef PRINTK_HEADER
35#undef PRINTK_HEADER
36#endif /* PRINTK_HEADER */
37#define PRINTK_HEADER "dasd(eckd):"
38
39#define ECKD_C0(i) (i->home_bytes)
40#define ECKD_F(i) (i->formula)
41#define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
42 (i->factors.f_0x02.f1))
43#define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
44 (i->factors.f_0x02.f2))
45#define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
46 (i->factors.f_0x02.f3))
47#define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
48#define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
49#define ECKD_F6(i) (i->factor6)
50#define ECKD_F7(i) (i->factor7)
51#define ECKD_F8(i) (i->factor8)
52
53MODULE_LICENSE("GPL");
54
55static struct dasd_discipline dasd_eckd_discipline;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* The ccw bus type uses this table to find devices that it sends to
58 * dasd_eckd_probe */
59static struct ccw_device_id dasd_eckd_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020060 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
61 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
62 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
63 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
64 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
65 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
66 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
67 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
68 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
69 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 { /* end of list */ },
71};
72
73MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
74
75static struct ccw_driver dasd_eckd_driver; /* see below */
76
77/* initial attempt at a probe function. this can be simplified once
78 * the other detection code is gone */
79static int
80dasd_eckd_probe (struct ccw_device *cdev)
81{
82 int ret;
83
Horst Hummel40545572006-06-29 15:08:18 +020084 /* set ECKD specific ccw-device options */
85 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
86 if (ret) {
87 printk(KERN_WARNING
88 "dasd_eckd_probe: could not set ccw-device options "
Kay Sievers2a0217d2008-10-10 21:33:09 +020089 "for %s\n", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 return ret;
Horst Hummel40545572006-06-29 15:08:18 +020091 }
92 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
93 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
96static int
97dasd_eckd_set_online(struct ccw_device *cdev)
98{
Horst Hummel40545572006-06-29 15:08:18 +020099 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102static struct ccw_driver dasd_eckd_driver = {
103 .name = "dasd-eckd",
104 .owner = THIS_MODULE,
105 .ids = dasd_eckd_ids,
106 .probe = dasd_eckd_probe,
107 .remove = dasd_generic_remove,
108 .set_offline = dasd_generic_set_offline,
109 .set_online = dasd_eckd_set_online,
110 .notify = dasd_generic_notify,
111};
112
113static const int sizes_trk0[] = { 28, 148, 84 };
114#define LABEL_SIZE 140
115
116static inline unsigned int
117round_up_multiple(unsigned int no, unsigned int mult)
118{
119 int rem = no % mult;
120 return (rem ? no - rem + mult : no);
121}
122
123static inline unsigned int
124ceil_quot(unsigned int d1, unsigned int d2)
125{
126 return (d1 + (d2 - 1)) / d2;
127}
128
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100129static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130recs_per_track(struct dasd_eckd_characteristics * rdc,
131 unsigned int kl, unsigned int dl)
132{
133 int dn, kn;
134
135 switch (rdc->dev_type) {
136 case 0x3380:
137 if (kl)
138 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
139 ceil_quot(dl + 12, 32));
140 else
141 return 1499 / (15 + ceil_quot(dl + 12, 32));
142 case 0x3390:
143 dn = ceil_quot(dl + 6, 232) + 1;
144 if (kl) {
145 kn = ceil_quot(kl + 6, 232) + 1;
146 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
147 9 + ceil_quot(dl + 6 * dn, 34));
148 } else
149 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
150 case 0x9345:
151 dn = ceil_quot(dl + 6, 232) + 1;
152 if (kl) {
153 kn = ceil_quot(kl + 6, 232) + 1;
154 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
155 ceil_quot(dl + 6 * dn, 34));
156 } else
157 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
158 }
159 return 0;
160}
161
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100162static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163check_XRC (struct ccw1 *de_ccw,
164 struct DE_eckd_data *data,
165 struct dasd_device *device)
166{
167 struct dasd_eckd_private *private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100168 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 private = (struct dasd_eckd_private *) device->private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100171 if (!private->rdc_data.facilities.XRC_supported)
172 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 /* switch on System Time Stamp - needed for XRC Support */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100175 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
176 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
Horst Hummel138c0142006-06-29 14:58:12 +0200177
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100178 rc = get_sync_clock(&data->ep_sys_time);
179 /* Ignore return code if sync clock is switched off. */
180 if (rc == -ENOSYS || rc == -EACCES)
181 rc = 0;
Horst Hummel138c0142006-06-29 14:58:12 +0200182
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100183 de_ccw->count = sizeof(struct DE_eckd_data);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100184 de_ccw->flags |= CCW_FLAG_SLI;
185 return rc;
186}
Horst Hummel138c0142006-06-29 14:58:12 +0200187
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100188static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189define_extent(struct ccw1 * ccw, struct DE_eckd_data * data, int trk,
190 int totrk, int cmd, struct dasd_device * device)
191{
192 struct dasd_eckd_private *private;
193 struct ch_t geo, beg, end;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100194 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 private = (struct dasd_eckd_private *) device->private;
197
198 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
199 ccw->flags = 0;
200 ccw->count = 16;
201 ccw->cda = (__u32) __pa(data);
202
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100203 memset(data, 0, sizeof(struct DE_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 switch (cmd) {
205 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
206 case DASD_ECKD_CCW_READ_RECORD_ZERO:
207 case DASD_ECKD_CCW_READ:
208 case DASD_ECKD_CCW_READ_MT:
209 case DASD_ECKD_CCW_READ_CKD:
210 case DASD_ECKD_CCW_READ_CKD_MT:
211 case DASD_ECKD_CCW_READ_KD:
212 case DASD_ECKD_CCW_READ_KD_MT:
213 case DASD_ECKD_CCW_READ_COUNT:
214 data->mask.perm = 0x1;
215 data->attributes.operation = private->attrib.operation;
216 break;
217 case DASD_ECKD_CCW_WRITE:
218 case DASD_ECKD_CCW_WRITE_MT:
219 case DASD_ECKD_CCW_WRITE_KD:
220 case DASD_ECKD_CCW_WRITE_KD_MT:
221 data->mask.perm = 0x02;
222 data->attributes.operation = private->attrib.operation;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100223 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 break;
225 case DASD_ECKD_CCW_WRITE_CKD:
226 case DASD_ECKD_CCW_WRITE_CKD_MT:
227 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100228 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 break;
230 case DASD_ECKD_CCW_ERASE:
231 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
232 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
233 data->mask.perm = 0x3;
234 data->mask.auth = 0x1;
235 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100236 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
238 default:
239 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
240 break;
241 }
242
243 data->attributes.mode = 0x3; /* ECKD */
244
245 if ((private->rdc_data.cu_type == 0x2105 ||
246 private->rdc_data.cu_type == 0x2107 ||
247 private->rdc_data.cu_type == 0x1750)
248 && !(private->uses_cdl && trk < 2))
249 data->ga_extended |= 0x40; /* Regular Data Format Mode */
250
251 geo.cyl = private->rdc_data.no_cyl;
252 geo.head = private->rdc_data.trk_per_cyl;
253 beg.cyl = trk / geo.head;
254 beg.head = trk % geo.head;
255 end.cyl = totrk / geo.head;
256 end.head = totrk % geo.head;
257
258 /* check for sequential prestage - enhance cylinder range */
259 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
260 data->attributes.operation == DASD_SEQ_ACCESS) {
Horst Hummel138c0142006-06-29 14:58:12 +0200261
262 if (end.cyl + private->attrib.nr_cyl < geo.cyl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 end.cyl += private->attrib.nr_cyl;
264 else
265 end.cyl = (geo.cyl - 1);
266 }
267
268 data->beg_ext.cyl = beg.cyl;
269 data->beg_ext.head = beg.head;
270 data->end_ext.cyl = end.cyl;
271 data->end_ext.head = end.head;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100272 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100275static 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 */
286 pfxdata->define_extend.ga_extended |= 0x08; /* 'Time Stamp Valid' */
287 pfxdata->define_extend.ga_extended |= 0x02; /* 'Extended Parameter' */
288 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
289
290 rc = get_sync_clock(&pfxdata->define_extend.ep_sys_time);
291 /* Ignore return code if sync clock is switched off. */
292 if (rc == -ENOSYS || rc == -EACCES)
293 rc = 0;
294 return rc;
295}
296
297static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, int trk,
298 int totrk, int cmd, struct dasd_device *basedev,
299 struct dasd_device *startdev)
300{
301 struct dasd_eckd_private *basepriv, *startpriv;
302 struct DE_eckd_data *data;
303 struct ch_t geo, beg, end;
304 int rc = 0;
305
306 basepriv = (struct dasd_eckd_private *) basedev->private;
307 startpriv = (struct dasd_eckd_private *) startdev->private;
308 data = &pfxdata->define_extend;
309
310 ccw->cmd_code = DASD_ECKD_CCW_PFX;
311 ccw->flags = 0;
312 ccw->count = sizeof(*pfxdata);
313 ccw->cda = (__u32) __pa(pfxdata);
314
315 memset(pfxdata, 0, sizeof(*pfxdata));
316 /* prefix data */
317 pfxdata->format = 0;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200318 pfxdata->base_address = basepriv->ned->unit_addr;
319 pfxdata->base_lss = basepriv->ned->ID;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100320 pfxdata->validity.define_extend = 1;
321
322 /* private uid is kept up to date, conf_data may be outdated */
323 if (startpriv->uid.type != UA_BASE_DEVICE) {
324 pfxdata->validity.verify_base = 1;
325 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
326 pfxdata->validity.hyper_pav = 1;
327 }
328
329 /* define extend data (mostly)*/
330 switch (cmd) {
331 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
332 case DASD_ECKD_CCW_READ_RECORD_ZERO:
333 case DASD_ECKD_CCW_READ:
334 case DASD_ECKD_CCW_READ_MT:
335 case DASD_ECKD_CCW_READ_CKD:
336 case DASD_ECKD_CCW_READ_CKD_MT:
337 case DASD_ECKD_CCW_READ_KD:
338 case DASD_ECKD_CCW_READ_KD_MT:
339 case DASD_ECKD_CCW_READ_COUNT:
340 data->mask.perm = 0x1;
341 data->attributes.operation = basepriv->attrib.operation;
342 break;
343 case DASD_ECKD_CCW_WRITE:
344 case DASD_ECKD_CCW_WRITE_MT:
345 case DASD_ECKD_CCW_WRITE_KD:
346 case DASD_ECKD_CCW_WRITE_KD_MT:
347 data->mask.perm = 0x02;
348 data->attributes.operation = basepriv->attrib.operation;
349 rc = check_XRC_on_prefix(pfxdata, basedev);
350 break;
351 case DASD_ECKD_CCW_WRITE_CKD:
352 case DASD_ECKD_CCW_WRITE_CKD_MT:
353 data->attributes.operation = DASD_BYPASS_CACHE;
354 rc = check_XRC_on_prefix(pfxdata, basedev);
355 break;
356 case DASD_ECKD_CCW_ERASE:
357 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
358 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
359 data->mask.perm = 0x3;
360 data->mask.auth = 0x1;
361 data->attributes.operation = DASD_BYPASS_CACHE;
362 rc = check_XRC_on_prefix(pfxdata, basedev);
363 break;
364 default:
365 DEV_MESSAGE(KERN_ERR, basedev, "unknown opcode 0x%x", cmd);
366 break;
367 }
368
369 data->attributes.mode = 0x3; /* ECKD */
370
371 if ((basepriv->rdc_data.cu_type == 0x2105 ||
372 basepriv->rdc_data.cu_type == 0x2107 ||
373 basepriv->rdc_data.cu_type == 0x1750)
374 && !(basepriv->uses_cdl && trk < 2))
375 data->ga_extended |= 0x40; /* Regular Data Format Mode */
376
377 geo.cyl = basepriv->rdc_data.no_cyl;
378 geo.head = basepriv->rdc_data.trk_per_cyl;
379 beg.cyl = trk / geo.head;
380 beg.head = trk % geo.head;
381 end.cyl = totrk / geo.head;
382 end.head = totrk % geo.head;
383
384 /* check for sequential prestage - enhance cylinder range */
385 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
386 data->attributes.operation == DASD_SEQ_ACCESS) {
387
388 if (end.cyl + basepriv->attrib.nr_cyl < geo.cyl)
389 end.cyl += basepriv->attrib.nr_cyl;
390 else
391 end.cyl = (geo.cyl - 1);
392 }
393
394 data->beg_ext.cyl = beg.cyl;
395 data->beg_ext.head = beg.head;
396 data->end_ext.cyl = end.cyl;
397 data->end_ext.head = end.head;
398 return rc;
399}
400
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100401static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk,
403 int rec_on_trk, int no_rec, int cmd,
404 struct dasd_device * device, int reclen)
405{
406 struct dasd_eckd_private *private;
407 int sector;
408 int dn, d;
Horst Hummel138c0142006-06-29 14:58:12 +0200409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 private = (struct dasd_eckd_private *) device->private;
411
412 DBF_DEV_EVENT(DBF_INFO, device,
413 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
414 trk, rec_on_trk, no_rec, cmd, reclen);
415
416 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
417 ccw->flags = 0;
418 ccw->count = 16;
419 ccw->cda = (__u32) __pa(data);
420
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100421 memset(data, 0, sizeof(struct LO_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 sector = 0;
423 if (rec_on_trk) {
424 switch (private->rdc_data.dev_type) {
425 case 0x3390:
426 dn = ceil_quot(reclen + 6, 232);
427 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
428 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
429 break;
430 case 0x3380:
431 d = 7 + ceil_quot(reclen + 12, 32);
432 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
433 break;
434 }
435 }
436 data->sector = sector;
437 data->count = no_rec;
438 switch (cmd) {
439 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
440 data->operation.orientation = 0x3;
441 data->operation.operation = 0x03;
442 break;
443 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
444 data->operation.orientation = 0x3;
445 data->operation.operation = 0x16;
446 break;
447 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
448 data->operation.orientation = 0x1;
449 data->operation.operation = 0x03;
450 data->count++;
451 break;
452 case DASD_ECKD_CCW_READ_RECORD_ZERO:
453 data->operation.orientation = 0x3;
454 data->operation.operation = 0x16;
455 data->count++;
456 break;
457 case DASD_ECKD_CCW_WRITE:
458 case DASD_ECKD_CCW_WRITE_MT:
459 case DASD_ECKD_CCW_WRITE_KD:
460 case DASD_ECKD_CCW_WRITE_KD_MT:
461 data->auxiliary.last_bytes_used = 0x1;
462 data->length = reclen;
463 data->operation.operation = 0x01;
464 break;
465 case DASD_ECKD_CCW_WRITE_CKD:
466 case DASD_ECKD_CCW_WRITE_CKD_MT:
467 data->auxiliary.last_bytes_used = 0x1;
468 data->length = reclen;
469 data->operation.operation = 0x03;
470 break;
471 case DASD_ECKD_CCW_READ:
472 case DASD_ECKD_CCW_READ_MT:
473 case DASD_ECKD_CCW_READ_KD:
474 case DASD_ECKD_CCW_READ_KD_MT:
475 data->auxiliary.last_bytes_used = 0x1;
476 data->length = reclen;
477 data->operation.operation = 0x06;
478 break;
479 case DASD_ECKD_CCW_READ_CKD:
480 case DASD_ECKD_CCW_READ_CKD_MT:
481 data->auxiliary.last_bytes_used = 0x1;
482 data->length = reclen;
483 data->operation.operation = 0x16;
484 break;
485 case DASD_ECKD_CCW_READ_COUNT:
486 data->operation.operation = 0x06;
487 break;
488 case DASD_ECKD_CCW_ERASE:
489 data->length = reclen;
490 data->auxiliary.last_bytes_used = 0x1;
491 data->operation.operation = 0x0b;
492 break;
493 default:
494 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
495 }
496 data->seek_addr.cyl = data->search_arg.cyl =
497 trk / private->rdc_data.trk_per_cyl;
498 data->seek_addr.head = data->search_arg.head =
499 trk % private->rdc_data.trk_per_cyl;
500 data->search_arg.record = rec_on_trk;
501}
502
503/*
504 * Returns 1 if the block is one of the special blocks that needs
505 * to get read/written with the KD variant of the command.
506 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
507 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
508 * Luckily the KD variants differ only by one bit (0x08) from the
509 * normal variant. So don't wonder about code like:
510 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
511 * ccw->cmd_code |= 0x8;
512 */
513static inline int
514dasd_eckd_cdl_special(int blk_per_trk, int recid)
515{
516 if (recid < 3)
517 return 1;
518 if (recid < blk_per_trk)
519 return 0;
520 if (recid < 2 * blk_per_trk)
521 return 1;
522 return 0;
523}
524
525/*
526 * Returns the record size for the special blocks of the cdl format.
527 * Only returns something useful if dasd_eckd_cdl_special is true
528 * for the recid.
529 */
530static inline int
531dasd_eckd_cdl_reclen(int recid)
532{
533 if (recid < 3)
534 return sizes_trk0[recid];
535 return LABEL_SIZE;
536}
537
Horst Hummel3d052592006-04-27 18:40:28 -0700538/*
539 * Generate device unique id that specifies the physical device.
540 */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200541static int dasd_eckd_generate_uid(struct dasd_device *device,
542 struct dasd_uid *uid)
Horst Hummel3d052592006-04-27 18:40:28 -0700543{
544 struct dasd_eckd_private *private;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200545 int count;
Horst Hummel3d052592006-04-27 18:40:28 -0700546
547 private = (struct dasd_eckd_private *) device->private;
548 if (!private)
549 return -ENODEV;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200550 if (!private->ned || !private->gneq)
Horst Hummel3d052592006-04-27 18:40:28 -0700551 return -ENODEV;
552
553 memset(uid, 0, sizeof(struct dasd_uid));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200554 memcpy(uid->vendor, private->ned->HDA_manufacturer,
Horst Hummeld0710c72006-08-10 15:45:16 +0200555 sizeof(uid->vendor) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700556 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200557 memcpy(uid->serial, private->ned->HDA_location,
Horst Hummeld0710c72006-08-10 15:45:16 +0200558 sizeof(uid->serial) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700559 EBCASC(uid->serial, sizeof(uid->serial) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200560 uid->ssid = private->gneq->subsystemID;
561 uid->real_unit_addr = private->ned->unit_addr;;
562 if (private->sneq) {
563 uid->type = private->sneq->sua_flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100564 if (uid->type == UA_BASE_PAV_ALIAS)
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200565 uid->base_unit_addr = private->sneq->base_unit_addr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100566 } else {
567 uid->type = UA_BASE_DEVICE;
568 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200569 if (private->vdsneq) {
570 for (count = 0; count < 16; count++) {
571 sprintf(uid->vduit+2*count, "%02x",
572 private->vdsneq->uit[count]);
573 }
574 }
Horst Hummel3d052592006-04-27 18:40:28 -0700575 return 0;
576}
577
Heiko Carstens763968e2007-05-10 15:45:46 +0200578static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
579 void *rcd_buffer,
580 struct ciw *ciw, __u8 lpm)
Cornelia Huck17283b52007-05-04 18:47:51 +0200581{
582 struct dasd_ccw_req *cqr;
583 struct ccw1 *ccw;
584
585 cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
586
587 if (IS_ERR(cqr)) {
588 DEV_MESSAGE(KERN_WARNING, device, "%s",
589 "Could not allocate RCD request");
590 return cqr;
591 }
592
593 ccw = cqr->cpaddr;
594 ccw->cmd_code = ciw->cmd;
595 ccw->cda = (__u32)(addr_t)rcd_buffer;
596 ccw->count = ciw->count;
597
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100598 cqr->startdev = device;
599 cqr->memdev = device;
600 cqr->block = NULL;
Cornelia Huck17283b52007-05-04 18:47:51 +0200601 cqr->expires = 10*HZ;
602 cqr->lpm = lpm;
603 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
604 cqr->retries = 2;
605 cqr->buildclk = get_clock();
606 cqr->status = DASD_CQR_FILLED;
607 return cqr;
608}
609
610static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
611 void **rcd_buffer,
612 int *rcd_buffer_size, __u8 lpm)
613{
614 struct ciw *ciw;
615 char *rcd_buf = NULL;
616 int ret;
617 struct dasd_ccw_req *cqr;
618
619 /*
620 * scan for RCD command in extended SenseID data
621 */
622 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
623 if (!ciw || ciw->cmd == 0) {
624 ret = -EOPNOTSUPP;
625 goto out_error;
626 }
627 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
628 if (!rcd_buf) {
629 ret = -ENOMEM;
630 goto out_error;
631 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200632
633 /*
634 * buffer has to start with EBCDIC "V1.0" to show
635 * support for virtual device SNEQ
636 */
637 rcd_buf[0] = 0xE5;
638 rcd_buf[1] = 0xF1;
639 rcd_buf[2] = 0x4B;
640 rcd_buf[3] = 0xF0;
Cornelia Huck17283b52007-05-04 18:47:51 +0200641 cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
642 if (IS_ERR(cqr)) {
643 ret = PTR_ERR(cqr);
644 goto out_error;
645 }
646 ret = dasd_sleep_on(cqr);
647 /*
648 * on success we update the user input parms
649 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100650 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +0200651 if (ret)
652 goto out_error;
653
654 *rcd_buffer_size = ciw->count;
655 *rcd_buffer = rcd_buf;
656 return 0;
657out_error:
658 kfree(rcd_buf);
659 *rcd_buffer = NULL;
660 *rcd_buffer_size = 0;
661 return ret;
662}
663
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200664static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
665{
666
667 struct dasd_sneq *sneq;
668 int i, count;
669
670 private->ned = NULL;
671 private->sneq = NULL;
672 private->vdsneq = NULL;
673 private->gneq = NULL;
674 count = private->conf_len / sizeof(struct dasd_sneq);
675 sneq = (struct dasd_sneq *)private->conf_data;
676 for (i = 0; i < count; ++i) {
677 if (sneq->flags.identifier == 1 && sneq->format == 1)
678 private->sneq = sneq;
679 else if (sneq->flags.identifier == 1 && sneq->format == 4)
680 private->vdsneq = (struct vd_sneq *)sneq;
681 else if (sneq->flags.identifier == 2)
682 private->gneq = (struct dasd_gneq *)sneq;
683 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
684 private->ned = (struct dasd_ned *)sneq;
685 sneq++;
686 }
687 if (!private->ned || !private->gneq) {
688 private->ned = NULL;
689 private->sneq = NULL;
690 private->vdsneq = NULL;
691 private->gneq = NULL;
692 return -EINVAL;
693 }
694 return 0;
695
696};
697
698static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
699{
700 struct dasd_gneq *gneq;
701 int i, count, found;
702
703 count = conf_len / sizeof(*gneq);
704 gneq = (struct dasd_gneq *)conf_data;
705 found = 0;
706 for (i = 0; i < count; ++i) {
707 if (gneq->flags.identifier == 2) {
708 found = 1;
709 break;
710 }
711 gneq++;
712 }
713 if (found)
714 return ((char *)gneq)[18] & 0x07;
715 else
716 return 0;
717}
718
719static int dasd_eckd_read_conf(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
721 void *conf_data;
722 int conf_len, conf_data_saved;
723 int rc;
724 __u8 lpm;
725 struct dasd_eckd_private *private;
726 struct dasd_eckd_path *path_data;
727
728 private = (struct dasd_eckd_private *) device->private;
729 path_data = (struct dasd_eckd_path *) &private->path_data;
730 path_data->opm = ccw_device_get_path_mask(device->cdev);
731 lpm = 0x80;
732 conf_data_saved = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 /* get configuration data per operational path */
734 for (lpm = 0x80; lpm; lpm>>= 1) {
735 if (lpm & path_data->opm){
Cornelia Huck17283b52007-05-04 18:47:51 +0200736 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
737 &conf_len, lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
739 MESSAGE(KERN_WARNING,
740 "Read configuration data returned "
741 "error %d", rc);
742 return rc;
743 }
744 if (conf_data == NULL) {
745 MESSAGE(KERN_WARNING, "%s", "No configuration "
746 "data retrieved");
Gabriel Craciunescud133a962007-07-31 00:39:19 -0700747 continue; /* no error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 /* save first valid configuration data */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200750 if (!conf_data_saved) {
751 kfree(private->conf_data);
752 private->conf_data = conf_data;
753 private->conf_len = conf_len;
754 if (dasd_eckd_identify_conf_parts(private)) {
755 private->conf_data = NULL;
756 private->conf_len = 0;
757 kfree(conf_data);
758 continue;
759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 conf_data_saved++;
761 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200762 switch (dasd_eckd_path_access(conf_data, conf_len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 case 0x02:
764 path_data->npm |= lpm;
765 break;
766 case 0x03:
767 path_data->ppm |= lpm;
768 break;
769 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200770 if (conf_data != private->conf_data)
771 kfree(conf_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773 }
774 return 0;
775}
776
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100777static int dasd_eckd_read_features(struct dasd_device *device)
778{
779 struct dasd_psf_prssd_data *prssdp;
780 struct dasd_rssd_features *features;
781 struct dasd_ccw_req *cqr;
782 struct ccw1 *ccw;
783 int rc;
784 struct dasd_eckd_private *private;
785
786 private = (struct dasd_eckd_private *) device->private;
787 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
788 1 /* PSF */ + 1 /* RSSD */ ,
789 (sizeof(struct dasd_psf_prssd_data) +
790 sizeof(struct dasd_rssd_features)),
791 device);
792 if (IS_ERR(cqr)) {
793 DEV_MESSAGE(KERN_WARNING, device, "%s",
794 "Could not allocate initialization request");
795 return PTR_ERR(cqr);
796 }
797 cqr->startdev = device;
798 cqr->memdev = device;
799 cqr->block = NULL;
800 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
801 cqr->retries = 5;
802 cqr->expires = 10 * HZ;
803
804 /* Prepare for Read Subsystem Data */
805 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
806 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
807 prssdp->order = PSF_ORDER_PRSSD;
808 prssdp->suborder = 0x41; /* Read Feature Codes */
809 /* all other bytes of prssdp must be zero */
810
811 ccw = cqr->cpaddr;
812 ccw->cmd_code = DASD_ECKD_CCW_PSF;
813 ccw->count = sizeof(struct dasd_psf_prssd_data);
814 ccw->flags |= CCW_FLAG_CC;
815 ccw->cda = (__u32)(addr_t) prssdp;
816
817 /* Read Subsystem Data - feature codes */
818 features = (struct dasd_rssd_features *) (prssdp + 1);
819 memset(features, 0, sizeof(struct dasd_rssd_features));
820
821 ccw++;
822 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
823 ccw->count = sizeof(struct dasd_rssd_features);
824 ccw->cda = (__u32)(addr_t) features;
825
826 cqr->buildclk = get_clock();
827 cqr->status = DASD_CQR_FILLED;
828 rc = dasd_sleep_on(cqr);
829 if (rc == 0) {
830 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
831 features = (struct dasd_rssd_features *) (prssdp + 1);
832 memcpy(&private->features, features,
833 sizeof(struct dasd_rssd_features));
834 }
835 dasd_sfree_request(cqr, cqr->memdev);
836 return rc;
837}
838
839
Horst Hummel3d052592006-04-27 18:40:28 -0700840/*
Horst Hummel40545572006-06-29 15:08:18 +0200841 * Build CP for Perform Subsystem Function - SSC.
842 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100843static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device)
Horst Hummel40545572006-06-29 15:08:18 +0200844{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100845 struct dasd_ccw_req *cqr;
846 struct dasd_psf_ssc_data *psf_ssc_data;
847 struct ccw1 *ccw;
Horst Hummel40545572006-06-29 15:08:18 +0200848
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100849 cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
Horst Hummel40545572006-06-29 15:08:18 +0200850 sizeof(struct dasd_psf_ssc_data),
851 device);
852
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100853 if (IS_ERR(cqr)) {
854 DEV_MESSAGE(KERN_WARNING, device, "%s",
Horst Hummel40545572006-06-29 15:08:18 +0200855 "Could not allocate PSF-SSC request");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100856 return cqr;
857 }
858 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
859 psf_ssc_data->order = PSF_ORDER_SSC;
860 psf_ssc_data->suborder = 0x88;
861 psf_ssc_data->reserved[0] = 0x88;
Horst Hummel40545572006-06-29 15:08:18 +0200862
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100863 ccw = cqr->cpaddr;
864 ccw->cmd_code = DASD_ECKD_CCW_PSF;
865 ccw->cda = (__u32)(addr_t)psf_ssc_data;
866 ccw->count = 66;
Horst Hummel40545572006-06-29 15:08:18 +0200867
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100868 cqr->startdev = device;
869 cqr->memdev = device;
870 cqr->block = NULL;
871 cqr->expires = 10*HZ;
872 cqr->buildclk = get_clock();
873 cqr->status = DASD_CQR_FILLED;
874 return cqr;
Horst Hummel40545572006-06-29 15:08:18 +0200875}
876
877/*
878 * Perform Subsystem Function.
879 * It is necessary to trigger CIO for channel revalidation since this
880 * call might change behaviour of DASD devices.
881 */
882static int
883dasd_eckd_psf_ssc(struct dasd_device *device)
884{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100885 struct dasd_ccw_req *cqr;
886 int rc;
Horst Hummel40545572006-06-29 15:08:18 +0200887
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100888 cqr = dasd_eckd_build_psf_ssc(device);
889 if (IS_ERR(cqr))
890 return PTR_ERR(cqr);
Horst Hummel40545572006-06-29 15:08:18 +0200891
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100892 rc = dasd_sleep_on(cqr);
893 if (!rc)
894 /* trigger CIO to reprobe devices */
895 css_schedule_reprobe();
896 dasd_sfree_request(cqr, cqr->memdev);
897 return rc;
Horst Hummel40545572006-06-29 15:08:18 +0200898}
899
900/*
901 * Valide storage server of current device.
902 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100903static int dasd_eckd_validate_server(struct dasd_device *device)
Horst Hummel40545572006-06-29 15:08:18 +0200904{
905 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100906 struct dasd_eckd_private *private;
Horst Hummel40545572006-06-29 15:08:18 +0200907
908 /* Currently PAV is the only reason to 'validate' server on LPAR */
909 if (dasd_nopav || MACHINE_IS_VM)
910 return 0;
911
912 rc = dasd_eckd_psf_ssc(device);
Horst Hummel8e79a442006-08-24 13:22:36 +0200913 /* may be requested feature is not available on server,
914 * therefore just report error and go ahead */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100915 private = (struct dasd_eckd_private *) device->private;
Horst Hummel8e79a442006-08-24 13:22:36 +0200916 DEV_MESSAGE(KERN_INFO, device,
917 "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100918 private->uid.vendor, private->uid.serial,
919 private->uid.ssid, rc);
Horst Hummel40545572006-06-29 15:08:18 +0200920 /* RE-Read Configuration Data */
921 return dasd_eckd_read_conf(device);
922}
923
924/*
Horst Hummel3d052592006-04-27 18:40:28 -0700925 * Check device characteristics.
926 * If the device is accessible using ECKD discipline, the device is enabled.
927 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928static int
929dasd_eckd_check_characteristics(struct dasd_device *device)
930{
931 struct dasd_eckd_private *private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100932 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 void *rdc_data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100934 int is_known, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 private = (struct dasd_eckd_private *) device->private;
937 if (private == NULL) {
Horst Hummel138c0142006-06-29 14:58:12 +0200938 private = kzalloc(sizeof(struct dasd_eckd_private),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 GFP_KERNEL | GFP_DMA);
940 if (private == NULL) {
941 DEV_MESSAGE(KERN_WARNING, device, "%s",
942 "memory allocation failed for private "
943 "data");
944 return -ENOMEM;
945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 device->private = (void *) private;
947 }
948 /* Invalidate status of initial analysis. */
949 private->init_cqr_status = -1;
950 /* Set default cache operations. */
951 private->attrib.operation = DASD_NORMAL_CACHE;
952 private->attrib.nr_cyl = 0;
953
Horst Hummel40545572006-06-29 15:08:18 +0200954 /* Read Configuration Data */
955 rc = dasd_eckd_read_conf(device);
956 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100957 goto out_err1;
Horst Hummel40545572006-06-29 15:08:18 +0200958
959 /* Generate device unique id and register in devmap */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100960 rc = dasd_eckd_generate_uid(device, &private->uid);
Horst Hummel40545572006-06-29 15:08:18 +0200961 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100962 goto out_err1;
963 dasd_set_uid(device->cdev, &private->uid);
964
965 if (private->uid.type == UA_BASE_DEVICE) {
966 block = dasd_alloc_block();
967 if (IS_ERR(block)) {
968 DEV_MESSAGE(KERN_WARNING, device, "%s",
969 "could not allocate dasd block structure");
970 rc = PTR_ERR(block);
971 goto out_err1;
972 }
973 device->block = block;
974 block->base = device;
975 }
976
977 /* register lcu with alias handling, enable PAV if this is a new lcu */
978 is_known = dasd_alias_make_device_known_to_lcu(device);
979 if (is_known < 0) {
980 rc = is_known;
981 goto out_err2;
982 }
983 if (!is_known) {
984 /* new lcu found */
985 rc = dasd_eckd_validate_server(device); /* will switch pav on */
986 if (rc)
987 goto out_err3;
988 }
989
990 /* Read Feature Codes */
991 rc = dasd_eckd_read_features(device);
Horst Hummel40545572006-06-29 15:08:18 +0200992 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100993 goto out_err3;
Horst Hummel40545572006-06-29 15:08:18 +0200994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 /* Read Device Characteristics */
996 rdc_data = (void *) &(private->rdc_data);
Horst Hummel3d052592006-04-27 18:40:28 -0700997 memset(rdc_data, 0, sizeof(rdc_data));
Cornelia Huck17283b52007-05-04 18:47:51 +0200998 rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100999 if (rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 DEV_MESSAGE(KERN_WARNING, device,
Horst Hummel40545572006-06-29 15:08:18 +02001001 "Read device characteristics returned "
1002 "rc=%d", rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001003 goto out_err3;
1004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 DEV_MESSAGE(KERN_INFO, device,
1006 "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
1007 private->rdc_data.dev_type,
1008 private->rdc_data.dev_model,
1009 private->rdc_data.cu_type,
1010 private->rdc_data.cu_model.model,
1011 private->rdc_data.no_cyl,
1012 private->rdc_data.trk_per_cyl,
1013 private->rdc_data.sec_per_trk);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001014 return 0;
1015
1016out_err3:
1017 dasd_alias_disconnect_device_from_lcu(device);
1018out_err2:
1019 dasd_free_block(device->block);
1020 device->block = NULL;
1021out_err1:
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001022 kfree(private->conf_data);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001023 kfree(device->private);
1024 device->private = NULL;
Horst Hummel3d052592006-04-27 18:40:28 -07001025 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001028static void dasd_eckd_uncheck_device(struct dasd_device *device)
1029{
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001030 struct dasd_eckd_private *private;
1031
1032 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001033 dasd_alias_disconnect_device_from_lcu(device);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001034 private->ned = NULL;
1035 private->sneq = NULL;
1036 private->vdsneq = NULL;
1037 private->gneq = NULL;
1038 private->conf_len = 0;
1039 kfree(private->conf_data);
1040 private->conf_data = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001041}
1042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043static struct dasd_ccw_req *
1044dasd_eckd_analysis_ccw(struct dasd_device *device)
1045{
1046 struct dasd_eckd_private *private;
1047 struct eckd_count *count_data;
1048 struct LO_eckd_data *LO_data;
1049 struct dasd_ccw_req *cqr;
1050 struct ccw1 *ccw;
1051 int cplength, datasize;
1052 int i;
1053
1054 private = (struct dasd_eckd_private *) device->private;
1055
1056 cplength = 8;
1057 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1058 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1059 cplength, datasize, device);
1060 if (IS_ERR(cqr))
1061 return cqr;
1062 ccw = cqr->cpaddr;
1063 /* Define extent for the first 3 tracks. */
1064 define_extent(ccw++, cqr->data, 0, 2,
1065 DASD_ECKD_CCW_READ_COUNT, device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001066 LO_data = cqr->data + sizeof(struct DE_eckd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 /* Locate record for the first 4 records on track 0. */
1068 ccw[-1].flags |= CCW_FLAG_CC;
1069 locate_record(ccw++, LO_data++, 0, 0, 4,
1070 DASD_ECKD_CCW_READ_COUNT, device, 0);
1071
1072 count_data = private->count_area;
1073 for (i = 0; i < 4; i++) {
1074 ccw[-1].flags |= CCW_FLAG_CC;
1075 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1076 ccw->flags = 0;
1077 ccw->count = 8;
1078 ccw->cda = (__u32)(addr_t) count_data;
1079 ccw++;
1080 count_data++;
1081 }
1082
1083 /* Locate record for the first record on track 2. */
1084 ccw[-1].flags |= CCW_FLAG_CC;
1085 locate_record(ccw++, LO_data++, 2, 0, 1,
1086 DASD_ECKD_CCW_READ_COUNT, device, 0);
1087 /* Read count ccw. */
1088 ccw[-1].flags |= CCW_FLAG_CC;
1089 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1090 ccw->flags = 0;
1091 ccw->count = 8;
1092 ccw->cda = (__u32)(addr_t) count_data;
1093
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001094 cqr->block = NULL;
1095 cqr->startdev = device;
1096 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 cqr->retries = 0;
1098 cqr->buildclk = get_clock();
1099 cqr->status = DASD_CQR_FILLED;
1100 return cqr;
1101}
1102
1103/*
1104 * This is the callback function for the init_analysis cqr. It saves
1105 * the status of the initial analysis ccw before it frees it and kicks
1106 * the device to continue the startup sequence. This will call
1107 * dasd_eckd_do_analysis again (if the devices has not been marked
1108 * for deletion in the meantime).
1109 */
1110static void
1111dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
1112{
1113 struct dasd_eckd_private *private;
1114 struct dasd_device *device;
1115
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001116 device = init_cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 private = (struct dasd_eckd_private *) device->private;
1118 private->init_cqr_status = init_cqr->status;
1119 dasd_sfree_request(init_cqr, device);
1120 dasd_kick_device(device);
1121}
1122
1123static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001124dasd_eckd_start_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
1126 struct dasd_eckd_private *private;
1127 struct dasd_ccw_req *init_cqr;
1128
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001129 private = (struct dasd_eckd_private *) block->base->private;
1130 init_cqr = dasd_eckd_analysis_ccw(block->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (IS_ERR(init_cqr))
1132 return PTR_ERR(init_cqr);
1133 init_cqr->callback = dasd_eckd_analysis_callback;
1134 init_cqr->callback_data = NULL;
1135 init_cqr->expires = 5*HZ;
1136 dasd_add_request_head(init_cqr);
1137 return -EAGAIN;
1138}
1139
1140static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001141dasd_eckd_end_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001143 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 struct dasd_eckd_private *private;
1145 struct eckd_count *count_area;
1146 unsigned int sb, blk_per_trk;
1147 int status, i;
1148
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001149 device = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 private = (struct dasd_eckd_private *) device->private;
1151 status = private->init_cqr_status;
1152 private->init_cqr_status = -1;
1153 if (status != DASD_CQR_DONE) {
1154 DEV_MESSAGE(KERN_WARNING, device, "%s",
1155 "volume analysis returned unformatted disk");
1156 return -EMEDIUMTYPE;
1157 }
1158
1159 private->uses_cdl = 1;
1160 /* Calculate number of blocks/records per track. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001161 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 /* Check Track 0 for Compatible Disk Layout */
1163 count_area = NULL;
1164 for (i = 0; i < 3; i++) {
1165 if (private->count_area[i].kl != 4 ||
1166 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1167 private->uses_cdl = 0;
1168 break;
1169 }
1170 }
1171 if (i == 3)
1172 count_area = &private->count_area[4];
1173
1174 if (private->uses_cdl == 0) {
1175 for (i = 0; i < 5; i++) {
1176 if ((private->count_area[i].kl != 0) ||
1177 (private->count_area[i].dl !=
1178 private->count_area[0].dl))
1179 break;
1180 }
1181 if (i == 5)
1182 count_area = &private->count_area[0];
1183 } else {
1184 if (private->count_area[3].record == 1)
1185 DEV_MESSAGE(KERN_WARNING, device, "%s",
1186 "Trk 0: no records after VTOC!");
1187 }
1188 if (count_area != NULL && count_area->kl == 0) {
1189 /* we found notthing violating our disk layout */
1190 if (dasd_check_blocksize(count_area->dl) == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001191 block->bp_block = count_area->dl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001193 if (block->bp_block == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 DEV_MESSAGE(KERN_WARNING, device, "%s",
1195 "Volume has incompatible disk layout");
1196 return -EMEDIUMTYPE;
1197 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001198 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1199 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1200 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001202 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1203 block->blocks = (private->rdc_data.no_cyl *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 private->rdc_data.trk_per_cyl *
1205 blk_per_trk);
1206
1207 DEV_MESSAGE(KERN_INFO, device,
1208 "(%dkB blks): %dkB at %dkB/trk %s",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001209 (block->bp_block >> 10),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 ((private->rdc_data.no_cyl *
1211 private->rdc_data.trk_per_cyl *
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001212 blk_per_trk * (block->bp_block >> 9)) >> 1),
1213 ((blk_per_trk * block->bp_block) >> 10),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 private->uses_cdl ?
1215 "compatible disk layout" : "linux disk layout");
1216
1217 return 0;
1218}
1219
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001220static int dasd_eckd_do_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
1222 struct dasd_eckd_private *private;
1223
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001224 private = (struct dasd_eckd_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 if (private->init_cqr_status < 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001226 return dasd_eckd_start_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001228 return dasd_eckd_end_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001231static int dasd_eckd_ready_to_online(struct dasd_device *device)
1232{
1233 return dasd_alias_add_device(device);
1234};
1235
1236static int dasd_eckd_online_to_ready(struct dasd_device *device)
1237{
1238 return dasd_alias_remove_device(device);
1239};
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001242dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
1244 struct dasd_eckd_private *private;
1245
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001246 private = (struct dasd_eckd_private *) block->base->private;
1247 if (dasd_check_blocksize(block->bp_block) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 geo->sectors = recs_per_track(&private->rdc_data,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001249 0, block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251 geo->cylinders = private->rdc_data.no_cyl;
1252 geo->heads = private->rdc_data.trk_per_cyl;
1253 return 0;
1254}
1255
1256static struct dasd_ccw_req *
1257dasd_eckd_format_device(struct dasd_device * device,
1258 struct format_data_t * fdata)
1259{
1260 struct dasd_eckd_private *private;
1261 struct dasd_ccw_req *fcp;
1262 struct eckd_count *ect;
1263 struct ccw1 *ccw;
1264 void *data;
1265 int rpt, cyl, head;
1266 int cplength, datasize;
1267 int i;
1268
1269 private = (struct dasd_eckd_private *) device->private;
1270 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1271 cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
1272 head = fdata->start_unit % private->rdc_data.trk_per_cyl;
1273
1274 /* Sanity checks. */
1275 if (fdata->start_unit >=
1276 (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
1277 DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
1278 fdata->start_unit);
1279 return ERR_PTR(-EINVAL);
1280 }
1281 if (fdata->start_unit > fdata->stop_unit) {
1282 DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
1283 fdata->start_unit);
1284 return ERR_PTR(-EINVAL);
1285 }
1286 if (dasd_check_blocksize(fdata->blksize) != 0) {
1287 DEV_MESSAGE(KERN_WARNING, device,
1288 "Invalid blocksize %d...terminating!",
1289 fdata->blksize);
1290 return ERR_PTR(-EINVAL);
1291 }
1292
1293 /*
1294 * fdata->intensity is a bit string that tells us what to do:
1295 * Bit 0: write record zero
1296 * Bit 1: write home address, currently not supported
1297 * Bit 2: invalidate tracks
1298 * Bit 3: use OS/390 compatible disk layout (cdl)
1299 * Only some bit combinations do make sense.
1300 */
1301 switch (fdata->intensity) {
1302 case 0x00: /* Normal format */
1303 case 0x08: /* Normal format, use cdl. */
1304 cplength = 2 + rpt;
1305 datasize = sizeof(struct DE_eckd_data) +
1306 sizeof(struct LO_eckd_data) +
1307 rpt * sizeof(struct eckd_count);
1308 break;
1309 case 0x01: /* Write record zero and format track. */
1310 case 0x09: /* Write record zero and format track, use cdl. */
1311 cplength = 3 + rpt;
1312 datasize = sizeof(struct DE_eckd_data) +
1313 sizeof(struct LO_eckd_data) +
1314 sizeof(struct eckd_count) +
1315 rpt * sizeof(struct eckd_count);
1316 break;
1317 case 0x04: /* Invalidate track. */
1318 case 0x0c: /* Invalidate track, use cdl. */
1319 cplength = 3;
1320 datasize = sizeof(struct DE_eckd_data) +
1321 sizeof(struct LO_eckd_data) +
1322 sizeof(struct eckd_count);
1323 break;
1324 default:
1325 DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
1326 fdata->intensity);
1327 return ERR_PTR(-EINVAL);
1328 }
1329 /* Allocate the format ccw request. */
1330 fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
1331 cplength, datasize, device);
1332 if (IS_ERR(fcp))
1333 return fcp;
1334
1335 data = fcp->data;
1336 ccw = fcp->cpaddr;
1337
1338 switch (fdata->intensity & ~0x08) {
1339 case 0x00: /* Normal format. */
1340 define_extent(ccw++, (struct DE_eckd_data *) data,
1341 fdata->start_unit, fdata->start_unit,
1342 DASD_ECKD_CCW_WRITE_CKD, device);
1343 data += sizeof(struct DE_eckd_data);
1344 ccw[-1].flags |= CCW_FLAG_CC;
1345 locate_record(ccw++, (struct LO_eckd_data *) data,
1346 fdata->start_unit, 0, rpt,
1347 DASD_ECKD_CCW_WRITE_CKD, device,
1348 fdata->blksize);
1349 data += sizeof(struct LO_eckd_data);
1350 break;
1351 case 0x01: /* Write record zero + format track. */
1352 define_extent(ccw++, (struct DE_eckd_data *) data,
1353 fdata->start_unit, fdata->start_unit,
1354 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1355 device);
1356 data += sizeof(struct DE_eckd_data);
1357 ccw[-1].flags |= CCW_FLAG_CC;
1358 locate_record(ccw++, (struct LO_eckd_data *) data,
1359 fdata->start_unit, 0, rpt + 1,
1360 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001361 device->block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 data += sizeof(struct LO_eckd_data);
1363 break;
1364 case 0x04: /* Invalidate track. */
1365 define_extent(ccw++, (struct DE_eckd_data *) data,
1366 fdata->start_unit, fdata->start_unit,
1367 DASD_ECKD_CCW_WRITE_CKD, device);
1368 data += sizeof(struct DE_eckd_data);
1369 ccw[-1].flags |= CCW_FLAG_CC;
1370 locate_record(ccw++, (struct LO_eckd_data *) data,
1371 fdata->start_unit, 0, 1,
1372 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1373 data += sizeof(struct LO_eckd_data);
1374 break;
1375 }
1376 if (fdata->intensity & 0x01) { /* write record zero */
1377 ect = (struct eckd_count *) data;
1378 data += sizeof(struct eckd_count);
1379 ect->cyl = cyl;
1380 ect->head = head;
1381 ect->record = 0;
1382 ect->kl = 0;
1383 ect->dl = 8;
1384 ccw[-1].flags |= CCW_FLAG_CC;
1385 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1386 ccw->flags = CCW_FLAG_SLI;
1387 ccw->count = 8;
1388 ccw->cda = (__u32)(addr_t) ect;
1389 ccw++;
1390 }
1391 if ((fdata->intensity & ~0x08) & 0x04) { /* erase track */
1392 ect = (struct eckd_count *) data;
1393 data += sizeof(struct eckd_count);
1394 ect->cyl = cyl;
1395 ect->head = head;
1396 ect->record = 1;
1397 ect->kl = 0;
1398 ect->dl = 0;
1399 ccw[-1].flags |= CCW_FLAG_CC;
1400 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1401 ccw->flags = CCW_FLAG_SLI;
1402 ccw->count = 8;
1403 ccw->cda = (__u32)(addr_t) ect;
1404 } else { /* write remaining records */
1405 for (i = 0; i < rpt; i++) {
1406 ect = (struct eckd_count *) data;
1407 data += sizeof(struct eckd_count);
1408 ect->cyl = cyl;
1409 ect->head = head;
1410 ect->record = i + 1;
1411 ect->kl = 0;
1412 ect->dl = fdata->blksize;
1413 /* Check for special tracks 0-1 when formatting CDL */
1414 if ((fdata->intensity & 0x08) &&
1415 fdata->start_unit == 0) {
1416 if (i < 3) {
1417 ect->kl = 4;
1418 ect->dl = sizes_trk0[i] - 4;
Horst Hummel138c0142006-06-29 14:58:12 +02001419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421 if ((fdata->intensity & 0x08) &&
1422 fdata->start_unit == 1) {
1423 ect->kl = 44;
1424 ect->dl = LABEL_SIZE - 44;
1425 }
1426 ccw[-1].flags |= CCW_FLAG_CC;
1427 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1428 ccw->flags = CCW_FLAG_SLI;
1429 ccw->count = 8;
1430 ccw->cda = (__u32)(addr_t) ect;
1431 ccw++;
1432 }
1433 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001434 fcp->startdev = device;
1435 fcp->memdev = device;
1436 clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags);
1437 fcp->retries = 5; /* set retry counter to enable default ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 fcp->buildclk = get_clock();
1439 fcp->status = DASD_CQR_FILLED;
1440 return fcp;
1441}
1442
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001443static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001445 cqr->status = DASD_CQR_FILLED;
1446 if (cqr->block && (cqr->startdev != cqr->block->base)) {
1447 dasd_eckd_reset_ccw_to_base_io(cqr);
1448 cqr->startdev = cqr->block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001450};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
1452static dasd_erp_fn_t
1453dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1454{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001455 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 struct ccw_device *cdev = device->cdev;
1457
1458 switch (cdev->id.cu_type) {
1459 case 0x3990:
1460 case 0x2105:
1461 case 0x2107:
1462 case 0x1750:
1463 return dasd_3990_erp_action;
1464 case 0x9343:
1465 case 0x3880:
1466 default:
1467 return dasd_default_erp_action;
1468 }
1469}
1470
1471static dasd_erp_fn_t
1472dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1473{
1474 return dasd_default_erp_postaction;
1475}
1476
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001477
1478static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1479 struct irb *irb)
1480{
1481 char mask;
1482
1483 /* first of all check for state change pending interrupt */
1484 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001485 if ((irb->scsw.cmd.dstat & mask) == mask) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001486 dasd_generic_handle_state_change(device);
1487 return;
1488 }
1489
1490 /* summary unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001491 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
1492 (irb->ecw[7] == 0x0D)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001493 dasd_alias_handle_summary_unit_check(device, irb);
1494 return;
1495 }
1496
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001497
1498 /* service information message SIM */
Stefan Haberland50afd202008-12-25 13:38:53 +01001499 if (irb->esw.esw0.erw.cons && !(irb->ecw[27] & DASD_SENSE_BIT_0) &&
Stefan Haberland9d853ca2008-07-17 17:16:41 +02001500 ((irb->ecw[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001501 dasd_3990_erp_handle_sim(device, irb->ecw);
Stefan Haberland9d853ca2008-07-17 17:16:41 +02001502 dasd_schedule_device_bh(device);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001503 return;
1504 }
1505
Stefan Haberlandada3df92008-10-10 21:33:23 +02001506 if ((irb->scsw.cmd.cc == 1) &&
1507 (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
1508 (irb->scsw.cmd.actl & SCSW_ACTL_START_PEND) &&
1509 (irb->scsw.cmd.stctl & SCSW_STCTL_STATUS_PEND)) {
1510 /* fake irb do nothing, they are handled elsewhere */
1511 dasd_schedule_device_bh(device);
1512 return;
1513 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001514
Stefan Haberlandada3df92008-10-10 21:33:23 +02001515 if (!(irb->esw.esw0.erw.cons)) {
1516 /* just report other unsolicited interrupts */
1517 DEV_MESSAGE(KERN_ERR, device, "%s",
1518 "unsolicited interrupt received");
1519 } else {
1520 DEV_MESSAGE(KERN_ERR, device, "%s",
1521 "unsolicited interrupt received "
1522 "(sense available)");
1523 device->discipline->dump_sense(device, NULL, irb);
1524 }
1525
1526 dasd_schedule_device_bh(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001527 return;
1528};
1529
1530static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
1531 struct dasd_block *block,
1532 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
1534 struct dasd_eckd_private *private;
1535 unsigned long *idaws;
1536 struct LO_eckd_data *LO_data;
1537 struct dasd_ccw_req *cqr;
1538 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02001539 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 struct bio_vec *bv;
1541 char *dst;
1542 unsigned int blksize, blk_per_trk, off;
1543 int count, cidaw, cplength, datasize;
1544 sector_t recid, first_rec, last_rec;
1545 sector_t first_trk, last_trk;
1546 unsigned int first_offs, last_offs;
1547 unsigned char cmd, rcmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001548 int use_prefix;
1549 struct dasd_device *basedev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001551 basedev = block->base;
1552 private = (struct dasd_eckd_private *) basedev->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 if (rq_data_dir(req) == READ)
1554 cmd = DASD_ECKD_CCW_READ_MT;
1555 else if (rq_data_dir(req) == WRITE)
1556 cmd = DASD_ECKD_CCW_WRITE_MT;
1557 else
1558 return ERR_PTR(-EINVAL);
1559 /* Calculate number of blocks/records per track. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001560 blksize = block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1562 /* Calculate record id of first and last block. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001563 first_rec = first_trk = req->sector >> block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 first_offs = sector_div(first_trk, blk_per_trk);
1565 last_rec = last_trk =
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001566 (req->sector + req->nr_sectors - 1) >> block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 last_offs = sector_div(last_trk, blk_per_trk);
1568 /* Check struct bio and count the number of blocks for the request. */
1569 count = 0;
1570 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +02001571 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +02001572 if (bv->bv_len & (blksize - 1))
1573 /* Eckd can only do full blocks. */
1574 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001575 count += bv->bv_len >> (block->s2b_shift + 9);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001576#if defined(CONFIG_64BIT)
Jens Axboe6c92e692007-08-16 13:43:12 +02001577 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001578 cidaw += bv->bv_len >> (block->s2b_shift + 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 }
1581 /* Paranoia. */
1582 if (count != last_rec - first_rec + 1)
1583 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001584
1585 /* use the prefix command if available */
1586 use_prefix = private->features.feature[8] & 0x01;
1587 if (use_prefix) {
1588 /* 1x prefix + number of blocks */
1589 cplength = 2 + count;
1590 /* 1x prefix + cidaws*sizeof(long) */
1591 datasize = sizeof(struct PFX_eckd_data) +
1592 sizeof(struct LO_eckd_data) +
1593 cidaw * sizeof(unsigned long);
1594 } else {
1595 /* 1x define extent + 1x locate record + number of blocks */
1596 cplength = 2 + count;
1597 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1598 datasize = sizeof(struct DE_eckd_data) +
1599 sizeof(struct LO_eckd_data) +
1600 cidaw * sizeof(unsigned long);
1601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 /* Find out the number of additional locate record ccws for cdl. */
1603 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1604 if (last_rec >= 2*blk_per_trk)
1605 count = 2*blk_per_trk - first_rec;
1606 cplength += count;
1607 datasize += count*sizeof(struct LO_eckd_data);
1608 }
1609 /* Allocate the ccw request. */
1610 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001611 cplength, datasize, startdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 if (IS_ERR(cqr))
1613 return cqr;
1614 ccw = cqr->cpaddr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001615 /* First ccw is define extent or prefix. */
1616 if (use_prefix) {
1617 if (prefix(ccw++, cqr->data, first_trk,
1618 last_trk, cmd, basedev, startdev) == -EAGAIN) {
1619 /* Clock not in sync and XRC is enabled.
1620 * Try again later.
1621 */
1622 dasd_sfree_request(cqr, startdev);
1623 return ERR_PTR(-EAGAIN);
1624 }
1625 idaws = (unsigned long *) (cqr->data +
1626 sizeof(struct PFX_eckd_data));
1627 } else {
1628 if (define_extent(ccw++, cqr->data, first_trk,
1629 last_trk, cmd, startdev) == -EAGAIN) {
1630 /* Clock not in sync and XRC is enabled.
1631 * Try again later.
1632 */
1633 dasd_sfree_request(cqr, startdev);
1634 return ERR_PTR(-EAGAIN);
1635 }
1636 idaws = (unsigned long *) (cqr->data +
1637 sizeof(struct DE_eckd_data));
Martin Schwidefskyd54853e2007-02-05 21:18:19 +01001638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /* Build locate_record+read/write/ccws. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1641 recid = first_rec;
1642 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1643 /* Only standard blocks so there is just one locate record. */
1644 ccw[-1].flags |= CCW_FLAG_CC;
1645 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001646 last_rec - recid + 1, cmd, basedev, blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 }
NeilBrown5705f702007-09-25 12:35:59 +02001648 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 dst = page_address(bv->bv_page) + bv->bv_offset;
1650 if (dasd_page_cache) {
1651 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -08001652 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (copy && rq_data_dir(req) == WRITE)
1654 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1655 if (copy)
1656 dst = copy + bv->bv_offset;
1657 }
1658 for (off = 0; off < bv->bv_len; off += blksize) {
1659 sector_t trkid = recid;
1660 unsigned int recoffs = sector_div(trkid, blk_per_trk);
1661 rcmd = cmd;
1662 count = blksize;
1663 /* Locate record for cdl special block ? */
1664 if (private->uses_cdl && recid < 2*blk_per_trk) {
1665 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1666 rcmd |= 0x8;
1667 count = dasd_eckd_cdl_reclen(recid);
Horst Hummelec5883a2005-05-01 08:58:59 -07001668 if (count < blksize &&
1669 rq_data_dir(req) == READ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 memset(dst + count, 0xe5,
1671 blksize - count);
1672 }
1673 ccw[-1].flags |= CCW_FLAG_CC;
1674 locate_record(ccw++, LO_data++,
1675 trkid, recoffs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001676 1, rcmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 }
1678 /* Locate record for standard blocks ? */
1679 if (private->uses_cdl && recid == 2*blk_per_trk) {
1680 ccw[-1].flags |= CCW_FLAG_CC;
1681 locate_record(ccw++, LO_data++,
1682 trkid, recoffs + 1,
1683 last_rec - recid + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001684 cmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 }
1686 /* Read/write ccw. */
1687 ccw[-1].flags |= CCW_FLAG_CC;
1688 ccw->cmd_code = rcmd;
1689 ccw->count = count;
1690 if (idal_is_needed(dst, blksize)) {
1691 ccw->cda = (__u32)(addr_t) idaws;
1692 ccw->flags = CCW_FLAG_IDA;
1693 idaws = idal_create_words(idaws, dst, blksize);
1694 } else {
1695 ccw->cda = (__u32)(addr_t) dst;
1696 ccw->flags = 0;
1697 }
1698 ccw++;
1699 dst += blksize;
1700 recid++;
1701 }
1702 }
Mike Christie6000a362008-08-19 18:45:30 -05001703 if (blk_noretry_request(req))
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001704 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001705 cqr->startdev = startdev;
1706 cqr->memdev = startdev;
1707 cqr->block = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
1709 cqr->lpm = private->path_data.ppm;
1710 cqr->retries = 256;
1711 cqr->buildclk = get_clock();
1712 cqr->status = DASD_CQR_FILLED;
1713 return cqr;
1714}
1715
1716static int
1717dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1718{
1719 struct dasd_eckd_private *private;
1720 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02001721 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 struct bio_vec *bv;
1723 char *dst, *cda;
1724 unsigned int blksize, blk_per_trk, off;
1725 sector_t recid;
NeilBrown5705f702007-09-25 12:35:59 +02001726 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 if (!dasd_page_cache)
1729 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001730 private = (struct dasd_eckd_private *) cqr->block->base->private;
1731 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001733 recid = req->sector >> cqr->block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 ccw = cqr->cpaddr;
1735 /* Skip over define extent & locate record. */
1736 ccw++;
1737 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
1738 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +02001739 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 dst = page_address(bv->bv_page) + bv->bv_offset;
1741 for (off = 0; off < bv->bv_len; off += blksize) {
1742 /* Skip locate record. */
1743 if (private->uses_cdl && recid <= 2*blk_per_trk)
1744 ccw++;
1745 if (dst) {
1746 if (ccw->flags & CCW_FLAG_IDA)
1747 cda = *((char **)((addr_t) ccw->cda));
1748 else
1749 cda = (char *)((addr_t) ccw->cda);
1750 if (dst != cda) {
1751 if (rq_data_dir(req) == READ)
1752 memcpy(dst, cda, bv->bv_len);
1753 kmem_cache_free(dasd_page_cache,
1754 (void *)((addr_t)cda & PAGE_MASK));
1755 }
1756 dst = NULL;
1757 }
1758 ccw++;
1759 recid++;
1760 }
1761 }
1762out:
1763 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001764 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return status;
1766}
1767
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001768/*
1769 * Modify ccw chain in cqr so it can be started on a base device.
1770 *
1771 * Note that this is not enough to restart the cqr!
1772 * Either reset cqr->startdev as well (summary unit check handling)
1773 * or restart via separate cqr (as in ERP handling).
1774 */
1775void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
1776{
1777 struct ccw1 *ccw;
1778 struct PFX_eckd_data *pfxdata;
1779
1780 ccw = cqr->cpaddr;
1781 pfxdata = cqr->data;
1782
1783 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
1784 pfxdata->validity.verify_base = 0;
1785 pfxdata->validity.hyper_pav = 0;
1786 }
1787}
1788
1789#define DASD_ECKD_CHANQ_MAX_SIZE 4
1790
1791static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
1792 struct dasd_block *block,
1793 struct request *req)
1794{
1795 struct dasd_eckd_private *private;
1796 struct dasd_device *startdev;
1797 unsigned long flags;
1798 struct dasd_ccw_req *cqr;
1799
1800 startdev = dasd_alias_get_start_dev(base);
1801 if (!startdev)
1802 startdev = base;
1803 private = (struct dasd_eckd_private *) startdev->private;
1804 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
1805 return ERR_PTR(-EBUSY);
1806
1807 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
1808 private->count++;
1809 cqr = dasd_eckd_build_cp(startdev, block, req);
1810 if (IS_ERR(cqr))
1811 private->count--;
1812 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
1813 return cqr;
1814}
1815
1816static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
1817 struct request *req)
1818{
1819 struct dasd_eckd_private *private;
1820 unsigned long flags;
1821
1822 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
1823 private = (struct dasd_eckd_private *) cqr->memdev->private;
1824 private->count--;
1825 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
1826 return dasd_eckd_free_cp(cqr, req);
1827}
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829static int
1830dasd_eckd_fill_info(struct dasd_device * device,
1831 struct dasd_information2_t * info)
1832{
1833 struct dasd_eckd_private *private;
1834
1835 private = (struct dasd_eckd_private *) device->private;
1836 info->label_block = 2;
1837 info->FBA_layout = private->uses_cdl ? 0 : 1;
1838 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
1839 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
1840 memcpy(info->characteristics, &private->rdc_data,
1841 sizeof(struct dasd_eckd_characteristics));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001842 info->confdata_size = min((unsigned long)private->conf_len,
1843 sizeof(info->configuration_data));
1844 memcpy(info->configuration_data, private->conf_data,
1845 info->confdata_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 return 0;
1847}
1848
1849/*
1850 * SECTION: ioctl functions for eckd devices.
1851 */
1852
1853/*
1854 * Release device ioctl.
Horst Hummel138c0142006-06-29 14:58:12 +02001855 * Buils a channel programm to releases a prior reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 * (see dasd_eckd_reserve) device.
1857 */
1858static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08001859dasd_eckd_release(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 struct dasd_ccw_req *cqr;
1862 int rc;
1863
1864 if (!capable(CAP_SYS_ADMIN))
1865 return -EACCES;
1866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1868 1, 32, device);
1869 if (IS_ERR(cqr)) {
1870 DEV_MESSAGE(KERN_WARNING, device, "%s",
1871 "Could not allocate initialization request");
1872 return PTR_ERR(cqr);
1873 }
1874 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
1875 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1876 cqr->cpaddr->count = 32;
1877 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001878 cqr->startdev = device;
1879 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001881 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01001882 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 cqr->expires = 2 * HZ;
1884 cqr->buildclk = get_clock();
1885 cqr->status = DASD_CQR_FILLED;
1886
1887 rc = dasd_sleep_on_immediatly(cqr);
1888
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001889 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 return rc;
1891}
1892
1893/*
1894 * Reserve device ioctl.
1895 * Options are set to 'synchronous wait for interrupt' and
Horst Hummel138c0142006-06-29 14:58:12 +02001896 * 'timeout the request'. This leads to a terminate IO if
1897 * the interrupt is outstanding for a certain time.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 */
1899static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08001900dasd_eckd_reserve(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 struct dasd_ccw_req *cqr;
1903 int rc;
1904
1905 if (!capable(CAP_SYS_ADMIN))
1906 return -EACCES;
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1909 1, 32, device);
1910 if (IS_ERR(cqr)) {
1911 DEV_MESSAGE(KERN_WARNING, device, "%s",
1912 "Could not allocate initialization request");
1913 return PTR_ERR(cqr);
1914 }
1915 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
1916 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1917 cqr->cpaddr->count = 32;
1918 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001919 cqr->startdev = device;
1920 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001922 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01001923 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 cqr->expires = 2 * HZ;
1925 cqr->buildclk = get_clock();
1926 cqr->status = DASD_CQR_FILLED;
1927
1928 rc = dasd_sleep_on_immediatly(cqr);
1929
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001930 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 return rc;
1932}
1933
1934/*
1935 * Steal lock ioctl - unconditional reserve device.
Horst Hummel138c0142006-06-29 14:58:12 +02001936 * Buils a channel programm to break a device's reservation.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 * (unconditional reserve)
1938 */
1939static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08001940dasd_eckd_steal_lock(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 struct dasd_ccw_req *cqr;
1943 int rc;
1944
1945 if (!capable(CAP_SYS_ADMIN))
1946 return -EACCES;
1947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1949 1, 32, device);
1950 if (IS_ERR(cqr)) {
1951 DEV_MESSAGE(KERN_WARNING, device, "%s",
1952 "Could not allocate initialization request");
1953 return PTR_ERR(cqr);
1954 }
1955 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
1956 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1957 cqr->cpaddr->count = 32;
1958 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001959 cqr->startdev = device;
1960 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001962 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01001963 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 cqr->expires = 2 * HZ;
1965 cqr->buildclk = get_clock();
1966 cqr->status = DASD_CQR_FILLED;
1967
1968 rc = dasd_sleep_on_immediatly(cqr);
1969
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001970 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 return rc;
1972}
1973
1974/*
1975 * Read performance statistics
1976 */
1977static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08001978dasd_eckd_performance(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 struct dasd_psf_prssd_data *prssdp;
1981 struct dasd_rssd_perf_stats_t *stats;
1982 struct dasd_ccw_req *cqr;
1983 struct ccw1 *ccw;
1984 int rc;
1985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1987 1 /* PSF */ + 1 /* RSSD */ ,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001988 (sizeof(struct dasd_psf_prssd_data) +
1989 sizeof(struct dasd_rssd_perf_stats_t)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 device);
1991 if (IS_ERR(cqr)) {
1992 DEV_MESSAGE(KERN_WARNING, device, "%s",
1993 "Could not allocate initialization request");
1994 return PTR_ERR(cqr);
1995 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001996 cqr->startdev = device;
1997 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 cqr->retries = 0;
1999 cqr->expires = 10 * HZ;
2000
2001 /* Prepare for Read Subsystem Data */
2002 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002003 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 prssdp->order = PSF_ORDER_PRSSD;
Joe Perches5d67d162008-01-26 14:11:20 +01002005 prssdp->suborder = 0x01; /* Performance Statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
2007
2008 ccw = cqr->cpaddr;
2009 ccw->cmd_code = DASD_ECKD_CCW_PSF;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002010 ccw->count = sizeof(struct dasd_psf_prssd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 ccw->flags |= CCW_FLAG_CC;
2012 ccw->cda = (__u32)(addr_t) prssdp;
2013
2014 /* Read Subsystem Data - Performance Statistics */
2015 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002016 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
2018 ccw++;
2019 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002020 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 ccw->cda = (__u32)(addr_t) stats;
2022
2023 cqr->buildclk = get_clock();
2024 cqr->status = DASD_CQR_FILLED;
2025 rc = dasd_sleep_on(cqr);
2026 if (rc == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2028 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002029 if (copy_to_user(argp, stats,
2030 sizeof(struct dasd_rssd_perf_stats_t)))
2031 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002033 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 return rc;
2035}
2036
2037/*
2038 * Get attributes (cache operations)
2039 * Returnes the cache attributes used in Define Extend (DE).
2040 */
2041static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002042dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002044 struct dasd_eckd_private *private =
2045 (struct dasd_eckd_private *)device->private;
2046 struct attrib_data_t attrib = private->attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 int rc;
2048
2049 if (!capable(CAP_SYS_ADMIN))
2050 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002051 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 return -EINVAL;
2053
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002054 rc = 0;
2055 if (copy_to_user(argp, (long *) &attrib,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002056 sizeof(struct attrib_data_t)))
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002057 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
2059 return rc;
2060}
2061
2062/*
2063 * Set attributes (cache operations)
2064 * Stores the attributes for cache operation to be used in Define Extend (DE).
2065 */
2066static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002067dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002069 struct dasd_eckd_private *private =
2070 (struct dasd_eckd_private *)device->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct attrib_data_t attrib;
2072
2073 if (!capable(CAP_SYS_ADMIN))
2074 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002075 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 return -EINVAL;
2077
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002078 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 private->attrib = attrib;
2081
2082 DEV_MESSAGE(KERN_INFO, device,
2083 "cache operation mode set to %x (%i cylinder prestage)",
2084 private->attrib.operation, private->attrib.nr_cyl);
2085 return 0;
2086}
2087
Nigel Hislopab1d8482008-10-10 21:33:25 +02002088/*
2089 * Issue syscall I/O to EMC Symmetrix array.
2090 * CCWs are PSF and RSSD
2091 */
2092static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2093{
2094 struct dasd_symmio_parms usrparm;
2095 char *psf_data, *rssd_result;
2096 struct dasd_ccw_req *cqr;
2097 struct ccw1 *ccw;
2098 int rc;
2099
2100 /* Copy parms from caller */
2101 rc = -EFAULT;
2102 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2103 goto out;
2104#ifndef CONFIG_64BIT
2105 /* Make sure pointers are sane even on 31 bit. */
2106 if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) {
2107 rc = -EINVAL;
2108 goto out;
2109 }
2110#endif
2111 /* alloc I/O data area */
2112 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2113 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2114 if (!psf_data || !rssd_result) {
2115 rc = -ENOMEM;
2116 goto out_free;
2117 }
2118
2119 /* get syscall header from user space */
2120 rc = -EFAULT;
2121 if (copy_from_user(psf_data,
2122 (void __user *)(unsigned long) usrparm.psf_data,
2123 usrparm.psf_data_len))
2124 goto out_free;
2125
2126 /* sanity check on syscall header */
2127 if (psf_data[0] != 0x17 && psf_data[1] != 0xce) {
2128 rc = -EINVAL;
2129 goto out_free;
2130 }
2131
2132 /* setup CCWs for PSF + RSSD */
2133 cqr = dasd_smalloc_request("ECKD", 2 , 0, device);
2134 if (IS_ERR(cqr)) {
2135 DEV_MESSAGE(KERN_WARNING, device, "%s",
2136 "Could not allocate initialization request");
2137 rc = PTR_ERR(cqr);
2138 goto out_free;
2139 }
2140
2141 cqr->startdev = device;
2142 cqr->memdev = device;
2143 cqr->retries = 3;
2144 cqr->expires = 10 * HZ;
2145 cqr->buildclk = get_clock();
2146 cqr->status = DASD_CQR_FILLED;
2147
2148 /* Build the ccws */
2149 ccw = cqr->cpaddr;
2150
2151 /* PSF ccw */
2152 ccw->cmd_code = DASD_ECKD_CCW_PSF;
2153 ccw->count = usrparm.psf_data_len;
2154 ccw->flags |= CCW_FLAG_CC;
2155 ccw->cda = (__u32)(addr_t) psf_data;
2156
2157 ccw++;
2158
2159 /* RSSD ccw */
2160 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2161 ccw->count = usrparm.rssd_result_len;
2162 ccw->flags = CCW_FLAG_SLI ;
2163 ccw->cda = (__u32)(addr_t) rssd_result;
2164
2165 rc = dasd_sleep_on(cqr);
2166 if (rc)
2167 goto out_sfree;
2168
2169 rc = -EFAULT;
2170 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
2171 rssd_result, usrparm.rssd_result_len))
2172 goto out_sfree;
2173 rc = 0;
2174
2175out_sfree:
2176 dasd_sfree_request(cqr, cqr->memdev);
2177out_free:
2178 kfree(rssd_result);
2179 kfree(psf_data);
2180out:
2181 DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc);
2182 return rc;
2183}
2184
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002185static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002186dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002187{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002188 struct dasd_device *device = block->base;
2189
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002190 switch (cmd) {
2191 case BIODASDGATTR:
2192 return dasd_eckd_get_attrib(device, argp);
2193 case BIODASDSATTR:
2194 return dasd_eckd_set_attrib(device, argp);
2195 case BIODASDPSRD:
2196 return dasd_eckd_performance(device, argp);
2197 case BIODASDRLSE:
2198 return dasd_eckd_release(device);
2199 case BIODASDRSRV:
2200 return dasd_eckd_reserve(device);
2201 case BIODASDSLCK:
2202 return dasd_eckd_steal_lock(device);
Nigel Hislopab1d8482008-10-10 21:33:25 +02002203 case BIODASDSYMMIO:
2204 return dasd_symm_io(device, argp);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002205 default:
2206 return -ENOIOCTLCMD;
2207 }
2208}
2209
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210/*
Horst Hummel445b5b42006-06-29 14:57:52 +02002211 * Dump the range of CCWs into 'page' buffer
2212 * and return number of printed chars.
2213 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002214static int
Horst Hummel445b5b42006-06-29 14:57:52 +02002215dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
2216{
2217 int len, count;
2218 char *datap;
2219
2220 len = 0;
2221 while (from <= to) {
2222 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2223 " CCW %p: %08X %08X DAT:",
2224 from, ((int *) from)[0], ((int *) from)[1]);
2225
2226 /* get pointer to data (consider IDALs) */
2227 if (from->flags & CCW_FLAG_IDA)
2228 datap = (char *) *((addr_t *) (addr_t) from->cda);
2229 else
2230 datap = (char *) ((addr_t) from->cda);
2231
2232 /* dump data (max 32 bytes) */
2233 for (count = 0; count < from->count && count < 32; count++) {
2234 if (count % 8 == 0) len += sprintf(page + len, " ");
2235 if (count % 4 == 0) len += sprintf(page + len, " ");
2236 len += sprintf(page + len, "%02x", datap[count]);
2237 }
2238 len += sprintf(page + len, "\n");
2239 from++;
2240 }
2241 return len;
2242}
2243
2244/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 * Print sense data and related channel program.
2246 * Parts are printed because printk buffer is only 1024 bytes.
2247 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002248static void dasd_eckd_dump_sense(struct dasd_device *device,
2249 struct dasd_ccw_req *req, struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250{
2251 char *page;
Horst Hummel445b5b42006-06-29 14:57:52 +02002252 struct ccw1 *first, *last, *fail, *from, *to;
2253 int len, sl, sct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
2255 page = (char *) get_zeroed_page(GFP_ATOMIC);
2256 if (page == NULL) {
2257 DEV_MESSAGE(KERN_ERR, device, " %s",
2258 "No memory to dump sense data");
2259 return;
2260 }
Horst Hummel445b5b42006-06-29 14:57:52 +02002261 /* dump the sense data */
2262 len = sprintf(page, KERN_ERR PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02002264 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2266 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02002267 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2269 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02002270 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02002271 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 if (irb->esw.esw0.erw.cons) {
2273 for (sl = 0; sl < 4; sl++) {
2274 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2275 " Sense(hex) %2d-%2d:",
2276 (8 * sl), ((8 * sl) + 7));
2277
2278 for (sct = 0; sct < 8; sct++) {
2279 len += sprintf(page + len, " %02x",
2280 irb->ecw[8 * sl + sct]);
2281 }
2282 len += sprintf(page + len, "\n");
2283 }
2284
2285 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
2286 /* 24 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02002287 sprintf(page + len, KERN_ERR PRINTK_HEADER
2288 " 24 Byte: %x MSG %x, "
2289 "%s MSGb to SYSOP\n",
2290 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
2291 irb->ecw[1] & 0x10 ? "" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 } else {
2293 /* 32 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02002294 sprintf(page + len, KERN_ERR PRINTK_HEADER
2295 " 32 Byte: Format: %x "
2296 "Exception class %x\n",
2297 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 }
2299 } else {
Horst Hummel445b5b42006-06-29 14:57:52 +02002300 sprintf(page + len, KERN_ERR PRINTK_HEADER
2301 " SORRY - NO VALID SENSE AVAILABLE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 }
Horst Hummel445b5b42006-06-29 14:57:52 +02002303 printk("%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002305 if (req) {
2306 /* req == NULL for unsolicited interrupts */
2307 /* dump the Channel Program (max 140 Bytes per line) */
2308 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
2309 first = req->cpaddr;
2310 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
2311 to = min(first + 6, last);
2312 len = sprintf(page, KERN_ERR PRINTK_HEADER
2313 " Related CP in req: %p\n", req);
2314 dasd_eckd_dump_ccw_range(first, to, page + len);
Horst Hummel445b5b42006-06-29 14:57:52 +02002315 printk("%s", page);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002316
2317 /* print failing CCW area (maximum 4) */
2318 /* scsw->cda is either valid or zero */
2319 len = 0;
2320 from = ++to;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02002321 fail = (struct ccw1 *)(addr_t)
2322 irb->scsw.cmd.cpa; /* failing CCW */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002323 if (from < fail - 2) {
2324 from = fail - 2; /* there is a gap - print header */
2325 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
2326 }
2327 to = min(fail + 1, last);
2328 len += dasd_eckd_dump_ccw_range(from, to, page + len);
2329
2330 /* print last CCWs (maximum 2) */
2331 from = max(from, ++to);
2332 if (from < last - 1) {
2333 from = last - 1; /* there is a gap - print header */
2334 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
2335 }
2336 len += dasd_eckd_dump_ccw_range(from, last, page + len);
2337 if (len > 0)
2338 printk("%s", page);
2339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 free_page((unsigned long) page);
2341}
2342
2343/*
2344 * max_blocks is dependent on the amount of storage that is available
2345 * in the static io buffer for each device. Currently each device has
2346 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
2347 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
2348 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
2349 * addition we have one define extent ccw + 16 bytes of data and one
2350 * locate record ccw + 16 bytes of data. That makes:
2351 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
2352 * We want to fit two into the available memory so that we can immediately
2353 * start the next request if one finishes off. That makes 249.5 blocks
2354 * for one request. Give a little safety and the result is 240.
2355 */
2356static struct dasd_discipline dasd_eckd_discipline = {
2357 .owner = THIS_MODULE,
2358 .name = "ECKD",
2359 .ebcname = "ECKD",
2360 .max_blocks = 240,
2361 .check_device = dasd_eckd_check_characteristics,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002362 .uncheck_device = dasd_eckd_uncheck_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 .do_analysis = dasd_eckd_do_analysis,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002364 .ready_to_online = dasd_eckd_ready_to_online,
2365 .online_to_ready = dasd_eckd_online_to_ready,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 .fill_geometry = dasd_eckd_fill_geometry,
2367 .start_IO = dasd_start_IO,
2368 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002369 .handle_terminated_request = dasd_eckd_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 .format_device = dasd_eckd_format_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 .erp_action = dasd_eckd_erp_action,
2372 .erp_postaction = dasd_eckd_erp_postaction,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002373 .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
2374 .build_cp = dasd_eckd_build_alias_cp,
2375 .free_cp = dasd_eckd_free_alias_cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 .dump_sense = dasd_eckd_dump_sense,
2377 .fill_info = dasd_eckd_fill_info,
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002378 .ioctl = dasd_eckd_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379};
2380
2381static int __init
2382dasd_eckd_init(void)
2383{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 ASCEBC(dasd_eckd_discipline.ebcname, 4);
Horst Hummel40545572006-06-29 15:08:18 +02002385 return ccw_driver_register(&dasd_eckd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
2388static void __exit
2389dasd_eckd_cleanup(void)
2390{
2391 ccw_driver_unregister(&dasd_eckd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392}
2393
2394module_init(dasd_eckd_init);
2395module_exit(dasd_eckd_cleanup);