2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call
5 * Copyright IBM Corp. 1999,2008
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 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/device.h>
17 #include <asm/chpid.h>
20 #include "../s390mach.h"
23 #include "cio_debug.h"
28 static void *sei_page
;
31 * chsc_error_from_response() - convert a chsc response to an error
32 * @response: chsc response code
34 * Returns an appropriate Linux error code for @response.
36 int chsc_error_from_response(int response
)
54 EXPORT_SYMBOL_GPL(chsc_error_from_response
);
56 struct chsc_ssd_area
{
57 struct chsc_header request
;
61 u16 f_sch
; /* first subchannel */
63 u16 l_sch
; /* last subchannel */
65 struct chsc_header response
;
69 u8 st
: 3; /* subchannel type */
71 u8 unit_addr
; /* unit address */
72 u16 devno
; /* device number */
75 u16 sch
; /* subchannel */
76 u8 chpid
[8]; /* chpids 0-7 */
77 u16 fla
[8]; /* full link addresses 0-7 */
78 } __attribute__ ((packed
));
80 int chsc_get_ssd_info(struct subchannel_id schid
, struct chsc_ssd_info
*ssd
)
83 struct chsc_ssd_area
*ssd_area
;
89 page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
92 ssd_area
= (struct chsc_ssd_area
*) page
;
93 ssd_area
->request
.length
= 0x0010;
94 ssd_area
->request
.code
= 0x0004;
95 ssd_area
->ssid
= schid
.ssid
;
96 ssd_area
->f_sch
= schid
.sch_no
;
97 ssd_area
->l_sch
= schid
.sch_no
;
99 ccode
= chsc(ssd_area
);
100 /* Check response. */
102 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
105 ret
= chsc_error_from_response(ssd_area
->response
.code
);
107 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
108 schid
.ssid
, schid
.sch_no
,
109 ssd_area
->response
.code
);
112 if (!ssd_area
->sch_valid
) {
118 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
119 if ((ssd_area
->st
!= SUBCHANNEL_TYPE_IO
) &&
120 (ssd_area
->st
!= SUBCHANNEL_TYPE_MSG
))
122 ssd
->path_mask
= ssd_area
->path_mask
;
123 ssd
->fla_valid_mask
= ssd_area
->fla_valid_mask
;
124 for (i
= 0; i
< 8; i
++) {
126 if (ssd_area
->path_mask
& mask
) {
127 chp_id_init(&ssd
->chpid
[i
]);
128 ssd
->chpid
[i
].id
= ssd_area
->chpid
[i
];
130 if (ssd_area
->fla_valid_mask
& mask
)
131 ssd
->fla
[i
] = ssd_area
->fla
[i
];
138 static int s390_subchannel_remove_chpid(struct subchannel
*sch
, void *data
)
140 spin_lock_irq(sch
->lock
);
141 if (sch
->driver
&& sch
->driver
->chp_event
)
142 if (sch
->driver
->chp_event(sch
, data
, CHP_OFFLINE
) != 0)
144 spin_unlock_irq(sch
->lock
);
149 spin_unlock_irq(sch
->lock
);
150 css_schedule_eval(sch
->schid
);
154 void chsc_chp_offline(struct chp_id chpid
)
157 struct chp_link link
;
159 sprintf(dbf_txt
, "chpr%x.%02x", chpid
.cssid
, chpid
.id
);
160 CIO_TRACE_EVENT(2, dbf_txt
);
162 if (chp_get_status(chpid
) <= 0)
164 memset(&link
, 0, sizeof(struct chp_link
));
166 /* Wait until previous actions have settled. */
167 css_wait_for_slow_path();
168 for_each_subchannel_staged(s390_subchannel_remove_chpid
, NULL
, &link
);
171 static int s390_process_res_acc_new_sch(struct subchannel_id schid
, void *data
)
175 * We don't know the device yet, but since a path
176 * may be available now to the device we'll have
177 * to do recognition again.
178 * Since we don't have any idea about which chpid
179 * that beast may be on we'll have to do a stsch
180 * on all devices, grr...
182 if (stsch_err(schid
, &schib
))
186 /* Put it on the slow path. */
187 css_schedule_eval(schid
);
191 static int __s390_process_res_acc(struct subchannel
*sch
, void *data
)
193 spin_lock_irq(sch
->lock
);
194 if (sch
->driver
&& sch
->driver
->chp_event
)
195 sch
->driver
->chp_event(sch
, data
, CHP_ONLINE
);
196 spin_unlock_irq(sch
->lock
);
201 static void s390_process_res_acc(struct chp_link
*link
)
205 sprintf(dbf_txt
, "accpr%x.%02x", link
->chpid
.cssid
,
207 CIO_TRACE_EVENT( 2, dbf_txt
);
208 if (link
->fla
!= 0) {
209 sprintf(dbf_txt
, "fla%x", link
->fla
);
210 CIO_TRACE_EVENT( 2, dbf_txt
);
212 /* Wait until previous actions have settled. */
213 css_wait_for_slow_path();
215 * I/O resources may have become accessible.
216 * Scan through all subchannels that may be concerned and
217 * do a validation on those.
218 * The more information we have (info), the less scanning
219 * will we have to do.
221 for_each_subchannel_staged(__s390_process_res_acc
,
222 s390_process_res_acc_new_sch
, link
);
226 __get_chpid_from_lir(void *data
)
232 /* incident-node descriptor */
234 /* attached-node descriptor */
236 /* incident-specific information */
238 } __attribute__ ((packed
)) *lir
;
242 /* NULL link incident record */
244 if (!(lir
->indesc
[0]&0xc0000000))
245 /* node descriptor not valid */
247 if (!(lir
->indesc
[0]&0x10000000))
248 /* don't handle device-type nodes - FIXME */
250 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
252 return (u16
) (lir
->indesc
[0]&0x000000ff);
255 struct chsc_sei_area
{
256 struct chsc_header request
;
260 struct chsc_header response
;
263 u8 vf
; /* validity flags */
264 u8 rs
; /* reporting source */
265 u8 cc
; /* content code */
266 u16 fla
; /* full link address */
267 u16 rsid
; /* reporting source id */
270 u8 ccdf
[4096 - 16 - 24]; /* content-code dependent field */
271 /* ccdf has to be big enough for a link-incident record */
272 } __attribute__ ((packed
));
274 static void chsc_process_sei_link_incident(struct chsc_sei_area
*sei_area
)
279 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
280 sei_area
->rs
, sei_area
->rsid
);
281 if (sei_area
->rs
!= 4)
283 id
= __get_chpid_from_lir(sei_area
->ccdf
);
285 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
289 chsc_chp_offline(chpid
);
293 static void chsc_process_sei_res_acc(struct chsc_sei_area
*sei_area
)
295 struct chp_link link
;
299 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
300 "rs_id=%04x)\n", sei_area
->rs
, sei_area
->rsid
);
301 if (sei_area
->rs
!= 4)
304 chpid
.id
= sei_area
->rsid
;
305 /* allocate a new channel path structure, if needed */
306 status
= chp_get_status(chpid
);
311 memset(&link
, 0, sizeof(struct chp_link
));
313 if ((sei_area
->vf
& 0xc0) != 0) {
314 link
.fla
= sei_area
->fla
;
315 if ((sei_area
->vf
& 0xc0) == 0xc0)
316 /* full link address */
317 link
.fla_mask
= 0xffff;
320 link
.fla_mask
= 0xff00;
322 s390_process_res_acc(&link
);
325 struct chp_config_data
{
331 static void chsc_process_sei_chp_config(struct chsc_sei_area
*sei_area
)
333 struct chp_config_data
*data
;
337 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
338 if (sei_area
->rs
!= 0)
340 data
= (struct chp_config_data
*) &(sei_area
->ccdf
);
342 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
343 if (!chp_test_bit(data
->map
, num
))
346 printk(KERN_WARNING
"cio: processing configure event %d for "
347 "chpid %x.%02x\n", data
->op
, chpid
.cssid
, chpid
.id
);
350 chp_cfg_schedule(chpid
, 1);
353 chp_cfg_schedule(chpid
, 0);
356 chp_cfg_cancel_deconfigure(chpid
);
362 static void chsc_process_sei(struct chsc_sei_area
*sei_area
)
364 /* Check if we might have lost some information. */
365 if (sei_area
->flags
& 0x40) {
366 CIO_CRW_EVENT(2, "chsc: event overflow\n");
367 css_schedule_eval_all();
369 /* which kind of information was stored? */
370 switch (sei_area
->cc
) {
371 case 1: /* link incident*/
372 chsc_process_sei_link_incident(sei_area
);
374 case 2: /* i/o resource accessibiliy */
375 chsc_process_sei_res_acc(sei_area
);
377 case 8: /* channel-path-configuration notification */
378 chsc_process_sei_chp_config(sei_area
);
380 default: /* other stuff */
381 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
387 static void chsc_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
389 struct chsc_sei_area
*sei_area
;
392 css_schedule_eval_all();
395 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
396 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
397 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
398 crw0
->erc
, crw0
->rsid
);
401 /* Access to sei_page is serialized through machine check handler
402 * thread, so no need for locking. */
405 CIO_TRACE_EVENT(2, "prcss");
407 memset(sei_area
, 0, sizeof(*sei_area
));
408 sei_area
->request
.length
= 0x0010;
409 sei_area
->request
.code
= 0x000e;
413 if (sei_area
->response
.code
== 0x0001) {
414 CIO_CRW_EVENT(4, "chsc: sei successful\n");
415 chsc_process_sei(sei_area
);
417 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
418 sei_area
->response
.code
);
421 } while (sei_area
->flags
& 0x80);
424 void chsc_chp_online(struct chp_id chpid
)
427 struct chp_link link
;
429 sprintf(dbf_txt
, "cadd%x.%02x", chpid
.cssid
, chpid
.id
);
430 CIO_TRACE_EVENT(2, dbf_txt
);
432 if (chp_get_status(chpid
) != 0) {
433 memset(&link
, 0, sizeof(struct chp_link
));
435 /* Wait until previous actions have settled. */
436 css_wait_for_slow_path();
437 for_each_subchannel_staged(__s390_process_res_acc
, NULL
,
442 static void __s390_subchannel_vary_chpid(struct subchannel
*sch
,
443 struct chp_id chpid
, int on
)
446 struct chp_link link
;
448 memset(&link
, 0, sizeof(struct chp_link
));
450 spin_lock_irqsave(sch
->lock
, flags
);
451 if (sch
->driver
&& sch
->driver
->chp_event
)
452 sch
->driver
->chp_event(sch
, &link
,
453 on
? CHP_VARY_ON
: CHP_VARY_OFF
);
454 spin_unlock_irqrestore(sch
->lock
, flags
);
457 static int s390_subchannel_vary_chpid_off(struct subchannel
*sch
, void *data
)
459 struct chp_id
*chpid
= data
;
461 __s390_subchannel_vary_chpid(sch
, *chpid
, 0);
465 static int s390_subchannel_vary_chpid_on(struct subchannel
*sch
, void *data
)
467 struct chp_id
*chpid
= data
;
469 __s390_subchannel_vary_chpid(sch
, *chpid
, 1);
474 __s390_vary_chpid_on(struct subchannel_id schid
, void *data
)
478 if (stsch_err(schid
, &schib
))
481 /* Put it on the slow path. */
482 css_schedule_eval(schid
);
487 * chsc_chp_vary - propagate channel-path vary operation to subchannels
488 * @chpid: channl-path ID
489 * @on: non-zero for vary online, zero for vary offline
491 int chsc_chp_vary(struct chp_id chpid
, int on
)
493 struct chp_link link
;
495 memset(&link
, 0, sizeof(struct chp_link
));
497 /* Wait until previous actions have settled. */
498 css_wait_for_slow_path();
500 * Redo PathVerification on the devices the chpid connects to
504 for_each_subchannel_staged(s390_subchannel_vary_chpid_on
,
505 __s390_vary_chpid_on
, &link
);
507 for_each_subchannel_staged(s390_subchannel_vary_chpid_off
,
514 chsc_remove_cmg_attr(struct channel_subsystem
*css
)
518 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
521 chp_remove_cmg_attr(css
->chps
[i
]);
526 chsc_add_cmg_attr(struct channel_subsystem
*css
)
531 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
534 ret
= chp_add_cmg_attr(css
->chps
[i
]);
540 for (--i
; i
>= 0; i
--) {
543 chp_remove_cmg_attr(css
->chps
[i
]);
549 __chsc_do_secm(struct channel_subsystem
*css
, int enable
, void *page
)
552 struct chsc_header request
;
553 u32 operation_code
: 2;
562 struct chsc_header response
;
567 } __attribute__ ((packed
)) *secm_area
;
571 secm_area
->request
.length
= 0x0050;
572 secm_area
->request
.code
= 0x0016;
574 secm_area
->key
= PAGE_DEFAULT_KEY
;
575 secm_area
->cub_addr1
= (u64
)(unsigned long)css
->cub_addr1
;
576 secm_area
->cub_addr2
= (u64
)(unsigned long)css
->cub_addr2
;
578 secm_area
->operation_code
= enable
? 0 : 1;
580 ccode
= chsc(secm_area
);
582 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
584 switch (secm_area
->response
.code
) {
589 ret
= chsc_error_from_response(secm_area
->response
.code
);
592 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
593 secm_area
->response
.code
);
598 chsc_secm(struct channel_subsystem
*css
, int enable
)
603 secm_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
607 if (enable
&& !css
->cm_enabled
) {
608 css
->cub_addr1
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
609 css
->cub_addr2
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
610 if (!css
->cub_addr1
|| !css
->cub_addr2
) {
611 free_page((unsigned long)css
->cub_addr1
);
612 free_page((unsigned long)css
->cub_addr2
);
613 free_page((unsigned long)secm_area
);
617 ret
= __chsc_do_secm(css
, enable
, secm_area
);
619 css
->cm_enabled
= enable
;
620 if (css
->cm_enabled
) {
621 ret
= chsc_add_cmg_attr(css
);
623 memset(secm_area
, 0, PAGE_SIZE
);
624 __chsc_do_secm(css
, 0, secm_area
);
628 chsc_remove_cmg_attr(css
);
630 if (!css
->cm_enabled
) {
631 free_page((unsigned long)css
->cub_addr1
);
632 free_page((unsigned long)css
->cub_addr2
);
634 free_page((unsigned long)secm_area
);
638 int chsc_determine_channel_path_desc(struct chp_id chpid
, int fmt
, int rfmt
,
640 struct chsc_response_struct
*resp
)
645 struct chsc_header request
;
657 struct chsc_header response
;
658 u8 data
[PAGE_SIZE
- 20];
659 } __attribute__ ((packed
)) *scpd_area
;
661 if ((rfmt
== 1) && !css_general_characteristics
.fcs
)
663 if ((rfmt
== 2) && !css_general_characteristics
.cib
)
665 scpd_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
669 scpd_area
->request
.length
= 0x0010;
670 scpd_area
->request
.code
= 0x0002;
672 scpd_area
->cssid
= chpid
.cssid
;
673 scpd_area
->first_chpid
= chpid
.id
;
674 scpd_area
->last_chpid
= chpid
.id
;
677 scpd_area
->fmt
= fmt
;
678 scpd_area
->rfmt
= rfmt
;
680 ccode
= chsc(scpd_area
);
682 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
686 ret
= chsc_error_from_response(scpd_area
->response
.code
);
689 memcpy(resp
, &scpd_area
->response
, scpd_area
->response
.length
);
691 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
692 scpd_area
->response
.code
);
694 free_page((unsigned long)scpd_area
);
697 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc
);
699 int chsc_determine_base_channel_path_desc(struct chp_id chpid
,
700 struct channel_path_desc
*desc
)
702 struct chsc_response_struct
*chsc_resp
;
705 chsc_resp
= kzalloc(sizeof(*chsc_resp
), GFP_KERNEL
);
708 ret
= chsc_determine_channel_path_desc(chpid
, 0, 0, 0, 0, chsc_resp
);
711 memcpy(desc
, &chsc_resp
->data
, chsc_resp
->length
);
718 chsc_initialize_cmg_chars(struct channel_path
*chp
, u8 cmcv
,
719 struct cmg_chars
*chars
)
724 chp
->cmg_chars
= kmalloc(sizeof(struct cmg_chars
),
726 if (chp
->cmg_chars
) {
728 struct cmg_chars
*cmg_chars
;
730 cmg_chars
= chp
->cmg_chars
;
731 for (i
= 0; i
< NR_MEASUREMENT_CHARS
; i
++) {
732 mask
= 0x80 >> (i
+ 3);
734 cmg_chars
->values
[i
] = chars
->values
[i
];
736 cmg_chars
->values
[i
] = 0;
741 /* No cmg-dependent data. */
746 int chsc_get_channel_measurement_chars(struct channel_path
*chp
)
751 struct chsc_header request
;
757 struct chsc_header response
;
768 u32 data
[NR_MEASUREMENT_CHARS
];
769 } __attribute__ ((packed
)) *scmc_area
;
771 scmc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
775 scmc_area
->request
.length
= 0x0010;
776 scmc_area
->request
.code
= 0x0022;
778 scmc_area
->first_chpid
= chp
->chpid
.id
;
779 scmc_area
->last_chpid
= chp
->chpid
.id
;
781 ccode
= chsc(scmc_area
);
783 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
787 ret
= chsc_error_from_response(scmc_area
->response
.code
);
790 if (!scmc_area
->not_valid
) {
791 chp
->cmg
= scmc_area
->cmg
;
792 chp
->shared
= scmc_area
->shared
;
793 chsc_initialize_cmg_chars(chp
, scmc_area
->cmcv
,
801 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
802 scmc_area
->response
.code
);
805 free_page((unsigned long)scmc_area
);
809 int __init
chsc_alloc_sei_area(void)
813 sei_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
815 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
816 "chsc machine checks!\n");
819 ret
= s390_register_crw_handler(CRW_RSC_CSS
, chsc_process_crw
);
825 void __init
chsc_free_sei_area(void)
827 s390_unregister_crw_handler(CRW_RSC_CSS
);
832 chsc_enable_facility(int operation_code
)
836 struct chsc_header request
;
843 u32 operation_data_area
[252];
844 struct chsc_header response
;
848 } __attribute__ ((packed
)) *sda_area
;
850 sda_area
= (void *)get_zeroed_page(GFP_KERNEL
|GFP_DMA
);
853 sda_area
->request
.length
= 0x0400;
854 sda_area
->request
.code
= 0x0031;
855 sda_area
->operation_code
= operation_code
;
857 ret
= chsc(sda_area
);
859 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
863 switch (sda_area
->response
.code
) {
868 ret
= chsc_error_from_response(sda_area
->response
.code
);
871 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
872 operation_code
, sda_area
->response
.code
);
874 free_page((unsigned long)sda_area
);
878 struct css_general_char css_general_characteristics
;
879 struct css_chsc_char css_chsc_characteristics
;
882 chsc_determine_css_characteristics(void)
886 struct chsc_header request
;
890 struct chsc_header response
;
892 u32 general_char
[510];
894 } __attribute__ ((packed
)) *scsc_area
;
896 scsc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
900 scsc_area
->request
.length
= 0x0010;
901 scsc_area
->request
.code
= 0x0010;
903 result
= chsc(scsc_area
);
905 result
= (result
== 3) ? -ENODEV
: -EBUSY
;
909 result
= chsc_error_from_response(scsc_area
->response
.code
);
911 memcpy(&css_general_characteristics
, scsc_area
->general_char
,
912 sizeof(css_general_characteristics
));
913 memcpy(&css_chsc_characteristics
, scsc_area
->chsc_char
,
914 sizeof(css_chsc_characteristics
));
916 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
917 scsc_area
->response
.code
);
919 free_page ((unsigned long) scsc_area
);
923 EXPORT_SYMBOL_GPL(css_general_characteristics
);
924 EXPORT_SYMBOL_GPL(css_chsc_characteristics
);
926 int chsc_sstpc(void *page
, unsigned int op
, u16 ctrl
)
929 struct chsc_header request
;
932 unsigned int rsvd1
: 8;
933 unsigned int ctrl
: 16;
934 unsigned int rsvd2
[5];
935 struct chsc_header response
;
936 unsigned int rsvd3
[7];
937 } __attribute__ ((packed
)) *rr
;
940 memset(page
, 0, PAGE_SIZE
);
942 rr
->request
.length
= 0x0020;
943 rr
->request
.code
= 0x0033;
949 rc
= (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
953 int chsc_sstpi(void *page
, void *result
, size_t size
)
956 struct chsc_header request
;
957 unsigned int rsvd0
[3];
958 struct chsc_header response
;
960 } __attribute__ ((packed
)) *rr
;
963 memset(page
, 0, PAGE_SIZE
);
965 rr
->request
.length
= 0x0010;
966 rr
->request
.code
= 0x0038;
970 memcpy(result
, &rr
->data
, size
);
971 return (rr
->response
.code
== 0x0001) ? 0 : -EIO
;