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