[S390] cio: suppress chpid event in case of configure error
[deliverable/linux.git] / drivers / s390 / cio / chsc.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call
1da177e4 4 *
c820de39 5 * Copyright IBM Corp. 1999,2008
1da177e4 6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
4ce3b30c 7 * Cornelia Huck (cornelia.huck@de.ibm.com)
1da177e4
LT
8 * Arnd Bergmann (arndb@de.ibm.com)
9 */
10
11#include <linux/module.h>
1da177e4
LT
12#include <linux/slab.h>
13#include <linux/init.h>
14#include <linux/device.h>
15
16#include <asm/cio.h>
e5854a58 17#include <asm/chpid.h>
1da177e4 18
c1156189 19#include "../s390mach.h"
1da177e4
LT
20#include "css.h"
21#include "cio.h"
22#include "cio_debug.h"
23#include "ioasm.h"
e6b6e10a 24#include "chp.h"
1da177e4
LT
25#include "chsc.h"
26
1da177e4
LT
27static void *sei_page;
28
b9c9a21a
CH
29static int chsc_error_from_response(int response)
30{
31 switch (response) {
32 case 0x0001:
33 return 0;
34 case 0x0002:
35 case 0x0003:
36 case 0x0006:
37 case 0x0007:
38 case 0x0008:
39 case 0x000a:
40 return -EINVAL;
41 case 0x0004:
42 return -EOPNOTSUPP;
43 default:
44 return -EIO;
45 }
46}
47
7ad6a249
PO
48struct chsc_ssd_area {
49 struct chsc_header request;
50 u16 :10;
51 u16 ssid:2;
52 u16 :4;
53 u16 f_sch; /* first subchannel */
54 u16 :16;
55 u16 l_sch; /* last subchannel */
56 u32 :32;
57 struct chsc_header response;
58 u32 :32;
59 u8 sch_valid : 1;
60 u8 dev_valid : 1;
61 u8 st : 3; /* subchannel type */
62 u8 zeroes : 3;
63 u8 unit_addr; /* unit address */
64 u16 devno; /* device number */
65 u8 path_mask;
66 u8 fla_valid_mask;
67 u16 sch; /* subchannel */
68 u8 chpid[8]; /* chpids 0-7 */
69 u16 fla[8]; /* full link addresses 0-7 */
70} __attribute__ ((packed));
71
72int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
1da177e4 73{
7ad6a249
PO
74 unsigned long page;
75 struct chsc_ssd_area *ssd_area;
76 int ccode;
77 int ret;
78 int i;
79 int mask;
1da177e4 80
7ad6a249
PO
81 page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
82 if (!page)
83 return -ENOMEM;
84 ssd_area = (struct chsc_ssd_area *) page;
495a5b45
CH
85 ssd_area->request.length = 0x0010;
86 ssd_area->request.code = 0x0004;
7ad6a249
PO
87 ssd_area->ssid = schid.ssid;
88 ssd_area->f_sch = schid.sch_no;
89 ssd_area->l_sch = schid.sch_no;
1da177e4
LT
90
91 ccode = chsc(ssd_area);
7ad6a249 92 /* Check response. */
1da177e4 93 if (ccode > 0) {
7ad6a249
PO
94 ret = (ccode == 3) ? -ENODEV : -EBUSY;
95 goto out_free;
1da177e4 96 }
b9c9a21a
CH
97 ret = chsc_error_from_response(ssd_area->response.code);
98 if (ret != 0) {
7ad6a249
PO
99 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
100 schid.ssid, schid.sch_no,
1da177e4 101 ssd_area->response.code);
7ad6a249 102 goto out_free;
1da177e4 103 }
7ad6a249
PO
104 if (!ssd_area->sch_valid) {
105 ret = -ENODEV;
106 goto out_free;
1da177e4 107 }
7ad6a249
PO
108 /* Copy data */
109 ret = 0;
110 memset(ssd, 0, sizeof(struct chsc_ssd_info));
b279a4f5
CH
111 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
112 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
7ad6a249
PO
113 goto out_free;
114 ssd->path_mask = ssd_area->path_mask;
115 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
116 for (i = 0; i < 8; i++) {
117 mask = 0x80 >> i;
118 if (ssd_area->path_mask & mask) {
119 chp_id_init(&ssd->chpid[i]);
120 ssd->chpid[i].id = ssd_area->chpid[i];
1da177e4 121 }
7ad6a249
PO
122 if (ssd_area->fla_valid_mask & mask)
123 ssd->fla[i] = ssd_area->fla[i];
1da177e4 124 }
7ad6a249
PO
125out_free:
126 free_page(page);
1da177e4
LT
127 return ret;
128}
129
e82a1567 130static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
1da177e4 131{
2ec22984 132 spin_lock_irq(sch->lock);
c820de39
CH
133 if (sch->driver && sch->driver->chp_event)
134 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
1da177e4 135 goto out_unreg;
2ec22984 136 spin_unlock_irq(sch->lock);
1da177e4 137 return 0;
387b734f 138
1da177e4 139out_unreg:
1da177e4 140 sch->lpm = 0;
387b734f 141 spin_unlock_irq(sch->lock);
83b3370c 142 css_schedule_eval(sch->schid);
1da177e4
LT
143 return 0;
144}
145
e6b6e10a 146void chsc_chp_offline(struct chp_id chpid)
1da177e4
LT
147{
148 char dbf_txt[15];
99611f87 149 struct chp_link link;
1da177e4 150
f86635fa 151 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
1da177e4
LT
152 CIO_TRACE_EVENT(2, dbf_txt);
153
e6b6e10a 154 if (chp_get_status(chpid) <= 0)
1da177e4 155 return;
99611f87
CH
156 memset(&link, 0, sizeof(struct chp_link));
157 link.chpid = chpid;
22806dc1
CH
158 /* Wait until previous actions have settled. */
159 css_wait_for_slow_path();
99611f87 160 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
1da177e4
LT
161}
162
e82a1567 163static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
f97a56fb
CH
164{
165 struct schib schib;
f97a56fb
CH
166 /*
167 * We don't know the device yet, but since a path
168 * may be available now to the device we'll have
169 * to do recognition again.
170 * Since we don't have any idea about which chpid
171 * that beast may be on we'll have to do a stsch
172 * on all devices, grr...
173 */
fb6958a5 174 if (stsch_err(schid, &schib))
f97a56fb 175 /* We're through */
83b3370c 176 return -ENXIO;
f97a56fb
CH
177
178 /* Put it on the slow path. */
83b3370c 179 css_schedule_eval(schid);
f97a56fb
CH
180 return 0;
181}
182
e82a1567 183static int __s390_process_res_acc(struct subchannel *sch, void *data)
1da177e4 184{
2ec22984 185 spin_lock_irq(sch->lock);
c820de39
CH
186 if (sch->driver && sch->driver->chp_event)
187 sch->driver->chp_event(sch, data, CHP_ONLINE);
2ec22984 188 spin_unlock_irq(sch->lock);
e82a1567 189
dd9963f9 190 return 0;
f97a56fb
CH
191}
192
99611f87 193static void s390_process_res_acc(struct chp_link *link)
f97a56fb 194{
1da177e4
LT
195 char dbf_txt[15];
196
99611f87
CH
197 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
198 link->chpid.id);
1da177e4 199 CIO_TRACE_EVENT( 2, dbf_txt);
99611f87
CH
200 if (link->fla != 0) {
201 sprintf(dbf_txt, "fla%x", link->fla);
1da177e4
LT
202 CIO_TRACE_EVENT( 2, dbf_txt);
203 }
22806dc1
CH
204 /* Wait until previous actions have settled. */
205 css_wait_for_slow_path();
1da177e4
LT
206 /*
207 * I/O resources may have become accessible.
208 * Scan through all subchannels that may be concerned and
209 * do a validation on those.
210 * The more information we have (info), the less scanning
211 * will we have to do.
212 */
e82a1567 213 for_each_subchannel_staged(__s390_process_res_acc,
99611f87 214 s390_process_res_acc_new_sch, link);
1da177e4
LT
215}
216
217static int
218__get_chpid_from_lir(void *data)
219{
220 struct lir {
221 u8 iq;
222 u8 ic;
223 u16 sci;
224 /* incident-node descriptor */
225 u32 indesc[28];
226 /* attached-node descriptor */
227 u32 andesc[28];
228 /* incident-specific information */
229 u32 isinfo[28];
0f008aa3 230 } __attribute__ ((packed)) *lir;
1da177e4 231
12975aef 232 lir = data;
1da177e4
LT
233 if (!(lir->iq&0x80))
234 /* NULL link incident record */
235 return -EINVAL;
236 if (!(lir->indesc[0]&0xc0000000))
237 /* node descriptor not valid */
238 return -EINVAL;
239 if (!(lir->indesc[0]&0x10000000))
240 /* don't handle device-type nodes - FIXME */
241 return -EINVAL;
242 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
243
244 return (u16) (lir->indesc[0]&0x000000ff);
245}
246
184357a5
PO
247struct chsc_sei_area {
248 struct chsc_header request;
249 u32 reserved1;
250 u32 reserved2;
251 u32 reserved3;
252 struct chsc_header response;
253 u32 reserved4;
254 u8 flags;
255 u8 vf; /* validity flags */
256 u8 rs; /* reporting source */
257 u8 cc; /* content code */
258 u16 fla; /* full link address */
259 u16 rsid; /* reporting source id */
260 u32 reserved5;
261 u32 reserved6;
262 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
263 /* ccdf has to be big enough for a link-incident record */
264} __attribute__ ((packed));
265
83b3370c 266static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
184357a5 267{
f86635fa
PO
268 struct chp_id chpid;
269 int id;
184357a5
PO
270
271 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
272 sei_area->rs, sei_area->rsid);
273 if (sei_area->rs != 4)
83b3370c 274 return;
f86635fa
PO
275 id = __get_chpid_from_lir(sei_area->ccdf);
276 if (id < 0)
184357a5 277 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
f86635fa
PO
278 else {
279 chp_id_init(&chpid);
280 chpid.id = id;
e6b6e10a 281 chsc_chp_offline(chpid);
f86635fa 282 }
184357a5
PO
283}
284
83b3370c 285static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
1da177e4 286{
99611f87 287 struct chp_link link;
f86635fa 288 struct chp_id chpid;
184357a5 289 int status;
184357a5
PO
290
291 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
292 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
293 if (sei_area->rs != 4)
83b3370c 294 return;
f86635fa
PO
295 chp_id_init(&chpid);
296 chpid.id = sei_area->rsid;
184357a5 297 /* allocate a new channel path structure, if needed */
e6b6e10a 298 status = chp_get_status(chpid);
184357a5 299 if (status < 0)
e6b6e10a 300 chp_new(chpid);
184357a5 301 else if (!status)
83b3370c 302 return;
99611f87
CH
303 memset(&link, 0, sizeof(struct chp_link));
304 link.chpid = chpid;
184357a5 305 if ((sei_area->vf & 0xc0) != 0) {
99611f87 306 link.fla = sei_area->fla;
184357a5
PO
307 if ((sei_area->vf & 0xc0) == 0xc0)
308 /* full link address */
99611f87 309 link.fla_mask = 0xffff;
184357a5
PO
310 else
311 /* link address */
99611f87 312 link.fla_mask = 0xff00;
184357a5 313 }
99611f87 314 s390_process_res_acc(&link);
184357a5
PO
315}
316
e5854a58
PO
317struct chp_config_data {
318 u8 map[32];
319 u8 op;
320 u8 pc;
321};
322
83b3370c 323static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
e5854a58
PO
324{
325 struct chp_config_data *data;
326 struct chp_id chpid;
327 int num;
328
329 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
330 if (sei_area->rs != 0)
83b3370c 331 return;
e5854a58
PO
332 data = (struct chp_config_data *) &(sei_area->ccdf);
333 chp_id_init(&chpid);
334 for (num = 0; num <= __MAX_CHPID; num++) {
335 if (!chp_test_bit(data->map, num))
336 continue;
337 chpid.id = num;
338 printk(KERN_WARNING "cio: processing configure event %d for "
339 "chpid %x.%02x\n", data->op, chpid.cssid, chpid.id);
340 switch (data->op) {
341 case 0:
342 chp_cfg_schedule(chpid, 1);
343 break;
344 case 1:
345 chp_cfg_schedule(chpid, 0);
346 break;
347 case 2:
348 chp_cfg_cancel_deconfigure(chpid);
349 break;
350 }
351 }
e5854a58
PO
352}
353
83b3370c 354static void chsc_process_sei(struct chsc_sei_area *sei_area)
184357a5 355{
184357a5 356 /* Check if we might have lost some information. */
83b3370c 357 if (sei_area->flags & 0x40) {
184357a5 358 CIO_CRW_EVENT(2, "chsc: event overflow\n");
83b3370c
PO
359 css_schedule_eval_all();
360 }
184357a5 361 /* which kind of information was stored? */
184357a5
PO
362 switch (sei_area->cc) {
363 case 1: /* link incident*/
83b3370c 364 chsc_process_sei_link_incident(sei_area);
184357a5
PO
365 break;
366 case 2: /* i/o resource accessibiliy */
83b3370c 367 chsc_process_sei_res_acc(sei_area);
184357a5 368 break;
e5854a58 369 case 8: /* channel-path-configuration notification */
83b3370c 370 chsc_process_sei_chp_config(sei_area);
e5854a58 371 break;
184357a5
PO
372 default: /* other stuff */
373 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
374 sei_area->cc);
375 break;
376 }
184357a5
PO
377}
378
c1156189 379static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
184357a5
PO
380{
381 struct chsc_sei_area *sei_area;
1da177e4 382
c1156189
CH
383 if (overflow) {
384 css_schedule_eval_all();
385 return;
386 }
387 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
388 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
389 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
390 crw0->erc, crw0->rsid);
1da177e4 391 if (!sei_page)
83b3370c 392 return;
184357a5
PO
393 /* Access to sei_page is serialized through machine check handler
394 * thread, so no need for locking. */
1da177e4
LT
395 sei_area = sei_page;
396
c1156189 397 CIO_TRACE_EVENT(2, "prcss");
1da177e4 398 do {
1da177e4 399 memset(sei_area, 0, sizeof(*sei_area));
495a5b45
CH
400 sei_area->request.length = 0x0010;
401 sei_area->request.code = 0x000e;
184357a5
PO
402 if (chsc(sei_area))
403 break;
1da177e4 404
184357a5
PO
405 if (sei_area->response.code == 0x0001) {
406 CIO_CRW_EVENT(4, "chsc: sei successful\n");
83b3370c 407 chsc_process_sei(sei_area);
184357a5
PO
408 } else {
409 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
1da177e4 410 sei_area->response.code);
1da177e4
LT
411 break;
412 }
413 } while (sei_area->flags & 0x80);
1da177e4
LT
414}
415
83b3370c 416void chsc_chp_online(struct chp_id chpid)
f97a56fb 417{
1da177e4 418 char dbf_txt[15];
99611f87 419 struct chp_link link;
1da177e4 420
f86635fa 421 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
1da177e4
LT
422 CIO_TRACE_EVENT(2, dbf_txt);
423
22806dc1 424 if (chp_get_status(chpid) != 0) {
99611f87
CH
425 memset(&link, 0, sizeof(struct chp_link));
426 link.chpid = chpid;
22806dc1
CH
427 /* Wait until previous actions have settled. */
428 css_wait_for_slow_path();
c820de39 429 for_each_subchannel_staged(__s390_process_res_acc, NULL,
99611f87 430 &link);
22806dc1 431 }
1da177e4
LT
432}
433
f86635fa
PO
434static void __s390_subchannel_vary_chpid(struct subchannel *sch,
435 struct chp_id chpid, int on)
1da177e4 436{
1da177e4 437 unsigned long flags;
99611f87 438 struct chp_link link;
1da177e4 439
99611f87
CH
440 memset(&link, 0, sizeof(struct chp_link));
441 link.chpid = chpid;
2ec22984 442 spin_lock_irqsave(sch->lock, flags);
c820de39 443 if (sch->driver && sch->driver->chp_event)
99611f87 444 sch->driver->chp_event(sch, &link,
c820de39 445 on ? CHP_VARY_ON : CHP_VARY_OFF);
2ec22984 446 spin_unlock_irqrestore(sch->lock, flags);
1da177e4
LT
447}
448
e82a1567 449static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
1da177e4 450{
e82a1567 451 struct chp_id *chpid = data;
1da177e4
LT
452
453 __s390_subchannel_vary_chpid(sch, *chpid, 0);
454 return 0;
455}
456
e82a1567 457static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
1da177e4 458{
e82a1567 459 struct chp_id *chpid = data;
1da177e4
LT
460
461 __s390_subchannel_vary_chpid(sch, *chpid, 1);
462 return 0;
463}
464
f97a56fb
CH
465static int
466__s390_vary_chpid_on(struct subchannel_id schid, void *data)
467{
468 struct schib schib;
f97a56fb 469
fb6958a5 470 if (stsch_err(schid, &schib))
f97a56fb
CH
471 /* We're through */
472 return -ENXIO;
473 /* Put it on the slow path. */
83b3370c 474 css_schedule_eval(schid);
f97a56fb
CH
475 return 0;
476}
477
e6b6e10a
PO
478/**
479 * chsc_chp_vary - propagate channel-path vary operation to subchannels
480 * @chpid: channl-path ID
481 * @on: non-zero for vary online, zero for vary offline
1da177e4 482 */
e6b6e10a 483int chsc_chp_vary(struct chp_id chpid, int on)
1da177e4 484{
99611f87
CH
485 struct chp_link link;
486
487 memset(&link, 0, sizeof(struct chp_link));
488 link.chpid = chpid;
22806dc1
CH
489 /* Wait until previous actions have settled. */
490 css_wait_for_slow_path();
1da177e4
LT
491 /*
492 * Redo PathVerification on the devices the chpid connects to
493 */
494
f97a56fb 495 if (on)
e82a1567 496 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
99611f87 497 __s390_vary_chpid_on, &link);
e82a1567
PO
498 else
499 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
99611f87 500 NULL, &link);
e82a1567 501
1da177e4
LT
502 return 0;
503}
504
495a5b45
CH
505static void
506chsc_remove_cmg_attr(struct channel_subsystem *css)
507{
508 int i;
509
510 for (i = 0; i <= __MAX_CHPID; i++) {
511 if (!css->chps[i])
512 continue;
e6b6e10a 513 chp_remove_cmg_attr(css->chps[i]);
495a5b45
CH
514 }
515}
516
517static int
518chsc_add_cmg_attr(struct channel_subsystem *css)
519{
520 int i, ret;
521
522 ret = 0;
523 for (i = 0; i <= __MAX_CHPID; i++) {
524 if (!css->chps[i])
525 continue;
e6b6e10a 526 ret = chp_add_cmg_attr(css->chps[i]);
495a5b45
CH
527 if (ret)
528 goto cleanup;
529 }
530 return ret;
531cleanup:
532 for (--i; i >= 0; i--) {
533 if (!css->chps[i])
534 continue;
e6b6e10a 535 chp_remove_cmg_attr(css->chps[i]);
495a5b45
CH
536 }
537 return ret;
538}
539
495a5b45
CH
540static int
541__chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
542{
543 struct {
544 struct chsc_header request;
545 u32 operation_code : 2;
546 u32 : 30;
547 u32 key : 4;
548 u32 : 28;
549 u32 zeroes1;
550 u32 cub_addr1;
551 u32 zeroes2;
552 u32 cub_addr2;
553 u32 reserved[13];
554 struct chsc_header response;
555 u32 status : 8;
556 u32 : 4;
557 u32 fmt : 4;
558 u32 : 16;
0f008aa3 559 } __attribute__ ((packed)) *secm_area;
495a5b45
CH
560 int ret, ccode;
561
562 secm_area = page;
563 secm_area->request.length = 0x0050;
564 secm_area->request.code = 0x0016;
565
566 secm_area->key = PAGE_DEFAULT_KEY;
567 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
568 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
569
570 secm_area->operation_code = enable ? 0 : 1;
571
572 ccode = chsc(secm_area);
573 if (ccode > 0)
574 return (ccode == 3) ? -ENODEV : -EBUSY;
575
576 switch (secm_area->response.code) {
b9c9a21a
CH
577 case 0x0102:
578 case 0x0103:
495a5b45 579 ret = -EINVAL;
495a5b45 580 default:
b9c9a21a 581 ret = chsc_error_from_response(secm_area->response.code);
495a5b45 582 }
b9c9a21a
CH
583 if (ret != 0)
584 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
585 secm_area->response.code);
495a5b45
CH
586 return ret;
587}
588
589int
590chsc_secm(struct channel_subsystem *css, int enable)
591{
592 void *secm_area;
593 int ret;
594
595 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
596 if (!secm_area)
597 return -ENOMEM;
598
495a5b45
CH
599 if (enable && !css->cm_enabled) {
600 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
601 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
602 if (!css->cub_addr1 || !css->cub_addr2) {
603 free_page((unsigned long)css->cub_addr1);
604 free_page((unsigned long)css->cub_addr2);
605 free_page((unsigned long)secm_area);
495a5b45
CH
606 return -ENOMEM;
607 }
608 }
609 ret = __chsc_do_secm(css, enable, secm_area);
610 if (!ret) {
611 css->cm_enabled = enable;
612 if (css->cm_enabled) {
613 ret = chsc_add_cmg_attr(css);
614 if (ret) {
615 memset(secm_area, 0, PAGE_SIZE);
616 __chsc_do_secm(css, 0, secm_area);
617 css->cm_enabled = 0;
618 }
619 } else
620 chsc_remove_cmg_attr(css);
621 }
8c4941c5 622 if (!css->cm_enabled) {
495a5b45
CH
623 free_page((unsigned long)css->cub_addr1);
624 free_page((unsigned long)css->cub_addr2);
625 }
495a5b45
CH
626 free_page((unsigned long)secm_area);
627 return ret;
628}
629
e6b6e10a
PO
630int chsc_determine_channel_path_description(struct chp_id chpid,
631 struct channel_path_desc *desc)
1da177e4
LT
632{
633 int ccode, ret;
634
635 struct {
636 struct chsc_header request;
637 u32 : 24;
638 u32 first_chpid : 8;
639 u32 : 24;
640 u32 last_chpid : 8;
641 u32 zeroes1;
642 struct chsc_header response;
643 u32 zeroes2;
644 struct channel_path_desc desc;
0f008aa3 645 } __attribute__ ((packed)) *scpd_area;
1da177e4
LT
646
647 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
648 if (!scpd_area)
649 return -ENOMEM;
650
495a5b45
CH
651 scpd_area->request.length = 0x0010;
652 scpd_area->request.code = 0x0002;
1da177e4 653
f86635fa
PO
654 scpd_area->first_chpid = chpid.id;
655 scpd_area->last_chpid = chpid.id;
1da177e4
LT
656
657 ccode = chsc(scpd_area);
658 if (ccode > 0) {
659 ret = (ccode == 3) ? -ENODEV : -EBUSY;
660 goto out;
661 }
662
b9c9a21a
CH
663 ret = chsc_error_from_response(scpd_area->response.code);
664 if (ret == 0)
665 /* Success. */
1da177e4
LT
666 memcpy(desc, &scpd_area->desc,
667 sizeof(struct channel_path_desc));
b9c9a21a
CH
668 else
669 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
1da177e4 670 scpd_area->response.code);
1da177e4
LT
671out:
672 free_page((unsigned long)scpd_area);
673 return ret;
674}
675
495a5b45
CH
676static void
677chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
678 struct cmg_chars *chars)
679{
680 switch (chp->cmg) {
681 case 2:
682 case 3:
683 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
684 GFP_KERNEL);
685 if (chp->cmg_chars) {
686 int i, mask;
687 struct cmg_chars *cmg_chars;
688
689 cmg_chars = chp->cmg_chars;
690 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
691 mask = 0x80 >> (i + 3);
692 if (cmcv & mask)
693 cmg_chars->values[i] = chars->values[i];
694 else
695 cmg_chars->values[i] = 0;
696 }
697 }
698 break;
699 default:
700 /* No cmg-dependent data. */
701 break;
702 }
703}
704
e6b6e10a 705int chsc_get_channel_measurement_chars(struct channel_path *chp)
495a5b45
CH
706{
707 int ccode, ret;
708
709 struct {
710 struct chsc_header request;
711 u32 : 24;
712 u32 first_chpid : 8;
713 u32 : 24;
714 u32 last_chpid : 8;
715 u32 zeroes1;
716 struct chsc_header response;
717 u32 zeroes2;
718 u32 not_valid : 1;
719 u32 shared : 1;
720 u32 : 22;
721 u32 chpid : 8;
722 u32 cmcv : 5;
723 u32 : 11;
724 u32 cmgq : 8;
725 u32 cmg : 8;
726 u32 zeroes3;
727 u32 data[NR_MEASUREMENT_CHARS];
0f008aa3 728 } __attribute__ ((packed)) *scmc_area;
495a5b45
CH
729
730 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
731 if (!scmc_area)
732 return -ENOMEM;
733
734 scmc_area->request.length = 0x0010;
735 scmc_area->request.code = 0x0022;
736
f86635fa
PO
737 scmc_area->first_chpid = chp->chpid.id;
738 scmc_area->last_chpid = chp->chpid.id;
495a5b45
CH
739
740 ccode = chsc(scmc_area);
741 if (ccode > 0) {
742 ret = (ccode == 3) ? -ENODEV : -EBUSY;
743 goto out;
744 }
745
b9c9a21a
CH
746 ret = chsc_error_from_response(scmc_area->response.code);
747 if (ret == 0) {
748 /* Success. */
495a5b45
CH
749 if (!scmc_area->not_valid) {
750 chp->cmg = scmc_area->cmg;
751 chp->shared = scmc_area->shared;
752 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
753 (struct cmg_chars *)
754 &scmc_area->data);
755 } else {
756 chp->cmg = -1;
757 chp->shared = -1;
758 }
b9c9a21a
CH
759 } else {
760 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
495a5b45 761 scmc_area->response.code);
495a5b45
CH
762 }
763out:
764 free_page((unsigned long)scmc_area);
765 return ret;
766}
767
4434a38c 768int __init chsc_alloc_sei_area(void)
1da177e4 769{
c1156189
CH
770 int ret;
771
1da177e4 772 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
c1156189 773 if (!sei_page) {
e556bbbd
CH
774 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
775 "chsc machine checks!\n");
c1156189
CH
776 return -ENOMEM;
777 }
778 ret = s390_register_crw_handler(CRW_RSC_CSS, chsc_process_crw);
779 if (ret)
780 kfree(sei_page);
781 return ret;
1da177e4
LT
782}
783
4434a38c
CH
784void __init chsc_free_sei_area(void)
785{
c1156189 786 s390_unregister_crw_handler(CRW_RSC_CSS);
4434a38c
CH
787 kfree(sei_page);
788}
789
fb6958a5
CH
790int __init
791chsc_enable_facility(int operation_code)
792{
793 int ret;
794 struct {
795 struct chsc_header request;
796 u8 reserved1:4;
797 u8 format:4;
798 u8 reserved2;
799 u16 operation_code;
800 u32 reserved3;
801 u32 reserved4;
802 u32 operation_data_area[252];
803 struct chsc_header response;
804 u32 reserved5:4;
805 u32 format2:4;
806 u32 reserved6:24;
0f008aa3 807 } __attribute__ ((packed)) *sda_area;
fb6958a5
CH
808
809 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
810 if (!sda_area)
811 return -ENOMEM;
495a5b45
CH
812 sda_area->request.length = 0x0400;
813 sda_area->request.code = 0x0031;
fb6958a5
CH
814 sda_area->operation_code = operation_code;
815
816 ret = chsc(sda_area);
817 if (ret > 0) {
818 ret = (ret == 3) ? -ENODEV : -EBUSY;
819 goto out;
820 }
b9c9a21a 821
fb6958a5 822 switch (sda_area->response.code) {
b9c9a21a 823 case 0x0101:
fb6958a5
CH
824 ret = -EOPNOTSUPP;
825 break;
b9c9a21a
CH
826 default:
827 ret = chsc_error_from_response(sda_area->response.code);
fb6958a5 828 }
b9c9a21a
CH
829 if (ret != 0)
830 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
831 operation_code, sda_area->response.code);
fb6958a5
CH
832 out:
833 free_page((unsigned long)sda_area);
834 return ret;
835}
836
1da177e4
LT
837struct css_general_char css_general_characteristics;
838struct css_chsc_char css_chsc_characteristics;
839
840int __init
841chsc_determine_css_characteristics(void)
842{
843 int result;
844 struct {
845 struct chsc_header request;
846 u32 reserved1;
847 u32 reserved2;
848 u32 reserved3;
849 struct chsc_header response;
850 u32 reserved4;
851 u32 general_char[510];
852 u32 chsc_char[518];
0f008aa3 853 } __attribute__ ((packed)) *scsc_area;
1da177e4
LT
854
855 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
b9c9a21a 856 if (!scsc_area)
1da177e4 857 return -ENOMEM;
1da177e4 858
495a5b45
CH
859 scsc_area->request.length = 0x0010;
860 scsc_area->request.code = 0x0010;
1da177e4
LT
861
862 result = chsc(scsc_area);
863 if (result) {
b9c9a21a 864 result = (result == 3) ? -ENODEV : -EBUSY;
1da177e4
LT
865 goto exit;
866 }
867
b9c9a21a
CH
868 result = chsc_error_from_response(scsc_area->response.code);
869 if (result == 0) {
870 memcpy(&css_general_characteristics, scsc_area->general_char,
871 sizeof(css_general_characteristics));
872 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
873 sizeof(css_chsc_characteristics));
874 } else
875 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
876 scsc_area->response.code);
1da177e4
LT
877exit:
878 free_page ((unsigned long) scsc_area);
879 return result;
880}
881
882EXPORT_SYMBOL_GPL(css_general_characteristics);
883EXPORT_SYMBOL_GPL(css_chsc_characteristics);
d2fec595
MS
884
885int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
886{
887 struct {
888 struct chsc_header request;
889 unsigned int rsvd0;
890 unsigned int op : 8;
891 unsigned int rsvd1 : 8;
892 unsigned int ctrl : 16;
893 unsigned int rsvd2[5];
894 struct chsc_header response;
895 unsigned int rsvd3[7];
896 } __attribute__ ((packed)) *rr;
897 int rc;
898
899 memset(page, 0, PAGE_SIZE);
900 rr = page;
901 rr->request.length = 0x0020;
902 rr->request.code = 0x0033;
903 rr->op = op;
904 rr->ctrl = ctrl;
905 rc = chsc(rr);
906 if (rc)
907 return -EIO;
908 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
909 return rc;
910}
911
912int chsc_sstpi(void *page, void *result, size_t size)
913{
914 struct {
915 struct chsc_header request;
916 unsigned int rsvd0[3];
917 struct chsc_header response;
918 char data[size];
919 } __attribute__ ((packed)) *rr;
920 int rc;
921
922 memset(page, 0, PAGE_SIZE);
923 rr = page;
924 rr->request.length = 0x0010;
925 rr->request.code = 0x0038;
926 rc = chsc(rr);
927 if (rc)
928 return -EIO;
929 memcpy(result, &rr->data, size);
930 return (rr->response.code == 0x0001) ? 0 : -EIO;
931}
932
This page took 0.575831 seconds and 5 git commands to generate.