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