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