blob: abb2ec836ee87278b9bc151fe4919011987643e5 [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>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02008 * Copyright IBM Corp. 1999, 2009
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 */
12
Stefan Haberlandca99dab2009-09-11 10:28:30 +020013#define KMSG_COMPONENT "dasd-eckd"
Stefan Haberlandfc19f382009-03-26 15:23:49 +010014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/stddef.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/hdreg.h> /* HDIO_GETGEO */
19#include <linux/bio.h>
20#include <linux/module.h>
21#include <linux/init.h>
22
23#include <asm/debug.h>
24#include <asm/idals.h>
25#include <asm/ebcdic.h>
26#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/uaccess.h>
Horst Hummel40545572006-06-29 15:08:18 +020028#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/ccwdev.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010030#include <asm/itcw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include "dasd_int.h"
33#include "dasd_eckd.h"
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010034#include "../cio/chsc.h"
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#ifdef PRINTK_HEADER
38#undef PRINTK_HEADER
39#endif /* PRINTK_HEADER */
40#define PRINTK_HEADER "dasd(eckd):"
41
42#define ECKD_C0(i) (i->home_bytes)
43#define ECKD_F(i) (i->formula)
44#define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
45 (i->factors.f_0x02.f1))
46#define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
47 (i->factors.f_0x02.f2))
48#define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
49 (i->factors.f_0x02.f3))
50#define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
51#define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
52#define ECKD_F6(i) (i->factor6)
53#define ECKD_F7(i) (i->factor7)
54#define ECKD_F8(i) (i->factor8)
55
56MODULE_LICENSE("GPL");
57
58static struct dasd_discipline dasd_eckd_discipline;
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/* The ccw bus type uses this table to find devices that it sends to
61 * dasd_eckd_probe */
62static struct ccw_device_id dasd_eckd_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020063 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
64 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
65 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
66 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
67 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
68 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
69 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
70 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
71 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
72 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 { /* end of list */ },
74};
75
76MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
77
78static struct ccw_driver dasd_eckd_driver; /* see below */
79
80/* initial attempt at a probe function. this can be simplified once
81 * the other detection code is gone */
82static int
83dasd_eckd_probe (struct ccw_device *cdev)
84{
85 int ret;
86
Horst Hummel40545572006-06-29 15:08:18 +020087 /* set ECKD specific ccw-device options */
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +010088 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
89 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
Horst Hummel40545572006-06-29 15:08:18 +020090 if (ret) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +010091 DBF_EVENT(DBF_WARNING,
Horst Hummel40545572006-06-29 15:08:18 +020092 "dasd_eckd_probe: could not set ccw-device options "
Kay Sievers2a0217d2008-10-10 21:33:09 +020093 "for %s\n", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return ret;
Horst Hummel40545572006-06-29 15:08:18 +020095 }
96 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
97 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100static int
101dasd_eckd_set_online(struct ccw_device *cdev)
102{
Horst Hummel40545572006-06-29 15:08:18 +0200103 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static const int sizes_trk0[] = { 28, 148, 84 };
107#define LABEL_SIZE 140
108
109static inline unsigned int
110round_up_multiple(unsigned int no, unsigned int mult)
111{
112 int rem = no % mult;
113 return (rem ? no - rem + mult : no);
114}
115
116static inline unsigned int
117ceil_quot(unsigned int d1, unsigned int d2)
118{
119 return (d1 + (d2 - 1)) / d2;
120}
121
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100122static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123recs_per_track(struct dasd_eckd_characteristics * rdc,
124 unsigned int kl, unsigned int dl)
125{
126 int dn, kn;
127
128 switch (rdc->dev_type) {
129 case 0x3380:
130 if (kl)
131 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
132 ceil_quot(dl + 12, 32));
133 else
134 return 1499 / (15 + ceil_quot(dl + 12, 32));
135 case 0x3390:
136 dn = ceil_quot(dl + 6, 232) + 1;
137 if (kl) {
138 kn = ceil_quot(kl + 6, 232) + 1;
139 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
140 9 + ceil_quot(dl + 6 * dn, 34));
141 } else
142 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
143 case 0x9345:
144 dn = ceil_quot(dl + 6, 232) + 1;
145 if (kl) {
146 kn = ceil_quot(kl + 6, 232) + 1;
147 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
148 ceil_quot(dl + 6 * dn, 34));
149 } else
150 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
151 }
152 return 0;
153}
154
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100155static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
156{
157 geo->cyl = (__u16) cyl;
158 geo->head = cyl >> 16;
159 geo->head <<= 4;
160 geo->head |= head;
161}
162
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100163static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164check_XRC (struct ccw1 *de_ccw,
165 struct DE_eckd_data *data,
166 struct dasd_device *device)
167{
168 struct dasd_eckd_private *private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100169 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 private = (struct dasd_eckd_private *) device->private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100172 if (!private->rdc_data.facilities.XRC_supported)
173 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* switch on System Time Stamp - needed for XRC Support */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100176 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
177 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
Horst Hummel138c0142006-06-29 14:58:12 +0200178
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100179 rc = get_sync_clock(&data->ep_sys_time);
180 /* Ignore return code if sync clock is switched off. */
181 if (rc == -ENOSYS || rc == -EACCES)
182 rc = 0;
Horst Hummel138c0142006-06-29 14:58:12 +0200183
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100184 de_ccw->count = sizeof(struct DE_eckd_data);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100185 de_ccw->flags |= CCW_FLAG_SLI;
186 return rc;
187}
Horst Hummel138c0142006-06-29 14:58:12 +0200188
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100189static int
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100190define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
191 unsigned int totrk, int cmd, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 struct dasd_eckd_private *private;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100194 u32 begcyl, endcyl;
195 u16 heads, beghead, endhead;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100196 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 private = (struct dasd_eckd_private *) device->private;
199
200 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
201 ccw->flags = 0;
202 ccw->count = 16;
203 ccw->cda = (__u32) __pa(data);
204
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100205 memset(data, 0, sizeof(struct DE_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 switch (cmd) {
207 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
208 case DASD_ECKD_CCW_READ_RECORD_ZERO:
209 case DASD_ECKD_CCW_READ:
210 case DASD_ECKD_CCW_READ_MT:
211 case DASD_ECKD_CCW_READ_CKD:
212 case DASD_ECKD_CCW_READ_CKD_MT:
213 case DASD_ECKD_CCW_READ_KD:
214 case DASD_ECKD_CCW_READ_KD_MT:
215 case DASD_ECKD_CCW_READ_COUNT:
216 data->mask.perm = 0x1;
217 data->attributes.operation = private->attrib.operation;
218 break;
219 case DASD_ECKD_CCW_WRITE:
220 case DASD_ECKD_CCW_WRITE_MT:
221 case DASD_ECKD_CCW_WRITE_KD:
222 case DASD_ECKD_CCW_WRITE_KD_MT:
223 data->mask.perm = 0x02;
224 data->attributes.operation = private->attrib.operation;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100225 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 break;
227 case DASD_ECKD_CCW_WRITE_CKD:
228 case DASD_ECKD_CCW_WRITE_CKD_MT:
229 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100230 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 break;
232 case DASD_ECKD_CCW_ERASE:
233 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
234 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
235 data->mask.perm = 0x3;
236 data->mask.auth = 0x1;
237 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100238 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 break;
240 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100241 dev_err(&device->cdev->dev,
242 "0x%x is not a known command\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 break;
244 }
245
246 data->attributes.mode = 0x3; /* ECKD */
247
248 if ((private->rdc_data.cu_type == 0x2105 ||
249 private->rdc_data.cu_type == 0x2107 ||
250 private->rdc_data.cu_type == 0x1750)
251 && !(private->uses_cdl && trk < 2))
252 data->ga_extended |= 0x40; /* Regular Data Format Mode */
253
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100254 heads = private->rdc_data.trk_per_cyl;
255 begcyl = trk / heads;
256 beghead = trk % heads;
257 endcyl = totrk / heads;
258 endhead = totrk % heads;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 /* check for sequential prestage - enhance cylinder range */
261 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
262 data->attributes.operation == DASD_SEQ_ACCESS) {
Horst Hummel138c0142006-06-29 14:58:12 +0200263
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100264 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
265 endcyl += private->attrib.nr_cyl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100267 endcyl = (private->real_cyl - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100270 set_ch_t(&data->beg_ext, begcyl, beghead);
271 set_ch_t(&data->end_ext, endcyl, endhead);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100272 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100275static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
276 struct dasd_device *device)
277{
278 struct dasd_eckd_private *private;
279 int rc;
280
281 private = (struct dasd_eckd_private *) device->private;
282 if (!private->rdc_data.facilities.XRC_supported)
283 return 0;
284
285 /* switch on System Time Stamp - needed for XRC Support */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100286 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
287 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100288 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
289
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100290 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100291 /* Ignore return code if sync clock is switched off. */
292 if (rc == -ENOSYS || rc == -EACCES)
293 rc = 0;
294 return rc;
295}
296
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100297static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
298 unsigned int rec_on_trk, int count, int cmd,
299 struct dasd_device *device, unsigned int reclen,
300 unsigned int tlf)
301{
302 struct dasd_eckd_private *private;
303 int sector;
304 int dn, d;
305
306 private = (struct dasd_eckd_private *) device->private;
307
308 memset(data, 0, sizeof(*data));
309 sector = 0;
310 if (rec_on_trk) {
311 switch (private->rdc_data.dev_type) {
312 case 0x3390:
313 dn = ceil_quot(reclen + 6, 232);
314 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
315 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
316 break;
317 case 0x3380:
318 d = 7 + ceil_quot(reclen + 12, 32);
319 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
320 break;
321 }
322 }
323 data->sector = sector;
324 /* note: meaning of count depends on the operation
325 * for record based I/O it's the number of records, but for
326 * track based I/O it's the number of tracks
327 */
328 data->count = count;
329 switch (cmd) {
330 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
331 data->operation.orientation = 0x3;
332 data->operation.operation = 0x03;
333 break;
334 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
335 data->operation.orientation = 0x3;
336 data->operation.operation = 0x16;
337 break;
338 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
339 data->operation.orientation = 0x1;
340 data->operation.operation = 0x03;
341 data->count++;
342 break;
343 case DASD_ECKD_CCW_READ_RECORD_ZERO:
344 data->operation.orientation = 0x3;
345 data->operation.operation = 0x16;
346 data->count++;
347 break;
348 case DASD_ECKD_CCW_WRITE:
349 case DASD_ECKD_CCW_WRITE_MT:
350 case DASD_ECKD_CCW_WRITE_KD:
351 case DASD_ECKD_CCW_WRITE_KD_MT:
352 data->auxiliary.length_valid = 0x1;
353 data->length = reclen;
354 data->operation.operation = 0x01;
355 break;
356 case DASD_ECKD_CCW_WRITE_CKD:
357 case DASD_ECKD_CCW_WRITE_CKD_MT:
358 data->auxiliary.length_valid = 0x1;
359 data->length = reclen;
360 data->operation.operation = 0x03;
361 break;
362 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
363 data->auxiliary.length_valid = 0x1;
364 data->length = reclen; /* not tlf, as one might think */
365 data->operation.operation = 0x3F;
366 data->extended_operation = 0x23;
367 break;
368 case DASD_ECKD_CCW_READ:
369 case DASD_ECKD_CCW_READ_MT:
370 case DASD_ECKD_CCW_READ_KD:
371 case DASD_ECKD_CCW_READ_KD_MT:
372 data->auxiliary.length_valid = 0x1;
373 data->length = reclen;
374 data->operation.operation = 0x06;
375 break;
376 case DASD_ECKD_CCW_READ_CKD:
377 case DASD_ECKD_CCW_READ_CKD_MT:
378 data->auxiliary.length_valid = 0x1;
379 data->length = reclen;
380 data->operation.operation = 0x16;
381 break;
382 case DASD_ECKD_CCW_READ_COUNT:
383 data->operation.operation = 0x06;
384 break;
385 case DASD_ECKD_CCW_READ_TRACK_DATA:
386 data->auxiliary.length_valid = 0x1;
387 data->length = tlf;
388 data->operation.operation = 0x0C;
389 break;
390 case DASD_ECKD_CCW_ERASE:
391 data->length = reclen;
392 data->auxiliary.length_valid = 0x1;
393 data->operation.operation = 0x0b;
394 break;
395 default:
396 DBF_DEV_EVENT(DBF_ERR, device,
397 "fill LRE unknown opcode 0x%x", cmd);
398 BUG();
399 }
400 set_ch_t(&data->seek_addr,
401 trk / private->rdc_data.trk_per_cyl,
402 trk % private->rdc_data.trk_per_cyl);
403 data->search_arg.cyl = data->seek_addr.cyl;
404 data->search_arg.head = data->seek_addr.head;
405 data->search_arg.record = rec_on_trk;
406}
407
408static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
409 unsigned int trk, unsigned int totrk, int cmd,
410 struct dasd_device *basedev, struct dasd_device *startdev,
411 unsigned char format, unsigned int rec_on_trk, int count,
412 unsigned int blksize, unsigned int tlf)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100413{
414 struct dasd_eckd_private *basepriv, *startpriv;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100415 struct DE_eckd_data *dedata;
416 struct LRE_eckd_data *lredata;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100417 u32 begcyl, endcyl;
418 u16 heads, beghead, endhead;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100419 int rc = 0;
420
421 basepriv = (struct dasd_eckd_private *) basedev->private;
422 startpriv = (struct dasd_eckd_private *) startdev->private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100423 dedata = &pfxdata->define_extent;
424 lredata = &pfxdata->locate_record;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100425
426 ccw->cmd_code = DASD_ECKD_CCW_PFX;
427 ccw->flags = 0;
428 ccw->count = sizeof(*pfxdata);
429 ccw->cda = (__u32) __pa(pfxdata);
430
431 memset(pfxdata, 0, sizeof(*pfxdata));
432 /* prefix data */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100433 if (format > 1) {
434 DBF_DEV_EVENT(DBF_ERR, basedev,
435 "PFX LRE unknown format 0x%x", format);
436 BUG();
437 return -EINVAL;
438 }
439 pfxdata->format = format;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200440 pfxdata->base_address = basepriv->ned->unit_addr;
441 pfxdata->base_lss = basepriv->ned->ID;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100442 pfxdata->validity.define_extent = 1;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100443
444 /* private uid is kept up to date, conf_data may be outdated */
445 if (startpriv->uid.type != UA_BASE_DEVICE) {
446 pfxdata->validity.verify_base = 1;
447 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
448 pfxdata->validity.hyper_pav = 1;
449 }
450
451 /* define extend data (mostly)*/
452 switch (cmd) {
453 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
454 case DASD_ECKD_CCW_READ_RECORD_ZERO:
455 case DASD_ECKD_CCW_READ:
456 case DASD_ECKD_CCW_READ_MT:
457 case DASD_ECKD_CCW_READ_CKD:
458 case DASD_ECKD_CCW_READ_CKD_MT:
459 case DASD_ECKD_CCW_READ_KD:
460 case DASD_ECKD_CCW_READ_KD_MT:
461 case DASD_ECKD_CCW_READ_COUNT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100462 dedata->mask.perm = 0x1;
463 dedata->attributes.operation = basepriv->attrib.operation;
464 break;
465 case DASD_ECKD_CCW_READ_TRACK_DATA:
466 dedata->mask.perm = 0x1;
467 dedata->attributes.operation = basepriv->attrib.operation;
468 dedata->blk_size = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100469 break;
470 case DASD_ECKD_CCW_WRITE:
471 case DASD_ECKD_CCW_WRITE_MT:
472 case DASD_ECKD_CCW_WRITE_KD:
473 case DASD_ECKD_CCW_WRITE_KD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100474 dedata->mask.perm = 0x02;
475 dedata->attributes.operation = basepriv->attrib.operation;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100476 rc = check_XRC_on_prefix(pfxdata, basedev);
477 break;
478 case DASD_ECKD_CCW_WRITE_CKD:
479 case DASD_ECKD_CCW_WRITE_CKD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100480 dedata->attributes.operation = DASD_BYPASS_CACHE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100481 rc = check_XRC_on_prefix(pfxdata, basedev);
482 break;
483 case DASD_ECKD_CCW_ERASE:
484 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
485 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100486 dedata->mask.perm = 0x3;
487 dedata->mask.auth = 0x1;
488 dedata->attributes.operation = DASD_BYPASS_CACHE;
489 rc = check_XRC_on_prefix(pfxdata, basedev);
490 break;
491 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
492 dedata->mask.perm = 0x02;
493 dedata->attributes.operation = basepriv->attrib.operation;
494 dedata->blk_size = blksize;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100495 rc = check_XRC_on_prefix(pfxdata, basedev);
496 break;
497 default:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100498 DBF_DEV_EVENT(DBF_ERR, basedev,
499 "PFX LRE unknown opcode 0x%x", cmd);
500 BUG();
501 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100502 }
503
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100504 dedata->attributes.mode = 0x3; /* ECKD */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100505
506 if ((basepriv->rdc_data.cu_type == 0x2105 ||
507 basepriv->rdc_data.cu_type == 0x2107 ||
508 basepriv->rdc_data.cu_type == 0x1750)
509 && !(basepriv->uses_cdl && trk < 2))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100510 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100511
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100512 heads = basepriv->rdc_data.trk_per_cyl;
513 begcyl = trk / heads;
514 beghead = trk % heads;
515 endcyl = totrk / heads;
516 endhead = totrk % heads;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100517
518 /* check for sequential prestage - enhance cylinder range */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100519 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
520 dedata->attributes.operation == DASD_SEQ_ACCESS) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100521
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100522 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
523 endcyl += basepriv->attrib.nr_cyl;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100524 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100525 endcyl = (basepriv->real_cyl - 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100526 }
527
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100528 set_ch_t(&dedata->beg_ext, begcyl, beghead);
529 set_ch_t(&dedata->end_ext, endcyl, endhead);
530
531 if (format == 1) {
532 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
533 basedev, blksize, tlf);
534 }
535
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100536 return rc;
537}
538
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100539static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
540 unsigned int trk, unsigned int totrk, int cmd,
541 struct dasd_device *basedev, struct dasd_device *startdev)
542{
543 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
544 0, 0, 0, 0, 0);
545}
546
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100547static void
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100548locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
549 unsigned int rec_on_trk, int no_rec, int cmd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 struct dasd_device * device, int reclen)
551{
552 struct dasd_eckd_private *private;
553 int sector;
554 int dn, d;
Horst Hummel138c0142006-06-29 14:58:12 +0200555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 private = (struct dasd_eckd_private *) device->private;
557
558 DBF_DEV_EVENT(DBF_INFO, device,
559 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
560 trk, rec_on_trk, no_rec, cmd, reclen);
561
562 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
563 ccw->flags = 0;
564 ccw->count = 16;
565 ccw->cda = (__u32) __pa(data);
566
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100567 memset(data, 0, sizeof(struct LO_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 sector = 0;
569 if (rec_on_trk) {
570 switch (private->rdc_data.dev_type) {
571 case 0x3390:
572 dn = ceil_quot(reclen + 6, 232);
573 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
574 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
575 break;
576 case 0x3380:
577 d = 7 + ceil_quot(reclen + 12, 32);
578 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
579 break;
580 }
581 }
582 data->sector = sector;
583 data->count = no_rec;
584 switch (cmd) {
585 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
586 data->operation.orientation = 0x3;
587 data->operation.operation = 0x03;
588 break;
589 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
590 data->operation.orientation = 0x3;
591 data->operation.operation = 0x16;
592 break;
593 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
594 data->operation.orientation = 0x1;
595 data->operation.operation = 0x03;
596 data->count++;
597 break;
598 case DASD_ECKD_CCW_READ_RECORD_ZERO:
599 data->operation.orientation = 0x3;
600 data->operation.operation = 0x16;
601 data->count++;
602 break;
603 case DASD_ECKD_CCW_WRITE:
604 case DASD_ECKD_CCW_WRITE_MT:
605 case DASD_ECKD_CCW_WRITE_KD:
606 case DASD_ECKD_CCW_WRITE_KD_MT:
607 data->auxiliary.last_bytes_used = 0x1;
608 data->length = reclen;
609 data->operation.operation = 0x01;
610 break;
611 case DASD_ECKD_CCW_WRITE_CKD:
612 case DASD_ECKD_CCW_WRITE_CKD_MT:
613 data->auxiliary.last_bytes_used = 0x1;
614 data->length = reclen;
615 data->operation.operation = 0x03;
616 break;
617 case DASD_ECKD_CCW_READ:
618 case DASD_ECKD_CCW_READ_MT:
619 case DASD_ECKD_CCW_READ_KD:
620 case DASD_ECKD_CCW_READ_KD_MT:
621 data->auxiliary.last_bytes_used = 0x1;
622 data->length = reclen;
623 data->operation.operation = 0x06;
624 break;
625 case DASD_ECKD_CCW_READ_CKD:
626 case DASD_ECKD_CCW_READ_CKD_MT:
627 data->auxiliary.last_bytes_used = 0x1;
628 data->length = reclen;
629 data->operation.operation = 0x16;
630 break;
631 case DASD_ECKD_CCW_READ_COUNT:
632 data->operation.operation = 0x06;
633 break;
634 case DASD_ECKD_CCW_ERASE:
635 data->length = reclen;
636 data->auxiliary.last_bytes_used = 0x1;
637 data->operation.operation = 0x0b;
638 break;
639 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100640 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
641 "opcode 0x%x", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100643 set_ch_t(&data->seek_addr,
644 trk / private->rdc_data.trk_per_cyl,
645 trk % private->rdc_data.trk_per_cyl);
646 data->search_arg.cyl = data->seek_addr.cyl;
647 data->search_arg.head = data->seek_addr.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 data->search_arg.record = rec_on_trk;
649}
650
651/*
652 * Returns 1 if the block is one of the special blocks that needs
653 * to get read/written with the KD variant of the command.
654 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
655 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
656 * Luckily the KD variants differ only by one bit (0x08) from the
657 * normal variant. So don't wonder about code like:
658 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
659 * ccw->cmd_code |= 0x8;
660 */
661static inline int
662dasd_eckd_cdl_special(int blk_per_trk, int recid)
663{
664 if (recid < 3)
665 return 1;
666 if (recid < blk_per_trk)
667 return 0;
668 if (recid < 2 * blk_per_trk)
669 return 1;
670 return 0;
671}
672
673/*
674 * Returns the record size for the special blocks of the cdl format.
675 * Only returns something useful if dasd_eckd_cdl_special is true
676 * for the recid.
677 */
678static inline int
679dasd_eckd_cdl_reclen(int recid)
680{
681 if (recid < 3)
682 return sizes_trk0[recid];
683 return LABEL_SIZE;
684}
685
Horst Hummel3d052592006-04-27 18:40:28 -0700686/*
687 * Generate device unique id that specifies the physical device.
688 */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200689static int dasd_eckd_generate_uid(struct dasd_device *device,
690 struct dasd_uid *uid)
Horst Hummel3d052592006-04-27 18:40:28 -0700691{
692 struct dasd_eckd_private *private;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200693 int count;
Horst Hummel3d052592006-04-27 18:40:28 -0700694
695 private = (struct dasd_eckd_private *) device->private;
696 if (!private)
697 return -ENODEV;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200698 if (!private->ned || !private->gneq)
Horst Hummel3d052592006-04-27 18:40:28 -0700699 return -ENODEV;
700
701 memset(uid, 0, sizeof(struct dasd_uid));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200702 memcpy(uid->vendor, private->ned->HDA_manufacturer,
Horst Hummeld0710c72006-08-10 15:45:16 +0200703 sizeof(uid->vendor) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700704 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200705 memcpy(uid->serial, private->ned->HDA_location,
Horst Hummeld0710c72006-08-10 15:45:16 +0200706 sizeof(uid->serial) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700707 EBCASC(uid->serial, sizeof(uid->serial) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200708 uid->ssid = private->gneq->subsystemID;
Joe Perchesa419aef2009-08-18 11:18:35 -0700709 uid->real_unit_addr = private->ned->unit_addr;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200710 if (private->sneq) {
711 uid->type = private->sneq->sua_flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100712 if (uid->type == UA_BASE_PAV_ALIAS)
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200713 uid->base_unit_addr = private->sneq->base_unit_addr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100714 } else {
715 uid->type = UA_BASE_DEVICE;
716 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200717 if (private->vdsneq) {
718 for (count = 0; count < 16; count++) {
719 sprintf(uid->vduit+2*count, "%02x",
720 private->vdsneq->uit[count]);
721 }
722 }
Horst Hummel3d052592006-04-27 18:40:28 -0700723 return 0;
724}
725
Heiko Carstens763968e2007-05-10 15:45:46 +0200726static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
727 void *rcd_buffer,
728 struct ciw *ciw, __u8 lpm)
Cornelia Huck17283b52007-05-04 18:47:51 +0200729{
730 struct dasd_ccw_req *cqr;
731 struct ccw1 *ccw;
732
Stefan Haberland68b781f2009-09-11 10:28:29 +0200733 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, ciw->count,
734 device);
Cornelia Huck17283b52007-05-04 18:47:51 +0200735
736 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100737 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
738 "Could not allocate RCD request");
Cornelia Huck17283b52007-05-04 18:47:51 +0200739 return cqr;
740 }
741
742 ccw = cqr->cpaddr;
743 ccw->cmd_code = ciw->cmd;
744 ccw->cda = (__u32)(addr_t)rcd_buffer;
745 ccw->count = ciw->count;
746
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100747 cqr->startdev = device;
748 cqr->memdev = device;
749 cqr->block = NULL;
Cornelia Huck17283b52007-05-04 18:47:51 +0200750 cqr->expires = 10*HZ;
751 cqr->lpm = lpm;
752 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
753 cqr->retries = 2;
754 cqr->buildclk = get_clock();
755 cqr->status = DASD_CQR_FILLED;
756 return cqr;
757}
758
759static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
760 void **rcd_buffer,
761 int *rcd_buffer_size, __u8 lpm)
762{
763 struct ciw *ciw;
764 char *rcd_buf = NULL;
765 int ret;
766 struct dasd_ccw_req *cqr;
767
768 /*
769 * scan for RCD command in extended SenseID data
770 */
771 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
772 if (!ciw || ciw->cmd == 0) {
773 ret = -EOPNOTSUPP;
774 goto out_error;
775 }
776 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
777 if (!rcd_buf) {
778 ret = -ENOMEM;
779 goto out_error;
780 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200781
782 /*
783 * buffer has to start with EBCDIC "V1.0" to show
784 * support for virtual device SNEQ
785 */
786 rcd_buf[0] = 0xE5;
787 rcd_buf[1] = 0xF1;
788 rcd_buf[2] = 0x4B;
789 rcd_buf[3] = 0xF0;
Cornelia Huck17283b52007-05-04 18:47:51 +0200790 cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
791 if (IS_ERR(cqr)) {
792 ret = PTR_ERR(cqr);
793 goto out_error;
794 }
795 ret = dasd_sleep_on(cqr);
796 /*
797 * on success we update the user input parms
798 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100799 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +0200800 if (ret)
801 goto out_error;
802
803 *rcd_buffer_size = ciw->count;
804 *rcd_buffer = rcd_buf;
805 return 0;
806out_error:
807 kfree(rcd_buf);
808 *rcd_buffer = NULL;
809 *rcd_buffer_size = 0;
810 return ret;
811}
812
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200813static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
814{
815
816 struct dasd_sneq *sneq;
817 int i, count;
818
819 private->ned = NULL;
820 private->sneq = NULL;
821 private->vdsneq = NULL;
822 private->gneq = NULL;
823 count = private->conf_len / sizeof(struct dasd_sneq);
824 sneq = (struct dasd_sneq *)private->conf_data;
825 for (i = 0; i < count; ++i) {
826 if (sneq->flags.identifier == 1 && sneq->format == 1)
827 private->sneq = sneq;
828 else if (sneq->flags.identifier == 1 && sneq->format == 4)
829 private->vdsneq = (struct vd_sneq *)sneq;
830 else if (sneq->flags.identifier == 2)
831 private->gneq = (struct dasd_gneq *)sneq;
832 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
833 private->ned = (struct dasd_ned *)sneq;
834 sneq++;
835 }
836 if (!private->ned || !private->gneq) {
837 private->ned = NULL;
838 private->sneq = NULL;
839 private->vdsneq = NULL;
840 private->gneq = NULL;
841 return -EINVAL;
842 }
843 return 0;
844
845};
846
847static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
848{
849 struct dasd_gneq *gneq;
850 int i, count, found;
851
852 count = conf_len / sizeof(*gneq);
853 gneq = (struct dasd_gneq *)conf_data;
854 found = 0;
855 for (i = 0; i < count; ++i) {
856 if (gneq->flags.identifier == 2) {
857 found = 1;
858 break;
859 }
860 gneq++;
861 }
862 if (found)
863 return ((char *)gneq)[18] & 0x07;
864 else
865 return 0;
866}
867
868static int dasd_eckd_read_conf(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 void *conf_data;
871 int conf_len, conf_data_saved;
872 int rc;
873 __u8 lpm;
874 struct dasd_eckd_private *private;
875 struct dasd_eckd_path *path_data;
876
877 private = (struct dasd_eckd_private *) device->private;
878 path_data = (struct dasd_eckd_path *) &private->path_data;
879 path_data->opm = ccw_device_get_path_mask(device->cdev);
880 lpm = 0x80;
881 conf_data_saved = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /* get configuration data per operational path */
883 for (lpm = 0x80; lpm; lpm>>= 1) {
884 if (lpm & path_data->opm){
Cornelia Huck17283b52007-05-04 18:47:51 +0200885 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
886 &conf_len, lpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100888 DBF_EVENT(DBF_WARNING,
889 "Read configuration data returned "
890 "error %d for device: %s", rc,
891 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 return rc;
893 }
894 if (conf_data == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100895 DBF_EVENT(DBF_WARNING, "No configuration "
896 "data retrieved for device: %s",
897 dev_name(&device->cdev->dev));
Gabriel Craciunescud133a962007-07-31 00:39:19 -0700898 continue; /* no error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /* save first valid configuration data */
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200901 if (!conf_data_saved) {
902 kfree(private->conf_data);
903 private->conf_data = conf_data;
904 private->conf_len = conf_len;
905 if (dasd_eckd_identify_conf_parts(private)) {
906 private->conf_data = NULL;
907 private->conf_len = 0;
908 kfree(conf_data);
909 continue;
910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 conf_data_saved++;
912 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200913 switch (dasd_eckd_path_access(conf_data, conf_len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 case 0x02:
915 path_data->npm |= lpm;
916 break;
917 case 0x03:
918 path_data->ppm |= lpm;
919 break;
920 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200921 if (conf_data != private->conf_data)
922 kfree(conf_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 }
924 }
925 return 0;
926}
927
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100928static int dasd_eckd_read_features(struct dasd_device *device)
929{
930 struct dasd_psf_prssd_data *prssdp;
931 struct dasd_rssd_features *features;
932 struct dasd_ccw_req *cqr;
933 struct ccw1 *ccw;
934 int rc;
935 struct dasd_eckd_private *private;
936
937 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +0200938 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
Stefan Haberland68b781f2009-09-11 10:28:29 +0200939 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100940 (sizeof(struct dasd_psf_prssd_data) +
941 sizeof(struct dasd_rssd_features)),
942 device);
943 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100944 DBF_EVENT(DBF_WARNING, "Could not allocate initialization "
945 "request for device: %s",
946 dev_name(&device->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100947 return PTR_ERR(cqr);
948 }
949 cqr->startdev = device;
950 cqr->memdev = device;
951 cqr->block = NULL;
952 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
953 cqr->retries = 5;
954 cqr->expires = 10 * HZ;
955
956 /* Prepare for Read Subsystem Data */
957 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
958 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
959 prssdp->order = PSF_ORDER_PRSSD;
960 prssdp->suborder = 0x41; /* Read Feature Codes */
961 /* all other bytes of prssdp must be zero */
962
963 ccw = cqr->cpaddr;
964 ccw->cmd_code = DASD_ECKD_CCW_PSF;
965 ccw->count = sizeof(struct dasd_psf_prssd_data);
966 ccw->flags |= CCW_FLAG_CC;
967 ccw->cda = (__u32)(addr_t) prssdp;
968
969 /* Read Subsystem Data - feature codes */
970 features = (struct dasd_rssd_features *) (prssdp + 1);
971 memset(features, 0, sizeof(struct dasd_rssd_features));
972
973 ccw++;
974 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
975 ccw->count = sizeof(struct dasd_rssd_features);
976 ccw->cda = (__u32)(addr_t) features;
977
978 cqr->buildclk = get_clock();
979 cqr->status = DASD_CQR_FILLED;
980 rc = dasd_sleep_on(cqr);
981 if (rc == 0) {
982 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
983 features = (struct dasd_rssd_features *) (prssdp + 1);
984 memcpy(&private->features, features,
985 sizeof(struct dasd_rssd_features));
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +0200986 } else
987 dev_warn(&device->cdev->dev, "Reading device feature codes"
988 " failed with rc=%d\n", rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100989 dasd_sfree_request(cqr, cqr->memdev);
990 return rc;
991}
992
993
Horst Hummel3d052592006-04-27 18:40:28 -0700994/*
Horst Hummel40545572006-06-29 15:08:18 +0200995 * Build CP for Perform Subsystem Function - SSC.
996 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100997static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
998 int enable_pav)
Horst Hummel40545572006-06-29 15:08:18 +0200999{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001000 struct dasd_ccw_req *cqr;
1001 struct dasd_psf_ssc_data *psf_ssc_data;
1002 struct ccw1 *ccw;
Horst Hummel40545572006-06-29 15:08:18 +02001003
Stefan Haberland68b781f2009-09-11 10:28:29 +02001004 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
Horst Hummel40545572006-06-29 15:08:18 +02001005 sizeof(struct dasd_psf_ssc_data),
1006 device);
1007
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001008 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001009 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Horst Hummel40545572006-06-29 15:08:18 +02001010 "Could not allocate PSF-SSC request");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001011 return cqr;
1012 }
1013 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1014 psf_ssc_data->order = PSF_ORDER_SSC;
Stefan Weinhuber626350b2009-12-07 12:51:50 +01001015 psf_ssc_data->suborder = 0xc0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001016 if (enable_pav) {
Stefan Weinhuber626350b2009-12-07 12:51:50 +01001017 psf_ssc_data->suborder |= 0x08;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001018 psf_ssc_data->reserved[0] = 0x88;
1019 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001020 ccw = cqr->cpaddr;
1021 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1022 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1023 ccw->count = 66;
Horst Hummel40545572006-06-29 15:08:18 +02001024
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001025 cqr->startdev = device;
1026 cqr->memdev = device;
1027 cqr->block = NULL;
1028 cqr->expires = 10*HZ;
1029 cqr->buildclk = get_clock();
1030 cqr->status = DASD_CQR_FILLED;
1031 return cqr;
Horst Hummel40545572006-06-29 15:08:18 +02001032}
1033
1034/*
1035 * Perform Subsystem Function.
1036 * It is necessary to trigger CIO for channel revalidation since this
1037 * call might change behaviour of DASD devices.
1038 */
1039static int
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001040dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
Horst Hummel40545572006-06-29 15:08:18 +02001041{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001042 struct dasd_ccw_req *cqr;
1043 int rc;
Horst Hummel40545572006-06-29 15:08:18 +02001044
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001045 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001046 if (IS_ERR(cqr))
1047 return PTR_ERR(cqr);
Horst Hummel40545572006-06-29 15:08:18 +02001048
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001049 rc = dasd_sleep_on(cqr);
1050 if (!rc)
1051 /* trigger CIO to reprobe devices */
1052 css_schedule_reprobe();
1053 dasd_sfree_request(cqr, cqr->memdev);
1054 return rc;
Horst Hummel40545572006-06-29 15:08:18 +02001055}
1056
1057/*
1058 * Valide storage server of current device.
1059 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001060static int dasd_eckd_validate_server(struct dasd_device *device)
Horst Hummel40545572006-06-29 15:08:18 +02001061{
1062 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001063 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001064 int enable_pav;
Horst Hummel40545572006-06-29 15:08:18 +02001065
Horst Hummel40545572006-06-29 15:08:18 +02001066 if (dasd_nopav || MACHINE_IS_VM)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001067 enable_pav = 0;
1068 else
1069 enable_pav = 1;
1070 rc = dasd_eckd_psf_ssc(device, enable_pav);
Horst Hummel8e79a442006-08-24 13:22:36 +02001071 /* may be requested feature is not available on server,
1072 * therefore just report error and go ahead */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001073 private = (struct dasd_eckd_private *) device->private;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001074 DBF_EVENT(DBF_WARNING, "PSF-SSC on storage subsystem %s.%s.%04x "
1075 "returned rc=%d for device: %s",
1076 private->uid.vendor, private->uid.serial,
1077 private->uid.ssid, rc, dev_name(&device->cdev->dev));
Horst Hummel40545572006-06-29 15:08:18 +02001078 /* RE-Read Configuration Data */
1079 return dasd_eckd_read_conf(device);
1080}
1081
1082/*
Horst Hummel3d052592006-04-27 18:40:28 -07001083 * Check device characteristics.
1084 * If the device is accessible using ECKD discipline, the device is enabled.
1085 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086static int
1087dasd_eckd_check_characteristics(struct dasd_device *device)
1088{
1089 struct dasd_eckd_private *private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001090 struct dasd_block *block;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001091 int is_known, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +01001093 if (!ccw_device_is_pathgroup(device->cdev)) {
1094 dev_warn(&device->cdev->dev,
1095 "A channel path group could not be established\n");
1096 return -EIO;
1097 }
1098 if (!ccw_device_is_multipath(device->cdev)) {
1099 dev_info(&device->cdev->dev,
1100 "The DASD is not operating in multipath mode\n");
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 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 */
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02001159 dasd_eckd_read_features(device);
Horst Hummel40545572006-06-29 15:08:18 +02001160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001162 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1163 &private->rdc_data, 64);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001164 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001165 DBF_EVENT(DBF_WARNING,
1166 "Read device characteristics failed, rc=%d for "
1167 "device: %s", rc, dev_name(&device->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001168 goto out_err3;
1169 }
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001170 /* find the vaild cylinder size */
1171 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1172 private->rdc_data.long_no_cyl)
1173 private->real_cyl = private->rdc_data.long_no_cyl;
1174 else
1175 private->real_cyl = private->rdc_data.no_cyl;
1176
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001177 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1178 "with %d cylinders, %d heads, %d sectors\n",
1179 private->rdc_data.dev_type,
1180 private->rdc_data.dev_model,
1181 private->rdc_data.cu_type,
1182 private->rdc_data.cu_model.model,
Sebastian Ott92636b12009-06-12 10:26:37 +02001183 private->real_cyl,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001184 private->rdc_data.trk_per_cyl,
1185 private->rdc_data.sec_per_trk);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001186 return 0;
1187
1188out_err3:
1189 dasd_alias_disconnect_device_from_lcu(device);
1190out_err2:
1191 dasd_free_block(device->block);
1192 device->block = NULL;
1193out_err1:
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001194 kfree(private->conf_data);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001195 kfree(device->private);
1196 device->private = NULL;
Horst Hummel3d052592006-04-27 18:40:28 -07001197 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001200static void dasd_eckd_uncheck_device(struct dasd_device *device)
1201{
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001202 struct dasd_eckd_private *private;
1203
1204 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001205 dasd_alias_disconnect_device_from_lcu(device);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001206 private->ned = NULL;
1207 private->sneq = NULL;
1208 private->vdsneq = NULL;
1209 private->gneq = NULL;
1210 private->conf_len = 0;
1211 kfree(private->conf_data);
1212 private->conf_data = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001213}
1214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215static struct dasd_ccw_req *
1216dasd_eckd_analysis_ccw(struct dasd_device *device)
1217{
1218 struct dasd_eckd_private *private;
1219 struct eckd_count *count_data;
1220 struct LO_eckd_data *LO_data;
1221 struct dasd_ccw_req *cqr;
1222 struct ccw1 *ccw;
1223 int cplength, datasize;
1224 int i;
1225
1226 private = (struct dasd_eckd_private *) device->private;
1227
1228 cplength = 8;
1229 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
Stefan Haberland68b781f2009-09-11 10:28:29 +02001230 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 if (IS_ERR(cqr))
1232 return cqr;
1233 ccw = cqr->cpaddr;
1234 /* Define extent for the first 3 tracks. */
1235 define_extent(ccw++, cqr->data, 0, 2,
1236 DASD_ECKD_CCW_READ_COUNT, device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001237 LO_data = cqr->data + sizeof(struct DE_eckd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 /* Locate record for the first 4 records on track 0. */
1239 ccw[-1].flags |= CCW_FLAG_CC;
1240 locate_record(ccw++, LO_data++, 0, 0, 4,
1241 DASD_ECKD_CCW_READ_COUNT, device, 0);
1242
1243 count_data = private->count_area;
1244 for (i = 0; i < 4; i++) {
1245 ccw[-1].flags |= CCW_FLAG_CC;
1246 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1247 ccw->flags = 0;
1248 ccw->count = 8;
1249 ccw->cda = (__u32)(addr_t) count_data;
1250 ccw++;
1251 count_data++;
1252 }
1253
1254 /* Locate record for the first record on track 2. */
1255 ccw[-1].flags |= CCW_FLAG_CC;
1256 locate_record(ccw++, LO_data++, 2, 0, 1,
1257 DASD_ECKD_CCW_READ_COUNT, device, 0);
1258 /* Read count ccw. */
1259 ccw[-1].flags |= CCW_FLAG_CC;
1260 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1261 ccw->flags = 0;
1262 ccw->count = 8;
1263 ccw->cda = (__u32)(addr_t) count_data;
1264
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001265 cqr->block = NULL;
1266 cqr->startdev = device;
1267 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 cqr->retries = 0;
1269 cqr->buildclk = get_clock();
1270 cqr->status = DASD_CQR_FILLED;
1271 return cqr;
1272}
1273
1274/*
1275 * This is the callback function for the init_analysis cqr. It saves
1276 * the status of the initial analysis ccw before it frees it and kicks
1277 * the device to continue the startup sequence. This will call
1278 * dasd_eckd_do_analysis again (if the devices has not been marked
1279 * for deletion in the meantime).
1280 */
1281static void
1282dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
1283{
1284 struct dasd_eckd_private *private;
1285 struct dasd_device *device;
1286
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001287 device = init_cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 private = (struct dasd_eckd_private *) device->private;
1289 private->init_cqr_status = init_cqr->status;
1290 dasd_sfree_request(init_cqr, device);
1291 dasd_kick_device(device);
1292}
1293
1294static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001295dasd_eckd_start_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
1297 struct dasd_eckd_private *private;
1298 struct dasd_ccw_req *init_cqr;
1299
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001300 private = (struct dasd_eckd_private *) block->base->private;
1301 init_cqr = dasd_eckd_analysis_ccw(block->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 if (IS_ERR(init_cqr))
1303 return PTR_ERR(init_cqr);
1304 init_cqr->callback = dasd_eckd_analysis_callback;
1305 init_cqr->callback_data = NULL;
1306 init_cqr->expires = 5*HZ;
1307 dasd_add_request_head(init_cqr);
1308 return -EAGAIN;
1309}
1310
1311static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001312dasd_eckd_end_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001314 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 struct dasd_eckd_private *private;
1316 struct eckd_count *count_area;
1317 unsigned int sb, blk_per_trk;
1318 int status, i;
1319
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001320 device = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 private = (struct dasd_eckd_private *) device->private;
1322 status = private->init_cqr_status;
1323 private->init_cqr_status = -1;
1324 if (status != DASD_CQR_DONE) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001325 dev_warn(&device->cdev->dev,
1326 "The DASD is not formatted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 return -EMEDIUMTYPE;
1328 }
1329
1330 private->uses_cdl = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /* Check Track 0 for Compatible Disk Layout */
1332 count_area = NULL;
1333 for (i = 0; i < 3; i++) {
1334 if (private->count_area[i].kl != 4 ||
1335 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1336 private->uses_cdl = 0;
1337 break;
1338 }
1339 }
1340 if (i == 3)
1341 count_area = &private->count_area[4];
1342
1343 if (private->uses_cdl == 0) {
1344 for (i = 0; i < 5; i++) {
1345 if ((private->count_area[i].kl != 0) ||
1346 (private->count_area[i].dl !=
1347 private->count_area[0].dl))
1348 break;
1349 }
1350 if (i == 5)
1351 count_area = &private->count_area[0];
1352 } else {
1353 if (private->count_area[3].record == 1)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001354 dev_warn(&device->cdev->dev,
1355 "Track 0 has no records following the VTOC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
1357 if (count_area != NULL && count_area->kl == 0) {
1358 /* we found notthing violating our disk layout */
1359 if (dasd_check_blocksize(count_area->dl) == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001360 block->bp_block = count_area->dl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001362 if (block->bp_block == 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001363 dev_warn(&device->cdev->dev,
1364 "The disk layout of the DASD is not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 return -EMEDIUMTYPE;
1366 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001367 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1368 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1369 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001371 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001372 block->blocks = (private->real_cyl *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 private->rdc_data.trk_per_cyl *
1374 blk_per_trk);
1375
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001376 dev_info(&device->cdev->dev,
1377 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1378 "%s\n", (block->bp_block >> 10),
1379 ((private->real_cyl *
1380 private->rdc_data.trk_per_cyl *
1381 blk_per_trk * (block->bp_block >> 9)) >> 1),
1382 ((blk_per_trk * block->bp_block) >> 10),
1383 private->uses_cdl ?
1384 "compatible disk layout" : "linux disk layout");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 return 0;
1387}
1388
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001389static int dasd_eckd_do_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391 struct dasd_eckd_private *private;
1392
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001393 private = (struct dasd_eckd_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 if (private->init_cqr_status < 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001395 return dasd_eckd_start_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001397 return dasd_eckd_end_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001400static int dasd_eckd_ready_to_online(struct dasd_device *device)
1401{
1402 return dasd_alias_add_device(device);
1403};
1404
1405static int dasd_eckd_online_to_ready(struct dasd_device *device)
1406{
1407 return dasd_alias_remove_device(device);
1408};
1409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001411dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
1413 struct dasd_eckd_private *private;
1414
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001415 private = (struct dasd_eckd_private *) block->base->private;
1416 if (dasd_check_blocksize(block->bp_block) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 geo->sectors = recs_per_track(&private->rdc_data,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001418 0, block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
1420 geo->cylinders = private->rdc_data.no_cyl;
1421 geo->heads = private->rdc_data.trk_per_cyl;
1422 return 0;
1423}
1424
1425static struct dasd_ccw_req *
1426dasd_eckd_format_device(struct dasd_device * device,
1427 struct format_data_t * fdata)
1428{
1429 struct dasd_eckd_private *private;
1430 struct dasd_ccw_req *fcp;
1431 struct eckd_count *ect;
1432 struct ccw1 *ccw;
1433 void *data;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001434 int rpt;
1435 struct ch_t address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 int cplength, datasize;
1437 int i;
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001438 int intensity = 0;
1439 int r0_perm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 private = (struct dasd_eckd_private *) device->private;
1442 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001443 set_ch_t(&address,
1444 fdata->start_unit / private->rdc_data.trk_per_cyl,
1445 fdata->start_unit % private->rdc_data.trk_per_cyl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 /* Sanity checks. */
1448 if (fdata->start_unit >=
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001449 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001450 dev_warn(&device->cdev->dev, "Start track number %d used in "
1451 "formatting is too big\n", fdata->start_unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 return ERR_PTR(-EINVAL);
1453 }
1454 if (fdata->start_unit > fdata->stop_unit) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001455 dev_warn(&device->cdev->dev, "Start track %d used in "
1456 "formatting exceeds end track\n", fdata->start_unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return ERR_PTR(-EINVAL);
1458 }
1459 if (dasd_check_blocksize(fdata->blksize) != 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001460 dev_warn(&device->cdev->dev,
1461 "The DASD cannot be formatted with block size %d\n",
1462 fdata->blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 return ERR_PTR(-EINVAL);
1464 }
1465
1466 /*
1467 * fdata->intensity is a bit string that tells us what to do:
1468 * Bit 0: write record zero
1469 * Bit 1: write home address, currently not supported
1470 * Bit 2: invalidate tracks
1471 * Bit 3: use OS/390 compatible disk layout (cdl)
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001472 * Bit 4: do not allow storage subsystem to modify record zero
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 * Only some bit combinations do make sense.
1474 */
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001475 if (fdata->intensity & 0x10) {
1476 r0_perm = 0;
1477 intensity = fdata->intensity & ~0x10;
1478 } else {
1479 r0_perm = 1;
1480 intensity = fdata->intensity;
1481 }
1482 switch (intensity) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 case 0x00: /* Normal format */
1484 case 0x08: /* Normal format, use cdl. */
1485 cplength = 2 + rpt;
1486 datasize = sizeof(struct DE_eckd_data) +
1487 sizeof(struct LO_eckd_data) +
1488 rpt * sizeof(struct eckd_count);
1489 break;
1490 case 0x01: /* Write record zero and format track. */
1491 case 0x09: /* Write record zero and format track, use cdl. */
1492 cplength = 3 + rpt;
1493 datasize = sizeof(struct DE_eckd_data) +
1494 sizeof(struct LO_eckd_data) +
1495 sizeof(struct eckd_count) +
1496 rpt * sizeof(struct eckd_count);
1497 break;
1498 case 0x04: /* Invalidate track. */
1499 case 0x0c: /* Invalidate track, use cdl. */
1500 cplength = 3;
1501 datasize = sizeof(struct DE_eckd_data) +
1502 sizeof(struct LO_eckd_data) +
1503 sizeof(struct eckd_count);
1504 break;
1505 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001506 dev_warn(&device->cdev->dev, "An I/O control call used "
1507 "incorrect flags 0x%x\n", fdata->intensity);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 return ERR_PTR(-EINVAL);
1509 }
1510 /* Allocate the format ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001511 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 if (IS_ERR(fcp))
1513 return fcp;
1514
1515 data = fcp->data;
1516 ccw = fcp->cpaddr;
1517
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001518 switch (intensity & ~0x08) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 case 0x00: /* Normal format. */
1520 define_extent(ccw++, (struct DE_eckd_data *) data,
1521 fdata->start_unit, fdata->start_unit,
1522 DASD_ECKD_CCW_WRITE_CKD, device);
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001523 /* grant subsystem permission to format R0 */
1524 if (r0_perm)
1525 ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 data += sizeof(struct DE_eckd_data);
1527 ccw[-1].flags |= CCW_FLAG_CC;
1528 locate_record(ccw++, (struct LO_eckd_data *) data,
1529 fdata->start_unit, 0, rpt,
1530 DASD_ECKD_CCW_WRITE_CKD, device,
1531 fdata->blksize);
1532 data += sizeof(struct LO_eckd_data);
1533 break;
1534 case 0x01: /* Write record zero + format track. */
1535 define_extent(ccw++, (struct DE_eckd_data *) data,
1536 fdata->start_unit, fdata->start_unit,
1537 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1538 device);
1539 data += sizeof(struct DE_eckd_data);
1540 ccw[-1].flags |= CCW_FLAG_CC;
1541 locate_record(ccw++, (struct LO_eckd_data *) data,
1542 fdata->start_unit, 0, rpt + 1,
1543 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001544 device->block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 data += sizeof(struct LO_eckd_data);
1546 break;
1547 case 0x04: /* Invalidate track. */
1548 define_extent(ccw++, (struct DE_eckd_data *) data,
1549 fdata->start_unit, fdata->start_unit,
1550 DASD_ECKD_CCW_WRITE_CKD, device);
1551 data += sizeof(struct DE_eckd_data);
1552 ccw[-1].flags |= CCW_FLAG_CC;
1553 locate_record(ccw++, (struct LO_eckd_data *) data,
1554 fdata->start_unit, 0, 1,
1555 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1556 data += sizeof(struct LO_eckd_data);
1557 break;
1558 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001559 if (intensity & 0x01) { /* write record zero */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 ect = (struct eckd_count *) data;
1561 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001562 ect->cyl = address.cyl;
1563 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 ect->record = 0;
1565 ect->kl = 0;
1566 ect->dl = 8;
1567 ccw[-1].flags |= CCW_FLAG_CC;
1568 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1569 ccw->flags = CCW_FLAG_SLI;
1570 ccw->count = 8;
1571 ccw->cda = (__u32)(addr_t) ect;
1572 ccw++;
1573 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001574 if ((intensity & ~0x08) & 0x04) { /* erase track */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 ect = (struct eckd_count *) data;
1576 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001577 ect->cyl = address.cyl;
1578 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 ect->record = 1;
1580 ect->kl = 0;
1581 ect->dl = 0;
1582 ccw[-1].flags |= CCW_FLAG_CC;
1583 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1584 ccw->flags = CCW_FLAG_SLI;
1585 ccw->count = 8;
1586 ccw->cda = (__u32)(addr_t) ect;
1587 } else { /* write remaining records */
1588 for (i = 0; i < rpt; i++) {
1589 ect = (struct eckd_count *) data;
1590 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001591 ect->cyl = address.cyl;
1592 ect->head = address.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 ect->record = i + 1;
1594 ect->kl = 0;
1595 ect->dl = fdata->blksize;
1596 /* Check for special tracks 0-1 when formatting CDL */
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001597 if ((intensity & 0x08) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 fdata->start_unit == 0) {
1599 if (i < 3) {
1600 ect->kl = 4;
1601 ect->dl = sizes_trk0[i] - 4;
Horst Hummel138c0142006-06-29 14:58:12 +02001602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 }
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01001604 if ((intensity & 0x08) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 fdata->start_unit == 1) {
1606 ect->kl = 44;
1607 ect->dl = LABEL_SIZE - 44;
1608 }
1609 ccw[-1].flags |= CCW_FLAG_CC;
1610 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1611 ccw->flags = CCW_FLAG_SLI;
1612 ccw->count = 8;
1613 ccw->cda = (__u32)(addr_t) ect;
1614 ccw++;
1615 }
1616 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001617 fcp->startdev = device;
1618 fcp->memdev = device;
1619 clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags);
1620 fcp->retries = 5; /* set retry counter to enable default ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 fcp->buildclk = get_clock();
1622 fcp->status = DASD_CQR_FILLED;
1623 return fcp;
1624}
1625
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001626static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001628 cqr->status = DASD_CQR_FILLED;
1629 if (cqr->block && (cqr->startdev != cqr->block->base)) {
1630 dasd_eckd_reset_ccw_to_base_io(cqr);
1631 cqr->startdev = cqr->block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001633};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635static dasd_erp_fn_t
1636dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1637{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001638 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 struct ccw_device *cdev = device->cdev;
1640
1641 switch (cdev->id.cu_type) {
1642 case 0x3990:
1643 case 0x2105:
1644 case 0x2107:
1645 case 0x1750:
1646 return dasd_3990_erp_action;
1647 case 0x9343:
1648 case 0x3880:
1649 default:
1650 return dasd_default_erp_action;
1651 }
1652}
1653
1654static dasd_erp_fn_t
1655dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1656{
1657 return dasd_default_erp_postaction;
1658}
1659
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001660
1661static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1662 struct irb *irb)
1663{
1664 char mask;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001665 char *sense = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001666
1667 /* first of all check for state change pending interrupt */
1668 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001669 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001670 dasd_generic_handle_state_change(device);
1671 return;
1672 }
1673
1674 /* summary unit check */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001675 if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001676 (irb->ecw[7] == 0x0D)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001677 dasd_alias_handle_summary_unit_check(device, irb);
1678 return;
1679 }
1680
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001681 sense = dasd_get_sense(irb);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001682 /* service information message SIM */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001683 if (sense && !(sense[27] & DASD_SENSE_BIT_0) &&
1684 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
1685 dasd_3990_erp_handle_sim(device, sense);
Stefan Haberland9d853ca2008-07-17 17:16:41 +02001686 dasd_schedule_device_bh(device);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02001687 return;
1688 }
1689
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001690 if ((scsw_cc(&irb->scsw) == 1) &&
1691 (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
1692 (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) &&
1693 (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) {
Stefan Haberlandada3df92008-10-10 21:33:23 +02001694 /* fake irb do nothing, they are handled elsewhere */
1695 dasd_schedule_device_bh(device);
1696 return;
1697 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001698
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001699 if (!sense) {
Stefan Haberlandada3df92008-10-10 21:33:23 +02001700 /* just report other unsolicited interrupts */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001701 DBF_DEV_EVENT(DBF_ERR, device, "%s",
Stefan Haberlandada3df92008-10-10 21:33:23 +02001702 "unsolicited interrupt received");
1703 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001704 DBF_DEV_EVENT(DBF_ERR, device, "%s",
Stefan Haberlandada3df92008-10-10 21:33:23 +02001705 "unsolicited interrupt received "
1706 "(sense available)");
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02001707 device->discipline->dump_sense_dbf(device, irb, "unsolicited");
Stefan Haberlandada3df92008-10-10 21:33:23 +02001708 }
1709
1710 dasd_schedule_device_bh(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001711 return;
1712};
1713
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001714
1715static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
1716 struct dasd_device *startdev,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001717 struct dasd_block *block,
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001718 struct request *req,
1719 sector_t first_rec,
1720 sector_t last_rec,
1721 sector_t first_trk,
1722 sector_t last_trk,
1723 unsigned int first_offs,
1724 unsigned int last_offs,
1725 unsigned int blk_per_trk,
1726 unsigned int blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727{
1728 struct dasd_eckd_private *private;
1729 unsigned long *idaws;
1730 struct LO_eckd_data *LO_data;
1731 struct dasd_ccw_req *cqr;
1732 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02001733 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 struct bio_vec *bv;
1735 char *dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001736 unsigned int off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 int count, cidaw, cplength, datasize;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001738 sector_t recid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 unsigned char cmd, rcmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001740 int use_prefix;
1741 struct dasd_device *basedev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001743 basedev = block->base;
1744 private = (struct dasd_eckd_private *) basedev->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 if (rq_data_dir(req) == READ)
1746 cmd = DASD_ECKD_CCW_READ_MT;
1747 else if (rq_data_dir(req) == WRITE)
1748 cmd = DASD_ECKD_CCW_WRITE_MT;
1749 else
1750 return ERR_PTR(-EINVAL);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 /* Check struct bio and count the number of blocks for the request. */
1753 count = 0;
1754 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +02001755 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +02001756 if (bv->bv_len & (blksize - 1))
1757 /* Eckd can only do full blocks. */
1758 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001759 count += bv->bv_len >> (block->s2b_shift + 9);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001760#if defined(CONFIG_64BIT)
Jens Axboe6c92e692007-08-16 13:43:12 +02001761 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001762 cidaw += bv->bv_len >> (block->s2b_shift + 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 }
1765 /* Paranoia. */
1766 if (count != last_rec - first_rec + 1)
1767 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001768
1769 /* use the prefix command if available */
1770 use_prefix = private->features.feature[8] & 0x01;
1771 if (use_prefix) {
1772 /* 1x prefix + number of blocks */
1773 cplength = 2 + count;
1774 /* 1x prefix + cidaws*sizeof(long) */
1775 datasize = sizeof(struct PFX_eckd_data) +
1776 sizeof(struct LO_eckd_data) +
1777 cidaw * sizeof(unsigned long);
1778 } else {
1779 /* 1x define extent + 1x locate record + number of blocks */
1780 cplength = 2 + count;
1781 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1782 datasize = sizeof(struct DE_eckd_data) +
1783 sizeof(struct LO_eckd_data) +
1784 cidaw * sizeof(unsigned long);
1785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 /* Find out the number of additional locate record ccws for cdl. */
1787 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1788 if (last_rec >= 2*blk_per_trk)
1789 count = 2*blk_per_trk - first_rec;
1790 cplength += count;
1791 datasize += count*sizeof(struct LO_eckd_data);
1792 }
1793 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001794 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
1795 startdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 if (IS_ERR(cqr))
1797 return cqr;
1798 ccw = cqr->cpaddr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001799 /* First ccw is define extent or prefix. */
1800 if (use_prefix) {
1801 if (prefix(ccw++, cqr->data, first_trk,
1802 last_trk, cmd, basedev, startdev) == -EAGAIN) {
1803 /* Clock not in sync and XRC is enabled.
1804 * Try again later.
1805 */
1806 dasd_sfree_request(cqr, startdev);
1807 return ERR_PTR(-EAGAIN);
1808 }
1809 idaws = (unsigned long *) (cqr->data +
1810 sizeof(struct PFX_eckd_data));
1811 } else {
1812 if (define_extent(ccw++, cqr->data, first_trk,
1813 last_trk, cmd, startdev) == -EAGAIN) {
1814 /* Clock not in sync and XRC is enabled.
1815 * Try again later.
1816 */
1817 dasd_sfree_request(cqr, startdev);
1818 return ERR_PTR(-EAGAIN);
1819 }
1820 idaws = (unsigned long *) (cqr->data +
1821 sizeof(struct DE_eckd_data));
Martin Schwidefskyd54853e2007-02-05 21:18:19 +01001822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 /* Build locate_record+read/write/ccws. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1825 recid = first_rec;
1826 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1827 /* Only standard blocks so there is just one locate record. */
1828 ccw[-1].flags |= CCW_FLAG_CC;
1829 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001830 last_rec - recid + 1, cmd, basedev, blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
NeilBrown5705f702007-09-25 12:35:59 +02001832 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 dst = page_address(bv->bv_page) + bv->bv_offset;
1834 if (dasd_page_cache) {
1835 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -08001836 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if (copy && rq_data_dir(req) == WRITE)
1838 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1839 if (copy)
1840 dst = copy + bv->bv_offset;
1841 }
1842 for (off = 0; off < bv->bv_len; off += blksize) {
1843 sector_t trkid = recid;
1844 unsigned int recoffs = sector_div(trkid, blk_per_trk);
1845 rcmd = cmd;
1846 count = blksize;
1847 /* Locate record for cdl special block ? */
1848 if (private->uses_cdl && recid < 2*blk_per_trk) {
1849 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1850 rcmd |= 0x8;
1851 count = dasd_eckd_cdl_reclen(recid);
Horst Hummelec5883a2005-05-01 08:58:59 -07001852 if (count < blksize &&
1853 rq_data_dir(req) == READ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 memset(dst + count, 0xe5,
1855 blksize - count);
1856 }
1857 ccw[-1].flags |= CCW_FLAG_CC;
1858 locate_record(ccw++, LO_data++,
1859 trkid, recoffs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001860 1, rcmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 }
1862 /* Locate record for standard blocks ? */
1863 if (private->uses_cdl && recid == 2*blk_per_trk) {
1864 ccw[-1].flags |= CCW_FLAG_CC;
1865 locate_record(ccw++, LO_data++,
1866 trkid, recoffs + 1,
1867 last_rec - recid + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001868 cmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 }
1870 /* Read/write ccw. */
1871 ccw[-1].flags |= CCW_FLAG_CC;
1872 ccw->cmd_code = rcmd;
1873 ccw->count = count;
1874 if (idal_is_needed(dst, blksize)) {
1875 ccw->cda = (__u32)(addr_t) idaws;
1876 ccw->flags = CCW_FLAG_IDA;
1877 idaws = idal_create_words(idaws, dst, blksize);
1878 } else {
1879 ccw->cda = (__u32)(addr_t) dst;
1880 ccw->flags = 0;
1881 }
1882 ccw++;
1883 dst += blksize;
1884 recid++;
1885 }
1886 }
Holger Smolinski13de2272009-01-09 12:14:51 +01001887 if (blk_noretry_request(req) ||
1888 block->base->features & DASD_FEATURE_FAILFAST)
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001889 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001890 cqr->startdev = startdev;
1891 cqr->memdev = startdev;
1892 cqr->block = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
1894 cqr->lpm = private->path_data.ppm;
1895 cqr->retries = 256;
1896 cqr->buildclk = get_clock();
1897 cqr->status = DASD_CQR_FILLED;
1898 return cqr;
1899}
1900
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001901static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
1902 struct dasd_device *startdev,
1903 struct dasd_block *block,
1904 struct request *req,
1905 sector_t first_rec,
1906 sector_t last_rec,
1907 sector_t first_trk,
1908 sector_t last_trk,
1909 unsigned int first_offs,
1910 unsigned int last_offs,
1911 unsigned int blk_per_trk,
1912 unsigned int blksize)
1913{
1914 struct dasd_eckd_private *private;
1915 unsigned long *idaws;
1916 struct dasd_ccw_req *cqr;
1917 struct ccw1 *ccw;
1918 struct req_iterator iter;
1919 struct bio_vec *bv;
1920 char *dst, *idaw_dst;
1921 unsigned int cidaw, cplength, datasize;
1922 unsigned int tlf;
1923 sector_t recid;
1924 unsigned char cmd;
1925 struct dasd_device *basedev;
1926 unsigned int trkcount, count, count_to_trk_end;
1927 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
1928 unsigned char new_track, end_idaw;
1929 sector_t trkid;
1930 unsigned int recoffs;
1931
1932 basedev = block->base;
1933 private = (struct dasd_eckd_private *) basedev->private;
1934 if (rq_data_dir(req) == READ)
1935 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
1936 else if (rq_data_dir(req) == WRITE)
1937 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
1938 else
1939 return ERR_PTR(-EINVAL);
1940
1941 /* Track based I/O needs IDAWs for each page, and not just for
1942 * 64 bit addresses. We need additional idals for pages
1943 * that get filled from two tracks, so we use the number
1944 * of records as upper limit.
1945 */
1946 cidaw = last_rec - first_rec + 1;
1947 trkcount = last_trk - first_trk + 1;
1948
1949 /* 1x prefix + one read/write ccw per track */
1950 cplength = 1 + trkcount;
1951
1952 /* on 31-bit we need space for two 32 bit addresses per page
1953 * on 64-bit one 64 bit address
1954 */
1955 datasize = sizeof(struct PFX_eckd_data) +
1956 cidaw * sizeof(unsigned long long);
1957
1958 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001959 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
1960 startdev);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001961 if (IS_ERR(cqr))
1962 return cqr;
1963 ccw = cqr->cpaddr;
1964 /* transfer length factor: how many bytes to read from the last track */
1965 if (first_trk == last_trk)
1966 tlf = last_offs - first_offs + 1;
1967 else
1968 tlf = last_offs + 1;
1969 tlf *= blksize;
1970
1971 if (prefix_LRE(ccw++, cqr->data, first_trk,
1972 last_trk, cmd, basedev, startdev,
1973 1 /* format */, first_offs + 1,
1974 trkcount, blksize,
1975 tlf) == -EAGAIN) {
1976 /* Clock not in sync and XRC is enabled.
1977 * Try again later.
1978 */
1979 dasd_sfree_request(cqr, startdev);
1980 return ERR_PTR(-EAGAIN);
1981 }
1982
1983 /*
1984 * The translation of request into ccw programs must meet the
1985 * following conditions:
1986 * - all idaws but the first and the last must address full pages
1987 * (or 2K blocks on 31-bit)
1988 * - the scope of a ccw and it's idal ends with the track boundaries
1989 */
1990 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
1991 recid = first_rec;
1992 new_track = 1;
1993 end_idaw = 0;
1994 len_to_track_end = 0;
1995 idaw_dst = 0;
1996 idaw_len = 0;
1997 rq_for_each_segment(bv, req, iter) {
1998 dst = page_address(bv->bv_page) + bv->bv_offset;
1999 seg_len = bv->bv_len;
2000 while (seg_len) {
2001 if (new_track) {
2002 trkid = recid;
2003 recoffs = sector_div(trkid, blk_per_trk);
2004 count_to_trk_end = blk_per_trk - recoffs;
2005 count = min((last_rec - recid + 1),
2006 (sector_t)count_to_trk_end);
2007 len_to_track_end = count * blksize;
2008 ccw[-1].flags |= CCW_FLAG_CC;
2009 ccw->cmd_code = cmd;
2010 ccw->count = len_to_track_end;
2011 ccw->cda = (__u32)(addr_t)idaws;
2012 ccw->flags = CCW_FLAG_IDA;
2013 ccw++;
2014 recid += count;
2015 new_track = 0;
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002016 /* first idaw for a ccw may start anywhere */
2017 if (!idaw_dst)
2018 idaw_dst = dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002019 }
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002020 /* If we start a new idaw, we must make sure that it
2021 * starts on an IDA_BLOCK_SIZE boundary.
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002022 * If we continue an idaw, we must make sure that the
2023 * current segment begins where the so far accumulated
2024 * idaw ends
2025 */
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002026 if (!idaw_dst) {
2027 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2028 dasd_sfree_request(cqr, startdev);
2029 return ERR_PTR(-ERANGE);
2030 } else
2031 idaw_dst = dst;
2032 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002033 if ((idaw_dst + idaw_len) != dst) {
2034 dasd_sfree_request(cqr, startdev);
2035 return ERR_PTR(-ERANGE);
2036 }
2037 part_len = min(seg_len, len_to_track_end);
2038 seg_len -= part_len;
2039 dst += part_len;
2040 idaw_len += part_len;
2041 len_to_track_end -= part_len;
2042 /* collected memory area ends on an IDA_BLOCK border,
2043 * -> create an idaw
2044 * idal_create_words will handle cases where idaw_len
2045 * is larger then IDA_BLOCK_SIZE
2046 */
2047 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2048 end_idaw = 1;
2049 /* We also need to end the idaw at track end */
2050 if (!len_to_track_end) {
2051 new_track = 1;
2052 end_idaw = 1;
2053 }
2054 if (end_idaw) {
2055 idaws = idal_create_words(idaws, idaw_dst,
2056 idaw_len);
2057 idaw_dst = 0;
2058 idaw_len = 0;
2059 end_idaw = 0;
2060 }
2061 }
2062 }
2063
2064 if (blk_noretry_request(req) ||
2065 block->base->features & DASD_FEATURE_FAILFAST)
2066 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2067 cqr->startdev = startdev;
2068 cqr->memdev = startdev;
2069 cqr->block = block;
2070 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2071 cqr->lpm = private->path_data.ppm;
2072 cqr->retries = 256;
2073 cqr->buildclk = get_clock();
2074 cqr->status = DASD_CQR_FILLED;
2075 return cqr;
2076}
2077
2078static int prepare_itcw(struct itcw *itcw,
2079 unsigned int trk, unsigned int totrk, int cmd,
2080 struct dasd_device *basedev,
2081 struct dasd_device *startdev,
2082 unsigned int rec_on_trk, int count,
2083 unsigned int blksize,
2084 unsigned int total_data_size,
2085 unsigned int tlf,
2086 unsigned int blk_per_trk)
2087{
2088 struct PFX_eckd_data pfxdata;
2089 struct dasd_eckd_private *basepriv, *startpriv;
2090 struct DE_eckd_data *dedata;
2091 struct LRE_eckd_data *lredata;
2092 struct dcw *dcw;
2093
2094 u32 begcyl, endcyl;
2095 u16 heads, beghead, endhead;
2096 u8 pfx_cmd;
2097
2098 int rc = 0;
2099 int sector = 0;
2100 int dn, d;
2101
2102
2103 /* setup prefix data */
2104 basepriv = (struct dasd_eckd_private *) basedev->private;
2105 startpriv = (struct dasd_eckd_private *) startdev->private;
2106 dedata = &pfxdata.define_extent;
2107 lredata = &pfxdata.locate_record;
2108
2109 memset(&pfxdata, 0, sizeof(pfxdata));
2110 pfxdata.format = 1; /* PFX with LRE */
2111 pfxdata.base_address = basepriv->ned->unit_addr;
2112 pfxdata.base_lss = basepriv->ned->ID;
2113 pfxdata.validity.define_extent = 1;
2114
2115 /* private uid is kept up to date, conf_data may be outdated */
2116 if (startpriv->uid.type != UA_BASE_DEVICE) {
2117 pfxdata.validity.verify_base = 1;
2118 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2119 pfxdata.validity.hyper_pav = 1;
2120 }
2121
2122 switch (cmd) {
2123 case DASD_ECKD_CCW_READ_TRACK_DATA:
2124 dedata->mask.perm = 0x1;
2125 dedata->attributes.operation = basepriv->attrib.operation;
2126 dedata->blk_size = blksize;
2127 dedata->ga_extended |= 0x42;
2128 lredata->operation.orientation = 0x0;
2129 lredata->operation.operation = 0x0C;
2130 lredata->auxiliary.check_bytes = 0x01;
2131 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2132 break;
2133 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2134 dedata->mask.perm = 0x02;
2135 dedata->attributes.operation = basepriv->attrib.operation;
2136 dedata->blk_size = blksize;
2137 rc = check_XRC_on_prefix(&pfxdata, basedev);
2138 dedata->ga_extended |= 0x42;
2139 lredata->operation.orientation = 0x0;
2140 lredata->operation.operation = 0x3F;
2141 lredata->extended_operation = 0x23;
2142 lredata->auxiliary.check_bytes = 0x2;
2143 pfx_cmd = DASD_ECKD_CCW_PFX;
2144 break;
2145 default:
2146 DBF_DEV_EVENT(DBF_ERR, basedev,
2147 "prepare itcw, unknown opcode 0x%x", cmd);
2148 BUG();
2149 break;
2150 }
2151 if (rc)
2152 return rc;
2153
2154 dedata->attributes.mode = 0x3; /* ECKD */
2155
2156 heads = basepriv->rdc_data.trk_per_cyl;
2157 begcyl = trk / heads;
2158 beghead = trk % heads;
2159 endcyl = totrk / heads;
2160 endhead = totrk % heads;
2161
2162 /* check for sequential prestage - enhance cylinder range */
2163 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2164 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2165
2166 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2167 endcyl += basepriv->attrib.nr_cyl;
2168 else
2169 endcyl = (basepriv->real_cyl - 1);
2170 }
2171
2172 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2173 set_ch_t(&dedata->end_ext, endcyl, endhead);
2174
2175 dedata->ep_format = 0x20; /* records per track is valid */
2176 dedata->ep_rec_per_track = blk_per_trk;
2177
2178 if (rec_on_trk) {
2179 switch (basepriv->rdc_data.dev_type) {
2180 case 0x3390:
2181 dn = ceil_quot(blksize + 6, 232);
2182 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2183 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2184 break;
2185 case 0x3380:
2186 d = 7 + ceil_quot(blksize + 12, 32);
2187 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2188 break;
2189 }
2190 }
2191
2192 lredata->auxiliary.length_valid = 1;
2193 lredata->auxiliary.length_scope = 1;
2194 lredata->auxiliary.imbedded_ccw_valid = 1;
2195 lredata->length = tlf;
2196 lredata->imbedded_ccw = cmd;
2197 lredata->count = count;
2198 lredata->sector = sector;
2199 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2200 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2201 lredata->search_arg.head = lredata->seek_addr.head;
2202 lredata->search_arg.record = rec_on_trk;
2203
2204 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2205 &pfxdata, sizeof(pfxdata), total_data_size);
2206
2207 return rc;
2208}
2209
2210static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2211 struct dasd_device *startdev,
2212 struct dasd_block *block,
2213 struct request *req,
2214 sector_t first_rec,
2215 sector_t last_rec,
2216 sector_t first_trk,
2217 sector_t last_trk,
2218 unsigned int first_offs,
2219 unsigned int last_offs,
2220 unsigned int blk_per_trk,
2221 unsigned int blksize)
2222{
2223 struct dasd_eckd_private *private;
2224 struct dasd_ccw_req *cqr;
2225 struct req_iterator iter;
2226 struct bio_vec *bv;
2227 char *dst;
2228 unsigned int trkcount, ctidaw;
2229 unsigned char cmd;
2230 struct dasd_device *basedev;
2231 unsigned int tlf;
2232 struct itcw *itcw;
2233 struct tidaw *last_tidaw = NULL;
2234 int itcw_op;
2235 size_t itcw_size;
2236
2237 basedev = block->base;
2238 private = (struct dasd_eckd_private *) basedev->private;
2239 if (rq_data_dir(req) == READ) {
2240 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2241 itcw_op = ITCW_OP_READ;
2242 } else if (rq_data_dir(req) == WRITE) {
2243 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2244 itcw_op = ITCW_OP_WRITE;
2245 } else
2246 return ERR_PTR(-EINVAL);
2247
2248 /* trackbased I/O needs address all memory via TIDAWs,
2249 * not just for 64 bit addresses. This allows us to map
2250 * each segment directly to one tidaw.
2251 */
2252 trkcount = last_trk - first_trk + 1;
2253 ctidaw = 0;
2254 rq_for_each_segment(bv, req, iter) {
2255 ++ctidaw;
2256 }
2257
2258 /* Allocate the ccw request. */
2259 itcw_size = itcw_calc_size(0, ctidaw, 0);
Stefan Haberland68b781f2009-09-11 10:28:29 +02002260 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002261 if (IS_ERR(cqr))
2262 return cqr;
2263
2264 cqr->cpmode = 1;
2265 cqr->startdev = startdev;
2266 cqr->memdev = startdev;
2267 cqr->block = block;
2268 cqr->expires = 100*HZ;
2269 cqr->buildclk = get_clock();
2270 cqr->status = DASD_CQR_FILLED;
2271 cqr->retries = 10;
2272
2273 /* transfer length factor: how many bytes to read from the last track */
2274 if (first_trk == last_trk)
2275 tlf = last_offs - first_offs + 1;
2276 else
2277 tlf = last_offs + 1;
2278 tlf *= blksize;
2279
2280 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2281 cqr->cpaddr = itcw_get_tcw(itcw);
2282
2283 if (prepare_itcw(itcw, first_trk, last_trk,
2284 cmd, basedev, startdev,
2285 first_offs + 1,
2286 trkcount, blksize,
2287 (last_rec - first_rec + 1) * blksize,
2288 tlf, blk_per_trk) == -EAGAIN) {
2289 /* Clock not in sync and XRC is enabled.
2290 * Try again later.
2291 */
2292 dasd_sfree_request(cqr, startdev);
2293 return ERR_PTR(-EAGAIN);
2294 }
2295
2296 /*
2297 * A tidaw can address 4k of memory, but must not cross page boundaries
2298 * We can let the block layer handle this by setting
2299 * blk_queue_segment_boundary to page boundaries and
2300 * blk_max_segment_size to page size when setting up the request queue.
2301 */
2302 rq_for_each_segment(bv, req, iter) {
2303 dst = page_address(bv->bv_page) + bv->bv_offset;
2304 last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len);
2305 if (IS_ERR(last_tidaw))
2306 return (struct dasd_ccw_req *)last_tidaw;
2307 }
2308
2309 last_tidaw->flags |= 0x80;
2310 itcw_finalize(itcw);
2311
2312 if (blk_noretry_request(req) ||
2313 block->base->features & DASD_FEATURE_FAILFAST)
2314 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2315 cqr->startdev = startdev;
2316 cqr->memdev = startdev;
2317 cqr->block = block;
2318 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
2319 cqr->lpm = private->path_data.ppm;
2320 cqr->retries = 256;
2321 cqr->buildclk = get_clock();
2322 cqr->status = DASD_CQR_FILLED;
2323 return cqr;
2324}
2325
2326static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2327 struct dasd_block *block,
2328 struct request *req)
2329{
2330 int tpm, cmdrtd, cmdwtd;
2331 int use_prefix;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002332#if defined(CONFIG_64BIT)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002333 int fcx_in_css, fcx_in_gneq, fcx_in_features;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002334#endif
2335 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002336 struct dasd_device *basedev;
2337 sector_t first_rec, last_rec;
2338 sector_t first_trk, last_trk;
2339 unsigned int first_offs, last_offs;
2340 unsigned int blk_per_trk, blksize;
2341 int cdlspecial;
2342 struct dasd_ccw_req *cqr;
2343
2344 basedev = block->base;
2345 private = (struct dasd_eckd_private *) basedev->private;
2346
2347 /* Calculate number of blocks/records per track. */
2348 blksize = block->bp_block;
2349 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Stefan Haberland6fca97a2009-10-06 10:34:15 +02002350 if (blk_per_trk == 0)
2351 return ERR_PTR(-EINVAL);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002352 /* Calculate record id of first and last block. */
Tejun Heo83096eb2009-05-07 22:24:39 +09002353 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002354 first_offs = sector_div(first_trk, blk_per_trk);
2355 last_rec = last_trk =
Tejun Heo83096eb2009-05-07 22:24:39 +09002356 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002357 last_offs = sector_div(last_trk, blk_per_trk);
2358 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2359
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002360 /* is transport mode supported? */
2361#if defined(CONFIG_64BIT)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002362 fcx_in_css = css_general_characteristics.fcx;
2363 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
2364 fcx_in_features = private->features.feature[40] & 0x80;
2365 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02002366#else
2367 tpm = 0;
2368#endif
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002369
2370 /* is read track data and write track data in command mode supported? */
2371 cmdrtd = private->features.feature[9] & 0x20;
2372 cmdwtd = private->features.feature[12] & 0x40;
2373 use_prefix = private->features.feature[8] & 0x01;
2374
2375 cqr = NULL;
2376 if (cdlspecial || dasd_page_cache) {
2377 /* do nothing, just fall through to the cmd mode single case */
2378 } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) {
2379 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2380 first_rec, last_rec,
2381 first_trk, last_trk,
2382 first_offs, last_offs,
2383 blk_per_trk, blksize);
2384 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2385 cqr = NULL;
2386 } else if (use_prefix &&
2387 (((rq_data_dir(req) == READ) && cmdrtd) ||
2388 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
2389 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2390 first_rec, last_rec,
2391 first_trk, last_trk,
2392 first_offs, last_offs,
2393 blk_per_trk, blksize);
2394 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2395 cqr = NULL;
2396 }
2397 if (!cqr)
2398 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2399 first_rec, last_rec,
2400 first_trk, last_trk,
2401 first_offs, last_offs,
2402 blk_per_trk, blksize);
2403 return cqr;
2404}
2405
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406static int
2407dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2408{
2409 struct dasd_eckd_private *private;
2410 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02002411 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 struct bio_vec *bv;
2413 char *dst, *cda;
2414 unsigned int blksize, blk_per_trk, off;
2415 sector_t recid;
NeilBrown5705f702007-09-25 12:35:59 +02002416 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
2418 if (!dasd_page_cache)
2419 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002420 private = (struct dasd_eckd_private *) cqr->block->base->private;
2421 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Tejun Heo83096eb2009-05-07 22:24:39 +09002423 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 ccw = cqr->cpaddr;
2425 /* Skip over define extent & locate record. */
2426 ccw++;
2427 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2428 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +02002429 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 dst = page_address(bv->bv_page) + bv->bv_offset;
2431 for (off = 0; off < bv->bv_len; off += blksize) {
2432 /* Skip locate record. */
2433 if (private->uses_cdl && recid <= 2*blk_per_trk)
2434 ccw++;
2435 if (dst) {
2436 if (ccw->flags & CCW_FLAG_IDA)
2437 cda = *((char **)((addr_t) ccw->cda));
2438 else
2439 cda = (char *)((addr_t) ccw->cda);
2440 if (dst != cda) {
2441 if (rq_data_dir(req) == READ)
2442 memcpy(dst, cda, bv->bv_len);
2443 kmem_cache_free(dasd_page_cache,
2444 (void *)((addr_t)cda & PAGE_MASK));
2445 }
2446 dst = NULL;
2447 }
2448 ccw++;
2449 recid++;
2450 }
2451 }
2452out:
2453 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002454 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 return status;
2456}
2457
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002458/*
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002459 * Modify ccw/tcw in cqr so it can be started on a base device.
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002460 *
2461 * Note that this is not enough to restart the cqr!
2462 * Either reset cqr->startdev as well (summary unit check handling)
2463 * or restart via separate cqr (as in ERP handling).
2464 */
2465void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
2466{
2467 struct ccw1 *ccw;
2468 struct PFX_eckd_data *pfxdata;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002469 struct tcw *tcw;
2470 struct tccb *tccb;
2471 struct dcw *dcw;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002472
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002473 if (cqr->cpmode == 1) {
2474 tcw = cqr->cpaddr;
2475 tccb = tcw_get_tccb(tcw);
2476 dcw = (struct dcw *)&tccb->tca[0];
2477 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002478 pfxdata->validity.verify_base = 0;
2479 pfxdata->validity.hyper_pav = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002480 } else {
2481 ccw = cqr->cpaddr;
2482 pfxdata = cqr->data;
2483 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
2484 pfxdata->validity.verify_base = 0;
2485 pfxdata->validity.hyper_pav = 0;
2486 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002487 }
2488}
2489
2490#define DASD_ECKD_CHANQ_MAX_SIZE 4
2491
2492static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
2493 struct dasd_block *block,
2494 struct request *req)
2495{
2496 struct dasd_eckd_private *private;
2497 struct dasd_device *startdev;
2498 unsigned long flags;
2499 struct dasd_ccw_req *cqr;
2500
2501 startdev = dasd_alias_get_start_dev(base);
2502 if (!startdev)
2503 startdev = base;
2504 private = (struct dasd_eckd_private *) startdev->private;
2505 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
2506 return ERR_PTR(-EBUSY);
2507
2508 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
2509 private->count++;
2510 cqr = dasd_eckd_build_cp(startdev, block, req);
2511 if (IS_ERR(cqr))
2512 private->count--;
2513 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
2514 return cqr;
2515}
2516
2517static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
2518 struct request *req)
2519{
2520 struct dasd_eckd_private *private;
2521 unsigned long flags;
2522
2523 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
2524 private = (struct dasd_eckd_private *) cqr->memdev->private;
2525 private->count--;
2526 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
2527 return dasd_eckd_free_cp(cqr, req);
2528}
2529
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530static int
2531dasd_eckd_fill_info(struct dasd_device * device,
2532 struct dasd_information2_t * info)
2533{
2534 struct dasd_eckd_private *private;
2535
2536 private = (struct dasd_eckd_private *) device->private;
2537 info->label_block = 2;
2538 info->FBA_layout = private->uses_cdl ? 0 : 1;
2539 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
2540 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
2541 memcpy(info->characteristics, &private->rdc_data,
2542 sizeof(struct dasd_eckd_characteristics));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02002543 info->confdata_size = min((unsigned long)private->conf_len,
2544 sizeof(info->configuration_data));
2545 memcpy(info->configuration_data, private->conf_data,
2546 info->confdata_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 return 0;
2548}
2549
2550/*
2551 * SECTION: ioctl functions for eckd devices.
2552 */
2553
2554/*
2555 * Release device ioctl.
Horst Hummel138c0142006-06-29 14:58:12 +02002556 * Buils a channel programm to releases a prior reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 * (see dasd_eckd_reserve) device.
2558 */
2559static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002560dasd_eckd_release(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 struct dasd_ccw_req *cqr;
2563 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002564 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
2566 if (!capable(CAP_SYS_ADMIN))
2567 return -EACCES;
2568
Stefan Haberland68b781f2009-09-11 10:28:29 +02002569 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002571 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 "Could not allocate initialization request");
2573 return PTR_ERR(cqr);
2574 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002575 ccw = cqr->cpaddr;
2576 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
2577 ccw->flags |= CCW_FLAG_SLI;
2578 ccw->count = 32;
2579 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002580 cqr->startdev = device;
2581 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002583 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002584 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 cqr->expires = 2 * HZ;
2586 cqr->buildclk = get_clock();
2587 cqr->status = DASD_CQR_FILLED;
2588
2589 rc = dasd_sleep_on_immediatly(cqr);
2590
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002591 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 return rc;
2593}
2594
2595/*
2596 * Reserve device ioctl.
2597 * Options are set to 'synchronous wait for interrupt' and
Horst Hummel138c0142006-06-29 14:58:12 +02002598 * 'timeout the request'. This leads to a terminate IO if
2599 * the interrupt is outstanding for a certain time.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 */
2601static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002602dasd_eckd_reserve(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct dasd_ccw_req *cqr;
2605 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002606 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
2608 if (!capable(CAP_SYS_ADMIN))
2609 return -EACCES;
2610
Stefan Haberland68b781f2009-09-11 10:28:29 +02002611 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002613 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 "Could not allocate initialization request");
2615 return PTR_ERR(cqr);
2616 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002617 ccw = cqr->cpaddr;
2618 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
2619 ccw->flags |= CCW_FLAG_SLI;
2620 ccw->count = 32;
2621 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002622 cqr->startdev = device;
2623 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002625 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002626 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 cqr->expires = 2 * HZ;
2628 cqr->buildclk = get_clock();
2629 cqr->status = DASD_CQR_FILLED;
2630
2631 rc = dasd_sleep_on_immediatly(cqr);
2632
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002633 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 return rc;
2635}
2636
2637/*
2638 * Steal lock ioctl - unconditional reserve device.
Horst Hummel138c0142006-06-29 14:58:12 +02002639 * Buils a channel programm to break a device's reservation.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 * (unconditional reserve)
2641 */
2642static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002643dasd_eckd_steal_lock(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 struct dasd_ccw_req *cqr;
2646 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002647 struct ccw1 *ccw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
2649 if (!capable(CAP_SYS_ADMIN))
2650 return -EACCES;
2651
Stefan Haberland68b781f2009-09-11 10:28:29 +02002652 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002654 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 "Could not allocate initialization request");
2656 return PTR_ERR(cqr);
2657 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002658 ccw = cqr->cpaddr;
2659 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
2660 ccw->flags |= CCW_FLAG_SLI;
2661 ccw->count = 32;
2662 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002663 cqr->startdev = device;
2664 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002666 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01002667 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 cqr->expires = 2 * HZ;
2669 cqr->buildclk = get_clock();
2670 cqr->status = DASD_CQR_FILLED;
2671
2672 rc = dasd_sleep_on_immediatly(cqr);
2673
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002674 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 return rc;
2676}
2677
2678/*
2679 * Read performance statistics
2680 */
2681static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002682dasd_eckd_performance(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 struct dasd_psf_prssd_data *prssdp;
2685 struct dasd_rssd_perf_stats_t *stats;
2686 struct dasd_ccw_req *cqr;
2687 struct ccw1 *ccw;
2688 int rc;
2689
Stefan Haberland68b781f2009-09-11 10:28:29 +02002690 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002691 (sizeof(struct dasd_psf_prssd_data) +
2692 sizeof(struct dasd_rssd_perf_stats_t)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 device);
2694 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002695 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 "Could not allocate initialization request");
2697 return PTR_ERR(cqr);
2698 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002699 cqr->startdev = device;
2700 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 cqr->retries = 0;
2702 cqr->expires = 10 * HZ;
2703
2704 /* Prepare for Read Subsystem Data */
2705 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002706 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 prssdp->order = PSF_ORDER_PRSSD;
Joe Perches5d67d162008-01-26 14:11:20 +01002708 prssdp->suborder = 0x01; /* Performance Statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
2710
2711 ccw = cqr->cpaddr;
2712 ccw->cmd_code = DASD_ECKD_CCW_PSF;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002713 ccw->count = sizeof(struct dasd_psf_prssd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 ccw->flags |= CCW_FLAG_CC;
2715 ccw->cda = (__u32)(addr_t) prssdp;
2716
2717 /* Read Subsystem Data - Performance Statistics */
2718 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002719 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721 ccw++;
2722 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002723 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 ccw->cda = (__u32)(addr_t) stats;
2725
2726 cqr->buildclk = get_clock();
2727 cqr->status = DASD_CQR_FILLED;
2728 rc = dasd_sleep_on(cqr);
2729 if (rc == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2731 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002732 if (copy_to_user(argp, stats,
2733 sizeof(struct dasd_rssd_perf_stats_t)))
2734 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002736 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 return rc;
2738}
2739
2740/*
2741 * Get attributes (cache operations)
2742 * Returnes the cache attributes used in Define Extend (DE).
2743 */
2744static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002745dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002747 struct dasd_eckd_private *private =
2748 (struct dasd_eckd_private *)device->private;
2749 struct attrib_data_t attrib = private->attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 int rc;
2751
2752 if (!capable(CAP_SYS_ADMIN))
2753 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002754 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 return -EINVAL;
2756
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002757 rc = 0;
2758 if (copy_to_user(argp, (long *) &attrib,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002759 sizeof(struct attrib_data_t)))
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002760 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
2762 return rc;
2763}
2764
2765/*
2766 * Set attributes (cache operations)
2767 * Stores the attributes for cache operation to be used in Define Extend (DE).
2768 */
2769static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002770dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002772 struct dasd_eckd_private *private =
2773 (struct dasd_eckd_private *)device->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 struct attrib_data_t attrib;
2775
2776 if (!capable(CAP_SYS_ADMIN))
2777 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002778 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 return -EINVAL;
2780
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002781 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 private->attrib = attrib;
2784
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002785 dev_info(&device->cdev->dev,
2786 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
2787 private->attrib.operation, private->attrib.nr_cyl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 return 0;
2789}
2790
Nigel Hislopab1d8482008-10-10 21:33:25 +02002791/*
2792 * Issue syscall I/O to EMC Symmetrix array.
2793 * CCWs are PSF and RSSD
2794 */
2795static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2796{
2797 struct dasd_symmio_parms usrparm;
2798 char *psf_data, *rssd_result;
2799 struct dasd_ccw_req *cqr;
2800 struct ccw1 *ccw;
2801 int rc;
2802
2803 /* Copy parms from caller */
2804 rc = -EFAULT;
2805 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2806 goto out;
2807#ifndef CONFIG_64BIT
2808 /* Make sure pointers are sane even on 31 bit. */
2809 if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) {
2810 rc = -EINVAL;
2811 goto out;
2812 }
2813#endif
2814 /* alloc I/O data area */
2815 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2816 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2817 if (!psf_data || !rssd_result) {
2818 rc = -ENOMEM;
2819 goto out_free;
2820 }
2821
2822 /* get syscall header from user space */
2823 rc = -EFAULT;
2824 if (copy_from_user(psf_data,
2825 (void __user *)(unsigned long) usrparm.psf_data,
2826 usrparm.psf_data_len))
2827 goto out_free;
2828
2829 /* sanity check on syscall header */
2830 if (psf_data[0] != 0x17 && psf_data[1] != 0xce) {
2831 rc = -EINVAL;
2832 goto out_free;
2833 }
2834
2835 /* setup CCWs for PSF + RSSD */
Stefan Haberland68b781f2009-09-11 10:28:29 +02002836 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
Nigel Hislopab1d8482008-10-10 21:33:25 +02002837 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002838 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Nigel Hislopab1d8482008-10-10 21:33:25 +02002839 "Could not allocate initialization request");
2840 rc = PTR_ERR(cqr);
2841 goto out_free;
2842 }
2843
2844 cqr->startdev = device;
2845 cqr->memdev = device;
2846 cqr->retries = 3;
2847 cqr->expires = 10 * HZ;
2848 cqr->buildclk = get_clock();
2849 cqr->status = DASD_CQR_FILLED;
2850
2851 /* Build the ccws */
2852 ccw = cqr->cpaddr;
2853
2854 /* PSF ccw */
2855 ccw->cmd_code = DASD_ECKD_CCW_PSF;
2856 ccw->count = usrparm.psf_data_len;
2857 ccw->flags |= CCW_FLAG_CC;
2858 ccw->cda = (__u32)(addr_t) psf_data;
2859
2860 ccw++;
2861
2862 /* RSSD ccw */
2863 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2864 ccw->count = usrparm.rssd_result_len;
2865 ccw->flags = CCW_FLAG_SLI ;
2866 ccw->cda = (__u32)(addr_t) rssd_result;
2867
2868 rc = dasd_sleep_on(cqr);
2869 if (rc)
2870 goto out_sfree;
2871
2872 rc = -EFAULT;
2873 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
2874 rssd_result, usrparm.rssd_result_len))
2875 goto out_sfree;
2876 rc = 0;
2877
2878out_sfree:
2879 dasd_sfree_request(cqr, cqr->memdev);
2880out_free:
2881 kfree(rssd_result);
2882 kfree(psf_data);
2883out:
2884 DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc);
2885 return rc;
2886}
2887
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002888static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002889dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002890{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002891 struct dasd_device *device = block->base;
2892
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002893 switch (cmd) {
2894 case BIODASDGATTR:
2895 return dasd_eckd_get_attrib(device, argp);
2896 case BIODASDSATTR:
2897 return dasd_eckd_set_attrib(device, argp);
2898 case BIODASDPSRD:
2899 return dasd_eckd_performance(device, argp);
2900 case BIODASDRLSE:
2901 return dasd_eckd_release(device);
2902 case BIODASDRSRV:
2903 return dasd_eckd_reserve(device);
2904 case BIODASDSLCK:
2905 return dasd_eckd_steal_lock(device);
Nigel Hislopab1d8482008-10-10 21:33:25 +02002906 case BIODASDSYMMIO:
2907 return dasd_symm_io(device, argp);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08002908 default:
2909 return -ENOIOCTLCMD;
2910 }
2911}
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913/*
Horst Hummel445b5b42006-06-29 14:57:52 +02002914 * Dump the range of CCWs into 'page' buffer
2915 * and return number of printed chars.
2916 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002917static int
Horst Hummel445b5b42006-06-29 14:57:52 +02002918dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
2919{
2920 int len, count;
2921 char *datap;
2922
2923 len = 0;
2924 while (from <= to) {
2925 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2926 " CCW %p: %08X %08X DAT:",
2927 from, ((int *) from)[0], ((int *) from)[1]);
2928
2929 /* get pointer to data (consider IDALs) */
2930 if (from->flags & CCW_FLAG_IDA)
2931 datap = (char *) *((addr_t *) (addr_t) from->cda);
2932 else
2933 datap = (char *) ((addr_t) from->cda);
2934
2935 /* dump data (max 32 bytes) */
2936 for (count = 0; count < from->count && count < 32; count++) {
2937 if (count % 8 == 0) len += sprintf(page + len, " ");
2938 if (count % 4 == 0) len += sprintf(page + len, " ");
2939 len += sprintf(page + len, "%02x", datap[count]);
2940 }
2941 len += sprintf(page + len, "\n");
2942 from++;
2943 }
2944 return len;
2945}
2946
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002947static void
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02002948dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
2949 char *reason)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002950{
2951 u64 *sense;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002952
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02002953 sense = (u64 *) dasd_get_sense(irb);
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002954 if (sense) {
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02002955 DBF_DEV_EVENT(DBF_EMERG, device,
2956 "%s: %s %02x%02x%02x %016llx %016llx %016llx "
2957 "%016llx", reason,
2958 scsw_is_tm(&irb->scsw) ? "t" : "c",
2959 scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
2960 scsw_dstat(&irb->scsw), sense[0], sense[1],
2961 sense[2], sense[3]);
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002962 } else {
2963 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
2964 "SORRY - NO VALID SENSE AVAILABLE\n");
2965 }
2966}
2967
Horst Hummel445b5b42006-06-29 14:57:52 +02002968/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 * Print sense data and related channel program.
2970 * Parts are printed because printk buffer is only 1024 bytes.
2971 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002972static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002973 struct dasd_ccw_req *req, struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 char *page;
Horst Hummel445b5b42006-06-29 14:57:52 +02002976 struct ccw1 *first, *last, *fail, *from, *to;
2977 int len, sl, sct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
2979 page = (char *) get_zeroed_page(GFP_ATOMIC);
2980 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002981 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2982 "No memory to dump sense data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return;
2984 }
Horst Hummel445b5b42006-06-29 14:57:52 +02002985 /* dump the sense data */
2986 len = sprintf(page, KERN_ERR PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02002988 dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02002990 " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d\n",
2991 req, scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
2992 scsw_cc(&irb->scsw), req->intrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2994 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02002995 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02002996 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 if (irb->esw.esw0.erw.cons) {
2998 for (sl = 0; sl < 4; sl++) {
2999 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3000 " Sense(hex) %2d-%2d:",
3001 (8 * sl), ((8 * sl) + 7));
3002
3003 for (sct = 0; sct < 8; sct++) {
3004 len += sprintf(page + len, " %02x",
3005 irb->ecw[8 * sl + sct]);
3006 }
3007 len += sprintf(page + len, "\n");
3008 }
3009
3010 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3011 /* 24 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02003012 sprintf(page + len, KERN_ERR PRINTK_HEADER
3013 " 24 Byte: %x MSG %x, "
3014 "%s MSGb to SYSOP\n",
3015 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3016 irb->ecw[1] & 0x10 ? "" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 } else {
3018 /* 32 Byte Sense Data */
Horst Hummel445b5b42006-06-29 14:57:52 +02003019 sprintf(page + len, KERN_ERR PRINTK_HEADER
3020 " 32 Byte: Format: %x "
3021 "Exception class %x\n",
3022 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 }
3024 } else {
Horst Hummel445b5b42006-06-29 14:57:52 +02003025 sprintf(page + len, KERN_ERR PRINTK_HEADER
3026 " SORRY - NO VALID SENSE AVAILABLE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 }
Horst Hummel445b5b42006-06-29 14:57:52 +02003028 printk("%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003030 if (req) {
3031 /* req == NULL for unsolicited interrupts */
3032 /* dump the Channel Program (max 140 Bytes per line) */
3033 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3034 first = req->cpaddr;
3035 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3036 to = min(first + 6, last);
3037 len = sprintf(page, KERN_ERR PRINTK_HEADER
3038 " Related CP in req: %p\n", req);
3039 dasd_eckd_dump_ccw_range(first, to, page + len);
Horst Hummel445b5b42006-06-29 14:57:52 +02003040 printk("%s", page);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003041
3042 /* print failing CCW area (maximum 4) */
3043 /* scsw->cda is either valid or zero */
3044 len = 0;
3045 from = ++to;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02003046 fail = (struct ccw1 *)(addr_t)
3047 irb->scsw.cmd.cpa; /* failing CCW */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003048 if (from < fail - 2) {
3049 from = fail - 2; /* there is a gap - print header */
3050 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3051 }
3052 to = min(fail + 1, last);
3053 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3054
3055 /* print last CCWs (maximum 2) */
3056 from = max(from, ++to);
3057 if (from < last - 1) {
3058 from = last - 1; /* there is a gap - print header */
3059 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3060 }
3061 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3062 if (len > 0)
3063 printk("%s", page);
3064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 free_page((unsigned long) page);
3066}
3067
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003068
3069/*
3070 * Print sense data from a tcw.
3071 */
3072static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3073 struct dasd_ccw_req *req, struct irb *irb)
3074{
3075 char *page;
3076 int len, sl, sct, residual;
3077
3078 struct tsb *tsb;
3079 u8 *sense;
3080
3081
3082 page = (char *) get_zeroed_page(GFP_ATOMIC);
3083 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003084 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003085 "No memory to dump sense data");
3086 return;
3087 }
3088 /* dump the sense data */
3089 len = sprintf(page, KERN_ERR PRINTK_HEADER
3090 " I/O status report for device %s:\n",
3091 dev_name(&device->cdev->dev));
3092 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02003093 " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d "
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003094 "fcxs: 0x%02X schxs: 0x%02X\n", req,
3095 scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02003096 scsw_cc(&irb->scsw), req->intrc,
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003097 irb->scsw.tm.fcxs, irb->scsw.tm.schxs);
3098 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3099 " device %s: Failing TCW: %p\n",
3100 dev_name(&device->cdev->dev),
3101 (void *) (addr_t) irb->scsw.tm.tcw);
3102
3103 tsb = NULL;
3104 sense = NULL;
3105 if (irb->scsw.tm.tcw)
3106 tsb = tcw_get_tsb(
3107 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3108
3109 if (tsb && (irb->scsw.tm.fcxs == 0x01)) {
3110 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3111 " tsb->length %d\n", tsb->length);
3112 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3113 " tsb->flags %x\n", tsb->flags);
3114 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3115 " tsb->dcw_offset %d\n", tsb->dcw_offset);
3116 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3117 " tsb->count %d\n", tsb->count);
3118 residual = tsb->count - 28;
3119 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3120 " residual %d\n", residual);
3121
3122 switch (tsb->flags & 0x07) {
3123 case 1: /* tsa_iostat */
3124 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3125 " tsb->tsa.iostat.dev_time %d\n",
3126 tsb->tsa.iostat.dev_time);
3127 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3128 " tsb->tsa.iostat.def_time %d\n",
3129 tsb->tsa.iostat.def_time);
3130 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3131 " tsb->tsa.iostat.queue_time %d\n",
3132 tsb->tsa.iostat.queue_time);
3133 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3134 " tsb->tsa.iostat.dev_busy_time %d\n",
3135 tsb->tsa.iostat.dev_busy_time);
3136 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3137 " tsb->tsa.iostat.dev_act_time %d\n",
3138 tsb->tsa.iostat.dev_act_time);
3139 sense = tsb->tsa.iostat.sense;
3140 break;
3141 case 2: /* ts_ddpc */
3142 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3143 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3144 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3145 " tsb->tsa.ddpc.rcq: ");
3146 for (sl = 0; sl < 16; sl++) {
3147 for (sct = 0; sct < 8; sct++) {
3148 len += sprintf(page + len, " %02x",
3149 tsb->tsa.ddpc.rcq[sl]);
3150 }
3151 len += sprintf(page + len, "\n");
3152 }
3153 sense = tsb->tsa.ddpc.sense;
3154 break;
3155 case 3: /* tsa_intrg */
3156 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3157 " tsb->tsa.intrg.: not supportet yet \n");
3158 break;
3159 }
3160
3161 if (sense) {
3162 for (sl = 0; sl < 4; sl++) {
3163 len += sprintf(page + len,
3164 KERN_ERR PRINTK_HEADER
3165 " Sense(hex) %2d-%2d:",
3166 (8 * sl), ((8 * sl) + 7));
3167 for (sct = 0; sct < 8; sct++) {
3168 len += sprintf(page + len, " %02x",
3169 sense[8 * sl + sct]);
3170 }
3171 len += sprintf(page + len, "\n");
3172 }
3173
3174 if (sense[27] & DASD_SENSE_BIT_0) {
3175 /* 24 Byte Sense Data */
3176 sprintf(page + len, KERN_ERR PRINTK_HEADER
3177 " 24 Byte: %x MSG %x, "
3178 "%s MSGb to SYSOP\n",
3179 sense[7] >> 4, sense[7] & 0x0f,
3180 sense[1] & 0x10 ? "" : "no");
3181 } else {
3182 /* 32 Byte Sense Data */
3183 sprintf(page + len, KERN_ERR PRINTK_HEADER
3184 " 32 Byte: Format: %x "
3185 "Exception class %x\n",
3186 sense[6] & 0x0f, sense[22] >> 4);
3187 }
3188 } else {
3189 sprintf(page + len, KERN_ERR PRINTK_HEADER
3190 " SORRY - NO VALID SENSE AVAILABLE\n");
3191 }
3192 } else {
3193 sprintf(page + len, KERN_ERR PRINTK_HEADER
3194 " SORRY - NO TSB DATA AVAILABLE\n");
3195 }
3196 printk("%s", page);
3197 free_page((unsigned long) page);
3198}
3199
3200static void dasd_eckd_dump_sense(struct dasd_device *device,
3201 struct dasd_ccw_req *req, struct irb *irb)
3202{
3203 if (req && scsw_is_tm(&req->irb.scsw))
3204 dasd_eckd_dump_sense_tcw(device, req, irb);
3205 else
3206 dasd_eckd_dump_sense_ccw(device, req, irb);
3207}
3208
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003209int dasd_eckd_pm_freeze(struct dasd_device *device)
3210{
3211 /*
3212 * the device should be disconnected from our LCU structure
3213 * on restore we will reconnect it and reread LCU specific
3214 * information like PAV support that might have changed
3215 */
3216 dasd_alias_remove_device(device);
3217 dasd_alias_disconnect_device_from_lcu(device);
3218
3219 return 0;
3220}
3221
3222int dasd_eckd_restore_device(struct dasd_device *device)
3223{
3224 struct dasd_eckd_private *private;
Stefan Haberland6fca97a2009-10-06 10:34:15 +02003225 struct dasd_eckd_characteristics temp_rdc_data;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003226 int is_known, rc;
3227 struct dasd_uid temp_uid;
Stefan Haberlanda7602f62009-10-14 12:43:46 +02003228 unsigned long flags;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003229
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003230 private = (struct dasd_eckd_private *) device->private;
3231
3232 /* Read Configuration Data */
3233 rc = dasd_eckd_read_conf(device);
3234 if (rc)
3235 goto out_err;
3236
3237 /* Generate device unique id and register in devmap */
3238 rc = dasd_eckd_generate_uid(device, &private->uid);
3239 dasd_get_uid(device->cdev, &temp_uid);
3240 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
Stefan Haberlanda7602f62009-10-14 12:43:46 +02003241 dev_err(&device->cdev->dev, "The UID of the DASD has "
3242 "changed\n");
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003243 if (rc)
3244 goto out_err;
3245 dasd_set_uid(device->cdev, &private->uid);
3246
3247 /* register lcu with alias handling, enable PAV if this is a new lcu */
3248 is_known = dasd_alias_make_device_known_to_lcu(device);
3249 if (is_known < 0)
3250 return is_known;
3251 if (!is_known) {
3252 /* new lcu found */
3253 rc = dasd_eckd_validate_server(device); /* will switch pav on */
3254 if (rc)
3255 goto out_err;
3256 }
3257
3258 /* Read Feature Codes */
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02003259 dasd_eckd_read_features(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003260
3261 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +02003262 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
Stefan Haberland6fca97a2009-10-06 10:34:15 +02003263 &temp_rdc_data, 64);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003264 if (rc) {
3265 DBF_EVENT(DBF_WARNING,
3266 "Read device characteristics failed, rc=%d for "
3267 "device: %s", rc, dev_name(&device->cdev->dev));
3268 goto out_err;
3269 }
Stefan Haberlanda7602f62009-10-14 12:43:46 +02003270 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Haberland6fca97a2009-10-06 10:34:15 +02003271 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
Stefan Haberlanda7602f62009-10-14 12:43:46 +02003272 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003273
3274 /* add device to alias management */
3275 dasd_alias_add_device(device);
3276
3277 return 0;
3278
3279out_err:
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003280 return -1;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003281}
3282
3283static struct ccw_driver dasd_eckd_driver = {
3284 .name = "dasd-eckd",
3285 .owner = THIS_MODULE,
3286 .ids = dasd_eckd_ids,
3287 .probe = dasd_eckd_probe,
3288 .remove = dasd_generic_remove,
3289 .set_offline = dasd_generic_set_offline,
3290 .set_online = dasd_eckd_set_online,
3291 .notify = dasd_generic_notify,
3292 .freeze = dasd_generic_pm_freeze,
3293 .thaw = dasd_generic_restore_device,
3294 .restore = dasd_generic_restore_device,
3295};
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003296
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297/*
3298 * max_blocks is dependent on the amount of storage that is available
3299 * in the static io buffer for each device. Currently each device has
3300 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
3301 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
3302 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
3303 * addition we have one define extent ccw + 16 bytes of data and one
3304 * locate record ccw + 16 bytes of data. That makes:
3305 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
3306 * We want to fit two into the available memory so that we can immediately
3307 * start the next request if one finishes off. That makes 249.5 blocks
3308 * for one request. Give a little safety and the result is 240.
3309 */
3310static struct dasd_discipline dasd_eckd_discipline = {
3311 .owner = THIS_MODULE,
3312 .name = "ECKD",
3313 .ebcname = "ECKD",
3314 .max_blocks = 240,
3315 .check_device = dasd_eckd_check_characteristics,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003316 .uncheck_device = dasd_eckd_uncheck_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 .do_analysis = dasd_eckd_do_analysis,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003318 .ready_to_online = dasd_eckd_ready_to_online,
3319 .online_to_ready = dasd_eckd_online_to_ready,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 .fill_geometry = dasd_eckd_fill_geometry,
3321 .start_IO = dasd_start_IO,
3322 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003323 .handle_terminated_request = dasd_eckd_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 .format_device = dasd_eckd_format_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 .erp_action = dasd_eckd_erp_action,
3326 .erp_postaction = dasd_eckd_erp_postaction,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003327 .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
3328 .build_cp = dasd_eckd_build_alias_cp,
3329 .free_cp = dasd_eckd_free_alias_cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 .dump_sense = dasd_eckd_dump_sense,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003331 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 .fill_info = dasd_eckd_fill_info,
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003333 .ioctl = dasd_eckd_ioctl,
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003334 .freeze = dasd_eckd_pm_freeze,
3335 .restore = dasd_eckd_restore_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336};
3337
3338static int __init
3339dasd_eckd_init(void)
3340{
Sebastian Ott736e6ea2009-06-12 10:26:38 +02003341 int ret;
3342
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 ASCEBC(dasd_eckd_discipline.ebcname, 4);
Sebastian Ott736e6ea2009-06-12 10:26:38 +02003344 ret = ccw_driver_register(&dasd_eckd_driver);
3345 if (!ret)
3346 wait_for_device_probe();
3347
3348 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
3351static void __exit
3352dasd_eckd_cleanup(void)
3353{
3354 ccw_driver_unregister(&dasd_eckd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355}
3356
3357module_init(dasd_eckd_init);
3358module_exit(dasd_eckd_cleanup);