18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef S390_CHSC_H
38c2ecf20Sopenharmony_ci#define S390_CHSC_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/types.h>
68c2ecf20Sopenharmony_ci#include <linux/device.h>
78c2ecf20Sopenharmony_ci#include <asm/css_chars.h>
88c2ecf20Sopenharmony_ci#include <asm/chpid.h>
98c2ecf20Sopenharmony_ci#include <asm/chsc.h>
108c2ecf20Sopenharmony_ci#include <asm/schid.h>
118c2ecf20Sopenharmony_ci#include <asm/qdio.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define CHSC_SDA_OC_MSS   0x2
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define NR_MEASUREMENT_CHARS 5
168c2ecf20Sopenharmony_cistruct cmg_chars {
178c2ecf20Sopenharmony_ci	u32 values[NR_MEASUREMENT_CHARS];
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define NR_MEASUREMENT_ENTRIES 8
218c2ecf20Sopenharmony_cistruct cmg_entry {
228c2ecf20Sopenharmony_ci	u32 values[NR_MEASUREMENT_ENTRIES];
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct channel_path_desc_fmt1 {
268c2ecf20Sopenharmony_ci	u8 flags;
278c2ecf20Sopenharmony_ci	u8 lsn;
288c2ecf20Sopenharmony_ci	u8 desc;
298c2ecf20Sopenharmony_ci	u8 chpid;
308c2ecf20Sopenharmony_ci	u32:24;
318c2ecf20Sopenharmony_ci	u8 chpp;
328c2ecf20Sopenharmony_ci	u32 unused[2];
338c2ecf20Sopenharmony_ci	u16 chid;
348c2ecf20Sopenharmony_ci	u32:16;
358c2ecf20Sopenharmony_ci	u16 mdc;
368c2ecf20Sopenharmony_ci	u16:13;
378c2ecf20Sopenharmony_ci	u8 r:1;
388c2ecf20Sopenharmony_ci	u8 s:1;
398c2ecf20Sopenharmony_ci	u8 f:1;
408c2ecf20Sopenharmony_ci	u32 zeros[2];
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct channel_path_desc_fmt3 {
448c2ecf20Sopenharmony_ci	struct channel_path_desc_fmt1 fmt1_desc;
458c2ecf20Sopenharmony_ci	u8 util_str[64];
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct channel_path;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct css_chsc_char {
518c2ecf20Sopenharmony_ci	u64 res;
528c2ecf20Sopenharmony_ci	u64 : 20;
538c2ecf20Sopenharmony_ci	u32 secm : 1; /* bit 84 */
548c2ecf20Sopenharmony_ci	u32 : 1;
558c2ecf20Sopenharmony_ci	u32 scmc : 1; /* bit 86 */
568c2ecf20Sopenharmony_ci	u32 : 20;
578c2ecf20Sopenharmony_ci	u32 scssc : 1;  /* bit 107 */
588c2ecf20Sopenharmony_ci	u32 scsscf : 1; /* bit 108 */
598c2ecf20Sopenharmony_ci	u32:7;
608c2ecf20Sopenharmony_ci	u32 pnso:1; /* bit 116 */
618c2ecf20Sopenharmony_ci	u32:11;
628c2ecf20Sopenharmony_ci} __packed;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciextern struct css_chsc_char css_chsc_characteristics;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistruct chsc_ssd_info {
678c2ecf20Sopenharmony_ci	u8 path_mask;
688c2ecf20Sopenharmony_ci	u8 fla_valid_mask;
698c2ecf20Sopenharmony_ci	struct chp_id chpid[8];
708c2ecf20Sopenharmony_ci	u16 fla[8];
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistruct chsc_ssqd_area {
748c2ecf20Sopenharmony_ci	struct chsc_header request;
758c2ecf20Sopenharmony_ci	u16:10;
768c2ecf20Sopenharmony_ci	u8 ssid:2;
778c2ecf20Sopenharmony_ci	u8 fmt:4;
788c2ecf20Sopenharmony_ci	u16 first_sch;
798c2ecf20Sopenharmony_ci	u16:16;
808c2ecf20Sopenharmony_ci	u16 last_sch;
818c2ecf20Sopenharmony_ci	u32:32;
828c2ecf20Sopenharmony_ci	struct chsc_header response;
838c2ecf20Sopenharmony_ci	u32:32;
848c2ecf20Sopenharmony_ci	struct qdio_ssqd_desc qdio_ssqd;
858c2ecf20Sopenharmony_ci} __packed __aligned(PAGE_SIZE);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistruct chsc_scssc_area {
888c2ecf20Sopenharmony_ci	struct chsc_header request;
898c2ecf20Sopenharmony_ci	u16 operation_code;
908c2ecf20Sopenharmony_ci	u16:16;
918c2ecf20Sopenharmony_ci	u32:32;
928c2ecf20Sopenharmony_ci	u32:32;
938c2ecf20Sopenharmony_ci	u64 summary_indicator_addr;
948c2ecf20Sopenharmony_ci	u64 subchannel_indicator_addr;
958c2ecf20Sopenharmony_ci	u32 ks:4;
968c2ecf20Sopenharmony_ci	u32 kc:4;
978c2ecf20Sopenharmony_ci	u32:21;
988c2ecf20Sopenharmony_ci	u32 isc:3;
998c2ecf20Sopenharmony_ci	u32 word_with_d_bit;
1008c2ecf20Sopenharmony_ci	u32:32;
1018c2ecf20Sopenharmony_ci	struct subchannel_id schid;
1028c2ecf20Sopenharmony_ci	u32 reserved[1004];
1038c2ecf20Sopenharmony_ci	struct chsc_header response;
1048c2ecf20Sopenharmony_ci	u32:32;
1058c2ecf20Sopenharmony_ci} __packed __aligned(PAGE_SIZE);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistruct chsc_scpd {
1088c2ecf20Sopenharmony_ci	struct chsc_header request;
1098c2ecf20Sopenharmony_ci	u32:2;
1108c2ecf20Sopenharmony_ci	u32 m:1;
1118c2ecf20Sopenharmony_ci	u32 c:1;
1128c2ecf20Sopenharmony_ci	u32 fmt:4;
1138c2ecf20Sopenharmony_ci	u32 cssid:8;
1148c2ecf20Sopenharmony_ci	u32:4;
1158c2ecf20Sopenharmony_ci	u32 rfmt:4;
1168c2ecf20Sopenharmony_ci	u32 first_chpid:8;
1178c2ecf20Sopenharmony_ci	u32:24;
1188c2ecf20Sopenharmony_ci	u32 last_chpid:8;
1198c2ecf20Sopenharmony_ci	u32 zeroes1;
1208c2ecf20Sopenharmony_ci	struct chsc_header response;
1218c2ecf20Sopenharmony_ci	u32:32;
1228c2ecf20Sopenharmony_ci	u8 data[0];
1238c2ecf20Sopenharmony_ci} __packed __aligned(PAGE_SIZE);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct chsc_sda_area {
1268c2ecf20Sopenharmony_ci	struct chsc_header request;
1278c2ecf20Sopenharmony_ci	u8 :4;
1288c2ecf20Sopenharmony_ci	u8 format:4;
1298c2ecf20Sopenharmony_ci	u8 :8;
1308c2ecf20Sopenharmony_ci	u16 operation_code;
1318c2ecf20Sopenharmony_ci	u32 :32;
1328c2ecf20Sopenharmony_ci	u32 :32;
1338c2ecf20Sopenharmony_ci	u32 operation_data_area[252];
1348c2ecf20Sopenharmony_ci	struct chsc_header response;
1358c2ecf20Sopenharmony_ci	u32 :4;
1368c2ecf20Sopenharmony_ci	u32 format2:4;
1378c2ecf20Sopenharmony_ci	u32 :24;
1388c2ecf20Sopenharmony_ci} __packed __aligned(PAGE_SIZE);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ciextern int chsc_get_ssd_info(struct subchannel_id schid,
1418c2ecf20Sopenharmony_ci			     struct chsc_ssd_info *ssd);
1428c2ecf20Sopenharmony_ciextern int chsc_determine_css_characteristics(void);
1438c2ecf20Sopenharmony_ciextern int chsc_init(void);
1448c2ecf20Sopenharmony_ciextern void chsc_init_cleanup(void);
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciint __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code);
1478c2ecf20Sopenharmony_ciextern int chsc_enable_facility(int);
1488c2ecf20Sopenharmony_cistruct channel_subsystem;
1498c2ecf20Sopenharmony_ciextern int chsc_secm(struct channel_subsystem *, int);
1508c2ecf20Sopenharmony_ciint __chsc_do_secm(struct channel_subsystem *css, int enable);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciint chsc_chp_vary(struct chp_id chpid, int on);
1538c2ecf20Sopenharmony_ciint chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
1548c2ecf20Sopenharmony_ci				     int c, int m, void *page);
1558c2ecf20Sopenharmony_ciint chsc_determine_fmt0_channel_path_desc(struct chp_id chpid,
1568c2ecf20Sopenharmony_ci					  struct channel_path_desc_fmt0 *desc);
1578c2ecf20Sopenharmony_ciint chsc_determine_fmt1_channel_path_desc(struct chp_id chpid,
1588c2ecf20Sopenharmony_ci					  struct channel_path_desc_fmt1 *desc);
1598c2ecf20Sopenharmony_ciint chsc_determine_fmt3_channel_path_desc(struct chp_id chpid,
1608c2ecf20Sopenharmony_ci					  struct channel_path_desc_fmt3 *desc);
1618c2ecf20Sopenharmony_civoid chsc_chp_online(struct chp_id chpid);
1628c2ecf20Sopenharmony_civoid chsc_chp_offline(struct chp_id chpid);
1638c2ecf20Sopenharmony_ciint chsc_get_channel_measurement_chars(struct channel_path *chp);
1648c2ecf20Sopenharmony_ciint chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd);
1658c2ecf20Sopenharmony_ciint chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
1668c2ecf20Sopenharmony_ci	      u64 summary_indicator_addr, u64 subchannel_indicator_addr,
1678c2ecf20Sopenharmony_ci	      u8 isc);
1688c2ecf20Sopenharmony_ciint chsc_sgib(u32 origin);
1698c2ecf20Sopenharmony_ciint chsc_error_from_response(int response);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ciint chsc_siosl(struct subchannel_id schid);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/* Functions and definitions to query storage-class memory. */
1748c2ecf20Sopenharmony_cistruct sale {
1758c2ecf20Sopenharmony_ci	u64 sa;
1768c2ecf20Sopenharmony_ci	u32 p:4;
1778c2ecf20Sopenharmony_ci	u32 op_state:4;
1788c2ecf20Sopenharmony_ci	u32 data_state:4;
1798c2ecf20Sopenharmony_ci	u32 rank:4;
1808c2ecf20Sopenharmony_ci	u32 r:1;
1818c2ecf20Sopenharmony_ci	u32:7;
1828c2ecf20Sopenharmony_ci	u32 rid:8;
1838c2ecf20Sopenharmony_ci	u32:32;
1848c2ecf20Sopenharmony_ci} __packed;
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct chsc_scm_info {
1878c2ecf20Sopenharmony_ci	struct chsc_header request;
1888c2ecf20Sopenharmony_ci	u32:32;
1898c2ecf20Sopenharmony_ci	u64 reqtok;
1908c2ecf20Sopenharmony_ci	u32 reserved1[4];
1918c2ecf20Sopenharmony_ci	struct chsc_header response;
1928c2ecf20Sopenharmony_ci	u64:56;
1938c2ecf20Sopenharmony_ci	u8 rq;
1948c2ecf20Sopenharmony_ci	u32 mbc;
1958c2ecf20Sopenharmony_ci	u64 msa;
1968c2ecf20Sopenharmony_ci	u16 is;
1978c2ecf20Sopenharmony_ci	u16 mmc;
1988c2ecf20Sopenharmony_ci	u32 mci;
1998c2ecf20Sopenharmony_ci	u64 nr_scm_ini;
2008c2ecf20Sopenharmony_ci	u64 nr_scm_unini;
2018c2ecf20Sopenharmony_ci	u32 reserved2[10];
2028c2ecf20Sopenharmony_ci	u64 restok;
2038c2ecf20Sopenharmony_ci	struct sale scmal[248];
2048c2ecf20Sopenharmony_ci} __packed __aligned(PAGE_SIZE);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ciint chsc_scm_info(struct chsc_scm_info *scm_area, u64 token);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciint chsc_pnso(struct subchannel_id schid, struct chsc_pnso_area *pnso_area,
2098c2ecf20Sopenharmony_ci	      u8 oc, struct chsc_pnso_resume_token resume_token, int cnc);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ciint __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid);
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#ifdef CONFIG_SCM_BUS
2148c2ecf20Sopenharmony_ciint scm_update_information(void);
2158c2ecf20Sopenharmony_ciint scm_process_availability_information(void);
2168c2ecf20Sopenharmony_ci#else /* CONFIG_SCM_BUS */
2178c2ecf20Sopenharmony_cistatic inline int scm_update_information(void) { return 0; }
2188c2ecf20Sopenharmony_cistatic inline int scm_process_availability_information(void) { return 0; }
2198c2ecf20Sopenharmony_ci#endif /* CONFIG_SCM_BUS */
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci#endif
223