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
;
30 static int chsc_error_from_response(int response
)
49 struct chsc_ssd_area
{
50 struct chsc_header request
;
54 u16 f_sch
; /* first subchannel */
56 u16 l_sch
; /* last subchannel */
58 struct chsc_header response
;
62 u8 st
: 3; /* subchannel type */
64 u8 unit_addr
; /* unit address */
65 u16 devno
; /* device number */
68 u16 sch
; /* subchannel */
69 u8 chpid
[8]; /* chpids 0-7 */
70 u16 fla
[8]; /* full link addresses 0-7 */
71 } __attribute__ ((packed
));
73 int chsc_get_ssd_info(struct subchannel_id schid
, struct chsc_ssd_info
*ssd
)
76 struct chsc_ssd_area
*ssd_area
;
82 page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
85 ssd_area
= (struct chsc_ssd_area
*) page
;
86 ssd_area
->request
.length
= 0x0010;
87 ssd_area
->request
.code
= 0x0004;
88 ssd_area
->ssid
= schid
.ssid
;
89 ssd_area
->f_sch
= schid
.sch_no
;
90 ssd_area
->l_sch
= schid
.sch_no
;
92 ccode
= chsc(ssd_area
);
95 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
98 ret
= chsc_error_from_response(ssd_area
->response
.code
);
100 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
101 schid
.ssid
, schid
.sch_no
,
102 ssd_area
->response
.code
);
105 if (!ssd_area
->sch_valid
) {
111 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
112 if ((ssd_area
->st
!= SUBCHANNEL_TYPE_IO
) &&
113 (ssd_area
->st
!= SUBCHANNEL_TYPE_MSG
))
115 ssd
->path_mask
= ssd_area
->path_mask
;
116 ssd
->fla_valid_mask
= ssd_area
->fla_valid_mask
;
117 for (i
= 0; i
< 8; i
++) {
119 if (ssd_area
->path_mask
& mask
) {
120 chp_id_init(&ssd
->chpid
[i
]);
121 ssd
->chpid
[i
].id
= ssd_area
->chpid
[i
];
123 if (ssd_area
->fla_valid_mask
& mask
)
124 ssd
->fla
[i
] = ssd_area
->fla
[i
];
131 static int s390_subchannel_remove_chpid(struct subchannel
*sch
, void *data
)
133 spin_lock_irq(sch
->lock
);
134 if (sch
->driver
&& sch
->driver
->chp_event
)
135 if (sch
->driver
->chp_event(sch
, data
, CHP_OFFLINE
) != 0)
137 spin_unlock_irq(sch
->lock
);
142 spin_unlock_irq(sch
->lock
);
143 css_schedule_eval(sch
->schid
);
147 void chsc_chp_offline(struct chp_id chpid
)
150 struct chp_link link
;
152 sprintf(dbf_txt
, "chpr%x.%02x", chpid
.cssid
, chpid
.id
);
153 CIO_TRACE_EVENT(2, dbf_txt
);
155 if (chp_get_status(chpid
) <= 0)
157 memset(&link
, 0, sizeof(struct chp_link
));
159 /* Wait until previous actions have settled. */
160 css_wait_for_slow_path();
161 for_each_subchannel_staged(s390_subchannel_remove_chpid
, NULL
, &link
);
164 static int s390_process_res_acc_new_sch(struct subchannel_id schid
, void *data
)
168 * We don't know the device yet, but since a path
169 * may be available now to the device we'll have
170 * to do recognition again.
171 * Since we don't have any idea about which chpid
172 * that beast may be on we'll have to do a stsch
173 * on all devices, grr...
175 if (stsch_err(schid
, &schib
))
179 /* Put it on the slow path. */
180 css_schedule_eval(schid
);
184 static int __s390_process_res_acc(struct subchannel
*sch
, void *data
)
186 spin_lock_irq(sch
->lock
);
187 if (sch
->driver
&& sch
->driver
->chp_event
)
188 sch
->driver
->chp_event(sch
, data
, CHP_ONLINE
);
189 spin_unlock_irq(sch
->lock
);
194 static void s390_process_res_acc(struct chp_link
*link
)
198 sprintf(dbf_txt
, "accpr%x.%02x", link
->chpid
.cssid
,
200 CIO_TRACE_EVENT( 2, dbf_txt
);
201 if (link
->fla
!= 0) {
202 sprintf(dbf_txt
, "fla%x", link
->fla
);
203 CIO_TRACE_EVENT( 2, dbf_txt
);
205 /* Wait until previous actions have settled. */
206 css_wait_for_slow_path();
208 * I/O resources may have become accessible.
209 * Scan through all subchannels that may be concerned and
210 * do a validation on those.
211 * The more information we have (info), the less scanning
212 * will we have to do.
214 for_each_subchannel_staged(__s390_process_res_acc
,
215 s390_process_res_acc_new_sch
, link
);
219 __get_chpid_from_lir(void *data
)
225 /* incident-node descriptor */
227 /* attached-node descriptor */
229 /* incident-specific information */
231 } __attribute__ ((packed
)) *lir
;
235 /* NULL link incident record */
237 if (!(lir
->indesc
[0]&0xc0000000))
238 /* node descriptor not valid */
240 if (!(lir
->indesc
[0]&0x10000000))
241 /* don't handle device-type nodes - FIXME */
243 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
245 return (u16
) (lir
->indesc
[0]&0x000000ff);
248 struct chsc_sei_area
{
249 struct chsc_header request
;
253 struct chsc_header response
;
256 u8 vf
; /* validity flags */
257 u8 rs
; /* reporting source */
258 u8 cc
; /* content code */
259 u16 fla
; /* full link address */
260 u16 rsid
; /* reporting source id */
263 u8 ccdf
[4096 - 16 - 24]; /* content-code dependent field */
264 /* ccdf has to be big enough for a link-incident record */
265 } __attribute__ ((packed
));
267 static void chsc_process_sei_link_incident(struct chsc_sei_area
*sei_area
)
272 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
273 sei_area
->rs
, sei_area
->rsid
);
274 if (sei_area
->rs
!= 4)
276 id
= __get_chpid_from_lir(sei_area
->ccdf
);
278 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
282 chsc_chp_offline(chpid
);
286 static void chsc_process_sei_res_acc(struct chsc_sei_area
*sei_area
)
288 struct chp_link link
;
292 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
293 "rs_id=%04x)\n", sei_area
->rs
, sei_area
->rsid
);
294 if (sei_area
->rs
!= 4)
297 chpid
.id
= sei_area
->rsid
;
298 /* allocate a new channel path structure, if needed */
299 status
= chp_get_status(chpid
);
304 memset(&link
, 0, sizeof(struct chp_link
));
306 if ((sei_area
->vf
& 0xc0) != 0) {
307 link
.fla
= sei_area
->fla
;
308 if ((sei_area
->vf
& 0xc0) == 0xc0)
309 /* full link address */
310 link
.fla_mask
= 0xffff;
313 link
.fla_mask
= 0xff00;
315 s390_process_res_acc(&link
);
318 struct chp_config_data
{
324 static void chsc_process_sei_chp_config(struct chsc_sei_area
*sei_area
)
326 struct chp_config_data
*data
;
330 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
331 if (sei_area
->rs
!= 0)
333 data
= (struct chp_config_data
*) &(sei_area
->ccdf
);
335 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
336 if (!chp_test_bit(data
->map
, num
))
339 printk(KERN_WARNING
"cio: processing configure event %d for "
340 "chpid %x.%02x\n", data
->op
, chpid
.cssid
, chpid
.id
);
343 chp_cfg_schedule(chpid
, 1);
346 chp_cfg_schedule(chpid
, 0);
349 chp_cfg_cancel_deconfigure(chpid
);
355 static void chsc_process_sei(struct chsc_sei_area
*sei_area
)
357 /* Check if we might have lost some information. */
358 if (sei_area
->flags
& 0x40) {
359 CIO_CRW_EVENT(2, "chsc: event overflow\n");
360 css_schedule_eval_all();
362 /* which kind of information was stored? */
363 switch (sei_area
->cc
) {
364 case 1: /* link incident*/
365 chsc_process_sei_link_incident(sei_area
);
367 case 2: /* i/o resource accessibiliy */
368 chsc_process_sei_res_acc(sei_area
);
370 case 8: /* channel-path-configuration notification */
371 chsc_process_sei_chp_config(sei_area
);
373 default: /* other stuff */
374 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
380 static void chsc_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
382 struct chsc_sei_area
*sei_area
;
385 css_schedule_eval_all();
388 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
389 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
390 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
391 crw0
->erc
, crw0
->rsid
);
394 /* Access to sei_page is serialized through machine check handler
395 * thread, so no need for locking. */
398 CIO_TRACE_EVENT(2, "prcss");
400 memset(sei_area
, 0, sizeof(*sei_area
));
401 sei_area
->request
.length
= 0x0010;
402 sei_area
->request
.code
= 0x000e;
406 if (sei_area
->response
.code
== 0x0001) {
407 CIO_CRW_EVENT(4, "chsc: sei successful\n");
408 chsc_process_sei(sei_area
);
410 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
411 sei_area
->response
.code
);
414 } while (sei_area
->flags
& 0x80);
417 void chsc_chp_online(struct chp_id chpid
)
420 struct chp_link link
;
422 sprintf(dbf_txt
, "cadd%x.%02x", chpid
.cssid
, chpid
.id
);
423 CIO_TRACE_EVENT(2, dbf_txt
);
425 if (chp_get_status(chpid
) != 0) {
426 memset(&link
, 0, sizeof(struct chp_link
));
428 /* Wait until previous actions have settled. */
429 css_wait_for_slow_path();
430 for_each_subchannel_staged(__s390_process_res_acc
, NULL
,
435 static void __s390_subchannel_vary_chpid(struct subchannel
*sch
,
436 struct chp_id chpid
, int on
)
439 struct chp_link link
;
441 memset(&link
, 0, sizeof(struct chp_link
));
443 spin_lock_irqsave(sch
->lock
, flags
);
444 if (sch
->driver
&& sch
->driver
->chp_event
)
445 sch
->driver
->chp_event(sch
, &link
,
446 on
? CHP_VARY_ON
: CHP_VARY_OFF
);
447 spin_unlock_irqrestore(sch
->lock
, flags
);
450 static int s390_subchannel_vary_chpid_off(struct subchannel
*sch
, void *data
)
452 struct chp_id
*chpid
= data
;
454 __s390_subchannel_vary_chpid(sch
, *chpid
, 0);
458 static int s390_subchannel_vary_chpid_on(struct subchannel
*sch
, void *data
)
460 struct chp_id
*chpid
= data
;
462 __s390_subchannel_vary_chpid(sch
, *chpid
, 1);
467 __s390_vary_chpid_on(struct subchannel_id schid
, void *data
)
471 if (stsch_err(schid
, &schib
))
474 /* Put it on the slow path. */
475 css_schedule_eval(schid
);
480 * chsc_chp_vary - propagate channel-path vary operation to subchannels
481 * @chpid: channl-path ID
482 * @on: non-zero for vary online, zero for vary offline
484 int chsc_chp_vary(struct chp_id chpid
, int on
)
486 struct chp_link link
;
488 memset(&link
, 0, sizeof(struct chp_link
));
490 /* Wait until previous actions have settled. */
491 css_wait_for_slow_path();
493 * Redo PathVerification on the devices the chpid connects to
497 for_each_subchannel_staged(s390_subchannel_vary_chpid_on
,
498 __s390_vary_chpid_on
, &link
);
500 for_each_subchannel_staged(s390_subchannel_vary_chpid_off
,
507 chsc_remove_cmg_attr(struct channel_subsystem
*css
)
511 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
514 chp_remove_cmg_attr(css
->chps
[i
]);
519 chsc_add_cmg_attr(struct channel_subsystem
*css
)
524 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
527 ret
= chp_add_cmg_attr(css
->chps
[i
]);
533 for (--i
; i
>= 0; i
--) {
536 chp_remove_cmg_attr(css
->chps
[i
]);
542 __chsc_do_secm(struct channel_subsystem
*css
, int enable
, void *page
)
545 struct chsc_header request
;
546 u32 operation_code
: 2;
555 struct chsc_header response
;
560 } __attribute__ ((packed
)) *secm_area
;
564 secm_area
->request
.length
= 0x0050;
565 secm_area
->request
.code
= 0x0016;
567 secm_area
->key
= PAGE_DEFAULT_KEY
;
568 secm_area
->cub_addr1
= (u64
)(unsigned long)css
->cub_addr1
;
569 secm_area
->cub_addr2
= (u64
)(unsigned long)css
->cub_addr2
;
571 secm_area
->operation_code
= enable
? 0 : 1;
573 ccode
= chsc(secm_area
);
575 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
577 switch (secm_area
->response
.code
) {
582 ret
= chsc_error_from_response(secm_area
->response
.code
);
585 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
586 secm_area
->response
.code
);
591 chsc_secm(struct channel_subsystem
*css
, int enable
)
596 secm_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
600 if (enable
&& !css
->cm_enabled
) {
601 css
->cub_addr1
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
602 css
->cub_addr2
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
603 if (!css
->cub_addr1
|| !css
->cub_addr2
) {
604 free_page((unsigned long)css
->cub_addr1
);
605 free_page((unsigned long)css
->cub_addr2
);
606 free_page((unsigned long)secm_area
);
610 ret
= __chsc_do_secm(css
, enable
, secm_area
);
612 css
->cm_enabled
= enable
;
613 if (css
->cm_enabled
) {
614 ret
= chsc_add_cmg_attr(css
);
616 memset(secm_area
, 0, PAGE_SIZE
);
617 __chsc_do_secm(css
, 0, secm_area
);
621 chsc_remove_cmg_attr(css
);
623 if (!css
->cm_enabled
) {
624 free_page((unsigned long)css
->cub_addr1
);
625 free_page((unsigned long)css
->cub_addr2
);
627 free_page((unsigned long)secm_area
);
631 int chsc_determine_channel_path_desc(struct chp_id chpid
, int fmt
, int rfmt
,
633 struct chsc_response_struct
*resp
)
638 struct chsc_header request
;
650 struct chsc_header response
;
651 u8 data
[PAGE_SIZE
- 20];
652 } __attribute__ ((packed
)) *scpd_area
;
654 if ((rfmt
== 1) && !css_general_characteristics
.fcs
)
656 if ((rfmt
== 2) && !css_general_characteristics
.cib
)
658 scpd_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
662 scpd_area
->request
.length
= 0x0010;
663 scpd_area
->request
.code
= 0x0002;
665 scpd_area
->cssid
= chpid
.cssid
;
666 scpd_area
->first_chpid
= chpid
.id
;
667 scpd_area
->last_chpid
= chpid
.id
;
670 scpd_area
->fmt
= fmt
;
671 scpd_area
->rfmt
= rfmt
;
673 ccode
= chsc(scpd_area
);
675 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
679 ret
= chsc_error_from_response(scpd_area
->response
.code
);
682 memcpy(resp
, &scpd_area
->response
, scpd_area
->response
.length
);
684 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
685 scpd_area
->response
.code
);
687 free_page((unsigned long)scpd_area
);
690 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc
);
692 int chsc_determine_base_channel_path_desc(struct chp_id chpid
,
693 struct channel_path_desc
*desc
)
695 struct chsc_response_struct
*chsc_resp
;
698 chsc_resp
= kzalloc(sizeof(*chsc_resp
), GFP_KERNEL
);
701 ret
= chsc_determine_channel_path_desc(chpid
, 0, 0, 0, 0, chsc_resp
);
704 memcpy(desc
, &chsc_resp
->data
, chsc_resp
->length
);
711 chsc_initialize_cmg_chars(struct channel_path
*chp
, u8 cmcv
,
712 struct cmg_chars
*chars
)
717 chp
->cmg_chars
= kmalloc(sizeof(struct cmg_chars
),
719 if (chp
->cmg_chars
) {
721 struct cmg_chars
*cmg_chars
;
723 cmg_chars
= chp
->cmg_chars
;
724 for (i
= 0; i
< NR_MEASUREMENT_CHARS
; i
++) {
725 mask
= 0x80 >> (i
+ 3);
727 cmg_chars
->values
[i
] = chars
->values
[i
];
729 cmg_chars
->values
[i
] = 0;
734 /* No cmg-dependent data. */
739 int chsc_get_channel_measurement_chars(struct channel_path
*chp
)
744 struct chsc_header request
;
750 struct chsc_header response
;
761 u32 data
[NR_MEASUREMENT_CHARS
];
762 } __attribute__ ((packed
)) *scmc_area
;
764 scmc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
768 scmc_area
->request
.length
= 0x0010;
769 scmc_area
->request
.code
= 0x0022;
771 scmc_area
->first_chpid
= chp
->chpid
.id
;
772 scmc_area
->last_chpid
= chp
->chpid
.id
;
774 ccode
= chsc(scmc_area
);
776 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
780 ret
= chsc_error_from_response(scmc_area
->response
.code
);
783 if (!scmc_area
->not_valid
) {
784 chp
->cmg
= scmc_area
->cmg
;
785 chp
->shared
= scmc_area
->shared
;
786 chsc_initialize_cmg_chars(chp
, scmc_area
->cmcv
,
794 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
795 scmc_area
->response
.code
);
798 free_page((unsigned long)scmc_area
);
802 int __init
chsc_alloc_sei_area(void)
806 sei_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
808 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
809 "chsc machine checks!\n");
812 ret
= s390_register_crw_handler(CRW_RSC_CSS
, chsc_process_crw
);
818 void __init
chsc_free_sei_area(void)
820 s390_unregister_crw_handler(CRW_RSC_CSS
);
825 chsc_enable_facility(int operation_code
)
829 struct chsc_header request
;
836 u32 operation_data_area
[252];
837 struct chsc_header response
;
841 } __attribute__ ((packed
)) *sda_area
;
843 sda_area
= (void *)get_zeroed_page(GFP_KERNEL
|GFP_DMA
);
846 sda_area
->request
.length
= 0x0400;
847 sda_area
->request
.code
= 0x0031;
848 sda_area
->operation_code
= operation_code
;
850 ret
= chsc(sda_area
);
852 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
856 switch (sda_area
->response
.code
) {
861 ret
= chsc_error_from_response(sda_area
->response
.code
);
864 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
865 operation_code
, sda_area
->response
.code
);
867 free_page((unsigned long)sda_area
);
871 struct css_general_char css_general_characteristics
;
872 struct css_chsc_char css_chsc_characteristics
;
875 chsc_determine_css_characteristics(void)
879 struct chsc_header request
;
883 struct chsc_header response
;
885 u32 general_char
[510];
887 } __attribute__ ((packed
)) *scsc_area
;
889 scsc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
893 scsc_area
->request
.length
= 0x0010;
894 scsc_area
->request
.code
= 0x0010;
896 result
= chsc(scsc_area
);
898 result
= (result
== 3) ? -ENODEV
: -EBUSY
;
902 result
= chsc_error_from_response(scsc_area
->response
.code
);
904 memcpy(&css_general_characteristics
, scsc_area
->general_char
,
905 sizeof(css_general_characteristics
));
906 memcpy(&css_chsc_characteristics
, scsc_area
->chsc_char
,
907 sizeof(css_chsc_characteristics
));
909 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
910 scsc_area
->response
.code
);
912 free_page ((unsigned long) scsc_area
);
916 EXPORT_SYMBOL_GPL(css_general_characteristics
);
917 EXPORT_SYMBOL_GPL(css_chsc_characteristics
);
919 int chsc_sstpc(void *page
, unsigned int op
, u16 ctrl
)
922 struct chsc_header request
;
925 unsigned int rsvd1
: 8;
926 unsigned int ctrl
: 16;
927 unsigned int rsvd2
[5];
928 struct chsc_header response
;
929 unsigned int rsvd3
[7];
930 } __attribute__ ((packed
)) *rr
;
933 memset(page
, 0, PAGE_SIZE
);
935 rr
->request
.length
= 0x0020;
936 rr
->request
.code
= 0x0033;
942 rc
= (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
946 int chsc_sstpi(void *page
, void *result
, size_t size
)
949 struct chsc_header request
;
950 unsigned int rsvd0
[3];
951 struct chsc_header response
;
953 } __attribute__ ((packed
)) *rr
;
956 memset(page
, 0, PAGE_SIZE
);
958 rr
->request
.length
= 0x0010;
959 rr
->request
.code
= 0x0038;
963 memcpy(result
, &rr
->data
, size
);
964 return (rr
->response
.code
== 0x0001) ? 0 : -EIO
;