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