xref: /openbmc/linux/arch/s390/include/asm/ccwdev.h (revision 4800cd83)
1 /*
2  * Copyright  IBM Corp. 2002, 2009
3  *
4  * Author(s): Arnd Bergmann <arndb@de.ibm.com>
5  *
6  * Interface for CCW device drivers
7  */
8 #ifndef _S390_CCWDEV_H_
9 #define _S390_CCWDEV_H_
10 
11 #include <linux/device.h>
12 #include <linux/mod_devicetable.h>
13 #include <asm/fcx.h>
14 
15 /* structs from asm/cio.h */
16 struct irb;
17 struct ccw1;
18 struct ccw_dev_id;
19 
20 /* simplified initializers for struct ccw_device:
21  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
22  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
23 #define CCW_DEVICE(cu, cum) 						\
24 	.cu_type=(cu), .cu_model=(cum),					\
25 	.match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE			\
26 		   | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
27 
28 #define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm)				\
29 	.cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
30 	.match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE			\
31 		   | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) 	\
32 		   | CCW_DEVICE_ID_MATCH_DEVICE_TYPE			\
33 		   | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
34 
35 /* scan through an array of device ids and return the first
36  * entry that matches the device.
37  *
38  * the array must end with an entry containing zero match_flags
39  */
40 static inline const struct ccw_device_id *
41 ccw_device_id_match(const struct ccw_device_id *array,
42 			const struct ccw_device_id *match)
43 {
44 	const struct ccw_device_id *id = array;
45 
46 	for (id = array; id->match_flags; id++) {
47 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
48 		    && (id->cu_type != match->cu_type))
49 			continue;
50 
51 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
52 		    && (id->cu_model != match->cu_model))
53 			continue;
54 
55 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
56 		    && (id->dev_type != match->dev_type))
57 			continue;
58 
59 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
60 		    && (id->dev_model != match->dev_model))
61 			continue;
62 
63 		return id;
64 	}
65 
66 	return NULL;
67 }
68 
69 /**
70  * struct ccw_device - channel attached device
71  * @ccwlock: pointer to device lock
72  * @id: id of this device
73  * @drv: ccw driver for this device
74  * @dev: embedded device structure
75  * @online: online status of device
76  * @handler: interrupt handler
77  *
78  * @handler is a member of the device rather than the driver since a driver
79  * can have different interrupt handlers for different ccw devices
80  * (multi-subchannel drivers).
81  */
82 struct ccw_device {
83 	spinlock_t *ccwlock;
84 /* private: */
85 	struct ccw_device_private *private;	/* cio private information */
86 /* public: */
87 	struct ccw_device_id id;
88 	struct ccw_driver *drv;
89 	struct device dev;
90 	int online;
91 	void (*handler) (struct ccw_device *, unsigned long, struct irb *);
92 };
93 
94 /*
95  * Possible events used by the path_event notifier.
96  */
97 #define PE_NONE				0x0
98 #define PE_PATH_GONE			0x1 /* A path is no longer available. */
99 #define PE_PATH_AVAILABLE		0x2 /* A path has become available and
100 					       was successfully verified. */
101 #define PE_PATHGROUP_ESTABLISHED	0x4 /* A pathgroup was reset and had
102 					       to be established again. */
103 
104 /*
105  * Possible CIO actions triggered by the unit check handler.
106  */
107 enum uc_todo {
108 	UC_TODO_RETRY,
109 	UC_TODO_RETRY_ON_NEW_PATH,
110 	UC_TODO_STOP
111 };
112 
113 /**
114  * struct ccw driver - device driver for channel attached devices
115  * @owner: owning module
116  * @ids: ids supported by this driver
117  * @probe: function called on probe
118  * @remove: function called on remove
119  * @set_online: called when setting device online
120  * @set_offline: called when setting device offline
121  * @notify: notify driver of device state changes
122  * @path_event: notify driver of channel path events
123  * @shutdown: called at device shutdown
124  * @prepare: prepare for pm state transition
125  * @complete: undo work done in @prepare
126  * @freeze: callback for freezing during hibernation snapshotting
127  * @thaw: undo work done in @freeze
128  * @restore: callback for restoring after hibernation
129  * @uc_handler: callback for unit check handler
130  * @driver: embedded device driver structure
131  * @name: device driver name
132  */
133 struct ccw_driver {
134 	struct module *owner;
135 	struct ccw_device_id *ids;
136 	int (*probe) (struct ccw_device *);
137 	void (*remove) (struct ccw_device *);
138 	int (*set_online) (struct ccw_device *);
139 	int (*set_offline) (struct ccw_device *);
140 	int (*notify) (struct ccw_device *, int);
141 	void (*path_event) (struct ccw_device *, int *);
142 	void (*shutdown) (struct ccw_device *);
143 	int (*prepare) (struct ccw_device *);
144 	void (*complete) (struct ccw_device *);
145 	int (*freeze)(struct ccw_device *);
146 	int (*thaw) (struct ccw_device *);
147 	int (*restore)(struct ccw_device *);
148 	enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
149 	struct device_driver driver;
150 	char *name;
151 };
152 
153 extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
154 					      const char *bus_id);
155 
156 /* devices drivers call these during module load and unload.
157  * When a driver is registered, its probe method is called
158  * when new devices for its type pop up */
159 extern int  ccw_driver_register   (struct ccw_driver *driver);
160 extern void ccw_driver_unregister (struct ccw_driver *driver);
161 
162 struct ccw1;
163 
164 extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
165 extern int ccw_device_set_options(struct ccw_device *, unsigned long);
166 extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
167 int ccw_device_is_pathgroup(struct ccw_device *cdev);
168 int ccw_device_is_multipath(struct ccw_device *cdev);
169 
170 /* Allow for i/o completion notification after primary interrupt status. */
171 #define CCWDEV_EARLY_NOTIFICATION	0x0001
172 /* Report all interrupt conditions. */
173 #define CCWDEV_REPORT_ALL	 	0x0002
174 /* Try to perform path grouping. */
175 #define CCWDEV_DO_PATHGROUP             0x0004
176 /* Allow forced onlining of boxed devices. */
177 #define CCWDEV_ALLOW_FORCE              0x0008
178 /* Try to use multipath mode. */
179 #define CCWDEV_DO_MULTIPATH		0x0010
180 
181 extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
182 			    unsigned long, __u8, unsigned long);
183 extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
184 				    unsigned long, __u8, unsigned long, int);
185 extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
186 				unsigned long, __u8, __u8, unsigned long);
187 extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
188 					unsigned long, __u8, __u8,
189 					unsigned long, int);
190 
191 
192 extern int ccw_device_resume(struct ccw_device *);
193 extern int ccw_device_halt(struct ccw_device *, unsigned long);
194 extern int ccw_device_clear(struct ccw_device *, unsigned long);
195 int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
196 			    unsigned long intparm, u8 lpm, u8 key);
197 int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
198 			    unsigned long, u8, u8);
199 int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
200 			    unsigned long, u8, u8, int);
201 int ccw_device_tm_start(struct ccw_device *, struct tcw *,
202 			    unsigned long, u8);
203 int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
204 			    unsigned long, u8, int);
205 int ccw_device_tm_intrg(struct ccw_device *cdev);
206 
207 int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask);
208 
209 extern int ccw_device_set_online(struct ccw_device *cdev);
210 extern int ccw_device_set_offline(struct ccw_device *cdev);
211 
212 
213 extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
214 extern __u8 ccw_device_get_path_mask(struct ccw_device *);
215 extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
216 
217 #define get_ccwdev_lock(x) (x)->ccwlock
218 
219 #define to_ccwdev(n) container_of(n, struct ccw_device, dev)
220 #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
221 
222 extern struct ccw_device *ccw_device_probe_console(void);
223 extern int ccw_device_force_console(void);
224 
225 int ccw_device_siosl(struct ccw_device *);
226 
227 // FIXME: these have to go
228 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
229 
230 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
231 #endif /* _S390_CCWDEV_H_ */
232