1 // SPDX-License-Identifier: GPL-2.0
3 * S/390 common I/O routines -- channel subsystem call
5 * Copyright IBM Corp. 1999,2012
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);
41 * chsc_error_from_response() - convert a chsc response to an error
42 * @response: chsc response code
44 * Returns an appropriate Linux error code for @response.
46 int chsc_error_from_response(int response)
60 case 0x0106: /* "Wrong Channel Parm" for the op 0x003d */
63 case 0x0107: /* "Channel busy" for the op 0x003d */
68 case 0x0108: /* "HW limit exceeded" for the op 0x003d */
74 EXPORT_SYMBOL_GPL(chsc_error_from_response);
76 struct chsc_ssd_area {
77 struct chsc_header request;
81 u16 f_sch; /* first subchannel */
83 u16 l_sch; /* last subchannel */
85 struct chsc_header response;
89 u8 st : 3; /* subchannel type */
91 u8 unit_addr; /* unit address */
92 u16 devno; /* device number */
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);
100 int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
102 struct chsc_ssd_area *ssd_area;
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;
118 ccode = chsc(ssd_area);
119 /* Check response. */
121 ret = (ccode == 3) ? -ENODEV : -EBUSY;
124 ret = chsc_error_from_response(ssd_area->response.code);
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);
131 if (!ssd_area->sch_valid) {
137 memset(ssd, 0, sizeof(struct chsc_ssd_info));
138 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
139 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
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++) {
145 if (ssd_area->path_mask & mask) {
146 chp_id_init(&ssd->chpid[i]);
147 ssd->chpid[i].id = ssd_area->chpid[i];
149 if (ssd_area->fla_valid_mask & mask)
150 ssd->fla[i] = ssd_area->fla[i];
153 spin_unlock_irqrestore(&chsc_page_lock, flags);
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
162 * Returns 0 on success.
164 int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
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;
176 return chsc_error_from_response(ssqd->response.code);
178 EXPORT_SYMBOL_GPL(chsc_ssqd);
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
188 * Returns 0 on success.
190 int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
191 u64 summary_indicator_addr, u64 subchannel_indicator_addr, u8 isc)
193 memset(scssc, 0, sizeof(*scssc));
194 scssc->request.length = 0x0fe0;
195 scssc->request.code = 0x0021;
196 scssc->operation_code = 0;
198 scssc->summary_indicator_addr = summary_indicator_addr;
199 scssc->subchannel_indicator_addr = subchannel_indicator_addr;
201 scssc->ks = PAGE_DEFAULT_KEY >> 4;
202 scssc->kc = PAGE_DEFAULT_KEY >> 4;
204 scssc->schid = schid;
206 /* enable the time delay disablement facility */
207 if (css_general_characteristics.aif_tdd)
208 scssc->word_with_d_bit = 0x10000000;
213 return chsc_error_from_response(scssc->response.code);
215 EXPORT_SYMBOL_GPL(chsc_sadc);
217 static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
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)
223 spin_unlock_irq(sch->lock);
228 spin_unlock_irq(sch->lock);
229 css_schedule_eval(sch->schid);
233 void chsc_chp_offline(struct chp_id chpid)
235 struct channel_path *chp = chpid_to_chp(chpid);
236 struct chp_link link;
239 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
240 CIO_TRACE_EVENT(2, dbf_txt);
242 if (chp_get_status(chpid) <= 0)
244 memset(&link, 0, sizeof(struct chp_link));
246 /* Wait until previous actions have settled. */
247 css_wait_for_slow_path();
249 mutex_lock(&chp->lock);
250 chp_update_desc(chp);
251 mutex_unlock(&chp->lock);
253 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
256 static int __s390_process_res_acc(struct subchannel *sch, void *data)
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);
266 static void s390_process_res_acc(struct chp_link *link)
270 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
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);
277 /* Wait until previous actions have settled. */
278 css_wait_for_slow_path();
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.
286 for_each_subchannel_staged(__s390_process_res_acc, NULL, link);
287 css_schedule_reprobe();
290 struct chsc_sei_nt0_area {
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 */
299 /* ccdf has to be big enough for a link-incident record */
300 u8 ccdf[PAGE_SIZE - 24 - 16]; /* content-code dependent field */
303 struct chsc_sei_nt2_area {
304 u8 flags; /* p and v bit */
307 u8 cc; /* content code */
309 u8 ccdf[PAGE_SIZE - 24 - 56]; /* content-code dependent field */
312 #define CHSC_SEI_NT0 (1ULL << 63)
313 #define CHSC_SEI_NT2 (1ULL << 61)
316 struct chsc_header request;
318 u64 ntsm; /* notification type mask */
319 struct chsc_header response;
323 struct chsc_sei_nt0_area nt0_area;
324 struct chsc_sei_nt2_area nt2_area;
325 u8 nt_area[PAGE_SIZE - 24];
327 } __packed __aligned(PAGE_SIZE);
330 * Link Incident Record as defined in SA22-7202, "ESCON I/O Interface"
333 #define LIR_IQ_CLASS_INFO 0
334 #define LIR_IQ_CLASS_DEGRADED 1
335 #define LIR_IQ_CLASS_NOT_OPERATIONAL 2
346 struct node_descriptor incident_node;
347 struct node_descriptor attached_node;
351 #define PARAMS_LEN 10 /* PARAMS=xx,xxxxxx */
352 #define NODEID_LEN 35 /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
354 /* Copy EBCIDC text, convert to ASCII and optionally add delimiter. */
355 static char *store_ebcdic(char *dest, const char *src, unsigned long len,
358 memcpy(dest, src, len);
367 /* Format node ID and parameters for output in LIR log message. */
368 static void format_node_data(char *params, char *id, struct node_descriptor *nd)
370 memset(params, 0, PARAMS_LEN);
371 memset(id, 0, NODEID_LEN);
373 if (nd->validity != ND_VALIDITY_VALID) {
374 strncpy(params, "n/a", PARAMS_LEN - 1);
375 strncpy(id, "n/a", NODEID_LEN - 1);
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);
390 static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
392 struct lir *lir = (struct lir *) &sei_area->ccdf;
393 char iuparams[PARAMS_LEN], iunodeid[NODEID_LEN], auparams[PARAMS_LEN],
394 aunodeid[NODEID_LEN];
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]);
399 /* Ignore NULL Link Incident Records. */
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. */
407 format_node_data(iuparams, iunodeid, &lir->incident_node);
408 format_node_data(auparams, aunodeid, &lir->attached_node);
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);
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);
428 static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
430 struct channel_path *chp;
431 struct chp_link link;
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)
440 chpid.id = sei_area->rsid;
441 /* allocate a new channel path structure, if needed */
442 status = chp_get_status(chpid);
449 chp = chpid_to_chp(chpid);
450 mutex_lock(&chp->lock);
451 chp_update_desc(chp);
452 mutex_unlock(&chp->lock);
454 memset(&link, 0, sizeof(struct chp_link));
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;
463 link.fla_mask = 0xff00;
465 s390_process_res_acc(&link);
468 static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
470 struct channel_path *chp;
475 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
476 if (sei_area->rs != 0)
478 data = sei_area->ccdf;
480 for (num = 0; num <= __MAX_CHPID; num++) {
481 if (!chp_test_bit(data, num))
485 CIO_CRW_EVENT(4, "Update information for channel path "
486 "%x.%02x\n", chpid.cssid, chpid.id);
487 chp = chpid_to_chp(chpid);
492 mutex_lock(&chp->lock);
493 chp_update_desc(chp);
494 mutex_unlock(&chp->lock);
498 struct chp_config_data {
504 static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
506 struct chp_config_data *data;
509 char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
511 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
512 if (sei_area->rs != 0)
514 data = (struct chp_config_data *) &(sei_area->ccdf);
516 for (num = 0; num <= __MAX_CHPID; num++) {
517 if (!chp_test_bit(data->map, num))
520 pr_notice("Processing %s for channel path %x.%02x\n",
521 events[data->op], chpid.cssid, chpid.id);
524 chp_cfg_schedule(chpid, 1);
527 chp_cfg_schedule(chpid, 0);
530 chp_cfg_cancel_deconfigure(chpid);
536 static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
540 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
541 if (sei_area->rs != 7)
544 ret = scm_update_information();
546 CIO_CRW_EVENT(0, "chsc: updating change notification"
547 " failed (rc=%d).\n", ret);
550 static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
554 CIO_CRW_EVENT(4, "chsc: scm available information\n");
555 if (sei_area->rs != 7)
558 ret = scm_process_availability_information();
560 CIO_CRW_EVENT(0, "chsc: process availability information"
561 " failed (rc=%d).\n", ret);
564 static void chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area *sei_area)
566 CIO_CRW_EVENT(3, "chsc: ap config changed\n");
567 if (sei_area->rs != 5)
573 static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
575 switch (sei_area->cc) {
577 zpci_event_error(sei_area->ccdf);
580 zpci_event_availability(sei_area->ccdf);
583 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
589 static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
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);
596 case 2: /* i/o resource accessibility */
597 chsc_process_sei_res_acc(sei_area);
599 case 3: /* ap config changed */
600 chsc_process_sei_ap_cfg_chg(sei_area);
602 case 7: /* channel-path-availability information */
603 chsc_process_sei_chp_avail(sei_area);
605 case 8: /* channel-path-configuration notification */
606 chsc_process_sei_chp_config(sei_area);
608 case 12: /* scm change notification */
609 chsc_process_sei_scm_change(sei_area);
611 case 14: /* scm available notification */
612 chsc_process_sei_scm_avail(sei_area);
614 default: /* other stuff */
615 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
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();
627 static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
629 static int ntsm_unsupported;
632 memset(sei, 0, sizeof(*sei));
633 sei->request.length = 0x0010;
634 sei->request.code = 0x000e;
635 if (!ntsm_unsupported)
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);
645 if (sei->response.code == 3 && sei->ntsm) {
646 /* Fallback for old firmware. */
647 ntsm_unsupported = 1;
653 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
656 chsc_process_sei_nt0(&sei->u.nt0_area);
659 chsc_process_sei_nt2(&sei->u.nt2_area);
662 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
666 if (!(sei->u.nt0_area.flags & 0x80))
672 * Handle channel subsystem related CRWs.
673 * Use store event information to find out what's going on.
675 * Note: Access to sei_page is serialized through machine check handler
676 * thread, so no need for locking.
678 static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
680 struct chsc_sei *sei = sei_page;
683 css_schedule_eval_all();
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);
691 CIO_TRACE_EVENT(2, "prcss");
692 chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
695 void chsc_chp_online(struct chp_id chpid)
697 struct channel_path *chp = chpid_to_chp(chpid);
698 struct chp_link link;
701 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
702 CIO_TRACE_EVENT(2, dbf_txt);
704 if (chp_get_status(chpid) != 0) {
705 memset(&link, 0, sizeof(struct chp_link));
707 /* Wait until previous actions have settled. */
708 css_wait_for_slow_path();
710 mutex_lock(&chp->lock);
711 chp_update_desc(chp);
712 mutex_unlock(&chp->lock);
714 for_each_subchannel_staged(__s390_process_res_acc, NULL,
716 css_schedule_reprobe();
720 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
721 struct chp_id chpid, int on)
724 struct chp_link link;
726 memset(&link, 0, sizeof(struct chp_link));
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);
735 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
737 struct chp_id *chpid = data;
739 __s390_subchannel_vary_chpid(sch, *chpid, 0);
743 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
745 struct chp_id *chpid = data;
747 __s390_subchannel_vary_chpid(sch, *chpid, 1);
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
756 int chsc_chp_vary(struct chp_id chpid, int on)
758 struct channel_path *chp = chpid_to_chp(chpid);
760 /* Wait until previous actions have settled. */
761 css_wait_for_slow_path();
763 * Redo PathVerification on the devices the chpid connects to
766 /* Try to update the channel path description. */
767 chp_update_desc(chp);
768 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
770 css_schedule_reprobe();
772 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
779 chsc_remove_cmg_attr(struct channel_subsystem *css)
783 for (i = 0; i <= __MAX_CHPID; i++) {
786 chp_remove_cmg_attr(css->chps[i]);
791 chsc_add_cmg_attr(struct channel_subsystem *css)
796 for (i = 0; i <= __MAX_CHPID; i++) {
799 ret = chp_add_cmg_attr(css->chps[i]);
805 for (--i; i >= 0; i--) {
808 chp_remove_cmg_attr(css->chps[i]);
813 int __chsc_do_secm(struct channel_subsystem *css, int enable)
816 struct chsc_header request;
817 u32 operation_code : 2;
826 struct chsc_header response;
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;
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;
845 secm_area->operation_code = enable ? 0 : 1;
847 ccode = chsc(secm_area);
849 ret = (ccode == 3) ? -ENODEV : -EBUSY;
853 switch (secm_area->response.code) {
859 ret = chsc_error_from_response(secm_area->response.code);
862 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
863 secm_area->response.code);
865 spin_unlock_irqrestore(&chsc_page_lock, flags);
870 chsc_secm(struct channel_subsystem *css, int enable)
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);
883 ret = __chsc_do_secm(css, enable);
885 css->cm_enabled = enable;
886 if (css->cm_enabled) {
887 ret = chsc_add_cmg_attr(css);
889 __chsc_do_secm(css, 0);
893 chsc_remove_cmg_attr(css);
895 if (!css->cm_enabled) {
896 free_page((unsigned long)css->cub_addr1);
897 free_page((unsigned long)css->cub_addr2);
902 int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
903 int c, int m, void *page)
905 struct chsc_scpd *scpd_area;
908 if ((rfmt == 1 || rfmt == 0) && c == 1 &&
909 !css_general_characteristics.fcs)
911 if ((rfmt == 2) && !css_general_characteristics.cib)
913 if ((rfmt == 3) && !css_general_characteristics.util_str)
916 memset(page, 0, PAGE_SIZE);
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;
925 scpd_area->fmt = fmt;
926 scpd_area->rfmt = rfmt;
928 ccode = chsc(scpd_area);
930 return (ccode == 3) ? -ENODEV : -EBUSY;
932 ret = chsc_error_from_response(scpd_area->response.code);
934 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
935 scpd_area->response.code);
938 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
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) \
944 struct chsc_scpd *scpd_area; \
945 unsigned long flags; \
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, \
955 memcpy(desc, scpd_area->data, sizeof(*desc)); \
957 spin_unlock_irqrestore(&chsc_page_lock, flags); \
961 chsc_det_chp_desc(0, 0)
962 chsc_det_chp_desc(1, 1)
963 chsc_det_chp_desc(3, 0)
966 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
967 struct cmg_chars *chars)
971 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
972 mask = 0x80 >> (i + 3);
974 chp->cmg_chars.values[i] = chars->values[i];
976 chp->cmg_chars.values[i] = 0;
980 int chsc_get_channel_measurement_chars(struct channel_path *chp)
986 struct chsc_header request;
992 struct chsc_header response;
1003 u32 data[NR_MEASUREMENT_CHARS];
1009 if (!css_chsc_characteristics.scmc || !css_chsc_characteristics.secm)
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;
1020 ccode = chsc(scmc_area);
1022 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1026 ret = chsc_error_from_response(scmc_area->response.code);
1028 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
1029 scmc_area->response.code);
1032 if (scmc_area->not_valid)
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. */
1041 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1042 (struct cmg_chars *) &scmc_area->data);
1044 spin_unlock_irqrestore(&chsc_page_lock, flags);
1048 int __init chsc_init(void)
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) {
1058 ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
1063 free_page((unsigned long)chsc_page);
1064 free_page((unsigned long)sei_page);
1068 void __init chsc_init_cleanup(void)
1070 crw_unregister_handler(CRW_RSC_CSS);
1071 free_page((unsigned long)chsc_page);
1072 free_page((unsigned long)sei_page);
1075 int __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code)
1079 sda_area->request.length = 0x0400;
1080 sda_area->request.code = 0x0031;
1081 sda_area->operation_code = operation_code;
1083 ret = chsc(sda_area);
1085 ret = (ret == 3) ? -ENODEV : -EBUSY;
1089 switch (sda_area->response.code) {
1094 ret = chsc_error_from_response(sda_area->response.code);
1100 int chsc_enable_facility(int operation_code)
1102 struct chsc_sda_area *sda_area;
1103 unsigned long flags;
1106 spin_lock_irqsave(&chsc_page_lock, flags);
1107 memset(chsc_page, 0, PAGE_SIZE);
1108 sda_area = chsc_page;
1110 ret = __chsc_enable_facility(sda_area, operation_code);
1112 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1113 operation_code, sda_area->response.code);
1115 spin_unlock_irqrestore(&chsc_page_lock, flags);
1119 int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid)
1122 struct chsc_header request;
1126 struct chsc_header response;
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;
1143 ret = chsc(sdcal_area);
1145 ret = (ret == 3) ? -ENODEV : -EBUSY;
1149 ret = chsc_error_from_response(sdcal_area->response.code);
1151 CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
1152 sdcal_area->response.code);
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;
1164 spin_unlock_irq(&chsc_page_lock);
1168 struct css_general_char css_general_characteristics;
1169 struct css_chsc_char css_chsc_characteristics;
1172 chsc_determine_css_characteristics(void)
1174 unsigned long flags;
1177 struct chsc_header request;
1181 struct chsc_header response;
1183 u32 general_char[510];
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;
1193 result = chsc(scsc_area);
1195 result = (result == 3) ? -ENODEV : -EBUSY;
1199 result = chsc_error_from_response(scsc_area->response.code);
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));
1206 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1207 scsc_area->response.code);
1209 spin_unlock_irqrestore(&chsc_page_lock, flags);
1213 EXPORT_SYMBOL_GPL(css_general_characteristics);
1214 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
1216 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta)
1219 struct chsc_header request;
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];
1228 unsigned int rsvd4[2];
1232 memset(page, 0, PAGE_SIZE);
1234 rr->request.length = 0x0020;
1235 rr->request.code = 0x0033;
1241 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1243 *clock_delta = rr->clock_delta;
1247 int chsc_sstpi(void *page, void *result, size_t size)
1250 struct chsc_header request;
1251 unsigned int rsvd0[3];
1252 struct chsc_header response;
1257 memset(page, 0, PAGE_SIZE);
1259 rr->request.length = 0x0010;
1260 rr->request.code = 0x0038;
1264 memcpy(result, &rr->data, size);
1265 return (rr->response.code == 0x0001) ? 0 : -EIO;
1268 int chsc_stzi(void *page, void *result, size_t size)
1271 struct chsc_header request;
1272 unsigned int rsvd0[3];
1273 struct chsc_header response;
1278 memset(page, 0, PAGE_SIZE);
1280 rr->request.length = 0x0010;
1281 rr->request.code = 0x003e;
1285 memcpy(result, &rr->data, size);
1286 return (rr->response.code == 0x0001) ? 0 : -EIO;
1289 int chsc_siosl(struct subchannel_id schid)
1292 struct chsc_header request;
1294 struct subchannel_id sid;
1296 struct chsc_header response;
1299 unsigned long flags;
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;
1311 ccode = chsc(siosl_area);
1317 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1318 schid.ssid, schid.sch_no, ccode);
1321 rc = chsc_error_from_response(siosl_area->response.code);
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);
1327 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1328 schid.ssid, schid.sch_no);
1330 spin_unlock_irqrestore(&chsc_page_lock, flags);
1333 EXPORT_SYMBOL_GPL(chsc_siosl);
1336 * chsc_scm_info() - store SCM information (SSI)
1337 * @scm_area: request and response block for SSI
1338 * @token: continuation token
1340 * Returns 0 on success.
1342 int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
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;
1351 ccode = chsc(scm_area);
1353 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1356 ret = chsc_error_from_response(scm_area->response.code);
1358 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1359 scm_area->response.code);
1363 EXPORT_SYMBOL_GPL(chsc_scm_info);
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
1373 * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
1375 * Returns 0 on success.
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)
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;
1388 pnso_area->resume_token = resume_token;
1389 pnso_area->n = (cnc != 0);
1390 if (chsc(pnso_area))
1392 return chsc_error_from_response(pnso_area->response.code);
1395 int chsc_sgib(u32 origin)
1398 struct chsc_header request;
1404 /* operation data area begin */
1409 u8 reserved06[4029];
1410 struct chsc_header response;
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;
1423 ret = chsc(sgib_area);
1425 ret = chsc_error_from_response(sgib_area->response.code);
1426 spin_unlock_irq(&chsc_page_lock);
1430 EXPORT_SYMBOL_GPL(chsc_sgib);