xref: /openbmc/qemu/include/hw/s390x/css.h (revision 04e3aabd)
1 /*
2  * Channel subsystem structures and definitions.
3  *
4  * Copyright 2012 IBM Corp.
5  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6  *
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
9  * directory.
10  */
11 
12 #ifndef CSS_H
13 #define CSS_H
14 
15 #include "cpu.h"
16 #include "hw/s390x/adapter.h"
17 #include "hw/s390x/s390_flic.h"
18 #include "hw/s390x/ioinst.h"
19 #include "sysemu/kvm.h"
20 
21 /* Channel subsystem constants. */
22 #define MAX_DEVNO 65535
23 #define MAX_SCHID 65535
24 #define MAX_SSID 3
25 #define MAX_CSSID 255
26 #define MAX_CHPID 255
27 
28 #define MAX_ISC 7
29 
30 #define MAX_CIWS 62
31 
32 #define VIRTUAL_CSSID 0xfe
33 #define VIRTIO_CCW_CHPID 0   /* used by convention */
34 
35 typedef struct CIW {
36     uint8_t type;
37     uint8_t command;
38     uint16_t count;
39 } QEMU_PACKED CIW;
40 
41 typedef struct SenseId {
42     /* common part */
43     uint8_t reserved;        /* always 0x'FF' */
44     uint16_t cu_type;        /* control unit type */
45     uint8_t cu_model;        /* control unit model */
46     uint16_t dev_type;       /* device type */
47     uint8_t dev_model;       /* device model */
48     uint8_t unused;          /* padding byte */
49     /* extended part */
50     CIW ciw[MAX_CIWS];       /* variable # of CIWs */
51 } QEMU_PACKED SenseId;
52 
53 /* Channel measurements, from linux/drivers/s390/cio/cmf.c. */
54 typedef struct CMB {
55     uint16_t ssch_rsch_count;
56     uint16_t sample_count;
57     uint32_t device_connect_time;
58     uint32_t function_pending_time;
59     uint32_t device_disconnect_time;
60     uint32_t control_unit_queuing_time;
61     uint32_t device_active_only_time;
62     uint32_t reserved[2];
63 } QEMU_PACKED CMB;
64 
65 typedef struct CMBE {
66     uint32_t ssch_rsch_count;
67     uint32_t sample_count;
68     uint32_t device_connect_time;
69     uint32_t function_pending_time;
70     uint32_t device_disconnect_time;
71     uint32_t control_unit_queuing_time;
72     uint32_t device_active_only_time;
73     uint32_t device_busy_time;
74     uint32_t initial_command_response_time;
75     uint32_t reserved[7];
76 } QEMU_PACKED CMBE;
77 
78 typedef struct SubchDev SubchDev;
79 struct SubchDev {
80     /* channel-subsystem related things: */
81     uint8_t cssid;
82     uint8_t ssid;
83     uint16_t schid;
84     uint16_t devno;
85     SCHIB curr_status;
86     uint8_t sense_data[32];
87     hwaddr channel_prog;
88     CCW1 last_cmd;
89     bool last_cmd_valid;
90     bool ccw_fmt_1;
91     bool thinint_active;
92     uint8_t ccw_no_data_cnt;
93     uint16_t migrated_schid; /* used for missmatch detection */
94     ORB orb;
95     /* transport-provided data: */
96     int (*ccw_cb) (SubchDev *, CCW1);
97     void (*disable_cb)(SubchDev *);
98     int (*do_subchannel_work) (SubchDev *);
99     SenseId id;
100     void *driver_data;
101 };
102 
103 extern const VMStateDescription vmstate_subch_dev;
104 
105 /*
106  * Identify a device within the channel subsystem.
107  * Note that this can be used to identify either the subchannel or
108  * the attached I/O device, as there's always one I/O device per
109  * subchannel.
110  */
111 typedef struct CssDevId {
112     uint8_t cssid;
113     uint8_t ssid;
114     uint16_t devid;
115     bool valid;
116 } CssDevId;
117 
118 extern const PropertyInfo css_devid_propinfo;
119 
120 #define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
121     DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
122 
123 typedef struct IndAddr {
124     hwaddr addr;
125     uint64_t map;
126     unsigned long refcnt;
127     int32_t len;
128     QTAILQ_ENTRY(IndAddr) sibling;
129 } IndAddr;
130 
131 extern const VMStateDescription vmstate_ind_addr;
132 
133 #define VMSTATE_PTR_TO_IND_ADDR(_f, _s)                                   \
134     VMSTATE_STRUCT(_f, _s, 1, vmstate_ind_addr, IndAddr*)
135 
136 IndAddr *get_indicator(hwaddr ind_addr, int len);
137 void release_indicator(AdapterInfo *adapter, IndAddr *indicator);
138 int map_indicator(AdapterInfo *adapter, IndAddr *indicator);
139 
140 typedef SubchDev *(*css_subch_cb_func)(uint8_t m, uint8_t cssid, uint8_t ssid,
141                                        uint16_t schid);
142 int css_create_css_image(uint8_t cssid, bool default_image);
143 bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
144 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
145                       uint16_t devno, SubchDev *sch);
146 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
147 int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
148 unsigned int css_find_free_chpid(uint8_t cssid);
149 uint16_t css_build_subchannel_id(SubchDev *sch);
150 void copy_scsw_to_guest(SCSW *dest, const SCSW *src);
151 void css_inject_io_interrupt(SubchDev *sch);
152 void css_reset(void);
153 void css_reset_sch(SubchDev *sch);
154 void css_queue_crw(uint8_t rsc, uint8_t erc, int solicited,
155                    int chain, uint16_t rsid);
156 void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid,
157                            int hotplugged, int add);
158 void css_generate_chp_crws(uint8_t cssid, uint8_t chpid);
159 void css_generate_css_crws(uint8_t cssid);
160 void css_clear_sei_pending(void);
161 int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data);
162 int do_subchannel_work_virtual(SubchDev *sub);
163 int do_subchannel_work_passthrough(SubchDev *sub);
164 
165 typedef enum {
166     CSS_IO_ADAPTER_VIRTIO = 0,
167     CSS_IO_ADAPTER_PCI = 1,
168     CSS_IO_ADAPTER_TYPE_NUMS,
169 } CssIoAdapterType;
170 
171 void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc);
172 int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
173 uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
174 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
175                               uint8_t flags, Error **errp);
176 
177 #ifndef CONFIG_KVM
178 #define S390_ADAPTER_SUPPRESSIBLE 0x01
179 #else
180 #define S390_ADAPTER_SUPPRESSIBLE KVM_S390_ADAPTER_SUPPRESSIBLE
181 #endif
182 
183 #ifndef CONFIG_USER_ONLY
184 SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
185                          uint16_t schid);
186 bool css_subch_visible(SubchDev *sch);
187 void css_conditional_io_interrupt(SubchDev *sch);
188 int css_do_stsch(SubchDev *sch, SCHIB *schib);
189 bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid);
190 int css_do_msch(SubchDev *sch, const SCHIB *schib);
191 int css_do_xsch(SubchDev *sch);
192 int css_do_csch(SubchDev *sch);
193 int css_do_hsch(SubchDev *sch);
194 int css_do_ssch(SubchDev *sch, ORB *orb);
195 int css_do_tsch_get_irb(SubchDev *sch, IRB *irb, int *irb_len);
196 void css_do_tsch_update_subch(SubchDev *sch);
197 int css_do_stcrw(CRW *crw);
198 void css_undo_stcrw(CRW *crw);
199 int css_do_tpi(IOIntCode *int_code, int lowcore);
200 int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
201                          int rfmt, void *buf);
202 void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo);
203 int css_enable_mcsse(void);
204 int css_enable_mss(void);
205 int css_do_rsch(SubchDev *sch);
206 int css_do_rchp(uint8_t cssid, uint8_t chpid);
207 bool css_present(uint8_t cssid);
208 #endif
209 
210 extern const PropertyInfo css_devid_ro_propinfo;
211 
212 #define DEFINE_PROP_CSS_DEV_ID_RO(_n, _s, _f) \
213     DEFINE_PROP(_n, _s, _f, css_devid_ro_propinfo, CssDevId)
214 
215 /**
216  * Create a subchannel for the given bus id.
217  *
218  * If @p bus_id is valid, and @p squash_mcss is true, verify that it is
219  * not already in use in the default css, and find a free devno from the
220  * default css image for it.
221  * If @p bus_id is valid, and @p squash_mcss is false, verify that it is
222  * not already in use, and find a free devno for it.
223  * If @p bus_id is not valid, and if either @p squash_mcss or @p is_virtual
224  * is true, find a free subchannel id and device number across all
225  * subchannel sets from the default css image.
226  * If @p bus_id is not valid, and if both @p squash_mcss and @p is_virtual
227  * are false, find a non-full css image and find a free subchannel id and
228  * device number across all subchannel sets from it.
229  *
230  * If either of the former actions succeed, allocate a subchannel structure,
231  * initialise it with the bus id, subchannel id and device number, register
232  * it with the CSS and return it. Otherwise return NULL.
233  *
234  * The caller becomes owner of the returned subchannel structure and
235  * is responsible for unregistering and freeing it.
236  */
237 SubchDev *css_create_sch(CssDevId bus_id, bool is_virtual, bool squash_mcss,
238                          Error **errp);
239 
240 /** Turn on css migration */
241 void css_register_vmstate(void);
242 
243 #endif
244