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++) {
206 chpid = sch->ssd_info.chpid[j];
207 if (chpid && (get_chp_status(chpid) < 0))
208 new_channel_path(chpid);
215 s390_subchannel_remove_chpid(struct device *dev, void *data)
219 struct subchannel *sch;
220 struct channel_path *chpid;
223 sch = to_subchannel(dev);
225 for (j = 0; j < 8; j++)
226 if (sch->schib.pmcw.chpid[j] == chpid->id)
232 spin_lock_irq(&sch->lock);
234 stsch(sch->schid, &schib);
237 memcpy(&sch->schib, &schib, sizeof(struct schib));
238 /* Check for single path devices. */
239 if (sch->schib.pmcw.pim == 0x80)
241 if (sch->vpm == mask)
244 if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
245 (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
246 (sch->schib.pmcw.lpum == mask)) {
253 if (sch->driver && sch->driver->termination)
254 sch->driver->termination(&sch->dev);
258 /* trigger path verification. */
259 if (sch->driver && sch->driver->verify)
260 sch->driver->verify(&sch->dev);
262 spin_unlock_irq(&sch->lock);
265 spin_unlock_irq(&sch->lock);
267 if (css_enqueue_subchannel_slow(sch->schid)) {
268 css_clear_subchannel_slow_list();
275 s390_set_chpid_offline( __u8 chpid)
280 sprintf(dbf_txt, "chpr%x", chpid);
281 CIO_TRACE_EVENT(2, dbf_txt);
283 if (get_chp_status(chpid) <= 0)
285 dev = get_device(&css[0]->chps[chpid]->dev);
286 bus_for_each_dev(&css_bus_type, NULL, to_channelpath(dev),
287 s390_subchannel_remove_chpid);
289 if (need_rescan || css_slow_subchannels_exist())
290 queue_work(slow_path_wq, &slow_path_work);
294 struct res_acc_data {
295 struct channel_path *chp;
301 s390_process_res_acc_sch(struct res_acc_data *res_data, struct subchannel *sch)
308 for (chp = 0; chp <= 7; chp++)
310 * check if chpid is in information updated by ssd
312 if (sch->ssd_info.valid &&
313 sch->ssd_info.chpid[chp] == res_data->chp->id &&
314 (sch->ssd_info.fla[chp] & res_data->fla_mask)
324 * Do a stsch to update our subchannel structure with the
325 * new path information and eventually check for logically
328 ccode = stsch(sch->schid, &sch->schib);
336 s390_process_res_acc_new_sch(struct subchannel_id schid)
341 * We don't know the device yet, but since a path
342 * may be available now to the device we'll have
343 * to do recognition again.
344 * Since we don't have any idea about which chpid
345 * that beast may be on we'll have to do a stsch
346 * on all devices, grr...
348 if (stsch_err(schid, &schib))
350 return need_rescan ? -EAGAIN : -ENXIO;
352 /* Put it on the slow path. */
353 ret = css_enqueue_subchannel_slow(schid);
355 css_clear_subchannel_slow_list();
363 __s390_process_res_acc(struct subchannel_id schid, void *data)
365 int chp_mask, old_lpm;
366 struct res_acc_data *res_data;
367 struct subchannel *sch;
369 res_data = (struct res_acc_data *)data;
370 sch = get_subchannel_by_schid(schid);
372 /* Check if a subchannel is newly available. */
373 return s390_process_res_acc_new_sch(schid);
375 spin_lock_irq(&sch->lock);
377 chp_mask = s390_process_res_acc_sch(res_data, sch);
380 spin_unlock_irq(&sch->lock);
384 sch->lpm = ((sch->schib.pmcw.pim &
385 sch->schib.pmcw.pam &
387 | chp_mask) & sch->opm;
388 if (!old_lpm && sch->lpm)
389 device_trigger_reprobe(sch);
390 else if (sch->driver && sch->driver->verify)
391 sch->driver->verify(&sch->dev);
393 spin_unlock_irq(&sch->lock);
394 put_device(&sch->dev);
395 return (res_data->fla_mask == 0xffff) ? -ENODEV : 0;
400 s390_process_res_acc (struct res_acc_data *res_data)
405 sprintf(dbf_txt, "accpr%x", res_data->chp->id);
406 CIO_TRACE_EVENT( 2, dbf_txt);
407 if (res_data->fla != 0) {
408 sprintf(dbf_txt, "fla%x", res_data->fla);
409 CIO_TRACE_EVENT( 2, dbf_txt);
413 * I/O resources may have become accessible.
414 * Scan through all subchannels that may be concerned and
415 * do a validation on those.
416 * The more information we have (info), the less scanning
417 * will we have to do.
419 rc = for_each_subchannel(__s390_process_res_acc, res_data);
420 if (css_slow_subchannels_exist())
422 else if (rc != -EAGAIN)
428 __get_chpid_from_lir(void *data)
434 /* incident-node descriptor */
436 /* attached-node descriptor */
438 /* incident-specific information */
442 lir = (struct lir*) data;
444 /* NULL link incident record */
446 if (!(lir->indesc[0]&0xc0000000))
447 /* node descriptor not valid */
449 if (!(lir->indesc[0]&0x10000000))
450 /* don't handle device-type nodes - FIXME */
452 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
454 return (u16) (lir->indesc[0]&0x000000ff);
458 chsc_process_crw(void)
461 struct res_acc_data res_data;
463 struct chsc_header request;
467 struct chsc_header response;
470 u8 vf; /* validity flags */
471 u8 rs; /* reporting source */
472 u8 cc; /* content code */
473 u16 fla; /* full link address */
474 u16 rsid; /* reporting source id */
477 u32 ccdf[96]; /* content-code dependent field */
478 /* ccdf has to be big enough for a link-incident record */
484 * build the chsc request block for store event information
486 * This function is only called by the machine check handler thread,
487 * so we don't need locking for the sei_page.
491 CIO_TRACE_EVENT( 2, "prcss");
496 memset(sei_area, 0, sizeof(*sei_area));
497 memset(&res_data, 0, sizeof(struct res_acc_data));
498 sei_area->request.length = 0x0010;
499 sei_area->request.code = 0x000e;
501 ccode = chsc(sei_area);
505 switch (sei_area->response.code) {
506 /* for debug purposes, check for problems */
508 CIO_CRW_EVENT(4, "chsc_process_crw: event information "
509 "successfully stored\n");
510 break; /* everything ok */
513 "chsc_process_crw: invalid command!\n");
516 CIO_CRW_EVENT(2, "chsc_process_crw: error in chsc "
520 CIO_CRW_EVENT(2, "chsc_process_crw: no event "
521 "information stored\n");
524 CIO_CRW_EVENT(2, "chsc_process_crw: chsc response %d\n",
525 sei_area->response.code);
529 /* Check if we might have lost some information. */
530 if (sei_area->flags & 0x40)
531 CIO_CRW_EVENT(2, "chsc_process_crw: Event information "
532 "has been lost due to overflow!\n");
534 if (sei_area->rs != 4) {
535 CIO_CRW_EVENT(2, "chsc_process_crw: reporting source "
536 "(%04X) isn't a chpid!\n",
541 /* which kind of information was stored? */
542 switch (sei_area->cc) {
543 case 1: /* link incident*/
544 CIO_CRW_EVENT(4, "chsc_process_crw: "
545 "channel subsystem reports link incident,"
546 " reporting source is chpid %x\n",
548 chpid = __get_chpid_from_lir(sei_area->ccdf);
550 CIO_CRW_EVENT(4, "%s: Invalid LIR, skipping\n",
553 s390_set_chpid_offline(chpid);
556 case 2: /* i/o resource accessibiliy */
557 CIO_CRW_EVENT(4, "chsc_process_crw: "
558 "channel subsystem reports some I/O "
559 "devices may have become accessible\n");
560 pr_debug("Data received after sei: \n");
561 pr_debug("Validity flags: %x\n", sei_area->vf);
563 /* allocate a new channel path structure, if needed */
564 status = get_chp_status(sei_area->rsid);
566 new_channel_path(sei_area->rsid);
569 dev = get_device(&css[0]->chps[sei_area->rsid]->dev);
570 res_data.chp = to_channelpath(dev);
571 pr_debug("chpid: %x", sei_area->rsid);
572 if ((sei_area->vf & 0xc0) != 0) {
573 res_data.fla = sei_area->fla;
574 if ((sei_area->vf & 0xc0) == 0xc0) {
575 pr_debug(" full link addr: %x",
577 res_data.fla_mask = 0xffff;
579 pr_debug(" link addr: %x",
581 res_data.fla_mask = 0xff00;
584 ret = s390_process_res_acc(&res_data);
589 default: /* other stuff */
590 CIO_CRW_EVENT(4, "chsc_process_crw: event %d\n",
594 } while (sei_area->flags & 0x80);
599 __chp_add_new_sch(struct subchannel_id schid)
604 if (stsch(schid, &schib))
606 return need_rescan ? -EAGAIN : -ENXIO;
608 /* Put it on the slow path. */
609 ret = css_enqueue_subchannel_slow(schid);
611 css_clear_subchannel_slow_list();
620 __chp_add(struct subchannel_id schid, void *data)
623 struct channel_path *chp;
624 struct subchannel *sch;
626 chp = (struct channel_path *)data;
627 sch = get_subchannel_by_schid(schid);
629 /* Check if the subchannel is now available. */
630 return __chp_add_new_sch(schid);
631 spin_lock_irq(&sch->lock);
633 if (sch->schib.pmcw.chpid[i] == chp->id) {
634 if (stsch(sch->schid, &sch->schib) != 0) {
636 spin_unlock_irq(&sch->lock);
642 spin_unlock_irq(&sch->lock);
645 sch->lpm = ((sch->schib.pmcw.pim &
646 sch->schib.pmcw.pam &
648 | 0x80 >> i) & sch->opm;
650 if (sch->driver && sch->driver->verify)
651 sch->driver->verify(&sch->dev);
653 spin_unlock_irq(&sch->lock);
654 put_device(&sch->dev);
665 if (!get_chp_status(chpid))
666 return 0; /* no need to do the rest */
668 sprintf(dbf_txt, "cadd%x", chpid);
669 CIO_TRACE_EVENT(2, dbf_txt);
671 dev = get_device(&css[0]->chps[chpid]->dev);
672 rc = for_each_subchannel(__chp_add, to_channelpath(dev));
673 if (css_slow_subchannels_exist())
682 * Handling of crw machine checks with channel path source.
685 chp_process_crw(int chpid, int on)
688 /* Path has gone. We use the link incident routine.*/
689 s390_set_chpid_offline(chpid);
690 return 0; /* De-register is async anyway. */
693 * Path has come. Allocate a new channel path structure,
696 if (get_chp_status(chpid) < 0)
697 new_channel_path(chpid);
698 /* Avoid the extra overhead in process_rec_acc. */
699 return chp_add(chpid);
703 __check_for_io_and_kill(struct subchannel *sch, int index)
707 if (!device_is_online(sch))
708 /* cio could be doing I/O. */
710 cc = stsch(sch->schid, &sch->schib);
713 if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == (0x80 >> index)) {
714 device_set_waiting(sch);
721 __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
726 if (!sch->ssd_info.valid)
729 spin_lock_irqsave(&sch->lock, flags);
731 for (chp = 0; chp < 8; chp++) {
732 if (sch->ssd_info.chpid[chp] != chpid)
736 sch->opm |= (0x80 >> chp);
737 sch->lpm |= (0x80 >> chp);
739 device_trigger_reprobe(sch);
740 else if (sch->driver && sch->driver->verify)
741 sch->driver->verify(&sch->dev);
743 sch->opm &= ~(0x80 >> chp);
744 sch->lpm &= ~(0x80 >> chp);
746 * Give running I/O a grace period in which it
747 * can successfully terminate, even using the
748 * just varied off path. Then kill it.
750 if (!__check_for_io_and_kill(sch, chp) && !sch->lpm) {
751 if (css_enqueue_subchannel_slow(sch->schid)) {
752 css_clear_subchannel_slow_list();
755 } else if (sch->driver && sch->driver->verify)
756 sch->driver->verify(&sch->dev);
760 spin_unlock_irqrestore(&sch->lock, flags);
764 s390_subchannel_vary_chpid_off(struct device *dev, void *data)
766 struct subchannel *sch;
769 sch = to_subchannel(dev);
772 __s390_subchannel_vary_chpid(sch, *chpid, 0);
777 s390_subchannel_vary_chpid_on(struct device *dev, void *data)
779 struct subchannel *sch;
782 sch = to_subchannel(dev);
785 __s390_subchannel_vary_chpid(sch, *chpid, 1);
790 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
793 struct subchannel *sch;
795 sch = get_subchannel_by_schid(schid);
797 put_device(&sch->dev);
800 if (stsch_err(schid, &schib))
803 /* Put it on the slow path. */
804 if (css_enqueue_subchannel_slow(schid)) {
805 css_clear_subchannel_slow_list();
813 * Function: s390_vary_chpid
814 * Varies the specified chpid online or offline
817 s390_vary_chpid( __u8 chpid, int on)
822 sprintf(dbf_text, on?"varyon%x":"varyoff%x", chpid);
823 CIO_TRACE_EVENT( 2, dbf_text);
825 status = get_chp_status(chpid);
827 printk(KERN_ERR "Can't vary unknown chpid %02X\n", chpid);
831 if (!on && !status) {
832 printk(KERN_ERR "chpid %x is already offline\n", chpid);
836 set_chp_logically_online(chpid, on);
839 * Redo PathVerification on the devices the chpid connects to
842 bus_for_each_dev(&css_bus_type, NULL, &chpid, on ?
843 s390_subchannel_vary_chpid_on :
844 s390_subchannel_vary_chpid_off);
846 /* Scan for new devices on varied on path. */
847 for_each_subchannel(__s390_vary_chpid_on, NULL);
848 if (need_rescan || css_slow_subchannels_exist())
849 queue_work(slow_path_wq, &slow_path_work);
854 * Channel measurement related functions
857 chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
860 struct channel_path *chp;
863 chp = to_channelpath(container_of(kobj, struct device, kobj));
867 size = sizeof(struct cmg_chars);
871 if (off + count > size)
873 memcpy(buf, chp->cmg_chars + off, count);
877 static struct bin_attribute chp_measurement_chars_attr = {
879 .name = "measurement_chars",
881 .owner = THIS_MODULE,
883 .size = sizeof(struct cmg_chars),
884 .read = chp_measurement_chars_read,
888 chp_measurement_copy_block(struct cmg_entry *buf,
889 struct channel_subsystem *css, int chpid)
892 struct cmg_entry *entry, reference_buf;
896 area = css->cub_addr1;
899 area = css->cub_addr2;
902 entry = area + (idx * sizeof(struct cmg_entry));
904 memcpy(buf, entry, sizeof(*entry));
905 memcpy(&reference_buf, entry, sizeof(*entry));
906 } while (reference_buf.values[0] != buf->values[0]);
910 chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
912 struct channel_path *chp;
913 struct channel_subsystem *css;
916 chp = to_channelpath(container_of(kobj, struct device, kobj));
917 css = to_css(chp->dev.parent);
919 size = sizeof(struct cmg_entry);
921 /* Only allow single reads. */
922 if (off || count < size)
924 chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
929 static struct bin_attribute chp_measurement_attr = {
931 .name = "measurement",
933 .owner = THIS_MODULE,
935 .size = sizeof(struct cmg_entry),
936 .read = chp_measurement_read,
940 chsc_remove_chp_cmg_attr(struct channel_path *chp)
942 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_chars_attr);
943 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_attr);
947 chsc_add_chp_cmg_attr(struct channel_path *chp)
951 ret = sysfs_create_bin_file(&chp->dev.kobj,
952 &chp_measurement_chars_attr);
955 ret = sysfs_create_bin_file(&chp->dev.kobj, &chp_measurement_attr);
957 sysfs_remove_bin_file(&chp->dev.kobj,
958 &chp_measurement_chars_attr);
963 chsc_remove_cmg_attr(struct channel_subsystem *css)
967 for (i = 0; i <= __MAX_CHPID; i++) {
970 chsc_remove_chp_cmg_attr(css->chps[i]);
975 chsc_add_cmg_attr(struct channel_subsystem *css)
980 for (i = 0; i <= __MAX_CHPID; i++) {
983 ret = chsc_add_chp_cmg_attr(css->chps[i]);
989 for (--i; i >= 0; i--) {
992 chsc_remove_chp_cmg_attr(css->chps[i]);
999 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
1002 struct chsc_header request;
1003 u32 operation_code : 2;
1012 struct chsc_header response;
1021 secm_area->request.length = 0x0050;
1022 secm_area->request.code = 0x0016;
1024 secm_area->key = PAGE_DEFAULT_KEY;
1025 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
1026 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
1028 secm_area->operation_code = enable ? 0 : 1;
1030 ccode = chsc(secm_area);
1032 return (ccode == 3) ? -ENODEV : -EBUSY;
1034 switch (secm_area->response.code) {
1035 case 0x0001: /* Success. */
1038 case 0x0003: /* Invalid block. */
1039 case 0x0007: /* Invalid format. */
1040 case 0x0008: /* Other invalid block. */
1041 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1044 case 0x0004: /* Command not provided in model. */
1045 CIO_CRW_EVENT(2, "Model does not provide secm\n");
1048 case 0x0102: /* cub adresses incorrect */
1049 CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
1052 case 0x0103: /* key error */
1053 CIO_CRW_EVENT(2, "Access key error in secm\n");
1056 case 0x0105: /* error while starting */
1057 CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
1061 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1062 secm_area->response.code);
1069 chsc_secm(struct channel_subsystem *css, int enable)
1074 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1078 mutex_lock(&css->mutex);
1079 if (enable && !css->cm_enabled) {
1080 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1081 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1082 if (!css->cub_addr1 || !css->cub_addr2) {
1083 free_page((unsigned long)css->cub_addr1);
1084 free_page((unsigned long)css->cub_addr2);
1085 free_page((unsigned long)secm_area);
1086 mutex_unlock(&css->mutex);
1090 ret = __chsc_do_secm(css, enable, secm_area);
1092 css->cm_enabled = enable;
1093 if (css->cm_enabled) {
1094 ret = chsc_add_cmg_attr(css);
1096 memset(secm_area, 0, PAGE_SIZE);
1097 __chsc_do_secm(css, 0, secm_area);
1098 css->cm_enabled = 0;
1101 chsc_remove_cmg_attr(css);
1103 if (enable && !css->cm_enabled) {
1104 free_page((unsigned long)css->cub_addr1);
1105 free_page((unsigned long)css->cub_addr2);
1107 mutex_unlock(&css->mutex);
1108 free_page((unsigned long)secm_area);
1113 * Files for the channel path entries.
1116 chp_status_show(struct device *dev, struct device_attribute *attr, char *buf)
1118 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1122 return (get_chp_status(chp->id) ? sprintf(buf, "online\n") :
1123 sprintf(buf, "offline\n"));
1127 chp_status_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1129 struct channel_path *cp = container_of(dev, struct channel_path, dev);
1134 num_args = sscanf(buf, "%5s", cmd);
1138 if (!strnicmp(cmd, "on", 2))
1139 error = s390_vary_chpid(cp->id, 1);
1140 else if (!strnicmp(cmd, "off", 3))
1141 error = s390_vary_chpid(cp->id, 0);
1145 return error < 0 ? error : count;
1149 static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
1152 chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
1154 struct channel_path *chp = container_of(dev, struct channel_path, dev);
1158 return sprintf(buf, "%x\n", chp->desc.desc);
1161 static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
1164 chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
1166 struct channel_path *chp = to_channelpath(dev);
1170 if (chp->cmg == -1) /* channel measurements not available */
1171 return sprintf(buf, "unknown\n");
1172 return sprintf(buf, "%x\n", chp->cmg);
1175 static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
1178 chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
1180 struct channel_path *chp = to_channelpath(dev);
1184 if (chp->shared == -1) /* channel measurements not available */
1185 return sprintf(buf, "unknown\n");
1186 return sprintf(buf, "%x\n", chp->shared);
1189 static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
1191 static struct attribute * chp_attrs[] = {
1192 &dev_attr_status.attr,
1193 &dev_attr_type.attr,
1195 &dev_attr_shared.attr,
1199 static struct attribute_group chp_attr_group = {
1204 chp_release(struct device *dev)
1206 struct channel_path *cp;
1208 cp = container_of(dev, struct channel_path, dev);
1213 chsc_determine_channel_path_description(int chpid,
1214 struct channel_path_desc *desc)
1219 struct chsc_header request;
1221 u32 first_chpid : 8;
1225 struct chsc_header response;
1227 struct channel_path_desc desc;
1230 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1234 scpd_area->request.length = 0x0010;
1235 scpd_area->request.code = 0x0002;
1237 scpd_area->first_chpid = chpid;
1238 scpd_area->last_chpid = chpid;
1240 ccode = chsc(scpd_area);
1242 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1246 switch (scpd_area->response.code) {
1247 case 0x0001: /* Success. */
1248 memcpy(desc, &scpd_area->desc,
1249 sizeof(struct channel_path_desc));
1252 case 0x0003: /* Invalid block. */
1253 case 0x0007: /* Invalid format. */
1254 case 0x0008: /* Other invalid block. */
1255 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1258 case 0x0004: /* Command not provided in model. */
1259 CIO_CRW_EVENT(2, "Model does not provide scpd\n");
1263 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1264 scpd_area->response.code);
1268 free_page((unsigned long)scpd_area);
1273 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
1274 struct cmg_chars *chars)
1279 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
1281 if (chp->cmg_chars) {
1283 struct cmg_chars *cmg_chars;
1285 cmg_chars = chp->cmg_chars;
1286 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
1287 mask = 0x80 >> (i + 3);
1289 cmg_chars->values[i] = chars->values[i];
1291 cmg_chars->values[i] = 0;
1296 /* No cmg-dependent data. */
1302 chsc_get_channel_measurement_chars(struct channel_path *chp)
1307 struct chsc_header request;
1309 u32 first_chpid : 8;
1313 struct chsc_header response;
1324 u32 data[NR_MEASUREMENT_CHARS];
1327 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1331 scmc_area->request.length = 0x0010;
1332 scmc_area->request.code = 0x0022;
1334 scmc_area->first_chpid = chp->id;
1335 scmc_area->last_chpid = chp->id;
1337 ccode = chsc(scmc_area);
1339 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1343 switch (scmc_area->response.code) {
1344 case 0x0001: /* Success. */
1345 if (!scmc_area->not_valid) {
1346 chp->cmg = scmc_area->cmg;
1347 chp->shared = scmc_area->shared;
1348 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1349 (struct cmg_chars *)
1357 case 0x0003: /* Invalid block. */
1358 case 0x0007: /* Invalid format. */
1359 case 0x0008: /* Invalid bit combination. */
1360 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1363 case 0x0004: /* Command not provided. */
1364 CIO_CRW_EVENT(2, "Model does not provide scmc\n");
1368 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1369 scmc_area->response.code);
1373 free_page((unsigned long)scmc_area);
1378 * Entries for chpids on the system bus.
1379 * This replaces /proc/chpids.
1382 new_channel_path(int chpid)
1384 struct channel_path *chp;
1387 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
1391 /* fill in status, etc. */
1394 chp->dev = (struct device) {
1395 .parent = &css[0]->device,
1396 .release = chp_release,
1398 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
1400 /* Obtain channel path description and fill it in. */
1401 ret = chsc_determine_channel_path_description(chpid, &chp->desc);
1404 /* Get channel-measurement characteristics. */
1405 if (css_characteristics_avail && css_chsc_characteristics.scmc
1406 && css_chsc_characteristics.secm) {
1407 ret = chsc_get_channel_measurement_chars(chp);
1411 static int msg_done;
1414 printk(KERN_WARNING "cio: Channel measurements not "
1415 "available, continuing.\n");
1421 /* make it known to the system */
1422 ret = device_register(&chp->dev);
1424 printk(KERN_WARNING "%s: could not register %02x\n",
1428 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
1430 device_unregister(&chp->dev);
1433 mutex_lock(&css[0]->mutex);
1434 if (css[0]->cm_enabled) {
1435 ret = chsc_add_chp_cmg_attr(chp);
1437 sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
1438 device_unregister(&chp->dev);
1439 mutex_unlock(&css[0]->mutex);
1443 css[0]->chps[chpid] = chp;
1444 mutex_unlock(&css[0]->mutex);
1452 chsc_get_chp_desc(struct subchannel *sch, int chp_no)
1454 struct channel_path *chp;
1455 struct channel_path_desc *desc;
1457 chp = css[0]->chps[sch->schib.pmcw.chpid[chp_no]];
1460 desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
1463 memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
1469 chsc_alloc_sei_area(void)
1471 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1473 printk(KERN_WARNING"Can't allocate page for processing of " \
1474 "chsc machine checks!\n");
1475 return (sei_page ? 0 : -ENOMEM);
1479 chsc_enable_facility(int operation_code)
1483 struct chsc_header request;
1490 u32 operation_data_area[252];
1491 struct chsc_header response;
1497 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
1500 sda_area->request.length = 0x0400;
1501 sda_area->request.code = 0x0031;
1502 sda_area->operation_code = operation_code;
1504 ret = chsc(sda_area);
1506 ret = (ret == 3) ? -ENODEV : -EBUSY;
1509 switch (sda_area->response.code) {
1510 case 0x0001: /* everything ok */
1513 case 0x0003: /* invalid request block */
1517 case 0x0004: /* command not provided */
1518 case 0x0101: /* facility not provided */
1521 default: /* something went wrong */
1525 free_page((unsigned long)sda_area);
1529 subsys_initcall(chsc_alloc_sei_area);
1531 struct css_general_char css_general_characteristics;
1532 struct css_chsc_char css_chsc_characteristics;
1535 chsc_determine_css_characteristics(void)
1539 struct chsc_header request;
1543 struct chsc_header response;
1545 u32 general_char[510];
1549 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1551 printk(KERN_WARNING"cio: Was not able to determine available" \
1552 "CHSCs due to no memory.\n");
1556 scsc_area->request.length = 0x0010;
1557 scsc_area->request.code = 0x0010;
1559 result = chsc(scsc_area);
1561 printk(KERN_WARNING"cio: Was not able to determine " \
1562 "available CHSCs, cc=%i.\n", result);
1567 if (scsc_area->response.code != 1) {
1568 printk(KERN_WARNING"cio: Was not able to determine " \
1569 "available CHSCs.\n");
1573 memcpy(&css_general_characteristics, scsc_area->general_char,
1574 sizeof(css_general_characteristics));
1575 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1576 sizeof(css_chsc_characteristics));
1578 free_page ((unsigned long) scsc_area);
1582 EXPORT_SYMBOL_GPL(css_general_characteristics);
1583 EXPORT_SYMBOL_GPL(css_chsc_characteristics);