css.h 7.4 KB

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