1 // SPDX-License-Identifier: GPL-2.0
3 * S/390 common I/O routines -- channel subsystem call
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)
11 #define KMSG_COMPONENT "cio"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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>
22 #include <asm/chpid.h>
26 #include <asm/ebcdic.h>
31 #include "cio_debug.h"
36 static void *sei_page
;
37 static void *chsc_page
;
38 static DEFINE_SPINLOCK(chsc_page_lock
);
40 #define SEI_VF_FLA 0xc0 /* VF flag for Full Link Address */
41 #define SEI_RS_CHPID 0x4 /* 4 in RS field indicates CHPID */
44 * chsc_error_from_response() - convert a chsc response to an error
45 * @response: chsc response code
47 * Returns an appropriate Linux error code for @response.
49 int chsc_error_from_response(int response
)
63 case 0x0106: /* "Wrong Channel Parm" for the op 0x003d */
66 case 0x0107: /* "Channel busy" for the op 0x003d */
71 case 0x0108: /* "HW limit exceeded" for the op 0x003d */
77 EXPORT_SYMBOL_GPL(chsc_error_from_response
);
79 struct chsc_ssd_area
{
80 struct chsc_header request
;
84 u16 f_sch
; /* first subchannel */
86 u16 l_sch
; /* last subchannel */
88 struct chsc_header response
;
92 u8 st
: 3; /* subchannel type */
94 u8 unit_addr
; /* unit address */
95 u16 devno
; /* device number */
98 u16 sch
; /* subchannel */
99 u8 chpid
[8]; /* chpids 0-7 */
100 u16 fla
[8]; /* full link addresses 0-7 */
101 } __packed
__aligned(PAGE_SIZE
);
103 int chsc_get_ssd_info(struct subchannel_id schid
, struct chsc_ssd_info
*ssd
)
105 struct chsc_ssd_area
*ssd_area
;
112 spin_lock_irqsave(&chsc_page_lock
, flags
);
113 memset(chsc_page
, 0, PAGE_SIZE
);
114 ssd_area
= chsc_page
;
115 ssd_area
->request
.length
= 0x0010;
116 ssd_area
->request
.code
= 0x0004;
117 ssd_area
->ssid
= schid
.ssid
;
118 ssd_area
->f_sch
= schid
.sch_no
;
119 ssd_area
->l_sch
= schid
.sch_no
;
121 ccode
= chsc(ssd_area
);
122 /* Check response. */
124 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
127 ret
= chsc_error_from_response(ssd_area
->response
.code
);
129 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
130 schid
.ssid
, schid
.sch_no
,
131 ssd_area
->response
.code
);
134 if (!ssd_area
->sch_valid
) {
140 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
141 if ((ssd_area
->st
!= SUBCHANNEL_TYPE_IO
) &&
142 (ssd_area
->st
!= SUBCHANNEL_TYPE_MSG
))
144 ssd
->path_mask
= ssd_area
->path_mask
;
145 ssd
->fla_valid_mask
= ssd_area
->fla_valid_mask
;
146 for (i
= 0; i
< 8; i
++) {
148 if (ssd_area
->path_mask
& mask
) {
149 chp_id_init(&ssd
->chpid
[i
]);
150 ssd
->chpid
[i
].id
= ssd_area
->chpid
[i
];
152 if (ssd_area
->fla_valid_mask
& mask
)
153 ssd
->fla
[i
] = ssd_area
->fla
[i
];
156 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
161 * chsc_ssqd() - store subchannel QDIO data (SSQD)
162 * @schid: id of the subchannel on which SSQD is performed
163 * @ssqd: request and response block for SSQD
165 * Returns 0 on success.
167 int chsc_ssqd(struct subchannel_id schid
, struct chsc_ssqd_area
*ssqd
)
169 memset(ssqd
, 0, sizeof(*ssqd
));
170 ssqd
->request
.length
= 0x0010;
171 ssqd
->request
.code
= 0x0024;
172 ssqd
->first_sch
= schid
.sch_no
;
173 ssqd
->last_sch
= schid
.sch_no
;
174 ssqd
->ssid
= schid
.ssid
;
179 return chsc_error_from_response(ssqd
->response
.code
);
181 EXPORT_SYMBOL_GPL(chsc_ssqd
);
184 * chsc_sadc() - set adapter device controls (SADC)
185 * @schid: id of the subchannel on which SADC is performed
186 * @scssc: request and response block for SADC
187 * @summary_indicator_addr: summary indicator address
188 * @subchannel_indicator_addr: subchannel indicator address
189 * @isc: Interruption Subclass for this subchannel
191 * Returns 0 on success.
193 int chsc_sadc(struct subchannel_id schid
, struct chsc_scssc_area
*scssc
,
194 u64 summary_indicator_addr
, u64 subchannel_indicator_addr
, u8 isc
)
196 memset(scssc
, 0, sizeof(*scssc
));
197 scssc
->request
.length
= 0x0fe0;
198 scssc
->request
.code
= 0x0021;
199 scssc
->operation_code
= 0;
201 scssc
->summary_indicator_addr
= summary_indicator_addr
;
202 scssc
->subchannel_indicator_addr
= subchannel_indicator_addr
;
204 scssc
->ks
= PAGE_DEFAULT_KEY
>> 4;
205 scssc
->kc
= PAGE_DEFAULT_KEY
>> 4;
207 scssc
->schid
= schid
;
209 /* enable the time delay disablement facility */
210 if (css_general_characteristics
.aif_tdd
)
211 scssc
->word_with_d_bit
= 0x10000000;
216 return chsc_error_from_response(scssc
->response
.code
);
218 EXPORT_SYMBOL_GPL(chsc_sadc
);
220 static int s390_subchannel_remove_chpid(struct subchannel
*sch
, void *data
)
222 spin_lock_irq(sch
->lock
);
223 if (sch
->driver
&& sch
->driver
->chp_event
)
224 if (sch
->driver
->chp_event(sch
, data
, CHP_OFFLINE
) != 0)
226 spin_unlock_irq(sch
->lock
);
231 spin_unlock_irq(sch
->lock
);
232 css_schedule_eval(sch
->schid
);
236 void chsc_chp_offline(struct chp_id chpid
)
238 struct channel_path
*chp
= chpid_to_chp(chpid
);
239 struct chp_link link
;
242 sprintf(dbf_txt
, "chpr%x.%02x", chpid
.cssid
, chpid
.id
);
243 CIO_TRACE_EVENT(2, dbf_txt
);
245 if (chp_get_status(chpid
) <= 0)
247 memset(&link
, 0, sizeof(struct chp_link
));
249 /* Wait until previous actions have settled. */
250 css_wait_for_slow_path();
252 mutex_lock(&chp
->lock
);
253 chp_update_desc(chp
);
254 mutex_unlock(&chp
->lock
);
256 for_each_subchannel_staged(s390_subchannel_remove_chpid
, NULL
, &link
);
259 static int __s390_process_res_acc(struct subchannel
*sch
, void *data
)
261 spin_lock_irq(sch
->lock
);
262 if (sch
->driver
&& sch
->driver
->chp_event
)
263 sch
->driver
->chp_event(sch
, data
, CHP_ONLINE
);
264 spin_unlock_irq(sch
->lock
);
269 static void s390_process_res_acc(struct chp_link
*link
)
273 sprintf(dbf_txt
, "accpr%x.%02x", link
->chpid
.cssid
,
275 CIO_TRACE_EVENT( 2, dbf_txt
);
276 if (link
->fla
!= 0) {
277 sprintf(dbf_txt
, "fla%x", link
->fla
);
278 CIO_TRACE_EVENT( 2, dbf_txt
);
280 /* Wait until previous actions have settled. */
281 css_wait_for_slow_path();
283 * I/O resources may have become accessible.
284 * Scan through all subchannels that may be concerned and
285 * do a validation on those.
286 * The more information we have (info), the less scanning
287 * will we have to do.
289 for_each_subchannel_staged(__s390_process_res_acc
, NULL
, link
);
290 css_schedule_reprobe();
293 static int process_fces_event(struct subchannel
*sch
, void *data
)
295 spin_lock_irq(sch
->lock
);
296 if (sch
->driver
&& sch
->driver
->chp_event
)
297 sch
->driver
->chp_event(sch
, data
, CHP_FCES_EVENT
);
298 spin_unlock_irq(sch
->lock
);
302 struct chsc_sei_nt0_area
{
304 u8 vf
; /* validity flags */
305 u8 rs
; /* reporting source */
306 u8 cc
; /* content code */
307 u16 fla
; /* full link address */
308 u16 rsid
; /* reporting source id */
311 /* ccdf has to be big enough for a link-incident record */
312 u8 ccdf
[PAGE_SIZE
- 24 - 16]; /* content-code dependent field */
315 struct chsc_sei_nt2_area
{
316 u8 flags
; /* p and v bit */
319 u8 cc
; /* content code */
321 u8 ccdf
[PAGE_SIZE
- 24 - 56]; /* content-code dependent field */
324 #define CHSC_SEI_NT0 (1ULL << 63)
325 #define CHSC_SEI_NT2 (1ULL << 61)
328 struct chsc_header request
;
330 u64 ntsm
; /* notification type mask */
331 struct chsc_header response
;
335 struct chsc_sei_nt0_area nt0_area
;
336 struct chsc_sei_nt2_area nt2_area
;
337 u8 nt_area
[PAGE_SIZE
- 24];
339 } __packed
__aligned(PAGE_SIZE
);
342 * Link Incident Record as defined in SA22-7202, "ESCON I/O Interface"
345 #define LIR_IQ_CLASS_INFO 0
346 #define LIR_IQ_CLASS_DEGRADED 1
347 #define LIR_IQ_CLASS_NOT_OPERATIONAL 2
358 struct node_descriptor incident_node
;
359 struct node_descriptor attached_node
;
363 #define PARAMS_LEN 10 /* PARAMS=xx,xxxxxx */
364 #define NODEID_LEN 35 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
366 /* Copy EBCIDC text, convert to ASCII and optionally add delimiter. */
367 static char *store_ebcdic(char *dest
, const char *src
, unsigned long len
,
370 memcpy(dest
, src
, len
);
379 static void chsc_link_from_sei(struct chp_link
*link
,
380 struct chsc_sei_nt0_area
*sei_area
)
382 if ((sei_area
->vf
& SEI_VF_FLA
) != 0) {
383 link
->fla
= sei_area
->fla
;
384 link
->fla_mask
= ((sei_area
->vf
& SEI_VF_FLA
) == SEI_VF_FLA
) ?
389 /* Format node ID and parameters for output in LIR log message. */
390 static void format_node_data(char *params
, char *id
, struct node_descriptor
*nd
)
392 memset(params
, 0, PARAMS_LEN
);
393 memset(id
, 0, NODEID_LEN
);
395 if (nd
->validity
!= ND_VALIDITY_VALID
) {
396 strncpy(params
, "n/a", PARAMS_LEN
- 1);
397 strncpy(id
, "n/a", NODEID_LEN
- 1);
401 /* PARAMS=xx,xxxxxx */
402 snprintf(params
, PARAMS_LEN
, "%02x,%06x", nd
->byte0
, nd
->params
);
403 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
404 id
= store_ebcdic(id
, nd
->type
, sizeof(nd
->type
), '/');
405 id
= store_ebcdic(id
, nd
->model
, sizeof(nd
->model
), ',');
406 id
= store_ebcdic(id
, nd
->manufacturer
, sizeof(nd
->manufacturer
), '.');
407 id
= store_ebcdic(id
, nd
->plant
, sizeof(nd
->plant
), 0);
408 id
= store_ebcdic(id
, nd
->seq
, sizeof(nd
->seq
), ',');
409 sprintf(id
, "%04X", nd
->tag
);
412 static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area
*sei_area
)
414 struct lir
*lir
= (struct lir
*) &sei_area
->ccdf
;
415 char iuparams
[PARAMS_LEN
], iunodeid
[NODEID_LEN
], auparams
[PARAMS_LEN
],
416 aunodeid
[NODEID_LEN
];
418 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x, iq=%02x)\n",
419 sei_area
->rs
, sei_area
->rsid
, sei_area
->ccdf
[0]);
421 /* Ignore NULL Link Incident Records. */
425 /* Inform user that a link requires maintenance actions because it has
426 * become degraded or not operational. Note that this log message is
427 * the primary intention behind a Link Incident Record. */
429 format_node_data(iuparams
, iunodeid
, &lir
->incident_node
);
430 format_node_data(auparams
, aunodeid
, &lir
->attached_node
);
432 switch (lir
->iq
.class) {
433 case LIR_IQ_CLASS_DEGRADED
:
434 pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x "
435 "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
436 sei_area
->rs
, sei_area
->rsid
, lir
->ic
, iuparams
,
437 iunodeid
, auparams
, aunodeid
);
439 case LIR_IQ_CLASS_NOT_OPERATIONAL
:
440 pr_err("Link stopped: RS=%02x RSID=%04x IC=%02x "
441 "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
442 sei_area
->rs
, sei_area
->rsid
, lir
->ic
, iuparams
,
443 iunodeid
, auparams
, aunodeid
);
450 static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area
*sei_area
)
452 struct channel_path
*chp
;
453 struct chp_link link
;
457 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
458 "rs_id=%04x)\n", sei_area
->rs
, sei_area
->rsid
);
459 if (sei_area
->rs
!= 4)
462 chpid
.id
= sei_area
->rsid
;
463 /* allocate a new channel path structure, if needed */
464 status
= chp_get_status(chpid
);
471 chp
= chpid_to_chp(chpid
);
472 mutex_lock(&chp
->lock
);
473 chp_update_desc(chp
);
474 mutex_unlock(&chp
->lock
);
476 memset(&link
, 0, sizeof(struct chp_link
));
478 chsc_link_from_sei(&link
, sei_area
);
479 s390_process_res_acc(&link
);
482 static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area
*sei_area
)
484 struct channel_path
*chp
;
489 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
490 if (sei_area
->rs
!= 0)
492 data
= sei_area
->ccdf
;
494 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
495 if (!chp_test_bit(data
, num
))
499 CIO_CRW_EVENT(4, "Update information for channel path "
500 "%x.%02x\n", chpid
.cssid
, chpid
.id
);
501 chp
= chpid_to_chp(chpid
);
506 mutex_lock(&chp
->lock
);
507 chp_update_desc(chp
);
508 mutex_unlock(&chp
->lock
);
512 struct chp_config_data
{
518 static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area
*sei_area
)
520 struct chp_config_data
*data
;
523 char *events
[3] = {"configure", "deconfigure", "cancel deconfigure"};
525 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
526 if (sei_area
->rs
!= 0)
528 data
= (struct chp_config_data
*) &(sei_area
->ccdf
);
530 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
531 if (!chp_test_bit(data
->map
, num
))
534 pr_notice("Processing %s for channel path %x.%02x\n",
535 events
[data
->op
], chpid
.cssid
, chpid
.id
);
538 chp_cfg_schedule(chpid
, 1);
541 chp_cfg_schedule(chpid
, 0);
544 chp_cfg_cancel_deconfigure(chpid
);
550 static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area
*sei_area
)
554 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
555 if (sei_area
->rs
!= 7)
558 ret
= scm_update_information();
560 CIO_CRW_EVENT(0, "chsc: updating change notification"
561 " failed (rc=%d).\n", ret
);
564 static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area
*sei_area
)
568 CIO_CRW_EVENT(4, "chsc: scm available information\n");
569 if (sei_area
->rs
!= 7)
572 ret
= scm_process_availability_information();
574 CIO_CRW_EVENT(0, "chsc: process availability information"
575 " failed (rc=%d).\n", ret
);
578 static void chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area
*sei_area
)
580 CIO_CRW_EVENT(3, "chsc: ap config changed\n");
581 if (sei_area
->rs
!= 5)
587 static void chsc_process_sei_fces_event(struct chsc_sei_nt0_area
*sei_area
)
589 struct chp_link link
;
591 struct channel_path
*chp
;
594 "chsc: FCES status notification (rs=%02x, rs_id=%04x, FCES-status=%x)\n",
595 sei_area
->rs
, sei_area
->rsid
, sei_area
->ccdf
[0]);
597 if (sei_area
->rs
!= SEI_RS_CHPID
)
600 chpid
.id
= sei_area
->rsid
;
602 /* Ignore the event on unknown/invalid chp */
603 chp
= chpid_to_chp(chpid
);
607 memset(&link
, 0, sizeof(struct chp_link
));
609 chsc_link_from_sei(&link
, sei_area
);
611 for_each_subchannel_staged(process_fces_event
, NULL
, &link
);
614 static void chsc_process_sei_nt2(struct chsc_sei_nt2_area
*sei_area
)
616 switch (sei_area
->cc
) {
618 zpci_event_error(sei_area
->ccdf
);
621 zpci_event_availability(sei_area
->ccdf
);
624 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
630 static void chsc_process_sei_nt0(struct chsc_sei_nt0_area
*sei_area
)
632 /* which kind of information was stored? */
633 switch (sei_area
->cc
) {
634 case 1: /* link incident*/
635 chsc_process_sei_link_incident(sei_area
);
637 case 2: /* i/o resource accessibility */
638 chsc_process_sei_res_acc(sei_area
);
640 case 3: /* ap config changed */
641 chsc_process_sei_ap_cfg_chg(sei_area
);
643 case 7: /* channel-path-availability information */
644 chsc_process_sei_chp_avail(sei_area
);
646 case 8: /* channel-path-configuration notification */
647 chsc_process_sei_chp_config(sei_area
);
649 case 12: /* scm change notification */
650 chsc_process_sei_scm_change(sei_area
);
652 case 14: /* scm available notification */
653 chsc_process_sei_scm_avail(sei_area
);
655 case 15: /* FCES event notification */
656 chsc_process_sei_fces_event(sei_area
);
658 default: /* other stuff */
659 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
664 /* Check if we might have lost some information. */
665 if (sei_area
->flags
& 0x40) {
666 CIO_CRW_EVENT(2, "chsc: event overflow\n");
667 css_schedule_eval_all();
671 static void chsc_process_event_information(struct chsc_sei
*sei
, u64 ntsm
)
673 static int ntsm_unsupported
;
676 memset(sei
, 0, sizeof(*sei
));
677 sei
->request
.length
= 0x0010;
678 sei
->request
.code
= 0x000e;
679 if (!ntsm_unsupported
)
685 if (sei
->response
.code
!= 0x0001) {
686 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x, ntsm=%llx)\n",
687 sei
->response
.code
, sei
->ntsm
);
689 if (sei
->response
.code
== 3 && sei
->ntsm
) {
690 /* Fallback for old firmware. */
691 ntsm_unsupported
= 1;
697 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei
->nt
);
700 chsc_process_sei_nt0(&sei
->u
.nt0_area
);
703 chsc_process_sei_nt2(&sei
->u
.nt2_area
);
706 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei
->nt
);
710 if (!(sei
->u
.nt0_area
.flags
& 0x80))
716 * Handle channel subsystem related CRWs.
717 * Use store event information to find out what's going on.
719 * Note: Access to sei_page is serialized through machine check handler
720 * thread, so no need for locking.
722 static void chsc_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
724 struct chsc_sei
*sei
= sei_page
;
727 css_schedule_eval_all();
730 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
731 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
732 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
733 crw0
->erc
, crw0
->rsid
);
735 CIO_TRACE_EVENT(2, "prcss");
736 chsc_process_event_information(sei
, CHSC_SEI_NT0
| CHSC_SEI_NT2
);
739 void chsc_chp_online(struct chp_id chpid
)
741 struct channel_path
*chp
= chpid_to_chp(chpid
);
742 struct chp_link link
;
745 sprintf(dbf_txt
, "cadd%x.%02x", chpid
.cssid
, chpid
.id
);
746 CIO_TRACE_EVENT(2, dbf_txt
);
748 if (chp_get_status(chpid
) != 0) {
749 memset(&link
, 0, sizeof(struct chp_link
));
751 /* Wait until previous actions have settled. */
752 css_wait_for_slow_path();
754 mutex_lock(&chp
->lock
);
755 chp_update_desc(chp
);
756 mutex_unlock(&chp
->lock
);
758 for_each_subchannel_staged(__s390_process_res_acc
, NULL
,
760 css_schedule_reprobe();
764 static void __s390_subchannel_vary_chpid(struct subchannel
*sch
,
765 struct chp_id chpid
, int on
)
768 struct chp_link link
;
770 memset(&link
, 0, sizeof(struct chp_link
));
772 spin_lock_irqsave(sch
->lock
, flags
);
773 if (sch
->driver
&& sch
->driver
->chp_event
)
774 sch
->driver
->chp_event(sch
, &link
,
775 on
? CHP_VARY_ON
: CHP_VARY_OFF
);
776 spin_unlock_irqrestore(sch
->lock
, flags
);
779 static int s390_subchannel_vary_chpid_off(struct subchannel
*sch
, void *data
)
781 struct chp_id
*chpid
= data
;
783 __s390_subchannel_vary_chpid(sch
, *chpid
, 0);
787 static int s390_subchannel_vary_chpid_on(struct subchannel
*sch
, void *data
)
789 struct chp_id
*chpid
= data
;
791 __s390_subchannel_vary_chpid(sch
, *chpid
, 1);
796 * chsc_chp_vary - propagate channel-path vary operation to subchannels
797 * @chpid: channl-path ID
798 * @on: non-zero for vary online, zero for vary offline
800 int chsc_chp_vary(struct chp_id chpid
, int on
)
802 struct channel_path
*chp
= chpid_to_chp(chpid
);
804 /* Wait until previous actions have settled. */
805 css_wait_for_slow_path();
807 * Redo PathVerification on the devices the chpid connects to
810 /* Try to update the channel path description. */
811 chp_update_desc(chp
);
812 for_each_subchannel_staged(s390_subchannel_vary_chpid_on
,
814 css_schedule_reprobe();
816 for_each_subchannel_staged(s390_subchannel_vary_chpid_off
,
823 chsc_remove_cmg_attr(struct channel_subsystem
*css
)
827 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
830 chp_remove_cmg_attr(css
->chps
[i
]);
835 chsc_add_cmg_attr(struct channel_subsystem
*css
)
840 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
843 ret
= chp_add_cmg_attr(css
->chps
[i
]);
849 for (--i
; i
>= 0; i
--) {
852 chp_remove_cmg_attr(css
->chps
[i
]);
857 int __chsc_do_secm(struct channel_subsystem
*css
, int enable
)
860 struct chsc_header request
;
861 u32 operation_code
: 2;
870 struct chsc_header response
;
879 spin_lock_irqsave(&chsc_page_lock
, flags
);
880 memset(chsc_page
, 0, PAGE_SIZE
);
881 secm_area
= chsc_page
;
882 secm_area
->request
.length
= 0x0050;
883 secm_area
->request
.code
= 0x0016;
885 secm_area
->key
= PAGE_DEFAULT_KEY
>> 4;
886 secm_area
->cub_addr1
= (u64
)(unsigned long)css
->cub_addr1
;
887 secm_area
->cub_addr2
= (u64
)(unsigned long)css
->cub_addr2
;
889 secm_area
->operation_code
= enable
? 0 : 1;
891 ccode
= chsc(secm_area
);
893 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
897 switch (secm_area
->response
.code
) {
903 ret
= chsc_error_from_response(secm_area
->response
.code
);
906 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
907 secm_area
->response
.code
);
909 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
914 chsc_secm(struct channel_subsystem
*css
, int enable
)
918 if (enable
&& !css
->cm_enabled
) {
919 css
->cub_addr1
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
920 css
->cub_addr2
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
921 if (!css
->cub_addr1
|| !css
->cub_addr2
) {
922 free_page((unsigned long)css
->cub_addr1
);
923 free_page((unsigned long)css
->cub_addr2
);
927 ret
= __chsc_do_secm(css
, enable
);
929 css
->cm_enabled
= enable
;
930 if (css
->cm_enabled
) {
931 ret
= chsc_add_cmg_attr(css
);
933 __chsc_do_secm(css
, 0);
937 chsc_remove_cmg_attr(css
);
939 if (!css
->cm_enabled
) {
940 free_page((unsigned long)css
->cub_addr1
);
941 free_page((unsigned long)css
->cub_addr2
);
946 int chsc_determine_channel_path_desc(struct chp_id chpid
, int fmt
, int rfmt
,
947 int c
, int m
, void *page
)
949 struct chsc_scpd
*scpd_area
;
952 if ((rfmt
== 1 || rfmt
== 0) && c
== 1 &&
953 !css_general_characteristics
.fcs
)
955 if ((rfmt
== 2) && !css_general_characteristics
.cib
)
957 if ((rfmt
== 3) && !css_general_characteristics
.util_str
)
960 memset(page
, 0, PAGE_SIZE
);
962 scpd_area
->request
.length
= 0x0010;
963 scpd_area
->request
.code
= 0x0002;
964 scpd_area
->cssid
= chpid
.cssid
;
965 scpd_area
->first_chpid
= chpid
.id
;
966 scpd_area
->last_chpid
= chpid
.id
;
969 scpd_area
->fmt
= fmt
;
970 scpd_area
->rfmt
= rfmt
;
972 ccode
= chsc(scpd_area
);
974 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
976 ret
= chsc_error_from_response(scpd_area
->response
.code
);
978 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
979 scpd_area
->response
.code
);
982 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc
);
984 #define chsc_det_chp_desc(FMT, c) \
985 int chsc_determine_fmt##FMT##_channel_path_desc( \
986 struct chp_id chpid, struct channel_path_desc_fmt##FMT *desc) \
988 struct chsc_scpd *scpd_area; \
989 unsigned long flags; \
992 spin_lock_irqsave(&chsc_page_lock, flags); \
993 scpd_area = chsc_page; \
994 ret = chsc_determine_channel_path_desc(chpid, 0, FMT, c, 0, \
999 memcpy(desc, scpd_area->data, sizeof(*desc)); \
1001 spin_unlock_irqrestore(&chsc_page_lock, flags); \
1005 chsc_det_chp_desc(0, 0)
1006 chsc_det_chp_desc(1, 1)
1007 chsc_det_chp_desc(3, 0)
1010 chsc_initialize_cmg_chars(struct channel_path
*chp
, u8 cmcv
,
1011 struct cmg_chars
*chars
)
1015 for (i
= 0; i
< NR_MEASUREMENT_CHARS
; i
++) {
1016 mask
= 0x80 >> (i
+ 3);
1018 chp
->cmg_chars
.values
[i
] = chars
->values
[i
];
1020 chp
->cmg_chars
.values
[i
] = 0;
1024 int chsc_get_channel_measurement_chars(struct channel_path
*chp
)
1026 unsigned long flags
;
1030 struct chsc_header request
;
1032 u32 first_chpid
: 8;
1036 struct chsc_header response
;
1047 u32 data
[NR_MEASUREMENT_CHARS
];
1053 if (!css_chsc_characteristics
.scmc
|| !css_chsc_characteristics
.secm
)
1056 spin_lock_irqsave(&chsc_page_lock
, flags
);
1057 memset(chsc_page
, 0, PAGE_SIZE
);
1058 scmc_area
= chsc_page
;
1059 scmc_area
->request
.length
= 0x0010;
1060 scmc_area
->request
.code
= 0x0022;
1061 scmc_area
->first_chpid
= chp
->chpid
.id
;
1062 scmc_area
->last_chpid
= chp
->chpid
.id
;
1064 ccode
= chsc(scmc_area
);
1066 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
1070 ret
= chsc_error_from_response(scmc_area
->response
.code
);
1072 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
1073 scmc_area
->response
.code
);
1076 if (scmc_area
->not_valid
)
1079 chp
->cmg
= scmc_area
->cmg
;
1080 chp
->shared
= scmc_area
->shared
;
1081 if (chp
->cmg
!= 2 && chp
->cmg
!= 3) {
1082 /* No cmg-dependent data. */
1085 chsc_initialize_cmg_chars(chp
, scmc_area
->cmcv
,
1086 (struct cmg_chars
*) &scmc_area
->data
);
1088 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1092 int __init
chsc_init(void)
1096 sei_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1097 chsc_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1098 if (!sei_page
|| !chsc_page
) {
1102 ret
= crw_register_handler(CRW_RSC_CSS
, chsc_process_crw
);
1107 free_page((unsigned long)chsc_page
);
1108 free_page((unsigned long)sei_page
);
1112 void __init
chsc_init_cleanup(void)
1114 crw_unregister_handler(CRW_RSC_CSS
);
1115 free_page((unsigned long)chsc_page
);
1116 free_page((unsigned long)sei_page
);
1119 int __chsc_enable_facility(struct chsc_sda_area
*sda_area
, int operation_code
)
1123 sda_area
->request
.length
= 0x0400;
1124 sda_area
->request
.code
= 0x0031;
1125 sda_area
->operation_code
= operation_code
;
1127 ret
= chsc(sda_area
);
1129 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
1133 switch (sda_area
->response
.code
) {
1138 ret
= chsc_error_from_response(sda_area
->response
.code
);
1144 int chsc_enable_facility(int operation_code
)
1146 struct chsc_sda_area
*sda_area
;
1147 unsigned long flags
;
1150 spin_lock_irqsave(&chsc_page_lock
, flags
);
1151 memset(chsc_page
, 0, PAGE_SIZE
);
1152 sda_area
= chsc_page
;
1154 ret
= __chsc_enable_facility(sda_area
, operation_code
);
1156 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1157 operation_code
, sda_area
->response
.code
);
1159 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1163 int __init
chsc_get_cssid_iid(int idx
, u8
*cssid
, u8
*iid
)
1166 struct chsc_header request
;
1170 struct chsc_header response
;
1180 spin_lock_irq(&chsc_page_lock
);
1181 memset(chsc_page
, 0, PAGE_SIZE
);
1182 sdcal_area
= chsc_page
;
1183 sdcal_area
->request
.length
= 0x0020;
1184 sdcal_area
->request
.code
= 0x0034;
1185 sdcal_area
->atype
= 4;
1187 ret
= chsc(sdcal_area
);
1189 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
1193 ret
= chsc_error_from_response(sdcal_area
->response
.code
);
1195 CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
1196 sdcal_area
->response
.code
);
1200 if ((addr_t
) &sdcal_area
->list
[idx
] <
1201 (addr_t
) &sdcal_area
->response
+ sdcal_area
->response
.length
) {
1202 *cssid
= sdcal_area
->list
[idx
].cssid
;
1203 *iid
= sdcal_area
->list
[idx
].iid
;
1208 spin_unlock_irq(&chsc_page_lock
);
1212 struct css_general_char css_general_characteristics
;
1213 struct css_chsc_char css_chsc_characteristics
;
1216 chsc_determine_css_characteristics(void)
1218 unsigned long flags
;
1221 struct chsc_header request
;
1225 struct chsc_header response
;
1227 u32 general_char
[510];
1231 spin_lock_irqsave(&chsc_page_lock
, flags
);
1232 memset(chsc_page
, 0, PAGE_SIZE
);
1233 scsc_area
= chsc_page
;
1234 scsc_area
->request
.length
= 0x0010;
1235 scsc_area
->request
.code
= 0x0010;
1237 result
= chsc(scsc_area
);
1239 result
= (result
== 3) ? -ENODEV
: -EBUSY
;
1243 result
= chsc_error_from_response(scsc_area
->response
.code
);
1245 memcpy(&css_general_characteristics
, scsc_area
->general_char
,
1246 sizeof(css_general_characteristics
));
1247 memcpy(&css_chsc_characteristics
, scsc_area
->chsc_char
,
1248 sizeof(css_chsc_characteristics
));
1250 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1251 scsc_area
->response
.code
);
1253 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1257 EXPORT_SYMBOL_GPL(css_general_characteristics
);
1258 EXPORT_SYMBOL_GPL(css_chsc_characteristics
);
1260 int chsc_sstpc(void *page
, unsigned int op
, u16 ctrl
, u64
*clock_delta
)
1263 struct chsc_header request
;
1265 unsigned int op
: 8;
1266 unsigned int rsvd1
: 8;
1267 unsigned int ctrl
: 16;
1268 unsigned int rsvd2
[5];
1269 struct chsc_header response
;
1270 unsigned int rsvd3
[3];
1272 unsigned int rsvd4
[2];
1276 memset(page
, 0, PAGE_SIZE
);
1278 rr
->request
.length
= 0x0020;
1279 rr
->request
.code
= 0x0033;
1285 rc
= (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
1287 *clock_delta
= rr
->clock_delta
;
1291 int chsc_sstpi(void *page
, void *result
, size_t size
)
1294 struct chsc_header request
;
1295 unsigned int rsvd0
[3];
1296 struct chsc_header response
;
1301 memset(page
, 0, PAGE_SIZE
);
1303 rr
->request
.length
= 0x0010;
1304 rr
->request
.code
= 0x0038;
1308 memcpy(result
, &rr
->data
, size
);
1309 return (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
1312 int chsc_stzi(void *page
, void *result
, size_t size
)
1315 struct chsc_header request
;
1316 unsigned int rsvd0
[3];
1317 struct chsc_header response
;
1322 memset(page
, 0, PAGE_SIZE
);
1324 rr
->request
.length
= 0x0010;
1325 rr
->request
.code
= 0x003e;
1329 memcpy(result
, &rr
->data
, size
);
1330 return (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
1333 int chsc_siosl(struct subchannel_id schid
)
1336 struct chsc_header request
;
1338 struct subchannel_id sid
;
1340 struct chsc_header response
;
1343 unsigned long flags
;
1347 spin_lock_irqsave(&chsc_page_lock
, flags
);
1348 memset(chsc_page
, 0, PAGE_SIZE
);
1349 siosl_area
= chsc_page
;
1350 siosl_area
->request
.length
= 0x0010;
1351 siosl_area
->request
.code
= 0x0046;
1352 siosl_area
->word1
= 0x80000000;
1353 siosl_area
->sid
= schid
;
1355 ccode
= chsc(siosl_area
);
1361 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1362 schid
.ssid
, schid
.sch_no
, ccode
);
1365 rc
= chsc_error_from_response(siosl_area
->response
.code
);
1367 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1368 schid
.ssid
, schid
.sch_no
,
1369 siosl_area
->response
.code
);
1371 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1372 schid
.ssid
, schid
.sch_no
);
1374 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1377 EXPORT_SYMBOL_GPL(chsc_siosl
);
1380 * chsc_scm_info() - store SCM information (SSI)
1381 * @scm_area: request and response block for SSI
1382 * @token: continuation token
1384 * Returns 0 on success.
1386 int chsc_scm_info(struct chsc_scm_info
*scm_area
, u64 token
)
1390 memset(scm_area
, 0, sizeof(*scm_area
));
1391 scm_area
->request
.length
= 0x0020;
1392 scm_area
->request
.code
= 0x004C;
1393 scm_area
->reqtok
= token
;
1395 ccode
= chsc(scm_area
);
1397 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
1400 ret
= chsc_error_from_response(scm_area
->response
.code
);
1402 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1403 scm_area
->response
.code
);
1407 EXPORT_SYMBOL_GPL(chsc_scm_info
);
1410 * chsc_pnso() - Perform Network-Subchannel Operation
1411 * @schid: id of the subchannel on which PNSO is performed
1412 * @pnso_area: request and response block for the operation
1413 * @oc: Operation Code
1414 * @resume_token: resume token for multiblock response
1415 * @cnc: Boolean change-notification control
1417 * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
1419 * Returns 0 on success.
1421 int chsc_pnso(struct subchannel_id schid
, struct chsc_pnso_area
*pnso_area
,
1422 u8 oc
, struct chsc_pnso_resume_token resume_token
, int cnc
)
1424 memset(pnso_area
, 0, sizeof(*pnso_area
));
1425 pnso_area
->request
.length
= 0x0030;
1426 pnso_area
->request
.code
= 0x003d; /* network-subchannel operation */
1427 pnso_area
->m
= schid
.m
;
1428 pnso_area
->ssid
= schid
.ssid
;
1429 pnso_area
->sch
= schid
.sch_no
;
1430 pnso_area
->cssid
= schid
.cssid
;
1432 pnso_area
->resume_token
= resume_token
;
1433 pnso_area
->n
= (cnc
!= 0);
1434 if (chsc(pnso_area
))
1436 return chsc_error_from_response(pnso_area
->response
.code
);
1439 int chsc_sgib(u32 origin
)
1442 struct chsc_header request
;
1448 /* operation data area begin */
1453 u8 reserved06
[4029];
1454 struct chsc_header response
;
1459 spin_lock_irq(&chsc_page_lock
);
1460 memset(chsc_page
, 0, PAGE_SIZE
);
1461 sgib_area
= chsc_page
;
1462 sgib_area
->request
.length
= 0x0fe0;
1463 sgib_area
->request
.code
= 0x0021;
1464 sgib_area
->op
= 0x1;
1465 sgib_area
->gib_origin
= origin
;
1467 ret
= chsc(sgib_area
);
1469 ret
= chsc_error_from_response(sgib_area
->response
.code
);
1470 spin_unlock_irq(&chsc_page_lock
);
1474 EXPORT_SYMBOL_GPL(chsc_sgib
);
1476 #define SCUD_REQ_LEN 0x10 /* SCUD request block length */
1477 #define SCUD_REQ_CMD 0x4b /* SCUD Command Code */
1493 struct chsc_header request
;
1501 struct chsc_header response
;
1505 struct chse_cudb cudb
[];
1509 * chsc_scud() - Store control-unit description.
1510 * @cu: number of the control-unit
1511 * @esm: 8 1-byte endpoint security mode values
1512 * @esm_valid: validity mask for @esm
1514 * Interface to retrieve information about the endpoint security
1515 * modes for up to 8 paths of a control unit.
1517 * Returns 0 on success.
1519 int chsc_scud(u16 cu
, u64
*esm
, u8
*esm_valid
)
1521 struct chsc_scud
*scud
= chsc_page
;
1524 spin_lock_irq(&chsc_page_lock
);
1525 memset(chsc_page
, 0, PAGE_SIZE
);
1526 scud
->request
.length
= SCUD_REQ_LEN
;
1527 scud
->request
.code
= SCUD_REQ_CMD
;
1530 scud
->first_cu
= cu
;
1535 ret
= chsc_error_from_response(scud
->response
.code
);
1537 if (!ret
&& (scud
->response
.length
<= 8 || scud
->fmt_resp
!= 0
1538 || !(scud
->cudb
[0].flags
& 0x80)
1539 || scud
->cudb
[0].cu
!= cu
)) {
1541 CIO_MSG_EVENT(2, "chsc: scud failed rc=%04x, L2=%04x "
1542 "FMT=%04x, cudb.flags=%02x, cudb.cu=%04x",
1543 scud
->response
.code
, scud
->response
.length
,
1544 scud
->fmt_resp
, scud
->cudb
[0].flags
, scud
->cudb
[0].cu
);
1551 memcpy(esm
, scud
->cudb
[0].esm
, sizeof(*esm
));
1552 *esm_valid
= scud
->cudb
[0].esm_valid
;
1554 spin_unlock_irq(&chsc_page_lock
);
1557 EXPORT_SYMBOL_GPL(chsc_scud
);