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