2 * S/390 common I/O routines -- channel subsystem call
4 * Copyright IBM Corp. 1999,2012
5 * Author(s): Ingo Adlung (adlung@de.ibm.com)
6 * Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Arnd Bergmann (arndb@de.ibm.com)
10 #define KMSG_COMPONENT "cio"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
17 #include <linux/pci.h>
20 #include <asm/chpid.h>
27 #include "cio_debug.h"
32 static void *sei_page
;
33 static void *chsc_page
;
34 static DEFINE_SPINLOCK(chsc_page_lock
);
37 * chsc_error_from_response() - convert a chsc response to an error
38 * @response: chsc response code
40 * Returns an appropriate Linux error code for @response.
42 int chsc_error_from_response(int response
)
66 EXPORT_SYMBOL_GPL(chsc_error_from_response
);
68 struct chsc_ssd_area
{
69 struct chsc_header request
;
73 u16 f_sch
; /* first subchannel */
75 u16 l_sch
; /* last subchannel */
77 struct chsc_header response
;
81 u8 st
: 3; /* subchannel type */
83 u8 unit_addr
; /* unit address */
84 u16 devno
; /* device number */
87 u16 sch
; /* subchannel */
88 u8 chpid
[8]; /* chpids 0-7 */
89 u16 fla
[8]; /* full link addresses 0-7 */
90 } __attribute__ ((packed
));
92 int chsc_get_ssd_info(struct subchannel_id schid
, struct chsc_ssd_info
*ssd
)
94 struct chsc_ssd_area
*ssd_area
;
100 spin_lock_irq(&chsc_page_lock
);
101 memset(chsc_page
, 0, PAGE_SIZE
);
102 ssd_area
= chsc_page
;
103 ssd_area
->request
.length
= 0x0010;
104 ssd_area
->request
.code
= 0x0004;
105 ssd_area
->ssid
= schid
.ssid
;
106 ssd_area
->f_sch
= schid
.sch_no
;
107 ssd_area
->l_sch
= schid
.sch_no
;
109 ccode
= chsc(ssd_area
);
110 /* Check response. */
112 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
115 ret
= chsc_error_from_response(ssd_area
->response
.code
);
117 CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
118 schid
.ssid
, schid
.sch_no
,
119 ssd_area
->response
.code
);
122 if (!ssd_area
->sch_valid
) {
128 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
129 if ((ssd_area
->st
!= SUBCHANNEL_TYPE_IO
) &&
130 (ssd_area
->st
!= SUBCHANNEL_TYPE_MSG
))
132 ssd
->path_mask
= ssd_area
->path_mask
;
133 ssd
->fla_valid_mask
= ssd_area
->fla_valid_mask
;
134 for (i
= 0; i
< 8; i
++) {
136 if (ssd_area
->path_mask
& mask
) {
137 chp_id_init(&ssd
->chpid
[i
]);
138 ssd
->chpid
[i
].id
= ssd_area
->chpid
[i
];
140 if (ssd_area
->fla_valid_mask
& mask
)
141 ssd
->fla
[i
] = ssd_area
->fla
[i
];
144 spin_unlock_irq(&chsc_page_lock
);
149 * chsc_ssqd() - store subchannel QDIO data (SSQD)
150 * @schid: id of the subchannel on which SSQD is performed
151 * @ssqd: request and response block for SSQD
153 * Returns 0 on success.
155 int chsc_ssqd(struct subchannel_id schid
, struct chsc_ssqd_area
*ssqd
)
157 memset(ssqd
, 0, sizeof(*ssqd
));
158 ssqd
->request
.length
= 0x0010;
159 ssqd
->request
.code
= 0x0024;
160 ssqd
->first_sch
= schid
.sch_no
;
161 ssqd
->last_sch
= schid
.sch_no
;
162 ssqd
->ssid
= schid
.ssid
;
167 return chsc_error_from_response(ssqd
->response
.code
);
169 EXPORT_SYMBOL_GPL(chsc_ssqd
);
172 * chsc_sadc() - set adapter device controls (SADC)
173 * @schid: id of the subchannel on which SADC is performed
174 * @scssc: request and response block for SADC
175 * @summary_indicator_addr: summary indicator address
176 * @subchannel_indicator_addr: subchannel indicator address
178 * Returns 0 on success.
180 int chsc_sadc(struct subchannel_id schid
, struct chsc_scssc_area
*scssc
,
181 u64 summary_indicator_addr
, u64 subchannel_indicator_addr
)
183 memset(scssc
, 0, sizeof(*scssc
));
184 scssc
->request
.length
= 0x0fe0;
185 scssc
->request
.code
= 0x0021;
186 scssc
->operation_code
= 0;
188 scssc
->summary_indicator_addr
= summary_indicator_addr
;
189 scssc
->subchannel_indicator_addr
= subchannel_indicator_addr
;
191 scssc
->ks
= PAGE_DEFAULT_KEY
>> 4;
192 scssc
->kc
= PAGE_DEFAULT_KEY
>> 4;
193 scssc
->isc
= QDIO_AIRQ_ISC
;
194 scssc
->schid
= schid
;
196 /* enable the time delay disablement facility */
197 if (css_general_characteristics
.aif_tdd
)
198 scssc
->word_with_d_bit
= 0x10000000;
203 return chsc_error_from_response(scssc
->response
.code
);
205 EXPORT_SYMBOL_GPL(chsc_sadc
);
207 static int s390_subchannel_remove_chpid(struct subchannel
*sch
, void *data
)
209 spin_lock_irq(sch
->lock
);
210 if (sch
->driver
&& sch
->driver
->chp_event
)
211 if (sch
->driver
->chp_event(sch
, data
, CHP_OFFLINE
) != 0)
213 spin_unlock_irq(sch
->lock
);
218 spin_unlock_irq(sch
->lock
);
219 css_schedule_eval(sch
->schid
);
223 void chsc_chp_offline(struct chp_id chpid
)
226 struct chp_link link
;
228 sprintf(dbf_txt
, "chpr%x.%02x", chpid
.cssid
, chpid
.id
);
229 CIO_TRACE_EVENT(2, dbf_txt
);
231 if (chp_get_status(chpid
) <= 0)
233 memset(&link
, 0, sizeof(struct chp_link
));
235 /* Wait until previous actions have settled. */
236 css_wait_for_slow_path();
237 for_each_subchannel_staged(s390_subchannel_remove_chpid
, NULL
, &link
);
240 static int s390_process_res_acc_new_sch(struct subchannel_id schid
, void *data
)
244 * We don't know the device yet, but since a path
245 * may be available now to the device we'll have
246 * to do recognition again.
247 * Since we don't have any idea about which chpid
248 * that beast may be on we'll have to do a stsch
249 * on all devices, grr...
251 if (stsch_err(schid
, &schib
))
255 /* Put it on the slow path. */
256 css_schedule_eval(schid
);
260 static int __s390_process_res_acc(struct subchannel
*sch
, void *data
)
262 spin_lock_irq(sch
->lock
);
263 if (sch
->driver
&& sch
->driver
->chp_event
)
264 sch
->driver
->chp_event(sch
, data
, CHP_ONLINE
);
265 spin_unlock_irq(sch
->lock
);
270 static void s390_process_res_acc(struct chp_link
*link
)
274 sprintf(dbf_txt
, "accpr%x.%02x", link
->chpid
.cssid
,
276 CIO_TRACE_EVENT( 2, dbf_txt
);
277 if (link
->fla
!= 0) {
278 sprintf(dbf_txt
, "fla%x", link
->fla
);
279 CIO_TRACE_EVENT( 2, dbf_txt
);
281 /* Wait until previous actions have settled. */
282 css_wait_for_slow_path();
284 * I/O resources may have become accessible.
285 * Scan through all subchannels that may be concerned and
286 * do a validation on those.
287 * The more information we have (info), the less scanning
288 * will we have to do.
290 for_each_subchannel_staged(__s390_process_res_acc
,
291 s390_process_res_acc_new_sch
, link
);
295 __get_chpid_from_lir(void *data
)
301 /* incident-node descriptor */
303 /* attached-node descriptor */
305 /* incident-specific information */
307 } __attribute__ ((packed
)) *lir
;
311 /* NULL link incident record */
313 if (!(lir
->indesc
[0]&0xc0000000))
314 /* node descriptor not valid */
316 if (!(lir
->indesc
[0]&0x10000000))
317 /* don't handle device-type nodes - FIXME */
319 /* Byte 3 contains the chpid. Could also be CTCA, but we don't care */
321 return (u16
) (lir
->indesc
[0]&0x000000ff);
324 struct chsc_sei_nt0_area
{
326 u8 vf
; /* validity flags */
327 u8 rs
; /* reporting source */
328 u8 cc
; /* content code */
329 u16 fla
; /* full link address */
330 u16 rsid
; /* reporting source id */
333 /* ccdf has to be big enough for a link-incident record */
334 u8 ccdf
[PAGE_SIZE
- 24 - 16]; /* content-code dependent field */
337 struct chsc_sei_nt2_area
{
338 u8 flags
; /* p and v bit */
341 u8 cc
; /* content code */
343 u8 ccdf
[PAGE_SIZE
- 24 - 56]; /* content-code dependent field */
346 #define CHSC_SEI_NT0 (1ULL << 63)
347 #define CHSC_SEI_NT2 (1ULL << 61)
350 struct chsc_header request
;
352 u64 ntsm
; /* notification type mask */
353 struct chsc_header response
;
357 struct chsc_sei_nt0_area nt0_area
;
358 struct chsc_sei_nt2_area nt2_area
;
359 u8 nt_area
[PAGE_SIZE
- 24];
363 static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area
*sei_area
)
368 CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x)\n",
369 sei_area
->rs
, sei_area
->rsid
);
370 if (sei_area
->rs
!= 4)
372 id
= __get_chpid_from_lir(sei_area
->ccdf
);
374 CIO_CRW_EVENT(4, "chsc: link incident - invalid LIR\n");
378 chsc_chp_offline(chpid
);
382 static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area
*sei_area
)
384 struct chp_link link
;
388 CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
389 "rs_id=%04x)\n", sei_area
->rs
, sei_area
->rsid
);
390 if (sei_area
->rs
!= 4)
393 chpid
.id
= sei_area
->rsid
;
394 /* allocate a new channel path structure, if needed */
395 status
= chp_get_status(chpid
);
400 memset(&link
, 0, sizeof(struct chp_link
));
402 if ((sei_area
->vf
& 0xc0) != 0) {
403 link
.fla
= sei_area
->fla
;
404 if ((sei_area
->vf
& 0xc0) == 0xc0)
405 /* full link address */
406 link
.fla_mask
= 0xffff;
409 link
.fla_mask
= 0xff00;
411 s390_process_res_acc(&link
);
414 static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area
*sei_area
)
416 struct channel_path
*chp
;
421 CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
422 if (sei_area
->rs
!= 0)
424 data
= sei_area
->ccdf
;
426 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
427 if (!chp_test_bit(data
, num
))
431 CIO_CRW_EVENT(4, "Update information for channel path "
432 "%x.%02x\n", chpid
.cssid
, chpid
.id
);
433 chp
= chpid_to_chp(chpid
);
438 mutex_lock(&chp
->lock
);
439 chp_update_desc(chp
);
440 mutex_unlock(&chp
->lock
);
444 struct chp_config_data
{
450 static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area
*sei_area
)
452 struct chp_config_data
*data
;
455 char *events
[3] = {"configure", "deconfigure", "cancel deconfigure"};
457 CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
458 if (sei_area
->rs
!= 0)
460 data
= (struct chp_config_data
*) &(sei_area
->ccdf
);
462 for (num
= 0; num
<= __MAX_CHPID
; num
++) {
463 if (!chp_test_bit(data
->map
, num
))
466 pr_notice("Processing %s for channel path %x.%02x\n",
467 events
[data
->op
], chpid
.cssid
, chpid
.id
);
470 chp_cfg_schedule(chpid
, 1);
473 chp_cfg_schedule(chpid
, 0);
476 chp_cfg_cancel_deconfigure(chpid
);
482 static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area
*sei_area
)
486 CIO_CRW_EVENT(4, "chsc: scm change notification\n");
487 if (sei_area
->rs
!= 7)
490 ret
= scm_update_information();
492 CIO_CRW_EVENT(0, "chsc: updating change notification"
493 " failed (rc=%d).\n", ret
);
496 static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area
*sei_area
)
500 CIO_CRW_EVENT(4, "chsc: scm available information\n");
501 if (sei_area
->rs
!= 7)
504 ret
= scm_process_availability_information();
506 CIO_CRW_EVENT(0, "chsc: process availability information"
507 " failed (rc=%d).\n", ret
);
510 static void chsc_process_sei_nt2(struct chsc_sei_nt2_area
*sei_area
)
512 switch (sei_area
->cc
) {
514 zpci_event_error(sei_area
->ccdf
);
517 zpci_event_availability(sei_area
->ccdf
);
520 CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
526 static void chsc_process_sei_nt0(struct chsc_sei_nt0_area
*sei_area
)
528 /* which kind of information was stored? */
529 switch (sei_area
->cc
) {
530 case 1: /* link incident*/
531 chsc_process_sei_link_incident(sei_area
);
533 case 2: /* i/o resource accessibility */
534 chsc_process_sei_res_acc(sei_area
);
536 case 7: /* channel-path-availability information */
537 chsc_process_sei_chp_avail(sei_area
);
539 case 8: /* channel-path-configuration notification */
540 chsc_process_sei_chp_config(sei_area
);
542 case 12: /* scm change notification */
543 chsc_process_sei_scm_change(sei_area
);
545 case 14: /* scm available notification */
546 chsc_process_sei_scm_avail(sei_area
);
548 default: /* other stuff */
549 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
554 /* Check if we might have lost some information. */
555 if (sei_area
->flags
& 0x40) {
556 CIO_CRW_EVENT(2, "chsc: event overflow\n");
557 css_schedule_eval_all();
561 static void chsc_process_event_information(struct chsc_sei
*sei
, u64 ntsm
)
563 static int ntsm_unsupported
;
566 memset(sei
, 0, sizeof(*sei
));
567 sei
->request
.length
= 0x0010;
568 sei
->request
.code
= 0x000e;
569 if (!ntsm_unsupported
)
575 if (sei
->response
.code
!= 0x0001) {
576 CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x, ntsm=%llx)\n",
577 sei
->response
.code
, sei
->ntsm
);
579 if (sei
->response
.code
== 3 && sei
->ntsm
) {
580 /* Fallback for old firmware. */
581 ntsm_unsupported
= 1;
587 CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei
->nt
);
590 chsc_process_sei_nt0(&sei
->u
.nt0_area
);
593 chsc_process_sei_nt2(&sei
->u
.nt2_area
);
596 CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei
->nt
);
600 if (!(sei
->u
.nt0_area
.flags
& 0x80))
606 * Handle channel subsystem related CRWs.
607 * Use store event information to find out what's going on.
609 * Note: Access to sei_page is serialized through machine check handler
610 * thread, so no need for locking.
612 static void chsc_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
614 struct chsc_sei
*sei
= sei_page
;
617 css_schedule_eval_all();
620 CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
621 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
622 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
623 crw0
->erc
, crw0
->rsid
);
625 CIO_TRACE_EVENT(2, "prcss");
626 chsc_process_event_information(sei
, CHSC_SEI_NT0
| CHSC_SEI_NT2
);
629 void chsc_chp_online(struct chp_id chpid
)
632 struct chp_link link
;
634 sprintf(dbf_txt
, "cadd%x.%02x", chpid
.cssid
, chpid
.id
);
635 CIO_TRACE_EVENT(2, dbf_txt
);
637 if (chp_get_status(chpid
) != 0) {
638 memset(&link
, 0, sizeof(struct chp_link
));
640 /* Wait until previous actions have settled. */
641 css_wait_for_slow_path();
642 for_each_subchannel_staged(__s390_process_res_acc
, NULL
,
647 static void __s390_subchannel_vary_chpid(struct subchannel
*sch
,
648 struct chp_id chpid
, int on
)
651 struct chp_link link
;
653 memset(&link
, 0, sizeof(struct chp_link
));
655 spin_lock_irqsave(sch
->lock
, flags
);
656 if (sch
->driver
&& sch
->driver
->chp_event
)
657 sch
->driver
->chp_event(sch
, &link
,
658 on
? CHP_VARY_ON
: CHP_VARY_OFF
);
659 spin_unlock_irqrestore(sch
->lock
, flags
);
662 static int s390_subchannel_vary_chpid_off(struct subchannel
*sch
, void *data
)
664 struct chp_id
*chpid
= data
;
666 __s390_subchannel_vary_chpid(sch
, *chpid
, 0);
670 static int s390_subchannel_vary_chpid_on(struct subchannel
*sch
, void *data
)
672 struct chp_id
*chpid
= data
;
674 __s390_subchannel_vary_chpid(sch
, *chpid
, 1);
679 __s390_vary_chpid_on(struct subchannel_id schid
, void *data
)
683 if (stsch_err(schid
, &schib
))
686 /* Put it on the slow path. */
687 css_schedule_eval(schid
);
692 * chsc_chp_vary - propagate channel-path vary operation to subchannels
693 * @chpid: channl-path ID
694 * @on: non-zero for vary online, zero for vary offline
696 int chsc_chp_vary(struct chp_id chpid
, int on
)
698 struct channel_path
*chp
= chpid_to_chp(chpid
);
700 /* Wait until previous actions have settled. */
701 css_wait_for_slow_path();
703 * Redo PathVerification on the devices the chpid connects to
706 /* Try to update the channel path description. */
707 chp_update_desc(chp
);
708 for_each_subchannel_staged(s390_subchannel_vary_chpid_on
,
709 __s390_vary_chpid_on
, &chpid
);
711 for_each_subchannel_staged(s390_subchannel_vary_chpid_off
,
718 chsc_remove_cmg_attr(struct channel_subsystem
*css
)
722 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
725 chp_remove_cmg_attr(css
->chps
[i
]);
730 chsc_add_cmg_attr(struct channel_subsystem
*css
)
735 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
738 ret
= chp_add_cmg_attr(css
->chps
[i
]);
744 for (--i
; i
>= 0; i
--) {
747 chp_remove_cmg_attr(css
->chps
[i
]);
752 int __chsc_do_secm(struct channel_subsystem
*css
, int enable
)
755 struct chsc_header request
;
756 u32 operation_code
: 2;
765 struct chsc_header response
;
770 } __attribute__ ((packed
)) *secm_area
;
773 spin_lock_irq(&chsc_page_lock
);
774 memset(chsc_page
, 0, PAGE_SIZE
);
775 secm_area
= chsc_page
;
776 secm_area
->request
.length
= 0x0050;
777 secm_area
->request
.code
= 0x0016;
779 secm_area
->key
= PAGE_DEFAULT_KEY
>> 4;
780 secm_area
->cub_addr1
= (u64
)(unsigned long)css
->cub_addr1
;
781 secm_area
->cub_addr2
= (u64
)(unsigned long)css
->cub_addr2
;
783 secm_area
->operation_code
= enable
? 0 : 1;
785 ccode
= chsc(secm_area
);
787 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
791 switch (secm_area
->response
.code
) {
797 ret
= chsc_error_from_response(secm_area
->response
.code
);
800 CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
801 secm_area
->response
.code
);
803 spin_unlock_irq(&chsc_page_lock
);
808 chsc_secm(struct channel_subsystem
*css
, int enable
)
812 if (enable
&& !css
->cm_enabled
) {
813 css
->cub_addr1
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
814 css
->cub_addr2
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
815 if (!css
->cub_addr1
|| !css
->cub_addr2
) {
816 free_page((unsigned long)css
->cub_addr1
);
817 free_page((unsigned long)css
->cub_addr2
);
821 ret
= __chsc_do_secm(css
, enable
);
823 css
->cm_enabled
= enable
;
824 if (css
->cm_enabled
) {
825 ret
= chsc_add_cmg_attr(css
);
827 __chsc_do_secm(css
, 0);
831 chsc_remove_cmg_attr(css
);
833 if (!css
->cm_enabled
) {
834 free_page((unsigned long)css
->cub_addr1
);
835 free_page((unsigned long)css
->cub_addr2
);
840 int chsc_determine_channel_path_desc(struct chp_id chpid
, int fmt
, int rfmt
,
841 int c
, int m
, void *page
)
843 struct chsc_scpd
*scpd_area
;
846 if ((rfmt
== 1) && !css_general_characteristics
.fcs
)
848 if ((rfmt
== 2) && !css_general_characteristics
.cib
)
851 memset(page
, 0, PAGE_SIZE
);
853 scpd_area
->request
.length
= 0x0010;
854 scpd_area
->request
.code
= 0x0002;
855 scpd_area
->cssid
= chpid
.cssid
;
856 scpd_area
->first_chpid
= chpid
.id
;
857 scpd_area
->last_chpid
= chpid
.id
;
860 scpd_area
->fmt
= fmt
;
861 scpd_area
->rfmt
= rfmt
;
863 ccode
= chsc(scpd_area
);
865 return (ccode
== 3) ? -ENODEV
: -EBUSY
;
867 ret
= chsc_error_from_response(scpd_area
->response
.code
);
869 CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
870 scpd_area
->response
.code
);
873 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc
);
875 int chsc_determine_base_channel_path_desc(struct chp_id chpid
,
876 struct channel_path_desc
*desc
)
878 struct chsc_response_struct
*chsc_resp
;
879 struct chsc_scpd
*scpd_area
;
883 spin_lock_irqsave(&chsc_page_lock
, flags
);
884 scpd_area
= chsc_page
;
885 ret
= chsc_determine_channel_path_desc(chpid
, 0, 0, 0, 0, scpd_area
);
888 chsc_resp
= (void *)&scpd_area
->response
;
889 memcpy(desc
, &chsc_resp
->data
, sizeof(*desc
));
891 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
895 int chsc_determine_fmt1_channel_path_desc(struct chp_id chpid
,
896 struct channel_path_desc_fmt1
*desc
)
898 struct chsc_response_struct
*chsc_resp
;
899 struct chsc_scpd
*scpd_area
;
903 spin_lock_irqsave(&chsc_page_lock
, flags
);
904 scpd_area
= chsc_page
;
905 ret
= chsc_determine_channel_path_desc(chpid
, 0, 0, 1, 0, scpd_area
);
908 chsc_resp
= (void *)&scpd_area
->response
;
909 memcpy(desc
, &chsc_resp
->data
, sizeof(*desc
));
911 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
916 chsc_initialize_cmg_chars(struct channel_path
*chp
, u8 cmcv
,
917 struct cmg_chars
*chars
)
919 struct cmg_chars
*cmg_chars
;
922 cmg_chars
= chp
->cmg_chars
;
923 for (i
= 0; i
< NR_MEASUREMENT_CHARS
; i
++) {
924 mask
= 0x80 >> (i
+ 3);
926 cmg_chars
->values
[i
] = chars
->values
[i
];
928 cmg_chars
->values
[i
] = 0;
932 int chsc_get_channel_measurement_chars(struct channel_path
*chp
)
934 struct cmg_chars
*cmg_chars
;
938 struct chsc_header request
;
944 struct chsc_header response
;
955 u32 data
[NR_MEASUREMENT_CHARS
];
956 } __attribute__ ((packed
)) *scmc_area
;
958 chp
->cmg_chars
= NULL
;
959 cmg_chars
= kmalloc(sizeof(*cmg_chars
), GFP_KERNEL
);
963 spin_lock_irq(&chsc_page_lock
);
964 memset(chsc_page
, 0, PAGE_SIZE
);
965 scmc_area
= chsc_page
;
966 scmc_area
->request
.length
= 0x0010;
967 scmc_area
->request
.code
= 0x0022;
968 scmc_area
->first_chpid
= chp
->chpid
.id
;
969 scmc_area
->last_chpid
= chp
->chpid
.id
;
971 ccode
= chsc(scmc_area
);
973 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
977 ret
= chsc_error_from_response(scmc_area
->response
.code
);
979 CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
980 scmc_area
->response
.code
);
983 if (scmc_area
->not_valid
) {
988 chp
->cmg
= scmc_area
->cmg
;
989 chp
->shared
= scmc_area
->shared
;
990 if (chp
->cmg
!= 2 && chp
->cmg
!= 3) {
991 /* No cmg-dependent data. */
994 chp
->cmg_chars
= cmg_chars
;
995 chsc_initialize_cmg_chars(chp
, scmc_area
->cmcv
,
996 (struct cmg_chars
*) &scmc_area
->data
);
998 spin_unlock_irq(&chsc_page_lock
);
1005 int __init
chsc_init(void)
1009 sei_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1010 chsc_page
= (void *)get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
1011 if (!sei_page
|| !chsc_page
) {
1015 ret
= crw_register_handler(CRW_RSC_CSS
, chsc_process_crw
);
1020 free_page((unsigned long)chsc_page
);
1021 free_page((unsigned long)sei_page
);
1025 void __init
chsc_init_cleanup(void)
1027 crw_unregister_handler(CRW_RSC_CSS
);
1028 free_page((unsigned long)chsc_page
);
1029 free_page((unsigned long)sei_page
);
1032 int chsc_enable_facility(int operation_code
)
1034 unsigned long flags
;
1037 struct chsc_header request
;
1044 u32 operation_data_area
[252];
1045 struct chsc_header response
;
1049 } __attribute__ ((packed
)) *sda_area
;
1051 spin_lock_irqsave(&chsc_page_lock
, flags
);
1052 memset(chsc_page
, 0, PAGE_SIZE
);
1053 sda_area
= chsc_page
;
1054 sda_area
->request
.length
= 0x0400;
1055 sda_area
->request
.code
= 0x0031;
1056 sda_area
->operation_code
= operation_code
;
1058 ret
= chsc(sda_area
);
1060 ret
= (ret
== 3) ? -ENODEV
: -EBUSY
;
1064 switch (sda_area
->response
.code
) {
1069 ret
= chsc_error_from_response(sda_area
->response
.code
);
1072 CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1073 operation_code
, sda_area
->response
.code
);
1075 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1079 struct css_general_char css_general_characteristics
;
1080 struct css_chsc_char css_chsc_characteristics
;
1083 chsc_determine_css_characteristics(void)
1087 struct chsc_header request
;
1091 struct chsc_header response
;
1093 u32 general_char
[510];
1095 } __attribute__ ((packed
)) *scsc_area
;
1097 spin_lock_irq(&chsc_page_lock
);
1098 memset(chsc_page
, 0, PAGE_SIZE
);
1099 scsc_area
= chsc_page
;
1100 scsc_area
->request
.length
= 0x0010;
1101 scsc_area
->request
.code
= 0x0010;
1103 result
= chsc(scsc_area
);
1105 result
= (result
== 3) ? -ENODEV
: -EBUSY
;
1109 result
= chsc_error_from_response(scsc_area
->response
.code
);
1111 memcpy(&css_general_characteristics
, scsc_area
->general_char
,
1112 sizeof(css_general_characteristics
));
1113 memcpy(&css_chsc_characteristics
, scsc_area
->chsc_char
,
1114 sizeof(css_chsc_characteristics
));
1116 CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1117 scsc_area
->response
.code
);
1119 spin_unlock_irq(&chsc_page_lock
);
1123 EXPORT_SYMBOL_GPL(css_general_characteristics
);
1124 EXPORT_SYMBOL_GPL(css_chsc_characteristics
);
1126 int chsc_sstpc(void *page
, unsigned int op
, u16 ctrl
)
1129 struct chsc_header request
;
1131 unsigned int op
: 8;
1132 unsigned int rsvd1
: 8;
1133 unsigned int ctrl
: 16;
1134 unsigned int rsvd2
[5];
1135 struct chsc_header response
;
1136 unsigned int rsvd3
[7];
1137 } __attribute__ ((packed
)) *rr
;
1140 memset(page
, 0, PAGE_SIZE
);
1142 rr
->request
.length
= 0x0020;
1143 rr
->request
.code
= 0x0033;
1149 rc
= (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
1153 int chsc_sstpi(void *page
, void *result
, size_t size
)
1156 struct chsc_header request
;
1157 unsigned int rsvd0
[3];
1158 struct chsc_header response
;
1160 } __attribute__ ((packed
)) *rr
;
1163 memset(page
, 0, PAGE_SIZE
);
1165 rr
->request
.length
= 0x0010;
1166 rr
->request
.code
= 0x0038;
1170 memcpy(result
, &rr
->data
, size
);
1171 return (rr
->response
.code
== 0x0001) ? 0 : -EIO
;
1174 int chsc_siosl(struct subchannel_id schid
)
1177 struct chsc_header request
;
1179 struct subchannel_id sid
;
1181 struct chsc_header response
;
1183 } __attribute__ ((packed
)) *siosl_area
;
1184 unsigned long flags
;
1188 spin_lock_irqsave(&chsc_page_lock
, flags
);
1189 memset(chsc_page
, 0, PAGE_SIZE
);
1190 siosl_area
= chsc_page
;
1191 siosl_area
->request
.length
= 0x0010;
1192 siosl_area
->request
.code
= 0x0046;
1193 siosl_area
->word1
= 0x80000000;
1194 siosl_area
->sid
= schid
;
1196 ccode
= chsc(siosl_area
);
1202 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1203 schid
.ssid
, schid
.sch_no
, ccode
);
1206 rc
= chsc_error_from_response(siosl_area
->response
.code
);
1208 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1209 schid
.ssid
, schid
.sch_no
,
1210 siosl_area
->response
.code
);
1212 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1213 schid
.ssid
, schid
.sch_no
);
1215 spin_unlock_irqrestore(&chsc_page_lock
, flags
);
1218 EXPORT_SYMBOL_GPL(chsc_siosl
);
1221 * chsc_scm_info() - store SCM information (SSI)
1222 * @scm_area: request and response block for SSI
1223 * @token: continuation token
1225 * Returns 0 on success.
1227 int chsc_scm_info(struct chsc_scm_info
*scm_area
, u64 token
)
1231 memset(scm_area
, 0, sizeof(*scm_area
));
1232 scm_area
->request
.length
= 0x0020;
1233 scm_area
->request
.code
= 0x004C;
1234 scm_area
->reqtok
= token
;
1236 ccode
= chsc(scm_area
);
1238 ret
= (ccode
== 3) ? -ENODEV
: -EBUSY
;
1241 ret
= chsc_error_from_response(scm_area
->response
.code
);
1243 CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1244 scm_area
->response
.code
);
1248 EXPORT_SYMBOL_GPL(chsc_scm_info
);