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 */
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)) {
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);
263 else if (sch->lpm == mask)
266 spin_unlock_irq(&sch->lock);
269 spin_unlock_irq(&sch->lock);
271 if (css_enqueue_subchannel_slow(sch->schid)) {
272 css_clear_subchannel_slow_list();
279 s390_set_chpid_offline( __u8 chpid)
284 sprintf(dbf_txt, "chpr%x", chpid);
285 CIO_TRACE_EVENT(2, dbf_txt);
287 if (get_chp_status(chpid) <= 0)
289 dev = get_device(&css[0]->chps[chpid]->dev);
290 bus_for_each_dev(&css_bus_type, NULL, to_channelpath(dev),
291 s390_subchannel_remove_chpid);
293 if (need_rescan || css_slow_subchannels_exist())
294 queue_work(slow_path_wq, &slow_path_work);
298 struct res_acc_data {
299 struct channel_path *chp;
305 s390_process_res_acc_sch(struct res_acc_data *res_data, struct subchannel *sch)
312 for (chp = 0; chp <= 7; chp++)
314 * check if chpid is in information updated by ssd
316 if (sch->ssd_info.valid &&
317 sch->ssd_info.chpid[chp] == res_data->chp->id &&
318 (sch->ssd_info.fla[chp] & res_data->fla_mask)
328 * Do a stsch to update our subchannel structure with the
329 * new path information and eventually check for logically
332 ccode = stsch(sch->schid, &sch->schib);
340 s390_process_res_acc_new_sch(struct subchannel_id schid)
345 * We don't know the device yet, but since a path
346 * may be available now to the device we'll have
347 * to do recognition again.
348 * Since we don't have any idea about which chpid
349 * that beast may be on we'll have to do a stsch
350 * on all devices, grr...
352 if (stsch_err(schid, &schib))
354 return need_rescan ? -EAGAIN : -ENXIO;
356 /* Put it on the slow path. */
357 ret = css_enqueue_subchannel_slow(schid);
359 css_clear_subchannel_slow_list();
367 __s390_process_res_acc(struct subchannel_id schid, void *data)
369 int chp_mask, old_lpm;
370 struct res_acc_data *res_data;
371 struct subchannel *sch;
374 sch = get_subchannel_by_schid(schid);
376 /* Check if a subchannel is newly available. */
377 return s390_process_res_acc_new_sch(schid);
379 spin_lock_irq(&sch->lock);
381 chp_mask = s390_process_res_acc_sch(res_data, sch);
384 spin_unlock_irq(&sch->lock);
385 put_device(&sch->dev);
389 sch->lpm = ((sch->schib.pmcw.pim &
390 sch->schib.pmcw.pam &
392 | chp_mask) & sch->opm;
393 if (!old_lpm && sch->lpm)
394 device_trigger_reprobe(sch);
395 else if (sch->driver && sch->driver->verify)
396 sch->driver->verify(&sch->dev);
398 spin_unlock_irq(&sch->lock);
399 put_device(&sch->dev);
405 s390_process_res_acc (struct res_acc_data *res_data)
410 sprintf(dbf_txt, "accpr%x", res_data->chp->id);
411 CIO_TRACE_EVENT( 2, dbf_txt);
412 if (res_data->fla != 0) {
413 sprintf(dbf_txt, "fla%x", res_data->fla);
414 CIO_TRACE_EVENT( 2, dbf_txt);
418 * I/O resources may have become accessible.
419 * Scan through all subchannels that may be concerned and
420 * do a validation on those.
421 * The more information we have (info), the less scanning
422 * will we have to do.
424 rc = for_each_subchannel(__s390_process_res_acc, res_data);
425 if (css_slow_subchannels_exist())
427 else if (rc != -EAGAIN)
433 __get_chpid_from_lir(void *data)
439 /* incident-node descriptor */
441 /* attached-node descriptor */
443 /* incident-specific information */
449 /* NULL link incident record */
451 if (!(lir->indesc[0]&0xc0000000))
452 /* node descriptor not valid */
454 if (!(lir->indesc[0]&0x10000000))
455 /* don't handle device-type nodes - FIXME */
457 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
459 return (u16) (lir->indesc[0]&0x000000ff);
463 chsc_process_crw(void)
466 struct res_acc_data res_data;
468 struct chsc_header request;
472 struct chsc_header response;
475 u8 vf; /* validity flags */
476 u8 rs; /* reporting source */
477 u8 cc; /* content code */
478 u16 fla; /* full link address */
479 u16 rsid; /* reporting source id */
482 u32 ccdf[96]; /* content-code dependent field */
483 /* ccdf has to be big enough for a link-incident record */
489 * build the chsc request block for store event information
491 * This function is only called by the machine check handler thread,
492 * so we don't need locking for the sei_page.
496 CIO_TRACE_EVENT( 2, "prcss");
501 memset(sei_area, 0, sizeof(*sei_area));
502 memset(&res_data, 0, sizeof(struct res_acc_data));
503 sei_area->request.length = 0x0010;
504 sei_area->request.code = 0x000e;
506 ccode = chsc(sei_area);
510 switch (sei_area->response.code) {
511 /* for debug purposes, check for problems */
513 CIO_CRW_EVENT(4, "chsc_process_crw: event information "
514 "successfully stored\n");
515 break; /* everything ok */
518 "chsc_process_crw: invalid command!\n");
521 CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
525 CIO_CRW_EVENT(2, "chsc_process_crw: no event "
526 "information stored\n");
529 CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
530 sei_area->response.code);
534 /* Check if we might have lost some information. */
535 if (sei_area->flags & 0x40)
536 CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
537 "has been lost due to overflow!\n");
539 if (sei_area->rs != 4) {
540 CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
541 "(%04X) isn't a chpid!\n",
546 /* which kind of information was stored? */
547 switch (sei_area->cc) {
548 case 1: /* link incident*/
549 CIO_CRW_EVENT(4, "chsc_process_crw: "
550 "channel subsystem reports link incident,"
551 " reporting source is chpid %x\n",
553 chpid = __get_chpid_from_lir(sei_area->ccdf);
555 CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
558 s390_set_chpid_offline(chpid);
561 case 2: /* i/o resource accessibiliy */
562 CIO_CRW_EVENT(4, "chsc_process_crw: "
563 "channel subsystem reports some I/O "
564 "devices may have become accessible\n");
565 pr_debug("Data received after sei: \n");
566 pr_debug("Validity flags: %x\n", sei_area->vf);
568 /* allocate a new channel path structure, if needed */
569 status = get_chp_status(sei_area->rsid);
571 new_channel_path(sei_area->rsid);
574 dev = get_device(&css[0]->chps[sei_area->rsid]->dev);
575 res_data.chp = to_channelpath(dev);
576 pr_debug("chpid: %x", sei_area->rsid);
577 if ((sei_area->vf & 0xc0) != 0) {
578 res_data.fla = sei_area->fla;
579 if ((sei_area->vf & 0xc0) == 0xc0) {
580 pr_debug(" full link addr: %x",
582 res_data.fla_mask = 0xffff;
584 pr_debug(" link addr: %x",
586 res_data.fla_mask = 0xff00;
589 ret = s390_process_res_acc(&res_data);
594 default: /* other stuff */
595 CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
599 } while (sei_area->flags & 0x80);
604 __chp_add_new_sch(struct subchannel_id schid)
609 if (stsch(schid, &schib))
611 return need_rescan ? -EAGAIN : -ENXIO;
613 /* Put it on the slow path. */
614 ret = css_enqueue_subchannel_slow(schid);
616 css_clear_subchannel_slow_list();
625 __chp_add(struct subchannel_id schid, void *data)
628 struct channel_path *chp;
629 struct subchannel *sch;
632 sch = get_subchannel_by_schid(schid);
634 /* Check if the subchannel is now available. */
635 return __chp_add_new_sch(schid);
636 spin_lock_irq(&sch->lock);
637 for (i=0; i<8; i++) {
639 if ((sch->schib.pmcw.pim & mask) &&
640 (sch->schib.pmcw.chpid[i] == chp->id)) {
641 if (stsch(sch->schid, &sch->schib) != 0) {
643 spin_unlock_irq(&sch->lock);
650 spin_unlock_irq(&sch->lock);
653 sch->lpm = ((sch->schib.pmcw.pim &
654 sch->schib.pmcw.pam &
658 if (sch->driver && sch->driver->verify)
659 sch->driver->verify(&sch->dev);
661 spin_unlock_irq(&sch->lock);
662 put_device(&sch->dev);
673 if (!get_chp_status(chpid))
674 return 0; /* no need to do the rest */
676 sprintf(dbf_txt, "cadd%x", chpid);
677 CIO_TRACE_EVENT(2, dbf_txt);
679 dev = get_device(&css[0]->chps[chpid]->dev);
680 rc = for_each_subchannel(__chp_add, to_channelpath(dev));
681 if (css_slow_subchannels_exist())
690 * Handling of crw machine checks with channel path source.
693 chp_process_crw(int chpid, int on)
696 /* Path has gone. We use the link incident routine.*/
697 s390_set_chpid_offline(chpid);
698 return 0; /* De-register is async anyway. */
701 * Path has come. Allocate a new channel path structure,
704 if (get_chp_status(chpid) < 0)
705 new_channel_path(chpid);
706 /* Avoid the extra overhead in process_rec_acc. */
707 return chp_add(chpid);
710 static inline int check_for_io_on_path(struct subchannel *sch, int index)
714 if (!device_is_online(sch))
715 /* cio could be doing I/O. */
717 cc = stsch(sch->schid, &sch->schib);
720 if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index))
726 __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
731 if (!sch->ssd_info.valid)
734 spin_lock_irqsave(&sch->lock, flags);
736 for (chp = 0; chp < 8; chp++) {
737 if (sch->ssd_info.chpid[chp] != chpid)
741 sch->opm |= (0x80 >> chp);
742 sch->lpm |= (0x80 >> chp);
744 device_trigger_reprobe(sch);
745 else if (sch->driver && sch->driver->verify)
746 sch->driver->verify(&sch->dev);
749 sch->opm &= ~(0x80 >> chp);
750 sch->lpm &= ~(0x80 >> chp);
751 if (check_for_io_on_path(sch, chp))
752 /* Path verification is done after killing. */
754 else if (!sch->lpm) {
755 if (device_trigger_verify(sch) != 0) {
756 if (css_enqueue_subchannel_slow(sch->schid)) {
757 css_clear_subchannel_slow_list();
761 } else if (sch->driver && sch->driver->verify)
762 sch->driver->verify(&sch->dev);
765 spin_unlock_irqrestore(&sch->lock, flags);
769 s390_subchannel_vary_chpid_off(struct device *dev, void *data)
771 struct subchannel *sch;
774 sch = to_subchannel(dev);
777 __s390_subchannel_vary_chpid(sch, *chpid, 0);
782 s390_subchannel_vary_chpid_on(struct device *dev, void *data)
784 struct subchannel *sch;
787 sch = to_subchannel(dev);
790 __s390_subchannel_vary_chpid(sch, *chpid, 1);
795 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
798 struct subchannel *sch;
800 sch = get_subchannel_by_schid(schid);
802 put_device(&sch->dev);
805 if (stsch_err(schid, &schib))
808 /* Put it on the slow path. */
809 if (css_enqueue_subchannel_slow(schid)) {
810 css_clear_subchannel_slow_list();
818 * Function: s390_vary_chpid
819 * Varies the specified chpid online or offline
822 s390_vary_chpid( __u8 chpid, int on)
827 sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
828 CIO_TRACE_EVENT( 2, dbf_text);
830 status = get_chp_status(chpid);
832 printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
836 if (!on && !status) {
837 printk(KERN_ERR "chpid %x is already offline\n", chpid);
841 set_chp_logically_online(chpid, on);
844 * Redo PathVerification on the devices the chpid connects to
847 bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
848 s390_subchannel_vary_chpid_on :
849 s390_subchannel_vary_chpid_off);
851 /* Scan for new devices on varied on path. */
852 for_each_subchannel(__s390_vary_chpid_on, NULL);
853 if (need_rescan || css_slow_subchannels_exist())
854 queue_work(slow_path_wq, &slow_path_work);
859 * Channel measurement related functions
862 chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
865 struct channel_path *chp;
868 chp = to_channelpath(container_of(kobj, struct device, kobj));
872 size = sizeof(struct cmg_chars);
876 if (off + count > size)
878 memcpy(buf, chp->cmg_chars + off, count);
882 static struct bin_attribute chp_measurement_chars_attr = {
884 .name = "measurement_chars",
886 .owner = THIS_MODULE,
888 .size = sizeof(struct cmg_chars),
889 .read = chp_measurement_chars_read,
893 chp_measurement_copy_block(struct cmg_entry *buf,
894 struct channel_subsystem *css, int chpid)
897 struct cmg_entry *entry, reference_buf;
901 area = css->cub_addr1;
904 area = css->cub_addr2;
907 entry = area + (idx * sizeof(struct cmg_entry));
909 memcpy(buf, entry, sizeof(*entry));
910 memcpy(&reference_buf, entry, sizeof(*entry));
911 } while (reference_buf.values[0] != buf->values[0]);
915 chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
917 struct channel_path *chp;
918 struct channel_subsystem *css;
921 chp = to_channelpath(container_of(kobj, struct device, kobj));
922 css = to_css(chp->dev.parent);
924 size = sizeof(struct cmg_entry);
926 /* Only allow single reads. */
927 if (off || count < size)
929 chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
934 static struct bin_attribute chp_measurement_attr = {
936 .name = "measurement",
938 .owner = THIS_MODULE,
940 .size = sizeof(struct cmg_entry),
941 .read = chp_measurement_read,
945 chsc_remove_chp_cmg_attr(struct channel_path *chp)
947 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_chars_attr);
948 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_attr);
952 chsc_add_chp_cmg_attr(struct channel_path *chp)
956 ret = sysfs_create_bin_file(&chp->dev.kobj,
957 &chp_measurement_chars_attr);
960 ret = sysfs_create_bin_file(&chp->dev.kobj, &chp_measurement_attr);
962 sysfs_remove_bin_file(&chp->dev.kobj,
963 &chp_measurement_chars_attr);
968 chsc_remove_cmg_attr(struct channel_subsystem *css)
972 for (i = 0; i <= __MAX_CHPID; i++) {
975 chsc_remove_chp_cmg_attr(css->chps[i]);
980 chsc_add_cmg_attr(struct channel_subsystem *css)
985 for (i = 0; i <= __MAX_CHPID; i++) {
988 ret = chsc_add_chp_cmg_attr(css->chps[i]);
994 for (--i; i >= 0; i--) {
997 chsc_remove_chp_cmg_attr(css->chps[i]);
1004 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
1007 struct chsc_header request;
1008 u32 operation_code : 2;
1017 struct chsc_header response;
1026 secm_area->request.length = 0x0050;
1027 secm_area->request.code = 0x0016;
1029 secm_area->key = PAGE_DEFAULT_KEY;
1030 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
1031 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
1033 secm_area->operation_code = enable ? 0 : 1;
1035 ccode = chsc(secm_area);
1037 return (ccode == 3) ? -ENODEV : -EBUSY;
1039 switch (secm_area->response.code) {
1040 case 0x0001: /* Success. */
1043 case 0x0003: /* Invalid block. */
1044 case 0x0007: /* Invalid format. */
1045 case 0x0008: /* Other invalid block. */
1046 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1049 case 0x0004: /* Command not provided in model. */
1050 CIO_CRW_EVENT(2, "Model does not provide secm\n");
1053 case 0x0102: /* cub adresses incorrect */
1054 CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
1057 case 0x0103: /* key error */
1058 CIO_CRW_EVENT(2, "Access key error in secm\n");
1061 case 0x0105: /* error while starting */
1062 CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
1066 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1067 secm_area->response.code);
1074 chsc_secm(struct channel_subsystem *css, int enable)
1079 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1083 mutex_lock(&css->mutex);
1084 if (enable && !css->cm_enabled) {
1085 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1086 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1087 if (!css->cub_addr1 || !css->cub_addr2) {
1088 free_page((unsigned long)css->cub_addr1);
1089 free_page((unsigned long)css->cub_addr2);
1090 free_page((unsigned long)secm_area);
1091 mutex_unlock(&css->mutex);
1095 ret = __chsc_do_secm(css, enable, secm_area);
1097 css->cm_enabled = enable;
1098 if (css->cm_enabled) {
1099 ret = chsc_add_cmg_attr(css);
1101 memset(secm_area, 0, PAGE_SIZE);
1102 __chsc_do_secm(css, 0, secm_area);
1103 css->cm_enabled = 0;
1106 chsc_remove_cmg_attr(css);
1108 if (enable && !css->cm_enabled) {
1109 free_page((unsigned long)css->cub_addr1);
1110 free_page((unsigned long)css->cub_addr2);
1112 mutex_unlock(&css->mutex);
1113 free_page((unsigned long)secm_area);
1118 * Files for the channel path entries.
1121 chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
1123 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1127 return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
1128 sprintf(buf, "offline\n"));
1132 chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1134 struct channel_path *cp = container_of(dev, struct channel_path, dev);
1139 num_args = sscanf(buf, "%5s", cmd);
1143 if (!strnicmp(cmd, "on", 2))
1144 error = s390_vary_chpid(cp->id, 1);
1145 else if (!strnicmp(cmd, "off", 3))
1146 error = s390_vary_chpid(cp->id, 0);
1150 return error < 0 ? error : count;
1154 static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
1157 chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
1159 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1163 return sprintf(buf, "%x\n", chp->desc.desc);
1166 static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
1169 chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
1171 struct channel_path *chp = to_channelpath(dev);
1175 if (chp->cmg == -1) /* channel measurements not available */
1176 return sprintf(buf, "unknown\n");
1177 return sprintf(buf, "%x\n", chp->cmg);
1180 static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
1183 chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
1185 struct channel_path *chp = to_channelpath(dev);
1189 if (chp->shared == -1) /* channel measurements not available */
1190 return sprintf(buf, "unknown\n");
1191 return sprintf(buf, "%x\n", chp->shared);
1194 static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
1196 static struct attribute * chp_attrs[] = {
1197 &dev_attr_status.attr,
1198 &dev_attr_type.attr,
1200 &dev_attr_shared.attr,
1204 static struct attribute_group chp_attr_group = {
1209 chp_release(struct device *dev)
1211 struct channel_path *cp;
1213 cp = container_of(dev, struct channel_path, dev);
1218 chsc_determine_channel_path_description(int chpid,
1219 struct channel_path_desc *desc)
1224 struct chsc_header request;
1226 u32 first_chpid : 8;
1230 struct chsc_header response;
1232 struct channel_path_desc desc;
1235 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1239 scpd_area->request.length = 0x0010;
1240 scpd_area->request.code = 0x0002;
1242 scpd_area->first_chpid = chpid;
1243 scpd_area->last_chpid = chpid;
1245 ccode = chsc(scpd_area);
1247 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1251 switch (scpd_area->response.code) {
1252 case 0x0001: /* Success. */
1253 memcpy(desc, &scpd_area->desc,
1254 sizeof(struct channel_path_desc));
1257 case 0x0003: /* Invalid block. */
1258 case 0x0007: /* Invalid format. */
1259 case 0x0008: /* Other invalid block. */
1260 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1263 case 0x0004: /* Command not provided in model. */
1264 CIO_CRW_EVENT(2, "Model does not provide scpd\n");
1268 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1269 scpd_area->response.code);
1273 free_page((unsigned long)scpd_area);
1278 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
1279 struct cmg_chars *chars)
1284 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
1286 if (chp->cmg_chars) {
1288 struct cmg_chars *cmg_chars;
1290 cmg_chars = chp->cmg_chars;
1291 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
1292 mask = 0x80 >> (i + 3);
1294 cmg_chars->values[i] = chars->values[i];
1296 cmg_chars->values[i] = 0;
1301 /* No cmg-dependent data. */
1307 chsc_get_channel_measurement_chars(struct channel_path *chp)
1312 struct chsc_header request;
1314 u32 first_chpid : 8;
1318 struct chsc_header response;
1329 u32 data[NR_MEASUREMENT_CHARS];
1332 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1336 scmc_area->request.length = 0x0010;
1337 scmc_area->request.code = 0x0022;
1339 scmc_area->first_chpid = chp->id;
1340 scmc_area->last_chpid = chp->id;
1342 ccode = chsc(scmc_area);
1344 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1348 switch (scmc_area->response.code) {
1349 case 0x0001: /* Success. */
1350 if (!scmc_area->not_valid) {
1351 chp->cmg = scmc_area->cmg;
1352 chp->shared = scmc_area->shared;
1353 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1354 (struct cmg_chars *)
1362 case 0x0003: /* Invalid block. */
1363 case 0x0007: /* Invalid format. */
1364 case 0x0008: /* Invalid bit combination. */
1365 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1368 case 0x0004: /* Command not provided. */
1369 CIO_CRW_EVENT(2, "Model does not provide scmc\n");
1373 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1374 scmc_area->response.code);
1378 free_page((unsigned long)scmc_area);
1383 * Entries for chpids on the system bus.
1384 * This replaces /proc/chpids.
1387 new_channel_path(int chpid)
1389 struct channel_path *chp;
1392 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
1396 /* fill in status, etc. */
1399 chp->dev.parent = &css[0]->device;
1400 chp->dev.release = chp_release;
1401 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
1403 /* Obtain channel path description and fill it in. */
1404 ret = chsc_determine_channel_path_description(chpid, &chp->desc);
1407 /* Get channel-measurement characteristics. */
1408 if (css_characteristics_avail && css_chsc_characteristics.scmc
1409 && css_chsc_characteristics.secm) {
1410 ret = chsc_get_channel_measurement_chars(chp);
1414 static int msg_done;
1417 printk(KERN_WARNING "cio: Channel measurements not "
1418 "available, continuing.\n");
1424 /* make it known to the system */
1425 ret = device_register(&chp->dev);
1427 printk(KERN_WARNING "%s: could not register %02x\n",
1431 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
1433 device_unregister(&chp->dev);
1436 mutex_lock(&css[0]->mutex);
1437 if (css[0]->cm_enabled) {
1438 ret = chsc_add_chp_cmg_attr(chp);
1440 sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
1441 device_unregister(&chp->dev);
1442 mutex_unlock(&css[0]->mutex);
1446 css[0]->chps[chpid] = chp;
1447 mutex_unlock(&css[0]->mutex);
1455 chsc_get_chp_desc(struct subchannel *sch, int chp_no)
1457 struct channel_path *chp;
1458 struct channel_path_desc *desc;
1460 chp = css[0]->chps[sch->schib.pmcw.chpid[chp_no]];
1463 desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
1466 memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
1471 chsc_alloc_sei_area(void)
1473 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1475 printk(KERN_WARNING"Can't allocate page for processing of " \
1476 "chsc machine checks!\n");
1477 return (sei_page ? 0 : -ENOMEM);
1481 chsc_enable_facility(int operation_code)
1485 struct chsc_header request;
1492 u32 operation_data_area[252];
1493 struct chsc_header response;
1499 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
1502 sda_area->request.length = 0x0400;
1503 sda_area->request.code = 0x0031;
1504 sda_area->operation_code = operation_code;
1506 ret = chsc(sda_area);
1508 ret = (ret == 3) ? -ENODEV : -EBUSY;
1511 switch (sda_area->response.code) {
1512 case 0x0001: /* everything ok */
1515 case 0x0003: /* invalid request block */
1519 case 0x0004: /* command not provided */
1520 case 0x0101: /* facility not provided */
1523 default: /* something went wrong */
1527 free_page((unsigned long)sda_area);
1531 subsys_initcall(chsc_alloc_sei_area);
1533 struct css_general_char css_general_characteristics;
1534 struct css_chsc_char css_chsc_characteristics;
1537 chsc_determine_css_characteristics(void)
1541 struct chsc_header request;
1545 struct chsc_header response;
1547 u32 general_char[510];
1551 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1553 printk(KERN_WARNING"cio: Was not able to determine available" \
1554 "CHSCs due to no memory.\n");
1558 scsc_area->request.length = 0x0010;
1559 scsc_area->request.code = 0x0010;
1561 result = chsc(scsc_area);
1563 printk(KERN_WARNING"cio: Was not able to determine " \
1564 "available CHSCs, cc=%i.\n", result);
1569 if (scsc_area->response.code != 1) {
1570 printk(KERN_WARNING"cio: Was not able to determine " \
1571 "available CHSCs.\n");
1575 memcpy(&css_general_characteristics, scsc_area->general_char,
1576 sizeof(css_general_characteristics));
1577 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1578 sizeof(css_chsc_characteristics));
1580 free_page ((unsigned long) scsc_area);
1584 EXPORT_SYMBOL_GPL(css_general_characteristics);
1585 EXPORT_SYMBOL_GPL(css_chsc_characteristics);