blob: 95e45782692fa7bb2a89e9ec566a6a035f736381 [file] [log] [blame]
Horst Hummel138c0142006-06-29 14:58:12 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
Horst Hummel138c0142006-06-29 14:58:12 +02003 * Horst Hummel <Horst.Hummel@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02007 * Copyright IBM Corp. 1999, 2009
Nigel Hislopab1d8482008-10-10 21:33:25 +02008 * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
9 * Author.........: Nigel Hislop <hislop_nigel@emc.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Stefan Haberlandca99dab2009-09-11 10:28:30 +020012#define KMSG_COMPONENT "dasd-eckd"
Stefan Haberlandfc19f382009-03-26 15:23:49 +010013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/stddef.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/hdreg.h> /* HDIO_GETGEO */
18#include <linux/bio.h>
19#include <linux/module.h>
Heiko Carstens048cd4e2012-02-27 10:01:52 +010020#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22
Sebastian Ott382b7362012-08-28 16:43:36 +020023#include <asm/css_chars.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/debug.h>
25#include <asm/idals.h>
26#include <asm/ebcdic.h>
27#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/uaccess.h>
Horst Hummel40545572006-06-29 15:08:18 +020029#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/ccwdev.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010031#include <asm/itcw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include "dasd_int.h"
34#include "dasd_eckd.h"
35
36#ifdef PRINTK_HEADER
37#undef PRINTK_HEADER
38#endif /* PRINTK_HEADER */
39#define PRINTK_HEADER "dasd(eckd):"
40
41#define ECKD_C0(i) (i->home_bytes)
42#define ECKD_F(i) (i->formula)
43#define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
44 (i->factors.f_0x02.f1))
45#define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
46 (i->factors.f_0x02.f2))
47#define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
48 (i->factors.f_0x02.f3))
49#define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
50#define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
51#define ECKD_F6(i) (i->factor6)
52#define ECKD_F7(i) (i->factor7)
53#define ECKD_F8(i) (i->factor8)
54
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +010055/*
56 * raw track access always map to 64k in memory
57 * so it maps to 16 blocks of 4k per track
58 */
59#define DASD_RAW_BLOCK_PER_TRACK 16
60#define DASD_RAW_BLOCKSIZE 4096
61/* 64k are 128 x 512 byte sectors */
62#define DASD_RAW_SECTORS_PER_TRACK 128
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064MODULE_LICENSE("GPL");
65
66static struct dasd_discipline dasd_eckd_discipline;
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* The ccw bus type uses this table to find devices that it sends to
69 * dasd_eckd_probe */
70static struct ccw_device_id dasd_eckd_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +020071 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
Stefan Haberland5da24b72011-02-17 13:13:55 +010073 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
Heiko Carstensd2c993d2006-07-12 16:41:55 +020074 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
75 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
76 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
77 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
78 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
79 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
80 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 { /* end of list */ },
82};
83
84MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
85
86static struct ccw_driver dasd_eckd_driver; /* see below */
87
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +020088static void *rawpadpage;
89
Stefan Weinhubereb6e1992009-12-07 12:51:51 +010090#define INIT_CQR_OK 0
91#define INIT_CQR_UNFORMATTED 1
92#define INIT_CQR_ERROR 2
93
Stefan Weinhuberf932bce2010-08-09 18:12:59 +020094/* emergency request for reserve/release */
95static struct {
96 struct dasd_ccw_req cqr;
97 struct ccw1 ccw;
98 char data[32];
99} *dasd_reserve_req;
100static DEFINE_MUTEX(dasd_reserve_mutex);
101
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100102/* definitions for the path verification worker */
103struct path_verification_work_data {
104 struct work_struct worker;
105 struct dasd_device *device;
106 struct dasd_ccw_req cqr;
107 struct ccw1 ccw;
108 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
109 int isglobal;
110 __u8 tbvpm;
111};
112static struct path_verification_work_data *path_verification_worker;
113static DEFINE_MUTEX(dasd_path_verification_mutex);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* initial attempt at a probe function. this can be simplified once
116 * the other detection code is gone */
117static int
118dasd_eckd_probe (struct ccw_device *cdev)
119{
120 int ret;
121
Horst Hummel40545572006-06-29 15:08:18 +0200122 /* set ECKD specific ccw-device options */
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100123 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
124 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
Horst Hummel40545572006-06-29 15:08:18 +0200125 if (ret) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +0100126 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
127 "dasd_eckd_probe: could not set "
128 "ccw-device options");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return ret;
Horst Hummel40545572006-06-29 15:08:18 +0200130 }
131 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
132 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135static int
136dasd_eckd_set_online(struct ccw_device *cdev)
137{
Horst Hummel40545572006-06-29 15:08:18 +0200138 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141static const int sizes_trk0[] = { 28, 148, 84 };
142#define LABEL_SIZE 140
143
Stefan Haberland3bc9fef92012-09-20 18:37:36 +0200144/* head and record addresses of count_area read in analysis ccw */
145static const int count_area_head[] = { 0, 0, 0, 0, 2 };
146static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static inline unsigned int
149round_up_multiple(unsigned int no, unsigned int mult)
150{
151 int rem = no % mult;
152 return (rem ? no - rem + mult : no);
153}
154
155static inline unsigned int
156ceil_quot(unsigned int d1, unsigned int d2)
157{
158 return (d1 + (d2 - 1)) / d2;
159}
160
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100161static unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162recs_per_track(struct dasd_eckd_characteristics * rdc,
163 unsigned int kl, unsigned int dl)
164{
165 int dn, kn;
166
167 switch (rdc->dev_type) {
168 case 0x3380:
169 if (kl)
170 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
171 ceil_quot(dl + 12, 32));
172 else
173 return 1499 / (15 + ceil_quot(dl + 12, 32));
174 case 0x3390:
175 dn = ceil_quot(dl + 6, 232) + 1;
176 if (kl) {
177 kn = ceil_quot(kl + 6, 232) + 1;
178 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
179 9 + ceil_quot(dl + 6 * dn, 34));
180 } else
181 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
182 case 0x9345:
183 dn = ceil_quot(dl + 6, 232) + 1;
184 if (kl) {
185 kn = ceil_quot(kl + 6, 232) + 1;
186 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
187 ceil_quot(dl + 6 * dn, 34));
188 } else
189 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
190 }
191 return 0;
192}
193
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100194static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
195{
196 geo->cyl = (__u16) cyl;
197 geo->head = cyl >> 16;
198 geo->head <<= 4;
199 geo->head |= head;
200}
201
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100202static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203check_XRC (struct ccw1 *de_ccw,
204 struct DE_eckd_data *data,
205 struct dasd_device *device)
206{
207 struct dasd_eckd_private *private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100208 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 private = (struct dasd_eckd_private *) device->private;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100211 if (!private->rdc_data.facilities.XRC_supported)
212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* switch on System Time Stamp - needed for XRC Support */
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100215 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
216 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
Horst Hummel138c0142006-06-29 14:58:12 +0200217
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100218 rc = get_sync_clock(&data->ep_sys_time);
219 /* Ignore return code if sync clock is switched off. */
Heiko Carstensa8f6db42012-09-06 15:13:34 +0200220 if (rc == -EOPNOTSUPP || rc == -EACCES)
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100221 rc = 0;
Horst Hummel138c0142006-06-29 14:58:12 +0200222
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100223 de_ccw->count = sizeof(struct DE_eckd_data);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100224 de_ccw->flags |= CCW_FLAG_SLI;
225 return rc;
226}
Horst Hummel138c0142006-06-29 14:58:12 +0200227
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100228static int
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100229define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
230 unsigned int totrk, int cmd, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 struct dasd_eckd_private *private;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100233 u32 begcyl, endcyl;
234 u16 heads, beghead, endhead;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100235 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 private = (struct dasd_eckd_private *) device->private;
238
239 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
240 ccw->flags = 0;
241 ccw->count = 16;
242 ccw->cda = (__u32) __pa(data);
243
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100244 memset(data, 0, sizeof(struct DE_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 switch (cmd) {
246 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
247 case DASD_ECKD_CCW_READ_RECORD_ZERO:
248 case DASD_ECKD_CCW_READ:
249 case DASD_ECKD_CCW_READ_MT:
250 case DASD_ECKD_CCW_READ_CKD:
251 case DASD_ECKD_CCW_READ_CKD_MT:
252 case DASD_ECKD_CCW_READ_KD:
253 case DASD_ECKD_CCW_READ_KD_MT:
254 case DASD_ECKD_CCW_READ_COUNT:
255 data->mask.perm = 0x1;
256 data->attributes.operation = private->attrib.operation;
257 break;
258 case DASD_ECKD_CCW_WRITE:
259 case DASD_ECKD_CCW_WRITE_MT:
260 case DASD_ECKD_CCW_WRITE_KD:
261 case DASD_ECKD_CCW_WRITE_KD_MT:
262 data->mask.perm = 0x02;
263 data->attributes.operation = private->attrib.operation;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100264 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
266 case DASD_ECKD_CCW_WRITE_CKD:
267 case DASD_ECKD_CCW_WRITE_CKD_MT:
268 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100269 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 break;
271 case DASD_ECKD_CCW_ERASE:
272 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
273 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
274 data->mask.perm = 0x3;
275 data->mask.auth = 0x1;
276 data->attributes.operation = DASD_BYPASS_CACHE;
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100277 rc = check_XRC (ccw, data, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
279 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100280 dev_err(&device->cdev->dev,
281 "0x%x is not a known command\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 break;
283 }
284
285 data->attributes.mode = 0x3; /* ECKD */
286
287 if ((private->rdc_data.cu_type == 0x2105 ||
288 private->rdc_data.cu_type == 0x2107 ||
289 private->rdc_data.cu_type == 0x1750)
290 && !(private->uses_cdl && trk < 2))
291 data->ga_extended |= 0x40; /* Regular Data Format Mode */
292
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100293 heads = private->rdc_data.trk_per_cyl;
294 begcyl = trk / heads;
295 beghead = trk % heads;
296 endcyl = totrk / heads;
297 endhead = totrk % heads;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 /* check for sequential prestage - enhance cylinder range */
300 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
301 data->attributes.operation == DASD_SEQ_ACCESS) {
Horst Hummel138c0142006-06-29 14:58:12 +0200302
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100303 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
304 endcyl += private->attrib.nr_cyl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100306 endcyl = (private->real_cyl - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100309 set_ch_t(&data->beg_ext, begcyl, beghead);
310 set_ch_t(&data->end_ext, endcyl, endhead);
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100311 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100314static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
315 struct dasd_device *device)
316{
317 struct dasd_eckd_private *private;
318 int rc;
319
320 private = (struct dasd_eckd_private *) device->private;
321 if (!private->rdc_data.facilities.XRC_supported)
322 return 0;
323
324 /* switch on System Time Stamp - needed for XRC Support */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100325 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
326 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100327 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
328
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100329 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100330 /* Ignore return code if sync clock is switched off. */
Heiko Carstensa8f6db42012-09-06 15:13:34 +0200331 if (rc == -EOPNOTSUPP || rc == -EACCES)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100332 rc = 0;
333 return rc;
334}
335
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100336static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
337 unsigned int rec_on_trk, int count, int cmd,
338 struct dasd_device *device, unsigned int reclen,
339 unsigned int tlf)
340{
341 struct dasd_eckd_private *private;
342 int sector;
343 int dn, d;
344
345 private = (struct dasd_eckd_private *) device->private;
346
347 memset(data, 0, sizeof(*data));
348 sector = 0;
349 if (rec_on_trk) {
350 switch (private->rdc_data.dev_type) {
351 case 0x3390:
352 dn = ceil_quot(reclen + 6, 232);
353 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
354 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
355 break;
356 case 0x3380:
357 d = 7 + ceil_quot(reclen + 12, 32);
358 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
359 break;
360 }
361 }
362 data->sector = sector;
363 /* note: meaning of count depends on the operation
364 * for record based I/O it's the number of records, but for
365 * track based I/O it's the number of tracks
366 */
367 data->count = count;
368 switch (cmd) {
369 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
370 data->operation.orientation = 0x3;
371 data->operation.operation = 0x03;
372 break;
373 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
374 data->operation.orientation = 0x3;
375 data->operation.operation = 0x16;
376 break;
377 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
378 data->operation.orientation = 0x1;
379 data->operation.operation = 0x03;
380 data->count++;
381 break;
382 case DASD_ECKD_CCW_READ_RECORD_ZERO:
383 data->operation.orientation = 0x3;
384 data->operation.operation = 0x16;
385 data->count++;
386 break;
387 case DASD_ECKD_CCW_WRITE:
388 case DASD_ECKD_CCW_WRITE_MT:
389 case DASD_ECKD_CCW_WRITE_KD:
390 case DASD_ECKD_CCW_WRITE_KD_MT:
391 data->auxiliary.length_valid = 0x1;
392 data->length = reclen;
393 data->operation.operation = 0x01;
394 break;
395 case DASD_ECKD_CCW_WRITE_CKD:
396 case DASD_ECKD_CCW_WRITE_CKD_MT:
397 data->auxiliary.length_valid = 0x1;
398 data->length = reclen;
399 data->operation.operation = 0x03;
400 break;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100401 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
402 data->operation.orientation = 0x0;
403 data->operation.operation = 0x3F;
404 data->extended_operation = 0x11;
405 data->length = 0;
406 data->extended_parameter_length = 0x02;
407 if (data->count > 8) {
408 data->extended_parameter[0] = 0xFF;
409 data->extended_parameter[1] = 0xFF;
410 data->extended_parameter[1] <<= (16 - count);
411 } else {
412 data->extended_parameter[0] = 0xFF;
413 data->extended_parameter[0] <<= (8 - count);
414 data->extended_parameter[1] = 0x00;
415 }
416 data->sector = 0xFF;
417 break;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100418 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
419 data->auxiliary.length_valid = 0x1;
420 data->length = reclen; /* not tlf, as one might think */
421 data->operation.operation = 0x3F;
422 data->extended_operation = 0x23;
423 break;
424 case DASD_ECKD_CCW_READ:
425 case DASD_ECKD_CCW_READ_MT:
426 case DASD_ECKD_CCW_READ_KD:
427 case DASD_ECKD_CCW_READ_KD_MT:
428 data->auxiliary.length_valid = 0x1;
429 data->length = reclen;
430 data->operation.operation = 0x06;
431 break;
432 case DASD_ECKD_CCW_READ_CKD:
433 case DASD_ECKD_CCW_READ_CKD_MT:
434 data->auxiliary.length_valid = 0x1;
435 data->length = reclen;
436 data->operation.operation = 0x16;
437 break;
438 case DASD_ECKD_CCW_READ_COUNT:
439 data->operation.operation = 0x06;
440 break;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100441 case DASD_ECKD_CCW_READ_TRACK:
442 data->operation.orientation = 0x1;
443 data->operation.operation = 0x0C;
444 data->extended_parameter_length = 0;
445 data->sector = 0xFF;
446 break;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100447 case DASD_ECKD_CCW_READ_TRACK_DATA:
448 data->auxiliary.length_valid = 0x1;
449 data->length = tlf;
450 data->operation.operation = 0x0C;
451 break;
452 case DASD_ECKD_CCW_ERASE:
453 data->length = reclen;
454 data->auxiliary.length_valid = 0x1;
455 data->operation.operation = 0x0b;
456 break;
457 default:
458 DBF_DEV_EVENT(DBF_ERR, device,
459 "fill LRE unknown opcode 0x%x", cmd);
460 BUG();
461 }
462 set_ch_t(&data->seek_addr,
463 trk / private->rdc_data.trk_per_cyl,
464 trk % private->rdc_data.trk_per_cyl);
465 data->search_arg.cyl = data->seek_addr.cyl;
466 data->search_arg.head = data->seek_addr.head;
467 data->search_arg.record = rec_on_trk;
468}
469
470static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
471 unsigned int trk, unsigned int totrk, int cmd,
472 struct dasd_device *basedev, struct dasd_device *startdev,
473 unsigned char format, unsigned int rec_on_trk, int count,
474 unsigned int blksize, unsigned int tlf)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100475{
476 struct dasd_eckd_private *basepriv, *startpriv;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100477 struct DE_eckd_data *dedata;
478 struct LRE_eckd_data *lredata;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100479 u32 begcyl, endcyl;
480 u16 heads, beghead, endhead;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100481 int rc = 0;
482
483 basepriv = (struct dasd_eckd_private *) basedev->private;
484 startpriv = (struct dasd_eckd_private *) startdev->private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100485 dedata = &pfxdata->define_extent;
486 lredata = &pfxdata->locate_record;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100487
488 ccw->cmd_code = DASD_ECKD_CCW_PFX;
489 ccw->flags = 0;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100490 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
491 ccw->count = sizeof(*pfxdata) + 2;
492 ccw->cda = (__u32) __pa(pfxdata);
493 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
494 } else {
495 ccw->count = sizeof(*pfxdata);
496 ccw->cda = (__u32) __pa(pfxdata);
497 memset(pfxdata, 0, sizeof(*pfxdata));
498 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100499
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100500 /* prefix data */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100501 if (format > 1) {
502 DBF_DEV_EVENT(DBF_ERR, basedev,
503 "PFX LRE unknown format 0x%x", format);
504 BUG();
505 return -EINVAL;
506 }
507 pfxdata->format = format;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200508 pfxdata->base_address = basepriv->ned->unit_addr;
509 pfxdata->base_lss = basepriv->ned->ID;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100510 pfxdata->validity.define_extent = 1;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100511
512 /* private uid is kept up to date, conf_data may be outdated */
513 if (startpriv->uid.type != UA_BASE_DEVICE) {
514 pfxdata->validity.verify_base = 1;
515 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
516 pfxdata->validity.hyper_pav = 1;
517 }
518
519 /* define extend data (mostly)*/
520 switch (cmd) {
521 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
522 case DASD_ECKD_CCW_READ_RECORD_ZERO:
523 case DASD_ECKD_CCW_READ:
524 case DASD_ECKD_CCW_READ_MT:
525 case DASD_ECKD_CCW_READ_CKD:
526 case DASD_ECKD_CCW_READ_CKD_MT:
527 case DASD_ECKD_CCW_READ_KD:
528 case DASD_ECKD_CCW_READ_KD_MT:
529 case DASD_ECKD_CCW_READ_COUNT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100530 dedata->mask.perm = 0x1;
531 dedata->attributes.operation = basepriv->attrib.operation;
532 break;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100533 case DASD_ECKD_CCW_READ_TRACK:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100534 case DASD_ECKD_CCW_READ_TRACK_DATA:
535 dedata->mask.perm = 0x1;
536 dedata->attributes.operation = basepriv->attrib.operation;
537 dedata->blk_size = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100538 break;
539 case DASD_ECKD_CCW_WRITE:
540 case DASD_ECKD_CCW_WRITE_MT:
541 case DASD_ECKD_CCW_WRITE_KD:
542 case DASD_ECKD_CCW_WRITE_KD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100543 dedata->mask.perm = 0x02;
544 dedata->attributes.operation = basepriv->attrib.operation;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100545 rc = check_XRC_on_prefix(pfxdata, basedev);
546 break;
547 case DASD_ECKD_CCW_WRITE_CKD:
548 case DASD_ECKD_CCW_WRITE_CKD_MT:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100549 dedata->attributes.operation = DASD_BYPASS_CACHE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100550 rc = check_XRC_on_prefix(pfxdata, basedev);
551 break;
552 case DASD_ECKD_CCW_ERASE:
553 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
554 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100555 dedata->mask.perm = 0x3;
556 dedata->mask.auth = 0x1;
557 dedata->attributes.operation = DASD_BYPASS_CACHE;
558 rc = check_XRC_on_prefix(pfxdata, basedev);
559 break;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100560 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
561 dedata->mask.perm = 0x03;
562 dedata->attributes.operation = basepriv->attrib.operation;
563 dedata->blk_size = 0;
564 break;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100565 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
566 dedata->mask.perm = 0x02;
567 dedata->attributes.operation = basepriv->attrib.operation;
568 dedata->blk_size = blksize;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100569 rc = check_XRC_on_prefix(pfxdata, basedev);
570 break;
571 default:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100572 DBF_DEV_EVENT(DBF_ERR, basedev,
573 "PFX LRE unknown opcode 0x%x", cmd);
574 BUG();
575 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100576 }
577
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100578 dedata->attributes.mode = 0x3; /* ECKD */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100579
580 if ((basepriv->rdc_data.cu_type == 0x2105 ||
581 basepriv->rdc_data.cu_type == 0x2107 ||
582 basepriv->rdc_data.cu_type == 0x1750)
583 && !(basepriv->uses_cdl && trk < 2))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100584 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100585
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100586 heads = basepriv->rdc_data.trk_per_cyl;
587 begcyl = trk / heads;
588 beghead = trk % heads;
589 endcyl = totrk / heads;
590 endhead = totrk % heads;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100591
592 /* check for sequential prestage - enhance cylinder range */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100593 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
594 dedata->attributes.operation == DASD_SEQ_ACCESS) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100595
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100596 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
597 endcyl += basepriv->attrib.nr_cyl;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100598 else
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100599 endcyl = (basepriv->real_cyl - 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100600 }
601
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100602 set_ch_t(&dedata->beg_ext, begcyl, beghead);
603 set_ch_t(&dedata->end_ext, endcyl, endhead);
604
605 if (format == 1) {
606 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
607 basedev, blksize, tlf);
608 }
609
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100610 return rc;
611}
612
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100613static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
614 unsigned int trk, unsigned int totrk, int cmd,
615 struct dasd_device *basedev, struct dasd_device *startdev)
616{
617 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
618 0, 0, 0, 0, 0);
619}
620
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100621static void
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100622locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
623 unsigned int rec_on_trk, int no_rec, int cmd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 struct dasd_device * device, int reclen)
625{
626 struct dasd_eckd_private *private;
627 int sector;
628 int dn, d;
Horst Hummel138c0142006-06-29 14:58:12 +0200629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 private = (struct dasd_eckd_private *) device->private;
631
632 DBF_DEV_EVENT(DBF_INFO, device,
633 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
634 trk, rec_on_trk, no_rec, cmd, reclen);
635
636 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
637 ccw->flags = 0;
638 ccw->count = 16;
639 ccw->cda = (__u32) __pa(data);
640
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100641 memset(data, 0, sizeof(struct LO_eckd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 sector = 0;
643 if (rec_on_trk) {
644 switch (private->rdc_data.dev_type) {
645 case 0x3390:
646 dn = ceil_quot(reclen + 6, 232);
647 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
648 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
649 break;
650 case 0x3380:
651 d = 7 + ceil_quot(reclen + 12, 32);
652 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
653 break;
654 }
655 }
656 data->sector = sector;
657 data->count = no_rec;
658 switch (cmd) {
659 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
660 data->operation.orientation = 0x3;
661 data->operation.operation = 0x03;
662 break;
663 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
664 data->operation.orientation = 0x3;
665 data->operation.operation = 0x16;
666 break;
667 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
668 data->operation.orientation = 0x1;
669 data->operation.operation = 0x03;
670 data->count++;
671 break;
672 case DASD_ECKD_CCW_READ_RECORD_ZERO:
673 data->operation.orientation = 0x3;
674 data->operation.operation = 0x16;
675 data->count++;
676 break;
677 case DASD_ECKD_CCW_WRITE:
678 case DASD_ECKD_CCW_WRITE_MT:
679 case DASD_ECKD_CCW_WRITE_KD:
680 case DASD_ECKD_CCW_WRITE_KD_MT:
681 data->auxiliary.last_bytes_used = 0x1;
682 data->length = reclen;
683 data->operation.operation = 0x01;
684 break;
685 case DASD_ECKD_CCW_WRITE_CKD:
686 case DASD_ECKD_CCW_WRITE_CKD_MT:
687 data->auxiliary.last_bytes_used = 0x1;
688 data->length = reclen;
689 data->operation.operation = 0x03;
690 break;
691 case DASD_ECKD_CCW_READ:
692 case DASD_ECKD_CCW_READ_MT:
693 case DASD_ECKD_CCW_READ_KD:
694 case DASD_ECKD_CCW_READ_KD_MT:
695 data->auxiliary.last_bytes_used = 0x1;
696 data->length = reclen;
697 data->operation.operation = 0x06;
698 break;
699 case DASD_ECKD_CCW_READ_CKD:
700 case DASD_ECKD_CCW_READ_CKD_MT:
701 data->auxiliary.last_bytes_used = 0x1;
702 data->length = reclen;
703 data->operation.operation = 0x16;
704 break;
705 case DASD_ECKD_CCW_READ_COUNT:
706 data->operation.operation = 0x06;
707 break;
708 case DASD_ECKD_CCW_ERASE:
709 data->length = reclen;
710 data->auxiliary.last_bytes_used = 0x1;
711 data->operation.operation = 0x0b;
712 break;
713 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100714 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
715 "opcode 0x%x", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100717 set_ch_t(&data->seek_addr,
718 trk / private->rdc_data.trk_per_cyl,
719 trk % private->rdc_data.trk_per_cyl);
720 data->search_arg.cyl = data->seek_addr.cyl;
721 data->search_arg.head = data->seek_addr.head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 data->search_arg.record = rec_on_trk;
723}
724
725/*
726 * Returns 1 if the block is one of the special blocks that needs
727 * to get read/written with the KD variant of the command.
728 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
729 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
730 * Luckily the KD variants differ only by one bit (0x08) from the
731 * normal variant. So don't wonder about code like:
732 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
733 * ccw->cmd_code |= 0x8;
734 */
735static inline int
736dasd_eckd_cdl_special(int blk_per_trk, int recid)
737{
738 if (recid < 3)
739 return 1;
740 if (recid < blk_per_trk)
741 return 0;
742 if (recid < 2 * blk_per_trk)
743 return 1;
744 return 0;
745}
746
747/*
748 * Returns the record size for the special blocks of the cdl format.
749 * Only returns something useful if dasd_eckd_cdl_special is true
750 * for the recid.
751 */
752static inline int
753dasd_eckd_cdl_reclen(int recid)
754{
755 if (recid < 3)
756 return sizes_trk0[recid];
757 return LABEL_SIZE;
758}
Stefan Haberlandb2061812011-12-27 11:27:27 +0100759/* create unique id from private structure. */
760static void create_uid(struct dasd_eckd_private *private)
Horst Hummel3d052592006-04-27 18:40:28 -0700761{
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200762 int count;
Stefan Haberlandb2061812011-12-27 11:27:27 +0100763 struct dasd_uid *uid;
Horst Hummel3d052592006-04-27 18:40:28 -0700764
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200765 uid = &private->uid;
Horst Hummel3d052592006-04-27 18:40:28 -0700766 memset(uid, 0, sizeof(struct dasd_uid));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200767 memcpy(uid->vendor, private->ned->HDA_manufacturer,
Horst Hummeld0710c72006-08-10 15:45:16 +0200768 sizeof(uid->vendor) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700769 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200770 memcpy(uid->serial, private->ned->HDA_location,
Horst Hummeld0710c72006-08-10 15:45:16 +0200771 sizeof(uid->serial) - 1);
Horst Hummel3d052592006-04-27 18:40:28 -0700772 EBCASC(uid->serial, sizeof(uid->serial) - 1);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200773 uid->ssid = private->gneq->subsystemID;
Joe Perchesa419aef2009-08-18 11:18:35 -0700774 uid->real_unit_addr = private->ned->unit_addr;
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200775 if (private->sneq) {
776 uid->type = private->sneq->sua_flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100777 if (uid->type == UA_BASE_PAV_ALIAS)
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200778 uid->base_unit_addr = private->sneq->base_unit_addr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100779 } else {
780 uid->type = UA_BASE_DEVICE;
781 }
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200782 if (private->vdsneq) {
783 for (count = 0; count < 16; count++) {
784 sprintf(uid->vduit+2*count, "%02x",
785 private->vdsneq->uit[count]);
786 }
787 }
Stefan Haberlandb2061812011-12-27 11:27:27 +0100788}
789
790/*
791 * Generate device unique id that specifies the physical device.
792 */
793static int dasd_eckd_generate_uid(struct dasd_device *device)
794{
795 struct dasd_eckd_private *private;
796 unsigned long flags;
797
798 private = (struct dasd_eckd_private *) device->private;
799 if (!private)
800 return -ENODEV;
801 if (!private->ned || !private->gneq)
802 return -ENODEV;
803 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
804 create_uid(private);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200805 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Horst Hummel3d052592006-04-27 18:40:28 -0700806 return 0;
807}
808
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200809static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
810{
811 struct dasd_eckd_private *private;
812 unsigned long flags;
813
814 if (device->private) {
815 private = (struct dasd_eckd_private *)device->private;
816 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
817 *uid = private->uid;
818 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
819 return 0;
820 }
821 return -EINVAL;
822}
823
Stefan Haberlandb2061812011-12-27 11:27:27 +0100824/*
825 * compare device UID with data of a given dasd_eckd_private structure
826 * return 0 for match
827 */
828static int dasd_eckd_compare_path_uid(struct dasd_device *device,
829 struct dasd_eckd_private *private)
830{
831 struct dasd_uid device_uid;
832
833 create_uid(private);
834 dasd_eckd_get_uid(device, &device_uid);
835
836 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
837}
838
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100839static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
840 struct dasd_ccw_req *cqr,
841 __u8 *rcd_buffer,
842 __u8 lpm)
Cornelia Huck17283b52007-05-04 18:47:51 +0200843{
Cornelia Huck17283b52007-05-04 18:47:51 +0200844 struct ccw1 *ccw;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100845 /*
846 * buffer has to start with EBCDIC "V1.0" to show
847 * support for virtual device SNEQ
848 */
849 rcd_buffer[0] = 0xE5;
850 rcd_buffer[1] = 0xF1;
851 rcd_buffer[2] = 0x4B;
852 rcd_buffer[3] = 0xF0;
Cornelia Huck17283b52007-05-04 18:47:51 +0200853
854 ccw = cqr->cpaddr;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100855 ccw->cmd_code = DASD_ECKD_CCW_RCD;
856 ccw->flags = 0;
Cornelia Huck17283b52007-05-04 18:47:51 +0200857 ccw->cda = (__u32)(addr_t)rcd_buffer;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100858 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
859 cqr->magic = DASD_ECKD_MAGIC;
Cornelia Huck17283b52007-05-04 18:47:51 +0200860
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100861 cqr->startdev = device;
862 cqr->memdev = device;
863 cqr->block = NULL;
Cornelia Huck17283b52007-05-04 18:47:51 +0200864 cqr->expires = 10*HZ;
865 cqr->lpm = lpm;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100866 cqr->retries = 256;
Heiko Carstens1aae0562013-01-30 09:49:40 +0100867 cqr->buildclk = get_tod_clock();
Cornelia Huck17283b52007-05-04 18:47:51 +0200868 cqr->status = DASD_CQR_FILLED;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100869 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
870}
871
Stefan Haberland5915a872011-10-30 15:16:57 +0100872/*
873 * Wakeup helper for read_conf
874 * if the cqr is not done and needs some error recovery
875 * the buffer has to be re-initialized with the EBCDIC "V1.0"
876 * to show support for virtual device SNEQ
877 */
878static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
879{
880 struct ccw1 *ccw;
881 __u8 *rcd_buffer;
882
883 if (cqr->status != DASD_CQR_DONE) {
884 ccw = cqr->cpaddr;
885 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
886 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
887
888 rcd_buffer[0] = 0xE5;
889 rcd_buffer[1] = 0xF1;
890 rcd_buffer[2] = 0x4B;
891 rcd_buffer[3] = 0xF0;
892 }
893 dasd_wakeup_cb(cqr, data);
894}
895
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100896static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
897 struct dasd_ccw_req *cqr,
898 __u8 *rcd_buffer,
899 __u8 lpm)
900{
901 struct ciw *ciw;
902 int rc;
903 /*
904 * sanity check: scan for RCD command in extended SenseID data
905 * some devices do not support RCD
906 */
907 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
908 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
909 return -EOPNOTSUPP;
910
911 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
912 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +0100913 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100914 cqr->retries = 5;
Stefan Haberland5915a872011-10-30 15:16:57 +0100915 cqr->callback = read_conf_cb;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100916 rc = dasd_sleep_on_immediatly(cqr);
917 return rc;
Cornelia Huck17283b52007-05-04 18:47:51 +0200918}
919
920static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
921 void **rcd_buffer,
922 int *rcd_buffer_size, __u8 lpm)
923{
924 struct ciw *ciw;
925 char *rcd_buf = NULL;
926 int ret;
927 struct dasd_ccw_req *cqr;
928
929 /*
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100930 * sanity check: scan for RCD command in extended SenseID data
931 * some devices do not support RCD
Cornelia Huck17283b52007-05-04 18:47:51 +0200932 */
933 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100934 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
Cornelia Huck17283b52007-05-04 18:47:51 +0200935 ret = -EOPNOTSUPP;
936 goto out_error;
937 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100938 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
Cornelia Huck17283b52007-05-04 18:47:51 +0200939 if (!rcd_buf) {
940 ret = -ENOMEM;
941 goto out_error;
942 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100943 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
944 0, /* use rcd_buf as data ara */
945 device);
Cornelia Huck17283b52007-05-04 18:47:51 +0200946 if (IS_ERR(cqr)) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100947 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
948 "Could not allocate RCD request");
949 ret = -ENOMEM;
Cornelia Huck17283b52007-05-04 18:47:51 +0200950 goto out_error;
951 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100952 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
Stefan Haberland5915a872011-10-30 15:16:57 +0100953 cqr->callback = read_conf_cb;
Cornelia Huck17283b52007-05-04 18:47:51 +0200954 ret = dasd_sleep_on(cqr);
955 /*
956 * on success we update the user input parms
957 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100958 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +0200959 if (ret)
960 goto out_error;
961
Stefan Weinhubera4d26c62011-01-05 12:48:03 +0100962 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
Cornelia Huck17283b52007-05-04 18:47:51 +0200963 *rcd_buffer = rcd_buf;
964 return 0;
965out_error:
966 kfree(rcd_buf);
967 *rcd_buffer = NULL;
968 *rcd_buffer_size = 0;
969 return ret;
970}
971
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +0200972static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
973{
974
975 struct dasd_sneq *sneq;
976 int i, count;
977
978 private->ned = NULL;
979 private->sneq = NULL;
980 private->vdsneq = NULL;
981 private->gneq = NULL;
982 count = private->conf_len / sizeof(struct dasd_sneq);
983 sneq = (struct dasd_sneq *)private->conf_data;
984 for (i = 0; i < count; ++i) {
985 if (sneq->flags.identifier == 1 && sneq->format == 1)
986 private->sneq = sneq;
987 else if (sneq->flags.identifier == 1 && sneq->format == 4)
988 private->vdsneq = (struct vd_sneq *)sneq;
989 else if (sneq->flags.identifier == 2)
990 private->gneq = (struct dasd_gneq *)sneq;
991 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
992 private->ned = (struct dasd_ned *)sneq;
993 sneq++;
994 }
995 if (!private->ned || !private->gneq) {
996 private->ned = NULL;
997 private->sneq = NULL;
998 private->vdsneq = NULL;
999 private->gneq = NULL;
1000 return -EINVAL;
1001 }
1002 return 0;
1003
1004};
1005
1006static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1007{
1008 struct dasd_gneq *gneq;
1009 int i, count, found;
1010
1011 count = conf_len / sizeof(*gneq);
1012 gneq = (struct dasd_gneq *)conf_data;
1013 found = 0;
1014 for (i = 0; i < count; ++i) {
1015 if (gneq->flags.identifier == 2) {
1016 found = 1;
1017 break;
1018 }
1019 gneq++;
1020 }
1021 if (found)
1022 return ((char *)gneq)[18] & 0x07;
1023 else
1024 return 0;
1025}
1026
1027static int dasd_eckd_read_conf(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
1029 void *conf_data;
1030 int conf_len, conf_data_saved;
Stefan Haberland55d3a852012-11-27 17:04:14 +01001031 int rc, path_err;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001032 __u8 lpm, opm;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001033 struct dasd_eckd_private *private, path_private;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001034 struct dasd_path *path_data;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001035 struct dasd_uid *uid;
1036 char print_path_uid[60], print_device_uid[60];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
1038 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001039 path_data = &device->path_data;
1040 opm = ccw_device_get_path_mask(device->cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 conf_data_saved = 0;
Stefan Haberland55d3a852012-11-27 17:04:14 +01001042 path_err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 /* get configuration data per operational path */
1044 for (lpm = 0x80; lpm; lpm>>= 1) {
Stefan Haberlandb2061812011-12-27 11:27:27 +01001045 if (!(lpm & opm))
1046 continue;
1047 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1048 &conf_len, lpm);
1049 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1050 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1051 "Read configuration data returned "
1052 "error %d", rc);
1053 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
Stefan Haberlandb2061812011-12-27 11:27:27 +01001055 if (conf_data == NULL) {
1056 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1057 "No configuration data "
1058 "retrieved");
1059 /* no further analysis possible */
1060 path_data->opm |= lpm;
1061 continue; /* no error */
1062 }
1063 /* save first valid configuration data */
1064 if (!conf_data_saved) {
1065 kfree(private->conf_data);
1066 private->conf_data = conf_data;
1067 private->conf_len = conf_len;
1068 if (dasd_eckd_identify_conf_parts(private)) {
1069 private->conf_data = NULL;
1070 private->conf_len = 0;
1071 kfree(conf_data);
1072 continue;
1073 }
1074 /*
1075 * build device UID that other path data
1076 * can be compared to it
1077 */
1078 dasd_eckd_generate_uid(device);
1079 conf_data_saved++;
1080 } else {
1081 path_private.conf_data = conf_data;
1082 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1083 if (dasd_eckd_identify_conf_parts(
1084 &path_private)) {
1085 path_private.conf_data = NULL;
1086 path_private.conf_len = 0;
1087 kfree(conf_data);
1088 continue;
1089 }
1090
1091 if (dasd_eckd_compare_path_uid(
1092 device, &path_private)) {
1093 uid = &path_private.uid;
1094 if (strlen(uid->vduit) > 0)
1095 snprintf(print_path_uid,
1096 sizeof(print_path_uid),
1097 "%s.%s.%04x.%02x.%s",
1098 uid->vendor, uid->serial,
1099 uid->ssid, uid->real_unit_addr,
1100 uid->vduit);
1101 else
1102 snprintf(print_path_uid,
1103 sizeof(print_path_uid),
1104 "%s.%s.%04x.%02x",
1105 uid->vendor, uid->serial,
1106 uid->ssid,
1107 uid->real_unit_addr);
1108 uid = &private->uid;
1109 if (strlen(uid->vduit) > 0)
1110 snprintf(print_device_uid,
1111 sizeof(print_device_uid),
1112 "%s.%s.%04x.%02x.%s",
1113 uid->vendor, uid->serial,
1114 uid->ssid, uid->real_unit_addr,
1115 uid->vduit);
1116 else
1117 snprintf(print_device_uid,
1118 sizeof(print_device_uid),
1119 "%s.%s.%04x.%02x",
1120 uid->vendor, uid->serial,
1121 uid->ssid,
1122 uid->real_unit_addr);
1123 dev_err(&device->cdev->dev,
1124 "Not all channel paths lead to "
1125 "the same device, path %02X leads to "
1126 "device %s instead of %s\n", lpm,
1127 print_path_uid, print_device_uid);
Stefan Haberland55d3a852012-11-27 17:04:14 +01001128 path_err = -EINVAL;
1129 continue;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001130 }
1131
1132 path_private.conf_data = NULL;
1133 path_private.conf_len = 0;
1134 }
1135 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1136 case 0x02:
1137 path_data->npm |= lpm;
1138 break;
1139 case 0x03:
1140 path_data->ppm |= lpm;
1141 break;
1142 }
1143 path_data->opm |= lpm;
1144
1145 if (conf_data != private->conf_data)
1146 kfree(conf_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
Stefan Haberlandb2061812011-12-27 11:27:27 +01001148
Stefan Haberland55d3a852012-11-27 17:04:14 +01001149 return path_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001152static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1153{
1154 struct dasd_eckd_private *private;
1155 int mdc;
1156 u32 fcx_max_data;
1157
1158 private = (struct dasd_eckd_private *) device->private;
1159 if (private->fcx_max_data) {
1160 mdc = ccw_device_get_mdc(device->cdev, lpm);
1161 if ((mdc < 0)) {
1162 dev_warn(&device->cdev->dev,
1163 "Detecting the maximum data size for zHPF "
1164 "requests failed (rc=%d) for a new path %x\n",
1165 mdc, lpm);
1166 return mdc;
1167 }
1168 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1169 if (fcx_max_data < private->fcx_max_data) {
1170 dev_warn(&device->cdev->dev,
1171 "The maximum data size for zHPF requests %u "
1172 "on a new path %x is below the active maximum "
1173 "%u\n", fcx_max_data, lpm,
1174 private->fcx_max_data);
1175 return -EACCES;
1176 }
1177 }
1178 return 0;
1179}
1180
Stefan Haberlandb2061812011-12-27 11:27:27 +01001181static int rebuild_device_uid(struct dasd_device *device,
1182 struct path_verification_work_data *data)
1183{
1184 struct dasd_eckd_private *private;
1185 struct dasd_path *path_data;
1186 __u8 lpm, opm;
1187 int rc;
1188
1189 rc = -ENODEV;
1190 private = (struct dasd_eckd_private *) device->private;
1191 path_data = &device->path_data;
1192 opm = device->path_data.opm;
1193
1194 for (lpm = 0x80; lpm; lpm >>= 1) {
1195 if (!(lpm & opm))
1196 continue;
1197 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1198 memset(&data->cqr, 0, sizeof(data->cqr));
1199 data->cqr.cpaddr = &data->ccw;
1200 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1201 data->rcd_buffer,
1202 lpm);
1203
1204 if (rc) {
1205 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1206 continue;
1207 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1208 "Read configuration data "
1209 "returned error %d", rc);
1210 break;
1211 }
1212 memcpy(private->conf_data, data->rcd_buffer,
1213 DASD_ECKD_RCD_DATA_SIZE);
1214 if (dasd_eckd_identify_conf_parts(private)) {
1215 rc = -ENODEV;
1216 } else /* first valid path is enough */
1217 break;
1218 }
1219
1220 if (!rc)
1221 rc = dasd_eckd_generate_uid(device);
1222
1223 return rc;
1224}
1225
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001226static void do_path_verification_work(struct work_struct *work)
1227{
1228 struct path_verification_work_data *data;
1229 struct dasd_device *device;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001230 struct dasd_eckd_private path_private;
1231 struct dasd_uid *uid;
1232 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001233 __u8 lpm, opm, npm, ppm, epm;
1234 unsigned long flags;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001235 char print_uid[60];
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001236 int rc;
1237
1238 data = container_of(work, struct path_verification_work_data, worker);
1239 device = data->device;
1240
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01001241 /* delay path verification until device was resumed */
1242 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1243 schedule_work(work);
1244 return;
1245 }
1246
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001247 opm = 0;
1248 npm = 0;
1249 ppm = 0;
1250 epm = 0;
1251 for (lpm = 0x80; lpm; lpm >>= 1) {
Stefan Haberlandb2061812011-12-27 11:27:27 +01001252 if (!(lpm & data->tbvpm))
1253 continue;
1254 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1255 memset(&data->cqr, 0, sizeof(data->cqr));
1256 data->cqr.cpaddr = &data->ccw;
1257 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1258 data->rcd_buffer,
1259 lpm);
1260 if (!rc) {
1261 switch (dasd_eckd_path_access(data->rcd_buffer,
1262 DASD_ECKD_RCD_DATA_SIZE)
1263 ) {
1264 case 0x02:
1265 npm |= lpm;
1266 break;
1267 case 0x03:
1268 ppm |= lpm;
1269 break;
1270 }
1271 opm |= lpm;
1272 } else if (rc == -EOPNOTSUPP) {
1273 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1274 "path verification: No configuration "
1275 "data retrieved");
1276 opm |= lpm;
1277 } else if (rc == -EAGAIN) {
1278 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001279 "path verification: device is stopped,"
1280 " try again later");
Stefan Haberlandb2061812011-12-27 11:27:27 +01001281 epm |= lpm;
1282 } else {
1283 dev_warn(&device->cdev->dev,
1284 "Reading device feature codes failed "
1285 "(rc=%d) for new path %x\n", rc, lpm);
1286 continue;
1287 }
1288 if (verify_fcx_max_data(device, lpm)) {
1289 opm &= ~lpm;
1290 npm &= ~lpm;
1291 ppm &= ~lpm;
1292 continue;
1293 }
1294
1295 /*
1296 * save conf_data for comparison after
1297 * rebuild_device_uid may have changed
1298 * the original data
1299 */
1300 memcpy(&path_rcd_buf, data->rcd_buffer,
1301 DASD_ECKD_RCD_DATA_SIZE);
1302 path_private.conf_data = (void *) &path_rcd_buf;
1303 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1304 if (dasd_eckd_identify_conf_parts(&path_private)) {
1305 path_private.conf_data = NULL;
1306 path_private.conf_len = 0;
1307 continue;
1308 }
1309
1310 /*
1311 * compare path UID with device UID only if at least
1312 * one valid path is left
1313 * in other case the device UID may have changed and
1314 * the first working path UID will be used as device UID
1315 */
1316 if (device->path_data.opm &&
1317 dasd_eckd_compare_path_uid(device, &path_private)) {
1318 /*
1319 * the comparison was not successful
1320 * rebuild the device UID with at least one
1321 * known path in case a z/VM hyperswap command
1322 * has changed the device
1323 *
1324 * after this compare again
1325 *
1326 * if either the rebuild or the recompare fails
1327 * the path can not be used
1328 */
1329 if (rebuild_device_uid(device, data) ||
1330 dasd_eckd_compare_path_uid(
1331 device, &path_private)) {
1332 uid = &path_private.uid;
1333 if (strlen(uid->vduit) > 0)
1334 snprintf(print_uid, sizeof(print_uid),
1335 "%s.%s.%04x.%02x.%s",
1336 uid->vendor, uid->serial,
1337 uid->ssid, uid->real_unit_addr,
1338 uid->vduit);
1339 else
1340 snprintf(print_uid, sizeof(print_uid),
1341 "%s.%s.%04x.%02x",
1342 uid->vendor, uid->serial,
1343 uid->ssid,
1344 uid->real_unit_addr);
1345 dev_err(&device->cdev->dev,
1346 "The newly added channel path %02X "
1347 "will not be used because it leads "
1348 "to a different device %s\n",
1349 lpm, print_uid);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001350 opm &= ~lpm;
1351 npm &= ~lpm;
1352 ppm &= ~lpm;
Stefan Haberlandb2061812011-12-27 11:27:27 +01001353 continue;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001354 }
1355 }
Stefan Haberlandb2061812011-12-27 11:27:27 +01001356
1357 /*
1358 * There is a small chance that a path is lost again between
1359 * above path verification and the following modification of
1360 * the device opm mask. We could avoid that race here by using
1361 * yet another path mask, but we rather deal with this unlikely
1362 * situation in dasd_start_IO.
1363 */
1364 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1365 if (!device->path_data.opm && opm) {
1366 device->path_data.opm = opm;
1367 dasd_generic_path_operational(device);
1368 } else
1369 device->path_data.opm |= opm;
1370 device->path_data.npm |= npm;
1371 device->path_data.ppm |= ppm;
1372 device->path_data.tbvpm |= epm;
1373 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001374 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001375
1376 dasd_put_device(device);
1377 if (data->isglobal)
1378 mutex_unlock(&dasd_path_verification_mutex);
1379 else
1380 kfree(data);
1381}
1382
1383static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1384{
1385 struct path_verification_work_data *data;
1386
1387 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1388 if (!data) {
1389 if (mutex_trylock(&dasd_path_verification_mutex)) {
1390 data = path_verification_worker;
1391 data->isglobal = 1;
1392 } else
1393 return -ENOMEM;
1394 } else {
1395 memset(data, 0, sizeof(*data));
1396 data->isglobal = 0;
1397 }
1398 INIT_WORK(&data->worker, do_path_verification_work);
1399 dasd_get_device(device);
1400 data->device = device;
1401 data->tbvpm = lpm;
1402 schedule_work(&data->worker);
1403 return 0;
1404}
1405
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001406static int dasd_eckd_read_features(struct dasd_device *device)
1407{
1408 struct dasd_psf_prssd_data *prssdp;
1409 struct dasd_rssd_features *features;
1410 struct dasd_ccw_req *cqr;
1411 struct ccw1 *ccw;
1412 int rc;
1413 struct dasd_eckd_private *private;
1414
1415 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02001416 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
Stefan Haberland68b781f2009-09-11 10:28:29 +02001417 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001418 (sizeof(struct dasd_psf_prssd_data) +
1419 sizeof(struct dasd_rssd_features)),
1420 device);
1421 if (IS_ERR(cqr)) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001422 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1423 "allocate initialization request");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001424 return PTR_ERR(cqr);
1425 }
1426 cqr->startdev = device;
1427 cqr->memdev = device;
1428 cqr->block = NULL;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001429 cqr->retries = 256;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001430 cqr->expires = 10 * HZ;
1431
1432 /* Prepare for Read Subsystem Data */
1433 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1434 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1435 prssdp->order = PSF_ORDER_PRSSD;
1436 prssdp->suborder = 0x41; /* Read Feature Codes */
1437 /* all other bytes of prssdp must be zero */
1438
1439 ccw = cqr->cpaddr;
1440 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1441 ccw->count = sizeof(struct dasd_psf_prssd_data);
1442 ccw->flags |= CCW_FLAG_CC;
1443 ccw->cda = (__u32)(addr_t) prssdp;
1444
1445 /* Read Subsystem Data - feature codes */
1446 features = (struct dasd_rssd_features *) (prssdp + 1);
1447 memset(features, 0, sizeof(struct dasd_rssd_features));
1448
1449 ccw++;
1450 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1451 ccw->count = sizeof(struct dasd_rssd_features);
1452 ccw->cda = (__u32)(addr_t) features;
1453
Heiko Carstens1aae0562013-01-30 09:49:40 +01001454 cqr->buildclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001455 cqr->status = DASD_CQR_FILLED;
1456 rc = dasd_sleep_on(cqr);
1457 if (rc == 0) {
1458 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1459 features = (struct dasd_rssd_features *) (prssdp + 1);
1460 memcpy(&private->features, features,
1461 sizeof(struct dasd_rssd_features));
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02001462 } else
1463 dev_warn(&device->cdev->dev, "Reading device feature codes"
1464 " failed with rc=%d\n", rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001465 dasd_sfree_request(cqr, cqr->memdev);
1466 return rc;
1467}
1468
1469
Horst Hummel3d052592006-04-27 18:40:28 -07001470/*
Horst Hummel40545572006-06-29 15:08:18 +02001471 * Build CP for Perform Subsystem Function - SSC.
1472 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001473static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1474 int enable_pav)
Horst Hummel40545572006-06-29 15:08:18 +02001475{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001476 struct dasd_ccw_req *cqr;
1477 struct dasd_psf_ssc_data *psf_ssc_data;
1478 struct ccw1 *ccw;
Horst Hummel40545572006-06-29 15:08:18 +02001479
Stefan Haberland68b781f2009-09-11 10:28:29 +02001480 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
Horst Hummel40545572006-06-29 15:08:18 +02001481 sizeof(struct dasd_psf_ssc_data),
1482 device);
1483
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001484 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001485 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Horst Hummel40545572006-06-29 15:08:18 +02001486 "Could not allocate PSF-SSC request");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001487 return cqr;
1488 }
1489 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1490 psf_ssc_data->order = PSF_ORDER_SSC;
Stefan Weinhuber626350b2009-12-07 12:51:50 +01001491 psf_ssc_data->suborder = 0xc0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001492 if (enable_pav) {
Stefan Weinhuber626350b2009-12-07 12:51:50 +01001493 psf_ssc_data->suborder |= 0x08;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001494 psf_ssc_data->reserved[0] = 0x88;
1495 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001496 ccw = cqr->cpaddr;
1497 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1498 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1499 ccw->count = 66;
Horst Hummel40545572006-06-29 15:08:18 +02001500
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001501 cqr->startdev = device;
1502 cqr->memdev = device;
1503 cqr->block = NULL;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001504 cqr->retries = 256;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001505 cqr->expires = 10*HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01001506 cqr->buildclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001507 cqr->status = DASD_CQR_FILLED;
1508 return cqr;
Horst Hummel40545572006-06-29 15:08:18 +02001509}
1510
1511/*
1512 * Perform Subsystem Function.
1513 * It is necessary to trigger CIO for channel revalidation since this
1514 * call might change behaviour of DASD devices.
1515 */
1516static int
Stefan Haberland12d7b102012-09-11 15:10:58 +02001517dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1518 unsigned long flags)
Horst Hummel40545572006-06-29 15:08:18 +02001519{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001520 struct dasd_ccw_req *cqr;
1521 int rc;
Horst Hummel40545572006-06-29 15:08:18 +02001522
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001523 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001524 if (IS_ERR(cqr))
1525 return PTR_ERR(cqr);
Horst Hummel40545572006-06-29 15:08:18 +02001526
Stefan Haberland12d7b102012-09-11 15:10:58 +02001527 /*
1528 * set flags e.g. turn on failfast, to prevent blocking
1529 * the calling function should handle failed requests
1530 */
1531 cqr->flags |= flags;
1532
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001533 rc = dasd_sleep_on(cqr);
1534 if (!rc)
1535 /* trigger CIO to reprobe devices */
1536 css_schedule_reprobe();
Stefan Haberland12d7b102012-09-11 15:10:58 +02001537 else if (cqr->intrc == -EAGAIN)
1538 rc = -EAGAIN;
1539
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001540 dasd_sfree_request(cqr, cqr->memdev);
1541 return rc;
Horst Hummel40545572006-06-29 15:08:18 +02001542}
1543
1544/*
1545 * Valide storage server of current device.
1546 */
Stefan Haberland12d7b102012-09-11 15:10:58 +02001547static int dasd_eckd_validate_server(struct dasd_device *device,
1548 unsigned long flags)
Horst Hummel40545572006-06-29 15:08:18 +02001549{
1550 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001551 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001552 int enable_pav;
Horst Hummel40545572006-06-29 15:08:18 +02001553
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01001554 private = (struct dasd_eckd_private *) device->private;
1555 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1556 private->uid.type == UA_HYPER_PAV_ALIAS)
Stefan Haberland12d7b102012-09-11 15:10:58 +02001557 return 0;
Horst Hummel40545572006-06-29 15:08:18 +02001558 if (dasd_nopav || MACHINE_IS_VM)
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001559 enable_pav = 0;
1560 else
1561 enable_pav = 1;
Stefan Haberland12d7b102012-09-11 15:10:58 +02001562 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001563
Horst Hummel8e79a442006-08-24 13:22:36 +02001564 /* may be requested feature is not available on server,
1565 * therefore just report error and go ahead */
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001566 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1567 "returned rc=%d", private->uid.ssid, rc);
Stefan Haberland12d7b102012-09-11 15:10:58 +02001568 return rc;
Horst Hummel40545572006-06-29 15:08:18 +02001569}
1570
Stefan Haberlandf1633032012-01-18 18:03:41 +01001571/*
1572 * worker to do a validate server in case of a lost pathgroup
1573 */
1574static void dasd_eckd_do_validate_server(struct work_struct *work)
1575{
1576 struct dasd_device *device = container_of(work, struct dasd_device,
1577 kick_validate);
Stefan Haberlandea4da6e2013-02-19 09:30:05 +01001578 unsigned long flags = 0;
1579
1580 set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1581 if (dasd_eckd_validate_server(device, flags)
Stefan Haberland12d7b102012-09-11 15:10:58 +02001582 == -EAGAIN) {
1583 /* schedule worker again if failed */
1584 schedule_work(&device->kick_validate);
1585 return;
1586 }
1587
Stefan Haberlandf1633032012-01-18 18:03:41 +01001588 dasd_put_device(device);
1589}
1590
1591static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1592{
1593 dasd_get_device(device);
Stefan Haberland25e2cf12012-03-11 11:59:37 -04001594 /* exit if device not online or in offline processing */
1595 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1596 device->state < DASD_STATE_ONLINE) {
1597 dasd_put_device(device);
1598 return;
1599 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01001600 /* queue call to do_validate_server to the kernel event daemon. */
1601 schedule_work(&device->kick_validate);
1602}
1603
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01001604static u32 get_fcx_max_data(struct dasd_device *device)
1605{
1606#if defined(CONFIG_64BIT)
1607 int tpm, mdc;
1608 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1609 struct dasd_eckd_private *private;
1610
1611 if (dasd_nofcx)
1612 return 0;
1613 /* is transport mode supported? */
1614 private = (struct dasd_eckd_private *) device->private;
1615 fcx_in_css = css_general_characteristics.fcx;
1616 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1617 fcx_in_features = private->features.feature[40] & 0x80;
1618 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1619
1620 if (!tpm)
1621 return 0;
1622
1623 mdc = ccw_device_get_mdc(device->cdev, 0);
1624 if (mdc < 0) {
1625 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1626 " data size for zHPF requests failed\n");
1627 return 0;
1628 } else
1629 return mdc * FCX_MAX_DATA_FACTOR;
1630#else
1631 return 0;
1632#endif
1633}
1634
Horst Hummel40545572006-06-29 15:08:18 +02001635/*
Horst Hummel3d052592006-04-27 18:40:28 -07001636 * Check device characteristics.
1637 * If the device is accessible using ECKD discipline, the device is enabled.
1638 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639static int
1640dasd_eckd_check_characteristics(struct dasd_device *device)
1641{
1642 struct dasd_eckd_private *private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001643 struct dasd_block *block;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001644 struct dasd_uid temp_uid;
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01001645 int rc, i;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01001646 int readonly;
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001647 unsigned long value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Stefan Haberlandf1633032012-01-18 18:03:41 +01001649 /* setup work queue for validate server*/
1650 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1651
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +01001652 if (!ccw_device_is_pathgroup(device->cdev)) {
1653 dev_warn(&device->cdev->dev,
1654 "A channel path group could not be established\n");
1655 return -EIO;
1656 }
1657 if (!ccw_device_is_multipath(device->cdev)) {
1658 dev_info(&device->cdev->dev,
1659 "The DASD is not operating in multipath mode\n");
1660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 private = (struct dasd_eckd_private *) device->private;
Sebastian Ott92636b12009-06-12 10:26:37 +02001662 if (!private) {
1663 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1664 if (!private) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001665 dev_warn(&device->cdev->dev,
1666 "Allocating memory for private DASD data "
1667 "failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 return -ENOMEM;
1669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 device->private = (void *) private;
Sebastian Ott92636b12009-06-12 10:26:37 +02001671 } else {
1672 memset(private, 0, sizeof(*private));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 }
1674 /* Invalidate status of initial analysis. */
1675 private->init_cqr_status = -1;
1676 /* Set default cache operations. */
1677 private->attrib.operation = DASD_NORMAL_CACHE;
1678 private->attrib.nr_cyl = 0;
1679
Horst Hummel40545572006-06-29 15:08:18 +02001680 /* Read Configuration Data */
1681 rc = dasd_eckd_read_conf(device);
1682 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001683 goto out_err1;
Horst Hummel40545572006-06-29 15:08:18 +02001684
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001685 /* set default timeout */
1686 device->default_expires = DASD_EXPIRES;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00001687 /* set default retry count */
1688 device->default_retries = DASD_RETRIES;
1689
Stefan Haberland7c8faa82010-08-09 18:13:00 +02001690 if (private->gneq) {
1691 value = 1;
1692 for (i = 0; i < private->gneq->timeout.value; i++)
1693 value = 10 * value;
1694 value = value * private->gneq->timeout.number;
1695 /* do not accept useless values */
1696 if (value != 0 && value <= DASD_EXPIRES_MAX)
1697 device->default_expires = value;
1698 }
1699
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02001700 dasd_eckd_get_uid(device, &temp_uid);
1701 if (temp_uid.type == UA_BASE_DEVICE) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001702 block = dasd_alloc_block();
1703 if (IS_ERR(block)) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001704 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1705 "could not allocate dasd "
1706 "block structure");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001707 rc = PTR_ERR(block);
1708 goto out_err1;
1709 }
1710 device->block = block;
1711 block->base = device;
1712 }
1713
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01001714 /* register lcu with alias handling, enable PAV */
1715 rc = dasd_alias_make_device_known_to_lcu(device);
1716 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001717 goto out_err2;
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01001718
Stefan Haberland12d7b102012-09-11 15:10:58 +02001719 dasd_eckd_validate_server(device, 0);
Stefan Weinhuberf4ac1d02009-12-07 12:51:53 +01001720
1721 /* device may report different configuration data after LCU setup */
1722 rc = dasd_eckd_read_conf(device);
1723 if (rc)
1724 goto out_err3;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001725
1726 /* Read Feature Codes */
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02001727 dasd_eckd_read_features(device);
Horst Hummel40545572006-06-29 15:08:18 +02001728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001730 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1731 &private->rdc_data, 64);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001732 if (rc) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001733 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1734 "Read device characteristic failed, rc=%d", rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001735 goto out_err3;
1736 }
Stefan Haberland34cd5512011-08-03 16:44:23 +02001737
1738 if ((device->features & DASD_FEATURE_USERAW) &&
1739 !(private->rdc_data.facilities.RT_in_LR)) {
1740 dev_err(&device->cdev->dev, "The storage server does not "
1741 "support raw-track access\n");
1742 rc = -EINVAL;
1743 goto out_err3;
1744 }
1745
Nikanth Karthikesan817f2c82010-09-20 11:44:00 +05301746 /* find the valid cylinder size */
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01001747 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1748 private->rdc_data.long_no_cyl)
1749 private->real_cyl = private->rdc_data.long_no_cyl;
1750 else
1751 private->real_cyl = private->rdc_data.no_cyl;
1752
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01001753 private->fcx_max_data = get_fcx_max_data(device);
1754
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01001755 readonly = dasd_device_is_ro(device);
1756 if (readonly)
1757 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1758
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001759 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01001760 "with %d cylinders, %d heads, %d sectors%s\n",
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001761 private->rdc_data.dev_type,
1762 private->rdc_data.dev_model,
1763 private->rdc_data.cu_type,
1764 private->rdc_data.cu_model.model,
Sebastian Ott92636b12009-06-12 10:26:37 +02001765 private->real_cyl,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001766 private->rdc_data.trk_per_cyl,
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01001767 private->rdc_data.sec_per_trk,
1768 readonly ? ", read-only device" : "");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001769 return 0;
1770
1771out_err3:
1772 dasd_alias_disconnect_device_from_lcu(device);
1773out_err2:
1774 dasd_free_block(device->block);
1775 device->block = NULL;
1776out_err1:
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001777 kfree(private->conf_data);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001778 kfree(device->private);
1779 device->private = NULL;
Horst Hummel3d052592006-04-27 18:40:28 -07001780 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781}
1782
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001783static void dasd_eckd_uncheck_device(struct dasd_device *device)
1784{
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001785 struct dasd_eckd_private *private;
1786
1787 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001788 dasd_alias_disconnect_device_from_lcu(device);
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02001789 private->ned = NULL;
1790 private->sneq = NULL;
1791 private->vdsneq = NULL;
1792 private->gneq = NULL;
1793 private->conf_len = 0;
1794 kfree(private->conf_data);
1795 private->conf_data = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001796}
1797
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798static struct dasd_ccw_req *
1799dasd_eckd_analysis_ccw(struct dasd_device *device)
1800{
1801 struct dasd_eckd_private *private;
1802 struct eckd_count *count_data;
1803 struct LO_eckd_data *LO_data;
1804 struct dasd_ccw_req *cqr;
1805 struct ccw1 *ccw;
1806 int cplength, datasize;
1807 int i;
1808
1809 private = (struct dasd_eckd_private *) device->private;
1810
1811 cplength = 8;
1812 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
Stefan Haberland68b781f2009-09-11 10:28:29 +02001813 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 if (IS_ERR(cqr))
1815 return cqr;
1816 ccw = cqr->cpaddr;
1817 /* Define extent for the first 3 tracks. */
1818 define_extent(ccw++, cqr->data, 0, 2,
1819 DASD_ECKD_CCW_READ_COUNT, device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001820 LO_data = cqr->data + sizeof(struct DE_eckd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 /* Locate record for the first 4 records on track 0. */
1822 ccw[-1].flags |= CCW_FLAG_CC;
1823 locate_record(ccw++, LO_data++, 0, 0, 4,
1824 DASD_ECKD_CCW_READ_COUNT, device, 0);
1825
1826 count_data = private->count_area;
1827 for (i = 0; i < 4; i++) {
1828 ccw[-1].flags |= CCW_FLAG_CC;
1829 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1830 ccw->flags = 0;
1831 ccw->count = 8;
1832 ccw->cda = (__u32)(addr_t) count_data;
1833 ccw++;
1834 count_data++;
1835 }
1836
1837 /* Locate record for the first record on track 2. */
1838 ccw[-1].flags |= CCW_FLAG_CC;
1839 locate_record(ccw++, LO_data++, 2, 0, 1,
1840 DASD_ECKD_CCW_READ_COUNT, device, 0);
1841 /* Read count ccw. */
1842 ccw[-1].flags |= CCW_FLAG_CC;
1843 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1844 ccw->flags = 0;
1845 ccw->count = 8;
1846 ccw->cda = (__u32)(addr_t) count_data;
1847
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001848 cqr->block = NULL;
1849 cqr->startdev = device;
1850 cqr->memdev = device;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001851 cqr->retries = 255;
Heiko Carstens1aae0562013-01-30 09:49:40 +01001852 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 cqr->status = DASD_CQR_FILLED;
1854 return cqr;
1855}
1856
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001857/* differentiate between 'no record found' and any other error */
1858static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1859{
1860 char *sense;
1861 if (init_cqr->status == DASD_CQR_DONE)
1862 return INIT_CQR_OK;
1863 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1864 init_cqr->status == DASD_CQR_FAILED) {
1865 sense = dasd_get_sense(&init_cqr->irb);
1866 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1867 return INIT_CQR_UNFORMATTED;
1868 else
1869 return INIT_CQR_ERROR;
1870 } else
1871 return INIT_CQR_ERROR;
1872}
1873
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874/*
1875 * This is the callback function for the init_analysis cqr. It saves
1876 * the status of the initial analysis ccw before it frees it and kicks
1877 * the device to continue the startup sequence. This will call
1878 * dasd_eckd_do_analysis again (if the devices has not been marked
1879 * for deletion in the meantime).
1880 */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001881static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1882 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883{
1884 struct dasd_eckd_private *private;
1885 struct dasd_device *device;
1886
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001887 device = init_cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001889 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 dasd_sfree_request(init_cqr, device);
1891 dasd_kick_device(device);
1892}
1893
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001894static int dasd_eckd_start_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 struct dasd_ccw_req *init_cqr;
1897
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001898 init_cqr = dasd_eckd_analysis_ccw(block->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 if (IS_ERR(init_cqr))
1900 return PTR_ERR(init_cqr);
1901 init_cqr->callback = dasd_eckd_analysis_callback;
1902 init_cqr->callback_data = NULL;
1903 init_cqr->expires = 5*HZ;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001904 /* first try without ERP, so we can later handle unformatted
1905 * devices as special case
1906 */
1907 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1908 init_cqr->retries = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 dasd_add_request_head(init_cqr);
1910 return -EAGAIN;
1911}
1912
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001913static int dasd_eckd_end_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001915 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 struct dasd_eckd_private *private;
1917 struct eckd_count *count_area;
1918 unsigned int sb, blk_per_trk;
1919 int status, i;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001920 struct dasd_ccw_req *init_cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001922 device = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 private = (struct dasd_eckd_private *) device->private;
1924 status = private->init_cqr_status;
1925 private->init_cqr_status = -1;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001926 if (status == INIT_CQR_ERROR) {
1927 /* try again, this time with full ERP */
1928 init_cqr = dasd_eckd_analysis_ccw(device);
1929 dasd_sleep_on(init_cqr);
1930 status = dasd_eckd_analysis_evaluation(init_cqr);
1931 dasd_sfree_request(init_cqr, device);
1932 }
1933
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01001934 if (device->features & DASD_FEATURE_USERAW) {
1935 block->bp_block = DASD_RAW_BLOCKSIZE;
1936 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1937 block->s2b_shift = 3;
1938 goto raw;
1939 }
1940
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001941 if (status == INIT_CQR_UNFORMATTED) {
1942 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 return -EMEDIUMTYPE;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001944 } else if (status == INIT_CQR_ERROR) {
1945 dev_err(&device->cdev->dev,
1946 "Detecting the DASD disk layout failed because "
1947 "of an I/O error\n");
1948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
1950
1951 private->uses_cdl = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 /* Check Track 0 for Compatible Disk Layout */
1953 count_area = NULL;
1954 for (i = 0; i < 3; i++) {
1955 if (private->count_area[i].kl != 4 ||
Stefan Haberland3bc9fef92012-09-20 18:37:36 +02001956 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
1957 private->count_area[i].cyl != 0 ||
1958 private->count_area[i].head != count_area_head[i] ||
1959 private->count_area[i].record != count_area_rec[i]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 private->uses_cdl = 0;
1961 break;
1962 }
1963 }
1964 if (i == 3)
1965 count_area = &private->count_area[4];
1966
1967 if (private->uses_cdl == 0) {
1968 for (i = 0; i < 5; i++) {
1969 if ((private->count_area[i].kl != 0) ||
1970 (private->count_area[i].dl !=
Stefan Haberland3bc9fef92012-09-20 18:37:36 +02001971 private->count_area[0].dl) ||
1972 private->count_area[i].cyl != 0 ||
1973 private->count_area[i].head != count_area_head[i] ||
1974 private->count_area[i].record != count_area_rec[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 break;
1976 }
1977 if (i == 5)
1978 count_area = &private->count_area[0];
1979 } else {
1980 if (private->count_area[3].record == 1)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001981 dev_warn(&device->cdev->dev,
1982 "Track 0 has no records following the VTOC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 }
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01001984
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 if (count_area != NULL && count_area->kl == 0) {
1986 /* we found notthing violating our disk layout */
1987 if (dasd_check_blocksize(count_area->dl) == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001988 block->bp_block = count_area->dl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001990 if (block->bp_block == 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001991 dev_warn(&device->cdev->dev,
1992 "The disk layout of the DASD is not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 return -EMEDIUMTYPE;
1994 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001995 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1996 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1997 block->s2b_shift++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001999 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01002000
2001raw:
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01002002 block->blocks = (private->real_cyl *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 private->rdc_data.trk_per_cyl *
2004 blk_per_trk);
2005
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002006 dev_info(&device->cdev->dev,
2007 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2008 "%s\n", (block->bp_block >> 10),
2009 ((private->real_cyl *
2010 private->rdc_data.trk_per_cyl *
2011 blk_per_trk * (block->bp_block >> 9)) >> 1),
2012 ((blk_per_trk * block->bp_block) >> 10),
2013 private->uses_cdl ?
2014 "compatible disk layout" : "linux disk layout");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016 return 0;
2017}
2018
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002019static int dasd_eckd_do_analysis(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 struct dasd_eckd_private *private;
2022
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002023 private = (struct dasd_eckd_private *) block->base->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 if (private->init_cqr_status < 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002025 return dasd_eckd_start_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002027 return dasd_eckd_end_analysis(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028}
2029
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002030static int dasd_eckd_basic_to_ready(struct dasd_device *device)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002031{
2032 return dasd_alias_add_device(device);
2033};
2034
2035static int dasd_eckd_online_to_ready(struct dasd_device *device)
2036{
Stefan Haberland501183f2010-05-17 10:00:10 +02002037 cancel_work_sync(&device->reload_device);
Stefan Haberland25e2cf12012-03-11 11:59:37 -04002038 cancel_work_sync(&device->kick_validate);
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002039 return 0;
2040};
2041
2042static int dasd_eckd_ready_to_basic(struct dasd_device *device)
2043{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002044 return dasd_alias_remove_device(device);
2045};
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002048dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
2050 struct dasd_eckd_private *private;
2051
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002052 private = (struct dasd_eckd_private *) block->base->private;
2053 if (dasd_check_blocksize(block->bp_block) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 geo->sectors = recs_per_track(&private->rdc_data,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002055 0, block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
2057 geo->cylinders = private->rdc_data.no_cyl;
2058 geo->heads = private->rdc_data.trk_per_cyl;
2059 return 0;
2060}
2061
2062static struct dasd_ccw_req *
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002063dasd_eckd_build_format(struct dasd_device *base,
2064 struct format_data_t *fdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002066 struct dasd_eckd_private *base_priv;
2067 struct dasd_eckd_private *start_priv;
2068 struct dasd_device *startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 struct dasd_ccw_req *fcp;
2070 struct eckd_count *ect;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002071 struct ch_t address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct ccw1 *ccw;
2073 void *data;
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01002074 int rpt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 int cplength, datasize;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002076 int i, j;
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01002077 int intensity = 0;
2078 int r0_perm;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002079 int nr_tracks;
Stefan Haberland18d66242013-10-09 14:30:08 +02002080 int use_prefix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002082 startdev = dasd_alias_get_start_dev(base);
2083 if (!startdev)
2084 startdev = base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002086 start_priv = (struct dasd_eckd_private *) startdev->private;
2087 base_priv = (struct dasd_eckd_private *) base->private;
2088
2089 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2090
2091 nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 /*
2094 * fdata->intensity is a bit string that tells us what to do:
2095 * Bit 0: write record zero
2096 * Bit 1: write home address, currently not supported
2097 * Bit 2: invalidate tracks
2098 * Bit 3: use OS/390 compatible disk layout (cdl)
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01002099 * Bit 4: do not allow storage subsystem to modify record zero
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 * Only some bit combinations do make sense.
2101 */
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01002102 if (fdata->intensity & 0x10) {
2103 r0_perm = 0;
2104 intensity = fdata->intensity & ~0x10;
2105 } else {
2106 r0_perm = 1;
2107 intensity = fdata->intensity;
2108 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002109
Stefan Haberland18d66242013-10-09 14:30:08 +02002110 use_prefix = base_priv->features.feature[8] & 0x01;
2111
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01002112 switch (intensity) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 case 0x00: /* Normal format */
2114 case 0x08: /* Normal format, use cdl. */
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002115 cplength = 2 + (rpt*nr_tracks);
Stefan Haberland18d66242013-10-09 14:30:08 +02002116 if (use_prefix)
2117 datasize = sizeof(struct PFX_eckd_data) +
2118 sizeof(struct LO_eckd_data) +
2119 rpt * nr_tracks * sizeof(struct eckd_count);
2120 else
2121 datasize = sizeof(struct DE_eckd_data) +
2122 sizeof(struct LO_eckd_data) +
2123 rpt * nr_tracks * sizeof(struct eckd_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 break;
2125 case 0x01: /* Write record zero and format track. */
2126 case 0x09: /* Write record zero and format track, use cdl. */
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002127 cplength = 2 + rpt * nr_tracks;
Stefan Haberland18d66242013-10-09 14:30:08 +02002128 if (use_prefix)
2129 datasize = sizeof(struct PFX_eckd_data) +
2130 sizeof(struct LO_eckd_data) +
2131 sizeof(struct eckd_count) +
2132 rpt * nr_tracks * sizeof(struct eckd_count);
2133 else
2134 datasize = sizeof(struct DE_eckd_data) +
2135 sizeof(struct LO_eckd_data) +
2136 sizeof(struct eckd_count) +
2137 rpt * nr_tracks * sizeof(struct eckd_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 break;
2139 case 0x04: /* Invalidate track. */
2140 case 0x0c: /* Invalidate track, use cdl. */
2141 cplength = 3;
Stefan Haberland18d66242013-10-09 14:30:08 +02002142 if (use_prefix)
2143 datasize = sizeof(struct PFX_eckd_data) +
2144 sizeof(struct LO_eckd_data) +
2145 sizeof(struct eckd_count);
2146 else
2147 datasize = sizeof(struct DE_eckd_data) +
2148 sizeof(struct LO_eckd_data) +
2149 sizeof(struct eckd_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 break;
2151 default:
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002152 dev_warn(&startdev->cdev->dev,
2153 "An I/O control call used incorrect flags 0x%x\n",
2154 fdata->intensity);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 return ERR_PTR(-EINVAL);
2156 }
2157 /* Allocate the format ccw request. */
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002158 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2159 datasize, startdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 if (IS_ERR(fcp))
2161 return fcp;
2162
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002163 start_priv->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 data = fcp->data;
2165 ccw = fcp->cpaddr;
2166
Jean-Baptiste Joretf9a28f72009-03-26 15:23:46 +01002167 switch (intensity & ~0x08) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 case 0x00: /* Normal format. */
Stefan Haberland18d66242013-10-09 14:30:08 +02002169 if (use_prefix) {
2170 prefix(ccw++, (struct PFX_eckd_data *) data,
2171 fdata->start_unit, fdata->stop_unit,
2172 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2173 /* grant subsystem permission to format R0 */
2174 if (r0_perm)
2175 ((struct PFX_eckd_data *)data)
2176 ->define_extent.ga_extended |= 0x04;
2177 data += sizeof(struct PFX_eckd_data);
2178 } else {
2179 define_extent(ccw++, (struct DE_eckd_data *) data,
2180 fdata->start_unit, fdata->stop_unit,
2181 DASD_ECKD_CCW_WRITE_CKD, startdev);
2182 /* grant subsystem permission to format R0 */
2183 if (r0_perm)
2184 ((struct DE_eckd_data *) data)
2185 ->ga_extended |= 0x04;
2186 data += sizeof(struct DE_eckd_data);
2187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 ccw[-1].flags |= CCW_FLAG_CC;
2189 locate_record(ccw++, (struct LO_eckd_data *) data,
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002190 fdata->start_unit, 0, rpt*nr_tracks,
2191 DASD_ECKD_CCW_WRITE_CKD, base,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 fdata->blksize);
2193 data += sizeof(struct LO_eckd_data);
2194 break;
2195 case 0x01: /* Write record zero + format track. */
Stefan Haberland18d66242013-10-09 14:30:08 +02002196 if (use_prefix) {
2197 prefix(ccw++, (struct PFX_eckd_data *) data,
2198 fdata->start_unit, fdata->stop_unit,
2199 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2200 base, startdev);
2201 data += sizeof(struct PFX_eckd_data);
2202 } else {
2203 define_extent(ccw++, (struct DE_eckd_data *) data,
2204 fdata->start_unit, fdata->stop_unit,
2205 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
2206 data += sizeof(struct DE_eckd_data);
2207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 ccw[-1].flags |= CCW_FLAG_CC;
2209 locate_record(ccw++, (struct LO_eckd_data *) data,
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002210 fdata->start_unit, 0, rpt * nr_tracks + 1,
2211 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2212 base->block->bp_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 data += sizeof(struct LO_eckd_data);
2214 break;
2215 case 0x04: /* Invalidate track. */
Stefan Haberland18d66242013-10-09 14:30:08 +02002216 if (use_prefix) {
2217 prefix(ccw++, (struct PFX_eckd_data *) data,
2218 fdata->start_unit, fdata->stop_unit,
2219 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2220 data += sizeof(struct PFX_eckd_data);
2221 } else {
2222 define_extent(ccw++, (struct DE_eckd_data *) data,
2223 fdata->start_unit, fdata->stop_unit,
2224 DASD_ECKD_CCW_WRITE_CKD, startdev);
2225 data += sizeof(struct DE_eckd_data);
2226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 ccw[-1].flags |= CCW_FLAG_CC;
2228 locate_record(ccw++, (struct LO_eckd_data *) data,
2229 fdata->start_unit, 0, 1,
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002230 DASD_ECKD_CCW_WRITE_CKD, base, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 data += sizeof(struct LO_eckd_data);
2232 break;
2233 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002234
2235 for (j = 0; j < nr_tracks; j++) {
2236 /* calculate cylinder and head for the current track */
2237 set_ch_t(&address,
2238 (fdata->start_unit + j) /
2239 base_priv->rdc_data.trk_per_cyl,
2240 (fdata->start_unit + j) %
2241 base_priv->rdc_data.trk_per_cyl);
2242 if (intensity & 0x01) { /* write record zero */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 ect = (struct eckd_count *) data;
2244 data += sizeof(struct eckd_count);
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +01002245 ect->cyl = address.cyl;
2246 ect->head = address.head;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002247 ect->record = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 ect->kl = 0;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002249 ect->dl = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 ccw[-1].flags |= CCW_FLAG_CC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002251 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 ccw->flags = CCW_FLAG_SLI;
2253 ccw->count = 8;
2254 ccw->cda = (__u32)(addr_t) ect;
2255 ccw++;
2256 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002257 if ((intensity & ~0x08) & 0x04) { /* erase track */
2258 ect = (struct eckd_count *) data;
2259 data += sizeof(struct eckd_count);
2260 ect->cyl = address.cyl;
2261 ect->head = address.head;
2262 ect->record = 1;
2263 ect->kl = 0;
2264 ect->dl = 0;
2265 ccw[-1].flags |= CCW_FLAG_CC;
2266 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2267 ccw->flags = CCW_FLAG_SLI;
2268 ccw->count = 8;
2269 ccw->cda = (__u32)(addr_t) ect;
2270 } else { /* write remaining records */
2271 for (i = 0; i < rpt; i++) {
2272 ect = (struct eckd_count *) data;
2273 data += sizeof(struct eckd_count);
2274 ect->cyl = address.cyl;
2275 ect->head = address.head;
2276 ect->record = i + 1;
2277 ect->kl = 0;
2278 ect->dl = fdata->blksize;
2279 /*
2280 * Check for special tracks 0-1
2281 * when formatting CDL
2282 */
2283 if ((intensity & 0x08) &&
2284 fdata->start_unit == 0) {
2285 if (i < 3) {
2286 ect->kl = 4;
2287 ect->dl = sizes_trk0[i] - 4;
2288 }
2289 }
2290 if ((intensity & 0x08) &&
2291 fdata->start_unit == 1) {
2292 ect->kl = 44;
2293 ect->dl = LABEL_SIZE - 44;
2294 }
2295 ccw[-1].flags |= CCW_FLAG_CC;
2296 if (i != 0 || j == 0)
2297 ccw->cmd_code =
2298 DASD_ECKD_CCW_WRITE_CKD;
2299 else
2300 ccw->cmd_code =
2301 DASD_ECKD_CCW_WRITE_CKD_MT;
2302 ccw->flags = CCW_FLAG_SLI;
2303 ccw->count = 8;
2304 ccw->cda = (__u32)(addr_t) ect;
2305 ccw++;
2306 }
2307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002309
2310 fcp->startdev = startdev;
2311 fcp->memdev = startdev;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002312 fcp->retries = 256;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002313 fcp->expires = startdev->default_expires * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01002314 fcp->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 fcp->status = DASD_CQR_FILLED;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 return fcp;
2318}
2319
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002320static int
2321dasd_eckd_format_device(struct dasd_device *base,
2322 struct format_data_t *fdata)
2323{
2324 struct dasd_ccw_req *cqr, *n;
2325 struct dasd_block *block;
2326 struct dasd_eckd_private *private;
2327 struct list_head format_queue;
2328 struct dasd_device *device;
2329 int old_stop, format_step;
2330 int step, rc = 0;
2331
2332 block = base->block;
2333 private = (struct dasd_eckd_private *) base->private;
2334
2335 /* Sanity checks. */
2336 if (fdata->start_unit >=
2337 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2338 dev_warn(&base->cdev->dev,
2339 "Start track number %u used in formatting is too big\n",
2340 fdata->start_unit);
2341 return -EINVAL;
2342 }
2343 if (fdata->stop_unit >=
2344 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2345 dev_warn(&base->cdev->dev,
2346 "Stop track number %u used in formatting is too big\n",
2347 fdata->stop_unit);
2348 return -EINVAL;
2349 }
2350 if (fdata->start_unit > fdata->stop_unit) {
2351 dev_warn(&base->cdev->dev,
2352 "Start track %u used in formatting exceeds end track\n",
2353 fdata->start_unit);
2354 return -EINVAL;
2355 }
2356 if (dasd_check_blocksize(fdata->blksize) != 0) {
2357 dev_warn(&base->cdev->dev,
2358 "The DASD cannot be formatted with block size %u\n",
2359 fdata->blksize);
2360 return -EINVAL;
2361 }
2362
2363 INIT_LIST_HEAD(&format_queue);
2364 old_stop = fdata->stop_unit;
2365
2366 while (fdata->start_unit <= 1) {
2367 fdata->stop_unit = fdata->start_unit;
2368 cqr = dasd_eckd_build_format(base, fdata);
2369 list_add(&cqr->blocklist, &format_queue);
2370
2371 fdata->stop_unit = old_stop;
2372 fdata->start_unit++;
2373
2374 if (fdata->start_unit > fdata->stop_unit)
2375 goto sleep;
2376 }
2377
2378retry:
2379 format_step = 255 / recs_per_track(&private->rdc_data, 0,
2380 fdata->blksize);
2381 while (fdata->start_unit <= old_stop) {
2382 step = fdata->stop_unit - fdata->start_unit + 1;
2383 if (step > format_step)
2384 fdata->stop_unit = fdata->start_unit + format_step - 1;
2385
2386 cqr = dasd_eckd_build_format(base, fdata);
2387 if (IS_ERR(cqr)) {
2388 if (PTR_ERR(cqr) == -ENOMEM) {
2389 /*
2390 * not enough memory available
2391 * go to out and start requests
2392 * retry after first requests were finished
2393 */
2394 fdata->stop_unit = old_stop;
2395 goto sleep;
2396 } else
2397 return PTR_ERR(cqr);
2398 }
2399 list_add(&cqr->blocklist, &format_queue);
2400
2401 fdata->start_unit = fdata->stop_unit + 1;
2402 fdata->stop_unit = old_stop;
2403 }
2404
2405sleep:
2406 dasd_sleep_on_queue(&format_queue);
2407
2408 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2409 device = cqr->startdev;
2410 private = (struct dasd_eckd_private *) device->private;
2411 if (cqr->status == DASD_CQR_FAILED)
2412 rc = -EIO;
2413 list_del_init(&cqr->blocklist);
2414 dasd_sfree_request(cqr, device);
2415 private->count--;
2416 }
2417
2418 /*
2419 * in case of ENOMEM we need to retry after
2420 * first requests are finished
2421 */
2422 if (fdata->start_unit <= fdata->stop_unit)
2423 goto retry;
2424
2425 return rc;
2426}
2427
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002428static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Hannes Reineckea2ace462013-01-30 09:26:14 +00002430 if (cqr->retries < 0) {
2431 cqr->status = DASD_CQR_FAILED;
2432 return;
2433 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002434 cqr->status = DASD_CQR_FILLED;
2435 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2436 dasd_eckd_reset_ccw_to_base_io(cqr);
2437 cqr->startdev = cqr->block->base;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002438 cqr->lpm = cqr->block->base->path_data.opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002440};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442static dasd_erp_fn_t
2443dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2444{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002445 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 struct ccw_device *cdev = device->cdev;
2447
2448 switch (cdev->id.cu_type) {
2449 case 0x3990:
2450 case 0x2105:
2451 case 0x2107:
2452 case 0x1750:
2453 return dasd_3990_erp_action;
2454 case 0x9343:
2455 case 0x3880:
2456 default:
2457 return dasd_default_erp_action;
2458 }
2459}
2460
2461static dasd_erp_fn_t
2462dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2463{
2464 return dasd_default_erp_postaction;
2465}
2466
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002467static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2468 struct dasd_ccw_req *cqr,
2469 struct irb *irb)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002470{
2471 char mask;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002472 char *sense = NULL;
Stefan Haberland501183f2010-05-17 10:00:10 +02002473 struct dasd_eckd_private *private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002474
Stefan Haberland501183f2010-05-17 10:00:10 +02002475 private = (struct dasd_eckd_private *) device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002476 /* first of all check for state change pending interrupt */
2477 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002478 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01002479 /*
2480 * for alias only, not in offline processing
2481 * and only if not suspended
2482 */
Stefan Haberland501183f2010-05-17 10:00:10 +02002483 if (!device->block && private->lcu &&
Stefan Haberland25e2cf12012-03-11 11:59:37 -04002484 device->state == DASD_STATE_ONLINE &&
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01002485 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2486 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
Stefan Haberland501183f2010-05-17 10:00:10 +02002487 /*
2488 * the state change could be caused by an alias
2489 * reassignment remove device from alias handling
2490 * to prevent new requests from being scheduled on
2491 * the wrong alias device
2492 */
2493 dasd_alias_remove_device(device);
2494
2495 /* schedule worker to reload device */
2496 dasd_reload_device(device);
2497 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002498 dasd_generic_handle_state_change(device);
2499 return;
2500 }
2501
Stefan Weinhubera5a00612010-10-25 16:10:47 +02002502 sense = dasd_get_sense(irb);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002503 if (!sense)
2504 return;
2505
2506 /* summary unit check */
Stefan Weinhuberc7a29e52011-04-20 10:15:35 +02002507 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
Stefan Weinhubera5a00612010-10-25 16:10:47 +02002508 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002509 dasd_alias_handle_summary_unit_check(device, irb);
2510 return;
2511 }
2512
Stefan Haberlandf60c7682008-04-17 07:46:08 +02002513 /* service information message SIM */
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002514 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002515 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2516 dasd_3990_erp_handle_sim(device, sense);
Stefan Haberlandf60c7682008-04-17 07:46:08 +02002517 return;
2518 }
2519
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002520 /* loss of device reservation is handled via base devices only
2521 * as alias devices may be used with several bases
2522 */
Stefan Weinhuberc7a29e52011-04-20 10:15:35 +02002523 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
2524 (sense[7] == 0x3F) &&
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002525 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2526 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2527 if (device->features & DASD_FEATURE_FAILONSLCK)
2528 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2529 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2530 dev_err(&device->cdev->dev,
2531 "The device reservation was lost\n");
Stefan Haberlandada3df92008-10-10 21:33:23 +02002532 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002533}
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002534
2535static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2536 struct dasd_device *startdev,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002537 struct dasd_block *block,
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002538 struct request *req,
2539 sector_t first_rec,
2540 sector_t last_rec,
2541 sector_t first_trk,
2542 sector_t last_trk,
2543 unsigned int first_offs,
2544 unsigned int last_offs,
2545 unsigned int blk_per_trk,
2546 unsigned int blksize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
2548 struct dasd_eckd_private *private;
2549 unsigned long *idaws;
2550 struct LO_eckd_data *LO_data;
2551 struct dasd_ccw_req *cqr;
2552 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02002553 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct bio_vec *bv;
2555 char *dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002556 unsigned int off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 int count, cidaw, cplength, datasize;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002558 sector_t recid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 unsigned char cmd, rcmd;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002560 int use_prefix;
2561 struct dasd_device *basedev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002563 basedev = block->base;
2564 private = (struct dasd_eckd_private *) basedev->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (rq_data_dir(req) == READ)
2566 cmd = DASD_ECKD_CCW_READ_MT;
2567 else if (rq_data_dir(req) == WRITE)
2568 cmd = DASD_ECKD_CCW_WRITE_MT;
2569 else
2570 return ERR_PTR(-EINVAL);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002571
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 /* Check struct bio and count the number of blocks for the request. */
2573 count = 0;
2574 cidaw = 0;
NeilBrown5705f702007-09-25 12:35:59 +02002575 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +02002576 if (bv->bv_len & (blksize - 1))
2577 /* Eckd can only do full blocks. */
2578 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002579 count += bv->bv_len >> (block->s2b_shift + 9);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08002580#if defined(CONFIG_64BIT)
Jens Axboe6c92e692007-08-16 13:43:12 +02002581 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002582 cidaw += bv->bv_len >> (block->s2b_shift + 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 }
2585 /* Paranoia. */
2586 if (count != last_rec - first_rec + 1)
2587 return ERR_PTR(-EINVAL);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002588
2589 /* use the prefix command if available */
2590 use_prefix = private->features.feature[8] & 0x01;
2591 if (use_prefix) {
2592 /* 1x prefix + number of blocks */
2593 cplength = 2 + count;
2594 /* 1x prefix + cidaws*sizeof(long) */
2595 datasize = sizeof(struct PFX_eckd_data) +
2596 sizeof(struct LO_eckd_data) +
2597 cidaw * sizeof(unsigned long);
2598 } else {
2599 /* 1x define extent + 1x locate record + number of blocks */
2600 cplength = 2 + count;
2601 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2602 datasize = sizeof(struct DE_eckd_data) +
2603 sizeof(struct LO_eckd_data) +
2604 cidaw * sizeof(unsigned long);
2605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* Find out the number of additional locate record ccws for cdl. */
2607 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2608 if (last_rec >= 2*blk_per_trk)
2609 count = 2*blk_per_trk - first_rec;
2610 cplength += count;
2611 datasize += count*sizeof(struct LO_eckd_data);
2612 }
2613 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +02002614 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2615 startdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 if (IS_ERR(cqr))
2617 return cqr;
2618 ccw = cqr->cpaddr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002619 /* First ccw is define extent or prefix. */
2620 if (use_prefix) {
2621 if (prefix(ccw++, cqr->data, first_trk,
2622 last_trk, cmd, basedev, startdev) == -EAGAIN) {
2623 /* Clock not in sync and XRC is enabled.
2624 * Try again later.
2625 */
2626 dasd_sfree_request(cqr, startdev);
2627 return ERR_PTR(-EAGAIN);
2628 }
2629 idaws = (unsigned long *) (cqr->data +
2630 sizeof(struct PFX_eckd_data));
2631 } else {
2632 if (define_extent(ccw++, cqr->data, first_trk,
Stefan Haberlandb38f27e2011-12-27 11:27:28 +01002633 last_trk, cmd, basedev) == -EAGAIN) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002634 /* Clock not in sync and XRC is enabled.
2635 * Try again later.
2636 */
2637 dasd_sfree_request(cqr, startdev);
2638 return ERR_PTR(-EAGAIN);
2639 }
2640 idaws = (unsigned long *) (cqr->data +
2641 sizeof(struct DE_eckd_data));
Martin Schwidefskyd54853e2007-02-05 21:18:19 +01002642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 /* Build locate_record+read/write/ccws. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2645 recid = first_rec;
2646 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2647 /* Only standard blocks so there is just one locate record. */
2648 ccw[-1].flags |= CCW_FLAG_CC;
2649 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002650 last_rec - recid + 1, cmd, basedev, blksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 }
NeilBrown5705f702007-09-25 12:35:59 +02002652 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 dst = page_address(bv->bv_page) + bv->bv_offset;
2654 if (dasd_page_cache) {
2655 char *copy = kmem_cache_alloc(dasd_page_cache,
Christoph Lameter441e1432006-12-06 20:33:19 -08002656 GFP_DMA | __GFP_NOWARN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 if (copy && rq_data_dir(req) == WRITE)
2658 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
2659 if (copy)
2660 dst = copy + bv->bv_offset;
2661 }
2662 for (off = 0; off < bv->bv_len; off += blksize) {
2663 sector_t trkid = recid;
2664 unsigned int recoffs = sector_div(trkid, blk_per_trk);
2665 rcmd = cmd;
2666 count = blksize;
2667 /* Locate record for cdl special block ? */
2668 if (private->uses_cdl && recid < 2*blk_per_trk) {
2669 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2670 rcmd |= 0x8;
2671 count = dasd_eckd_cdl_reclen(recid);
Horst Hummelec5883a2005-05-01 08:58:59 -07002672 if (count < blksize &&
2673 rq_data_dir(req) == READ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 memset(dst + count, 0xe5,
2675 blksize - count);
2676 }
2677 ccw[-1].flags |= CCW_FLAG_CC;
2678 locate_record(ccw++, LO_data++,
2679 trkid, recoffs + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002680 1, rcmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
2682 /* Locate record for standard blocks ? */
2683 if (private->uses_cdl && recid == 2*blk_per_trk) {
2684 ccw[-1].flags |= CCW_FLAG_CC;
2685 locate_record(ccw++, LO_data++,
2686 trkid, recoffs + 1,
2687 last_rec - recid + 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002688 cmd, basedev, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 }
2690 /* Read/write ccw. */
2691 ccw[-1].flags |= CCW_FLAG_CC;
2692 ccw->cmd_code = rcmd;
2693 ccw->count = count;
2694 if (idal_is_needed(dst, blksize)) {
2695 ccw->cda = (__u32)(addr_t) idaws;
2696 ccw->flags = CCW_FLAG_IDA;
2697 idaws = idal_create_words(idaws, dst, blksize);
2698 } else {
2699 ccw->cda = (__u32)(addr_t) dst;
2700 ccw->flags = 0;
2701 }
2702 ccw++;
2703 dst += blksize;
2704 recid++;
2705 }
2706 }
Holger Smolinski13de2272009-01-09 12:14:51 +01002707 if (blk_noretry_request(req) ||
2708 block->base->features & DASD_FEATURE_FAILFAST)
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002709 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002710 cqr->startdev = startdev;
2711 cqr->memdev = startdev;
2712 cqr->block = block;
Stefan Haberland7c8faa82010-08-09 18:13:00 +02002713 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002714 cqr->lpm = startdev->path_data.ppm;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00002715 cqr->retries = startdev->default_retries;
Heiko Carstens1aae0562013-01-30 09:49:40 +01002716 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 cqr->status = DASD_CQR_FILLED;
2718 return cqr;
2719}
2720
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002721static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2722 struct dasd_device *startdev,
2723 struct dasd_block *block,
2724 struct request *req,
2725 sector_t first_rec,
2726 sector_t last_rec,
2727 sector_t first_trk,
2728 sector_t last_trk,
2729 unsigned int first_offs,
2730 unsigned int last_offs,
2731 unsigned int blk_per_trk,
2732 unsigned int blksize)
2733{
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002734 unsigned long *idaws;
2735 struct dasd_ccw_req *cqr;
2736 struct ccw1 *ccw;
2737 struct req_iterator iter;
2738 struct bio_vec *bv;
2739 char *dst, *idaw_dst;
2740 unsigned int cidaw, cplength, datasize;
2741 unsigned int tlf;
2742 sector_t recid;
2743 unsigned char cmd;
2744 struct dasd_device *basedev;
2745 unsigned int trkcount, count, count_to_trk_end;
2746 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2747 unsigned char new_track, end_idaw;
2748 sector_t trkid;
2749 unsigned int recoffs;
2750
2751 basedev = block->base;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002752 if (rq_data_dir(req) == READ)
2753 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2754 else if (rq_data_dir(req) == WRITE)
2755 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2756 else
2757 return ERR_PTR(-EINVAL);
2758
2759 /* Track based I/O needs IDAWs for each page, and not just for
2760 * 64 bit addresses. We need additional idals for pages
2761 * that get filled from two tracks, so we use the number
2762 * of records as upper limit.
2763 */
2764 cidaw = last_rec - first_rec + 1;
2765 trkcount = last_trk - first_trk + 1;
2766
2767 /* 1x prefix + one read/write ccw per track */
2768 cplength = 1 + trkcount;
2769
2770 /* on 31-bit we need space for two 32 bit addresses per page
2771 * on 64-bit one 64 bit address
2772 */
2773 datasize = sizeof(struct PFX_eckd_data) +
2774 cidaw * sizeof(unsigned long long);
2775
2776 /* Allocate the ccw request. */
Stefan Haberland68b781f2009-09-11 10:28:29 +02002777 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2778 startdev);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002779 if (IS_ERR(cqr))
2780 return cqr;
2781 ccw = cqr->cpaddr;
2782 /* transfer length factor: how many bytes to read from the last track */
2783 if (first_trk == last_trk)
2784 tlf = last_offs - first_offs + 1;
2785 else
2786 tlf = last_offs + 1;
2787 tlf *= blksize;
2788
2789 if (prefix_LRE(ccw++, cqr->data, first_trk,
2790 last_trk, cmd, basedev, startdev,
2791 1 /* format */, first_offs + 1,
2792 trkcount, blksize,
2793 tlf) == -EAGAIN) {
2794 /* Clock not in sync and XRC is enabled.
2795 * Try again later.
2796 */
2797 dasd_sfree_request(cqr, startdev);
2798 return ERR_PTR(-EAGAIN);
2799 }
2800
2801 /*
2802 * The translation of request into ccw programs must meet the
2803 * following conditions:
2804 * - all idaws but the first and the last must address full pages
2805 * (or 2K blocks on 31-bit)
2806 * - the scope of a ccw and it's idal ends with the track boundaries
2807 */
2808 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2809 recid = first_rec;
2810 new_track = 1;
2811 end_idaw = 0;
2812 len_to_track_end = 0;
Martin Schwidefsky246ccea2011-10-30 15:17:16 +01002813 idaw_dst = NULL;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002814 idaw_len = 0;
2815 rq_for_each_segment(bv, req, iter) {
2816 dst = page_address(bv->bv_page) + bv->bv_offset;
2817 seg_len = bv->bv_len;
2818 while (seg_len) {
2819 if (new_track) {
2820 trkid = recid;
2821 recoffs = sector_div(trkid, blk_per_trk);
2822 count_to_trk_end = blk_per_trk - recoffs;
2823 count = min((last_rec - recid + 1),
2824 (sector_t)count_to_trk_end);
2825 len_to_track_end = count * blksize;
2826 ccw[-1].flags |= CCW_FLAG_CC;
2827 ccw->cmd_code = cmd;
2828 ccw->count = len_to_track_end;
2829 ccw->cda = (__u32)(addr_t)idaws;
2830 ccw->flags = CCW_FLAG_IDA;
2831 ccw++;
2832 recid += count;
2833 new_track = 0;
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002834 /* first idaw for a ccw may start anywhere */
2835 if (!idaw_dst)
2836 idaw_dst = dst;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002837 }
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002838 /* If we start a new idaw, we must make sure that it
2839 * starts on an IDA_BLOCK_SIZE boundary.
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002840 * If we continue an idaw, we must make sure that the
2841 * current segment begins where the so far accumulated
2842 * idaw ends
2843 */
Stefan Weinhuber52db45c2009-04-14 15:36:24 +02002844 if (!idaw_dst) {
2845 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2846 dasd_sfree_request(cqr, startdev);
2847 return ERR_PTR(-ERANGE);
2848 } else
2849 idaw_dst = dst;
2850 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002851 if ((idaw_dst + idaw_len) != dst) {
2852 dasd_sfree_request(cqr, startdev);
2853 return ERR_PTR(-ERANGE);
2854 }
2855 part_len = min(seg_len, len_to_track_end);
2856 seg_len -= part_len;
2857 dst += part_len;
2858 idaw_len += part_len;
2859 len_to_track_end -= part_len;
2860 /* collected memory area ends on an IDA_BLOCK border,
2861 * -> create an idaw
2862 * idal_create_words will handle cases where idaw_len
2863 * is larger then IDA_BLOCK_SIZE
2864 */
2865 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2866 end_idaw = 1;
2867 /* We also need to end the idaw at track end */
2868 if (!len_to_track_end) {
2869 new_track = 1;
2870 end_idaw = 1;
2871 }
2872 if (end_idaw) {
2873 idaws = idal_create_words(idaws, idaw_dst,
2874 idaw_len);
Martin Schwidefsky246ccea2011-10-30 15:17:16 +01002875 idaw_dst = NULL;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002876 idaw_len = 0;
2877 end_idaw = 0;
2878 }
2879 }
2880 }
2881
2882 if (blk_noretry_request(req) ||
2883 block->base->features & DASD_FEATURE_FAILFAST)
2884 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2885 cqr->startdev = startdev;
2886 cqr->memdev = startdev;
2887 cqr->block = block;
Stefan Haberland7c8faa82010-08-09 18:13:00 +02002888 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002889 cqr->lpm = startdev->path_data.ppm;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00002890 cqr->retries = startdev->default_retries;
Heiko Carstens1aae0562013-01-30 09:49:40 +01002891 cqr->buildclk = get_tod_clock();
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002892 cqr->status = DASD_CQR_FILLED;
2893 return cqr;
2894}
2895
2896static int prepare_itcw(struct itcw *itcw,
2897 unsigned int trk, unsigned int totrk, int cmd,
2898 struct dasd_device *basedev,
2899 struct dasd_device *startdev,
2900 unsigned int rec_on_trk, int count,
2901 unsigned int blksize,
2902 unsigned int total_data_size,
2903 unsigned int tlf,
2904 unsigned int blk_per_trk)
2905{
2906 struct PFX_eckd_data pfxdata;
2907 struct dasd_eckd_private *basepriv, *startpriv;
2908 struct DE_eckd_data *dedata;
2909 struct LRE_eckd_data *lredata;
2910 struct dcw *dcw;
2911
2912 u32 begcyl, endcyl;
2913 u16 heads, beghead, endhead;
2914 u8 pfx_cmd;
2915
2916 int rc = 0;
2917 int sector = 0;
2918 int dn, d;
2919
2920
2921 /* setup prefix data */
2922 basepriv = (struct dasd_eckd_private *) basedev->private;
2923 startpriv = (struct dasd_eckd_private *) startdev->private;
2924 dedata = &pfxdata.define_extent;
2925 lredata = &pfxdata.locate_record;
2926
2927 memset(&pfxdata, 0, sizeof(pfxdata));
2928 pfxdata.format = 1; /* PFX with LRE */
2929 pfxdata.base_address = basepriv->ned->unit_addr;
2930 pfxdata.base_lss = basepriv->ned->ID;
2931 pfxdata.validity.define_extent = 1;
2932
2933 /* private uid is kept up to date, conf_data may be outdated */
2934 if (startpriv->uid.type != UA_BASE_DEVICE) {
2935 pfxdata.validity.verify_base = 1;
2936 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2937 pfxdata.validity.hyper_pav = 1;
2938 }
2939
2940 switch (cmd) {
2941 case DASD_ECKD_CCW_READ_TRACK_DATA:
2942 dedata->mask.perm = 0x1;
2943 dedata->attributes.operation = basepriv->attrib.operation;
2944 dedata->blk_size = blksize;
2945 dedata->ga_extended |= 0x42;
2946 lredata->operation.orientation = 0x0;
2947 lredata->operation.operation = 0x0C;
2948 lredata->auxiliary.check_bytes = 0x01;
2949 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2950 break;
2951 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2952 dedata->mask.perm = 0x02;
2953 dedata->attributes.operation = basepriv->attrib.operation;
2954 dedata->blk_size = blksize;
2955 rc = check_XRC_on_prefix(&pfxdata, basedev);
2956 dedata->ga_extended |= 0x42;
2957 lredata->operation.orientation = 0x0;
2958 lredata->operation.operation = 0x3F;
2959 lredata->extended_operation = 0x23;
2960 lredata->auxiliary.check_bytes = 0x2;
2961 pfx_cmd = DASD_ECKD_CCW_PFX;
2962 break;
2963 default:
2964 DBF_DEV_EVENT(DBF_ERR, basedev,
2965 "prepare itcw, unknown opcode 0x%x", cmd);
2966 BUG();
2967 break;
2968 }
2969 if (rc)
2970 return rc;
2971
2972 dedata->attributes.mode = 0x3; /* ECKD */
2973
2974 heads = basepriv->rdc_data.trk_per_cyl;
2975 begcyl = trk / heads;
2976 beghead = trk % heads;
2977 endcyl = totrk / heads;
2978 endhead = totrk % heads;
2979
2980 /* check for sequential prestage - enhance cylinder range */
2981 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2982 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2983
2984 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2985 endcyl += basepriv->attrib.nr_cyl;
2986 else
2987 endcyl = (basepriv->real_cyl - 1);
2988 }
2989
2990 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2991 set_ch_t(&dedata->end_ext, endcyl, endhead);
2992
2993 dedata->ep_format = 0x20; /* records per track is valid */
2994 dedata->ep_rec_per_track = blk_per_trk;
2995
2996 if (rec_on_trk) {
2997 switch (basepriv->rdc_data.dev_type) {
2998 case 0x3390:
2999 dn = ceil_quot(blksize + 6, 232);
3000 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
3001 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
3002 break;
3003 case 0x3380:
3004 d = 7 + ceil_quot(blksize + 12, 32);
3005 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
3006 break;
3007 }
3008 }
3009
3010 lredata->auxiliary.length_valid = 1;
3011 lredata->auxiliary.length_scope = 1;
3012 lredata->auxiliary.imbedded_ccw_valid = 1;
3013 lredata->length = tlf;
3014 lredata->imbedded_ccw = cmd;
3015 lredata->count = count;
3016 lredata->sector = sector;
3017 set_ch_t(&lredata->seek_addr, begcyl, beghead);
3018 lredata->search_arg.cyl = lredata->seek_addr.cyl;
3019 lredata->search_arg.head = lredata->seek_addr.head;
3020 lredata->search_arg.record = rec_on_trk;
3021
3022 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
3023 &pfxdata, sizeof(pfxdata), total_data_size);
Thomas Meyer82a7b952013-06-01 11:52:16 +02003024 return PTR_RET(dcw);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003025}
3026
3027static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
3028 struct dasd_device *startdev,
3029 struct dasd_block *block,
3030 struct request *req,
3031 sector_t first_rec,
3032 sector_t last_rec,
3033 sector_t first_trk,
3034 sector_t last_trk,
3035 unsigned int first_offs,
3036 unsigned int last_offs,
3037 unsigned int blk_per_trk,
3038 unsigned int blksize)
3039{
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003040 struct dasd_ccw_req *cqr;
3041 struct req_iterator iter;
3042 struct bio_vec *bv;
3043 char *dst;
3044 unsigned int trkcount, ctidaw;
3045 unsigned char cmd;
3046 struct dasd_device *basedev;
3047 unsigned int tlf;
3048 struct itcw *itcw;
3049 struct tidaw *last_tidaw = NULL;
3050 int itcw_op;
3051 size_t itcw_size;
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003052 u8 tidaw_flags;
3053 unsigned int seg_len, part_len, len_to_track_end;
3054 unsigned char new_track;
3055 sector_t recid, trkid;
3056 unsigned int offs;
3057 unsigned int count, count_to_trk_end;
Julia Lawallcd105022012-04-11 14:28:04 +02003058 int ret;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003059
3060 basedev = block->base;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003061 if (rq_data_dir(req) == READ) {
3062 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3063 itcw_op = ITCW_OP_READ;
3064 } else if (rq_data_dir(req) == WRITE) {
3065 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3066 itcw_op = ITCW_OP_WRITE;
3067 } else
3068 return ERR_PTR(-EINVAL);
3069
3070 /* trackbased I/O needs address all memory via TIDAWs,
3071 * not just for 64 bit addresses. This allows us to map
3072 * each segment directly to one tidaw.
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003073 * In the case of write requests, additional tidaws may
3074 * be needed when a segment crosses a track boundary.
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003075 */
3076 trkcount = last_trk - first_trk + 1;
3077 ctidaw = 0;
3078 rq_for_each_segment(bv, req, iter) {
3079 ++ctidaw;
3080 }
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003081 if (rq_data_dir(req) == WRITE)
3082 ctidaw += (last_trk - first_trk);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003083
3084 /* Allocate the ccw request. */
3085 itcw_size = itcw_calc_size(0, ctidaw, 0);
Stefan Haberland68b781f2009-09-11 10:28:29 +02003086 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003087 if (IS_ERR(cqr))
3088 return cqr;
3089
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003090 /* transfer length factor: how many bytes to read from the last track */
3091 if (first_trk == last_trk)
3092 tlf = last_offs - first_offs + 1;
3093 else
3094 tlf = last_offs + 1;
3095 tlf *= blksize;
3096
3097 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003098 if (IS_ERR(itcw)) {
Julia Lawallcd105022012-04-11 14:28:04 +02003099 ret = -EINVAL;
3100 goto out_error;
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003101 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003102 cqr->cpaddr = itcw_get_tcw(itcw);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003103 if (prepare_itcw(itcw, first_trk, last_trk,
3104 cmd, basedev, startdev,
3105 first_offs + 1,
3106 trkcount, blksize,
3107 (last_rec - first_rec + 1) * blksize,
3108 tlf, blk_per_trk) == -EAGAIN) {
3109 /* Clock not in sync and XRC is enabled.
3110 * Try again later.
3111 */
Julia Lawallcd105022012-04-11 14:28:04 +02003112 ret = -EAGAIN;
3113 goto out_error;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003114 }
Heiko Carstensd54cddb2011-03-15 17:08:21 +01003115 len_to_track_end = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003116 /*
3117 * A tidaw can address 4k of memory, but must not cross page boundaries
3118 * We can let the block layer handle this by setting
3119 * blk_queue_segment_boundary to page boundaries and
3120 * blk_max_segment_size to page size when setting up the request queue.
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003121 * For write requests, a TIDAW must not cross track boundaries, because
3122 * we have to set the CBC flag on the last tidaw for each track.
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003123 */
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003124 if (rq_data_dir(req) == WRITE) {
3125 new_track = 1;
3126 recid = first_rec;
3127 rq_for_each_segment(bv, req, iter) {
3128 dst = page_address(bv->bv_page) + bv->bv_offset;
3129 seg_len = bv->bv_len;
3130 while (seg_len) {
3131 if (new_track) {
3132 trkid = recid;
3133 offs = sector_div(trkid, blk_per_trk);
3134 count_to_trk_end = blk_per_trk - offs;
3135 count = min((last_rec - recid + 1),
3136 (sector_t)count_to_trk_end);
3137 len_to_track_end = count * blksize;
3138 recid += count;
3139 new_track = 0;
3140 }
3141 part_len = min(seg_len, len_to_track_end);
3142 seg_len -= part_len;
3143 len_to_track_end -= part_len;
3144 /* We need to end the tidaw at track end */
3145 if (!len_to_track_end) {
3146 new_track = 1;
3147 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3148 } else
3149 tidaw_flags = 0;
3150 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3151 dst, part_len);
Julia Lawallcd105022012-04-11 14:28:04 +02003152 if (IS_ERR(last_tidaw)) {
3153 ret = -EINVAL;
3154 goto out_error;
3155 }
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003156 dst += part_len;
3157 }
3158 }
3159 } else {
3160 rq_for_each_segment(bv, req, iter) {
3161 dst = page_address(bv->bv_page) + bv->bv_offset;
3162 last_tidaw = itcw_add_tidaw(itcw, 0x00,
3163 dst, bv->bv_len);
Julia Lawallcd105022012-04-11 14:28:04 +02003164 if (IS_ERR(last_tidaw)) {
3165 ret = -EINVAL;
3166 goto out_error;
3167 }
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003168 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003169 }
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003170 last_tidaw->flags |= TIDAW_FLAGS_LAST;
3171 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003172 itcw_finalize(itcw);
3173
3174 if (blk_noretry_request(req) ||
3175 block->base->features & DASD_FEATURE_FAILFAST)
3176 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003177 cqr->cpmode = 1;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003178 cqr->startdev = startdev;
3179 cqr->memdev = startdev;
3180 cqr->block = block;
Stefan Haberland7c8faa82010-08-09 18:13:00 +02003181 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003182 cqr->lpm = startdev->path_data.ppm;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00003183 cqr->retries = startdev->default_retries;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003184 cqr->buildclk = get_tod_clock();
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003185 cqr->status = DASD_CQR_FILLED;
3186 return cqr;
Julia Lawallcd105022012-04-11 14:28:04 +02003187out_error:
3188 dasd_sfree_request(cqr, startdev);
3189 return ERR_PTR(ret);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003190}
3191
3192static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3193 struct dasd_block *block,
3194 struct request *req)
3195{
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003196 int cmdrtd, cmdwtd;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003197 int use_prefix;
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003198 int fcx_multitrack;
Stefan Weinhuber45b44d72009-06-12 10:26:36 +02003199 struct dasd_eckd_private *private;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003200 struct dasd_device *basedev;
3201 sector_t first_rec, last_rec;
3202 sector_t first_trk, last_trk;
3203 unsigned int first_offs, last_offs;
3204 unsigned int blk_per_trk, blksize;
3205 int cdlspecial;
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003206 unsigned int data_size;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003207 struct dasd_ccw_req *cqr;
3208
3209 basedev = block->base;
3210 private = (struct dasd_eckd_private *) basedev->private;
3211
3212 /* Calculate number of blocks/records per track. */
3213 blksize = block->bp_block;
3214 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Stefan Haberland6fca97a2009-10-06 10:34:15 +02003215 if (blk_per_trk == 0)
3216 return ERR_PTR(-EINVAL);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003217 /* Calculate record id of first and last block. */
Tejun Heo83096eb2009-05-07 22:24:39 +09003218 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003219 first_offs = sector_div(first_trk, blk_per_trk);
3220 last_rec = last_trk =
Tejun Heo83096eb2009-05-07 22:24:39 +09003221 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003222 last_offs = sector_div(last_trk, blk_per_trk);
3223 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3224
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003225 fcx_multitrack = private->features.feature[40] & 0x20;
3226 data_size = blk_rq_bytes(req);
Stefan Weinhuber26a35f32013-11-19 14:15:57 +01003227 if (data_size % blksize)
3228 return ERR_PTR(-EINVAL);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003229 /* tpm write request add CBC data on each track boundary */
3230 if (rq_data_dir(req) == WRITE)
3231 data_size += (last_trk - first_trk) * 4;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003232
3233 /* is read track data and write track data in command mode supported? */
3234 cmdrtd = private->features.feature[9] & 0x20;
3235 cmdwtd = private->features.feature[12] & 0x40;
3236 use_prefix = private->features.feature[8] & 0x01;
3237
3238 cqr = NULL;
3239 if (cdlspecial || dasd_page_cache) {
3240 /* do nothing, just fall through to the cmd mode single case */
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003241 } else if ((data_size <= private->fcx_max_data)
3242 && (fcx_multitrack || (first_trk == last_trk))) {
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003243 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3244 first_rec, last_rec,
3245 first_trk, last_trk,
3246 first_offs, last_offs,
3247 blk_per_trk, blksize);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003248 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3249 (PTR_ERR(cqr) != -ENOMEM))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003250 cqr = NULL;
3251 } else if (use_prefix &&
3252 (((rq_data_dir(req) == READ) && cmdrtd) ||
3253 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3254 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3255 first_rec, last_rec,
3256 first_trk, last_trk,
3257 first_offs, last_offs,
3258 blk_per_trk, blksize);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01003259 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3260 (PTR_ERR(cqr) != -ENOMEM))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003261 cqr = NULL;
3262 }
3263 if (!cqr)
3264 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3265 first_rec, last_rec,
3266 first_trk, last_trk,
3267 first_offs, last_offs,
3268 blk_per_trk, blksize);
3269 return cqr;
3270}
3271
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003272static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3273 struct dasd_block *block,
3274 struct request *req)
3275{
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003276 unsigned long *idaws;
3277 struct dasd_device *basedev;
3278 struct dasd_ccw_req *cqr;
3279 struct ccw1 *ccw;
3280 struct req_iterator iter;
3281 struct bio_vec *bv;
3282 char *dst;
3283 unsigned char cmd;
3284 unsigned int trkcount;
3285 unsigned int seg_len, len_to_track_end;
3286 unsigned int first_offs;
3287 unsigned int cidaw, cplength, datasize;
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003288 sector_t first_trk, last_trk, sectors;
3289 sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003290 unsigned int pfx_datasize;
3291
3292 /*
3293 * raw track access needs to be mutiple of 64k and on 64k boundary
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003294 * For read requests we can fix an incorrect alignment by padding
3295 * the request with dummy pages.
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003296 */
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003297 start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
3298 end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
3299 DASD_RAW_SECTORS_PER_TRACK;
3300 end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
3301 DASD_RAW_SECTORS_PER_TRACK;
3302 basedev = block->base;
3303 if ((start_padding_sectors || end_padding_sectors) &&
3304 (rq_data_dir(req) == WRITE)) {
3305 DBF_DEV_EVENT(DBF_ERR, basedev,
3306 "raw write not track aligned (%lu,%lu) req %p",
3307 start_padding_sectors, end_padding_sectors, req);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003308 cqr = ERR_PTR(-EINVAL);
3309 goto out;
3310 }
3311
3312 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3313 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3314 DASD_RAW_SECTORS_PER_TRACK;
3315 trkcount = last_trk - first_trk + 1;
3316 first_offs = 0;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003317
3318 if (rq_data_dir(req) == READ)
3319 cmd = DASD_ECKD_CCW_READ_TRACK;
3320 else if (rq_data_dir(req) == WRITE)
3321 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3322 else {
3323 cqr = ERR_PTR(-EINVAL);
3324 goto out;
3325 }
3326
3327 /*
3328 * Raw track based I/O needs IDAWs for each page,
3329 * and not just for 64 bit addresses.
3330 */
3331 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3332
3333 /* 1x prefix + one read/write ccw per track */
3334 cplength = 1 + trkcount;
3335
3336 /*
3337 * struct PFX_eckd_data has up to 2 byte as extended parameter
3338 * this is needed for write full track and has to be mentioned
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003339 * separately
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003340 * add 8 instead of 2 to keep 8 byte boundary
3341 */
3342 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3343
3344 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3345
3346 /* Allocate the ccw request. */
3347 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3348 datasize, startdev);
3349 if (IS_ERR(cqr))
3350 goto out;
3351 ccw = cqr->cpaddr;
3352
3353 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3354 basedev, startdev, 1 /* format */, first_offs + 1,
3355 trkcount, 0, 0) == -EAGAIN) {
3356 /* Clock not in sync and XRC is enabled.
3357 * Try again later.
3358 */
3359 dasd_sfree_request(cqr, startdev);
3360 cqr = ERR_PTR(-EAGAIN);
3361 goto out;
3362 }
3363
3364 idaws = (unsigned long *)(cqr->data + pfx_datasize);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003365 len_to_track_end = 0;
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003366 if (start_padding_sectors) {
3367 ccw[-1].flags |= CCW_FLAG_CC;
3368 ccw->cmd_code = cmd;
3369 /* maximum 3390 track size */
3370 ccw->count = 57326;
3371 /* 64k map to one track */
3372 len_to_track_end = 65536 - start_padding_sectors * 512;
3373 ccw->cda = (__u32)(addr_t)idaws;
3374 ccw->flags |= CCW_FLAG_IDA;
3375 ccw->flags |= CCW_FLAG_SLI;
3376 ccw++;
3377 for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
3378 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3379 }
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003380 rq_for_each_segment(bv, req, iter) {
3381 dst = page_address(bv->bv_page) + bv->bv_offset;
3382 seg_len = bv->bv_len;
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003383 if (cmd == DASD_ECKD_CCW_READ_TRACK)
3384 memset(dst, 0, seg_len);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003385 if (!len_to_track_end) {
3386 ccw[-1].flags |= CCW_FLAG_CC;
3387 ccw->cmd_code = cmd;
3388 /* maximum 3390 track size */
3389 ccw->count = 57326;
3390 /* 64k map to one track */
3391 len_to_track_end = 65536;
3392 ccw->cda = (__u32)(addr_t)idaws;
3393 ccw->flags |= CCW_FLAG_IDA;
3394 ccw->flags |= CCW_FLAG_SLI;
3395 ccw++;
3396 }
3397 len_to_track_end -= seg_len;
3398 idaws = idal_create_words(idaws, dst, seg_len);
3399 }
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02003400 for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
3401 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003402 if (blk_noretry_request(req) ||
3403 block->base->features & DASD_FEATURE_FAILFAST)
3404 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3405 cqr->startdev = startdev;
3406 cqr->memdev = startdev;
3407 cqr->block = block;
3408 cqr->expires = startdev->default_expires * HZ;
3409 cqr->lpm = startdev->path_data.ppm;
Hannes Reinecke1f1ee9a2013-01-30 09:26:12 +00003410 cqr->retries = startdev->default_retries;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003411 cqr->buildclk = get_tod_clock();
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003412 cqr->status = DASD_CQR_FILLED;
3413
3414 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3415 cqr = NULL;
3416out:
3417 return cqr;
3418}
3419
3420
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421static int
3422dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3423{
3424 struct dasd_eckd_private *private;
3425 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +02003426 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 struct bio_vec *bv;
3428 char *dst, *cda;
3429 unsigned int blksize, blk_per_trk, off;
3430 sector_t recid;
NeilBrown5705f702007-09-25 12:35:59 +02003431 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 if (!dasd_page_cache)
3434 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003435 private = (struct dasd_eckd_private *) cqr->block->base->private;
3436 blksize = cqr->block->bp_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
Tejun Heo83096eb2009-05-07 22:24:39 +09003438 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 ccw = cqr->cpaddr;
3440 /* Skip over define extent & locate record. */
3441 ccw++;
3442 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
3443 ccw++;
NeilBrown5705f702007-09-25 12:35:59 +02003444 rq_for_each_segment(bv, req, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 dst = page_address(bv->bv_page) + bv->bv_offset;
3446 for (off = 0; off < bv->bv_len; off += blksize) {
3447 /* Skip locate record. */
3448 if (private->uses_cdl && recid <= 2*blk_per_trk)
3449 ccw++;
3450 if (dst) {
3451 if (ccw->flags & CCW_FLAG_IDA)
3452 cda = *((char **)((addr_t) ccw->cda));
3453 else
3454 cda = (char *)((addr_t) ccw->cda);
3455 if (dst != cda) {
3456 if (rq_data_dir(req) == READ)
3457 memcpy(dst, cda, bv->bv_len);
3458 kmem_cache_free(dasd_page_cache,
3459 (void *)((addr_t)cda & PAGE_MASK));
3460 }
3461 dst = NULL;
3462 }
3463 ccw++;
3464 recid++;
3465 }
3466 }
3467out:
3468 status = cqr->status == DASD_CQR_DONE;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003469 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 return status;
3471}
3472
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003473/*
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003474 * Modify ccw/tcw in cqr so it can be started on a base device.
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003475 *
3476 * Note that this is not enough to restart the cqr!
3477 * Either reset cqr->startdev as well (summary unit check handling)
3478 * or restart via separate cqr (as in ERP handling).
3479 */
3480void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3481{
3482 struct ccw1 *ccw;
3483 struct PFX_eckd_data *pfxdata;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003484 struct tcw *tcw;
3485 struct tccb *tccb;
3486 struct dcw *dcw;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003487
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003488 if (cqr->cpmode == 1) {
3489 tcw = cqr->cpaddr;
3490 tccb = tcw_get_tccb(tcw);
3491 dcw = (struct dcw *)&tccb->tca[0];
3492 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003493 pfxdata->validity.verify_base = 0;
3494 pfxdata->validity.hyper_pav = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003495 } else {
3496 ccw = cqr->cpaddr;
3497 pfxdata = cqr->data;
3498 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3499 pfxdata->validity.verify_base = 0;
3500 pfxdata->validity.hyper_pav = 0;
3501 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003502 }
3503}
3504
3505#define DASD_ECKD_CHANQ_MAX_SIZE 4
3506
3507static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3508 struct dasd_block *block,
3509 struct request *req)
3510{
3511 struct dasd_eckd_private *private;
3512 struct dasd_device *startdev;
3513 unsigned long flags;
3514 struct dasd_ccw_req *cqr;
3515
3516 startdev = dasd_alias_get_start_dev(base);
3517 if (!startdev)
3518 startdev = base;
3519 private = (struct dasd_eckd_private *) startdev->private;
3520 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3521 return ERR_PTR(-EBUSY);
3522
3523 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3524 private->count++;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003525 if ((base->features & DASD_FEATURE_USERAW))
3526 cqr = dasd_raw_build_cp(startdev, block, req);
3527 else
3528 cqr = dasd_eckd_build_cp(startdev, block, req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003529 if (IS_ERR(cqr))
3530 private->count--;
3531 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3532 return cqr;
3533}
3534
3535static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3536 struct request *req)
3537{
3538 struct dasd_eckd_private *private;
3539 unsigned long flags;
3540
3541 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3542 private = (struct dasd_eckd_private *) cqr->memdev->private;
3543 private->count--;
3544 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3545 return dasd_eckd_free_cp(cqr, req);
3546}
3547
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548static int
3549dasd_eckd_fill_info(struct dasd_device * device,
3550 struct dasd_information2_t * info)
3551{
3552 struct dasd_eckd_private *private;
3553
3554 private = (struct dasd_eckd_private *) device->private;
3555 info->label_block = 2;
3556 info->FBA_layout = private->uses_cdl ? 0 : 1;
3557 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3558 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3559 memcpy(info->characteristics, &private->rdc_data,
3560 sizeof(struct dasd_eckd_characteristics));
Stefan Weinhuber4abb08c2008-08-01 16:39:09 +02003561 info->confdata_size = min((unsigned long)private->conf_len,
3562 sizeof(info->configuration_data));
3563 memcpy(info->configuration_data, private->conf_data,
3564 info->confdata_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 return 0;
3566}
3567
3568/*
3569 * SECTION: ioctl functions for eckd devices.
3570 */
3571
3572/*
3573 * Release device ioctl.
Horst Hummel138c0142006-06-29 14:58:12 +02003574 * Buils a channel programm to releases a prior reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 * (see dasd_eckd_reserve) device.
3576 */
3577static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003578dasd_eckd_release(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 struct dasd_ccw_req *cqr;
3581 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003582 struct ccw1 *ccw;
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003583 int useglobal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
3585 if (!capable(CAP_SYS_ADMIN))
3586 return -EACCES;
3587
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003588 useglobal = 0;
Stefan Haberland68b781f2009-09-11 10:28:29 +02003589 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 if (IS_ERR(cqr)) {
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003591 mutex_lock(&dasd_reserve_mutex);
3592 useglobal = 1;
3593 cqr = &dasd_reserve_req->cqr;
3594 memset(cqr, 0, sizeof(*cqr));
3595 memset(&dasd_reserve_req->ccw, 0,
3596 sizeof(dasd_reserve_req->ccw));
3597 cqr->cpaddr = &dasd_reserve_req->ccw;
3598 cqr->data = &dasd_reserve_req->data;
3599 cqr->magic = DASD_ECKD_MAGIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003601 ccw = cqr->cpaddr;
3602 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3603 ccw->flags |= CCW_FLAG_SLI;
3604 ccw->count = 32;
3605 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003606 cqr->startdev = device;
3607 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003609 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01003610 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 cqr->expires = 2 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003612 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 cqr->status = DASD_CQR_FILLED;
3614
3615 rc = dasd_sleep_on_immediatly(cqr);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01003616 if (!rc)
3617 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003619 if (useglobal)
3620 mutex_unlock(&dasd_reserve_mutex);
3621 else
3622 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 return rc;
3624}
3625
3626/*
3627 * Reserve device ioctl.
3628 * Options are set to 'synchronous wait for interrupt' and
Horst Hummel138c0142006-06-29 14:58:12 +02003629 * 'timeout the request'. This leads to a terminate IO if
3630 * the interrupt is outstanding for a certain time.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 */
3632static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003633dasd_eckd_reserve(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 struct dasd_ccw_req *cqr;
3636 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003637 struct ccw1 *ccw;
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003638 int useglobal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
3640 if (!capable(CAP_SYS_ADMIN))
3641 return -EACCES;
3642
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003643 useglobal = 0;
Stefan Haberland68b781f2009-09-11 10:28:29 +02003644 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 if (IS_ERR(cqr)) {
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003646 mutex_lock(&dasd_reserve_mutex);
3647 useglobal = 1;
3648 cqr = &dasd_reserve_req->cqr;
3649 memset(cqr, 0, sizeof(*cqr));
3650 memset(&dasd_reserve_req->ccw, 0,
3651 sizeof(dasd_reserve_req->ccw));
3652 cqr->cpaddr = &dasd_reserve_req->ccw;
3653 cqr->data = &dasd_reserve_req->data;
3654 cqr->magic = DASD_ECKD_MAGIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003656 ccw = cqr->cpaddr;
3657 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3658 ccw->flags |= CCW_FLAG_SLI;
3659 ccw->count = 32;
3660 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003661 cqr->startdev = device;
3662 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003664 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01003665 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 cqr->expires = 2 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003667 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 cqr->status = DASD_CQR_FILLED;
3669
3670 rc = dasd_sleep_on_immediatly(cqr);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01003671 if (!rc)
3672 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003674 if (useglobal)
3675 mutex_unlock(&dasd_reserve_mutex);
3676 else
3677 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 return rc;
3679}
3680
3681/*
3682 * Steal lock ioctl - unconditional reserve device.
Horst Hummel138c0142006-06-29 14:58:12 +02003683 * Buils a channel programm to break a device's reservation.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 * (unconditional reserve)
3685 */
3686static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003687dasd_eckd_steal_lock(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 struct dasd_ccw_req *cqr;
3690 int rc;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003691 struct ccw1 *ccw;
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003692 int useglobal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693
3694 if (!capable(CAP_SYS_ADMIN))
3695 return -EACCES;
3696
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003697 useglobal = 0;
Stefan Haberland68b781f2009-09-11 10:28:29 +02003698 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 if (IS_ERR(cqr)) {
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003700 mutex_lock(&dasd_reserve_mutex);
3701 useglobal = 1;
3702 cqr = &dasd_reserve_req->cqr;
3703 memset(cqr, 0, sizeof(*cqr));
3704 memset(&dasd_reserve_req->ccw, 0,
3705 sizeof(dasd_reserve_req->ccw));
3706 cqr->cpaddr = &dasd_reserve_req->ccw;
3707 cqr->data = &dasd_reserve_req->data;
3708 cqr->magic = DASD_ECKD_MAGIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003710 ccw = cqr->cpaddr;
3711 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3712 ccw->flags |= CCW_FLAG_SLI;
3713 ccw->count = 32;
3714 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003715 cqr->startdev = device;
3716 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003718 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Horst Hummel336c3402007-02-05 21:17:24 +01003719 cqr->retries = 2; /* set retry counter to enable basic ERP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 cqr->expires = 2 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003721 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 cqr->status = DASD_CQR_FILLED;
3723
3724 rc = dasd_sleep_on_immediatly(cqr);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01003725 if (!rc)
3726 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02003728 if (useglobal)
3729 mutex_unlock(&dasd_reserve_mutex);
3730 else
3731 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 return rc;
3733}
3734
3735/*
Stefan Weinhuber196339f2010-10-29 16:50:43 +02003736 * SNID - Sense Path Group ID
3737 * This ioctl may be used in situations where I/O is stalled due to
3738 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3739 * preallocated dasd_reserve_req.
3740 */
3741static int dasd_eckd_snid(struct dasd_device *device,
3742 void __user *argp)
3743{
3744 struct dasd_ccw_req *cqr;
3745 int rc;
3746 struct ccw1 *ccw;
3747 int useglobal;
3748 struct dasd_snid_ioctl_data usrparm;
3749
3750 if (!capable(CAP_SYS_ADMIN))
3751 return -EACCES;
3752
3753 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3754 return -EFAULT;
3755
3756 useglobal = 0;
3757 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3758 sizeof(struct dasd_snid_data), device);
3759 if (IS_ERR(cqr)) {
3760 mutex_lock(&dasd_reserve_mutex);
3761 useglobal = 1;
3762 cqr = &dasd_reserve_req->cqr;
3763 memset(cqr, 0, sizeof(*cqr));
3764 memset(&dasd_reserve_req->ccw, 0,
3765 sizeof(dasd_reserve_req->ccw));
3766 cqr->cpaddr = &dasd_reserve_req->ccw;
3767 cqr->data = &dasd_reserve_req->data;
3768 cqr->magic = DASD_ECKD_MAGIC;
3769 }
3770 ccw = cqr->cpaddr;
3771 ccw->cmd_code = DASD_ECKD_CCW_SNID;
3772 ccw->flags |= CCW_FLAG_SLI;
3773 ccw->count = 12;
3774 ccw->cda = (__u32)(addr_t) cqr->data;
3775 cqr->startdev = device;
3776 cqr->memdev = device;
3777 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3778 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01003779 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
Stefan Weinhuber196339f2010-10-29 16:50:43 +02003780 cqr->retries = 5;
3781 cqr->expires = 10 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003782 cqr->buildclk = get_tod_clock();
Stefan Weinhuber196339f2010-10-29 16:50:43 +02003783 cqr->status = DASD_CQR_FILLED;
3784 cqr->lpm = usrparm.path_mask;
3785
3786 rc = dasd_sleep_on_immediatly(cqr);
3787 /* verify that I/O processing didn't modify the path mask */
3788 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3789 rc = -EIO;
3790 if (!rc) {
3791 usrparm.data = *((struct dasd_snid_data *)cqr->data);
3792 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3793 rc = -EFAULT;
3794 }
3795
3796 if (useglobal)
3797 mutex_unlock(&dasd_reserve_mutex);
3798 else
3799 dasd_sfree_request(cqr, cqr->memdev);
3800 return rc;
3801}
3802
3803/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 * Read performance statistics
3805 */
3806static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003807dasd_eckd_performance(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 struct dasd_psf_prssd_data *prssdp;
3810 struct dasd_rssd_perf_stats_t *stats;
3811 struct dasd_ccw_req *cqr;
3812 struct ccw1 *ccw;
3813 int rc;
3814
Stefan Haberland68b781f2009-09-11 10:28:29 +02003815 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003816 (sizeof(struct dasd_psf_prssd_data) +
3817 sizeof(struct dasd_rssd_perf_stats_t)),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 device);
3819 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003820 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 "Could not allocate initialization request");
3822 return PTR_ERR(cqr);
3823 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003824 cqr->startdev = device;
3825 cqr->memdev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 cqr->retries = 0;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003827 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 cqr->expires = 10 * HZ;
3829
3830 /* Prepare for Read Subsystem Data */
3831 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003832 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 prssdp->order = PSF_ORDER_PRSSD;
Joe Perches5d67d162008-01-26 14:11:20 +01003834 prssdp->suborder = 0x01; /* Performance Statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3836
3837 ccw = cqr->cpaddr;
3838 ccw->cmd_code = DASD_ECKD_CCW_PSF;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003839 ccw->count = sizeof(struct dasd_psf_prssd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 ccw->flags |= CCW_FLAG_CC;
3841 ccw->cda = (__u32)(addr_t) prssdp;
3842
3843 /* Read Subsystem Data - Performance Statistics */
3844 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003845 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847 ccw++;
3848 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003849 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 ccw->cda = (__u32)(addr_t) stats;
3851
Heiko Carstens1aae0562013-01-30 09:49:40 +01003852 cqr->buildclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 cqr->status = DASD_CQR_FILLED;
3854 rc = dasd_sleep_on(cqr);
3855 if (rc == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3857 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003858 if (copy_to_user(argp, stats,
3859 sizeof(struct dasd_rssd_perf_stats_t)))
3860 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003862 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 return rc;
3864}
3865
3866/*
3867 * Get attributes (cache operations)
3868 * Returnes the cache attributes used in Define Extend (DE).
3869 */
3870static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003871dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003873 struct dasd_eckd_private *private =
3874 (struct dasd_eckd_private *)device->private;
3875 struct attrib_data_t attrib = private->attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 int rc;
3877
3878 if (!capable(CAP_SYS_ADMIN))
3879 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003880 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 return -EINVAL;
3882
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003883 rc = 0;
3884 if (copy_to_user(argp, (long *) &attrib,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003885 sizeof(struct attrib_data_t)))
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003886 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887
3888 return rc;
3889}
3890
3891/*
3892 * Set attributes (cache operations)
3893 * Stores the attributes for cache operation to be used in Define Extend (DE).
3894 */
3895static int
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003896dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897{
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003898 struct dasd_eckd_private *private =
3899 (struct dasd_eckd_private *)device->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 struct attrib_data_t attrib;
3901
3902 if (!capable(CAP_SYS_ADMIN))
3903 return -EACCES;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003904 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 return -EINVAL;
3906
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08003907 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 private->attrib = attrib;
3910
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003911 dev_info(&device->cdev->dev,
3912 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3913 private->attrib.operation, private->attrib.nr_cyl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 return 0;
3915}
3916
Nigel Hislopab1d8482008-10-10 21:33:25 +02003917/*
3918 * Issue syscall I/O to EMC Symmetrix array.
3919 * CCWs are PSF and RSSD
3920 */
3921static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3922{
3923 struct dasd_symmio_parms usrparm;
3924 char *psf_data, *rssd_result;
3925 struct dasd_ccw_req *cqr;
3926 struct ccw1 *ccw;
Nigel Hislop52898022010-03-08 12:25:16 +01003927 char psf0, psf1;
Nigel Hislopab1d8482008-10-10 21:33:25 +02003928 int rc;
3929
Nigel Hislop52898022010-03-08 12:25:16 +01003930 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3931 return -EACCES;
3932 psf0 = psf1 = 0;
3933
Nigel Hislopab1d8482008-10-10 21:33:25 +02003934 /* Copy parms from caller */
3935 rc = -EFAULT;
3936 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3937 goto out;
Heiko Carstensf8b068592010-01-13 20:44:40 +01003938 if (is_compat_task() || sizeof(long) == 4) {
3939 /* Make sure pointers are sane even on 31 bit. */
Nigel Hislopab1d8482008-10-10 21:33:25 +02003940 rc = -EINVAL;
Heiko Carstensf8b068592010-01-13 20:44:40 +01003941 if ((usrparm.psf_data >> 32) != 0)
3942 goto out;
3943 if ((usrparm.rssd_result >> 32) != 0)
3944 goto out;
3945 usrparm.psf_data &= 0x7fffffffULL;
3946 usrparm.rssd_result &= 0x7fffffffULL;
Nigel Hislopab1d8482008-10-10 21:33:25 +02003947 }
Nigel Hislopab1d8482008-10-10 21:33:25 +02003948 /* alloc I/O data area */
3949 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3950 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3951 if (!psf_data || !rssd_result) {
3952 rc = -ENOMEM;
3953 goto out_free;
3954 }
3955
3956 /* get syscall header from user space */
3957 rc = -EFAULT;
3958 if (copy_from_user(psf_data,
3959 (void __user *)(unsigned long) usrparm.psf_data,
3960 usrparm.psf_data_len))
3961 goto out_free;
Nigel Hislop52898022010-03-08 12:25:16 +01003962 psf0 = psf_data[0];
3963 psf1 = psf_data[1];
Nigel Hislopab1d8482008-10-10 21:33:25 +02003964
3965 /* setup CCWs for PSF + RSSD */
Stefan Haberland68b781f2009-09-11 10:28:29 +02003966 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
Nigel Hislopab1d8482008-10-10 21:33:25 +02003967 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003968 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Nigel Hislopab1d8482008-10-10 21:33:25 +02003969 "Could not allocate initialization request");
3970 rc = PTR_ERR(cqr);
3971 goto out_free;
3972 }
3973
3974 cqr->startdev = device;
3975 cqr->memdev = device;
3976 cqr->retries = 3;
3977 cqr->expires = 10 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003978 cqr->buildclk = get_tod_clock();
Nigel Hislopab1d8482008-10-10 21:33:25 +02003979 cqr->status = DASD_CQR_FILLED;
3980
3981 /* Build the ccws */
3982 ccw = cqr->cpaddr;
3983
3984 /* PSF ccw */
3985 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3986 ccw->count = usrparm.psf_data_len;
3987 ccw->flags |= CCW_FLAG_CC;
3988 ccw->cda = (__u32)(addr_t) psf_data;
3989
3990 ccw++;
3991
3992 /* RSSD ccw */
3993 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3994 ccw->count = usrparm.rssd_result_len;
3995 ccw->flags = CCW_FLAG_SLI ;
3996 ccw->cda = (__u32)(addr_t) rssd_result;
3997
3998 rc = dasd_sleep_on(cqr);
3999 if (rc)
4000 goto out_sfree;
4001
4002 rc = -EFAULT;
4003 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
4004 rssd_result, usrparm.rssd_result_len))
4005 goto out_sfree;
4006 rc = 0;
4007
4008out_sfree:
4009 dasd_sfree_request(cqr, cqr->memdev);
4010out_free:
4011 kfree(rssd_result);
4012 kfree(psf_data);
4013out:
Nigel Hislop52898022010-03-08 12:25:16 +01004014 DBF_DEV_EVENT(DBF_WARNING, device,
4015 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4016 (int) psf0, (int) psf1, rc);
Nigel Hislopab1d8482008-10-10 21:33:25 +02004017 return rc;
4018}
4019
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004020static int
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004021dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004022{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004023 struct dasd_device *device = block->base;
4024
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004025 switch (cmd) {
4026 case BIODASDGATTR:
4027 return dasd_eckd_get_attrib(device, argp);
4028 case BIODASDSATTR:
4029 return dasd_eckd_set_attrib(device, argp);
4030 case BIODASDPSRD:
4031 return dasd_eckd_performance(device, argp);
4032 case BIODASDRLSE:
4033 return dasd_eckd_release(device);
4034 case BIODASDRSRV:
4035 return dasd_eckd_reserve(device);
4036 case BIODASDSLCK:
4037 return dasd_eckd_steal_lock(device);
Stefan Weinhuber196339f2010-10-29 16:50:43 +02004038 case BIODASDSNID:
4039 return dasd_eckd_snid(device, argp);
Nigel Hislopab1d8482008-10-10 21:33:25 +02004040 case BIODASDSYMMIO:
4041 return dasd_symm_io(device, argp);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004042 default:
Heiko Carstens6b79d142012-08-27 10:59:42 +02004043 return -ENOTTY;
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004044 }
4045}
4046
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047/*
Horst Hummel445b5b42006-06-29 14:57:52 +02004048 * Dump the range of CCWs into 'page' buffer
4049 * and return number of printed chars.
4050 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004051static int
Horst Hummel445b5b42006-06-29 14:57:52 +02004052dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
4053{
4054 int len, count;
4055 char *datap;
4056
4057 len = 0;
4058 while (from <= to) {
Sebastian Ott773bab42012-10-23 20:28:37 +02004059 len += sprintf(page + len, PRINTK_HEADER
Horst Hummel445b5b42006-06-29 14:57:52 +02004060 " CCW %p: %08X %08X DAT:",
4061 from, ((int *) from)[0], ((int *) from)[1]);
4062
4063 /* get pointer to data (consider IDALs) */
4064 if (from->flags & CCW_FLAG_IDA)
4065 datap = (char *) *((addr_t *) (addr_t) from->cda);
4066 else
4067 datap = (char *) ((addr_t) from->cda);
4068
4069 /* dump data (max 32 bytes) */
4070 for (count = 0; count < from->count && count < 32; count++) {
4071 if (count % 8 == 0) len += sprintf(page + len, " ");
4072 if (count % 4 == 0) len += sprintf(page + len, " ");
4073 len += sprintf(page + len, "%02x", datap[count]);
4074 }
4075 len += sprintf(page + len, "\n");
4076 from++;
4077 }
4078 return len;
4079}
4080
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004081static void
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02004082dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4083 char *reason)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004084{
4085 u64 *sense;
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004086 u64 *stat;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004087
Stefan Haberlandaeec92c2009-07-07 16:37:06 +02004088 sense = (u64 *) dasd_get_sense(irb);
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004089 stat = (u64 *) &irb->scsw;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004090 if (sense) {
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004091 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4092 "%016llx %016llx %016llx %016llx",
4093 reason, *stat, *((u32 *) (stat + 1)),
Stefan Haberlanded3640b2010-10-25 16:10:24 +02004094 sense[0], sense[1], sense[2], sense[3]);
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004095 } else {
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004096 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4097 reason, *stat, *((u32 *) (stat + 1)),
4098 "NO VALID SENSE");
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004099 }
4100}
4101
Horst Hummel445b5b42006-06-29 14:57:52 +02004102/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 * Print sense data and related channel program.
4104 * Parts are printed because printk buffer is only 1024 bytes.
4105 */
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004106static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004107 struct dasd_ccw_req *req, struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108{
4109 char *page;
Horst Hummel445b5b42006-06-29 14:57:52 +02004110 struct ccw1 *first, *last, *fail, *from, *to;
4111 int len, sl, sct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
4113 page = (char *) get_zeroed_page(GFP_ATOMIC);
4114 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004115 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4116 "No memory to dump sense data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 return;
4118 }
Horst Hummel445b5b42006-06-29 14:57:52 +02004119 /* dump the sense data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004120 len = sprintf(page, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 " I/O status report for device %s:\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02004122 dev_name(&device->cdev->dev));
Sebastian Ott773bab42012-10-23 20:28:37 +02004123 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004124 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4125 "CS:%02X RC:%d\n",
4126 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4127 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4128 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4129 req ? req->intrc : 0);
Sebastian Ott773bab42012-10-23 20:28:37 +02004130 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 " device %s: Failing CCW: %p\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02004132 dev_name(&device->cdev->dev),
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02004133 (void *) (addr_t) irb->scsw.cmd.cpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 if (irb->esw.esw0.erw.cons) {
4135 for (sl = 0; sl < 4; sl++) {
Sebastian Ott773bab42012-10-23 20:28:37 +02004136 len += sprintf(page + len, PRINTK_HEADER
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 " Sense(hex) %2d-%2d:",
4138 (8 * sl), ((8 * sl) + 7));
4139
4140 for (sct = 0; sct < 8; sct++) {
4141 len += sprintf(page + len, " %02x",
4142 irb->ecw[8 * sl + sct]);
4143 }
4144 len += sprintf(page + len, "\n");
4145 }
4146
4147 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4148 /* 24 Byte Sense Data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004149 sprintf(page + len, PRINTK_HEADER
Horst Hummel445b5b42006-06-29 14:57:52 +02004150 " 24 Byte: %x MSG %x, "
4151 "%s MSGb to SYSOP\n",
4152 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4153 irb->ecw[1] & 0x10 ? "" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 } else {
4155 /* 32 Byte Sense Data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004156 sprintf(page + len, PRINTK_HEADER
Horst Hummel445b5b42006-06-29 14:57:52 +02004157 " 32 Byte: Format: %x "
4158 "Exception class %x\n",
4159 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 }
4161 } else {
Sebastian Ott773bab42012-10-23 20:28:37 +02004162 sprintf(page + len, PRINTK_HEADER
Horst Hummel445b5b42006-06-29 14:57:52 +02004163 " SORRY - NO VALID SENSE AVAILABLE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 }
Sebastian Ott773bab42012-10-23 20:28:37 +02004165 printk(KERN_ERR "%s", page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004167 if (req) {
4168 /* req == NULL for unsolicited interrupts */
4169 /* dump the Channel Program (max 140 Bytes per line) */
4170 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4171 first = req->cpaddr;
4172 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4173 to = min(first + 6, last);
Sebastian Ott773bab42012-10-23 20:28:37 +02004174 len = sprintf(page, PRINTK_HEADER
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004175 " Related CP in req: %p\n", req);
4176 dasd_eckd_dump_ccw_range(first, to, page + len);
Sebastian Ott773bab42012-10-23 20:28:37 +02004177 printk(KERN_ERR "%s", page);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004178
4179 /* print failing CCW area (maximum 4) */
4180 /* scsw->cda is either valid or zero */
4181 len = 0;
4182 from = ++to;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02004183 fail = (struct ccw1 *)(addr_t)
4184 irb->scsw.cmd.cpa; /* failing CCW */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004185 if (from < fail - 2) {
4186 from = fail - 2; /* there is a gap - print header */
Sebastian Ott773bab42012-10-23 20:28:37 +02004187 len += sprintf(page, PRINTK_HEADER "......\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004188 }
4189 to = min(fail + 1, last);
4190 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4191
4192 /* print last CCWs (maximum 2) */
4193 from = max(from, ++to);
4194 if (from < last - 1) {
4195 from = last - 1; /* there is a gap - print header */
Sebastian Ott773bab42012-10-23 20:28:37 +02004196 len += sprintf(page + len, PRINTK_HEADER "......\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004197 }
4198 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4199 if (len > 0)
Sebastian Ott773bab42012-10-23 20:28:37 +02004200 printk(KERN_ERR "%s", page);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 free_page((unsigned long) page);
4203}
4204
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004205
4206/*
4207 * Print sense data from a tcw.
4208 */
4209static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4210 struct dasd_ccw_req *req, struct irb *irb)
4211{
4212 char *page;
4213 int len, sl, sct, residual;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004214 struct tsb *tsb;
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01004215 u8 *sense, *rcq;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004216
4217 page = (char *) get_zeroed_page(GFP_ATOMIC);
4218 if (page == NULL) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004219 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004220 "No memory to dump sense data");
4221 return;
4222 }
4223 /* dump the sense data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004224 len = sprintf(page, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004225 " I/O status report for device %s:\n",
4226 dev_name(&device->cdev->dev));
Sebastian Ott773bab42012-10-23 20:28:37 +02004227 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004228 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4229 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4230 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4231 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4232 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4233 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
4234 req ? req->intrc : 0);
Sebastian Ott773bab42012-10-23 20:28:37 +02004235 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004236 " device %s: Failing TCW: %p\n",
4237 dev_name(&device->cdev->dev),
4238 (void *) (addr_t) irb->scsw.tm.tcw);
4239
4240 tsb = NULL;
4241 sense = NULL;
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004242 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004243 tsb = tcw_get_tsb(
4244 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4245
Stefan Haberlandb8fde722010-03-24 11:49:54 +01004246 if (tsb) {
Sebastian Ott773bab42012-10-23 20:28:37 +02004247 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004248 " tsb->length %d\n", tsb->length);
Sebastian Ott773bab42012-10-23 20:28:37 +02004249 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004250 " tsb->flags %x\n", tsb->flags);
Sebastian Ott773bab42012-10-23 20:28:37 +02004251 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004252 " tsb->dcw_offset %d\n", tsb->dcw_offset);
Sebastian Ott773bab42012-10-23 20:28:37 +02004253 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004254 " tsb->count %d\n", tsb->count);
4255 residual = tsb->count - 28;
Sebastian Ott773bab42012-10-23 20:28:37 +02004256 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004257 " residual %d\n", residual);
4258
4259 switch (tsb->flags & 0x07) {
4260 case 1: /* tsa_iostat */
Sebastian Ott773bab42012-10-23 20:28:37 +02004261 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004262 " tsb->tsa.iostat.dev_time %d\n",
4263 tsb->tsa.iostat.dev_time);
Sebastian Ott773bab42012-10-23 20:28:37 +02004264 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004265 " tsb->tsa.iostat.def_time %d\n",
4266 tsb->tsa.iostat.def_time);
Sebastian Ott773bab42012-10-23 20:28:37 +02004267 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004268 " tsb->tsa.iostat.queue_time %d\n",
4269 tsb->tsa.iostat.queue_time);
Sebastian Ott773bab42012-10-23 20:28:37 +02004270 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004271 " tsb->tsa.iostat.dev_busy_time %d\n",
4272 tsb->tsa.iostat.dev_busy_time);
Sebastian Ott773bab42012-10-23 20:28:37 +02004273 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004274 " tsb->tsa.iostat.dev_act_time %d\n",
4275 tsb->tsa.iostat.dev_act_time);
4276 sense = tsb->tsa.iostat.sense;
4277 break;
4278 case 2: /* ts_ddpc */
Sebastian Ott773bab42012-10-23 20:28:37 +02004279 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004280 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01004281 for (sl = 0; sl < 2; sl++) {
Sebastian Ott773bab42012-10-23 20:28:37 +02004282 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01004283 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4284 (8 * sl), ((8 * sl) + 7));
4285 rcq = tsb->tsa.ddpc.rcq;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004286 for (sct = 0; sct < 8; sct++) {
4287 len += sprintf(page + len, " %02x",
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01004288 rcq[8 * sl + sct]);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004289 }
4290 len += sprintf(page + len, "\n");
4291 }
4292 sense = tsb->tsa.ddpc.sense;
4293 break;
4294 case 3: /* tsa_intrg */
Sebastian Ott773bab42012-10-23 20:28:37 +02004295 len += sprintf(page + len, PRINTK_HEADER
4296 " tsb->tsa.intrg.: not supportet yet\n");
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004297 break;
4298 }
4299
4300 if (sense) {
4301 for (sl = 0; sl < 4; sl++) {
Sebastian Ott773bab42012-10-23 20:28:37 +02004302 len += sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004303 " Sense(hex) %2d-%2d:",
4304 (8 * sl), ((8 * sl) + 7));
4305 for (sct = 0; sct < 8; sct++) {
4306 len += sprintf(page + len, " %02x",
4307 sense[8 * sl + sct]);
4308 }
4309 len += sprintf(page + len, "\n");
4310 }
4311
4312 if (sense[27] & DASD_SENSE_BIT_0) {
4313 /* 24 Byte Sense Data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004314 sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004315 " 24 Byte: %x MSG %x, "
4316 "%s MSGb to SYSOP\n",
4317 sense[7] >> 4, sense[7] & 0x0f,
4318 sense[1] & 0x10 ? "" : "no");
4319 } else {
4320 /* 32 Byte Sense Data */
Sebastian Ott773bab42012-10-23 20:28:37 +02004321 sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004322 " 32 Byte: Format: %x "
4323 "Exception class %x\n",
4324 sense[6] & 0x0f, sense[22] >> 4);
4325 }
4326 } else {
Sebastian Ott773bab42012-10-23 20:28:37 +02004327 sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004328 " SORRY - NO VALID SENSE AVAILABLE\n");
4329 }
4330 } else {
Sebastian Ott773bab42012-10-23 20:28:37 +02004331 sprintf(page + len, PRINTK_HEADER
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004332 " SORRY - NO TSB DATA AVAILABLE\n");
4333 }
Sebastian Ott773bab42012-10-23 20:28:37 +02004334 printk(KERN_ERR "%s", page);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004335 free_page((unsigned long) page);
4336}
4337
4338static void dasd_eckd_dump_sense(struct dasd_device *device,
4339 struct dasd_ccw_req *req, struct irb *irb)
4340{
Stefan Weinhubera5a00612010-10-25 16:10:47 +02004341 if (scsw_is_tm(&irb->scsw))
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004342 dasd_eckd_dump_sense_tcw(device, req, irb);
4343 else
4344 dasd_eckd_dump_sense_ccw(device, req, irb);
4345}
4346
Stefan Haberland501183f2010-05-17 10:00:10 +02004347static int dasd_eckd_pm_freeze(struct dasd_device *device)
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004348{
4349 /*
4350 * the device should be disconnected from our LCU structure
4351 * on restore we will reconnect it and reread LCU specific
4352 * information like PAV support that might have changed
4353 */
4354 dasd_alias_remove_device(device);
4355 dasd_alias_disconnect_device_from_lcu(device);
4356
4357 return 0;
4358}
4359
Stefan Haberland501183f2010-05-17 10:00:10 +02004360static int dasd_eckd_restore_device(struct dasd_device *device)
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004361{
4362 struct dasd_eckd_private *private;
Stefan Haberland6fca97a2009-10-06 10:34:15 +02004363 struct dasd_eckd_characteristics temp_rdc_data;
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01004364 int rc;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004365 struct dasd_uid temp_uid;
Stefan Haberlanda7602f62009-10-14 12:43:46 +02004366 unsigned long flags;
Stefan Haberlandea4da6e2013-02-19 09:30:05 +01004367 unsigned long cqr_flags = 0;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004368
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004369 private = (struct dasd_eckd_private *) device->private;
4370
4371 /* Read Configuration Data */
Stefan Haberland55d3a852012-11-27 17:04:14 +01004372 dasd_eckd_read_conf(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004373
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004374 dasd_eckd_get_uid(device, &temp_uid);
4375 /* Generate device unique id */
4376 rc = dasd_eckd_generate_uid(device);
4377 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004378 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
Stefan Haberlanda7602f62009-10-14 12:43:46 +02004379 dev_err(&device->cdev->dev, "The UID of the DASD has "
4380 "changed\n");
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004381 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004382 if (rc)
4383 goto out_err;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004384
4385 /* register lcu with alias handling, enable PAV if this is a new lcu */
Stefan Haberlandf9f8d022012-01-18 18:03:40 +01004386 rc = dasd_alias_make_device_known_to_lcu(device);
4387 if (rc)
4388 return rc;
Stefan Haberlandea4da6e2013-02-19 09:30:05 +01004389
4390 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4391 dasd_eckd_validate_server(device, cqr_flags);
Stefan Weinhuberf4ac1d02009-12-07 12:51:53 +01004392
4393 /* RE-Read Configuration Data */
Stefan Haberland55d3a852012-11-27 17:04:14 +01004394 dasd_eckd_read_conf(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004395
4396 /* Read Feature Codes */
Stefan Weinhuber68d1e5f2009-09-22 22:58:52 +02004397 dasd_eckd_read_features(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004398
4399 /* Read Device Characteristics */
Stefan Haberland68b781f2009-09-11 10:28:29 +02004400 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
Stefan Haberland6fca97a2009-10-06 10:34:15 +02004401 &temp_rdc_data, 64);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004402 if (rc) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01004403 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4404 "Read device characteristic failed, rc=%d", rc);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004405 goto out_err;
4406 }
Stefan Haberlanda7602f62009-10-14 12:43:46 +02004407 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Haberland6fca97a2009-10-06 10:34:15 +02004408 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
Stefan Haberlanda7602f62009-10-14 12:43:46 +02004409 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004410
4411 /* add device to alias management */
4412 dasd_alias_add_device(device);
4413
4414 return 0;
4415
4416out_err:
Stefan Haberlande6125fb2009-06-22 12:08:17 +02004417 return -1;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004418}
4419
Stefan Haberland501183f2010-05-17 10:00:10 +02004420static int dasd_eckd_reload_device(struct dasd_device *device)
4421{
4422 struct dasd_eckd_private *private;
4423 int rc, old_base;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004424 char print_uid[60];
4425 struct dasd_uid uid;
4426 unsigned long flags;
Stefan Haberland501183f2010-05-17 10:00:10 +02004427
4428 private = (struct dasd_eckd_private *) device->private;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004429
4430 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Haberland501183f2010-05-17 10:00:10 +02004431 old_base = private->uid.base_unit_addr;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004432 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4433
Stefan Haberland501183f2010-05-17 10:00:10 +02004434 /* Read Configuration Data */
4435 rc = dasd_eckd_read_conf(device);
4436 if (rc)
4437 goto out_err;
4438
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004439 rc = dasd_eckd_generate_uid(device);
Stefan Haberland501183f2010-05-17 10:00:10 +02004440 if (rc)
4441 goto out_err;
Stefan Haberland501183f2010-05-17 10:00:10 +02004442 /*
4443 * update unit address configuration and
4444 * add device to alias management
4445 */
4446 dasd_alias_update_add_device(device);
4447
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004448 dasd_eckd_get_uid(device, &uid);
4449
4450 if (old_base != uid.base_unit_addr) {
4451 if (strlen(uid.vduit) > 0)
4452 snprintf(print_uid, sizeof(print_uid),
4453 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
4454 uid.ssid, uid.base_unit_addr, uid.vduit);
Stefan Haberland501183f2010-05-17 10:00:10 +02004455 else
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004456 snprintf(print_uid, sizeof(print_uid),
4457 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
4458 uid.ssid, uid.base_unit_addr);
Stefan Haberland501183f2010-05-17 10:00:10 +02004459
4460 dev_info(&device->cdev->dev,
4461 "An Alias device was reassigned to a new base device "
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004462 "with UID: %s\n", print_uid);
Stefan Haberland501183f2010-05-17 10:00:10 +02004463 }
4464 return 0;
4465
4466out_err:
4467 return -1;
4468}
4469
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004470static struct ccw_driver dasd_eckd_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +01004471 .driver = {
4472 .name = "dasd-eckd",
4473 .owner = THIS_MODULE,
4474 },
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004475 .ids = dasd_eckd_ids,
4476 .probe = dasd_eckd_probe,
4477 .remove = dasd_generic_remove,
4478 .set_offline = dasd_generic_set_offline,
4479 .set_online = dasd_eckd_set_online,
4480 .notify = dasd_generic_notify,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004481 .path_event = dasd_generic_path_event,
Stefan Haberland4679e892012-06-19 17:30:12 +02004482 .shutdown = dasd_generic_shutdown,
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004483 .freeze = dasd_generic_pm_freeze,
4484 .thaw = dasd_generic_restore_device,
4485 .restore = dasd_generic_restore_device,
Stefan Haberlanda23ed002010-05-26 23:27:09 +02004486 .uc_handler = dasd_generic_uc_handler,
Heiko Carstens420f42e2013-01-02 15:18:18 +01004487 .int_class = IRQIO_DAS,
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004488};
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004489
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490/*
4491 * max_blocks is dependent on the amount of storage that is available
4492 * in the static io buffer for each device. Currently each device has
4493 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4494 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4495 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4496 * addition we have one define extent ccw + 16 bytes of data and one
4497 * locate record ccw + 16 bytes of data. That makes:
4498 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4499 * We want to fit two into the available memory so that we can immediately
4500 * start the next request if one finishes off. That makes 249.5 blocks
4501 * for one request. Give a little safety and the result is 240.
4502 */
4503static struct dasd_discipline dasd_eckd_discipline = {
4504 .owner = THIS_MODULE,
4505 .name = "ECKD",
4506 .ebcname = "ECKD",
Stefan Weinhuberef19298b2011-01-05 12:48:02 +01004507 .max_blocks = 190,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 .check_device = dasd_eckd_check_characteristics,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004509 .uncheck_device = dasd_eckd_uncheck_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 .do_analysis = dasd_eckd_do_analysis,
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004511 .verify_path = dasd_eckd_verify_path,
Stefan Haberlandd42e1712013-04-15 16:22:23 +02004512 .basic_to_ready = dasd_eckd_basic_to_ready,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004513 .online_to_ready = dasd_eckd_online_to_ready,
Stefan Haberlandd42e1712013-04-15 16:22:23 +02004514 .ready_to_basic = dasd_eckd_ready_to_basic,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 .fill_geometry = dasd_eckd_fill_geometry,
4516 .start_IO = dasd_start_IO,
4517 .term_IO = dasd_term_IO,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004518 .handle_terminated_request = dasd_eckd_handle_terminated_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 .format_device = dasd_eckd_format_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 .erp_action = dasd_eckd_erp_action,
4521 .erp_postaction = dasd_eckd_erp_postaction,
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01004522 .check_for_device_change = dasd_eckd_check_for_device_change,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004523 .build_cp = dasd_eckd_build_alias_cp,
4524 .free_cp = dasd_eckd_free_alias_cp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 .dump_sense = dasd_eckd_dump_sense,
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004526 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 .fill_info = dasd_eckd_fill_info,
Christoph Hellwig1107ccf2006-03-24 03:15:20 -08004528 .ioctl = dasd_eckd_ioctl,
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004529 .freeze = dasd_eckd_pm_freeze,
4530 .restore = dasd_eckd_restore_device,
Stefan Haberland501183f2010-05-17 10:00:10 +02004531 .reload = dasd_eckd_reload_device,
Stefan Haberland2dedf0d2010-05-17 10:00:11 +02004532 .get_uid = dasd_eckd_get_uid,
Stefan Haberlandf1633032012-01-18 18:03:41 +01004533 .kick_validate = dasd_eckd_kick_validate_server,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534};
4535
4536static int __init
4537dasd_eckd_init(void)
4538{
Sebastian Ott736e6ea2009-06-12 10:26:38 +02004539 int ret;
4540
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 ASCEBC(dasd_eckd_discipline.ebcname, 4);
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02004542 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4543 GFP_KERNEL | GFP_DMA);
4544 if (!dasd_reserve_req)
4545 return -ENOMEM;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004546 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4547 GFP_KERNEL | GFP_DMA);
4548 if (!path_verification_worker) {
4549 kfree(dasd_reserve_req);
4550 return -ENOMEM;
4551 }
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02004552 rawpadpage = (void *)__get_free_page(GFP_KERNEL);
4553 if (!rawpadpage) {
4554 kfree(path_verification_worker);
4555 kfree(dasd_reserve_req);
4556 return -ENOMEM;
4557 }
Sebastian Ott736e6ea2009-06-12 10:26:38 +02004558 ret = ccw_driver_register(&dasd_eckd_driver);
4559 if (!ret)
4560 wait_for_device_probe();
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004561 else {
4562 kfree(path_verification_worker);
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02004563 kfree(dasd_reserve_req);
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02004564 free_page((unsigned long)rawpadpage);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004565 }
Sebastian Ott736e6ea2009-06-12 10:26:38 +02004566 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567}
4568
4569static void __exit
4570dasd_eckd_cleanup(void)
4571{
4572 ccw_driver_unregister(&dasd_eckd_driver);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004573 kfree(path_verification_worker);
Stefan Weinhuberf932bce2010-08-09 18:12:59 +02004574 kfree(dasd_reserve_req);
Stefan Weinhuber558b9ef2013-08-16 15:57:32 +02004575 free_page((unsigned long)rawpadpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576}
4577
4578module_init(dasd_eckd_init);
4579module_exit(dasd_eckd_cleanup);