blob: 216c09bcd222409fd46fa2f9195e07d078e0ed12 [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
Stefan Haberlandfc19f382009-03-26 15:23:49 +010014#define KMSG_COMPONENT "dasd"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/stddef.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/hdreg.h> /* HDIO_GETGEO */
20#include <linux/bio.h>
21#include <linux/module.h>
22#include <linux/init.h>
23
24#include <asm/debug.h>
25#include <asm/idals.h>
26#include <asm/ebcdic.h>
27#include <asm/io.h>
28#include <asm/todclk.h>
29#include <asm/uaccess.h>
Horst Hummel40545572006-06-29 15:08:18 +020030#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/ccwdev.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010032#include <asm/itcw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include "dasd_int.h"
35#include "dasd_eckd.h"
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010036#include "../cio/chsc.h"
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#ifdef PRINTK_HEADER
40#undef PRINTK_HEADER
41#endif /* PRINTK_HEADER */
42#define PRINTK_HEADER "dasd(eckd):"
43
44#define ECKD_C0(i) (i->home_bytes)
45#define ECKD_F(i) (i->formula)
46#define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
47 (i->factors.f_0x02.f1))
48#define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
49 (i->factors.f_0x02.f2))
50#define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
51 (i->factors.f_0x02.f3))
52#define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
53#define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
54#define ECKD_F6(i) (i->factor6)
55#define ECKD_F7(i) (i->factor7)
56#define ECKD_F8(i) (i->factor8)
57
58MODULE_LICENSE("GPL");
59
60static struct dasd_discipline dasd_eckd_discipline;
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/* The ccw bus type uses this table to find devices that it sends to
63 * dasd_eckd_probe */
64static struct ccw_device_id dasd_eckd_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020065 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
66 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
67 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
68 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
69 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
70 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
71 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
72 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
73 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
74 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 { /* end of list */ },
76};
77
78MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
79
80static struct ccw_driver dasd_eckd_driver; /* see below */
81
82/* initial attempt at a probe function. this can be simplified once
83 * the other detection code is gone */
84static int
85dasd_eckd_probe (struct ccw_device *cdev)
86{
87 int ret;
88
Horst Hummel40545572006-06-29 15:08:18 +020089 /* set ECKD specific ccw-device options */
90 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
91 if (ret) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +010092 DBF_EVENT(DBF_WARNING,
Horst Hummel40545572006-06-29 15:08:18 +020093 "dasd_eckd_probe: could not set ccw-device options "
Kay Sievers2a0217d2008-10-10 21:33:09 +020094 "for %s\n", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return ret;
Horst Hummel40545572006-06-29 15:08:18 +020096 }
97 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
98 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101static int
102dasd_eckd_set_online(struct ccw_device *cdev)
103{
Horst Hummel40545572006-06-29 15:08:18 +0200104 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
107static struct ccw_driver dasd_eckd_driver = {
108 .name = "dasd-eckd",
109 .owner = THIS_MODULE,
110 .ids = dasd_eckd_ids,
111 .probe = dasd_eckd_probe,
112 .remove = dasd_generic_remove,
113 .set_offline = dasd_generic_set_offline,
114 .set_online = dasd_eckd_set_online,
115 .notify = dasd_generic_notify,
116};
117
118static const int sizes_trk0[] = { 28, 148, 84 };
119#define LABEL_SIZE 140
120
121static inline unsigned int
122round_up_multiple(unsigned int no, unsigned int mult)
123{
124 int rem = no % mult;
125 return (rem ? no - rem + mult : no);
126}
127
128static inline unsigned int
129ceil_quot(unsigned int d1, unsigned int d2)
130{
131 return (d1 + (d2 - 1)) / d2;
132}
133
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100134static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135recs_per_track(struct dasd_eckd_characteristics * rdc,
136 unsigned int kl, unsigned int dl)
137{
138 int dn, kn;
139
140 switch (rdc->dev_type) {
141 case 0x3380:
142 if (kl)
143 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
144 ceil_quot(dl + 12, 32));
145 else
146 return 1499 / (15 + ceil_quot(dl + 12, 32));
147 case 0x3390:
148 dn = ceil_quot(dl + 6, 232) + 1;
149 if (kl) {
150 kn = ceil_quot(kl + 6, 232) + 1;
151 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
152 9 + ceil_quot(dl + 6 * dn, 34));
153 } else
154 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
155 case 0x9345:
156 dn = ceil_quot(dl + 6, 232) + 1;
157 if (kl) {
158 kn = ceil_quot(kl + 6, 232) + 1;
159 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
160 ceil_quot(dl + 6 * dn, 34));
161 } else
162 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
163 }
164 return 0;
165}
166
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100167static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
168{
169 geo->cyl = (__u16) cyl;
170 geo->head = cyl >> 16;
171 geo->head <<= 4;
172 geo->head |= head;
173}
174
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100175static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176check_XRC (struct ccw1 *de_ccw,
177 struct DE_eckd_data *data,
178 struct dasd_device *device)
179{
180 struct dasd_eckd_private *private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100181 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 private = (struct dasd_eckd_private *) device->private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100184 if (!private->rdc_data.facilities.XRC_supported)
185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 /* switch on System Time Stamp - needed for XRC Support */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100188 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
189 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
Horst Hummel138c0142006-06-29 14:58:12 +0200190
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100191 rc = get_sync_clock(&data->ep_sys_time);
192 /* Ignore return code if sync clock is switched off. */
193 if (rc == -ENOSYS || rc == -EACCES)
194 rc = 0;
Horst Hummel138c0142006-06-29 14:58:12 +0200195
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100196 de_ccw->count = sizeof(struct DE_eckd_data);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100197 de_ccw->flags |= CCW_FLAG_SLI;
198 return rc;
199}
Horst Hummel138c0142006-06-29 14:58:12 +0200200
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100201static int
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100202define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
203 unsigned int totrk, int cmd, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 struct dasd_eckd_private *private;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100206 u32 begcyl, endcyl;
207 u16 heads, beghead, endhead;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100208 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 private = (struct dasd_eckd_private *) device->private;
211
212 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
213 ccw->flags = 0;
214 ccw->count = 16;
215 ccw->cda = (__u32) __pa(data);
216
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100217 memset(data, 0, sizeof(struct DE_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 switch (cmd) {
219 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
220 case DASD_ECKD_CCW_READ_RECORD_ZERO:
221 case DASD_ECKD_CCW_READ:
222 case DASD_ECKD_CCW_READ_MT:
223 case DASD_ECKD_CCW_READ_CKD:
224 case DASD_ECKD_CCW_READ_CKD_MT:
225 case DASD_ECKD_CCW_READ_KD:
226 case DASD_ECKD_CCW_READ_KD_MT:
227 case DASD_ECKD_CCW_READ_COUNT:
228 data->mask.perm = 0x1;
229 data->attributes.operation = private->attrib.operation;
230 break;
231 case DASD_ECKD_CCW_WRITE:
232 case DASD_ECKD_CCW_WRITE_MT:
233 case DASD_ECKD_CCW_WRITE_KD:
234 case DASD_ECKD_CCW_WRITE_KD_MT:
235 data->mask.perm = 0x02;
236 data->attributes.operation = private->attrib.operation;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100237 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 break;
239 case DASD_ECKD_CCW_WRITE_CKD:
240 case DASD_ECKD_CCW_WRITE_CKD_MT:
241 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100242 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 break;
244 case DASD_ECKD_CCW_ERASE:
245 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
246 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
247 data->mask.perm = 0x3;
248 data->mask.auth = 0x1;
249 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100250 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 break;
252 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100253 dev_err(&device->cdev->dev,
254 "0x%x is not a known command\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 break;
256 }
257
258 data->attributes.mode = 0x3; /* ECKD */
259
260 if ((private->rdc_data.cu_type == 0x2105 ||
261 private->rdc_data.cu_type == 0x2107 ||
262 private->rdc_data.cu_type == 0x1750)
263 && !(private->uses_cdl && trk < 2))
264 data->ga_extended |= 0x40; /* Regular Data Format Mode */
265
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100266 heads = private->rdc_data.trk_per_cyl;
267 begcyl = trk / heads;
268 beghead = trk % heads;
269 endcyl = totrk / heads;
270 endhead = totrk % heads;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 /* check for sequential prestage - enhance cylinder range */
273 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
274 data->attributes.operation == DASD_SEQ_ACCESS) {
Horst Hummel138c0142006-06-29 14:58:12 +0200275
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100276 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
277 endcyl += private->attrib.nr_cyl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100279 endcyl = (private->real_cyl - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100282 set_ch_t(&data->beg_ext, begcyl, beghead);
283 set_ch_t(&data->end_ext, endcyl, endhead);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100284 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100287static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
288 struct dasd_device *device)
289{
290 struct dasd_eckd_private *private;
291 int rc;
292
293 private = (struct dasd_eckd_private *) device->private;
294 if (!private->rdc_data.facilities.XRC_supported)
295 return 0;
296
297 /* switch on System Time Stamp - needed for XRC Support */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100298 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
299 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100300 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
301
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100302 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100303 /* Ignore return code if sync clock is switched off. */
304 if (rc == -ENOSYS || rc == -EACCES)
305 rc = 0;
306 return rc;
307}
308
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100309static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
310 unsigned int rec_on_trk, int count, int cmd,
311 struct dasd_device *device, unsigned int reclen,
312 unsigned int tlf)
313{
314 struct dasd_eckd_private *private;
315 int sector;
316 int dn, d;
317
318 private = (struct dasd_eckd_private *) device->private;
319
320 memset(data, 0, sizeof(*data));
321 sector = 0;
322 if (rec_on_trk) {
323 switch (private->rdc_data.dev_type) {
324 case 0x3390:
325 dn = ceil_quot(reclen + 6, 232);
326 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
327 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
328 break;
329 case 0x3380:
330 d = 7 + ceil_quot(reclen + 12, 32);
331 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
332 break;
333 }
334 }
335 data->sector = sector;
336 /* note: meaning of count depends on the operation
337 * for record based I/O it's the number of records, but for
338 * track based I/O it's the number of tracks
339 */
340 data->count = count;
341 switch (cmd) {
342 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
343 data->operation.orientation = 0x3;
344 data->operation.operation = 0x03;
345 break;
346 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
347 data->operation.orientation = 0x3;
348 data->operation.operation = 0x16;
349 break;
350 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
351 data->operation.orientation = 0x1;
352 data->operation.operation = 0x03;
353 data->count++;
354 break;
355 case DASD_ECKD_CCW_READ_RECORD_ZERO:
356 data->operation.orientation = 0x3;
357 data->operation.operation = 0x16;
358 data->count++;
359 break;
360 case DASD_ECKD_CCW_WRITE:
361 case DASD_ECKD_CCW_WRITE_MT:
362 case DASD_ECKD_CCW_WRITE_KD:
363 case DASD_ECKD_CCW_WRITE_KD_MT:
364 data->auxiliary.length_valid = 0x1;
365 data->length = reclen;
366 data->operation.operation = 0x01;
367 break;
368 case DASD_ECKD_CCW_WRITE_CKD:
369 case DASD_ECKD_CCW_WRITE_CKD_MT:
370 data->auxiliary.length_valid = 0x1;
371 data->length = reclen;
372 data->operation.operation = 0x03;
373 break;
374 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
375 data->auxiliary.length_valid = 0x1;
376 data->length = reclen; /* not tlf, as one might think */
377 data->operation.operation = 0x3F;
378 data->extended_operation = 0x23;
379 break;
380 case DASD_ECKD_CCW_READ:
381 case DASD_ECKD_CCW_READ_MT:
382 case DASD_ECKD_CCW_READ_KD:
383 case DASD_ECKD_CCW_READ_KD_MT:
384 data->auxiliary.length_valid = 0x1;
385 data->length = reclen;
386 data->operation.operation = 0x06;
387 break;
388 case DASD_ECKD_CCW_READ_CKD:
389 case DASD_ECKD_CCW_READ_CKD_MT:
390 data->auxiliary.length_valid = 0x1;
391 data->length = reclen;
392 data->operation.operation = 0x16;
393 break;
394 case DASD_ECKD_CCW_READ_COUNT:
395 data->operation.operation = 0x06;
396 break;
397 case DASD_ECKD_CCW_READ_TRACK_DATA:
398 data->auxiliary.length_valid = 0x1;
399 data->length = tlf;
400 data->operation.operation = 0x0C;
401 break;
402 case DASD_ECKD_CCW_ERASE:
403 data->length = reclen;
404 data->auxiliary.length_valid = 0x1;
405 data->operation.operation = 0x0b;
406 break;
407 default:
408 DBF_DEV_EVENT(DBF_ERR, device,
409 "fill LRE unknown opcode 0x%x", cmd);
410 BUG();
411 }
412 set_ch_t(&data->seek_addr,
413 trk / private->rdc_data.trk_per_cyl,
414 trk % private->rdc_data.trk_per_cyl);
415 data->search_arg.cyl = data->seek_addr.cyl;
416 data->search_arg.head = data->seek_addr.head;
417 data->search_arg.record = rec_on_trk;
418}
419
420static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
421 unsigned int trk, unsigned int totrk, int cmd,
422 struct dasd_device *basedev, struct dasd_device *startdev,
423 unsigned char format, unsigned int rec_on_trk, int count,
424 unsigned int blksize, unsigned int tlf)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100425{
426 struct dasd_eckd_private *basepriv, *startpriv;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100427 struct DE_eckd_data *dedata;
428 struct LRE_eckd_data *lredata;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100429 u32 begcyl, endcyl;
430 u16 heads, beghead, endhead;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100431 int rc = 0;
432
433 basepriv = (struct dasd_eckd_private *) basedev->private;
434 startpriv = (struct dasd_eckd_private *) startdev->private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100435 dedata = &pfxdata->define_extent;
436 lredata = &pfxdata->locate_record;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100437
438 ccw->cmd_code = DASD_ECKD_CCW_PFX;
439 ccw->flags = 0;
440 ccw->count = sizeof(*pfxdata);
441 ccw->cda = (__u32) __pa(pfxdata);
442
443 memset(pfxdata, 0, sizeof(*pfxdata));
444 /* prefix data */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100445 if (format > 1) {
446 DBF_DEV_EVENT(DBF_ERR, basedev,
447 "PFX LRE unknown format 0x%x", format);
448 BUG();
449 return -EINVAL;
450 }
451 pfxdata->format = format;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200452 pfxdata->base_address = basepriv->ned->unit_addr;
453 pfxdata->base_lss = basepriv->ned->ID;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100454 pfxdata->validity.define_extent = 1;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100455
456 /* private uid is kept up to date, conf_data may be outdated */
457 if (startpriv->uid.type != UA_BASE_DEVICE) {
458 pfxdata->validity.verify_base = 1;
459 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
460 pfxdata->validity.hyper_pav = 1;
461 }
462
463 /* define extend data (mostly)*/
464 switch (cmd) {
465 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
466 case DASD_ECKD_CCW_READ_RECORD_ZERO:
467 case DASD_ECKD_CCW_READ:
468 case DASD_ECKD_CCW_READ_MT:
469 case DASD_ECKD_CCW_READ_CKD:
470 case DASD_ECKD_CCW_READ_CKD_MT:
471 case DASD_ECKD_CCW_READ_KD:
472 case DASD_ECKD_CCW_READ_KD_MT:
473 case DASD_ECKD_CCW_READ_COUNT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100474 dedata->mask.perm = 0x1;
475 dedata->attributes.operation = basepriv->attrib.operation;
476 break;
477 case DASD_ECKD_CCW_READ_TRACK_DATA:
478 dedata->mask.perm = 0x1;
479 dedata->attributes.operation = basepriv->attrib.operation;
480 dedata->blk_size = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100481 break;
482 case DASD_ECKD_CCW_WRITE:
483 case DASD_ECKD_CCW_WRITE_MT:
484 case DASD_ECKD_CCW_WRITE_KD:
485 case DASD_ECKD_CCW_WRITE_KD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100486 dedata->mask.perm = 0x02;
487 dedata->attributes.operation = basepriv->attrib.operation;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100488 rc = check_XRC_on_prefix(pfxdata, basedev);
489 break;
490 case DASD_ECKD_CCW_WRITE_CKD:
491 case DASD_ECKD_CCW_WRITE_CKD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100492 dedata->attributes.operation = DASD_BYPASS_CACHE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100493 rc = check_XRC_on_prefix(pfxdata, basedev);
494 break;
495 case DASD_ECKD_CCW_ERASE:
496 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
497 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100498 dedata->mask.perm = 0x3;
499 dedata->mask.auth = 0x1;
500 dedata->attributes.operation = DASD_BYPASS_CACHE;
501 rc = check_XRC_on_prefix(pfxdata, basedev);
502 break;
503 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
504 dedata->mask.perm = 0x02;
505 dedata->attributes.operation = basepriv->attrib.operation;
506 dedata->blk_size = blksize;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100507 rc = check_XRC_on_prefix(pfxdata, basedev);
508 break;
509 default:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100510 DBF_DEV_EVENT(DBF_ERR, basedev,
511 "PFX LRE unknown opcode 0x%x", cmd);
512 BUG();
513 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100514 }
515
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100516 dedata->attributes.mode = 0x3; /* ECKD */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100517
518 if ((basepriv->rdc_data.cu_type == 0x2105 ||
519 basepriv->rdc_data.cu_type == 0x2107 ||
520 basepriv->rdc_data.cu_type == 0x1750)
521 && !(basepriv->uses_cdl && trk < 2))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100522 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100523
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100524 heads = basepriv->rdc_data.trk_per_cyl;
525 begcyl = trk / heads;
526 beghead = trk % heads;
527 endcyl = totrk / heads;
528 endhead = totrk % heads;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100529
530 /* check for sequential prestage - enhance cylinder range */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100531 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
532 dedata->attributes.operation == DASD_SEQ_ACCESS) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100533
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100534 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
535 endcyl += basepriv->attrib.nr_cyl;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100536 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100537 endcyl = (basepriv->real_cyl - 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100538 }
539
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100540 set_ch_t(&dedata->beg_ext, begcyl, beghead);
541 set_ch_t(&dedata->end_ext, endcyl, endhead);
542
543 if (format == 1) {
544 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
545 basedev, blksize, tlf);
546 }
547
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100548 return rc;
549}
550
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100551static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
552 unsigned int trk, unsigned int totrk, int cmd,
553 struct dasd_device *basedev, struct dasd_device *startdev)
554{
555 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
556 0, 0, 0, 0, 0);
557}
558
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100559static void
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100560locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
561 unsigned int rec_on_trk, int no_rec, int cmd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 struct dasd_device * device, int reclen)
563{
564 struct dasd_eckd_private *private;
565 int sector;
566 int dn, d;
Horst Hummel138c0142006-06-29 14:58:12 +0200567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 private = (struct dasd_eckd_private *) device->private;
569
570 DBF_DEV_EVENT(DBF_INFO, device,
571 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
572 trk, rec_on_trk, no_rec, cmd, reclen);
573
574 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
575 ccw->flags = 0;
576 ccw->count = 16;
577 ccw->cda = (__u32) __pa(data);
578
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100579 memset(data, 0, sizeof(struct LO_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 sector = 0;
581 if (rec_on_trk) {
582 switch (private->rdc_data.dev_type) {
583 case 0x3390:
584 dn = ceil_quot(reclen + 6, 232);
585 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
586 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
587 break;
588 case 0x3380:
589 d = 7 + ceil_quot(reclen + 12, 32);
590 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
591 break;
592 }
593 }
594 data->sector = sector;
595 data->count = no_rec;
596 switch (cmd) {
597 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
598 data->operation.orientation = 0x3;
599 data->operation.operation = 0x03;
600 break;
601 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
602 data->operation.orientation = 0x3;
603 data->operation.operation = 0x16;
604 break;
605 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
606 data->operation.orientation = 0x1;
607 data->operation.operation = 0x03;
608 data->count++;
609 break;
610 case DASD_ECKD_CCW_READ_RECORD_ZERO:
611 data->operation.orientation = 0x3;
612 data->operation.operation = 0x16;
613 data->count++;
614 break;
615 case DASD_ECKD_CCW_WRITE:
616 case DASD_ECKD_CCW_WRITE_MT:
617 case DASD_ECKD_CCW_WRITE_KD:
618 case DASD_ECKD_CCW_WRITE_KD_MT:
619 data->auxiliary.last_bytes_used = 0x1;
620 data->length = reclen;
621 data->operation.operation = 0x01;
622 break;
623 case DASD_ECKD_CCW_WRITE_CKD:
624 case DASD_ECKD_CCW_WRITE_CKD_MT:
625 data->auxiliary.last_bytes_used = 0x1;
626 data->length = reclen;
627 data->operation.operation = 0x03;
628 break;
629 case DASD_ECKD_CCW_READ:
630 case DASD_ECKD_CCW_READ_MT:
631 case DASD_ECKD_CCW_READ_KD:
632 case DASD_ECKD_CCW_READ_KD_MT:
633 data->auxiliary.last_bytes_used = 0x1;
634 data->length = reclen;
635 data->operation.operation = 0x06;
636 break;
637 case DASD_ECKD_CCW_READ_CKD:
638 case DASD_ECKD_CCW_READ_CKD_MT:
639 data->auxiliary.last_bytes_used = 0x1;
640 data->length = reclen;
641 data->operation.operation = 0x16;
642 break;
643 case DASD_ECKD_CCW_READ_COUNT:
644 data->operation.operation = 0x06;
645 break;
646 case DASD_ECKD_CCW_ERASE:
647 data->length = reclen;
648 data->auxiliary.last_bytes_used = 0x1;
649 data->operation.operation = 0x0b;
650 break;
651 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100652 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
653 "opcode 0x%x", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100655 set_ch_t(&data->seek_addr,
656 trk / private->rdc_data.trk_per_cyl,
657 trk % private->rdc_data.trk_per_cyl);
658 data->search_arg.cyl = data->seek_addr.cyl;
659 data->search_arg.head = data->seek_addr.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 data->search_arg.record = rec_on_trk;
661}
662
663/*
664 * Returns 1 if the block is one of the special blocks that needs
665 * to get read/written with the KD variant of the command.
666 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
667 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
668 * Luckily the KD variants differ only by one bit (0x08) from the
669 * normal variant. So don't wonder about code like:
670 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
671 * ccw->cmd_code |= 0x8;
672 */
673static inline int
674dasd_eckd_cdl_special(int blk_per_trk, int recid)
675{
676 if (recid < 3)
677 return 1;
678 if (recid < blk_per_trk)
679 return 0;
680 if (recid < 2 * blk_per_trk)
681 return 1;
682 return 0;
683}
684
685/*
686 * Returns the record size for the special blocks of the cdl format.
687 * Only returns something useful if dasd_eckd_cdl_special is true
688 * for the recid.
689 */
690static inline int
691dasd_eckd_cdl_reclen(int recid)
692{
693 if (recid < 3)
694 return sizes_trk0[recid];
695 return LABEL_SIZE;
696}
697
Horst Hummel3d052592006-04-27 18:40:28 -0700698/*
699 * Generate device unique id that specifies the physical device.
700 */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200701static int dasd_eckd_generate_uid(struct dasd_device *device,
702 struct dasd_uid *uid)
Horst Hummel3d052592006-04-27 18:40:28 -0700703{
704 struct dasd_eckd_private *private;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200705 int count;
Horst Hummel3d052592006-04-27 18:40:28 -0700706
707 private = (struct dasd_eckd_private *) device->private;
708 if (!private)
709 return -ENODEV;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200710 if (!private->ned || !private->gneq)
Horst Hummel3d052592006-04-27 18:40:28 -0700711 return -ENODEV;
712
713 memset(uid, 0, sizeof(struct dasd_uid));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200714 memcpy(uid->vendor, private->ned->HDA_manufacturer,
Horst Hummeld0710c72006-08-10 15:45:16 +0200715 sizeof(uid->vendor) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700716 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200717 memcpy(uid->serial, private->ned->HDA_location,
Horst Hummeld0710c72006-08-10 15:45:16 +0200718 sizeof(uid->serial) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700719 EBCASC(uid->serial, sizeof(uid->serial) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200720 uid->ssid = private->gneq->subsystemID;
721 uid->real_unit_addr = private->ned->unit_addr;;
722 if (private->sneq) {
723 uid->type = private->sneq->sua_flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100724 if (uid->type == UA_BASE_PAV_ALIAS)
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200725 uid->base_unit_addr = private->sneq->base_unit_addr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100726 } else {
727 uid->type = UA_BASE_DEVICE;
728 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200729 if (private->vdsneq) {
730 for (count = 0; count < 16; count++) {
731 sprintf(uid->vduit+2*count, "%02x",
732 private->vdsneq->uit[count]);
733 }
734 }
Horst Hummel3d052592006-04-27 18:40:28 -0700735 return 0;
736}
737
Heiko Carstens763968e2007-05-10 15:45:46 +0200738static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
739 void *rcd_buffer,
740 struct ciw *ciw, __u8 lpm)
Cornelia Huck17283b52007-05-04 18:47:51 +0200741{
742 struct dasd_ccw_req *cqr;
743 struct ccw1 *ccw;
744
745 cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
746
747 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100748 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
749 "Could not allocate RCD request");
Cornelia Huck17283b52007-05-04 18:47:51 +0200750 return cqr;
751 }
752
753 ccw = cqr->cpaddr;
754 ccw->cmd_code = ciw->cmd;
755 ccw->cda = (__u32)(addr_t)rcd_buffer;
756 ccw->count = ciw->count;
757
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100758 cqr->startdev = device;
759 cqr->memdev = device;
760 cqr->block = NULL;
Cornelia Huck17283b52007-05-04 18:47:51 +0200761 cqr->expires = 10*HZ;
762 cqr->lpm = lpm;
763 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
764 cqr->retries = 2;
765 cqr->buildclk = get_clock();
766 cqr->status = DASD_CQR_FILLED;
767 return cqr;
768}
769
770static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
771 void **rcd_buffer,
772 int *rcd_buffer_size, __u8 lpm)
773{
774 struct ciw *ciw;
775 char *rcd_buf = NULL;
776 int ret;
777 struct dasd_ccw_req *cqr;
778
779 /*
780 * scan for RCD command in extended SenseID data
781 */
782 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
783 if (!ciw || ciw->cmd == 0) {
784 ret = -EOPNOTSUPP;
785 goto out_error;
786 }
787 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
788 if (!rcd_buf) {
789 ret = -ENOMEM;
790 goto out_error;
791 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200792
793 /*
794 * buffer has to start with EBCDIC "V1.0" to show
795 * support for virtual device SNEQ
796 */
797 rcd_buf[0] = 0xE5;
798 rcd_buf[1] = 0xF1;
799 rcd_buf[2] = 0x4B;
800 rcd_buf[3] = 0xF0;
Cornelia Huck17283b52007-05-04 18:47:51 +0200801 cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
802 if (IS_ERR(cqr)) {
803 ret = PTR_ERR(cqr);
804 goto out_error;
805 }
806 ret = dasd_sleep_on(cqr);
807 /*
808 * on success we update the user input parms
809 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100810 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +0200811 if (ret)
812 goto out_error;
813
814 *rcd_buffer_size = ciw->count;
815 *rcd_buffer = rcd_buf;
816 return 0;
817out_error:
818 kfree(rcd_buf);
819 *rcd_buffer = NULL;
820 *rcd_buffer_size = 0;
821 return ret;
822}
823
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200824static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
825{
826
827 struct dasd_sneq *sneq;
828 int i, count;
829
830 private->ned = NULL;
831 private->sneq = NULL;
832 private->vdsneq = NULL;
833 private->gneq = NULL;
834 count = private->conf_len / sizeof(struct dasd_sneq);
835 sneq = (struct dasd_sneq *)private->conf_data;
836 for (i = 0; i < count; ++i) {
837 if (sneq->flags.identifier == 1 && sneq->format == 1)
838 private->sneq = sneq;
839 else if (sneq->flags.identifier == 1 && sneq->format == 4)
840 private->vdsneq = (struct vd_sneq *)sneq;
841 else if (sneq->flags.identifier == 2)
842 private->gneq = (struct dasd_gneq *)sneq;
843 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
844 private->ned = (struct dasd_ned *)sneq;
845 sneq++;
846 }
847 if (!private->ned || !private->gneq) {
848 private->ned = NULL;
849 private->sneq = NULL;
850 private->vdsneq = NULL;
851 private->gneq = NULL;
852 return -EINVAL;
853 }
854 return 0;
855
856};
857
858static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
859{
860 struct dasd_gneq *gneq;
861 int i, count, found;
862
863 count = conf_len / sizeof(*gneq);
864 gneq = (struct dasd_gneq *)conf_data;
865 found = 0;
866 for (i = 0; i < count; ++i) {
867 if (gneq->flags.identifier == 2) {
868 found = 1;
869 break;
870 }
871 gneq++;
872 }
873 if (found)
874 return ((char *)gneq)[18] & 0x07;
875 else
876 return 0;
877}
878
879static int dasd_eckd_read_conf(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
881 void *conf_data;
882 int conf_len, conf_data_saved;
883 int rc;
884 __u8 lpm;
885 struct dasd_eckd_private *private;
886 struct dasd_eckd_path *path_data;
887
888 private = (struct dasd_eckd_private *) device->private;
889 path_data = (struct dasd_eckd_path *) &private->path_data;
890 path_data->opm = ccw_device_get_path_mask(device->cdev);
891 lpm = 0x80;
892 conf_data_saved = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 /* get configuration data per operational path */
894 for (lpm = 0x80; lpm; lpm>>= 1) {
895 if (lpm & path_data->opm){
Cornelia Huck17283b52007-05-04 18:47:51 +0200896 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
897 &conf_len, lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100899 DBF_EVENT(DBF_WARNING,
900 "Read configuration data returned "
901 "error %d for device: %s", rc,
902 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return rc;
904 }
905 if (conf_data == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100906 DBF_EVENT(DBF_WARNING, "No configuration "
907 "data retrieved for device: %s",
908 dev_name(&device->cdev->dev));
Gabriel Craciunescud133a962007-07-31 00:39:19 -0700909 continue; /* no error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /* save first valid configuration data */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200912 if (!conf_data_saved) {
913 kfree(private->conf_data);
914 private->conf_data = conf_data;
915 private->conf_len = conf_len;
916 if (dasd_eckd_identify_conf_parts(private)) {
917 private->conf_data = NULL;
918 private->conf_len = 0;
919 kfree(conf_data);
920 continue;
921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 conf_data_saved++;
923 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200924 switch (dasd_eckd_path_access(conf_data, conf_len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 case 0x02:
926 path_data->npm |= lpm;
927 break;
928 case 0x03:
929 path_data->ppm |= lpm;
930 break;
931 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200932 if (conf_data != private->conf_data)
933 kfree(conf_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 }
935 }
936 return 0;
937}
938
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100939static int dasd_eckd_read_features(struct dasd_device *device)
940{
941 struct dasd_psf_prssd_data *prssdp;
942 struct dasd_rssd_features *features;
943 struct dasd_ccw_req *cqr;
944 struct ccw1 *ccw;
945 int rc;
946 struct dasd_eckd_private *private;
947
948 private = (struct dasd_eckd_private *) device->private;
949 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
950 1 /* PSF */ + 1 /* RSSD */ ,
951 (sizeof(struct dasd_psf_prssd_data) +
952 sizeof(struct dasd_rssd_features)),
953 device);
954 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100955 DBF_EVENT(DBF_WARNING, "Could not allocate initialization "
956 "request for device: %s",
957 dev_name(&device->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100958 return PTR_ERR(cqr);
959 }
960 cqr->startdev = device;
961 cqr->memdev = device;
962 cqr->block = NULL;
963 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
964 cqr->retries = 5;
965 cqr->expires = 10 * HZ;
966
967 /* Prepare for Read Subsystem Data */
968 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
969 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
970 prssdp->order = PSF_ORDER_PRSSD;
971 prssdp->suborder = 0x41; /* Read Feature Codes */
972 /* all other bytes of prssdp must be zero */
973
974 ccw = cqr->cpaddr;
975 ccw->cmd_code = DASD_ECKD_CCW_PSF;
976 ccw->count = sizeof(struct dasd_psf_prssd_data);
977 ccw->flags |= CCW_FLAG_CC;
978 ccw->cda = (__u32)(addr_t) prssdp;
979
980 /* Read Subsystem Data - feature codes */
981 features = (struct dasd_rssd_features *) (prssdp + 1);
982 memset(features, 0, sizeof(struct dasd_rssd_features));
983
984 ccw++;
985 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
986 ccw->count = sizeof(struct dasd_rssd_features);
987 ccw->cda = (__u32)(addr_t) features;
988
989 cqr->buildclk = get_clock();
990 cqr->status = DASD_CQR_FILLED;
991 rc = dasd_sleep_on(cqr);
992 if (rc == 0) {
993 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
994 features = (struct dasd_rssd_features *) (prssdp + 1);
995 memcpy(&private->features, features,
996 sizeof(struct dasd_rssd_features));
997 }
998 dasd_sfree_request(cqr, cqr->memdev);
999 return rc;
1000}
1001
1002
Horst Hummel3d052592006-04-27 18:40:28 -07001003/*
Horst Hummel40545572006-06-29 15:08:18 +02001004 * Build CP for Perform Subsystem Function - SSC.
1005 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001006static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1007 int enable_pav)
Horst Hummel40545572006-06-29 15:08:18 +02001008{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001009 struct dasd_ccw_req *cqr;
1010 struct dasd_psf_ssc_data *psf_ssc_data;
1011 struct ccw1 *ccw;
Horst Hummel40545572006-06-29 15:08:18 +02001012
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001013 cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
Horst Hummel40545572006-06-29 15:08:18 +02001014 sizeof(struct dasd_psf_ssc_data),
1015 device);
1016
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001017 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001018 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Horst Hummel40545572006-06-29 15:08:18 +02001019 "Could not allocate PSF-SSC request");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001020 return cqr;
1021 }
1022 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1023 psf_ssc_data->order = PSF_ORDER_SSC;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001024 psf_ssc_data->suborder = 0x40;
1025 if (enable_pav) {
1026 psf_ssc_data->suborder |= 0x88;
1027 psf_ssc_data->reserved[0] = 0x88;
1028 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001029 ccw = cqr->cpaddr;
1030 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1031 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1032 ccw->count = 66;
Horst Hummel40545572006-06-29 15:08:18 +02001033
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001034 cqr->startdev = device;
1035 cqr->memdev = device;
1036 cqr->block = NULL;
1037 cqr->expires = 10*HZ;
1038 cqr->buildclk = get_clock();
1039 cqr->status = DASD_CQR_FILLED;
1040 return cqr;
Horst Hummel40545572006-06-29 15:08:18 +02001041}
1042
1043/*
1044 * Perform Subsystem Function.
1045 * It is necessary to trigger CIO for channel revalidation since this
1046 * call might change behaviour of DASD devices.
1047 */
1048static int
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001049dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
Horst Hummel40545572006-06-29 15:08:18 +02001050{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001051 struct dasd_ccw_req *cqr;
1052 int rc;
Horst Hummel40545572006-06-29 15:08:18 +02001053
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001054 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001055 if (IS_ERR(cqr))
1056 return PTR_ERR(cqr);
Horst Hummel40545572006-06-29 15:08:18 +02001057
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001058 rc = dasd_sleep_on(cqr);
1059 if (!rc)
1060 /* trigger CIO to reprobe devices */
1061 css_schedule_reprobe();
1062 dasd_sfree_request(cqr, cqr->memdev);
1063 return rc;
Horst Hummel40545572006-06-29 15:08:18 +02001064}
1065
1066/*
1067 * Valide storage server of current device.
1068 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001069static int dasd_eckd_validate_server(struct dasd_device *device)
Horst Hummel40545572006-06-29 15:08:18 +02001070{
1071 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001072 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001073 int enable_pav;
Horst Hummel40545572006-06-29 15:08:18 +02001074
Horst Hummel40545572006-06-29 15:08:18 +02001075 if (dasd_nopav || MACHINE_IS_VM)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001076 enable_pav = 0;
1077 else
1078 enable_pav = 1;
1079 rc = dasd_eckd_psf_ssc(device, enable_pav);
Horst Hummel8e79a442006-08-24 13:22:36 +02001080 /* may be requested feature is not available on server,
1081 * therefore just report error and go ahead */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001082 private = (struct dasd_eckd_private *) device->private;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001083 DBF_EVENT(DBF_WARNING, "PSF-SSC on storage subsystem %s.%s.%04x "
1084 "returned rc=%d for device: %s",
1085 private->uid.vendor, private->uid.serial,
1086 private->uid.ssid, rc, dev_name(&device->cdev->dev));
Horst Hummel40545572006-06-29 15:08:18 +02001087 /* RE-Read Configuration Data */
1088 return dasd_eckd_read_conf(device);
1089}
1090
1091/*
Horst Hummel3d052592006-04-27 18:40:28 -07001092 * Check device characteristics.
1093 * If the device is accessible using ECKD discipline, the device is enabled.
1094 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095static int
1096dasd_eckd_check_characteristics(struct dasd_device *device)
1097{
1098 struct dasd_eckd_private *private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001099 struct dasd_block *block;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001100 int is_known, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 private = (struct dasd_eckd_private *) device->private;
Sebastian Ott92636b12009-06-12 10:26:37 +02001103 if (!private) {
1104 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1105 if (!private) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001106 dev_warn(&device->cdev->dev,
1107 "Allocating memory for private DASD data "
1108 "failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 return -ENOMEM;
1110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 device->private = (void *) private;
Sebastian Ott92636b12009-06-12 10:26:37 +02001112 } else {
1113 memset(private, 0, sizeof(*private));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
1115 /* Invalidate status of initial analysis. */
1116 private->init_cqr_status = -1;
1117 /* Set default cache operations. */
1118 private->attrib.operation = DASD_NORMAL_CACHE;
1119 private->attrib.nr_cyl = 0;
1120
Horst Hummel40545572006-06-29 15:08:18 +02001121 /* Read Configuration Data */
1122 rc = dasd_eckd_read_conf(device);
1123 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001124 goto out_err1;
Horst Hummel40545572006-06-29 15:08:18 +02001125
1126 /* Generate device unique id and register in devmap */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001127 rc = dasd_eckd_generate_uid(device, &private->uid);
Horst Hummel40545572006-06-29 15:08:18 +02001128 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001129 goto out_err1;
1130 dasd_set_uid(device->cdev, &private->uid);
1131
1132 if (private->uid.type == UA_BASE_DEVICE) {
1133 block = dasd_alloc_block();
1134 if (IS_ERR(block)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001135 DBF_EVENT(DBF_WARNING, "could not allocate dasd "
1136 "block structure for device: %s",
1137 dev_name(&device->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001138 rc = PTR_ERR(block);
1139 goto out_err1;
1140 }
1141 device->block = block;
1142 block->base = device;
1143 }
1144
1145 /* register lcu with alias handling, enable PAV if this is a new lcu */
1146 is_known = dasd_alias_make_device_known_to_lcu(device);
1147 if (is_known < 0) {
1148 rc = is_known;
1149 goto out_err2;
1150 }
1151 if (!is_known) {
1152 /* new lcu found */
1153 rc = dasd_eckd_validate_server(device); /* will switch pav on */
1154 if (rc)
1155 goto out_err3;
1156 }
1157
1158 /* Read Feature Codes */
1159 rc = dasd_eckd_read_features(device);
Horst Hummel40545572006-06-29 15:08:18 +02001160 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001161 goto out_err3;
Horst Hummel40545572006-06-29 15:08:18 +02001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 /* Read Device Characteristics */
Sebastian Ott92636b12009-06-12 10:26:37 +02001164 rc = dasd_generic_read_dev_chars(device, "ECKD", &private->rdc_data,
1165 64);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001166 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001167 DBF_EVENT(DBF_WARNING,
1168 "Read device characteristics failed, rc=%d for "
1169 "device: %s", rc, dev_name(&device->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001170 goto out_err3;
1171 }
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001172 /* find the vaild cylinder size */
1173 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1174 private->rdc_data.long_no_cyl)
1175 private->real_cyl = private->rdc_data.long_no_cyl;
1176 else
1177 private->real_cyl = private->rdc_data.no_cyl;
1178
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001179 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1180 "with %d cylinders, %d heads, %d sectors\n",
1181 private->rdc_data.dev_type,
1182 private->rdc_data.dev_model,
1183 private->rdc_data.cu_type,
1184 private->rdc_data.cu_model.model,
Sebastian Ott92636b12009-06-12 10:26:37 +02001185 private->real_cyl,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001186 private->rdc_data.trk_per_cyl,
1187 private->rdc_data.sec_per_trk);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001188 return 0;
1189
1190out_err3:
1191 dasd_alias_disconnect_device_from_lcu(device);
1192out_err2:
1193 dasd_free_block(device->block);
1194 device->block = NULL;
1195out_err1:
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001196 kfree(private->conf_data);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001197 kfree(device->private);
1198 device->private = NULL;
Horst Hummel3d052592006-04-27 18:40:28 -07001199 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001202static void dasd_eckd_uncheck_device(struct dasd_device *device)
1203{
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001204 struct dasd_eckd_private *private;
1205
1206 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001207 dasd_alias_disconnect_device_from_lcu(device);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001208 private->ned = NULL;
1209 private->sneq = NULL;
1210 private->vdsneq = NULL;
1211 private->gneq = NULL;
1212 private->conf_len = 0;
1213 kfree(private->conf_data);
1214 private->conf_data = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001215}
1216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217static struct dasd_ccw_req *
1218dasd_eckd_analysis_ccw(struct dasd_device *device)
1219{
1220 struct dasd_eckd_private *private;
1221 struct eckd_count *count_data;
1222 struct LO_eckd_data *LO_data;
1223 struct dasd_ccw_req *cqr;
1224 struct ccw1 *ccw;
1225 int cplength, datasize;
1226 int i;
1227
1228 private = (struct dasd_eckd_private *) device->private;
1229
1230 cplength = 8;
1231 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1232 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1233 cplength, datasize, device);
1234 if (IS_ERR(cqr))
1235 return cqr;
1236 ccw = cqr->cpaddr;
1237 /* Define extent for the first 3 tracks. */
1238 define_extent(ccw++, cqr->data, 0, 2,
1239 DASD_ECKD_CCW_READ_COUNT, device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001240 LO_data = cqr->data + sizeof(struct DE_eckd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 /* Locate record for the first 4 records on track 0. */
1242 ccw[-1].flags |= CCW_FLAG_CC;
1243 locate_record(ccw++, LO_data++, 0, 0, 4,
1244 DASD_ECKD_CCW_READ_COUNT, device, 0);
1245
1246 count_data = private->count_area;
1247 for (i = 0; i < 4; i++) {
1248 ccw[-1].flags |= CCW_FLAG_CC;
1249 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1250 ccw->flags = 0;
1251 ccw->count = 8;
1252 ccw->cda = (__u32)(addr_t) count_data;
1253 ccw++;
1254 count_data++;
1255 }
1256
1257 /* Locate record for the first record on track 2. */
1258 ccw[-1].flags |= CCW_FLAG_CC;
1259 locate_record(ccw++, LO_data++, 2, 0, 1,
1260 DASD_ECKD_CCW_READ_COUNT, device, 0);
1261 /* Read count ccw. */
1262 ccw[-1].flags |= CCW_FLAG_CC;
1263 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1264 ccw->flags = 0;
1265 ccw->count = 8;
1266 ccw->cda = (__u32)(addr_t) count_data;
1267
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001268 cqr->block = NULL;
1269 cqr->startdev = device;
1270 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 cqr->retries = 0;
1272 cqr->buildclk = get_clock();
1273 cqr->status = DASD_CQR_FILLED;
1274 return cqr;
1275}
1276
1277/*
1278 * This is the callback function for the init_analysis cqr. It saves
1279 * the status of the initial analysis ccw before it frees it and kicks
1280 * the device to continue the startup sequence. This will call
1281 * dasd_eckd_do_analysis again (if the devices has not been marked
1282 * for deletion in the meantime).
1283 */
1284static void
1285dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
1286{
1287 struct dasd_eckd_private *private;
1288 struct dasd_device *device;
1289
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001290 device = init_cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 private = (struct dasd_eckd_private *) device->private;
1292 private->init_cqr_status = init_cqr->status;
1293 dasd_sfree_request(init_cqr, device);
1294 dasd_kick_device(device);
1295}
1296
1297static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001298dasd_eckd_start_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 struct dasd_eckd_private *private;
1301 struct dasd_ccw_req *init_cqr;
1302
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001303 private = (struct dasd_eckd_private *) block->base->private;
1304 init_cqr = dasd_eckd_analysis_ccw(block->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 if (IS_ERR(init_cqr))
1306 return PTR_ERR(init_cqr);
1307 init_cqr->callback = dasd_eckd_analysis_callback;
1308 init_cqr->callback_data = NULL;
1309 init_cqr->expires = 5*HZ;
1310 dasd_add_request_head(init_cqr);
1311 return -EAGAIN;
1312}
1313
1314static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001315dasd_eckd_end_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001317 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 struct dasd_eckd_private *private;
1319 struct eckd_count *count_area;
1320 unsigned int sb, blk_per_trk;
1321 int status, i;
1322
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001323 device = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 private = (struct dasd_eckd_private *) device->private;
1325 status = private->init_cqr_status;
1326 private->init_cqr_status = -1;
1327 if (status != DASD_CQR_DONE) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001328 dev_warn(&device->cdev->dev,
1329 "The DASD is not formatted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 return -EMEDIUMTYPE;
1331 }
1332
1333 private->uses_cdl = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* Check Track 0 for Compatible Disk Layout */
1335 count_area = NULL;
1336 for (i = 0; i < 3; i++) {
1337 if (private->count_area[i].kl != 4 ||
1338 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1339 private->uses_cdl = 0;
1340 break;
1341 }
1342 }
1343 if (i == 3)
1344 count_area = &private->count_area[4];
1345
1346 if (private->uses_cdl == 0) {
1347 for (i = 0; i < 5; i++) {
1348 if ((private->count_area[i].kl != 0) ||
1349 (private->count_area[i].dl !=
1350 private->count_area[0].dl))
1351 break;
1352 }
1353 if (i == 5)
1354 count_area = &private->count_area[0];
1355 } else {
1356 if (private->count_area[3].record == 1)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001357 dev_warn(&device->cdev->dev,
1358 "Track 0 has no records following the VTOC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360 if (count_area != NULL && count_area->kl == 0) {
1361 /* we found notthing violating our disk layout */
1362 if (dasd_check_blocksize(count_area->dl) == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001363 block->bp_block = count_area->dl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001365 if (block->bp_block == 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001366 dev_warn(&device->cdev->dev,
1367 "The disk layout of the DASD is not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return -EMEDIUMTYPE;
1369 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001370 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1371 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1372 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001374 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001375 block->blocks = (private->real_cyl *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 private->rdc_data.trk_per_cyl *
1377 blk_per_trk);
1378
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001379 dev_info(&device->cdev->dev,
1380 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1381 "%s\n", (block->bp_block >> 10),
1382 ((private->real_cyl *
1383 private->rdc_data.trk_per_cyl *
1384 blk_per_trk * (block->bp_block >> 9)) >> 1),
1385 ((blk_per_trk * block->bp_block) >> 10),
1386 private->uses_cdl ?
1387 "compatible disk layout" : "linux disk layout");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 return 0;
1390}
1391
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001392static int dasd_eckd_do_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 struct dasd_eckd_private *private;
1395
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001396 private = (struct dasd_eckd_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (private->init_cqr_status < 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001398 return dasd_eckd_start_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001400 return dasd_eckd_end_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001403static int dasd_eckd_ready_to_online(struct dasd_device *device)
1404{
1405 return dasd_alias_add_device(device);
1406};
1407
1408static int dasd_eckd_online_to_ready(struct dasd_device *device)
1409{
1410 return dasd_alias_remove_device(device);
1411};
1412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001414dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
1416 struct dasd_eckd_private *private;
1417
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001418 private = (struct dasd_eckd_private *) block->base->private;
1419 if (dasd_check_blocksize(block->bp_block) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 geo->sectors = recs_per_track(&private->rdc_data,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001421 0, block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423 geo->cylinders = private->rdc_data.no_cyl;
1424 geo->heads = private->rdc_data.trk_per_cyl;
1425 return 0;
1426}
1427
1428static struct dasd_ccw_req *
1429dasd_eckd_format_device(struct dasd_device * device,
1430 struct format_data_t * fdata)
1431{
1432 struct dasd_eckd_private *private;
1433 struct dasd_ccw_req *fcp;
1434 struct eckd_count *ect;
1435 struct ccw1 *ccw;
1436 void *data;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001437 int rpt;
1438 struct ch_t address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 int cplength, datasize;
1440 int i;
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001441 int intensity = 0;
1442 int r0_perm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 private = (struct dasd_eckd_private *) device->private;
1445 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001446 set_ch_t(&address,
1447 fdata->start_unit / private->rdc_data.trk_per_cyl,
1448 fdata->start_unit % private->rdc_data.trk_per_cyl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 /* Sanity checks. */
1451 if (fdata->start_unit >=
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001452 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001453 dev_warn(&device->cdev->dev, "Start track number %d used in "
1454 "formatting is too big\n", fdata->start_unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 return ERR_PTR(-EINVAL);
1456 }
1457 if (fdata->start_unit > fdata->stop_unit) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001458 dev_warn(&device->cdev->dev, "Start track %d used in "
1459 "formatting exceeds end track\n", fdata->start_unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 return ERR_PTR(-EINVAL);
1461 }
1462 if (dasd_check_blocksize(fdata->blksize) != 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001463 dev_warn(&device->cdev->dev,
1464 "The DASD cannot be formatted with block size %d\n",
1465 fdata->blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 return ERR_PTR(-EINVAL);
1467 }
1468
1469 /*
1470 * fdata->intensity is a bit string that tells us what to do:
1471 * Bit 0: write record zero
1472 * Bit 1: write home address, currently not supported
1473 * Bit 2: invalidate tracks
1474 * Bit 3: use OS/390 compatible disk layout (cdl)
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001475 * Bit 4: do not allow storage subsystem to modify record zero
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 * Only some bit combinations do make sense.
1477 */
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001478 if (fdata->intensity & 0x10) {
1479 r0_perm = 0;
1480 intensity = fdata->intensity & ~0x10;
1481 } else {
1482 r0_perm = 1;
1483 intensity = fdata->intensity;
1484 }
1485 switch (intensity) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 case 0x00: /* Normal format */
1487 case 0x08: /* Normal format, use cdl. */
1488 cplength = 2 + rpt;
1489 datasize = sizeof(struct DE_eckd_data) +
1490 sizeof(struct LO_eckd_data) +
1491 rpt * sizeof(struct eckd_count);
1492 break;
1493 case 0x01: /* Write record zero and format track. */
1494 case 0x09: /* Write record zero and format track, use cdl. */
1495 cplength = 3 + rpt;
1496 datasize = sizeof(struct DE_eckd_data) +
1497 sizeof(struct LO_eckd_data) +
1498 sizeof(struct eckd_count) +
1499 rpt * sizeof(struct eckd_count);
1500 break;
1501 case 0x04: /* Invalidate track. */
1502 case 0x0c: /* Invalidate track, use cdl. */
1503 cplength = 3;
1504 datasize = sizeof(struct DE_eckd_data) +
1505 sizeof(struct LO_eckd_data) +
1506 sizeof(struct eckd_count);
1507 break;
1508 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001509 dev_warn(&device->cdev->dev, "An I/O control call used "
1510 "incorrect flags 0x%x\n", fdata->intensity);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 return ERR_PTR(-EINVAL);
1512 }
1513 /* Allocate the format ccw request. */
1514 fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
1515 cplength, datasize, device);
1516 if (IS_ERR(fcp))
1517 return fcp;
1518
1519 data = fcp->data;
1520 ccw = fcp->cpaddr;
1521
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001522 switch (intensity & ~0x08) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 case 0x00: /* Normal format. */
1524 define_extent(ccw++, (struct DE_eckd_data *) data,
1525 fdata->start_unit, fdata->start_unit,
1526 DASD_ECKD_CCW_WRITE_CKD, device);
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001527 /* grant subsystem permission to format R0 */
1528 if (r0_perm)
1529 ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 data += sizeof(struct DE_eckd_data);
1531 ccw[-1].flags |= CCW_FLAG_CC;
1532 locate_record(ccw++, (struct LO_eckd_data *) data,
1533 fdata->start_unit, 0, rpt,
1534 DASD_ECKD_CCW_WRITE_CKD, device,
1535 fdata->blksize);
1536 data += sizeof(struct LO_eckd_data);
1537 break;
1538 case 0x01: /* Write record zero + format track. */
1539 define_extent(ccw++, (struct DE_eckd_data *) data,
1540 fdata->start_unit, fdata->start_unit,
1541 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1542 device);
1543 data += sizeof(struct DE_eckd_data);
1544 ccw[-1].flags |= CCW_FLAG_CC;
1545 locate_record(ccw++, (struct LO_eckd_data *) data,
1546 fdata->start_unit, 0, rpt + 1,
1547 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001548 device->block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 data += sizeof(struct LO_eckd_data);
1550 break;
1551 case 0x04: /* Invalidate track. */
1552 define_extent(ccw++, (struct DE_eckd_data *) data,
1553 fdata->start_unit, fdata->start_unit,
1554 DASD_ECKD_CCW_WRITE_CKD, device);
1555 data += sizeof(struct DE_eckd_data);
1556 ccw[-1].flags |= CCW_FLAG_CC;
1557 locate_record(ccw++, (struct LO_eckd_data *) data,
1558 fdata->start_unit, 0, 1,
1559 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1560 data += sizeof(struct LO_eckd_data);
1561 break;
1562 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001563 if (intensity & 0x01) { /* write record zero */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 ect = (struct eckd_count *) data;
1565 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001566 ect->cyl = address.cyl;
1567 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 ect->record = 0;
1569 ect->kl = 0;
1570 ect->dl = 8;
1571 ccw[-1].flags |= CCW_FLAG_CC;
1572 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1573 ccw->flags = CCW_FLAG_SLI;
1574 ccw->count = 8;
1575 ccw->cda = (__u32)(addr_t) ect;
1576 ccw++;
1577 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001578 if ((intensity & ~0x08) & 0x04) { /* erase track */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 ect = (struct eckd_count *) data;
1580 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001581 ect->cyl = address.cyl;
1582 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 ect->record = 1;
1584 ect->kl = 0;
1585 ect->dl = 0;
1586 ccw[-1].flags |= CCW_FLAG_CC;
1587 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1588 ccw->flags = CCW_FLAG_SLI;
1589 ccw->count = 8;
1590 ccw->cda = (__u32)(addr_t) ect;
1591 } else { /* write remaining records */
1592 for (i = 0; i < rpt; i++) {
1593 ect = (struct eckd_count *) data;
1594 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001595 ect->cyl = address.cyl;
1596 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 ect->record = i + 1;
1598 ect->kl = 0;
1599 ect->dl = fdata->blksize;
1600 /* Check for special tracks 0-1 when formatting CDL */
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001601 if ((intensity & 0x08) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 fdata->start_unit == 0) {
1603 if (i < 3) {
1604 ect->kl = 4;
1605 ect->dl = sizes_trk0[i] - 4;
Horst Hummel138c0142006-06-29 14:58:12 +02001606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001608 if ((intensity & 0x08) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 fdata->start_unit == 1) {
1610 ect->kl = 44;
1611 ect->dl = LABEL_SIZE - 44;
1612 }
1613 ccw[-1].flags |= CCW_FLAG_CC;
1614 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1615 ccw->flags = CCW_FLAG_SLI;
1616 ccw->count = 8;
1617 ccw->cda = (__u32)(addr_t) ect;
1618 ccw++;
1619 }
1620 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001621 fcp->startdev = device;
1622 fcp->memdev = device;
1623 clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags);
1624 fcp->retries = 5; /* set retry counter to enable default ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 fcp->buildclk = get_clock();
1626 fcp->status = DASD_CQR_FILLED;
1627 return fcp;
1628}
1629
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001630static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001632 cqr->status = DASD_CQR_FILLED;
1633 if (cqr->block && (cqr->startdev != cqr->block->base)) {
1634 dasd_eckd_reset_ccw_to_base_io(cqr);
1635 cqr->startdev = cqr->block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001637};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639static dasd_erp_fn_t
1640dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1641{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001642 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 struct ccw_device *cdev = device->cdev;
1644
1645 switch (cdev->id.cu_type) {
1646 case 0x3990:
1647 case 0x2105:
1648 case 0x2107:
1649 case 0x1750:
1650 return dasd_3990_erp_action;
1651 case 0x9343:
1652 case 0x3880:
1653 default:
1654 return dasd_default_erp_action;
1655 }
1656}
1657
1658static dasd_erp_fn_t
1659dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1660{
1661 return dasd_default_erp_postaction;
1662}
1663
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001664
1665static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1666 struct irb *irb)
1667{
1668 char mask;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001669 char *sense = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001670
1671 /* first of all check for state change pending interrupt */
1672 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001673 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001674 dasd_generic_handle_state_change(device);
1675 return;
1676 }
1677
1678 /* summary unit check */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001679 if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001680 (irb->ecw[7] == 0x0D)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001681 dasd_alias_handle_summary_unit_check(device, irb);
1682 return;
1683 }
1684
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001685 sense = dasd_get_sense(irb);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001686 /* service information message SIM */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001687 if (sense && !(sense[27] & DASD_SENSE_BIT_0) &&
1688 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
1689 dasd_3990_erp_handle_sim(device, sense);
Stefan Haberland9d853ca2008-07-17 17:16:41 +02001690 dasd_schedule_device_bh(device);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001691 return;
1692 }
1693
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001694 if ((scsw_cc(&irb->scsw) == 1) &&
1695 (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
1696 (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) &&
1697 (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) {
Stefan Haberlandada3df92008-10-10 21:33:23 +02001698 /* fake irb do nothing, they are handled elsewhere */
1699 dasd_schedule_device_bh(device);
1700 return;
1701 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001702
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001703 if (!sense) {
Stefan Haberlandada3df92008-10-10 21:33:23 +02001704 /* just report other unsolicited interrupts */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001705 DBF_DEV_EVENT(DBF_ERR, device, "%s",
Stefan Haberlandada3df92008-10-10 21:33:23 +02001706 "unsolicited interrupt received");
1707 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001708 DBF_DEV_EVENT(DBF_ERR, device, "%s",
Stefan Haberlandada3df92008-10-10 21:33:23 +02001709 "unsolicited interrupt received "
1710 "(sense available)");
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001711 device->discipline->dump_sense_dbf(device, NULL, irb,
1712 "unsolicited");
Stefan Haberlandada3df92008-10-10 21:33:23 +02001713 }
1714
1715 dasd_schedule_device_bh(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001716 return;
1717};
1718
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001719
1720static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
1721 struct dasd_device *startdev,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001722 struct dasd_block *block,
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001723 struct request *req,
1724 sector_t first_rec,
1725 sector_t last_rec,
1726 sector_t first_trk,
1727 sector_t last_trk,
1728 unsigned int first_offs,
1729 unsigned int last_offs,
1730 unsigned int blk_per_trk,
1731 unsigned int blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
1733 struct dasd_eckd_private *private;
1734 unsigned long *idaws;
1735 struct LO_eckd_data *LO_data;
1736 struct dasd_ccw_req *cqr;
1737 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02001738 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 struct bio_vec *bv;
1740 char *dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001741 unsigned int off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 int count, cidaw, cplength, datasize;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001743 sector_t recid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 unsigned char cmd, rcmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001745 int use_prefix;
1746 struct dasd_device *basedev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001748 basedev = block->base;
1749 private = (struct dasd_eckd_private *) basedev->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 if (rq_data_dir(req) == READ)
1751 cmd = DASD_ECKD_CCW_READ_MT;
1752 else if (rq_data_dir(req) == WRITE)
1753 cmd = DASD_ECKD_CCW_WRITE_MT;
1754 else
1755 return ERR_PTR(-EINVAL);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 /* Check struct bio and count the number of blocks for the request. */
1758 count = 0;
1759 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +02001760 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +02001761 if (bv->bv_len & (blksize - 1))
1762 /* Eckd can only do full blocks. */
1763 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001764 count += bv->bv_len >> (block->s2b_shift + 9);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001765#if defined(CONFIG_64BIT)
Jens Axboe6c92e692007-08-16 13:43:12 +02001766 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001767 cidaw += bv->bv_len >> (block->s2b_shift + 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 }
1770 /* Paranoia. */
1771 if (count != last_rec - first_rec + 1)
1772 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001773
1774 /* use the prefix command if available */
1775 use_prefix = private->features.feature[8] & 0x01;
1776 if (use_prefix) {
1777 /* 1x prefix + number of blocks */
1778 cplength = 2 + count;
1779 /* 1x prefix + cidaws*sizeof(long) */
1780 datasize = sizeof(struct PFX_eckd_data) +
1781 sizeof(struct LO_eckd_data) +
1782 cidaw * sizeof(unsigned long);
1783 } else {
1784 /* 1x define extent + 1x locate record + number of blocks */
1785 cplength = 2 + count;
1786 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1787 datasize = sizeof(struct DE_eckd_data) +
1788 sizeof(struct LO_eckd_data) +
1789 cidaw * sizeof(unsigned long);
1790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 /* Find out the number of additional locate record ccws for cdl. */
1792 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1793 if (last_rec >= 2*blk_per_trk)
1794 count = 2*blk_per_trk - first_rec;
1795 cplength += count;
1796 datasize += count*sizeof(struct LO_eckd_data);
1797 }
1798 /* Allocate the ccw request. */
1799 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001800 cplength, datasize, startdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 if (IS_ERR(cqr))
1802 return cqr;
1803 ccw = cqr->cpaddr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001804 /* First ccw is define extent or prefix. */
1805 if (use_prefix) {
1806 if (prefix(ccw++, cqr->data, first_trk,
1807 last_trk, cmd, basedev, startdev) == -EAGAIN) {
1808 /* Clock not in sync and XRC is enabled.
1809 * Try again later.
1810 */
1811 dasd_sfree_request(cqr, startdev);
1812 return ERR_PTR(-EAGAIN);
1813 }
1814 idaws = (unsigned long *) (cqr->data +
1815 sizeof(struct PFX_eckd_data));
1816 } else {
1817 if (define_extent(ccw++, cqr->data, first_trk,
1818 last_trk, cmd, startdev) == -EAGAIN) {
1819 /* Clock not in sync and XRC is enabled.
1820 * Try again later.
1821 */
1822 dasd_sfree_request(cqr, startdev);
1823 return ERR_PTR(-EAGAIN);
1824 }
1825 idaws = (unsigned long *) (cqr->data +
1826 sizeof(struct DE_eckd_data));
Martin Schwidefskyd54853e2007-02-05 21:18:19 +01001827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 /* Build locate_record+read/write/ccws. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1830 recid = first_rec;
1831 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1832 /* Only standard blocks so there is just one locate record. */
1833 ccw[-1].flags |= CCW_FLAG_CC;
1834 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001835 last_rec - recid + 1, cmd, basedev, blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 }
NeilBrown5705f702007-09-25 12:35:59 +02001837 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 dst = page_address(bv->bv_page) + bv->bv_offset;
1839 if (dasd_page_cache) {
1840 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -08001841 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 if (copy && rq_data_dir(req) == WRITE)
1843 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1844 if (copy)
1845 dst = copy + bv->bv_offset;
1846 }
1847 for (off = 0; off < bv->bv_len; off += blksize) {
1848 sector_t trkid = recid;
1849 unsigned int recoffs = sector_div(trkid, blk_per_trk);
1850 rcmd = cmd;
1851 count = blksize;
1852 /* Locate record for cdl special block ? */
1853 if (private->uses_cdl && recid < 2*blk_per_trk) {
1854 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1855 rcmd |= 0x8;
1856 count = dasd_eckd_cdl_reclen(recid);
Horst Hummelec5883a2005-05-01 08:58:59 -07001857 if (count < blksize &&
1858 rq_data_dir(req) == READ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 memset(dst + count, 0xe5,
1860 blksize - count);
1861 }
1862 ccw[-1].flags |= CCW_FLAG_CC;
1863 locate_record(ccw++, LO_data++,
1864 trkid, recoffs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001865 1, rcmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
1867 /* Locate record for standard blocks ? */
1868 if (private->uses_cdl && recid == 2*blk_per_trk) {
1869 ccw[-1].flags |= CCW_FLAG_CC;
1870 locate_record(ccw++, LO_data++,
1871 trkid, recoffs + 1,
1872 last_rec - recid + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001873 cmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
1875 /* Read/write ccw. */
1876 ccw[-1].flags |= CCW_FLAG_CC;
1877 ccw->cmd_code = rcmd;
1878 ccw->count = count;
1879 if (idal_is_needed(dst, blksize)) {
1880 ccw->cda = (__u32)(addr_t) idaws;
1881 ccw->flags = CCW_FLAG_IDA;
1882 idaws = idal_create_words(idaws, dst, blksize);
1883 } else {
1884 ccw->cda = (__u32)(addr_t) dst;
1885 ccw->flags = 0;
1886 }
1887 ccw++;
1888 dst += blksize;
1889 recid++;
1890 }
1891 }
Holger Smolinski13de2272009-01-09 12:14:51 +01001892 if (blk_noretry_request(req) ||
1893 block->base->features & DASD_FEATURE_FAILFAST)
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001894 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001895 cqr->startdev = startdev;
1896 cqr->memdev = startdev;
1897 cqr->block = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
1899 cqr->lpm = private->path_data.ppm;
1900 cqr->retries = 256;
1901 cqr->buildclk = get_clock();
1902 cqr->status = DASD_CQR_FILLED;
1903 return cqr;
1904}
1905
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001906static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
1907 struct dasd_device *startdev,
1908 struct dasd_block *block,
1909 struct request *req,
1910 sector_t first_rec,
1911 sector_t last_rec,
1912 sector_t first_trk,
1913 sector_t last_trk,
1914 unsigned int first_offs,
1915 unsigned int last_offs,
1916 unsigned int blk_per_trk,
1917 unsigned int blksize)
1918{
1919 struct dasd_eckd_private *private;
1920 unsigned long *idaws;
1921 struct dasd_ccw_req *cqr;
1922 struct ccw1 *ccw;
1923 struct req_iterator iter;
1924 struct bio_vec *bv;
1925 char *dst, *idaw_dst;
1926 unsigned int cidaw, cplength, datasize;
1927 unsigned int tlf;
1928 sector_t recid;
1929 unsigned char cmd;
1930 struct dasd_device *basedev;
1931 unsigned int trkcount, count, count_to_trk_end;
1932 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
1933 unsigned char new_track, end_idaw;
1934 sector_t trkid;
1935 unsigned int recoffs;
1936
1937 basedev = block->base;
1938 private = (struct dasd_eckd_private *) basedev->private;
1939 if (rq_data_dir(req) == READ)
1940 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
1941 else if (rq_data_dir(req) == WRITE)
1942 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
1943 else
1944 return ERR_PTR(-EINVAL);
1945
1946 /* Track based I/O needs IDAWs for each page, and not just for
1947 * 64 bit addresses. We need additional idals for pages
1948 * that get filled from two tracks, so we use the number
1949 * of records as upper limit.
1950 */
1951 cidaw = last_rec - first_rec + 1;
1952 trkcount = last_trk - first_trk + 1;
1953
1954 /* 1x prefix + one read/write ccw per track */
1955 cplength = 1 + trkcount;
1956
1957 /* on 31-bit we need space for two 32 bit addresses per page
1958 * on 64-bit one 64 bit address
1959 */
1960 datasize = sizeof(struct PFX_eckd_data) +
1961 cidaw * sizeof(unsigned long long);
1962
1963 /* Allocate the ccw request. */
1964 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1965 cplength, datasize, startdev);
1966 if (IS_ERR(cqr))
1967 return cqr;
1968 ccw = cqr->cpaddr;
1969 /* transfer length factor: how many bytes to read from the last track */
1970 if (first_trk == last_trk)
1971 tlf = last_offs - first_offs + 1;
1972 else
1973 tlf = last_offs + 1;
1974 tlf *= blksize;
1975
1976 if (prefix_LRE(ccw++, cqr->data, first_trk,
1977 last_trk, cmd, basedev, startdev,
1978 1 /* format */, first_offs + 1,
1979 trkcount, blksize,
1980 tlf) == -EAGAIN) {
1981 /* Clock not in sync and XRC is enabled.
1982 * Try again later.
1983 */
1984 dasd_sfree_request(cqr, startdev);
1985 return ERR_PTR(-EAGAIN);
1986 }
1987
1988 /*
1989 * The translation of request into ccw programs must meet the
1990 * following conditions:
1991 * - all idaws but the first and the last must address full pages
1992 * (or 2K blocks on 31-bit)
1993 * - the scope of a ccw and it's idal ends with the track boundaries
1994 */
1995 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
1996 recid = first_rec;
1997 new_track = 1;
1998 end_idaw = 0;
1999 len_to_track_end = 0;
2000 idaw_dst = 0;
2001 idaw_len = 0;
2002 rq_for_each_segment(bv, req, iter) {
2003 dst = page_address(bv->bv_page) + bv->bv_offset;
2004 seg_len = bv->bv_len;
2005 while (seg_len) {
2006 if (new_track) {
2007 trkid = recid;
2008 recoffs = sector_div(trkid, blk_per_trk);
2009 count_to_trk_end = blk_per_trk - recoffs;
2010 count = min((last_rec - recid + 1),
2011 (sector_t)count_to_trk_end);
2012 len_to_track_end = count * blksize;
2013 ccw[-1].flags |= CCW_FLAG_CC;
2014 ccw->cmd_code = cmd;
2015 ccw->count = len_to_track_end;
2016 ccw->cda = (__u32)(addr_t)idaws;
2017 ccw->flags = CCW_FLAG_IDA;
2018 ccw++;
2019 recid += count;
2020 new_track = 0;
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002021 /* first idaw for a ccw may start anywhere */
2022 if (!idaw_dst)
2023 idaw_dst = dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002024 }
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002025 /* If we start a new idaw, we must make sure that it
2026 * starts on an IDA_BLOCK_SIZE boundary.
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002027 * If we continue an idaw, we must make sure that the
2028 * current segment begins where the so far accumulated
2029 * idaw ends
2030 */
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002031 if (!idaw_dst) {
2032 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2033 dasd_sfree_request(cqr, startdev);
2034 return ERR_PTR(-ERANGE);
2035 } else
2036 idaw_dst = dst;
2037 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002038 if ((idaw_dst + idaw_len) != dst) {
2039 dasd_sfree_request(cqr, startdev);
2040 return ERR_PTR(-ERANGE);
2041 }
2042 part_len = min(seg_len, len_to_track_end);
2043 seg_len -= part_len;
2044 dst += part_len;
2045 idaw_len += part_len;
2046 len_to_track_end -= part_len;
2047 /* collected memory area ends on an IDA_BLOCK border,
2048 * -> create an idaw
2049 * idal_create_words will handle cases where idaw_len
2050 * is larger then IDA_BLOCK_SIZE
2051 */
2052 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2053 end_idaw = 1;
2054 /* We also need to end the idaw at track end */
2055 if (!len_to_track_end) {
2056 new_track = 1;
2057 end_idaw = 1;
2058 }
2059 if (end_idaw) {
2060 idaws = idal_create_words(idaws, idaw_dst,
2061 idaw_len);
2062 idaw_dst = 0;
2063 idaw_len = 0;
2064 end_idaw = 0;
2065 }
2066 }
2067 }
2068
2069 if (blk_noretry_request(req) ||
2070 block->base->features & DASD_FEATURE_FAILFAST)
2071 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2072 cqr->startdev = startdev;
2073 cqr->memdev = startdev;
2074 cqr->block = block;
2075 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2076 cqr->lpm = private->path_data.ppm;
2077 cqr->retries = 256;
2078 cqr->buildclk = get_clock();
2079 cqr->status = DASD_CQR_FILLED;
2080 return cqr;
2081}
2082
2083static int prepare_itcw(struct itcw *itcw,
2084 unsigned int trk, unsigned int totrk, int cmd,
2085 struct dasd_device *basedev,
2086 struct dasd_device *startdev,
2087 unsigned int rec_on_trk, int count,
2088 unsigned int blksize,
2089 unsigned int total_data_size,
2090 unsigned int tlf,
2091 unsigned int blk_per_trk)
2092{
2093 struct PFX_eckd_data pfxdata;
2094 struct dasd_eckd_private *basepriv, *startpriv;
2095 struct DE_eckd_data *dedata;
2096 struct LRE_eckd_data *lredata;
2097 struct dcw *dcw;
2098
2099 u32 begcyl, endcyl;
2100 u16 heads, beghead, endhead;
2101 u8 pfx_cmd;
2102
2103 int rc = 0;
2104 int sector = 0;
2105 int dn, d;
2106
2107
2108 /* setup prefix data */
2109 basepriv = (struct dasd_eckd_private *) basedev->private;
2110 startpriv = (struct dasd_eckd_private *) startdev->private;
2111 dedata = &pfxdata.define_extent;
2112 lredata = &pfxdata.locate_record;
2113
2114 memset(&pfxdata, 0, sizeof(pfxdata));
2115 pfxdata.format = 1; /* PFX with LRE */
2116 pfxdata.base_address = basepriv->ned->unit_addr;
2117 pfxdata.base_lss = basepriv->ned->ID;
2118 pfxdata.validity.define_extent = 1;
2119
2120 /* private uid is kept up to date, conf_data may be outdated */
2121 if (startpriv->uid.type != UA_BASE_DEVICE) {
2122 pfxdata.validity.verify_base = 1;
2123 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2124 pfxdata.validity.hyper_pav = 1;
2125 }
2126
2127 switch (cmd) {
2128 case DASD_ECKD_CCW_READ_TRACK_DATA:
2129 dedata->mask.perm = 0x1;
2130 dedata->attributes.operation = basepriv->attrib.operation;
2131 dedata->blk_size = blksize;
2132 dedata->ga_extended |= 0x42;
2133 lredata->operation.orientation = 0x0;
2134 lredata->operation.operation = 0x0C;
2135 lredata->auxiliary.check_bytes = 0x01;
2136 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2137 break;
2138 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2139 dedata->mask.perm = 0x02;
2140 dedata->attributes.operation = basepriv->attrib.operation;
2141 dedata->blk_size = blksize;
2142 rc = check_XRC_on_prefix(&pfxdata, basedev);
2143 dedata->ga_extended |= 0x42;
2144 lredata->operation.orientation = 0x0;
2145 lredata->operation.operation = 0x3F;
2146 lredata->extended_operation = 0x23;
2147 lredata->auxiliary.check_bytes = 0x2;
2148 pfx_cmd = DASD_ECKD_CCW_PFX;
2149 break;
2150 default:
2151 DBF_DEV_EVENT(DBF_ERR, basedev,
2152 "prepare itcw, unknown opcode 0x%x", cmd);
2153 BUG();
2154 break;
2155 }
2156 if (rc)
2157 return rc;
2158
2159 dedata->attributes.mode = 0x3; /* ECKD */
2160
2161 heads = basepriv->rdc_data.trk_per_cyl;
2162 begcyl = trk / heads;
2163 beghead = trk % heads;
2164 endcyl = totrk / heads;
2165 endhead = totrk % heads;
2166
2167 /* check for sequential prestage - enhance cylinder range */
2168 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2169 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2170
2171 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2172 endcyl += basepriv->attrib.nr_cyl;
2173 else
2174 endcyl = (basepriv->real_cyl - 1);
2175 }
2176
2177 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2178 set_ch_t(&dedata->end_ext, endcyl, endhead);
2179
2180 dedata->ep_format = 0x20; /* records per track is valid */
2181 dedata->ep_rec_per_track = blk_per_trk;
2182
2183 if (rec_on_trk) {
2184 switch (basepriv->rdc_data.dev_type) {
2185 case 0x3390:
2186 dn = ceil_quot(blksize + 6, 232);
2187 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2188 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2189 break;
2190 case 0x3380:
2191 d = 7 + ceil_quot(blksize + 12, 32);
2192 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2193 break;
2194 }
2195 }
2196
2197 lredata->auxiliary.length_valid = 1;
2198 lredata->auxiliary.length_scope = 1;
2199 lredata->auxiliary.imbedded_ccw_valid = 1;
2200 lredata->length = tlf;
2201 lredata->imbedded_ccw = cmd;
2202 lredata->count = count;
2203 lredata->sector = sector;
2204 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2205 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2206 lredata->search_arg.head = lredata->seek_addr.head;
2207 lredata->search_arg.record = rec_on_trk;
2208
2209 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2210 &pfxdata, sizeof(pfxdata), total_data_size);
2211
2212 return rc;
2213}
2214
2215static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2216 struct dasd_device *startdev,
2217 struct dasd_block *block,
2218 struct request *req,
2219 sector_t first_rec,
2220 sector_t last_rec,
2221 sector_t first_trk,
2222 sector_t last_trk,
2223 unsigned int first_offs,
2224 unsigned int last_offs,
2225 unsigned int blk_per_trk,
2226 unsigned int blksize)
2227{
2228 struct dasd_eckd_private *private;
2229 struct dasd_ccw_req *cqr;
2230 struct req_iterator iter;
2231 struct bio_vec *bv;
2232 char *dst;
2233 unsigned int trkcount, ctidaw;
2234 unsigned char cmd;
2235 struct dasd_device *basedev;
2236 unsigned int tlf;
2237 struct itcw *itcw;
2238 struct tidaw *last_tidaw = NULL;
2239 int itcw_op;
2240 size_t itcw_size;
2241
2242 basedev = block->base;
2243 private = (struct dasd_eckd_private *) basedev->private;
2244 if (rq_data_dir(req) == READ) {
2245 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2246 itcw_op = ITCW_OP_READ;
2247 } else if (rq_data_dir(req) == WRITE) {
2248 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2249 itcw_op = ITCW_OP_WRITE;
2250 } else
2251 return ERR_PTR(-EINVAL);
2252
2253 /* trackbased I/O needs address all memory via TIDAWs,
2254 * not just for 64 bit addresses. This allows us to map
2255 * each segment directly to one tidaw.
2256 */
2257 trkcount = last_trk - first_trk + 1;
2258 ctidaw = 0;
2259 rq_for_each_segment(bv, req, iter) {
2260 ++ctidaw;
2261 }
2262
2263 /* Allocate the ccw request. */
2264 itcw_size = itcw_calc_size(0, ctidaw, 0);
2265 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2266 0, itcw_size, startdev);
2267 if (IS_ERR(cqr))
2268 return cqr;
2269
2270 cqr->cpmode = 1;
2271 cqr->startdev = startdev;
2272 cqr->memdev = startdev;
2273 cqr->block = block;
2274 cqr->expires = 100*HZ;
2275 cqr->buildclk = get_clock();
2276 cqr->status = DASD_CQR_FILLED;
2277 cqr->retries = 10;
2278
2279 /* transfer length factor: how many bytes to read from the last track */
2280 if (first_trk == last_trk)
2281 tlf = last_offs - first_offs + 1;
2282 else
2283 tlf = last_offs + 1;
2284 tlf *= blksize;
2285
2286 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2287 cqr->cpaddr = itcw_get_tcw(itcw);
2288
2289 if (prepare_itcw(itcw, first_trk, last_trk,
2290 cmd, basedev, startdev,
2291 first_offs + 1,
2292 trkcount, blksize,
2293 (last_rec - first_rec + 1) * blksize,
2294 tlf, blk_per_trk) == -EAGAIN) {
2295 /* Clock not in sync and XRC is enabled.
2296 * Try again later.
2297 */
2298 dasd_sfree_request(cqr, startdev);
2299 return ERR_PTR(-EAGAIN);
2300 }
2301
2302 /*
2303 * A tidaw can address 4k of memory, but must not cross page boundaries
2304 * We can let the block layer handle this by setting
2305 * blk_queue_segment_boundary to page boundaries and
2306 * blk_max_segment_size to page size when setting up the request queue.
2307 */
2308 rq_for_each_segment(bv, req, iter) {
2309 dst = page_address(bv->bv_page) + bv->bv_offset;
2310 last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len);
2311 if (IS_ERR(last_tidaw))
2312 return (struct dasd_ccw_req *)last_tidaw;
2313 }
2314
2315 last_tidaw->flags |= 0x80;
2316 itcw_finalize(itcw);
2317
2318 if (blk_noretry_request(req) ||
2319 block->base->features & DASD_FEATURE_FAILFAST)
2320 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2321 cqr->startdev = startdev;
2322 cqr->memdev = startdev;
2323 cqr->block = block;
2324 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2325 cqr->lpm = private->path_data.ppm;
2326 cqr->retries = 256;
2327 cqr->buildclk = get_clock();
2328 cqr->status = DASD_CQR_FILLED;
2329 return cqr;
2330}
2331
2332static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2333 struct dasd_block *block,
2334 struct request *req)
2335{
2336 int tpm, cmdrtd, cmdwtd;
2337 int use_prefix;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002338#if defined(CONFIG_64BIT)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002339 int fcx_in_css, fcx_in_gneq, fcx_in_features;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002340#endif
2341 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002342 struct dasd_device *basedev;
2343 sector_t first_rec, last_rec;
2344 sector_t first_trk, last_trk;
2345 unsigned int first_offs, last_offs;
2346 unsigned int blk_per_trk, blksize;
2347 int cdlspecial;
2348 struct dasd_ccw_req *cqr;
2349
2350 basedev = block->base;
2351 private = (struct dasd_eckd_private *) basedev->private;
2352
2353 /* Calculate number of blocks/records per track. */
2354 blksize = block->bp_block;
2355 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2356 /* Calculate record id of first and last block. */
Tejun Heo83096eb2009-05-07 22:24:39 +09002357 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002358 first_offs = sector_div(first_trk, blk_per_trk);
2359 last_rec = last_trk =
Tejun Heo83096eb2009-05-07 22:24:39 +09002360 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002361 last_offs = sector_div(last_trk, blk_per_trk);
2362 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2363
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002364 /* is transport mode supported? */
2365#if defined(CONFIG_64BIT)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002366 fcx_in_css = css_general_characteristics.fcx;
2367 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
2368 fcx_in_features = private->features.feature[40] & 0x80;
2369 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002370#else
2371 tpm = 0;
2372#endif
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002373
2374 /* is read track data and write track data in command mode supported? */
2375 cmdrtd = private->features.feature[9] & 0x20;
2376 cmdwtd = private->features.feature[12] & 0x40;
2377 use_prefix = private->features.feature[8] & 0x01;
2378
2379 cqr = NULL;
2380 if (cdlspecial || dasd_page_cache) {
2381 /* do nothing, just fall through to the cmd mode single case */
2382 } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) {
2383 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2384 first_rec, last_rec,
2385 first_trk, last_trk,
2386 first_offs, last_offs,
2387 blk_per_trk, blksize);
2388 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2389 cqr = NULL;
2390 } else if (use_prefix &&
2391 (((rq_data_dir(req) == READ) && cmdrtd) ||
2392 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
2393 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2394 first_rec, last_rec,
2395 first_trk, last_trk,
2396 first_offs, last_offs,
2397 blk_per_trk, blksize);
2398 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2399 cqr = NULL;
2400 }
2401 if (!cqr)
2402 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2403 first_rec, last_rec,
2404 first_trk, last_trk,
2405 first_offs, last_offs,
2406 blk_per_trk, blksize);
2407 return cqr;
2408}
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410static int
2411dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2412{
2413 struct dasd_eckd_private *private;
2414 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02002415 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 struct bio_vec *bv;
2417 char *dst, *cda;
2418 unsigned int blksize, blk_per_trk, off;
2419 sector_t recid;
NeilBrown5705f702007-09-25 12:35:59 +02002420 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
2422 if (!dasd_page_cache)
2423 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002424 private = (struct dasd_eckd_private *) cqr->block->base->private;
2425 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Tejun Heo83096eb2009-05-07 22:24:39 +09002427 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 ccw = cqr->cpaddr;
2429 /* Skip over define extent & locate record. */
2430 ccw++;
2431 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2432 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +02002433 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 dst = page_address(bv->bv_page) + bv->bv_offset;
2435 for (off = 0; off < bv->bv_len; off += blksize) {
2436 /* Skip locate record. */
2437 if (private->uses_cdl && recid <= 2*blk_per_trk)
2438 ccw++;
2439 if (dst) {
2440 if (ccw->flags & CCW_FLAG_IDA)
2441 cda = *((char **)((addr_t) ccw->cda));
2442 else
2443 cda = (char *)((addr_t) ccw->cda);
2444 if (dst != cda) {
2445 if (rq_data_dir(req) == READ)
2446 memcpy(dst, cda, bv->bv_len);
2447 kmem_cache_free(dasd_page_cache,
2448 (void *)((addr_t)cda & PAGE_MASK));
2449 }
2450 dst = NULL;
2451 }
2452 ccw++;
2453 recid++;
2454 }
2455 }
2456out:
2457 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002458 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 return status;
2460}
2461
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002462/*
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002463 * Modify ccw/tcw in cqr so it can be started on a base device.
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002464 *
2465 * Note that this is not enough to restart the cqr!
2466 * Either reset cqr->startdev as well (summary unit check handling)
2467 * or restart via separate cqr (as in ERP handling).
2468 */
2469void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
2470{
2471 struct ccw1 *ccw;
2472 struct PFX_eckd_data *pfxdata;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002473 struct tcw *tcw;
2474 struct tccb *tccb;
2475 struct dcw *dcw;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002476
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002477 if (cqr->cpmode == 1) {
2478 tcw = cqr->cpaddr;
2479 tccb = tcw_get_tccb(tcw);
2480 dcw = (struct dcw *)&tccb->tca[0];
2481 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002482 pfxdata->validity.verify_base = 0;
2483 pfxdata->validity.hyper_pav = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002484 } else {
2485 ccw = cqr->cpaddr;
2486 pfxdata = cqr->data;
2487 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
2488 pfxdata->validity.verify_base = 0;
2489 pfxdata->validity.hyper_pav = 0;
2490 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002491 }
2492}
2493
2494#define DASD_ECKD_CHANQ_MAX_SIZE 4
2495
2496static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
2497 struct dasd_block *block,
2498 struct request *req)
2499{
2500 struct dasd_eckd_private *private;
2501 struct dasd_device *startdev;
2502 unsigned long flags;
2503 struct dasd_ccw_req *cqr;
2504
2505 startdev = dasd_alias_get_start_dev(base);
2506 if (!startdev)
2507 startdev = base;
2508 private = (struct dasd_eckd_private *) startdev->private;
2509 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
2510 return ERR_PTR(-EBUSY);
2511
2512 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
2513 private->count++;
2514 cqr = dasd_eckd_build_cp(startdev, block, req);
2515 if (IS_ERR(cqr))
2516 private->count--;
2517 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
2518 return cqr;
2519}
2520
2521static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
2522 struct request *req)
2523{
2524 struct dasd_eckd_private *private;
2525 unsigned long flags;
2526
2527 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
2528 private = (struct dasd_eckd_private *) cqr->memdev->private;
2529 private->count--;
2530 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
2531 return dasd_eckd_free_cp(cqr, req);
2532}
2533
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534static int
2535dasd_eckd_fill_info(struct dasd_device * device,
2536 struct dasd_information2_t * info)
2537{
2538 struct dasd_eckd_private *private;
2539
2540 private = (struct dasd_eckd_private *) device->private;
2541 info->label_block = 2;
2542 info->FBA_layout = private->uses_cdl ? 0 : 1;
2543 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
2544 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
2545 memcpy(info->characteristics, &private->rdc_data,
2546 sizeof(struct dasd_eckd_characteristics));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02002547 info->confdata_size = min((unsigned long)private->conf_len,
2548 sizeof(info->configuration_data));
2549 memcpy(info->configuration_data, private->conf_data,
2550 info->confdata_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 return 0;
2552}
2553
2554/*
2555 * SECTION: ioctl functions for eckd devices.
2556 */
2557
2558/*
2559 * Release device ioctl.
Horst Hummel138c0142006-06-29 14:58:12 +02002560 * Buils a channel programm to releases a prior reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 * (see dasd_eckd_reserve) device.
2562 */
2563static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002564dasd_eckd_release(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 struct dasd_ccw_req *cqr;
2567 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002568 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
2570 if (!capable(CAP_SYS_ADMIN))
2571 return -EACCES;
2572
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2574 1, 32, device);
2575 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002576 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 "Could not allocate initialization request");
2578 return PTR_ERR(cqr);
2579 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002580 ccw = cqr->cpaddr;
2581 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
2582 ccw->flags |= CCW_FLAG_SLI;
2583 ccw->count = 32;
2584 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002585 cqr->startdev = device;
2586 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002588 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002589 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 cqr->expires = 2 * HZ;
2591 cqr->buildclk = get_clock();
2592 cqr->status = DASD_CQR_FILLED;
2593
2594 rc = dasd_sleep_on_immediatly(cqr);
2595
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002596 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 return rc;
2598}
2599
2600/*
2601 * Reserve device ioctl.
2602 * Options are set to 'synchronous wait for interrupt' and
Horst Hummel138c0142006-06-29 14:58:12 +02002603 * 'timeout the request'. This leads to a terminate IO if
2604 * the interrupt is outstanding for a certain time.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 */
2606static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002607dasd_eckd_reserve(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 struct dasd_ccw_req *cqr;
2610 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002611 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 if (!capable(CAP_SYS_ADMIN))
2614 return -EACCES;
2615
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2617 1, 32, device);
2618 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002619 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 "Could not allocate initialization request");
2621 return PTR_ERR(cqr);
2622 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002623 ccw = cqr->cpaddr;
2624 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
2625 ccw->flags |= CCW_FLAG_SLI;
2626 ccw->count = 32;
2627 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002628 cqr->startdev = device;
2629 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002631 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002632 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 cqr->expires = 2 * HZ;
2634 cqr->buildclk = get_clock();
2635 cqr->status = DASD_CQR_FILLED;
2636
2637 rc = dasd_sleep_on_immediatly(cqr);
2638
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002639 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 return rc;
2641}
2642
2643/*
2644 * Steal lock ioctl - unconditional reserve device.
Horst Hummel138c0142006-06-29 14:58:12 +02002645 * Buils a channel programm to break a device's reservation.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 * (unconditional reserve)
2647 */
2648static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002649dasd_eckd_steal_lock(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct dasd_ccw_req *cqr;
2652 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002653 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 if (!capable(CAP_SYS_ADMIN))
2656 return -EACCES;
2657
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2659 1, 32, device);
2660 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002661 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 "Could not allocate initialization request");
2663 return PTR_ERR(cqr);
2664 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002665 ccw = cqr->cpaddr;
2666 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
2667 ccw->flags |= CCW_FLAG_SLI;
2668 ccw->count = 32;
2669 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002670 cqr->startdev = device;
2671 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002673 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002674 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 cqr->expires = 2 * HZ;
2676 cqr->buildclk = get_clock();
2677 cqr->status = DASD_CQR_FILLED;
2678
2679 rc = dasd_sleep_on_immediatly(cqr);
2680
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002681 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 return rc;
2683}
2684
2685/*
2686 * Read performance statistics
2687 */
2688static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002689dasd_eckd_performance(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 struct dasd_psf_prssd_data *prssdp;
2692 struct dasd_rssd_perf_stats_t *stats;
2693 struct dasd_ccw_req *cqr;
2694 struct ccw1 *ccw;
2695 int rc;
2696
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2698 1 /* PSF */ + 1 /* RSSD */ ,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002699 (sizeof(struct dasd_psf_prssd_data) +
2700 sizeof(struct dasd_rssd_perf_stats_t)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 device);
2702 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002703 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 "Could not allocate initialization request");
2705 return PTR_ERR(cqr);
2706 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002707 cqr->startdev = device;
2708 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 cqr->retries = 0;
2710 cqr->expires = 10 * HZ;
2711
2712 /* Prepare for Read Subsystem Data */
2713 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002714 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 prssdp->order = PSF_ORDER_PRSSD;
Joe Perches5d67d162008-01-26 14:11:20 +01002716 prssdp->suborder = 0x01; /* Performance Statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
2718
2719 ccw = cqr->cpaddr;
2720 ccw->cmd_code = DASD_ECKD_CCW_PSF;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002721 ccw->count = sizeof(struct dasd_psf_prssd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 ccw->flags |= CCW_FLAG_CC;
2723 ccw->cda = (__u32)(addr_t) prssdp;
2724
2725 /* Read Subsystem Data - Performance Statistics */
2726 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002727 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729 ccw++;
2730 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002731 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 ccw->cda = (__u32)(addr_t) stats;
2733
2734 cqr->buildclk = get_clock();
2735 cqr->status = DASD_CQR_FILLED;
2736 rc = dasd_sleep_on(cqr);
2737 if (rc == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2739 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002740 if (copy_to_user(argp, stats,
2741 sizeof(struct dasd_rssd_perf_stats_t)))
2742 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002744 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return rc;
2746}
2747
2748/*
2749 * Get attributes (cache operations)
2750 * Returnes the cache attributes used in Define Extend (DE).
2751 */
2752static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002753dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002755 struct dasd_eckd_private *private =
2756 (struct dasd_eckd_private *)device->private;
2757 struct attrib_data_t attrib = private->attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 int rc;
2759
2760 if (!capable(CAP_SYS_ADMIN))
2761 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002762 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 return -EINVAL;
2764
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002765 rc = 0;
2766 if (copy_to_user(argp, (long *) &attrib,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002767 sizeof(struct attrib_data_t)))
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002768 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
2770 return rc;
2771}
2772
2773/*
2774 * Set attributes (cache operations)
2775 * Stores the attributes for cache operation to be used in Define Extend (DE).
2776 */
2777static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002778dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002780 struct dasd_eckd_private *private =
2781 (struct dasd_eckd_private *)device->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 struct attrib_data_t attrib;
2783
2784 if (!capable(CAP_SYS_ADMIN))
2785 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002786 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 return -EINVAL;
2788
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002789 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 private->attrib = attrib;
2792
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002793 dev_info(&device->cdev->dev,
2794 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
2795 private->attrib.operation, private->attrib.nr_cyl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 return 0;
2797}
2798
Nigel Hislopab1d8482008-10-10 21:33:25 +02002799/*
2800 * Issue syscall I/O to EMC Symmetrix array.
2801 * CCWs are PSF and RSSD
2802 */
2803static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2804{
2805 struct dasd_symmio_parms usrparm;
2806 char *psf_data, *rssd_result;
2807 struct dasd_ccw_req *cqr;
2808 struct ccw1 *ccw;
2809 int rc;
2810
2811 /* Copy parms from caller */
2812 rc = -EFAULT;
2813 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2814 goto out;
2815#ifndef CONFIG_64BIT
2816 /* Make sure pointers are sane even on 31 bit. */
2817 if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) {
2818 rc = -EINVAL;
2819 goto out;
2820 }
2821#endif
2822 /* alloc I/O data area */
2823 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2824 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2825 if (!psf_data || !rssd_result) {
2826 rc = -ENOMEM;
2827 goto out_free;
2828 }
2829
2830 /* get syscall header from user space */
2831 rc = -EFAULT;
2832 if (copy_from_user(psf_data,
2833 (void __user *)(unsigned long) usrparm.psf_data,
2834 usrparm.psf_data_len))
2835 goto out_free;
2836
2837 /* sanity check on syscall header */
2838 if (psf_data[0] != 0x17 && psf_data[1] != 0xce) {
2839 rc = -EINVAL;
2840 goto out_free;
2841 }
2842
2843 /* setup CCWs for PSF + RSSD */
2844 cqr = dasd_smalloc_request("ECKD", 2 , 0, device);
2845 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002846 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Nigel Hislopab1d8482008-10-10 21:33:25 +02002847 "Could not allocate initialization request");
2848 rc = PTR_ERR(cqr);
2849 goto out_free;
2850 }
2851
2852 cqr->startdev = device;
2853 cqr->memdev = device;
2854 cqr->retries = 3;
2855 cqr->expires = 10 * HZ;
2856 cqr->buildclk = get_clock();
2857 cqr->status = DASD_CQR_FILLED;
2858
2859 /* Build the ccws */
2860 ccw = cqr->cpaddr;
2861
2862 /* PSF ccw */
2863 ccw->cmd_code = DASD_ECKD_CCW_PSF;
2864 ccw->count = usrparm.psf_data_len;
2865 ccw->flags |= CCW_FLAG_CC;
2866 ccw->cda = (__u32)(addr_t) psf_data;
2867
2868 ccw++;
2869
2870 /* RSSD ccw */
2871 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2872 ccw->count = usrparm.rssd_result_len;
2873 ccw->flags = CCW_FLAG_SLI ;
2874 ccw->cda = (__u32)(addr_t) rssd_result;
2875
2876 rc = dasd_sleep_on(cqr);
2877 if (rc)
2878 goto out_sfree;
2879
2880 rc = -EFAULT;
2881 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
2882 rssd_result, usrparm.rssd_result_len))
2883 goto out_sfree;
2884 rc = 0;
2885
2886out_sfree:
2887 dasd_sfree_request(cqr, cqr->memdev);
2888out_free:
2889 kfree(rssd_result);
2890 kfree(psf_data);
2891out:
2892 DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc);
2893 return rc;
2894}
2895
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002896static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002897dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002898{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002899 struct dasd_device *device = block->base;
2900
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002901 switch (cmd) {
2902 case BIODASDGATTR:
2903 return dasd_eckd_get_attrib(device, argp);
2904 case BIODASDSATTR:
2905 return dasd_eckd_set_attrib(device, argp);
2906 case BIODASDPSRD:
2907 return dasd_eckd_performance(device, argp);
2908 case BIODASDRLSE:
2909 return dasd_eckd_release(device);
2910 case BIODASDRSRV:
2911 return dasd_eckd_reserve(device);
2912 case BIODASDSLCK:
2913 return dasd_eckd_steal_lock(device);
Nigel Hislopab1d8482008-10-10 21:33:25 +02002914 case BIODASDSYMMIO:
2915 return dasd_symm_io(device, argp);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002916 default:
2917 return -ENOIOCTLCMD;
2918 }
2919}
2920
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921/*
Horst Hummel445b5b42006-06-29 14:57:52 +02002922 * Dump the range of CCWs into 'page' buffer
2923 * and return number of printed chars.
2924 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002925static int
Horst Hummel445b5b42006-06-29 14:57:52 +02002926dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
2927{
2928 int len, count;
2929 char *datap;
2930
2931 len = 0;
2932 while (from <= to) {
2933 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2934 " CCW %p: %08X %08X DAT:",
2935 from, ((int *) from)[0], ((int *) from)[1]);
2936
2937 /* get pointer to data (consider IDALs) */
2938 if (from->flags & CCW_FLAG_IDA)
2939 datap = (char *) *((addr_t *) (addr_t) from->cda);
2940 else
2941 datap = (char *) ((addr_t) from->cda);
2942
2943 /* dump data (max 32 bytes) */
2944 for (count = 0; count < from->count && count < 32; count++) {
2945 if (count % 8 == 0) len += sprintf(page + len, " ");
2946 if (count % 4 == 0) len += sprintf(page + len, " ");
2947 len += sprintf(page + len, "%02x", datap[count]);
2948 }
2949 len += sprintf(page + len, "\n");
2950 from++;
2951 }
2952 return len;
2953}
2954
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002955static void
2956dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct dasd_ccw_req *req,
2957 struct irb *irb, char *reason)
2958{
2959 u64 *sense;
2960 int sl;
2961 struct tsb *tsb;
2962
2963 sense = NULL;
2964 tsb = NULL;
2965 if (req && scsw_is_tm(&req->irb.scsw)) {
2966 if (irb->scsw.tm.tcw)
2967 tsb = tcw_get_tsb(
2968 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
2969 if (tsb && (irb->scsw.tm.fcxs == 0x01)) {
2970 switch (tsb->flags & 0x07) {
2971 case 1: /* tsa_iostat */
2972 sense = (u64 *)tsb->tsa.iostat.sense;
2973 break;
2974 case 2: /* ts_ddpc */
2975 sense = (u64 *)tsb->tsa.ddpc.sense;
2976 break;
2977 case 3: /* tsa_intrg */
2978 break;
2979 }
2980 }
2981 } else {
2982 if (irb->esw.esw0.erw.cons)
2983 sense = (u64 *)irb->ecw;
2984 }
2985 if (sense) {
2986 for (sl = 0; sl < 4; sl++) {
2987 DBF_DEV_EVENT(DBF_EMERG, device,
2988 "%s: %016llx %016llx %016llx %016llx",
2989 reason, sense[0], sense[1], sense[2],
2990 sense[3]);
2991 }
2992 } else {
2993 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
2994 "SORRY - NO VALID SENSE AVAILABLE\n");
2995 }
2996}
2997
Horst Hummel445b5b42006-06-29 14:57:52 +02002998/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 * Print sense data and related channel program.
3000 * Parts are printed because printk buffer is only 1024 bytes.
3001 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003002static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003003 struct dasd_ccw_req *req, struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004{
3005 char *page;
Horst Hummel445b5b42006-06-29 14:57:52 +02003006 struct ccw1 *first, *last, *fail, *from, *to;
3007 int len, sl, sct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
3009 page = (char *) get_zeroed_page(GFP_ATOMIC);
3010 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003011 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3012 "No memory to dump sense data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return;
3014 }
Horst Hummel445b5b42006-06-29 14:57:52 +02003015 /* dump the sense data */
3016 len = sprintf(page, KERN_ERR PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02003018 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3020 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003021 scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3023 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02003024 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02003025 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (irb->esw.esw0.erw.cons) {
3027 for (sl = 0; sl < 4; sl++) {
3028 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3029 " Sense(hex) %2d-%2d:",
3030 (8 * sl), ((8 * sl) + 7));
3031
3032 for (sct = 0; sct < 8; sct++) {
3033 len += sprintf(page + len, " %02x",
3034 irb->ecw[8 * sl + sct]);
3035 }
3036 len += sprintf(page + len, "\n");
3037 }
3038
3039 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3040 /* 24 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02003041 sprintf(page + len, KERN_ERR PRINTK_HEADER
3042 " 24 Byte: %x MSG %x, "
3043 "%s MSGb to SYSOP\n",
3044 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3045 irb->ecw[1] & 0x10 ? "" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 } else {
3047 /* 32 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02003048 sprintf(page + len, KERN_ERR PRINTK_HEADER
3049 " 32 Byte: Format: %x "
3050 "Exception class %x\n",
3051 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 }
3053 } else {
Horst Hummel445b5b42006-06-29 14:57:52 +02003054 sprintf(page + len, KERN_ERR PRINTK_HEADER
3055 " SORRY - NO VALID SENSE AVAILABLE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 }
Horst Hummel445b5b42006-06-29 14:57:52 +02003057 printk("%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003059 if (req) {
3060 /* req == NULL for unsolicited interrupts */
3061 /* dump the Channel Program (max 140 Bytes per line) */
3062 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3063 first = req->cpaddr;
3064 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3065 to = min(first + 6, last);
3066 len = sprintf(page, KERN_ERR PRINTK_HEADER
3067 " Related CP in req: %p\n", req);
3068 dasd_eckd_dump_ccw_range(first, to, page + len);
Horst Hummel445b5b42006-06-29 14:57:52 +02003069 printk("%s", page);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003070
3071 /* print failing CCW area (maximum 4) */
3072 /* scsw->cda is either valid or zero */
3073 len = 0;
3074 from = ++to;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02003075 fail = (struct ccw1 *)(addr_t)
3076 irb->scsw.cmd.cpa; /* failing CCW */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003077 if (from < fail - 2) {
3078 from = fail - 2; /* there is a gap - print header */
3079 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3080 }
3081 to = min(fail + 1, last);
3082 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3083
3084 /* print last CCWs (maximum 2) */
3085 from = max(from, ++to);
3086 if (from < last - 1) {
3087 from = last - 1; /* there is a gap - print header */
3088 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3089 }
3090 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3091 if (len > 0)
3092 printk("%s", page);
3093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 free_page((unsigned long) page);
3095}
3096
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003097
3098/*
3099 * Print sense data from a tcw.
3100 */
3101static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3102 struct dasd_ccw_req *req, struct irb *irb)
3103{
3104 char *page;
3105 int len, sl, sct, residual;
3106
3107 struct tsb *tsb;
3108 u8 *sense;
3109
3110
3111 page = (char *) get_zeroed_page(GFP_ATOMIC);
3112 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003113 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003114 "No memory to dump sense data");
3115 return;
3116 }
3117 /* dump the sense data */
3118 len = sprintf(page, KERN_ERR PRINTK_HEADER
3119 " I/O status report for device %s:\n",
3120 dev_name(&device->cdev->dev));
3121 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3122 " in req: %p CS: 0x%02X DS: 0x%02X "
3123 "fcxs: 0x%02X schxs: 0x%02X\n", req,
3124 scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
3125 irb->scsw.tm.fcxs, irb->scsw.tm.schxs);
3126 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3127 " device %s: Failing TCW: %p\n",
3128 dev_name(&device->cdev->dev),
3129 (void *) (addr_t) irb->scsw.tm.tcw);
3130
3131 tsb = NULL;
3132 sense = NULL;
3133 if (irb->scsw.tm.tcw)
3134 tsb = tcw_get_tsb(
3135 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3136
3137 if (tsb && (irb->scsw.tm.fcxs == 0x01)) {
3138 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3139 " tsb->length %d\n", tsb->length);
3140 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3141 " tsb->flags %x\n", tsb->flags);
3142 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3143 " tsb->dcw_offset %d\n", tsb->dcw_offset);
3144 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3145 " tsb->count %d\n", tsb->count);
3146 residual = tsb->count - 28;
3147 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3148 " residual %d\n", residual);
3149
3150 switch (tsb->flags & 0x07) {
3151 case 1: /* tsa_iostat */
3152 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3153 " tsb->tsa.iostat.dev_time %d\n",
3154 tsb->tsa.iostat.dev_time);
3155 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3156 " tsb->tsa.iostat.def_time %d\n",
3157 tsb->tsa.iostat.def_time);
3158 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3159 " tsb->tsa.iostat.queue_time %d\n",
3160 tsb->tsa.iostat.queue_time);
3161 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3162 " tsb->tsa.iostat.dev_busy_time %d\n",
3163 tsb->tsa.iostat.dev_busy_time);
3164 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3165 " tsb->tsa.iostat.dev_act_time %d\n",
3166 tsb->tsa.iostat.dev_act_time);
3167 sense = tsb->tsa.iostat.sense;
3168 break;
3169 case 2: /* ts_ddpc */
3170 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3171 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3172 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3173 " tsb->tsa.ddpc.rcq: ");
3174 for (sl = 0; sl < 16; sl++) {
3175 for (sct = 0; sct < 8; sct++) {
3176 len += sprintf(page + len, " %02x",
3177 tsb->tsa.ddpc.rcq[sl]);
3178 }
3179 len += sprintf(page + len, "\n");
3180 }
3181 sense = tsb->tsa.ddpc.sense;
3182 break;
3183 case 3: /* tsa_intrg */
3184 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3185 " tsb->tsa.intrg.: not supportet yet \n");
3186 break;
3187 }
3188
3189 if (sense) {
3190 for (sl = 0; sl < 4; sl++) {
3191 len += sprintf(page + len,
3192 KERN_ERR PRINTK_HEADER
3193 " Sense(hex) %2d-%2d:",
3194 (8 * sl), ((8 * sl) + 7));
3195 for (sct = 0; sct < 8; sct++) {
3196 len += sprintf(page + len, " %02x",
3197 sense[8 * sl + sct]);
3198 }
3199 len += sprintf(page + len, "\n");
3200 }
3201
3202 if (sense[27] & DASD_SENSE_BIT_0) {
3203 /* 24 Byte Sense Data */
3204 sprintf(page + len, KERN_ERR PRINTK_HEADER
3205 " 24 Byte: %x MSG %x, "
3206 "%s MSGb to SYSOP\n",
3207 sense[7] >> 4, sense[7] & 0x0f,
3208 sense[1] & 0x10 ? "" : "no");
3209 } else {
3210 /* 32 Byte Sense Data */
3211 sprintf(page + len, KERN_ERR PRINTK_HEADER
3212 " 32 Byte: Format: %x "
3213 "Exception class %x\n",
3214 sense[6] & 0x0f, sense[22] >> 4);
3215 }
3216 } else {
3217 sprintf(page + len, KERN_ERR PRINTK_HEADER
3218 " SORRY - NO VALID SENSE AVAILABLE\n");
3219 }
3220 } else {
3221 sprintf(page + len, KERN_ERR PRINTK_HEADER
3222 " SORRY - NO TSB DATA AVAILABLE\n");
3223 }
3224 printk("%s", page);
3225 free_page((unsigned long) page);
3226}
3227
3228static void dasd_eckd_dump_sense(struct dasd_device *device,
3229 struct dasd_ccw_req *req, struct irb *irb)
3230{
3231 if (req && scsw_is_tm(&req->irb.scsw))
3232 dasd_eckd_dump_sense_tcw(device, req, irb);
3233 else
3234 dasd_eckd_dump_sense_ccw(device, req, irb);
3235}
3236
3237
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238/*
3239 * max_blocks is dependent on the amount of storage that is available
3240 * in the static io buffer for each device. Currently each device has
3241 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
3242 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
3243 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
3244 * addition we have one define extent ccw + 16 bytes of data and one
3245 * locate record ccw + 16 bytes of data. That makes:
3246 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
3247 * We want to fit two into the available memory so that we can immediately
3248 * start the next request if one finishes off. That makes 249.5 blocks
3249 * for one request. Give a little safety and the result is 240.
3250 */
3251static struct dasd_discipline dasd_eckd_discipline = {
3252 .owner = THIS_MODULE,
3253 .name = "ECKD",
3254 .ebcname = "ECKD",
3255 .max_blocks = 240,
3256 .check_device = dasd_eckd_check_characteristics,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003257 .uncheck_device = dasd_eckd_uncheck_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 .do_analysis = dasd_eckd_do_analysis,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003259 .ready_to_online = dasd_eckd_ready_to_online,
3260 .online_to_ready = dasd_eckd_online_to_ready,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 .fill_geometry = dasd_eckd_fill_geometry,
3262 .start_IO = dasd_start_IO,
3263 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003264 .handle_terminated_request = dasd_eckd_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 .format_device = dasd_eckd_format_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 .erp_action = dasd_eckd_erp_action,
3267 .erp_postaction = dasd_eckd_erp_postaction,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003268 .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
3269 .build_cp = dasd_eckd_build_alias_cp,
3270 .free_cp = dasd_eckd_free_alias_cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 .dump_sense = dasd_eckd_dump_sense,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003272 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 .fill_info = dasd_eckd_fill_info,
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003274 .ioctl = dasd_eckd_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275};
3276
3277static int __init
3278dasd_eckd_init(void)
3279{
Sebastian Ott736e6ea2009-06-12 10:26:38 +02003280 int ret;
3281
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 ASCEBC(dasd_eckd_discipline.ebcname, 4);
Sebastian Ott736e6ea2009-06-12 10:26:38 +02003283 ret = ccw_driver_register(&dasd_eckd_driver);
3284 if (!ret)
3285 wait_for_device_probe();
3286
3287 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288}
3289
3290static void __exit
3291dasd_eckd_cleanup(void)
3292{
3293 ccw_driver_unregister(&dasd_eckd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294}
3295
3296module_init(dasd_eckd_init);
3297module_exit(dasd_eckd_cleanup);