2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Cornelia Huck (cornelia.huck@de.ibm.com)
9 * Arnd Bergmann (arndb@de.ibm.com)
12 #include <linux/module.h>
13 #include <linux/config.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
22 #include "cio_debug.h"
26 static void *sei_page
;
28 static int new_channel_path(int chpid
);
31 set_chp_logically_online(int chp
, int onoff
)
33 css
[0]->chps
[chp
]->state
= onoff
;
37 get_chp_status(int chp
)
39 return (css
[0]->chps
[chp
] ? css
[0]->chps
[chp
]->state
: -ENODEV
);
43 chsc_validate_chpids(struct subchannel
*sch
)
47 for (chp
= 0; chp
<= 7; chp
++) {
49 if (!get_chp_status(sch
->schib
.pmcw
.chpid
[chp
]))
50 /* disable using this path */
56 chpid_is_actually_online(int chp
)
60 state
= get_chp_status(chp
);
63 queue_work(slow_path_wq
, &slow_path_work
);
68 /* FIXME: this is _always_ called for every subchannel. shouldn't we
69 * process more than one at a time? */
71 chsc_get_sch_desc_irq(struct subchannel
*sch
, void *page
)
76 struct chsc_header request
;
80 u16 f_sch
; /* first subchannel */
82 u16 l_sch
; /* last subchannel */
84 struct chsc_header response
;
88 u8 st
: 3; /* subchannel type */
90 u8 unit_addr
; /* unit address */
91 u16 devno
; /* device number */
94 u16 sch
; /* subchannel */
95 u8 chpid
[8]; /* chpids 0-7 */
96 u16 fla
[8]; /* full link addresses 0-7 */
101 ssd_area
->request
.length
= 0x0010;
102 ssd_area
->request
.code
= 0x0004;
104 ssd_area
->ssid
= sch
->schid
.ssid
;
105 ssd_area
->f_sch
= sch
->schid
.sch_no
;
106 ssd_area
->l_sch
= sch
->schid
.sch_no
;
108 ccode
= chsc(ssd_area
);
110 pr_debug("chsc returned with ccode = %d\n", ccode
);
111 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
114 switch (ssd_area
->response
.code
) {
115 case 0x0001: /* everything ok */
118 CIO_CRW_EVENT(2, "Invalid command!\n");
121 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
124 CIO_CRW_EVENT(2, "Model does not provide ssd\n");
127 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
128 ssd_area
->response
.code
);
133 * ssd_area->st stores the type of the detected
134 * subchannel, with the following definitions:
136 * 0: I/O subchannel: All fields have meaning
137 * 1: CHSC subchannel: Only sch_val, st and sch
139 * 2: Message subchannel: All fields except unit_addr
141 * 3: ADM subchannel: Only sch_val, st and sch
144 * Other types are currently undefined.
146 if (ssd_area
->st
> 3) { /* uhm, that looks strange... */
147 CIO_CRW_EVENT(0, "Strange subchannel type %d"
148 " for sch 0.%x.%04x\n", ssd_area
->st
,
149 sch
->schid
.ssid
, sch
->schid
.sch_no
);
151 * There may have been a new subchannel type defined in the
152 * time since this code was written; since we don't know which
153 * fields have meaning and what to do with it we just jump out
157 const char *type
[4] = {"I/O", "chsc", "message", "ADM"};
158 CIO_CRW_EVENT(6, "ssd: sch 0.%x.%04x is %s subchannel\n",
159 sch
->schid
.ssid
, sch
->schid
.sch_no
,
162 sch
->ssd_info
.valid
= 1;
163 sch
->ssd_info
.type
= ssd_area
->st
;
166 if (ssd_area
->st
== 0 || ssd_area
->st
== 2) {
167 for (j
= 0; j
< 8; j
++) {
168 if (!((0x80 >> j
) & ssd_area
->path_mask
&
169 ssd_area
->fla_valid_mask
))
171 sch
->ssd_info
.chpid
[j
] = ssd_area
->chpid
[j
];
172 sch
->ssd_info
.fla
[j
] = ssd_area
->fla
[j
];
179 css_get_ssd_info(struct subchannel
*sch
)
184 page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
187 spin_lock_irq(&sch
->lock
);
188 ret
= chsc_get_sch_desc_irq(sch
, page
);
190 static int cio_chsc_err_msg
;
192 if (!cio_chsc_err_msg
) {
194 "chsc_get_sch_descriptions:"
195 " Error %d while doing chsc; "
196 "processing some machine checks may "
198 cio_chsc_err_msg
= 1;
201 spin_unlock_irq(&sch
->lock
);
202 free_page((unsigned long)page
);
205 /* Allocate channel path structures, if needed. */
206 for (j
= 0; j
< 8; j
++) {
207 chpid
= sch
->ssd_info
.chpid
[j
];
208 if (chpid
&& (get_chp_status(chpid
) < 0))
209 new_channel_path(chpid
);
216 s390_subchannel_remove_chpid(struct device
*dev
, void *data
)
220 struct subchannel
*sch
;
221 struct channel_path
*chpid
;
224 sch
= to_subchannel(dev
);
226 for (j
= 0; j
< 8; j
++)
227 if (sch
->schib
.pmcw
.chpid
[j
] == chpid
->id
)
233 spin_lock_irq(&sch
->lock
);
235 stsch(sch
->schid
, &schib
);
238 memcpy(&sch
->schib
, &schib
, sizeof(struct schib
));
239 /* Check for single path devices. */
240 if (sch
->schib
.pmcw
.pim
== 0x80)
242 if (sch
->vpm
== mask
)
245 if ((sch
->schib
.scsw
.actl
& SCSW_ACTL_DEVACT
) &&
246 (sch
->schib
.scsw
.actl
& SCSW_ACTL_SCHACT
) &&
247 (sch
->schib
.pmcw
.lpum
== mask
) &&
255 if (sch
->driver
&& sch
->driver
->termination
)
256 sch
->driver
->termination(&sch
->dev
);
260 /* trigger path verification. */
261 if (sch
->driver
&& sch
->driver
->verify
)
262 sch
->driver
->verify(&sch
->dev
);
264 spin_unlock_irq(&sch
->lock
);
267 spin_unlock_irq(&sch
->lock
);
269 if (css_enqueue_subchannel_slow(sch
->schid
)) {
270 css_clear_subchannel_slow_list();
277 s390_set_chpid_offline( __u8 chpid
)
282 sprintf(dbf_txt
, "chpr%x", chpid
);
283 CIO_TRACE_EVENT(2, dbf_txt
);
285 if (get_chp_status(chpid
) <= 0)
287 dev
= get_device(&css
[0]->chps
[chpid
]->dev
);
288 bus_for_each_dev(&css_bus_type
, NULL
, to_channelpath(dev
),
289 s390_subchannel_remove_chpid
);
291 if (need_rescan
|| css_slow_subchannels_exist())
292 queue_work(slow_path_wq
, &slow_path_work
);
296 struct res_acc_data
{
297 struct channel_path
*chp
;
303 s390_process_res_acc_sch(struct res_acc_data
*res_data
, struct subchannel
*sch
)
310 for (chp
= 0; chp
<= 7; chp
++)
312 * check if chpid is in information updated by ssd
314 if (sch
->ssd_info
.valid
&&
315 sch
->ssd_info
.chpid
[chp
] == res_data
->chp
->id
&&
316 (sch
->ssd_info
.fla
[chp
] & res_data
->fla_mask
)
326 * Do a stsch to update our subchannel structure with the
327 * new path information and eventually check for logically
330 ccode
= stsch(sch
->schid
, &sch
->schib
);
338 s390_process_res_acc_new_sch(struct subchannel_id schid
)
343 * We don't know the device yet, but since a path
344 * may be available now to the device we'll have
345 * to do recognition again.
346 * Since we don't have any idea about which chpid
347 * that beast may be on we'll have to do a stsch
348 * on all devices, grr...
350 if (stsch_err(schid
, &schib
))
352 return need_rescan
? -EAGAIN
: -ENXIO
;
354 /* Put it on the slow path. */
355 ret
= css_enqueue_subchannel_slow(schid
);
357 css_clear_subchannel_slow_list();
365 __s390_process_res_acc(struct subchannel_id schid
, void *data
)
367 int chp_mask
, old_lpm
;
368 struct res_acc_data
*res_data
;
369 struct subchannel
*sch
;
371 res_data
= (struct res_acc_data
*)data
;
372 sch
= get_subchannel_by_schid(schid
);
374 /* Check if a subchannel is newly available. */
375 return s390_process_res_acc_new_sch(schid
);
377 spin_lock_irq(&sch
->lock
);
379 chp_mask
= s390_process_res_acc_sch(res_data
, sch
);
382 spin_unlock_irq(&sch
->lock
);
386 sch
->lpm
= ((sch
->schib
.pmcw
.pim
&
387 sch
->schib
.pmcw
.pam
&
389 | chp_mask
) & sch
->opm
;
390 if (!old_lpm
&& sch
->lpm
)
391 device_trigger_reprobe(sch
);
392 else if (sch
->driver
&& sch
->driver
->verify
)
393 sch
->driver
->verify(&sch
->dev
);
395 spin_unlock_irq(&sch
->lock
);
396 put_device(&sch
->dev
);
397 return (res_data
->fla_mask
== 0xffff) ? -ENODEV
: 0;
402 s390_process_res_acc (struct res_acc_data
*res_data
)
407 sprintf(dbf_txt
, "accpr%x", res_data
->chp
->id
);
408 CIO_TRACE_EVENT( 2, dbf_txt
);
409 if (res_data
->fla
!= 0) {
410 sprintf(dbf_txt
, "fla%x", res_data
->fla
);
411 CIO_TRACE_EVENT( 2, dbf_txt
);
415 * I/O resources may have become accessible.
416 * Scan through all subchannels that may be concerned and
417 * do a validation on those.
418 * The more information we have (info), the less scanning
419 * will we have to do.
421 rc
= for_each_subchannel(__s390_process_res_acc
, res_data
);
422 if (css_slow_subchannels_exist())
424 else if (rc
!= -EAGAIN
)
430 __get_chpid_from_lir(void *data
)
436 /* incident-node descriptor */
438 /* attached-node descriptor */
440 /* incident-specific information */
444 lir
= (struct lir
*) data
;
446 /* NULL link incident record */
448 if (!(lir
->indesc
[0]&0xc0000000))
449 /* node descriptor not valid */
451 if (!(lir
->indesc
[0]&0x10000000))
452 /* don't handle device-type nodes - FIXME */
454 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
456 return (u16
) (lir
->indesc
[0]&0x000000ff);
460 chsc_process_crw(void)
463 struct res_acc_data res_data
;
465 struct chsc_header request
;
469 struct chsc_header response
;
472 u8 vf
; /* validity flags */
473 u8 rs
; /* reporting source */
474 u8 cc
; /* content code */
475 u16 fla
; /* full link address */
476 u16 rsid
; /* reporting source id */
479 u32 ccdf
[96]; /* content-code dependent field */
480 /* ccdf has to be big enough for a link-incident record */
486 * build the chsc request block for store event information
488 * This function is only called by the machine check handler thread,
489 * so we don't need locking for the sei_page.
493 CIO_TRACE_EVENT( 2, "prcss");
498 memset(sei_area
, 0, sizeof(*sei_area
));
499 memset(&res_data
, 0, sizeof(struct res_acc_data
));
500 sei_area
->request
.length
= 0x0010;
501 sei_area
->request
.code
= 0x000e;
503 ccode
= chsc(sei_area
);
507 switch (sei_area
->response
.code
) {
508 /* for debug purposes, check for problems */
510 CIO_CRW_EVENT(4, "chsc_process_crw: event information "
511 "successfully stored\n");
512 break; /* everything ok */
515 "chsc_process_crw: invalid command!\n");
518 CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
522 CIO_CRW_EVENT(2, "chsc_process_crw: no event "
523 "information stored\n");
526 CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
527 sei_area
->response
.code
);
531 /* Check if we might have lost some information. */
532 if (sei_area
->flags
& 0x40)
533 CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
534 "has been lost due to overflow!\n");
536 if (sei_area
->rs
!= 4) {
537 CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
538 "(%04X) isn't a chpid!\n",
543 /* which kind of information was stored? */
544 switch (sei_area
->cc
) {
545 case 1: /* link incident*/
546 CIO_CRW_EVENT(4, "chsc_process_crw: "
547 "channel subsystem reports link incident,"
548 " reporting source is chpid %x\n",
550 chpid
= __get_chpid_from_lir(sei_area
->ccdf
);
552 CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
555 s390_set_chpid_offline(chpid
);
558 case 2: /* i/o resource accessibiliy */
559 CIO_CRW_EVENT(4, "chsc_process_crw: "
560 "channel subsystem reports some I/O "
561 "devices may have become accessible\n");
562 pr_debug("Data received after sei: \n");
563 pr_debug("Validity flags: %x\n", sei_area
->vf
);
565 /* allocate a new channel path structure, if needed */
566 status
= get_chp_status(sei_area
->rsid
);
568 new_channel_path(sei_area
->rsid
);
571 dev
= get_device(&css
[0]->chps
[sei_area
->rsid
]->dev
);
572 res_data
.chp
= to_channelpath(dev
);
573 pr_debug("chpid: %x", sei_area
->rsid
);
574 if ((sei_area
->vf
& 0xc0) != 0) {
575 res_data
.fla
= sei_area
->fla
;
576 if ((sei_area
->vf
& 0xc0) == 0xc0) {
577 pr_debug(" full link addr: %x",
579 res_data
.fla_mask
= 0xffff;
581 pr_debug(" link addr: %x",
583 res_data
.fla_mask
= 0xff00;
586 ret
= s390_process_res_acc(&res_data
);
591 default: /* other stuff */
592 CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
596 } while (sei_area
->flags
& 0x80);
601 __chp_add_new_sch(struct subchannel_id schid
)
606 if (stsch(schid
, &schib
))
608 return need_rescan
? -EAGAIN
: -ENXIO
;
610 /* Put it on the slow path. */
611 ret
= css_enqueue_subchannel_slow(schid
);
613 css_clear_subchannel_slow_list();
622 __chp_add(struct subchannel_id schid
, void *data
)
625 struct channel_path
*chp
;
626 struct subchannel
*sch
;
628 chp
= (struct channel_path
*)data
;
629 sch
= get_subchannel_by_schid(schid
);
631 /* Check if the subchannel is now available. */
632 return __chp_add_new_sch(schid
);
633 spin_lock_irq(&sch
->lock
);
635 if (sch
->schib
.pmcw
.chpid
[i
] == chp
->id
) {
636 if (stsch(sch
->schid
, &sch
->schib
) != 0) {
638 spin_unlock_irq(&sch
->lock
);
644 spin_unlock_irq(&sch
->lock
);
647 sch
->lpm
= ((sch
->schib
.pmcw
.pim
&
648 sch
->schib
.pmcw
.pam
&
650 | 0x80 >> i
) & sch
->opm
;
652 if (sch
->driver
&& sch
->driver
->verify
)
653 sch
->driver
->verify(&sch
->dev
);
655 spin_unlock_irq(&sch
->lock
);
656 put_device(&sch
->dev
);
667 if (!get_chp_status(chpid
))
668 return 0; /* no need to do the rest */
670 sprintf(dbf_txt
, "cadd%x", chpid
);
671 CIO_TRACE_EVENT(2, dbf_txt
);
673 dev
= get_device(&css
[0]->chps
[chpid
]->dev
);
674 rc
= for_each_subchannel(__chp_add
, to_channelpath(dev
));
675 if (css_slow_subchannels_exist())
684 * Handling of crw machine checks with channel path source.
687 chp_process_crw(int chpid
, int on
)
690 /* Path has gone. We use the link incident routine.*/
691 s390_set_chpid_offline(chpid
);
692 return 0; /* De-register is async anyway. */
695 * Path has come. Allocate a new channel path structure,
698 if (get_chp_status(chpid
) < 0)
699 new_channel_path(chpid
);
700 /* Avoid the extra overhead in process_rec_acc. */
701 return chp_add(chpid
);
705 __check_for_io_and_kill(struct subchannel
*sch
, int index
)
709 if (!device_is_online(sch
))
710 /* cio could be doing I/O. */
712 cc
= stsch(sch
->schid
, &sch
->schib
);
715 if (sch
->schib
.scsw
.actl
&& sch
->schib
.pmcw
.lpum
== (0x80 >> index
)) {
716 device_set_waiting(sch
);
723 __s390_subchannel_vary_chpid(struct subchannel
*sch
, __u8 chpid
, int on
)
728 if (!sch
->ssd_info
.valid
)
731 spin_lock_irqsave(&sch
->lock
, flags
);
733 for (chp
= 0; chp
< 8; chp
++) {
734 if (sch
->ssd_info
.chpid
[chp
] != chpid
)
738 sch
->opm
|= (0x80 >> chp
);
739 sch
->lpm
|= (0x80 >> chp
);
741 device_trigger_reprobe(sch
);
742 else if (sch
->driver
&& sch
->driver
->verify
)
743 sch
->driver
->verify(&sch
->dev
);
745 sch
->opm
&= ~(0x80 >> chp
);
746 sch
->lpm
&= ~(0x80 >> chp
);
748 * Give running I/O a grace period in which it
749 * can successfully terminate, even using the
750 * just varied off path. Then kill it.
752 if (!__check_for_io_and_kill(sch
, chp
) && !sch
->lpm
) {
753 if (css_enqueue_subchannel_slow(sch
->schid
)) {
754 css_clear_subchannel_slow_list();
757 } else if (sch
->driver
&& sch
->driver
->verify
)
758 sch
->driver
->verify(&sch
->dev
);
762 spin_unlock_irqrestore(&sch
->lock
, flags
);
766 s390_subchannel_vary_chpid_off(struct device
*dev
, void *data
)
768 struct subchannel
*sch
;
771 sch
= to_subchannel(dev
);
774 __s390_subchannel_vary_chpid(sch
, *chpid
, 0);
779 s390_subchannel_vary_chpid_on(struct device
*dev
, void *data
)
781 struct subchannel
*sch
;
784 sch
= to_subchannel(dev
);
787 __s390_subchannel_vary_chpid(sch
, *chpid
, 1);
792 __s390_vary_chpid_on(struct subchannel_id schid
, void *data
)
795 struct subchannel
*sch
;
797 sch
= get_subchannel_by_schid(schid
);
799 put_device(&sch
->dev
);
802 if (stsch_err(schid
, &schib
))
805 /* Put it on the slow path. */
806 if (css_enqueue_subchannel_slow(schid
)) {
807 css_clear_subchannel_slow_list();
815 * Function: s390_vary_chpid
816 * Varies the specified chpid online or offline
819 s390_vary_chpid( __u8 chpid
, int on
)
824 sprintf(dbf_text
, on
?"varyon%x":"varyoff%x", chpid
);
825 CIO_TRACE_EVENT( 2, dbf_text
);
827 status
= get_chp_status(chpid
);
829 printk(KERN_ERR
"Can't vary unknown chpid %02X\n", chpid
);
833 if (!on
&& !status
) {
834 printk(KERN_ERR
"chpid %x is already offline\n", chpid
);
838 set_chp_logically_online(chpid
, on
);
841 * Redo PathVerification on the devices the chpid connects to
844 bus_for_each_dev(&css_bus_type
, NULL
, &chpid
, on
?
845 s390_subchannel_vary_chpid_on
:
846 s390_subchannel_vary_chpid_off
);
848 /* Scan for new devices on varied on path. */
849 for_each_subchannel(__s390_vary_chpid_on
, NULL
);
850 if (need_rescan
|| css_slow_subchannels_exist())
851 queue_work(slow_path_wq
, &slow_path_work
);
856 * Channel measurement related functions
859 chp_measurement_chars_read(struct kobject
*kobj
, char *buf
, loff_t off
,
862 struct channel_path
*chp
;
865 chp
= to_channelpath(container_of(kobj
, struct device
, kobj
));
869 size
= sizeof(struct cmg_chars
);
873 if (off
+ count
> size
)
875 memcpy(buf
, chp
->cmg_chars
+ off
, count
);
879 static struct bin_attribute chp_measurement_chars_attr
= {
881 .name
= "measurement_chars",
883 .owner
= THIS_MODULE
,
885 .size
= sizeof(struct cmg_chars
),
886 .read
= chp_measurement_chars_read
,
890 chp_measurement_copy_block(struct cmg_entry
*buf
,
891 struct channel_subsystem
*css
, int chpid
)
894 struct cmg_entry
*entry
, reference_buf
;
898 area
= css
->cub_addr1
;
901 area
= css
->cub_addr2
;
904 entry
= area
+ (idx
* sizeof(struct cmg_entry
));
906 memcpy(buf
, entry
, sizeof(*entry
));
907 memcpy(&reference_buf
, entry
, sizeof(*entry
));
908 } while (reference_buf
.values
[0] != buf
->values
[0]);
912 chp_measurement_read(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
914 struct channel_path
*chp
;
915 struct channel_subsystem
*css
;
918 chp
= to_channelpath(container_of(kobj
, struct device
, kobj
));
919 css
= to_css(chp
->dev
.parent
);
921 size
= sizeof(struct cmg_chars
);
923 /* Only allow single reads. */
924 if (off
|| count
< size
)
926 chp_measurement_copy_block((struct cmg_entry
*)buf
, css
, chp
->id
);
930 static struct bin_attribute chp_measurement_attr
= {
932 .name
= "measurement",
934 .owner
= THIS_MODULE
,
936 .size
= sizeof(struct cmg_entry
),
937 .read
= chp_measurement_read
,
941 chsc_remove_chp_cmg_attr(struct channel_path
*chp
)
943 sysfs_remove_bin_file(&chp
->dev
.kobj
, &chp_measurement_chars_attr
);
944 sysfs_remove_bin_file(&chp
->dev
.kobj
, &chp_measurement_attr
);
948 chsc_add_chp_cmg_attr(struct channel_path
*chp
)
952 ret
= sysfs_create_bin_file(&chp
->dev
.kobj
,
953 &chp_measurement_chars_attr
);
956 ret
= sysfs_create_bin_file(&chp
->dev
.kobj
, &chp_measurement_attr
);
958 sysfs_remove_bin_file(&chp
->dev
.kobj
,
959 &chp_measurement_chars_attr
);
964 chsc_remove_cmg_attr(struct channel_subsystem
*css
)
968 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
971 chsc_remove_chp_cmg_attr(css
->chps
[i
]);
976 chsc_add_cmg_attr(struct channel_subsystem
*css
)
981 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
984 ret
= chsc_add_chp_cmg_attr(css
->chps
[i
]);
990 for (--i
; i
>= 0; i
--) {
993 chsc_remove_chp_cmg_attr(css
->chps
[i
]);
1000 __chsc_do_secm(struct channel_subsystem
*css
, int enable
, void *page
)
1003 struct chsc_header request
;
1004 u32 operation_code
: 2;
1013 struct chsc_header response
;
1022 secm_area
->request
.length
= 0x0050;
1023 secm_area
->request
.code
= 0x0016;
1025 secm_area
->key
= PAGE_DEFAULT_KEY
;
1026 secm_area
->cub_addr1
= (u64
)(unsigned long)css
->cub_addr1
;
1027 secm_area
->cub_addr2
= (u64
)(unsigned long)css
->cub_addr2
;
1029 secm_area
->operation_code
= enable
? 0 : 1;
1031 ccode
= chsc(secm_area
);
1033 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
1035 switch (secm_area
->response
.code
) {
1036 case 0x0001: /* Success. */
1039 case 0x0003: /* Invalid block. */
1040 case 0x0007: /* Invalid format. */
1041 case 0x0008: /* Other invalid block. */
1042 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1045 case 0x0004: /* Command not provided in model. */
1046 CIO_CRW_EVENT(2, "Model does not provide secm\n");
1049 case 0x0102: /* cub adresses incorrect */
1050 CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
1053 case 0x0103: /* key error */
1054 CIO_CRW_EVENT(2, "Access key error in secm\n");
1057 case 0x0105: /* error while starting */
1058 CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
1062 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1063 secm_area
->response
.code
);
1070 chsc_secm(struct channel_subsystem
*css
, int enable
)
1075 secm_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1079 mutex_lock(&css
->mutex
);
1080 if (enable
&& !css
->cm_enabled
) {
1081 css
->cub_addr1
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1082 css
->cub_addr2
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1083 if (!css
->cub_addr1
|| !css
->cub_addr2
) {
1084 free_page((unsigned long)css
->cub_addr1
);
1085 free_page((unsigned long)css
->cub_addr2
);
1086 free_page((unsigned long)secm_area
);
1087 mutex_unlock(&css
->mutex
);
1091 ret
= __chsc_do_secm(css
, enable
, secm_area
);
1093 css
->cm_enabled
= enable
;
1094 if (css
->cm_enabled
) {
1095 ret
= chsc_add_cmg_attr(css
);
1097 memset(secm_area
, 0, PAGE_SIZE
);
1098 __chsc_do_secm(css
, 0, secm_area
);
1099 css
->cm_enabled
= 0;
1102 chsc_remove_cmg_attr(css
);
1104 if (enable
&& !css
->cm_enabled
) {
1105 free_page((unsigned long)css
->cub_addr1
);
1106 free_page((unsigned long)css
->cub_addr2
);
1108 mutex_unlock(&css
->mutex
);
1109 free_page((unsigned long)secm_area
);
1114 * Files for the channel path entries.
1117 chp_status_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1119 struct channel_path
*chp
= container_of(dev
, struct channel_path
, dev
);
1123 return (get_chp_status(chp
->id
) ? sprintf(buf
, "online\n") :
1124 sprintf(buf
, "offline\n"));
1128 chp_status_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1130 struct channel_path
*cp
= container_of(dev
, struct channel_path
, dev
);
1135 num_args
= sscanf(buf
, "%5s", cmd
);
1139 if (!strnicmp(cmd
, "on", 2))
1140 error
= s390_vary_chpid(cp
->id
, 1);
1141 else if (!strnicmp(cmd
, "off", 3))
1142 error
= s390_vary_chpid(cp
->id
, 0);
1146 return error
< 0 ? error
: count
;
1150 static DEVICE_ATTR(status
, 0644, chp_status_show
, chp_status_write
);
1153 chp_type_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1155 struct channel_path
*chp
= container_of(dev
, struct channel_path
, dev
);
1159 return sprintf(buf
, "%x\n", chp
->desc
.desc
);
1162 static DEVICE_ATTR(type
, 0444, chp_type_show
, NULL
);
1165 chp_cmg_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1167 struct channel_path
*chp
= to_channelpath(dev
);
1171 if (chp
->cmg
== -1) /* channel measurements not available */
1172 return sprintf(buf
, "unknown\n");
1173 return sprintf(buf
, "%x\n", chp
->cmg
);
1176 static DEVICE_ATTR(cmg
, 0444, chp_cmg_show
, NULL
);
1179 chp_shared_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1181 struct channel_path
*chp
= to_channelpath(dev
);
1185 if (chp
->shared
== -1) /* channel measurements not available */
1186 return sprintf(buf
, "unknown\n");
1187 return sprintf(buf
, "%x\n", chp
->shared
);
1190 static DEVICE_ATTR(shared
, 0444, chp_shared_show
, NULL
);
1192 static struct attribute
* chp_attrs
[] = {
1193 &dev_attr_status
.attr
,
1194 &dev_attr_type
.attr
,
1196 &dev_attr_shared
.attr
,
1200 static struct attribute_group chp_attr_group
= {
1205 chp_release(struct device
*dev
)
1207 struct channel_path
*cp
;
1209 cp
= container_of(dev
, struct channel_path
, dev
);
1214 chsc_determine_channel_path_description(int chpid
,
1215 struct channel_path_desc
*desc
)
1220 struct chsc_header request
;
1222 u32 first_chpid
: 8;
1226 struct chsc_header response
;
1228 struct channel_path_desc desc
;
1231 scpd_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1235 scpd_area
->request
.length
= 0x0010;
1236 scpd_area
->request
.code
= 0x0002;
1238 scpd_area
->first_chpid
= chpid
;
1239 scpd_area
->last_chpid
= chpid
;
1241 ccode
= chsc(scpd_area
);
1243 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
1247 switch (scpd_area
->response
.code
) {
1248 case 0x0001: /* Success. */
1249 memcpy(desc
, &scpd_area
->desc
,
1250 sizeof(struct channel_path_desc
));
1253 case 0x0003: /* Invalid block. */
1254 case 0x0007: /* Invalid format. */
1255 case 0x0008: /* Other invalid block. */
1256 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1259 case 0x0004: /* Command not provided in model. */
1260 CIO_CRW_EVENT(2, "Model does not provide scpd\n");
1264 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1265 scpd_area
->response
.code
);
1269 free_page((unsigned long)scpd_area
);
1274 chsc_initialize_cmg_chars(struct channel_path
*chp
, u8 cmcv
,
1275 struct cmg_chars
*chars
)
1280 chp
->cmg_chars
= kmalloc(sizeof(struct cmg_chars
),
1282 if (chp
->cmg_chars
) {
1284 struct cmg_chars
*cmg_chars
;
1286 cmg_chars
= chp
->cmg_chars
;
1287 for (i
= 0; i
< NR_MEASUREMENT_CHARS
; i
++) {
1288 mask
= 0x80 >> (i
+ 3);
1290 cmg_chars
->values
[i
] = chars
->values
[i
];
1292 cmg_chars
->values
[i
] = 0;
1297 /* No cmg-dependent data. */
1303 chsc_get_channel_measurement_chars(struct channel_path
*chp
)
1308 struct chsc_header request
;
1310 u32 first_chpid
: 8;
1314 struct chsc_header response
;
1325 u32 data
[NR_MEASUREMENT_CHARS
];
1328 scmc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1332 scmc_area
->request
.length
= 0x0010;
1333 scmc_area
->request
.code
= 0x0022;
1335 scmc_area
->first_chpid
= chp
->id
;
1336 scmc_area
->last_chpid
= chp
->id
;
1338 ccode
= chsc(scmc_area
);
1340 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
1344 switch (scmc_area
->response
.code
) {
1345 case 0x0001: /* Success. */
1346 if (!scmc_area
->not_valid
) {
1347 chp
->cmg
= scmc_area
->cmg
;
1348 chp
->shared
= scmc_area
->shared
;
1349 chsc_initialize_cmg_chars(chp
, scmc_area
->cmcv
,
1350 (struct cmg_chars
*)
1358 case 0x0003: /* Invalid block. */
1359 case 0x0007: /* Invalid format. */
1360 case 0x0008: /* Invalid bit combination. */
1361 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1364 case 0x0004: /* Command not provided. */
1365 CIO_CRW_EVENT(2, "Model does not provide scmc\n");
1369 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1370 scmc_area
->response
.code
);
1374 free_page((unsigned long)scmc_area
);
1379 * Entries for chpids on the system bus.
1380 * This replaces /proc/chpids.
1383 new_channel_path(int chpid
)
1385 struct channel_path
*chp
;
1388 chp
= kzalloc(sizeof(struct channel_path
), GFP_KERNEL
);
1392 /* fill in status, etc. */
1395 chp
->dev
= (struct device
) {
1396 .parent
= &css
[0]->device
,
1397 .release
= chp_release
,
1399 snprintf(chp
->dev
.bus_id
, BUS_ID_SIZE
, "chp0.%x", chpid
);
1401 /* Obtain channel path description and fill it in. */
1402 ret
= chsc_determine_channel_path_description(chpid
, &chp
->desc
);
1405 /* Get channel-measurement characteristics. */
1406 if (css_characteristics_avail
&& css_chsc_characteristics
.scmc
1407 && css_chsc_characteristics
.secm
) {
1408 ret
= chsc_get_channel_measurement_chars(chp
);
1412 static int msg_done
;
1415 printk(KERN_WARNING
"cio: Channel measurements not "
1416 "available, continuing.\n");
1422 /* make it known to the system */
1423 ret
= device_register(&chp
->dev
);
1425 printk(KERN_WARNING
"%s: could not register %02x\n",
1429 ret
= sysfs_create_group(&chp
->dev
.kobj
, &chp_attr_group
);
1431 device_unregister(&chp
->dev
);
1434 mutex_lock(&css
[0]->mutex
);
1435 if (css
[0]->cm_enabled
) {
1436 ret
= chsc_add_chp_cmg_attr(chp
);
1438 sysfs_remove_group(&chp
->dev
.kobj
, &chp_attr_group
);
1439 device_unregister(&chp
->dev
);
1440 mutex_unlock(&css
[0]->mutex
);
1444 css
[0]->chps
[chpid
] = chp
;
1445 mutex_unlock(&css
[0]->mutex
);
1453 chsc_get_chp_desc(struct subchannel
*sch
, int chp_no
)
1455 struct channel_path
*chp
;
1456 struct channel_path_desc
*desc
;
1458 chp
= css
[0]->chps
[sch
->schib
.pmcw
.chpid
[chp_no
]];
1461 desc
= kmalloc(sizeof(struct channel_path_desc
), GFP_KERNEL
);
1464 memcpy(desc
, &chp
->desc
, sizeof(struct channel_path_desc
));
1470 chsc_alloc_sei_area(void)
1472 sei_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1474 printk(KERN_WARNING
"Can't allocate page for processing of " \
1475 "chsc machine checks!\n");
1476 return (sei_page
? 0 : -ENOMEM
);
1480 chsc_enable_facility(int operation_code
)
1484 struct chsc_header request
;
1491 u32 operation_data_area
[252];
1492 struct chsc_header response
;
1498 sda_area
= (void *)get_zeroed_page(GFP_KERNEL
|GFP_DMA
);
1501 sda_area
->request
.length
= 0x0400;
1502 sda_area
->request
.code
= 0x0031;
1503 sda_area
->operation_code
= operation_code
;
1505 ret
= chsc(sda_area
);
1507 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
1510 switch (sda_area
->response
.code
) {
1511 case 0x0001: /* everything ok */
1514 case 0x0003: /* invalid request block */
1518 case 0x0004: /* command not provided */
1519 case 0x0101: /* facility not provided */
1522 default: /* something went wrong */
1526 free_page((unsigned long)sda_area
);
1530 subsys_initcall(chsc_alloc_sei_area
);
1532 struct css_general_char css_general_characteristics
;
1533 struct css_chsc_char css_chsc_characteristics
;
1536 chsc_determine_css_characteristics(void)
1540 struct chsc_header request
;
1544 struct chsc_header response
;
1546 u32 general_char
[510];
1550 scsc_area
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1552 printk(KERN_WARNING
"cio: Was not able to determine available" \
1553 "CHSCs due to no memory.\n");
1557 scsc_area
->request
.length
= 0x0010;
1558 scsc_area
->request
.code
= 0x0010;
1560 result
= chsc(scsc_area
);
1562 printk(KERN_WARNING
"cio: Was not able to determine " \
1563 "available CHSCs, cc=%i.\n", result
);
1568 if (scsc_area
->response
.code
!= 1) {
1569 printk(KERN_WARNING
"cio: Was not able to determine " \
1570 "available CHSCs.\n");
1574 memcpy(&css_general_characteristics
, scsc_area
->general_char
,
1575 sizeof(css_general_characteristics
));
1576 memcpy(&css_chsc_characteristics
, scsc_area
->chsc_char
,
1577 sizeof(css_chsc_characteristics
));
1579 free_page ((unsigned long) scsc_area
);
1583 EXPORT_SYMBOL_GPL(css_general_characteristics
);
1584 EXPORT_SYMBOL_GPL(css_chsc_characteristics
);