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