2 * Channel subsystem base support.
4 * Copyright 2012 IBM Corp.
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
12 #include "qemu/osdep.h"
14 #include "qemu/bitops.h"
15 #include "exec/address-spaces.h"
17 #include "hw/s390x/ioinst.h"
18 #include "hw/s390x/css.h"
20 #include "hw/s390x/s390_flic.h"
22 typedef struct CrwContainer {
24 QTAILQ_ENTRY(CrwContainer) sibling;
27 typedef struct ChpInfo {
33 typedef struct SubchSet {
34 SubchDev *sch[MAX_SCHID + 1];
35 unsigned long schids_used[BITS_TO_LONGS(MAX_SCHID + 1)];
36 unsigned long devnos_used[BITS_TO_LONGS(MAX_SCHID + 1)];
39 typedef struct CssImage {
40 SubchSet *sch_set[MAX_SSID + 1];
41 ChpInfo chpids[MAX_CHPID + 1];
44 typedef struct IoAdapter {
48 QTAILQ_ENTRY(IoAdapter) sibling;
51 typedef struct ChannelSubSys {
52 QTAILQ_HEAD(, CrwContainer) pending_crws;
60 CssImage *css[MAX_CSSID + 1];
61 uint8_t default_cssid;
62 QTAILQ_HEAD(, IoAdapter) io_adapters;
63 QTAILQ_HEAD(, IndAddr) indicator_addresses;
66 static ChannelSubSys channel_subsys = {
67 .pending_crws = QTAILQ_HEAD_INITIALIZER(channel_subsys.pending_crws),
72 .chnmon_active = false,
73 .io_adapters = QTAILQ_HEAD_INITIALIZER(channel_subsys.io_adapters),
74 .indicator_addresses =
75 QTAILQ_HEAD_INITIALIZER(channel_subsys.indicator_addresses),
78 IndAddr *get_indicator(hwaddr ind_addr, int len)
82 QTAILQ_FOREACH(indicator, &channel_subsys.indicator_addresses, sibling) {
83 if (indicator->addr == ind_addr) {
88 indicator = g_new0(IndAddr, 1);
89 indicator->addr = ind_addr;
91 indicator->refcnt = 1;
92 QTAILQ_INSERT_TAIL(&channel_subsys.indicator_addresses,
97 static int s390_io_adapter_map(AdapterInfo *adapter, uint64_t map_addr,
100 S390FLICState *fs = s390_get_flic();
101 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
103 return fsc->io_adapter_map(fs, adapter->adapter_id, map_addr, do_map);
106 void release_indicator(AdapterInfo *adapter, IndAddr *indicator)
108 assert(indicator->refcnt > 0);
110 if (indicator->refcnt > 0) {
113 QTAILQ_REMOVE(&channel_subsys.indicator_addresses, indicator, sibling);
114 if (indicator->map) {
115 s390_io_adapter_map(adapter, indicator->map, false);
120 int map_indicator(AdapterInfo *adapter, IndAddr *indicator)
124 if (indicator->map) {
125 return 0; /* already mapped is not an error */
127 indicator->map = indicator->addr;
128 ret = s390_io_adapter_map(adapter, indicator->map, true);
129 if ((ret != 0) && (ret != -ENOSYS)) {
139 int css_create_css_image(uint8_t cssid, bool default_image)
141 trace_css_new_image(cssid, default_image ? "(default)" : "");
142 if (cssid > MAX_CSSID) {
145 if (channel_subsys.css[cssid]) {
148 channel_subsys.css[cssid] = g_malloc0(sizeof(CssImage));
150 channel_subsys.default_cssid = cssid;
155 int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap,
156 bool maskable, uint32_t *id)
161 S390FLICState *fs = s390_get_flic();
162 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
165 QTAILQ_FOREACH(adapter, &channel_subsys.io_adapters, sibling) {
166 if ((adapter->type == type) && (adapter->isc == isc)) {
172 if (adapter->id >= *id) {
173 *id = adapter->id + 1;
179 adapter = g_new0(IoAdapter, 1);
180 ret = fsc->register_io_adapter(fs, *id, isc, swap, maskable);
184 adapter->type = type;
185 QTAILQ_INSERT_TAIL(&channel_subsys.io_adapters, adapter, sibling);
188 fprintf(stderr, "Unexpected error %d when registering adapter %d\n",
195 uint16_t css_build_subchannel_id(SubchDev *sch)
197 if (channel_subsys.max_cssid > 0) {
198 return (sch->cssid << 8) | (1 << 3) | (sch->ssid << 1) | 1;
200 return (sch->ssid << 1) | 1;
203 static void css_inject_io_interrupt(SubchDev *sch)
205 uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
207 trace_css_io_interrupt(sch->cssid, sch->ssid, sch->schid,
208 sch->curr_status.pmcw.intparm, isc, "");
209 s390_io_interrupt(css_build_subchannel_id(sch),
211 sch->curr_status.pmcw.intparm,
215 void css_conditional_io_interrupt(SubchDev *sch)
218 * If the subchannel is not currently status pending, make it pending
221 if (!(sch->curr_status.scsw.ctrl & SCSW_STCTL_STATUS_PEND)) {
222 uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
224 trace_css_io_interrupt(sch->cssid, sch->ssid, sch->schid,
225 sch->curr_status.pmcw.intparm, isc,
227 sch->curr_status.scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL;
228 sch->curr_status.scsw.ctrl |=
229 SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
230 /* Inject an I/O interrupt. */
231 s390_io_interrupt(css_build_subchannel_id(sch),
233 sch->curr_status.pmcw.intparm,
238 void css_adapter_interrupt(uint8_t isc)
240 uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
242 trace_css_adapter_interrupt(isc);
243 s390_io_interrupt(0, 0, 0, io_int_word);
246 static void sch_handle_clear_func(SubchDev *sch)
248 PMCW *p = &sch->curr_status.pmcw;
249 SCSW *s = &sch->curr_status.scsw;
252 /* Path management: In our simple css, we always choose the only path. */
255 /* Reset values prior to 'issuing the clear signal'. */
258 s->flags &= ~SCSW_FLAGS_MASK_PNO;
260 /* We always 'attempt to issue the clear signal', and we always succeed. */
261 sch->channel_prog = 0x0;
262 sch->last_cmd_valid = false;
263 s->ctrl &= ~SCSW_ACTL_CLEAR_PEND;
264 s->ctrl |= SCSW_STCTL_STATUS_PEND;
272 static void sch_handle_halt_func(SubchDev *sch)
275 PMCW *p = &sch->curr_status.pmcw;
276 SCSW *s = &sch->curr_status.scsw;
277 hwaddr curr_ccw = sch->channel_prog;
280 /* Path management: In our simple css, we always choose the only path. */
283 /* We always 'attempt to issue the halt signal', and we always succeed. */
284 sch->channel_prog = 0x0;
285 sch->last_cmd_valid = false;
286 s->ctrl &= ~SCSW_ACTL_HALT_PEND;
287 s->ctrl |= SCSW_STCTL_STATUS_PEND;
289 if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) ||
290 !((s->ctrl & SCSW_ACTL_START_PEND) ||
291 (s->ctrl & SCSW_ACTL_SUSP))) {
292 s->dstat = SCSW_DSTAT_DEVICE_END;
294 if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) ||
295 (s->ctrl & SCSW_ACTL_SUSP)) {
296 s->cpa = curr_ccw + 8;
303 static void copy_sense_id_to_guest(SenseId *dest, SenseId *src)
307 dest->reserved = src->reserved;
308 dest->cu_type = cpu_to_be16(src->cu_type);
309 dest->cu_model = src->cu_model;
310 dest->dev_type = cpu_to_be16(src->dev_type);
311 dest->dev_model = src->dev_model;
312 dest->unused = src->unused;
313 for (i = 0; i < ARRAY_SIZE(dest->ciw); i++) {
314 dest->ciw[i].type = src->ciw[i].type;
315 dest->ciw[i].command = src->ciw[i].command;
316 dest->ciw[i].count = cpu_to_be16(src->ciw[i].count);
320 static CCW1 copy_ccw_from_guest(hwaddr addr, bool fmt1)
327 cpu_physical_memory_read(addr, &tmp1, sizeof(tmp1));
328 ret.cmd_code = tmp1.cmd_code;
329 ret.flags = tmp1.flags;
330 ret.count = be16_to_cpu(tmp1.count);
331 ret.cda = be32_to_cpu(tmp1.cda);
333 cpu_physical_memory_read(addr, &tmp0, sizeof(tmp0));
334 ret.cmd_code = tmp0.cmd_code;
335 ret.flags = tmp0.flags;
336 ret.count = be16_to_cpu(tmp0.count);
337 ret.cda = be16_to_cpu(tmp0.cda1) | (tmp0.cda0 << 16);
338 if ((ret.cmd_code & 0x0f) == CCW_CMD_TIC) {
339 ret.cmd_code &= 0x0f;
345 static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr,
346 bool suspend_allowed)
357 /* Translate everything to format-1 ccws - the information is the same. */
358 ccw = copy_ccw_from_guest(ccw_addr, sch->ccw_fmt_1);
360 /* Check for invalid command codes. */
361 if ((ccw.cmd_code & 0x0f) == 0) {
364 if (((ccw.cmd_code & 0x0f) == CCW_CMD_TIC) &&
365 ((ccw.cmd_code & 0xf0) != 0)) {
368 if (!sch->ccw_fmt_1 && (ccw.count == 0) &&
369 (ccw.cmd_code != CCW_CMD_TIC)) {
373 if (ccw.flags & CCW_FLAG_SUSPEND) {
374 return suspend_allowed ? -EINPROGRESS : -EINVAL;
377 check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
380 if (sch->ccw_no_data_cnt == 255) {
383 sch->ccw_no_data_cnt++;
386 /* Look at the command. */
387 switch (ccw.cmd_code) {
392 case CCW_CMD_BASIC_SENSE:
394 if (ccw.count != sizeof(sch->sense_data)) {
399 len = MIN(ccw.count, sizeof(sch->sense_data));
400 cpu_physical_memory_write(ccw.cda, sch->sense_data, len);
401 sch->curr_status.scsw.count = ccw.count - len;
402 memset(sch->sense_data, 0, sizeof(sch->sense_data));
405 case CCW_CMD_SENSE_ID:
409 copy_sense_id_to_guest(&sense_id, &sch->id);
410 /* Sense ID information is device specific. */
412 if (ccw.count != sizeof(sense_id)) {
417 len = MIN(ccw.count, sizeof(sense_id));
419 * Only indicate 0xff in the first sense byte if we actually
420 * have enough place to store at least bytes 0-3.
423 sense_id.reserved = 0xff;
425 sense_id.reserved = 0;
427 cpu_physical_memory_write(ccw.cda, &sense_id, len);
428 sch->curr_status.scsw.count = ccw.count - len;
433 if (sch->last_cmd_valid && (sch->last_cmd.cmd_code == CCW_CMD_TIC)) {
437 if (ccw.flags & (CCW_FLAG_CC | CCW_FLAG_DC)) {
441 sch->channel_prog = ccw.cda;
446 /* Handle device specific commands. */
447 ret = sch->ccw_cb(sch, ccw);
454 sch->last_cmd_valid = true;
456 if (ccw.flags & CCW_FLAG_CC) {
457 sch->channel_prog += 8;
465 static void sch_handle_start_func(SubchDev *sch, ORB *orb)
468 PMCW *p = &sch->curr_status.pmcw;
469 SCSW *s = &sch->curr_status.scsw;
472 bool suspend_allowed;
474 /* Path management: In our simple css, we always choose the only path. */
477 if (!(s->ctrl & SCSW_ACTL_SUSP)) {
480 /* Look at the orb and try to execute the channel program. */
481 assert(orb != NULL); /* resume does not pass an orb */
482 p->intparm = orb->intparm;
483 if (!(orb->lpm & path)) {
484 /* Generate a deferred cc 3 condition. */
485 s->flags |= SCSW_FLAGS_MASK_CC;
486 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
487 s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND);
490 sch->ccw_fmt_1 = !!(orb->ctrl0 & ORB_CTRL0_MASK_FMT);
491 sch->ccw_no_data_cnt = 0;
492 suspend_allowed = !!(orb->ctrl0 & ORB_CTRL0_MASK_SPND);
494 s->ctrl &= ~(SCSW_ACTL_SUSP | SCSW_ACTL_RESUME_PEND);
495 /* The channel program had been suspended before. */
496 suspend_allowed = true;
498 sch->last_cmd_valid = false;
500 ret = css_interpret_ccw(sch, sch->channel_prog, suspend_allowed);
503 /* ccw chain, continue processing */
507 s->ctrl &= ~SCSW_ACTL_START_PEND;
508 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
509 s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
510 SCSW_STCTL_STATUS_PEND;
511 s->dstat = SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END;
512 s->cpa = sch->channel_prog + 8;
515 /* unsupported command, generate unit check (command reject) */
516 s->ctrl &= ~SCSW_ACTL_START_PEND;
517 s->dstat = SCSW_DSTAT_UNIT_CHECK;
518 /* Set sense bit 0 in ecw0. */
519 sch->sense_data[0] = 0x80;
520 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
521 s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
522 SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
523 s->cpa = sch->channel_prog + 8;
526 /* memory problem, generate channel data check */
527 s->ctrl &= ~SCSW_ACTL_START_PEND;
528 s->cstat = SCSW_CSTAT_DATA_CHECK;
529 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
530 s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
531 SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
532 s->cpa = sch->channel_prog + 8;
535 /* subchannel busy, generate deferred cc 1 */
536 s->flags &= ~SCSW_FLAGS_MASK_CC;
537 s->flags |= (1 << 8);
538 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
539 s->ctrl |= SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
542 /* channel program has been suspended */
543 s->ctrl &= ~SCSW_ACTL_START_PEND;
544 s->ctrl |= SCSW_ACTL_SUSP;
547 /* error, generate channel program check */
548 s->ctrl &= ~SCSW_ACTL_START_PEND;
549 s->cstat = SCSW_CSTAT_PROG_CHECK;
550 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
551 s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
552 SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
553 s->cpa = sch->channel_prog + 8;
556 } while (ret == -EAGAIN);
561 * On real machines, this would run asynchronously to the main vcpus.
562 * We might want to make some parts of the ssch handling (interpreting
563 * read/writes) asynchronous later on if we start supporting more than
564 * our current very simple devices.
566 static void do_subchannel_work(SubchDev *sch, ORB *orb)
569 SCSW *s = &sch->curr_status.scsw;
571 if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) {
572 sch_handle_clear_func(sch);
573 } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) {
574 sch_handle_halt_func(sch);
575 } else if (s->ctrl & SCSW_FCTL_START_FUNC) {
576 sch_handle_start_func(sch, orb);
581 css_inject_io_interrupt(sch);
584 static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
588 dest->intparm = cpu_to_be32(src->intparm);
589 dest->flags = cpu_to_be16(src->flags);
590 dest->devno = cpu_to_be16(src->devno);
591 dest->lpm = src->lpm;
592 dest->pnom = src->pnom;
593 dest->lpum = src->lpum;
594 dest->pim = src->pim;
595 dest->mbi = cpu_to_be16(src->mbi);
596 dest->pom = src->pom;
597 dest->pam = src->pam;
598 for (i = 0; i < ARRAY_SIZE(dest->chpid); i++) {
599 dest->chpid[i] = src->chpid[i];
601 dest->chars = cpu_to_be32(src->chars);
604 static void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
606 dest->flags = cpu_to_be16(src->flags);
607 dest->ctrl = cpu_to_be16(src->ctrl);
608 dest->cpa = cpu_to_be32(src->cpa);
609 dest->dstat = src->dstat;
610 dest->cstat = src->cstat;
611 dest->count = cpu_to_be16(src->count);
614 static void copy_schib_to_guest(SCHIB *dest, const SCHIB *src)
618 copy_pmcw_to_guest(&dest->pmcw, &src->pmcw);
619 copy_scsw_to_guest(&dest->scsw, &src->scsw);
620 dest->mba = cpu_to_be64(src->mba);
621 for (i = 0; i < ARRAY_SIZE(dest->mda); i++) {
622 dest->mda[i] = src->mda[i];
626 int css_do_stsch(SubchDev *sch, SCHIB *schib)
628 /* Use current status. */
629 copy_schib_to_guest(schib, &sch->curr_status);
633 static void copy_pmcw_from_guest(PMCW *dest, const PMCW *src)
637 dest->intparm = be32_to_cpu(src->intparm);
638 dest->flags = be16_to_cpu(src->flags);
639 dest->devno = be16_to_cpu(src->devno);
640 dest->lpm = src->lpm;
641 dest->pnom = src->pnom;
642 dest->lpum = src->lpum;
643 dest->pim = src->pim;
644 dest->mbi = be16_to_cpu(src->mbi);
645 dest->pom = src->pom;
646 dest->pam = src->pam;
647 for (i = 0; i < ARRAY_SIZE(dest->chpid); i++) {
648 dest->chpid[i] = src->chpid[i];
650 dest->chars = be32_to_cpu(src->chars);
653 static void copy_scsw_from_guest(SCSW *dest, const SCSW *src)
655 dest->flags = be16_to_cpu(src->flags);
656 dest->ctrl = be16_to_cpu(src->ctrl);
657 dest->cpa = be32_to_cpu(src->cpa);
658 dest->dstat = src->dstat;
659 dest->cstat = src->cstat;
660 dest->count = be16_to_cpu(src->count);
663 static void copy_schib_from_guest(SCHIB *dest, const SCHIB *src)
667 copy_pmcw_from_guest(&dest->pmcw, &src->pmcw);
668 copy_scsw_from_guest(&dest->scsw, &src->scsw);
669 dest->mba = be64_to_cpu(src->mba);
670 for (i = 0; i < ARRAY_SIZE(dest->mda); i++) {
671 dest->mda[i] = src->mda[i];
675 int css_do_msch(SubchDev *sch, const SCHIB *orig_schib)
677 SCSW *s = &sch->curr_status.scsw;
678 PMCW *p = &sch->curr_status.pmcw;
683 if (!(sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_DNV)) {
688 if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
694 (SCSW_FCTL_START_FUNC|SCSW_FCTL_HALT_FUNC|SCSW_FCTL_CLEAR_FUNC)) {
699 copy_schib_from_guest(&schib, orig_schib);
700 /* Only update the program-modifiable fields. */
701 p->intparm = schib.pmcw.intparm;
703 p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
704 PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
706 p->flags |= schib.pmcw.flags &
707 (PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
708 PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
710 p->lpm = schib.pmcw.lpm;
711 p->mbi = schib.pmcw.mbi;
712 p->pom = schib.pmcw.pom;
713 p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE);
714 p->chars |= schib.pmcw.chars &
715 (PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE);
716 sch->curr_status.mba = schib.mba;
718 /* Has the channel been disabled? */
719 if (sch->disable_cb && (oldflags & PMCW_FLAGS_MASK_ENA) != 0
720 && (p->flags & PMCW_FLAGS_MASK_ENA) == 0) {
721 sch->disable_cb(sch);
730 int css_do_xsch(SubchDev *sch)
732 SCSW *s = &sch->curr_status.scsw;
733 PMCW *p = &sch->curr_status.pmcw;
736 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
741 if (!(s->ctrl & SCSW_CTRL_MASK_FCTL) ||
742 ((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) ||
744 (SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_SUSP))) ||
745 (s->ctrl & SCSW_ACTL_SUBCH_ACTIVE)) {
750 if (s->ctrl & SCSW_CTRL_MASK_STCTL) {
755 /* Cancel the current operation. */
756 s->ctrl &= ~(SCSW_FCTL_START_FUNC |
757 SCSW_ACTL_RESUME_PEND |
758 SCSW_ACTL_START_PEND |
760 sch->channel_prog = 0x0;
761 sch->last_cmd_valid = false;
770 int css_do_csch(SubchDev *sch)
772 SCSW *s = &sch->curr_status.scsw;
773 PMCW *p = &sch->curr_status.pmcw;
776 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
781 /* Trigger the clear function. */
782 s->ctrl &= ~(SCSW_CTRL_MASK_FCTL | SCSW_CTRL_MASK_ACTL);
783 s->ctrl |= SCSW_FCTL_CLEAR_FUNC | SCSW_ACTL_CLEAR_PEND;
785 do_subchannel_work(sch, NULL);
792 int css_do_hsch(SubchDev *sch)
794 SCSW *s = &sch->curr_status.scsw;
795 PMCW *p = &sch->curr_status.pmcw;
798 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
803 if (((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_STATUS_PEND) ||
804 (s->ctrl & (SCSW_STCTL_PRIMARY |
805 SCSW_STCTL_SECONDARY |
806 SCSW_STCTL_ALERT))) {
811 if (s->ctrl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
816 /* Trigger the halt function. */
817 s->ctrl |= SCSW_FCTL_HALT_FUNC;
818 s->ctrl &= ~SCSW_FCTL_START_FUNC;
819 if (((s->ctrl & SCSW_CTRL_MASK_ACTL) ==
820 (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) &&
821 ((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_INTERMEDIATE)) {
822 s->ctrl &= ~SCSW_STCTL_STATUS_PEND;
824 s->ctrl |= SCSW_ACTL_HALT_PEND;
826 do_subchannel_work(sch, NULL);
833 static void css_update_chnmon(SubchDev *sch)
835 if (!(sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_MME)) {
839 /* The counter is conveniently located at the beginning of the struct. */
840 if (sch->curr_status.pmcw.chars & PMCW_CHARS_MASK_MBFC) {
841 /* Format 1, per-subchannel area. */
844 count = address_space_ldl(&address_space_memory,
845 sch->curr_status.mba,
846 MEMTXATTRS_UNSPECIFIED,
849 address_space_stl(&address_space_memory, sch->curr_status.mba, count,
850 MEMTXATTRS_UNSPECIFIED, NULL);
852 /* Format 0, global area. */
856 offset = sch->curr_status.pmcw.mbi << 5;
857 count = address_space_lduw(&address_space_memory,
858 channel_subsys.chnmon_area + offset,
859 MEMTXATTRS_UNSPECIFIED,
862 address_space_stw(&address_space_memory,
863 channel_subsys.chnmon_area + offset, count,
864 MEMTXATTRS_UNSPECIFIED, NULL);
868 int css_do_ssch(SubchDev *sch, ORB *orb)
870 SCSW *s = &sch->curr_status.scsw;
871 PMCW *p = &sch->curr_status.pmcw;
874 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
879 if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
884 if (s->ctrl & (SCSW_FCTL_START_FUNC |
885 SCSW_FCTL_HALT_FUNC |
886 SCSW_FCTL_CLEAR_FUNC)) {
891 /* If monitoring is active, update counter. */
892 if (channel_subsys.chnmon_active) {
893 css_update_chnmon(sch);
895 sch->channel_prog = orb->cpa;
896 /* Trigger the start function. */
897 s->ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND);
898 s->flags &= ~SCSW_FLAGS_MASK_PNO;
900 do_subchannel_work(sch, orb);
907 static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw,
911 uint16_t stctl = src->scsw.ctrl & SCSW_CTRL_MASK_STCTL;
912 uint16_t actl = src->scsw.ctrl & SCSW_CTRL_MASK_ACTL;
914 copy_scsw_to_guest(&dest->scsw, &src->scsw);
916 for (i = 0; i < ARRAY_SIZE(dest->esw); i++) {
917 dest->esw[i] = cpu_to_be32(src->esw[i]);
919 for (i = 0; i < ARRAY_SIZE(dest->ecw); i++) {
920 dest->ecw[i] = cpu_to_be32(src->ecw[i]);
922 *irb_len = sizeof(*dest) - sizeof(dest->emw);
924 /* extended measurements enabled? */
925 if ((src->scsw.flags & SCSW_FLAGS_MASK_ESWF) ||
926 !(pmcw->flags & PMCW_FLAGS_MASK_TF) ||
927 !(pmcw->chars & PMCW_CHARS_MASK_XMWME)) {
930 /* extended measurements pending? */
931 if (!(stctl & SCSW_STCTL_STATUS_PEND)) {
934 if ((stctl & SCSW_STCTL_PRIMARY) ||
935 (stctl == SCSW_STCTL_SECONDARY) ||
936 ((stctl & SCSW_STCTL_INTERMEDIATE) && (actl & SCSW_ACTL_SUSP))) {
937 for (i = 0; i < ARRAY_SIZE(dest->emw); i++) {
938 dest->emw[i] = cpu_to_be32(src->emw[i]);
941 *irb_len = sizeof(*dest);
944 int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len)
946 SCSW *s = &sch->curr_status.scsw;
947 PMCW *p = &sch->curr_status.pmcw;
951 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
955 stctl = s->ctrl & SCSW_CTRL_MASK_STCTL;
957 /* Prepare the irb for the guest. */
958 memset(&irb, 0, sizeof(IRB));
960 /* Copy scsw from current status. */
961 memcpy(&irb.scsw, s, sizeof(SCSW));
962 if (stctl & SCSW_STCTL_STATUS_PEND) {
963 if (s->cstat & (SCSW_CSTAT_DATA_CHECK |
964 SCSW_CSTAT_CHN_CTRL_CHK |
965 SCSW_CSTAT_INTF_CTRL_CHK)) {
966 irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF;
967 irb.esw[0] = 0x04804000;
969 irb.esw[0] = 0x00800000;
971 /* If a unit check is pending, copy sense data. */
972 if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) &&
973 (p->chars & PMCW_CHARS_MASK_CSENSE)) {
976 irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF | SCSW_FLAGS_MASK_ECTL;
977 /* Attention: sense_data is already BE! */
978 memcpy(irb.ecw, sch->sense_data, sizeof(sch->sense_data));
979 for (i = 0; i < ARRAY_SIZE(irb.ecw); i++) {
980 irb.ecw[i] = be32_to_cpu(irb.ecw[i]);
982 irb.esw[1] = 0x01000000 | (sizeof(sch->sense_data) << 8);
985 /* Store the irb to the guest. */
986 copy_irb_to_guest(target_irb, &irb, p, irb_len);
988 return ((stctl & SCSW_STCTL_STATUS_PEND) == 0);
991 void css_do_tsch_update_subch(SubchDev *sch)
993 SCSW *s = &sch->curr_status.scsw;
994 PMCW *p = &sch->curr_status.pmcw;
999 stctl = s->ctrl & SCSW_CTRL_MASK_STCTL;
1000 fctl = s->ctrl & SCSW_CTRL_MASK_FCTL;
1001 actl = s->ctrl & SCSW_CTRL_MASK_ACTL;
1003 /* Clear conditions on subchannel, if applicable. */
1004 if (stctl & SCSW_STCTL_STATUS_PEND) {
1005 s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
1006 if ((stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) ||
1007 ((fctl & SCSW_FCTL_HALT_FUNC) &&
1008 (actl & SCSW_ACTL_SUSP))) {
1009 s->ctrl &= ~SCSW_CTRL_MASK_FCTL;
1011 if (stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) {
1012 s->flags &= ~SCSW_FLAGS_MASK_PNO;
1013 s->ctrl &= ~(SCSW_ACTL_RESUME_PEND |
1014 SCSW_ACTL_START_PEND |
1015 SCSW_ACTL_HALT_PEND |
1016 SCSW_ACTL_CLEAR_PEND |
1019 if ((actl & SCSW_ACTL_SUSP) &&
1020 (fctl & SCSW_FCTL_START_FUNC)) {
1021 s->flags &= ~SCSW_FLAGS_MASK_PNO;
1022 if (fctl & SCSW_FCTL_HALT_FUNC) {
1023 s->ctrl &= ~(SCSW_ACTL_RESUME_PEND |
1024 SCSW_ACTL_START_PEND |
1025 SCSW_ACTL_HALT_PEND |
1026 SCSW_ACTL_CLEAR_PEND |
1029 s->ctrl &= ~SCSW_ACTL_RESUME_PEND;
1033 /* Clear pending sense data. */
1034 if (p->chars & PMCW_CHARS_MASK_CSENSE) {
1035 memset(sch->sense_data, 0 , sizeof(sch->sense_data));
1040 static void copy_crw_to_guest(CRW *dest, const CRW *src)
1042 dest->flags = cpu_to_be16(src->flags);
1043 dest->rsid = cpu_to_be16(src->rsid);
1046 int css_do_stcrw(CRW *crw)
1048 CrwContainer *crw_cont;
1051 crw_cont = QTAILQ_FIRST(&channel_subsys.pending_crws);
1053 QTAILQ_REMOVE(&channel_subsys.pending_crws, crw_cont, sibling);
1054 copy_crw_to_guest(crw, &crw_cont->crw);
1058 /* List was empty, turn crw machine checks on again. */
1059 memset(crw, 0, sizeof(*crw));
1060 channel_subsys.do_crw_mchk = true;
1067 static void copy_crw_from_guest(CRW *dest, const CRW *src)
1069 dest->flags = be16_to_cpu(src->flags);
1070 dest->rsid = be16_to_cpu(src->rsid);
1073 void css_undo_stcrw(CRW *crw)
1075 CrwContainer *crw_cont;
1077 crw_cont = g_try_malloc0(sizeof(CrwContainer));
1079 channel_subsys.crws_lost = true;
1082 copy_crw_from_guest(&crw_cont->crw, crw);
1084 QTAILQ_INSERT_HEAD(&channel_subsys.pending_crws, crw_cont, sibling);
1087 int css_do_tpi(IOIntCode *int_code, int lowcore)
1089 /* No pending interrupts for !KVM. */
1093 int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
1094 int rfmt, void *buf)
1098 uint32_t chpid_type_word;
1102 css = channel_subsys.css[channel_subsys.default_cssid];
1104 css = channel_subsys.css[cssid];
1110 for (i = f_chpid; i <= l_chpid; i++) {
1111 if (css->chpids[i].in_use) {
1112 chpid_type_word = 0x80000000 | (css->chpids[i].type << 8) | i;
1114 words[0] = cpu_to_be32(chpid_type_word);
1116 memcpy(buf + desc_size, words, 8);
1118 } else if (rfmt == 1) {
1119 words[0] = cpu_to_be32(chpid_type_word);
1127 memcpy(buf + desc_size, words, 32);
1135 void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo)
1137 /* dct is currently ignored (not really meaningful for our devices) */
1138 /* TODO: Don't ignore mbk. */
1139 if (update && !channel_subsys.chnmon_active) {
1140 /* Enable measuring. */
1141 channel_subsys.chnmon_area = mbo;
1142 channel_subsys.chnmon_active = true;
1144 if (!update && channel_subsys.chnmon_active) {
1145 /* Disable measuring. */
1146 channel_subsys.chnmon_area = 0;
1147 channel_subsys.chnmon_active = false;
1151 int css_do_rsch(SubchDev *sch)
1153 SCSW *s = &sch->curr_status.scsw;
1154 PMCW *p = &sch->curr_status.pmcw;
1157 if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
1162 if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
1167 if (((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) ||
1168 (s->ctrl & SCSW_ACTL_RESUME_PEND) ||
1169 (!(s->ctrl & SCSW_ACTL_SUSP))) {
1174 /* If monitoring is active, update counter. */
1175 if (channel_subsys.chnmon_active) {
1176 css_update_chnmon(sch);
1179 s->ctrl |= SCSW_ACTL_RESUME_PEND;
1180 do_subchannel_work(sch, NULL);
1187 int css_do_rchp(uint8_t cssid, uint8_t chpid)
1191 if (cssid > channel_subsys.max_cssid) {
1194 if (channel_subsys.max_cssid == 0) {
1195 real_cssid = channel_subsys.default_cssid;
1199 if (!channel_subsys.css[real_cssid]) {
1203 if (!channel_subsys.css[real_cssid]->chpids[chpid].in_use) {
1207 if (!channel_subsys.css[real_cssid]->chpids[chpid].is_virtual) {
1209 "rchp unsupported for non-virtual chpid %x.%02x!\n",
1214 /* We don't really use a channel path, so we're done here. */
1215 css_queue_crw(CRW_RSC_CHP, CRW_ERC_INIT,
1216 channel_subsys.max_cssid > 0 ? 1 : 0, chpid);
1217 if (channel_subsys.max_cssid > 0) {
1218 css_queue_crw(CRW_RSC_CHP, CRW_ERC_INIT, 0, real_cssid << 8);
1223 bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid)
1228 real_cssid = (!m && (cssid == 0)) ? channel_subsys.default_cssid : cssid;
1229 if (real_cssid > MAX_CSSID || ssid > MAX_SSID ||
1230 !channel_subsys.css[real_cssid] ||
1231 !channel_subsys.css[real_cssid]->sch_set[ssid]) {
1234 set = channel_subsys.css[real_cssid]->sch_set[ssid];
1235 return schid > find_last_bit(set->schids_used,
1236 (MAX_SCHID + 1) / sizeof(unsigned long));
1239 static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
1243 trace_css_chpid_add(cssid, chpid, type);
1244 if (cssid > MAX_CSSID) {
1247 css = channel_subsys.css[cssid];
1251 if (css->chpids[chpid].in_use) {
1254 css->chpids[chpid].in_use = 1;
1255 css->chpids[chpid].type = type;
1256 css->chpids[chpid].is_virtual = 1;
1258 css_generate_chp_crws(cssid, chpid);
1263 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type)
1265 PMCW *p = &sch->curr_status.pmcw;
1266 SCSW *s = &sch->curr_status.scsw;
1268 CssImage *css = channel_subsys.css[sch->cssid];
1270 assert(css != NULL);
1271 memset(p, 0, sizeof(PMCW));
1272 p->flags |= PMCW_FLAGS_MASK_DNV;
1273 p->devno = sch->devno;
1278 p->chpid[0] = chpid;
1279 if (!css->chpids[chpid].in_use) {
1280 css_add_virtual_chpid(sch->cssid, chpid, type);
1283 memset(s, 0, sizeof(SCSW));
1284 sch->curr_status.mba = 0;
1285 for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) {
1286 sch->curr_status.mda[i] = 0;
1290 SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid, uint16_t schid)
1294 real_cssid = (!m && (cssid == 0)) ? channel_subsys.default_cssid : cssid;
1296 if (!channel_subsys.css[real_cssid]) {
1300 if (!channel_subsys.css[real_cssid]->sch_set[ssid]) {
1304 return channel_subsys.css[real_cssid]->sch_set[ssid]->sch[schid];
1307 bool css_subch_visible(SubchDev *sch)
1309 if (sch->ssid > channel_subsys.max_ssid) {
1313 if (sch->cssid != channel_subsys.default_cssid) {
1314 return (channel_subsys.max_cssid > 0);
1320 bool css_present(uint8_t cssid)
1322 return (channel_subsys.css[cssid] != NULL);
1325 bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno)
1327 if (!channel_subsys.css[cssid]) {
1330 if (!channel_subsys.css[cssid]->sch_set[ssid]) {
1334 return !!test_bit(devno,
1335 channel_subsys.css[cssid]->sch_set[ssid]->devnos_used);
1338 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
1339 uint16_t devno, SubchDev *sch)
1344 trace_css_assign_subch(sch ? "assign" : "deassign", cssid, ssid, schid,
1346 if (!channel_subsys.css[cssid]) {
1348 "Suspicious call to %s (%x.%x.%04x) for non-existing css!\n",
1349 __func__, cssid, ssid, schid);
1352 css = channel_subsys.css[cssid];
1354 if (!css->sch_set[ssid]) {
1355 css->sch_set[ssid] = g_malloc0(sizeof(SubchSet));
1357 s_set = css->sch_set[ssid];
1359 s_set->sch[schid] = sch;
1361 set_bit(schid, s_set->schids_used);
1362 set_bit(devno, s_set->devnos_used);
1364 clear_bit(schid, s_set->schids_used);
1365 clear_bit(devno, s_set->devnos_used);
1369 void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid)
1371 CrwContainer *crw_cont;
1373 trace_css_crw(rsc, erc, rsid, chain ? "(chained)" : "");
1374 /* TODO: Maybe use a static crw pool? */
1375 crw_cont = g_try_malloc0(sizeof(CrwContainer));
1377 channel_subsys.crws_lost = true;
1380 crw_cont->crw.flags = (rsc << 8) | erc;
1382 crw_cont->crw.flags |= CRW_FLAGS_MASK_C;
1384 crw_cont->crw.rsid = rsid;
1385 if (channel_subsys.crws_lost) {
1386 crw_cont->crw.flags |= CRW_FLAGS_MASK_R;
1387 channel_subsys.crws_lost = false;
1390 QTAILQ_INSERT_TAIL(&channel_subsys.pending_crws, crw_cont, sibling);
1392 if (channel_subsys.do_crw_mchk) {
1393 channel_subsys.do_crw_mchk = false;
1394 /* Inject crw pending machine check. */
1399 void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid,
1400 int hotplugged, int add)
1402 uint8_t guest_cssid;
1405 if (add && !hotplugged) {
1408 if (channel_subsys.max_cssid == 0) {
1409 /* Default cssid shows up as 0. */
1410 guest_cssid = (cssid == channel_subsys.default_cssid) ? 0 : cssid;
1412 /* Show real cssid to the guest. */
1413 guest_cssid = cssid;
1416 * Only notify for higher subchannel sets/channel subsystems if the
1417 * guest has enabled it.
1419 if ((ssid > channel_subsys.max_ssid) ||
1420 (guest_cssid > channel_subsys.max_cssid) ||
1421 ((channel_subsys.max_cssid == 0) &&
1422 (cssid != channel_subsys.default_cssid))) {
1425 chain_crw = (channel_subsys.max_ssid > 0) ||
1426 (channel_subsys.max_cssid > 0);
1427 css_queue_crw(CRW_RSC_SUBCH, CRW_ERC_IPI, chain_crw ? 1 : 0, schid);
1429 css_queue_crw(CRW_RSC_SUBCH, CRW_ERC_IPI, 0,
1430 (guest_cssid << 8) | (ssid << 4));
1434 void css_generate_chp_crws(uint8_t cssid, uint8_t chpid)
1439 void css_generate_css_crws(uint8_t cssid)
1441 if (!channel_subsys.sei_pending) {
1442 css_queue_crw(CRW_RSC_CSS, 0, 0, cssid);
1444 channel_subsys.sei_pending = true;
1447 void css_clear_sei_pending(void)
1449 channel_subsys.sei_pending = false;
1452 int css_enable_mcsse(void)
1454 trace_css_enable_facility("mcsse");
1455 channel_subsys.max_cssid = MAX_CSSID;
1459 int css_enable_mss(void)
1461 trace_css_enable_facility("mss");
1462 channel_subsys.max_ssid = MAX_SSID;
1466 void subch_device_save(SubchDev *s, QEMUFile *f)
1470 qemu_put_byte(f, s->cssid);
1471 qemu_put_byte(f, s->ssid);
1472 qemu_put_be16(f, s->schid);
1473 qemu_put_be16(f, s->devno);
1474 qemu_put_byte(f, s->thinint_active);
1477 qemu_put_be32(f, s->curr_status.pmcw.intparm);
1478 qemu_put_be16(f, s->curr_status.pmcw.flags);
1479 qemu_put_be16(f, s->curr_status.pmcw.devno);
1480 qemu_put_byte(f, s->curr_status.pmcw.lpm);
1481 qemu_put_byte(f, s->curr_status.pmcw.pnom);
1482 qemu_put_byte(f, s->curr_status.pmcw.lpum);
1483 qemu_put_byte(f, s->curr_status.pmcw.pim);
1484 qemu_put_be16(f, s->curr_status.pmcw.mbi);
1485 qemu_put_byte(f, s->curr_status.pmcw.pom);
1486 qemu_put_byte(f, s->curr_status.pmcw.pam);
1487 qemu_put_buffer(f, s->curr_status.pmcw.chpid, 8);
1488 qemu_put_be32(f, s->curr_status.pmcw.chars);
1490 qemu_put_be16(f, s->curr_status.scsw.flags);
1491 qemu_put_be16(f, s->curr_status.scsw.ctrl);
1492 qemu_put_be32(f, s->curr_status.scsw.cpa);
1493 qemu_put_byte(f, s->curr_status.scsw.dstat);
1494 qemu_put_byte(f, s->curr_status.scsw.cstat);
1495 qemu_put_be16(f, s->curr_status.scsw.count);
1496 qemu_put_be64(f, s->curr_status.mba);
1497 qemu_put_buffer(f, s->curr_status.mda, 4);
1499 qemu_put_buffer(f, s->sense_data, 32);
1500 qemu_put_be64(f, s->channel_prog);
1502 qemu_put_byte(f, s->last_cmd.cmd_code);
1503 qemu_put_byte(f, s->last_cmd.flags);
1504 qemu_put_be16(f, s->last_cmd.count);
1505 qemu_put_be32(f, s->last_cmd.cda);
1506 qemu_put_byte(f, s->last_cmd_valid);
1507 qemu_put_byte(f, s->id.reserved);
1508 qemu_put_be16(f, s->id.cu_type);
1509 qemu_put_byte(f, s->id.cu_model);
1510 qemu_put_be16(f, s->id.dev_type);
1511 qemu_put_byte(f, s->id.dev_model);
1512 qemu_put_byte(f, s->id.unused);
1513 for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) {
1514 qemu_put_byte(f, s->id.ciw[i].type);
1515 qemu_put_byte(f, s->id.ciw[i].command);
1516 qemu_put_be16(f, s->id.ciw[i].count);
1518 qemu_put_byte(f, s->ccw_fmt_1);
1519 qemu_put_byte(f, s->ccw_no_data_cnt);
1522 int subch_device_load(SubchDev *s, QEMUFile *f)
1526 s->cssid = qemu_get_byte(f);
1527 s->ssid = qemu_get_byte(f);
1528 s->schid = qemu_get_be16(f);
1529 s->devno = qemu_get_be16(f);
1530 s->thinint_active = qemu_get_byte(f);
1533 s->curr_status.pmcw.intparm = qemu_get_be32(f);
1534 s->curr_status.pmcw.flags = qemu_get_be16(f);
1535 s->curr_status.pmcw.devno = qemu_get_be16(f);
1536 s->curr_status.pmcw.lpm = qemu_get_byte(f);
1537 s->curr_status.pmcw.pnom = qemu_get_byte(f);
1538 s->curr_status.pmcw.lpum = qemu_get_byte(f);
1539 s->curr_status.pmcw.pim = qemu_get_byte(f);
1540 s->curr_status.pmcw.mbi = qemu_get_be16(f);
1541 s->curr_status.pmcw.pom = qemu_get_byte(f);
1542 s->curr_status.pmcw.pam = qemu_get_byte(f);
1543 qemu_get_buffer(f, s->curr_status.pmcw.chpid, 8);
1544 s->curr_status.pmcw.chars = qemu_get_be32(f);
1546 s->curr_status.scsw.flags = qemu_get_be16(f);
1547 s->curr_status.scsw.ctrl = qemu_get_be16(f);
1548 s->curr_status.scsw.cpa = qemu_get_be32(f);
1549 s->curr_status.scsw.dstat = qemu_get_byte(f);
1550 s->curr_status.scsw.cstat = qemu_get_byte(f);
1551 s->curr_status.scsw.count = qemu_get_be16(f);
1552 s->curr_status.mba = qemu_get_be64(f);
1553 qemu_get_buffer(f, s->curr_status.mda, 4);
1555 qemu_get_buffer(f, s->sense_data, 32);
1556 s->channel_prog = qemu_get_be64(f);
1558 s->last_cmd.cmd_code = qemu_get_byte(f);
1559 s->last_cmd.flags = qemu_get_byte(f);
1560 s->last_cmd.count = qemu_get_be16(f);
1561 s->last_cmd.cda = qemu_get_be32(f);
1562 s->last_cmd_valid = qemu_get_byte(f);
1563 s->id.reserved = qemu_get_byte(f);
1564 s->id.cu_type = qemu_get_be16(f);
1565 s->id.cu_model = qemu_get_byte(f);
1566 s->id.dev_type = qemu_get_be16(f);
1567 s->id.dev_model = qemu_get_byte(f);
1568 s->id.unused = qemu_get_byte(f);
1569 for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) {
1570 s->id.ciw[i].type = qemu_get_byte(f);
1571 s->id.ciw[i].command = qemu_get_byte(f);
1572 s->id.ciw[i].count = qemu_get_be16(f);
1574 s->ccw_fmt_1 = qemu_get_byte(f);
1575 s->ccw_no_data_cnt = qemu_get_byte(f);
1577 * Hack alert. We don't migrate the channel subsystem status (no
1578 * device!), but we need to find out if the guest enabled mss/mcss-e.
1579 * If the subchannel is enabled, it certainly was able to access it,
1580 * so adjust the max_ssid/max_cssid values for relevant ssid/cssid
1581 * values. This is not watertight, but better than nothing.
1583 if (s->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA) {
1585 channel_subsys.max_ssid = MAX_SSID;
1587 if (s->cssid != channel_subsys.default_cssid) {
1588 channel_subsys.max_cssid = MAX_CSSID;
1594 void css_reset_sch(SubchDev *sch)
1596 PMCW *p = &sch->curr_status.pmcw;
1598 if ((p->flags & PMCW_FLAGS_MASK_ENA) != 0 && sch->disable_cb) {
1599 sch->disable_cb(sch);
1603 p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
1604 PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
1605 PMCW_FLAGS_MASK_MP | PMCW_FLAGS_MASK_TF);
1606 p->flags |= PMCW_FLAGS_MASK_DNV;
1607 p->devno = sch->devno;
1615 p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_XMWME |
1616 PMCW_CHARS_MASK_CSENSE);
1618 memset(&sch->curr_status.scsw, 0, sizeof(sch->curr_status.scsw));
1619 sch->curr_status.mba = 0;
1621 sch->channel_prog = 0x0;
1622 sch->last_cmd_valid = false;
1623 sch->thinint_active = false;
1626 void css_reset(void)
1628 CrwContainer *crw_cont;
1630 /* Clean up monitoring. */
1631 channel_subsys.chnmon_active = false;
1632 channel_subsys.chnmon_area = 0;
1634 /* Clear pending CRWs. */
1635 while ((crw_cont = QTAILQ_FIRST(&channel_subsys.pending_crws))) {
1636 QTAILQ_REMOVE(&channel_subsys.pending_crws, crw_cont, sibling);
1639 channel_subsys.sei_pending = false;
1640 channel_subsys.do_crw_mchk = true;
1641 channel_subsys.crws_lost = false;
1643 /* Reset maximum ids. */
1644 channel_subsys.max_cssid = 0;
1645 channel_subsys.max_ssid = 0;