Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 | 2 | * S/390 common I/O routines -- channel subsystem call |
1da177e4 | 3 | * |
cbc0dd1f | 4 | * Copyright IBM Corp. 1999,2012 |
1da177e4 | 5 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
4ce3b30c | 6 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
1da177e4 LT |
7 | * Arnd Bergmann (arndb@de.ibm.com) |
8 | */ | |
9 | ||
e6d5a428 ME |
10 | #define KMSG_COMPONENT "cio" |
11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
12 | ||
1da177e4 | 13 | #include <linux/module.h> |
1da177e4 LT |
14 | #include <linux/slab.h> |
15 | #include <linux/init.h> | |
16 | #include <linux/device.h> | |
cbc0dd1f | 17 | #include <linux/pci.h> |
1da177e4 LT |
18 | |
19 | #include <asm/cio.h> | |
e5854a58 | 20 | #include <asm/chpid.h> |
9d92a7e1 | 21 | #include <asm/chsc.h> |
f5daba1d | 22 | #include <asm/crw.h> |
1da177e4 LT |
23 | |
24 | #include "css.h" | |
25 | #include "cio.h" | |
26 | #include "cio_debug.h" | |
27 | #include "ioasm.h" | |
e6b6e10a | 28 | #include "chp.h" |
1da177e4 LT |
29 | #include "chsc.h" |
30 | ||
1da177e4 | 31 | static void *sei_page; |
34196f82 SO |
32 | static void *chsc_page; |
33 | static DEFINE_SPINLOCK(chsc_page_lock); | |
1da177e4 | 34 | |
dae39843 CH |
35 | /** |
36 | * chsc_error_from_response() - convert a chsc response to an error | |
37 | * @response: chsc response code | |
38 | * | |
39 | * Returns an appropriate Linux error code for @response. | |
40 | */ | |
41 | int chsc_error_from_response(int response) | |
b9c9a21a CH |
42 | { |
43 | switch (response) { | |
44 | case 0x0001: | |
45 | return 0; | |
46 | case 0x0002: | |
47 | case 0x0003: | |
48 | case 0x0006: | |
49 | case 0x0007: | |
50 | case 0x0008: | |
51 | case 0x000a: | |
fd0457a6 | 52 | case 0x0104: |
b9c9a21a CH |
53 | return -EINVAL; |
54 | case 0x0004: | |
55 | return -EOPNOTSUPP; | |
184b08af SO |
56 | case 0x000b: |
57 | return -EBUSY; | |
58 | case 0x0100: | |
59 | case 0x0102: | |
60 | return -ENOMEM; | |
b9c9a21a CH |
61 | default: |
62 | return -EIO; | |
63 | } | |
64 | } | |
dae39843 | 65 | EXPORT_SYMBOL_GPL(chsc_error_from_response); |
b9c9a21a | 66 | |
7ad6a249 PO |
67 | struct chsc_ssd_area { |
68 | struct chsc_header request; | |
69 | u16 :10; | |
70 | u16 ssid:2; | |
71 | u16 :4; | |
72 | u16 f_sch; /* first subchannel */ | |
73 | u16 :16; | |
74 | u16 l_sch; /* last subchannel */ | |
75 | u32 :32; | |
76 | struct chsc_header response; | |
77 | u32 :32; | |
78 | u8 sch_valid : 1; | |
79 | u8 dev_valid : 1; | |
80 | u8 st : 3; /* subchannel type */ | |
81 | u8 zeroes : 3; | |
82 | u8 unit_addr; /* unit address */ | |
83 | u16 devno; /* device number */ | |
84 | u8 path_mask; | |
85 | u8 fla_valid_mask; | |
86 | u16 sch; /* subchannel */ | |
87 | u8 chpid[8]; /* chpids 0-7 */ | |
88 | u16 fla[8]; /* full link addresses 0-7 */ | |
89 | } __attribute__ ((packed)); | |
90 | ||
91 | int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd) | |
1da177e4 | 92 | { |
7ad6a249 PO |
93 | struct chsc_ssd_area *ssd_area; |
94 | int ccode; | |
95 | int ret; | |
96 | int i; | |
97 | int mask; | |
1da177e4 | 98 | |
34196f82 SO |
99 | spin_lock_irq(&chsc_page_lock); |
100 | memset(chsc_page, 0, PAGE_SIZE); | |
101 | ssd_area = chsc_page; | |
495a5b45 CH |
102 | ssd_area->request.length = 0x0010; |
103 | ssd_area->request.code = 0x0004; | |
7ad6a249 PO |
104 | ssd_area->ssid = schid.ssid; |
105 | ssd_area->f_sch = schid.sch_no; | |
106 | ssd_area->l_sch = schid.sch_no; | |
1da177e4 LT |
107 | |
108 | ccode = chsc(ssd_area); | |
7ad6a249 | 109 | /* Check response. */ |
1da177e4 | 110 | if (ccode > 0) { |
7ad6a249 | 111 | ret = (ccode == 3) ? -ENODEV : -EBUSY; |
34196f82 | 112 | goto out; |
1da177e4 | 113 | } |
b9c9a21a CH |
114 | ret = chsc_error_from_response(ssd_area->response.code); |
115 | if (ret != 0) { | |
7ad6a249 PO |
116 | CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n", |
117 | schid.ssid, schid.sch_no, | |
1da177e4 | 118 | ssd_area->response.code); |
34196f82 | 119 | goto out; |
1da177e4 | 120 | } |
7ad6a249 PO |
121 | if (!ssd_area->sch_valid) { |
122 | ret = -ENODEV; | |
34196f82 | 123 | goto out; |
1da177e4 | 124 | } |
7ad6a249 PO |
125 | /* Copy data */ |
126 | ret = 0; | |
127 | memset(ssd, 0, sizeof(struct chsc_ssd_info)); | |
b279a4f5 CH |
128 | if ((ssd_area->st != SUBCHANNEL_TYPE_IO) && |
129 | (ssd_area->st != SUBCHANNEL_TYPE_MSG)) | |
34196f82 | 130 | goto out; |
7ad6a249 PO |
131 | ssd->path_mask = ssd_area->path_mask; |
132 | ssd->fla_valid_mask = ssd_area->fla_valid_mask; | |
133 | for (i = 0; i < 8; i++) { | |
134 | mask = 0x80 >> i; | |
135 | if (ssd_area->path_mask & mask) { | |
136 | chp_id_init(&ssd->chpid[i]); | |
137 | ssd->chpid[i].id = ssd_area->chpid[i]; | |
1da177e4 | 138 | } |
7ad6a249 PO |
139 | if (ssd_area->fla_valid_mask & mask) |
140 | ssd->fla[i] = ssd_area->fla[i]; | |
1da177e4 | 141 | } |
34196f82 SO |
142 | out: |
143 | spin_unlock_irq(&chsc_page_lock); | |
1da177e4 LT |
144 | return ret; |
145 | } | |
146 | ||
e82a1567 | 147 | static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data) |
1da177e4 | 148 | { |
2ec22984 | 149 | spin_lock_irq(sch->lock); |
c820de39 CH |
150 | if (sch->driver && sch->driver->chp_event) |
151 | if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0) | |
1da177e4 | 152 | goto out_unreg; |
2ec22984 | 153 | spin_unlock_irq(sch->lock); |
1da177e4 | 154 | return 0; |
387b734f | 155 | |
1da177e4 | 156 | out_unreg: |
1da177e4 | 157 | sch->lpm = 0; |
387b734f | 158 | spin_unlock_irq(sch->lock); |
83b3370c | 159 | css_schedule_eval(sch->schid); |
1da177e4 LT |
160 | return 0; |
161 | } | |
162 | ||
e6b6e10a | 163 | void chsc_chp_offline(struct chp_id chpid) |
1da177e4 LT |
164 | { |
165 | char dbf_txt[15]; | |
99611f87 | 166 | struct chp_link link; |
1da177e4 | 167 | |
f86635fa | 168 | sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id); |
1da177e4 LT |
169 | CIO_TRACE_EVENT(2, dbf_txt); |
170 | ||
e6b6e10a | 171 | if (chp_get_status(chpid) <= 0) |
1da177e4 | 172 | return; |
99611f87 CH |
173 | memset(&link, 0, sizeof(struct chp_link)); |
174 | link.chpid = chpid; | |
22806dc1 CH |
175 | /* Wait until previous actions have settled. */ |
176 | css_wait_for_slow_path(); | |
99611f87 | 177 | for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link); |
1da177e4 LT |
178 | } |
179 | ||
e82a1567 | 180 | static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data) |
f97a56fb CH |
181 | { |
182 | struct schib schib; | |
f97a56fb CH |
183 | /* |
184 | * We don't know the device yet, but since a path | |
185 | * may be available now to the device we'll have | |
186 | * to do recognition again. | |
187 | * Since we don't have any idea about which chpid | |
188 | * that beast may be on we'll have to do a stsch | |
189 | * on all devices, grr... | |
190 | */ | |
fb6958a5 | 191 | if (stsch_err(schid, &schib)) |
f97a56fb | 192 | /* We're through */ |
83b3370c | 193 | return -ENXIO; |
f97a56fb CH |
194 | |
195 | /* Put it on the slow path. */ | |
83b3370c | 196 | css_schedule_eval(schid); |
f97a56fb CH |
197 | return 0; |
198 | } | |
199 | ||
e82a1567 | 200 | static int __s390_process_res_acc(struct subchannel *sch, void *data) |
1da177e4 | 201 | { |
2ec22984 | 202 | spin_lock_irq(sch->lock); |
c820de39 CH |
203 | if (sch->driver && sch->driver->chp_event) |
204 | sch->driver->chp_event(sch, data, CHP_ONLINE); | |
2ec22984 | 205 | spin_unlock_irq(sch->lock); |
e82a1567 | 206 | |
dd9963f9 | 207 | return 0; |
f97a56fb CH |
208 | } |
209 | ||
99611f87 | 210 | static void s390_process_res_acc(struct chp_link *link) |
f97a56fb | 211 | { |
1da177e4 LT |
212 | char dbf_txt[15]; |
213 | ||
99611f87 CH |
214 | sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid, |
215 | link->chpid.id); | |
1da177e4 | 216 | CIO_TRACE_EVENT( 2, dbf_txt); |
99611f87 CH |
217 | if (link->fla != 0) { |
218 | sprintf(dbf_txt, "fla%x", link->fla); | |
1da177e4 LT |
219 | CIO_TRACE_EVENT( 2, dbf_txt); |
220 | } | |
22806dc1 CH |
221 | /* Wait until previous actions have settled. */ |
222 | css_wait_for_slow_path(); | |
1da177e4 LT |
223 | /* |
224 | * I/O resources may have become accessible. | |
225 | * Scan through all subchannels that may be concerned and | |
226 | * do a validation on those. | |
227 | * The more information we have (info), the less scanning | |
228 | * will we have to do. | |
229 | */ | |
e82a1567 | 230 | for_each_subchannel_staged(__s390_process_res_acc, |
99611f87 | 231 | s390_process_res_acc_new_sch, link); |
1da177e4 LT |
232 | } |
233 | ||
234 | static int | |
235 | __get_chpid_from_lir(void *data) | |
236 | { | |
237 | struct lir { | |
238 | u8 iq; | |
239 | u8 ic; | |
240 | u16 sci; | |
241 | /* incident-node descriptor */ | |
242 | u32 indesc[28]; | |
243 | /* attached-node descriptor */ | |
244 | u32 andesc[28]; | |
245 | /* incident-specific information */ | |
246 | u32 isinfo[28]; | |
0f008aa3 | 247 | } __attribute__ ((packed)) *lir; |
1da177e4 | 248 | |
12975aef | 249 | lir = data; |
1da177e4 LT |
250 | if (!(lir->iq&0x80)) |
251 | /* NULL link incident record */ | |
252 | return -EINVAL; | |
253 | if (!(lir->indesc[0]&0xc0000000)) | |
254 | /* node descriptor not valid */ | |
255 | return -EINVAL; | |
256 | if (!(lir->indesc[0]&0x10000000)) | |
257 | /* don't handle device-type nodes - FIXME */ | |
258 | return -EINVAL; | |
259 | /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */ | |
260 | ||
261 | return (u16) (lir->indesc[0]&0x000000ff); | |
262 | } | |
263 | ||
cbc0dd1f JG |
264 | struct chsc_sei_nt0_area { |
265 | u8 flags; | |
266 | u8 vf; /* validity flags */ | |
267 | u8 rs; /* reporting source */ | |
268 | u8 cc; /* content code */ | |
269 | u16 fla; /* full link address */ | |
270 | u16 rsid; /* reporting source id */ | |
184357a5 PO |
271 | u32 reserved1; |
272 | u32 reserved2; | |
184357a5 | 273 | /* ccdf has to be big enough for a link-incident record */ |
cbc0dd1f JG |
274 | u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */ |
275 | } __packed; | |
276 | ||
277 | struct chsc_sei_nt2_area { | |
278 | u8 flags; /* p and v bit */ | |
279 | u8 reserved1; | |
280 | u8 reserved2; | |
281 | u8 cc; /* content code */ | |
282 | u32 reserved3[13]; | |
283 | u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */ | |
284 | } __packed; | |
285 | ||
509d97b6 | 286 | #define CHSC_SEI_NT0 (1ULL << 63) |
cbc0dd1f JG |
287 | #define CHSC_SEI_NT2 (1ULL << 61) |
288 | ||
289 | struct chsc_sei { | |
290 | struct chsc_header request; | |
291 | u32 reserved1; | |
292 | u64 ntsm; /* notification type mask */ | |
293 | struct chsc_header response; | |
509d97b6 SO |
294 | u32 :24; |
295 | u8 nt; | |
cbc0dd1f JG |
296 | union { |
297 | struct chsc_sei_nt0_area nt0_area; | |
298 | struct chsc_sei_nt2_area nt2_area; | |
299 | u8 nt_area[PAGE_SIZE - 24]; | |
300 | } u; | |
301 | } __packed; | |
302 | ||
303 | static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area) | |
184357a5 | 304 | { |
f86635fa PO |
305 | struct chp_id chpid; |
306 | int id; | |
184357a5 PO |
307 | |
308 | CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n", | |
309 | sei_area->rs, sei_area->rsid); | |
310 | if (sei_area->rs != 4) | |
83b3370c | 311 | return; |
f86635fa PO |
312 | id = __get_chpid_from_lir(sei_area->ccdf); |
313 | if (id < 0) | |
184357a5 | 314 | CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n"); |
f86635fa PO |
315 | else { |
316 | chp_id_init(&chpid); | |
317 | chpid.id = id; | |
e6b6e10a | 318 | chsc_chp_offline(chpid); |
f86635fa | 319 | } |
184357a5 PO |
320 | } |
321 | ||
cbc0dd1f | 322 | static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area) |
1da177e4 | 323 | { |
99611f87 | 324 | struct chp_link link; |
f86635fa | 325 | struct chp_id chpid; |
184357a5 | 326 | int status; |
184357a5 PO |
327 | |
328 | CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, " | |
329 | "rs_id=%04x)\n", sei_area->rs, sei_area->rsid); | |
330 | if (sei_area->rs != 4) | |
83b3370c | 331 | return; |
f86635fa PO |
332 | chp_id_init(&chpid); |
333 | chpid.id = sei_area->rsid; | |
184357a5 | 334 | /* allocate a new channel path structure, if needed */ |
e6b6e10a | 335 | status = chp_get_status(chpid); |
184357a5 | 336 | if (status < 0) |
e6b6e10a | 337 | chp_new(chpid); |
184357a5 | 338 | else if (!status) |
83b3370c | 339 | return; |
99611f87 CH |
340 | memset(&link, 0, sizeof(struct chp_link)); |
341 | link.chpid = chpid; | |
184357a5 | 342 | if ((sei_area->vf & 0xc0) != 0) { |
99611f87 | 343 | link.fla = sei_area->fla; |
184357a5 PO |
344 | if ((sei_area->vf & 0xc0) == 0xc0) |
345 | /* full link address */ | |
99611f87 | 346 | link.fla_mask = 0xffff; |
184357a5 PO |
347 | else |
348 | /* link address */ | |
99611f87 | 349 | link.fla_mask = 0xff00; |
184357a5 | 350 | } |
99611f87 | 351 | s390_process_res_acc(&link); |
184357a5 PO |
352 | } |
353 | ||
cbc0dd1f | 354 | static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area) |
fca894ed SO |
355 | { |
356 | struct channel_path *chp; | |
357 | struct chp_id chpid; | |
358 | u8 *data; | |
359 | int num; | |
360 | ||
361 | CIO_CRW_EVENT(4, "chsc: channel path availability information\n"); | |
362 | if (sei_area->rs != 0) | |
363 | return; | |
364 | data = sei_area->ccdf; | |
365 | chp_id_init(&chpid); | |
366 | for (num = 0; num <= __MAX_CHPID; num++) { | |
367 | if (!chp_test_bit(data, num)) | |
368 | continue; | |
369 | chpid.id = num; | |
370 | ||
371 | CIO_CRW_EVENT(4, "Update information for channel path " | |
372 | "%x.%02x\n", chpid.cssid, chpid.id); | |
373 | chp = chpid_to_chp(chpid); | |
374 | if (!chp) { | |
375 | chp_new(chpid); | |
376 | continue; | |
377 | } | |
378 | mutex_lock(&chp->lock); | |
379 | chsc_determine_base_channel_path_desc(chpid, &chp->desc); | |
380 | mutex_unlock(&chp->lock); | |
381 | } | |
382 | } | |
383 | ||
e5854a58 PO |
384 | struct chp_config_data { |
385 | u8 map[32]; | |
386 | u8 op; | |
387 | u8 pc; | |
388 | }; | |
389 | ||
cbc0dd1f | 390 | static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area) |
e5854a58 PO |
391 | { |
392 | struct chp_config_data *data; | |
393 | struct chp_id chpid; | |
394 | int num; | |
e6d5a428 | 395 | char *events[3] = {"configure", "deconfigure", "cancel deconfigure"}; |
e5854a58 PO |
396 | |
397 | CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n"); | |
398 | if (sei_area->rs != 0) | |
83b3370c | 399 | return; |
e5854a58 PO |
400 | data = (struct chp_config_data *) &(sei_area->ccdf); |
401 | chp_id_init(&chpid); | |
402 | for (num = 0; num <= __MAX_CHPID; num++) { | |
403 | if (!chp_test_bit(data->map, num)) | |
404 | continue; | |
405 | chpid.id = num; | |
e6d5a428 ME |
406 | pr_notice("Processing %s for channel path %x.%02x\n", |
407 | events[data->op], chpid.cssid, chpid.id); | |
e5854a58 PO |
408 | switch (data->op) { |
409 | case 0: | |
410 | chp_cfg_schedule(chpid, 1); | |
411 | break; | |
412 | case 1: | |
413 | chp_cfg_schedule(chpid, 0); | |
414 | break; | |
415 | case 2: | |
416 | chp_cfg_cancel_deconfigure(chpid); | |
417 | break; | |
418 | } | |
419 | } | |
e5854a58 PO |
420 | } |
421 | ||
cbc0dd1f | 422 | static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area) |
40ff4cc0 SO |
423 | { |
424 | int ret; | |
425 | ||
426 | CIO_CRW_EVENT(4, "chsc: scm change notification\n"); | |
427 | if (sei_area->rs != 7) | |
428 | return; | |
429 | ||
430 | ret = scm_update_information(); | |
431 | if (ret) | |
432 | CIO_CRW_EVENT(0, "chsc: updating change notification" | |
433 | " failed (rc=%d).\n", ret); | |
434 | } | |
435 | ||
aebfa669 SO |
436 | static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area) |
437 | { | |
438 | int ret; | |
439 | ||
440 | CIO_CRW_EVENT(4, "chsc: scm available information\n"); | |
441 | if (sei_area->rs != 7) | |
442 | return; | |
443 | ||
444 | ret = scm_process_availability_information(); | |
445 | if (ret) | |
446 | CIO_CRW_EVENT(0, "chsc: process availability information" | |
447 | " failed (rc=%d).\n", ret); | |
448 | } | |
449 | ||
cbc0dd1f | 450 | static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area) |
184357a5 | 451 | { |
cbc0dd1f JG |
452 | switch (sei_area->cc) { |
453 | case 1: | |
454 | zpci_event_error(sei_area->ccdf); | |
455 | break; | |
456 | case 2: | |
457 | zpci_event_availability(sei_area->ccdf); | |
458 | break; | |
459 | default: | |
9a17e972 | 460 | CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n", |
cbc0dd1f JG |
461 | sei_area->cc); |
462 | break; | |
83b3370c | 463 | } |
cbc0dd1f JG |
464 | } |
465 | ||
466 | static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area) | |
467 | { | |
184357a5 | 468 | /* which kind of information was stored? */ |
184357a5 PO |
469 | switch (sei_area->cc) { |
470 | case 1: /* link incident*/ | |
83b3370c | 471 | chsc_process_sei_link_incident(sei_area); |
184357a5 | 472 | break; |
fca894ed | 473 | case 2: /* i/o resource accessibility */ |
83b3370c | 474 | chsc_process_sei_res_acc(sei_area); |
184357a5 | 475 | break; |
fca894ed SO |
476 | case 7: /* channel-path-availability information */ |
477 | chsc_process_sei_chp_avail(sei_area); | |
478 | break; | |
e5854a58 | 479 | case 8: /* channel-path-configuration notification */ |
83b3370c | 480 | chsc_process_sei_chp_config(sei_area); |
e5854a58 | 481 | break; |
40ff4cc0 SO |
482 | case 12: /* scm change notification */ |
483 | chsc_process_sei_scm_change(sei_area); | |
484 | break; | |
aebfa669 SO |
485 | case 14: /* scm available notification */ |
486 | chsc_process_sei_scm_avail(sei_area); | |
487 | break; | |
184357a5 | 488 | default: /* other stuff */ |
9a17e972 | 489 | CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n", |
184357a5 PO |
490 | sei_area->cc); |
491 | break; | |
492 | } | |
9a17e972 SO |
493 | |
494 | /* Check if we might have lost some information. */ | |
495 | if (sei_area->flags & 0x40) { | |
496 | CIO_CRW_EVENT(2, "chsc: event overflow\n"); | |
497 | css_schedule_eval_all(); | |
498 | } | |
184357a5 PO |
499 | } |
500 | ||
9a17e972 | 501 | static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm) |
cbc0dd1f JG |
502 | { |
503 | do { | |
504 | memset(sei, 0, sizeof(*sei)); | |
505 | sei->request.length = 0x0010; | |
506 | sei->request.code = 0x000e; | |
507 | sei->ntsm = ntsm; | |
508 | ||
509 | if (chsc(sei)) | |
510 | break; | |
511 | ||
9a17e972 | 512 | if (sei->response.code != 0x0001) { |
cbc0dd1f JG |
513 | CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n", |
514 | sei->response.code); | |
515 | break; | |
516 | } | |
cbc0dd1f | 517 | |
9a17e972 SO |
518 | CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt); |
519 | switch (sei->nt) { | |
520 | case 0: | |
521 | chsc_process_sei_nt0(&sei->u.nt0_area); | |
522 | break; | |
523 | case 2: | |
524 | chsc_process_sei_nt2(&sei->u.nt2_area); | |
525 | break; | |
526 | default: | |
527 | CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt); | |
528 | break; | |
529 | } | |
530 | } while (sei->u.nt0_area.flags & 0x80); | |
cbc0dd1f JG |
531 | } |
532 | ||
9a17e972 SO |
533 | /* |
534 | * Handle channel subsystem related CRWs. | |
535 | * Use store event information to find out what's going on. | |
536 | * | |
537 | * Note: Access to sei_page is serialized through machine check handler | |
538 | * thread, so no need for locking. | |
539 | */ | |
c1156189 | 540 | static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow) |
184357a5 | 541 | { |
9a17e972 | 542 | struct chsc_sei *sei = sei_page; |
1da177e4 | 543 | |
c1156189 CH |
544 | if (overflow) { |
545 | css_schedule_eval_all(); | |
546 | return; | |
547 | } | |
548 | CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, " | |
549 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", | |
550 | crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc, | |
551 | crw0->erc, crw0->rsid); | |
1da177e4 | 552 | |
c1156189 | 553 | CIO_TRACE_EVENT(2, "prcss"); |
9a17e972 | 554 | chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2); |
1da177e4 LT |
555 | } |
556 | ||
83b3370c | 557 | void chsc_chp_online(struct chp_id chpid) |
f97a56fb | 558 | { |
1da177e4 | 559 | char dbf_txt[15]; |
99611f87 | 560 | struct chp_link link; |
1da177e4 | 561 | |
f86635fa | 562 | sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id); |
1da177e4 LT |
563 | CIO_TRACE_EVENT(2, dbf_txt); |
564 | ||
22806dc1 | 565 | if (chp_get_status(chpid) != 0) { |
99611f87 CH |
566 | memset(&link, 0, sizeof(struct chp_link)); |
567 | link.chpid = chpid; | |
22806dc1 CH |
568 | /* Wait until previous actions have settled. */ |
569 | css_wait_for_slow_path(); | |
c820de39 | 570 | for_each_subchannel_staged(__s390_process_res_acc, NULL, |
99611f87 | 571 | &link); |
22806dc1 | 572 | } |
1da177e4 LT |
573 | } |
574 | ||
f86635fa PO |
575 | static void __s390_subchannel_vary_chpid(struct subchannel *sch, |
576 | struct chp_id chpid, int on) | |
1da177e4 | 577 | { |
1da177e4 | 578 | unsigned long flags; |
99611f87 | 579 | struct chp_link link; |
1da177e4 | 580 | |
99611f87 CH |
581 | memset(&link, 0, sizeof(struct chp_link)); |
582 | link.chpid = chpid; | |
2ec22984 | 583 | spin_lock_irqsave(sch->lock, flags); |
c820de39 | 584 | if (sch->driver && sch->driver->chp_event) |
99611f87 | 585 | sch->driver->chp_event(sch, &link, |
c820de39 | 586 | on ? CHP_VARY_ON : CHP_VARY_OFF); |
2ec22984 | 587 | spin_unlock_irqrestore(sch->lock, flags); |
1da177e4 LT |
588 | } |
589 | ||
e82a1567 | 590 | static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data) |
1da177e4 | 591 | { |
e82a1567 | 592 | struct chp_id *chpid = data; |
1da177e4 LT |
593 | |
594 | __s390_subchannel_vary_chpid(sch, *chpid, 0); | |
595 | return 0; | |
596 | } | |
597 | ||
e82a1567 | 598 | static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data) |
1da177e4 | 599 | { |
e82a1567 | 600 | struct chp_id *chpid = data; |
1da177e4 LT |
601 | |
602 | __s390_subchannel_vary_chpid(sch, *chpid, 1); | |
603 | return 0; | |
604 | } | |
605 | ||
f97a56fb CH |
606 | static int |
607 | __s390_vary_chpid_on(struct subchannel_id schid, void *data) | |
608 | { | |
609 | struct schib schib; | |
f97a56fb | 610 | |
fb6958a5 | 611 | if (stsch_err(schid, &schib)) |
f97a56fb CH |
612 | /* We're through */ |
613 | return -ENXIO; | |
614 | /* Put it on the slow path. */ | |
83b3370c | 615 | css_schedule_eval(schid); |
f97a56fb CH |
616 | return 0; |
617 | } | |
618 | ||
e6b6e10a PO |
619 | /** |
620 | * chsc_chp_vary - propagate channel-path vary operation to subchannels | |
621 | * @chpid: channl-path ID | |
622 | * @on: non-zero for vary online, zero for vary offline | |
1da177e4 | 623 | */ |
e6b6e10a | 624 | int chsc_chp_vary(struct chp_id chpid, int on) |
1da177e4 | 625 | { |
c38a90a3 | 626 | struct channel_path *chp = chpid_to_chp(chpid); |
99611f87 | 627 | |
22806dc1 CH |
628 | /* Wait until previous actions have settled. */ |
629 | css_wait_for_slow_path(); | |
1da177e4 LT |
630 | /* |
631 | * Redo PathVerification on the devices the chpid connects to | |
632 | */ | |
c38a90a3 SO |
633 | if (on) { |
634 | /* Try to update the channel path descritor. */ | |
635 | chsc_determine_base_channel_path_desc(chpid, &chp->desc); | |
e82a1567 | 636 | for_each_subchannel_staged(s390_subchannel_vary_chpid_on, |
3b484ec6 | 637 | __s390_vary_chpid_on, &chpid); |
c38a90a3 | 638 | } else |
e82a1567 | 639 | for_each_subchannel_staged(s390_subchannel_vary_chpid_off, |
3b484ec6 | 640 | NULL, &chpid); |
e82a1567 | 641 | |
1da177e4 LT |
642 | return 0; |
643 | } | |
644 | ||
495a5b45 CH |
645 | static void |
646 | chsc_remove_cmg_attr(struct channel_subsystem *css) | |
647 | { | |
648 | int i; | |
649 | ||
650 | for (i = 0; i <= __MAX_CHPID; i++) { | |
651 | if (!css->chps[i]) | |
652 | continue; | |
e6b6e10a | 653 | chp_remove_cmg_attr(css->chps[i]); |
495a5b45 CH |
654 | } |
655 | } | |
656 | ||
657 | static int | |
658 | chsc_add_cmg_attr(struct channel_subsystem *css) | |
659 | { | |
660 | int i, ret; | |
661 | ||
662 | ret = 0; | |
663 | for (i = 0; i <= __MAX_CHPID; i++) { | |
664 | if (!css->chps[i]) | |
665 | continue; | |
e6b6e10a | 666 | ret = chp_add_cmg_attr(css->chps[i]); |
495a5b45 CH |
667 | if (ret) |
668 | goto cleanup; | |
669 | } | |
670 | return ret; | |
671 | cleanup: | |
672 | for (--i; i >= 0; i--) { | |
673 | if (!css->chps[i]) | |
674 | continue; | |
e6b6e10a | 675 | chp_remove_cmg_attr(css->chps[i]); |
495a5b45 CH |
676 | } |
677 | return ret; | |
678 | } | |
679 | ||
34196f82 | 680 | int __chsc_do_secm(struct channel_subsystem *css, int enable) |
495a5b45 CH |
681 | { |
682 | struct { | |
683 | struct chsc_header request; | |
684 | u32 operation_code : 2; | |
685 | u32 : 30; | |
686 | u32 key : 4; | |
687 | u32 : 28; | |
688 | u32 zeroes1; | |
689 | u32 cub_addr1; | |
690 | u32 zeroes2; | |
691 | u32 cub_addr2; | |
692 | u32 reserved[13]; | |
693 | struct chsc_header response; | |
694 | u32 status : 8; | |
695 | u32 : 4; | |
696 | u32 fmt : 4; | |
697 | u32 : 16; | |
0f008aa3 | 698 | } __attribute__ ((packed)) *secm_area; |
495a5b45 CH |
699 | int ret, ccode; |
700 | ||
34196f82 SO |
701 | spin_lock_irq(&chsc_page_lock); |
702 | memset(chsc_page, 0, PAGE_SIZE); | |
703 | secm_area = chsc_page; | |
495a5b45 CH |
704 | secm_area->request.length = 0x0050; |
705 | secm_area->request.code = 0x0016; | |
706 | ||
d1bf8590 | 707 | secm_area->key = PAGE_DEFAULT_KEY >> 4; |
495a5b45 CH |
708 | secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1; |
709 | secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2; | |
710 | ||
711 | secm_area->operation_code = enable ? 0 : 1; | |
712 | ||
713 | ccode = chsc(secm_area); | |
34196f82 SO |
714 | if (ccode > 0) { |
715 | ret = (ccode == 3) ? -ENODEV : -EBUSY; | |
716 | goto out; | |
717 | } | |
495a5b45 CH |
718 | |
719 | switch (secm_area->response.code) { | |
b9c9a21a CH |
720 | case 0x0102: |
721 | case 0x0103: | |
495a5b45 | 722 | ret = -EINVAL; |
17e7d87d | 723 | break; |
495a5b45 | 724 | default: |
b9c9a21a | 725 | ret = chsc_error_from_response(secm_area->response.code); |
495a5b45 | 726 | } |
b9c9a21a CH |
727 | if (ret != 0) |
728 | CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n", | |
729 | secm_area->response.code); | |
34196f82 SO |
730 | out: |
731 | spin_unlock_irq(&chsc_page_lock); | |
495a5b45 CH |
732 | return ret; |
733 | } | |
734 | ||
735 | int | |
736 | chsc_secm(struct channel_subsystem *css, int enable) | |
737 | { | |
495a5b45 CH |
738 | int ret; |
739 | ||
495a5b45 CH |
740 | if (enable && !css->cm_enabled) { |
741 | css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
742 | css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
743 | if (!css->cub_addr1 || !css->cub_addr2) { | |
744 | free_page((unsigned long)css->cub_addr1); | |
745 | free_page((unsigned long)css->cub_addr2); | |
495a5b45 CH |
746 | return -ENOMEM; |
747 | } | |
748 | } | |
34196f82 | 749 | ret = __chsc_do_secm(css, enable); |
495a5b45 CH |
750 | if (!ret) { |
751 | css->cm_enabled = enable; | |
752 | if (css->cm_enabled) { | |
753 | ret = chsc_add_cmg_attr(css); | |
754 | if (ret) { | |
34196f82 | 755 | __chsc_do_secm(css, 0); |
495a5b45 CH |
756 | css->cm_enabled = 0; |
757 | } | |
758 | } else | |
759 | chsc_remove_cmg_attr(css); | |
760 | } | |
8c4941c5 | 761 | if (!css->cm_enabled) { |
495a5b45 CH |
762 | free_page((unsigned long)css->cub_addr1); |
763 | free_page((unsigned long)css->cub_addr2); | |
764 | } | |
495a5b45 CH |
765 | return ret; |
766 | } | |
767 | ||
9d92a7e1 | 768 | int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt, |
906c9768 | 769 | int c, int m, void *page) |
1da177e4 | 770 | { |
906c9768 | 771 | struct chsc_scpd *scpd_area; |
1da177e4 LT |
772 | int ccode, ret; |
773 | ||
9d92a7e1 CH |
774 | if ((rfmt == 1) && !css_general_characteristics.fcs) |
775 | return -EINVAL; | |
776 | if ((rfmt == 2) && !css_general_characteristics.cib) | |
777 | return -EINVAL; | |
1da177e4 | 778 | |
906c9768 SO |
779 | memset(page, 0, PAGE_SIZE); |
780 | scpd_area = page; | |
495a5b45 CH |
781 | scpd_area->request.length = 0x0010; |
782 | scpd_area->request.code = 0x0002; | |
9d92a7e1 | 783 | scpd_area->cssid = chpid.cssid; |
f86635fa PO |
784 | scpd_area->first_chpid = chpid.id; |
785 | scpd_area->last_chpid = chpid.id; | |
9d92a7e1 CH |
786 | scpd_area->m = m; |
787 | scpd_area->c = c; | |
788 | scpd_area->fmt = fmt; | |
789 | scpd_area->rfmt = rfmt; | |
1da177e4 LT |
790 | |
791 | ccode = chsc(scpd_area); | |
906c9768 SO |
792 | if (ccode > 0) |
793 | return (ccode == 3) ? -ENODEV : -EBUSY; | |
1da177e4 | 794 | |
b9c9a21a | 795 | ret = chsc_error_from_response(scpd_area->response.code); |
906c9768 | 796 | if (ret) |
b9c9a21a | 797 | CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n", |
1da177e4 | 798 | scpd_area->response.code); |
1da177e4 LT |
799 | return ret; |
800 | } | |
9d92a7e1 CH |
801 | EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc); |
802 | ||
803 | int chsc_determine_base_channel_path_desc(struct chp_id chpid, | |
804 | struct channel_path_desc *desc) | |
805 | { | |
806 | struct chsc_response_struct *chsc_resp; | |
906c9768 | 807 | struct chsc_scpd *scpd_area; |
62da177a | 808 | unsigned long flags; |
9d92a7e1 CH |
809 | int ret; |
810 | ||
62da177a | 811 | spin_lock_irqsave(&chsc_page_lock, flags); |
906c9768 SO |
812 | scpd_area = chsc_page; |
813 | ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, scpd_area); | |
9d92a7e1 | 814 | if (ret) |
906c9768 SO |
815 | goto out; |
816 | chsc_resp = (void *)&scpd_area->response; | |
878c4956 | 817 | memcpy(desc, &chsc_resp->data, sizeof(*desc)); |
906c9768 | 818 | out: |
62da177a | 819 | spin_unlock_irqrestore(&chsc_page_lock, flags); |
9d92a7e1 CH |
820 | return ret; |
821 | } | |
1da177e4 | 822 | |
ce322ccd SO |
823 | int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid, |
824 | struct channel_path_desc_fmt1 *desc) | |
825 | { | |
826 | struct chsc_response_struct *chsc_resp; | |
827 | struct chsc_scpd *scpd_area; | |
828 | int ret; | |
829 | ||
830 | spin_lock_irq(&chsc_page_lock); | |
831 | scpd_area = chsc_page; | |
832 | ret = chsc_determine_channel_path_desc(chpid, 0, 0, 1, 0, scpd_area); | |
833 | if (ret) | |
834 | goto out; | |
835 | chsc_resp = (void *)&scpd_area->response; | |
836 | memcpy(desc, &chsc_resp->data, sizeof(*desc)); | |
837 | out: | |
838 | spin_unlock_irq(&chsc_page_lock); | |
839 | return ret; | |
840 | } | |
841 | ||
495a5b45 CH |
842 | static void |
843 | chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv, | |
844 | struct cmg_chars *chars) | |
845 | { | |
34196f82 SO |
846 | struct cmg_chars *cmg_chars; |
847 | int i, mask; | |
848 | ||
849 | cmg_chars = chp->cmg_chars; | |
850 | for (i = 0; i < NR_MEASUREMENT_CHARS; i++) { | |
851 | mask = 0x80 >> (i + 3); | |
852 | if (cmcv & mask) | |
853 | cmg_chars->values[i] = chars->values[i]; | |
854 | else | |
855 | cmg_chars->values[i] = 0; | |
495a5b45 CH |
856 | } |
857 | } | |
858 | ||
e6b6e10a | 859 | int chsc_get_channel_measurement_chars(struct channel_path *chp) |
495a5b45 | 860 | { |
34196f82 | 861 | struct cmg_chars *cmg_chars; |
495a5b45 CH |
862 | int ccode, ret; |
863 | ||
864 | struct { | |
865 | struct chsc_header request; | |
866 | u32 : 24; | |
867 | u32 first_chpid : 8; | |
868 | u32 : 24; | |
869 | u32 last_chpid : 8; | |
870 | u32 zeroes1; | |
871 | struct chsc_header response; | |
872 | u32 zeroes2; | |
873 | u32 not_valid : 1; | |
874 | u32 shared : 1; | |
875 | u32 : 22; | |
876 | u32 chpid : 8; | |
877 | u32 cmcv : 5; | |
878 | u32 : 11; | |
879 | u32 cmgq : 8; | |
880 | u32 cmg : 8; | |
881 | u32 zeroes3; | |
882 | u32 data[NR_MEASUREMENT_CHARS]; | |
0f008aa3 | 883 | } __attribute__ ((packed)) *scmc_area; |
495a5b45 | 884 | |
34196f82 SO |
885 | chp->cmg_chars = NULL; |
886 | cmg_chars = kmalloc(sizeof(*cmg_chars), GFP_KERNEL); | |
887 | if (!cmg_chars) | |
495a5b45 CH |
888 | return -ENOMEM; |
889 | ||
34196f82 SO |
890 | spin_lock_irq(&chsc_page_lock); |
891 | memset(chsc_page, 0, PAGE_SIZE); | |
892 | scmc_area = chsc_page; | |
495a5b45 CH |
893 | scmc_area->request.length = 0x0010; |
894 | scmc_area->request.code = 0x0022; | |
f86635fa PO |
895 | scmc_area->first_chpid = chp->chpid.id; |
896 | scmc_area->last_chpid = chp->chpid.id; | |
495a5b45 CH |
897 | |
898 | ccode = chsc(scmc_area); | |
899 | if (ccode > 0) { | |
900 | ret = (ccode == 3) ? -ENODEV : -EBUSY; | |
901 | goto out; | |
902 | } | |
903 | ||
b9c9a21a | 904 | ret = chsc_error_from_response(scmc_area->response.code); |
34196f82 | 905 | if (ret) { |
b9c9a21a | 906 | CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n", |
495a5b45 | 907 | scmc_area->response.code); |
34196f82 SO |
908 | goto out; |
909 | } | |
910 | if (scmc_area->not_valid) { | |
911 | chp->cmg = -1; | |
912 | chp->shared = -1; | |
913 | goto out; | |
914 | } | |
915 | chp->cmg = scmc_area->cmg; | |
916 | chp->shared = scmc_area->shared; | |
917 | if (chp->cmg != 2 && chp->cmg != 3) { | |
918 | /* No cmg-dependent data. */ | |
919 | goto out; | |
495a5b45 | 920 | } |
34196f82 SO |
921 | chp->cmg_chars = cmg_chars; |
922 | chsc_initialize_cmg_chars(chp, scmc_area->cmcv, | |
923 | (struct cmg_chars *) &scmc_area->data); | |
495a5b45 | 924 | out: |
34196f82 SO |
925 | spin_unlock_irq(&chsc_page_lock); |
926 | if (!chp->cmg_chars) | |
927 | kfree(cmg_chars); | |
928 | ||
495a5b45 CH |
929 | return ret; |
930 | } | |
931 | ||
34aec07c | 932 | int __init chsc_init(void) |
1da177e4 | 933 | { |
c1156189 CH |
934 | int ret; |
935 | ||
1da177e4 | 936 | sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); |
34196f82 SO |
937 | chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); |
938 | if (!sei_page || !chsc_page) { | |
939 | ret = -ENOMEM; | |
940 | goto out_err; | |
c1156189 | 941 | } |
f5daba1d | 942 | ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw); |
c1156189 | 943 | if (ret) |
34196f82 SO |
944 | goto out_err; |
945 | return ret; | |
946 | out_err: | |
947 | free_page((unsigned long)chsc_page); | |
948 | free_page((unsigned long)sei_page); | |
c1156189 | 949 | return ret; |
1da177e4 LT |
950 | } |
951 | ||
34aec07c | 952 | void __init chsc_init_cleanup(void) |
4434a38c | 953 | { |
f5daba1d | 954 | crw_unregister_handler(CRW_RSC_CSS); |
34196f82 | 955 | free_page((unsigned long)chsc_page); |
34aec07c | 956 | free_page((unsigned long)sei_page); |
4434a38c CH |
957 | } |
958 | ||
818c272b | 959 | int chsc_enable_facility(int operation_code) |
fb6958a5 | 960 | { |
34196f82 | 961 | unsigned long flags; |
fb6958a5 | 962 | int ret; |
34196f82 | 963 | struct { |
fb6958a5 CH |
964 | struct chsc_header request; |
965 | u8 reserved1:4; | |
966 | u8 format:4; | |
967 | u8 reserved2; | |
968 | u16 operation_code; | |
969 | u32 reserved3; | |
970 | u32 reserved4; | |
971 | u32 operation_data_area[252]; | |
972 | struct chsc_header response; | |
973 | u32 reserved5:4; | |
974 | u32 format2:4; | |
975 | u32 reserved6:24; | |
34196f82 | 976 | } __attribute__ ((packed)) *sda_area; |
fb6958a5 | 977 | |
34196f82 SO |
978 | spin_lock_irqsave(&chsc_page_lock, flags); |
979 | memset(chsc_page, 0, PAGE_SIZE); | |
980 | sda_area = chsc_page; | |
981 | sda_area->request.length = 0x0400; | |
982 | sda_area->request.code = 0x0031; | |
983 | sda_area->operation_code = operation_code; | |
fb6958a5 | 984 | |
34196f82 | 985 | ret = chsc(sda_area); |
fb6958a5 CH |
986 | if (ret > 0) { |
987 | ret = (ret == 3) ? -ENODEV : -EBUSY; | |
988 | goto out; | |
989 | } | |
b9c9a21a | 990 | |
34196f82 | 991 | switch (sda_area->response.code) { |
b9c9a21a | 992 | case 0x0101: |
fb6958a5 CH |
993 | ret = -EOPNOTSUPP; |
994 | break; | |
b9c9a21a | 995 | default: |
34196f82 | 996 | ret = chsc_error_from_response(sda_area->response.code); |
fb6958a5 | 997 | } |
b9c9a21a CH |
998 | if (ret != 0) |
999 | CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n", | |
34196f82 SO |
1000 | operation_code, sda_area->response.code); |
1001 | out: | |
1002 | spin_unlock_irqrestore(&chsc_page_lock, flags); | |
fb6958a5 CH |
1003 | return ret; |
1004 | } | |
1005 | ||
1da177e4 LT |
1006 | struct css_general_char css_general_characteristics; |
1007 | struct css_chsc_char css_chsc_characteristics; | |
1008 | ||
1009 | int __init | |
1010 | chsc_determine_css_characteristics(void) | |
1011 | { | |
1012 | int result; | |
1013 | struct { | |
1014 | struct chsc_header request; | |
1015 | u32 reserved1; | |
1016 | u32 reserved2; | |
1017 | u32 reserved3; | |
1018 | struct chsc_header response; | |
1019 | u32 reserved4; | |
1020 | u32 general_char[510]; | |
34aec07c | 1021 | u32 chsc_char[508]; |
0f008aa3 | 1022 | } __attribute__ ((packed)) *scsc_area; |
1da177e4 | 1023 | |
34196f82 SO |
1024 | spin_lock_irq(&chsc_page_lock); |
1025 | memset(chsc_page, 0, PAGE_SIZE); | |
1026 | scsc_area = chsc_page; | |
495a5b45 CH |
1027 | scsc_area->request.length = 0x0010; |
1028 | scsc_area->request.code = 0x0010; | |
1da177e4 LT |
1029 | |
1030 | result = chsc(scsc_area); | |
1031 | if (result) { | |
b9c9a21a | 1032 | result = (result == 3) ? -ENODEV : -EBUSY; |
1da177e4 LT |
1033 | goto exit; |
1034 | } | |
1035 | ||
b9c9a21a CH |
1036 | result = chsc_error_from_response(scsc_area->response.code); |
1037 | if (result == 0) { | |
1038 | memcpy(&css_general_characteristics, scsc_area->general_char, | |
1039 | sizeof(css_general_characteristics)); | |
1040 | memcpy(&css_chsc_characteristics, scsc_area->chsc_char, | |
1041 | sizeof(css_chsc_characteristics)); | |
1042 | } else | |
1043 | CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n", | |
1044 | scsc_area->response.code); | |
1da177e4 | 1045 | exit: |
34196f82 | 1046 | spin_unlock_irq(&chsc_page_lock); |
1da177e4 LT |
1047 | return result; |
1048 | } | |
1049 | ||
1050 | EXPORT_SYMBOL_GPL(css_general_characteristics); | |
1051 | EXPORT_SYMBOL_GPL(css_chsc_characteristics); | |
d2fec595 MS |
1052 | |
1053 | int chsc_sstpc(void *page, unsigned int op, u16 ctrl) | |
1054 | { | |
1055 | struct { | |
1056 | struct chsc_header request; | |
1057 | unsigned int rsvd0; | |
1058 | unsigned int op : 8; | |
1059 | unsigned int rsvd1 : 8; | |
1060 | unsigned int ctrl : 16; | |
1061 | unsigned int rsvd2[5]; | |
1062 | struct chsc_header response; | |
1063 | unsigned int rsvd3[7]; | |
1064 | } __attribute__ ((packed)) *rr; | |
1065 | int rc; | |
1066 | ||
1067 | memset(page, 0, PAGE_SIZE); | |
1068 | rr = page; | |
1069 | rr->request.length = 0x0020; | |
1070 | rr->request.code = 0x0033; | |
1071 | rr->op = op; | |
1072 | rr->ctrl = ctrl; | |
1073 | rc = chsc(rr); | |
1074 | if (rc) | |
1075 | return -EIO; | |
1076 | rc = (rr->response.code == 0x0001) ? 0 : -EIO; | |
1077 | return rc; | |
1078 | } | |
1079 | ||
1080 | int chsc_sstpi(void *page, void *result, size_t size) | |
1081 | { | |
1082 | struct { | |
1083 | struct chsc_header request; | |
1084 | unsigned int rsvd0[3]; | |
1085 | struct chsc_header response; | |
1086 | char data[size]; | |
1087 | } __attribute__ ((packed)) *rr; | |
1088 | int rc; | |
1089 | ||
1090 | memset(page, 0, PAGE_SIZE); | |
1091 | rr = page; | |
1092 | rr->request.length = 0x0010; | |
1093 | rr->request.code = 0x0038; | |
1094 | rc = chsc(rr); | |
1095 | if (rc) | |
1096 | return -EIO; | |
1097 | memcpy(result, &rr->data, size); | |
1098 | return (rr->response.code == 0x0001) ? 0 : -EIO; | |
1099 | } | |
1100 | ||
fd0457a6 ME |
1101 | int chsc_siosl(struct subchannel_id schid) |
1102 | { | |
34196f82 SO |
1103 | struct { |
1104 | struct chsc_header request; | |
1105 | u32 word1; | |
1106 | struct subchannel_id sid; | |
1107 | u32 word3; | |
1108 | struct chsc_header response; | |
1109 | u32 word[11]; | |
1110 | } __attribute__ ((packed)) *siosl_area; | |
fd0457a6 ME |
1111 | unsigned long flags; |
1112 | int ccode; | |
1113 | int rc; | |
1114 | ||
34196f82 SO |
1115 | spin_lock_irqsave(&chsc_page_lock, flags); |
1116 | memset(chsc_page, 0, PAGE_SIZE); | |
1117 | siosl_area = chsc_page; | |
1118 | siosl_area->request.length = 0x0010; | |
1119 | siosl_area->request.code = 0x0046; | |
1120 | siosl_area->word1 = 0x80000000; | |
1121 | siosl_area->sid = schid; | |
fd0457a6 | 1122 | |
34196f82 | 1123 | ccode = chsc(siosl_area); |
fd0457a6 ME |
1124 | if (ccode > 0) { |
1125 | if (ccode == 3) | |
1126 | rc = -ENODEV; | |
1127 | else | |
1128 | rc = -EBUSY; | |
1129 | CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n", | |
1130 | schid.ssid, schid.sch_no, ccode); | |
1131 | goto out; | |
1132 | } | |
34196f82 | 1133 | rc = chsc_error_from_response(siosl_area->response.code); |
fd0457a6 ME |
1134 | if (rc) |
1135 | CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n", | |
1136 | schid.ssid, schid.sch_no, | |
34196f82 | 1137 | siosl_area->response.code); |
fd0457a6 ME |
1138 | else |
1139 | CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n", | |
1140 | schid.ssid, schid.sch_no); | |
1141 | out: | |
34196f82 | 1142 | spin_unlock_irqrestore(&chsc_page_lock, flags); |
fd0457a6 ME |
1143 | return rc; |
1144 | } | |
1145 | EXPORT_SYMBOL_GPL(chsc_siosl); | |
184b08af SO |
1146 | |
1147 | /** | |
1148 | * chsc_scm_info() - store SCM information (SSI) | |
1149 | * @scm_area: request and response block for SSI | |
1150 | * @token: continuation token | |
1151 | * | |
1152 | * Returns 0 on success. | |
1153 | */ | |
1154 | int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token) | |
1155 | { | |
1156 | int ccode, ret; | |
1157 | ||
1158 | memset(scm_area, 0, sizeof(*scm_area)); | |
1159 | scm_area->request.length = 0x0020; | |
1160 | scm_area->request.code = 0x004C; | |
1161 | scm_area->reqtok = token; | |
1162 | ||
1163 | ccode = chsc(scm_area); | |
1164 | if (ccode > 0) { | |
1165 | ret = (ccode == 3) ? -ENODEV : -EBUSY; | |
1166 | goto out; | |
1167 | } | |
1168 | ret = chsc_error_from_response(scm_area->response.code); | |
1169 | if (ret != 0) | |
1170 | CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n", | |
1171 | scm_area->response.code); | |
1172 | out: | |
1173 | return ret; | |
1174 | } | |
1175 | EXPORT_SYMBOL_GPL(chsc_scm_info); |