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)
150 sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
151 CIO_TRACE_EVENT(2, dbf_txt);
153 if (chp_get_status(chpid) <= 0)
155 /* Wait until previous actions have settled. */
156 css_wait_for_slow_path();
157 for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &chpid);
160 static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
164 * We don't know the device yet, but since a path
165 * may be available now to the device we'll have
166 * to do recognition again.
167 * Since we don't have any idea about which chpid
168 * that beast may be on we'll have to do a stsch
169 * on all devices, grr...
171 if (stsch_err(schid, &schib))
175 /* Put it on the slow path. */
176 css_schedule_eval(schid);
180 static int __s390_process_res_acc(struct subchannel *sch, void *data)
182 spin_lock_irq(sch->lock);
183 if (sch->driver && sch->driver->chp_event)
184 sch->driver->chp_event(sch, data, CHP_ONLINE);
185 spin_unlock_irq(sch->lock);
190 static void s390_process_res_acc (struct res_acc_data *res_data)
194 sprintf(dbf_txt, "accpr%x.%02x", res_data->chpid.cssid,
196 CIO_TRACE_EVENT( 2, dbf_txt);
197 if (res_data->fla != 0) {
198 sprintf(dbf_txt, "fla%x", res_data->fla);
199 CIO_TRACE_EVENT( 2, dbf_txt);
201 /* Wait until previous actions have settled. */
202 css_wait_for_slow_path();
204 * I/O resources may have become accessible.
205 * Scan through all subchannels that may be concerned and
206 * do a validation on those.
207 * The more information we have (info), the less scanning
208 * will we have to do.
210 for_each_subchannel_staged(__s390_process_res_acc,
211 s390_process_res_acc_new_sch, res_data);
215 __get_chpid_from_lir(void *data)
221 /* incident-node descriptor */
223 /* attached-node descriptor */
225 /* incident-specific information */
227 } __attribute__ ((packed)) *lir;
231 /* NULL link incident record */
233 if (!(lir->indesc[0]&0xc0000000))
234 /* node descriptor not valid */
236 if (!(lir->indesc[0]&0x10000000))
237 /* don't handle device-type nodes - FIXME */
239 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
241 return (u16) (lir->indesc[0]&0x000000ff);
244 struct chsc_sei_area {
245 struct chsc_header request;
249 struct chsc_header response;
252 u8 vf; /* validity flags */
253 u8 rs; /* reporting source */
254 u8 cc; /* content code */
255 u16 fla; /* full link address */
256 u16 rsid; /* reporting source id */
259 u8 ccdf[4096 - 16 - 24]; /* content-code dependent field */
260 /* ccdf has to be big enough for a link-incident record */
261 } __attribute__ ((packed));
263 static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
268 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
269 sei_area->rs, sei_area->rsid);
270 if (sei_area->rs != 4)
272 id = __get_chpid_from_lir(sei_area->ccdf);
274 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
278 chsc_chp_offline(chpid);
282 static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
284 struct res_acc_data res_data;
288 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
289 "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
290 if (sei_area->rs != 4)
293 chpid.id = sei_area->rsid;
294 /* allocate a new channel path structure, if needed */
295 status = chp_get_status(chpid);
300 memset(&res_data, 0, sizeof(struct res_acc_data));
301 res_data.chpid = chpid;
302 if ((sei_area->vf & 0xc0) != 0) {
303 res_data.fla = sei_area->fla;
304 if ((sei_area->vf & 0xc0) == 0xc0)
305 /* full link address */
306 res_data.fla_mask = 0xffff;
309 res_data.fla_mask = 0xff00;
311 s390_process_res_acc(&res_data);
314 struct chp_config_data {
320 static void chsc_process_sei_chp_config(struct chsc_sei_area *sei_area)
322 struct chp_config_data *data;
326 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
327 if (sei_area->rs != 0)
329 data = (struct chp_config_data *) &(sei_area->ccdf);
331 for (num = 0; num <= __MAX_CHPID; num++) {
332 if (!chp_test_bit(data->map, num))
335 printk(KERN_WARNING "cio: processing configure event %d for "
336 "chpid %x.%02x\n", data->op, chpid.cssid, chpid.id);
339 chp_cfg_schedule(chpid, 1);
342 chp_cfg_schedule(chpid, 0);
345 chp_cfg_cancel_deconfigure(chpid);
351 static void chsc_process_sei(struct chsc_sei_area *sei_area)
353 /* Check if we might have lost some information. */
354 if (sei_area->flags & 0x40) {
355 CIO_CRW_EVENT(2, "chsc: event overflow\n");
356 css_schedule_eval_all();
358 /* which kind of information was stored? */
359 switch (sei_area->cc) {
360 case 1: /* link incident*/
361 chsc_process_sei_link_incident(sei_area);
363 case 2: /* i/o resource accessibiliy */
364 chsc_process_sei_res_acc(sei_area);
366 case 8: /* channel-path-configuration notification */
367 chsc_process_sei_chp_config(sei_area);
369 default: /* other stuff */
370 CIO_CRW_EVENT(4, "chsc: unhandled sei content code %d\n",
376 static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
378 struct chsc_sei_area *sei_area;
381 css_schedule_eval_all();
384 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
385 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
386 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
387 crw0->erc, crw0->rsid);
390 /* Access to sei_page is serialized through machine check handler
391 * thread, so no need for locking. */
394 CIO_TRACE_EVENT(2, "prcss");
396 memset(sei_area, 0, sizeof(*sei_area));
397 sei_area->request.length = 0x0010;
398 sei_area->request.code = 0x000e;
402 if (sei_area->response.code == 0x0001) {
403 CIO_CRW_EVENT(4, "chsc: sei successful\n");
404 chsc_process_sei(sei_area);
406 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x)\n",
407 sei_area->response.code);
410 } while (sei_area->flags & 0x80);
413 void chsc_chp_online(struct chp_id chpid)
416 struct res_acc_data res_data;
418 sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
419 CIO_TRACE_EVENT(2, dbf_txt);
421 if (chp_get_status(chpid) != 0) {
422 memset(&res_data, 0, sizeof(struct res_acc_data));
423 res_data.chpid = chpid;
424 /* Wait until previous actions have settled. */
425 css_wait_for_slow_path();
426 for_each_subchannel_staged(__s390_process_res_acc, NULL,
431 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
432 struct chp_id chpid, int on)
435 struct res_acc_data res_data;
437 memset(&res_data, 0, sizeof(struct res_acc_data));
438 res_data.chpid = chpid;
439 spin_lock_irqsave(sch->lock, flags);
440 if (sch->driver && sch->driver->chp_event)
441 sch->driver->chp_event(sch, &res_data,
442 on ? CHP_VARY_ON : CHP_VARY_OFF);
443 spin_unlock_irqrestore(sch->lock, flags);
446 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
448 struct chp_id *chpid = data;
450 __s390_subchannel_vary_chpid(sch, *chpid, 0);
454 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
456 struct chp_id *chpid = data;
458 __s390_subchannel_vary_chpid(sch, *chpid, 1);
463 __s390_vary_chpid_on(struct subchannel_id schid, void *data)
467 if (stsch_err(schid, &schib))
470 /* Put it on the slow path. */
471 css_schedule_eval(schid);
476 * chsc_chp_vary - propagate channel-path vary operation to subchannels
477 * @chpid: channl-path ID
478 * @on: non-zero for vary online, zero for vary offline
480 int chsc_chp_vary(struct chp_id chpid, int on)
482 /* Wait until previous actions have settled. */
483 css_wait_for_slow_path();
485 * Redo PathVerification on the devices the chpid connects to
489 for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
490 __s390_vary_chpid_on, &chpid);
492 for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
499 chsc_remove_cmg_attr(struct channel_subsystem *css)
503 for (i = 0; i <= __MAX_CHPID; i++) {
506 chp_remove_cmg_attr(css->chps[i]);
511 chsc_add_cmg_attr(struct channel_subsystem *css)
516 for (i = 0; i <= __MAX_CHPID; i++) {
519 ret = chp_add_cmg_attr(css->chps[i]);
525 for (--i; i >= 0; i--) {
528 chp_remove_cmg_attr(css->chps[i]);
534 __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
537 struct chsc_header request;
538 u32 operation_code : 2;
547 struct chsc_header response;
552 } __attribute__ ((packed)) *secm_area;
556 secm_area->request.length = 0x0050;
557 secm_area->request.code = 0x0016;
559 secm_area->key = PAGE_DEFAULT_KEY;
560 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
561 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
563 secm_area->operation_code = enable ? 0 : 1;
565 ccode = chsc(secm_area);
567 return (ccode == 3) ? -ENODEV : -EBUSY;
569 switch (secm_area->response.code) {
574 ret = chsc_error_from_response(secm_area->response.code);
577 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
578 secm_area->response.code);
583 chsc_secm(struct channel_subsystem *css, int enable)
588 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
592 if (enable && !css->cm_enabled) {
593 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
594 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
595 if (!css->cub_addr1 || !css->cub_addr2) {
596 free_page((unsigned long)css->cub_addr1);
597 free_page((unsigned long)css->cub_addr2);
598 free_page((unsigned long)secm_area);
602 ret = __chsc_do_secm(css, enable, secm_area);
604 css->cm_enabled = enable;
605 if (css->cm_enabled) {
606 ret = chsc_add_cmg_attr(css);
608 memset(secm_area, 0, PAGE_SIZE);
609 __chsc_do_secm(css, 0, secm_area);
613 chsc_remove_cmg_attr(css);
615 if (!css->cm_enabled) {
616 free_page((unsigned long)css->cub_addr1);
617 free_page((unsigned long)css->cub_addr2);
619 free_page((unsigned long)secm_area);
623 int chsc_determine_channel_path_description(struct chp_id chpid,
624 struct channel_path_desc *desc)
629 struct chsc_header request;
635 struct chsc_header response;
637 struct channel_path_desc desc;
638 } __attribute__ ((packed)) *scpd_area;
640 scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
644 scpd_area->request.length = 0x0010;
645 scpd_area->request.code = 0x0002;
647 scpd_area->first_chpid = chpid.id;
648 scpd_area->last_chpid = chpid.id;
650 ccode = chsc(scpd_area);
652 ret = (ccode == 3) ? -ENODEV : -EBUSY;
656 ret = chsc_error_from_response(scpd_area->response.code);
659 memcpy(desc, &scpd_area->desc,
660 sizeof(struct channel_path_desc));
662 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
663 scpd_area->response.code);
665 free_page((unsigned long)scpd_area);
670 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
671 struct cmg_chars *chars)
676 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
678 if (chp->cmg_chars) {
680 struct cmg_chars *cmg_chars;
682 cmg_chars = chp->cmg_chars;
683 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
684 mask = 0x80 >> (i + 3);
686 cmg_chars->values[i] = chars->values[i];
688 cmg_chars->values[i] = 0;
693 /* No cmg-dependent data. */
698 int chsc_get_channel_measurement_chars(struct channel_path *chp)
703 struct chsc_header request;
709 struct chsc_header response;
720 u32 data[NR_MEASUREMENT_CHARS];
721 } __attribute__ ((packed)) *scmc_area;
723 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
727 scmc_area->request.length = 0x0010;
728 scmc_area->request.code = 0x0022;
730 scmc_area->first_chpid = chp->chpid.id;
731 scmc_area->last_chpid = chp->chpid.id;
733 ccode = chsc(scmc_area);
735 ret = (ccode == 3) ? -ENODEV : -EBUSY;
739 ret = chsc_error_from_response(scmc_area->response.code);
742 if (!scmc_area->not_valid) {
743 chp->cmg = scmc_area->cmg;
744 chp->shared = scmc_area->shared;
745 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
753 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
754 scmc_area->response.code);
757 free_page((unsigned long)scmc_area);
761 int __init chsc_alloc_sei_area(void)
765 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
767 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
768 "chsc machine checks!\n");
771 ret = s390_register_crw_handler(CRW_RSC_CSS, chsc_process_crw);
777 void __init chsc_free_sei_area(void)
779 s390_unregister_crw_handler(CRW_RSC_CSS);
784 chsc_enable_facility(int operation_code)
788 struct chsc_header request;
795 u32 operation_data_area[252];
796 struct chsc_header response;
800 } __attribute__ ((packed)) *sda_area;
802 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
805 sda_area->request.length = 0x0400;
806 sda_area->request.code = 0x0031;
807 sda_area->operation_code = operation_code;
809 ret = chsc(sda_area);
811 ret = (ret == 3) ? -ENODEV : -EBUSY;
815 switch (sda_area->response.code) {
820 ret = chsc_error_from_response(sda_area->response.code);
823 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
824 operation_code, sda_area->response.code);
826 free_page((unsigned long)sda_area);
830 struct css_general_char css_general_characteristics;
831 struct css_chsc_char css_chsc_characteristics;
834 chsc_determine_css_characteristics(void)
838 struct chsc_header request;
842 struct chsc_header response;
844 u32 general_char[510];
846 } __attribute__ ((packed)) *scsc_area;
848 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
852 scsc_area->request.length = 0x0010;
853 scsc_area->request.code = 0x0010;
855 result = chsc(scsc_area);
857 result = (result == 3) ? -ENODEV : -EBUSY;
861 result = chsc_error_from_response(scsc_area->response.code);
863 memcpy(&css_general_characteristics, scsc_area->general_char,
864 sizeof(css_general_characteristics));
865 memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
866 sizeof(css_chsc_characteristics));
868 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
869 scsc_area->response.code);
871 free_page ((unsigned long) scsc_area);
875 EXPORT_SYMBOL_GPL(css_general_characteristics);
876 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
878 int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
881 struct chsc_header request;
884 unsigned int rsvd1 : 8;
885 unsigned int ctrl : 16;
886 unsigned int rsvd2[5];
887 struct chsc_header response;
888 unsigned int rsvd3[7];
889 } __attribute__ ((packed)) *rr;
892 memset(page, 0, PAGE_SIZE);
894 rr->request.length = 0x0020;
895 rr->request.code = 0x0033;
901 rc = (rr->response.code == 0x0001) ? 0 : -EIO;
905 int chsc_sstpi(void *page, void *result, size_t size)
908 struct chsc_header request;
909 unsigned int rsvd0[3];
910 struct chsc_header response;
912 } __attribute__ ((packed)) *rr;
915 memset(page, 0, PAGE_SIZE);
917 rr->request.length = 0x0010;
918 rr->request.code = 0x0038;
922 memcpy(result, &rr->data, size);
923 return (rr->response.code == 0x0001) ? 0 : -EIO;