2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call
5 * Copyright IBM Corp. 1999,2008
6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
7 * Cornelia Huck (cornelia.huck@de.ibm.com)
8 * Arnd Bergmann (arndb@de.ibm.com)
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/device.h>
17 #include <asm/chpid.h>
19 #include "../s390mach.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 s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
132 spin_lock_irq(sch->lock);
133 if (sch->driver && sch->driver->chp_event)
134 if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
136 spin_unlock_irq(sch->lock);
141 spin_unlock_irq(sch->lock);
142 css_schedule_eval(sch->schid);
146 void chsc_chp_offline(struct chp_id chpid)
149 struct chp_link link;
151 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
152 CIO_TRACE_EVENT(2, dbf_txt);
154 if (chp_get_status(chpid) <= 0)
156 memset(&link, 0, sizeof(struct chp_link));
158 /* Wait until previous actions have settled. */
159 css_wait_for_slow_path();
160 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
163 static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
167 * We don't know the device yet, but since a path
168 * may be available now to the device we'll have
169 * to do recognition again.
170 * Since we don't have any idea about which chpid
171 * that beast may be on we'll have to do a stsch
172 * on all devices, grr...
174 if (stsch_err(schid, &schib))
178 /* Put it on the slow path. */
179 css_schedule_eval(schid);
183 static int __s390_process_res_acc(struct subchannel *sch, void *data)
185 spin_lock_irq(sch->lock);
186 if (sch->driver && sch->driver->chp_event)
187 sch->driver->chp_event(sch, data, CHP_ONLINE);
188 spin_unlock_irq(sch->lock);
193 static void s390_process_res_acc(struct chp_link *link)
197 sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
199 CIO_TRACE_EVENT( 2, dbf_txt);
200 if (link->fla != 0) {
201 sprintf(dbf_txt, "fla%x", link->fla);
202 CIO_TRACE_EVENT( 2, dbf_txt);
204 /* Wait until previous actions have settled. */
205 css_wait_for_slow_path();
207 * I/O resources may have become accessible.
208 * Scan through all subchannels that may be concerned and
209 * do a validation on those.
210 * The more information we have (info), the less scanning
211 * will we have to do.
213 for_each_subchannel_staged(__s390_process_res_acc,
214 s390_process_res_acc_new_sch, link);
218 __get_chpid_from_lir(void *data)
224 /* incident-node descriptor */
226 /* attached-node descriptor */
228 /* incident-specific information */
230 } __attribute__ ((packed)) *lir;
234 /* NULL link incident record */
236 if (!(lir->indesc[0]&0xc0000000))
237 /* node descriptor not valid */
239 if (!(lir->indesc[0]&0x10000000))
240 /* don't handle device-type nodes - FIXME */
242 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
244 return (u16) (lir->indesc[0]&0x000000ff);
247 struct chsc_sei_area {
248 struct chsc_header request;
252 struct chsc_header response;
255 u8 vf; /* validity flags */
256 u8 rs; /* reporting source */
257 u8 cc; /* content code */
258 u16 fla; /* full link address */
259 u16 rsid; /* reporting source id */
262 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
263 /* ccdf has to be big enough for a link-incident record */
264 } __attribute__ ((packed));
266 static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
271 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
272 sei_area->rs, sei_area->rsid);
273 if (sei_area->rs != 4)
275 id = __get_chpid_from_lir(sei_area->ccdf);
277 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
281 chsc_chp_offline(chpid);
285 static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
287 struct chp_link link;
291 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
292 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
293 if (sei_area->rs != 4)
296 chpid.id = sei_area->rsid;
297 /* allocate a new channel path structure, if needed */
298 status = chp_get_status(chpid);
303 memset(&link, 0, sizeof(struct chp_link));
305 if ((sei_area->vf & 0xc0) != 0) {
306 link.fla = sei_area->fla;
307 if ((sei_area->vf & 0xc0) == 0xc0)
308 /* full link address */
309 link.fla_mask = 0xffff;
312 link.fla_mask = 0xff00;
314 s390_process_res_acc(&link);
317 struct chp_config_data {
323 static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
325 struct chp_config_data *data;
329 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
330 if (sei_area->rs != 0)
332 data = (struct chp_config_data *) &(sei_area->ccdf);
334 for (num = 0; num <= __MAX_CHPID; num++) {
335 if (!chp_test_bit(data->map, num))
338 printk(KERN_WARNING "cio: processing configure event %d for "
339 "chpid %x.%02x\n", data->op, chpid.cssid, chpid.id);
342 chp_cfg_schedule(chpid, 1);
345 chp_cfg_schedule(chpid, 0);
348 chp_cfg_cancel_deconfigure(chpid);
354 static void chsc_process_sei(struct chsc_sei_area *sei_area)
356 /* Check if we might have lost some information. */
357 if (sei_area->flags & 0x40) {
358 CIO_CRW_EVENT(2, "chsc: event overflow\n");
359 css_schedule_eval_all();
361 /* which kind of information was stored? */
362 switch (sei_area->cc) {
363 case 1: /* link incident*/
364 chsc_process_sei_link_incident(sei_area);
366 case 2: /* i/o resource accessibiliy */
367 chsc_process_sei_res_acc(sei_area);
369 case 8: /* channel-path-configuration notification */
370 chsc_process_sei_chp_config(sei_area);
372 default: /* other stuff */
373 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
379 static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
381 struct chsc_sei_area *sei_area;
384 css_schedule_eval_all();
387 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
388 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
389 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
390 crw0->erc, crw0->rsid);
393 /* Access to sei_page is serialized through machine check handler
394 * thread, so no need for locking. */
397 CIO_TRACE_EVENT(2, "prcss");
399 memset(sei_area, 0, sizeof(*sei_area));
400 sei_area->request.length = 0x0010;
401 sei_area->request.code = 0x000e;
405 if (sei_area->response.code == 0x0001) {
406 CIO_CRW_EVENT(4, "chsc: sei successful\n");
407 chsc_process_sei(sei_area);
409 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
410 sei_area->response.code);
413 } while (sei_area->flags & 0x80);
416 void chsc_chp_online(struct chp_id chpid)
419 struct chp_link link;
421 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
422 CIO_TRACE_EVENT(2, dbf_txt);
424 if (chp_get_status(chpid) != 0) {
425 memset(&link, 0, sizeof(struct chp_link));
427 /* Wait until previous actions have settled. */
428 css_wait_for_slow_path();
429 for_each_subchannel_staged(__s390_process_res_acc, NULL,
434 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
435 struct chp_id chpid, int on)
438 struct chp_link link;
440 memset(&link, 0, sizeof(struct chp_link));
442 spin_lock_irqsave(sch->lock, flags);
443 if (sch->driver && sch->driver->chp_event)
444 sch->driver->chp_event(sch, &link,
445 on ? CHP_VARY_ON : CHP_VARY_OFF);
446 spin_unlock_irqrestore(sch->lock, flags);
449 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
451 struct chp_id *chpid = data;
453 __s390_subchannel_vary_chpid(sch, *chpid, 0);
457 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
459 struct chp_id *chpid = data;
461 __s390_subchannel_vary_chpid(sch, *chpid, 1);
466 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
470 if (stsch_err(schid, &schib))
473 /* Put it on the slow path. */
474 css_schedule_eval(schid);
479 * chsc_chp_vary - propagate channel-path vary operation to subchannels
480 * @chpid: channl-path ID
481 * @on: non-zero for vary online, zero for vary offline
483 int chsc_chp_vary(struct chp_id chpid, int on)
485 struct chp_link link;
487 memset(&link, 0, sizeof(struct chp_link));
489 /* Wait until previous actions have settled. */
490 css_wait_for_slow_path();
492 * Redo PathVerification on the devices the chpid connects to
496 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
497 __s390_vary_chpid_on, &link);
499 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
506 chsc_remove_cmg_attr(struct channel_subsystem *css)
510 for (i = 0; i <= __MAX_CHPID; i++) {
513 chp_remove_cmg_attr(css->chps[i]);
518 chsc_add_cmg_attr(struct channel_subsystem *css)
523 for (i = 0; i <= __MAX_CHPID; i++) {
526 ret = chp_add_cmg_attr(css->chps[i]);
532 for (--i; i >= 0; i--) {
535 chp_remove_cmg_attr(css->chps[i]);
541 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
544 struct chsc_header request;
545 u32 operation_code : 2;
554 struct chsc_header response;
559 } __attribute__ ((packed)) *secm_area;
563 secm_area->request.length = 0x0050;
564 secm_area->request.code = 0x0016;
566 secm_area->key = PAGE_DEFAULT_KEY;
567 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
568 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
570 secm_area->operation_code = enable ? 0 : 1;
572 ccode = chsc(secm_area);
574 return (ccode == 3) ? -ENODEV : -EBUSY;
576 switch (secm_area->response.code) {
581 ret = chsc_error_from_response(secm_area->response.code);
584 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
585 secm_area->response.code);
590 chsc_secm(struct channel_subsystem *css, int enable)
595 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
599 if (enable && !css->cm_enabled) {
600 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
601 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
602 if (!css->cub_addr1 || !css->cub_addr2) {
603 free_page((unsigned long)css->cub_addr1);
604 free_page((unsigned long)css->cub_addr2);
605 free_page((unsigned long)secm_area);
609 ret = __chsc_do_secm(css, enable, secm_area);
611 css->cm_enabled = enable;
612 if (css->cm_enabled) {
613 ret = chsc_add_cmg_attr(css);
615 memset(secm_area, 0, PAGE_SIZE);
616 __chsc_do_secm(css, 0, secm_area);
620 chsc_remove_cmg_attr(css);
622 if (!css->cm_enabled) {
623 free_page((unsigned long)css->cub_addr1);
624 free_page((unsigned long)css->cub_addr2);
626 free_page((unsigned long)secm_area);
630 int chsc_determine_channel_path_description(struct chp_id chpid,
631 struct channel_path_desc *desc)
636 struct chsc_header request;
642 struct chsc_header response;
644 struct channel_path_desc desc;
645 } __attribute__ ((packed)) *scpd_area;
647 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
651 scpd_area->request.length = 0x0010;
652 scpd_area->request.code = 0x0002;
654 scpd_area->first_chpid = chpid.id;
655 scpd_area->last_chpid = chpid.id;
657 ccode = chsc(scpd_area);
659 ret = (ccode == 3) ? -ENODEV : -EBUSY;
663 ret = chsc_error_from_response(scpd_area->response.code);
666 memcpy(desc, &scpd_area->desc,
667 sizeof(struct channel_path_desc));
669 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
670 scpd_area->response.code);
672 free_page((unsigned long)scpd_area);
677 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
678 struct cmg_chars *chars)
683 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
685 if (chp->cmg_chars) {
687 struct cmg_chars *cmg_chars;
689 cmg_chars = chp->cmg_chars;
690 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
691 mask = 0x80 >> (i + 3);
693 cmg_chars->values[i] = chars->values[i];
695 cmg_chars->values[i] = 0;
700 /* No cmg-dependent data. */
705 int chsc_get_channel_measurement_chars(struct channel_path *chp)
710 struct chsc_header request;
716 struct chsc_header response;
727 u32 data[NR_MEASUREMENT_CHARS];
728 } __attribute__ ((packed)) *scmc_area;
730 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
734 scmc_area->request.length = 0x0010;
735 scmc_area->request.code = 0x0022;
737 scmc_area->first_chpid = chp->chpid.id;
738 scmc_area->last_chpid = chp->chpid.id;
740 ccode = chsc(scmc_area);
742 ret = (ccode == 3) ? -ENODEV : -EBUSY;
746 ret = chsc_error_from_response(scmc_area->response.code);
749 if (!scmc_area->not_valid) {
750 chp->cmg = scmc_area->cmg;
751 chp->shared = scmc_area->shared;
752 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
760 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
761 scmc_area->response.code);
764 free_page((unsigned long)scmc_area);
768 int __init chsc_alloc_sei_area(void)
772 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
774 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
775 "chsc machine checks!\n");
778 ret = s390_register_crw_handler(CRW_RSC_CSS, chsc_process_crw);
784 void __init chsc_free_sei_area(void)
786 s390_unregister_crw_handler(CRW_RSC_CSS);
791 chsc_enable_facility(int operation_code)
795 struct chsc_header request;
802 u32 operation_data_area[252];
803 struct chsc_header response;
807 } __attribute__ ((packed)) *sda_area;
809 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
812 sda_area->request.length = 0x0400;
813 sda_area->request.code = 0x0031;
814 sda_area->operation_code = operation_code;
816 ret = chsc(sda_area);
818 ret = (ret == 3) ? -ENODEV : -EBUSY;
822 switch (sda_area->response.code) {
827 ret = chsc_error_from_response(sda_area->response.code);
830 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
831 operation_code, sda_area->response.code);
833 free_page((unsigned long)sda_area);
837 struct css_general_char css_general_characteristics;
838 struct css_chsc_char css_chsc_characteristics;
841 chsc_determine_css_characteristics(void)
845 struct chsc_header request;
849 struct chsc_header response;
851 u32 general_char[510];
853 } __attribute__ ((packed)) *scsc_area;
855 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
859 scsc_area->request.length = 0x0010;
860 scsc_area->request.code = 0x0010;
862 result = chsc(scsc_area);
864 result = (result == 3) ? -ENODEV : -EBUSY;
868 result = chsc_error_from_response(scsc_area->response.code);
870 memcpy(&css_general_characteristics, scsc_area->general_char,
871 sizeof(css_general_characteristics));
872 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
873 sizeof(css_chsc_characteristics));
875 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
876 scsc_area->response.code);
878 free_page ((unsigned long) scsc_area);
882 EXPORT_SYMBOL_GPL(css_general_characteristics);
883 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
885 int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
888 struct chsc_header request;
891 unsigned int rsvd1 : 8;
892 unsigned int ctrl : 16;
893 unsigned int rsvd2[5];
894 struct chsc_header response;
895 unsigned int rsvd3[7];
896 } __attribute__ ((packed)) *rr;
899 memset(page, 0, PAGE_SIZE);
901 rr->request.length = 0x0020;
902 rr->request.code = 0x0033;
908 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
912 int chsc_sstpi(void *page, void *result, size_t size)
915 struct chsc_header request;
916 unsigned int rsvd0[3];
917 struct chsc_header response;
919 } __attribute__ ((packed)) *rr;
922 memset(page, 0, PAGE_SIZE);
924 rr->request.length = 0x0010;
925 rr->request.code = 0x0038;
929 memcpy(result, &rr->data, size);
930 return (rr->response.code == 0x0001) ? 0 : -EIO;