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