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