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>
18 #include <asm/chpid.h>
22 #include "cio_debug.h"
27 static void *sei_page;
29 static int chsc_error_from_response(int response)
48 struct chsc_ssd_area {
49 struct chsc_header request;
53 u16 f_sch; /* first subchannel */
55 u16 l_sch; /* last subchannel */
57 struct chsc_header response;
61 u8 st : 3; /* subchannel type */
63 u8 unit_addr; /* unit address */
64 u16 devno; /* device number */
67 u16 sch; /* subchannel */
68 u8 chpid[8]; /* chpids 0-7 */
69 u16 fla[8]; /* full link addresses 0-7 */
70 } __attribute__ ((packed));
72 int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
75 struct chsc_ssd_area *ssd_area;
81 page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
84 ssd_area = (struct chsc_ssd_area *) page;
85 ssd_area->request.length = 0x0010;
86 ssd_area->request.code = 0x0004;
87 ssd_area->ssid = schid.ssid;
88 ssd_area->f_sch = schid.sch_no;
89 ssd_area->l_sch = schid.sch_no;
91 ccode = chsc(ssd_area);
94 ret = (ccode == 3) ? -ENODEV : -EBUSY;
97 ret = chsc_error_from_response(ssd_area->response.code);
99 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
100 schid.ssid, schid.sch_no,
101 ssd_area->response.code);
104 if (!ssd_area->sch_valid) {
110 memset(ssd, 0, sizeof(struct chsc_ssd_info));
111 if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
112 (ssd_area->st != SUBCHANNEL_TYPE_MSG))
114 ssd->path_mask = ssd_area->path_mask;
115 ssd->fla_valid_mask = ssd_area->fla_valid_mask;
116 for (i = 0; i < 8; i++) {
118 if (ssd_area->path_mask & mask) {
119 chp_id_init(&ssd->chpid[i]);
120 ssd->chpid[i].id = ssd_area->chpid[i];
122 if (ssd_area->fla_valid_mask & mask)
123 ssd->fla[i] = ssd_area->fla[i];
130 static int check_for_io_on_path(struct subchannel *sch, int mask)
134 cc = stsch(sch->schid, &sch->schib);
137 if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == mask)
142 static void terminate_internal_io(struct subchannel *sch)
144 if (cio_clear(sch)) {
145 /* Recheck device in case clear failed. */
147 if (device_trigger_verify(sch) != 0)
148 css_schedule_eval(sch->schid);
151 /* Request retry of internal operation. */
152 device_set_intretry(sch);
154 if (sch->driver && sch->driver->termination)
155 sch->driver->termination(sch);
158 static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
162 struct chp_id *chpid = data;
165 for (j = 0; j < 8; j++) {
167 if ((sch->schib.pmcw.pim & mask) &&
168 (sch->schib.pmcw.chpid[j] == chpid->id))
174 spin_lock_irq(sch->lock);
176 stsch(sch->schid, &schib);
177 if (!css_sch_is_valid(&schib))
179 memcpy(&sch->schib, &schib, sizeof(struct schib));
180 /* Check for single path devices. */
181 if (sch->schib.pmcw.pim == 0x80)
184 if (check_for_io_on_path(sch, mask)) {
185 if (device_is_online(sch))
188 terminate_internal_io(sch);
189 /* Re-start path verification. */
190 if (sch->driver && sch->driver->verify)
191 sch->driver->verify(sch);
194 /* trigger path verification. */
195 if (sch->driver && sch->driver->verify)
196 sch->driver->verify(sch);
197 else if (sch->lpm == mask)
201 spin_unlock_irq(sch->lock);
206 spin_unlock_irq(sch->lock);
207 css_schedule_eval(sch->schid);
211 void chsc_chp_offline(struct chp_id chpid)
215 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
216 CIO_TRACE_EVENT(2, dbf_txt);
218 if (chp_get_status(chpid) <= 0)
220 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &chpid);
223 static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
227 * We don't know the device yet, but since a path
228 * may be available now to the device we'll have
229 * to do recognition again.
230 * Since we don't have any idea about which chpid
231 * that beast may be on we'll have to do a stsch
232 * on all devices, grr...
234 if (stsch_err(schid, &schib))
238 /* Put it on the slow path. */
239 css_schedule_eval(schid);
243 struct res_acc_data {
249 static int get_res_chpid_mask(struct chsc_ssd_info *ssd,
250 struct res_acc_data *data)
255 for (i = 0; i < 8; i++) {
257 if (!(ssd->path_mask & mask))
259 if (!chp_id_is_equal(&ssd->chpid[i], &data->chpid))
261 if ((ssd->fla_valid_mask & mask) &&
262 ((ssd->fla[i] & data->fla_mask) != data->fla))
269 static int __s390_process_res_acc(struct subchannel *sch, void *data)
271 int chp_mask, old_lpm;
272 struct res_acc_data *res_data = data;
274 spin_lock_irq(sch->lock);
275 chp_mask = get_res_chpid_mask(&sch->ssd_info, res_data);
278 if (stsch(sch->schid, &sch->schib))
281 sch->lpm = ((sch->schib.pmcw.pim &
282 sch->schib.pmcw.pam &
284 | chp_mask) & sch->opm;
285 if (!old_lpm && sch->lpm)
286 device_trigger_reprobe(sch);
287 else if (sch->driver && sch->driver->verify)
288 sch->driver->verify(sch);
290 spin_unlock_irq(sch->lock);
295 static void s390_process_res_acc (struct res_acc_data *res_data)
299 sprintf(dbf_txt, "accpr%x.%02x", res_data->chpid.cssid,
301 CIO_TRACE_EVENT( 2, dbf_txt);
302 if (res_data->fla != 0) {
303 sprintf(dbf_txt, "fla%x", res_data->fla);
304 CIO_TRACE_EVENT( 2, dbf_txt);
308 * I/O resources may have become accessible.
309 * Scan through all subchannels that may be concerned and
310 * do a validation on those.
311 * The more information we have (info), the less scanning
312 * will we have to do.
314 for_each_subchannel_staged(__s390_process_res_acc,
315 s390_process_res_acc_new_sch, res_data);
319 __get_chpid_from_lir(void *data)
325 /* incident-node descriptor */
327 /* attached-node descriptor */
329 /* incident-specific information */
331 } __attribute__ ((packed)) *lir;
335 /* NULL link incident record */
337 if (!(lir->indesc[0]&0xc0000000))
338 /* node descriptor not valid */
340 if (!(lir->indesc[0]&0x10000000))
341 /* don't handle device-type nodes - FIXME */
343 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
345 return (u16) (lir->indesc[0]&0x000000ff);
348 struct chsc_sei_area {
349 struct chsc_header request;
353 struct chsc_header response;
356 u8 vf; /* validity flags */
357 u8 rs; /* reporting source */
358 u8 cc; /* content code */
359 u16 fla; /* full link address */
360 u16 rsid; /* reporting source id */
363 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
364 /* ccdf has to be big enough for a link-incident record */
365 } __attribute__ ((packed));
367 static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
372 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
373 sei_area->rs, sei_area->rsid);
374 if (sei_area->rs != 4)
376 id = __get_chpid_from_lir(sei_area->ccdf);
378 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
382 chsc_chp_offline(chpid);
386 static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
388 struct res_acc_data res_data;
392 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
393 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
394 if (sei_area->rs != 4)
397 chpid.id = sei_area->rsid;
398 /* allocate a new channel path structure, if needed */
399 status = chp_get_status(chpid);
404 memset(&res_data, 0, sizeof(struct res_acc_data));
405 res_data.chpid = chpid;
406 if ((sei_area->vf & 0xc0) != 0) {
407 res_data.fla = sei_area->fla;
408 if ((sei_area->vf & 0xc0) == 0xc0)
409 /* full link address */
410 res_data.fla_mask = 0xffff;
413 res_data.fla_mask = 0xff00;
415 s390_process_res_acc(&res_data);
418 struct chp_config_data {
424 static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
426 struct chp_config_data *data;
430 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
431 if (sei_area->rs != 0)
433 data = (struct chp_config_data *) &(sei_area->ccdf);
435 for (num = 0; num <= __MAX_CHPID; num++) {
436 if (!chp_test_bit(data->map, num))
439 printk(KERN_WARNING "cio: processing configure event %d for "
440 "chpid %x.%02x\n", data->op, chpid.cssid, chpid.id);
443 chp_cfg_schedule(chpid, 1);
446 chp_cfg_schedule(chpid, 0);
449 chp_cfg_cancel_deconfigure(chpid);
455 static void chsc_process_sei(struct chsc_sei_area *sei_area)
457 /* Check if we might have lost some information. */
458 if (sei_area->flags & 0x40) {
459 CIO_CRW_EVENT(2, "chsc: event overflow\n");
460 css_schedule_eval_all();
462 /* which kind of information was stored? */
463 switch (sei_area->cc) {
464 case 1: /* link incident*/
465 chsc_process_sei_link_incident(sei_area);
467 case 2: /* i/o resource accessibiliy */
468 chsc_process_sei_res_acc(sei_area);
470 case 8: /* channel-path-configuration notification */
471 chsc_process_sei_chp_config(sei_area);
473 default: /* other stuff */
474 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
480 void chsc_process_crw(void)
482 struct chsc_sei_area *sei_area;
486 /* Access to sei_page is serialized through machine check handler
487 * thread, so no need for locking. */
490 CIO_TRACE_EVENT( 2, "prcss");
492 memset(sei_area, 0, sizeof(*sei_area));
493 sei_area->request.length = 0x0010;
494 sei_area->request.code = 0x000e;
498 if (sei_area->response.code == 0x0001) {
499 CIO_CRW_EVENT(4, "chsc: sei successful\n");
500 chsc_process_sei(sei_area);
502 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
503 sei_area->response.code);
506 } while (sei_area->flags & 0x80);
509 static int __chp_add_new_sch(struct subchannel_id schid, void *data)
513 if (stsch_err(schid, &schib))
517 /* Put it on the slow path. */
518 css_schedule_eval(schid);
523 static int __chp_add(struct subchannel *sch, void *data)
526 struct chp_id *chpid = data;
528 spin_lock_irq(sch->lock);
529 for (i=0; i<8; i++) {
531 if ((sch->schib.pmcw.pim & mask) &&
532 (sch->schib.pmcw.chpid[i] == chpid->id))
536 spin_unlock_irq(sch->lock);
539 if (stsch(sch->schid, &sch->schib)) {
540 spin_unlock_irq(sch->lock);
541 css_schedule_eval(sch->schid);
544 sch->lpm = ((sch->schib.pmcw.pim &
545 sch->schib.pmcw.pam &
549 if (sch->driver && sch->driver->verify)
550 sch->driver->verify(sch);
552 spin_unlock_irq(sch->lock);
557 void chsc_chp_online(struct chp_id chpid)
561 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
562 CIO_TRACE_EVENT(2, dbf_txt);
564 if (chp_get_status(chpid) != 0)
565 for_each_subchannel_staged(__chp_add, __chp_add_new_sch,
569 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
570 struct chp_id chpid, int on)
576 spin_lock_irqsave(sch->lock, flags);
578 for (chp = 0; chp < 8; chp++) {
580 if (!(sch->ssd_info.path_mask & mask))
582 if (!chp_id_is_equal(&sch->ssd_info.chpid[chp], &chpid))
589 device_trigger_reprobe(sch);
590 else if (sch->driver && sch->driver->verify)
591 sch->driver->verify(sch);
596 if (check_for_io_on_path(sch, mask)) {
597 if (device_is_online(sch))
598 /* Path verification is done after killing. */
601 /* Kill and retry internal I/O. */
602 terminate_internal_io(sch);
603 /* Re-start path verification. */
604 if (sch->driver && sch->driver->verify)
605 sch->driver->verify(sch);
607 } else if (!sch->lpm) {
608 if (device_trigger_verify(sch) != 0)
609 css_schedule_eval(sch->schid);
610 } else if (sch->driver && sch->driver->verify)
611 sch->driver->verify(sch);
614 spin_unlock_irqrestore(sch->lock, flags);
617 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
619 struct chp_id *chpid = data;
621 __s390_subchannel_vary_chpid(sch, *chpid, 0);
625 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
627 struct chp_id *chpid = data;
629 __s390_subchannel_vary_chpid(sch, *chpid, 1);
634 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
638 if (stsch_err(schid, &schib))
641 /* Put it on the slow path. */
642 css_schedule_eval(schid);
647 * chsc_chp_vary - propagate channel-path vary operation to subchannels
648 * @chpid: channl-path ID
649 * @on: non-zero for vary online, zero for vary offline
651 int chsc_chp_vary(struct chp_id chpid, int on)
654 * Redo PathVerification on the devices the chpid connects to
658 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
659 __s390_vary_chpid_on, &chpid);
661 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
668 chsc_remove_cmg_attr(struct channel_subsystem *css)
672 for (i = 0; i <= __MAX_CHPID; i++) {
675 chp_remove_cmg_attr(css->chps[i]);
680 chsc_add_cmg_attr(struct channel_subsystem *css)
685 for (i = 0; i <= __MAX_CHPID; i++) {
688 ret = chp_add_cmg_attr(css->chps[i]);
694 for (--i; i >= 0; i--) {
697 chp_remove_cmg_attr(css->chps[i]);
703 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
706 struct chsc_header request;
707 u32 operation_code : 2;
716 struct chsc_header response;
721 } __attribute__ ((packed)) *secm_area;
725 secm_area->request.length = 0x0050;
726 secm_area->request.code = 0x0016;
728 secm_area->key = PAGE_DEFAULT_KEY;
729 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
730 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
732 secm_area->operation_code = enable ? 0 : 1;
734 ccode = chsc(secm_area);
736 return (ccode == 3) ? -ENODEV : -EBUSY;
738 switch (secm_area->response.code) {
743 ret = chsc_error_from_response(secm_area->response.code);
746 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
747 secm_area->response.code);
752 chsc_secm(struct channel_subsystem *css, int enable)
757 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
761 mutex_lock(&css->mutex);
762 if (enable && !css->cm_enabled) {
763 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
764 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
765 if (!css->cub_addr1 || !css->cub_addr2) {
766 free_page((unsigned long)css->cub_addr1);
767 free_page((unsigned long)css->cub_addr2);
768 free_page((unsigned long)secm_area);
769 mutex_unlock(&css->mutex);
773 ret = __chsc_do_secm(css, enable, secm_area);
775 css->cm_enabled = enable;
776 if (css->cm_enabled) {
777 ret = chsc_add_cmg_attr(css);
779 memset(secm_area, 0, PAGE_SIZE);
780 __chsc_do_secm(css, 0, secm_area);
784 chsc_remove_cmg_attr(css);
786 if (!css->cm_enabled) {
787 free_page((unsigned long)css->cub_addr1);
788 free_page((unsigned long)css->cub_addr2);
790 mutex_unlock(&css->mutex);
791 free_page((unsigned long)secm_area);
795 int chsc_determine_channel_path_description(struct chp_id chpid,
796 struct channel_path_desc *desc)
801 struct chsc_header request;
807 struct chsc_header response;
809 struct channel_path_desc desc;
810 } __attribute__ ((packed)) *scpd_area;
812 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
816 scpd_area->request.length = 0x0010;
817 scpd_area->request.code = 0x0002;
819 scpd_area->first_chpid = chpid.id;
820 scpd_area->last_chpid = chpid.id;
822 ccode = chsc(scpd_area);
824 ret = (ccode == 3) ? -ENODEV : -EBUSY;
828 ret = chsc_error_from_response(scpd_area->response.code);
831 memcpy(desc, &scpd_area->desc,
832 sizeof(struct channel_path_desc));
834 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
835 scpd_area->response.code);
837 free_page((unsigned long)scpd_area);
842 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
843 struct cmg_chars *chars)
848 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
850 if (chp->cmg_chars) {
852 struct cmg_chars *cmg_chars;
854 cmg_chars = chp->cmg_chars;
855 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
856 mask = 0x80 >> (i + 3);
858 cmg_chars->values[i] = chars->values[i];
860 cmg_chars->values[i] = 0;
865 /* No cmg-dependent data. */
870 int chsc_get_channel_measurement_chars(struct channel_path *chp)
875 struct chsc_header request;
881 struct chsc_header response;
892 u32 data[NR_MEASUREMENT_CHARS];
893 } __attribute__ ((packed)) *scmc_area;
895 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
899 scmc_area->request.length = 0x0010;
900 scmc_area->request.code = 0x0022;
902 scmc_area->first_chpid = chp->chpid.id;
903 scmc_area->last_chpid = chp->chpid.id;
905 ccode = chsc(scmc_area);
907 ret = (ccode == 3) ? -ENODEV : -EBUSY;
911 ret = chsc_error_from_response(scmc_area->response.code);
914 if (!scmc_area->not_valid) {
915 chp->cmg = scmc_area->cmg;
916 chp->shared = scmc_area->shared;
917 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
925 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
926 scmc_area->response.code);
929 free_page((unsigned long)scmc_area);
933 int __init chsc_alloc_sei_area(void)
935 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
937 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
938 "chsc machine checks!\n");
939 return (sei_page ? 0 : -ENOMEM);
942 void __init chsc_free_sei_area(void)
948 chsc_enable_facility(int operation_code)
952 struct chsc_header request;
959 u32 operation_data_area[252];
960 struct chsc_header response;
964 } __attribute__ ((packed)) *sda_area;
966 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
969 sda_area->request.length = 0x0400;
970 sda_area->request.code = 0x0031;
971 sda_area->operation_code = operation_code;
973 ret = chsc(sda_area);
975 ret = (ret == 3) ? -ENODEV : -EBUSY;
979 switch (sda_area->response.code) {
984 ret = chsc_error_from_response(sda_area->response.code);
987 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
988 operation_code, sda_area->response.code);
990 free_page((unsigned long)sda_area);
994 struct css_general_char css_general_characteristics;
995 struct css_chsc_char css_chsc_characteristics;
998 chsc_determine_css_characteristics(void)
1002 struct chsc_header request;
1006 struct chsc_header response;
1008 u32 general_char[510];
1010 } __attribute__ ((packed)) *scsc_area;
1012 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1016 scsc_area->request.length = 0x0010;
1017 scsc_area->request.code = 0x0010;
1019 result = chsc(scsc_area);
1021 result = (result == 3) ? -ENODEV : -EBUSY;
1025 result = chsc_error_from_response(scsc_area->response.code);
1027 memcpy(&css_general_characteristics, scsc_area->general_char,
1028 sizeof(css_general_characteristics));
1029 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1030 sizeof(css_chsc_characteristics));
1032 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1033 scsc_area->response.code);
1035 free_page ((unsigned long) scsc_area);
1039 EXPORT_SYMBOL_GPL(css_general_characteristics);
1040 EXPORT_SYMBOL_GPL(css_chsc_characteristics);