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