Commit | Line | Data |
---|---|---|
6a55d2cd | 1 | // SPDX-License-Identifier: GPL-2.0 |
138c014d | 2 | /* |
1da177e4 | 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
138c014d | 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
1da177e4 LT |
5 | * Carsten Otte <Cotte@de.ibm.com> |
6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> | |
7 | * Bugreports.to..: <Linux390@de.ibm.com> | |
d41dd122 | 8 | * Copyright IBM Corp. 1999, 2009 |
ab1d848f NH |
9 | * EMC Symmetrix ioctl Copyright EMC Corporation, 2008 |
10 | * Author.........: Nigel Hislop <hislop_nigel@emc.com> | |
1da177e4 LT |
11 | */ |
12 | ||
ca99dab0 | 13 | #define KMSG_COMPONENT "dasd-eckd" |
fc19f381 | 14 | |
1da177e4 LT |
15 | #include <linux/stddef.h> |
16 | #include <linux/kernel.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/hdreg.h> /* HDIO_GETGEO */ | |
19 | #include <linux/bio.h> | |
20 | #include <linux/module.h> | |
048cd4e5 | 21 | #include <linux/compat.h> |
1da177e4 | 22 | #include <linux/init.h> |
5a3b7b11 | 23 | #include <linux/seq_file.h> |
1da177e4 | 24 | |
382b7366 | 25 | #include <asm/css_chars.h> |
1da177e4 LT |
26 | #include <asm/debug.h> |
27 | #include <asm/idals.h> | |
28 | #include <asm/ebcdic.h> | |
29 | #include <asm/io.h> | |
7c0f6ba6 | 30 | #include <linux/uaccess.h> |
40545573 | 31 | #include <asm/cio.h> |
1da177e4 | 32 | #include <asm/ccwdev.h> |
f3eb5384 | 33 | #include <asm/itcw.h> |
5db8440c SH |
34 | #include <asm/schid.h> |
35 | #include <asm/chpid.h> | |
1da177e4 LT |
36 | |
37 | #include "dasd_int.h" | |
38 | #include "dasd_eckd.h" | |
39 | ||
40 | #ifdef PRINTK_HEADER | |
41 | #undef PRINTK_HEADER | |
42 | #endif /* PRINTK_HEADER */ | |
43 | #define PRINTK_HEADER "dasd(eckd):" | |
44 | ||
e4dbb0f2 SH |
45 | /* |
46 | * raw track access always map to 64k in memory | |
47 | * so it maps to 16 blocks of 4k per track | |
48 | */ | |
49 | #define DASD_RAW_BLOCK_PER_TRACK 16 | |
50 | #define DASD_RAW_BLOCKSIZE 4096 | |
51 | /* 64k are 128 x 512 byte sectors */ | |
52 | #define DASD_RAW_SECTORS_PER_TRACK 128 | |
53 | ||
1da177e4 LT |
54 | MODULE_LICENSE("GPL"); |
55 | ||
56 | static struct dasd_discipline dasd_eckd_discipline; | |
57 | ||
1da177e4 LT |
58 | /* The ccw bus type uses this table to find devices that it sends to |
59 | * dasd_eckd_probe */ | |
60 | static struct ccw_device_id dasd_eckd_ids[] = { | |
d2c993d8 HC |
61 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
62 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, | |
5da24b76 | 63 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3}, |
d2c993d8 HC |
64 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
65 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, | |
66 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, | |
67 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, | |
68 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, | |
69 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, | |
70 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, | |
1da177e4 LT |
71 | { /* end of list */ }, |
72 | }; | |
73 | ||
74 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); | |
75 | ||
76 | static struct ccw_driver dasd_eckd_driver; /* see below */ | |
77 | ||
558b9ef0 SW |
78 | static void *rawpadpage; |
79 | ||
eb6e199b SW |
80 | #define INIT_CQR_OK 0 |
81 | #define INIT_CQR_UNFORMATTED 1 | |
82 | #define INIT_CQR_ERROR 2 | |
83 | ||
f932bcea SW |
84 | /* emergency request for reserve/release */ |
85 | static struct { | |
86 | struct dasd_ccw_req cqr; | |
87 | struct ccw1 ccw; | |
88 | char data[32]; | |
89 | } *dasd_reserve_req; | |
90 | static DEFINE_MUTEX(dasd_reserve_mutex); | |
91 | ||
9e12e54c JH |
92 | static struct { |
93 | struct dasd_ccw_req cqr; | |
94 | struct ccw1 ccw[2]; | |
95 | char data[40]; | |
96 | } *dasd_vol_info_req; | |
97 | static DEFINE_MUTEX(dasd_vol_info_mutex); | |
98 | ||
99 | struct ext_pool_exhaust_work_data { | |
100 | struct work_struct worker; | |
101 | struct dasd_device *device; | |
102 | struct dasd_device *base; | |
103 | }; | |
104 | ||
a4d26c6a SW |
105 | /* definitions for the path verification worker */ |
106 | struct path_verification_work_data { | |
107 | struct work_struct worker; | |
108 | struct dasd_device *device; | |
109 | struct dasd_ccw_req cqr; | |
110 | struct ccw1 ccw; | |
111 | __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE]; | |
112 | int isglobal; | |
113 | __u8 tbvpm; | |
114 | }; | |
115 | static struct path_verification_work_data *path_verification_worker; | |
116 | static DEFINE_MUTEX(dasd_path_verification_mutex); | |
eb6e199b | 117 | |
5db8440c SH |
118 | struct check_attention_work_data { |
119 | struct work_struct worker; | |
120 | struct dasd_device *device; | |
121 | __u8 lpum; | |
122 | }; | |
123 | ||
c729696b | 124 | static int dasd_eckd_ext_pool_id(struct dasd_device *); |
8fd57520 JH |
125 | static int prepare_itcw(struct itcw *, unsigned int, unsigned int, int, |
126 | struct dasd_device *, struct dasd_device *, | |
127 | unsigned int, int, unsigned int, unsigned int, | |
128 | unsigned int, unsigned int); | |
129 | ||
1da177e4 LT |
130 | /* initial attempt at a probe function. this can be simplified once |
131 | * the other detection code is gone */ | |
132 | static int | |
133 | dasd_eckd_probe (struct ccw_device *cdev) | |
134 | { | |
135 | int ret; | |
136 | ||
40545573 | 137 | /* set ECKD specific ccw-device options */ |
454e1fa1 PO |
138 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE | |
139 | CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH); | |
40545573 | 140 | if (ret) { |
b8ed5dd5 SH |
141 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", |
142 | "dasd_eckd_probe: could not set " | |
143 | "ccw-device options"); | |
1da177e4 | 144 | return ret; |
40545573 HH |
145 | } |
146 | ret = dasd_generic_probe(cdev, &dasd_eckd_discipline); | |
147 | return ret; | |
1da177e4 LT |
148 | } |
149 | ||
150 | static int | |
151 | dasd_eckd_set_online(struct ccw_device *cdev) | |
152 | { | |
40545573 | 153 | return dasd_generic_set_online(cdev, &dasd_eckd_discipline); |
1da177e4 LT |
154 | } |
155 | ||
1da177e4 LT |
156 | static const int sizes_trk0[] = { 28, 148, 84 }; |
157 | #define LABEL_SIZE 140 | |
158 | ||
3bc9fef9 | 159 | /* head and record addresses of count_area read in analysis ccw */ |
ce6915f5 | 160 | static const int count_area_head[] = { 0, 0, 0, 0, 1 }; |
3bc9fef9 SH |
161 | static const int count_area_rec[] = { 1, 2, 3, 4, 1 }; |
162 | ||
1da177e4 LT |
163 | static inline unsigned int |
164 | ceil_quot(unsigned int d1, unsigned int d2) | |
165 | { | |
166 | return (d1 + (d2 - 1)) / d2; | |
167 | } | |
168 | ||
4d284cac | 169 | static unsigned int |
1da177e4 LT |
170 | recs_per_track(struct dasd_eckd_characteristics * rdc, |
171 | unsigned int kl, unsigned int dl) | |
172 | { | |
173 | int dn, kn; | |
174 | ||
175 | switch (rdc->dev_type) { | |
176 | case 0x3380: | |
177 | if (kl) | |
178 | return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) + | |
179 | ceil_quot(dl + 12, 32)); | |
180 | else | |
181 | return 1499 / (15 + ceil_quot(dl + 12, 32)); | |
182 | case 0x3390: | |
183 | dn = ceil_quot(dl + 6, 232) + 1; | |
184 | if (kl) { | |
185 | kn = ceil_quot(kl + 6, 232) + 1; | |
186 | return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) + | |
187 | 9 + ceil_quot(dl + 6 * dn, 34)); | |
188 | } else | |
189 | return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34)); | |
190 | case 0x9345: | |
191 | dn = ceil_quot(dl + 6, 232) + 1; | |
192 | if (kl) { | |
193 | kn = ceil_quot(kl + 6, 232) + 1; | |
194 | return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) + | |
195 | ceil_quot(dl + 6 * dn, 34)); | |
196 | } else | |
197 | return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34)); | |
198 | } | |
199 | return 0; | |
200 | } | |
201 | ||
b44b0ab3 SW |
202 | static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head) |
203 | { | |
204 | geo->cyl = (__u16) cyl; | |
205 | geo->head = cyl >> 16; | |
206 | geo->head <<= 4; | |
207 | geo->head |= head; | |
208 | } | |
209 | ||
5628683c | 210 | static int set_timestamp(struct ccw1 *ccw, struct DE_eckd_data *data, |
45f186be | 211 | struct dasd_device *device) |
1da177e4 | 212 | { |
543691a4 | 213 | struct dasd_eckd_private *private = device->private; |
d54853ef | 214 | int rc; |
1da177e4 | 215 | |
5628683c SH |
216 | rc = get_phys_clock(&data->ep_sys_time); |
217 | /* | |
218 | * Ignore return code if XRC is not supported or | |
219 | * sync clock is switched off | |
220 | */ | |
221 | if ((rc && !private->rdc_data.facilities.XRC_supported) || | |
222 | rc == -EOPNOTSUPP || rc == -EACCES) | |
d54853ef | 223 | return 0; |
1da177e4 | 224 | |
45f186be | 225 | /* switch on System Time Stamp - needed for XRC Support */ |
d54853ef MS |
226 | data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */ |
227 | data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */ | |
1da177e4 | 228 | |
45f186be JH |
229 | if (ccw) { |
230 | ccw->count = sizeof(struct DE_eckd_data); | |
231 | ccw->flags |= CCW_FLAG_SLI; | |
232 | } | |
233 | ||
d54853ef MS |
234 | return rc; |
235 | } | |
1da177e4 | 236 | |
4d284cac | 237 | static int |
b44b0ab3 | 238 | define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk, |
45f186be JH |
239 | unsigned int totrk, int cmd, struct dasd_device *device, |
240 | int blksize) | |
1da177e4 | 241 | { |
543691a4 | 242 | struct dasd_eckd_private *private = device->private; |
b44b0ab3 | 243 | u16 heads, beghead, endhead; |
45f186be | 244 | u32 begcyl, endcyl; |
d54853ef | 245 | int rc = 0; |
1da177e4 | 246 | |
45f186be JH |
247 | if (ccw) { |
248 | ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT; | |
249 | ccw->flags = 0; | |
250 | ccw->count = 16; | |
251 | ccw->cda = (__u32)__pa(data); | |
252 | } | |
1da177e4 | 253 | |
8e09f215 | 254 | memset(data, 0, sizeof(struct DE_eckd_data)); |
1da177e4 LT |
255 | switch (cmd) { |
256 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
257 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
258 | case DASD_ECKD_CCW_READ: | |
259 | case DASD_ECKD_CCW_READ_MT: | |
260 | case DASD_ECKD_CCW_READ_CKD: | |
261 | case DASD_ECKD_CCW_READ_CKD_MT: | |
262 | case DASD_ECKD_CCW_READ_KD: | |
263 | case DASD_ECKD_CCW_READ_KD_MT: | |
1da177e4 LT |
264 | data->mask.perm = 0x1; |
265 | data->attributes.operation = private->attrib.operation; | |
266 | break; | |
8fd57520 JH |
267 | case DASD_ECKD_CCW_READ_COUNT: |
268 | data->mask.perm = 0x1; | |
269 | data->attributes.operation = DASD_BYPASS_CACHE; | |
270 | break; | |
45f186be JH |
271 | case DASD_ECKD_CCW_READ_TRACK: |
272 | case DASD_ECKD_CCW_READ_TRACK_DATA: | |
273 | data->mask.perm = 0x1; | |
274 | data->attributes.operation = private->attrib.operation; | |
275 | data->blk_size = 0; | |
276 | break; | |
1da177e4 LT |
277 | case DASD_ECKD_CCW_WRITE: |
278 | case DASD_ECKD_CCW_WRITE_MT: | |
279 | case DASD_ECKD_CCW_WRITE_KD: | |
280 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
281 | data->mask.perm = 0x02; | |
282 | data->attributes.operation = private->attrib.operation; | |
5628683c | 283 | rc = set_timestamp(ccw, data, device); |
1da177e4 LT |
284 | break; |
285 | case DASD_ECKD_CCW_WRITE_CKD: | |
286 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
287 | data->attributes.operation = DASD_BYPASS_CACHE; | |
5628683c | 288 | rc = set_timestamp(ccw, data, device); |
1da177e4 LT |
289 | break; |
290 | case DASD_ECKD_CCW_ERASE: | |
291 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
292 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
293 | data->mask.perm = 0x3; | |
294 | data->mask.auth = 0x1; | |
295 | data->attributes.operation = DASD_BYPASS_CACHE; | |
5628683c | 296 | rc = set_timestamp(ccw, data, device); |
45f186be JH |
297 | break; |
298 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: | |
299 | data->mask.perm = 0x03; | |
300 | data->attributes.operation = private->attrib.operation; | |
301 | data->blk_size = 0; | |
302 | break; | |
303 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: | |
304 | data->mask.perm = 0x02; | |
305 | data->attributes.operation = private->attrib.operation; | |
306 | data->blk_size = blksize; | |
5628683c | 307 | rc = set_timestamp(ccw, data, device); |
1da177e4 LT |
308 | break; |
309 | default: | |
fc19f381 SH |
310 | dev_err(&device->cdev->dev, |
311 | "0x%x is not a known command\n", cmd); | |
1da177e4 LT |
312 | break; |
313 | } | |
314 | ||
315 | data->attributes.mode = 0x3; /* ECKD */ | |
316 | ||
317 | if ((private->rdc_data.cu_type == 0x2105 || | |
318 | private->rdc_data.cu_type == 0x2107 || | |
319 | private->rdc_data.cu_type == 0x1750) | |
320 | && !(private->uses_cdl && trk < 2)) | |
321 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ | |
322 | ||
b44b0ab3 SW |
323 | heads = private->rdc_data.trk_per_cyl; |
324 | begcyl = trk / heads; | |
325 | beghead = trk % heads; | |
326 | endcyl = totrk / heads; | |
327 | endhead = totrk % heads; | |
1da177e4 LT |
328 | |
329 | /* check for sequential prestage - enhance cylinder range */ | |
330 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || | |
331 | data->attributes.operation == DASD_SEQ_ACCESS) { | |
138c014d | 332 | |
b44b0ab3 SW |
333 | if (endcyl + private->attrib.nr_cyl < private->real_cyl) |
334 | endcyl += private->attrib.nr_cyl; | |
1da177e4 | 335 | else |
b44b0ab3 | 336 | endcyl = (private->real_cyl - 1); |
1da177e4 LT |
337 | } |
338 | ||
b44b0ab3 SW |
339 | set_ch_t(&data->beg_ext, begcyl, beghead); |
340 | set_ch_t(&data->end_ext, endcyl, endhead); | |
d54853ef | 341 | return rc; |
1da177e4 LT |
342 | } |
343 | ||
8e09f215 | 344 | |
45f186be JH |
345 | static void locate_record_ext(struct ccw1 *ccw, struct LRE_eckd_data *data, |
346 | unsigned int trk, unsigned int rec_on_trk, | |
347 | int count, int cmd, struct dasd_device *device, | |
348 | unsigned int reclen, unsigned int tlf) | |
f3eb5384 | 349 | { |
543691a4 | 350 | struct dasd_eckd_private *private = device->private; |
f3eb5384 SW |
351 | int sector; |
352 | int dn, d; | |
353 | ||
45f186be JH |
354 | if (ccw) { |
355 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD_EXT; | |
356 | ccw->flags = 0; | |
357 | if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) | |
358 | ccw->count = 22; | |
359 | else | |
360 | ccw->count = 20; | |
361 | ccw->cda = (__u32)__pa(data); | |
362 | } | |
363 | ||
f3eb5384 SW |
364 | memset(data, 0, sizeof(*data)); |
365 | sector = 0; | |
366 | if (rec_on_trk) { | |
367 | switch (private->rdc_data.dev_type) { | |
368 | case 0x3390: | |
369 | dn = ceil_quot(reclen + 6, 232); | |
370 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); | |
371 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
372 | break; | |
373 | case 0x3380: | |
374 | d = 7 + ceil_quot(reclen + 12, 32); | |
375 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
376 | break; | |
377 | } | |
378 | } | |
379 | data->sector = sector; | |
380 | /* note: meaning of count depends on the operation | |
381 | * for record based I/O it's the number of records, but for | |
382 | * track based I/O it's the number of tracks | |
383 | */ | |
384 | data->count = count; | |
385 | switch (cmd) { | |
386 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
387 | data->operation.orientation = 0x3; | |
388 | data->operation.operation = 0x03; | |
389 | break; | |
390 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
391 | data->operation.orientation = 0x3; | |
392 | data->operation.operation = 0x16; | |
393 | break; | |
394 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
395 | data->operation.orientation = 0x1; | |
396 | data->operation.operation = 0x03; | |
397 | data->count++; | |
398 | break; | |
399 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
400 | data->operation.orientation = 0x3; | |
401 | data->operation.operation = 0x16; | |
402 | data->count++; | |
403 | break; | |
404 | case DASD_ECKD_CCW_WRITE: | |
405 | case DASD_ECKD_CCW_WRITE_MT: | |
406 | case DASD_ECKD_CCW_WRITE_KD: | |
407 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
408 | data->auxiliary.length_valid = 0x1; | |
409 | data->length = reclen; | |
410 | data->operation.operation = 0x01; | |
411 | break; | |
412 | case DASD_ECKD_CCW_WRITE_CKD: | |
413 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
414 | data->auxiliary.length_valid = 0x1; | |
415 | data->length = reclen; | |
416 | data->operation.operation = 0x03; | |
417 | break; | |
e4dbb0f2 SH |
418 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: |
419 | data->operation.orientation = 0x0; | |
420 | data->operation.operation = 0x3F; | |
421 | data->extended_operation = 0x11; | |
422 | data->length = 0; | |
423 | data->extended_parameter_length = 0x02; | |
424 | if (data->count > 8) { | |
425 | data->extended_parameter[0] = 0xFF; | |
426 | data->extended_parameter[1] = 0xFF; | |
427 | data->extended_parameter[1] <<= (16 - count); | |
428 | } else { | |
429 | data->extended_parameter[0] = 0xFF; | |
430 | data->extended_parameter[0] <<= (8 - count); | |
431 | data->extended_parameter[1] = 0x00; | |
432 | } | |
433 | data->sector = 0xFF; | |
434 | break; | |
f3eb5384 SW |
435 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
436 | data->auxiliary.length_valid = 0x1; | |
437 | data->length = reclen; /* not tlf, as one might think */ | |
438 | data->operation.operation = 0x3F; | |
439 | data->extended_operation = 0x23; | |
440 | break; | |
441 | case DASD_ECKD_CCW_READ: | |
442 | case DASD_ECKD_CCW_READ_MT: | |
443 | case DASD_ECKD_CCW_READ_KD: | |
444 | case DASD_ECKD_CCW_READ_KD_MT: | |
445 | data->auxiliary.length_valid = 0x1; | |
446 | data->length = reclen; | |
447 | data->operation.operation = 0x06; | |
448 | break; | |
449 | case DASD_ECKD_CCW_READ_CKD: | |
450 | case DASD_ECKD_CCW_READ_CKD_MT: | |
451 | data->auxiliary.length_valid = 0x1; | |
452 | data->length = reclen; | |
453 | data->operation.operation = 0x16; | |
454 | break; | |
455 | case DASD_ECKD_CCW_READ_COUNT: | |
456 | data->operation.operation = 0x06; | |
457 | break; | |
e4dbb0f2 SH |
458 | case DASD_ECKD_CCW_READ_TRACK: |
459 | data->operation.orientation = 0x1; | |
460 | data->operation.operation = 0x0C; | |
461 | data->extended_parameter_length = 0; | |
462 | data->sector = 0xFF; | |
463 | break; | |
f3eb5384 SW |
464 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
465 | data->auxiliary.length_valid = 0x1; | |
466 | data->length = tlf; | |
467 | data->operation.operation = 0x0C; | |
468 | break; | |
469 | case DASD_ECKD_CCW_ERASE: | |
470 | data->length = reclen; | |
471 | data->auxiliary.length_valid = 0x1; | |
472 | data->operation.operation = 0x0b; | |
473 | break; | |
474 | default: | |
475 | DBF_DEV_EVENT(DBF_ERR, device, | |
476 | "fill LRE unknown opcode 0x%x", cmd); | |
477 | BUG(); | |
478 | } | |
479 | set_ch_t(&data->seek_addr, | |
480 | trk / private->rdc_data.trk_per_cyl, | |
481 | trk % private->rdc_data.trk_per_cyl); | |
482 | data->search_arg.cyl = data->seek_addr.cyl; | |
483 | data->search_arg.head = data->seek_addr.head; | |
484 | data->search_arg.record = rec_on_trk; | |
485 | } | |
486 | ||
487 | static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, | |
488 | unsigned int trk, unsigned int totrk, int cmd, | |
489 | struct dasd_device *basedev, struct dasd_device *startdev, | |
45f186be | 490 | unsigned int format, unsigned int rec_on_trk, int count, |
f3eb5384 | 491 | unsigned int blksize, unsigned int tlf) |
8e09f215 SW |
492 | { |
493 | struct dasd_eckd_private *basepriv, *startpriv; | |
f3eb5384 | 494 | struct LRE_eckd_data *lredata; |
45f186be | 495 | struct DE_eckd_data *dedata; |
8e09f215 SW |
496 | int rc = 0; |
497 | ||
543691a4 SO |
498 | basepriv = basedev->private; |
499 | startpriv = startdev->private; | |
f3eb5384 SW |
500 | dedata = &pfxdata->define_extent; |
501 | lredata = &pfxdata->locate_record; | |
8e09f215 SW |
502 | |
503 | ccw->cmd_code = DASD_ECKD_CCW_PFX; | |
504 | ccw->flags = 0; | |
e4dbb0f2 SH |
505 | if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) { |
506 | ccw->count = sizeof(*pfxdata) + 2; | |
507 | ccw->cda = (__u32) __pa(pfxdata); | |
508 | memset(pfxdata, 0, sizeof(*pfxdata) + 2); | |
509 | } else { | |
510 | ccw->count = sizeof(*pfxdata); | |
511 | ccw->cda = (__u32) __pa(pfxdata); | |
512 | memset(pfxdata, 0, sizeof(*pfxdata)); | |
513 | } | |
8e09f215 | 514 | |
8e09f215 | 515 | /* prefix data */ |
f3eb5384 SW |
516 | if (format > 1) { |
517 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
518 | "PFX LRE unknown format 0x%x", format); | |
519 | BUG(); | |
520 | return -EINVAL; | |
521 | } | |
522 | pfxdata->format = format; | |
4abb08c2 SW |
523 | pfxdata->base_address = basepriv->ned->unit_addr; |
524 | pfxdata->base_lss = basepriv->ned->ID; | |
f3eb5384 | 525 | pfxdata->validity.define_extent = 1; |
8e09f215 SW |
526 | |
527 | /* private uid is kept up to date, conf_data may be outdated */ | |
da340f92 | 528 | if (startpriv->uid.type == UA_BASE_PAV_ALIAS) |
8e09f215 | 529 | pfxdata->validity.verify_base = 1; |
da340f92 SH |
530 | |
531 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) { | |
532 | pfxdata->validity.verify_base = 1; | |
533 | pfxdata->validity.hyper_pav = 1; | |
8e09f215 SW |
534 | } |
535 | ||
45f186be | 536 | rc = define_extent(NULL, dedata, trk, totrk, cmd, basedev, blksize); |
8e09f215 | 537 | |
45f186be JH |
538 | /* |
539 | * For some commands the System Time Stamp is set in the define extent | |
540 | * data when XRC is supported. The validity of the time stamp must be | |
541 | * reflected in the prefix data as well. | |
542 | */ | |
543 | if (dedata->ga_extended & 0x08 && dedata->ga_extended & 0x02) | |
544 | pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */ | |
f3eb5384 SW |
545 | |
546 | if (format == 1) { | |
45f186be JH |
547 | locate_record_ext(NULL, lredata, trk, rec_on_trk, count, cmd, |
548 | basedev, blksize, tlf); | |
f3eb5384 SW |
549 | } |
550 | ||
8e09f215 SW |
551 | return rc; |
552 | } | |
553 | ||
f3eb5384 SW |
554 | static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
555 | unsigned int trk, unsigned int totrk, int cmd, | |
556 | struct dasd_device *basedev, struct dasd_device *startdev) | |
557 | { | |
558 | return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev, | |
559 | 0, 0, 0, 0, 0); | |
560 | } | |
561 | ||
4d284cac | 562 | static void |
b44b0ab3 SW |
563 | locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk, |
564 | unsigned int rec_on_trk, int no_rec, int cmd, | |
1da177e4 LT |
565 | struct dasd_device * device, int reclen) |
566 | { | |
543691a4 | 567 | struct dasd_eckd_private *private = device->private; |
1da177e4 LT |
568 | int sector; |
569 | int dn, d; | |
138c014d | 570 | |
1da177e4 LT |
571 | DBF_DEV_EVENT(DBF_INFO, device, |
572 | "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d", | |
573 | trk, rec_on_trk, no_rec, cmd, reclen); | |
574 | ||
575 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD; | |
576 | ccw->flags = 0; | |
577 | ccw->count = 16; | |
578 | ccw->cda = (__u32) __pa(data); | |
579 | ||
8e09f215 | 580 | memset(data, 0, sizeof(struct LO_eckd_data)); |
1da177e4 LT |
581 | sector = 0; |
582 | if (rec_on_trk) { | |
583 | switch (private->rdc_data.dev_type) { | |
584 | case 0x3390: | |
585 | dn = ceil_quot(reclen + 6, 232); | |
586 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); | |
587 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
588 | break; | |
589 | case 0x3380: | |
590 | d = 7 + ceil_quot(reclen + 12, 32); | |
591 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
592 | break; | |
593 | } | |
594 | } | |
595 | data->sector = sector; | |
596 | data->count = no_rec; | |
597 | switch (cmd) { | |
598 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
599 | data->operation.orientation = 0x3; | |
600 | data->operation.operation = 0x03; | |
601 | break; | |
602 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
603 | data->operation.orientation = 0x3; | |
604 | data->operation.operation = 0x16; | |
605 | break; | |
606 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
607 | data->operation.orientation = 0x1; | |
608 | data->operation.operation = 0x03; | |
609 | data->count++; | |
610 | break; | |
611 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
612 | data->operation.orientation = 0x3; | |
613 | data->operation.operation = 0x16; | |
614 | data->count++; | |
615 | break; | |
616 | case DASD_ECKD_CCW_WRITE: | |
617 | case DASD_ECKD_CCW_WRITE_MT: | |
618 | case DASD_ECKD_CCW_WRITE_KD: | |
619 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
620 | data->auxiliary.last_bytes_used = 0x1; | |
621 | data->length = reclen; | |
622 | data->operation.operation = 0x01; | |
623 | break; | |
624 | case DASD_ECKD_CCW_WRITE_CKD: | |
625 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
626 | data->auxiliary.last_bytes_used = 0x1; | |
627 | data->length = reclen; | |
628 | data->operation.operation = 0x03; | |
629 | break; | |
630 | case DASD_ECKD_CCW_READ: | |
631 | case DASD_ECKD_CCW_READ_MT: | |
632 | case DASD_ECKD_CCW_READ_KD: | |
633 | case DASD_ECKD_CCW_READ_KD_MT: | |
634 | data->auxiliary.last_bytes_used = 0x1; | |
635 | data->length = reclen; | |
636 | data->operation.operation = 0x06; | |
637 | break; | |
638 | case DASD_ECKD_CCW_READ_CKD: | |
639 | case DASD_ECKD_CCW_READ_CKD_MT: | |
640 | data->auxiliary.last_bytes_used = 0x1; | |
641 | data->length = reclen; | |
642 | data->operation.operation = 0x16; | |
643 | break; | |
644 | case DASD_ECKD_CCW_READ_COUNT: | |
645 | data->operation.operation = 0x06; | |
646 | break; | |
647 | case DASD_ECKD_CCW_ERASE: | |
648 | data->length = reclen; | |
649 | data->auxiliary.last_bytes_used = 0x1; | |
650 | data->operation.operation = 0x0b; | |
651 | break; | |
652 | default: | |
fc19f381 SH |
653 | DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record " |
654 | "opcode 0x%x", cmd); | |
1da177e4 | 655 | } |
b44b0ab3 SW |
656 | set_ch_t(&data->seek_addr, |
657 | trk / private->rdc_data.trk_per_cyl, | |
658 | trk % private->rdc_data.trk_per_cyl); | |
659 | data->search_arg.cyl = data->seek_addr.cyl; | |
660 | data->search_arg.head = data->seek_addr.head; | |
1da177e4 LT |
661 | data->search_arg.record = rec_on_trk; |
662 | } | |
663 | ||
664 | /* | |
665 | * Returns 1 if the block is one of the special blocks that needs | |
666 | * to get read/written with the KD variant of the command. | |
667 | * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and | |
668 | * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT. | |
669 | * Luckily the KD variants differ only by one bit (0x08) from the | |
670 | * normal variant. So don't wonder about code like: | |
671 | * if (dasd_eckd_cdl_special(blk_per_trk, recid)) | |
672 | * ccw->cmd_code |= 0x8; | |
673 | */ | |
674 | static inline int | |
675 | dasd_eckd_cdl_special(int blk_per_trk, int recid) | |
676 | { | |
677 | if (recid < 3) | |
678 | return 1; | |
679 | if (recid < blk_per_trk) | |
680 | return 0; | |
681 | if (recid < 2 * blk_per_trk) | |
682 | return 1; | |
683 | return 0; | |
684 | } | |
685 | ||
686 | /* | |
687 | * Returns the record size for the special blocks of the cdl format. | |
688 | * Only returns something useful if dasd_eckd_cdl_special is true | |
689 | * for the recid. | |
690 | */ | |
691 | static inline int | |
692 | dasd_eckd_cdl_reclen(int recid) | |
693 | { | |
694 | if (recid < 3) | |
695 | return sizes_trk0[recid]; | |
696 | return LABEL_SIZE; | |
697 | } | |
b206181d SH |
698 | /* create unique id from private structure. */ |
699 | static void create_uid(struct dasd_eckd_private *private) | |
3d052595 | 700 | { |
4abb08c2 | 701 | int count; |
b206181d | 702 | struct dasd_uid *uid; |
3d052595 | 703 | |
2dedf0d9 | 704 | uid = &private->uid; |
3d052595 | 705 | memset(uid, 0, sizeof(struct dasd_uid)); |
4abb08c2 | 706 | memcpy(uid->vendor, private->ned->HDA_manufacturer, |
d0710c7c | 707 | sizeof(uid->vendor) - 1); |
3d052595 | 708 | EBCASC(uid->vendor, sizeof(uid->vendor) - 1); |
4abb08c2 | 709 | memcpy(uid->serial, private->ned->HDA_location, |
d0710c7c | 710 | sizeof(uid->serial) - 1); |
3d052595 | 711 | EBCASC(uid->serial, sizeof(uid->serial) - 1); |
4abb08c2 | 712 | uid->ssid = private->gneq->subsystemID; |
a419aef8 | 713 | uid->real_unit_addr = private->ned->unit_addr; |
4abb08c2 SW |
714 | if (private->sneq) { |
715 | uid->type = private->sneq->sua_flags; | |
8e09f215 | 716 | if (uid->type == UA_BASE_PAV_ALIAS) |
4abb08c2 | 717 | uid->base_unit_addr = private->sneq->base_unit_addr; |
8e09f215 SW |
718 | } else { |
719 | uid->type = UA_BASE_DEVICE; | |
720 | } | |
4abb08c2 SW |
721 | if (private->vdsneq) { |
722 | for (count = 0; count < 16; count++) { | |
723 | sprintf(uid->vduit+2*count, "%02x", | |
724 | private->vdsneq->uit[count]); | |
725 | } | |
726 | } | |
b206181d SH |
727 | } |
728 | ||
729 | /* | |
730 | * Generate device unique id that specifies the physical device. | |
731 | */ | |
732 | static int dasd_eckd_generate_uid(struct dasd_device *device) | |
733 | { | |
543691a4 | 734 | struct dasd_eckd_private *private = device->private; |
b206181d SH |
735 | unsigned long flags; |
736 | ||
b206181d SH |
737 | if (!private) |
738 | return -ENODEV; | |
739 | if (!private->ned || !private->gneq) | |
740 | return -ENODEV; | |
741 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
742 | create_uid(private); | |
2dedf0d9 | 743 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
3d052595 HH |
744 | return 0; |
745 | } | |
746 | ||
2dedf0d9 SH |
747 | static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid) |
748 | { | |
543691a4 | 749 | struct dasd_eckd_private *private = device->private; |
2dedf0d9 SH |
750 | unsigned long flags; |
751 | ||
543691a4 | 752 | if (private) { |
2dedf0d9 SH |
753 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
754 | *uid = private->uid; | |
755 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
756 | return 0; | |
757 | } | |
758 | return -EINVAL; | |
759 | } | |
760 | ||
b206181d SH |
761 | /* |
762 | * compare device UID with data of a given dasd_eckd_private structure | |
763 | * return 0 for match | |
764 | */ | |
765 | static int dasd_eckd_compare_path_uid(struct dasd_device *device, | |
766 | struct dasd_eckd_private *private) | |
767 | { | |
768 | struct dasd_uid device_uid; | |
769 | ||
770 | create_uid(private); | |
771 | dasd_eckd_get_uid(device, &device_uid); | |
772 | ||
773 | return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid)); | |
774 | } | |
775 | ||
a4d26c6a SW |
776 | static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device, |
777 | struct dasd_ccw_req *cqr, | |
778 | __u8 *rcd_buffer, | |
779 | __u8 lpm) | |
17283b56 | 780 | { |
17283b56 | 781 | struct ccw1 *ccw; |
a4d26c6a SW |
782 | /* |
783 | * buffer has to start with EBCDIC "V1.0" to show | |
784 | * support for virtual device SNEQ | |
785 | */ | |
786 | rcd_buffer[0] = 0xE5; | |
787 | rcd_buffer[1] = 0xF1; | |
788 | rcd_buffer[2] = 0x4B; | |
789 | rcd_buffer[3] = 0xF0; | |
17283b56 CH |
790 | |
791 | ccw = cqr->cpaddr; | |
a4d26c6a SW |
792 | ccw->cmd_code = DASD_ECKD_CCW_RCD; |
793 | ccw->flags = 0; | |
17283b56 | 794 | ccw->cda = (__u32)(addr_t)rcd_buffer; |
a4d26c6a SW |
795 | ccw->count = DASD_ECKD_RCD_DATA_SIZE; |
796 | cqr->magic = DASD_ECKD_MAGIC; | |
17283b56 | 797 | |
8e09f215 SW |
798 | cqr->startdev = device; |
799 | cqr->memdev = device; | |
800 | cqr->block = NULL; | |
17283b56 CH |
801 | cqr->expires = 10*HZ; |
802 | cqr->lpm = lpm; | |
eb6e199b | 803 | cqr->retries = 256; |
1aae0560 | 804 | cqr->buildclk = get_tod_clock(); |
17283b56 | 805 | cqr->status = DASD_CQR_FILLED; |
a4d26c6a SW |
806 | set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); |
807 | } | |
808 | ||
5915a873 SH |
809 | /* |
810 | * Wakeup helper for read_conf | |
811 | * if the cqr is not done and needs some error recovery | |
812 | * the buffer has to be re-initialized with the EBCDIC "V1.0" | |
813 | * to show support for virtual device SNEQ | |
814 | */ | |
815 | static void read_conf_cb(struct dasd_ccw_req *cqr, void *data) | |
816 | { | |
817 | struct ccw1 *ccw; | |
818 | __u8 *rcd_buffer; | |
819 | ||
820 | if (cqr->status != DASD_CQR_DONE) { | |
821 | ccw = cqr->cpaddr; | |
822 | rcd_buffer = (__u8 *)((addr_t) ccw->cda); | |
823 | memset(rcd_buffer, 0, sizeof(*rcd_buffer)); | |
824 | ||
825 | rcd_buffer[0] = 0xE5; | |
826 | rcd_buffer[1] = 0xF1; | |
827 | rcd_buffer[2] = 0x4B; | |
828 | rcd_buffer[3] = 0xF0; | |
829 | } | |
830 | dasd_wakeup_cb(cqr, data); | |
831 | } | |
832 | ||
a4d26c6a SW |
833 | static int dasd_eckd_read_conf_immediately(struct dasd_device *device, |
834 | struct dasd_ccw_req *cqr, | |
835 | __u8 *rcd_buffer, | |
836 | __u8 lpm) | |
837 | { | |
838 | struct ciw *ciw; | |
839 | int rc; | |
840 | /* | |
841 | * sanity check: scan for RCD command in extended SenseID data | |
842 | * some devices do not support RCD | |
843 | */ | |
844 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); | |
845 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) | |
846 | return -EOPNOTSUPP; | |
847 | ||
848 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm); | |
849 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
5a27e60d | 850 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
a4d26c6a | 851 | cqr->retries = 5; |
5915a873 | 852 | cqr->callback = read_conf_cb; |
a4d26c6a SW |
853 | rc = dasd_sleep_on_immediatly(cqr); |
854 | return rc; | |
17283b56 CH |
855 | } |
856 | ||
857 | static int dasd_eckd_read_conf_lpm(struct dasd_device *device, | |
858 | void **rcd_buffer, | |
859 | int *rcd_buffer_size, __u8 lpm) | |
860 | { | |
861 | struct ciw *ciw; | |
862 | char *rcd_buf = NULL; | |
863 | int ret; | |
864 | struct dasd_ccw_req *cqr; | |
865 | ||
866 | /* | |
a4d26c6a SW |
867 | * sanity check: scan for RCD command in extended SenseID data |
868 | * some devices do not support RCD | |
17283b56 CH |
869 | */ |
870 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); | |
a4d26c6a | 871 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) { |
17283b56 CH |
872 | ret = -EOPNOTSUPP; |
873 | goto out_error; | |
874 | } | |
a4d26c6a | 875 | rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA); |
17283b56 CH |
876 | if (!rcd_buf) { |
877 | ret = -ENOMEM; | |
878 | goto out_error; | |
879 | } | |
a4d26c6a SW |
880 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, |
881 | 0, /* use rcd_buf as data ara */ | |
c5205f2f | 882 | device, NULL); |
17283b56 | 883 | if (IS_ERR(cqr)) { |
a4d26c6a SW |
884 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
885 | "Could not allocate RCD request"); | |
886 | ret = -ENOMEM; | |
17283b56 CH |
887 | goto out_error; |
888 | } | |
a4d26c6a | 889 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm); |
5915a873 | 890 | cqr->callback = read_conf_cb; |
17283b56 CH |
891 | ret = dasd_sleep_on(cqr); |
892 | /* | |
893 | * on success we update the user input parms | |
894 | */ | |
8e09f215 | 895 | dasd_sfree_request(cqr, cqr->memdev); |
17283b56 CH |
896 | if (ret) |
897 | goto out_error; | |
898 | ||
a4d26c6a | 899 | *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE; |
17283b56 CH |
900 | *rcd_buffer = rcd_buf; |
901 | return 0; | |
902 | out_error: | |
903 | kfree(rcd_buf); | |
904 | *rcd_buffer = NULL; | |
905 | *rcd_buffer_size = 0; | |
906 | return ret; | |
907 | } | |
908 | ||
4abb08c2 SW |
909 | static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private) |
910 | { | |
911 | ||
912 | struct dasd_sneq *sneq; | |
913 | int i, count; | |
914 | ||
915 | private->ned = NULL; | |
916 | private->sneq = NULL; | |
917 | private->vdsneq = NULL; | |
918 | private->gneq = NULL; | |
919 | count = private->conf_len / sizeof(struct dasd_sneq); | |
920 | sneq = (struct dasd_sneq *)private->conf_data; | |
921 | for (i = 0; i < count; ++i) { | |
922 | if (sneq->flags.identifier == 1 && sneq->format == 1) | |
923 | private->sneq = sneq; | |
924 | else if (sneq->flags.identifier == 1 && sneq->format == 4) | |
925 | private->vdsneq = (struct vd_sneq *)sneq; | |
926 | else if (sneq->flags.identifier == 2) | |
927 | private->gneq = (struct dasd_gneq *)sneq; | |
928 | else if (sneq->flags.identifier == 3 && sneq->res1 == 1) | |
929 | private->ned = (struct dasd_ned *)sneq; | |
930 | sneq++; | |
931 | } | |
932 | if (!private->ned || !private->gneq) { | |
933 | private->ned = NULL; | |
934 | private->sneq = NULL; | |
935 | private->vdsneq = NULL; | |
936 | private->gneq = NULL; | |
937 | return -EINVAL; | |
938 | } | |
939 | return 0; | |
940 | ||
941 | }; | |
942 | ||
943 | static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len) | |
944 | { | |
945 | struct dasd_gneq *gneq; | |
946 | int i, count, found; | |
947 | ||
948 | count = conf_len / sizeof(*gneq); | |
949 | gneq = (struct dasd_gneq *)conf_data; | |
950 | found = 0; | |
951 | for (i = 0; i < count; ++i) { | |
952 | if (gneq->flags.identifier == 2) { | |
953 | found = 1; | |
954 | break; | |
955 | } | |
956 | gneq++; | |
957 | } | |
958 | if (found) | |
959 | return ((char *)gneq)[18] & 0x07; | |
960 | else | |
961 | return 0; | |
962 | } | |
963 | ||
c7c0c9de SH |
964 | static void dasd_eckd_clear_conf_data(struct dasd_device *device) |
965 | { | |
543691a4 | 966 | struct dasd_eckd_private *private = device->private; |
c7c0c9de SH |
967 | int i; |
968 | ||
c7c0c9de SH |
969 | private->conf_data = NULL; |
970 | private->conf_len = 0; | |
971 | for (i = 0; i < 8; i++) { | |
c9346151 SH |
972 | kfree(device->path[i].conf_data); |
973 | device->path[i].conf_data = NULL; | |
a521b048 SH |
974 | device->path[i].cssid = 0; |
975 | device->path[i].ssid = 0; | |
976 | device->path[i].chpid = 0; | |
c7c0c9de SH |
977 | } |
978 | } | |
979 | ||
980 | ||
4abb08c2 | 981 | static int dasd_eckd_read_conf(struct dasd_device *device) |
1da177e4 LT |
982 | { |
983 | void *conf_data; | |
984 | int conf_len, conf_data_saved; | |
b179b037 | 985 | int rc, path_err, pos; |
a4d26c6a | 986 | __u8 lpm, opm; |
b206181d | 987 | struct dasd_eckd_private *private, path_private; |
b206181d SH |
988 | struct dasd_uid *uid; |
989 | char print_path_uid[60], print_device_uid[60]; | |
ded27d8d | 990 | struct channel_path_desc_fmt0 *chp_desc; |
a521b048 | 991 | struct subchannel_id sch_id; |
1da177e4 | 992 | |
543691a4 | 993 | private = device->private; |
a4d26c6a | 994 | opm = ccw_device_get_path_mask(device->cdev); |
a521b048 | 995 | ccw_device_get_schid(device->cdev, &sch_id); |
1da177e4 | 996 | conf_data_saved = 0; |
55d3a85c | 997 | path_err = 0; |
1da177e4 LT |
998 | /* get configuration data per operational path */ |
999 | for (lpm = 0x80; lpm; lpm>>= 1) { | |
b206181d SH |
1000 | if (!(lpm & opm)) |
1001 | continue; | |
1002 | rc = dasd_eckd_read_conf_lpm(device, &conf_data, | |
1003 | &conf_len, lpm); | |
1004 | if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ | |
1005 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
1006 | "Read configuration data returned " | |
1007 | "error %d", rc); | |
1008 | return rc; | |
1009 | } | |
1010 | if (conf_data == NULL) { | |
1011 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1012 | "No configuration data " | |
1013 | "retrieved"); | |
1014 | /* no further analysis possible */ | |
c9346151 | 1015 | dasd_path_add_opm(device, opm); |
b206181d SH |
1016 | continue; /* no error */ |
1017 | } | |
1018 | /* save first valid configuration data */ | |
1019 | if (!conf_data_saved) { | |
c7c0c9de SH |
1020 | /* initially clear previously stored conf_data */ |
1021 | dasd_eckd_clear_conf_data(device); | |
b206181d SH |
1022 | private->conf_data = conf_data; |
1023 | private->conf_len = conf_len; | |
1024 | if (dasd_eckd_identify_conf_parts(private)) { | |
1025 | private->conf_data = NULL; | |
1026 | private->conf_len = 0; | |
1027 | kfree(conf_data); | |
1028 | continue; | |
1da177e4 | 1029 | } |
c7c0c9de SH |
1030 | pos = pathmask_to_pos(lpm); |
1031 | /* store per path conf_data */ | |
c9346151 | 1032 | device->path[pos].conf_data = conf_data; |
a521b048 SH |
1033 | device->path[pos].cssid = sch_id.cssid; |
1034 | device->path[pos].ssid = sch_id.ssid; | |
1035 | chp_desc = ccw_device_get_chp_desc(device->cdev, pos); | |
1036 | if (chp_desc) | |
1037 | device->path[pos].chpid = chp_desc->chpid; | |
1038 | kfree(chp_desc); | |
b206181d SH |
1039 | /* |
1040 | * build device UID that other path data | |
1041 | * can be compared to it | |
1042 | */ | |
1043 | dasd_eckd_generate_uid(device); | |
1044 | conf_data_saved++; | |
1045 | } else { | |
1046 | path_private.conf_data = conf_data; | |
1047 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; | |
1048 | if (dasd_eckd_identify_conf_parts( | |
1049 | &path_private)) { | |
1050 | path_private.conf_data = NULL; | |
1051 | path_private.conf_len = 0; | |
1052 | kfree(conf_data); | |
1053 | continue; | |
1da177e4 | 1054 | } |
b206181d SH |
1055 | if (dasd_eckd_compare_path_uid( |
1056 | device, &path_private)) { | |
1057 | uid = &path_private.uid; | |
1058 | if (strlen(uid->vduit) > 0) | |
1059 | snprintf(print_path_uid, | |
1060 | sizeof(print_path_uid), | |
1061 | "%s.%s.%04x.%02x.%s", | |
1062 | uid->vendor, uid->serial, | |
1063 | uid->ssid, uid->real_unit_addr, | |
1064 | uid->vduit); | |
1065 | else | |
1066 | snprintf(print_path_uid, | |
1067 | sizeof(print_path_uid), | |
1068 | "%s.%s.%04x.%02x", | |
1069 | uid->vendor, uid->serial, | |
1070 | uid->ssid, | |
1071 | uid->real_unit_addr); | |
1072 | uid = &private->uid; | |
1073 | if (strlen(uid->vduit) > 0) | |
1074 | snprintf(print_device_uid, | |
1075 | sizeof(print_device_uid), | |
1076 | "%s.%s.%04x.%02x.%s", | |
1077 | uid->vendor, uid->serial, | |
1078 | uid->ssid, uid->real_unit_addr, | |
1079 | uid->vduit); | |
1080 | else | |
1081 | snprintf(print_device_uid, | |
1082 | sizeof(print_device_uid), | |
1083 | "%s.%s.%04x.%02x", | |
1084 | uid->vendor, uid->serial, | |
1085 | uid->ssid, | |
1086 | uid->real_unit_addr); | |
1087 | dev_err(&device->cdev->dev, | |
1088 | "Not all channel paths lead to " | |
1089 | "the same device, path %02X leads to " | |
1090 | "device %s instead of %s\n", lpm, | |
1091 | print_path_uid, print_device_uid); | |
55d3a85c | 1092 | path_err = -EINVAL; |
c9346151 | 1093 | dasd_path_add_cablepm(device, lpm); |
55d3a85c | 1094 | continue; |
1da177e4 | 1095 | } |
c7c0c9de SH |
1096 | pos = pathmask_to_pos(lpm); |
1097 | /* store per path conf_data */ | |
c9346151 | 1098 | device->path[pos].conf_data = conf_data; |
a521b048 SH |
1099 | device->path[pos].cssid = sch_id.cssid; |
1100 | device->path[pos].ssid = sch_id.ssid; | |
1101 | chp_desc = ccw_device_get_chp_desc(device->cdev, pos); | |
1102 | if (chp_desc) | |
1103 | device->path[pos].chpid = chp_desc->chpid; | |
1104 | kfree(chp_desc); | |
b206181d SH |
1105 | path_private.conf_data = NULL; |
1106 | path_private.conf_len = 0; | |
1107 | } | |
1108 | switch (dasd_eckd_path_access(conf_data, conf_len)) { | |
1109 | case 0x02: | |
c9346151 | 1110 | dasd_path_add_nppm(device, lpm); |
b206181d SH |
1111 | break; |
1112 | case 0x03: | |
c9346151 | 1113 | dasd_path_add_ppm(device, lpm); |
b206181d | 1114 | break; |
1da177e4 | 1115 | } |
c9346151 SH |
1116 | if (!dasd_path_get_opm(device)) { |
1117 | dasd_path_set_opm(device, lpm); | |
ccc0e7dc SH |
1118 | dasd_generic_path_operational(device); |
1119 | } else { | |
c9346151 | 1120 | dasd_path_add_opm(device, lpm); |
ccc0e7dc | 1121 | } |
1da177e4 | 1122 | } |
b206181d | 1123 | |
55d3a85c | 1124 | return path_err; |
1da177e4 LT |
1125 | } |
1126 | ||
a521b048 SH |
1127 | static u32 get_fcx_max_data(struct dasd_device *device) |
1128 | { | |
1129 | struct dasd_eckd_private *private = device->private; | |
1130 | int fcx_in_css, fcx_in_gneq, fcx_in_features; | |
1131 | int tpm, mdc; | |
1132 | ||
1133 | if (dasd_nofcx) | |
1134 | return 0; | |
1135 | /* is transport mode supported? */ | |
1136 | fcx_in_css = css_general_characteristics.fcx; | |
1137 | fcx_in_gneq = private->gneq->reserved2[7] & 0x04; | |
1138 | fcx_in_features = private->features.feature[40] & 0x80; | |
1139 | tpm = fcx_in_css && fcx_in_gneq && fcx_in_features; | |
1140 | ||
1141 | if (!tpm) | |
1142 | return 0; | |
1143 | ||
1144 | mdc = ccw_device_get_mdc(device->cdev, 0); | |
1145 | if (mdc < 0) { | |
1146 | dev_warn(&device->cdev->dev, "Detecting the maximum supported data size for zHPF requests failed\n"); | |
1147 | return 0; | |
1148 | } else { | |
1149 | return (u32)mdc * FCX_MAX_DATA_FACTOR; | |
1150 | } | |
1151 | } | |
1152 | ||
a4d26c6a SW |
1153 | static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm) |
1154 | { | |
543691a4 | 1155 | struct dasd_eckd_private *private = device->private; |
a4d26c6a SW |
1156 | int mdc; |
1157 | u32 fcx_max_data; | |
1158 | ||
a4d26c6a SW |
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 | } | |
0f02c4e7 | 1168 | fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR; |
a4d26c6a SW |
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 | ||
b206181d SH |
1181 | static int rebuild_device_uid(struct dasd_device *device, |
1182 | struct path_verification_work_data *data) | |
1183 | { | |
543691a4 | 1184 | struct dasd_eckd_private *private = device->private; |
c9346151 | 1185 | __u8 lpm, opm = dasd_path_get_opm(device); |
543691a4 | 1186 | int rc = -ENODEV; |
b206181d SH |
1187 | |
1188 | for (lpm = 0x80; lpm; lpm >>= 1) { | |
1189 | if (!(lpm & opm)) | |
1190 | continue; | |
1191 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); | |
1192 | memset(&data->cqr, 0, sizeof(data->cqr)); | |
1193 | data->cqr.cpaddr = &data->ccw; | |
1194 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, | |
1195 | data->rcd_buffer, | |
1196 | lpm); | |
1197 | ||
1198 | if (rc) { | |
1199 | if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */ | |
1200 | continue; | |
1201 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
1202 | "Read configuration data " | |
1203 | "returned error %d", rc); | |
1204 | break; | |
1205 | } | |
1206 | memcpy(private->conf_data, data->rcd_buffer, | |
1207 | DASD_ECKD_RCD_DATA_SIZE); | |
1208 | if (dasd_eckd_identify_conf_parts(private)) { | |
1209 | rc = -ENODEV; | |
1210 | } else /* first valid path is enough */ | |
1211 | break; | |
1212 | } | |
1213 | ||
1214 | if (!rc) | |
1215 | rc = dasd_eckd_generate_uid(device); | |
1216 | ||
1217 | return rc; | |
1218 | } | |
1219 | ||
a4d26c6a SW |
1220 | static void do_path_verification_work(struct work_struct *work) |
1221 | { | |
1222 | struct path_verification_work_data *data; | |
1223 | struct dasd_device *device; | |
b206181d SH |
1224 | struct dasd_eckd_private path_private; |
1225 | struct dasd_uid *uid; | |
1226 | __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE]; | |
5db8440c | 1227 | __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm; |
a4d26c6a | 1228 | unsigned long flags; |
b206181d | 1229 | char print_uid[60]; |
a4d26c6a SW |
1230 | int rc; |
1231 | ||
1232 | data = container_of(work, struct path_verification_work_data, worker); | |
1233 | device = data->device; | |
1234 | ||
c8d1c0ff SH |
1235 | /* delay path verification until device was resumed */ |
1236 | if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { | |
1237 | schedule_work(work); | |
1238 | return; | |
1239 | } | |
1eb38023 SH |
1240 | /* check if path verification already running and delay if so */ |
1241 | if (test_and_set_bit(DASD_FLAG_PATH_VERIFY, &device->flags)) { | |
1242 | schedule_work(work); | |
1243 | return; | |
1244 | } | |
a4d26c6a SW |
1245 | opm = 0; |
1246 | npm = 0; | |
1247 | ppm = 0; | |
1248 | epm = 0; | |
5db8440c SH |
1249 | hpfpm = 0; |
1250 | cablepm = 0; | |
1251 | ||
a4d26c6a | 1252 | for (lpm = 0x80; lpm; lpm >>= 1) { |
b206181d SH |
1253 | if (!(lpm & data->tbvpm)) |
1254 | continue; | |
1255 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); | |
1256 | memset(&data->cqr, 0, sizeof(data->cqr)); | |
1257 | data->cqr.cpaddr = &data->ccw; | |
1258 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, | |
1259 | data->rcd_buffer, | |
1260 | lpm); | |
1261 | if (!rc) { | |
1262 | switch (dasd_eckd_path_access(data->rcd_buffer, | |
1263 | DASD_ECKD_RCD_DATA_SIZE) | |
1264 | ) { | |
1265 | case 0x02: | |
1266 | npm |= lpm; | |
1267 | break; | |
1268 | case 0x03: | |
1269 | ppm |= lpm; | |
1270 | break; | |
1271 | } | |
1272 | opm |= lpm; | |
1273 | } else if (rc == -EOPNOTSUPP) { | |
1274 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1275 | "path verification: No configuration " | |
1276 | "data retrieved"); | |
1277 | opm |= lpm; | |
1278 | } else if (rc == -EAGAIN) { | |
1279 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
a4d26c6a SW |
1280 | "path verification: device is stopped," |
1281 | " try again later"); | |
b206181d SH |
1282 | epm |= lpm; |
1283 | } else { | |
1284 | dev_warn(&device->cdev->dev, | |
1285 | "Reading device feature codes failed " | |
1286 | "(rc=%d) for new path %x\n", rc, lpm); | |
1287 | continue; | |
1288 | } | |
1289 | if (verify_fcx_max_data(device, lpm)) { | |
1290 | opm &= ~lpm; | |
1291 | npm &= ~lpm; | |
1292 | ppm &= ~lpm; | |
5db8440c | 1293 | hpfpm |= lpm; |
b206181d SH |
1294 | continue; |
1295 | } | |
1296 | ||
1297 | /* | |
1298 | * save conf_data for comparison after | |
1299 | * rebuild_device_uid may have changed | |
1300 | * the original data | |
1301 | */ | |
1302 | memcpy(&path_rcd_buf, data->rcd_buffer, | |
1303 | DASD_ECKD_RCD_DATA_SIZE); | |
1304 | path_private.conf_data = (void *) &path_rcd_buf; | |
1305 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; | |
1306 | if (dasd_eckd_identify_conf_parts(&path_private)) { | |
1307 | path_private.conf_data = NULL; | |
1308 | path_private.conf_len = 0; | |
1309 | continue; | |
1310 | } | |
1311 | ||
1312 | /* | |
1313 | * compare path UID with device UID only if at least | |
1314 | * one valid path is left | |
1315 | * in other case the device UID may have changed and | |
1316 | * the first working path UID will be used as device UID | |
1317 | */ | |
c9346151 | 1318 | if (dasd_path_get_opm(device) && |
b206181d SH |
1319 | dasd_eckd_compare_path_uid(device, &path_private)) { |
1320 | /* | |
1321 | * the comparison was not successful | |
1322 | * rebuild the device UID with at least one | |
1323 | * known path in case a z/VM hyperswap command | |
1324 | * has changed the device | |
1325 | * | |
1326 | * after this compare again | |
1327 | * | |
1328 | * if either the rebuild or the recompare fails | |
1329 | * the path can not be used | |
1330 | */ | |
1331 | if (rebuild_device_uid(device, data) || | |
1332 | dasd_eckd_compare_path_uid( | |
1333 | device, &path_private)) { | |
1334 | uid = &path_private.uid; | |
1335 | if (strlen(uid->vduit) > 0) | |
1336 | snprintf(print_uid, sizeof(print_uid), | |
1337 | "%s.%s.%04x.%02x.%s", | |
1338 | uid->vendor, uid->serial, | |
1339 | uid->ssid, uid->real_unit_addr, | |
1340 | uid->vduit); | |
1341 | else | |
1342 | snprintf(print_uid, sizeof(print_uid), | |
1343 | "%s.%s.%04x.%02x", | |
1344 | uid->vendor, uid->serial, | |
1345 | uid->ssid, | |
1346 | uid->real_unit_addr); | |
1347 | dev_err(&device->cdev->dev, | |
1348 | "The newly added channel path %02X " | |
1349 | "will not be used because it leads " | |
1350 | "to a different device %s\n", | |
1351 | lpm, print_uid); | |
a4d26c6a SW |
1352 | opm &= ~lpm; |
1353 | npm &= ~lpm; | |
1354 | ppm &= ~lpm; | |
5db8440c | 1355 | cablepm |= lpm; |
b206181d | 1356 | continue; |
a4d26c6a SW |
1357 | } |
1358 | } | |
b206181d SH |
1359 | |
1360 | /* | |
1361 | * There is a small chance that a path is lost again between | |
1362 | * above path verification and the following modification of | |
1363 | * the device opm mask. We could avoid that race here by using | |
1364 | * yet another path mask, but we rather deal with this unlikely | |
1365 | * situation in dasd_start_IO. | |
1366 | */ | |
1367 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
c9346151 SH |
1368 | if (!dasd_path_get_opm(device) && opm) { |
1369 | dasd_path_set_opm(device, opm); | |
b206181d | 1370 | dasd_generic_path_operational(device); |
5db8440c | 1371 | } else { |
c9346151 | 1372 | dasd_path_add_opm(device, opm); |
5db8440c | 1373 | } |
c9346151 SH |
1374 | dasd_path_add_nppm(device, npm); |
1375 | dasd_path_add_ppm(device, ppm); | |
1376 | dasd_path_add_tbvpm(device, epm); | |
1377 | dasd_path_add_cablepm(device, cablepm); | |
1378 | dasd_path_add_nohpfpm(device, hpfpm); | |
b206181d | 1379 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
a4d26c6a | 1380 | } |
1eb38023 | 1381 | clear_bit(DASD_FLAG_PATH_VERIFY, &device->flags); |
a4d26c6a SW |
1382 | dasd_put_device(device); |
1383 | if (data->isglobal) | |
1384 | mutex_unlock(&dasd_path_verification_mutex); | |
1385 | else | |
1386 | kfree(data); | |
1387 | } | |
1388 | ||
1389 | static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm) | |
1390 | { | |
1391 | struct path_verification_work_data *data; | |
1392 | ||
1393 | data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA); | |
1394 | if (!data) { | |
1395 | if (mutex_trylock(&dasd_path_verification_mutex)) { | |
1396 | data = path_verification_worker; | |
1397 | data->isglobal = 1; | |
1398 | } else | |
1399 | return -ENOMEM; | |
1400 | } else { | |
1401 | memset(data, 0, sizeof(*data)); | |
1402 | data->isglobal = 0; | |
1403 | } | |
1404 | INIT_WORK(&data->worker, do_path_verification_work); | |
1405 | dasd_get_device(device); | |
1406 | data->device = device; | |
1407 | data->tbvpm = lpm; | |
1408 | schedule_work(&data->worker); | |
1409 | return 0; | |
1410 | } | |
1411 | ||
a521b048 SH |
1412 | static void dasd_eckd_reset_path(struct dasd_device *device, __u8 pm) |
1413 | { | |
1414 | struct dasd_eckd_private *private = device->private; | |
1415 | unsigned long flags; | |
1416 | ||
1417 | if (!private->fcx_max_data) | |
1418 | private->fcx_max_data = get_fcx_max_data(device); | |
1419 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
1420 | dasd_path_set_tbvpm(device, pm ? : dasd_path_get_notoperpm(device)); | |
1421 | dasd_schedule_device_bh(device); | |
1422 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
1423 | } | |
1424 | ||
8e09f215 SW |
1425 | static int dasd_eckd_read_features(struct dasd_device *device) |
1426 | { | |
543691a4 | 1427 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
1428 | struct dasd_psf_prssd_data *prssdp; |
1429 | struct dasd_rssd_features *features; | |
1430 | struct dasd_ccw_req *cqr; | |
1431 | struct ccw1 *ccw; | |
1432 | int rc; | |
8e09f215 | 1433 | |
68d1e5f0 | 1434 | memset(&private->features, 0, sizeof(struct dasd_rssd_features)); |
68b781fe | 1435 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
8e09f215 SW |
1436 | (sizeof(struct dasd_psf_prssd_data) + |
1437 | sizeof(struct dasd_rssd_features)), | |
c5205f2f | 1438 | device, NULL); |
8e09f215 | 1439 | if (IS_ERR(cqr)) { |
b8ed5dd5 SH |
1440 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not " |
1441 | "allocate initialization request"); | |
8e09f215 SW |
1442 | return PTR_ERR(cqr); |
1443 | } | |
1444 | cqr->startdev = device; | |
1445 | cqr->memdev = device; | |
1446 | cqr->block = NULL; | |
eb6e199b | 1447 | cqr->retries = 256; |
8e09f215 SW |
1448 | cqr->expires = 10 * HZ; |
1449 | ||
1450 | /* Prepare for Read Subsystem Data */ | |
1451 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
1452 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); | |
1453 | prssdp->order = PSF_ORDER_PRSSD; | |
1454 | prssdp->suborder = 0x41; /* Read Feature Codes */ | |
1455 | /* all other bytes of prssdp must be zero */ | |
1456 | ||
1457 | ccw = cqr->cpaddr; | |
1458 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1459 | ccw->count = sizeof(struct dasd_psf_prssd_data); | |
1460 | ccw->flags |= CCW_FLAG_CC; | |
1461 | ccw->cda = (__u32)(addr_t) prssdp; | |
1462 | ||
1463 | /* Read Subsystem Data - feature codes */ | |
1464 | features = (struct dasd_rssd_features *) (prssdp + 1); | |
1465 | memset(features, 0, sizeof(struct dasd_rssd_features)); | |
1466 | ||
1467 | ccw++; | |
1468 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
1469 | ccw->count = sizeof(struct dasd_rssd_features); | |
1470 | ccw->cda = (__u32)(addr_t) features; | |
1471 | ||
1aae0560 | 1472 | cqr->buildclk = get_tod_clock(); |
8e09f215 SW |
1473 | cqr->status = DASD_CQR_FILLED; |
1474 | rc = dasd_sleep_on(cqr); | |
1475 | if (rc == 0) { | |
1476 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
1477 | features = (struct dasd_rssd_features *) (prssdp + 1); | |
1478 | memcpy(&private->features, features, | |
1479 | sizeof(struct dasd_rssd_features)); | |
68d1e5f0 SW |
1480 | } else |
1481 | dev_warn(&device->cdev->dev, "Reading device feature codes" | |
1482 | " failed with rc=%d\n", rc); | |
8e09f215 SW |
1483 | dasd_sfree_request(cqr, cqr->memdev); |
1484 | return rc; | |
1485 | } | |
1486 | ||
c729696b JH |
1487 | /* Read Volume Information - Volume Storage Query */ |
1488 | static int dasd_eckd_read_vol_info(struct dasd_device *device) | |
1489 | { | |
1490 | struct dasd_eckd_private *private = device->private; | |
1491 | struct dasd_psf_prssd_data *prssdp; | |
1492 | struct dasd_rssd_vsq *vsq; | |
1493 | struct dasd_ccw_req *cqr; | |
1494 | struct ccw1 *ccw; | |
9e12e54c | 1495 | int useglobal; |
c729696b JH |
1496 | int rc; |
1497 | ||
1498 | /* This command cannot be executed on an alias device */ | |
1499 | if (private->uid.type == UA_BASE_PAV_ALIAS || | |
1500 | private->uid.type == UA_HYPER_PAV_ALIAS) | |
1501 | return 0; | |
1502 | ||
9e12e54c | 1503 | useglobal = 0; |
c729696b JH |
1504 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 /* PSF + RSSD */, |
1505 | sizeof(*prssdp) + sizeof(*vsq), device, NULL); | |
1506 | if (IS_ERR(cqr)) { | |
1507 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1508 | "Could not allocate initialization request"); | |
9e12e54c JH |
1509 | mutex_lock(&dasd_vol_info_mutex); |
1510 | useglobal = 1; | |
1511 | cqr = &dasd_vol_info_req->cqr; | |
1512 | memset(cqr, 0, sizeof(*cqr)); | |
1513 | memset(dasd_vol_info_req, 0, sizeof(*dasd_vol_info_req)); | |
1514 | cqr->cpaddr = &dasd_vol_info_req->ccw; | |
1515 | cqr->data = &dasd_vol_info_req->data; | |
1516 | cqr->magic = DASD_ECKD_MAGIC; | |
c729696b JH |
1517 | } |
1518 | ||
1519 | /* Prepare for Read Subsystem Data */ | |
1520 | prssdp = cqr->data; | |
1521 | prssdp->order = PSF_ORDER_PRSSD; | |
1522 | prssdp->suborder = PSF_SUBORDER_VSQ; /* Volume Storage Query */ | |
1523 | prssdp->lss = private->ned->ID; | |
1524 | prssdp->volume = private->ned->unit_addr; | |
1525 | ||
1526 | ccw = cqr->cpaddr; | |
1527 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1528 | ccw->count = sizeof(*prssdp); | |
1529 | ccw->flags |= CCW_FLAG_CC; | |
1530 | ccw->cda = (__u32)(addr_t)prssdp; | |
1531 | ||
1532 | /* Read Subsystem Data - Volume Storage Query */ | |
1533 | vsq = (struct dasd_rssd_vsq *)(prssdp + 1); | |
1534 | memset(vsq, 0, sizeof(*vsq)); | |
1535 | ||
1536 | ccw++; | |
1537 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
1538 | ccw->count = sizeof(*vsq); | |
1539 | ccw->flags |= CCW_FLAG_SLI; | |
1540 | ccw->cda = (__u32)(addr_t)vsq; | |
1541 | ||
1542 | cqr->buildclk = get_tod_clock(); | |
1543 | cqr->status = DASD_CQR_FILLED; | |
1544 | cqr->startdev = device; | |
1545 | cqr->memdev = device; | |
1546 | cqr->block = NULL; | |
1547 | cqr->retries = 256; | |
1548 | cqr->expires = device->default_expires * HZ; | |
1549 | /* The command might not be supported. Suppress the error output */ | |
1550 | __set_bit(DASD_CQR_SUPPRESS_CR, &cqr->flags); | |
1551 | ||
1552 | rc = dasd_sleep_on_interruptible(cqr); | |
1553 | if (rc == 0) { | |
1554 | memcpy(&private->vsq, vsq, sizeof(*vsq)); | |
1555 | } else { | |
dd454839 JH |
1556 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
1557 | "Reading the volume storage information failed with rc=%d", rc); | |
c729696b JH |
1558 | } |
1559 | ||
9e12e54c JH |
1560 | if (useglobal) |
1561 | mutex_unlock(&dasd_vol_info_mutex); | |
1562 | else | |
1563 | dasd_sfree_request(cqr, cqr->memdev); | |
c729696b JH |
1564 | |
1565 | return rc; | |
1566 | } | |
1567 | ||
1568 | static int dasd_eckd_is_ese(struct dasd_device *device) | |
1569 | { | |
1570 | struct dasd_eckd_private *private = device->private; | |
1571 | ||
1572 | return private->vsq.vol_info.ese; | |
1573 | } | |
1574 | ||
1575 | static int dasd_eckd_ext_pool_id(struct dasd_device *device) | |
1576 | { | |
1577 | struct dasd_eckd_private *private = device->private; | |
1578 | ||
1579 | return private->vsq.extent_pool_id; | |
1580 | } | |
1581 | ||
1582 | /* | |
1583 | * This value represents the total amount of available space. As more space is | |
1584 | * allocated by ESE volumes, this value will decrease. | |
1585 | * The data for this value is therefore updated on any call. | |
1586 | */ | |
1587 | static int dasd_eckd_space_configured(struct dasd_device *device) | |
1588 | { | |
1589 | struct dasd_eckd_private *private = device->private; | |
1590 | int rc; | |
1591 | ||
1592 | rc = dasd_eckd_read_vol_info(device); | |
1593 | ||
1594 | return rc ? : private->vsq.space_configured; | |
1595 | } | |
1596 | ||
1597 | /* | |
1598 | * The value of space allocated by an ESE volume may have changed and is | |
1599 | * therefore updated on any call. | |
1600 | */ | |
1601 | static int dasd_eckd_space_allocated(struct dasd_device *device) | |
1602 | { | |
1603 | struct dasd_eckd_private *private = device->private; | |
1604 | int rc; | |
1605 | ||
1606 | rc = dasd_eckd_read_vol_info(device); | |
1607 | ||
1608 | return rc ? : private->vsq.space_allocated; | |
1609 | } | |
1610 | ||
1611 | static int dasd_eckd_logical_capacity(struct dasd_device *device) | |
1612 | { | |
1613 | struct dasd_eckd_private *private = device->private; | |
1614 | ||
1615 | return private->vsq.logical_capacity; | |
1616 | } | |
1617 | ||
9e12e54c JH |
1618 | static void dasd_eckd_ext_pool_exhaust_work(struct work_struct *work) |
1619 | { | |
1620 | struct ext_pool_exhaust_work_data *data; | |
1621 | struct dasd_device *device; | |
1622 | struct dasd_device *base; | |
1623 | ||
1624 | data = container_of(work, struct ext_pool_exhaust_work_data, worker); | |
1625 | device = data->device; | |
1626 | base = data->base; | |
1627 | ||
1628 | if (!base) | |
1629 | base = device; | |
1630 | if (dasd_eckd_space_configured(base) != 0) { | |
1631 | dasd_generic_space_avail(device); | |
1632 | } else { | |
1633 | dev_warn(&device->cdev->dev, "No space left in the extent pool\n"); | |
1634 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "out of space"); | |
1635 | } | |
1636 | ||
1637 | dasd_put_device(device); | |
1638 | kfree(data); | |
1639 | } | |
1640 | ||
1641 | static int dasd_eckd_ext_pool_exhaust(struct dasd_device *device, | |
1642 | struct dasd_ccw_req *cqr) | |
1643 | { | |
1644 | struct ext_pool_exhaust_work_data *data; | |
1645 | ||
1646 | data = kzalloc(sizeof(*data), GFP_ATOMIC); | |
1647 | if (!data) | |
1648 | return -ENOMEM; | |
1649 | INIT_WORK(&data->worker, dasd_eckd_ext_pool_exhaust_work); | |
1650 | dasd_get_device(device); | |
1651 | data->device = device; | |
1652 | ||
1653 | if (cqr->block) | |
1654 | data->base = cqr->block->base; | |
1655 | else if (cqr->basedev) | |
1656 | data->base = cqr->basedev; | |
1657 | else | |
1658 | data->base = NULL; | |
1659 | ||
1660 | schedule_work(&data->worker); | |
1661 | ||
1662 | return 0; | |
1663 | } | |
1664 | ||
c729696b JH |
1665 | static void dasd_eckd_cpy_ext_pool_data(struct dasd_device *device, |
1666 | struct dasd_rssd_lcq *lcq) | |
1667 | { | |
1668 | struct dasd_eckd_private *private = device->private; | |
1669 | int pool_id = dasd_eckd_ext_pool_id(device); | |
1670 | struct dasd_ext_pool_sum eps; | |
1671 | int i; | |
1672 | ||
1673 | for (i = 0; i < lcq->pool_count; i++) { | |
1674 | eps = lcq->ext_pool_sum[i]; | |
1675 | if (eps.pool_id == pool_id) { | |
1676 | memcpy(&private->eps, &eps, | |
1677 | sizeof(struct dasd_ext_pool_sum)); | |
1678 | } | |
1679 | } | |
1680 | } | |
1681 | ||
1682 | /* Read Extent Pool Information - Logical Configuration Query */ | |
1683 | static int dasd_eckd_read_ext_pool_info(struct dasd_device *device) | |
1684 | { | |
1685 | struct dasd_eckd_private *private = device->private; | |
1686 | struct dasd_psf_prssd_data *prssdp; | |
1687 | struct dasd_rssd_lcq *lcq; | |
1688 | struct dasd_ccw_req *cqr; | |
1689 | struct ccw1 *ccw; | |
1690 | int rc; | |
1691 | ||
1692 | /* This command cannot be executed on an alias device */ | |
1693 | if (private->uid.type == UA_BASE_PAV_ALIAS || | |
1694 | private->uid.type == UA_HYPER_PAV_ALIAS) | |
1695 | return 0; | |
1696 | ||
1697 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 /* PSF + RSSD */, | |
1698 | sizeof(*prssdp) + sizeof(*lcq), device, NULL); | |
1699 | if (IS_ERR(cqr)) { | |
1700 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1701 | "Could not allocate initialization request"); | |
1702 | return PTR_ERR(cqr); | |
1703 | } | |
1704 | ||
1705 | /* Prepare for Read Subsystem Data */ | |
1706 | prssdp = cqr->data; | |
1707 | memset(prssdp, 0, sizeof(*prssdp)); | |
1708 | prssdp->order = PSF_ORDER_PRSSD; | |
1709 | prssdp->suborder = PSF_SUBORDER_LCQ; /* Logical Configuration Query */ | |
1710 | ||
1711 | ccw = cqr->cpaddr; | |
1712 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1713 | ccw->count = sizeof(*prssdp); | |
1714 | ccw->flags |= CCW_FLAG_CC; | |
1715 | ccw->cda = (__u32)(addr_t)prssdp; | |
1716 | ||
1717 | lcq = (struct dasd_rssd_lcq *)(prssdp + 1); | |
1718 | memset(lcq, 0, sizeof(*lcq)); | |
1719 | ||
1720 | ccw++; | |
1721 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
1722 | ccw->count = sizeof(*lcq); | |
1723 | ccw->flags |= CCW_FLAG_SLI; | |
1724 | ccw->cda = (__u32)(addr_t)lcq; | |
1725 | ||
1726 | cqr->buildclk = get_tod_clock(); | |
1727 | cqr->status = DASD_CQR_FILLED; | |
1728 | cqr->startdev = device; | |
1729 | cqr->memdev = device; | |
1730 | cqr->block = NULL; | |
1731 | cqr->retries = 256; | |
1732 | cqr->expires = device->default_expires * HZ; | |
1733 | /* The command might not be supported. Suppress the error output */ | |
1734 | __set_bit(DASD_CQR_SUPPRESS_CR, &cqr->flags); | |
1735 | ||
1736 | rc = dasd_sleep_on_interruptible(cqr); | |
1737 | if (rc == 0) { | |
1738 | dasd_eckd_cpy_ext_pool_data(device, lcq); | |
1739 | } else { | |
dd454839 JH |
1740 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
1741 | "Reading the logical configuration failed with rc=%d", rc); | |
c729696b JH |
1742 | } |
1743 | ||
1744 | dasd_sfree_request(cqr, cqr->memdev); | |
1745 | ||
1746 | return rc; | |
1747 | } | |
1748 | ||
1749 | /* | |
1750 | * Depending on the device type, the extent size is specified either as | |
1751 | * cylinders per extent (CKD) or size per extent (FBA) | |
1752 | * A 1GB size corresponds to 1113cyl, and 16MB to 21cyl. | |
1753 | */ | |
1754 | static int dasd_eckd_ext_size(struct dasd_device *device) | |
1755 | { | |
1756 | struct dasd_eckd_private *private = device->private; | |
1757 | struct dasd_ext_pool_sum eps = private->eps; | |
1758 | ||
1759 | if (!eps.flags.extent_size_valid) | |
1760 | return 0; | |
1761 | if (eps.extent_size.size_1G) | |
1762 | return 1113; | |
1763 | if (eps.extent_size.size_16M) | |
1764 | return 21; | |
1765 | ||
1766 | return 0; | |
1767 | } | |
1768 | ||
1769 | static int dasd_eckd_ext_pool_warn_thrshld(struct dasd_device *device) | |
1770 | { | |
1771 | struct dasd_eckd_private *private = device->private; | |
1772 | ||
1773 | return private->eps.warn_thrshld; | |
1774 | } | |
1775 | ||
1776 | static int dasd_eckd_ext_pool_cap_at_warnlevel(struct dasd_device *device) | |
1777 | { | |
1778 | struct dasd_eckd_private *private = device->private; | |
1779 | ||
1780 | return private->eps.flags.capacity_at_warnlevel; | |
1781 | } | |
1782 | ||
1783 | /* | |
1784 | * Extent Pool out of space | |
1785 | */ | |
1786 | static int dasd_eckd_ext_pool_oos(struct dasd_device *device) | |
1787 | { | |
1788 | struct dasd_eckd_private *private = device->private; | |
1789 | ||
1790 | return private->eps.flags.pool_oos; | |
1791 | } | |
8e09f215 | 1792 | |
40545573 HH |
1793 | /* |
1794 | * Build CP for Perform Subsystem Function - SSC. | |
1795 | */ | |
f3eb5384 SW |
1796 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, |
1797 | int enable_pav) | |
40545573 | 1798 | { |
8e09f215 SW |
1799 | struct dasd_ccw_req *cqr; |
1800 | struct dasd_psf_ssc_data *psf_ssc_data; | |
1801 | struct ccw1 *ccw; | |
40545573 | 1802 | |
68b781fe | 1803 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , |
40545573 | 1804 | sizeof(struct dasd_psf_ssc_data), |
c5205f2f | 1805 | device, NULL); |
40545573 | 1806 | |
8e09f215 | 1807 | if (IS_ERR(cqr)) { |
fc19f381 | 1808 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
40545573 | 1809 | "Could not allocate PSF-SSC request"); |
8e09f215 SW |
1810 | return cqr; |
1811 | } | |
1812 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; | |
1813 | psf_ssc_data->order = PSF_ORDER_SSC; | |
626350b6 | 1814 | psf_ssc_data->suborder = 0xc0; |
f3eb5384 | 1815 | if (enable_pav) { |
626350b6 | 1816 | psf_ssc_data->suborder |= 0x08; |
f3eb5384 SW |
1817 | psf_ssc_data->reserved[0] = 0x88; |
1818 | } | |
8e09f215 SW |
1819 | ccw = cqr->cpaddr; |
1820 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1821 | ccw->cda = (__u32)(addr_t)psf_ssc_data; | |
1822 | ccw->count = 66; | |
1823 | ||
1824 | cqr->startdev = device; | |
1825 | cqr->memdev = device; | |
1826 | cqr->block = NULL; | |
eb6e199b | 1827 | cqr->retries = 256; |
8e09f215 | 1828 | cqr->expires = 10*HZ; |
1aae0560 | 1829 | cqr->buildclk = get_tod_clock(); |
8e09f215 SW |
1830 | cqr->status = DASD_CQR_FILLED; |
1831 | return cqr; | |
40545573 HH |
1832 | } |
1833 | ||
1834 | /* | |
1835 | * Perform Subsystem Function. | |
1836 | * It is necessary to trigger CIO for channel revalidation since this | |
1837 | * call might change behaviour of DASD devices. | |
1838 | */ | |
1839 | static int | |
12d7b107 SH |
1840 | dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav, |
1841 | unsigned long flags) | |
40545573 | 1842 | { |
8e09f215 SW |
1843 | struct dasd_ccw_req *cqr; |
1844 | int rc; | |
1845 | ||
f3eb5384 | 1846 | cqr = dasd_eckd_build_psf_ssc(device, enable_pav); |
8e09f215 SW |
1847 | if (IS_ERR(cqr)) |
1848 | return PTR_ERR(cqr); | |
1849 | ||
12d7b107 SH |
1850 | /* |
1851 | * set flags e.g. turn on failfast, to prevent blocking | |
1852 | * the calling function should handle failed requests | |
1853 | */ | |
1854 | cqr->flags |= flags; | |
1855 | ||
8e09f215 SW |
1856 | rc = dasd_sleep_on(cqr); |
1857 | if (!rc) | |
1858 | /* trigger CIO to reprobe devices */ | |
1859 | css_schedule_reprobe(); | |
12d7b107 SH |
1860 | else if (cqr->intrc == -EAGAIN) |
1861 | rc = -EAGAIN; | |
1862 | ||
8e09f215 SW |
1863 | dasd_sfree_request(cqr, cqr->memdev); |
1864 | return rc; | |
40545573 HH |
1865 | } |
1866 | ||
1867 | /* | |
1868 | * Valide storage server of current device. | |
1869 | */ | |
12d7b107 SH |
1870 | static int dasd_eckd_validate_server(struct dasd_device *device, |
1871 | unsigned long flags) | |
40545573 | 1872 | { |
543691a4 SO |
1873 | struct dasd_eckd_private *private = device->private; |
1874 | int enable_pav, rc; | |
40545573 | 1875 | |
f9f8d02f SH |
1876 | if (private->uid.type == UA_BASE_PAV_ALIAS || |
1877 | private->uid.type == UA_HYPER_PAV_ALIAS) | |
12d7b107 | 1878 | return 0; |
40545573 | 1879 | if (dasd_nopav || MACHINE_IS_VM) |
f3eb5384 SW |
1880 | enable_pav = 0; |
1881 | else | |
1882 | enable_pav = 1; | |
12d7b107 | 1883 | rc = dasd_eckd_psf_ssc(device, enable_pav, flags); |
eb6e199b | 1884 | |
8e79a441 HH |
1885 | /* may be requested feature is not available on server, |
1886 | * therefore just report error and go ahead */ | |
b8ed5dd5 SH |
1887 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x " |
1888 | "returned rc=%d", private->uid.ssid, rc); | |
12d7b107 | 1889 | return rc; |
40545573 HH |
1890 | } |
1891 | ||
f1633031 SH |
1892 | /* |
1893 | * worker to do a validate server in case of a lost pathgroup | |
1894 | */ | |
1895 | static void dasd_eckd_do_validate_server(struct work_struct *work) | |
1896 | { | |
1897 | struct dasd_device *device = container_of(work, struct dasd_device, | |
1898 | kick_validate); | |
ea4da6ea SH |
1899 | unsigned long flags = 0; |
1900 | ||
1901 | set_bit(DASD_CQR_FLAGS_FAILFAST, &flags); | |
1902 | if (dasd_eckd_validate_server(device, flags) | |
12d7b107 SH |
1903 | == -EAGAIN) { |
1904 | /* schedule worker again if failed */ | |
1905 | schedule_work(&device->kick_validate); | |
1906 | return; | |
1907 | } | |
1908 | ||
f1633031 SH |
1909 | dasd_put_device(device); |
1910 | } | |
1911 | ||
1912 | static void dasd_eckd_kick_validate_server(struct dasd_device *device) | |
1913 | { | |
1914 | dasd_get_device(device); | |
25e2cf1c SH |
1915 | /* exit if device not online or in offline processing */ |
1916 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || | |
1917 | device->state < DASD_STATE_ONLINE) { | |
1918 | dasd_put_device(device); | |
1919 | return; | |
1920 | } | |
f1633031 | 1921 | /* queue call to do_validate_server to the kernel event daemon. */ |
f2608cd4 SH |
1922 | if (!schedule_work(&device->kick_validate)) |
1923 | dasd_put_device(device); | |
f1633031 SH |
1924 | } |
1925 | ||
3d052595 HH |
1926 | /* |
1927 | * Check device characteristics. | |
1928 | * If the device is accessible using ECKD discipline, the device is enabled. | |
1929 | */ | |
1da177e4 LT |
1930 | static int |
1931 | dasd_eckd_check_characteristics(struct dasd_device *device) | |
1932 | { | |
543691a4 | 1933 | struct dasd_eckd_private *private = device->private; |
8e09f215 | 1934 | struct dasd_block *block; |
2dedf0d9 | 1935 | struct dasd_uid temp_uid; |
f9f8d02f | 1936 | int rc, i; |
33b62a30 | 1937 | int readonly; |
7c8faa86 | 1938 | unsigned long value; |
1da177e4 | 1939 | |
f1633031 SH |
1940 | /* setup work queue for validate server*/ |
1941 | INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server); | |
59a9ed5f SH |
1942 | /* setup work queue for summary unit check */ |
1943 | INIT_WORK(&device->suc_work, dasd_alias_handle_summary_unit_check); | |
f1633031 | 1944 | |
454e1fa1 PO |
1945 | if (!ccw_device_is_pathgroup(device->cdev)) { |
1946 | dev_warn(&device->cdev->dev, | |
1947 | "A channel path group could not be established\n"); | |
1948 | return -EIO; | |
1949 | } | |
1950 | if (!ccw_device_is_multipath(device->cdev)) { | |
1951 | dev_info(&device->cdev->dev, | |
1952 | "The DASD is not operating in multipath mode\n"); | |
1953 | } | |
92636b15 SO |
1954 | if (!private) { |
1955 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); | |
1956 | if (!private) { | |
fc19f381 SH |
1957 | dev_warn(&device->cdev->dev, |
1958 | "Allocating memory for private DASD data " | |
1959 | "failed\n"); | |
1da177e4 LT |
1960 | return -ENOMEM; |
1961 | } | |
543691a4 | 1962 | device->private = private; |
92636b15 SO |
1963 | } else { |
1964 | memset(private, 0, sizeof(*private)); | |
1da177e4 LT |
1965 | } |
1966 | /* Invalidate status of initial analysis. */ | |
1967 | private->init_cqr_status = -1; | |
1968 | /* Set default cache operations. */ | |
1969 | private->attrib.operation = DASD_NORMAL_CACHE; | |
1970 | private->attrib.nr_cyl = 0; | |
1971 | ||
40545573 HH |
1972 | /* Read Configuration Data */ |
1973 | rc = dasd_eckd_read_conf(device); | |
1974 | if (rc) | |
8e09f215 | 1975 | goto out_err1; |
40545573 | 1976 | |
a521b048 | 1977 | /* set some default values */ |
7c8faa86 | 1978 | device->default_expires = DASD_EXPIRES; |
1f1ee9ad | 1979 | device->default_retries = DASD_RETRIES; |
a521b048 SH |
1980 | device->path_thrhld = DASD_ECKD_PATH_THRHLD; |
1981 | device->path_interval = DASD_ECKD_PATH_INTERVAL; | |
1f1ee9ad | 1982 | |
7c8faa86 SH |
1983 | if (private->gneq) { |
1984 | value = 1; | |
1985 | for (i = 0; i < private->gneq->timeout.value; i++) | |
1986 | value = 10 * value; | |
1987 | value = value * private->gneq->timeout.number; | |
1988 | /* do not accept useless values */ | |
1989 | if (value != 0 && value <= DASD_EXPIRES_MAX) | |
1990 | device->default_expires = value; | |
1991 | } | |
1992 | ||
2dedf0d9 SH |
1993 | dasd_eckd_get_uid(device, &temp_uid); |
1994 | if (temp_uid.type == UA_BASE_DEVICE) { | |
8e09f215 SW |
1995 | block = dasd_alloc_block(); |
1996 | if (IS_ERR(block)) { | |
b8ed5dd5 SH |
1997 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
1998 | "could not allocate dasd " | |
1999 | "block structure"); | |
8e09f215 SW |
2000 | rc = PTR_ERR(block); |
2001 | goto out_err1; | |
2002 | } | |
2003 | device->block = block; | |
2004 | block->base = device; | |
2005 | } | |
2006 | ||
f9f8d02f SH |
2007 | /* register lcu with alias handling, enable PAV */ |
2008 | rc = dasd_alias_make_device_known_to_lcu(device); | |
2009 | if (rc) | |
8e09f215 | 2010 | goto out_err2; |
f9f8d02f | 2011 | |
12d7b107 | 2012 | dasd_eckd_validate_server(device, 0); |
f4ac1d02 SW |
2013 | |
2014 | /* device may report different configuration data after LCU setup */ | |
2015 | rc = dasd_eckd_read_conf(device); | |
2016 | if (rc) | |
2017 | goto out_err3; | |
8e09f215 SW |
2018 | |
2019 | /* Read Feature Codes */ | |
68d1e5f0 | 2020 | dasd_eckd_read_features(device); |
40545573 | 2021 | |
c729696b | 2022 | /* Read Volume Information */ |
dd454839 | 2023 | dasd_eckd_read_vol_info(device); |
c729696b JH |
2024 | |
2025 | /* Read Extent Pool Information */ | |
dd454839 | 2026 | dasd_eckd_read_ext_pool_info(device); |
c729696b | 2027 | |
1da177e4 | 2028 | /* Read Device Characteristics */ |
68b781fe SH |
2029 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
2030 | &private->rdc_data, 64); | |
8e09f215 | 2031 | if (rc) { |
b8ed5dd5 SH |
2032 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
2033 | "Read device characteristic failed, rc=%d", rc); | |
8e09f215 SW |
2034 | goto out_err3; |
2035 | } | |
34cd551a SH |
2036 | |
2037 | if ((device->features & DASD_FEATURE_USERAW) && | |
2038 | !(private->rdc_data.facilities.RT_in_LR)) { | |
2039 | dev_err(&device->cdev->dev, "The storage server does not " | |
2040 | "support raw-track access\n"); | |
2041 | rc = -EINVAL; | |
2042 | goto out_err3; | |
2043 | } | |
2044 | ||
817f2c84 | 2045 | /* find the valid cylinder size */ |
b44b0ab3 SW |
2046 | if (private->rdc_data.no_cyl == LV_COMPAT_CYL && |
2047 | private->rdc_data.long_no_cyl) | |
2048 | private->real_cyl = private->rdc_data.long_no_cyl; | |
2049 | else | |
2050 | private->real_cyl = private->rdc_data.no_cyl; | |
2051 | ||
ef19298b SW |
2052 | private->fcx_max_data = get_fcx_max_data(device); |
2053 | ||
33b62a30 SW |
2054 | readonly = dasd_device_is_ro(device); |
2055 | if (readonly) | |
2056 | set_bit(DASD_FLAG_DEVICE_RO, &device->flags); | |
2057 | ||
fc19f381 | 2058 | dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " |
33b62a30 | 2059 | "with %d cylinders, %d heads, %d sectors%s\n", |
fc19f381 SH |
2060 | private->rdc_data.dev_type, |
2061 | private->rdc_data.dev_model, | |
2062 | private->rdc_data.cu_type, | |
2063 | private->rdc_data.cu_model.model, | |
92636b15 | 2064 | private->real_cyl, |
fc19f381 | 2065 | private->rdc_data.trk_per_cyl, |
33b62a30 SW |
2066 | private->rdc_data.sec_per_trk, |
2067 | readonly ? ", read-only device" : ""); | |
8e09f215 SW |
2068 | return 0; |
2069 | ||
2070 | out_err3: | |
2071 | dasd_alias_disconnect_device_from_lcu(device); | |
2072 | out_err2: | |
2073 | dasd_free_block(device->block); | |
2074 | device->block = NULL; | |
2075 | out_err1: | |
4abb08c2 | 2076 | kfree(private->conf_data); |
8e09f215 SW |
2077 | kfree(device->private); |
2078 | device->private = NULL; | |
3d052595 | 2079 | return rc; |
1da177e4 LT |
2080 | } |
2081 | ||
8e09f215 SW |
2082 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
2083 | { | |
543691a4 | 2084 | struct dasd_eckd_private *private = device->private; |
b179b037 | 2085 | int i; |
4abb08c2 | 2086 | |
7c6553d4 SH |
2087 | if (!private) |
2088 | return; | |
2089 | ||
8e09f215 | 2090 | dasd_alias_disconnect_device_from_lcu(device); |
4abb08c2 SW |
2091 | private->ned = NULL; |
2092 | private->sneq = NULL; | |
2093 | private->vdsneq = NULL; | |
2094 | private->gneq = NULL; | |
2095 | private->conf_len = 0; | |
b179b037 | 2096 | for (i = 0; i < 8; i++) { |
c9346151 SH |
2097 | kfree(device->path[i].conf_data); |
2098 | if ((__u8 *)device->path[i].conf_data == | |
b179b037 SH |
2099 | private->conf_data) { |
2100 | private->conf_data = NULL; | |
2101 | private->conf_len = 0; | |
2102 | } | |
c9346151 | 2103 | device->path[i].conf_data = NULL; |
a521b048 SH |
2104 | device->path[i].cssid = 0; |
2105 | device->path[i].ssid = 0; | |
2106 | device->path[i].chpid = 0; | |
b179b037 | 2107 | } |
4abb08c2 SW |
2108 | kfree(private->conf_data); |
2109 | private->conf_data = NULL; | |
8e09f215 SW |
2110 | } |
2111 | ||
1da177e4 LT |
2112 | static struct dasd_ccw_req * |
2113 | dasd_eckd_analysis_ccw(struct dasd_device *device) | |
2114 | { | |
543691a4 | 2115 | struct dasd_eckd_private *private = device->private; |
1da177e4 LT |
2116 | struct eckd_count *count_data; |
2117 | struct LO_eckd_data *LO_data; | |
2118 | struct dasd_ccw_req *cqr; | |
2119 | struct ccw1 *ccw; | |
2120 | int cplength, datasize; | |
2121 | int i; | |
2122 | ||
1da177e4 LT |
2123 | cplength = 8; |
2124 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); | |
c5205f2f SO |
2125 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device, |
2126 | NULL); | |
1da177e4 LT |
2127 | if (IS_ERR(cqr)) |
2128 | return cqr; | |
2129 | ccw = cqr->cpaddr; | |
ce6915f5 JH |
2130 | /* Define extent for the first 2 tracks. */ |
2131 | define_extent(ccw++, cqr->data, 0, 1, | |
45f186be | 2132 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
8e09f215 | 2133 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
1da177e4 LT |
2134 | /* Locate record for the first 4 records on track 0. */ |
2135 | ccw[-1].flags |= CCW_FLAG_CC; | |
2136 | locate_record(ccw++, LO_data++, 0, 0, 4, | |
2137 | DASD_ECKD_CCW_READ_COUNT, device, 0); | |
2138 | ||
2139 | count_data = private->count_area; | |
2140 | for (i = 0; i < 4; i++) { | |
2141 | ccw[-1].flags |= CCW_FLAG_CC; | |
2142 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; | |
2143 | ccw->flags = 0; | |
2144 | ccw->count = 8; | |
2145 | ccw->cda = (__u32)(addr_t) count_data; | |
2146 | ccw++; | |
2147 | count_data++; | |
2148 | } | |
2149 | ||
ce6915f5 | 2150 | /* Locate record for the first record on track 1. */ |
1da177e4 | 2151 | ccw[-1].flags |= CCW_FLAG_CC; |
ce6915f5 | 2152 | locate_record(ccw++, LO_data++, 1, 0, 1, |
1da177e4 LT |
2153 | DASD_ECKD_CCW_READ_COUNT, device, 0); |
2154 | /* Read count ccw. */ | |
2155 | ccw[-1].flags |= CCW_FLAG_CC; | |
2156 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; | |
2157 | ccw->flags = 0; | |
2158 | ccw->count = 8; | |
2159 | ccw->cda = (__u32)(addr_t) count_data; | |
2160 | ||
8e09f215 SW |
2161 | cqr->block = NULL; |
2162 | cqr->startdev = device; | |
2163 | cqr->memdev = device; | |
eb6e199b | 2164 | cqr->retries = 255; |
1aae0560 | 2165 | cqr->buildclk = get_tod_clock(); |
1da177e4 | 2166 | cqr->status = DASD_CQR_FILLED; |
9e12e54c JH |
2167 | /* Set flags to suppress output for expected errors */ |
2168 | set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); | |
2169 | ||
1da177e4 LT |
2170 | return cqr; |
2171 | } | |
2172 | ||
eb6e199b SW |
2173 | /* differentiate between 'no record found' and any other error */ |
2174 | static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr) | |
2175 | { | |
2176 | char *sense; | |
2177 | if (init_cqr->status == DASD_CQR_DONE) | |
2178 | return INIT_CQR_OK; | |
2179 | else if (init_cqr->status == DASD_CQR_NEED_ERP || | |
2180 | init_cqr->status == DASD_CQR_FAILED) { | |
2181 | sense = dasd_get_sense(&init_cqr->irb); | |
2182 | if (sense && (sense[1] & SNS1_NO_REC_FOUND)) | |
2183 | return INIT_CQR_UNFORMATTED; | |
2184 | else | |
2185 | return INIT_CQR_ERROR; | |
2186 | } else | |
2187 | return INIT_CQR_ERROR; | |
2188 | } | |
2189 | ||
1da177e4 LT |
2190 | /* |
2191 | * This is the callback function for the init_analysis cqr. It saves | |
2192 | * the status of the initial analysis ccw before it frees it and kicks | |
2193 | * the device to continue the startup sequence. This will call | |
2194 | * dasd_eckd_do_analysis again (if the devices has not been marked | |
2195 | * for deletion in the meantime). | |
2196 | */ | |
eb6e199b SW |
2197 | static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, |
2198 | void *data) | |
1da177e4 | 2199 | { |
543691a4 SO |
2200 | struct dasd_device *device = init_cqr->startdev; |
2201 | struct dasd_eckd_private *private = device->private; | |
1da177e4 | 2202 | |
eb6e199b | 2203 | private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr); |
1da177e4 LT |
2204 | dasd_sfree_request(init_cqr, device); |
2205 | dasd_kick_device(device); | |
2206 | } | |
2207 | ||
eb6e199b | 2208 | static int dasd_eckd_start_analysis(struct dasd_block *block) |
1da177e4 | 2209 | { |
1da177e4 LT |
2210 | struct dasd_ccw_req *init_cqr; |
2211 | ||
8e09f215 | 2212 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
1da177e4 LT |
2213 | if (IS_ERR(init_cqr)) |
2214 | return PTR_ERR(init_cqr); | |
2215 | init_cqr->callback = dasd_eckd_analysis_callback; | |
2216 | init_cqr->callback_data = NULL; | |
2217 | init_cqr->expires = 5*HZ; | |
eb6e199b SW |
2218 | /* first try without ERP, so we can later handle unformatted |
2219 | * devices as special case | |
2220 | */ | |
2221 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags); | |
2222 | init_cqr->retries = 0; | |
1da177e4 LT |
2223 | dasd_add_request_head(init_cqr); |
2224 | return -EAGAIN; | |
2225 | } | |
2226 | ||
eb6e199b | 2227 | static int dasd_eckd_end_analysis(struct dasd_block *block) |
1da177e4 | 2228 | { |
543691a4 SO |
2229 | struct dasd_device *device = block->base; |
2230 | struct dasd_eckd_private *private = device->private; | |
1da177e4 LT |
2231 | struct eckd_count *count_area; |
2232 | unsigned int sb, blk_per_trk; | |
2233 | int status, i; | |
eb6e199b | 2234 | struct dasd_ccw_req *init_cqr; |
1da177e4 | 2235 | |
1da177e4 LT |
2236 | status = private->init_cqr_status; |
2237 | private->init_cqr_status = -1; | |
eb6e199b SW |
2238 | if (status == INIT_CQR_ERROR) { |
2239 | /* try again, this time with full ERP */ | |
2240 | init_cqr = dasd_eckd_analysis_ccw(device); | |
2241 | dasd_sleep_on(init_cqr); | |
2242 | status = dasd_eckd_analysis_evaluation(init_cqr); | |
2243 | dasd_sfree_request(init_cqr, device); | |
2244 | } | |
2245 | ||
e4dbb0f2 SH |
2246 | if (device->features & DASD_FEATURE_USERAW) { |
2247 | block->bp_block = DASD_RAW_BLOCKSIZE; | |
2248 | blk_per_trk = DASD_RAW_BLOCK_PER_TRACK; | |
2249 | block->s2b_shift = 3; | |
2250 | goto raw; | |
2251 | } | |
2252 | ||
eb6e199b SW |
2253 | if (status == INIT_CQR_UNFORMATTED) { |
2254 | dev_warn(&device->cdev->dev, "The DASD is not formatted\n"); | |
1da177e4 | 2255 | return -EMEDIUMTYPE; |
eb6e199b SW |
2256 | } else if (status == INIT_CQR_ERROR) { |
2257 | dev_err(&device->cdev->dev, | |
2258 | "Detecting the DASD disk layout failed because " | |
2259 | "of an I/O error\n"); | |
2260 | return -EIO; | |
1da177e4 LT |
2261 | } |
2262 | ||
2263 | private->uses_cdl = 1; | |
1da177e4 LT |
2264 | /* Check Track 0 for Compatible Disk Layout */ |
2265 | count_area = NULL; | |
2266 | for (i = 0; i < 3; i++) { | |
2267 | if (private->count_area[i].kl != 4 || | |
3bc9fef9 SH |
2268 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 || |
2269 | private->count_area[i].cyl != 0 || | |
2270 | private->count_area[i].head != count_area_head[i] || | |
2271 | private->count_area[i].record != count_area_rec[i]) { | |
1da177e4 LT |
2272 | private->uses_cdl = 0; |
2273 | break; | |
2274 | } | |
2275 | } | |
2276 | if (i == 3) | |
ce6915f5 | 2277 | count_area = &private->count_area[3]; |
1da177e4 LT |
2278 | |
2279 | if (private->uses_cdl == 0) { | |
2280 | for (i = 0; i < 5; i++) { | |
2281 | if ((private->count_area[i].kl != 0) || | |
2282 | (private->count_area[i].dl != | |
3bc9fef9 SH |
2283 | private->count_area[0].dl) || |
2284 | private->count_area[i].cyl != 0 || | |
2285 | private->count_area[i].head != count_area_head[i] || | |
2286 | private->count_area[i].record != count_area_rec[i]) | |
1da177e4 LT |
2287 | break; |
2288 | } | |
2289 | if (i == 5) | |
2290 | count_area = &private->count_area[0]; | |
2291 | } else { | |
2292 | if (private->count_area[3].record == 1) | |
fc19f381 SH |
2293 | dev_warn(&device->cdev->dev, |
2294 | "Track 0 has no records following the VTOC\n"); | |
1da177e4 | 2295 | } |
e4dbb0f2 | 2296 | |
1da177e4 LT |
2297 | if (count_area != NULL && count_area->kl == 0) { |
2298 | /* we found notthing violating our disk layout */ | |
2299 | if (dasd_check_blocksize(count_area->dl) == 0) | |
8e09f215 | 2300 | block->bp_block = count_area->dl; |
1da177e4 | 2301 | } |
8e09f215 | 2302 | if (block->bp_block == 0) { |
fc19f381 SH |
2303 | dev_warn(&device->cdev->dev, |
2304 | "The disk layout of the DASD is not supported\n"); | |
1da177e4 LT |
2305 | return -EMEDIUMTYPE; |
2306 | } | |
8e09f215 SW |
2307 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
2308 | for (sb = 512; sb < block->bp_block; sb = sb << 1) | |
2309 | block->s2b_shift++; | |
1da177e4 | 2310 | |
8e09f215 | 2311 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
e4dbb0f2 SH |
2312 | |
2313 | raw: | |
2cc9637c | 2314 | block->blocks = ((unsigned long) private->real_cyl * |
1da177e4 LT |
2315 | private->rdc_data.trk_per_cyl * |
2316 | blk_per_trk); | |
2317 | ||
fc19f381 | 2318 | dev_info(&device->cdev->dev, |
2cc9637c | 2319 | "DASD with %u KB/block, %lu KB total size, %u KB/track, " |
fc19f381 | 2320 | "%s\n", (block->bp_block >> 10), |
2cc9637c | 2321 | (((unsigned long) private->real_cyl * |
fc19f381 SH |
2322 | private->rdc_data.trk_per_cyl * |
2323 | blk_per_trk * (block->bp_block >> 9)) >> 1), | |
2324 | ((blk_per_trk * block->bp_block) >> 10), | |
2325 | private->uses_cdl ? | |
2326 | "compatible disk layout" : "linux disk layout"); | |
1da177e4 LT |
2327 | |
2328 | return 0; | |
2329 | } | |
2330 | ||
8e09f215 | 2331 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
1da177e4 | 2332 | { |
543691a4 | 2333 | struct dasd_eckd_private *private = block->base->private; |
1da177e4 | 2334 | |
1da177e4 | 2335 | if (private->init_cqr_status < 0) |
8e09f215 | 2336 | return dasd_eckd_start_analysis(block); |
1da177e4 | 2337 | else |
8e09f215 | 2338 | return dasd_eckd_end_analysis(block); |
1da177e4 LT |
2339 | } |
2340 | ||
d42e1712 | 2341 | static int dasd_eckd_basic_to_ready(struct dasd_device *device) |
8e09f215 SW |
2342 | { |
2343 | return dasd_alias_add_device(device); | |
2344 | }; | |
2345 | ||
2346 | static int dasd_eckd_online_to_ready(struct dasd_device *device) | |
2347 | { | |
669f3765 SH |
2348 | if (cancel_work_sync(&device->reload_device)) |
2349 | dasd_put_device(device); | |
2350 | if (cancel_work_sync(&device->kick_validate)) | |
2351 | dasd_put_device(device); | |
2352 | ||
d42e1712 SH |
2353 | return 0; |
2354 | }; | |
2355 | ||
daa991bf | 2356 | static int dasd_eckd_basic_to_known(struct dasd_device *device) |
d42e1712 | 2357 | { |
8e09f215 SW |
2358 | return dasd_alias_remove_device(device); |
2359 | }; | |
2360 | ||
1da177e4 | 2361 | static int |
8e09f215 | 2362 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
1da177e4 | 2363 | { |
543691a4 | 2364 | struct dasd_eckd_private *private = block->base->private; |
1da177e4 | 2365 | |
8e09f215 | 2366 | if (dasd_check_blocksize(block->bp_block) == 0) { |
1da177e4 | 2367 | geo->sectors = recs_per_track(&private->rdc_data, |
8e09f215 | 2368 | 0, block->bp_block); |
1da177e4 LT |
2369 | } |
2370 | geo->cylinders = private->rdc_data.no_cyl; | |
2371 | geo->heads = private->rdc_data.trk_per_cyl; | |
2372 | return 0; | |
2373 | } | |
2374 | ||
8fd57520 JH |
2375 | /* |
2376 | * Build the TCW request for the format check | |
2377 | */ | |
2378 | static struct dasd_ccw_req * | |
2379 | dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata, | |
2380 | int enable_pav, struct eckd_count *fmt_buffer, | |
2381 | int rpt) | |
2382 | { | |
2383 | struct dasd_eckd_private *start_priv; | |
2384 | struct dasd_device *startdev = NULL; | |
2385 | struct tidaw *last_tidaw = NULL; | |
2386 | struct dasd_ccw_req *cqr; | |
2387 | struct itcw *itcw; | |
2388 | int itcw_size; | |
2389 | int count; | |
2390 | int rc; | |
2391 | int i; | |
2392 | ||
2393 | if (enable_pav) | |
2394 | startdev = dasd_alias_get_start_dev(base); | |
2395 | ||
2396 | if (!startdev) | |
2397 | startdev = base; | |
2398 | ||
2399 | start_priv = startdev->private; | |
2400 | ||
2401 | count = rpt * (fdata->stop_unit - fdata->start_unit + 1); | |
2402 | ||
2403 | /* | |
2404 | * we're adding 'count' amount of tidaw to the itcw. | |
2405 | * calculate the corresponding itcw_size | |
2406 | */ | |
2407 | itcw_size = itcw_calc_size(0, count, 0); | |
2408 | ||
5e2b17e7 | 2409 | cqr = dasd_fmalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); |
8fd57520 JH |
2410 | if (IS_ERR(cqr)) |
2411 | return cqr; | |
2412 | ||
2413 | start_priv->count++; | |
2414 | ||
2415 | itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0); | |
2416 | if (IS_ERR(itcw)) { | |
2417 | rc = -EINVAL; | |
2418 | goto out_err; | |
2419 | } | |
2420 | ||
2421 | cqr->cpaddr = itcw_get_tcw(itcw); | |
2422 | rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit, | |
2423 | DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count, | |
2424 | sizeof(struct eckd_count), | |
2425 | count * sizeof(struct eckd_count), 0, rpt); | |
2426 | if (rc) | |
2427 | goto out_err; | |
2428 | ||
2429 | for (i = 0; i < count; i++) { | |
2430 | last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++, | |
2431 | sizeof(struct eckd_count)); | |
2432 | if (IS_ERR(last_tidaw)) { | |
2433 | rc = -EINVAL; | |
2434 | goto out_err; | |
2435 | } | |
2436 | } | |
2437 | ||
2438 | last_tidaw->flags |= TIDAW_FLAGS_LAST; | |
2439 | itcw_finalize(itcw); | |
2440 | ||
2441 | cqr->cpmode = 1; | |
2442 | cqr->startdev = startdev; | |
2443 | cqr->memdev = startdev; | |
2444 | cqr->basedev = base; | |
2445 | cqr->retries = startdev->default_retries; | |
2446 | cqr->expires = startdev->default_expires * HZ; | |
2447 | cqr->buildclk = get_tod_clock(); | |
2448 | cqr->status = DASD_CQR_FILLED; | |
2449 | /* Set flags to suppress output for expected errors */ | |
2450 | set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags); | |
2451 | set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags); | |
2452 | ||
2453 | return cqr; | |
2454 | ||
2455 | out_err: | |
2456 | dasd_sfree_request(cqr, startdev); | |
2457 | ||
2458 | return ERR_PTR(rc); | |
2459 | } | |
2460 | ||
2461 | /* | |
2462 | * Build the CCW request for the format check | |
2463 | */ | |
2464 | static struct dasd_ccw_req * | |
2465 | dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata, | |
2466 | int enable_pav, struct eckd_count *fmt_buffer, int rpt) | |
2467 | { | |
2468 | struct dasd_eckd_private *start_priv; | |
2469 | struct dasd_eckd_private *base_priv; | |
2470 | struct dasd_device *startdev = NULL; | |
2471 | struct dasd_ccw_req *cqr; | |
2472 | struct ccw1 *ccw; | |
2473 | void *data; | |
2474 | int cplength, datasize; | |
2475 | int use_prefix; | |
2476 | int count; | |
2477 | int i; | |
2478 | ||
2479 | if (enable_pav) | |
2480 | startdev = dasd_alias_get_start_dev(base); | |
2481 | ||
2482 | if (!startdev) | |
2483 | startdev = base; | |
2484 | ||
2485 | start_priv = startdev->private; | |
2486 | base_priv = base->private; | |
2487 | ||
2488 | count = rpt * (fdata->stop_unit - fdata->start_unit + 1); | |
2489 | ||
2490 | use_prefix = base_priv->features.feature[8] & 0x01; | |
2491 | ||
2492 | if (use_prefix) { | |
2493 | cplength = 1; | |
2494 | datasize = sizeof(struct PFX_eckd_data); | |
2495 | } else { | |
2496 | cplength = 2; | |
2497 | datasize = sizeof(struct DE_eckd_data) + | |
2498 | sizeof(struct LO_eckd_data); | |
2499 | } | |
2500 | cplength += count; | |
2501 | ||
5e2b17e7 | 2502 | cqr = dasd_fmalloc_request(DASD_ECKD_MAGIC, cplength, datasize, startdev); |
8fd57520 JH |
2503 | if (IS_ERR(cqr)) |
2504 | return cqr; | |
2505 | ||
2506 | start_priv->count++; | |
2507 | data = cqr->data; | |
2508 | ccw = cqr->cpaddr; | |
2509 | ||
2510 | if (use_prefix) { | |
2511 | prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit, | |
2512 | DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0, | |
2513 | count, 0, 0); | |
2514 | } else { | |
2515 | define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit, | |
45f186be | 2516 | DASD_ECKD_CCW_READ_COUNT, startdev, 0); |
8fd57520 JH |
2517 | |
2518 | data += sizeof(struct DE_eckd_data); | |
2519 | ccw[-1].flags |= CCW_FLAG_CC; | |
2520 | ||
2521 | locate_record(ccw++, data, fdata->start_unit, 0, count, | |
2522 | DASD_ECKD_CCW_READ_COUNT, base, 0); | |
2523 | } | |
2524 | ||
2525 | for (i = 0; i < count; i++) { | |
2526 | ccw[-1].flags |= CCW_FLAG_CC; | |
2527 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; | |
2528 | ccw->flags = CCW_FLAG_SLI; | |
2529 | ccw->count = 8; | |
2530 | ccw->cda = (__u32)(addr_t) fmt_buffer; | |
2531 | ccw++; | |
2532 | fmt_buffer++; | |
2533 | } | |
2534 | ||
2535 | cqr->startdev = startdev; | |
2536 | cqr->memdev = startdev; | |
2537 | cqr->basedev = base; | |
2538 | cqr->retries = DASD_RETRIES; | |
2539 | cqr->expires = startdev->default_expires * HZ; | |
2540 | cqr->buildclk = get_tod_clock(); | |
2541 | cqr->status = DASD_CQR_FILLED; | |
2542 | /* Set flags to suppress output for expected errors */ | |
2543 | set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); | |
2544 | ||
2545 | return cqr; | |
2546 | } | |
2547 | ||
1da177e4 | 2548 | static struct dasd_ccw_req * |
5e2b17e7 JH |
2549 | dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, |
2550 | struct format_data_t *fdata, int enable_pav) | |
1da177e4 | 2551 | { |
d42e1712 SH |
2552 | struct dasd_eckd_private *base_priv; |
2553 | struct dasd_eckd_private *start_priv; | |
1da177e4 LT |
2554 | struct dasd_ccw_req *fcp; |
2555 | struct eckd_count *ect; | |
d42e1712 | 2556 | struct ch_t address; |
1da177e4 LT |
2557 | struct ccw1 *ccw; |
2558 | void *data; | |
b44b0ab3 | 2559 | int rpt; |
1da177e4 | 2560 | int cplength, datasize; |
d42e1712 | 2561 | int i, j; |
f9a28f7b JBJ |
2562 | int intensity = 0; |
2563 | int r0_perm; | |
d42e1712 | 2564 | int nr_tracks; |
18d6624e | 2565 | int use_prefix; |
1da177e4 | 2566 | |
a94fa154 | 2567 | if (enable_pav) |
29b8dd9d SH |
2568 | startdev = dasd_alias_get_start_dev(base); |
2569 | ||
d42e1712 SH |
2570 | if (!startdev) |
2571 | startdev = base; | |
1da177e4 | 2572 | |
543691a4 SO |
2573 | start_priv = startdev->private; |
2574 | base_priv = base->private; | |
d42e1712 SH |
2575 | |
2576 | rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize); | |
2577 | ||
2578 | nr_tracks = fdata->stop_unit - fdata->start_unit + 1; | |
1da177e4 LT |
2579 | |
2580 | /* | |
2581 | * fdata->intensity is a bit string that tells us what to do: | |
2582 | * Bit 0: write record zero | |
2583 | * Bit 1: write home address, currently not supported | |
2584 | * Bit 2: invalidate tracks | |
2585 | * Bit 3: use OS/390 compatible disk layout (cdl) | |
f9a28f7b | 2586 | * Bit 4: do not allow storage subsystem to modify record zero |
1da177e4 LT |
2587 | * Only some bit combinations do make sense. |
2588 | */ | |
f9a28f7b JBJ |
2589 | if (fdata->intensity & 0x10) { |
2590 | r0_perm = 0; | |
2591 | intensity = fdata->intensity & ~0x10; | |
2592 | } else { | |
2593 | r0_perm = 1; | |
2594 | intensity = fdata->intensity; | |
2595 | } | |
d42e1712 | 2596 | |
18d6624e SH |
2597 | use_prefix = base_priv->features.feature[8] & 0x01; |
2598 | ||
f9a28f7b | 2599 | switch (intensity) { |
1da177e4 LT |
2600 | case 0x00: /* Normal format */ |
2601 | case 0x08: /* Normal format, use cdl. */ | |
d42e1712 | 2602 | cplength = 2 + (rpt*nr_tracks); |
18d6624e SH |
2603 | if (use_prefix) |
2604 | datasize = sizeof(struct PFX_eckd_data) + | |
2605 | sizeof(struct LO_eckd_data) + | |
2606 | rpt * nr_tracks * sizeof(struct eckd_count); | |
2607 | else | |
2608 | datasize = sizeof(struct DE_eckd_data) + | |
2609 | sizeof(struct LO_eckd_data) + | |
2610 | rpt * nr_tracks * sizeof(struct eckd_count); | |
1da177e4 LT |
2611 | break; |
2612 | case 0x01: /* Write record zero and format track. */ | |
2613 | case 0x09: /* Write record zero and format track, use cdl. */ | |
d42e1712 | 2614 | cplength = 2 + rpt * nr_tracks; |
18d6624e SH |
2615 | if (use_prefix) |
2616 | datasize = sizeof(struct PFX_eckd_data) + | |
2617 | sizeof(struct LO_eckd_data) + | |
2618 | sizeof(struct eckd_count) + | |
2619 | rpt * nr_tracks * sizeof(struct eckd_count); | |
2620 | else | |
2621 | datasize = sizeof(struct DE_eckd_data) + | |
2622 | sizeof(struct LO_eckd_data) + | |
2623 | sizeof(struct eckd_count) + | |
2624 | rpt * nr_tracks * sizeof(struct eckd_count); | |
1da177e4 LT |
2625 | break; |
2626 | case 0x04: /* Invalidate track. */ | |
2627 | case 0x0c: /* Invalidate track, use cdl. */ | |
2628 | cplength = 3; | |
18d6624e SH |
2629 | if (use_prefix) |
2630 | datasize = sizeof(struct PFX_eckd_data) + | |
2631 | sizeof(struct LO_eckd_data) + | |
2632 | sizeof(struct eckd_count); | |
2633 | else | |
2634 | datasize = sizeof(struct DE_eckd_data) + | |
2635 | sizeof(struct LO_eckd_data) + | |
2636 | sizeof(struct eckd_count); | |
1da177e4 LT |
2637 | break; |
2638 | default: | |
d42e1712 SH |
2639 | dev_warn(&startdev->cdev->dev, |
2640 | "An I/O control call used incorrect flags 0x%x\n", | |
2641 | fdata->intensity); | |
1da177e4 LT |
2642 | return ERR_PTR(-EINVAL); |
2643 | } | |
5e2b17e7 JH |
2644 | |
2645 | fcp = dasd_fmalloc_request(DASD_ECKD_MAGIC, cplength, datasize, startdev); | |
1da177e4 LT |
2646 | if (IS_ERR(fcp)) |
2647 | return fcp; | |
2648 | ||
d42e1712 | 2649 | start_priv->count++; |
1da177e4 LT |
2650 | data = fcp->data; |
2651 | ccw = fcp->cpaddr; | |
2652 | ||
f9a28f7b | 2653 | switch (intensity & ~0x08) { |
1da177e4 | 2654 | case 0x00: /* Normal format. */ |
18d6624e SH |
2655 | if (use_prefix) { |
2656 | prefix(ccw++, (struct PFX_eckd_data *) data, | |
2657 | fdata->start_unit, fdata->stop_unit, | |
2658 | DASD_ECKD_CCW_WRITE_CKD, base, startdev); | |
2659 | /* grant subsystem permission to format R0 */ | |
2660 | if (r0_perm) | |
2661 | ((struct PFX_eckd_data *)data) | |
2662 | ->define_extent.ga_extended |= 0x04; | |
2663 | data += sizeof(struct PFX_eckd_data); | |
2664 | } else { | |
2665 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2666 | fdata->start_unit, fdata->stop_unit, | |
45f186be | 2667 | DASD_ECKD_CCW_WRITE_CKD, startdev, 0); |
18d6624e SH |
2668 | /* grant subsystem permission to format R0 */ |
2669 | if (r0_perm) | |
2670 | ((struct DE_eckd_data *) data) | |
2671 | ->ga_extended |= 0x04; | |
2672 | data += sizeof(struct DE_eckd_data); | |
2673 | } | |
1da177e4 LT |
2674 | ccw[-1].flags |= CCW_FLAG_CC; |
2675 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
d42e1712 SH |
2676 | fdata->start_unit, 0, rpt*nr_tracks, |
2677 | DASD_ECKD_CCW_WRITE_CKD, base, | |
1da177e4 LT |
2678 | fdata->blksize); |
2679 | data += sizeof(struct LO_eckd_data); | |
2680 | break; | |
2681 | case 0x01: /* Write record zero + format track. */ | |
18d6624e SH |
2682 | if (use_prefix) { |
2683 | prefix(ccw++, (struct PFX_eckd_data *) data, | |
2684 | fdata->start_unit, fdata->stop_unit, | |
2685 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, | |
2686 | base, startdev); | |
2687 | data += sizeof(struct PFX_eckd_data); | |
2688 | } else { | |
2689 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2690 | fdata->start_unit, fdata->stop_unit, | |
45f186be | 2691 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev, 0); |
18d6624e SH |
2692 | data += sizeof(struct DE_eckd_data); |
2693 | } | |
1da177e4 LT |
2694 | ccw[-1].flags |= CCW_FLAG_CC; |
2695 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
d42e1712 SH |
2696 | fdata->start_unit, 0, rpt * nr_tracks + 1, |
2697 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, base, | |
2698 | base->block->bp_block); | |
1da177e4 LT |
2699 | data += sizeof(struct LO_eckd_data); |
2700 | break; | |
2701 | case 0x04: /* Invalidate track. */ | |
18d6624e SH |
2702 | if (use_prefix) { |
2703 | prefix(ccw++, (struct PFX_eckd_data *) data, | |
2704 | fdata->start_unit, fdata->stop_unit, | |
2705 | DASD_ECKD_CCW_WRITE_CKD, base, startdev); | |
2706 | data += sizeof(struct PFX_eckd_data); | |
2707 | } else { | |
2708 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2709 | fdata->start_unit, fdata->stop_unit, | |
45f186be | 2710 | DASD_ECKD_CCW_WRITE_CKD, startdev, 0); |
18d6624e SH |
2711 | data += sizeof(struct DE_eckd_data); |
2712 | } | |
1da177e4 LT |
2713 | ccw[-1].flags |= CCW_FLAG_CC; |
2714 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
2715 | fdata->start_unit, 0, 1, | |
d42e1712 | 2716 | DASD_ECKD_CCW_WRITE_CKD, base, 8); |
1da177e4 LT |
2717 | data += sizeof(struct LO_eckd_data); |
2718 | break; | |
2719 | } | |
d42e1712 SH |
2720 | |
2721 | for (j = 0; j < nr_tracks; j++) { | |
2722 | /* calculate cylinder and head for the current track */ | |
2723 | set_ch_t(&address, | |
2724 | (fdata->start_unit + j) / | |
2725 | base_priv->rdc_data.trk_per_cyl, | |
2726 | (fdata->start_unit + j) % | |
2727 | base_priv->rdc_data.trk_per_cyl); | |
2728 | if (intensity & 0x01) { /* write record zero */ | |
1da177e4 LT |
2729 | ect = (struct eckd_count *) data; |
2730 | data += sizeof(struct eckd_count); | |
b44b0ab3 SW |
2731 | ect->cyl = address.cyl; |
2732 | ect->head = address.head; | |
d42e1712 | 2733 | ect->record = 0; |
1da177e4 | 2734 | ect->kl = 0; |
d42e1712 | 2735 | ect->dl = 8; |
1da177e4 | 2736 | ccw[-1].flags |= CCW_FLAG_CC; |
d42e1712 | 2737 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; |
1da177e4 LT |
2738 | ccw->flags = CCW_FLAG_SLI; |
2739 | ccw->count = 8; | |
2740 | ccw->cda = (__u32)(addr_t) ect; | |
2741 | ccw++; | |
2742 | } | |
d42e1712 SH |
2743 | if ((intensity & ~0x08) & 0x04) { /* erase track */ |
2744 | ect = (struct eckd_count *) data; | |
2745 | data += sizeof(struct eckd_count); | |
2746 | ect->cyl = address.cyl; | |
2747 | ect->head = address.head; | |
2748 | ect->record = 1; | |
2749 | ect->kl = 0; | |
2750 | ect->dl = 0; | |
2751 | ccw[-1].flags |= CCW_FLAG_CC; | |
2752 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; | |
2753 | ccw->flags = CCW_FLAG_SLI; | |
2754 | ccw->count = 8; | |
2755 | ccw->cda = (__u32)(addr_t) ect; | |
2756 | } else { /* write remaining records */ | |
2757 | for (i = 0; i < rpt; i++) { | |
2758 | ect = (struct eckd_count *) data; | |
2759 | data += sizeof(struct eckd_count); | |
2760 | ect->cyl = address.cyl; | |
2761 | ect->head = address.head; | |
2762 | ect->record = i + 1; | |
2763 | ect->kl = 0; | |
2764 | ect->dl = fdata->blksize; | |
2765 | /* | |
2766 | * Check for special tracks 0-1 | |
2767 | * when formatting CDL | |
2768 | */ | |
2769 | if ((intensity & 0x08) && | |
46d1c03c | 2770 | address.cyl == 0 && address.head == 0) { |
d42e1712 SH |
2771 | if (i < 3) { |
2772 | ect->kl = 4; | |
2773 | ect->dl = sizes_trk0[i] - 4; | |
2774 | } | |
2775 | } | |
2776 | if ((intensity & 0x08) && | |
46d1c03c | 2777 | address.cyl == 0 && address.head == 1) { |
d42e1712 SH |
2778 | ect->kl = 44; |
2779 | ect->dl = LABEL_SIZE - 44; | |
2780 | } | |
2781 | ccw[-1].flags |= CCW_FLAG_CC; | |
2782 | if (i != 0 || j == 0) | |
2783 | ccw->cmd_code = | |
2784 | DASD_ECKD_CCW_WRITE_CKD; | |
2785 | else | |
2786 | ccw->cmd_code = | |
2787 | DASD_ECKD_CCW_WRITE_CKD_MT; | |
2788 | ccw->flags = CCW_FLAG_SLI; | |
2789 | ccw->count = 8; | |
ba21d0ea SH |
2790 | ccw->cda = (__u32)(addr_t) ect; |
2791 | ccw++; | |
d42e1712 SH |
2792 | } |
2793 | } | |
1da177e4 | 2794 | } |
d42e1712 SH |
2795 | |
2796 | fcp->startdev = startdev; | |
2797 | fcp->memdev = startdev; | |
29b8dd9d | 2798 | fcp->basedev = base; |
eb6e199b | 2799 | fcp->retries = 256; |
d42e1712 | 2800 | fcp->expires = startdev->default_expires * HZ; |
1aae0560 | 2801 | fcp->buildclk = get_tod_clock(); |
1da177e4 | 2802 | fcp->status = DASD_CQR_FILLED; |
d42e1712 | 2803 | |
1da177e4 LT |
2804 | return fcp; |
2805 | } | |
2806 | ||
570d237c JH |
2807 | /* |
2808 | * Wrapper function to build a CCW request depending on input data | |
2809 | */ | |
2810 | static struct dasd_ccw_req * | |
2811 | dasd_eckd_format_build_ccw_req(struct dasd_device *base, | |
8fd57520 JH |
2812 | struct format_data_t *fdata, int enable_pav, |
2813 | int tpm, struct eckd_count *fmt_buffer, int rpt) | |
570d237c | 2814 | { |
8fd57520 JH |
2815 | struct dasd_ccw_req *ccw_req; |
2816 | ||
2817 | if (!fmt_buffer) { | |
5e2b17e7 | 2818 | ccw_req = dasd_eckd_build_format(base, NULL, fdata, enable_pav); |
8fd57520 JH |
2819 | } else { |
2820 | if (tpm) | |
2821 | ccw_req = dasd_eckd_build_check_tcw(base, fdata, | |
2822 | enable_pav, | |
2823 | fmt_buffer, rpt); | |
2824 | else | |
2825 | ccw_req = dasd_eckd_build_check(base, fdata, enable_pav, | |
2826 | fmt_buffer, rpt); | |
2827 | } | |
2828 | ||
2829 | return ccw_req; | |
570d237c JH |
2830 | } |
2831 | ||
2832 | /* | |
2833 | * Sanity checks on format_data | |
2834 | */ | |
2835 | static int dasd_eckd_format_sanity_checks(struct dasd_device *base, | |
2836 | struct format_data_t *fdata) | |
d42e1712 | 2837 | { |
543691a4 | 2838 | struct dasd_eckd_private *private = base->private; |
d42e1712 | 2839 | |
d42e1712 SH |
2840 | if (fdata->start_unit >= |
2841 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { | |
2842 | dev_warn(&base->cdev->dev, | |
2843 | "Start track number %u used in formatting is too big\n", | |
2844 | fdata->start_unit); | |
2845 | return -EINVAL; | |
2846 | } | |
2847 | if (fdata->stop_unit >= | |
2848 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { | |
2849 | dev_warn(&base->cdev->dev, | |
2850 | "Stop track number %u used in formatting is too big\n", | |
2851 | fdata->stop_unit); | |
2852 | return -EINVAL; | |
2853 | } | |
2854 | if (fdata->start_unit > fdata->stop_unit) { | |
2855 | dev_warn(&base->cdev->dev, | |
2856 | "Start track %u used in formatting exceeds end track\n", | |
2857 | fdata->start_unit); | |
2858 | return -EINVAL; | |
2859 | } | |
2860 | if (dasd_check_blocksize(fdata->blksize) != 0) { | |
2861 | dev_warn(&base->cdev->dev, | |
2862 | "The DASD cannot be formatted with block size %u\n", | |
2863 | fdata->blksize); | |
2864 | return -EINVAL; | |
2865 | } | |
570d237c JH |
2866 | return 0; |
2867 | } | |
2868 | ||
2869 | /* | |
2870 | * This function will process format_data originally coming from an IOCTL | |
2871 | */ | |
2872 | static int dasd_eckd_format_process_data(struct dasd_device *base, | |
2873 | struct format_data_t *fdata, | |
8fd57520 JH |
2874 | int enable_pav, int tpm, |
2875 | struct eckd_count *fmt_buffer, int rpt, | |
2876 | struct irb *irb) | |
570d237c | 2877 | { |
543691a4 | 2878 | struct dasd_eckd_private *private = base->private; |
570d237c | 2879 | struct dasd_ccw_req *cqr, *n; |
570d237c JH |
2880 | struct list_head format_queue; |
2881 | struct dasd_device *device; | |
8fd57520 | 2882 | char *sense = NULL; |
570d237c JH |
2883 | int old_start, old_stop, format_step; |
2884 | int step, retry; | |
2885 | int rc; | |
2886 | ||
570d237c JH |
2887 | rc = dasd_eckd_format_sanity_checks(base, fdata); |
2888 | if (rc) | |
2889 | return rc; | |
d42e1712 SH |
2890 | |
2891 | INIT_LIST_HEAD(&format_queue); | |
d42e1712 | 2892 | |
46d1c03c | 2893 | old_start = fdata->start_unit; |
29b8dd9d | 2894 | old_stop = fdata->stop_unit; |
d42e1712 | 2895 | |
8fd57520 JH |
2896 | if (!tpm && fmt_buffer != NULL) { |
2897 | /* Command Mode / Format Check */ | |
2898 | format_step = 1; | |
2899 | } else if (tpm && fmt_buffer != NULL) { | |
2900 | /* Transport Mode / Format Check */ | |
2901 | format_step = DASD_CQR_MAX_CCW / rpt; | |
2902 | } else { | |
2903 | /* Normal Formatting */ | |
2904 | format_step = DASD_CQR_MAX_CCW / | |
2905 | recs_per_track(&private->rdc_data, 0, fdata->blksize); | |
2906 | } | |
2907 | ||
46d1c03c JH |
2908 | do { |
2909 | retry = 0; | |
2910 | while (fdata->start_unit <= old_stop) { | |
2911 | step = fdata->stop_unit - fdata->start_unit + 1; | |
2912 | if (step > format_step) { | |
2913 | fdata->stop_unit = | |
2914 | fdata->start_unit + format_step - 1; | |
2915 | } | |
d42e1712 | 2916 | |
570d237c | 2917 | cqr = dasd_eckd_format_build_ccw_req(base, fdata, |
8fd57520 JH |
2918 | enable_pav, tpm, |
2919 | fmt_buffer, rpt); | |
46d1c03c JH |
2920 | if (IS_ERR(cqr)) { |
2921 | rc = PTR_ERR(cqr); | |
2922 | if (rc == -ENOMEM) { | |
2923 | if (list_empty(&format_queue)) | |
2924 | goto out; | |
2925 | /* | |
2926 | * not enough memory available, start | |
2927 | * requests retry after first requests | |
2928 | * were finished | |
2929 | */ | |
2930 | retry = 1; | |
2931 | break; | |
2932 | } | |
2933 | goto out_err; | |
2934 | } | |
2935 | list_add_tail(&cqr->blocklist, &format_queue); | |
d42e1712 | 2936 | |
8fd57520 JH |
2937 | if (fmt_buffer) { |
2938 | step = fdata->stop_unit - fdata->start_unit + 1; | |
2939 | fmt_buffer += rpt * step; | |
2940 | } | |
46d1c03c JH |
2941 | fdata->start_unit = fdata->stop_unit + 1; |
2942 | fdata->stop_unit = old_stop; | |
d42e1712 | 2943 | } |
d42e1712 | 2944 | |
46d1c03c JH |
2945 | rc = dasd_sleep_on_queue(&format_queue); |
2946 | ||
2947 | out_err: | |
2948 | list_for_each_entry_safe(cqr, n, &format_queue, blocklist) { | |
2949 | device = cqr->startdev; | |
543691a4 | 2950 | private = device->private; |
8fd57520 JH |
2951 | |
2952 | if (cqr->status == DASD_CQR_FAILED) { | |
2953 | /* | |
2954 | * Only get sense data if called by format | |
2955 | * check | |
2956 | */ | |
2957 | if (fmt_buffer && irb) { | |
2958 | sense = dasd_get_sense(&cqr->irb); | |
2959 | memcpy(irb, &cqr->irb, sizeof(*irb)); | |
2960 | } | |
46d1c03c | 2961 | rc = -EIO; |
8fd57520 | 2962 | } |
46d1c03c | 2963 | list_del_init(&cqr->blocklist); |
5e2b17e7 | 2964 | dasd_ffree_request(cqr, device); |
46d1c03c JH |
2965 | private->count--; |
2966 | } | |
d42e1712 | 2967 | |
8fd57520 | 2968 | if (rc && rc != -EIO) |
46d1c03c | 2969 | goto out; |
8fd57520 JH |
2970 | if (rc == -EIO) { |
2971 | /* | |
2972 | * In case fewer than the expected records are on the | |
2973 | * track, we will most likely get a 'No Record Found' | |
2974 | * error (in command mode) or a 'File Protected' error | |
2975 | * (in transport mode). Those particular cases shouldn't | |
2976 | * pass the -EIO to the IOCTL, therefore reset the rc | |
2977 | * and continue. | |
2978 | */ | |
2979 | if (sense && | |
2980 | (sense[1] & SNS1_NO_REC_FOUND || | |
2981 | sense[1] & SNS1_FILE_PROTECTED)) | |
2982 | retry = 1; | |
2983 | else | |
2984 | goto out; | |
2985 | } | |
d42e1712 | 2986 | |
46d1c03c | 2987 | } while (retry); |
29b8dd9d | 2988 | |
46d1c03c JH |
2989 | out: |
2990 | fdata->start_unit = old_start; | |
2991 | fdata->stop_unit = old_stop; | |
d42e1712 SH |
2992 | |
2993 | return rc; | |
2994 | } | |
2995 | ||
570d237c JH |
2996 | static int dasd_eckd_format_device(struct dasd_device *base, |
2997 | struct format_data_t *fdata, int enable_pav) | |
2998 | { | |
8fd57520 JH |
2999 | return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL, |
3000 | 0, NULL); | |
3001 | } | |
3002 | ||
5e2b17e7 JH |
3003 | /* |
3004 | * Callback function to free ESE format requests. | |
3005 | */ | |
3006 | static void dasd_eckd_ese_format_cb(struct dasd_ccw_req *cqr, void *data) | |
3007 | { | |
3008 | struct dasd_device *device = cqr->startdev; | |
3009 | struct dasd_eckd_private *private = device->private; | |
3010 | ||
3011 | private->count--; | |
3012 | dasd_ffree_request(cqr, device); | |
3013 | } | |
3014 | ||
3015 | static struct dasd_ccw_req * | |
3016 | dasd_eckd_ese_format(struct dasd_device *startdev, struct dasd_ccw_req *cqr) | |
3017 | { | |
3018 | struct dasd_eckd_private *private; | |
3019 | struct format_data_t fdata; | |
3020 | unsigned int recs_per_trk; | |
3021 | struct dasd_ccw_req *fcqr; | |
3022 | struct dasd_device *base; | |
3023 | struct dasd_block *block; | |
3024 | unsigned int blksize; | |
3025 | struct request *req; | |
3026 | sector_t first_trk; | |
3027 | sector_t last_trk; | |
3028 | int rc; | |
3029 | ||
3030 | req = cqr->callback_data; | |
3031 | base = cqr->block->base; | |
3032 | private = base->private; | |
3033 | block = base->block; | |
3034 | blksize = block->bp_block; | |
3035 | recs_per_trk = recs_per_track(&private->rdc_data, 0, blksize); | |
3036 | ||
3037 | first_trk = blk_rq_pos(req) >> block->s2b_shift; | |
3038 | sector_div(first_trk, recs_per_trk); | |
3039 | last_trk = | |
3040 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; | |
3041 | sector_div(last_trk, recs_per_trk); | |
3042 | ||
3043 | fdata.start_unit = first_trk; | |
3044 | fdata.stop_unit = last_trk; | |
3045 | fdata.blksize = blksize; | |
3046 | fdata.intensity = private->uses_cdl ? DASD_FMT_INT_COMPAT : 0; | |
3047 | ||
3048 | rc = dasd_eckd_format_sanity_checks(base, &fdata); | |
3049 | if (rc) | |
3050 | return ERR_PTR(-EINVAL); | |
3051 | ||
3052 | /* | |
3053 | * We're building the request with PAV disabled as we're reusing | |
3054 | * the former startdev. | |
3055 | */ | |
3056 | fcqr = dasd_eckd_build_format(base, startdev, &fdata, 0); | |
3057 | if (IS_ERR(fcqr)) | |
3058 | return fcqr; | |
3059 | ||
3060 | fcqr->callback = dasd_eckd_ese_format_cb; | |
3061 | ||
3062 | return fcqr; | |
3063 | } | |
3064 | ||
3065 | /* | |
3066 | * When data is read from an unformatted area of an ESE volume, this function | |
3067 | * returns zeroed data and thereby mimics a read of zero data. | |
3068 | */ | |
3069 | static void dasd_eckd_ese_read(struct dasd_ccw_req *cqr) | |
3070 | { | |
3071 | unsigned int blksize, off; | |
3072 | struct dasd_device *base; | |
3073 | struct req_iterator iter; | |
3074 | struct request *req; | |
3075 | struct bio_vec bv; | |
3076 | char *dst; | |
3077 | ||
3078 | req = (struct request *) cqr->callback_data; | |
3079 | base = cqr->block->base; | |
3080 | blksize = base->block->bp_block; | |
3081 | ||
3082 | rq_for_each_segment(bv, req, iter) { | |
3083 | dst = page_address(bv.bv_page) + bv.bv_offset; | |
3084 | for (off = 0; off < bv.bv_len; off += blksize) { | |
3085 | if (dst && rq_data_dir(req) == READ) { | |
3086 | dst += off; | |
3087 | memset(dst, 0, blksize); | |
3088 | } | |
3089 | } | |
3090 | } | |
3091 | } | |
3092 | ||
8fd57520 JH |
3093 | /* |
3094 | * Helper function to count consecutive records of a single track. | |
3095 | */ | |
3096 | static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start, | |
3097 | int max) | |
3098 | { | |
3099 | int head; | |
3100 | int i; | |
3101 | ||
3102 | head = fmt_buffer[start].head; | |
3103 | ||
3104 | /* | |
3105 | * There are 3 conditions where we stop counting: | |
3106 | * - if data reoccurs (same head and record may reoccur), which may | |
3107 | * happen due to the way DASD_ECKD_CCW_READ_COUNT works | |
3108 | * - when the head changes, because we're iterating over several tracks | |
3109 | * then (DASD_ECKD_CCW_READ_COUNT_MT) | |
3110 | * - when we've reached the end of sensible data in the buffer (the | |
3111 | * record will be 0 then) | |
3112 | */ | |
3113 | for (i = start; i < max; i++) { | |
3114 | if (i > start) { | |
3115 | if ((fmt_buffer[i].head == head && | |
3116 | fmt_buffer[i].record == 1) || | |
3117 | fmt_buffer[i].head != head || | |
3118 | fmt_buffer[i].record == 0) | |
3119 | break; | |
3120 | } | |
3121 | } | |
3122 | ||
3123 | return i - start; | |
3124 | } | |
3125 | ||
3126 | /* | |
3127 | * Evaluate a given range of tracks. Data like number of records, blocksize, | |
3128 | * record ids, and key length are compared with expected data. | |
3129 | * | |
3130 | * If a mismatch occurs, the corresponding error bit is set, as well as | |
3131 | * additional information, depending on the error. | |
3132 | */ | |
3133 | static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer, | |
3134 | struct format_check_t *cdata, | |
3135 | int rpt_max, int rpt_exp, | |
3136 | int trk_per_cyl, int tpm) | |
3137 | { | |
3138 | struct ch_t geo; | |
3139 | int max_entries; | |
3140 | int count = 0; | |
3141 | int trkcount; | |
3142 | int blksize; | |
3143 | int pos = 0; | |
3144 | int i, j; | |
3145 | int kl; | |
3146 | ||
3147 | trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1; | |
3148 | max_entries = trkcount * rpt_max; | |
3149 | ||
3150 | for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) { | |
3151 | /* Calculate the correct next starting position in the buffer */ | |
3152 | if (tpm) { | |
3153 | while (fmt_buffer[pos].record == 0 && | |
3154 | fmt_buffer[pos].dl == 0) { | |
3155 | if (pos++ > max_entries) | |
3156 | break; | |
3157 | } | |
3158 | } else { | |
3159 | if (i != cdata->expect.start_unit) | |
3160 | pos += rpt_max - count; | |
3161 | } | |
3162 | ||
3163 | /* Calculate the expected geo values for the current track */ | |
3164 | set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl); | |
3165 | ||
3166 | /* Count and check number of records */ | |
3167 | count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max); | |
3168 | ||
3169 | if (count < rpt_exp) { | |
3170 | cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS; | |
3171 | break; | |
3172 | } | |
3173 | if (count > rpt_exp) { | |
3174 | cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS; | |
3175 | break; | |
3176 | } | |
3177 | ||
3178 | for (j = 0; j < count; j++, pos++) { | |
3179 | blksize = cdata->expect.blksize; | |
3180 | kl = 0; | |
3181 | ||
3182 | /* | |
3183 | * Set special values when checking CDL formatted | |
3184 | * devices. | |
3185 | */ | |
3186 | if ((cdata->expect.intensity & 0x08) && | |
3187 | geo.cyl == 0 && geo.head == 0) { | |
3188 | if (j < 3) { | |
3189 | blksize = sizes_trk0[j] - 4; | |
3190 | kl = 4; | |
3191 | } | |
3192 | } | |
3193 | if ((cdata->expect.intensity & 0x08) && | |
3194 | geo.cyl == 0 && geo.head == 1) { | |
3195 | blksize = LABEL_SIZE - 44; | |
3196 | kl = 44; | |
3197 | } | |
3198 | ||
3199 | /* Check blocksize */ | |
3200 | if (fmt_buffer[pos].dl != blksize) { | |
3201 | cdata->result = DASD_FMT_ERR_BLKSIZE; | |
3202 | goto out; | |
3203 | } | |
3204 | /* Check if key length is 0 */ | |
3205 | if (fmt_buffer[pos].kl != kl) { | |
3206 | cdata->result = DASD_FMT_ERR_KEY_LENGTH; | |
3207 | goto out; | |
3208 | } | |
3209 | /* Check if record_id is correct */ | |
3210 | if (fmt_buffer[pos].cyl != geo.cyl || | |
3211 | fmt_buffer[pos].head != geo.head || | |
3212 | fmt_buffer[pos].record != (j + 1)) { | |
3213 | cdata->result = DASD_FMT_ERR_RECORD_ID; | |
3214 | goto out; | |
3215 | } | |
3216 | } | |
3217 | } | |
3218 | ||
3219 | out: | |
3220 | /* | |
3221 | * In case of no errors, we need to decrease by one | |
3222 | * to get the correct positions. | |
3223 | */ | |
3224 | if (!cdata->result) { | |
3225 | i--; | |
3226 | pos--; | |
3227 | } | |
3228 | ||
3229 | cdata->unit = i; | |
3230 | cdata->num_records = count; | |
3231 | cdata->rec = fmt_buffer[pos].record; | |
3232 | cdata->blksize = fmt_buffer[pos].dl; | |
3233 | cdata->key_length = fmt_buffer[pos].kl; | |
3234 | } | |
3235 | ||
3236 | /* | |
3237 | * Check the format of a range of tracks of a DASD. | |
3238 | */ | |
3239 | static int dasd_eckd_check_device_format(struct dasd_device *base, | |
3240 | struct format_check_t *cdata, | |
3241 | int enable_pav) | |
3242 | { | |
3243 | struct dasd_eckd_private *private = base->private; | |
3244 | struct eckd_count *fmt_buffer; | |
3245 | struct irb irb; | |
3246 | int rpt_max, rpt_exp; | |
3247 | int fmt_buffer_size; | |
3248 | int trk_per_cyl; | |
3249 | int trkcount; | |
3250 | int tpm = 0; | |
3251 | int rc; | |
3252 | ||
3253 | trk_per_cyl = private->rdc_data.trk_per_cyl; | |
3254 | ||
3255 | /* Get maximum and expected amount of records per track */ | |
3256 | rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1; | |
3257 | rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize); | |
3258 | ||
3259 | trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1; | |
3260 | fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count); | |
3261 | ||
3262 | fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA); | |
3263 | if (!fmt_buffer) | |
3264 | return -ENOMEM; | |
3265 | ||
3266 | /* | |
3267 | * A certain FICON feature subset is needed to operate in transport | |
3268 | * mode. Additionally, the support for transport mode is implicitly | |
3269 | * checked by comparing the buffer size with fcx_max_data. As long as | |
3270 | * the buffer size is smaller we can operate in transport mode and | |
3271 | * process multiple tracks. If not, only one track at once is being | |
3272 | * processed using command mode. | |
3273 | */ | |
3274 | if ((private->features.feature[40] & 0x04) && | |
3275 | fmt_buffer_size <= private->fcx_max_data) | |
3276 | tpm = 1; | |
3277 | ||
3278 | rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav, | |
3279 | tpm, fmt_buffer, rpt_max, &irb); | |
3280 | if (rc && rc != -EIO) | |
3281 | goto out; | |
3282 | if (rc == -EIO) { | |
3283 | /* | |
3284 | * If our first attempt with transport mode enabled comes back | |
3285 | * with an incorrect length error, we're going to retry the | |
3286 | * check with command mode. | |
3287 | */ | |
3288 | if (tpm && scsw_cstat(&irb.scsw) == 0x40) { | |
3289 | tpm = 0; | |
3290 | rc = dasd_eckd_format_process_data(base, &cdata->expect, | |
3291 | enable_pav, tpm, | |
3292 | fmt_buffer, rpt_max, | |
3293 | &irb); | |
3294 | if (rc) | |
3295 | goto out; | |
3296 | } else { | |
3297 | goto out; | |
3298 | } | |
3299 | } | |
3300 | ||
3301 | dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp, | |
3302 | trk_per_cyl, tpm); | |
3303 | ||
3304 | out: | |
3305 | kfree(fmt_buffer); | |
3306 | ||
3307 | return rc; | |
570d237c JH |
3308 | } |
3309 | ||
8e09f215 | 3310 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
1da177e4 | 3311 | { |
a2ace466 HR |
3312 | if (cqr->retries < 0) { |
3313 | cqr->status = DASD_CQR_FAILED; | |
3314 | return; | |
3315 | } | |
8e09f215 SW |
3316 | cqr->status = DASD_CQR_FILLED; |
3317 | if (cqr->block && (cqr->startdev != cqr->block->base)) { | |
3318 | dasd_eckd_reset_ccw_to_base_io(cqr); | |
3319 | cqr->startdev = cqr->block->base; | |
c9346151 | 3320 | cqr->lpm = dasd_path_get_opm(cqr->block->base); |
1da177e4 | 3321 | } |
8e09f215 | 3322 | }; |
1da177e4 LT |
3323 | |
3324 | static dasd_erp_fn_t | |
3325 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) | |
3326 | { | |
8e09f215 | 3327 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
1da177e4 LT |
3328 | struct ccw_device *cdev = device->cdev; |
3329 | ||
3330 | switch (cdev->id.cu_type) { | |
3331 | case 0x3990: | |
3332 | case 0x2105: | |
3333 | case 0x2107: | |
3334 | case 0x1750: | |
3335 | return dasd_3990_erp_action; | |
3336 | case 0x9343: | |
3337 | case 0x3880: | |
3338 | default: | |
3339 | return dasd_default_erp_action; | |
3340 | } | |
3341 | } | |
3342 | ||
3343 | static dasd_erp_fn_t | |
3344 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) | |
3345 | { | |
3346 | return dasd_default_erp_postaction; | |
3347 | } | |
3348 | ||
5a27e60d SW |
3349 | static void dasd_eckd_check_for_device_change(struct dasd_device *device, |
3350 | struct dasd_ccw_req *cqr, | |
3351 | struct irb *irb) | |
8e09f215 SW |
3352 | { |
3353 | char mask; | |
f3eb5384 | 3354 | char *sense = NULL; |
543691a4 | 3355 | struct dasd_eckd_private *private = device->private; |
8e09f215 SW |
3356 | |
3357 | /* first of all check for state change pending interrupt */ | |
3358 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; | |
f3eb5384 | 3359 | if ((scsw_dstat(&irb->scsw) & mask) == mask) { |
c8d1c0ff SH |
3360 | /* |
3361 | * for alias only, not in offline processing | |
3362 | * and only if not suspended | |
3363 | */ | |
501183f2 | 3364 | if (!device->block && private->lcu && |
25e2cf1c | 3365 | device->state == DASD_STATE_ONLINE && |
c8d1c0ff SH |
3366 | !test_bit(DASD_FLAG_OFFLINE, &device->flags) && |
3367 | !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { | |
501183f2 SH |
3368 | /* schedule worker to reload device */ |
3369 | dasd_reload_device(device); | |
3370 | } | |
8e09f215 SW |
3371 | dasd_generic_handle_state_change(device); |
3372 | return; | |
3373 | } | |
3374 | ||
a5a0061f | 3375 | sense = dasd_get_sense(irb); |
5a27e60d SW |
3376 | if (!sense) |
3377 | return; | |
3378 | ||
3379 | /* summary unit check */ | |
c7a29e56 | 3380 | if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) && |
a5a0061f | 3381 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) { |
59a9ed5f SH |
3382 | if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) { |
3383 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
3384 | "eckd suc: device already notified"); | |
3385 | return; | |
3386 | } | |
3387 | sense = dasd_get_sense(irb); | |
3388 | if (!sense) { | |
3389 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
3390 | "eckd suc: no reason code available"); | |
3391 | clear_bit(DASD_FLAG_SUC, &device->flags); | |
3392 | return; | |
3393 | ||
3394 | } | |
3395 | private->suc_reason = sense[8]; | |
3396 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x", | |
3397 | "eckd handle summary unit check: reason", | |
3398 | private->suc_reason); | |
3399 | dasd_get_device(device); | |
3400 | if (!schedule_work(&device->suc_work)) | |
3401 | dasd_put_device(device); | |
3402 | ||
8e09f215 SW |
3403 | return; |
3404 | } | |
3405 | ||
f60c768c | 3406 | /* service information message SIM */ |
5a27e60d | 3407 | if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) && |
f3eb5384 SW |
3408 | ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
3409 | dasd_3990_erp_handle_sim(device, sense); | |
f60c768c SH |
3410 | return; |
3411 | } | |
3412 | ||
5a27e60d SW |
3413 | /* loss of device reservation is handled via base devices only |
3414 | * as alias devices may be used with several bases | |
3415 | */ | |
c7a29e56 SW |
3416 | if (device->block && (sense[27] & DASD_SENSE_BIT_0) && |
3417 | (sense[7] == 0x3F) && | |
5a27e60d SW |
3418 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
3419 | test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) { | |
3420 | if (device->features & DASD_FEATURE_FAILONSLCK) | |
3421 | set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); | |
3422 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
3423 | dev_err(&device->cdev->dev, | |
3424 | "The device reservation was lost\n"); | |
ada3df91 | 3425 | } |
5a27e60d | 3426 | } |
f3eb5384 | 3427 | |
91dc4a19 JH |
3428 | static int dasd_eckd_ras_sanity_checks(struct dasd_device *device, |
3429 | unsigned int first_trk, | |
3430 | unsigned int last_trk) | |
3431 | { | |
3432 | struct dasd_eckd_private *private = device->private; | |
3433 | unsigned int trks_per_vol; | |
3434 | int rc = 0; | |
3435 | ||
3436 | trks_per_vol = private->real_cyl * private->rdc_data.trk_per_cyl; | |
3437 | ||
3438 | if (first_trk >= trks_per_vol) { | |
3439 | dev_warn(&device->cdev->dev, | |
3440 | "Start track number %u used in the space release command is too big\n", | |
3441 | first_trk); | |
3442 | rc = -EINVAL; | |
3443 | } else if (last_trk >= trks_per_vol) { | |
3444 | dev_warn(&device->cdev->dev, | |
3445 | "Stop track number %u used in the space release command is too big\n", | |
3446 | last_trk); | |
3447 | rc = -EINVAL; | |
3448 | } else if (first_trk > last_trk) { | |
3449 | dev_warn(&device->cdev->dev, | |
3450 | "Start track %u used in the space release command exceeds the end track\n", | |
3451 | first_trk); | |
3452 | rc = -EINVAL; | |
3453 | } | |
3454 | return rc; | |
3455 | } | |
3456 | ||
3457 | /* | |
3458 | * Helper function to count the amount of involved extents within a given range | |
3459 | * with extent alignment in mind. | |
3460 | */ | |
3461 | static int count_exts(unsigned int from, unsigned int to, int trks_per_ext) | |
3462 | { | |
3463 | int cur_pos = 0; | |
3464 | int count = 0; | |
3465 | int tmp; | |
3466 | ||
3467 | if (from == to) | |
3468 | return 1; | |
3469 | ||
3470 | /* Count first partial extent */ | |
3471 | if (from % trks_per_ext != 0) { | |
3472 | tmp = from + trks_per_ext - (from % trks_per_ext) - 1; | |
3473 | if (tmp > to) | |
3474 | tmp = to; | |
3475 | cur_pos = tmp - from + 1; | |
3476 | count++; | |
3477 | } | |
3478 | /* Count full extents */ | |
3479 | if (to - (from + cur_pos) + 1 >= trks_per_ext) { | |
3480 | tmp = to - ((to - trks_per_ext + 1) % trks_per_ext); | |
3481 | count += (tmp - (from + cur_pos) + 1) / trks_per_ext; | |
3482 | cur_pos = tmp; | |
3483 | } | |
3484 | /* Count last partial extent */ | |
3485 | if (cur_pos < to) | |
3486 | count++; | |
3487 | ||
3488 | return count; | |
3489 | } | |
3490 | ||
3491 | /* | |
3492 | * Release allocated space for a given range or an entire volume. | |
3493 | */ | |
3494 | static struct dasd_ccw_req * | |
3495 | dasd_eckd_dso_ras(struct dasd_device *device, struct dasd_block *block, | |
3496 | struct request *req, unsigned int first_trk, | |
3497 | unsigned int last_trk, int by_extent) | |
3498 | { | |
3499 | struct dasd_eckd_private *private = device->private; | |
3500 | struct dasd_dso_ras_ext_range *ras_range; | |
3501 | struct dasd_rssd_features *features; | |
3502 | struct dasd_dso_ras_data *ras_data; | |
3503 | u16 heads, beg_head, end_head; | |
3504 | int cur_to_trk, cur_from_trk; | |
3505 | struct dasd_ccw_req *cqr; | |
3506 | u32 beg_cyl, end_cyl; | |
3507 | struct ccw1 *ccw; | |
3508 | int trks_per_ext; | |
3509 | size_t ras_size; | |
3510 | size_t size; | |
3511 | int nr_exts; | |
3512 | void *rq; | |
3513 | int i; | |
3514 | ||
3515 | if (dasd_eckd_ras_sanity_checks(device, first_trk, last_trk)) | |
3516 | return ERR_PTR(-EINVAL); | |
3517 | ||
3518 | rq = req ? blk_mq_rq_to_pdu(req) : NULL; | |
3519 | ||
3520 | features = &private->features; | |
3521 | ||
3522 | trks_per_ext = dasd_eckd_ext_size(device) * private->rdc_data.trk_per_cyl; | |
3523 | nr_exts = 0; | |
3524 | if (by_extent) | |
3525 | nr_exts = count_exts(first_trk, last_trk, trks_per_ext); | |
3526 | ras_size = sizeof(*ras_data); | |
3527 | size = ras_size + (nr_exts * sizeof(*ras_range)); | |
3528 | ||
3529 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, size, device, rq); | |
3530 | if (IS_ERR(cqr)) { | |
3531 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
3532 | "Could not allocate RAS request"); | |
3533 | return cqr; | |
3534 | } | |
3535 | ||
3536 | ras_data = cqr->data; | |
3537 | memset(ras_data, 0, size); | |
3538 | ||
3539 | ras_data->order = DSO_ORDER_RAS; | |
3540 | ras_data->flags.vol_type = 0; /* CKD volume */ | |
3541 | /* Release specified extents or entire volume */ | |
3542 | ras_data->op_flags.by_extent = by_extent; | |
3543 | /* | |
3544 | * This bit guarantees initialisation of tracks within an extent that is | |
3545 | * not fully specified, but is only supported with a certain feature | |
3546 | * subset. | |
3547 | */ | |
3548 | ras_data->op_flags.guarantee_init = !!(features->feature[56] & 0x01); | |
3549 | ras_data->lss = private->ned->ID; | |
3550 | ras_data->dev_addr = private->ned->unit_addr; | |
3551 | ras_data->nr_exts = nr_exts; | |
3552 | ||
3553 | if (by_extent) { | |
3554 | heads = private->rdc_data.trk_per_cyl; | |
3555 | cur_from_trk = first_trk; | |
3556 | cur_to_trk = first_trk + trks_per_ext - | |
3557 | (first_trk % trks_per_ext) - 1; | |
3558 | if (cur_to_trk > last_trk) | |
3559 | cur_to_trk = last_trk; | |
3560 | ras_range = (struct dasd_dso_ras_ext_range *)(cqr->data + ras_size); | |
3561 | ||
3562 | for (i = 0; i < nr_exts; i++) { | |
3563 | beg_cyl = cur_from_trk / heads; | |
3564 | beg_head = cur_from_trk % heads; | |
3565 | end_cyl = cur_to_trk / heads; | |
3566 | end_head = cur_to_trk % heads; | |
3567 | ||
3568 | set_ch_t(&ras_range->beg_ext, beg_cyl, beg_head); | |
3569 | set_ch_t(&ras_range->end_ext, end_cyl, end_head); | |
3570 | ||
3571 | cur_from_trk = cur_to_trk + 1; | |
3572 | cur_to_trk = cur_from_trk + trks_per_ext - 1; | |
3573 | if (cur_to_trk > last_trk) | |
3574 | cur_to_trk = last_trk; | |
3575 | ras_range++; | |
3576 | } | |
3577 | } | |
3578 | ||
3579 | ccw = cqr->cpaddr; | |
3580 | ccw->cda = (__u32)(addr_t)cqr->data; | |
3581 | ccw->cmd_code = DASD_ECKD_CCW_DSO; | |
3582 | ccw->count = size; | |
3583 | ||
3584 | cqr->startdev = device; | |
3585 | cqr->memdev = device; | |
3586 | cqr->block = block; | |
3587 | cqr->retries = 256; | |
3588 | cqr->expires = device->default_expires * HZ; | |
3589 | cqr->buildclk = get_tod_clock(); | |
3590 | cqr->status = DASD_CQR_FILLED; | |
3591 | ||
3592 | return cqr; | |
3593 | } | |
3594 | ||
3595 | static int dasd_eckd_release_space_full(struct dasd_device *device) | |
3596 | { | |
3597 | struct dasd_ccw_req *cqr; | |
3598 | int rc; | |
3599 | ||
3600 | cqr = dasd_eckd_dso_ras(device, NULL, NULL, 0, 0, 0); | |
3601 | if (IS_ERR(cqr)) | |
3602 | return PTR_ERR(cqr); | |
3603 | ||
3604 | rc = dasd_sleep_on_interruptible(cqr); | |
3605 | ||
3606 | dasd_sfree_request(cqr, cqr->memdev); | |
3607 | ||
3608 | return rc; | |
3609 | } | |
3610 | ||
3611 | static int dasd_eckd_release_space_trks(struct dasd_device *device, | |
3612 | unsigned int from, unsigned int to) | |
3613 | { | |
3614 | struct dasd_eckd_private *private = device->private; | |
3615 | struct dasd_block *block = device->block; | |
3616 | struct dasd_ccw_req *cqr, *n; | |
3617 | struct list_head ras_queue; | |
3618 | unsigned int device_exts; | |
3619 | int trks_per_ext; | |
3620 | int stop, step; | |
3621 | int cur_pos; | |
3622 | int rc = 0; | |
3623 | int retry; | |
3624 | ||
3625 | INIT_LIST_HEAD(&ras_queue); | |
3626 | ||
3627 | device_exts = private->real_cyl / dasd_eckd_ext_size(device); | |
3628 | trks_per_ext = dasd_eckd_ext_size(device) * private->rdc_data.trk_per_cyl; | |
3629 | ||
3630 | /* Make sure device limits are not exceeded */ | |
3631 | step = trks_per_ext * min(device_exts, DASD_ECKD_RAS_EXTS_MAX); | |
3632 | cur_pos = from; | |
3633 | ||
3634 | do { | |
3635 | retry = 0; | |
3636 | while (cur_pos < to) { | |
3637 | stop = cur_pos + step - | |
3638 | ((cur_pos + step) % trks_per_ext) - 1; | |
3639 | if (stop > to) | |
3640 | stop = to; | |
3641 | ||
3642 | cqr = dasd_eckd_dso_ras(device, NULL, NULL, cur_pos, stop, 1); | |
3643 | if (IS_ERR(cqr)) { | |
3644 | rc = PTR_ERR(cqr); | |
3645 | if (rc == -ENOMEM) { | |
3646 | if (list_empty(&ras_queue)) | |
3647 | goto out; | |
3648 | retry = 1; | |
3649 | break; | |
3650 | } | |
3651 | goto err_out; | |
3652 | } | |
3653 | ||
3654 | spin_lock_irq(&block->queue_lock); | |
3655 | list_add_tail(&cqr->blocklist, &ras_queue); | |
3656 | spin_unlock_irq(&block->queue_lock); | |
3657 | cur_pos = stop + 1; | |
3658 | } | |
3659 | ||
3660 | rc = dasd_sleep_on_queue_interruptible(&ras_queue); | |
3661 | ||
3662 | err_out: | |
3663 | list_for_each_entry_safe(cqr, n, &ras_queue, blocklist) { | |
3664 | device = cqr->startdev; | |
3665 | private = device->private; | |
3666 | ||
3667 | spin_lock_irq(&block->queue_lock); | |
3668 | list_del_init(&cqr->blocklist); | |
3669 | spin_unlock_irq(&block->queue_lock); | |
3670 | dasd_sfree_request(cqr, device); | |
3671 | private->count--; | |
3672 | } | |
3673 | } while (retry); | |
3674 | ||
3675 | out: | |
3676 | return rc; | |
3677 | } | |
3678 | ||
3679 | static int dasd_eckd_release_space(struct dasd_device *device, | |
3680 | struct format_data_t *rdata) | |
3681 | { | |
3682 | if (rdata->intensity & DASD_FMT_INT_ESE_FULL) | |
3683 | return dasd_eckd_release_space_full(device); | |
3684 | else if (rdata->intensity == 0) | |
3685 | return dasd_eckd_release_space_trks(device, rdata->start_unit, | |
3686 | rdata->stop_unit); | |
3687 | else | |
3688 | return -EINVAL; | |
3689 | } | |
3690 | ||
f3eb5384 SW |
3691 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( |
3692 | struct dasd_device *startdev, | |
8e09f215 | 3693 | struct dasd_block *block, |
f3eb5384 SW |
3694 | struct request *req, |
3695 | sector_t first_rec, | |
3696 | sector_t last_rec, | |
3697 | sector_t first_trk, | |
3698 | sector_t last_trk, | |
3699 | unsigned int first_offs, | |
3700 | unsigned int last_offs, | |
3701 | unsigned int blk_per_trk, | |
3702 | unsigned int blksize) | |
1da177e4 LT |
3703 | { |
3704 | struct dasd_eckd_private *private; | |
3705 | unsigned long *idaws; | |
3706 | struct LO_eckd_data *LO_data; | |
3707 | struct dasd_ccw_req *cqr; | |
3708 | struct ccw1 *ccw; | |
5705f702 | 3709 | struct req_iterator iter; |
7988613b | 3710 | struct bio_vec bv; |
1da177e4 | 3711 | char *dst; |
f3eb5384 | 3712 | unsigned int off; |
1da177e4 | 3713 | int count, cidaw, cplength, datasize; |
f3eb5384 | 3714 | sector_t recid; |
1da177e4 | 3715 | unsigned char cmd, rcmd; |
8e09f215 SW |
3716 | int use_prefix; |
3717 | struct dasd_device *basedev; | |
1da177e4 | 3718 | |
8e09f215 | 3719 | basedev = block->base; |
543691a4 | 3720 | private = basedev->private; |
1da177e4 LT |
3721 | if (rq_data_dir(req) == READ) |
3722 | cmd = DASD_ECKD_CCW_READ_MT; | |
3723 | else if (rq_data_dir(req) == WRITE) | |
3724 | cmd = DASD_ECKD_CCW_WRITE_MT; | |
3725 | else | |
3726 | return ERR_PTR(-EINVAL); | |
f3eb5384 | 3727 | |
1da177e4 LT |
3728 | /* Check struct bio and count the number of blocks for the request. */ |
3729 | count = 0; | |
3730 | cidaw = 0; | |
5705f702 | 3731 | rq_for_each_segment(bv, req, iter) { |
7988613b | 3732 | if (bv.bv_len & (blksize - 1)) |
6c92e699 JA |
3733 | /* Eckd can only do full blocks. */ |
3734 | return ERR_PTR(-EINVAL); | |
7988613b | 3735 | count += bv.bv_len >> (block->s2b_shift + 9); |
7988613b KO |
3736 | if (idal_is_needed (page_address(bv.bv_page), bv.bv_len)) |
3737 | cidaw += bv.bv_len >> (block->s2b_shift + 9); | |
1da177e4 LT |
3738 | } |
3739 | /* Paranoia. */ | |
3740 | if (count != last_rec - first_rec + 1) | |
3741 | return ERR_PTR(-EINVAL); | |
8e09f215 SW |
3742 | |
3743 | /* use the prefix command if available */ | |
3744 | use_prefix = private->features.feature[8] & 0x01; | |
3745 | if (use_prefix) { | |
3746 | /* 1x prefix + number of blocks */ | |
3747 | cplength = 2 + count; | |
3748 | /* 1x prefix + cidaws*sizeof(long) */ | |
3749 | datasize = sizeof(struct PFX_eckd_data) + | |
3750 | sizeof(struct LO_eckd_data) + | |
3751 | cidaw * sizeof(unsigned long); | |
3752 | } else { | |
3753 | /* 1x define extent + 1x locate record + number of blocks */ | |
3754 | cplength = 2 + count; | |
3755 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ | |
3756 | datasize = sizeof(struct DE_eckd_data) + | |
3757 | sizeof(struct LO_eckd_data) + | |
3758 | cidaw * sizeof(unsigned long); | |
3759 | } | |
1da177e4 LT |
3760 | /* Find out the number of additional locate record ccws for cdl. */ |
3761 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { | |
3762 | if (last_rec >= 2*blk_per_trk) | |
3763 | count = 2*blk_per_trk - first_rec; | |
3764 | cplength += count; | |
3765 | datasize += count*sizeof(struct LO_eckd_data); | |
3766 | } | |
3767 | /* Allocate the ccw request. */ | |
68b781fe | 3768 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
c5205f2f | 3769 | startdev, blk_mq_rq_to_pdu(req)); |
1da177e4 LT |
3770 | if (IS_ERR(cqr)) |
3771 | return cqr; | |
3772 | ccw = cqr->cpaddr; | |
8e09f215 SW |
3773 | /* First ccw is define extent or prefix. */ |
3774 | if (use_prefix) { | |
3775 | if (prefix(ccw++, cqr->data, first_trk, | |
3776 | last_trk, cmd, basedev, startdev) == -EAGAIN) { | |
3777 | /* Clock not in sync and XRC is enabled. | |
3778 | * Try again later. | |
3779 | */ | |
3780 | dasd_sfree_request(cqr, startdev); | |
3781 | return ERR_PTR(-EAGAIN); | |
3782 | } | |
3783 | idaws = (unsigned long *) (cqr->data + | |
3784 | sizeof(struct PFX_eckd_data)); | |
3785 | } else { | |
3786 | if (define_extent(ccw++, cqr->data, first_trk, | |
45f186be | 3787 | last_trk, cmd, basedev, 0) == -EAGAIN) { |
8e09f215 SW |
3788 | /* Clock not in sync and XRC is enabled. |
3789 | * Try again later. | |
3790 | */ | |
3791 | dasd_sfree_request(cqr, startdev); | |
3792 | return ERR_PTR(-EAGAIN); | |
3793 | } | |
3794 | idaws = (unsigned long *) (cqr->data + | |
3795 | sizeof(struct DE_eckd_data)); | |
d54853ef | 3796 | } |
1da177e4 | 3797 | /* Build locate_record+read/write/ccws. */ |
1da177e4 LT |
3798 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
3799 | recid = first_rec; | |
3800 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { | |
3801 | /* Only standard blocks so there is just one locate record. */ | |
3802 | ccw[-1].flags |= CCW_FLAG_CC; | |
3803 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, | |
8e09f215 | 3804 | last_rec - recid + 1, cmd, basedev, blksize); |
1da177e4 | 3805 | } |
5705f702 | 3806 | rq_for_each_segment(bv, req, iter) { |
7988613b | 3807 | dst = page_address(bv.bv_page) + bv.bv_offset; |
1da177e4 LT |
3808 | if (dasd_page_cache) { |
3809 | char *copy = kmem_cache_alloc(dasd_page_cache, | |
441e143e | 3810 | GFP_DMA | __GFP_NOWARN); |
1da177e4 | 3811 | if (copy && rq_data_dir(req) == WRITE) |
7988613b | 3812 | memcpy(copy + bv.bv_offset, dst, bv.bv_len); |
1da177e4 | 3813 | if (copy) |
7988613b | 3814 | dst = copy + bv.bv_offset; |
1da177e4 | 3815 | } |
7988613b | 3816 | for (off = 0; off < bv.bv_len; off += blksize) { |
1da177e4 LT |
3817 | sector_t trkid = recid; |
3818 | unsigned int recoffs = sector_div(trkid, blk_per_trk); | |
3819 | rcmd = cmd; | |
3820 | count = blksize; | |
3821 | /* Locate record for cdl special block ? */ | |
3822 | if (private->uses_cdl && recid < 2*blk_per_trk) { | |
3823 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ | |
3824 | rcmd |= 0x8; | |
3825 | count = dasd_eckd_cdl_reclen(recid); | |
ec5883ab HH |
3826 | if (count < blksize && |
3827 | rq_data_dir(req) == READ) | |
1da177e4 LT |
3828 | memset(dst + count, 0xe5, |
3829 | blksize - count); | |
3830 | } | |
3831 | ccw[-1].flags |= CCW_FLAG_CC; | |
3832 | locate_record(ccw++, LO_data++, | |
3833 | trkid, recoffs + 1, | |
8e09f215 | 3834 | 1, rcmd, basedev, count); |
1da177e4 LT |
3835 | } |
3836 | /* Locate record for standard blocks ? */ | |
3837 | if (private->uses_cdl && recid == 2*blk_per_trk) { | |
3838 | ccw[-1].flags |= CCW_FLAG_CC; | |
3839 | locate_record(ccw++, LO_data++, | |
3840 | trkid, recoffs + 1, | |
3841 | last_rec - recid + 1, | |
8e09f215 | 3842 | cmd, basedev, count); |
1da177e4 LT |
3843 | } |
3844 | /* Read/write ccw. */ | |
3845 | ccw[-1].flags |= CCW_FLAG_CC; | |
3846 | ccw->cmd_code = rcmd; | |
3847 | ccw->count = count; | |
3848 | if (idal_is_needed(dst, blksize)) { | |
3849 | ccw->cda = (__u32)(addr_t) idaws; | |
3850 | ccw->flags = CCW_FLAG_IDA; | |
3851 | idaws = idal_create_words(idaws, dst, blksize); | |
3852 | } else { | |
3853 | ccw->cda = (__u32)(addr_t) dst; | |
3854 | ccw->flags = 0; | |
3855 | } | |
3856 | ccw++; | |
3857 | dst += blksize; | |
3858 | recid++; | |
3859 | } | |
3860 | } | |
13de227b HS |
3861 | if (blk_noretry_request(req) || |
3862 | block->base->features & DASD_FEATURE_FAILFAST) | |
1c01b8a5 | 3863 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
8e09f215 SW |
3864 | cqr->startdev = startdev; |
3865 | cqr->memdev = startdev; | |
3866 | cqr->block = block; | |
7c8faa86 | 3867 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
c9346151 | 3868 | cqr->lpm = dasd_path_get_ppm(startdev); |
1f1ee9ad | 3869 | cqr->retries = startdev->default_retries; |
1aae0560 | 3870 | cqr->buildclk = get_tod_clock(); |
1da177e4 | 3871 | cqr->status = DASD_CQR_FILLED; |
5e2b17e7 JH |
3872 | |
3873 | /* Set flags to suppress output for expected errors */ | |
3874 | if (dasd_eckd_is_ese(basedev)) { | |
3875 | set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags); | |
3876 | set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags); | |
3877 | set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); | |
3878 | } | |
3879 | ||
1da177e4 LT |
3880 | return cqr; |
3881 | } | |
3882 | ||
f3eb5384 SW |
3883 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( |
3884 | struct dasd_device *startdev, | |
3885 | struct dasd_block *block, | |
3886 | struct request *req, | |
3887 | sector_t first_rec, | |
3888 | sector_t last_rec, | |
3889 | sector_t first_trk, | |
3890 | sector_t last_trk, | |
3891 | unsigned int first_offs, | |
3892 | unsigned int last_offs, | |
3893 | unsigned int blk_per_trk, | |
3894 | unsigned int blksize) | |
3895 | { | |
f3eb5384 SW |
3896 | unsigned long *idaws; |
3897 | struct dasd_ccw_req *cqr; | |
3898 | struct ccw1 *ccw; | |
3899 | struct req_iterator iter; | |
7988613b | 3900 | struct bio_vec bv; |
f3eb5384 SW |
3901 | char *dst, *idaw_dst; |
3902 | unsigned int cidaw, cplength, datasize; | |
3903 | unsigned int tlf; | |
3904 | sector_t recid; | |
3905 | unsigned char cmd; | |
3906 | struct dasd_device *basedev; | |
3907 | unsigned int trkcount, count, count_to_trk_end; | |
3908 | unsigned int idaw_len, seg_len, part_len, len_to_track_end; | |
3909 | unsigned char new_track, end_idaw; | |
3910 | sector_t trkid; | |
3911 | unsigned int recoffs; | |
3912 | ||
3913 | basedev = block->base; | |
f3eb5384 SW |
3914 | if (rq_data_dir(req) == READ) |
3915 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; | |
3916 | else if (rq_data_dir(req) == WRITE) | |
3917 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; | |
3918 | else | |
3919 | return ERR_PTR(-EINVAL); | |
3920 | ||
3921 | /* Track based I/O needs IDAWs for each page, and not just for | |
3922 | * 64 bit addresses. We need additional idals for pages | |
3923 | * that get filled from two tracks, so we use the number | |
3924 | * of records as upper limit. | |
3925 | */ | |
3926 | cidaw = last_rec - first_rec + 1; | |
3927 | trkcount = last_trk - first_trk + 1; | |
3928 | ||
3929 | /* 1x prefix + one read/write ccw per track */ | |
3930 | cplength = 1 + trkcount; | |
3931 | ||
7bf76f01 | 3932 | datasize = sizeof(struct PFX_eckd_data) + cidaw * sizeof(unsigned long); |
f3eb5384 SW |
3933 | |
3934 | /* Allocate the ccw request. */ | |
68b781fe | 3935 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
c5205f2f | 3936 | startdev, blk_mq_rq_to_pdu(req)); |
f3eb5384 SW |
3937 | if (IS_ERR(cqr)) |
3938 | return cqr; | |
3939 | ccw = cqr->cpaddr; | |
3940 | /* transfer length factor: how many bytes to read from the last track */ | |
3941 | if (first_trk == last_trk) | |
3942 | tlf = last_offs - first_offs + 1; | |
3943 | else | |
3944 | tlf = last_offs + 1; | |
3945 | tlf *= blksize; | |
3946 | ||
3947 | if (prefix_LRE(ccw++, cqr->data, first_trk, | |
3948 | last_trk, cmd, basedev, startdev, | |
3949 | 1 /* format */, first_offs + 1, | |
3950 | trkcount, blksize, | |
3951 | tlf) == -EAGAIN) { | |
3952 | /* Clock not in sync and XRC is enabled. | |
3953 | * Try again later. | |
3954 | */ | |
3955 | dasd_sfree_request(cqr, startdev); | |
3956 | return ERR_PTR(-EAGAIN); | |
3957 | } | |
3958 | ||
3959 | /* | |
3960 | * The translation of request into ccw programs must meet the | |
3961 | * following conditions: | |
3962 | * - all idaws but the first and the last must address full pages | |
3963 | * (or 2K blocks on 31-bit) | |
3964 | * - the scope of a ccw and it's idal ends with the track boundaries | |
3965 | */ | |
3966 | idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); | |
3967 | recid = first_rec; | |
3968 | new_track = 1; | |
3969 | end_idaw = 0; | |
3970 | len_to_track_end = 0; | |
246ccea1 | 3971 | idaw_dst = NULL; |
f3eb5384 SW |
3972 | idaw_len = 0; |
3973 | rq_for_each_segment(bv, req, iter) { | |
7988613b KO |
3974 | dst = page_address(bv.bv_page) + bv.bv_offset; |
3975 | seg_len = bv.bv_len; | |
f3eb5384 SW |
3976 | while (seg_len) { |
3977 | if (new_track) { | |
3978 | trkid = recid; | |
3979 | recoffs = sector_div(trkid, blk_per_trk); | |
3980 | count_to_trk_end = blk_per_trk - recoffs; | |
3981 | count = min((last_rec - recid + 1), | |
3982 | (sector_t)count_to_trk_end); | |
3983 | len_to_track_end = count * blksize; | |
3984 | ccw[-1].flags |= CCW_FLAG_CC; | |
3985 | ccw->cmd_code = cmd; | |
3986 | ccw->count = len_to_track_end; | |
3987 | ccw->cda = (__u32)(addr_t)idaws; | |
3988 | ccw->flags = CCW_FLAG_IDA; | |
3989 | ccw++; | |
3990 | recid += count; | |
3991 | new_track = 0; | |
52db45c3 SW |
3992 | /* first idaw for a ccw may start anywhere */ |
3993 | if (!idaw_dst) | |
3994 | idaw_dst = dst; | |
f3eb5384 | 3995 | } |
52db45c3 SW |
3996 | /* If we start a new idaw, we must make sure that it |
3997 | * starts on an IDA_BLOCK_SIZE boundary. | |
f3eb5384 SW |
3998 | * If we continue an idaw, we must make sure that the |
3999 | * current segment begins where the so far accumulated | |
4000 | * idaw ends | |
4001 | */ | |
52db45c3 SW |
4002 | if (!idaw_dst) { |
4003 | if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { | |
4004 | dasd_sfree_request(cqr, startdev); | |
4005 | return ERR_PTR(-ERANGE); | |
4006 | } else | |
4007 | idaw_dst = dst; | |
4008 | } | |
f3eb5384 SW |
4009 | if ((idaw_dst + idaw_len) != dst) { |
4010 | dasd_sfree_request(cqr, startdev); | |
4011 | return ERR_PTR(-ERANGE); | |
4012 | } | |
4013 | part_len = min(seg_len, len_to_track_end); | |
4014 | seg_len -= part_len; | |
4015 | dst += part_len; | |
4016 | idaw_len += part_len; | |
4017 | len_to_track_end -= part_len; | |
4018 | /* collected memory area ends on an IDA_BLOCK border, | |
4019 | * -> create an idaw | |
4020 | * idal_create_words will handle cases where idaw_len | |
4021 | * is larger then IDA_BLOCK_SIZE | |
4022 | */ | |
4023 | if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) | |
4024 | end_idaw = 1; | |
4025 | /* We also need to end the idaw at track end */ | |
4026 | if (!len_to_track_end) { | |
4027 | new_track = 1; | |
4028 | end_idaw = 1; | |
4029 | } | |
4030 | if (end_idaw) { | |
4031 | idaws = idal_create_words(idaws, idaw_dst, | |
4032 | idaw_len); | |
246ccea1 | 4033 | idaw_dst = NULL; |
f3eb5384 SW |
4034 | idaw_len = 0; |
4035 | end_idaw = 0; | |
4036 | } | |
4037 | } | |
4038 | } | |
4039 | ||
4040 | if (blk_noretry_request(req) || | |
4041 | block->base->features & DASD_FEATURE_FAILFAST) | |
4042 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
4043 | cqr->startdev = startdev; | |
4044 | cqr->memdev = startdev; | |
4045 | cqr->block = block; | |
7c8faa86 | 4046 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
c9346151 | 4047 | cqr->lpm = dasd_path_get_ppm(startdev); |
1f1ee9ad | 4048 | cqr->retries = startdev->default_retries; |
1aae0560 | 4049 | cqr->buildclk = get_tod_clock(); |
f3eb5384 | 4050 | cqr->status = DASD_CQR_FILLED; |
5e2b17e7 JH |
4051 | |
4052 | /* Set flags to suppress output for expected errors */ | |
4053 | if (dasd_eckd_is_ese(basedev)) | |
4054 | set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); | |
4055 | ||
f3eb5384 SW |
4056 | return cqr; |
4057 | } | |
4058 | ||
4059 | static int prepare_itcw(struct itcw *itcw, | |
4060 | unsigned int trk, unsigned int totrk, int cmd, | |
4061 | struct dasd_device *basedev, | |
4062 | struct dasd_device *startdev, | |
4063 | unsigned int rec_on_trk, int count, | |
4064 | unsigned int blksize, | |
4065 | unsigned int total_data_size, | |
4066 | unsigned int tlf, | |
4067 | unsigned int blk_per_trk) | |
4068 | { | |
4069 | struct PFX_eckd_data pfxdata; | |
4070 | struct dasd_eckd_private *basepriv, *startpriv; | |
4071 | struct DE_eckd_data *dedata; | |
4072 | struct LRE_eckd_data *lredata; | |
4073 | struct dcw *dcw; | |
4074 | ||
4075 | u32 begcyl, endcyl; | |
4076 | u16 heads, beghead, endhead; | |
4077 | u8 pfx_cmd; | |
4078 | ||
4079 | int rc = 0; | |
4080 | int sector = 0; | |
4081 | int dn, d; | |
4082 | ||
4083 | ||
4084 | /* setup prefix data */ | |
543691a4 SO |
4085 | basepriv = basedev->private; |
4086 | startpriv = startdev->private; | |
f3eb5384 SW |
4087 | dedata = &pfxdata.define_extent; |
4088 | lredata = &pfxdata.locate_record; | |
4089 | ||
4090 | memset(&pfxdata, 0, sizeof(pfxdata)); | |
4091 | pfxdata.format = 1; /* PFX with LRE */ | |
4092 | pfxdata.base_address = basepriv->ned->unit_addr; | |
4093 | pfxdata.base_lss = basepriv->ned->ID; | |
4094 | pfxdata.validity.define_extent = 1; | |
4095 | ||
4096 | /* private uid is kept up to date, conf_data may be outdated */ | |
da340f92 SH |
4097 | if (startpriv->uid.type == UA_BASE_PAV_ALIAS) |
4098 | pfxdata.validity.verify_base = 1; | |
4099 | ||
4100 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) { | |
f3eb5384 | 4101 | pfxdata.validity.verify_base = 1; |
da340f92 | 4102 | pfxdata.validity.hyper_pav = 1; |
f3eb5384 SW |
4103 | } |
4104 | ||
4105 | switch (cmd) { | |
4106 | case DASD_ECKD_CCW_READ_TRACK_DATA: | |
4107 | dedata->mask.perm = 0x1; | |
4108 | dedata->attributes.operation = basepriv->attrib.operation; | |
4109 | dedata->blk_size = blksize; | |
4110 | dedata->ga_extended |= 0x42; | |
4111 | lredata->operation.orientation = 0x0; | |
4112 | lredata->operation.operation = 0x0C; | |
4113 | lredata->auxiliary.check_bytes = 0x01; | |
4114 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; | |
4115 | break; | |
4116 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: | |
4117 | dedata->mask.perm = 0x02; | |
4118 | dedata->attributes.operation = basepriv->attrib.operation; | |
4119 | dedata->blk_size = blksize; | |
5628683c | 4120 | rc = set_timestamp(NULL, dedata, basedev); |
f3eb5384 SW |
4121 | dedata->ga_extended |= 0x42; |
4122 | lredata->operation.orientation = 0x0; | |
4123 | lredata->operation.operation = 0x3F; | |
4124 | lredata->extended_operation = 0x23; | |
4125 | lredata->auxiliary.check_bytes = 0x2; | |
45f186be JH |
4126 | /* |
4127 | * If XRC is supported the System Time Stamp is set. The | |
4128 | * validity of the time stamp must be reflected in the prefix | |
4129 | * data as well. | |
4130 | */ | |
4131 | if (dedata->ga_extended & 0x08 && dedata->ga_extended & 0x02) | |
4132 | pfxdata.validity.time_stamp = 1; /* 'Time Stamp Valid' */ | |
f3eb5384 SW |
4133 | pfx_cmd = DASD_ECKD_CCW_PFX; |
4134 | break; | |
8fd57520 JH |
4135 | case DASD_ECKD_CCW_READ_COUNT_MT: |
4136 | dedata->mask.perm = 0x1; | |
4137 | dedata->attributes.operation = DASD_BYPASS_CACHE; | |
4138 | dedata->ga_extended |= 0x42; | |
4139 | dedata->blk_size = blksize; | |
4140 | lredata->operation.orientation = 0x2; | |
4141 | lredata->operation.operation = 0x16; | |
4142 | lredata->auxiliary.check_bytes = 0x01; | |
4143 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; | |
4144 | break; | |
f3eb5384 SW |
4145 | default: |
4146 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
4147 | "prepare itcw, unknown opcode 0x%x", cmd); | |
4148 | BUG(); | |
4149 | break; | |
4150 | } | |
4151 | if (rc) | |
4152 | return rc; | |
4153 | ||
4154 | dedata->attributes.mode = 0x3; /* ECKD */ | |
4155 | ||
4156 | heads = basepriv->rdc_data.trk_per_cyl; | |
4157 | begcyl = trk / heads; | |
4158 | beghead = trk % heads; | |
4159 | endcyl = totrk / heads; | |
4160 | endhead = totrk % heads; | |
4161 | ||
4162 | /* check for sequential prestage - enhance cylinder range */ | |
4163 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || | |
4164 | dedata->attributes.operation == DASD_SEQ_ACCESS) { | |
4165 | ||
4166 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) | |
4167 | endcyl += basepriv->attrib.nr_cyl; | |
4168 | else | |
4169 | endcyl = (basepriv->real_cyl - 1); | |
4170 | } | |
4171 | ||
4172 | set_ch_t(&dedata->beg_ext, begcyl, beghead); | |
4173 | set_ch_t(&dedata->end_ext, endcyl, endhead); | |
4174 | ||
4175 | dedata->ep_format = 0x20; /* records per track is valid */ | |
4176 | dedata->ep_rec_per_track = blk_per_trk; | |
4177 | ||
4178 | if (rec_on_trk) { | |
4179 | switch (basepriv->rdc_data.dev_type) { | |
4180 | case 0x3390: | |
4181 | dn = ceil_quot(blksize + 6, 232); | |
4182 | d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); | |
4183 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
4184 | break; | |
4185 | case 0x3380: | |
4186 | d = 7 + ceil_quot(blksize + 12, 32); | |
4187 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
4188 | break; | |
4189 | } | |
4190 | } | |
4191 | ||
8fd57520 JH |
4192 | if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) { |
4193 | lredata->auxiliary.length_valid = 0; | |
4194 | lredata->auxiliary.length_scope = 0; | |
4195 | lredata->sector = 0xff; | |
4196 | } else { | |
4197 | lredata->auxiliary.length_valid = 1; | |
4198 | lredata->auxiliary.length_scope = 1; | |
4199 | lredata->sector = sector; | |
4200 | } | |
f3eb5384 SW |
4201 | lredata->auxiliary.imbedded_ccw_valid = 1; |
4202 | lredata->length = tlf; | |
4203 | lredata->imbedded_ccw = cmd; | |
4204 | lredata->count = count; | |
f3eb5384 SW |
4205 | set_ch_t(&lredata->seek_addr, begcyl, beghead); |
4206 | lredata->search_arg.cyl = lredata->seek_addr.cyl; | |
4207 | lredata->search_arg.head = lredata->seek_addr.head; | |
4208 | lredata->search_arg.record = rec_on_trk; | |
4209 | ||
4210 | dcw = itcw_add_dcw(itcw, pfx_cmd, 0, | |
4211 | &pfxdata, sizeof(pfxdata), total_data_size); | |
757853ea | 4212 | return PTR_ERR_OR_ZERO(dcw); |
f3eb5384 SW |
4213 | } |
4214 | ||
4215 | static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( | |
4216 | struct dasd_device *startdev, | |
4217 | struct dasd_block *block, | |
4218 | struct request *req, | |
4219 | sector_t first_rec, | |
4220 | sector_t last_rec, | |
4221 | sector_t first_trk, | |
4222 | sector_t last_trk, | |
4223 | unsigned int first_offs, | |
4224 | unsigned int last_offs, | |
4225 | unsigned int blk_per_trk, | |
4226 | unsigned int blksize) | |
4227 | { | |
f3eb5384 SW |
4228 | struct dasd_ccw_req *cqr; |
4229 | struct req_iterator iter; | |
7988613b | 4230 | struct bio_vec bv; |
f3eb5384 SW |
4231 | char *dst; |
4232 | unsigned int trkcount, ctidaw; | |
4233 | unsigned char cmd; | |
4234 | struct dasd_device *basedev; | |
4235 | unsigned int tlf; | |
4236 | struct itcw *itcw; | |
4237 | struct tidaw *last_tidaw = NULL; | |
4238 | int itcw_op; | |
4239 | size_t itcw_size; | |
ef19298b SW |
4240 | u8 tidaw_flags; |
4241 | unsigned int seg_len, part_len, len_to_track_end; | |
4242 | unsigned char new_track; | |
4243 | sector_t recid, trkid; | |
4244 | unsigned int offs; | |
4245 | unsigned int count, count_to_trk_end; | |
cd10502b | 4246 | int ret; |
f3eb5384 SW |
4247 | |
4248 | basedev = block->base; | |
f3eb5384 SW |
4249 | if (rq_data_dir(req) == READ) { |
4250 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; | |
4251 | itcw_op = ITCW_OP_READ; | |
4252 | } else if (rq_data_dir(req) == WRITE) { | |
4253 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; | |
4254 | itcw_op = ITCW_OP_WRITE; | |
4255 | } else | |
4256 | return ERR_PTR(-EINVAL); | |
4257 | ||
4258 | /* trackbased I/O needs address all memory via TIDAWs, | |
4259 | * not just for 64 bit addresses. This allows us to map | |
4260 | * each segment directly to one tidaw. | |
ef19298b SW |
4261 | * In the case of write requests, additional tidaws may |
4262 | * be needed when a segment crosses a track boundary. | |
f3eb5384 SW |
4263 | */ |
4264 | trkcount = last_trk - first_trk + 1; | |
4265 | ctidaw = 0; | |
4266 | rq_for_each_segment(bv, req, iter) { | |
4267 | ++ctidaw; | |
4268 | } | |
ef19298b SW |
4269 | if (rq_data_dir(req) == WRITE) |
4270 | ctidaw += (last_trk - first_trk); | |
f3eb5384 SW |
4271 | |
4272 | /* Allocate the ccw request. */ | |
4273 | itcw_size = itcw_calc_size(0, ctidaw, 0); | |
c5205f2f SO |
4274 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev, |
4275 | blk_mq_rq_to_pdu(req)); | |
f3eb5384 SW |
4276 | if (IS_ERR(cqr)) |
4277 | return cqr; | |
4278 | ||
f3eb5384 SW |
4279 | /* transfer length factor: how many bytes to read from the last track */ |
4280 | if (first_trk == last_trk) | |
4281 | tlf = last_offs - first_offs + 1; | |
4282 | else | |
4283 | tlf = last_offs + 1; | |
4284 | tlf *= blksize; | |
4285 | ||
4286 | itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); | |
ef19298b | 4287 | if (IS_ERR(itcw)) { |
cd10502b JL |
4288 | ret = -EINVAL; |
4289 | goto out_error; | |
ef19298b | 4290 | } |
f3eb5384 | 4291 | cqr->cpaddr = itcw_get_tcw(itcw); |
f3eb5384 SW |
4292 | if (prepare_itcw(itcw, first_trk, last_trk, |
4293 | cmd, basedev, startdev, | |
4294 | first_offs + 1, | |
4295 | trkcount, blksize, | |
4296 | (last_rec - first_rec + 1) * blksize, | |
4297 | tlf, blk_per_trk) == -EAGAIN) { | |
4298 | /* Clock not in sync and XRC is enabled. | |
4299 | * Try again later. | |
4300 | */ | |
cd10502b JL |
4301 | ret = -EAGAIN; |
4302 | goto out_error; | |
f3eb5384 | 4303 | } |
d54cddb6 | 4304 | len_to_track_end = 0; |
f3eb5384 SW |
4305 | /* |
4306 | * A tidaw can address 4k of memory, but must not cross page boundaries | |
4307 | * We can let the block layer handle this by setting | |
4308 | * blk_queue_segment_boundary to page boundaries and | |
4309 | * blk_max_segment_size to page size when setting up the request queue. | |
ef19298b SW |
4310 | * For write requests, a TIDAW must not cross track boundaries, because |
4311 | * we have to set the CBC flag on the last tidaw for each track. | |
f3eb5384 | 4312 | */ |
ef19298b SW |
4313 | if (rq_data_dir(req) == WRITE) { |
4314 | new_track = 1; | |
4315 | recid = first_rec; | |
4316 | rq_for_each_segment(bv, req, iter) { | |
7988613b KO |
4317 | dst = page_address(bv.bv_page) + bv.bv_offset; |
4318 | seg_len = bv.bv_len; | |
ef19298b SW |
4319 | while (seg_len) { |
4320 | if (new_track) { | |
4321 | trkid = recid; | |
4322 | offs = sector_div(trkid, blk_per_trk); | |
4323 | count_to_trk_end = blk_per_trk - offs; | |
4324 | count = min((last_rec - recid + 1), | |
4325 | (sector_t)count_to_trk_end); | |
4326 | len_to_track_end = count * blksize; | |
4327 | recid += count; | |
4328 | new_track = 0; | |
4329 | } | |
4330 | part_len = min(seg_len, len_to_track_end); | |
4331 | seg_len -= part_len; | |
4332 | len_to_track_end -= part_len; | |
4333 | /* We need to end the tidaw at track end */ | |
4334 | if (!len_to_track_end) { | |
4335 | new_track = 1; | |
4336 | tidaw_flags = TIDAW_FLAGS_INSERT_CBC; | |
4337 | } else | |
4338 | tidaw_flags = 0; | |
4339 | last_tidaw = itcw_add_tidaw(itcw, tidaw_flags, | |
4340 | dst, part_len); | |
cd10502b JL |
4341 | if (IS_ERR(last_tidaw)) { |
4342 | ret = -EINVAL; | |
4343 | goto out_error; | |
4344 | } | |
ef19298b SW |
4345 | dst += part_len; |
4346 | } | |
4347 | } | |
4348 | } else { | |
4349 | rq_for_each_segment(bv, req, iter) { | |
7988613b | 4350 | dst = page_address(bv.bv_page) + bv.bv_offset; |
ef19298b | 4351 | last_tidaw = itcw_add_tidaw(itcw, 0x00, |
7988613b | 4352 | dst, bv.bv_len); |
cd10502b JL |
4353 | if (IS_ERR(last_tidaw)) { |
4354 | ret = -EINVAL; | |
4355 | goto out_error; | |
4356 | } | |
ef19298b | 4357 | } |
f3eb5384 | 4358 | } |
ef19298b SW |
4359 | last_tidaw->flags |= TIDAW_FLAGS_LAST; |
4360 | last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC; | |
f3eb5384 SW |
4361 | itcw_finalize(itcw); |
4362 | ||
4363 | if (blk_noretry_request(req) || | |
4364 | block->base->features & DASD_FEATURE_FAILFAST) | |
4365 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
ef19298b | 4366 | cqr->cpmode = 1; |
f3eb5384 SW |
4367 | cqr->startdev = startdev; |
4368 | cqr->memdev = startdev; | |
4369 | cqr->block = block; | |
7c8faa86 | 4370 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
c9346151 | 4371 | cqr->lpm = dasd_path_get_ppm(startdev); |
1f1ee9ad | 4372 | cqr->retries = startdev->default_retries; |
1aae0560 | 4373 | cqr->buildclk = get_tod_clock(); |
f3eb5384 | 4374 | cqr->status = DASD_CQR_FILLED; |
5e2b17e7 JH |
4375 | |
4376 | /* Set flags to suppress output for expected errors */ | |
4377 | if (dasd_eckd_is_ese(basedev)) { | |
4378 | set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags); | |
4379 | set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags); | |
4380 | set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); | |
4381 | } | |
4382 | ||
f3eb5384 | 4383 | return cqr; |
cd10502b JL |
4384 | out_error: |
4385 | dasd_sfree_request(cqr, startdev); | |
4386 | return ERR_PTR(ret); | |
f3eb5384 SW |
4387 | } |
4388 | ||
4389 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, | |
4390 | struct dasd_block *block, | |
4391 | struct request *req) | |
4392 | { | |
ef19298b | 4393 | int cmdrtd, cmdwtd; |
f3eb5384 | 4394 | int use_prefix; |
ef19298b | 4395 | int fcx_multitrack; |
45b44d76 | 4396 | struct dasd_eckd_private *private; |
f3eb5384 SW |
4397 | struct dasd_device *basedev; |
4398 | sector_t first_rec, last_rec; | |
4399 | sector_t first_trk, last_trk; | |
4400 | unsigned int first_offs, last_offs; | |
4401 | unsigned int blk_per_trk, blksize; | |
4402 | int cdlspecial; | |
ef19298b | 4403 | unsigned int data_size; |
f3eb5384 SW |
4404 | struct dasd_ccw_req *cqr; |
4405 | ||
4406 | basedev = block->base; | |
543691a4 | 4407 | private = basedev->private; |
f3eb5384 SW |
4408 | |
4409 | /* Calculate number of blocks/records per track. */ | |
4410 | blksize = block->bp_block; | |
4411 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); | |
6fca97a9 SH |
4412 | if (blk_per_trk == 0) |
4413 | return ERR_PTR(-EINVAL); | |
f3eb5384 | 4414 | /* Calculate record id of first and last block. */ |
83096ebf | 4415 | first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; |
f3eb5384 SW |
4416 | first_offs = sector_div(first_trk, blk_per_trk); |
4417 | last_rec = last_trk = | |
83096ebf | 4418 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
f3eb5384 SW |
4419 | last_offs = sector_div(last_trk, blk_per_trk); |
4420 | cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); | |
4421 | ||
ef19298b SW |
4422 | fcx_multitrack = private->features.feature[40] & 0x20; |
4423 | data_size = blk_rq_bytes(req); | |
26a35f37 SW |
4424 | if (data_size % blksize) |
4425 | return ERR_PTR(-EINVAL); | |
ef19298b SW |
4426 | /* tpm write request add CBC data on each track boundary */ |
4427 | if (rq_data_dir(req) == WRITE) | |
4428 | data_size += (last_trk - first_trk) * 4; | |
f3eb5384 SW |
4429 | |
4430 | /* is read track data and write track data in command mode supported? */ | |
4431 | cmdrtd = private->features.feature[9] & 0x20; | |
4432 | cmdwtd = private->features.feature[12] & 0x40; | |
4433 | use_prefix = private->features.feature[8] & 0x01; | |
4434 | ||
4435 | cqr = NULL; | |
4436 | if (cdlspecial || dasd_page_cache) { | |
4437 | /* do nothing, just fall through to the cmd mode single case */ | |
ef19298b SW |
4438 | } else if ((data_size <= private->fcx_max_data) |
4439 | && (fcx_multitrack || (first_trk == last_trk))) { | |
f3eb5384 SW |
4440 | cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, |
4441 | first_rec, last_rec, | |
4442 | first_trk, last_trk, | |
4443 | first_offs, last_offs, | |
4444 | blk_per_trk, blksize); | |
ef19298b SW |
4445 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
4446 | (PTR_ERR(cqr) != -ENOMEM)) | |
f3eb5384 SW |
4447 | cqr = NULL; |
4448 | } else if (use_prefix && | |
4449 | (((rq_data_dir(req) == READ) && cmdrtd) || | |
4450 | ((rq_data_dir(req) == WRITE) && cmdwtd))) { | |
4451 | cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, | |
4452 | first_rec, last_rec, | |
4453 | first_trk, last_trk, | |
4454 | first_offs, last_offs, | |
4455 | blk_per_trk, blksize); | |
ef19298b SW |
4456 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
4457 | (PTR_ERR(cqr) != -ENOMEM)) | |
f3eb5384 SW |
4458 | cqr = NULL; |
4459 | } | |
4460 | if (!cqr) | |
4461 | cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, | |
4462 | first_rec, last_rec, | |
4463 | first_trk, last_trk, | |
4464 | first_offs, last_offs, | |
4465 | blk_per_trk, blksize); | |
4466 | return cqr; | |
4467 | } | |
4468 | ||
bbc7f7ea JH |
4469 | static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev, |
4470 | struct dasd_block *block, | |
4471 | struct request *req) | |
e4dbb0f2 | 4472 | { |
9d2be0c1 JH |
4473 | sector_t start_padding_sectors, end_sector_offset, end_padding_sectors; |
4474 | unsigned int seg_len, len_to_track_end; | |
4475 | unsigned int cidaw, cplength, datasize; | |
4476 | sector_t first_trk, last_trk, sectors; | |
4477 | struct dasd_eckd_private *base_priv; | |
e4dbb0f2 | 4478 | struct dasd_device *basedev; |
e4dbb0f2 | 4479 | struct req_iterator iter; |
9d2be0c1 JH |
4480 | struct dasd_ccw_req *cqr; |
4481 | unsigned int first_offs; | |
4482 | unsigned int trkcount; | |
4483 | unsigned long *idaws; | |
4484 | unsigned int size; | |
4485 | unsigned char cmd; | |
7988613b | 4486 | struct bio_vec bv; |
9d2be0c1 JH |
4487 | struct ccw1 *ccw; |
4488 | int use_prefix; | |
4489 | void *data; | |
e4dbb0f2 | 4490 | char *dst; |
e4dbb0f2 SH |
4491 | |
4492 | /* | |
4493 | * raw track access needs to be mutiple of 64k and on 64k boundary | |
558b9ef0 SW |
4494 | * For read requests we can fix an incorrect alignment by padding |
4495 | * the request with dummy pages. | |
e4dbb0f2 | 4496 | */ |
558b9ef0 SW |
4497 | start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK; |
4498 | end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) % | |
4499 | DASD_RAW_SECTORS_PER_TRACK; | |
4500 | end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) % | |
4501 | DASD_RAW_SECTORS_PER_TRACK; | |
4502 | basedev = block->base; | |
4503 | if ((start_padding_sectors || end_padding_sectors) && | |
4504 | (rq_data_dir(req) == WRITE)) { | |
4505 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
e78c21d1 | 4506 | "raw write not track aligned (%llu,%llu) req %p", |
558b9ef0 | 4507 | start_padding_sectors, end_padding_sectors, req); |
9d2be0c1 | 4508 | return ERR_PTR(-EINVAL); |
e4dbb0f2 SH |
4509 | } |
4510 | ||
4511 | first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK; | |
4512 | last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) / | |
4513 | DASD_RAW_SECTORS_PER_TRACK; | |
4514 | trkcount = last_trk - first_trk + 1; | |
4515 | first_offs = 0; | |
e4dbb0f2 SH |
4516 | |
4517 | if (rq_data_dir(req) == READ) | |
4518 | cmd = DASD_ECKD_CCW_READ_TRACK; | |
4519 | else if (rq_data_dir(req) == WRITE) | |
4520 | cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK; | |
9d2be0c1 JH |
4521 | else |
4522 | return ERR_PTR(-EINVAL); | |
e4dbb0f2 SH |
4523 | |
4524 | /* | |
4525 | * Raw track based I/O needs IDAWs for each page, | |
4526 | * and not just for 64 bit addresses. | |
4527 | */ | |
4528 | cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK; | |
4529 | ||
e4dbb0f2 | 4530 | /* |
9d2be0c1 JH |
4531 | * struct PFX_eckd_data and struct LRE_eckd_data can have up to 2 bytes |
4532 | * of extended parameter. This is needed for write full track. | |
e4dbb0f2 | 4533 | */ |
9d2be0c1 JH |
4534 | base_priv = basedev->private; |
4535 | use_prefix = base_priv->features.feature[8] & 0x01; | |
4536 | if (use_prefix) { | |
4537 | cplength = 1 + trkcount; | |
4538 | size = sizeof(struct PFX_eckd_data) + 2; | |
4539 | } else { | |
4540 | cplength = 2 + trkcount; | |
4541 | size = sizeof(struct DE_eckd_data) + | |
4542 | sizeof(struct LRE_eckd_data) + 2; | |
4543 | } | |
4544 | size = ALIGN(size, 8); | |
e4dbb0f2 | 4545 | |
7bf76f01 | 4546 | datasize = size + cidaw * sizeof(unsigned long); |
e4dbb0f2 SH |
4547 | |
4548 | /* Allocate the ccw request. */ | |
4549 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, | |
c5205f2f | 4550 | datasize, startdev, blk_mq_rq_to_pdu(req)); |
e4dbb0f2 | 4551 | if (IS_ERR(cqr)) |
9d2be0c1 JH |
4552 | return cqr; |
4553 | ||
e4dbb0f2 | 4554 | ccw = cqr->cpaddr; |
9d2be0c1 | 4555 | data = cqr->data; |
e4dbb0f2 | 4556 | |
9d2be0c1 JH |
4557 | if (use_prefix) { |
4558 | prefix_LRE(ccw++, data, first_trk, last_trk, cmd, basedev, | |
4559 | startdev, 1, first_offs + 1, trkcount, 0, 0); | |
4560 | } else { | |
4561 | define_extent(ccw++, data, first_trk, last_trk, cmd, basedev, 0); | |
4562 | ccw[-1].flags |= CCW_FLAG_CC; | |
4563 | ||
4564 | data += sizeof(struct DE_eckd_data); | |
4565 | locate_record_ext(ccw++, data, first_trk, first_offs + 1, | |
4566 | trkcount, cmd, basedev, 0, 0); | |
e4dbb0f2 SH |
4567 | } |
4568 | ||
9d2be0c1 | 4569 | idaws = (unsigned long *)(cqr->data + size); |
e4dbb0f2 | 4570 | len_to_track_end = 0; |
558b9ef0 SW |
4571 | if (start_padding_sectors) { |
4572 | ccw[-1].flags |= CCW_FLAG_CC; | |
4573 | ccw->cmd_code = cmd; | |
4574 | /* maximum 3390 track size */ | |
4575 | ccw->count = 57326; | |
4576 | /* 64k map to one track */ | |
4577 | len_to_track_end = 65536 - start_padding_sectors * 512; | |
4578 | ccw->cda = (__u32)(addr_t)idaws; | |
4579 | ccw->flags |= CCW_FLAG_IDA; | |
4580 | ccw->flags |= CCW_FLAG_SLI; | |
4581 | ccw++; | |
4582 | for (sectors = 0; sectors < start_padding_sectors; sectors += 8) | |
4583 | idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); | |
4584 | } | |
e4dbb0f2 | 4585 | rq_for_each_segment(bv, req, iter) { |
7988613b KO |
4586 | dst = page_address(bv.bv_page) + bv.bv_offset; |
4587 | seg_len = bv.bv_len; | |
558b9ef0 SW |
4588 | if (cmd == DASD_ECKD_CCW_READ_TRACK) |
4589 | memset(dst, 0, seg_len); | |
e4dbb0f2 SH |
4590 | if (!len_to_track_end) { |
4591 | ccw[-1].flags |= CCW_FLAG_CC; | |
4592 | ccw->cmd_code = cmd; | |
4593 | /* maximum 3390 track size */ | |
4594 | ccw->count = 57326; | |
4595 | /* 64k map to one track */ | |
4596 | len_to_track_end = 65536; | |
4597 | ccw->cda = (__u32)(addr_t)idaws; | |
4598 | ccw->flags |= CCW_FLAG_IDA; | |
4599 | ccw->flags |= CCW_FLAG_SLI; | |
4600 | ccw++; | |
4601 | } | |
4602 | len_to_track_end -= seg_len; | |
4603 | idaws = idal_create_words(idaws, dst, seg_len); | |
4604 | } | |
558b9ef0 SW |
4605 | for (sectors = 0; sectors < end_padding_sectors; sectors += 8) |
4606 | idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); | |
e4dbb0f2 SH |
4607 | if (blk_noretry_request(req) || |
4608 | block->base->features & DASD_FEATURE_FAILFAST) | |
4609 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
4610 | cqr->startdev = startdev; | |
4611 | cqr->memdev = startdev; | |
4612 | cqr->block = block; | |
4613 | cqr->expires = startdev->default_expires * HZ; | |
c9346151 | 4614 | cqr->lpm = dasd_path_get_ppm(startdev); |
1f1ee9ad | 4615 | cqr->retries = startdev->default_retries; |
1aae0560 | 4616 | cqr->buildclk = get_tod_clock(); |
e4dbb0f2 SH |
4617 | cqr->status = DASD_CQR_FILLED; |
4618 | ||
e4dbb0f2 SH |
4619 | return cqr; |
4620 | } | |
4621 | ||
4622 | ||
1da177e4 LT |
4623 | static int |
4624 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) | |
4625 | { | |
4626 | struct dasd_eckd_private *private; | |
4627 | struct ccw1 *ccw; | |
5705f702 | 4628 | struct req_iterator iter; |
7988613b | 4629 | struct bio_vec bv; |
1da177e4 LT |
4630 | char *dst, *cda; |
4631 | unsigned int blksize, blk_per_trk, off; | |
4632 | sector_t recid; | |
5705f702 | 4633 | int status; |
1da177e4 LT |
4634 | |
4635 | if (!dasd_page_cache) | |
4636 | goto out; | |
543691a4 | 4637 | private = cqr->block->base->private; |
8e09f215 | 4638 | blksize = cqr->block->bp_block; |
1da177e4 | 4639 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
83096ebf | 4640 | recid = blk_rq_pos(req) >> cqr->block->s2b_shift; |
1da177e4 LT |
4641 | ccw = cqr->cpaddr; |
4642 | /* Skip over define extent & locate record. */ | |
4643 | ccw++; | |
4644 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) | |
4645 | ccw++; | |
5705f702 | 4646 | rq_for_each_segment(bv, req, iter) { |
7988613b KO |
4647 | dst = page_address(bv.bv_page) + bv.bv_offset; |
4648 | for (off = 0; off < bv.bv_len; off += blksize) { | |
1da177e4 LT |
4649 | /* Skip locate record. */ |
4650 | if (private->uses_cdl && recid <= 2*blk_per_trk) | |
4651 | ccw++; | |
4652 | if (dst) { | |
4653 | if (ccw->flags & CCW_FLAG_IDA) | |
4654 | cda = *((char **)((addr_t) ccw->cda)); | |
4655 | else | |
4656 | cda = (char *)((addr_t) ccw->cda); | |
4657 | if (dst != cda) { | |
4658 | if (rq_data_dir(req) == READ) | |
7988613b | 4659 | memcpy(dst, cda, bv.bv_len); |
1da177e4 LT |
4660 | kmem_cache_free(dasd_page_cache, |
4661 | (void *)((addr_t)cda & PAGE_MASK)); | |
4662 | } | |
4663 | dst = NULL; | |
4664 | } | |
4665 | ccw++; | |
4666 | recid++; | |
4667 | } | |
4668 | } | |
4669 | out: | |
4670 | status = cqr->status == DASD_CQR_DONE; | |
8e09f215 | 4671 | dasd_sfree_request(cqr, cqr->memdev); |
1da177e4 LT |
4672 | return status; |
4673 | } | |
4674 | ||
8e09f215 | 4675 | /* |
f3eb5384 | 4676 | * Modify ccw/tcw in cqr so it can be started on a base device. |
8e09f215 SW |
4677 | * |
4678 | * Note that this is not enough to restart the cqr! | |
4679 | * Either reset cqr->startdev as well (summary unit check handling) | |
4680 | * or restart via separate cqr (as in ERP handling). | |
4681 | */ | |
4682 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) | |
4683 | { | |
4684 | struct ccw1 *ccw; | |
4685 | struct PFX_eckd_data *pfxdata; | |
f3eb5384 SW |
4686 | struct tcw *tcw; |
4687 | struct tccb *tccb; | |
4688 | struct dcw *dcw; | |
4689 | ||
4690 | if (cqr->cpmode == 1) { | |
4691 | tcw = cqr->cpaddr; | |
4692 | tccb = tcw_get_tccb(tcw); | |
4693 | dcw = (struct dcw *)&tccb->tca[0]; | |
4694 | pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; | |
8e09f215 SW |
4695 | pfxdata->validity.verify_base = 0; |
4696 | pfxdata->validity.hyper_pav = 0; | |
f3eb5384 SW |
4697 | } else { |
4698 | ccw = cqr->cpaddr; | |
4699 | pfxdata = cqr->data; | |
4700 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { | |
4701 | pfxdata->validity.verify_base = 0; | |
4702 | pfxdata->validity.hyper_pav = 0; | |
4703 | } | |
8e09f215 SW |
4704 | } |
4705 | } | |
4706 | ||
4707 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 | |
4708 | ||
4709 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, | |
4710 | struct dasd_block *block, | |
4711 | struct request *req) | |
4712 | { | |
4713 | struct dasd_eckd_private *private; | |
964ce509 | 4714 | struct dasd_device *startdev; |
7e64db15 | 4715 | unsigned long flags; |
964ce509 | 4716 | struct dasd_ccw_req *cqr; |
8e09f215 | 4717 | |
964ce509 | 4718 | startdev = dasd_alias_get_start_dev(base); |
8e09f215 SW |
4719 | if (!startdev) |
4720 | startdev = base; | |
543691a4 | 4721 | private = startdev->private; |
8e09f215 SW |
4722 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) |
4723 | return ERR_PTR(-EBUSY); | |
4724 | ||
4725 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); | |
4726 | private->count++; | |
e4dbb0f2 | 4727 | if ((base->features & DASD_FEATURE_USERAW)) |
bbc7f7ea | 4728 | cqr = dasd_eckd_build_cp_raw(startdev, block, req); |
e4dbb0f2 SH |
4729 | else |
4730 | cqr = dasd_eckd_build_cp(startdev, block, req); | |
8e09f215 SW |
4731 | if (IS_ERR(cqr)) |
4732 | private->count--; | |
4733 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); | |
4734 | return cqr; | |
4735 | } | |
4736 | ||
4737 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, | |
4738 | struct request *req) | |
4739 | { | |
4740 | struct dasd_eckd_private *private; | |
4741 | unsigned long flags; | |
4742 | ||
4743 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); | |
543691a4 | 4744 | private = cqr->memdev->private; |
8e09f215 SW |
4745 | private->count--; |
4746 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); | |
4747 | return dasd_eckd_free_cp(cqr, req); | |
4748 | } | |
4749 | ||
1da177e4 LT |
4750 | static int |
4751 | dasd_eckd_fill_info(struct dasd_device * device, | |
4752 | struct dasd_information2_t * info) | |
4753 | { | |
543691a4 | 4754 | struct dasd_eckd_private *private = device->private; |
1da177e4 | 4755 | |
1da177e4 LT |
4756 | info->label_block = 2; |
4757 | info->FBA_layout = private->uses_cdl ? 0 : 1; | |
4758 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; | |
543691a4 | 4759 | info->characteristics_size = sizeof(private->rdc_data); |
1da177e4 | 4760 | memcpy(info->characteristics, &private->rdc_data, |
543691a4 | 4761 | sizeof(private->rdc_data)); |
4abb08c2 SW |
4762 | info->confdata_size = min((unsigned long)private->conf_len, |
4763 | sizeof(info->configuration_data)); | |
4764 | memcpy(info->configuration_data, private->conf_data, | |
4765 | info->confdata_size); | |
1da177e4 LT |
4766 | return 0; |
4767 | } | |
4768 | ||
4769 | /* | |
4770 | * SECTION: ioctl functions for eckd devices. | |
4771 | */ | |
4772 | ||
4773 | /* | |
4774 | * Release device ioctl. | |
138c014d | 4775 | * Buils a channel programm to releases a prior reserved |
1da177e4 LT |
4776 | * (see dasd_eckd_reserve) device. |
4777 | */ | |
4778 | static int | |
1107ccfb | 4779 | dasd_eckd_release(struct dasd_device *device) |
1da177e4 | 4780 | { |
1da177e4 LT |
4781 | struct dasd_ccw_req *cqr; |
4782 | int rc; | |
f3eb5384 | 4783 | struct ccw1 *ccw; |
f932bcea | 4784 | int useglobal; |
1da177e4 LT |
4785 | |
4786 | if (!capable(CAP_SYS_ADMIN)) | |
4787 | return -EACCES; | |
4788 | ||
f932bcea | 4789 | useglobal = 0; |
c5205f2f | 4790 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); |
1da177e4 | 4791 | if (IS_ERR(cqr)) { |
f932bcea SW |
4792 | mutex_lock(&dasd_reserve_mutex); |
4793 | useglobal = 1; | |
4794 | cqr = &dasd_reserve_req->cqr; | |
4795 | memset(cqr, 0, sizeof(*cqr)); | |
4796 | memset(&dasd_reserve_req->ccw, 0, | |
4797 | sizeof(dasd_reserve_req->ccw)); | |
4798 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
4799 | cqr->data = &dasd_reserve_req->data; | |
4800 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 4801 | } |
f3eb5384 SW |
4802 | ccw = cqr->cpaddr; |
4803 | ccw->cmd_code = DASD_ECKD_CCW_RELEASE; | |
4804 | ccw->flags |= CCW_FLAG_SLI; | |
4805 | ccw->count = 32; | |
4806 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
4807 | cqr->startdev = device; |
4808 | cqr->memdev = device; | |
1da177e4 | 4809 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 4810 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 4811 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 | 4812 | cqr->expires = 2 * HZ; |
1aae0560 | 4813 | cqr->buildclk = get_tod_clock(); |
1da177e4 LT |
4814 | cqr->status = DASD_CQR_FILLED; |
4815 | ||
4816 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
4817 | if (!rc) |
4818 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 4819 | |
f932bcea SW |
4820 | if (useglobal) |
4821 | mutex_unlock(&dasd_reserve_mutex); | |
4822 | else | |
4823 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
4824 | return rc; |
4825 | } | |
4826 | ||
4827 | /* | |
4828 | * Reserve device ioctl. | |
4829 | * Options are set to 'synchronous wait for interrupt' and | |
138c014d HH |
4830 | * 'timeout the request'. This leads to a terminate IO if |
4831 | * the interrupt is outstanding for a certain time. | |
1da177e4 LT |
4832 | */ |
4833 | static int | |
1107ccfb | 4834 | dasd_eckd_reserve(struct dasd_device *device) |
1da177e4 | 4835 | { |
1da177e4 LT |
4836 | struct dasd_ccw_req *cqr; |
4837 | int rc; | |
f3eb5384 | 4838 | struct ccw1 *ccw; |
f932bcea | 4839 | int useglobal; |
1da177e4 LT |
4840 | |
4841 | if (!capable(CAP_SYS_ADMIN)) | |
4842 | return -EACCES; | |
4843 | ||
f932bcea | 4844 | useglobal = 0; |
c5205f2f | 4845 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); |
1da177e4 | 4846 | if (IS_ERR(cqr)) { |
f932bcea SW |
4847 | mutex_lock(&dasd_reserve_mutex); |
4848 | useglobal = 1; | |
4849 | cqr = &dasd_reserve_req->cqr; | |
4850 | memset(cqr, 0, sizeof(*cqr)); | |
4851 | memset(&dasd_reserve_req->ccw, 0, | |
4852 | sizeof(dasd_reserve_req->ccw)); | |
4853 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
4854 | cqr->data = &dasd_reserve_req->data; | |
4855 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 4856 | } |
f3eb5384 SW |
4857 | ccw = cqr->cpaddr; |
4858 | ccw->cmd_code = DASD_ECKD_CCW_RESERVE; | |
4859 | ccw->flags |= CCW_FLAG_SLI; | |
4860 | ccw->count = 32; | |
4861 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
4862 | cqr->startdev = device; |
4863 | cqr->memdev = device; | |
1da177e4 | 4864 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 4865 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 4866 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 | 4867 | cqr->expires = 2 * HZ; |
1aae0560 | 4868 | cqr->buildclk = get_tod_clock(); |
1da177e4 LT |
4869 | cqr->status = DASD_CQR_FILLED; |
4870 | ||
4871 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
4872 | if (!rc) |
4873 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 4874 | |
f932bcea SW |
4875 | if (useglobal) |
4876 | mutex_unlock(&dasd_reserve_mutex); | |
4877 | else | |
4878 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
4879 | return rc; |
4880 | } | |
4881 | ||
4882 | /* | |
4883 | * Steal lock ioctl - unconditional reserve device. | |
138c014d | 4884 | * Buils a channel programm to break a device's reservation. |
1da177e4 LT |
4885 | * (unconditional reserve) |
4886 | */ | |
4887 | static int | |
1107ccfb | 4888 | dasd_eckd_steal_lock(struct dasd_device *device) |
1da177e4 | 4889 | { |
1da177e4 LT |
4890 | struct dasd_ccw_req *cqr; |
4891 | int rc; | |
f3eb5384 | 4892 | struct ccw1 *ccw; |
f932bcea | 4893 | int useglobal; |
1da177e4 LT |
4894 | |
4895 | if (!capable(CAP_SYS_ADMIN)) | |
4896 | return -EACCES; | |
4897 | ||
f932bcea | 4898 | useglobal = 0; |
c5205f2f | 4899 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); |
1da177e4 | 4900 | if (IS_ERR(cqr)) { |
f932bcea SW |
4901 | mutex_lock(&dasd_reserve_mutex); |
4902 | useglobal = 1; | |
4903 | cqr = &dasd_reserve_req->cqr; | |
4904 | memset(cqr, 0, sizeof(*cqr)); | |
4905 | memset(&dasd_reserve_req->ccw, 0, | |
4906 | sizeof(dasd_reserve_req->ccw)); | |
4907 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
4908 | cqr->data = &dasd_reserve_req->data; | |
4909 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 4910 | } |
f3eb5384 SW |
4911 | ccw = cqr->cpaddr; |
4912 | ccw->cmd_code = DASD_ECKD_CCW_SLCK; | |
4913 | ccw->flags |= CCW_FLAG_SLI; | |
4914 | ccw->count = 32; | |
4915 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
4916 | cqr->startdev = device; |
4917 | cqr->memdev = device; | |
1da177e4 | 4918 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 4919 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 4920 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 | 4921 | cqr->expires = 2 * HZ; |
1aae0560 | 4922 | cqr->buildclk = get_tod_clock(); |
1da177e4 LT |
4923 | cqr->status = DASD_CQR_FILLED; |
4924 | ||
4925 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
4926 | if (!rc) |
4927 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 4928 | |
f932bcea SW |
4929 | if (useglobal) |
4930 | mutex_unlock(&dasd_reserve_mutex); | |
4931 | else | |
4932 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
4933 | return rc; |
4934 | } | |
4935 | ||
196339f1 SW |
4936 | /* |
4937 | * SNID - Sense Path Group ID | |
4938 | * This ioctl may be used in situations where I/O is stalled due to | |
4939 | * a reserve, so if the normal dasd_smalloc_request fails, we use the | |
4940 | * preallocated dasd_reserve_req. | |
4941 | */ | |
4942 | static int dasd_eckd_snid(struct dasd_device *device, | |
4943 | void __user *argp) | |
4944 | { | |
4945 | struct dasd_ccw_req *cqr; | |
4946 | int rc; | |
4947 | struct ccw1 *ccw; | |
4948 | int useglobal; | |
4949 | struct dasd_snid_ioctl_data usrparm; | |
4950 | ||
4951 | if (!capable(CAP_SYS_ADMIN)) | |
4952 | return -EACCES; | |
4953 | ||
4954 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) | |
4955 | return -EFAULT; | |
4956 | ||
4957 | useglobal = 0; | |
4958 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, | |
c5205f2f SO |
4959 | sizeof(struct dasd_snid_data), device, |
4960 | NULL); | |
196339f1 SW |
4961 | if (IS_ERR(cqr)) { |
4962 | mutex_lock(&dasd_reserve_mutex); | |
4963 | useglobal = 1; | |
4964 | cqr = &dasd_reserve_req->cqr; | |
4965 | memset(cqr, 0, sizeof(*cqr)); | |
4966 | memset(&dasd_reserve_req->ccw, 0, | |
4967 | sizeof(dasd_reserve_req->ccw)); | |
4968 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
4969 | cqr->data = &dasd_reserve_req->data; | |
4970 | cqr->magic = DASD_ECKD_MAGIC; | |
4971 | } | |
4972 | ccw = cqr->cpaddr; | |
4973 | ccw->cmd_code = DASD_ECKD_CCW_SNID; | |
4974 | ccw->flags |= CCW_FLAG_SLI; | |
4975 | ccw->count = 12; | |
4976 | ccw->cda = (__u32)(addr_t) cqr->data; | |
4977 | cqr->startdev = device; | |
4978 | cqr->memdev = device; | |
4979 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
4980 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
5a27e60d | 4981 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
196339f1 SW |
4982 | cqr->retries = 5; |
4983 | cqr->expires = 10 * HZ; | |
1aae0560 | 4984 | cqr->buildclk = get_tod_clock(); |
196339f1 SW |
4985 | cqr->status = DASD_CQR_FILLED; |
4986 | cqr->lpm = usrparm.path_mask; | |
4987 | ||
4988 | rc = dasd_sleep_on_immediatly(cqr); | |
4989 | /* verify that I/O processing didn't modify the path mask */ | |
4990 | if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask)) | |
4991 | rc = -EIO; | |
4992 | if (!rc) { | |
4993 | usrparm.data = *((struct dasd_snid_data *)cqr->data); | |
4994 | if (copy_to_user(argp, &usrparm, sizeof(usrparm))) | |
4995 | rc = -EFAULT; | |
4996 | } | |
4997 | ||
4998 | if (useglobal) | |
4999 | mutex_unlock(&dasd_reserve_mutex); | |
5000 | else | |
5001 | dasd_sfree_request(cqr, cqr->memdev); | |
5002 | return rc; | |
5003 | } | |
5004 | ||
1da177e4 LT |
5005 | /* |
5006 | * Read performance statistics | |
5007 | */ | |
5008 | static int | |
1107ccfb | 5009 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
1da177e4 | 5010 | { |
1da177e4 LT |
5011 | struct dasd_psf_prssd_data *prssdp; |
5012 | struct dasd_rssd_perf_stats_t *stats; | |
5013 | struct dasd_ccw_req *cqr; | |
5014 | struct ccw1 *ccw; | |
5015 | int rc; | |
5016 | ||
68b781fe | 5017 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
8e09f215 SW |
5018 | (sizeof(struct dasd_psf_prssd_data) + |
5019 | sizeof(struct dasd_rssd_perf_stats_t)), | |
c5205f2f | 5020 | device, NULL); |
1da177e4 | 5021 | if (IS_ERR(cqr)) { |
fc19f381 | 5022 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 LT |
5023 | "Could not allocate initialization request"); |
5024 | return PTR_ERR(cqr); | |
5025 | } | |
8e09f215 SW |
5026 | cqr->startdev = device; |
5027 | cqr->memdev = device; | |
1da177e4 | 5028 | cqr->retries = 0; |
eb6e199b | 5029 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1da177e4 LT |
5030 | cqr->expires = 10 * HZ; |
5031 | ||
5032 | /* Prepare for Read Subsystem Data */ | |
5033 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
8e09f215 | 5034 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
1da177e4 | 5035 | prssdp->order = PSF_ORDER_PRSSD; |
5d67d164 | 5036 | prssdp->suborder = 0x01; /* Performance Statistics */ |
1da177e4 LT |
5037 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
5038 | ||
5039 | ccw = cqr->cpaddr; | |
5040 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
8e09f215 | 5041 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
1da177e4 LT |
5042 | ccw->flags |= CCW_FLAG_CC; |
5043 | ccw->cda = (__u32)(addr_t) prssdp; | |
5044 | ||
5045 | /* Read Subsystem Data - Performance Statistics */ | |
5046 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); | |
8e09f215 | 5047 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
1da177e4 LT |
5048 | |
5049 | ccw++; | |
5050 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
8e09f215 | 5051 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
1da177e4 LT |
5052 | ccw->cda = (__u32)(addr_t) stats; |
5053 | ||
1aae0560 | 5054 | cqr->buildclk = get_tod_clock(); |
1da177e4 LT |
5055 | cqr->status = DASD_CQR_FILLED; |
5056 | rc = dasd_sleep_on(cqr); | |
5057 | if (rc == 0) { | |
1da177e4 LT |
5058 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
5059 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); | |
1107ccfb CH |
5060 | if (copy_to_user(argp, stats, |
5061 | sizeof(struct dasd_rssd_perf_stats_t))) | |
5062 | rc = -EFAULT; | |
1da177e4 | 5063 | } |
8e09f215 | 5064 | dasd_sfree_request(cqr, cqr->memdev); |
1da177e4 LT |
5065 | return rc; |
5066 | } | |
5067 | ||
5068 | /* | |
5069 | * Get attributes (cache operations) | |
5070 | * Returnes the cache attributes used in Define Extend (DE). | |
5071 | */ | |
5072 | static int | |
1107ccfb | 5073 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
1da177e4 | 5074 | { |
543691a4 | 5075 | struct dasd_eckd_private *private = device->private; |
1107ccfb | 5076 | struct attrib_data_t attrib = private->attrib; |
1da177e4 LT |
5077 | int rc; |
5078 | ||
5079 | if (!capable(CAP_SYS_ADMIN)) | |
5080 | return -EACCES; | |
1107ccfb | 5081 | if (!argp) |
1da177e4 LT |
5082 | return -EINVAL; |
5083 | ||
1107ccfb CH |
5084 | rc = 0; |
5085 | if (copy_to_user(argp, (long *) &attrib, | |
8e09f215 | 5086 | sizeof(struct attrib_data_t))) |
1107ccfb | 5087 | rc = -EFAULT; |
1da177e4 LT |
5088 | |
5089 | return rc; | |
5090 | } | |
5091 | ||
5092 | /* | |
5093 | * Set attributes (cache operations) | |
5094 | * Stores the attributes for cache operation to be used in Define Extend (DE). | |
5095 | */ | |
5096 | static int | |
1107ccfb | 5097 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
1da177e4 | 5098 | { |
543691a4 | 5099 | struct dasd_eckd_private *private = device->private; |
1da177e4 LT |
5100 | struct attrib_data_t attrib; |
5101 | ||
5102 | if (!capable(CAP_SYS_ADMIN)) | |
5103 | return -EACCES; | |
1107ccfb | 5104 | if (!argp) |
1da177e4 LT |
5105 | return -EINVAL; |
5106 | ||
1107ccfb | 5107 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
1da177e4 | 5108 | return -EFAULT; |
1da177e4 LT |
5109 | private->attrib = attrib; |
5110 | ||
fc19f381 SH |
5111 | dev_info(&device->cdev->dev, |
5112 | "The DASD cache mode was set to %x (%i cylinder prestage)\n", | |
5113 | private->attrib.operation, private->attrib.nr_cyl); | |
1da177e4 LT |
5114 | return 0; |
5115 | } | |
5116 | ||
ab1d848f NH |
5117 | /* |
5118 | * Issue syscall I/O to EMC Symmetrix array. | |
5119 | * CCWs are PSF and RSSD | |
5120 | */ | |
5121 | static int dasd_symm_io(struct dasd_device *device, void __user *argp) | |
5122 | { | |
5123 | struct dasd_symmio_parms usrparm; | |
5124 | char *psf_data, *rssd_result; | |
5125 | struct dasd_ccw_req *cqr; | |
5126 | struct ccw1 *ccw; | |
52898025 | 5127 | char psf0, psf1; |
ab1d848f NH |
5128 | int rc; |
5129 | ||
52898025 NH |
5130 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) |
5131 | return -EACCES; | |
5132 | psf0 = psf1 = 0; | |
5133 | ||
ab1d848f NH |
5134 | /* Copy parms from caller */ |
5135 | rc = -EFAULT; | |
5136 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) | |
5137 | goto out; | |
92d62891 | 5138 | if (is_compat_task()) { |
f8b06859 | 5139 | /* Make sure pointers are sane even on 31 bit. */ |
ab1d848f | 5140 | rc = -EINVAL; |
f8b06859 HC |
5141 | if ((usrparm.psf_data >> 32) != 0) |
5142 | goto out; | |
5143 | if ((usrparm.rssd_result >> 32) != 0) | |
5144 | goto out; | |
5145 | usrparm.psf_data &= 0x7fffffffULL; | |
5146 | usrparm.rssd_result &= 0x7fffffffULL; | |
ab1d848f | 5147 | } |
4a8ef699 SH |
5148 | /* at least 2 bytes are accessed and should be allocated */ |
5149 | if (usrparm.psf_data_len < 2) { | |
5150 | DBF_DEV_EVENT(DBF_WARNING, device, | |
5151 | "Symmetrix ioctl invalid data length %d", | |
5152 | usrparm.psf_data_len); | |
5153 | rc = -EINVAL; | |
5154 | goto out; | |
5155 | } | |
ab1d848f NH |
5156 | /* alloc I/O data area */ |
5157 | psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); | |
5158 | rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); | |
5159 | if (!psf_data || !rssd_result) { | |
5160 | rc = -ENOMEM; | |
5161 | goto out_free; | |
5162 | } | |
5163 | ||
5164 | /* get syscall header from user space */ | |
5165 | rc = -EFAULT; | |
5166 | if (copy_from_user(psf_data, | |
5167 | (void __user *)(unsigned long) usrparm.psf_data, | |
5168 | usrparm.psf_data_len)) | |
5169 | goto out_free; | |
52898025 NH |
5170 | psf0 = psf_data[0]; |
5171 | psf1 = psf_data[1]; | |
ab1d848f NH |
5172 | |
5173 | /* setup CCWs for PSF + RSSD */ | |
c5205f2f | 5174 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2, 0, device, NULL); |
ab1d848f | 5175 | if (IS_ERR(cqr)) { |
fc19f381 | 5176 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
ab1d848f NH |
5177 | "Could not allocate initialization request"); |
5178 | rc = PTR_ERR(cqr); | |
5179 | goto out_free; | |
5180 | } | |
5181 | ||
5182 | cqr->startdev = device; | |
5183 | cqr->memdev = device; | |
5184 | cqr->retries = 3; | |
5185 | cqr->expires = 10 * HZ; | |
1aae0560 | 5186 | cqr->buildclk = get_tod_clock(); |
ab1d848f NH |
5187 | cqr->status = DASD_CQR_FILLED; |
5188 | ||
5189 | /* Build the ccws */ | |
5190 | ccw = cqr->cpaddr; | |
5191 | ||
5192 | /* PSF ccw */ | |
5193 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
5194 | ccw->count = usrparm.psf_data_len; | |
5195 | ccw->flags |= CCW_FLAG_CC; | |
5196 | ccw->cda = (__u32)(addr_t) psf_data; | |
5197 | ||
5198 | ccw++; | |
5199 | ||
5200 | /* RSSD ccw */ | |
5201 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
5202 | ccw->count = usrparm.rssd_result_len; | |
5203 | ccw->flags = CCW_FLAG_SLI ; | |
5204 | ccw->cda = (__u32)(addr_t) rssd_result; | |
5205 | ||
5206 | rc = dasd_sleep_on(cqr); | |
5207 | if (rc) | |
5208 | goto out_sfree; | |
5209 | ||
5210 | rc = -EFAULT; | |
5211 | if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, | |
5212 | rssd_result, usrparm.rssd_result_len)) | |
5213 | goto out_sfree; | |
5214 | rc = 0; | |
5215 | ||
5216 | out_sfree: | |
5217 | dasd_sfree_request(cqr, cqr->memdev); | |
5218 | out_free: | |
5219 | kfree(rssd_result); | |
5220 | kfree(psf_data); | |
5221 | out: | |
52898025 NH |
5222 | DBF_DEV_EVENT(DBF_WARNING, device, |
5223 | "Symmetrix ioctl (0x%02x 0x%02x): rc=%d", | |
5224 | (int) psf0, (int) psf1, rc); | |
ab1d848f NH |
5225 | return rc; |
5226 | } | |
5227 | ||
1107ccfb | 5228 | static int |
8e09f215 | 5229 | dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp) |
1107ccfb | 5230 | { |
8e09f215 SW |
5231 | struct dasd_device *device = block->base; |
5232 | ||
1107ccfb CH |
5233 | switch (cmd) { |
5234 | case BIODASDGATTR: | |
5235 | return dasd_eckd_get_attrib(device, argp); | |
5236 | case BIODASDSATTR: | |
5237 | return dasd_eckd_set_attrib(device, argp); | |
5238 | case BIODASDPSRD: | |
5239 | return dasd_eckd_performance(device, argp); | |
5240 | case BIODASDRLSE: | |
5241 | return dasd_eckd_release(device); | |
5242 | case BIODASDRSRV: | |
5243 | return dasd_eckd_reserve(device); | |
5244 | case BIODASDSLCK: | |
5245 | return dasd_eckd_steal_lock(device); | |
196339f1 SW |
5246 | case BIODASDSNID: |
5247 | return dasd_eckd_snid(device, argp); | |
ab1d848f NH |
5248 | case BIODASDSYMMIO: |
5249 | return dasd_symm_io(device, argp); | |
1107ccfb | 5250 | default: |
6b79d14e | 5251 | return -ENOTTY; |
1107ccfb CH |
5252 | } |
5253 | } | |
5254 | ||
445b5b49 HH |
5255 | /* |
5256 | * Dump the range of CCWs into 'page' buffer | |
5257 | * and return number of printed chars. | |
5258 | */ | |
4d284cac | 5259 | static int |
445b5b49 HH |
5260 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
5261 | { | |
5262 | int len, count; | |
5263 | char *datap; | |
5264 | ||
5265 | len = 0; | |
5266 | while (from <= to) { | |
773bab4a | 5267 | len += sprintf(page + len, PRINTK_HEADER |
445b5b49 HH |
5268 | " CCW %p: %08X %08X DAT:", |
5269 | from, ((int *) from)[0], ((int *) from)[1]); | |
5270 | ||
5271 | /* get pointer to data (consider IDALs) */ | |
5272 | if (from->flags & CCW_FLAG_IDA) | |
5273 | datap = (char *) *((addr_t *) (addr_t) from->cda); | |
5274 | else | |
5275 | datap = (char *) ((addr_t) from->cda); | |
5276 | ||
5277 | /* dump data (max 32 bytes) */ | |
5278 | for (count = 0; count < from->count && count < 32; count++) { | |
5279 | if (count % 8 == 0) len += sprintf(page + len, " "); | |
5280 | if (count % 4 == 0) len += sprintf(page + len, " "); | |
5281 | len += sprintf(page + len, "%02x", datap[count]); | |
5282 | } | |
5283 | len += sprintf(page + len, "\n"); | |
5284 | from++; | |
5285 | } | |
5286 | return len; | |
5287 | } | |
5288 | ||
fc19f381 | 5289 | static void |
aeec92ca SH |
5290 | dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
5291 | char *reason) | |
fc19f381 SH |
5292 | { |
5293 | u64 *sense; | |
a5a0061f | 5294 | u64 *stat; |
aeec92ca SH |
5295 | |
5296 | sense = (u64 *) dasd_get_sense(irb); | |
a5a0061f | 5297 | stat = (u64 *) &irb->scsw; |
fc19f381 | 5298 | if (sense) { |
a5a0061f SW |
5299 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : " |
5300 | "%016llx %016llx %016llx %016llx", | |
5301 | reason, *stat, *((u32 *) (stat + 1)), | |
ed3640b2 | 5302 | sense[0], sense[1], sense[2], sense[3]); |
fc19f381 | 5303 | } else { |
a5a0061f SW |
5304 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s", |
5305 | reason, *stat, *((u32 *) (stat + 1)), | |
5306 | "NO VALID SENSE"); | |
fc19f381 SH |
5307 | } |
5308 | } | |
5309 | ||
1da177e4 LT |
5310 | /* |
5311 | * Print sense data and related channel program. | |
5312 | * Parts are printed because printk buffer is only 1024 bytes. | |
5313 | */ | |
f3eb5384 | 5314 | static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, |
8e09f215 | 5315 | struct dasd_ccw_req *req, struct irb *irb) |
1da177e4 LT |
5316 | { |
5317 | char *page; | |
445b5b49 HH |
5318 | struct ccw1 *first, *last, *fail, *from, *to; |
5319 | int len, sl, sct; | |
1da177e4 LT |
5320 | |
5321 | page = (char *) get_zeroed_page(GFP_ATOMIC); | |
5322 | if (page == NULL) { | |
fc19f381 SH |
5323 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
5324 | "No memory to dump sense data\n"); | |
1da177e4 LT |
5325 | return; |
5326 | } | |
445b5b49 | 5327 | /* dump the sense data */ |
773bab4a | 5328 | len = sprintf(page, PRINTK_HEADER |
1da177e4 | 5329 | " I/O status report for device %s:\n", |
2a0217d5 | 5330 | dev_name(&device->cdev->dev)); |
773bab4a | 5331 | len += sprintf(page + len, PRINTK_HEADER |
a5a0061f SW |
5332 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
5333 | "CS:%02X RC:%d\n", | |
5334 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), | |
5335 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), | |
5336 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), | |
5337 | req ? req->intrc : 0); | |
773bab4a | 5338 | len += sprintf(page + len, PRINTK_HEADER |
1da177e4 | 5339 | " device %s: Failing CCW: %p\n", |
2a0217d5 | 5340 | dev_name(&device->cdev->dev), |
23d805b6 | 5341 | (void *) (addr_t) irb->scsw.cmd.cpa); |
1da177e4 LT |
5342 | if (irb->esw.esw0.erw.cons) { |
5343 | for (sl = 0; sl < 4; sl++) { | |
773bab4a | 5344 | len += sprintf(page + len, PRINTK_HEADER |
1da177e4 LT |
5345 | " Sense(hex) %2d-%2d:", |
5346 | (8 * sl), ((8 * sl) + 7)); | |
5347 | ||
5348 | for (sct = 0; sct < 8; sct++) { | |
5349 | len += sprintf(page + len, " %02x", | |
5350 | irb->ecw[8 * sl + sct]); | |
5351 | } | |
5352 | len += sprintf(page + len, "\n"); | |
5353 | } | |
5354 | ||
5355 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { | |
5356 | /* 24 Byte Sense Data */ | |
773bab4a | 5357 | sprintf(page + len, PRINTK_HEADER |
445b5b49 HH |
5358 | " 24 Byte: %x MSG %x, " |
5359 | "%s MSGb to SYSOP\n", | |
5360 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, | |
5361 | irb->ecw[1] & 0x10 ? "" : "no"); | |
1da177e4 LT |
5362 | } else { |
5363 | /* 32 Byte Sense Data */ | |
773bab4a | 5364 | sprintf(page + len, PRINTK_HEADER |
445b5b49 HH |
5365 | " 32 Byte: Format: %x " |
5366 | "Exception class %x\n", | |
5367 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); | |
1da177e4 LT |
5368 | } |
5369 | } else { | |
773bab4a | 5370 | sprintf(page + len, PRINTK_HEADER |
445b5b49 | 5371 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
1da177e4 | 5372 | } |
773bab4a | 5373 | printk(KERN_ERR "%s", page); |
445b5b49 | 5374 | |
8e09f215 SW |
5375 | if (req) { |
5376 | /* req == NULL for unsolicited interrupts */ | |
5377 | /* dump the Channel Program (max 140 Bytes per line) */ | |
5378 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ | |
5379 | first = req->cpaddr; | |
5380 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); | |
5381 | to = min(first + 6, last); | |
773bab4a | 5382 | len = sprintf(page, PRINTK_HEADER |
8e09f215 SW |
5383 | " Related CP in req: %p\n", req); |
5384 | dasd_eckd_dump_ccw_range(first, to, page + len); | |
773bab4a | 5385 | printk(KERN_ERR "%s", page); |
1da177e4 | 5386 | |
8e09f215 SW |
5387 | /* print failing CCW area (maximum 4) */ |
5388 | /* scsw->cda is either valid or zero */ | |
5389 | len = 0; | |
5390 | from = ++to; | |
23d805b6 PO |
5391 | fail = (struct ccw1 *)(addr_t) |
5392 | irb->scsw.cmd.cpa; /* failing CCW */ | |
8e09f215 SW |
5393 | if (from < fail - 2) { |
5394 | from = fail - 2; /* there is a gap - print header */ | |
773bab4a | 5395 | len += sprintf(page, PRINTK_HEADER "......\n"); |
8e09f215 SW |
5396 | } |
5397 | to = min(fail + 1, last); | |
5398 | len += dasd_eckd_dump_ccw_range(from, to, page + len); | |
5399 | ||
5400 | /* print last CCWs (maximum 2) */ | |
5401 | from = max(from, ++to); | |
5402 | if (from < last - 1) { | |
5403 | from = last - 1; /* there is a gap - print header */ | |
773bab4a | 5404 | len += sprintf(page + len, PRINTK_HEADER "......\n"); |
8e09f215 SW |
5405 | } |
5406 | len += dasd_eckd_dump_ccw_range(from, last, page + len); | |
5407 | if (len > 0) | |
773bab4a | 5408 | printk(KERN_ERR "%s", page); |
1da177e4 | 5409 | } |
1da177e4 LT |
5410 | free_page((unsigned long) page); |
5411 | } | |
5412 | ||
f3eb5384 SW |
5413 | |
5414 | /* | |
5415 | * Print sense data from a tcw. | |
5416 | */ | |
5417 | static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, | |
5418 | struct dasd_ccw_req *req, struct irb *irb) | |
5419 | { | |
5420 | char *page; | |
5421 | int len, sl, sct, residual; | |
f3eb5384 | 5422 | struct tsb *tsb; |
ef19298b | 5423 | u8 *sense, *rcq; |
f3eb5384 SW |
5424 | |
5425 | page = (char *) get_zeroed_page(GFP_ATOMIC); | |
5426 | if (page == NULL) { | |
fc19f381 | 5427 | DBF_DEV_EVENT(DBF_WARNING, device, " %s", |
f3eb5384 SW |
5428 | "No memory to dump sense data"); |
5429 | return; | |
5430 | } | |
5431 | /* dump the sense data */ | |
773bab4a | 5432 | len = sprintf(page, PRINTK_HEADER |
f3eb5384 SW |
5433 | " I/O status report for device %s:\n", |
5434 | dev_name(&device->cdev->dev)); | |
773bab4a | 5435 | len += sprintf(page + len, PRINTK_HEADER |
a5a0061f SW |
5436 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
5437 | "CS:%02X fcxs:%02X schxs:%02X RC:%d\n", | |
5438 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), | |
5439 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), | |
5440 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), | |
a521b048 SH |
5441 | irb->scsw.tm.fcxs, |
5442 | (irb->scsw.tm.ifob << 7) | irb->scsw.tm.sesq, | |
a5a0061f | 5443 | req ? req->intrc : 0); |
773bab4a | 5444 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5445 | " device %s: Failing TCW: %p\n", |
5446 | dev_name(&device->cdev->dev), | |
5447 | (void *) (addr_t) irb->scsw.tm.tcw); | |
5448 | ||
5449 | tsb = NULL; | |
5450 | sense = NULL; | |
a5a0061f | 5451 | if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01)) |
f3eb5384 SW |
5452 | tsb = tcw_get_tsb( |
5453 | (struct tcw *)(unsigned long)irb->scsw.tm.tcw); | |
5454 | ||
b8fde722 | 5455 | if (tsb) { |
773bab4a | 5456 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 | 5457 | " tsb->length %d\n", tsb->length); |
773bab4a | 5458 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 | 5459 | " tsb->flags %x\n", tsb->flags); |
773bab4a | 5460 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 | 5461 | " tsb->dcw_offset %d\n", tsb->dcw_offset); |
773bab4a | 5462 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5463 | " tsb->count %d\n", tsb->count); |
5464 | residual = tsb->count - 28; | |
773bab4a | 5465 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5466 | " residual %d\n", residual); |
5467 | ||
5468 | switch (tsb->flags & 0x07) { | |
5469 | case 1: /* tsa_iostat */ | |
773bab4a | 5470 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5471 | " tsb->tsa.iostat.dev_time %d\n", |
5472 | tsb->tsa.iostat.dev_time); | |
773bab4a | 5473 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5474 | " tsb->tsa.iostat.def_time %d\n", |
5475 | tsb->tsa.iostat.def_time); | |
773bab4a | 5476 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5477 | " tsb->tsa.iostat.queue_time %d\n", |
5478 | tsb->tsa.iostat.queue_time); | |
773bab4a | 5479 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5480 | " tsb->tsa.iostat.dev_busy_time %d\n", |
5481 | tsb->tsa.iostat.dev_busy_time); | |
773bab4a | 5482 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5483 | " tsb->tsa.iostat.dev_act_time %d\n", |
5484 | tsb->tsa.iostat.dev_act_time); | |
5485 | sense = tsb->tsa.iostat.sense; | |
5486 | break; | |
5487 | case 2: /* ts_ddpc */ | |
773bab4a | 5488 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 | 5489 | " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); |
ef19298b | 5490 | for (sl = 0; sl < 2; sl++) { |
773bab4a | 5491 | len += sprintf(page + len, PRINTK_HEADER |
ef19298b SW |
5492 | " tsb->tsa.ddpc.rcq %2d-%2d: ", |
5493 | (8 * sl), ((8 * sl) + 7)); | |
5494 | rcq = tsb->tsa.ddpc.rcq; | |
f3eb5384 SW |
5495 | for (sct = 0; sct < 8; sct++) { |
5496 | len += sprintf(page + len, " %02x", | |
ef19298b | 5497 | rcq[8 * sl + sct]); |
f3eb5384 SW |
5498 | } |
5499 | len += sprintf(page + len, "\n"); | |
5500 | } | |
5501 | sense = tsb->tsa.ddpc.sense; | |
5502 | break; | |
5503 | case 3: /* tsa_intrg */ | |
773bab4a | 5504 | len += sprintf(page + len, PRINTK_HEADER |
8693b914 | 5505 | " tsb->tsa.intrg.: not supported yet\n"); |
f3eb5384 SW |
5506 | break; |
5507 | } | |
5508 | ||
5509 | if (sense) { | |
5510 | for (sl = 0; sl < 4; sl++) { | |
773bab4a | 5511 | len += sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5512 | " Sense(hex) %2d-%2d:", |
5513 | (8 * sl), ((8 * sl) + 7)); | |
5514 | for (sct = 0; sct < 8; sct++) { | |
5515 | len += sprintf(page + len, " %02x", | |
5516 | sense[8 * sl + sct]); | |
5517 | } | |
5518 | len += sprintf(page + len, "\n"); | |
5519 | } | |
5520 | ||
5521 | if (sense[27] & DASD_SENSE_BIT_0) { | |
5522 | /* 24 Byte Sense Data */ | |
773bab4a | 5523 | sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5524 | " 24 Byte: %x MSG %x, " |
5525 | "%s MSGb to SYSOP\n", | |
5526 | sense[7] >> 4, sense[7] & 0x0f, | |
5527 | sense[1] & 0x10 ? "" : "no"); | |
5528 | } else { | |
5529 | /* 32 Byte Sense Data */ | |
773bab4a | 5530 | sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5531 | " 32 Byte: Format: %x " |
5532 | "Exception class %x\n", | |
5533 | sense[6] & 0x0f, sense[22] >> 4); | |
5534 | } | |
5535 | } else { | |
773bab4a | 5536 | sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5537 | " SORRY - NO VALID SENSE AVAILABLE\n"); |
5538 | } | |
5539 | } else { | |
773bab4a | 5540 | sprintf(page + len, PRINTK_HEADER |
f3eb5384 SW |
5541 | " SORRY - NO TSB DATA AVAILABLE\n"); |
5542 | } | |
773bab4a | 5543 | printk(KERN_ERR "%s", page); |
f3eb5384 SW |
5544 | free_page((unsigned long) page); |
5545 | } | |
5546 | ||
5547 | static void dasd_eckd_dump_sense(struct dasd_device *device, | |
5548 | struct dasd_ccw_req *req, struct irb *irb) | |
5549 | { | |
8fd57520 JH |
5550 | u8 *sense = dasd_get_sense(irb); |
5551 | ||
5552 | if (scsw_is_tm(&irb->scsw)) { | |
5553 | /* | |
5554 | * In some cases the 'File Protected' or 'Incorrect Length' | |
5555 | * error might be expected and log messages shouldn't be written | |
5556 | * then. Check if the according suppress bit is set. | |
5557 | */ | |
5558 | if (sense && (sense[1] & SNS1_FILE_PROTECTED) && | |
5559 | test_bit(DASD_CQR_SUPPRESS_FP, &req->flags)) | |
5560 | return; | |
5561 | if (scsw_cstat(&irb->scsw) == 0x40 && | |
5562 | test_bit(DASD_CQR_SUPPRESS_IL, &req->flags)) | |
5563 | return; | |
5564 | ||
f3eb5384 | 5565 | dasd_eckd_dump_sense_tcw(device, req, irb); |
8fd57520 JH |
5566 | } else { |
5567 | /* | |
ab24fbd3 SH |
5568 | * In some cases the 'Command Reject' or 'No Record Found' |
5569 | * error might be expected and log messages shouldn't be | |
5570 | * written then. Check if the according suppress bit is set. | |
8fd57520 | 5571 | */ |
ab24fbd3 SH |
5572 | if (sense && sense[0] & SNS0_CMD_REJECT && |
5573 | test_bit(DASD_CQR_SUPPRESS_CR, &req->flags)) | |
5574 | return; | |
5575 | ||
8fd57520 JH |
5576 | if (sense && sense[1] & SNS1_NO_REC_FOUND && |
5577 | test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags)) | |
5578 | return; | |
5579 | ||
f3eb5384 | 5580 | dasd_eckd_dump_sense_ccw(device, req, irb); |
8fd57520 | 5581 | } |
f3eb5384 SW |
5582 | } |
5583 | ||
501183f2 | 5584 | static int dasd_eckd_pm_freeze(struct dasd_device *device) |
d41dd122 SH |
5585 | { |
5586 | /* | |
5587 | * the device should be disconnected from our LCU structure | |
5588 | * on restore we will reconnect it and reread LCU specific | |
5589 | * information like PAV support that might have changed | |
5590 | */ | |
5591 | dasd_alias_remove_device(device); | |
5592 | dasd_alias_disconnect_device_from_lcu(device); | |
5593 | ||
5594 | return 0; | |
5595 | } | |
5596 | ||
501183f2 | 5597 | static int dasd_eckd_restore_device(struct dasd_device *device) |
d41dd122 | 5598 | { |
543691a4 | 5599 | struct dasd_eckd_private *private = device->private; |
6fca97a9 | 5600 | struct dasd_eckd_characteristics temp_rdc_data; |
f9f8d02f | 5601 | int rc; |
d41dd122 | 5602 | struct dasd_uid temp_uid; |
a7602f6c | 5603 | unsigned long flags; |
ea4da6ea | 5604 | unsigned long cqr_flags = 0; |
d41dd122 | 5605 | |
d41dd122 | 5606 | /* Read Configuration Data */ |
251afd69 SH |
5607 | rc = dasd_eckd_read_conf(device); |
5608 | if (rc) { | |
5609 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
5610 | "Read configuration data failed, rc=%d", rc); | |
5611 | goto out_err; | |
5612 | } | |
d41dd122 | 5613 | |
2dedf0d9 SH |
5614 | dasd_eckd_get_uid(device, &temp_uid); |
5615 | /* Generate device unique id */ | |
5616 | rc = dasd_eckd_generate_uid(device); | |
5617 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
d41dd122 | 5618 | if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) |
a7602f6c SH |
5619 | dev_err(&device->cdev->dev, "The UID of the DASD has " |
5620 | "changed\n"); | |
2dedf0d9 | 5621 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
d41dd122 SH |
5622 | if (rc) |
5623 | goto out_err; | |
d41dd122 SH |
5624 | |
5625 | /* register lcu with alias handling, enable PAV if this is a new lcu */ | |
f9f8d02f SH |
5626 | rc = dasd_alias_make_device_known_to_lcu(device); |
5627 | if (rc) | |
251afd69 | 5628 | goto out_err; |
ea4da6ea SH |
5629 | |
5630 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags); | |
5631 | dasd_eckd_validate_server(device, cqr_flags); | |
f4ac1d02 SW |
5632 | |
5633 | /* RE-Read Configuration Data */ | |
251afd69 SH |
5634 | rc = dasd_eckd_read_conf(device); |
5635 | if (rc) { | |
5636 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
5637 | "Read configuration data failed, rc=%d", rc); | |
5638 | goto out_err2; | |
5639 | } | |
d41dd122 SH |
5640 | |
5641 | /* Read Feature Codes */ | |
68d1e5f0 | 5642 | dasd_eckd_read_features(device); |
d41dd122 | 5643 | |
c729696b | 5644 | /* Read Volume Information */ |
dd454839 | 5645 | dasd_eckd_read_vol_info(device); |
c729696b JH |
5646 | |
5647 | /* Read Extent Pool Information */ | |
dd454839 | 5648 | dasd_eckd_read_ext_pool_info(device); |
c729696b | 5649 | |
d41dd122 | 5650 | /* Read Device Characteristics */ |
68b781fe | 5651 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
6fca97a9 | 5652 | &temp_rdc_data, 64); |
d41dd122 | 5653 | if (rc) { |
b8ed5dd5 SH |
5654 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
5655 | "Read device characteristic failed, rc=%d", rc); | |
251afd69 | 5656 | goto out_err2; |
d41dd122 | 5657 | } |
a7602f6c | 5658 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
6fca97a9 | 5659 | memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data)); |
a7602f6c | 5660 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
d41dd122 SH |
5661 | |
5662 | /* add device to alias management */ | |
5663 | dasd_alias_add_device(device); | |
5664 | ||
5665 | return 0; | |
5666 | ||
251afd69 SH |
5667 | out_err2: |
5668 | dasd_alias_disconnect_device_from_lcu(device); | |
d41dd122 | 5669 | out_err: |
e6125fba | 5670 | return -1; |
d41dd122 SH |
5671 | } |
5672 | ||
501183f2 SH |
5673 | static int dasd_eckd_reload_device(struct dasd_device *device) |
5674 | { | |
543691a4 | 5675 | struct dasd_eckd_private *private = device->private; |
501183f2 | 5676 | int rc, old_base; |
2dedf0d9 SH |
5677 | char print_uid[60]; |
5678 | struct dasd_uid uid; | |
5679 | unsigned long flags; | |
501183f2 | 5680 | |
59a9ed5f SH |
5681 | /* |
5682 | * remove device from alias handling to prevent new requests | |
5683 | * from being scheduled on the wrong alias device | |
5684 | */ | |
5685 | dasd_alias_remove_device(device); | |
5686 | ||
2dedf0d9 | 5687 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
501183f2 | 5688 | old_base = private->uid.base_unit_addr; |
2dedf0d9 SH |
5689 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
5690 | ||
501183f2 SH |
5691 | /* Read Configuration Data */ |
5692 | rc = dasd_eckd_read_conf(device); | |
5693 | if (rc) | |
5694 | goto out_err; | |
5695 | ||
2dedf0d9 | 5696 | rc = dasd_eckd_generate_uid(device); |
501183f2 SH |
5697 | if (rc) |
5698 | goto out_err; | |
501183f2 SH |
5699 | /* |
5700 | * update unit address configuration and | |
5701 | * add device to alias management | |
5702 | */ | |
5703 | dasd_alias_update_add_device(device); | |
5704 | ||
2dedf0d9 SH |
5705 | dasd_eckd_get_uid(device, &uid); |
5706 | ||
5707 | if (old_base != uid.base_unit_addr) { | |
5708 | if (strlen(uid.vduit) > 0) | |
5709 | snprintf(print_uid, sizeof(print_uid), | |
5710 | "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial, | |
5711 | uid.ssid, uid.base_unit_addr, uid.vduit); | |
501183f2 | 5712 | else |
2dedf0d9 SH |
5713 | snprintf(print_uid, sizeof(print_uid), |
5714 | "%s.%s.%04x.%02x", uid.vendor, uid.serial, | |
5715 | uid.ssid, uid.base_unit_addr); | |
501183f2 SH |
5716 | |
5717 | dev_info(&device->cdev->dev, | |
5718 | "An Alias device was reassigned to a new base device " | |
2dedf0d9 | 5719 | "with UID: %s\n", print_uid); |
501183f2 SH |
5720 | } |
5721 | return 0; | |
5722 | ||
5723 | out_err: | |
5724 | return -1; | |
5725 | } | |
5726 | ||
5db8440c SH |
5727 | static int dasd_eckd_read_message_buffer(struct dasd_device *device, |
5728 | struct dasd_rssd_messages *messages, | |
5729 | __u8 lpum) | |
5730 | { | |
5731 | struct dasd_rssd_messages *message_buf; | |
5732 | struct dasd_psf_prssd_data *prssdp; | |
5db8440c SH |
5733 | struct dasd_ccw_req *cqr; |
5734 | struct ccw1 *ccw; | |
5735 | int rc; | |
5736 | ||
5db8440c SH |
5737 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
5738 | (sizeof(struct dasd_psf_prssd_data) + | |
5739 | sizeof(struct dasd_rssd_messages)), | |
c5205f2f | 5740 | device, NULL); |
5db8440c SH |
5741 | if (IS_ERR(cqr)) { |
5742 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
5743 | "Could not allocate read message buffer request"); | |
5744 | return PTR_ERR(cqr); | |
5745 | } | |
5746 | ||
af775210 SH |
5747 | cqr->lpm = lpum; |
5748 | retry: | |
5db8440c SH |
5749 | cqr->startdev = device; |
5750 | cqr->memdev = device; | |
5751 | cqr->block = NULL; | |
5db8440c | 5752 | cqr->expires = 10 * HZ; |
5db8440c | 5753 | set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); |
b179b037 SH |
5754 | /* dasd_sleep_on_immediatly does not do complex error |
5755 | * recovery so clear erp flag and set retry counter to | |
5756 | * do basic erp */ | |
5757 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
5758 | cqr->retries = 256; | |
5db8440c SH |
5759 | |
5760 | /* Prepare for Read Subsystem Data */ | |
5761 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
5762 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); | |
5763 | prssdp->order = PSF_ORDER_PRSSD; | |
5764 | prssdp->suborder = 0x03; /* Message Buffer */ | |
5765 | /* all other bytes of prssdp must be zero */ | |
5766 | ||
5767 | ccw = cqr->cpaddr; | |
5768 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
5769 | ccw->count = sizeof(struct dasd_psf_prssd_data); | |
5770 | ccw->flags |= CCW_FLAG_CC; | |
5771 | ccw->flags |= CCW_FLAG_SLI; | |
5772 | ccw->cda = (__u32)(addr_t) prssdp; | |
5773 | ||
5774 | /* Read Subsystem Data - message buffer */ | |
5775 | message_buf = (struct dasd_rssd_messages *) (prssdp + 1); | |
5776 | memset(message_buf, 0, sizeof(struct dasd_rssd_messages)); | |
5777 | ||
5778 | ccw++; | |
5779 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
5780 | ccw->count = sizeof(struct dasd_rssd_messages); | |
5781 | ccw->flags |= CCW_FLAG_SLI; | |
5782 | ccw->cda = (__u32)(addr_t) message_buf; | |
5783 | ||
5784 | cqr->buildclk = get_tod_clock(); | |
5785 | cqr->status = DASD_CQR_FILLED; | |
5786 | rc = dasd_sleep_on_immediatly(cqr); | |
5787 | if (rc == 0) { | |
5788 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
5789 | message_buf = (struct dasd_rssd_messages *) | |
5790 | (prssdp + 1); | |
5791 | memcpy(messages, message_buf, | |
5792 | sizeof(struct dasd_rssd_messages)); | |
af775210 SH |
5793 | } else if (cqr->lpm) { |
5794 | /* | |
5795 | * on z/VM we might not be able to do I/O on the requested path | |
5796 | * but instead we get the required information on any path | |
5797 | * so retry with open path mask | |
5798 | */ | |
5799 | cqr->lpm = 0; | |
5800 | goto retry; | |
5db8440c SH |
5801 | } else |
5802 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
5803 | "Reading messages failed with rc=%d\n" | |
5804 | , rc); | |
5805 | dasd_sfree_request(cqr, cqr->memdev); | |
5806 | return rc; | |
5807 | } | |
5808 | ||
5a3b7b11 SH |
5809 | static int dasd_eckd_query_host_access(struct dasd_device *device, |
5810 | struct dasd_psf_query_host_access *data) | |
5811 | { | |
5812 | struct dasd_eckd_private *private = device->private; | |
5813 | struct dasd_psf_query_host_access *host_access; | |
5814 | struct dasd_psf_prssd_data *prssdp; | |
5815 | struct dasd_ccw_req *cqr; | |
5816 | struct ccw1 *ccw; | |
5817 | int rc; | |
5818 | ||
5819 | /* not available for HYPER PAV alias devices */ | |
5820 | if (!device->block && private->lcu->pav == HYPER_PAV) | |
5821 | return -EOPNOTSUPP; | |
5822 | ||
ccd53fa2 SH |
5823 | /* may not be supported by the storage server */ |
5824 | if (!(private->features.feature[14] & 0x80)) | |
5825 | return -EOPNOTSUPP; | |
5826 | ||
5a3b7b11 SH |
5827 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
5828 | sizeof(struct dasd_psf_prssd_data) + 1, | |
c5205f2f | 5829 | device, NULL); |
5a3b7b11 SH |
5830 | if (IS_ERR(cqr)) { |
5831 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
5832 | "Could not allocate read message buffer request"); | |
5833 | return PTR_ERR(cqr); | |
5834 | } | |
5835 | host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA); | |
5836 | if (!host_access) { | |
5837 | dasd_sfree_request(cqr, device); | |
5838 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
5839 | "Could not allocate host_access buffer"); | |
5840 | return -ENOMEM; | |
5841 | } | |
5842 | cqr->startdev = device; | |
5843 | cqr->memdev = device; | |
5844 | cqr->block = NULL; | |
5845 | cqr->retries = 256; | |
5846 | cqr->expires = 10 * HZ; | |
5847 | ||
5848 | /* Prepare for Read Subsystem Data */ | |
5849 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
5850 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); | |
5851 | prssdp->order = PSF_ORDER_PRSSD; | |
5852 | prssdp->suborder = PSF_SUBORDER_QHA; /* query host access */ | |
5853 | /* LSS and Volume that will be queried */ | |
5854 | prssdp->lss = private->ned->ID; | |
5855 | prssdp->volume = private->ned->unit_addr; | |
5856 | /* all other bytes of prssdp must be zero */ | |
5857 | ||
5858 | ccw = cqr->cpaddr; | |
5859 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
5860 | ccw->count = sizeof(struct dasd_psf_prssd_data); | |
5861 | ccw->flags |= CCW_FLAG_CC; | |
5862 | ccw->flags |= CCW_FLAG_SLI; | |
5863 | ccw->cda = (__u32)(addr_t) prssdp; | |
5864 | ||
5865 | /* Read Subsystem Data - query host access */ | |
5866 | ccw++; | |
5867 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
5868 | ccw->count = sizeof(struct dasd_psf_query_host_access); | |
5869 | ccw->flags |= CCW_FLAG_SLI; | |
5870 | ccw->cda = (__u32)(addr_t) host_access; | |
5871 | ||
5872 | cqr->buildclk = get_tod_clock(); | |
5873 | cqr->status = DASD_CQR_FILLED; | |
ab24fbd3 SH |
5874 | /* the command might not be supported, suppress error message */ |
5875 | __set_bit(DASD_CQR_SUPPRESS_CR, &cqr->flags); | |
f50af850 | 5876 | rc = dasd_sleep_on_interruptible(cqr); |
5a3b7b11 SH |
5877 | if (rc == 0) { |
5878 | *data = *host_access; | |
5879 | } else { | |
5880 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
5881 | "Reading host access data failed with rc=%d\n", | |
5882 | rc); | |
5883 | rc = -EOPNOTSUPP; | |
5884 | } | |
5885 | ||
5886 | dasd_sfree_request(cqr, cqr->memdev); | |
5887 | kfree(host_access); | |
5888 | return rc; | |
5889 | } | |
5890 | /* | |
5891 | * return number of grouped devices | |
5892 | */ | |
5893 | static int dasd_eckd_host_access_count(struct dasd_device *device) | |
5894 | { | |
5895 | struct dasd_psf_query_host_access *access; | |
5896 | struct dasd_ckd_path_group_entry *entry; | |
5897 | struct dasd_ckd_host_information *info; | |
5898 | int count = 0; | |
5899 | int rc, i; | |
5900 | ||
5901 | access = kzalloc(sizeof(*access), GFP_NOIO); | |
5902 | if (!access) { | |
5903 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
5904 | "Could not allocate access buffer"); | |
5905 | return -ENOMEM; | |
5906 | } | |
5907 | rc = dasd_eckd_query_host_access(device, access); | |
5908 | if (rc) { | |
5909 | kfree(access); | |
5910 | return rc; | |
5911 | } | |
5912 | ||
5913 | info = (struct dasd_ckd_host_information *) | |
5914 | access->host_access_information; | |
5915 | for (i = 0; i < info->entry_count; i++) { | |
5916 | entry = (struct dasd_ckd_path_group_entry *) | |
5917 | (info->entry + i * info->entry_size); | |
5918 | if (entry->status_flags & DASD_ECKD_PG_GROUPED) | |
5919 | count++; | |
5920 | } | |
5921 | ||
5922 | kfree(access); | |
5923 | return count; | |
5924 | } | |
5925 | ||
5926 | /* | |
5927 | * write host access information to a sequential file | |
5928 | */ | |
5929 | static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m) | |
5930 | { | |
5931 | struct dasd_psf_query_host_access *access; | |
5932 | struct dasd_ckd_path_group_entry *entry; | |
5933 | struct dasd_ckd_host_information *info; | |
5934 | char sysplex[9] = ""; | |
c7848e14 | 5935 | int rc, i; |
5a3b7b11 SH |
5936 | |
5937 | access = kzalloc(sizeof(*access), GFP_NOIO); | |
5938 | if (!access) { | |
5939 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
5940 | "Could not allocate access buffer"); | |
5941 | return -ENOMEM; | |
5942 | } | |
5943 | rc = dasd_eckd_query_host_access(device, access); | |
5944 | if (rc) { | |
5945 | kfree(access); | |
5946 | return rc; | |
5947 | } | |
5948 | ||
5949 | info = (struct dasd_ckd_host_information *) | |
5950 | access->host_access_information; | |
5951 | for (i = 0; i < info->entry_count; i++) { | |
5952 | entry = (struct dasd_ckd_path_group_entry *) | |
5953 | (info->entry + i * info->entry_size); | |
5954 | /* PGID */ | |
c7848e14 | 5955 | seq_printf(m, "pgid %*phN\n", 11, entry->pgid); |
5a3b7b11 SH |
5956 | /* FLAGS */ |
5957 | seq_printf(m, "status_flags %02x\n", entry->status_flags); | |
5958 | /* SYSPLEX NAME */ | |
5959 | memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1); | |
5960 | EBCASC(sysplex, sizeof(sysplex)); | |
5961 | seq_printf(m, "sysplex_name %8s\n", sysplex); | |
5962 | /* SUPPORTED CYLINDER */ | |
5963 | seq_printf(m, "supported_cylinder %d\n", entry->cylinder); | |
5964 | /* TIMESTAMP */ | |
5965 | seq_printf(m, "timestamp %lu\n", (unsigned long) | |
5966 | entry->timestamp); | |
5967 | } | |
5968 | kfree(access); | |
5969 | ||
5970 | return 0; | |
5971 | } | |
5972 | ||
5db8440c SH |
5973 | /* |
5974 | * Perform Subsystem Function - CUIR response | |
5975 | */ | |
5976 | static int | |
5977 | dasd_eckd_psf_cuir_response(struct dasd_device *device, int response, | |
a521b048 | 5978 | __u32 message_id, __u8 lpum) |
5db8440c SH |
5979 | { |
5980 | struct dasd_psf_cuir_response *psf_cuir; | |
a521b048 | 5981 | int pos = pathmask_to_pos(lpum); |
5db8440c SH |
5982 | struct dasd_ccw_req *cqr; |
5983 | struct ccw1 *ccw; | |
5984 | int rc; | |
5985 | ||
5986 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , | |
c5205f2f SO |
5987 | sizeof(struct dasd_psf_cuir_response), |
5988 | device, NULL); | |
5db8440c SH |
5989 | |
5990 | if (IS_ERR(cqr)) { | |
5991 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
5992 | "Could not allocate PSF-CUIR request"); | |
5993 | return PTR_ERR(cqr); | |
5994 | } | |
5995 | ||
5996 | psf_cuir = (struct dasd_psf_cuir_response *)cqr->data; | |
5997 | psf_cuir->order = PSF_ORDER_CUIR_RESPONSE; | |
5998 | psf_cuir->cc = response; | |
a521b048 | 5999 | psf_cuir->chpid = device->path[pos].chpid; |
5db8440c | 6000 | psf_cuir->message_id = message_id; |
a521b048 SH |
6001 | psf_cuir->cssid = device->path[pos].cssid; |
6002 | psf_cuir->ssid = device->path[pos].ssid; | |
5db8440c SH |
6003 | ccw = cqr->cpaddr; |
6004 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
6005 | ccw->cda = (__u32)(addr_t)psf_cuir; | |
b179b037 | 6006 | ccw->flags = CCW_FLAG_SLI; |
5db8440c SH |
6007 | ccw->count = sizeof(struct dasd_psf_cuir_response); |
6008 | ||
6009 | cqr->startdev = device; | |
6010 | cqr->memdev = device; | |
6011 | cqr->block = NULL; | |
6012 | cqr->retries = 256; | |
6013 | cqr->expires = 10*HZ; | |
6014 | cqr->buildclk = get_tod_clock(); | |
6015 | cqr->status = DASD_CQR_FILLED; | |
b179b037 | 6016 | set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); |
5db8440c SH |
6017 | |
6018 | rc = dasd_sleep_on(cqr); | |
6019 | ||
6020 | dasd_sfree_request(cqr, cqr->memdev); | |
6021 | return rc; | |
6022 | } | |
6023 | ||
b179b037 SH |
6024 | /* |
6025 | * return configuration data that is referenced by record selector | |
6026 | * if a record selector is specified or per default return the | |
6027 | * conf_data pointer for the path specified by lpum | |
6028 | */ | |
6029 | static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device, | |
6030 | __u8 lpum, | |
6031 | struct dasd_cuir_message *cuir) | |
5db8440c | 6032 | { |
b179b037 SH |
6033 | struct dasd_conf_data *conf_data; |
6034 | int path, pos; | |
5db8440c | 6035 | |
b179b037 SH |
6036 | if (cuir->record_selector == 0) |
6037 | goto out; | |
6038 | for (path = 0x80, pos = 0; path; path >>= 1, pos++) { | |
c9346151 | 6039 | conf_data = device->path[pos].conf_data; |
b179b037 SH |
6040 | if (conf_data->gneq.record_selector == |
6041 | cuir->record_selector) | |
6042 | return conf_data; | |
5db8440c | 6043 | } |
b179b037 | 6044 | out: |
c9346151 | 6045 | return device->path[pathmask_to_pos(lpum)].conf_data; |
5db8440c SH |
6046 | } |
6047 | ||
6048 | /* | |
b179b037 SH |
6049 | * This function determines the scope of a reconfiguration request by |
6050 | * analysing the path and device selection data provided in the CUIR request. | |
6051 | * Returns a path mask containing CUIR affected paths for the give device. | |
6052 | * | |
6053 | * If the CUIR request does not contain the required information return the | |
6054 | * path mask of the path the attention message for the CUIR request was reveived | |
6055 | * on. | |
6056 | */ | |
6057 | static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum, | |
6058 | struct dasd_cuir_message *cuir) | |
6059 | { | |
6060 | struct dasd_conf_data *ref_conf_data; | |
6061 | unsigned long bitmask = 0, mask = 0; | |
b179b037 SH |
6062 | struct dasd_conf_data *conf_data; |
6063 | unsigned int pos, path; | |
6064 | char *ref_gneq, *gneq; | |
6065 | char *ref_ned, *ned; | |
6066 | int tbcpm = 0; | |
6067 | ||
6068 | /* if CUIR request does not specify the scope use the path | |
6069 | the attention message was presented on */ | |
6070 | if (!cuir->ned_map || | |
6071 | !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2])) | |
6072 | return lpum; | |
6073 | ||
b179b037 SH |
6074 | /* get reference conf data */ |
6075 | ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir); | |
6076 | /* reference ned is determined by ned_map field */ | |
6077 | pos = 8 - ffs(cuir->ned_map); | |
6078 | ref_ned = (char *)&ref_conf_data->neds[pos]; | |
6079 | ref_gneq = (char *)&ref_conf_data->gneq; | |
6080 | /* transfer 24 bit neq_map to mask */ | |
6081 | mask = cuir->neq_map[2]; | |
6082 | mask |= cuir->neq_map[1] << 8; | |
6083 | mask |= cuir->neq_map[0] << 16; | |
6084 | ||
c9346151 | 6085 | for (path = 0; path < 8; path++) { |
b179b037 SH |
6086 | /* initialise data per path */ |
6087 | bitmask = mask; | |
c9346151 | 6088 | conf_data = device->path[path].conf_data; |
b179b037 SH |
6089 | pos = 8 - ffs(cuir->ned_map); |
6090 | ned = (char *) &conf_data->neds[pos]; | |
6091 | /* compare reference ned and per path ned */ | |
6092 | if (memcmp(ref_ned, ned, sizeof(*ned)) != 0) | |
6093 | continue; | |
6094 | gneq = (char *)&conf_data->gneq; | |
6095 | /* compare reference gneq and per_path gneq under | |
6096 | 24 bit mask where mask bit 0 equals byte 7 of | |
6097 | the gneq and mask bit 24 equals byte 31 */ | |
6098 | while (bitmask) { | |
6099 | pos = ffs(bitmask) - 1; | |
6100 | if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1) | |
6101 | != 0) | |
6102 | break; | |
6103 | clear_bit(pos, &bitmask); | |
6104 | } | |
6105 | if (bitmask) | |
6106 | continue; | |
6107 | /* device and path match the reference values | |
6108 | add path to CUIR scope */ | |
c9346151 | 6109 | tbcpm |= 0x80 >> path; |
b179b037 SH |
6110 | } |
6111 | return tbcpm; | |
6112 | } | |
6113 | ||
6114 | static void dasd_eckd_cuir_notify_user(struct dasd_device *device, | |
a521b048 | 6115 | unsigned long paths, int action) |
b179b037 | 6116 | { |
b179b037 SH |
6117 | int pos; |
6118 | ||
6119 | while (paths) { | |
6120 | /* get position of bit in mask */ | |
a521b048 | 6121 | pos = 8 - ffs(paths); |
b179b037 | 6122 | /* get channel path descriptor from this position */ |
b179b037 | 6123 | if (action == CUIR_QUIESCE) |
a521b048 SH |
6124 | pr_warn("Service on the storage server caused path %x.%02x to go offline", |
6125 | device->path[pos].cssid, | |
6126 | device->path[pos].chpid); | |
b179b037 | 6127 | else if (action == CUIR_RESUME) |
a521b048 SH |
6128 | pr_info("Path %x.%02x is back online after service on the storage server", |
6129 | device->path[pos].cssid, | |
6130 | device->path[pos].chpid); | |
6131 | clear_bit(7 - pos, &paths); | |
b179b037 SH |
6132 | } |
6133 | } | |
6134 | ||
6135 | static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum, | |
6136 | struct dasd_cuir_message *cuir) | |
6137 | { | |
6138 | unsigned long tbcpm; | |
6139 | ||
6140 | tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir); | |
6141 | /* nothing to do if path is not in use */ | |
c9346151 | 6142 | if (!(dasd_path_get_opm(device) & tbcpm)) |
b179b037 | 6143 | return 0; |
c9346151 | 6144 | if (!(dasd_path_get_opm(device) & ~tbcpm)) { |
b179b037 SH |
6145 | /* no path would be left if the CUIR action is taken |
6146 | return error */ | |
6147 | return -EINVAL; | |
6148 | } | |
6149 | /* remove device from operational path mask */ | |
c9346151 SH |
6150 | dasd_path_remove_opm(device, tbcpm); |
6151 | dasd_path_add_cuirpm(device, tbcpm); | |
b179b037 SH |
6152 | return tbcpm; |
6153 | } | |
6154 | ||
6155 | /* | |
6156 | * walk through all devices and build a path mask to quiesce them | |
6157 | * return an error if the last path to a device would be removed | |
5db8440c SH |
6158 | * |
6159 | * if only part of the devices are quiesced and an error | |
6160 | * occurs no onlining necessary, the storage server will | |
6161 | * notify the already set offline devices again | |
6162 | */ | |
6163 | static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum, | |
b179b037 | 6164 | struct dasd_cuir_message *cuir) |
5db8440c | 6165 | { |
543691a4 | 6166 | struct dasd_eckd_private *private = device->private; |
5db8440c | 6167 | struct alias_pav_group *pavgroup, *tempgroup; |
5db8440c | 6168 | struct dasd_device *dev, *n; |
b179b037 SH |
6169 | unsigned long paths = 0; |
6170 | unsigned long flags; | |
6171 | int tbcpm; | |
5db8440c | 6172 | |
5db8440c | 6173 | /* active devices */ |
b179b037 | 6174 | list_for_each_entry_safe(dev, n, &private->lcu->active_devices, |
5db8440c | 6175 | alias_list) { |
b179b037 SH |
6176 | spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); |
6177 | tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); | |
6178 | spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags); | |
6179 | if (tbcpm < 0) | |
6180 | goto out_err; | |
6181 | paths |= tbcpm; | |
5db8440c | 6182 | } |
5db8440c | 6183 | /* inactive devices */ |
b179b037 | 6184 | list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices, |
5db8440c | 6185 | alias_list) { |
b179b037 SH |
6186 | spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); |
6187 | tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); | |
6188 | spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags); | |
6189 | if (tbcpm < 0) | |
6190 | goto out_err; | |
6191 | paths |= tbcpm; | |
5db8440c | 6192 | } |
5db8440c SH |
6193 | /* devices in PAV groups */ |
6194 | list_for_each_entry_safe(pavgroup, tempgroup, | |
6195 | &private->lcu->grouplist, group) { | |
6196 | list_for_each_entry_safe(dev, n, &pavgroup->baselist, | |
6197 | alias_list) { | |
b179b037 SH |
6198 | spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); |
6199 | tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); | |
6200 | spin_unlock_irqrestore( | |
6201 | get_ccwdev_lock(dev->cdev), flags); | |
6202 | if (tbcpm < 0) | |
6203 | goto out_err; | |
6204 | paths |= tbcpm; | |
5db8440c SH |
6205 | } |
6206 | list_for_each_entry_safe(dev, n, &pavgroup->aliaslist, | |
6207 | alias_list) { | |
b179b037 SH |
6208 | spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); |
6209 | tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); | |
6210 | spin_unlock_irqrestore( | |
6211 | get_ccwdev_lock(dev->cdev), flags); | |
6212 | if (tbcpm < 0) | |
6213 | goto out_err; | |
6214 | paths |= tbcpm; | |
5db8440c SH |
6215 | } |
6216 | } | |
b179b037 | 6217 | /* notify user about all paths affected by CUIR action */ |
a521b048 | 6218 | dasd_eckd_cuir_notify_user(device, paths, CUIR_QUIESCE); |
b179b037 SH |
6219 | return 0; |
6220 | out_err: | |
6221 | return tbcpm; | |
5db8440c SH |
6222 | } |
6223 | ||
6224 | static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum, | |
b179b037 | 6225 | struct dasd_cuir_message *cuir) |
5db8440c | 6226 | { |
543691a4 | 6227 | struct dasd_eckd_private *private = device->private; |
5db8440c | 6228 | struct alias_pav_group *pavgroup, *tempgroup; |
5db8440c | 6229 | struct dasd_device *dev, *n; |
b179b037 SH |
6230 | unsigned long paths = 0; |
6231 | int tbcpm; | |
5db8440c | 6232 | |
5db8440c SH |
6233 | /* |
6234 | * the path may have been added through a generic path event before | |
6235 | * only trigger path verification if the path is not already in use | |
6236 | */ | |
5db8440c SH |
6237 | list_for_each_entry_safe(dev, n, |
6238 | &private->lcu->active_devices, | |
6239 | alias_list) { | |
b179b037 SH |
6240 | tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); |
6241 | paths |= tbcpm; | |
c9346151 SH |
6242 | if (!(dasd_path_get_opm(dev) & tbcpm)) { |
6243 | dasd_path_add_tbvpm(dev, tbcpm); | |
5db8440c SH |
6244 | dasd_schedule_device_bh(dev); |
6245 | } | |
6246 | } | |
5db8440c SH |
6247 | list_for_each_entry_safe(dev, n, |
6248 | &private->lcu->inactive_devices, | |
6249 | alias_list) { | |
b179b037 SH |
6250 | tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); |
6251 | paths |= tbcpm; | |
c9346151 SH |
6252 | if (!(dasd_path_get_opm(dev) & tbcpm)) { |
6253 | dasd_path_add_tbvpm(dev, tbcpm); | |
5db8440c SH |
6254 | dasd_schedule_device_bh(dev); |
6255 | } | |
6256 | } | |
5db8440c SH |
6257 | /* devices in PAV groups */ |
6258 | list_for_each_entry_safe(pavgroup, tempgroup, | |
6259 | &private->lcu->grouplist, | |
6260 | group) { | |
6261 | list_for_each_entry_safe(dev, n, | |
6262 | &pavgroup->baselist, | |
6263 | alias_list) { | |
b179b037 SH |
6264 | tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); |
6265 | paths |= tbcpm; | |
c9346151 SH |
6266 | if (!(dasd_path_get_opm(dev) & tbcpm)) { |
6267 | dasd_path_add_tbvpm(dev, tbcpm); | |
5db8440c SH |
6268 | dasd_schedule_device_bh(dev); |
6269 | } | |
6270 | } | |
6271 | list_for_each_entry_safe(dev, n, | |
6272 | &pavgroup->aliaslist, | |
6273 | alias_list) { | |
b179b037 SH |
6274 | tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); |
6275 | paths |= tbcpm; | |
c9346151 SH |
6276 | if (!(dasd_path_get_opm(dev) & tbcpm)) { |
6277 | dasd_path_add_tbvpm(dev, tbcpm); | |
5db8440c SH |
6278 | dasd_schedule_device_bh(dev); |
6279 | } | |
6280 | } | |
6281 | } | |
b179b037 | 6282 | /* notify user about all paths affected by CUIR action */ |
a521b048 | 6283 | dasd_eckd_cuir_notify_user(device, paths, CUIR_RESUME); |
b179b037 | 6284 | return 0; |
5db8440c SH |
6285 | } |
6286 | ||
6287 | static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages, | |
6288 | __u8 lpum) | |
6289 | { | |
6290 | struct dasd_cuir_message *cuir = messages; | |
a521b048 | 6291 | int response; |
5db8440c | 6292 | |
b179b037 SH |
6293 | DBF_DEV_EVENT(DBF_WARNING, device, |
6294 | "CUIR request: %016llx %016llx %016llx %08x", | |
6295 | ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2], | |
6296 | ((u32 *)cuir)[3]); | |
5db8440c SH |
6297 | |
6298 | if (cuir->code == CUIR_QUIESCE) { | |
6299 | /* quiesce */ | |
a521b048 | 6300 | if (dasd_eckd_cuir_quiesce(device, lpum, cuir)) |
b179b037 SH |
6301 | response = PSF_CUIR_LAST_PATH; |
6302 | else | |
6303 | response = PSF_CUIR_COMPLETED; | |
5db8440c SH |
6304 | } else if (cuir->code == CUIR_RESUME) { |
6305 | /* resume */ | |
a521b048 | 6306 | dasd_eckd_cuir_resume(device, lpum, cuir); |
b179b037 | 6307 | response = PSF_CUIR_COMPLETED; |
5db8440c SH |
6308 | } else |
6309 | response = PSF_CUIR_NOT_SUPPORTED; | |
6310 | ||
b179b037 | 6311 | dasd_eckd_psf_cuir_response(device, response, |
a521b048 | 6312 | cuir->message_id, lpum); |
b179b037 SH |
6313 | DBF_DEV_EVENT(DBF_WARNING, device, |
6314 | "CUIR response: %d on message ID %08x", response, | |
6315 | cuir->message_id); | |
b179b037 SH |
6316 | /* to make sure there is no attention left schedule work again */ |
6317 | device->discipline->check_attention(device, lpum); | |
5db8440c SH |
6318 | } |
6319 | ||
9e12e54c JH |
6320 | static void dasd_eckd_oos_resume(struct dasd_device *device) |
6321 | { | |
6322 | struct dasd_eckd_private *private = device->private; | |
6323 | struct alias_pav_group *pavgroup, *tempgroup; | |
6324 | struct dasd_device *dev, *n; | |
6325 | unsigned long flags; | |
6326 | ||
6327 | spin_lock_irqsave(&private->lcu->lock, flags); | |
6328 | list_for_each_entry_safe(dev, n, &private->lcu->active_devices, | |
6329 | alias_list) { | |
6330 | if (dev->stopped & DASD_STOPPED_NOSPC) | |
6331 | dasd_generic_space_avail(dev); | |
6332 | } | |
6333 | list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices, | |
6334 | alias_list) { | |
6335 | if (dev->stopped & DASD_STOPPED_NOSPC) | |
6336 | dasd_generic_space_avail(dev); | |
6337 | } | |
6338 | /* devices in PAV groups */ | |
6339 | list_for_each_entry_safe(pavgroup, tempgroup, | |
6340 | &private->lcu->grouplist, | |
6341 | group) { | |
6342 | list_for_each_entry_safe(dev, n, &pavgroup->baselist, | |
6343 | alias_list) { | |
6344 | if (dev->stopped & DASD_STOPPED_NOSPC) | |
6345 | dasd_generic_space_avail(dev); | |
6346 | } | |
6347 | list_for_each_entry_safe(dev, n, &pavgroup->aliaslist, | |
6348 | alias_list) { | |
6349 | if (dev->stopped & DASD_STOPPED_NOSPC) | |
6350 | dasd_generic_space_avail(dev); | |
6351 | } | |
6352 | } | |
6353 | spin_unlock_irqrestore(&private->lcu->lock, flags); | |
6354 | } | |
6355 | ||
6356 | static void dasd_eckd_handle_oos(struct dasd_device *device, void *messages, | |
6357 | __u8 lpum) | |
6358 | { | |
6359 | struct dasd_oos_message *oos = messages; | |
6360 | ||
6361 | switch (oos->code) { | |
6362 | case REPO_WARN: | |
6363 | case POOL_WARN: | |
6364 | dev_warn(&device->cdev->dev, | |
6365 | "Extent pool usage has reached a critical value\n"); | |
6366 | dasd_eckd_oos_resume(device); | |
6367 | break; | |
6368 | case REPO_EXHAUST: | |
6369 | case POOL_EXHAUST: | |
6370 | dev_warn(&device->cdev->dev, | |
6371 | "Extent pool is exhausted\n"); | |
6372 | break; | |
6373 | case REPO_RELIEVE: | |
6374 | case POOL_RELIEVE: | |
6375 | dev_info(&device->cdev->dev, | |
6376 | "Extent pool physical space constraint has been relieved\n"); | |
6377 | break; | |
6378 | } | |
6379 | ||
6380 | /* In any case, update related data */ | |
6381 | dasd_eckd_read_ext_pool_info(device); | |
6382 | ||
6383 | /* to make sure there is no attention left schedule work again */ | |
6384 | device->discipline->check_attention(device, lpum); | |
6385 | } | |
6386 | ||
5db8440c SH |
6387 | static void dasd_eckd_check_attention_work(struct work_struct *work) |
6388 | { | |
6389 | struct check_attention_work_data *data; | |
6390 | struct dasd_rssd_messages *messages; | |
6391 | struct dasd_device *device; | |
6392 | int rc; | |
6393 | ||
6394 | data = container_of(work, struct check_attention_work_data, worker); | |
6395 | device = data->device; | |
5db8440c SH |
6396 | messages = kzalloc(sizeof(*messages), GFP_KERNEL); |
6397 | if (!messages) { | |
6398 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
6399 | "Could not allocate attention message buffer"); | |
6400 | goto out; | |
6401 | } | |
5db8440c SH |
6402 | rc = dasd_eckd_read_message_buffer(device, messages, data->lpum); |
6403 | if (rc) | |
6404 | goto out; | |
9e12e54c | 6405 | |
5db8440c SH |
6406 | if (messages->length == ATTENTION_LENGTH_CUIR && |
6407 | messages->format == ATTENTION_FORMAT_CUIR) | |
6408 | dasd_eckd_handle_cuir(device, messages, data->lpum); | |
9e12e54c JH |
6409 | if (messages->length == ATTENTION_LENGTH_OOS && |
6410 | messages->format == ATTENTION_FORMAT_OOS) | |
6411 | dasd_eckd_handle_oos(device, messages, data->lpum); | |
6412 | ||
5db8440c SH |
6413 | out: |
6414 | dasd_put_device(device); | |
6415 | kfree(messages); | |
6416 | kfree(data); | |
6417 | } | |
6418 | ||
6419 | static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum) | |
6420 | { | |
6421 | struct check_attention_work_data *data; | |
6422 | ||
6423 | data = kzalloc(sizeof(*data), GFP_ATOMIC); | |
6424 | if (!data) | |
6425 | return -ENOMEM; | |
6426 | INIT_WORK(&data->worker, dasd_eckd_check_attention_work); | |
6427 | dasd_get_device(device); | |
6428 | data->device = device; | |
6429 | data->lpum = lpum; | |
6430 | schedule_work(&data->worker); | |
6431 | return 0; | |
6432 | } | |
6433 | ||
a521b048 SH |
6434 | static int dasd_eckd_disable_hpf_path(struct dasd_device *device, __u8 lpum) |
6435 | { | |
6436 | if (~lpum & dasd_path_get_opm(device)) { | |
6437 | dasd_path_add_nohpfpm(device, lpum); | |
6438 | dasd_path_remove_opm(device, lpum); | |
6439 | dev_err(&device->cdev->dev, | |
6440 | "Channel path %02X lost HPF functionality and is disabled\n", | |
6441 | lpum); | |
6442 | return 1; | |
6443 | } | |
6444 | return 0; | |
6445 | } | |
6446 | ||
6447 | static void dasd_eckd_disable_hpf_device(struct dasd_device *device) | |
6448 | { | |
6449 | struct dasd_eckd_private *private = device->private; | |
6450 | ||
6451 | dev_err(&device->cdev->dev, | |
6452 | "High Performance FICON disabled\n"); | |
6453 | private->fcx_max_data = 0; | |
6454 | } | |
6455 | ||
6456 | static int dasd_eckd_hpf_enabled(struct dasd_device *device) | |
6457 | { | |
6458 | struct dasd_eckd_private *private = device->private; | |
6459 | ||
6460 | return private->fcx_max_data ? 1 : 0; | |
6461 | } | |
6462 | ||
6463 | static void dasd_eckd_handle_hpf_error(struct dasd_device *device, | |
6464 | struct irb *irb) | |
6465 | { | |
6466 | struct dasd_eckd_private *private = device->private; | |
6467 | ||
6468 | if (!private->fcx_max_data) { | |
6469 | /* sanity check for no HPF, the error makes no sense */ | |
6470 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
6471 | "Trying to disable HPF for a non HPF device"); | |
6472 | return; | |
6473 | } | |
6474 | if (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX) { | |
6475 | dasd_eckd_disable_hpf_device(device); | |
6476 | } else if (irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX) { | |
6477 | if (dasd_eckd_disable_hpf_path(device, irb->esw.esw1.lpum)) | |
6478 | return; | |
6479 | dasd_eckd_disable_hpf_device(device); | |
6480 | dasd_path_set_tbvpm(device, | |
6481 | dasd_path_get_hpfpm(device)); | |
6482 | } | |
6483 | /* | |
6484 | * prevent that any new I/O ist started on the device and schedule a | |
6485 | * requeue of existing requests | |
6486 | */ | |
6487 | dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC); | |
6488 | dasd_schedule_requeue(device); | |
6489 | } | |
6490 | ||
a0610a8a JH |
6491 | /* |
6492 | * Initialize block layer request queue. | |
6493 | */ | |
6494 | static void dasd_eckd_setup_blk_queue(struct dasd_block *block) | |
6495 | { | |
6496 | unsigned int logical_block_size = block->bp_block; | |
6497 | struct request_queue *q = block->request_queue; | |
6498 | struct dasd_device *device = block->base; | |
6499 | int max; | |
6500 | ||
6501 | if (device->features & DASD_FEATURE_USERAW) { | |
6502 | /* | |
6503 | * the max_blocks value for raw_track access is 256 | |
6504 | * it is higher than the native ECKD value because we | |
6505 | * only need one ccw per track | |
6506 | * so the max_hw_sectors are | |
6507 | * 2048 x 512B = 1024kB = 16 tracks | |
6508 | */ | |
6509 | max = DASD_ECKD_MAX_BLOCKS_RAW << block->s2b_shift; | |
6510 | } else { | |
6511 | max = DASD_ECKD_MAX_BLOCKS << block->s2b_shift; | |
6512 | } | |
6513 | blk_queue_flag_set(QUEUE_FLAG_NONROT, q); | |
6514 | q->limits.max_dev_sectors = max; | |
6515 | blk_queue_logical_block_size(q, logical_block_size); | |
6516 | blk_queue_max_hw_sectors(q, max); | |
6517 | blk_queue_max_segments(q, USHRT_MAX); | |
6518 | /* With page sized segments each segment can be translated into one idaw/tidaw */ | |
6519 | blk_queue_max_segment_size(q, PAGE_SIZE); | |
6520 | blk_queue_segment_boundary(q, PAGE_SIZE - 1); | |
6521 | } | |
6522 | ||
d41dd122 | 6523 | static struct ccw_driver dasd_eckd_driver = { |
3bda058b SO |
6524 | .driver = { |
6525 | .name = "dasd-eckd", | |
6526 | .owner = THIS_MODULE, | |
6527 | }, | |
d41dd122 SH |
6528 | .ids = dasd_eckd_ids, |
6529 | .probe = dasd_eckd_probe, | |
6530 | .remove = dasd_generic_remove, | |
6531 | .set_offline = dasd_generic_set_offline, | |
6532 | .set_online = dasd_eckd_set_online, | |
6533 | .notify = dasd_generic_notify, | |
a4d26c6a | 6534 | .path_event = dasd_generic_path_event, |
4679e893 | 6535 | .shutdown = dasd_generic_shutdown, |
d41dd122 SH |
6536 | .freeze = dasd_generic_pm_freeze, |
6537 | .thaw = dasd_generic_restore_device, | |
6538 | .restore = dasd_generic_restore_device, | |
a23ed009 | 6539 | .uc_handler = dasd_generic_uc_handler, |
420f42ec | 6540 | .int_class = IRQIO_DAS, |
d41dd122 | 6541 | }; |
f3eb5384 | 6542 | |
1da177e4 LT |
6543 | static struct dasd_discipline dasd_eckd_discipline = { |
6544 | .owner = THIS_MODULE, | |
6545 | .name = "ECKD", | |
6546 | .ebcname = "ECKD", | |
1da177e4 | 6547 | .check_device = dasd_eckd_check_characteristics, |
8e09f215 | 6548 | .uncheck_device = dasd_eckd_uncheck_device, |
1da177e4 | 6549 | .do_analysis = dasd_eckd_do_analysis, |
a4d26c6a | 6550 | .verify_path = dasd_eckd_verify_path, |
d42e1712 | 6551 | .basic_to_ready = dasd_eckd_basic_to_ready, |
8e09f215 | 6552 | .online_to_ready = dasd_eckd_online_to_ready, |
daa991bf | 6553 | .basic_to_known = dasd_eckd_basic_to_known, |
a0610a8a | 6554 | .setup_blk_queue = dasd_eckd_setup_blk_queue, |
1da177e4 LT |
6555 | .fill_geometry = dasd_eckd_fill_geometry, |
6556 | .start_IO = dasd_start_IO, | |
6557 | .term_IO = dasd_term_IO, | |
8e09f215 | 6558 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
1da177e4 | 6559 | .format_device = dasd_eckd_format_device, |
8fd57520 | 6560 | .check_device_format = dasd_eckd_check_device_format, |
1da177e4 LT |
6561 | .erp_action = dasd_eckd_erp_action, |
6562 | .erp_postaction = dasd_eckd_erp_postaction, | |
5a27e60d | 6563 | .check_for_device_change = dasd_eckd_check_for_device_change, |
8e09f215 SW |
6564 | .build_cp = dasd_eckd_build_alias_cp, |
6565 | .free_cp = dasd_eckd_free_alias_cp, | |
1da177e4 | 6566 | .dump_sense = dasd_eckd_dump_sense, |
fc19f381 | 6567 | .dump_sense_dbf = dasd_eckd_dump_sense_dbf, |
1da177e4 | 6568 | .fill_info = dasd_eckd_fill_info, |
1107ccfb | 6569 | .ioctl = dasd_eckd_ioctl, |
d41dd122 SH |
6570 | .freeze = dasd_eckd_pm_freeze, |
6571 | .restore = dasd_eckd_restore_device, | |
501183f2 | 6572 | .reload = dasd_eckd_reload_device, |
2dedf0d9 | 6573 | .get_uid = dasd_eckd_get_uid, |
f1633031 | 6574 | .kick_validate = dasd_eckd_kick_validate_server, |
5db8440c | 6575 | .check_attention = dasd_eckd_check_attention, |
5a3b7b11 SH |
6576 | .host_access_count = dasd_eckd_host_access_count, |
6577 | .hosts_print = dasd_hosts_print, | |
a521b048 SH |
6578 | .handle_hpf_error = dasd_eckd_handle_hpf_error, |
6579 | .disable_hpf = dasd_eckd_disable_hpf_device, | |
6580 | .hpf_enabled = dasd_eckd_hpf_enabled, | |
6581 | .reset_path = dasd_eckd_reset_path, | |
c729696b JH |
6582 | .is_ese = dasd_eckd_is_ese, |
6583 | .space_allocated = dasd_eckd_space_allocated, | |
6584 | .space_configured = dasd_eckd_space_configured, | |
6585 | .logical_capacity = dasd_eckd_logical_capacity, | |
91dc4a19 | 6586 | .release_space = dasd_eckd_release_space, |
c729696b JH |
6587 | .ext_pool_id = dasd_eckd_ext_pool_id, |
6588 | .ext_size = dasd_eckd_ext_size, | |
6589 | .ext_pool_cap_at_warnlevel = dasd_eckd_ext_pool_cap_at_warnlevel, | |
6590 | .ext_pool_warn_thrshld = dasd_eckd_ext_pool_warn_thrshld, | |
6591 | .ext_pool_oos = dasd_eckd_ext_pool_oos, | |
9e12e54c | 6592 | .ext_pool_exhaust = dasd_eckd_ext_pool_exhaust, |
5e2b17e7 JH |
6593 | .ese_format = dasd_eckd_ese_format, |
6594 | .ese_read = dasd_eckd_ese_read, | |
1da177e4 LT |
6595 | }; |
6596 | ||
6597 | static int __init | |
6598 | dasd_eckd_init(void) | |
6599 | { | |
736e6ea0 SO |
6600 | int ret; |
6601 | ||
1da177e4 | 6602 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
f932bcea SW |
6603 | dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req), |
6604 | GFP_KERNEL | GFP_DMA); | |
6605 | if (!dasd_reserve_req) | |
6606 | return -ENOMEM; | |
9e12e54c JH |
6607 | dasd_vol_info_req = kmalloc(sizeof(*dasd_vol_info_req), |
6608 | GFP_KERNEL | GFP_DMA); | |
6609 | if (!dasd_vol_info_req) | |
6610 | return -ENOMEM; | |
a4d26c6a SW |
6611 | path_verification_worker = kmalloc(sizeof(*path_verification_worker), |
6612 | GFP_KERNEL | GFP_DMA); | |
6613 | if (!path_verification_worker) { | |
6614 | kfree(dasd_reserve_req); | |
9e12e54c | 6615 | kfree(dasd_vol_info_req); |
a4d26c6a SW |
6616 | return -ENOMEM; |
6617 | } | |
558b9ef0 SW |
6618 | rawpadpage = (void *)__get_free_page(GFP_KERNEL); |
6619 | if (!rawpadpage) { | |
6620 | kfree(path_verification_worker); | |
6621 | kfree(dasd_reserve_req); | |
9e12e54c | 6622 | kfree(dasd_vol_info_req); |
558b9ef0 SW |
6623 | return -ENOMEM; |
6624 | } | |
736e6ea0 SO |
6625 | ret = ccw_driver_register(&dasd_eckd_driver); |
6626 | if (!ret) | |
6627 | wait_for_device_probe(); | |
a4d26c6a SW |
6628 | else { |
6629 | kfree(path_verification_worker); | |
f932bcea | 6630 | kfree(dasd_reserve_req); |
9e12e54c | 6631 | kfree(dasd_vol_info_req); |
558b9ef0 | 6632 | free_page((unsigned long)rawpadpage); |
a4d26c6a | 6633 | } |
736e6ea0 | 6634 | return ret; |
1da177e4 LT |
6635 | } |
6636 | ||
6637 | static void __exit | |
6638 | dasd_eckd_cleanup(void) | |
6639 | { | |
6640 | ccw_driver_unregister(&dasd_eckd_driver); | |
a4d26c6a | 6641 | kfree(path_verification_worker); |
f932bcea | 6642 | kfree(dasd_reserve_req); |
558b9ef0 | 6643 | free_page((unsigned long)rawpadpage); |
1da177e4 LT |
6644 | } |
6645 | ||
6646 | module_init(dasd_eckd_init); | |
6647 | module_exit(dasd_eckd_cleanup); |