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