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