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_SCHID 65535 21 #define MAX_SSID 3 22 #define MAX_CSSID 254 /* 255 is reserved */ 23 #define MAX_CHPID 255 24 25 #define MAX_CIWS 62 26 27 typedef struct CIW { 28 uint8_t type; 29 uint8_t command; 30 uint16_t count; 31 } QEMU_PACKED CIW; 32 33 typedef struct SenseId { 34 /* common part */ 35 uint8_t reserved; /* always 0x'FF' */ 36 uint16_t cu_type; /* control unit type */ 37 uint8_t cu_model; /* control unit model */ 38 uint16_t dev_type; /* device type */ 39 uint8_t dev_model; /* device model */ 40 uint8_t unused; /* padding byte */ 41 /* extended part */ 42 CIW ciw[MAX_CIWS]; /* variable # of CIWs */ 43 } QEMU_PACKED SenseId; 44 45 /* Channel measurements, from linux/drivers/s390/cio/cmf.c. */ 46 typedef struct CMB { 47 uint16_t ssch_rsch_count; 48 uint16_t sample_count; 49 uint32_t device_connect_time; 50 uint32_t function_pending_time; 51 uint32_t device_disconnect_time; 52 uint32_t control_unit_queuing_time; 53 uint32_t device_active_only_time; 54 uint32_t reserved[2]; 55 } QEMU_PACKED CMB; 56 57 typedef struct CMBE { 58 uint32_t ssch_rsch_count; 59 uint32_t sample_count; 60 uint32_t device_connect_time; 61 uint32_t function_pending_time; 62 uint32_t device_disconnect_time; 63 uint32_t control_unit_queuing_time; 64 uint32_t device_active_only_time; 65 uint32_t device_busy_time; 66 uint32_t initial_command_response_time; 67 uint32_t reserved[7]; 68 } QEMU_PACKED CMBE; 69 70 typedef struct SubchDev SubchDev; 71 struct SubchDev { 72 /* channel-subsystem related things: */ 73 uint8_t cssid; 74 uint8_t ssid; 75 uint16_t schid; 76 uint16_t devno; 77 SCHIB curr_status; 78 uint8_t sense_data[32]; 79 hwaddr channel_prog; 80 CCW1 last_cmd; 81 bool last_cmd_valid; 82 bool ccw_fmt_1; 83 bool thinint_active; 84 uint8_t ccw_no_data_cnt; 85 /* transport-provided data: */ 86 int (*ccw_cb) (SubchDev *, CCW1); 87 void (*disable_cb)(SubchDev *); 88 SenseId id; 89 void *driver_data; 90 }; 91 92 typedef struct IndAddr { 93 hwaddr addr; 94 uint64_t map; 95 unsigned long refcnt; 96 int len; 97 QTAILQ_ENTRY(IndAddr) sibling; 98 } IndAddr; 99 100 IndAddr *get_indicator(hwaddr ind_addr, int len); 101 void release_indicator(AdapterInfo *adapter, IndAddr *indicator); 102 int map_indicator(AdapterInfo *adapter, IndAddr *indicator); 103 104 typedef SubchDev *(*css_subch_cb_func)(uint8_t m, uint8_t cssid, uint8_t ssid, 105 uint16_t schid); 106 void subch_device_save(SubchDev *s, QEMUFile *f); 107 int subch_device_load(SubchDev *s, QEMUFile *f); 108 int css_create_css_image(uint8_t cssid, bool default_image); 109 bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno); 110 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, 111 uint16_t devno, SubchDev *sch); 112 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type); 113 uint16_t css_build_subchannel_id(SubchDev *sch); 114 void css_reset(void); 115 void css_reset_sch(SubchDev *sch); 116 void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid); 117 void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid, 118 int hotplugged, int add); 119 void css_generate_chp_crws(uint8_t cssid, uint8_t chpid); 120 void css_generate_css_crws(uint8_t cssid); 121 void css_clear_sei_pending(void); 122 void css_adapter_interrupt(uint8_t isc); 123 124 #define CSS_IO_ADAPTER_VIRTIO 1 125 int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap, 126 bool maskable, uint32_t *id); 127 128 #ifndef CONFIG_USER_ONLY 129 SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid, 130 uint16_t schid); 131 bool css_subch_visible(SubchDev *sch); 132 void css_conditional_io_interrupt(SubchDev *sch); 133 int css_do_stsch(SubchDev *sch, SCHIB *schib); 134 bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid); 135 int css_do_msch(SubchDev *sch, const SCHIB *schib); 136 int css_do_xsch(SubchDev *sch); 137 int css_do_csch(SubchDev *sch); 138 int css_do_hsch(SubchDev *sch); 139 int css_do_ssch(SubchDev *sch, ORB *orb); 140 int css_do_tsch_get_irb(SubchDev *sch, IRB *irb, int *irb_len); 141 void css_do_tsch_update_subch(SubchDev *sch); 142 int css_do_stcrw(CRW *crw); 143 void css_undo_stcrw(CRW *crw); 144 int css_do_tpi(IOIntCode *int_code, int lowcore); 145 int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid, 146 int rfmt, void *buf); 147 void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo); 148 int css_enable_mcsse(void); 149 int css_enable_mss(void); 150 int css_do_rsch(SubchDev *sch); 151 int css_do_rchp(uint8_t cssid, uint8_t chpid); 152 bool css_present(uint8_t cssid); 153 #endif 154 /* 155 * Identify a device within the channel subsystem. 156 * Note that this can be used to identify either the subchannel or 157 * the attached I/O device, as there's always one I/O device per 158 * subchannel. 159 */ 160 typedef struct CssDevId { 161 uint8_t cssid; 162 uint8_t ssid; 163 uint16_t devid; 164 bool valid; 165 } CssDevId; 166 167 extern PropertyInfo css_devid_propinfo; 168 169 #define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \ 170 DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId) 171 172 #endif 173