Commit | Line | Data |
---|---|---|
138c014d | 1 | /* |
1da177e4 | 2 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
138c014d | 3 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
1da177e4 LT |
4 | * Carsten Otte <Cotte@de.ibm.com> |
5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> | |
6 | * Bugreports.to..: <Linux390@de.ibm.com> | |
d41dd122 | 7 | * Copyright IBM Corp. 1999, 2009 |
ab1d848f NH |
8 | * EMC Symmetrix ioctl Copyright EMC Corporation, 2008 |
9 | * Author.........: Nigel Hislop <hislop_nigel@emc.com> | |
1da177e4 LT |
10 | */ |
11 | ||
ca99dab0 | 12 | #define KMSG_COMPONENT "dasd-eckd" |
fc19f381 | 13 | |
1da177e4 LT |
14 | #include <linux/stddef.h> |
15 | #include <linux/kernel.h> | |
16 | #include <linux/slab.h> | |
17 | #include <linux/hdreg.h> /* HDIO_GETGEO */ | |
18 | #include <linux/bio.h> | |
19 | #include <linux/module.h> | |
048cd4e5 | 20 | #include <linux/compat.h> |
1da177e4 LT |
21 | #include <linux/init.h> |
22 | ||
382b7366 | 23 | #include <asm/css_chars.h> |
1da177e4 LT |
24 | #include <asm/debug.h> |
25 | #include <asm/idals.h> | |
26 | #include <asm/ebcdic.h> | |
27 | #include <asm/io.h> | |
1da177e4 | 28 | #include <asm/uaccess.h> |
40545573 | 29 | #include <asm/cio.h> |
1da177e4 | 30 | #include <asm/ccwdev.h> |
f3eb5384 | 31 | #include <asm/itcw.h> |
1da177e4 LT |
32 | |
33 | #include "dasd_int.h" | |
34 | #include "dasd_eckd.h" | |
35 | ||
36 | #ifdef PRINTK_HEADER | |
37 | #undef PRINTK_HEADER | |
38 | #endif /* PRINTK_HEADER */ | |
39 | #define PRINTK_HEADER "dasd(eckd):" | |
40 | ||
41 | #define ECKD_C0(i) (i->home_bytes) | |
42 | #define ECKD_F(i) (i->formula) | |
43 | #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\ | |
44 | (i->factors.f_0x02.f1)) | |
45 | #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\ | |
46 | (i->factors.f_0x02.f2)) | |
47 | #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\ | |
48 | (i->factors.f_0x02.f3)) | |
49 | #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0) | |
50 | #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0) | |
51 | #define ECKD_F6(i) (i->factor6) | |
52 | #define ECKD_F7(i) (i->factor7) | |
53 | #define ECKD_F8(i) (i->factor8) | |
54 | ||
e4dbb0f2 SH |
55 | /* |
56 | * raw track access always map to 64k in memory | |
57 | * so it maps to 16 blocks of 4k per track | |
58 | */ | |
59 | #define DASD_RAW_BLOCK_PER_TRACK 16 | |
60 | #define DASD_RAW_BLOCKSIZE 4096 | |
61 | /* 64k are 128 x 512 byte sectors */ | |
62 | #define DASD_RAW_SECTORS_PER_TRACK 128 | |
63 | ||
1da177e4 LT |
64 | MODULE_LICENSE("GPL"); |
65 | ||
66 | static struct dasd_discipline dasd_eckd_discipline; | |
67 | ||
1da177e4 LT |
68 | /* The ccw bus type uses this table to find devices that it sends to |
69 | * dasd_eckd_probe */ | |
70 | static struct ccw_device_id dasd_eckd_ids[] = { | |
d2c993d8 HC |
71 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1}, |
72 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2}, | |
5da24b76 | 73 | { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3}, |
d2c993d8 HC |
74 | { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4}, |
75 | { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5}, | |
76 | { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6}, | |
77 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7}, | |
78 | { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8}, | |
79 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9}, | |
80 | { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa}, | |
1da177e4 LT |
81 | { /* end of list */ }, |
82 | }; | |
83 | ||
84 | MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids); | |
85 | ||
86 | static struct ccw_driver dasd_eckd_driver; /* see below */ | |
87 | ||
eb6e199b SW |
88 | #define INIT_CQR_OK 0 |
89 | #define INIT_CQR_UNFORMATTED 1 | |
90 | #define INIT_CQR_ERROR 2 | |
91 | ||
f932bcea SW |
92 | /* emergency request for reserve/release */ |
93 | static struct { | |
94 | struct dasd_ccw_req cqr; | |
95 | struct ccw1 ccw; | |
96 | char data[32]; | |
97 | } *dasd_reserve_req; | |
98 | static DEFINE_MUTEX(dasd_reserve_mutex); | |
99 | ||
a4d26c6a SW |
100 | /* definitions for the path verification worker */ |
101 | struct path_verification_work_data { | |
102 | struct work_struct worker; | |
103 | struct dasd_device *device; | |
104 | struct dasd_ccw_req cqr; | |
105 | struct ccw1 ccw; | |
106 | __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE]; | |
107 | int isglobal; | |
108 | __u8 tbvpm; | |
109 | }; | |
110 | static struct path_verification_work_data *path_verification_worker; | |
111 | static DEFINE_MUTEX(dasd_path_verification_mutex); | |
eb6e199b | 112 | |
1da177e4 LT |
113 | /* initial attempt at a probe function. this can be simplified once |
114 | * the other detection code is gone */ | |
115 | static int | |
116 | dasd_eckd_probe (struct ccw_device *cdev) | |
117 | { | |
118 | int ret; | |
119 | ||
40545573 | 120 | /* set ECKD specific ccw-device options */ |
454e1fa1 PO |
121 | ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE | |
122 | CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH); | |
40545573 | 123 | if (ret) { |
b8ed5dd5 SH |
124 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", |
125 | "dasd_eckd_probe: could not set " | |
126 | "ccw-device options"); | |
1da177e4 | 127 | return ret; |
40545573 HH |
128 | } |
129 | ret = dasd_generic_probe(cdev, &dasd_eckd_discipline); | |
130 | return ret; | |
1da177e4 LT |
131 | } |
132 | ||
133 | static int | |
134 | dasd_eckd_set_online(struct ccw_device *cdev) | |
135 | { | |
40545573 | 136 | return dasd_generic_set_online(cdev, &dasd_eckd_discipline); |
1da177e4 LT |
137 | } |
138 | ||
1da177e4 LT |
139 | static const int sizes_trk0[] = { 28, 148, 84 }; |
140 | #define LABEL_SIZE 140 | |
141 | ||
142 | static inline unsigned int | |
143 | round_up_multiple(unsigned int no, unsigned int mult) | |
144 | { | |
145 | int rem = no % mult; | |
146 | return (rem ? no - rem + mult : no); | |
147 | } | |
148 | ||
149 | static inline unsigned int | |
150 | ceil_quot(unsigned int d1, unsigned int d2) | |
151 | { | |
152 | return (d1 + (d2 - 1)) / d2; | |
153 | } | |
154 | ||
4d284cac | 155 | static unsigned int |
1da177e4 LT |
156 | recs_per_track(struct dasd_eckd_characteristics * rdc, |
157 | unsigned int kl, unsigned int dl) | |
158 | { | |
159 | int dn, kn; | |
160 | ||
161 | switch (rdc->dev_type) { | |
162 | case 0x3380: | |
163 | if (kl) | |
164 | return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) + | |
165 | ceil_quot(dl + 12, 32)); | |
166 | else | |
167 | return 1499 / (15 + ceil_quot(dl + 12, 32)); | |
168 | case 0x3390: | |
169 | dn = ceil_quot(dl + 6, 232) + 1; | |
170 | if (kl) { | |
171 | kn = ceil_quot(kl + 6, 232) + 1; | |
172 | return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) + | |
173 | 9 + ceil_quot(dl + 6 * dn, 34)); | |
174 | } else | |
175 | return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34)); | |
176 | case 0x9345: | |
177 | dn = ceil_quot(dl + 6, 232) + 1; | |
178 | if (kl) { | |
179 | kn = ceil_quot(kl + 6, 232) + 1; | |
180 | return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) + | |
181 | ceil_quot(dl + 6 * dn, 34)); | |
182 | } else | |
183 | return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34)); | |
184 | } | |
185 | return 0; | |
186 | } | |
187 | ||
b44b0ab3 SW |
188 | static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head) |
189 | { | |
190 | geo->cyl = (__u16) cyl; | |
191 | geo->head = cyl >> 16; | |
192 | geo->head <<= 4; | |
193 | geo->head |= head; | |
194 | } | |
195 | ||
4d284cac | 196 | static int |
1da177e4 LT |
197 | check_XRC (struct ccw1 *de_ccw, |
198 | struct DE_eckd_data *data, | |
199 | struct dasd_device *device) | |
200 | { | |
201 | struct dasd_eckd_private *private; | |
d54853ef | 202 | int rc; |
1da177e4 LT |
203 | |
204 | private = (struct dasd_eckd_private *) device->private; | |
d54853ef MS |
205 | if (!private->rdc_data.facilities.XRC_supported) |
206 | return 0; | |
1da177e4 LT |
207 | |
208 | /* switch on System Time Stamp - needed for XRC Support */ | |
d54853ef MS |
209 | data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */ |
210 | data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */ | |
1da177e4 | 211 | |
d54853ef MS |
212 | rc = get_sync_clock(&data->ep_sys_time); |
213 | /* Ignore return code if sync clock is switched off. */ | |
a8f6db4d | 214 | if (rc == -EOPNOTSUPP || rc == -EACCES) |
d54853ef | 215 | rc = 0; |
1da177e4 | 216 | |
8e09f215 | 217 | de_ccw->count = sizeof(struct DE_eckd_data); |
d54853ef MS |
218 | de_ccw->flags |= CCW_FLAG_SLI; |
219 | return rc; | |
220 | } | |
1da177e4 | 221 | |
4d284cac | 222 | static int |
b44b0ab3 SW |
223 | define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk, |
224 | unsigned int totrk, int cmd, struct dasd_device *device) | |
1da177e4 LT |
225 | { |
226 | struct dasd_eckd_private *private; | |
b44b0ab3 SW |
227 | u32 begcyl, endcyl; |
228 | u16 heads, beghead, endhead; | |
d54853ef | 229 | int rc = 0; |
1da177e4 LT |
230 | |
231 | private = (struct dasd_eckd_private *) device->private; | |
232 | ||
233 | ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT; | |
234 | ccw->flags = 0; | |
235 | ccw->count = 16; | |
236 | ccw->cda = (__u32) __pa(data); | |
237 | ||
8e09f215 | 238 | memset(data, 0, sizeof(struct DE_eckd_data)); |
1da177e4 LT |
239 | switch (cmd) { |
240 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
241 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
242 | case DASD_ECKD_CCW_READ: | |
243 | case DASD_ECKD_CCW_READ_MT: | |
244 | case DASD_ECKD_CCW_READ_CKD: | |
245 | case DASD_ECKD_CCW_READ_CKD_MT: | |
246 | case DASD_ECKD_CCW_READ_KD: | |
247 | case DASD_ECKD_CCW_READ_KD_MT: | |
248 | case DASD_ECKD_CCW_READ_COUNT: | |
249 | data->mask.perm = 0x1; | |
250 | data->attributes.operation = private->attrib.operation; | |
251 | break; | |
252 | case DASD_ECKD_CCW_WRITE: | |
253 | case DASD_ECKD_CCW_WRITE_MT: | |
254 | case DASD_ECKD_CCW_WRITE_KD: | |
255 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
256 | data->mask.perm = 0x02; | |
257 | data->attributes.operation = private->attrib.operation; | |
d54853ef | 258 | rc = check_XRC (ccw, data, device); |
1da177e4 LT |
259 | break; |
260 | case DASD_ECKD_CCW_WRITE_CKD: | |
261 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
262 | data->attributes.operation = DASD_BYPASS_CACHE; | |
d54853ef | 263 | rc = check_XRC (ccw, data, device); |
1da177e4 LT |
264 | break; |
265 | case DASD_ECKD_CCW_ERASE: | |
266 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
267 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
268 | data->mask.perm = 0x3; | |
269 | data->mask.auth = 0x1; | |
270 | data->attributes.operation = DASD_BYPASS_CACHE; | |
d54853ef | 271 | rc = check_XRC (ccw, data, device); |
1da177e4 LT |
272 | break; |
273 | default: | |
fc19f381 SH |
274 | dev_err(&device->cdev->dev, |
275 | "0x%x is not a known command\n", cmd); | |
1da177e4 LT |
276 | break; |
277 | } | |
278 | ||
279 | data->attributes.mode = 0x3; /* ECKD */ | |
280 | ||
281 | if ((private->rdc_data.cu_type == 0x2105 || | |
282 | private->rdc_data.cu_type == 0x2107 || | |
283 | private->rdc_data.cu_type == 0x1750) | |
284 | && !(private->uses_cdl && trk < 2)) | |
285 | data->ga_extended |= 0x40; /* Regular Data Format Mode */ | |
286 | ||
b44b0ab3 SW |
287 | heads = private->rdc_data.trk_per_cyl; |
288 | begcyl = trk / heads; | |
289 | beghead = trk % heads; | |
290 | endcyl = totrk / heads; | |
291 | endhead = totrk % heads; | |
1da177e4 LT |
292 | |
293 | /* check for sequential prestage - enhance cylinder range */ | |
294 | if (data->attributes.operation == DASD_SEQ_PRESTAGE || | |
295 | data->attributes.operation == DASD_SEQ_ACCESS) { | |
138c014d | 296 | |
b44b0ab3 SW |
297 | if (endcyl + private->attrib.nr_cyl < private->real_cyl) |
298 | endcyl += private->attrib.nr_cyl; | |
1da177e4 | 299 | else |
b44b0ab3 | 300 | endcyl = (private->real_cyl - 1); |
1da177e4 LT |
301 | } |
302 | ||
b44b0ab3 SW |
303 | set_ch_t(&data->beg_ext, begcyl, beghead); |
304 | set_ch_t(&data->end_ext, endcyl, endhead); | |
d54853ef | 305 | return rc; |
1da177e4 LT |
306 | } |
307 | ||
8e09f215 SW |
308 | static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata, |
309 | struct dasd_device *device) | |
310 | { | |
311 | struct dasd_eckd_private *private; | |
312 | int rc; | |
313 | ||
314 | private = (struct dasd_eckd_private *) device->private; | |
315 | if (!private->rdc_data.facilities.XRC_supported) | |
316 | return 0; | |
317 | ||
318 | /* switch on System Time Stamp - needed for XRC Support */ | |
f3eb5384 SW |
319 | pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */ |
320 | pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */ | |
8e09f215 SW |
321 | pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */ |
322 | ||
f3eb5384 | 323 | rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time); |
8e09f215 | 324 | /* Ignore return code if sync clock is switched off. */ |
a8f6db4d | 325 | if (rc == -EOPNOTSUPP || rc == -EACCES) |
8e09f215 SW |
326 | rc = 0; |
327 | return rc; | |
328 | } | |
329 | ||
f3eb5384 SW |
330 | static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk, |
331 | unsigned int rec_on_trk, int count, int cmd, | |
332 | struct dasd_device *device, unsigned int reclen, | |
333 | unsigned int tlf) | |
334 | { | |
335 | struct dasd_eckd_private *private; | |
336 | int sector; | |
337 | int dn, d; | |
338 | ||
339 | private = (struct dasd_eckd_private *) device->private; | |
340 | ||
341 | memset(data, 0, sizeof(*data)); | |
342 | sector = 0; | |
343 | if (rec_on_trk) { | |
344 | switch (private->rdc_data.dev_type) { | |
345 | case 0x3390: | |
346 | dn = ceil_quot(reclen + 6, 232); | |
347 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); | |
348 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
349 | break; | |
350 | case 0x3380: | |
351 | d = 7 + ceil_quot(reclen + 12, 32); | |
352 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
353 | break; | |
354 | } | |
355 | } | |
356 | data->sector = sector; | |
357 | /* note: meaning of count depends on the operation | |
358 | * for record based I/O it's the number of records, but for | |
359 | * track based I/O it's the number of tracks | |
360 | */ | |
361 | data->count = count; | |
362 | switch (cmd) { | |
363 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
364 | data->operation.orientation = 0x3; | |
365 | data->operation.operation = 0x03; | |
366 | break; | |
367 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
368 | data->operation.orientation = 0x3; | |
369 | data->operation.operation = 0x16; | |
370 | break; | |
371 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
372 | data->operation.orientation = 0x1; | |
373 | data->operation.operation = 0x03; | |
374 | data->count++; | |
375 | break; | |
376 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
377 | data->operation.orientation = 0x3; | |
378 | data->operation.operation = 0x16; | |
379 | data->count++; | |
380 | break; | |
381 | case DASD_ECKD_CCW_WRITE: | |
382 | case DASD_ECKD_CCW_WRITE_MT: | |
383 | case DASD_ECKD_CCW_WRITE_KD: | |
384 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
385 | data->auxiliary.length_valid = 0x1; | |
386 | data->length = reclen; | |
387 | data->operation.operation = 0x01; | |
388 | break; | |
389 | case DASD_ECKD_CCW_WRITE_CKD: | |
390 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
391 | data->auxiliary.length_valid = 0x1; | |
392 | data->length = reclen; | |
393 | data->operation.operation = 0x03; | |
394 | break; | |
e4dbb0f2 SH |
395 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: |
396 | data->operation.orientation = 0x0; | |
397 | data->operation.operation = 0x3F; | |
398 | data->extended_operation = 0x11; | |
399 | data->length = 0; | |
400 | data->extended_parameter_length = 0x02; | |
401 | if (data->count > 8) { | |
402 | data->extended_parameter[0] = 0xFF; | |
403 | data->extended_parameter[1] = 0xFF; | |
404 | data->extended_parameter[1] <<= (16 - count); | |
405 | } else { | |
406 | data->extended_parameter[0] = 0xFF; | |
407 | data->extended_parameter[0] <<= (8 - count); | |
408 | data->extended_parameter[1] = 0x00; | |
409 | } | |
410 | data->sector = 0xFF; | |
411 | break; | |
f3eb5384 SW |
412 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
413 | data->auxiliary.length_valid = 0x1; | |
414 | data->length = reclen; /* not tlf, as one might think */ | |
415 | data->operation.operation = 0x3F; | |
416 | data->extended_operation = 0x23; | |
417 | break; | |
418 | case DASD_ECKD_CCW_READ: | |
419 | case DASD_ECKD_CCW_READ_MT: | |
420 | case DASD_ECKD_CCW_READ_KD: | |
421 | case DASD_ECKD_CCW_READ_KD_MT: | |
422 | data->auxiliary.length_valid = 0x1; | |
423 | data->length = reclen; | |
424 | data->operation.operation = 0x06; | |
425 | break; | |
426 | case DASD_ECKD_CCW_READ_CKD: | |
427 | case DASD_ECKD_CCW_READ_CKD_MT: | |
428 | data->auxiliary.length_valid = 0x1; | |
429 | data->length = reclen; | |
430 | data->operation.operation = 0x16; | |
431 | break; | |
432 | case DASD_ECKD_CCW_READ_COUNT: | |
433 | data->operation.operation = 0x06; | |
434 | break; | |
e4dbb0f2 SH |
435 | case DASD_ECKD_CCW_READ_TRACK: |
436 | data->operation.orientation = 0x1; | |
437 | data->operation.operation = 0x0C; | |
438 | data->extended_parameter_length = 0; | |
439 | data->sector = 0xFF; | |
440 | break; | |
f3eb5384 SW |
441 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
442 | data->auxiliary.length_valid = 0x1; | |
443 | data->length = tlf; | |
444 | data->operation.operation = 0x0C; | |
445 | break; | |
446 | case DASD_ECKD_CCW_ERASE: | |
447 | data->length = reclen; | |
448 | data->auxiliary.length_valid = 0x1; | |
449 | data->operation.operation = 0x0b; | |
450 | break; | |
451 | default: | |
452 | DBF_DEV_EVENT(DBF_ERR, device, | |
453 | "fill LRE unknown opcode 0x%x", cmd); | |
454 | BUG(); | |
455 | } | |
456 | set_ch_t(&data->seek_addr, | |
457 | trk / private->rdc_data.trk_per_cyl, | |
458 | trk % private->rdc_data.trk_per_cyl); | |
459 | data->search_arg.cyl = data->seek_addr.cyl; | |
460 | data->search_arg.head = data->seek_addr.head; | |
461 | data->search_arg.record = rec_on_trk; | |
462 | } | |
463 | ||
464 | static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, | |
465 | unsigned int trk, unsigned int totrk, int cmd, | |
466 | struct dasd_device *basedev, struct dasd_device *startdev, | |
467 | unsigned char format, unsigned int rec_on_trk, int count, | |
468 | unsigned int blksize, unsigned int tlf) | |
8e09f215 SW |
469 | { |
470 | struct dasd_eckd_private *basepriv, *startpriv; | |
f3eb5384 SW |
471 | struct DE_eckd_data *dedata; |
472 | struct LRE_eckd_data *lredata; | |
b44b0ab3 SW |
473 | u32 begcyl, endcyl; |
474 | u16 heads, beghead, endhead; | |
8e09f215 SW |
475 | int rc = 0; |
476 | ||
477 | basepriv = (struct dasd_eckd_private *) basedev->private; | |
478 | startpriv = (struct dasd_eckd_private *) startdev->private; | |
f3eb5384 SW |
479 | dedata = &pfxdata->define_extent; |
480 | lredata = &pfxdata->locate_record; | |
8e09f215 SW |
481 | |
482 | ccw->cmd_code = DASD_ECKD_CCW_PFX; | |
483 | ccw->flags = 0; | |
e4dbb0f2 SH |
484 | if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) { |
485 | ccw->count = sizeof(*pfxdata) + 2; | |
486 | ccw->cda = (__u32) __pa(pfxdata); | |
487 | memset(pfxdata, 0, sizeof(*pfxdata) + 2); | |
488 | } else { | |
489 | ccw->count = sizeof(*pfxdata); | |
490 | ccw->cda = (__u32) __pa(pfxdata); | |
491 | memset(pfxdata, 0, sizeof(*pfxdata)); | |
492 | } | |
8e09f215 | 493 | |
8e09f215 | 494 | /* prefix data */ |
f3eb5384 SW |
495 | if (format > 1) { |
496 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
497 | "PFX LRE unknown format 0x%x", format); | |
498 | BUG(); | |
499 | return -EINVAL; | |
500 | } | |
501 | pfxdata->format = format; | |
4abb08c2 SW |
502 | pfxdata->base_address = basepriv->ned->unit_addr; |
503 | pfxdata->base_lss = basepriv->ned->ID; | |
f3eb5384 | 504 | pfxdata->validity.define_extent = 1; |
8e09f215 SW |
505 | |
506 | /* private uid is kept up to date, conf_data may be outdated */ | |
507 | if (startpriv->uid.type != UA_BASE_DEVICE) { | |
508 | pfxdata->validity.verify_base = 1; | |
509 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) | |
510 | pfxdata->validity.hyper_pav = 1; | |
511 | } | |
512 | ||
513 | /* define extend data (mostly)*/ | |
514 | switch (cmd) { | |
515 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
516 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
517 | case DASD_ECKD_CCW_READ: | |
518 | case DASD_ECKD_CCW_READ_MT: | |
519 | case DASD_ECKD_CCW_READ_CKD: | |
520 | case DASD_ECKD_CCW_READ_CKD_MT: | |
521 | case DASD_ECKD_CCW_READ_KD: | |
522 | case DASD_ECKD_CCW_READ_KD_MT: | |
523 | case DASD_ECKD_CCW_READ_COUNT: | |
f3eb5384 SW |
524 | dedata->mask.perm = 0x1; |
525 | dedata->attributes.operation = basepriv->attrib.operation; | |
526 | break; | |
e4dbb0f2 | 527 | case DASD_ECKD_CCW_READ_TRACK: |
f3eb5384 SW |
528 | case DASD_ECKD_CCW_READ_TRACK_DATA: |
529 | dedata->mask.perm = 0x1; | |
530 | dedata->attributes.operation = basepriv->attrib.operation; | |
531 | dedata->blk_size = 0; | |
8e09f215 SW |
532 | break; |
533 | case DASD_ECKD_CCW_WRITE: | |
534 | case DASD_ECKD_CCW_WRITE_MT: | |
535 | case DASD_ECKD_CCW_WRITE_KD: | |
536 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
f3eb5384 SW |
537 | dedata->mask.perm = 0x02; |
538 | dedata->attributes.operation = basepriv->attrib.operation; | |
8e09f215 SW |
539 | rc = check_XRC_on_prefix(pfxdata, basedev); |
540 | break; | |
541 | case DASD_ECKD_CCW_WRITE_CKD: | |
542 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
f3eb5384 | 543 | dedata->attributes.operation = DASD_BYPASS_CACHE; |
8e09f215 SW |
544 | rc = check_XRC_on_prefix(pfxdata, basedev); |
545 | break; | |
546 | case DASD_ECKD_CCW_ERASE: | |
547 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
548 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
f3eb5384 SW |
549 | dedata->mask.perm = 0x3; |
550 | dedata->mask.auth = 0x1; | |
551 | dedata->attributes.operation = DASD_BYPASS_CACHE; | |
8e09f215 SW |
552 | rc = check_XRC_on_prefix(pfxdata, basedev); |
553 | break; | |
e4dbb0f2 SH |
554 | case DASD_ECKD_CCW_WRITE_FULL_TRACK: |
555 | dedata->mask.perm = 0x03; | |
556 | dedata->attributes.operation = basepriv->attrib.operation; | |
557 | dedata->blk_size = 0; | |
558 | break; | |
f3eb5384 SW |
559 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: |
560 | dedata->mask.perm = 0x02; | |
561 | dedata->attributes.operation = basepriv->attrib.operation; | |
562 | dedata->blk_size = blksize; | |
563 | rc = check_XRC_on_prefix(pfxdata, basedev); | |
8e09f215 | 564 | break; |
f3eb5384 SW |
565 | default: |
566 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
567 | "PFX LRE unknown opcode 0x%x", cmd); | |
568 | BUG(); | |
569 | return -EINVAL; | |
8e09f215 SW |
570 | } |
571 | ||
f3eb5384 | 572 | dedata->attributes.mode = 0x3; /* ECKD */ |
8e09f215 SW |
573 | |
574 | if ((basepriv->rdc_data.cu_type == 0x2105 || | |
575 | basepriv->rdc_data.cu_type == 0x2107 || | |
576 | basepriv->rdc_data.cu_type == 0x1750) | |
577 | && !(basepriv->uses_cdl && trk < 2)) | |
f3eb5384 | 578 | dedata->ga_extended |= 0x40; /* Regular Data Format Mode */ |
8e09f215 | 579 | |
b44b0ab3 SW |
580 | heads = basepriv->rdc_data.trk_per_cyl; |
581 | begcyl = trk / heads; | |
582 | beghead = trk % heads; | |
583 | endcyl = totrk / heads; | |
584 | endhead = totrk % heads; | |
8e09f215 SW |
585 | |
586 | /* check for sequential prestage - enhance cylinder range */ | |
f3eb5384 SW |
587 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || |
588 | dedata->attributes.operation == DASD_SEQ_ACCESS) { | |
8e09f215 | 589 | |
b44b0ab3 SW |
590 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) |
591 | endcyl += basepriv->attrib.nr_cyl; | |
8e09f215 | 592 | else |
b44b0ab3 | 593 | endcyl = (basepriv->real_cyl - 1); |
8e09f215 SW |
594 | } |
595 | ||
f3eb5384 SW |
596 | set_ch_t(&dedata->beg_ext, begcyl, beghead); |
597 | set_ch_t(&dedata->end_ext, endcyl, endhead); | |
598 | ||
599 | if (format == 1) { | |
600 | fill_LRE_data(lredata, trk, rec_on_trk, count, cmd, | |
601 | basedev, blksize, tlf); | |
602 | } | |
603 | ||
8e09f215 SW |
604 | return rc; |
605 | } | |
606 | ||
f3eb5384 SW |
607 | static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, |
608 | unsigned int trk, unsigned int totrk, int cmd, | |
609 | struct dasd_device *basedev, struct dasd_device *startdev) | |
610 | { | |
611 | return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev, | |
612 | 0, 0, 0, 0, 0); | |
613 | } | |
614 | ||
4d284cac | 615 | static void |
b44b0ab3 SW |
616 | locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk, |
617 | unsigned int rec_on_trk, int no_rec, int cmd, | |
1da177e4 LT |
618 | struct dasd_device * device, int reclen) |
619 | { | |
620 | struct dasd_eckd_private *private; | |
621 | int sector; | |
622 | int dn, d; | |
138c014d | 623 | |
1da177e4 LT |
624 | private = (struct dasd_eckd_private *) device->private; |
625 | ||
626 | DBF_DEV_EVENT(DBF_INFO, device, | |
627 | "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d", | |
628 | trk, rec_on_trk, no_rec, cmd, reclen); | |
629 | ||
630 | ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD; | |
631 | ccw->flags = 0; | |
632 | ccw->count = 16; | |
633 | ccw->cda = (__u32) __pa(data); | |
634 | ||
8e09f215 | 635 | memset(data, 0, sizeof(struct LO_eckd_data)); |
1da177e4 LT |
636 | sector = 0; |
637 | if (rec_on_trk) { | |
638 | switch (private->rdc_data.dev_type) { | |
639 | case 0x3390: | |
640 | dn = ceil_quot(reclen + 6, 232); | |
641 | d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34); | |
642 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
643 | break; | |
644 | case 0x3380: | |
645 | d = 7 + ceil_quot(reclen + 12, 32); | |
646 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
647 | break; | |
648 | } | |
649 | } | |
650 | data->sector = sector; | |
651 | data->count = no_rec; | |
652 | switch (cmd) { | |
653 | case DASD_ECKD_CCW_WRITE_HOME_ADDRESS: | |
654 | data->operation.orientation = 0x3; | |
655 | data->operation.operation = 0x03; | |
656 | break; | |
657 | case DASD_ECKD_CCW_READ_HOME_ADDRESS: | |
658 | data->operation.orientation = 0x3; | |
659 | data->operation.operation = 0x16; | |
660 | break; | |
661 | case DASD_ECKD_CCW_WRITE_RECORD_ZERO: | |
662 | data->operation.orientation = 0x1; | |
663 | data->operation.operation = 0x03; | |
664 | data->count++; | |
665 | break; | |
666 | case DASD_ECKD_CCW_READ_RECORD_ZERO: | |
667 | data->operation.orientation = 0x3; | |
668 | data->operation.operation = 0x16; | |
669 | data->count++; | |
670 | break; | |
671 | case DASD_ECKD_CCW_WRITE: | |
672 | case DASD_ECKD_CCW_WRITE_MT: | |
673 | case DASD_ECKD_CCW_WRITE_KD: | |
674 | case DASD_ECKD_CCW_WRITE_KD_MT: | |
675 | data->auxiliary.last_bytes_used = 0x1; | |
676 | data->length = reclen; | |
677 | data->operation.operation = 0x01; | |
678 | break; | |
679 | case DASD_ECKD_CCW_WRITE_CKD: | |
680 | case DASD_ECKD_CCW_WRITE_CKD_MT: | |
681 | data->auxiliary.last_bytes_used = 0x1; | |
682 | data->length = reclen; | |
683 | data->operation.operation = 0x03; | |
684 | break; | |
685 | case DASD_ECKD_CCW_READ: | |
686 | case DASD_ECKD_CCW_READ_MT: | |
687 | case DASD_ECKD_CCW_READ_KD: | |
688 | case DASD_ECKD_CCW_READ_KD_MT: | |
689 | data->auxiliary.last_bytes_used = 0x1; | |
690 | data->length = reclen; | |
691 | data->operation.operation = 0x06; | |
692 | break; | |
693 | case DASD_ECKD_CCW_READ_CKD: | |
694 | case DASD_ECKD_CCW_READ_CKD_MT: | |
695 | data->auxiliary.last_bytes_used = 0x1; | |
696 | data->length = reclen; | |
697 | data->operation.operation = 0x16; | |
698 | break; | |
699 | case DASD_ECKD_CCW_READ_COUNT: | |
700 | data->operation.operation = 0x06; | |
701 | break; | |
702 | case DASD_ECKD_CCW_ERASE: | |
703 | data->length = reclen; | |
704 | data->auxiliary.last_bytes_used = 0x1; | |
705 | data->operation.operation = 0x0b; | |
706 | break; | |
707 | default: | |
fc19f381 SH |
708 | DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record " |
709 | "opcode 0x%x", cmd); | |
1da177e4 | 710 | } |
b44b0ab3 SW |
711 | set_ch_t(&data->seek_addr, |
712 | trk / private->rdc_data.trk_per_cyl, | |
713 | trk % private->rdc_data.trk_per_cyl); | |
714 | data->search_arg.cyl = data->seek_addr.cyl; | |
715 | data->search_arg.head = data->seek_addr.head; | |
1da177e4 LT |
716 | data->search_arg.record = rec_on_trk; |
717 | } | |
718 | ||
719 | /* | |
720 | * Returns 1 if the block is one of the special blocks that needs | |
721 | * to get read/written with the KD variant of the command. | |
722 | * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and | |
723 | * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT. | |
724 | * Luckily the KD variants differ only by one bit (0x08) from the | |
725 | * normal variant. So don't wonder about code like: | |
726 | * if (dasd_eckd_cdl_special(blk_per_trk, recid)) | |
727 | * ccw->cmd_code |= 0x8; | |
728 | */ | |
729 | static inline int | |
730 | dasd_eckd_cdl_special(int blk_per_trk, int recid) | |
731 | { | |
732 | if (recid < 3) | |
733 | return 1; | |
734 | if (recid < blk_per_trk) | |
735 | return 0; | |
736 | if (recid < 2 * blk_per_trk) | |
737 | return 1; | |
738 | return 0; | |
739 | } | |
740 | ||
741 | /* | |
742 | * Returns the record size for the special blocks of the cdl format. | |
743 | * Only returns something useful if dasd_eckd_cdl_special is true | |
744 | * for the recid. | |
745 | */ | |
746 | static inline int | |
747 | dasd_eckd_cdl_reclen(int recid) | |
748 | { | |
749 | if (recid < 3) | |
750 | return sizes_trk0[recid]; | |
751 | return LABEL_SIZE; | |
752 | } | |
b206181d SH |
753 | /* create unique id from private structure. */ |
754 | static void create_uid(struct dasd_eckd_private *private) | |
3d052595 | 755 | { |
4abb08c2 | 756 | int count; |
b206181d | 757 | struct dasd_uid *uid; |
3d052595 | 758 | |
2dedf0d9 | 759 | uid = &private->uid; |
3d052595 | 760 | memset(uid, 0, sizeof(struct dasd_uid)); |
4abb08c2 | 761 | memcpy(uid->vendor, private->ned->HDA_manufacturer, |
d0710c7c | 762 | sizeof(uid->vendor) - 1); |
3d052595 | 763 | EBCASC(uid->vendor, sizeof(uid->vendor) - 1); |
4abb08c2 | 764 | memcpy(uid->serial, private->ned->HDA_location, |
d0710c7c | 765 | sizeof(uid->serial) - 1); |
3d052595 | 766 | EBCASC(uid->serial, sizeof(uid->serial) - 1); |
4abb08c2 | 767 | uid->ssid = private->gneq->subsystemID; |
a419aef8 | 768 | uid->real_unit_addr = private->ned->unit_addr; |
4abb08c2 SW |
769 | if (private->sneq) { |
770 | uid->type = private->sneq->sua_flags; | |
8e09f215 | 771 | if (uid->type == UA_BASE_PAV_ALIAS) |
4abb08c2 | 772 | uid->base_unit_addr = private->sneq->base_unit_addr; |
8e09f215 SW |
773 | } else { |
774 | uid->type = UA_BASE_DEVICE; | |
775 | } | |
4abb08c2 SW |
776 | if (private->vdsneq) { |
777 | for (count = 0; count < 16; count++) { | |
778 | sprintf(uid->vduit+2*count, "%02x", | |
779 | private->vdsneq->uit[count]); | |
780 | } | |
781 | } | |
b206181d SH |
782 | } |
783 | ||
784 | /* | |
785 | * Generate device unique id that specifies the physical device. | |
786 | */ | |
787 | static int dasd_eckd_generate_uid(struct dasd_device *device) | |
788 | { | |
789 | struct dasd_eckd_private *private; | |
790 | unsigned long flags; | |
791 | ||
792 | private = (struct dasd_eckd_private *) device->private; | |
793 | if (!private) | |
794 | return -ENODEV; | |
795 | if (!private->ned || !private->gneq) | |
796 | return -ENODEV; | |
797 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
798 | create_uid(private); | |
2dedf0d9 | 799 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
3d052595 HH |
800 | return 0; |
801 | } | |
802 | ||
2dedf0d9 SH |
803 | static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid) |
804 | { | |
805 | struct dasd_eckd_private *private; | |
806 | unsigned long flags; | |
807 | ||
808 | if (device->private) { | |
809 | private = (struct dasd_eckd_private *)device->private; | |
810 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
811 | *uid = private->uid; | |
812 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
813 | return 0; | |
814 | } | |
815 | return -EINVAL; | |
816 | } | |
817 | ||
b206181d SH |
818 | /* |
819 | * compare device UID with data of a given dasd_eckd_private structure | |
820 | * return 0 for match | |
821 | */ | |
822 | static int dasd_eckd_compare_path_uid(struct dasd_device *device, | |
823 | struct dasd_eckd_private *private) | |
824 | { | |
825 | struct dasd_uid device_uid; | |
826 | ||
827 | create_uid(private); | |
828 | dasd_eckd_get_uid(device, &device_uid); | |
829 | ||
830 | return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid)); | |
831 | } | |
832 | ||
a4d26c6a SW |
833 | static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device, |
834 | struct dasd_ccw_req *cqr, | |
835 | __u8 *rcd_buffer, | |
836 | __u8 lpm) | |
17283b56 | 837 | { |
17283b56 | 838 | struct ccw1 *ccw; |
a4d26c6a SW |
839 | /* |
840 | * buffer has to start with EBCDIC "V1.0" to show | |
841 | * support for virtual device SNEQ | |
842 | */ | |
843 | rcd_buffer[0] = 0xE5; | |
844 | rcd_buffer[1] = 0xF1; | |
845 | rcd_buffer[2] = 0x4B; | |
846 | rcd_buffer[3] = 0xF0; | |
17283b56 CH |
847 | |
848 | ccw = cqr->cpaddr; | |
a4d26c6a SW |
849 | ccw->cmd_code = DASD_ECKD_CCW_RCD; |
850 | ccw->flags = 0; | |
17283b56 | 851 | ccw->cda = (__u32)(addr_t)rcd_buffer; |
a4d26c6a SW |
852 | ccw->count = DASD_ECKD_RCD_DATA_SIZE; |
853 | cqr->magic = DASD_ECKD_MAGIC; | |
17283b56 | 854 | |
8e09f215 SW |
855 | cqr->startdev = device; |
856 | cqr->memdev = device; | |
857 | cqr->block = NULL; | |
17283b56 CH |
858 | cqr->expires = 10*HZ; |
859 | cqr->lpm = lpm; | |
eb6e199b | 860 | cqr->retries = 256; |
17283b56 CH |
861 | cqr->buildclk = get_clock(); |
862 | cqr->status = DASD_CQR_FILLED; | |
a4d26c6a SW |
863 | set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); |
864 | } | |
865 | ||
5915a873 SH |
866 | /* |
867 | * Wakeup helper for read_conf | |
868 | * if the cqr is not done and needs some error recovery | |
869 | * the buffer has to be re-initialized with the EBCDIC "V1.0" | |
870 | * to show support for virtual device SNEQ | |
871 | */ | |
872 | static void read_conf_cb(struct dasd_ccw_req *cqr, void *data) | |
873 | { | |
874 | struct ccw1 *ccw; | |
875 | __u8 *rcd_buffer; | |
876 | ||
877 | if (cqr->status != DASD_CQR_DONE) { | |
878 | ccw = cqr->cpaddr; | |
879 | rcd_buffer = (__u8 *)((addr_t) ccw->cda); | |
880 | memset(rcd_buffer, 0, sizeof(*rcd_buffer)); | |
881 | ||
882 | rcd_buffer[0] = 0xE5; | |
883 | rcd_buffer[1] = 0xF1; | |
884 | rcd_buffer[2] = 0x4B; | |
885 | rcd_buffer[3] = 0xF0; | |
886 | } | |
887 | dasd_wakeup_cb(cqr, data); | |
888 | } | |
889 | ||
a4d26c6a SW |
890 | static int dasd_eckd_read_conf_immediately(struct dasd_device *device, |
891 | struct dasd_ccw_req *cqr, | |
892 | __u8 *rcd_buffer, | |
893 | __u8 lpm) | |
894 | { | |
895 | struct ciw *ciw; | |
896 | int rc; | |
897 | /* | |
898 | * sanity check: scan for RCD command in extended SenseID data | |
899 | * some devices do not support RCD | |
900 | */ | |
901 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); | |
902 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) | |
903 | return -EOPNOTSUPP; | |
904 | ||
905 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm); | |
906 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
5a27e60d | 907 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
a4d26c6a | 908 | cqr->retries = 5; |
5915a873 | 909 | cqr->callback = read_conf_cb; |
a4d26c6a SW |
910 | rc = dasd_sleep_on_immediatly(cqr); |
911 | return rc; | |
17283b56 CH |
912 | } |
913 | ||
914 | static int dasd_eckd_read_conf_lpm(struct dasd_device *device, | |
915 | void **rcd_buffer, | |
916 | int *rcd_buffer_size, __u8 lpm) | |
917 | { | |
918 | struct ciw *ciw; | |
919 | char *rcd_buf = NULL; | |
920 | int ret; | |
921 | struct dasd_ccw_req *cqr; | |
922 | ||
923 | /* | |
a4d26c6a SW |
924 | * sanity check: scan for RCD command in extended SenseID data |
925 | * some devices do not support RCD | |
17283b56 CH |
926 | */ |
927 | ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD); | |
a4d26c6a | 928 | if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) { |
17283b56 CH |
929 | ret = -EOPNOTSUPP; |
930 | goto out_error; | |
931 | } | |
a4d26c6a | 932 | rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA); |
17283b56 CH |
933 | if (!rcd_buf) { |
934 | ret = -ENOMEM; | |
935 | goto out_error; | |
936 | } | |
a4d26c6a SW |
937 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, |
938 | 0, /* use rcd_buf as data ara */ | |
939 | device); | |
17283b56 | 940 | if (IS_ERR(cqr)) { |
a4d26c6a SW |
941 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
942 | "Could not allocate RCD request"); | |
943 | ret = -ENOMEM; | |
17283b56 CH |
944 | goto out_error; |
945 | } | |
a4d26c6a | 946 | dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm); |
5915a873 | 947 | cqr->callback = read_conf_cb; |
17283b56 CH |
948 | ret = dasd_sleep_on(cqr); |
949 | /* | |
950 | * on success we update the user input parms | |
951 | */ | |
8e09f215 | 952 | dasd_sfree_request(cqr, cqr->memdev); |
17283b56 CH |
953 | if (ret) |
954 | goto out_error; | |
955 | ||
a4d26c6a | 956 | *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE; |
17283b56 CH |
957 | *rcd_buffer = rcd_buf; |
958 | return 0; | |
959 | out_error: | |
960 | kfree(rcd_buf); | |
961 | *rcd_buffer = NULL; | |
962 | *rcd_buffer_size = 0; | |
963 | return ret; | |
964 | } | |
965 | ||
4abb08c2 SW |
966 | static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private) |
967 | { | |
968 | ||
969 | struct dasd_sneq *sneq; | |
970 | int i, count; | |
971 | ||
972 | private->ned = NULL; | |
973 | private->sneq = NULL; | |
974 | private->vdsneq = NULL; | |
975 | private->gneq = NULL; | |
976 | count = private->conf_len / sizeof(struct dasd_sneq); | |
977 | sneq = (struct dasd_sneq *)private->conf_data; | |
978 | for (i = 0; i < count; ++i) { | |
979 | if (sneq->flags.identifier == 1 && sneq->format == 1) | |
980 | private->sneq = sneq; | |
981 | else if (sneq->flags.identifier == 1 && sneq->format == 4) | |
982 | private->vdsneq = (struct vd_sneq *)sneq; | |
983 | else if (sneq->flags.identifier == 2) | |
984 | private->gneq = (struct dasd_gneq *)sneq; | |
985 | else if (sneq->flags.identifier == 3 && sneq->res1 == 1) | |
986 | private->ned = (struct dasd_ned *)sneq; | |
987 | sneq++; | |
988 | } | |
989 | if (!private->ned || !private->gneq) { | |
990 | private->ned = NULL; | |
991 | private->sneq = NULL; | |
992 | private->vdsneq = NULL; | |
993 | private->gneq = NULL; | |
994 | return -EINVAL; | |
995 | } | |
996 | return 0; | |
997 | ||
998 | }; | |
999 | ||
1000 | static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len) | |
1001 | { | |
1002 | struct dasd_gneq *gneq; | |
1003 | int i, count, found; | |
1004 | ||
1005 | count = conf_len / sizeof(*gneq); | |
1006 | gneq = (struct dasd_gneq *)conf_data; | |
1007 | found = 0; | |
1008 | for (i = 0; i < count; ++i) { | |
1009 | if (gneq->flags.identifier == 2) { | |
1010 | found = 1; | |
1011 | break; | |
1012 | } | |
1013 | gneq++; | |
1014 | } | |
1015 | if (found) | |
1016 | return ((char *)gneq)[18] & 0x07; | |
1017 | else | |
1018 | return 0; | |
1019 | } | |
1020 | ||
1021 | static int dasd_eckd_read_conf(struct dasd_device *device) | |
1da177e4 LT |
1022 | { |
1023 | void *conf_data; | |
1024 | int conf_len, conf_data_saved; | |
1025 | int rc; | |
a4d26c6a | 1026 | __u8 lpm, opm; |
b206181d | 1027 | struct dasd_eckd_private *private, path_private; |
a4d26c6a | 1028 | struct dasd_path *path_data; |
b206181d SH |
1029 | struct dasd_uid *uid; |
1030 | char print_path_uid[60], print_device_uid[60]; | |
1da177e4 LT |
1031 | |
1032 | private = (struct dasd_eckd_private *) device->private; | |
a4d26c6a SW |
1033 | path_data = &device->path_data; |
1034 | opm = ccw_device_get_path_mask(device->cdev); | |
1da177e4 | 1035 | conf_data_saved = 0; |
1da177e4 LT |
1036 | /* get configuration data per operational path */ |
1037 | for (lpm = 0x80; lpm; lpm>>= 1) { | |
b206181d SH |
1038 | if (!(lpm & opm)) |
1039 | continue; | |
1040 | rc = dasd_eckd_read_conf_lpm(device, &conf_data, | |
1041 | &conf_len, lpm); | |
1042 | if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ | |
1043 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
1044 | "Read configuration data returned " | |
1045 | "error %d", rc); | |
1046 | return rc; | |
1047 | } | |
1048 | if (conf_data == NULL) { | |
1049 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1050 | "No configuration data " | |
1051 | "retrieved"); | |
1052 | /* no further analysis possible */ | |
1053 | path_data->opm |= lpm; | |
1054 | continue; /* no error */ | |
1055 | } | |
1056 | /* save first valid configuration data */ | |
1057 | if (!conf_data_saved) { | |
1058 | kfree(private->conf_data); | |
1059 | private->conf_data = conf_data; | |
1060 | private->conf_len = conf_len; | |
1061 | if (dasd_eckd_identify_conf_parts(private)) { | |
1062 | private->conf_data = NULL; | |
1063 | private->conf_len = 0; | |
1064 | kfree(conf_data); | |
1065 | continue; | |
1da177e4 | 1066 | } |
b206181d SH |
1067 | /* |
1068 | * build device UID that other path data | |
1069 | * can be compared to it | |
1070 | */ | |
1071 | dasd_eckd_generate_uid(device); | |
1072 | conf_data_saved++; | |
1073 | } else { | |
1074 | path_private.conf_data = conf_data; | |
1075 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; | |
1076 | if (dasd_eckd_identify_conf_parts( | |
1077 | &path_private)) { | |
1078 | path_private.conf_data = NULL; | |
1079 | path_private.conf_len = 0; | |
1080 | kfree(conf_data); | |
1081 | continue; | |
1da177e4 | 1082 | } |
b206181d SH |
1083 | |
1084 | if (dasd_eckd_compare_path_uid( | |
1085 | device, &path_private)) { | |
1086 | uid = &path_private.uid; | |
1087 | if (strlen(uid->vduit) > 0) | |
1088 | snprintf(print_path_uid, | |
1089 | sizeof(print_path_uid), | |
1090 | "%s.%s.%04x.%02x.%s", | |
1091 | uid->vendor, uid->serial, | |
1092 | uid->ssid, uid->real_unit_addr, | |
1093 | uid->vduit); | |
1094 | else | |
1095 | snprintf(print_path_uid, | |
1096 | sizeof(print_path_uid), | |
1097 | "%s.%s.%04x.%02x", | |
1098 | uid->vendor, uid->serial, | |
1099 | uid->ssid, | |
1100 | uid->real_unit_addr); | |
1101 | uid = &private->uid; | |
1102 | if (strlen(uid->vduit) > 0) | |
1103 | snprintf(print_device_uid, | |
1104 | sizeof(print_device_uid), | |
1105 | "%s.%s.%04x.%02x.%s", | |
1106 | uid->vendor, uid->serial, | |
1107 | uid->ssid, uid->real_unit_addr, | |
1108 | uid->vduit); | |
1109 | else | |
1110 | snprintf(print_device_uid, | |
1111 | sizeof(print_device_uid), | |
1112 | "%s.%s.%04x.%02x", | |
1113 | uid->vendor, uid->serial, | |
1114 | uid->ssid, | |
1115 | uid->real_unit_addr); | |
1116 | dev_err(&device->cdev->dev, | |
1117 | "Not all channel paths lead to " | |
1118 | "the same device, path %02X leads to " | |
1119 | "device %s instead of %s\n", lpm, | |
1120 | print_path_uid, print_device_uid); | |
1121 | return -EINVAL; | |
1da177e4 | 1122 | } |
b206181d SH |
1123 | |
1124 | path_private.conf_data = NULL; | |
1125 | path_private.conf_len = 0; | |
1126 | } | |
1127 | switch (dasd_eckd_path_access(conf_data, conf_len)) { | |
1128 | case 0x02: | |
1129 | path_data->npm |= lpm; | |
1130 | break; | |
1131 | case 0x03: | |
1132 | path_data->ppm |= lpm; | |
1133 | break; | |
1da177e4 | 1134 | } |
b206181d SH |
1135 | path_data->opm |= lpm; |
1136 | ||
1137 | if (conf_data != private->conf_data) | |
1138 | kfree(conf_data); | |
1da177e4 | 1139 | } |
b206181d | 1140 | |
1da177e4 LT |
1141 | return 0; |
1142 | } | |
1143 | ||
a4d26c6a SW |
1144 | static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm) |
1145 | { | |
1146 | struct dasd_eckd_private *private; | |
1147 | int mdc; | |
1148 | u32 fcx_max_data; | |
1149 | ||
1150 | private = (struct dasd_eckd_private *) device->private; | |
1151 | if (private->fcx_max_data) { | |
1152 | mdc = ccw_device_get_mdc(device->cdev, lpm); | |
1153 | if ((mdc < 0)) { | |
1154 | dev_warn(&device->cdev->dev, | |
1155 | "Detecting the maximum data size for zHPF " | |
1156 | "requests failed (rc=%d) for a new path %x\n", | |
1157 | mdc, lpm); | |
1158 | return mdc; | |
1159 | } | |
1160 | fcx_max_data = mdc * FCX_MAX_DATA_FACTOR; | |
1161 | if (fcx_max_data < private->fcx_max_data) { | |
1162 | dev_warn(&device->cdev->dev, | |
1163 | "The maximum data size for zHPF requests %u " | |
1164 | "on a new path %x is below the active maximum " | |
1165 | "%u\n", fcx_max_data, lpm, | |
1166 | private->fcx_max_data); | |
1167 | return -EACCES; | |
1168 | } | |
1169 | } | |
1170 | return 0; | |
1171 | } | |
1172 | ||
b206181d SH |
1173 | static int rebuild_device_uid(struct dasd_device *device, |
1174 | struct path_verification_work_data *data) | |
1175 | { | |
1176 | struct dasd_eckd_private *private; | |
1177 | struct dasd_path *path_data; | |
1178 | __u8 lpm, opm; | |
1179 | int rc; | |
1180 | ||
1181 | rc = -ENODEV; | |
1182 | private = (struct dasd_eckd_private *) device->private; | |
1183 | path_data = &device->path_data; | |
1184 | opm = device->path_data.opm; | |
1185 | ||
1186 | for (lpm = 0x80; lpm; lpm >>= 1) { | |
1187 | if (!(lpm & opm)) | |
1188 | continue; | |
1189 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); | |
1190 | memset(&data->cqr, 0, sizeof(data->cqr)); | |
1191 | data->cqr.cpaddr = &data->ccw; | |
1192 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, | |
1193 | data->rcd_buffer, | |
1194 | lpm); | |
1195 | ||
1196 | if (rc) { | |
1197 | if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */ | |
1198 | continue; | |
1199 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, | |
1200 | "Read configuration data " | |
1201 | "returned error %d", rc); | |
1202 | break; | |
1203 | } | |
1204 | memcpy(private->conf_data, data->rcd_buffer, | |
1205 | DASD_ECKD_RCD_DATA_SIZE); | |
1206 | if (dasd_eckd_identify_conf_parts(private)) { | |
1207 | rc = -ENODEV; | |
1208 | } else /* first valid path is enough */ | |
1209 | break; | |
1210 | } | |
1211 | ||
1212 | if (!rc) | |
1213 | rc = dasd_eckd_generate_uid(device); | |
1214 | ||
1215 | return rc; | |
1216 | } | |
1217 | ||
a4d26c6a SW |
1218 | static void do_path_verification_work(struct work_struct *work) |
1219 | { | |
1220 | struct path_verification_work_data *data; | |
1221 | struct dasd_device *device; | |
b206181d SH |
1222 | struct dasd_eckd_private path_private; |
1223 | struct dasd_uid *uid; | |
1224 | __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE]; | |
a4d26c6a SW |
1225 | __u8 lpm, opm, npm, ppm, epm; |
1226 | unsigned long flags; | |
b206181d | 1227 | char print_uid[60]; |
a4d26c6a SW |
1228 | int rc; |
1229 | ||
1230 | data = container_of(work, struct path_verification_work_data, worker); | |
1231 | device = data->device; | |
1232 | ||
c8d1c0ff SH |
1233 | /* delay path verification until device was resumed */ |
1234 | if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { | |
1235 | schedule_work(work); | |
1236 | return; | |
1237 | } | |
1238 | ||
a4d26c6a SW |
1239 | opm = 0; |
1240 | npm = 0; | |
1241 | ppm = 0; | |
1242 | epm = 0; | |
1243 | for (lpm = 0x80; lpm; lpm >>= 1) { | |
b206181d SH |
1244 | if (!(lpm & data->tbvpm)) |
1245 | continue; | |
1246 | memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer)); | |
1247 | memset(&data->cqr, 0, sizeof(data->cqr)); | |
1248 | data->cqr.cpaddr = &data->ccw; | |
1249 | rc = dasd_eckd_read_conf_immediately(device, &data->cqr, | |
1250 | data->rcd_buffer, | |
1251 | lpm); | |
1252 | if (!rc) { | |
1253 | switch (dasd_eckd_path_access(data->rcd_buffer, | |
1254 | DASD_ECKD_RCD_DATA_SIZE) | |
1255 | ) { | |
1256 | case 0x02: | |
1257 | npm |= lpm; | |
1258 | break; | |
1259 | case 0x03: | |
1260 | ppm |= lpm; | |
1261 | break; | |
1262 | } | |
1263 | opm |= lpm; | |
1264 | } else if (rc == -EOPNOTSUPP) { | |
1265 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
1266 | "path verification: No configuration " | |
1267 | "data retrieved"); | |
1268 | opm |= lpm; | |
1269 | } else if (rc == -EAGAIN) { | |
1270 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", | |
a4d26c6a SW |
1271 | "path verification: device is stopped," |
1272 | " try again later"); | |
b206181d SH |
1273 | epm |= lpm; |
1274 | } else { | |
1275 | dev_warn(&device->cdev->dev, | |
1276 | "Reading device feature codes failed " | |
1277 | "(rc=%d) for new path %x\n", rc, lpm); | |
1278 | continue; | |
1279 | } | |
1280 | if (verify_fcx_max_data(device, lpm)) { | |
1281 | opm &= ~lpm; | |
1282 | npm &= ~lpm; | |
1283 | ppm &= ~lpm; | |
1284 | continue; | |
1285 | } | |
1286 | ||
1287 | /* | |
1288 | * save conf_data for comparison after | |
1289 | * rebuild_device_uid may have changed | |
1290 | * the original data | |
1291 | */ | |
1292 | memcpy(&path_rcd_buf, data->rcd_buffer, | |
1293 | DASD_ECKD_RCD_DATA_SIZE); | |
1294 | path_private.conf_data = (void *) &path_rcd_buf; | |
1295 | path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE; | |
1296 | if (dasd_eckd_identify_conf_parts(&path_private)) { | |
1297 | path_private.conf_data = NULL; | |
1298 | path_private.conf_len = 0; | |
1299 | continue; | |
1300 | } | |
1301 | ||
1302 | /* | |
1303 | * compare path UID with device UID only if at least | |
1304 | * one valid path is left | |
1305 | * in other case the device UID may have changed and | |
1306 | * the first working path UID will be used as device UID | |
1307 | */ | |
1308 | if (device->path_data.opm && | |
1309 | dasd_eckd_compare_path_uid(device, &path_private)) { | |
1310 | /* | |
1311 | * the comparison was not successful | |
1312 | * rebuild the device UID with at least one | |
1313 | * known path in case a z/VM hyperswap command | |
1314 | * has changed the device | |
1315 | * | |
1316 | * after this compare again | |
1317 | * | |
1318 | * if either the rebuild or the recompare fails | |
1319 | * the path can not be used | |
1320 | */ | |
1321 | if (rebuild_device_uid(device, data) || | |
1322 | dasd_eckd_compare_path_uid( | |
1323 | device, &path_private)) { | |
1324 | uid = &path_private.uid; | |
1325 | if (strlen(uid->vduit) > 0) | |
1326 | snprintf(print_uid, sizeof(print_uid), | |
1327 | "%s.%s.%04x.%02x.%s", | |
1328 | uid->vendor, uid->serial, | |
1329 | uid->ssid, uid->real_unit_addr, | |
1330 | uid->vduit); | |
1331 | else | |
1332 | snprintf(print_uid, sizeof(print_uid), | |
1333 | "%s.%s.%04x.%02x", | |
1334 | uid->vendor, uid->serial, | |
1335 | uid->ssid, | |
1336 | uid->real_unit_addr); | |
1337 | dev_err(&device->cdev->dev, | |
1338 | "The newly added channel path %02X " | |
1339 | "will not be used because it leads " | |
1340 | "to a different device %s\n", | |
1341 | lpm, print_uid); | |
a4d26c6a SW |
1342 | opm &= ~lpm; |
1343 | npm &= ~lpm; | |
1344 | ppm &= ~lpm; | |
b206181d | 1345 | continue; |
a4d26c6a SW |
1346 | } |
1347 | } | |
b206181d SH |
1348 | |
1349 | /* | |
1350 | * There is a small chance that a path is lost again between | |
1351 | * above path verification and the following modification of | |
1352 | * the device opm mask. We could avoid that race here by using | |
1353 | * yet another path mask, but we rather deal with this unlikely | |
1354 | * situation in dasd_start_IO. | |
1355 | */ | |
1356 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
1357 | if (!device->path_data.opm && opm) { | |
1358 | device->path_data.opm = opm; | |
1359 | dasd_generic_path_operational(device); | |
1360 | } else | |
1361 | device->path_data.opm |= opm; | |
1362 | device->path_data.npm |= npm; | |
1363 | device->path_data.ppm |= ppm; | |
1364 | device->path_data.tbvpm |= epm; | |
1365 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
a4d26c6a | 1366 | } |
a4d26c6a SW |
1367 | |
1368 | dasd_put_device(device); | |
1369 | if (data->isglobal) | |
1370 | mutex_unlock(&dasd_path_verification_mutex); | |
1371 | else | |
1372 | kfree(data); | |
1373 | } | |
1374 | ||
1375 | static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm) | |
1376 | { | |
1377 | struct path_verification_work_data *data; | |
1378 | ||
1379 | data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA); | |
1380 | if (!data) { | |
1381 | if (mutex_trylock(&dasd_path_verification_mutex)) { | |
1382 | data = path_verification_worker; | |
1383 | data->isglobal = 1; | |
1384 | } else | |
1385 | return -ENOMEM; | |
1386 | } else { | |
1387 | memset(data, 0, sizeof(*data)); | |
1388 | data->isglobal = 0; | |
1389 | } | |
1390 | INIT_WORK(&data->worker, do_path_verification_work); | |
1391 | dasd_get_device(device); | |
1392 | data->device = device; | |
1393 | data->tbvpm = lpm; | |
1394 | schedule_work(&data->worker); | |
1395 | return 0; | |
1396 | } | |
1397 | ||
8e09f215 SW |
1398 | static int dasd_eckd_read_features(struct dasd_device *device) |
1399 | { | |
1400 | struct dasd_psf_prssd_data *prssdp; | |
1401 | struct dasd_rssd_features *features; | |
1402 | struct dasd_ccw_req *cqr; | |
1403 | struct ccw1 *ccw; | |
1404 | int rc; | |
1405 | struct dasd_eckd_private *private; | |
1406 | ||
1407 | private = (struct dasd_eckd_private *) device->private; | |
68d1e5f0 | 1408 | memset(&private->features, 0, sizeof(struct dasd_rssd_features)); |
68b781fe | 1409 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
8e09f215 SW |
1410 | (sizeof(struct dasd_psf_prssd_data) + |
1411 | sizeof(struct dasd_rssd_features)), | |
1412 | device); | |
1413 | if (IS_ERR(cqr)) { | |
b8ed5dd5 SH |
1414 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not " |
1415 | "allocate initialization request"); | |
8e09f215 SW |
1416 | return PTR_ERR(cqr); |
1417 | } | |
1418 | cqr->startdev = device; | |
1419 | cqr->memdev = device; | |
1420 | cqr->block = NULL; | |
eb6e199b | 1421 | cqr->retries = 256; |
8e09f215 SW |
1422 | cqr->expires = 10 * HZ; |
1423 | ||
1424 | /* Prepare for Read Subsystem Data */ | |
1425 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
1426 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); | |
1427 | prssdp->order = PSF_ORDER_PRSSD; | |
1428 | prssdp->suborder = 0x41; /* Read Feature Codes */ | |
1429 | /* all other bytes of prssdp must be zero */ | |
1430 | ||
1431 | ccw = cqr->cpaddr; | |
1432 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1433 | ccw->count = sizeof(struct dasd_psf_prssd_data); | |
1434 | ccw->flags |= CCW_FLAG_CC; | |
1435 | ccw->cda = (__u32)(addr_t) prssdp; | |
1436 | ||
1437 | /* Read Subsystem Data - feature codes */ | |
1438 | features = (struct dasd_rssd_features *) (prssdp + 1); | |
1439 | memset(features, 0, sizeof(struct dasd_rssd_features)); | |
1440 | ||
1441 | ccw++; | |
1442 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
1443 | ccw->count = sizeof(struct dasd_rssd_features); | |
1444 | ccw->cda = (__u32)(addr_t) features; | |
1445 | ||
1446 | cqr->buildclk = get_clock(); | |
1447 | cqr->status = DASD_CQR_FILLED; | |
1448 | rc = dasd_sleep_on(cqr); | |
1449 | if (rc == 0) { | |
1450 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
1451 | features = (struct dasd_rssd_features *) (prssdp + 1); | |
1452 | memcpy(&private->features, features, | |
1453 | sizeof(struct dasd_rssd_features)); | |
68d1e5f0 SW |
1454 | } else |
1455 | dev_warn(&device->cdev->dev, "Reading device feature codes" | |
1456 | " failed with rc=%d\n", rc); | |
8e09f215 SW |
1457 | dasd_sfree_request(cqr, cqr->memdev); |
1458 | return rc; | |
1459 | } | |
1460 | ||
1461 | ||
40545573 HH |
1462 | /* |
1463 | * Build CP for Perform Subsystem Function - SSC. | |
1464 | */ | |
f3eb5384 SW |
1465 | static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device, |
1466 | int enable_pav) | |
40545573 | 1467 | { |
8e09f215 SW |
1468 | struct dasd_ccw_req *cqr; |
1469 | struct dasd_psf_ssc_data *psf_ssc_data; | |
1470 | struct ccw1 *ccw; | |
40545573 | 1471 | |
68b781fe | 1472 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , |
40545573 HH |
1473 | sizeof(struct dasd_psf_ssc_data), |
1474 | device); | |
1475 | ||
8e09f215 | 1476 | if (IS_ERR(cqr)) { |
fc19f381 | 1477 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
40545573 | 1478 | "Could not allocate PSF-SSC request"); |
8e09f215 SW |
1479 | return cqr; |
1480 | } | |
1481 | psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data; | |
1482 | psf_ssc_data->order = PSF_ORDER_SSC; | |
626350b6 | 1483 | psf_ssc_data->suborder = 0xc0; |
f3eb5384 | 1484 | if (enable_pav) { |
626350b6 | 1485 | psf_ssc_data->suborder |= 0x08; |
f3eb5384 SW |
1486 | psf_ssc_data->reserved[0] = 0x88; |
1487 | } | |
8e09f215 SW |
1488 | ccw = cqr->cpaddr; |
1489 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
1490 | ccw->cda = (__u32)(addr_t)psf_ssc_data; | |
1491 | ccw->count = 66; | |
1492 | ||
1493 | cqr->startdev = device; | |
1494 | cqr->memdev = device; | |
1495 | cqr->block = NULL; | |
eb6e199b | 1496 | cqr->retries = 256; |
8e09f215 SW |
1497 | cqr->expires = 10*HZ; |
1498 | cqr->buildclk = get_clock(); | |
1499 | cqr->status = DASD_CQR_FILLED; | |
1500 | return cqr; | |
40545573 HH |
1501 | } |
1502 | ||
1503 | /* | |
1504 | * Perform Subsystem Function. | |
1505 | * It is necessary to trigger CIO for channel revalidation since this | |
1506 | * call might change behaviour of DASD devices. | |
1507 | */ | |
1508 | static int | |
12d7b107 SH |
1509 | dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav, |
1510 | unsigned long flags) | |
40545573 | 1511 | { |
8e09f215 SW |
1512 | struct dasd_ccw_req *cqr; |
1513 | int rc; | |
1514 | ||
f3eb5384 | 1515 | cqr = dasd_eckd_build_psf_ssc(device, enable_pav); |
8e09f215 SW |
1516 | if (IS_ERR(cqr)) |
1517 | return PTR_ERR(cqr); | |
1518 | ||
12d7b107 SH |
1519 | /* |
1520 | * set flags e.g. turn on failfast, to prevent blocking | |
1521 | * the calling function should handle failed requests | |
1522 | */ | |
1523 | cqr->flags |= flags; | |
1524 | ||
8e09f215 SW |
1525 | rc = dasd_sleep_on(cqr); |
1526 | if (!rc) | |
1527 | /* trigger CIO to reprobe devices */ | |
1528 | css_schedule_reprobe(); | |
12d7b107 SH |
1529 | else if (cqr->intrc == -EAGAIN) |
1530 | rc = -EAGAIN; | |
1531 | ||
8e09f215 SW |
1532 | dasd_sfree_request(cqr, cqr->memdev); |
1533 | return rc; | |
40545573 HH |
1534 | } |
1535 | ||
1536 | /* | |
1537 | * Valide storage server of current device. | |
1538 | */ | |
12d7b107 SH |
1539 | static int dasd_eckd_validate_server(struct dasd_device *device, |
1540 | unsigned long flags) | |
40545573 HH |
1541 | { |
1542 | int rc; | |
8e09f215 | 1543 | struct dasd_eckd_private *private; |
f3eb5384 | 1544 | int enable_pav; |
40545573 | 1545 | |
f9f8d02f SH |
1546 | private = (struct dasd_eckd_private *) device->private; |
1547 | if (private->uid.type == UA_BASE_PAV_ALIAS || | |
1548 | private->uid.type == UA_HYPER_PAV_ALIAS) | |
12d7b107 | 1549 | return 0; |
40545573 | 1550 | if (dasd_nopav || MACHINE_IS_VM) |
f3eb5384 SW |
1551 | enable_pav = 0; |
1552 | else | |
1553 | enable_pav = 1; | |
12d7b107 | 1554 | rc = dasd_eckd_psf_ssc(device, enable_pav, flags); |
eb6e199b | 1555 | |
8e79a441 HH |
1556 | /* may be requested feature is not available on server, |
1557 | * therefore just report error and go ahead */ | |
b8ed5dd5 SH |
1558 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x " |
1559 | "returned rc=%d", private->uid.ssid, rc); | |
12d7b107 | 1560 | return rc; |
40545573 HH |
1561 | } |
1562 | ||
f1633031 SH |
1563 | /* |
1564 | * worker to do a validate server in case of a lost pathgroup | |
1565 | */ | |
1566 | static void dasd_eckd_do_validate_server(struct work_struct *work) | |
1567 | { | |
1568 | struct dasd_device *device = container_of(work, struct dasd_device, | |
1569 | kick_validate); | |
12d7b107 SH |
1570 | if (dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST) |
1571 | == -EAGAIN) { | |
1572 | /* schedule worker again if failed */ | |
1573 | schedule_work(&device->kick_validate); | |
1574 | return; | |
1575 | } | |
1576 | ||
f1633031 SH |
1577 | dasd_put_device(device); |
1578 | } | |
1579 | ||
1580 | static void dasd_eckd_kick_validate_server(struct dasd_device *device) | |
1581 | { | |
1582 | dasd_get_device(device); | |
25e2cf1c SH |
1583 | /* exit if device not online or in offline processing */ |
1584 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || | |
1585 | device->state < DASD_STATE_ONLINE) { | |
1586 | dasd_put_device(device); | |
1587 | return; | |
1588 | } | |
f1633031 SH |
1589 | /* queue call to do_validate_server to the kernel event daemon. */ |
1590 | schedule_work(&device->kick_validate); | |
1591 | } | |
1592 | ||
ef19298b SW |
1593 | static u32 get_fcx_max_data(struct dasd_device *device) |
1594 | { | |
1595 | #if defined(CONFIG_64BIT) | |
1596 | int tpm, mdc; | |
1597 | int fcx_in_css, fcx_in_gneq, fcx_in_features; | |
1598 | struct dasd_eckd_private *private; | |
1599 | ||
1600 | if (dasd_nofcx) | |
1601 | return 0; | |
1602 | /* is transport mode supported? */ | |
1603 | private = (struct dasd_eckd_private *) device->private; | |
1604 | fcx_in_css = css_general_characteristics.fcx; | |
1605 | fcx_in_gneq = private->gneq->reserved2[7] & 0x04; | |
1606 | fcx_in_features = private->features.feature[40] & 0x80; | |
1607 | tpm = fcx_in_css && fcx_in_gneq && fcx_in_features; | |
1608 | ||
1609 | if (!tpm) | |
1610 | return 0; | |
1611 | ||
1612 | mdc = ccw_device_get_mdc(device->cdev, 0); | |
1613 | if (mdc < 0) { | |
1614 | dev_warn(&device->cdev->dev, "Detecting the maximum supported" | |
1615 | " data size for zHPF requests failed\n"); | |
1616 | return 0; | |
1617 | } else | |
1618 | return mdc * FCX_MAX_DATA_FACTOR; | |
1619 | #else | |
1620 | return 0; | |
1621 | #endif | |
1622 | } | |
1623 | ||
3d052595 HH |
1624 | /* |
1625 | * Check device characteristics. | |
1626 | * If the device is accessible using ECKD discipline, the device is enabled. | |
1627 | */ | |
1da177e4 LT |
1628 | static int |
1629 | dasd_eckd_check_characteristics(struct dasd_device *device) | |
1630 | { | |
1631 | struct dasd_eckd_private *private; | |
8e09f215 | 1632 | struct dasd_block *block; |
2dedf0d9 | 1633 | struct dasd_uid temp_uid; |
f9f8d02f | 1634 | int rc, i; |
33b62a30 | 1635 | int readonly; |
7c8faa86 | 1636 | unsigned long value; |
1da177e4 | 1637 | |
f1633031 SH |
1638 | /* setup work queue for validate server*/ |
1639 | INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server); | |
1640 | ||
454e1fa1 PO |
1641 | if (!ccw_device_is_pathgroup(device->cdev)) { |
1642 | dev_warn(&device->cdev->dev, | |
1643 | "A channel path group could not be established\n"); | |
1644 | return -EIO; | |
1645 | } | |
1646 | if (!ccw_device_is_multipath(device->cdev)) { | |
1647 | dev_info(&device->cdev->dev, | |
1648 | "The DASD is not operating in multipath mode\n"); | |
1649 | } | |
1da177e4 | 1650 | private = (struct dasd_eckd_private *) device->private; |
92636b15 SO |
1651 | if (!private) { |
1652 | private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); | |
1653 | if (!private) { | |
fc19f381 SH |
1654 | dev_warn(&device->cdev->dev, |
1655 | "Allocating memory for private DASD data " | |
1656 | "failed\n"); | |
1da177e4 LT |
1657 | return -ENOMEM; |
1658 | } | |
1da177e4 | 1659 | device->private = (void *) private; |
92636b15 SO |
1660 | } else { |
1661 | memset(private, 0, sizeof(*private)); | |
1da177e4 LT |
1662 | } |
1663 | /* Invalidate status of initial analysis. */ | |
1664 | private->init_cqr_status = -1; | |
1665 | /* Set default cache operations. */ | |
1666 | private->attrib.operation = DASD_NORMAL_CACHE; | |
1667 | private->attrib.nr_cyl = 0; | |
1668 | ||
40545573 HH |
1669 | /* Read Configuration Data */ |
1670 | rc = dasd_eckd_read_conf(device); | |
1671 | if (rc) | |
8e09f215 | 1672 | goto out_err1; |
40545573 | 1673 | |
7c8faa86 SH |
1674 | /* set default timeout */ |
1675 | device->default_expires = DASD_EXPIRES; | |
1676 | if (private->gneq) { | |
1677 | value = 1; | |
1678 | for (i = 0; i < private->gneq->timeout.value; i++) | |
1679 | value = 10 * value; | |
1680 | value = value * private->gneq->timeout.number; | |
1681 | /* do not accept useless values */ | |
1682 | if (value != 0 && value <= DASD_EXPIRES_MAX) | |
1683 | device->default_expires = value; | |
1684 | } | |
1685 | ||
2dedf0d9 SH |
1686 | dasd_eckd_get_uid(device, &temp_uid); |
1687 | if (temp_uid.type == UA_BASE_DEVICE) { | |
8e09f215 SW |
1688 | block = dasd_alloc_block(); |
1689 | if (IS_ERR(block)) { | |
b8ed5dd5 SH |
1690 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", |
1691 | "could not allocate dasd " | |
1692 | "block structure"); | |
8e09f215 SW |
1693 | rc = PTR_ERR(block); |
1694 | goto out_err1; | |
1695 | } | |
1696 | device->block = block; | |
1697 | block->base = device; | |
1698 | } | |
1699 | ||
f9f8d02f SH |
1700 | /* register lcu with alias handling, enable PAV */ |
1701 | rc = dasd_alias_make_device_known_to_lcu(device); | |
1702 | if (rc) | |
8e09f215 | 1703 | goto out_err2; |
f9f8d02f | 1704 | |
12d7b107 | 1705 | dasd_eckd_validate_server(device, 0); |
f4ac1d02 SW |
1706 | |
1707 | /* device may report different configuration data after LCU setup */ | |
1708 | rc = dasd_eckd_read_conf(device); | |
1709 | if (rc) | |
1710 | goto out_err3; | |
8e09f215 SW |
1711 | |
1712 | /* Read Feature Codes */ | |
68d1e5f0 | 1713 | dasd_eckd_read_features(device); |
40545573 | 1714 | |
1da177e4 | 1715 | /* Read Device Characteristics */ |
68b781fe SH |
1716 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
1717 | &private->rdc_data, 64); | |
8e09f215 | 1718 | if (rc) { |
b8ed5dd5 SH |
1719 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
1720 | "Read device characteristic failed, rc=%d", rc); | |
8e09f215 SW |
1721 | goto out_err3; |
1722 | } | |
34cd551a SH |
1723 | |
1724 | if ((device->features & DASD_FEATURE_USERAW) && | |
1725 | !(private->rdc_data.facilities.RT_in_LR)) { | |
1726 | dev_err(&device->cdev->dev, "The storage server does not " | |
1727 | "support raw-track access\n"); | |
1728 | rc = -EINVAL; | |
1729 | goto out_err3; | |
1730 | } | |
1731 | ||
817f2c84 | 1732 | /* find the valid cylinder size */ |
b44b0ab3 SW |
1733 | if (private->rdc_data.no_cyl == LV_COMPAT_CYL && |
1734 | private->rdc_data.long_no_cyl) | |
1735 | private->real_cyl = private->rdc_data.long_no_cyl; | |
1736 | else | |
1737 | private->real_cyl = private->rdc_data.no_cyl; | |
1738 | ||
ef19298b SW |
1739 | private->fcx_max_data = get_fcx_max_data(device); |
1740 | ||
33b62a30 SW |
1741 | readonly = dasd_device_is_ro(device); |
1742 | if (readonly) | |
1743 | set_bit(DASD_FLAG_DEVICE_RO, &device->flags); | |
1744 | ||
fc19f381 | 1745 | dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " |
33b62a30 | 1746 | "with %d cylinders, %d heads, %d sectors%s\n", |
fc19f381 SH |
1747 | private->rdc_data.dev_type, |
1748 | private->rdc_data.dev_model, | |
1749 | private->rdc_data.cu_type, | |
1750 | private->rdc_data.cu_model.model, | |
92636b15 | 1751 | private->real_cyl, |
fc19f381 | 1752 | private->rdc_data.trk_per_cyl, |
33b62a30 SW |
1753 | private->rdc_data.sec_per_trk, |
1754 | readonly ? ", read-only device" : ""); | |
8e09f215 SW |
1755 | return 0; |
1756 | ||
1757 | out_err3: | |
1758 | dasd_alias_disconnect_device_from_lcu(device); | |
1759 | out_err2: | |
1760 | dasd_free_block(device->block); | |
1761 | device->block = NULL; | |
1762 | out_err1: | |
4abb08c2 | 1763 | kfree(private->conf_data); |
8e09f215 SW |
1764 | kfree(device->private); |
1765 | device->private = NULL; | |
3d052595 | 1766 | return rc; |
1da177e4 LT |
1767 | } |
1768 | ||
8e09f215 SW |
1769 | static void dasd_eckd_uncheck_device(struct dasd_device *device) |
1770 | { | |
4abb08c2 SW |
1771 | struct dasd_eckd_private *private; |
1772 | ||
1773 | private = (struct dasd_eckd_private *) device->private; | |
8e09f215 | 1774 | dasd_alias_disconnect_device_from_lcu(device); |
4abb08c2 SW |
1775 | private->ned = NULL; |
1776 | private->sneq = NULL; | |
1777 | private->vdsneq = NULL; | |
1778 | private->gneq = NULL; | |
1779 | private->conf_len = 0; | |
1780 | kfree(private->conf_data); | |
1781 | private->conf_data = NULL; | |
8e09f215 SW |
1782 | } |
1783 | ||
1da177e4 LT |
1784 | static struct dasd_ccw_req * |
1785 | dasd_eckd_analysis_ccw(struct dasd_device *device) | |
1786 | { | |
1787 | struct dasd_eckd_private *private; | |
1788 | struct eckd_count *count_data; | |
1789 | struct LO_eckd_data *LO_data; | |
1790 | struct dasd_ccw_req *cqr; | |
1791 | struct ccw1 *ccw; | |
1792 | int cplength, datasize; | |
1793 | int i; | |
1794 | ||
1795 | private = (struct dasd_eckd_private *) device->private; | |
1796 | ||
1797 | cplength = 8; | |
1798 | datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); | |
68b781fe | 1799 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
1da177e4 LT |
1800 | if (IS_ERR(cqr)) |
1801 | return cqr; | |
1802 | ccw = cqr->cpaddr; | |
1803 | /* Define extent for the first 3 tracks. */ | |
1804 | define_extent(ccw++, cqr->data, 0, 2, | |
1805 | DASD_ECKD_CCW_READ_COUNT, device); | |
8e09f215 | 1806 | LO_data = cqr->data + sizeof(struct DE_eckd_data); |
1da177e4 LT |
1807 | /* Locate record for the first 4 records on track 0. */ |
1808 | ccw[-1].flags |= CCW_FLAG_CC; | |
1809 | locate_record(ccw++, LO_data++, 0, 0, 4, | |
1810 | DASD_ECKD_CCW_READ_COUNT, device, 0); | |
1811 | ||
1812 | count_data = private->count_area; | |
1813 | for (i = 0; i < 4; i++) { | |
1814 | ccw[-1].flags |= CCW_FLAG_CC; | |
1815 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; | |
1816 | ccw->flags = 0; | |
1817 | ccw->count = 8; | |
1818 | ccw->cda = (__u32)(addr_t) count_data; | |
1819 | ccw++; | |
1820 | count_data++; | |
1821 | } | |
1822 | ||
1823 | /* Locate record for the first record on track 2. */ | |
1824 | ccw[-1].flags |= CCW_FLAG_CC; | |
1825 | locate_record(ccw++, LO_data++, 2, 0, 1, | |
1826 | DASD_ECKD_CCW_READ_COUNT, device, 0); | |
1827 | /* Read count ccw. */ | |
1828 | ccw[-1].flags |= CCW_FLAG_CC; | |
1829 | ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; | |
1830 | ccw->flags = 0; | |
1831 | ccw->count = 8; | |
1832 | ccw->cda = (__u32)(addr_t) count_data; | |
1833 | ||
8e09f215 SW |
1834 | cqr->block = NULL; |
1835 | cqr->startdev = device; | |
1836 | cqr->memdev = device; | |
eb6e199b | 1837 | cqr->retries = 255; |
1da177e4 LT |
1838 | cqr->buildclk = get_clock(); |
1839 | cqr->status = DASD_CQR_FILLED; | |
1840 | return cqr; | |
1841 | } | |
1842 | ||
eb6e199b SW |
1843 | /* differentiate between 'no record found' and any other error */ |
1844 | static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr) | |
1845 | { | |
1846 | char *sense; | |
1847 | if (init_cqr->status == DASD_CQR_DONE) | |
1848 | return INIT_CQR_OK; | |
1849 | else if (init_cqr->status == DASD_CQR_NEED_ERP || | |
1850 | init_cqr->status == DASD_CQR_FAILED) { | |
1851 | sense = dasd_get_sense(&init_cqr->irb); | |
1852 | if (sense && (sense[1] & SNS1_NO_REC_FOUND)) | |
1853 | return INIT_CQR_UNFORMATTED; | |
1854 | else | |
1855 | return INIT_CQR_ERROR; | |
1856 | } else | |
1857 | return INIT_CQR_ERROR; | |
1858 | } | |
1859 | ||
1da177e4 LT |
1860 | /* |
1861 | * This is the callback function for the init_analysis cqr. It saves | |
1862 | * the status of the initial analysis ccw before it frees it and kicks | |
1863 | * the device to continue the startup sequence. This will call | |
1864 | * dasd_eckd_do_analysis again (if the devices has not been marked | |
1865 | * for deletion in the meantime). | |
1866 | */ | |
eb6e199b SW |
1867 | static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, |
1868 | void *data) | |
1da177e4 LT |
1869 | { |
1870 | struct dasd_eckd_private *private; | |
1871 | struct dasd_device *device; | |
1872 | ||
8e09f215 | 1873 | device = init_cqr->startdev; |
1da177e4 | 1874 | private = (struct dasd_eckd_private *) device->private; |
eb6e199b | 1875 | private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr); |
1da177e4 LT |
1876 | dasd_sfree_request(init_cqr, device); |
1877 | dasd_kick_device(device); | |
1878 | } | |
1879 | ||
eb6e199b | 1880 | static int dasd_eckd_start_analysis(struct dasd_block *block) |
1da177e4 | 1881 | { |
1da177e4 LT |
1882 | struct dasd_ccw_req *init_cqr; |
1883 | ||
8e09f215 | 1884 | init_cqr = dasd_eckd_analysis_ccw(block->base); |
1da177e4 LT |
1885 | if (IS_ERR(init_cqr)) |
1886 | return PTR_ERR(init_cqr); | |
1887 | init_cqr->callback = dasd_eckd_analysis_callback; | |
1888 | init_cqr->callback_data = NULL; | |
1889 | init_cqr->expires = 5*HZ; | |
eb6e199b SW |
1890 | /* first try without ERP, so we can later handle unformatted |
1891 | * devices as special case | |
1892 | */ | |
1893 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags); | |
1894 | init_cqr->retries = 0; | |
1da177e4 LT |
1895 | dasd_add_request_head(init_cqr); |
1896 | return -EAGAIN; | |
1897 | } | |
1898 | ||
eb6e199b | 1899 | static int dasd_eckd_end_analysis(struct dasd_block *block) |
1da177e4 | 1900 | { |
8e09f215 | 1901 | struct dasd_device *device; |
1da177e4 LT |
1902 | struct dasd_eckd_private *private; |
1903 | struct eckd_count *count_area; | |
1904 | unsigned int sb, blk_per_trk; | |
1905 | int status, i; | |
eb6e199b | 1906 | struct dasd_ccw_req *init_cqr; |
1da177e4 | 1907 | |
8e09f215 | 1908 | device = block->base; |
1da177e4 LT |
1909 | private = (struct dasd_eckd_private *) device->private; |
1910 | status = private->init_cqr_status; | |
1911 | private->init_cqr_status = -1; | |
eb6e199b SW |
1912 | if (status == INIT_CQR_ERROR) { |
1913 | /* try again, this time with full ERP */ | |
1914 | init_cqr = dasd_eckd_analysis_ccw(device); | |
1915 | dasd_sleep_on(init_cqr); | |
1916 | status = dasd_eckd_analysis_evaluation(init_cqr); | |
1917 | dasd_sfree_request(init_cqr, device); | |
1918 | } | |
1919 | ||
e4dbb0f2 SH |
1920 | if (device->features & DASD_FEATURE_USERAW) { |
1921 | block->bp_block = DASD_RAW_BLOCKSIZE; | |
1922 | blk_per_trk = DASD_RAW_BLOCK_PER_TRACK; | |
1923 | block->s2b_shift = 3; | |
1924 | goto raw; | |
1925 | } | |
1926 | ||
eb6e199b SW |
1927 | if (status == INIT_CQR_UNFORMATTED) { |
1928 | dev_warn(&device->cdev->dev, "The DASD is not formatted\n"); | |
1da177e4 | 1929 | return -EMEDIUMTYPE; |
eb6e199b SW |
1930 | } else if (status == INIT_CQR_ERROR) { |
1931 | dev_err(&device->cdev->dev, | |
1932 | "Detecting the DASD disk layout failed because " | |
1933 | "of an I/O error\n"); | |
1934 | return -EIO; | |
1da177e4 LT |
1935 | } |
1936 | ||
1937 | private->uses_cdl = 1; | |
1da177e4 LT |
1938 | /* Check Track 0 for Compatible Disk Layout */ |
1939 | count_area = NULL; | |
1940 | for (i = 0; i < 3; i++) { | |
1941 | if (private->count_area[i].kl != 4 || | |
1942 | private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) { | |
1943 | private->uses_cdl = 0; | |
1944 | break; | |
1945 | } | |
1946 | } | |
1947 | if (i == 3) | |
1948 | count_area = &private->count_area[4]; | |
1949 | ||
1950 | if (private->uses_cdl == 0) { | |
1951 | for (i = 0; i < 5; i++) { | |
1952 | if ((private->count_area[i].kl != 0) || | |
1953 | (private->count_area[i].dl != | |
1954 | private->count_area[0].dl)) | |
1955 | break; | |
1956 | } | |
1957 | if (i == 5) | |
1958 | count_area = &private->count_area[0]; | |
1959 | } else { | |
1960 | if (private->count_area[3].record == 1) | |
fc19f381 SH |
1961 | dev_warn(&device->cdev->dev, |
1962 | "Track 0 has no records following the VTOC\n"); | |
1da177e4 | 1963 | } |
e4dbb0f2 | 1964 | |
1da177e4 LT |
1965 | if (count_area != NULL && count_area->kl == 0) { |
1966 | /* we found notthing violating our disk layout */ | |
1967 | if (dasd_check_blocksize(count_area->dl) == 0) | |
8e09f215 | 1968 | block->bp_block = count_area->dl; |
1da177e4 | 1969 | } |
8e09f215 | 1970 | if (block->bp_block == 0) { |
fc19f381 SH |
1971 | dev_warn(&device->cdev->dev, |
1972 | "The disk layout of the DASD is not supported\n"); | |
1da177e4 LT |
1973 | return -EMEDIUMTYPE; |
1974 | } | |
8e09f215 SW |
1975 | block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
1976 | for (sb = 512; sb < block->bp_block; sb = sb << 1) | |
1977 | block->s2b_shift++; | |
1da177e4 | 1978 | |
8e09f215 | 1979 | blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); |
e4dbb0f2 SH |
1980 | |
1981 | raw: | |
b44b0ab3 | 1982 | block->blocks = (private->real_cyl * |
1da177e4 LT |
1983 | private->rdc_data.trk_per_cyl * |
1984 | blk_per_trk); | |
1985 | ||
fc19f381 SH |
1986 | dev_info(&device->cdev->dev, |
1987 | "DASD with %d KB/block, %d KB total size, %d KB/track, " | |
1988 | "%s\n", (block->bp_block >> 10), | |
1989 | ((private->real_cyl * | |
1990 | private->rdc_data.trk_per_cyl * | |
1991 | blk_per_trk * (block->bp_block >> 9)) >> 1), | |
1992 | ((blk_per_trk * block->bp_block) >> 10), | |
1993 | private->uses_cdl ? | |
1994 | "compatible disk layout" : "linux disk layout"); | |
1da177e4 LT |
1995 | |
1996 | return 0; | |
1997 | } | |
1998 | ||
8e09f215 | 1999 | static int dasd_eckd_do_analysis(struct dasd_block *block) |
1da177e4 LT |
2000 | { |
2001 | struct dasd_eckd_private *private; | |
2002 | ||
8e09f215 | 2003 | private = (struct dasd_eckd_private *) block->base->private; |
1da177e4 | 2004 | if (private->init_cqr_status < 0) |
8e09f215 | 2005 | return dasd_eckd_start_analysis(block); |
1da177e4 | 2006 | else |
8e09f215 | 2007 | return dasd_eckd_end_analysis(block); |
1da177e4 LT |
2008 | } |
2009 | ||
8e09f215 SW |
2010 | static int dasd_eckd_ready_to_online(struct dasd_device *device) |
2011 | { | |
2012 | return dasd_alias_add_device(device); | |
2013 | }; | |
2014 | ||
2015 | static int dasd_eckd_online_to_ready(struct dasd_device *device) | |
2016 | { | |
501183f2 | 2017 | cancel_work_sync(&device->reload_device); |
25e2cf1c | 2018 | cancel_work_sync(&device->kick_validate); |
8e09f215 SW |
2019 | return dasd_alias_remove_device(device); |
2020 | }; | |
2021 | ||
1da177e4 | 2022 | static int |
8e09f215 | 2023 | dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
1da177e4 LT |
2024 | { |
2025 | struct dasd_eckd_private *private; | |
2026 | ||
8e09f215 SW |
2027 | private = (struct dasd_eckd_private *) block->base->private; |
2028 | if (dasd_check_blocksize(block->bp_block) == 0) { | |
1da177e4 | 2029 | geo->sectors = recs_per_track(&private->rdc_data, |
8e09f215 | 2030 | 0, block->bp_block); |
1da177e4 LT |
2031 | } |
2032 | geo->cylinders = private->rdc_data.no_cyl; | |
2033 | geo->heads = private->rdc_data.trk_per_cyl; | |
2034 | return 0; | |
2035 | } | |
2036 | ||
2037 | static struct dasd_ccw_req * | |
2038 | dasd_eckd_format_device(struct dasd_device * device, | |
2039 | struct format_data_t * fdata) | |
2040 | { | |
2041 | struct dasd_eckd_private *private; | |
2042 | struct dasd_ccw_req *fcp; | |
2043 | struct eckd_count *ect; | |
2044 | struct ccw1 *ccw; | |
2045 | void *data; | |
b44b0ab3 SW |
2046 | int rpt; |
2047 | struct ch_t address; | |
1da177e4 LT |
2048 | int cplength, datasize; |
2049 | int i; | |
f9a28f7b JBJ |
2050 | int intensity = 0; |
2051 | int r0_perm; | |
1da177e4 LT |
2052 | |
2053 | private = (struct dasd_eckd_private *) device->private; | |
2054 | rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize); | |
b44b0ab3 SW |
2055 | set_ch_t(&address, |
2056 | fdata->start_unit / private->rdc_data.trk_per_cyl, | |
2057 | fdata->start_unit % private->rdc_data.trk_per_cyl); | |
1da177e4 LT |
2058 | |
2059 | /* Sanity checks. */ | |
2060 | if (fdata->start_unit >= | |
b44b0ab3 | 2061 | (private->real_cyl * private->rdc_data.trk_per_cyl)) { |
fc19f381 SH |
2062 | dev_warn(&device->cdev->dev, "Start track number %d used in " |
2063 | "formatting is too big\n", fdata->start_unit); | |
1da177e4 LT |
2064 | return ERR_PTR(-EINVAL); |
2065 | } | |
2066 | if (fdata->start_unit > fdata->stop_unit) { | |
fc19f381 SH |
2067 | dev_warn(&device->cdev->dev, "Start track %d used in " |
2068 | "formatting exceeds end track\n", fdata->start_unit); | |
1da177e4 LT |
2069 | return ERR_PTR(-EINVAL); |
2070 | } | |
2071 | if (dasd_check_blocksize(fdata->blksize) != 0) { | |
fc19f381 SH |
2072 | dev_warn(&device->cdev->dev, |
2073 | "The DASD cannot be formatted with block size %d\n", | |
2074 | fdata->blksize); | |
1da177e4 LT |
2075 | return ERR_PTR(-EINVAL); |
2076 | } | |
2077 | ||
2078 | /* | |
2079 | * fdata->intensity is a bit string that tells us what to do: | |
2080 | * Bit 0: write record zero | |
2081 | * Bit 1: write home address, currently not supported | |
2082 | * Bit 2: invalidate tracks | |
2083 | * Bit 3: use OS/390 compatible disk layout (cdl) | |
f9a28f7b | 2084 | * Bit 4: do not allow storage subsystem to modify record zero |
1da177e4 LT |
2085 | * Only some bit combinations do make sense. |
2086 | */ | |
f9a28f7b JBJ |
2087 | if (fdata->intensity & 0x10) { |
2088 | r0_perm = 0; | |
2089 | intensity = fdata->intensity & ~0x10; | |
2090 | } else { | |
2091 | r0_perm = 1; | |
2092 | intensity = fdata->intensity; | |
2093 | } | |
2094 | switch (intensity) { | |
1da177e4 LT |
2095 | case 0x00: /* Normal format */ |
2096 | case 0x08: /* Normal format, use cdl. */ | |
2097 | cplength = 2 + rpt; | |
2098 | datasize = sizeof(struct DE_eckd_data) + | |
2099 | sizeof(struct LO_eckd_data) + | |
2100 | rpt * sizeof(struct eckd_count); | |
2101 | break; | |
2102 | case 0x01: /* Write record zero and format track. */ | |
2103 | case 0x09: /* Write record zero and format track, use cdl. */ | |
2104 | cplength = 3 + rpt; | |
2105 | datasize = sizeof(struct DE_eckd_data) + | |
2106 | sizeof(struct LO_eckd_data) + | |
2107 | sizeof(struct eckd_count) + | |
2108 | rpt * sizeof(struct eckd_count); | |
2109 | break; | |
2110 | case 0x04: /* Invalidate track. */ | |
2111 | case 0x0c: /* Invalidate track, use cdl. */ | |
2112 | cplength = 3; | |
2113 | datasize = sizeof(struct DE_eckd_data) + | |
2114 | sizeof(struct LO_eckd_data) + | |
2115 | sizeof(struct eckd_count); | |
2116 | break; | |
2117 | default: | |
fc19f381 SH |
2118 | dev_warn(&device->cdev->dev, "An I/O control call used " |
2119 | "incorrect flags 0x%x\n", fdata->intensity); | |
1da177e4 LT |
2120 | return ERR_PTR(-EINVAL); |
2121 | } | |
2122 | /* Allocate the format ccw request. */ | |
68b781fe | 2123 | fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); |
1da177e4 LT |
2124 | if (IS_ERR(fcp)) |
2125 | return fcp; | |
2126 | ||
2127 | data = fcp->data; | |
2128 | ccw = fcp->cpaddr; | |
2129 | ||
f9a28f7b | 2130 | switch (intensity & ~0x08) { |
1da177e4 LT |
2131 | case 0x00: /* Normal format. */ |
2132 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2133 | fdata->start_unit, fdata->start_unit, | |
2134 | DASD_ECKD_CCW_WRITE_CKD, device); | |
f9a28f7b JBJ |
2135 | /* grant subsystem permission to format R0 */ |
2136 | if (r0_perm) | |
2137 | ((struct DE_eckd_data *)data)->ga_extended |= 0x04; | |
1da177e4 LT |
2138 | data += sizeof(struct DE_eckd_data); |
2139 | ccw[-1].flags |= CCW_FLAG_CC; | |
2140 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
2141 | fdata->start_unit, 0, rpt, | |
2142 | DASD_ECKD_CCW_WRITE_CKD, device, | |
2143 | fdata->blksize); | |
2144 | data += sizeof(struct LO_eckd_data); | |
2145 | break; | |
2146 | case 0x01: /* Write record zero + format track. */ | |
2147 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2148 | fdata->start_unit, fdata->start_unit, | |
2149 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, | |
2150 | device); | |
2151 | data += sizeof(struct DE_eckd_data); | |
2152 | ccw[-1].flags |= CCW_FLAG_CC; | |
2153 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
2154 | fdata->start_unit, 0, rpt + 1, | |
2155 | DASD_ECKD_CCW_WRITE_RECORD_ZERO, device, | |
8e09f215 | 2156 | device->block->bp_block); |
1da177e4 LT |
2157 | data += sizeof(struct LO_eckd_data); |
2158 | break; | |
2159 | case 0x04: /* Invalidate track. */ | |
2160 | define_extent(ccw++, (struct DE_eckd_data *) data, | |
2161 | fdata->start_unit, fdata->start_unit, | |
2162 | DASD_ECKD_CCW_WRITE_CKD, device); | |
2163 | data += sizeof(struct DE_eckd_data); | |
2164 | ccw[-1].flags |= CCW_FLAG_CC; | |
2165 | locate_record(ccw++, (struct LO_eckd_data *) data, | |
2166 | fdata->start_unit, 0, 1, | |
2167 | DASD_ECKD_CCW_WRITE_CKD, device, 8); | |
2168 | data += sizeof(struct LO_eckd_data); | |
2169 | break; | |
2170 | } | |
f9a28f7b | 2171 | if (intensity & 0x01) { /* write record zero */ |
1da177e4 LT |
2172 | ect = (struct eckd_count *) data; |
2173 | data += sizeof(struct eckd_count); | |
b44b0ab3 SW |
2174 | ect->cyl = address.cyl; |
2175 | ect->head = address.head; | |
1da177e4 LT |
2176 | ect->record = 0; |
2177 | ect->kl = 0; | |
2178 | ect->dl = 8; | |
2179 | ccw[-1].flags |= CCW_FLAG_CC; | |
2180 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; | |
2181 | ccw->flags = CCW_FLAG_SLI; | |
2182 | ccw->count = 8; | |
2183 | ccw->cda = (__u32)(addr_t) ect; | |
2184 | ccw++; | |
2185 | } | |
f9a28f7b | 2186 | if ((intensity & ~0x08) & 0x04) { /* erase track */ |
1da177e4 LT |
2187 | ect = (struct eckd_count *) data; |
2188 | data += sizeof(struct eckd_count); | |
b44b0ab3 SW |
2189 | ect->cyl = address.cyl; |
2190 | ect->head = address.head; | |
1da177e4 LT |
2191 | ect->record = 1; |
2192 | ect->kl = 0; | |
2193 | ect->dl = 0; | |
2194 | ccw[-1].flags |= CCW_FLAG_CC; | |
2195 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; | |
2196 | ccw->flags = CCW_FLAG_SLI; | |
2197 | ccw->count = 8; | |
2198 | ccw->cda = (__u32)(addr_t) ect; | |
2199 | } else { /* write remaining records */ | |
2200 | for (i = 0; i < rpt; i++) { | |
2201 | ect = (struct eckd_count *) data; | |
2202 | data += sizeof(struct eckd_count); | |
b44b0ab3 SW |
2203 | ect->cyl = address.cyl; |
2204 | ect->head = address.head; | |
1da177e4 LT |
2205 | ect->record = i + 1; |
2206 | ect->kl = 0; | |
2207 | ect->dl = fdata->blksize; | |
2208 | /* Check for special tracks 0-1 when formatting CDL */ | |
f9a28f7b | 2209 | if ((intensity & 0x08) && |
1da177e4 LT |
2210 | fdata->start_unit == 0) { |
2211 | if (i < 3) { | |
2212 | ect->kl = 4; | |
2213 | ect->dl = sizes_trk0[i] - 4; | |
138c014d | 2214 | } |
1da177e4 | 2215 | } |
f9a28f7b | 2216 | if ((intensity & 0x08) && |
1da177e4 LT |
2217 | fdata->start_unit == 1) { |
2218 | ect->kl = 44; | |
2219 | ect->dl = LABEL_SIZE - 44; | |
2220 | } | |
2221 | ccw[-1].flags |= CCW_FLAG_CC; | |
2222 | ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; | |
2223 | ccw->flags = CCW_FLAG_SLI; | |
2224 | ccw->count = 8; | |
2225 | ccw->cda = (__u32)(addr_t) ect; | |
2226 | ccw++; | |
2227 | } | |
2228 | } | |
8e09f215 SW |
2229 | fcp->startdev = device; |
2230 | fcp->memdev = device; | |
eb6e199b | 2231 | fcp->retries = 256; |
1da177e4 LT |
2232 | fcp->buildclk = get_clock(); |
2233 | fcp->status = DASD_CQR_FILLED; | |
2234 | return fcp; | |
2235 | } | |
2236 | ||
8e09f215 | 2237 | static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) |
1da177e4 | 2238 | { |
8e09f215 SW |
2239 | cqr->status = DASD_CQR_FILLED; |
2240 | if (cqr->block && (cqr->startdev != cqr->block->base)) { | |
2241 | dasd_eckd_reset_ccw_to_base_io(cqr); | |
2242 | cqr->startdev = cqr->block->base; | |
a4d26c6a | 2243 | cqr->lpm = cqr->block->base->path_data.opm; |
1da177e4 | 2244 | } |
8e09f215 | 2245 | }; |
1da177e4 LT |
2246 | |
2247 | static dasd_erp_fn_t | |
2248 | dasd_eckd_erp_action(struct dasd_ccw_req * cqr) | |
2249 | { | |
8e09f215 | 2250 | struct dasd_device *device = (struct dasd_device *) cqr->startdev; |
1da177e4 LT |
2251 | struct ccw_device *cdev = device->cdev; |
2252 | ||
2253 | switch (cdev->id.cu_type) { | |
2254 | case 0x3990: | |
2255 | case 0x2105: | |
2256 | case 0x2107: | |
2257 | case 0x1750: | |
2258 | return dasd_3990_erp_action; | |
2259 | case 0x9343: | |
2260 | case 0x3880: | |
2261 | default: | |
2262 | return dasd_default_erp_action; | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | static dasd_erp_fn_t | |
2267 | dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) | |
2268 | { | |
2269 | return dasd_default_erp_postaction; | |
2270 | } | |
2271 | ||
5a27e60d SW |
2272 | static void dasd_eckd_check_for_device_change(struct dasd_device *device, |
2273 | struct dasd_ccw_req *cqr, | |
2274 | struct irb *irb) | |
8e09f215 SW |
2275 | { |
2276 | char mask; | |
f3eb5384 | 2277 | char *sense = NULL; |
501183f2 | 2278 | struct dasd_eckd_private *private; |
8e09f215 | 2279 | |
501183f2 | 2280 | private = (struct dasd_eckd_private *) device->private; |
8e09f215 SW |
2281 | /* first of all check for state change pending interrupt */ |
2282 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; | |
f3eb5384 | 2283 | if ((scsw_dstat(&irb->scsw) & mask) == mask) { |
c8d1c0ff SH |
2284 | /* |
2285 | * for alias only, not in offline processing | |
2286 | * and only if not suspended | |
2287 | */ | |
501183f2 | 2288 | if (!device->block && private->lcu && |
25e2cf1c | 2289 | device->state == DASD_STATE_ONLINE && |
c8d1c0ff SH |
2290 | !test_bit(DASD_FLAG_OFFLINE, &device->flags) && |
2291 | !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { | |
501183f2 SH |
2292 | /* |
2293 | * the state change could be caused by an alias | |
2294 | * reassignment remove device from alias handling | |
2295 | * to prevent new requests from being scheduled on | |
2296 | * the wrong alias device | |
2297 | */ | |
2298 | dasd_alias_remove_device(device); | |
2299 | ||
2300 | /* schedule worker to reload device */ | |
2301 | dasd_reload_device(device); | |
2302 | } | |
8e09f215 SW |
2303 | dasd_generic_handle_state_change(device); |
2304 | return; | |
2305 | } | |
2306 | ||
a5a0061f | 2307 | sense = dasd_get_sense(irb); |
5a27e60d SW |
2308 | if (!sense) |
2309 | return; | |
2310 | ||
2311 | /* summary unit check */ | |
c7a29e56 | 2312 | if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) && |
a5a0061f | 2313 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) { |
8e09f215 SW |
2314 | dasd_alias_handle_summary_unit_check(device, irb); |
2315 | return; | |
2316 | } | |
2317 | ||
f60c768c | 2318 | /* service information message SIM */ |
5a27e60d | 2319 | if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) && |
f3eb5384 SW |
2320 | ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { |
2321 | dasd_3990_erp_handle_sim(device, sense); | |
f60c768c SH |
2322 | return; |
2323 | } | |
2324 | ||
5a27e60d SW |
2325 | /* loss of device reservation is handled via base devices only |
2326 | * as alias devices may be used with several bases | |
2327 | */ | |
c7a29e56 SW |
2328 | if (device->block && (sense[27] & DASD_SENSE_BIT_0) && |
2329 | (sense[7] == 0x3F) && | |
5a27e60d SW |
2330 | (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
2331 | test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) { | |
2332 | if (device->features & DASD_FEATURE_FAILONSLCK) | |
2333 | set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); | |
2334 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
2335 | dev_err(&device->cdev->dev, | |
2336 | "The device reservation was lost\n"); | |
ada3df91 | 2337 | } |
5a27e60d | 2338 | } |
f3eb5384 SW |
2339 | |
2340 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( | |
2341 | struct dasd_device *startdev, | |
8e09f215 | 2342 | struct dasd_block *block, |
f3eb5384 SW |
2343 | struct request *req, |
2344 | sector_t first_rec, | |
2345 | sector_t last_rec, | |
2346 | sector_t first_trk, | |
2347 | sector_t last_trk, | |
2348 | unsigned int first_offs, | |
2349 | unsigned int last_offs, | |
2350 | unsigned int blk_per_trk, | |
2351 | unsigned int blksize) | |
1da177e4 LT |
2352 | { |
2353 | struct dasd_eckd_private *private; | |
2354 | unsigned long *idaws; | |
2355 | struct LO_eckd_data *LO_data; | |
2356 | struct dasd_ccw_req *cqr; | |
2357 | struct ccw1 *ccw; | |
5705f702 | 2358 | struct req_iterator iter; |
1da177e4 LT |
2359 | struct bio_vec *bv; |
2360 | char *dst; | |
f3eb5384 | 2361 | unsigned int off; |
1da177e4 | 2362 | int count, cidaw, cplength, datasize; |
f3eb5384 | 2363 | sector_t recid; |
1da177e4 | 2364 | unsigned char cmd, rcmd; |
8e09f215 SW |
2365 | int use_prefix; |
2366 | struct dasd_device *basedev; | |
1da177e4 | 2367 | |
8e09f215 SW |
2368 | basedev = block->base; |
2369 | private = (struct dasd_eckd_private *) basedev->private; | |
1da177e4 LT |
2370 | if (rq_data_dir(req) == READ) |
2371 | cmd = DASD_ECKD_CCW_READ_MT; | |
2372 | else if (rq_data_dir(req) == WRITE) | |
2373 | cmd = DASD_ECKD_CCW_WRITE_MT; | |
2374 | else | |
2375 | return ERR_PTR(-EINVAL); | |
f3eb5384 | 2376 | |
1da177e4 LT |
2377 | /* Check struct bio and count the number of blocks for the request. */ |
2378 | count = 0; | |
2379 | cidaw = 0; | |
5705f702 | 2380 | rq_for_each_segment(bv, req, iter) { |
6c92e699 JA |
2381 | if (bv->bv_len & (blksize - 1)) |
2382 | /* Eckd can only do full blocks. */ | |
2383 | return ERR_PTR(-EINVAL); | |
8e09f215 | 2384 | count += bv->bv_len >> (block->s2b_shift + 9); |
347a8dc3 | 2385 | #if defined(CONFIG_64BIT) |
6c92e699 | 2386 | if (idal_is_needed (page_address(bv->bv_page), bv->bv_len)) |
8e09f215 | 2387 | cidaw += bv->bv_len >> (block->s2b_shift + 9); |
1da177e4 | 2388 | #endif |
1da177e4 LT |
2389 | } |
2390 | /* Paranoia. */ | |
2391 | if (count != last_rec - first_rec + 1) | |
2392 | return ERR_PTR(-EINVAL); | |
8e09f215 SW |
2393 | |
2394 | /* use the prefix command if available */ | |
2395 | use_prefix = private->features.feature[8] & 0x01; | |
2396 | if (use_prefix) { | |
2397 | /* 1x prefix + number of blocks */ | |
2398 | cplength = 2 + count; | |
2399 | /* 1x prefix + cidaws*sizeof(long) */ | |
2400 | datasize = sizeof(struct PFX_eckd_data) + | |
2401 | sizeof(struct LO_eckd_data) + | |
2402 | cidaw * sizeof(unsigned long); | |
2403 | } else { | |
2404 | /* 1x define extent + 1x locate record + number of blocks */ | |
2405 | cplength = 2 + count; | |
2406 | /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ | |
2407 | datasize = sizeof(struct DE_eckd_data) + | |
2408 | sizeof(struct LO_eckd_data) + | |
2409 | cidaw * sizeof(unsigned long); | |
2410 | } | |
1da177e4 LT |
2411 | /* Find out the number of additional locate record ccws for cdl. */ |
2412 | if (private->uses_cdl && first_rec < 2*blk_per_trk) { | |
2413 | if (last_rec >= 2*blk_per_trk) | |
2414 | count = 2*blk_per_trk - first_rec; | |
2415 | cplength += count; | |
2416 | datasize += count*sizeof(struct LO_eckd_data); | |
2417 | } | |
2418 | /* Allocate the ccw request. */ | |
68b781fe SH |
2419 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
2420 | startdev); | |
1da177e4 LT |
2421 | if (IS_ERR(cqr)) |
2422 | return cqr; | |
2423 | ccw = cqr->cpaddr; | |
8e09f215 SW |
2424 | /* First ccw is define extent or prefix. */ |
2425 | if (use_prefix) { | |
2426 | if (prefix(ccw++, cqr->data, first_trk, | |
2427 | last_trk, cmd, basedev, startdev) == -EAGAIN) { | |
2428 | /* Clock not in sync and XRC is enabled. | |
2429 | * Try again later. | |
2430 | */ | |
2431 | dasd_sfree_request(cqr, startdev); | |
2432 | return ERR_PTR(-EAGAIN); | |
2433 | } | |
2434 | idaws = (unsigned long *) (cqr->data + | |
2435 | sizeof(struct PFX_eckd_data)); | |
2436 | } else { | |
2437 | if (define_extent(ccw++, cqr->data, first_trk, | |
b38f27e8 | 2438 | last_trk, cmd, basedev) == -EAGAIN) { |
8e09f215 SW |
2439 | /* Clock not in sync and XRC is enabled. |
2440 | * Try again later. | |
2441 | */ | |
2442 | dasd_sfree_request(cqr, startdev); | |
2443 | return ERR_PTR(-EAGAIN); | |
2444 | } | |
2445 | idaws = (unsigned long *) (cqr->data + | |
2446 | sizeof(struct DE_eckd_data)); | |
d54853ef | 2447 | } |
1da177e4 | 2448 | /* Build locate_record+read/write/ccws. */ |
1da177e4 LT |
2449 | LO_data = (struct LO_eckd_data *) (idaws + cidaw); |
2450 | recid = first_rec; | |
2451 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { | |
2452 | /* Only standard blocks so there is just one locate record. */ | |
2453 | ccw[-1].flags |= CCW_FLAG_CC; | |
2454 | locate_record(ccw++, LO_data++, first_trk, first_offs + 1, | |
8e09f215 | 2455 | last_rec - recid + 1, cmd, basedev, blksize); |
1da177e4 | 2456 | } |
5705f702 | 2457 | rq_for_each_segment(bv, req, iter) { |
1da177e4 LT |
2458 | dst = page_address(bv->bv_page) + bv->bv_offset; |
2459 | if (dasd_page_cache) { | |
2460 | char *copy = kmem_cache_alloc(dasd_page_cache, | |
441e143e | 2461 | GFP_DMA | __GFP_NOWARN); |
1da177e4 LT |
2462 | if (copy && rq_data_dir(req) == WRITE) |
2463 | memcpy(copy + bv->bv_offset, dst, bv->bv_len); | |
2464 | if (copy) | |
2465 | dst = copy + bv->bv_offset; | |
2466 | } | |
2467 | for (off = 0; off < bv->bv_len; off += blksize) { | |
2468 | sector_t trkid = recid; | |
2469 | unsigned int recoffs = sector_div(trkid, blk_per_trk); | |
2470 | rcmd = cmd; | |
2471 | count = blksize; | |
2472 | /* Locate record for cdl special block ? */ | |
2473 | if (private->uses_cdl && recid < 2*blk_per_trk) { | |
2474 | if (dasd_eckd_cdl_special(blk_per_trk, recid)){ | |
2475 | rcmd |= 0x8; | |
2476 | count = dasd_eckd_cdl_reclen(recid); | |
ec5883ab HH |
2477 | if (count < blksize && |
2478 | rq_data_dir(req) == READ) | |
1da177e4 LT |
2479 | memset(dst + count, 0xe5, |
2480 | blksize - count); | |
2481 | } | |
2482 | ccw[-1].flags |= CCW_FLAG_CC; | |
2483 | locate_record(ccw++, LO_data++, | |
2484 | trkid, recoffs + 1, | |
8e09f215 | 2485 | 1, rcmd, basedev, count); |
1da177e4 LT |
2486 | } |
2487 | /* Locate record for standard blocks ? */ | |
2488 | if (private->uses_cdl && recid == 2*blk_per_trk) { | |
2489 | ccw[-1].flags |= CCW_FLAG_CC; | |
2490 | locate_record(ccw++, LO_data++, | |
2491 | trkid, recoffs + 1, | |
2492 | last_rec - recid + 1, | |
8e09f215 | 2493 | cmd, basedev, count); |
1da177e4 LT |
2494 | } |
2495 | /* Read/write ccw. */ | |
2496 | ccw[-1].flags |= CCW_FLAG_CC; | |
2497 | ccw->cmd_code = rcmd; | |
2498 | ccw->count = count; | |
2499 | if (idal_is_needed(dst, blksize)) { | |
2500 | ccw->cda = (__u32)(addr_t) idaws; | |
2501 | ccw->flags = CCW_FLAG_IDA; | |
2502 | idaws = idal_create_words(idaws, dst, blksize); | |
2503 | } else { | |
2504 | ccw->cda = (__u32)(addr_t) dst; | |
2505 | ccw->flags = 0; | |
2506 | } | |
2507 | ccw++; | |
2508 | dst += blksize; | |
2509 | recid++; | |
2510 | } | |
2511 | } | |
13de227b HS |
2512 | if (blk_noretry_request(req) || |
2513 | block->base->features & DASD_FEATURE_FAILFAST) | |
1c01b8a5 | 2514 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
8e09f215 SW |
2515 | cqr->startdev = startdev; |
2516 | cqr->memdev = startdev; | |
2517 | cqr->block = block; | |
7c8faa86 | 2518 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
a4d26c6a | 2519 | cqr->lpm = startdev->path_data.ppm; |
1da177e4 LT |
2520 | cqr->retries = 256; |
2521 | cqr->buildclk = get_clock(); | |
2522 | cqr->status = DASD_CQR_FILLED; | |
2523 | return cqr; | |
2524 | } | |
2525 | ||
f3eb5384 SW |
2526 | static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( |
2527 | struct dasd_device *startdev, | |
2528 | struct dasd_block *block, | |
2529 | struct request *req, | |
2530 | sector_t first_rec, | |
2531 | sector_t last_rec, | |
2532 | sector_t first_trk, | |
2533 | sector_t last_trk, | |
2534 | unsigned int first_offs, | |
2535 | unsigned int last_offs, | |
2536 | unsigned int blk_per_trk, | |
2537 | unsigned int blksize) | |
2538 | { | |
f3eb5384 SW |
2539 | unsigned long *idaws; |
2540 | struct dasd_ccw_req *cqr; | |
2541 | struct ccw1 *ccw; | |
2542 | struct req_iterator iter; | |
2543 | struct bio_vec *bv; | |
2544 | char *dst, *idaw_dst; | |
2545 | unsigned int cidaw, cplength, datasize; | |
2546 | unsigned int tlf; | |
2547 | sector_t recid; | |
2548 | unsigned char cmd; | |
2549 | struct dasd_device *basedev; | |
2550 | unsigned int trkcount, count, count_to_trk_end; | |
2551 | unsigned int idaw_len, seg_len, part_len, len_to_track_end; | |
2552 | unsigned char new_track, end_idaw; | |
2553 | sector_t trkid; | |
2554 | unsigned int recoffs; | |
2555 | ||
2556 | basedev = block->base; | |
f3eb5384 SW |
2557 | if (rq_data_dir(req) == READ) |
2558 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; | |
2559 | else if (rq_data_dir(req) == WRITE) | |
2560 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; | |
2561 | else | |
2562 | return ERR_PTR(-EINVAL); | |
2563 | ||
2564 | /* Track based I/O needs IDAWs for each page, and not just for | |
2565 | * 64 bit addresses. We need additional idals for pages | |
2566 | * that get filled from two tracks, so we use the number | |
2567 | * of records as upper limit. | |
2568 | */ | |
2569 | cidaw = last_rec - first_rec + 1; | |
2570 | trkcount = last_trk - first_trk + 1; | |
2571 | ||
2572 | /* 1x prefix + one read/write ccw per track */ | |
2573 | cplength = 1 + trkcount; | |
2574 | ||
2575 | /* on 31-bit we need space for two 32 bit addresses per page | |
2576 | * on 64-bit one 64 bit address | |
2577 | */ | |
2578 | datasize = sizeof(struct PFX_eckd_data) + | |
2579 | cidaw * sizeof(unsigned long long); | |
2580 | ||
2581 | /* Allocate the ccw request. */ | |
68b781fe SH |
2582 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, |
2583 | startdev); | |
f3eb5384 SW |
2584 | if (IS_ERR(cqr)) |
2585 | return cqr; | |
2586 | ccw = cqr->cpaddr; | |
2587 | /* transfer length factor: how many bytes to read from the last track */ | |
2588 | if (first_trk == last_trk) | |
2589 | tlf = last_offs - first_offs + 1; | |
2590 | else | |
2591 | tlf = last_offs + 1; | |
2592 | tlf *= blksize; | |
2593 | ||
2594 | if (prefix_LRE(ccw++, cqr->data, first_trk, | |
2595 | last_trk, cmd, basedev, startdev, | |
2596 | 1 /* format */, first_offs + 1, | |
2597 | trkcount, blksize, | |
2598 | tlf) == -EAGAIN) { | |
2599 | /* Clock not in sync and XRC is enabled. | |
2600 | * Try again later. | |
2601 | */ | |
2602 | dasd_sfree_request(cqr, startdev); | |
2603 | return ERR_PTR(-EAGAIN); | |
2604 | } | |
2605 | ||
2606 | /* | |
2607 | * The translation of request into ccw programs must meet the | |
2608 | * following conditions: | |
2609 | * - all idaws but the first and the last must address full pages | |
2610 | * (or 2K blocks on 31-bit) | |
2611 | * - the scope of a ccw and it's idal ends with the track boundaries | |
2612 | */ | |
2613 | idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); | |
2614 | recid = first_rec; | |
2615 | new_track = 1; | |
2616 | end_idaw = 0; | |
2617 | len_to_track_end = 0; | |
246ccea1 | 2618 | idaw_dst = NULL; |
f3eb5384 SW |
2619 | idaw_len = 0; |
2620 | rq_for_each_segment(bv, req, iter) { | |
2621 | dst = page_address(bv->bv_page) + bv->bv_offset; | |
2622 | seg_len = bv->bv_len; | |
2623 | while (seg_len) { | |
2624 | if (new_track) { | |
2625 | trkid = recid; | |
2626 | recoffs = sector_div(trkid, blk_per_trk); | |
2627 | count_to_trk_end = blk_per_trk - recoffs; | |
2628 | count = min((last_rec - recid + 1), | |
2629 | (sector_t)count_to_trk_end); | |
2630 | len_to_track_end = count * blksize; | |
2631 | ccw[-1].flags |= CCW_FLAG_CC; | |
2632 | ccw->cmd_code = cmd; | |
2633 | ccw->count = len_to_track_end; | |
2634 | ccw->cda = (__u32)(addr_t)idaws; | |
2635 | ccw->flags = CCW_FLAG_IDA; | |
2636 | ccw++; | |
2637 | recid += count; | |
2638 | new_track = 0; | |
52db45c3 SW |
2639 | /* first idaw for a ccw may start anywhere */ |
2640 | if (!idaw_dst) | |
2641 | idaw_dst = dst; | |
f3eb5384 | 2642 | } |
52db45c3 SW |
2643 | /* If we start a new idaw, we must make sure that it |
2644 | * starts on an IDA_BLOCK_SIZE boundary. | |
f3eb5384 SW |
2645 | * If we continue an idaw, we must make sure that the |
2646 | * current segment begins where the so far accumulated | |
2647 | * idaw ends | |
2648 | */ | |
52db45c3 SW |
2649 | if (!idaw_dst) { |
2650 | if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { | |
2651 | dasd_sfree_request(cqr, startdev); | |
2652 | return ERR_PTR(-ERANGE); | |
2653 | } else | |
2654 | idaw_dst = dst; | |
2655 | } | |
f3eb5384 SW |
2656 | if ((idaw_dst + idaw_len) != dst) { |
2657 | dasd_sfree_request(cqr, startdev); | |
2658 | return ERR_PTR(-ERANGE); | |
2659 | } | |
2660 | part_len = min(seg_len, len_to_track_end); | |
2661 | seg_len -= part_len; | |
2662 | dst += part_len; | |
2663 | idaw_len += part_len; | |
2664 | len_to_track_end -= part_len; | |
2665 | /* collected memory area ends on an IDA_BLOCK border, | |
2666 | * -> create an idaw | |
2667 | * idal_create_words will handle cases where idaw_len | |
2668 | * is larger then IDA_BLOCK_SIZE | |
2669 | */ | |
2670 | if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) | |
2671 | end_idaw = 1; | |
2672 | /* We also need to end the idaw at track end */ | |
2673 | if (!len_to_track_end) { | |
2674 | new_track = 1; | |
2675 | end_idaw = 1; | |
2676 | } | |
2677 | if (end_idaw) { | |
2678 | idaws = idal_create_words(idaws, idaw_dst, | |
2679 | idaw_len); | |
246ccea1 | 2680 | idaw_dst = NULL; |
f3eb5384 SW |
2681 | idaw_len = 0; |
2682 | end_idaw = 0; | |
2683 | } | |
2684 | } | |
2685 | } | |
2686 | ||
2687 | if (blk_noretry_request(req) || | |
2688 | block->base->features & DASD_FEATURE_FAILFAST) | |
2689 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
2690 | cqr->startdev = startdev; | |
2691 | cqr->memdev = startdev; | |
2692 | cqr->block = block; | |
7c8faa86 | 2693 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
a4d26c6a | 2694 | cqr->lpm = startdev->path_data.ppm; |
f3eb5384 SW |
2695 | cqr->retries = 256; |
2696 | cqr->buildclk = get_clock(); | |
2697 | cqr->status = DASD_CQR_FILLED; | |
2698 | return cqr; | |
2699 | } | |
2700 | ||
2701 | static int prepare_itcw(struct itcw *itcw, | |
2702 | unsigned int trk, unsigned int totrk, int cmd, | |
2703 | struct dasd_device *basedev, | |
2704 | struct dasd_device *startdev, | |
2705 | unsigned int rec_on_trk, int count, | |
2706 | unsigned int blksize, | |
2707 | unsigned int total_data_size, | |
2708 | unsigned int tlf, | |
2709 | unsigned int blk_per_trk) | |
2710 | { | |
2711 | struct PFX_eckd_data pfxdata; | |
2712 | struct dasd_eckd_private *basepriv, *startpriv; | |
2713 | struct DE_eckd_data *dedata; | |
2714 | struct LRE_eckd_data *lredata; | |
2715 | struct dcw *dcw; | |
2716 | ||
2717 | u32 begcyl, endcyl; | |
2718 | u16 heads, beghead, endhead; | |
2719 | u8 pfx_cmd; | |
2720 | ||
2721 | int rc = 0; | |
2722 | int sector = 0; | |
2723 | int dn, d; | |
2724 | ||
2725 | ||
2726 | /* setup prefix data */ | |
2727 | basepriv = (struct dasd_eckd_private *) basedev->private; | |
2728 | startpriv = (struct dasd_eckd_private *) startdev->private; | |
2729 | dedata = &pfxdata.define_extent; | |
2730 | lredata = &pfxdata.locate_record; | |
2731 | ||
2732 | memset(&pfxdata, 0, sizeof(pfxdata)); | |
2733 | pfxdata.format = 1; /* PFX with LRE */ | |
2734 | pfxdata.base_address = basepriv->ned->unit_addr; | |
2735 | pfxdata.base_lss = basepriv->ned->ID; | |
2736 | pfxdata.validity.define_extent = 1; | |
2737 | ||
2738 | /* private uid is kept up to date, conf_data may be outdated */ | |
2739 | if (startpriv->uid.type != UA_BASE_DEVICE) { | |
2740 | pfxdata.validity.verify_base = 1; | |
2741 | if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) | |
2742 | pfxdata.validity.hyper_pav = 1; | |
2743 | } | |
2744 | ||
2745 | switch (cmd) { | |
2746 | case DASD_ECKD_CCW_READ_TRACK_DATA: | |
2747 | dedata->mask.perm = 0x1; | |
2748 | dedata->attributes.operation = basepriv->attrib.operation; | |
2749 | dedata->blk_size = blksize; | |
2750 | dedata->ga_extended |= 0x42; | |
2751 | lredata->operation.orientation = 0x0; | |
2752 | lredata->operation.operation = 0x0C; | |
2753 | lredata->auxiliary.check_bytes = 0x01; | |
2754 | pfx_cmd = DASD_ECKD_CCW_PFX_READ; | |
2755 | break; | |
2756 | case DASD_ECKD_CCW_WRITE_TRACK_DATA: | |
2757 | dedata->mask.perm = 0x02; | |
2758 | dedata->attributes.operation = basepriv->attrib.operation; | |
2759 | dedata->blk_size = blksize; | |
2760 | rc = check_XRC_on_prefix(&pfxdata, basedev); | |
2761 | dedata->ga_extended |= 0x42; | |
2762 | lredata->operation.orientation = 0x0; | |
2763 | lredata->operation.operation = 0x3F; | |
2764 | lredata->extended_operation = 0x23; | |
2765 | lredata->auxiliary.check_bytes = 0x2; | |
2766 | pfx_cmd = DASD_ECKD_CCW_PFX; | |
2767 | break; | |
2768 | default: | |
2769 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
2770 | "prepare itcw, unknown opcode 0x%x", cmd); | |
2771 | BUG(); | |
2772 | break; | |
2773 | } | |
2774 | if (rc) | |
2775 | return rc; | |
2776 | ||
2777 | dedata->attributes.mode = 0x3; /* ECKD */ | |
2778 | ||
2779 | heads = basepriv->rdc_data.trk_per_cyl; | |
2780 | begcyl = trk / heads; | |
2781 | beghead = trk % heads; | |
2782 | endcyl = totrk / heads; | |
2783 | endhead = totrk % heads; | |
2784 | ||
2785 | /* check for sequential prestage - enhance cylinder range */ | |
2786 | if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || | |
2787 | dedata->attributes.operation == DASD_SEQ_ACCESS) { | |
2788 | ||
2789 | if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) | |
2790 | endcyl += basepriv->attrib.nr_cyl; | |
2791 | else | |
2792 | endcyl = (basepriv->real_cyl - 1); | |
2793 | } | |
2794 | ||
2795 | set_ch_t(&dedata->beg_ext, begcyl, beghead); | |
2796 | set_ch_t(&dedata->end_ext, endcyl, endhead); | |
2797 | ||
2798 | dedata->ep_format = 0x20; /* records per track is valid */ | |
2799 | dedata->ep_rec_per_track = blk_per_trk; | |
2800 | ||
2801 | if (rec_on_trk) { | |
2802 | switch (basepriv->rdc_data.dev_type) { | |
2803 | case 0x3390: | |
2804 | dn = ceil_quot(blksize + 6, 232); | |
2805 | d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); | |
2806 | sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; | |
2807 | break; | |
2808 | case 0x3380: | |
2809 | d = 7 + ceil_quot(blksize + 12, 32); | |
2810 | sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; | |
2811 | break; | |
2812 | } | |
2813 | } | |
2814 | ||
2815 | lredata->auxiliary.length_valid = 1; | |
2816 | lredata->auxiliary.length_scope = 1; | |
2817 | lredata->auxiliary.imbedded_ccw_valid = 1; | |
2818 | lredata->length = tlf; | |
2819 | lredata->imbedded_ccw = cmd; | |
2820 | lredata->count = count; | |
2821 | lredata->sector = sector; | |
2822 | set_ch_t(&lredata->seek_addr, begcyl, beghead); | |
2823 | lredata->search_arg.cyl = lredata->seek_addr.cyl; | |
2824 | lredata->search_arg.head = lredata->seek_addr.head; | |
2825 | lredata->search_arg.record = rec_on_trk; | |
2826 | ||
2827 | dcw = itcw_add_dcw(itcw, pfx_cmd, 0, | |
2828 | &pfxdata, sizeof(pfxdata), total_data_size); | |
364c18d8 | 2829 | return IS_ERR(dcw) ? PTR_ERR(dcw) : 0; |
f3eb5384 SW |
2830 | } |
2831 | ||
2832 | static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( | |
2833 | struct dasd_device *startdev, | |
2834 | struct dasd_block *block, | |
2835 | struct request *req, | |
2836 | sector_t first_rec, | |
2837 | sector_t last_rec, | |
2838 | sector_t first_trk, | |
2839 | sector_t last_trk, | |
2840 | unsigned int first_offs, | |
2841 | unsigned int last_offs, | |
2842 | unsigned int blk_per_trk, | |
2843 | unsigned int blksize) | |
2844 | { | |
f3eb5384 SW |
2845 | struct dasd_ccw_req *cqr; |
2846 | struct req_iterator iter; | |
2847 | struct bio_vec *bv; | |
2848 | char *dst; | |
2849 | unsigned int trkcount, ctidaw; | |
2850 | unsigned char cmd; | |
2851 | struct dasd_device *basedev; | |
2852 | unsigned int tlf; | |
2853 | struct itcw *itcw; | |
2854 | struct tidaw *last_tidaw = NULL; | |
2855 | int itcw_op; | |
2856 | size_t itcw_size; | |
ef19298b SW |
2857 | u8 tidaw_flags; |
2858 | unsigned int seg_len, part_len, len_to_track_end; | |
2859 | unsigned char new_track; | |
2860 | sector_t recid, trkid; | |
2861 | unsigned int offs; | |
2862 | unsigned int count, count_to_trk_end; | |
cd10502b | 2863 | int ret; |
f3eb5384 SW |
2864 | |
2865 | basedev = block->base; | |
f3eb5384 SW |
2866 | if (rq_data_dir(req) == READ) { |
2867 | cmd = DASD_ECKD_CCW_READ_TRACK_DATA; | |
2868 | itcw_op = ITCW_OP_READ; | |
2869 | } else if (rq_data_dir(req) == WRITE) { | |
2870 | cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; | |
2871 | itcw_op = ITCW_OP_WRITE; | |
2872 | } else | |
2873 | return ERR_PTR(-EINVAL); | |
2874 | ||
2875 | /* trackbased I/O needs address all memory via TIDAWs, | |
2876 | * not just for 64 bit addresses. This allows us to map | |
2877 | * each segment directly to one tidaw. | |
ef19298b SW |
2878 | * In the case of write requests, additional tidaws may |
2879 | * be needed when a segment crosses a track boundary. | |
f3eb5384 SW |
2880 | */ |
2881 | trkcount = last_trk - first_trk + 1; | |
2882 | ctidaw = 0; | |
2883 | rq_for_each_segment(bv, req, iter) { | |
2884 | ++ctidaw; | |
2885 | } | |
ef19298b SW |
2886 | if (rq_data_dir(req) == WRITE) |
2887 | ctidaw += (last_trk - first_trk); | |
f3eb5384 SW |
2888 | |
2889 | /* Allocate the ccw request. */ | |
2890 | itcw_size = itcw_calc_size(0, ctidaw, 0); | |
68b781fe | 2891 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); |
f3eb5384 SW |
2892 | if (IS_ERR(cqr)) |
2893 | return cqr; | |
2894 | ||
f3eb5384 SW |
2895 | /* transfer length factor: how many bytes to read from the last track */ |
2896 | if (first_trk == last_trk) | |
2897 | tlf = last_offs - first_offs + 1; | |
2898 | else | |
2899 | tlf = last_offs + 1; | |
2900 | tlf *= blksize; | |
2901 | ||
2902 | itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); | |
ef19298b | 2903 | if (IS_ERR(itcw)) { |
cd10502b JL |
2904 | ret = -EINVAL; |
2905 | goto out_error; | |
ef19298b | 2906 | } |
f3eb5384 | 2907 | cqr->cpaddr = itcw_get_tcw(itcw); |
f3eb5384 SW |
2908 | if (prepare_itcw(itcw, first_trk, last_trk, |
2909 | cmd, basedev, startdev, | |
2910 | first_offs + 1, | |
2911 | trkcount, blksize, | |
2912 | (last_rec - first_rec + 1) * blksize, | |
2913 | tlf, blk_per_trk) == -EAGAIN) { | |
2914 | /* Clock not in sync and XRC is enabled. | |
2915 | * Try again later. | |
2916 | */ | |
cd10502b JL |
2917 | ret = -EAGAIN; |
2918 | goto out_error; | |
f3eb5384 | 2919 | } |
d54cddb6 | 2920 | len_to_track_end = 0; |
f3eb5384 SW |
2921 | /* |
2922 | * A tidaw can address 4k of memory, but must not cross page boundaries | |
2923 | * We can let the block layer handle this by setting | |
2924 | * blk_queue_segment_boundary to page boundaries and | |
2925 | * blk_max_segment_size to page size when setting up the request queue. | |
ef19298b SW |
2926 | * For write requests, a TIDAW must not cross track boundaries, because |
2927 | * we have to set the CBC flag on the last tidaw for each track. | |
f3eb5384 | 2928 | */ |
ef19298b SW |
2929 | if (rq_data_dir(req) == WRITE) { |
2930 | new_track = 1; | |
2931 | recid = first_rec; | |
2932 | rq_for_each_segment(bv, req, iter) { | |
2933 | dst = page_address(bv->bv_page) + bv->bv_offset; | |
2934 | seg_len = bv->bv_len; | |
2935 | while (seg_len) { | |
2936 | if (new_track) { | |
2937 | trkid = recid; | |
2938 | offs = sector_div(trkid, blk_per_trk); | |
2939 | count_to_trk_end = blk_per_trk - offs; | |
2940 | count = min((last_rec - recid + 1), | |
2941 | (sector_t)count_to_trk_end); | |
2942 | len_to_track_end = count * blksize; | |
2943 | recid += count; | |
2944 | new_track = 0; | |
2945 | } | |
2946 | part_len = min(seg_len, len_to_track_end); | |
2947 | seg_len -= part_len; | |
2948 | len_to_track_end -= part_len; | |
2949 | /* We need to end the tidaw at track end */ | |
2950 | if (!len_to_track_end) { | |
2951 | new_track = 1; | |
2952 | tidaw_flags = TIDAW_FLAGS_INSERT_CBC; | |
2953 | } else | |
2954 | tidaw_flags = 0; | |
2955 | last_tidaw = itcw_add_tidaw(itcw, tidaw_flags, | |
2956 | dst, part_len); | |
cd10502b JL |
2957 | if (IS_ERR(last_tidaw)) { |
2958 | ret = -EINVAL; | |
2959 | goto out_error; | |
2960 | } | |
ef19298b SW |
2961 | dst += part_len; |
2962 | } | |
2963 | } | |
2964 | } else { | |
2965 | rq_for_each_segment(bv, req, iter) { | |
2966 | dst = page_address(bv->bv_page) + bv->bv_offset; | |
2967 | last_tidaw = itcw_add_tidaw(itcw, 0x00, | |
2968 | dst, bv->bv_len); | |
cd10502b JL |
2969 | if (IS_ERR(last_tidaw)) { |
2970 | ret = -EINVAL; | |
2971 | goto out_error; | |
2972 | } | |
ef19298b | 2973 | } |
f3eb5384 | 2974 | } |
ef19298b SW |
2975 | last_tidaw->flags |= TIDAW_FLAGS_LAST; |
2976 | last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC; | |
f3eb5384 SW |
2977 | itcw_finalize(itcw); |
2978 | ||
2979 | if (blk_noretry_request(req) || | |
2980 | block->base->features & DASD_FEATURE_FAILFAST) | |
2981 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
ef19298b | 2982 | cqr->cpmode = 1; |
f3eb5384 SW |
2983 | cqr->startdev = startdev; |
2984 | cqr->memdev = startdev; | |
2985 | cqr->block = block; | |
7c8faa86 | 2986 | cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ |
a4d26c6a | 2987 | cqr->lpm = startdev->path_data.ppm; |
f3eb5384 SW |
2988 | cqr->retries = 256; |
2989 | cqr->buildclk = get_clock(); | |
2990 | cqr->status = DASD_CQR_FILLED; | |
2991 | return cqr; | |
cd10502b JL |
2992 | out_error: |
2993 | dasd_sfree_request(cqr, startdev); | |
2994 | return ERR_PTR(ret); | |
f3eb5384 SW |
2995 | } |
2996 | ||
2997 | static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, | |
2998 | struct dasd_block *block, | |
2999 | struct request *req) | |
3000 | { | |
ef19298b | 3001 | int cmdrtd, cmdwtd; |
f3eb5384 | 3002 | int use_prefix; |
ef19298b | 3003 | int fcx_multitrack; |
45b44d76 | 3004 | struct dasd_eckd_private *private; |
f3eb5384 SW |
3005 | struct dasd_device *basedev; |
3006 | sector_t first_rec, last_rec; | |
3007 | sector_t first_trk, last_trk; | |
3008 | unsigned int first_offs, last_offs; | |
3009 | unsigned int blk_per_trk, blksize; | |
3010 | int cdlspecial; | |
ef19298b | 3011 | unsigned int data_size; |
f3eb5384 SW |
3012 | struct dasd_ccw_req *cqr; |
3013 | ||
3014 | basedev = block->base; | |
3015 | private = (struct dasd_eckd_private *) basedev->private; | |
3016 | ||
3017 | /* Calculate number of blocks/records per track. */ | |
3018 | blksize = block->bp_block; | |
3019 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); | |
6fca97a9 SH |
3020 | if (blk_per_trk == 0) |
3021 | return ERR_PTR(-EINVAL); | |
f3eb5384 | 3022 | /* Calculate record id of first and last block. */ |
83096ebf | 3023 | first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; |
f3eb5384 SW |
3024 | first_offs = sector_div(first_trk, blk_per_trk); |
3025 | last_rec = last_trk = | |
83096ebf | 3026 | (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
f3eb5384 SW |
3027 | last_offs = sector_div(last_trk, blk_per_trk); |
3028 | cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); | |
3029 | ||
ef19298b SW |
3030 | fcx_multitrack = private->features.feature[40] & 0x20; |
3031 | data_size = blk_rq_bytes(req); | |
3032 | /* tpm write request add CBC data on each track boundary */ | |
3033 | if (rq_data_dir(req) == WRITE) | |
3034 | data_size += (last_trk - first_trk) * 4; | |
f3eb5384 SW |
3035 | |
3036 | /* is read track data and write track data in command mode supported? */ | |
3037 | cmdrtd = private->features.feature[9] & 0x20; | |
3038 | cmdwtd = private->features.feature[12] & 0x40; | |
3039 | use_prefix = private->features.feature[8] & 0x01; | |
3040 | ||
3041 | cqr = NULL; | |
3042 | if (cdlspecial || dasd_page_cache) { | |
3043 | /* do nothing, just fall through to the cmd mode single case */ | |
ef19298b SW |
3044 | } else if ((data_size <= private->fcx_max_data) |
3045 | && (fcx_multitrack || (first_trk == last_trk))) { | |
f3eb5384 SW |
3046 | cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, |
3047 | first_rec, last_rec, | |
3048 | first_trk, last_trk, | |
3049 | first_offs, last_offs, | |
3050 | blk_per_trk, blksize); | |
ef19298b SW |
3051 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
3052 | (PTR_ERR(cqr) != -ENOMEM)) | |
f3eb5384 SW |
3053 | cqr = NULL; |
3054 | } else if (use_prefix && | |
3055 | (((rq_data_dir(req) == READ) && cmdrtd) || | |
3056 | ((rq_data_dir(req) == WRITE) && cmdwtd))) { | |
3057 | cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, | |
3058 | first_rec, last_rec, | |
3059 | first_trk, last_trk, | |
3060 | first_offs, last_offs, | |
3061 | blk_per_trk, blksize); | |
ef19298b SW |
3062 | if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && |
3063 | (PTR_ERR(cqr) != -ENOMEM)) | |
f3eb5384 SW |
3064 | cqr = NULL; |
3065 | } | |
3066 | if (!cqr) | |
3067 | cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, | |
3068 | first_rec, last_rec, | |
3069 | first_trk, last_trk, | |
3070 | first_offs, last_offs, | |
3071 | blk_per_trk, blksize); | |
3072 | return cqr; | |
3073 | } | |
3074 | ||
e4dbb0f2 SH |
3075 | static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev, |
3076 | struct dasd_block *block, | |
3077 | struct request *req) | |
3078 | { | |
e4dbb0f2 SH |
3079 | unsigned long *idaws; |
3080 | struct dasd_device *basedev; | |
3081 | struct dasd_ccw_req *cqr; | |
3082 | struct ccw1 *ccw; | |
3083 | struct req_iterator iter; | |
3084 | struct bio_vec *bv; | |
3085 | char *dst; | |
3086 | unsigned char cmd; | |
3087 | unsigned int trkcount; | |
3088 | unsigned int seg_len, len_to_track_end; | |
3089 | unsigned int first_offs; | |
3090 | unsigned int cidaw, cplength, datasize; | |
3091 | sector_t first_trk, last_trk; | |
3092 | unsigned int pfx_datasize; | |
3093 | ||
3094 | /* | |
3095 | * raw track access needs to be mutiple of 64k and on 64k boundary | |
3096 | */ | |
3097 | if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) { | |
3098 | cqr = ERR_PTR(-EINVAL); | |
3099 | goto out; | |
3100 | } | |
3101 | if (((blk_rq_pos(req) + blk_rq_sectors(req)) % | |
3102 | DASD_RAW_SECTORS_PER_TRACK) != 0) { | |
3103 | cqr = ERR_PTR(-EINVAL); | |
3104 | goto out; | |
3105 | } | |
3106 | ||
3107 | first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK; | |
3108 | last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) / | |
3109 | DASD_RAW_SECTORS_PER_TRACK; | |
3110 | trkcount = last_trk - first_trk + 1; | |
3111 | first_offs = 0; | |
3112 | basedev = block->base; | |
e4dbb0f2 SH |
3113 | |
3114 | if (rq_data_dir(req) == READ) | |
3115 | cmd = DASD_ECKD_CCW_READ_TRACK; | |
3116 | else if (rq_data_dir(req) == WRITE) | |
3117 | cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK; | |
3118 | else { | |
3119 | cqr = ERR_PTR(-EINVAL); | |
3120 | goto out; | |
3121 | } | |
3122 | ||
3123 | /* | |
3124 | * Raw track based I/O needs IDAWs for each page, | |
3125 | * and not just for 64 bit addresses. | |
3126 | */ | |
3127 | cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK; | |
3128 | ||
3129 | /* 1x prefix + one read/write ccw per track */ | |
3130 | cplength = 1 + trkcount; | |
3131 | ||
3132 | /* | |
3133 | * struct PFX_eckd_data has up to 2 byte as extended parameter | |
3134 | * this is needed for write full track and has to be mentioned | |
25985edc | 3135 | * separately |
e4dbb0f2 SH |
3136 | * add 8 instead of 2 to keep 8 byte boundary |
3137 | */ | |
3138 | pfx_datasize = sizeof(struct PFX_eckd_data) + 8; | |
3139 | ||
3140 | datasize = pfx_datasize + cidaw * sizeof(unsigned long long); | |
3141 | ||
3142 | /* Allocate the ccw request. */ | |
3143 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, | |
3144 | datasize, startdev); | |
3145 | if (IS_ERR(cqr)) | |
3146 | goto out; | |
3147 | ccw = cqr->cpaddr; | |
3148 | ||
3149 | if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd, | |
3150 | basedev, startdev, 1 /* format */, first_offs + 1, | |
3151 | trkcount, 0, 0) == -EAGAIN) { | |
3152 | /* Clock not in sync and XRC is enabled. | |
3153 | * Try again later. | |
3154 | */ | |
3155 | dasd_sfree_request(cqr, startdev); | |
3156 | cqr = ERR_PTR(-EAGAIN); | |
3157 | goto out; | |
3158 | } | |
3159 | ||
3160 | idaws = (unsigned long *)(cqr->data + pfx_datasize); | |
3161 | ||
3162 | len_to_track_end = 0; | |
3163 | ||
3164 | rq_for_each_segment(bv, req, iter) { | |
3165 | dst = page_address(bv->bv_page) + bv->bv_offset; | |
3166 | seg_len = bv->bv_len; | |
3167 | if (!len_to_track_end) { | |
3168 | ccw[-1].flags |= CCW_FLAG_CC; | |
3169 | ccw->cmd_code = cmd; | |
3170 | /* maximum 3390 track size */ | |
3171 | ccw->count = 57326; | |
3172 | /* 64k map to one track */ | |
3173 | len_to_track_end = 65536; | |
3174 | ccw->cda = (__u32)(addr_t)idaws; | |
3175 | ccw->flags |= CCW_FLAG_IDA; | |
3176 | ccw->flags |= CCW_FLAG_SLI; | |
3177 | ccw++; | |
3178 | } | |
3179 | len_to_track_end -= seg_len; | |
3180 | idaws = idal_create_words(idaws, dst, seg_len); | |
3181 | } | |
3182 | ||
3183 | if (blk_noretry_request(req) || | |
3184 | block->base->features & DASD_FEATURE_FAILFAST) | |
3185 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
3186 | cqr->startdev = startdev; | |
3187 | cqr->memdev = startdev; | |
3188 | cqr->block = block; | |
3189 | cqr->expires = startdev->default_expires * HZ; | |
3190 | cqr->lpm = startdev->path_data.ppm; | |
3191 | cqr->retries = 256; | |
3192 | cqr->buildclk = get_clock(); | |
3193 | cqr->status = DASD_CQR_FILLED; | |
3194 | ||
3195 | if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN) | |
3196 | cqr = NULL; | |
3197 | out: | |
3198 | return cqr; | |
3199 | } | |
3200 | ||
3201 | ||
1da177e4 LT |
3202 | static int |
3203 | dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) | |
3204 | { | |
3205 | struct dasd_eckd_private *private; | |
3206 | struct ccw1 *ccw; | |
5705f702 | 3207 | struct req_iterator iter; |
1da177e4 LT |
3208 | struct bio_vec *bv; |
3209 | char *dst, *cda; | |
3210 | unsigned int blksize, blk_per_trk, off; | |
3211 | sector_t recid; | |
5705f702 | 3212 | int status; |
1da177e4 LT |
3213 | |
3214 | if (!dasd_page_cache) | |
3215 | goto out; | |
8e09f215 SW |
3216 | private = (struct dasd_eckd_private *) cqr->block->base->private; |
3217 | blksize = cqr->block->bp_block; | |
1da177e4 | 3218 | blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); |
83096ebf | 3219 | recid = blk_rq_pos(req) >> cqr->block->s2b_shift; |
1da177e4 LT |
3220 | ccw = cqr->cpaddr; |
3221 | /* Skip over define extent & locate record. */ | |
3222 | ccw++; | |
3223 | if (private->uses_cdl == 0 || recid > 2*blk_per_trk) | |
3224 | ccw++; | |
5705f702 | 3225 | rq_for_each_segment(bv, req, iter) { |
1da177e4 LT |
3226 | dst = page_address(bv->bv_page) + bv->bv_offset; |
3227 | for (off = 0; off < bv->bv_len; off += blksize) { | |
3228 | /* Skip locate record. */ | |
3229 | if (private->uses_cdl && recid <= 2*blk_per_trk) | |
3230 | ccw++; | |
3231 | if (dst) { | |
3232 | if (ccw->flags & CCW_FLAG_IDA) | |
3233 | cda = *((char **)((addr_t) ccw->cda)); | |
3234 | else | |
3235 | cda = (char *)((addr_t) ccw->cda); | |
3236 | if (dst != cda) { | |
3237 | if (rq_data_dir(req) == READ) | |
3238 | memcpy(dst, cda, bv->bv_len); | |
3239 | kmem_cache_free(dasd_page_cache, | |
3240 | (void *)((addr_t)cda & PAGE_MASK)); | |
3241 | } | |
3242 | dst = NULL; | |
3243 | } | |
3244 | ccw++; | |
3245 | recid++; | |
3246 | } | |
3247 | } | |
3248 | out: | |
3249 | status = cqr->status == DASD_CQR_DONE; | |
8e09f215 | 3250 | dasd_sfree_request(cqr, cqr->memdev); |
1da177e4 LT |
3251 | return status; |
3252 | } | |
3253 | ||
8e09f215 | 3254 | /* |
f3eb5384 | 3255 | * Modify ccw/tcw in cqr so it can be started on a base device. |
8e09f215 SW |
3256 | * |
3257 | * Note that this is not enough to restart the cqr! | |
3258 | * Either reset cqr->startdev as well (summary unit check handling) | |
3259 | * or restart via separate cqr (as in ERP handling). | |
3260 | */ | |
3261 | void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) | |
3262 | { | |
3263 | struct ccw1 *ccw; | |
3264 | struct PFX_eckd_data *pfxdata; | |
f3eb5384 SW |
3265 | struct tcw *tcw; |
3266 | struct tccb *tccb; | |
3267 | struct dcw *dcw; | |
3268 | ||
3269 | if (cqr->cpmode == 1) { | |
3270 | tcw = cqr->cpaddr; | |
3271 | tccb = tcw_get_tccb(tcw); | |
3272 | dcw = (struct dcw *)&tccb->tca[0]; | |
3273 | pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; | |
8e09f215 SW |
3274 | pfxdata->validity.verify_base = 0; |
3275 | pfxdata->validity.hyper_pav = 0; | |
f3eb5384 SW |
3276 | } else { |
3277 | ccw = cqr->cpaddr; | |
3278 | pfxdata = cqr->data; | |
3279 | if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { | |
3280 | pfxdata->validity.verify_base = 0; | |
3281 | pfxdata->validity.hyper_pav = 0; | |
3282 | } | |
8e09f215 SW |
3283 | } |
3284 | } | |
3285 | ||
3286 | #define DASD_ECKD_CHANQ_MAX_SIZE 4 | |
3287 | ||
3288 | static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, | |
3289 | struct dasd_block *block, | |
3290 | struct request *req) | |
3291 | { | |
3292 | struct dasd_eckd_private *private; | |
3293 | struct dasd_device *startdev; | |
3294 | unsigned long flags; | |
3295 | struct dasd_ccw_req *cqr; | |
3296 | ||
3297 | startdev = dasd_alias_get_start_dev(base); | |
3298 | if (!startdev) | |
3299 | startdev = base; | |
3300 | private = (struct dasd_eckd_private *) startdev->private; | |
3301 | if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) | |
3302 | return ERR_PTR(-EBUSY); | |
3303 | ||
3304 | spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); | |
3305 | private->count++; | |
e4dbb0f2 SH |
3306 | if ((base->features & DASD_FEATURE_USERAW)) |
3307 | cqr = dasd_raw_build_cp(startdev, block, req); | |
3308 | else | |
3309 | cqr = dasd_eckd_build_cp(startdev, block, req); | |
8e09f215 SW |
3310 | if (IS_ERR(cqr)) |
3311 | private->count--; | |
3312 | spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); | |
3313 | return cqr; | |
3314 | } | |
3315 | ||
3316 | static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, | |
3317 | struct request *req) | |
3318 | { | |
3319 | struct dasd_eckd_private *private; | |
3320 | unsigned long flags; | |
3321 | ||
3322 | spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); | |
3323 | private = (struct dasd_eckd_private *) cqr->memdev->private; | |
3324 | private->count--; | |
3325 | spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); | |
3326 | return dasd_eckd_free_cp(cqr, req); | |
3327 | } | |
3328 | ||
1da177e4 LT |
3329 | static int |
3330 | dasd_eckd_fill_info(struct dasd_device * device, | |
3331 | struct dasd_information2_t * info) | |
3332 | { | |
3333 | struct dasd_eckd_private *private; | |
3334 | ||
3335 | private = (struct dasd_eckd_private *) device->private; | |
3336 | info->label_block = 2; | |
3337 | info->FBA_layout = private->uses_cdl ? 0 : 1; | |
3338 | info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; | |
3339 | info->characteristics_size = sizeof(struct dasd_eckd_characteristics); | |
3340 | memcpy(info->characteristics, &private->rdc_data, | |
3341 | sizeof(struct dasd_eckd_characteristics)); | |
4abb08c2 SW |
3342 | info->confdata_size = min((unsigned long)private->conf_len, |
3343 | sizeof(info->configuration_data)); | |
3344 | memcpy(info->configuration_data, private->conf_data, | |
3345 | info->confdata_size); | |
1da177e4 LT |
3346 | return 0; |
3347 | } | |
3348 | ||
3349 | /* | |
3350 | * SECTION: ioctl functions for eckd devices. | |
3351 | */ | |
3352 | ||
3353 | /* | |
3354 | * Release device ioctl. | |
138c014d | 3355 | * Buils a channel programm to releases a prior reserved |
1da177e4 LT |
3356 | * (see dasd_eckd_reserve) device. |
3357 | */ | |
3358 | static int | |
1107ccfb | 3359 | dasd_eckd_release(struct dasd_device *device) |
1da177e4 | 3360 | { |
1da177e4 LT |
3361 | struct dasd_ccw_req *cqr; |
3362 | int rc; | |
f3eb5384 | 3363 | struct ccw1 *ccw; |
f932bcea | 3364 | int useglobal; |
1da177e4 LT |
3365 | |
3366 | if (!capable(CAP_SYS_ADMIN)) | |
3367 | return -EACCES; | |
3368 | ||
f932bcea | 3369 | useglobal = 0; |
68b781fe | 3370 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
1da177e4 | 3371 | if (IS_ERR(cqr)) { |
f932bcea SW |
3372 | mutex_lock(&dasd_reserve_mutex); |
3373 | useglobal = 1; | |
3374 | cqr = &dasd_reserve_req->cqr; | |
3375 | memset(cqr, 0, sizeof(*cqr)); | |
3376 | memset(&dasd_reserve_req->ccw, 0, | |
3377 | sizeof(dasd_reserve_req->ccw)); | |
3378 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
3379 | cqr->data = &dasd_reserve_req->data; | |
3380 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 3381 | } |
f3eb5384 SW |
3382 | ccw = cqr->cpaddr; |
3383 | ccw->cmd_code = DASD_ECKD_CCW_RELEASE; | |
3384 | ccw->flags |= CCW_FLAG_SLI; | |
3385 | ccw->count = 32; | |
3386 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
3387 | cqr->startdev = device; |
3388 | cqr->memdev = device; | |
1da177e4 | 3389 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 3390 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 3391 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 LT |
3392 | cqr->expires = 2 * HZ; |
3393 | cqr->buildclk = get_clock(); | |
3394 | cqr->status = DASD_CQR_FILLED; | |
3395 | ||
3396 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
3397 | if (!rc) |
3398 | clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 3399 | |
f932bcea SW |
3400 | if (useglobal) |
3401 | mutex_unlock(&dasd_reserve_mutex); | |
3402 | else | |
3403 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
3404 | return rc; |
3405 | } | |
3406 | ||
3407 | /* | |
3408 | * Reserve device ioctl. | |
3409 | * Options are set to 'synchronous wait for interrupt' and | |
138c014d HH |
3410 | * 'timeout the request'. This leads to a terminate IO if |
3411 | * the interrupt is outstanding for a certain time. | |
1da177e4 LT |
3412 | */ |
3413 | static int | |
1107ccfb | 3414 | dasd_eckd_reserve(struct dasd_device *device) |
1da177e4 | 3415 | { |
1da177e4 LT |
3416 | struct dasd_ccw_req *cqr; |
3417 | int rc; | |
f3eb5384 | 3418 | struct ccw1 *ccw; |
f932bcea | 3419 | int useglobal; |
1da177e4 LT |
3420 | |
3421 | if (!capable(CAP_SYS_ADMIN)) | |
3422 | return -EACCES; | |
3423 | ||
f932bcea | 3424 | useglobal = 0; |
68b781fe | 3425 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
1da177e4 | 3426 | if (IS_ERR(cqr)) { |
f932bcea SW |
3427 | mutex_lock(&dasd_reserve_mutex); |
3428 | useglobal = 1; | |
3429 | cqr = &dasd_reserve_req->cqr; | |
3430 | memset(cqr, 0, sizeof(*cqr)); | |
3431 | memset(&dasd_reserve_req->ccw, 0, | |
3432 | sizeof(dasd_reserve_req->ccw)); | |
3433 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
3434 | cqr->data = &dasd_reserve_req->data; | |
3435 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 3436 | } |
f3eb5384 SW |
3437 | ccw = cqr->cpaddr; |
3438 | ccw->cmd_code = DASD_ECKD_CCW_RESERVE; | |
3439 | ccw->flags |= CCW_FLAG_SLI; | |
3440 | ccw->count = 32; | |
3441 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
3442 | cqr->startdev = device; |
3443 | cqr->memdev = device; | |
1da177e4 | 3444 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 3445 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 3446 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 LT |
3447 | cqr->expires = 2 * HZ; |
3448 | cqr->buildclk = get_clock(); | |
3449 | cqr->status = DASD_CQR_FILLED; | |
3450 | ||
3451 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
3452 | if (!rc) |
3453 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 3454 | |
f932bcea SW |
3455 | if (useglobal) |
3456 | mutex_unlock(&dasd_reserve_mutex); | |
3457 | else | |
3458 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
3459 | return rc; |
3460 | } | |
3461 | ||
3462 | /* | |
3463 | * Steal lock ioctl - unconditional reserve device. | |
138c014d | 3464 | * Buils a channel programm to break a device's reservation. |
1da177e4 LT |
3465 | * (unconditional reserve) |
3466 | */ | |
3467 | static int | |
1107ccfb | 3468 | dasd_eckd_steal_lock(struct dasd_device *device) |
1da177e4 | 3469 | { |
1da177e4 LT |
3470 | struct dasd_ccw_req *cqr; |
3471 | int rc; | |
f3eb5384 | 3472 | struct ccw1 *ccw; |
f932bcea | 3473 | int useglobal; |
1da177e4 LT |
3474 | |
3475 | if (!capable(CAP_SYS_ADMIN)) | |
3476 | return -EACCES; | |
3477 | ||
f932bcea | 3478 | useglobal = 0; |
68b781fe | 3479 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); |
1da177e4 | 3480 | if (IS_ERR(cqr)) { |
f932bcea SW |
3481 | mutex_lock(&dasd_reserve_mutex); |
3482 | useglobal = 1; | |
3483 | cqr = &dasd_reserve_req->cqr; | |
3484 | memset(cqr, 0, sizeof(*cqr)); | |
3485 | memset(&dasd_reserve_req->ccw, 0, | |
3486 | sizeof(dasd_reserve_req->ccw)); | |
3487 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
3488 | cqr->data = &dasd_reserve_req->data; | |
3489 | cqr->magic = DASD_ECKD_MAGIC; | |
1da177e4 | 3490 | } |
f3eb5384 SW |
3491 | ccw = cqr->cpaddr; |
3492 | ccw->cmd_code = DASD_ECKD_CCW_SLCK; | |
3493 | ccw->flags |= CCW_FLAG_SLI; | |
3494 | ccw->count = 32; | |
3495 | ccw->cda = (__u32)(addr_t) cqr->data; | |
8e09f215 SW |
3496 | cqr->startdev = device; |
3497 | cqr->memdev = device; | |
1da177e4 | 3498 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1c01b8a5 | 3499 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
336c340b | 3500 | cqr->retries = 2; /* set retry counter to enable basic ERP */ |
1da177e4 LT |
3501 | cqr->expires = 2 * HZ; |
3502 | cqr->buildclk = get_clock(); | |
3503 | cqr->status = DASD_CQR_FILLED; | |
3504 | ||
3505 | rc = dasd_sleep_on_immediatly(cqr); | |
5a27e60d SW |
3506 | if (!rc) |
3507 | set_bit(DASD_FLAG_IS_RESERVED, &device->flags); | |
1da177e4 | 3508 | |
f932bcea SW |
3509 | if (useglobal) |
3510 | mutex_unlock(&dasd_reserve_mutex); | |
3511 | else | |
3512 | dasd_sfree_request(cqr, cqr->memdev); | |
1da177e4 LT |
3513 | return rc; |
3514 | } | |
3515 | ||
196339f1 SW |
3516 | /* |
3517 | * SNID - Sense Path Group ID | |
3518 | * This ioctl may be used in situations where I/O is stalled due to | |
3519 | * a reserve, so if the normal dasd_smalloc_request fails, we use the | |
3520 | * preallocated dasd_reserve_req. | |
3521 | */ | |
3522 | static int dasd_eckd_snid(struct dasd_device *device, | |
3523 | void __user *argp) | |
3524 | { | |
3525 | struct dasd_ccw_req *cqr; | |
3526 | int rc; | |
3527 | struct ccw1 *ccw; | |
3528 | int useglobal; | |
3529 | struct dasd_snid_ioctl_data usrparm; | |
3530 | ||
3531 | if (!capable(CAP_SYS_ADMIN)) | |
3532 | return -EACCES; | |
3533 | ||
3534 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) | |
3535 | return -EFAULT; | |
3536 | ||
3537 | useglobal = 0; | |
3538 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, | |
3539 | sizeof(struct dasd_snid_data), device); | |
3540 | if (IS_ERR(cqr)) { | |
3541 | mutex_lock(&dasd_reserve_mutex); | |
3542 | useglobal = 1; | |
3543 | cqr = &dasd_reserve_req->cqr; | |
3544 | memset(cqr, 0, sizeof(*cqr)); | |
3545 | memset(&dasd_reserve_req->ccw, 0, | |
3546 | sizeof(dasd_reserve_req->ccw)); | |
3547 | cqr->cpaddr = &dasd_reserve_req->ccw; | |
3548 | cqr->data = &dasd_reserve_req->data; | |
3549 | cqr->magic = DASD_ECKD_MAGIC; | |
3550 | } | |
3551 | ccw = cqr->cpaddr; | |
3552 | ccw->cmd_code = DASD_ECKD_CCW_SNID; | |
3553 | ccw->flags |= CCW_FLAG_SLI; | |
3554 | ccw->count = 12; | |
3555 | ccw->cda = (__u32)(addr_t) cqr->data; | |
3556 | cqr->startdev = device; | |
3557 | cqr->memdev = device; | |
3558 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); | |
3559 | set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); | |
5a27e60d | 3560 | set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); |
196339f1 SW |
3561 | cqr->retries = 5; |
3562 | cqr->expires = 10 * HZ; | |
3563 | cqr->buildclk = get_clock(); | |
3564 | cqr->status = DASD_CQR_FILLED; | |
3565 | cqr->lpm = usrparm.path_mask; | |
3566 | ||
3567 | rc = dasd_sleep_on_immediatly(cqr); | |
3568 | /* verify that I/O processing didn't modify the path mask */ | |
3569 | if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask)) | |
3570 | rc = -EIO; | |
3571 | if (!rc) { | |
3572 | usrparm.data = *((struct dasd_snid_data *)cqr->data); | |
3573 | if (copy_to_user(argp, &usrparm, sizeof(usrparm))) | |
3574 | rc = -EFAULT; | |
3575 | } | |
3576 | ||
3577 | if (useglobal) | |
3578 | mutex_unlock(&dasd_reserve_mutex); | |
3579 | else | |
3580 | dasd_sfree_request(cqr, cqr->memdev); | |
3581 | return rc; | |
3582 | } | |
3583 | ||
1da177e4 LT |
3584 | /* |
3585 | * Read performance statistics | |
3586 | */ | |
3587 | static int | |
1107ccfb | 3588 | dasd_eckd_performance(struct dasd_device *device, void __user *argp) |
1da177e4 | 3589 | { |
1da177e4 LT |
3590 | struct dasd_psf_prssd_data *prssdp; |
3591 | struct dasd_rssd_perf_stats_t *stats; | |
3592 | struct dasd_ccw_req *cqr; | |
3593 | struct ccw1 *ccw; | |
3594 | int rc; | |
3595 | ||
68b781fe | 3596 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
8e09f215 SW |
3597 | (sizeof(struct dasd_psf_prssd_data) + |
3598 | sizeof(struct dasd_rssd_perf_stats_t)), | |
1da177e4 LT |
3599 | device); |
3600 | if (IS_ERR(cqr)) { | |
fc19f381 | 3601 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 LT |
3602 | "Could not allocate initialization request"); |
3603 | return PTR_ERR(cqr); | |
3604 | } | |
8e09f215 SW |
3605 | cqr->startdev = device; |
3606 | cqr->memdev = device; | |
1da177e4 | 3607 | cqr->retries = 0; |
eb6e199b | 3608 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
1da177e4 LT |
3609 | cqr->expires = 10 * HZ; |
3610 | ||
3611 | /* Prepare for Read Subsystem Data */ | |
3612 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; | |
8e09f215 | 3613 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
1da177e4 | 3614 | prssdp->order = PSF_ORDER_PRSSD; |
5d67d164 | 3615 | prssdp->suborder = 0x01; /* Performance Statistics */ |
1da177e4 LT |
3616 | prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ |
3617 | ||
3618 | ccw = cqr->cpaddr; | |
3619 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
8e09f215 | 3620 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
1da177e4 LT |
3621 | ccw->flags |= CCW_FLAG_CC; |
3622 | ccw->cda = (__u32)(addr_t) prssdp; | |
3623 | ||
3624 | /* Read Subsystem Data - Performance Statistics */ | |
3625 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); | |
8e09f215 | 3626 | memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); |
1da177e4 LT |
3627 | |
3628 | ccw++; | |
3629 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
8e09f215 | 3630 | ccw->count = sizeof(struct dasd_rssd_perf_stats_t); |
1da177e4 LT |
3631 | ccw->cda = (__u32)(addr_t) stats; |
3632 | ||
3633 | cqr->buildclk = get_clock(); | |
3634 | cqr->status = DASD_CQR_FILLED; | |
3635 | rc = dasd_sleep_on(cqr); | |
3636 | if (rc == 0) { | |
1da177e4 LT |
3637 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
3638 | stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); | |
1107ccfb CH |
3639 | if (copy_to_user(argp, stats, |
3640 | sizeof(struct dasd_rssd_perf_stats_t))) | |
3641 | rc = -EFAULT; | |
1da177e4 | 3642 | } |
8e09f215 | 3643 | dasd_sfree_request(cqr, cqr->memdev); |
1da177e4 LT |
3644 | return rc; |
3645 | } | |
3646 | ||
3647 | /* | |
3648 | * Get attributes (cache operations) | |
3649 | * Returnes the cache attributes used in Define Extend (DE). | |
3650 | */ | |
3651 | static int | |
1107ccfb | 3652 | dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) |
1da177e4 | 3653 | { |
1107ccfb CH |
3654 | struct dasd_eckd_private *private = |
3655 | (struct dasd_eckd_private *)device->private; | |
3656 | struct attrib_data_t attrib = private->attrib; | |
1da177e4 LT |
3657 | int rc; |
3658 | ||
3659 | if (!capable(CAP_SYS_ADMIN)) | |
3660 | return -EACCES; | |
1107ccfb | 3661 | if (!argp) |
1da177e4 LT |
3662 | return -EINVAL; |
3663 | ||
1107ccfb CH |
3664 | rc = 0; |
3665 | if (copy_to_user(argp, (long *) &attrib, | |
8e09f215 | 3666 | sizeof(struct attrib_data_t))) |
1107ccfb | 3667 | rc = -EFAULT; |
1da177e4 LT |
3668 | |
3669 | return rc; | |
3670 | } | |
3671 | ||
3672 | /* | |
3673 | * Set attributes (cache operations) | |
3674 | * Stores the attributes for cache operation to be used in Define Extend (DE). | |
3675 | */ | |
3676 | static int | |
1107ccfb | 3677 | dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) |
1da177e4 | 3678 | { |
1107ccfb CH |
3679 | struct dasd_eckd_private *private = |
3680 | (struct dasd_eckd_private *)device->private; | |
1da177e4 LT |
3681 | struct attrib_data_t attrib; |
3682 | ||
3683 | if (!capable(CAP_SYS_ADMIN)) | |
3684 | return -EACCES; | |
1107ccfb | 3685 | if (!argp) |
1da177e4 LT |
3686 | return -EINVAL; |
3687 | ||
1107ccfb | 3688 | if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) |
1da177e4 | 3689 | return -EFAULT; |
1da177e4 LT |
3690 | private->attrib = attrib; |
3691 | ||
fc19f381 SH |
3692 | dev_info(&device->cdev->dev, |
3693 | "The DASD cache mode was set to %x (%i cylinder prestage)\n", | |
3694 | private->attrib.operation, private->attrib.nr_cyl); | |
1da177e4 LT |
3695 | return 0; |
3696 | } | |
3697 | ||
ab1d848f NH |
3698 | /* |
3699 | * Issue syscall I/O to EMC Symmetrix array. | |
3700 | * CCWs are PSF and RSSD | |
3701 | */ | |
3702 | static int dasd_symm_io(struct dasd_device *device, void __user *argp) | |
3703 | { | |
3704 | struct dasd_symmio_parms usrparm; | |
3705 | char *psf_data, *rssd_result; | |
3706 | struct dasd_ccw_req *cqr; | |
3707 | struct ccw1 *ccw; | |
52898025 | 3708 | char psf0, psf1; |
ab1d848f NH |
3709 | int rc; |
3710 | ||
52898025 NH |
3711 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) |
3712 | return -EACCES; | |
3713 | psf0 = psf1 = 0; | |
3714 | ||
ab1d848f NH |
3715 | /* Copy parms from caller */ |
3716 | rc = -EFAULT; | |
3717 | if (copy_from_user(&usrparm, argp, sizeof(usrparm))) | |
3718 | goto out; | |
f8b06859 HC |
3719 | if (is_compat_task() || sizeof(long) == 4) { |
3720 | /* Make sure pointers are sane even on 31 bit. */ | |
ab1d848f | 3721 | rc = -EINVAL; |
f8b06859 HC |
3722 | if ((usrparm.psf_data >> 32) != 0) |
3723 | goto out; | |
3724 | if ((usrparm.rssd_result >> 32) != 0) | |
3725 | goto out; | |
3726 | usrparm.psf_data &= 0x7fffffffULL; | |
3727 | usrparm.rssd_result &= 0x7fffffffULL; | |
ab1d848f | 3728 | } |
ab1d848f NH |
3729 | /* alloc I/O data area */ |
3730 | psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); | |
3731 | rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); | |
3732 | if (!psf_data || !rssd_result) { | |
3733 | rc = -ENOMEM; | |
3734 | goto out_free; | |
3735 | } | |
3736 | ||
3737 | /* get syscall header from user space */ | |
3738 | rc = -EFAULT; | |
3739 | if (copy_from_user(psf_data, | |
3740 | (void __user *)(unsigned long) usrparm.psf_data, | |
3741 | usrparm.psf_data_len)) | |
3742 | goto out_free; | |
52898025 NH |
3743 | psf0 = psf_data[0]; |
3744 | psf1 = psf_data[1]; | |
ab1d848f NH |
3745 | |
3746 | /* setup CCWs for PSF + RSSD */ | |
68b781fe | 3747 | cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device); |
ab1d848f | 3748 | if (IS_ERR(cqr)) { |
fc19f381 | 3749 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
ab1d848f NH |
3750 | "Could not allocate initialization request"); |
3751 | rc = PTR_ERR(cqr); | |
3752 | goto out_free; | |
3753 | } | |
3754 | ||
3755 | cqr->startdev = device; | |
3756 | cqr->memdev = device; | |
3757 | cqr->retries = 3; | |
3758 | cqr->expires = 10 * HZ; | |
3759 | cqr->buildclk = get_clock(); | |
3760 | cqr->status = DASD_CQR_FILLED; | |
3761 | ||
3762 | /* Build the ccws */ | |
3763 | ccw = cqr->cpaddr; | |
3764 | ||
3765 | /* PSF ccw */ | |
3766 | ccw->cmd_code = DASD_ECKD_CCW_PSF; | |
3767 | ccw->count = usrparm.psf_data_len; | |
3768 | ccw->flags |= CCW_FLAG_CC; | |
3769 | ccw->cda = (__u32)(addr_t) psf_data; | |
3770 | ||
3771 | ccw++; | |
3772 | ||
3773 | /* RSSD ccw */ | |
3774 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; | |
3775 | ccw->count = usrparm.rssd_result_len; | |
3776 | ccw->flags = CCW_FLAG_SLI ; | |
3777 | ccw->cda = (__u32)(addr_t) rssd_result; | |
3778 | ||
3779 | rc = dasd_sleep_on(cqr); | |
3780 | if (rc) | |
3781 | goto out_sfree; | |
3782 | ||
3783 | rc = -EFAULT; | |
3784 | if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, | |
3785 | rssd_result, usrparm.rssd_result_len)) | |
3786 | goto out_sfree; | |
3787 | rc = 0; | |
3788 | ||
3789 | out_sfree: | |
3790 | dasd_sfree_request(cqr, cqr->memdev); | |
3791 | out_free: | |
3792 | kfree(rssd_result); | |
3793 | kfree(psf_data); | |
3794 | out: | |
52898025 NH |
3795 | DBF_DEV_EVENT(DBF_WARNING, device, |
3796 | "Symmetrix ioctl (0x%02x 0x%02x): rc=%d", | |
3797 | (int) psf0, (int) psf1, rc); | |
ab1d848f NH |
3798 | return rc; |
3799 | } | |
3800 | ||
1107ccfb | 3801 | static int |
8e09f215 | 3802 | dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp) |
1107ccfb | 3803 | { |
8e09f215 SW |
3804 | struct dasd_device *device = block->base; |
3805 | ||
1107ccfb CH |
3806 | switch (cmd) { |
3807 | case BIODASDGATTR: | |
3808 | return dasd_eckd_get_attrib(device, argp); | |
3809 | case BIODASDSATTR: | |
3810 | return dasd_eckd_set_attrib(device, argp); | |
3811 | case BIODASDPSRD: | |
3812 | return dasd_eckd_performance(device, argp); | |
3813 | case BIODASDRLSE: | |
3814 | return dasd_eckd_release(device); | |
3815 | case BIODASDRSRV: | |
3816 | return dasd_eckd_reserve(device); | |
3817 | case BIODASDSLCK: | |
3818 | return dasd_eckd_steal_lock(device); | |
196339f1 SW |
3819 | case BIODASDSNID: |
3820 | return dasd_eckd_snid(device, argp); | |
ab1d848f NH |
3821 | case BIODASDSYMMIO: |
3822 | return dasd_symm_io(device, argp); | |
1107ccfb | 3823 | default: |
6b79d14e | 3824 | return -ENOTTY; |
1107ccfb CH |
3825 | } |
3826 | } | |
3827 | ||
445b5b49 HH |
3828 | /* |
3829 | * Dump the range of CCWs into 'page' buffer | |
3830 | * and return number of printed chars. | |
3831 | */ | |
4d284cac | 3832 | static int |
445b5b49 HH |
3833 | dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) |
3834 | { | |
3835 | int len, count; | |
3836 | char *datap; | |
3837 | ||
3838 | len = 0; | |
3839 | while (from <= to) { | |
3840 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
3841 | " CCW %p: %08X %08X DAT:", | |
3842 | from, ((int *) from)[0], ((int *) from)[1]); | |
3843 | ||
3844 | /* get pointer to data (consider IDALs) */ | |
3845 | if (from->flags & CCW_FLAG_IDA) | |
3846 | datap = (char *) *((addr_t *) (addr_t) from->cda); | |
3847 | else | |
3848 | datap = (char *) ((addr_t) from->cda); | |
3849 | ||
3850 | /* dump data (max 32 bytes) */ | |
3851 | for (count = 0; count < from->count && count < 32; count++) { | |
3852 | if (count % 8 == 0) len += sprintf(page + len, " "); | |
3853 | if (count % 4 == 0) len += sprintf(page + len, " "); | |
3854 | len += sprintf(page + len, "%02x", datap[count]); | |
3855 | } | |
3856 | len += sprintf(page + len, "\n"); | |
3857 | from++; | |
3858 | } | |
3859 | return len; | |
3860 | } | |
3861 | ||
fc19f381 | 3862 | static void |
aeec92ca SH |
3863 | dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, |
3864 | char *reason) | |
fc19f381 SH |
3865 | { |
3866 | u64 *sense; | |
a5a0061f | 3867 | u64 *stat; |
aeec92ca SH |
3868 | |
3869 | sense = (u64 *) dasd_get_sense(irb); | |
a5a0061f | 3870 | stat = (u64 *) &irb->scsw; |
fc19f381 | 3871 | if (sense) { |
a5a0061f SW |
3872 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : " |
3873 | "%016llx %016llx %016llx %016llx", | |
3874 | reason, *stat, *((u32 *) (stat + 1)), | |
ed3640b2 | 3875 | sense[0], sense[1], sense[2], sense[3]); |
fc19f381 | 3876 | } else { |
a5a0061f SW |
3877 | DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s", |
3878 | reason, *stat, *((u32 *) (stat + 1)), | |
3879 | "NO VALID SENSE"); | |
fc19f381 SH |
3880 | } |
3881 | } | |
3882 | ||
1da177e4 LT |
3883 | /* |
3884 | * Print sense data and related channel program. | |
3885 | * Parts are printed because printk buffer is only 1024 bytes. | |
3886 | */ | |
f3eb5384 | 3887 | static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, |
8e09f215 | 3888 | struct dasd_ccw_req *req, struct irb *irb) |
1da177e4 LT |
3889 | { |
3890 | char *page; | |
445b5b49 HH |
3891 | struct ccw1 *first, *last, *fail, *from, *to; |
3892 | int len, sl, sct; | |
1da177e4 LT |
3893 | |
3894 | page = (char *) get_zeroed_page(GFP_ATOMIC); | |
3895 | if (page == NULL) { | |
fc19f381 SH |
3896 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
3897 | "No memory to dump sense data\n"); | |
1da177e4 LT |
3898 | return; |
3899 | } | |
445b5b49 HH |
3900 | /* dump the sense data */ |
3901 | len = sprintf(page, KERN_ERR PRINTK_HEADER | |
1da177e4 | 3902 | " I/O status report for device %s:\n", |
2a0217d5 | 3903 | dev_name(&device->cdev->dev)); |
1da177e4 | 3904 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
a5a0061f SW |
3905 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
3906 | "CS:%02X RC:%d\n", | |
3907 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), | |
3908 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), | |
3909 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), | |
3910 | req ? req->intrc : 0); | |
1da177e4 LT |
3911 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
3912 | " device %s: Failing CCW: %p\n", | |
2a0217d5 | 3913 | dev_name(&device->cdev->dev), |
23d805b6 | 3914 | (void *) (addr_t) irb->scsw.cmd.cpa); |
1da177e4 LT |
3915 | if (irb->esw.esw0.erw.cons) { |
3916 | for (sl = 0; sl < 4; sl++) { | |
3917 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
3918 | " Sense(hex) %2d-%2d:", | |
3919 | (8 * sl), ((8 * sl) + 7)); | |
3920 | ||
3921 | for (sct = 0; sct < 8; sct++) { | |
3922 | len += sprintf(page + len, " %02x", | |
3923 | irb->ecw[8 * sl + sct]); | |
3924 | } | |
3925 | len += sprintf(page + len, "\n"); | |
3926 | } | |
3927 | ||
3928 | if (irb->ecw[27] & DASD_SENSE_BIT_0) { | |
3929 | /* 24 Byte Sense Data */ | |
445b5b49 HH |
3930 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
3931 | " 24 Byte: %x MSG %x, " | |
3932 | "%s MSGb to SYSOP\n", | |
3933 | irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, | |
3934 | irb->ecw[1] & 0x10 ? "" : "no"); | |
1da177e4 LT |
3935 | } else { |
3936 | /* 32 Byte Sense Data */ | |
445b5b49 HH |
3937 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
3938 | " 32 Byte: Format: %x " | |
3939 | "Exception class %x\n", | |
3940 | irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); | |
1da177e4 LT |
3941 | } |
3942 | } else { | |
445b5b49 HH |
3943 | sprintf(page + len, KERN_ERR PRINTK_HEADER |
3944 | " SORRY - NO VALID SENSE AVAILABLE\n"); | |
1da177e4 | 3945 | } |
445b5b49 HH |
3946 | printk("%s", page); |
3947 | ||
8e09f215 SW |
3948 | if (req) { |
3949 | /* req == NULL for unsolicited interrupts */ | |
3950 | /* dump the Channel Program (max 140 Bytes per line) */ | |
3951 | /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ | |
3952 | first = req->cpaddr; | |
3953 | for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); | |
3954 | to = min(first + 6, last); | |
3955 | len = sprintf(page, KERN_ERR PRINTK_HEADER | |
3956 | " Related CP in req: %p\n", req); | |
3957 | dasd_eckd_dump_ccw_range(first, to, page + len); | |
3958 | printk("%s", page); | |
1da177e4 | 3959 | |
8e09f215 SW |
3960 | /* print failing CCW area (maximum 4) */ |
3961 | /* scsw->cda is either valid or zero */ | |
3962 | len = 0; | |
3963 | from = ++to; | |
23d805b6 PO |
3964 | fail = (struct ccw1 *)(addr_t) |
3965 | irb->scsw.cmd.cpa; /* failing CCW */ | |
8e09f215 SW |
3966 | if (from < fail - 2) { |
3967 | from = fail - 2; /* there is a gap - print header */ | |
3968 | len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n"); | |
3969 | } | |
3970 | to = min(fail + 1, last); | |
3971 | len += dasd_eckd_dump_ccw_range(from, to, page + len); | |
3972 | ||
3973 | /* print last CCWs (maximum 2) */ | |
3974 | from = max(from, ++to); | |
3975 | if (from < last - 1) { | |
3976 | from = last - 1; /* there is a gap - print header */ | |
3977 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n"); | |
3978 | } | |
3979 | len += dasd_eckd_dump_ccw_range(from, last, page + len); | |
3980 | if (len > 0) | |
3981 | printk("%s", page); | |
1da177e4 | 3982 | } |
1da177e4 LT |
3983 | free_page((unsigned long) page); |
3984 | } | |
3985 | ||
f3eb5384 SW |
3986 | |
3987 | /* | |
3988 | * Print sense data from a tcw. | |
3989 | */ | |
3990 | static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, | |
3991 | struct dasd_ccw_req *req, struct irb *irb) | |
3992 | { | |
3993 | char *page; | |
3994 | int len, sl, sct, residual; | |
f3eb5384 | 3995 | struct tsb *tsb; |
ef19298b | 3996 | u8 *sense, *rcq; |
f3eb5384 SW |
3997 | |
3998 | page = (char *) get_zeroed_page(GFP_ATOMIC); | |
3999 | if (page == NULL) { | |
fc19f381 | 4000 | DBF_DEV_EVENT(DBF_WARNING, device, " %s", |
f3eb5384 SW |
4001 | "No memory to dump sense data"); |
4002 | return; | |
4003 | } | |
4004 | /* dump the sense data */ | |
4005 | len = sprintf(page, KERN_ERR PRINTK_HEADER | |
4006 | " I/O status report for device %s:\n", | |
4007 | dev_name(&device->cdev->dev)); | |
4008 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
a5a0061f SW |
4009 | " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " |
4010 | "CS:%02X fcxs:%02X schxs:%02X RC:%d\n", | |
4011 | req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), | |
4012 | scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), | |
4013 | scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), | |
4014 | irb->scsw.tm.fcxs, irb->scsw.tm.schxs, | |
4015 | req ? req->intrc : 0); | |
f3eb5384 SW |
4016 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
4017 | " device %s: Failing TCW: %p\n", | |
4018 | dev_name(&device->cdev->dev), | |
4019 | (void *) (addr_t) irb->scsw.tm.tcw); | |
4020 | ||
4021 | tsb = NULL; | |
4022 | sense = NULL; | |
a5a0061f | 4023 | if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01)) |
f3eb5384 SW |
4024 | tsb = tcw_get_tsb( |
4025 | (struct tcw *)(unsigned long)irb->scsw.tm.tcw); | |
4026 | ||
b8fde722 | 4027 | if (tsb) { |
f3eb5384 SW |
4028 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER |
4029 | " tsb->length %d\n", tsb->length); | |
4030 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4031 | " tsb->flags %x\n", tsb->flags); | |
4032 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4033 | " tsb->dcw_offset %d\n", tsb->dcw_offset); | |
4034 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4035 | " tsb->count %d\n", tsb->count); | |
4036 | residual = tsb->count - 28; | |
4037 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4038 | " residual %d\n", residual); | |
4039 | ||
4040 | switch (tsb->flags & 0x07) { | |
4041 | case 1: /* tsa_iostat */ | |
4042 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4043 | " tsb->tsa.iostat.dev_time %d\n", | |
4044 | tsb->tsa.iostat.dev_time); | |
4045 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4046 | " tsb->tsa.iostat.def_time %d\n", | |
4047 | tsb->tsa.iostat.def_time); | |
4048 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4049 | " tsb->tsa.iostat.queue_time %d\n", | |
4050 | tsb->tsa.iostat.queue_time); | |
4051 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4052 | " tsb->tsa.iostat.dev_busy_time %d\n", | |
4053 | tsb->tsa.iostat.dev_busy_time); | |
4054 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4055 | " tsb->tsa.iostat.dev_act_time %d\n", | |
4056 | tsb->tsa.iostat.dev_act_time); | |
4057 | sense = tsb->tsa.iostat.sense; | |
4058 | break; | |
4059 | case 2: /* ts_ddpc */ | |
4060 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4061 | " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); | |
ef19298b SW |
4062 | for (sl = 0; sl < 2; sl++) { |
4063 | len += sprintf(page + len, | |
4064 | KERN_ERR PRINTK_HEADER | |
4065 | " tsb->tsa.ddpc.rcq %2d-%2d: ", | |
4066 | (8 * sl), ((8 * sl) + 7)); | |
4067 | rcq = tsb->tsa.ddpc.rcq; | |
f3eb5384 SW |
4068 | for (sct = 0; sct < 8; sct++) { |
4069 | len += sprintf(page + len, " %02x", | |
ef19298b | 4070 | rcq[8 * sl + sct]); |
f3eb5384 SW |
4071 | } |
4072 | len += sprintf(page + len, "\n"); | |
4073 | } | |
4074 | sense = tsb->tsa.ddpc.sense; | |
4075 | break; | |
4076 | case 3: /* tsa_intrg */ | |
4077 | len += sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4078 | " tsb->tsa.intrg.: not supportet yet \n"); | |
4079 | break; | |
4080 | } | |
4081 | ||
4082 | if (sense) { | |
4083 | for (sl = 0; sl < 4; sl++) { | |
4084 | len += sprintf(page + len, | |
4085 | KERN_ERR PRINTK_HEADER | |
4086 | " Sense(hex) %2d-%2d:", | |
4087 | (8 * sl), ((8 * sl) + 7)); | |
4088 | for (sct = 0; sct < 8; sct++) { | |
4089 | len += sprintf(page + len, " %02x", | |
4090 | sense[8 * sl + sct]); | |
4091 | } | |
4092 | len += sprintf(page + len, "\n"); | |
4093 | } | |
4094 | ||
4095 | if (sense[27] & DASD_SENSE_BIT_0) { | |
4096 | /* 24 Byte Sense Data */ | |
4097 | sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4098 | " 24 Byte: %x MSG %x, " | |
4099 | "%s MSGb to SYSOP\n", | |
4100 | sense[7] >> 4, sense[7] & 0x0f, | |
4101 | sense[1] & 0x10 ? "" : "no"); | |
4102 | } else { | |
4103 | /* 32 Byte Sense Data */ | |
4104 | sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4105 | " 32 Byte: Format: %x " | |
4106 | "Exception class %x\n", | |
4107 | sense[6] & 0x0f, sense[22] >> 4); | |
4108 | } | |
4109 | } else { | |
4110 | sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4111 | " SORRY - NO VALID SENSE AVAILABLE\n"); | |
4112 | } | |
4113 | } else { | |
4114 | sprintf(page + len, KERN_ERR PRINTK_HEADER | |
4115 | " SORRY - NO TSB DATA AVAILABLE\n"); | |
4116 | } | |
4117 | printk("%s", page); | |
4118 | free_page((unsigned long) page); | |
4119 | } | |
4120 | ||
4121 | static void dasd_eckd_dump_sense(struct dasd_device *device, | |
4122 | struct dasd_ccw_req *req, struct irb *irb) | |
4123 | { | |
a5a0061f | 4124 | if (scsw_is_tm(&irb->scsw)) |
f3eb5384 SW |
4125 | dasd_eckd_dump_sense_tcw(device, req, irb); |
4126 | else | |
4127 | dasd_eckd_dump_sense_ccw(device, req, irb); | |
4128 | } | |
4129 | ||
501183f2 | 4130 | static int dasd_eckd_pm_freeze(struct dasd_device *device) |
d41dd122 SH |
4131 | { |
4132 | /* | |
4133 | * the device should be disconnected from our LCU structure | |
4134 | * on restore we will reconnect it and reread LCU specific | |
4135 | * information like PAV support that might have changed | |
4136 | */ | |
4137 | dasd_alias_remove_device(device); | |
4138 | dasd_alias_disconnect_device_from_lcu(device); | |
4139 | ||
4140 | return 0; | |
4141 | } | |
4142 | ||
501183f2 | 4143 | static int dasd_eckd_restore_device(struct dasd_device *device) |
d41dd122 SH |
4144 | { |
4145 | struct dasd_eckd_private *private; | |
6fca97a9 | 4146 | struct dasd_eckd_characteristics temp_rdc_data; |
f9f8d02f | 4147 | int rc; |
d41dd122 | 4148 | struct dasd_uid temp_uid; |
a7602f6c | 4149 | unsigned long flags; |
d41dd122 | 4150 | |
d41dd122 SH |
4151 | private = (struct dasd_eckd_private *) device->private; |
4152 | ||
4153 | /* Read Configuration Data */ | |
4154 | rc = dasd_eckd_read_conf(device); | |
4155 | if (rc) | |
4156 | goto out_err; | |
4157 | ||
2dedf0d9 SH |
4158 | dasd_eckd_get_uid(device, &temp_uid); |
4159 | /* Generate device unique id */ | |
4160 | rc = dasd_eckd_generate_uid(device); | |
4161 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
d41dd122 | 4162 | if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) |
a7602f6c SH |
4163 | dev_err(&device->cdev->dev, "The UID of the DASD has " |
4164 | "changed\n"); | |
2dedf0d9 | 4165 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
d41dd122 SH |
4166 | if (rc) |
4167 | goto out_err; | |
d41dd122 SH |
4168 | |
4169 | /* register lcu with alias handling, enable PAV if this is a new lcu */ | |
f9f8d02f SH |
4170 | rc = dasd_alias_make_device_known_to_lcu(device); |
4171 | if (rc) | |
4172 | return rc; | |
12d7b107 | 4173 | dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST); |
f4ac1d02 SW |
4174 | |
4175 | /* RE-Read Configuration Data */ | |
4176 | rc = dasd_eckd_read_conf(device); | |
4177 | if (rc) | |
4178 | goto out_err; | |
d41dd122 SH |
4179 | |
4180 | /* Read Feature Codes */ | |
68d1e5f0 | 4181 | dasd_eckd_read_features(device); |
d41dd122 SH |
4182 | |
4183 | /* Read Device Characteristics */ | |
68b781fe | 4184 | rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, |
6fca97a9 | 4185 | &temp_rdc_data, 64); |
d41dd122 | 4186 | if (rc) { |
b8ed5dd5 SH |
4187 | DBF_EVENT_DEVID(DBF_WARNING, device->cdev, |
4188 | "Read device characteristic failed, rc=%d", rc); | |
d41dd122 SH |
4189 | goto out_err; |
4190 | } | |
a7602f6c | 4191 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
6fca97a9 | 4192 | memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data)); |
a7602f6c | 4193 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
d41dd122 SH |
4194 | |
4195 | /* add device to alias management */ | |
4196 | dasd_alias_add_device(device); | |
4197 | ||
4198 | return 0; | |
4199 | ||
4200 | out_err: | |
e6125fba | 4201 | return -1; |
d41dd122 SH |
4202 | } |
4203 | ||
501183f2 SH |
4204 | static int dasd_eckd_reload_device(struct dasd_device *device) |
4205 | { | |
4206 | struct dasd_eckd_private *private; | |
4207 | int rc, old_base; | |
2dedf0d9 SH |
4208 | char print_uid[60]; |
4209 | struct dasd_uid uid; | |
4210 | unsigned long flags; | |
501183f2 SH |
4211 | |
4212 | private = (struct dasd_eckd_private *) device->private; | |
2dedf0d9 SH |
4213 | |
4214 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
501183f2 | 4215 | old_base = private->uid.base_unit_addr; |
2dedf0d9 SH |
4216 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
4217 | ||
501183f2 SH |
4218 | /* Read Configuration Data */ |
4219 | rc = dasd_eckd_read_conf(device); | |
4220 | if (rc) | |
4221 | goto out_err; | |
4222 | ||
2dedf0d9 | 4223 | rc = dasd_eckd_generate_uid(device); |
501183f2 SH |
4224 | if (rc) |
4225 | goto out_err; | |
501183f2 SH |
4226 | /* |
4227 | * update unit address configuration and | |
4228 | * add device to alias management | |
4229 | */ | |
4230 | dasd_alias_update_add_device(device); | |
4231 | ||
2dedf0d9 SH |
4232 | dasd_eckd_get_uid(device, &uid); |
4233 | ||
4234 | if (old_base != uid.base_unit_addr) { | |
4235 | if (strlen(uid.vduit) > 0) | |
4236 | snprintf(print_uid, sizeof(print_uid), | |
4237 | "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial, | |
4238 | uid.ssid, uid.base_unit_addr, uid.vduit); | |
501183f2 | 4239 | else |
2dedf0d9 SH |
4240 | snprintf(print_uid, sizeof(print_uid), |
4241 | "%s.%s.%04x.%02x", uid.vendor, uid.serial, | |
4242 | uid.ssid, uid.base_unit_addr); | |
501183f2 SH |
4243 | |
4244 | dev_info(&device->cdev->dev, | |
4245 | "An Alias device was reassigned to a new base device " | |
2dedf0d9 | 4246 | "with UID: %s\n", print_uid); |
501183f2 SH |
4247 | } |
4248 | return 0; | |
4249 | ||
4250 | out_err: | |
4251 | return -1; | |
4252 | } | |
4253 | ||
d41dd122 | 4254 | static struct ccw_driver dasd_eckd_driver = { |
3bda058b SO |
4255 | .driver = { |
4256 | .name = "dasd-eckd", | |
4257 | .owner = THIS_MODULE, | |
4258 | }, | |
d41dd122 SH |
4259 | .ids = dasd_eckd_ids, |
4260 | .probe = dasd_eckd_probe, | |
4261 | .remove = dasd_generic_remove, | |
4262 | .set_offline = dasd_generic_set_offline, | |
4263 | .set_online = dasd_eckd_set_online, | |
4264 | .notify = dasd_generic_notify, | |
a4d26c6a | 4265 | .path_event = dasd_generic_path_event, |
4679e893 | 4266 | .shutdown = dasd_generic_shutdown, |
d41dd122 SH |
4267 | .freeze = dasd_generic_pm_freeze, |
4268 | .thaw = dasd_generic_restore_device, | |
4269 | .restore = dasd_generic_restore_device, | |
a23ed009 | 4270 | .uc_handler = dasd_generic_uc_handler, |
de400d6b | 4271 | .int_class = IOINT_DAS, |
d41dd122 | 4272 | }; |
f3eb5384 | 4273 | |
1da177e4 LT |
4274 | /* |
4275 | * max_blocks is dependent on the amount of storage that is available | |
4276 | * in the static io buffer for each device. Currently each device has | |
4277 | * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has | |
4278 | * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use | |
4279 | * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In | |
4280 | * addition we have one define extent ccw + 16 bytes of data and one | |
4281 | * locate record ccw + 16 bytes of data. That makes: | |
4282 | * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. | |
4283 | * We want to fit two into the available memory so that we can immediately | |
4284 | * start the next request if one finishes off. That makes 249.5 blocks | |
4285 | * for one request. Give a little safety and the result is 240. | |
4286 | */ | |
4287 | static struct dasd_discipline dasd_eckd_discipline = { | |
4288 | .owner = THIS_MODULE, | |
4289 | .name = "ECKD", | |
4290 | .ebcname = "ECKD", | |
ef19298b | 4291 | .max_blocks = 190, |
1da177e4 | 4292 | .check_device = dasd_eckd_check_characteristics, |
8e09f215 | 4293 | .uncheck_device = dasd_eckd_uncheck_device, |
1da177e4 | 4294 | .do_analysis = dasd_eckd_do_analysis, |
a4d26c6a | 4295 | .verify_path = dasd_eckd_verify_path, |
8e09f215 SW |
4296 | .ready_to_online = dasd_eckd_ready_to_online, |
4297 | .online_to_ready = dasd_eckd_online_to_ready, | |
1da177e4 LT |
4298 | .fill_geometry = dasd_eckd_fill_geometry, |
4299 | .start_IO = dasd_start_IO, | |
4300 | .term_IO = dasd_term_IO, | |
8e09f215 | 4301 | .handle_terminated_request = dasd_eckd_handle_terminated_request, |
1da177e4 | 4302 | .format_device = dasd_eckd_format_device, |
1da177e4 LT |
4303 | .erp_action = dasd_eckd_erp_action, |
4304 | .erp_postaction = dasd_eckd_erp_postaction, | |
5a27e60d | 4305 | .check_for_device_change = dasd_eckd_check_for_device_change, |
8e09f215 SW |
4306 | .build_cp = dasd_eckd_build_alias_cp, |
4307 | .free_cp = dasd_eckd_free_alias_cp, | |
1da177e4 | 4308 | .dump_sense = dasd_eckd_dump_sense, |
fc19f381 | 4309 | .dump_sense_dbf = dasd_eckd_dump_sense_dbf, |
1da177e4 | 4310 | .fill_info = dasd_eckd_fill_info, |
1107ccfb | 4311 | .ioctl = dasd_eckd_ioctl, |
d41dd122 SH |
4312 | .freeze = dasd_eckd_pm_freeze, |
4313 | .restore = dasd_eckd_restore_device, | |
501183f2 | 4314 | .reload = dasd_eckd_reload_device, |
2dedf0d9 | 4315 | .get_uid = dasd_eckd_get_uid, |
f1633031 | 4316 | .kick_validate = dasd_eckd_kick_validate_server, |
1da177e4 LT |
4317 | }; |
4318 | ||
4319 | static int __init | |
4320 | dasd_eckd_init(void) | |
4321 | { | |
736e6ea0 SO |
4322 | int ret; |
4323 | ||
1da177e4 | 4324 | ASCEBC(dasd_eckd_discipline.ebcname, 4); |
f932bcea SW |
4325 | dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req), |
4326 | GFP_KERNEL | GFP_DMA); | |
4327 | if (!dasd_reserve_req) | |
4328 | return -ENOMEM; | |
a4d26c6a SW |
4329 | path_verification_worker = kmalloc(sizeof(*path_verification_worker), |
4330 | GFP_KERNEL | GFP_DMA); | |
4331 | if (!path_verification_worker) { | |
4332 | kfree(dasd_reserve_req); | |
4333 | return -ENOMEM; | |
4334 | } | |
736e6ea0 SO |
4335 | ret = ccw_driver_register(&dasd_eckd_driver); |
4336 | if (!ret) | |
4337 | wait_for_device_probe(); | |
a4d26c6a SW |
4338 | else { |
4339 | kfree(path_verification_worker); | |
f932bcea | 4340 | kfree(dasd_reserve_req); |
a4d26c6a | 4341 | } |
736e6ea0 | 4342 | return ret; |
1da177e4 LT |
4343 | } |
4344 | ||
4345 | static void __exit | |
4346 | dasd_eckd_cleanup(void) | |
4347 | { | |
4348 | ccw_driver_unregister(&dasd_eckd_driver); | |
a4d26c6a | 4349 | kfree(path_verification_worker); |
f932bcea | 4350 | kfree(dasd_reserve_req); |
1da177e4 LT |
4351 | } |
4352 | ||
4353 | module_init(dasd_eckd_init); | |
4354 | module_exit(dasd_eckd_cleanup); |