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 /* Wait until previous actions have settled. */
761 css_wait_for_slow_path();
762 /*
763 * Redo PathVerification on the devices the chpid connects to
764 */
765 if (on) {
766 /* Try to update the channel path description. */
767 chp_update_desc(chp);
768 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
769 NULL, &chpid);
770 css_schedule_reprobe();
771 } else
772 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
773 NULL, &chpid);
774
775 return 0;
776 }
777
778 static void
chsc_remove_cmg_attr(struct channel_subsystem * css)779 chsc_remove_cmg_attr(struct channel_subsystem *css)
780 {
781 int i;
782
783 for (i = 0; i <= __MAX_CHPID; i++) {
784 if (!css->chps[i])
785 continue;
786 chp_remove_cmg_attr(css->chps[i]);
787 }
788 }
789
790 static int
chsc_add_cmg_attr(struct channel_subsystem * css)791 chsc_add_cmg_attr(struct channel_subsystem *css)
792 {
793 int i, ret;
794
795 ret = 0;
796 for (i = 0; i <= __MAX_CHPID; i++) {
797 if (!css->chps[i])
798 continue;
799 ret = chp_add_cmg_attr(css->chps[i]);
800 if (ret)
801 goto cleanup;
802 }
803 return ret;
804 cleanup:
805 for (--i; i >= 0; i--) {
806 if (!css->chps[i])
807 continue;
808 chp_remove_cmg_attr(css->chps[i]);
809 }
810 return ret;
811 }
812
__chsc_do_secm(struct channel_subsystem * css,int enable)813 int __chsc_do_secm(struct channel_subsystem *css, int enable)
814 {
815 struct {
816 struct chsc_header request;
817 u32 operation_code : 2;
818 u32 : 30;
819 u32 key : 4;
820 u32 : 28;
821 u32 zeroes1;
822 u32 cub_addr1;
823 u32 zeroes2;
824 u32 cub_addr2;
825 u32 reserved[13];
826 struct chsc_header response;
827 u32 status : 8;
828 u32 : 4;
829 u32 fmt : 4;
830 u32 : 16;
831 } *secm_area;
832 unsigned long flags;
833 int ret, ccode;
834
835 spin_lock_irqsave(&chsc_page_lock, flags);
836 memset(chsc_page, 0, PAGE_SIZE);
837 secm_area = chsc_page;
838 secm_area->request.length = 0x0050;
839 secm_area->request.code = 0x0016;
840
841 secm_area->key = PAGE_DEFAULT_KEY >> 4;
842 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
843 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
844
845 secm_area->operation_code = enable ? 0 : 1;
846
847 ccode = chsc(secm_area);
848 if (ccode > 0) {
849 ret = (ccode == 3) ? -ENODEV : -EBUSY;
850 goto out;
851 }
852
853 switch (secm_area->response.code) {
854 case 0x0102:
855 case 0x0103:
856 ret = -EINVAL;
857 break;
858 default:
859 ret = chsc_error_from_response(secm_area->response.code);
860 }
861 if (ret != 0)
862 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
863 secm_area->response.code);
864 out:
865 spin_unlock_irqrestore(&chsc_page_lock, flags);
866 return ret;
867 }
868
869 int
chsc_secm(struct channel_subsystem * css,int enable)870 chsc_secm(struct channel_subsystem *css, int enable)
871 {
872 int ret;
873
874 if (enable && !css->cm_enabled) {
875 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
876 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
877 if (!css->cub_addr1 || !css->cub_addr2) {
878 free_page((unsigned long)css->cub_addr1);
879 free_page((unsigned long)css->cub_addr2);
880 return -ENOMEM;
881 }
882 }
883 ret = __chsc_do_secm(css, enable);
884 if (!ret) {
885 css->cm_enabled = enable;
886 if (css->cm_enabled) {
887 ret = chsc_add_cmg_attr(css);
888 if (ret) {
889 __chsc_do_secm(css, 0);
890 css->cm_enabled = 0;
891 }
892 } else
893 chsc_remove_cmg_attr(css);
894 }
895 if (!css->cm_enabled) {
896 free_page((unsigned long)css->cub_addr1);
897 free_page((unsigned long)css->cub_addr2);
898 }
899 return ret;
900 }
901
chsc_determine_channel_path_desc(struct chp_id chpid,int fmt,int rfmt,int c,int m,void * page)902 int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
903 int c, int m, void *page)
904 {
905 struct chsc_scpd *scpd_area;
906 int ccode, ret;
907
908 if ((rfmt == 1 || rfmt == 0) && c == 1 &&
909 !css_general_characteristics.fcs)
910 return -EINVAL;
911 if ((rfmt == 2) && !css_general_characteristics.cib)
912 return -EINVAL;
913 if ((rfmt == 3) && !css_general_characteristics.util_str)
914 return -EINVAL;
915
916 memset(page, 0, PAGE_SIZE);
917 scpd_area = page;
918 scpd_area->request.length = 0x0010;
919 scpd_area->request.code = 0x0002;
920 scpd_area->cssid = chpid.cssid;
921 scpd_area->first_chpid = chpid.id;
922 scpd_area->last_chpid = chpid.id;
923 scpd_area->m = m;
924 scpd_area->c = c;
925 scpd_area->fmt = fmt;
926 scpd_area->rfmt = rfmt;
927
928 ccode = chsc(scpd_area);
929 if (ccode > 0)
930 return (ccode == 3) ? -ENODEV : -EBUSY;
931
932 ret = chsc_error_from_response(scpd_area->response.code);
933 if (ret)
934 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
935 scpd_area->response.code);
936 return ret;
937 }
938 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
939
940 #define chsc_det_chp_desc(FMT, c) \
941 int chsc_determine_fmt##FMT##_channel_path_desc( \
942 struct chp_id chpid, struct channel_path_desc_fmt##FMT *desc) \
943 { \
944 struct chsc_scpd *scpd_area; \
945 unsigned long flags; \
946 int ret; \
947 \
948 spin_lock_irqsave(&chsc_page_lock, flags); \
949 scpd_area = chsc_page; \
950 ret = chsc_determine_channel_path_desc(chpid, 0, FMT, c, 0, \
951 scpd_area); \
952 if (ret) \
953 goto out; \
954 \
955 memcpy(desc, scpd_area->data, sizeof(*desc)); \
956 out: \
957 spin_unlock_irqrestore(&chsc_page_lock, flags); \
958 return ret; \
959 }
960
961 chsc_det_chp_desc(0, 0)
962 chsc_det_chp_desc(1, 1)
963 chsc_det_chp_desc(3, 0)
964
965 static void
chsc_initialize_cmg_chars(struct channel_path * chp,u8 cmcv,struct cmg_chars * chars)966 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
967 struct cmg_chars *chars)
968 {
969 int i, mask;
970
971 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
972 mask = 0x80 >> (i + 3);
973 if (cmcv & mask)
974 chp->cmg_chars.values[i] = chars->values[i];
975 else
976 chp->cmg_chars.values[i] = 0;
977 }
978 }
979
chsc_get_channel_measurement_chars(struct channel_path * chp)980 int chsc_get_channel_measurement_chars(struct channel_path *chp)
981 {
982 unsigned long flags;
983 int ccode, ret;
984
985 struct {
986 struct chsc_header request;
987 u32 : 24;
988 u32 first_chpid : 8;
989 u32 : 24;
990 u32 last_chpid : 8;
991 u32 zeroes1;
992 struct chsc_header response;
993 u32 zeroes2;
994 u32 not_valid : 1;
995 u32 shared : 1;
996 u32 : 22;
997 u32 chpid : 8;
998 u32 cmcv : 5;
999 u32 : 11;
1000 u32 cmgq : 8;
1001 u32 cmg : 8;
1002 u32 zeroes3;
1003 u32 data[NR_MEASUREMENT_CHARS];
1004 } *scmc_area;
1005
1006 chp->shared = -1;
1007 chp->cmg = -1;
1008
1009 if (!css_chsc_characteristics.scmc || !css_chsc_characteristics.secm)
1010 return -EINVAL;
1011
1012 spin_lock_irqsave(&chsc_page_lock, flags);
1013 memset(chsc_page, 0, PAGE_SIZE);
1014 scmc_area = chsc_page;
1015 scmc_area->request.length = 0x0010;
1016 scmc_area->request.code = 0x0022;
1017 scmc_area->first_chpid = chp->chpid.id;
1018 scmc_area->last_chpid = chp->chpid.id;
1019
1020 ccode = chsc(scmc_area);
1021 if (ccode > 0) {
1022 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1023 goto out;
1024 }
1025
1026 ret = chsc_error_from_response(scmc_area->response.code);
1027 if (ret) {
1028 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
1029 scmc_area->response.code);
1030 goto out;
1031 }
1032 if (scmc_area->not_valid)
1033 goto out;
1034
1035 chp->cmg = scmc_area->cmg;
1036 chp->shared = scmc_area->shared;
1037 if (chp->cmg != 2 && chp->cmg != 3) {
1038 /* No cmg-dependent data. */
1039 goto out;
1040 }
1041 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1042 (struct cmg_chars *) &scmc_area->data);
1043 out:
1044 spin_unlock_irqrestore(&chsc_page_lock, flags);
1045 return ret;
1046 }
1047
chsc_init(void)1048 int __init chsc_init(void)
1049 {
1050 int ret;
1051
1052 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1053 chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1054 if (!sei_page || !chsc_page) {
1055 ret = -ENOMEM;
1056 goto out_err;
1057 }
1058 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
1059 if (ret)
1060 goto out_err;
1061 return ret;
1062 out_err:
1063 free_page((unsigned long)chsc_page);
1064 free_page((unsigned long)sei_page);
1065 return ret;
1066 }
1067
chsc_init_cleanup(void)1068 void __init chsc_init_cleanup(void)
1069 {
1070 crw_unregister_handler(CRW_RSC_CSS);
1071 free_page((unsigned long)chsc_page);
1072 free_page((unsigned long)sei_page);
1073 }
1074
__chsc_enable_facility(struct chsc_sda_area * sda_area,int operation_code)1075 int __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code)
1076 {
1077 int ret;
1078
1079 sda_area->request.length = 0x0400;
1080 sda_area->request.code = 0x0031;
1081 sda_area->operation_code = operation_code;
1082
1083 ret = chsc(sda_area);
1084 if (ret > 0) {
1085 ret = (ret == 3) ? -ENODEV : -EBUSY;
1086 goto out;
1087 }
1088
1089 switch (sda_area->response.code) {
1090 case 0x0101:
1091 ret = -EOPNOTSUPP;
1092 break;
1093 default:
1094 ret = chsc_error_from_response(sda_area->response.code);
1095 }
1096 out:
1097 return ret;
1098 }
1099
chsc_enable_facility(int operation_code)1100 int chsc_enable_facility(int operation_code)
1101 {
1102 struct chsc_sda_area *sda_area;
1103 unsigned long flags;
1104 int ret;
1105
1106 spin_lock_irqsave(&chsc_page_lock, flags);
1107 memset(chsc_page, 0, PAGE_SIZE);
1108 sda_area = chsc_page;
1109
1110 ret = __chsc_enable_facility(sda_area, operation_code);
1111 if (ret != 0)
1112 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1113 operation_code, sda_area->response.code);
1114
1115 spin_unlock_irqrestore(&chsc_page_lock, flags);
1116 return ret;
1117 }
1118
chsc_get_cssid_iid(int idx,u8 * cssid,u8 * iid)1119 int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid)
1120 {
1121 struct {
1122 struct chsc_header request;
1123 u8 atype;
1124 u32 : 24;
1125 u32 reserved1[6];
1126 struct chsc_header response;
1127 u32 reserved2[3];
1128 struct {
1129 u8 cssid;
1130 u8 iid;
1131 u32 : 16;
1132 } list[0];
1133 } *sdcal_area;
1134 int ret;
1135
1136 spin_lock_irq(&chsc_page_lock);
1137 memset(chsc_page, 0, PAGE_SIZE);
1138 sdcal_area = chsc_page;
1139 sdcal_area->request.length = 0x0020;
1140 sdcal_area->request.code = 0x0034;
1141 sdcal_area->atype = 4;
1142
1143 ret = chsc(sdcal_area);
1144 if (ret) {
1145 ret = (ret == 3) ? -ENODEV : -EBUSY;
1146 goto exit;
1147 }
1148
1149 ret = chsc_error_from_response(sdcal_area->response.code);
1150 if (ret) {
1151 CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
1152 sdcal_area->response.code);
1153 goto exit;
1154 }
1155
1156 if ((addr_t) &sdcal_area->list[idx] <
1157 (addr_t) &sdcal_area->response + sdcal_area->response.length) {
1158 *cssid = sdcal_area->list[idx].cssid;
1159 *iid = sdcal_area->list[idx].iid;
1160 }
1161 else
1162 ret = -ENODEV;
1163 exit:
1164 spin_unlock_irq(&chsc_page_lock);
1165 return ret;
1166 }
1167
1168 struct css_general_char css_general_characteristics;
1169 struct css_chsc_char css_chsc_characteristics;
1170
1171 int __init
chsc_determine_css_characteristics(void)1172 chsc_determine_css_characteristics(void)
1173 {
1174 unsigned long flags;
1175 int result;
1176 struct {
1177 struct chsc_header request;
1178 u32 reserved1;
1179 u32 reserved2;
1180 u32 reserved3;
1181 struct chsc_header response;
1182 u32 reserved4;
1183 u32 general_char[510];
1184 u32 chsc_char[508];
1185 } *scsc_area;
1186
1187 spin_lock_irqsave(&chsc_page_lock, flags);
1188 memset(chsc_page, 0, PAGE_SIZE);
1189 scsc_area = chsc_page;
1190 scsc_area->request.length = 0x0010;
1191 scsc_area->request.code = 0x0010;
1192
1193 result = chsc(scsc_area);
1194 if (result) {
1195 result = (result == 3) ? -ENODEV : -EBUSY;
1196 goto exit;
1197 }
1198
1199 result = chsc_error_from_response(scsc_area->response.code);
1200 if (result == 0) {
1201 memcpy(&css_general_characteristics, scsc_area->general_char,
1202 sizeof(css_general_characteristics));
1203 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1204 sizeof(css_chsc_characteristics));
1205 } else
1206 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1207 scsc_area->response.code);
1208 exit:
1209 spin_unlock_irqrestore(&chsc_page_lock, flags);
1210 return result;
1211 }
1212
1213 EXPORT_SYMBOL_GPL(css_general_characteristics);
1214 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
1215
chsc_sstpc(void * page,unsigned int op,u16 ctrl,u64 * clock_delta)1216 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta)
1217 {
1218 struct {
1219 struct chsc_header request;
1220 unsigned int rsvd0;
1221 unsigned int op : 8;
1222 unsigned int rsvd1 : 8;
1223 unsigned int ctrl : 16;
1224 unsigned int rsvd2[5];
1225 struct chsc_header response;
1226 unsigned int rsvd3[3];
1227 u64 clock_delta;
1228 unsigned int rsvd4[2];
1229 } *rr;
1230 int rc;
1231
1232 memset(page, 0, PAGE_SIZE);
1233 rr = page;
1234 rr->request.length = 0x0020;
1235 rr->request.code = 0x0033;
1236 rr->op = op;
1237 rr->ctrl = ctrl;
1238 rc = chsc(rr);
1239 if (rc)
1240 return -EIO;
1241 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1242 if (clock_delta)
1243 *clock_delta = rr->clock_delta;
1244 return rc;
1245 }
1246
chsc_sstpi(void * page,void * result,size_t size)1247 int chsc_sstpi(void *page, void *result, size_t size)
1248 {
1249 struct {
1250 struct chsc_header request;
1251 unsigned int rsvd0[3];
1252 struct chsc_header response;
1253 char data[];
1254 } *rr;
1255 int rc;
1256
1257 memset(page, 0, PAGE_SIZE);
1258 rr = page;
1259 rr->request.length = 0x0010;
1260 rr->request.code = 0x0038;
1261 rc = chsc(rr);
1262 if (rc)
1263 return -EIO;
1264 memcpy(result, &rr->data, size);
1265 return (rr->response.code == 0x0001) ? 0 : -EIO;
1266 }
1267
chsc_stzi(void * page,void * result,size_t size)1268 int chsc_stzi(void *page, void *result, size_t size)
1269 {
1270 struct {
1271 struct chsc_header request;
1272 unsigned int rsvd0[3];
1273 struct chsc_header response;
1274 char data[];
1275 } *rr;
1276 int rc;
1277
1278 memset(page, 0, PAGE_SIZE);
1279 rr = page;
1280 rr->request.length = 0x0010;
1281 rr->request.code = 0x003e;
1282 rc = chsc(rr);
1283 if (rc)
1284 return -EIO;
1285 memcpy(result, &rr->data, size);
1286 return (rr->response.code == 0x0001) ? 0 : -EIO;
1287 }
1288
chsc_siosl(struct subchannel_id schid)1289 int chsc_siosl(struct subchannel_id schid)
1290 {
1291 struct {
1292 struct chsc_header request;
1293 u32 word1;
1294 struct subchannel_id sid;
1295 u32 word3;
1296 struct chsc_header response;
1297 u32 word[11];
1298 } *siosl_area;
1299 unsigned long flags;
1300 int ccode;
1301 int rc;
1302
1303 spin_lock_irqsave(&chsc_page_lock, flags);
1304 memset(chsc_page, 0, PAGE_SIZE);
1305 siosl_area = chsc_page;
1306 siosl_area->request.length = 0x0010;
1307 siosl_area->request.code = 0x0046;
1308 siosl_area->word1 = 0x80000000;
1309 siosl_area->sid = schid;
1310
1311 ccode = chsc(siosl_area);
1312 if (ccode > 0) {
1313 if (ccode == 3)
1314 rc = -ENODEV;
1315 else
1316 rc = -EBUSY;
1317 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1318 schid.ssid, schid.sch_no, ccode);
1319 goto out;
1320 }
1321 rc = chsc_error_from_response(siosl_area->response.code);
1322 if (rc)
1323 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1324 schid.ssid, schid.sch_no,
1325 siosl_area->response.code);
1326 else
1327 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1328 schid.ssid, schid.sch_no);
1329 out:
1330 spin_unlock_irqrestore(&chsc_page_lock, flags);
1331 return rc;
1332 }
1333 EXPORT_SYMBOL_GPL(chsc_siosl);
1334
1335 /**
1336 * chsc_scm_info() - store SCM information (SSI)
1337 * @scm_area: request and response block for SSI
1338 * @token: continuation token
1339 *
1340 * Returns 0 on success.
1341 */
chsc_scm_info(struct chsc_scm_info * scm_area,u64 token)1342 int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1343 {
1344 int ccode, ret;
1345
1346 memset(scm_area, 0, sizeof(*scm_area));
1347 scm_area->request.length = 0x0020;
1348 scm_area->request.code = 0x004C;
1349 scm_area->reqtok = token;
1350
1351 ccode = chsc(scm_area);
1352 if (ccode > 0) {
1353 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1354 goto out;
1355 }
1356 ret = chsc_error_from_response(scm_area->response.code);
1357 if (ret != 0)
1358 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1359 scm_area->response.code);
1360 out:
1361 return ret;
1362 }
1363 EXPORT_SYMBOL_GPL(chsc_scm_info);
1364
1365 /**
1366 * chsc_pnso() - Perform Network-Subchannel Operation
1367 * @schid: id of the subchannel on which PNSO is performed
1368 * @pnso_area: request and response block for the operation
1369 * @oc: Operation Code
1370 * @resume_token: resume token for multiblock response
1371 * @cnc: Boolean change-notification control
1372 *
1373 * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
1374 *
1375 * Returns 0 on success.
1376 */
chsc_pnso(struct subchannel_id schid,struct chsc_pnso_area * pnso_area,u8 oc,struct chsc_pnso_resume_token resume_token,int cnc)1377 int chsc_pnso(struct subchannel_id schid, struct chsc_pnso_area *pnso_area,
1378 u8 oc, struct chsc_pnso_resume_token resume_token, int cnc)
1379 {
1380 memset(pnso_area, 0, sizeof(*pnso_area));
1381 pnso_area->request.length = 0x0030;
1382 pnso_area->request.code = 0x003d; /* network-subchannel operation */
1383 pnso_area->m = schid.m;
1384 pnso_area->ssid = schid.ssid;
1385 pnso_area->sch = schid.sch_no;
1386 pnso_area->cssid = schid.cssid;
1387 pnso_area->oc = oc;
1388 pnso_area->resume_token = resume_token;
1389 pnso_area->n = (cnc != 0);
1390 if (chsc(pnso_area))
1391 return -EIO;
1392 return chsc_error_from_response(pnso_area->response.code);
1393 }
1394
chsc_sgib(u32 origin)1395 int chsc_sgib(u32 origin)
1396 {
1397 struct {
1398 struct chsc_header request;
1399 u16 op;
1400 u8 reserved01[2];
1401 u8 reserved02:4;
1402 u8 fmt:4;
1403 u8 reserved03[7];
1404 /* operation data area begin */
1405 u8 reserved04[4];
1406 u32 gib_origin;
1407 u8 reserved05[10];
1408 u8 aix;
1409 u8 reserved06[4029];
1410 struct chsc_header response;
1411 u8 reserved07[4];
1412 } *sgib_area;
1413 int ret;
1414
1415 spin_lock_irq(&chsc_page_lock);
1416 memset(chsc_page, 0, PAGE_SIZE);
1417 sgib_area = chsc_page;
1418 sgib_area->request.length = 0x0fe0;
1419 sgib_area->request.code = 0x0021;
1420 sgib_area->op = 0x1;
1421 sgib_area->gib_origin = origin;
1422
1423 ret = chsc(sgib_area);
1424 if (ret == 0)
1425 ret = chsc_error_from_response(sgib_area->response.code);
1426 spin_unlock_irq(&chsc_page_lock);
1427
1428 return ret;
1429 }
1430 EXPORT_SYMBOL_GPL(chsc_sgib);
1431