1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * S/390 common I/O routines -- channel subsystem call
4 *
5 * Copyright IBM Corp. 1999,2012
6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
7 * Cornelia Huck (cornelia.huck@de.ibm.com)
8 * Arnd Bergmann (arndb@de.ibm.com)
9 */
10
11 #define KMSG_COMPONENT "cio"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/init.h>
17 #include <linux/device.h>
18 #include <linux/mutex.h>
19 #include <linux/pci.h>
20
21 #include <asm/cio.h>
22 #include <asm/chpid.h>
23 #include <asm/chsc.h>
24 #include <asm/crw.h>
25 #include <asm/isc.h>
26 #include <asm/ebcdic.h>
27 #include <asm/ap.h>
28
29 #include "css.h"
30 #include "cio.h"
31 #include "cio_debug.h"
32 #include "ioasm.h"
33 #include "chp.h"
34 #include "chsc.h"
35
36 static void *sei_page;
37 static void *chsc_page;
38 static DEFINE_SPINLOCK(chsc_page_lock);
39
40 /**
41 * chsc_error_from_response() - convert a chsc response to an error
42 * @response: chsc response code
43 *
44 * Returns an appropriate Linux error code for @response.
45 */
chsc_error_from_response(int response)46 int chsc_error_from_response(int response)
47 {
48 switch (response) {
49 case 0x0001:
50 return 0;
51 case 0x0002:
52 case 0x0003:
53 case 0x0006:
54 case 0x0007:
55 case 0x0008:
56 case 0x000a:
57 case 0x0104:
58 return -EINVAL;
59 case 0x0004:
60 case 0x0106: /* "Wrong Channel Parm" for the op 0x003d */
61 return -EOPNOTSUPP;
62 case 0x000b:
63 case 0x0107: /* "Channel busy" for the op 0x003d */
64 return -EBUSY;
65 case 0x0100:
66 case 0x0102:
67 return -ENOMEM;
68 case 0x0108: /* "HW limit exceeded" for the op 0x003d */
69 return -EUSERS;
70 default:
71 return -EIO;
72 }
73 }
74 EXPORT_SYMBOL_GPL(chsc_error_from_response);
75
76 struct chsc_ssd_area {
77 struct chsc_header request;
78 u16 :10;
79 u16 ssid:2;
80 u16 :4;
81 u16 f_sch; /* first subchannel */
82 u16 :16;
83 u16 l_sch; /* last subchannel */
84 u32 :32;
85 struct chsc_header response;
86 u32 :32;
87 u8 sch_valid : 1;
88 u8 dev_valid : 1;
89 u8 st : 3; /* subchannel type */
90 u8 zeroes : 3;
91 u8 unit_addr; /* unit address */
92 u16 devno; /* device number */
93 u8 path_mask;
94 u8 fla_valid_mask;
95 u16 sch; /* subchannel */
96 u8 chpid[8]; /* chpids 0-7 */
97 u16 fla[8]; /* full link addresses 0-7 */
98 } __packed __aligned(PAGE_SIZE);
99
chsc_get_ssd_info(struct subchannel_id schid,struct chsc_ssd_info * ssd)100 int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
101 {
102 struct chsc_ssd_area *ssd_area;
103 unsigned long flags;
104 int ccode;
105 int ret;
106 int i;
107 int mask;
108
109 spin_lock_irqsave(&chsc_page_lock, flags);
110 memset(chsc_page, 0, PAGE_SIZE);
111 ssd_area = chsc_page;
112 ssd_area->request.length = 0x0010;
113 ssd_area->request.code = 0x0004;
114 ssd_area->ssid = schid.ssid;
115 ssd_area->f_sch = schid.sch_no;
116 ssd_area->l_sch = schid.sch_no;
117
118 ccode = chsc(ssd_area);
119 /* Check response. */
120 if (ccode > 0) {
121 ret = (ccode == 3) ? -ENODEV : -EBUSY;
122 goto out;
123 }
124 ret = chsc_error_from_response(ssd_area->response.code);
125 if (ret != 0) {
126 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
127 schid.ssid, schid.sch_no,
128 ssd_area->response.code);
129 goto out;
130 }
131 if (!ssd_area->sch_valid) {
132 ret = -ENODEV;
133 goto out;
134 }
135 /* Copy data */
136 ret = 0;
137 memset(ssd, 0, sizeof(struct chsc_ssd_info));
138 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
139 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
140 goto out;
141 ssd->path_mask = ssd_area->path_mask;
142 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
143 for (i = 0; i < 8; i++) {
144 mask = 0x80 >> i;
145 if (ssd_area->path_mask & mask) {
146 chp_id_init(&ssd->chpid[i]);
147 ssd->chpid[i].id = ssd_area->chpid[i];
148 }
149 if (ssd_area->fla_valid_mask & mask)
150 ssd->fla[i] = ssd_area->fla[i];
151 }
152 out:
153 spin_unlock_irqrestore(&chsc_page_lock, flags);
154 return ret;
155 }
156
157 /**
158 * chsc_ssqd() - store subchannel QDIO data (SSQD)
159 * @schid: id of the subchannel on which SSQD is performed
160 * @ssqd: request and response block for SSQD
161 *
162 * Returns 0 on success.
163 */
chsc_ssqd(struct subchannel_id schid,struct chsc_ssqd_area * ssqd)164 int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
165 {
166 memset(ssqd, 0, sizeof(*ssqd));
167 ssqd->request.length = 0x0010;
168 ssqd->request.code = 0x0024;
169 ssqd->first_sch = schid.sch_no;
170 ssqd->last_sch = schid.sch_no;
171 ssqd->ssid = schid.ssid;
172
173 if (chsc(ssqd))
174 return -EIO;
175
176 return chsc_error_from_response(ssqd->response.code);
177 }
178 EXPORT_SYMBOL_GPL(chsc_ssqd);
179
180 /**
181 * chsc_sadc() - set adapter device controls (SADC)
182 * @schid: id of the subchannel on which SADC is performed
183 * @scssc: request and response block for SADC
184 * @summary_indicator_addr: summary indicator address
185 * @subchannel_indicator_addr: subchannel indicator address
186 * @isc: Interruption Subclass for this subchannel
187 *
188 * Returns 0 on success.
189 */
chsc_sadc(struct subchannel_id schid,struct chsc_scssc_area * scssc,u64 summary_indicator_addr,u64 subchannel_indicator_addr,u8 isc)190 int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
191 u64 summary_indicator_addr, u64 subchannel_indicator_addr, u8 isc)
192 {
193 memset(scssc, 0, sizeof(*scssc));
194 scssc->request.length = 0x0fe0;
195 scssc->request.code = 0x0021;
196 scssc->operation_code = 0;
197
198 scssc->summary_indicator_addr = summary_indicator_addr;
199 scssc->subchannel_indicator_addr = subchannel_indicator_addr;
200
201 scssc->ks = PAGE_DEFAULT_KEY >> 4;
202 scssc->kc = PAGE_DEFAULT_KEY >> 4;
203 scssc->isc = isc;
204 scssc->schid = schid;
205
206 /* enable the time delay disablement facility */
207 if (css_general_characteristics.aif_tdd)
208 scssc->word_with_d_bit = 0x10000000;
209
210 if (chsc(scssc))
211 return -EIO;
212
213 return chsc_error_from_response(scssc->response.code);
214 }
215 EXPORT_SYMBOL_GPL(chsc_sadc);
216
s390_subchannel_remove_chpid(struct subchannel * sch,void * data)217 static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
218 {
219 spin_lock_irq(sch->lock);
220 if (sch->driver && sch->driver->chp_event)
221 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
222 goto out_unreg;
223 spin_unlock_irq(sch->lock);
224 return 0;
225
226 out_unreg:
227 sch->lpm = 0;
228 spin_unlock_irq(sch->lock);
229 css_schedule_eval(sch->schid);
230 return 0;
231 }
232
chsc_chp_offline(struct chp_id chpid)233 void chsc_chp_offline(struct chp_id chpid)
234 {
235 struct channel_path *chp = chpid_to_chp(chpid);
236 struct chp_link link;
237 char dbf_txt[15];
238
239 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
240 CIO_TRACE_EVENT(2, dbf_txt);
241
242 if (chp_get_status(chpid) <= 0)
243 return;
244 memset(&link, 0, sizeof(struct chp_link));
245 link.chpid = chpid;
246 /* Wait until previous actions have settled. */
247 css_wait_for_slow_path();
248
249 mutex_lock(&chp->lock);
250 chp_update_desc(chp);
251 mutex_unlock(&chp->lock);
252
253 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
254 }
255
__s390_process_res_acc(struct subchannel * sch,void * data)256 static int __s390_process_res_acc(struct subchannel *sch, void *data)
257 {
258 spin_lock_irq(sch->lock);
259 if (sch->driver && sch->driver->chp_event)
260 sch->driver->chp_event(sch, data, CHP_ONLINE);
261 spin_unlock_irq(sch->lock);
262
263 return 0;
264 }
265
s390_process_res_acc(struct chp_link * link)266 static void s390_process_res_acc(struct chp_link *link)
267 {
268 char dbf_txt[15];
269
270 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
271 link->chpid.id);
272 CIO_TRACE_EVENT( 2, dbf_txt);
273 if (link->fla != 0) {
274 sprintf(dbf_txt, "fla%x", link->fla);
275 CIO_TRACE_EVENT( 2, dbf_txt);
276 }
277 /* Wait until previous actions have settled. */
278 css_wait_for_slow_path();
279 /*
280 * I/O resources may have become accessible.
281 * Scan through all subchannels that may be concerned and
282 * do a validation on those.
283 * The more information we have (info), the less scanning
284 * will we have to do.
285 */
286 for_each_subchannel_staged(__s390_process_res_acc, NULL, link);
287 css_schedule_reprobe();
288 }
289
290 struct chsc_sei_nt0_area {
291 u8 flags;
292 u8 vf; /* validity flags */
293 u8 rs; /* reporting source */
294 u8 cc; /* content code */
295 u16 fla; /* full link address */
296 u16 rsid; /* reporting source id */
297 u32 reserved1;
298 u32 reserved2;
299 /* ccdf has to be big enough for a link-incident record */
300 u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
301 } __packed;
302
303 struct chsc_sei_nt2_area {
304 u8 flags; /* p and v bit */
305 u8 reserved1;
306 u8 reserved2;
307 u8 cc; /* content code */
308 u32 reserved3[13];
309 u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
310 } __packed;
311
312 #define CHSC_SEI_NT0 (1ULL << 63)
313 #define CHSC_SEI_NT2 (1ULL << 61)
314
315 struct chsc_sei {
316 struct chsc_header request;
317 u32 reserved1;
318 u64 ntsm; /* notification type mask */
319 struct chsc_header response;
320 u32 :24;
321 u8 nt;
322 union {
323 struct chsc_sei_nt0_area nt0_area;
324 struct chsc_sei_nt2_area nt2_area;
325 u8 nt_area[PAGE_SIZE - 24];
326 } u;
327 } __packed __aligned(PAGE_SIZE);
328
329 /*
330 * Link Incident Record as defined in SA22-7202, "ESCON I/O Interface"
331 */
332
333 #define LIR_IQ_CLASS_INFO 0
334 #define LIR_IQ_CLASS_DEGRADED 1
335 #define LIR_IQ_CLASS_NOT_OPERATIONAL 2
336
337 struct lir {
338 struct {
339 u32 null:1;
340 u32 reserved:3;
341 u32 class:2;
342 u32 reserved2:2;
343 } __packed iq;
344 u32 ic:8;
345 u32 reserved:16;
346 struct node_descriptor incident_node;
347 struct node_descriptor attached_node;
348 u8 reserved2[32];
349 } __packed;
350
351 #define PARAMS_LEN 10 /* PARAMS=xx,xxxxxx */
352 #define NODEID_LEN 35 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
353
354 /* Copy EBCIDC text, convert to ASCII and optionally add delimiter. */
store_ebcdic(char * dest,const char * src,unsigned long len,char delim)355 static char *store_ebcdic(char *dest, const char *src, unsigned long len,
356 char delim)
357 {
358 memcpy(dest, src, len);
359 EBCASC(dest, len);
360
361 if (delim)
362 dest[len++] = delim;
363
364 return dest + len;
365 }
366
367 /* Format node ID and parameters for output in LIR log message. */
format_node_data(char * params,char * id,struct node_descriptor * nd)368 static void format_node_data(char *params, char *id, struct node_descriptor *nd)
369 {
370 memset(params, 0, PARAMS_LEN);
371 memset(id, 0, NODEID_LEN);
372
373 if (nd->validity != ND_VALIDITY_VALID) {
374 strncpy(params, "n/a", PARAMS_LEN - 1);
375 strncpy(id, "n/a", NODEID_LEN - 1);
376 return;
377 }
378
379 /* PARAMS=xx,xxxxxx */
380 snprintf(params, PARAMS_LEN, "%02x,%06x", nd->byte0, nd->params);
381 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
382 id = store_ebcdic(id, nd->type, sizeof(nd->type), '/');
383 id = store_ebcdic(id, nd->model, sizeof(nd->model), ',');
384 id = store_ebcdic(id, nd->manufacturer, sizeof(nd->manufacturer), '.');
385 id = store_ebcdic(id, nd->plant, sizeof(nd->plant), 0);
386 id = store_ebcdic(id, nd->seq, sizeof(nd->seq), ',');
387 sprintf(id, "%04X", nd->tag);
388 }
389
chsc_process_sei_link_incident(struct chsc_sei_nt0_area * sei_area)390 static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
391 {
392 struct lir *lir = (struct lir *) &sei_area->ccdf;
393 char iuparams[PARAMS_LEN], iunodeid[NODEID_LEN], auparams[PARAMS_LEN],
394 aunodeid[NODEID_LEN];
395
396 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x, iq=%02x)\n",
397 sei_area->rs, sei_area->rsid, sei_area->ccdf[0]);
398
399 /* Ignore NULL Link Incident Records. */
400 if (lir->iq.null)
401 return;
402
403 /* Inform user that a link requires maintenance actions because it has
404 * become degraded or not operational. Note that this log message is
405 * the primary intention behind a Link Incident Record. */
406
407 format_node_data(iuparams, iunodeid, &lir->incident_node);
408 format_node_data(auparams, aunodeid, &lir->attached_node);
409
410 switch (lir->iq.class) {
411 case LIR_IQ_CLASS_DEGRADED:
412 pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x "
413 "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
414 sei_area->rs, sei_area->rsid, lir->ic, iuparams,
415 iunodeid, auparams, aunodeid);
416 break;
417 case LIR_IQ_CLASS_NOT_OPERATIONAL:
418 pr_err("Link stopped: RS=%02x RSID=%04x IC=%02x "
419 "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
420 sei_area->rs, sei_area->rsid, lir->ic, iuparams,
421 iunodeid, auparams, aunodeid);
422 break;
423 default:
424 break;
425 }
426 }
427
chsc_process_sei_res_acc(struct chsc_sei_nt0_area * sei_area)428 static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
429 {
430 struct channel_path *chp;
431 struct chp_link link;
432 struct chp_id chpid;
433 int status;
434
435 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
436 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
437 if (sei_area->rs != 4)
438 return;
439 chp_id_init(&chpid);
440 chpid.id = sei_area->rsid;
441 /* allocate a new channel path structure, if needed */
442 status = chp_get_status(chpid);
443 if (!status)
444 return;
445
446 if (status < 0) {
447 chp_new(chpid);
448 } else {
449 chp = chpid_to_chp(chpid);
450 mutex_lock(&chp->lock);
451 chp_update_desc(chp);
452 mutex_unlock(&chp->lock);
453 }
454 memset(&link, 0, sizeof(struct chp_link));
455 link.chpid = chpid;
456 if ((sei_area->vf & 0xc0) != 0) {
457 link.fla = sei_area->fla;
458 if ((sei_area->vf & 0xc0) == 0xc0)
459 /* full link address */
460 link.fla_mask = 0xffff;
461 else
462 /* link address */
463 link.fla_mask = 0xff00;
464 }
465 s390_process_res_acc(&link);
466 }
467
chsc_process_sei_chp_avail(struct chsc_sei_nt0_area * sei_area)468 static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
469 {
470 struct channel_path *chp;
471 struct chp_id chpid;
472 u8 *data;
473 int num;
474
475 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
476 if (sei_area->rs != 0)
477 return;
478 data = sei_area->ccdf;
479 chp_id_init(&chpid);
480 for (num = 0; num <= __MAX_CHPID; num++) {
481 if (!chp_test_bit(data, num))
482 continue;
483 chpid.id = num;
484
485 CIO_CRW_EVENT(4, "Update information for channel path "
486 "%x.%02x\n", chpid.cssid, chpid.id);
487 chp = chpid_to_chp(chpid);
488 if (!chp) {
489 chp_new(chpid);
490 continue;
491 }
492 mutex_lock(&chp->lock);
493 chp_update_desc(chp);
494 mutex_unlock(&chp->lock);
495 }
496 }
497
498 struct chp_config_data {
499 u8 map[32];
500 u8 op;
501 u8 pc;
502 };
503
chsc_process_sei_chp_config(struct chsc_sei_nt0_area * sei_area)504 static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
505 {
506 struct chp_config_data *data;
507 struct chp_id chpid;
508 int num;
509 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
510
511 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
512 if (sei_area->rs != 0)
513 return;
514 data = (struct chp_config_data *) &(sei_area->ccdf);
515 chp_id_init(&chpid);
516 for (num = 0; num <= __MAX_CHPID; num++) {
517 if (!chp_test_bit(data->map, num))
518 continue;
519 chpid.id = num;
520 pr_notice("Processing %s for channel path %x.%02x\n",
521 events[data->op], chpid.cssid, chpid.id);
522 switch (data->op) {
523 case 0:
524 chp_cfg_schedule(chpid, 1);
525 break;
526 case 1:
527 chp_cfg_schedule(chpid, 0);
528 break;
529 case 2:
530 chp_cfg_cancel_deconfigure(chpid);
531 break;
532 }
533 }
534 }
535
chsc_process_sei_scm_change(struct chsc_sei_nt0_area * sei_area)536 static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
537 {
538 int ret;
539
540 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
541 if (sei_area->rs != 7)
542 return;
543
544 ret = scm_update_information();
545 if (ret)
546 CIO_CRW_EVENT(0, "chsc: updating change notification"
547 " failed (rc=%d).\n", ret);
548 }
549
chsc_process_sei_scm_avail(struct chsc_sei_nt0_area * sei_area)550 static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
551 {
552 int ret;
553
554 CIO_CRW_EVENT(4, "chsc: scm available information\n");
555 if (sei_area->rs != 7)
556 return;
557
558 ret = scm_process_availability_information();
559 if (ret)
560 CIO_CRW_EVENT(0, "chsc: process availability information"
561 " failed (rc=%d).\n", ret);
562 }
563
chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area * sei_area)564 static void chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area *sei_area)
565 {
566 CIO_CRW_EVENT(3, "chsc: ap config changed\n");
567 if (sei_area->rs != 5)
568 return;
569
570 ap_bus_cfg_chg();
571 }
572
chsc_process_sei_nt2(struct chsc_sei_nt2_area * sei_area)573 static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
574 {
575 switch (sei_area->cc) {
576 case 1:
577 zpci_event_error(sei_area->ccdf);
578 break;
579 case 2:
580 zpci_event_availability(sei_area->ccdf);
581 break;
582 default:
583 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
584 sei_area->cc);
585 break;
586 }
587 }
588
chsc_process_sei_nt0(struct chsc_sei_nt0_area * sei_area)589 static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
590 {
591 /* which kind of information was stored? */
592 switch (sei_area->cc) {
593 case 1: /* link incident*/
594 chsc_process_sei_link_incident(sei_area);
595 break;
596 case 2: /* i/o resource accessibility */
597 chsc_process_sei_res_acc(sei_area);
598 break;
599 case 3: /* ap config changed */
600 chsc_process_sei_ap_cfg_chg(sei_area);
601 break;
602 case 7: /* channel-path-availability information */
603 chsc_process_sei_chp_avail(sei_area);
604 break;
605 case 8: /* channel-path-configuration notification */
606 chsc_process_sei_chp_config(sei_area);
607 break;
608 case 12: /* scm change notification */
609 chsc_process_sei_scm_change(sei_area);
610 break;
611 case 14: /* scm available notification */
612 chsc_process_sei_scm_avail(sei_area);
613 break;
614 default: /* other stuff */
615 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
616 sei_area->cc);
617 break;
618 }
619
620 /* Check if we might have lost some information. */
621 if (sei_area->flags & 0x40) {
622 CIO_CRW_EVENT(2, "chsc: event overflow\n");
623 css_schedule_eval_all();
624 }
625 }
626
chsc_process_event_information(struct chsc_sei * sei,u64 ntsm)627 static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
628 {
629 static int ntsm_unsupported;
630
631 while (true) {
632 memset(sei, 0, sizeof(*sei));
633 sei->request.length = 0x0010;
634 sei->request.code = 0x000e;
635 if (!ntsm_unsupported)
636 sei->ntsm = ntsm;
637
638 if (chsc(sei))
639 break;
640
641 if (sei->response.code != 0x0001) {
642 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x, ntsm=%llx)\n",
643 sei->response.code, sei->ntsm);
644
645 if (sei->response.code == 3 && sei->ntsm) {
646 /* Fallback for old firmware. */
647 ntsm_unsupported = 1;
648 continue;
649 }
650 break;
651 }
652
653 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
654 switch (sei->nt) {
655 case 0:
656 chsc_process_sei_nt0(&sei->u.nt0_area);
657 break;
658 case 2:
659 chsc_process_sei_nt2(&sei->u.nt2_area);
660 break;
661 default:
662 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
663 break;
664 }
665
666 if (!(sei->u.nt0_area.flags & 0x80))
667 break;
668 }
669 }
670
671 /*
672 * Handle channel subsystem related CRWs.
673 * Use store event information to find out what's going on.
674 *
675 * Note: Access to sei_page is serialized through machine check handler
676 * thread, so no need for locking.
677 */
chsc_process_crw(struct crw * crw0,struct crw * crw1,int overflow)678 static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
679 {
680 struct chsc_sei *sei = sei_page;
681
682 if (overflow) {
683 css_schedule_eval_all();
684 return;
685 }
686 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
687 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
688 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
689 crw0->erc, crw0->rsid);
690
691 CIO_TRACE_EVENT(2, "prcss");
692 chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
693 }
694
chsc_chp_online(struct chp_id chpid)695 void chsc_chp_online(struct chp_id chpid)
696 {
697 struct channel_path *chp = chpid_to_chp(chpid);
698 struct chp_link link;
699 char dbf_txt[15];
700
701 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
702 CIO_TRACE_EVENT(2, dbf_txt);
703
704 if (chp_get_status(chpid) != 0) {
705 memset(&link, 0, sizeof(struct chp_link));
706 link.chpid = chpid;
707 /* Wait until previous actions have settled. */
708 css_wait_for_slow_path();
709
710 mutex_lock(&chp->lock);
711 chp_update_desc(chp);
712 mutex_unlock(&chp->lock);
713
714 for_each_subchannel_staged(__s390_process_res_acc, NULL,
715 &link);
716 css_schedule_reprobe();
717 }
718 }
719
__s390_subchannel_vary_chpid(struct subchannel * sch,struct chp_id chpid,int on)720 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
721 struct chp_id chpid, int on)
722 {
723 unsigned long flags;
724 struct chp_link link;
725
726 memset(&link, 0, sizeof(struct chp_link));
727 link.chpid = chpid;
728 spin_lock_irqsave(sch->lock, flags);
729 if (sch->driver && sch->driver->chp_event)
730 sch->driver->chp_event(sch, &link,
731 on ? CHP_VARY_ON : CHP_VARY_OFF);
732 spin_unlock_irqrestore(sch->lock, flags);
733 }
734
s390_subchannel_vary_chpid_off(struct subchannel * sch,void * data)735 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
736 {
737 struct chp_id *chpid = data;
738
739 __s390_subchannel_vary_chpid(sch, *chpid, 0);
740 return 0;
741 }
742
s390_subchannel_vary_chpid_on(struct subchannel * sch,void * data)743 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
744 {
745 struct chp_id *chpid = data;
746
747 __s390_subchannel_vary_chpid(sch, *chpid, 1);
748 return 0;
749 }
750
751 /**
752 * chsc_chp_vary - propagate channel-path vary operation to subchannels
753 * @chpid: channl-path ID
754 * @on: non-zero for vary online, zero for vary offline
755 */
chsc_chp_vary(struct chp_id chpid,int on)756 int chsc_chp_vary(struct chp_id chpid, int on)
757 {
758 struct channel_path *chp = chpid_to_chp(chpid);
759
760 /*
761 * Redo PathVerification on the devices the chpid connects to
762 */
763 if (on) {
764 /* Try to update the channel path description. */
765 chp_update_desc(chp);
766 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
767 NULL, &chpid);
768 css_schedule_reprobe();
769 } else
770 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
771 NULL, &chpid);
772
773 return 0;
774 }
775
776 static void
chsc_remove_cmg_attr(struct channel_subsystem * css)777 chsc_remove_cmg_attr(struct channel_subsystem *css)
778 {
779 int i;
780
781 for (i = 0; i <= __MAX_CHPID; i++) {
782 if (!css->chps[i])
783 continue;
784 chp_remove_cmg_attr(css->chps[i]);
785 }
786 }
787
788 static int
chsc_add_cmg_attr(struct channel_subsystem * css)789 chsc_add_cmg_attr(struct channel_subsystem *css)
790 {
791 int i, ret;
792
793 ret = 0;
794 for (i = 0; i <= __MAX_CHPID; i++) {
795 if (!css->chps[i])
796 continue;
797 ret = chp_add_cmg_attr(css->chps[i]);
798 if (ret)
799 goto cleanup;
800 }
801 return ret;
802 cleanup:
803 for (--i; i >= 0; i--) {
804 if (!css->chps[i])
805 continue;
806 chp_remove_cmg_attr(css->chps[i]);
807 }
808 return ret;
809 }
810
__chsc_do_secm(struct channel_subsystem * css,int enable)811 int __chsc_do_secm(struct channel_subsystem *css, int enable)
812 {
813 struct {
814 struct chsc_header request;
815 u32 operation_code : 2;
816 u32 : 30;
817 u32 key : 4;
818 u32 : 28;
819 u32 zeroes1;
820 u32 cub_addr1;
821 u32 zeroes2;
822 u32 cub_addr2;
823 u32 reserved[13];
824 struct chsc_header response;
825 u32 status : 8;
826 u32 : 4;
827 u32 fmt : 4;
828 u32 : 16;
829 } *secm_area;
830 unsigned long flags;
831 int ret, ccode;
832
833 spin_lock_irqsave(&chsc_page_lock, flags);
834 memset(chsc_page, 0, PAGE_SIZE);
835 secm_area = chsc_page;
836 secm_area->request.length = 0x0050;
837 secm_area->request.code = 0x0016;
838
839 secm_area->key = PAGE_DEFAULT_KEY >> 4;
840 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
841 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
842
843 secm_area->operation_code = enable ? 0 : 1;
844
845 ccode = chsc(secm_area);
846 if (ccode > 0) {
847 ret = (ccode == 3) ? -ENODEV : -EBUSY;
848 goto out;
849 }
850
851 switch (secm_area->response.code) {
852 case 0x0102:
853 case 0x0103:
854 ret = -EINVAL;
855 break;
856 default:
857 ret = chsc_error_from_response(secm_area->response.code);
858 }
859 if (ret != 0)
860 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
861 secm_area->response.code);
862 out:
863 spin_unlock_irqrestore(&chsc_page_lock, flags);
864 return ret;
865 }
866
867 int
chsc_secm(struct channel_subsystem * css,int enable)868 chsc_secm(struct channel_subsystem *css, int enable)
869 {
870 int ret;
871
872 if (enable && !css->cm_enabled) {
873 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
874 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
875 if (!css->cub_addr1 || !css->cub_addr2) {
876 free_page((unsigned long)css->cub_addr1);
877 free_page((unsigned long)css->cub_addr2);
878 return -ENOMEM;
879 }
880 }
881 ret = __chsc_do_secm(css, enable);
882 if (!ret) {
883 css->cm_enabled = enable;
884 if (css->cm_enabled) {
885 ret = chsc_add_cmg_attr(css);
886 if (ret) {
887 __chsc_do_secm(css, 0);
888 css->cm_enabled = 0;
889 }
890 } else
891 chsc_remove_cmg_attr(css);
892 }
893 if (!css->cm_enabled) {
894 free_page((unsigned long)css->cub_addr1);
895 free_page((unsigned long)css->cub_addr2);
896 }
897 return ret;
898 }
899
chsc_determine_channel_path_desc(struct chp_id chpid,int fmt,int rfmt,int c,int m,void * page)900 int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
901 int c, int m, void *page)
902 {
903 struct chsc_scpd *scpd_area;
904 int ccode, ret;
905
906 if ((rfmt == 1 || rfmt == 0) && c == 1 &&
907 !css_general_characteristics.fcs)
908 return -EINVAL;
909 if ((rfmt == 2) && !css_general_characteristics.cib)
910 return -EINVAL;
911 if ((rfmt == 3) && !css_general_characteristics.util_str)
912 return -EINVAL;
913
914 memset(page, 0, PAGE_SIZE);
915 scpd_area = page;
916 scpd_area->request.length = 0x0010;
917 scpd_area->request.code = 0x0002;
918 scpd_area->cssid = chpid.cssid;
919 scpd_area->first_chpid = chpid.id;
920 scpd_area->last_chpid = chpid.id;
921 scpd_area->m = m;
922 scpd_area->c = c;
923 scpd_area->fmt = fmt;
924 scpd_area->rfmt = rfmt;
925
926 ccode = chsc(scpd_area);
927 if (ccode > 0)
928 return (ccode == 3) ? -ENODEV : -EBUSY;
929
930 ret = chsc_error_from_response(scpd_area->response.code);
931 if (ret)
932 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
933 scpd_area->response.code);
934 return ret;
935 }
936 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
937
938 #define chsc_det_chp_desc(FMT, c) \
939 int chsc_determine_fmt##FMT##_channel_path_desc( \
940 struct chp_id chpid, struct channel_path_desc_fmt##FMT *desc) \
941 { \
942 struct chsc_scpd *scpd_area; \
943 unsigned long flags; \
944 int ret; \
945 \
946 spin_lock_irqsave(&chsc_page_lock, flags); \
947 scpd_area = chsc_page; \
948 ret = chsc_determine_channel_path_desc(chpid, 0, FMT, c, 0, \
949 scpd_area); \
950 if (ret) \
951 goto out; \
952 \
953 memcpy(desc, scpd_area->data, sizeof(*desc)); \
954 out: \
955 spin_unlock_irqrestore(&chsc_page_lock, flags); \
956 return ret; \
957 }
958
959 chsc_det_chp_desc(0, 0)
960 chsc_det_chp_desc(1, 1)
961 chsc_det_chp_desc(3, 0)
962
963 static void
chsc_initialize_cmg_chars(struct channel_path * chp,u8 cmcv,struct cmg_chars * chars)964 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
965 struct cmg_chars *chars)
966 {
967 int i, mask;
968
969 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
970 mask = 0x80 >> (i + 3);
971 if (cmcv & mask)
972 chp->cmg_chars.values[i] = chars->values[i];
973 else
974 chp->cmg_chars.values[i] = 0;
975 }
976 }
977
chsc_get_channel_measurement_chars(struct channel_path * chp)978 int chsc_get_channel_measurement_chars(struct channel_path *chp)
979 {
980 unsigned long flags;
981 int ccode, ret;
982
983 struct {
984 struct chsc_header request;
985 u32 : 24;
986 u32 first_chpid : 8;
987 u32 : 24;
988 u32 last_chpid : 8;
989 u32 zeroes1;
990 struct chsc_header response;
991 u32 zeroes2;
992 u32 not_valid : 1;
993 u32 shared : 1;
994 u32 : 22;
995 u32 chpid : 8;
996 u32 cmcv : 5;
997 u32 : 11;
998 u32 cmgq : 8;
999 u32 cmg : 8;
1000 u32 zeroes3;
1001 u32 data[NR_MEASUREMENT_CHARS];
1002 } *scmc_area;
1003
1004 chp->shared = -1;
1005 chp->cmg = -1;
1006
1007 if (!css_chsc_characteristics.scmc || !css_chsc_characteristics.secm)
1008 return -EINVAL;
1009
1010 spin_lock_irqsave(&chsc_page_lock, flags);
1011 memset(chsc_page, 0, PAGE_SIZE);
1012 scmc_area = chsc_page;
1013 scmc_area->request.length = 0x0010;
1014 scmc_area->request.code = 0x0022;
1015 scmc_area->first_chpid = chp->chpid.id;
1016 scmc_area->last_chpid = chp->chpid.id;
1017
1018 ccode = chsc(scmc_area);
1019 if (ccode > 0) {
1020 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1021 goto out;
1022 }
1023
1024 ret = chsc_error_from_response(scmc_area->response.code);
1025 if (ret) {
1026 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
1027 scmc_area->response.code);
1028 goto out;
1029 }
1030 if (scmc_area->not_valid)
1031 goto out;
1032
1033 chp->cmg = scmc_area->cmg;
1034 chp->shared = scmc_area->shared;
1035 if (chp->cmg != 2 && chp->cmg != 3) {
1036 /* No cmg-dependent data. */
1037 goto out;
1038 }
1039 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1040 (struct cmg_chars *) &scmc_area->data);
1041 out:
1042 spin_unlock_irqrestore(&chsc_page_lock, flags);
1043 return ret;
1044 }
1045
chsc_init(void)1046 int __init chsc_init(void)
1047 {
1048 int ret;
1049
1050 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1051 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1052 if (!sei_page || !chsc_page) {
1053 ret = -ENOMEM;
1054 goto out_err;
1055 }
1056 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
1057 if (ret)
1058 goto out_err;
1059 return ret;
1060 out_err:
1061 free_page((unsigned long)chsc_page);
1062 free_page((unsigned long)sei_page);
1063 return ret;
1064 }
1065
chsc_init_cleanup(void)1066 void __init chsc_init_cleanup(void)
1067 {
1068 crw_unregister_handler(CRW_RSC_CSS);
1069 free_page((unsigned long)chsc_page);
1070 free_page((unsigned long)sei_page);
1071 }
1072
__chsc_enable_facility(struct chsc_sda_area * sda_area,int operation_code)1073 int __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code)
1074 {
1075 int ret;
1076
1077 sda_area->request.length = 0x0400;
1078 sda_area->request.code = 0x0031;
1079 sda_area->operation_code = operation_code;
1080
1081 ret = chsc(sda_area);
1082 if (ret > 0) {
1083 ret = (ret == 3) ? -ENODEV : -EBUSY;
1084 goto out;
1085 }
1086
1087 switch (sda_area->response.code) {
1088 case 0x0101:
1089 ret = -EOPNOTSUPP;
1090 break;
1091 default:
1092 ret = chsc_error_from_response(sda_area->response.code);
1093 }
1094 out:
1095 return ret;
1096 }
1097
chsc_enable_facility(int operation_code)1098 int chsc_enable_facility(int operation_code)
1099 {
1100 struct chsc_sda_area *sda_area;
1101 unsigned long flags;
1102 int ret;
1103
1104 spin_lock_irqsave(&chsc_page_lock, flags);
1105 memset(chsc_page, 0, PAGE_SIZE);
1106 sda_area = chsc_page;
1107
1108 ret = __chsc_enable_facility(sda_area, operation_code);
1109 if (ret != 0)
1110 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1111 operation_code, sda_area->response.code);
1112
1113 spin_unlock_irqrestore(&chsc_page_lock, flags);
1114 return ret;
1115 }
1116
chsc_get_cssid_iid(int idx,u8 * cssid,u8 * iid)1117 int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid)
1118 {
1119 struct {
1120 struct chsc_header request;
1121 u8 atype;
1122 u32 : 24;
1123 u32 reserved1[6];
1124 struct chsc_header response;
1125 u32 reserved2[3];
1126 struct {
1127 u8 cssid;
1128 u8 iid;
1129 u32 : 16;
1130 } list[0];
1131 } *sdcal_area;
1132 int ret;
1133
1134 spin_lock_irq(&chsc_page_lock);
1135 memset(chsc_page, 0, PAGE_SIZE);
1136 sdcal_area = chsc_page;
1137 sdcal_area->request.length = 0x0020;
1138 sdcal_area->request.code = 0x0034;
1139 sdcal_area->atype = 4;
1140
1141 ret = chsc(sdcal_area);
1142 if (ret) {
1143 ret = (ret == 3) ? -ENODEV : -EBUSY;
1144 goto exit;
1145 }
1146
1147 ret = chsc_error_from_response(sdcal_area->response.code);
1148 if (ret) {
1149 CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
1150 sdcal_area->response.code);
1151 goto exit;
1152 }
1153
1154 if ((addr_t) &sdcal_area->list[idx] <
1155 (addr_t) &sdcal_area->response + sdcal_area->response.length) {
1156 *cssid = sdcal_area->list[idx].cssid;
1157 *iid = sdcal_area->list[idx].iid;
1158 }
1159 else
1160 ret = -ENODEV;
1161 exit:
1162 spin_unlock_irq(&chsc_page_lock);
1163 return ret;
1164 }
1165
1166 struct css_general_char css_general_characteristics;
1167 struct css_chsc_char css_chsc_characteristics;
1168
1169 int __init
chsc_determine_css_characteristics(void)1170 chsc_determine_css_characteristics(void)
1171 {
1172 unsigned long flags;
1173 int result;
1174 struct {
1175 struct chsc_header request;
1176 u32 reserved1;
1177 u32 reserved2;
1178 u32 reserved3;
1179 struct chsc_header response;
1180 u32 reserved4;
1181 u32 general_char[510];
1182 u32 chsc_char[508];
1183 } *scsc_area;
1184
1185 spin_lock_irqsave(&chsc_page_lock, flags);
1186 memset(chsc_page, 0, PAGE_SIZE);
1187 scsc_area = chsc_page;
1188 scsc_area->request.length = 0x0010;
1189 scsc_area->request.code = 0x0010;
1190
1191 result = chsc(scsc_area);
1192 if (result) {
1193 result = (result == 3) ? -ENODEV : -EBUSY;
1194 goto exit;
1195 }
1196
1197 result = chsc_error_from_response(scsc_area->response.code);
1198 if (result == 0) {
1199 memcpy(&css_general_characteristics, scsc_area->general_char,
1200 sizeof(css_general_characteristics));
1201 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1202 sizeof(css_chsc_characteristics));
1203 } else
1204 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1205 scsc_area->response.code);
1206 exit:
1207 spin_unlock_irqrestore(&chsc_page_lock, flags);
1208 return result;
1209 }
1210
1211 EXPORT_SYMBOL_GPL(css_general_characteristics);
1212 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
1213
chsc_sstpc(void * page,unsigned int op,u16 ctrl,u64 * clock_delta)1214 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta)
1215 {
1216 struct {
1217 struct chsc_header request;
1218 unsigned int rsvd0;
1219 unsigned int op : 8;
1220 unsigned int rsvd1 : 8;
1221 unsigned int ctrl : 16;
1222 unsigned int rsvd2[5];
1223 struct chsc_header response;
1224 unsigned int rsvd3[3];
1225 u64 clock_delta;
1226 unsigned int rsvd4[2];
1227 } *rr;
1228 int rc;
1229
1230 memset(page, 0, PAGE_SIZE);
1231 rr = page;
1232 rr->request.length = 0x0020;
1233 rr->request.code = 0x0033;
1234 rr->op = op;
1235 rr->ctrl = ctrl;
1236 rc = chsc(rr);
1237 if (rc)
1238 return -EIO;
1239 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1240 if (clock_delta)
1241 *clock_delta = rr->clock_delta;
1242 return rc;
1243 }
1244
chsc_sstpi(void * page,void * result,size_t size)1245 int chsc_sstpi(void *page, void *result, size_t size)
1246 {
1247 struct {
1248 struct chsc_header request;
1249 unsigned int rsvd0[3];
1250 struct chsc_header response;
1251 char data[];
1252 } *rr;
1253 int rc;
1254
1255 memset(page, 0, PAGE_SIZE);
1256 rr = page;
1257 rr->request.length = 0x0010;
1258 rr->request.code = 0x0038;
1259 rc = chsc(rr);
1260 if (rc)
1261 return -EIO;
1262 memcpy(result, &rr->data, size);
1263 return (rr->response.code == 0x0001) ? 0 : -EIO;
1264 }
1265
chsc_stzi(void * page,void * result,size_t size)1266 int chsc_stzi(void *page, void *result, size_t size)
1267 {
1268 struct {
1269 struct chsc_header request;
1270 unsigned int rsvd0[3];
1271 struct chsc_header response;
1272 char data[];
1273 } *rr;
1274 int rc;
1275
1276 memset(page, 0, PAGE_SIZE);
1277 rr = page;
1278 rr->request.length = 0x0010;
1279 rr->request.code = 0x003e;
1280 rc = chsc(rr);
1281 if (rc)
1282 return -EIO;
1283 memcpy(result, &rr->data, size);
1284 return (rr->response.code == 0x0001) ? 0 : -EIO;
1285 }
1286
chsc_siosl(struct subchannel_id schid)1287 int chsc_siosl(struct subchannel_id schid)
1288 {
1289 struct {
1290 struct chsc_header request;
1291 u32 word1;
1292 struct subchannel_id sid;
1293 u32 word3;
1294 struct chsc_header response;
1295 u32 word[11];
1296 } *siosl_area;
1297 unsigned long flags;
1298 int ccode;
1299 int rc;
1300
1301 spin_lock_irqsave(&chsc_page_lock, flags);
1302 memset(chsc_page, 0, PAGE_SIZE);
1303 siosl_area = chsc_page;
1304 siosl_area->request.length = 0x0010;
1305 siosl_area->request.code = 0x0046;
1306 siosl_area->word1 = 0x80000000;
1307 siosl_area->sid = schid;
1308
1309 ccode = chsc(siosl_area);
1310 if (ccode > 0) {
1311 if (ccode == 3)
1312 rc = -ENODEV;
1313 else
1314 rc = -EBUSY;
1315 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1316 schid.ssid, schid.sch_no, ccode);
1317 goto out;
1318 }
1319 rc = chsc_error_from_response(siosl_area->response.code);
1320 if (rc)
1321 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1322 schid.ssid, schid.sch_no,
1323 siosl_area->response.code);
1324 else
1325 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1326 schid.ssid, schid.sch_no);
1327 out:
1328 spin_unlock_irqrestore(&chsc_page_lock, flags);
1329 return rc;
1330 }
1331 EXPORT_SYMBOL_GPL(chsc_siosl);
1332
1333 /**
1334 * chsc_scm_info() - store SCM information (SSI)
1335 * @scm_area: request and response block for SSI
1336 * @token: continuation token
1337 *
1338 * Returns 0 on success.
1339 */
chsc_scm_info(struct chsc_scm_info * scm_area,u64 token)1340 int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1341 {
1342 int ccode, ret;
1343
1344 memset(scm_area, 0, sizeof(*scm_area));
1345 scm_area->request.length = 0x0020;
1346 scm_area->request.code = 0x004C;
1347 scm_area->reqtok = token;
1348
1349 ccode = chsc(scm_area);
1350 if (ccode > 0) {
1351 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1352 goto out;
1353 }
1354 ret = chsc_error_from_response(scm_area->response.code);
1355 if (ret != 0)
1356 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1357 scm_area->response.code);
1358 out:
1359 return ret;
1360 }
1361 EXPORT_SYMBOL_GPL(chsc_scm_info);
1362
1363 /**
1364 * chsc_pnso() - Perform Network-Subchannel Operation
1365 * @schid: id of the subchannel on which PNSO is performed
1366 * @pnso_area: request and response block for the operation
1367 * @oc: Operation Code
1368 * @resume_token: resume token for multiblock response
1369 * @cnc: Boolean change-notification control
1370 *
1371 * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
1372 *
1373 * Returns 0 on success.
1374 */
chsc_pnso(struct subchannel_id schid,struct chsc_pnso_area * pnso_area,u8 oc,struct chsc_pnso_resume_token resume_token,int cnc)1375 int chsc_pnso(struct subchannel_id schid, struct chsc_pnso_area *pnso_area,
1376 u8 oc, struct chsc_pnso_resume_token resume_token, int cnc)
1377 {
1378 memset(pnso_area, 0, sizeof(*pnso_area));
1379 pnso_area->request.length = 0x0030;
1380 pnso_area->request.code = 0x003d; /* network-subchannel operation */
1381 pnso_area->m = schid.m;
1382 pnso_area->ssid = schid.ssid;
1383 pnso_area->sch = schid.sch_no;
1384 pnso_area->cssid = schid.cssid;
1385 pnso_area->oc = oc;
1386 pnso_area->resume_token = resume_token;
1387 pnso_area->n = (cnc != 0);
1388 if (chsc(pnso_area))
1389 return -EIO;
1390 return chsc_error_from_response(pnso_area->response.code);
1391 }
1392
chsc_sgib(u32 origin)1393 int chsc_sgib(u32 origin)
1394 {
1395 struct {
1396 struct chsc_header request;
1397 u16 op;
1398 u8 reserved01[2];
1399 u8 reserved02:4;
1400 u8 fmt:4;
1401 u8 reserved03[7];
1402 /* operation data area begin */
1403 u8 reserved04[4];
1404 u32 gib_origin;
1405 u8 reserved05[10];
1406 u8 aix;
1407 u8 reserved06[4029];
1408 struct chsc_header response;
1409 u8 reserved07[4];
1410 } *sgib_area;
1411 int ret;
1412
1413 spin_lock_irq(&chsc_page_lock);
1414 memset(chsc_page, 0, PAGE_SIZE);
1415 sgib_area = chsc_page;
1416 sgib_area->request.length = 0x0fe0;
1417 sgib_area->request.code = 0x0021;
1418 sgib_area->op = 0x1;
1419 sgib_area->gib_origin = origin;
1420
1421 ret = chsc(sgib_area);
1422 if (ret == 0)
1423 ret = chsc_error_from_response(sgib_area->response.code);
1424 spin_unlock_irq(&chsc_page_lock);
1425
1426 return ret;
1427 }
1428 EXPORT_SYMBOL_GPL(chsc_sgib);
1429