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/slab.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
21 #include "cio_debug.h"
25 static void *sei_page;
27 static int new_channel_path(int chpid);
30 set_chp_logically_online(int chp, int onoff)
32 css[0]->chps[chp]->state = onoff;
36 get_chp_status(int chp)
38 return (css[0]->chps[chp] ? css[0]->chps[chp]->state : -ENODEV);
42 chsc_validate_chpids(struct subchannel *sch)
46 for (chp = 0; chp <= 7; chp++) {
48 if (!get_chp_status(sch->schib.pmcw.chpid[chp]))
49 /* disable using this path */
55 chpid_is_actually_online(int chp)
59 state = get_chp_status(chp);
62 queue_work(slow_path_wq, &slow_path_work);
67 /* FIXME: this is _always_ called for every subchannel. shouldn't we
68 * process more than one at a time? */
70 chsc_get_sch_desc_irq(struct subchannel *sch, void *page)
75 struct chsc_header request;
79 u16 f_sch; /* first subchannel */
81 u16 l_sch; /* last subchannel */
83 struct chsc_header response;
87 u8 st : 3; /* subchannel type */
89 u8 unit_addr; /* unit address */
90 u16 devno; /* device number */
93 u16 sch; /* subchannel */
94 u8 chpid[8]; /* chpids 0-7 */
95 u16 fla[8]; /* full link addresses 0-7 */
96 } __attribute__ ((packed)) *ssd_area;
100 ssd_area->request.length = 0x0010;
101 ssd_area->request.code = 0x0004;
103 ssd_area->ssid = sch->schid.ssid;
104 ssd_area->f_sch = sch->schid.sch_no;
105 ssd_area->l_sch = sch->schid.sch_no;
107 ccode = chsc(ssd_area);
109 pr_debug("chsc returned with ccode = %d\n", ccode);
110 return (ccode == 3) ? -ENODEV : -EBUSY;
113 switch (ssd_area->response.code) {
114 case 0x0001: /* everything ok */
117 CIO_CRW_EVENT(2, "Invalid command!\n");
120 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
123 CIO_CRW_EVENT(2, "Model does not provide ssd\n");
126 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
127 ssd_area->response.code);
132 * ssd_area->st stores the type of the detected
133 * subchannel, with the following definitions:
135 * 0: I/O subchannel: All fields have meaning
136 * 1: CHSC subchannel: Only sch_val, st and sch
138 * 2: Message subchannel: All fields except unit_addr
140 * 3: ADM subchannel: Only sch_val, st and sch
143 * Other types are currently undefined.
145 if (ssd_area->st > 3) { /* uhm, that looks strange... */
146 CIO_CRW_EVENT(0, "Strange subchannel type %d"
147 " for sch 0.%x.%04x\n", ssd_area->st,
148 sch->schid.ssid, sch->schid.sch_no);
150 * There may have been a new subchannel type defined in the
151 * time since this code was written; since we don't know which
152 * fields have meaning and what to do with it we just jump out
156 const char *type[4] = {"I/O", "chsc", "message", "ADM"};
157 CIO_CRW_EVENT(6, "ssd: sch 0.%x.%04x is %s subchannel\n",
158 sch->schid.ssid, sch->schid.sch_no,
161 sch->ssd_info.valid = 1;
162 sch->ssd_info.type = ssd_area->st;
165 if (ssd_area->st == 0 || ssd_area->st == 2) {
166 for (j = 0; j < 8; j++) {
167 if (!((0x80 >> j) & ssd_area->path_mask &
168 ssd_area->fla_valid_mask))
170 sch->ssd_info.chpid[j] = ssd_area->chpid[j];
171 sch->ssd_info.fla[j] = ssd_area->fla[j];
178 css_get_ssd_info(struct subchannel *sch)
183 page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
186 spin_lock_irq(sch->lock);
187 ret = chsc_get_sch_desc_irq(sch, page);
189 static int cio_chsc_err_msg;
191 if (!cio_chsc_err_msg) {
193 "chsc_get_sch_descriptions:"
194 " Error %d while doing chsc; "
195 "processing some machine checks may "
197 cio_chsc_err_msg = 1;
200 spin_unlock_irq(sch->lock);
201 free_page((unsigned long)page);
204 /* Allocate channel path structures, if needed. */
205 for (j = 0; j < 8; j++) {
207 chpid = sch->ssd_info.chpid[j];
208 if ((sch->schib.pmcw.pim & mask) &&
209 (get_chp_status(chpid) < 0))
210 new_channel_path(chpid);
217 s390_subchannel_remove_chpid(struct device *dev, void *data)
221 struct subchannel *sch;
222 struct channel_path *chpid;
225 sch = to_subchannel(dev);
227 for (j = 0; j < 8; j++) {
229 if ((sch->schib.pmcw.pim & mask) &&
230 (sch->schib.pmcw.chpid[j] == chpid->id))
236 spin_lock_irq(sch->lock);
238 stsch(sch->schid, &schib);
241 memcpy(&sch->schib, &schib, sizeof(struct schib));
242 /* Check for single path devices. */
243 if (sch->schib.pmcw.pim == 0x80)
246 if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
247 (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
248 (sch->schib.pmcw.lpum == mask)) {
254 /* Request retry of internal operation. */
255 device_set_intretry(sch);
257 if (sch->driver && sch->driver->termination)
258 sch->driver->termination(&sch->dev);
262 /* trigger path verification. */
263 if (sch->driver && sch->driver->verify)
264 sch->driver->verify(&sch->dev);
265 else if (sch->lpm == mask)
268 spin_unlock_irq(sch->lock);
271 spin_unlock_irq(sch->lock);
273 if (css_enqueue_subchannel_slow(sch->schid)) {
274 css_clear_subchannel_slow_list();
281 s390_set_chpid_offline( __u8 chpid)
286 sprintf(dbf_txt, "chpr%x", chpid);
287 CIO_TRACE_EVENT(2, dbf_txt);
289 if (get_chp_status(chpid) <= 0)
291 dev = get_device(&css[0]->chps[chpid]->dev);
292 bus_for_each_dev(&css_bus_type, NULL, to_channelpath(dev),
293 s390_subchannel_remove_chpid);
295 if (need_rescan || css_slow_subchannels_exist())
296 queue_work(slow_path_wq, &slow_path_work);
300 struct res_acc_data {
301 struct channel_path *chp;
307 s390_process_res_acc_sch(struct res_acc_data *res_data, struct subchannel *sch)
314 for (chp = 0; chp <= 7; chp++)
316 * check if chpid is in information updated by ssd
318 if (sch->ssd_info.valid &&
319 sch->ssd_info.chpid[chp] == res_data->chp->id &&
320 (sch->ssd_info.fla[chp] & res_data->fla_mask)
330 * Do a stsch to update our subchannel structure with the
331 * new path information and eventually check for logically
334 ccode = stsch(sch->schid, &sch->schib);
342 s390_process_res_acc_new_sch(struct subchannel_id schid)
347 * We don't know the device yet, but since a path
348 * may be available now to the device we'll have
349 * to do recognition again.
350 * Since we don't have any idea about which chpid
351 * that beast may be on we'll have to do a stsch
352 * on all devices, grr...
354 if (stsch_err(schid, &schib))
356 return need_rescan ? -EAGAIN : -ENXIO;
358 /* Put it on the slow path. */
359 ret = css_enqueue_subchannel_slow(schid);
361 css_clear_subchannel_slow_list();
369 __s390_process_res_acc(struct subchannel_id schid, void *data)
371 int chp_mask, old_lpm;
372 struct res_acc_data *res_data;
373 struct subchannel *sch;
376 sch = get_subchannel_by_schid(schid);
378 /* Check if a subchannel is newly available. */
379 return s390_process_res_acc_new_sch(schid);
381 spin_lock_irq(sch->lock);
383 chp_mask = s390_process_res_acc_sch(res_data, sch);
386 spin_unlock_irq(sch->lock);
387 put_device(&sch->dev);
391 sch->lpm = ((sch->schib.pmcw.pim &
392 sch->schib.pmcw.pam &
394 | chp_mask) & sch->opm;
395 if (!old_lpm && sch->lpm)
396 device_trigger_reprobe(sch);
397 else if (sch->driver && sch->driver->verify)
398 sch->driver->verify(&sch->dev);
400 spin_unlock_irq(sch->lock);
401 put_device(&sch->dev);
407 s390_process_res_acc (struct res_acc_data *res_data)
412 sprintf(dbf_txt, "accpr%x", res_data->chp->id);
413 CIO_TRACE_EVENT( 2, dbf_txt);
414 if (res_data->fla != 0) {
415 sprintf(dbf_txt, "fla%x", res_data->fla);
416 CIO_TRACE_EVENT( 2, dbf_txt);
420 * I/O resources may have become accessible.
421 * Scan through all subchannels that may be concerned and
422 * do a validation on those.
423 * The more information we have (info), the less scanning
424 * will we have to do.
426 rc = for_each_subchannel(__s390_process_res_acc, res_data);
427 if (css_slow_subchannels_exist())
429 else if (rc != -EAGAIN)
435 __get_chpid_from_lir(void *data)
441 /* incident-node descriptor */
443 /* attached-node descriptor */
445 /* incident-specific information */
447 } __attribute__ ((packed)) *lir;
451 /* NULL link incident record */
453 if (!(lir->indesc[0]&0xc0000000))
454 /* node descriptor not valid */
456 if (!(lir->indesc[0]&0x10000000))
457 /* don't handle device-type nodes - FIXME */
459 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
461 return (u16) (lir->indesc[0]&0x000000ff);
464 struct chsc_sei_area {
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 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
480 /* ccdf has to be big enough for a link-incident record */
481 } __attribute__ ((packed));
483 static int chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
487 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
488 sei_area->rs, sei_area->rsid);
489 if (sei_area->rs != 4)
491 chpid = __get_chpid_from_lir(sei_area->ccdf);
493 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
495 s390_set_chpid_offline(chpid);
500 static int chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
502 struct res_acc_data res_data;
507 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
508 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
509 if (sei_area->rs != 4)
511 /* allocate a new channel path structure, if needed */
512 status = get_chp_status(sei_area->rsid);
514 new_channel_path(sei_area->rsid);
517 dev = get_device(&css[0]->chps[sei_area->rsid]->dev);
518 memset(&res_data, 0, sizeof(struct res_acc_data));
519 res_data.chp = to_channelpath(dev);
520 if ((sei_area->vf & 0xc0) != 0) {
521 res_data.fla = sei_area->fla;
522 if ((sei_area->vf & 0xc0) == 0xc0)
523 /* full link address */
524 res_data.fla_mask = 0xffff;
527 res_data.fla_mask = 0xff00;
529 rc = s390_process_res_acc(&res_data);
535 static int chsc_process_sei(struct chsc_sei_area *sei_area)
539 /* Check if we might have lost some information. */
540 if (sei_area->flags & 0x40)
541 CIO_CRW_EVENT(2, "chsc: event overflow\n");
542 /* which kind of information was stored? */
544 switch (sei_area->cc) {
545 case 1: /* link incident*/
546 rc = chsc_process_sei_link_incident(sei_area);
548 case 2: /* i/o resource accessibiliy */
549 rc = chsc_process_sei_res_acc(sei_area);
551 default: /* other stuff */
552 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
560 int chsc_process_crw(void)
562 struct chsc_sei_area *sei_area;
568 /* Access to sei_page is serialized through machine check handler
569 * thread, so no need for locking. */
572 CIO_TRACE_EVENT( 2, "prcss");
575 memset(sei_area, 0, sizeof(*sei_area));
576 sei_area->request.length = 0x0010;
577 sei_area->request.code = 0x000e;
581 if (sei_area->response.code == 0x0001) {
582 CIO_CRW_EVENT(4, "chsc: sei successful\n");
583 rc = chsc_process_sei(sei_area);
587 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
588 sei_area->response.code);
592 } while (sei_area->flags & 0x80);
598 __chp_add_new_sch(struct subchannel_id schid)
603 if (stsch_err(schid, &schib))
605 return need_rescan ? -EAGAIN : -ENXIO;
607 /* Put it on the slow path. */
608 ret = css_enqueue_subchannel_slow(schid);
610 css_clear_subchannel_slow_list();
619 __chp_add(struct subchannel_id schid, void *data)
622 struct channel_path *chp;
623 struct subchannel *sch;
626 sch = get_subchannel_by_schid(schid);
628 /* Check if the subchannel is now available. */
629 return __chp_add_new_sch(schid);
630 spin_lock_irq(sch->lock);
631 for (i=0; i<8; i++) {
633 if ((sch->schib.pmcw.pim & mask) &&
634 (sch->schib.pmcw.chpid[i] == chp->id)) {
635 if (stsch(sch->schid, &sch->schib) != 0) {
637 spin_unlock_irq(sch->lock);
644 spin_unlock_irq(sch->lock);
647 sch->lpm = ((sch->schib.pmcw.pim &
648 sch->schib.pmcw.pam &
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);
704 static int check_for_io_on_path(struct subchannel *sch, int index)
708 cc = stsch(sch->schid, &sch->schib);
711 if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index))
716 static void terminate_internal_io(struct subchannel *sch)
718 if (cio_clear(sch)) {
719 /* Recheck device in case clear failed. */
721 if (device_trigger_verify(sch) != 0) {
722 if(css_enqueue_subchannel_slow(sch->schid)) {
723 css_clear_subchannel_slow_list();
729 /* Request retry of internal operation. */
730 device_set_intretry(sch);
732 if (sch->driver && sch->driver->termination)
733 sch->driver->termination(&sch->dev);
737 __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
742 if (!sch->ssd_info.valid)
745 spin_lock_irqsave(sch->lock, flags);
747 for (chp = 0; chp < 8; chp++) {
748 if (sch->ssd_info.chpid[chp] != chpid)
752 sch->opm |= (0x80 >> chp);
753 sch->lpm |= (0x80 >> chp);
755 device_trigger_reprobe(sch);
756 else if (sch->driver && sch->driver->verify)
757 sch->driver->verify(&sch->dev);
760 sch->opm &= ~(0x80 >> chp);
761 sch->lpm &= ~(0x80 >> chp);
762 if (check_for_io_on_path(sch, chp)) {
763 if (device_is_online(sch))
764 /* Path verification is done after killing. */
767 /* Kill and retry internal I/O. */
768 terminate_internal_io(sch);
769 } else if (!sch->lpm) {
770 if (device_trigger_verify(sch) != 0) {
771 if (css_enqueue_subchannel_slow(sch->schid)) {
772 css_clear_subchannel_slow_list();
776 } else if (sch->driver && sch->driver->verify)
777 sch->driver->verify(&sch->dev);
780 spin_unlock_irqrestore(sch->lock, flags);
784 s390_subchannel_vary_chpid_off(struct device *dev, void *data)
786 struct subchannel *sch;
789 sch = to_subchannel(dev);
792 __s390_subchannel_vary_chpid(sch, *chpid, 0);
797 s390_subchannel_vary_chpid_on(struct device *dev, void *data)
799 struct subchannel *sch;
802 sch = to_subchannel(dev);
805 __s390_subchannel_vary_chpid(sch, *chpid, 1);
810 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
813 struct subchannel *sch;
815 sch = get_subchannel_by_schid(schid);
817 put_device(&sch->dev);
820 if (stsch_err(schid, &schib))
823 /* Put it on the slow path. */
824 if (css_enqueue_subchannel_slow(schid)) {
825 css_clear_subchannel_slow_list();
833 * Function: s390_vary_chpid
834 * Varies the specified chpid online or offline
837 s390_vary_chpid( __u8 chpid, int on)
842 sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
843 CIO_TRACE_EVENT( 2, dbf_text);
845 status = get_chp_status(chpid);
847 printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
851 if (!on && !status) {
852 printk(KERN_ERR "chpid %x is already offline\n", chpid);
856 set_chp_logically_online(chpid, on);
859 * Redo PathVerification on the devices the chpid connects to
862 bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
863 s390_subchannel_vary_chpid_on :
864 s390_subchannel_vary_chpid_off);
866 /* Scan for new devices on varied on path. */
867 for_each_subchannel(__s390_vary_chpid_on, NULL);
868 if (need_rescan || css_slow_subchannels_exist())
869 queue_work(slow_path_wq, &slow_path_work);
874 * Channel measurement related functions
877 chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
880 struct channel_path *chp;
883 chp = to_channelpath(container_of(kobj, struct device, kobj));
887 size = sizeof(struct cmg_chars);
891 if (off + count > size)
893 memcpy(buf, chp->cmg_chars + off, count);
897 static struct bin_attribute chp_measurement_chars_attr = {
899 .name = "measurement_chars",
901 .owner = THIS_MODULE,
903 .size = sizeof(struct cmg_chars),
904 .read = chp_measurement_chars_read,
908 chp_measurement_copy_block(struct cmg_entry *buf,
909 struct channel_subsystem *css, int chpid)
912 struct cmg_entry *entry, reference_buf;
916 area = css->cub_addr1;
919 area = css->cub_addr2;
922 entry = area + (idx * sizeof(struct cmg_entry));
924 memcpy(buf, entry, sizeof(*entry));
925 memcpy(&reference_buf, entry, sizeof(*entry));
926 } while (reference_buf.values[0] != buf->values[0]);
930 chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
932 struct channel_path *chp;
933 struct channel_subsystem *css;
936 chp = to_channelpath(container_of(kobj, struct device, kobj));
937 css = to_css(chp->dev.parent);
939 size = sizeof(struct cmg_entry);
941 /* Only allow single reads. */
942 if (off || count < size)
944 chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
949 static struct bin_attribute chp_measurement_attr = {
951 .name = "measurement",
953 .owner = THIS_MODULE,
955 .size = sizeof(struct cmg_entry),
956 .read = chp_measurement_read,
960 chsc_remove_chp_cmg_attr(struct channel_path *chp)
962 device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
963 device_remove_bin_file(&chp->dev, &chp_measurement_attr);
967 chsc_add_chp_cmg_attr(struct channel_path *chp)
971 ret = device_create_bin_file(&chp->dev, &chp_measurement_chars_attr);
974 ret = device_create_bin_file(&chp->dev, &chp_measurement_attr);
976 device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
981 chsc_remove_cmg_attr(struct channel_subsystem *css)
985 for (i = 0; i <= __MAX_CHPID; i++) {
988 chsc_remove_chp_cmg_attr(css->chps[i]);
993 chsc_add_cmg_attr(struct channel_subsystem *css)
998 for (i = 0; i <= __MAX_CHPID; i++) {
1001 ret = chsc_add_chp_cmg_attr(css->chps[i]);
1007 for (--i; i >= 0; i--) {
1010 chsc_remove_chp_cmg_attr(css->chps[i]);
1017 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
1020 struct chsc_header request;
1021 u32 operation_code : 2;
1030 struct chsc_header response;
1035 } __attribute__ ((packed)) *secm_area;
1039 secm_area->request.length = 0x0050;
1040 secm_area->request.code = 0x0016;
1042 secm_area->key = PAGE_DEFAULT_KEY;
1043 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
1044 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
1046 secm_area->operation_code = enable ? 0 : 1;
1048 ccode = chsc(secm_area);
1050 return (ccode == 3) ? -ENODEV : -EBUSY;
1052 switch (secm_area->response.code) {
1053 case 0x0001: /* Success. */
1056 case 0x0003: /* Invalid block. */
1057 case 0x0007: /* Invalid format. */
1058 case 0x0008: /* Other invalid block. */
1059 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1062 case 0x0004: /* Command not provided in model. */
1063 CIO_CRW_EVENT(2, "Model does not provide secm\n");
1066 case 0x0102: /* cub adresses incorrect */
1067 CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
1070 case 0x0103: /* key error */
1071 CIO_CRW_EVENT(2, "Access key error in secm\n");
1074 case 0x0105: /* error while starting */
1075 CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
1079 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1080 secm_area->response.code);
1087 chsc_secm(struct channel_subsystem *css, int enable)
1092 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1096 mutex_lock(&css->mutex);
1097 if (enable && !css->cm_enabled) {
1098 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1099 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1100 if (!css->cub_addr1 || !css->cub_addr2) {
1101 free_page((unsigned long)css->cub_addr1);
1102 free_page((unsigned long)css->cub_addr2);
1103 free_page((unsigned long)secm_area);
1104 mutex_unlock(&css->mutex);
1108 ret = __chsc_do_secm(css, enable, secm_area);
1110 css->cm_enabled = enable;
1111 if (css->cm_enabled) {
1112 ret = chsc_add_cmg_attr(css);
1114 memset(secm_area, 0, PAGE_SIZE);
1115 __chsc_do_secm(css, 0, secm_area);
1116 css->cm_enabled = 0;
1119 chsc_remove_cmg_attr(css);
1121 if (enable && !css->cm_enabled) {
1122 free_page((unsigned long)css->cub_addr1);
1123 free_page((unsigned long)css->cub_addr2);
1125 mutex_unlock(&css->mutex);
1126 free_page((unsigned long)secm_area);
1131 * Files for the channel path entries.
1134 chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
1136 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1140 return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
1141 sprintf(buf, "offline\n"));
1145 chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1147 struct channel_path *cp = container_of(dev, struct channel_path, dev);
1152 num_args = sscanf(buf, "%5s", cmd);
1156 if (!strnicmp(cmd, "on", 2))
1157 error = s390_vary_chpid(cp->id, 1);
1158 else if (!strnicmp(cmd, "off", 3))
1159 error = s390_vary_chpid(cp->id, 0);
1163 return error < 0 ? error : count;
1167 static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
1170 chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
1172 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1176 return sprintf(buf, "%x\n", chp->desc.desc);
1179 static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
1182 chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
1184 struct channel_path *chp = to_channelpath(dev);
1188 if (chp->cmg == -1) /* channel measurements not available */
1189 return sprintf(buf, "unknown\n");
1190 return sprintf(buf, "%x\n", chp->cmg);
1193 static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
1196 chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
1198 struct channel_path *chp = to_channelpath(dev);
1202 if (chp->shared == -1) /* channel measurements not available */
1203 return sprintf(buf, "unknown\n");
1204 return sprintf(buf, "%x\n", chp->shared);
1207 static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
1209 static struct attribute * chp_attrs[] = {
1210 &dev_attr_status.attr,
1211 &dev_attr_type.attr,
1213 &dev_attr_shared.attr,
1217 static struct attribute_group chp_attr_group = {
1222 chp_release(struct device *dev)
1224 struct channel_path *cp;
1226 cp = container_of(dev, struct channel_path, dev);
1231 chsc_determine_channel_path_description(int chpid,
1232 struct channel_path_desc *desc)
1237 struct chsc_header request;
1239 u32 first_chpid : 8;
1243 struct chsc_header response;
1245 struct channel_path_desc desc;
1246 } __attribute__ ((packed)) *scpd_area;
1248 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1252 scpd_area->request.length = 0x0010;
1253 scpd_area->request.code = 0x0002;
1255 scpd_area->first_chpid = chpid;
1256 scpd_area->last_chpid = chpid;
1258 ccode = chsc(scpd_area);
1260 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1264 switch (scpd_area->response.code) {
1265 case 0x0001: /* Success. */
1266 memcpy(desc, &scpd_area->desc,
1267 sizeof(struct channel_path_desc));
1270 case 0x0003: /* Invalid block. */
1271 case 0x0007: /* Invalid format. */
1272 case 0x0008: /* Other invalid block. */
1273 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1276 case 0x0004: /* Command not provided in model. */
1277 CIO_CRW_EVENT(2, "Model does not provide scpd\n");
1281 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1282 scpd_area->response.code);
1286 free_page((unsigned long)scpd_area);
1291 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
1292 struct cmg_chars *chars)
1297 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
1299 if (chp->cmg_chars) {
1301 struct cmg_chars *cmg_chars;
1303 cmg_chars = chp->cmg_chars;
1304 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
1305 mask = 0x80 >> (i + 3);
1307 cmg_chars->values[i] = chars->values[i];
1309 cmg_chars->values[i] = 0;
1314 /* No cmg-dependent data. */
1320 chsc_get_channel_measurement_chars(struct channel_path *chp)
1325 struct chsc_header request;
1327 u32 first_chpid : 8;
1331 struct chsc_header response;
1342 u32 data[NR_MEASUREMENT_CHARS];
1343 } __attribute__ ((packed)) *scmc_area;
1345 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1349 scmc_area->request.length = 0x0010;
1350 scmc_area->request.code = 0x0022;
1352 scmc_area->first_chpid = chp->id;
1353 scmc_area->last_chpid = chp->id;
1355 ccode = chsc(scmc_area);
1357 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1361 switch (scmc_area->response.code) {
1362 case 0x0001: /* Success. */
1363 if (!scmc_area->not_valid) {
1364 chp->cmg = scmc_area->cmg;
1365 chp->shared = scmc_area->shared;
1366 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1367 (struct cmg_chars *)
1375 case 0x0003: /* Invalid block. */
1376 case 0x0007: /* Invalid format. */
1377 case 0x0008: /* Invalid bit combination. */
1378 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1381 case 0x0004: /* Command not provided. */
1382 CIO_CRW_EVENT(2, "Model does not provide scmc\n");
1386 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1387 scmc_area->response.code);
1391 free_page((unsigned long)scmc_area);
1396 * Entries for chpids on the system bus.
1397 * This replaces /proc/chpids.
1400 new_channel_path(int chpid)
1402 struct channel_path *chp;
1405 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
1409 /* fill in status, etc. */
1412 chp->dev.parent = &css[0]->device;
1413 chp->dev.release = chp_release;
1414 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
1416 /* Obtain channel path description and fill it in. */
1417 ret = chsc_determine_channel_path_description(chpid, &chp->desc);
1420 /* Get channel-measurement characteristics. */
1421 if (css_characteristics_avail && css_chsc_characteristics.scmc
1422 && css_chsc_characteristics.secm) {
1423 ret = chsc_get_channel_measurement_chars(chp);
1427 static int msg_done;
1430 printk(KERN_WARNING "cio: Channel measurements not "
1431 "available, continuing.\n");
1437 /* make it known to the system */
1438 ret = device_register(&chp->dev);
1440 printk(KERN_WARNING "%s: could not register %02x\n",
1444 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
1446 device_unregister(&chp->dev);
1449 mutex_lock(&css[0]->mutex);
1450 if (css[0]->cm_enabled) {
1451 ret = chsc_add_chp_cmg_attr(chp);
1453 sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
1454 device_unregister(&chp->dev);
1455 mutex_unlock(&css[0]->mutex);
1459 css[0]->chps[chpid] = chp;
1460 mutex_unlock(&css[0]->mutex);
1468 chsc_get_chp_desc(struct subchannel *sch, int chp_no)
1470 struct channel_path *chp;
1471 struct channel_path_desc *desc;
1473 chp = css[0]->chps[sch->schib.pmcw.chpid[chp_no]];
1476 desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
1479 memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
1484 chsc_alloc_sei_area(void)
1486 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1488 printk(KERN_WARNING"Can't allocate page for processing of " \
1489 "chsc machine checks!\n");
1490 return (sei_page ? 0 : -ENOMEM);
1494 chsc_enable_facility(int operation_code)
1498 struct chsc_header request;
1505 u32 operation_data_area[252];
1506 struct chsc_header response;
1510 } __attribute__ ((packed)) *sda_area;
1512 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
1515 sda_area->request.length = 0x0400;
1516 sda_area->request.code = 0x0031;
1517 sda_area->operation_code = operation_code;
1519 ret = chsc(sda_area);
1521 ret = (ret == 3) ? -ENODEV : -EBUSY;
1524 switch (sda_area->response.code) {
1525 case 0x0001: /* everything ok */
1528 case 0x0003: /* invalid request block */
1532 case 0x0004: /* command not provided */
1533 case 0x0101: /* facility not provided */
1536 default: /* something went wrong */
1540 free_page((unsigned long)sda_area);
1544 subsys_initcall(chsc_alloc_sei_area);
1546 struct css_general_char css_general_characteristics;
1547 struct css_chsc_char css_chsc_characteristics;
1550 chsc_determine_css_characteristics(void)
1554 struct chsc_header request;
1558 struct chsc_header response;
1560 u32 general_char[510];
1562 } __attribute__ ((packed)) *scsc_area;
1564 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1566 printk(KERN_WARNING"cio: Was not able to determine available" \
1567 "CHSCs due to no memory.\n");
1571 scsc_area->request.length = 0x0010;
1572 scsc_area->request.code = 0x0010;
1574 result = chsc(scsc_area);
1576 printk(KERN_WARNING"cio: Was not able to determine " \
1577 "available CHSCs, cc=%i.\n", result);
1582 if (scsc_area->response.code != 1) {
1583 printk(KERN_WARNING"cio: Was not able to determine " \
1584 "available CHSCs.\n");
1588 memcpy(&css_general_characteristics, scsc_area->general_char,
1589 sizeof(css_general_characteristics));
1590 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1591 sizeof(css_chsc_characteristics));
1593 free_page ((unsigned long) scsc_area);
1597 EXPORT_SYMBOL_GPL(css_general_characteristics);
1598 EXPORT_SYMBOL_GPL(css_chsc_characteristics);