xref: /openbmc/linux/drivers/s390/cio/css.h (revision db66795f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _CSS_H
3 #define _CSS_H
4 
5 #include <linux/mutex.h>
6 #include <linux/wait.h>
7 #include <linux/workqueue.h>
8 #include <linux/device.h>
9 #include <linux/types.h>
10 
11 #include <asm/cio.h>
12 #include <asm/chpid.h>
13 #include <asm/schid.h>
14 
15 #include "cio.h"
16 
17 /*
18  * path grouping stuff
19  */
20 #define SPID_FUNC_SINGLE_PATH	   0x00
21 #define SPID_FUNC_MULTI_PATH	   0x80
22 #define SPID_FUNC_ESTABLISH	   0x00
23 #define SPID_FUNC_RESIGN	   0x40
24 #define SPID_FUNC_DISBAND	   0x20
25 
26 #define SNID_STATE1_RESET	   0
27 #define SNID_STATE1_UNGROUPED	   2
28 #define SNID_STATE1_GROUPED	   3
29 
30 #define SNID_STATE2_NOT_RESVD	   0
31 #define SNID_STATE2_RESVD_ELSE	   2
32 #define SNID_STATE2_RESVD_SELF	   3
33 
34 #define SNID_STATE3_MULTI_PATH	   1
35 #define SNID_STATE3_SINGLE_PATH	   0
36 
37 /*
38  * Conditions used to specify which subchannels need evaluation
39  */
40 enum css_eval_cond {
41 	CSS_EVAL_NO_PATH,		/* Subchannels with no operational paths */
42 	CSS_EVAL_NOT_ONLINE	/* sch without an online-device */
43 };
44 
45 struct path_state {
46 	__u8  state1 : 2;	/* path state value 1 */
47 	__u8  state2 : 2;	/* path state value 2 */
48 	__u8  state3 : 1;	/* path state value 3 */
49 	__u8  resvd  : 3;	/* reserved */
50 } __attribute__ ((packed));
51 
52 struct extended_cssid {
53 	u8 version;
54 	u8 cssid;
55 } __attribute__ ((packed));
56 
57 struct pgid {
58 	union {
59 		__u8 fc;   	/* SPID function code */
60 		struct path_state ps;	/* SNID path state */
61 	} __attribute__ ((packed)) inf;
62 	union {
63 		__u32 cpu_addr	: 16;	/* CPU address */
64 		struct extended_cssid ext_cssid;
65 	} __attribute__ ((packed)) pgid_high;
66 	__u32 cpu_id	: 24;	/* CPU identification */
67 	__u32 cpu_model : 16;	/* CPU model */
68 	__u32 tod_high;		/* high word TOD clock */
69 } __attribute__ ((packed));
70 
71 struct subchannel;
72 struct chp_link;
73 /**
74  * struct css_driver - device driver for subchannels
75  * @subchannel_type: subchannel type supported by this driver
76  * @drv: embedded device driver structure
77  * @irq: called on interrupts
78  * @chp_event: called for events affecting a channel path
79  * @sch_event: called for events affecting the subchannel
80  * @probe: function called on probe
81  * @remove: function called on remove
82  * @shutdown: called at device shutdown
83  * @settle: wait for asynchronous work to finish
84  */
85 struct css_driver {
86 	struct css_device_id *subchannel_type;
87 	struct device_driver drv;
88 	void (*irq)(struct subchannel *);
89 	int (*chp_event)(struct subchannel *, struct chp_link *, int);
90 	int (*sch_event)(struct subchannel *, int);
91 	int (*probe)(struct subchannel *);
92 	void (*remove)(struct subchannel *);
93 	void (*shutdown)(struct subchannel *);
94 	int (*settle)(void);
95 };
96 
97 #define to_cssdriver(n) container_of(n, struct css_driver, drv)
98 
99 extern int css_driver_register(struct css_driver *);
100 extern void css_driver_unregister(struct css_driver *);
101 
102 extern void css_sch_device_unregister(struct subchannel *);
103 extern int css_register_subchannel(struct subchannel *);
104 extern struct subchannel *css_alloc_subchannel(struct subchannel_id,
105 					       struct schib *schib);
106 extern struct subchannel *get_subchannel_by_schid(struct subchannel_id);
107 extern int css_init_done;
108 extern int max_ssid;
109 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
110 			       int (*fn_unknown)(struct subchannel_id,
111 			       void *), void *data);
112 extern int for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *);
113 void css_update_ssd_info(struct subchannel *sch);
114 
115 struct channel_subsystem {
116 	u8 cssid;
117 	u8 iid;
118 	bool id_valid; /* cssid,iid */
119 	struct channel_path *chps[__MAX_CHPID + 1];
120 	struct device device;
121 	struct pgid global_pgid;
122 	struct mutex mutex;
123 	/* channel measurement related */
124 	int cm_enabled;
125 	void *cub_addr1;
126 	void *cub_addr2;
127 	/* for orphaned ccw devices */
128 	struct subchannel *pseudo_subchannel;
129 };
130 #define to_css(dev) container_of(dev, struct channel_subsystem, device)
131 
132 extern struct channel_subsystem *channel_subsystems[];
133 
134 /* Dummy helper which needs to change once we support more than one css. */
135 static inline struct channel_subsystem *css_by_id(u8 cssid)
136 {
137 	return channel_subsystems[0];
138 }
139 
140 /* Dummy iterator which needs to change once we support more than one css. */
141 #define for_each_css(css)						\
142 	for ((css) = channel_subsystems[0]; (css); (css) = NULL)
143 
144 /* Helper functions to build lists for the slow path. */
145 void css_schedule_eval(struct subchannel_id schid);
146 void css_schedule_eval_all(void);
147 void css_schedule_eval_cond(enum css_eval_cond, unsigned long delay);
148 int css_complete_work(void);
149 
150 int sch_is_pseudo_sch(struct subchannel *);
151 struct schib;
152 int css_sch_is_valid(struct schib *);
153 
154 extern struct workqueue_struct *cio_work_q;
155 void css_wait_for_slow_path(void);
156 void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo);
157 #endif
158