xref: /openbmc/linux/arch/s390/include/asm/ccwdev.h (revision b2441318)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2c6557e7fSMartin Schwidefsky /*
3823d494aSSebastian Ott  * Copyright IBM Corp. 2002, 2009
4c6557e7fSMartin Schwidefsky  *
5c6557e7fSMartin Schwidefsky  * Author(s): Arnd Bergmann <arndb@de.ibm.com>
6c6557e7fSMartin Schwidefsky  *
7c6557e7fSMartin Schwidefsky  * Interface for CCW device drivers
8c6557e7fSMartin Schwidefsky  */
9c6557e7fSMartin Schwidefsky #ifndef _S390_CCWDEV_H_
10c6557e7fSMartin Schwidefsky #define _S390_CCWDEV_H_
11c6557e7fSMartin Schwidefsky 
12c6557e7fSMartin Schwidefsky #include <linux/device.h>
13c6557e7fSMartin Schwidefsky #include <linux/mod_devicetable.h>
14c6557e7fSMartin Schwidefsky #include <asm/fcx.h>
15de400d6bSPeter Oberparleiter #include <asm/irq.h>
161f1c9610SCornelia Huck #include <asm/schid.h>
17c6557e7fSMartin Schwidefsky 
18c6557e7fSMartin Schwidefsky /* structs from asm/cio.h */
19c6557e7fSMartin Schwidefsky struct irb;
20c6557e7fSMartin Schwidefsky struct ccw1;
21c6557e7fSMartin Schwidefsky struct ccw_dev_id;
22c6557e7fSMartin Schwidefsky 
23c6557e7fSMartin Schwidefsky /* simplified initializers for struct ccw_device:
24c6557e7fSMartin Schwidefsky  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
25c6557e7fSMartin Schwidefsky  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
26c6557e7fSMartin Schwidefsky #define CCW_DEVICE(cu, cum) 						\
27c6557e7fSMartin Schwidefsky 	.cu_type=(cu), .cu_model=(cum),					\
28c6557e7fSMartin Schwidefsky 	.match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE			\
29c6557e7fSMartin Schwidefsky 		   | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
30c6557e7fSMartin Schwidefsky 
31c6557e7fSMartin Schwidefsky #define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm)				\
32c6557e7fSMartin Schwidefsky 	.cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
33c6557e7fSMartin Schwidefsky 	.match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE			\
34c6557e7fSMartin Schwidefsky 		   | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) 	\
35c6557e7fSMartin Schwidefsky 		   | CCW_DEVICE_ID_MATCH_DEVICE_TYPE			\
36c6557e7fSMartin Schwidefsky 		   | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
37c6557e7fSMartin Schwidefsky 
38c6557e7fSMartin Schwidefsky /* scan through an array of device ids and return the first
39c6557e7fSMartin Schwidefsky  * entry that matches the device.
40c6557e7fSMartin Schwidefsky  *
41c6557e7fSMartin Schwidefsky  * the array must end with an entry containing zero match_flags
42c6557e7fSMartin Schwidefsky  */
43c6557e7fSMartin Schwidefsky static inline const struct ccw_device_id *
44c6557e7fSMartin Schwidefsky ccw_device_id_match(const struct ccw_device_id *array,
45c6557e7fSMartin Schwidefsky 			const struct ccw_device_id *match)
46c6557e7fSMartin Schwidefsky {
47c6557e7fSMartin Schwidefsky 	const struct ccw_device_id *id = array;
48c6557e7fSMartin Schwidefsky 
49c6557e7fSMartin Schwidefsky 	for (id = array; id->match_flags; id++) {
50c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
51c6557e7fSMartin Schwidefsky 		    && (id->cu_type != match->cu_type))
52c6557e7fSMartin Schwidefsky 			continue;
53c6557e7fSMartin Schwidefsky 
54c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
55c6557e7fSMartin Schwidefsky 		    && (id->cu_model != match->cu_model))
56c6557e7fSMartin Schwidefsky 			continue;
57c6557e7fSMartin Schwidefsky 
58c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
59c6557e7fSMartin Schwidefsky 		    && (id->dev_type != match->dev_type))
60c6557e7fSMartin Schwidefsky 			continue;
61c6557e7fSMartin Schwidefsky 
62c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
63c6557e7fSMartin Schwidefsky 		    && (id->dev_model != match->dev_model))
64c6557e7fSMartin Schwidefsky 			continue;
65c6557e7fSMartin Schwidefsky 
66c6557e7fSMartin Schwidefsky 		return id;
67c6557e7fSMartin Schwidefsky 	}
68c6557e7fSMartin Schwidefsky 
69c6557e7fSMartin Schwidefsky 	return NULL;
70c6557e7fSMartin Schwidefsky }
71c6557e7fSMartin Schwidefsky 
72c6557e7fSMartin Schwidefsky /**
73c6557e7fSMartin Schwidefsky  * struct ccw_device - channel attached device
74c6557e7fSMartin Schwidefsky  * @ccwlock: pointer to device lock
75c6557e7fSMartin Schwidefsky  * @id: id of this device
76c6557e7fSMartin Schwidefsky  * @drv: ccw driver for this device
77c6557e7fSMartin Schwidefsky  * @dev: embedded device structure
78c6557e7fSMartin Schwidefsky  * @online: online status of device
79c6557e7fSMartin Schwidefsky  * @handler: interrupt handler
80c6557e7fSMartin Schwidefsky  *
81c6557e7fSMartin Schwidefsky  * @handler is a member of the device rather than the driver since a driver
82c6557e7fSMartin Schwidefsky  * can have different interrupt handlers for different ccw devices
83c6557e7fSMartin Schwidefsky  * (multi-subchannel drivers).
84c6557e7fSMartin Schwidefsky  */
85c6557e7fSMartin Schwidefsky struct ccw_device {
86c6557e7fSMartin Schwidefsky 	spinlock_t *ccwlock;
87c6557e7fSMartin Schwidefsky /* private: */
88c6557e7fSMartin Schwidefsky 	struct ccw_device_private *private;	/* cio private information */
89c6557e7fSMartin Schwidefsky /* public: */
90c6557e7fSMartin Schwidefsky 	struct ccw_device_id id;
91c6557e7fSMartin Schwidefsky 	struct ccw_driver *drv;
92c6557e7fSMartin Schwidefsky 	struct device dev;
93c6557e7fSMartin Schwidefsky 	int online;
94c6557e7fSMartin Schwidefsky 	void (*handler) (struct ccw_device *, unsigned long, struct irb *);
95c6557e7fSMartin Schwidefsky };
96c6557e7fSMartin Schwidefsky 
97094f2100SMichael Ernst /*
98585b954eSSebastian Ott  * Possible events used by the path_event notifier.
99585b954eSSebastian Ott  */
100585b954eSSebastian Ott #define PE_NONE				0x0
101585b954eSSebastian Ott #define PE_PATH_GONE			0x1 /* A path is no longer available. */
102585b954eSSebastian Ott #define PE_PATH_AVAILABLE		0x2 /* A path has become available and
103585b954eSSebastian Ott 					       was successfully verified. */
104585b954eSSebastian Ott #define PE_PATHGROUP_ESTABLISHED	0x4 /* A pathgroup was reset and had
105585b954eSSebastian Ott 					       to be established again. */
106585b954eSSebastian Ott 
107585b954eSSebastian Ott /*
108094f2100SMichael Ernst  * Possible CIO actions triggered by the unit check handler.
109094f2100SMichael Ernst  */
110094f2100SMichael Ernst enum uc_todo {
111094f2100SMichael Ernst 	UC_TODO_RETRY,
112094f2100SMichael Ernst 	UC_TODO_RETRY_ON_NEW_PATH,
113094f2100SMichael Ernst 	UC_TODO_STOP
114094f2100SMichael Ernst };
115c6557e7fSMartin Schwidefsky 
116c6557e7fSMartin Schwidefsky /**
117c6557e7fSMartin Schwidefsky  * struct ccw driver - device driver for channel attached devices
118c6557e7fSMartin Schwidefsky  * @ids: ids supported by this driver
119c6557e7fSMartin Schwidefsky  * @probe: function called on probe
120c6557e7fSMartin Schwidefsky  * @remove: function called on remove
121c6557e7fSMartin Schwidefsky  * @set_online: called when setting device online
122c6557e7fSMartin Schwidefsky  * @set_offline: called when setting device offline
123c6557e7fSMartin Schwidefsky  * @notify: notify driver of device state changes
124585b954eSSebastian Ott  * @path_event: notify driver of channel path events
125c6557e7fSMartin Schwidefsky  * @shutdown: called at device shutdown
126823d494aSSebastian Ott  * @prepare: prepare for pm state transition
127823d494aSSebastian Ott  * @complete: undo work done in @prepare
128823d494aSSebastian Ott  * @freeze: callback for freezing during hibernation snapshotting
129823d494aSSebastian Ott  * @thaw: undo work done in @freeze
130823d494aSSebastian Ott  * @restore: callback for restoring after hibernation
131094f2100SMichael Ernst  * @uc_handler: callback for unit check handler
132c6557e7fSMartin Schwidefsky  * @driver: embedded device driver structure
133de400d6bSPeter Oberparleiter  * @int_class: interruption class to use for accounting interrupts
134c6557e7fSMartin Schwidefsky  */
135c6557e7fSMartin Schwidefsky struct ccw_driver {
136c6557e7fSMartin Schwidefsky 	struct ccw_device_id *ids;
137c6557e7fSMartin Schwidefsky 	int (*probe) (struct ccw_device *);
138c6557e7fSMartin Schwidefsky 	void (*remove) (struct ccw_device *);
139c6557e7fSMartin Schwidefsky 	int (*set_online) (struct ccw_device *);
140c6557e7fSMartin Schwidefsky 	int (*set_offline) (struct ccw_device *);
141c6557e7fSMartin Schwidefsky 	int (*notify) (struct ccw_device *, int);
142585b954eSSebastian Ott 	void (*path_event) (struct ccw_device *, int *);
143c6557e7fSMartin Schwidefsky 	void (*shutdown) (struct ccw_device *);
144823d494aSSebastian Ott 	int (*prepare) (struct ccw_device *);
145823d494aSSebastian Ott 	void (*complete) (struct ccw_device *);
146823d494aSSebastian Ott 	int (*freeze)(struct ccw_device *);
147823d494aSSebastian Ott 	int (*thaw) (struct ccw_device *);
148823d494aSSebastian Ott 	int (*restore)(struct ccw_device *);
149094f2100SMichael Ernst 	enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
150c6557e7fSMartin Schwidefsky 	struct device_driver driver;
151de400d6bSPeter Oberparleiter 	enum interruption_class int_class;
152c6557e7fSMartin Schwidefsky };
153c6557e7fSMartin Schwidefsky 
154c6557e7fSMartin Schwidefsky extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
155c6557e7fSMartin Schwidefsky 					      const char *bus_id);
156c6557e7fSMartin Schwidefsky 
157c6557e7fSMartin Schwidefsky /* devices drivers call these during module load and unload.
158c6557e7fSMartin Schwidefsky  * When a driver is registered, its probe method is called
159c6557e7fSMartin Schwidefsky  * when new devices for its type pop up */
160c6557e7fSMartin Schwidefsky extern int  ccw_driver_register   (struct ccw_driver *driver);
161c6557e7fSMartin Schwidefsky extern void ccw_driver_unregister (struct ccw_driver *driver);
162c6557e7fSMartin Schwidefsky 
163c6557e7fSMartin Schwidefsky struct ccw1;
164c6557e7fSMartin Schwidefsky 
165c6557e7fSMartin Schwidefsky extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
166c6557e7fSMartin Schwidefsky extern int ccw_device_set_options(struct ccw_device *, unsigned long);
167c6557e7fSMartin Schwidefsky extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
168454e1fa1SPeter Oberparleiter int ccw_device_is_pathgroup(struct ccw_device *cdev);
169454e1fa1SPeter Oberparleiter int ccw_device_is_multipath(struct ccw_device *cdev);
170c6557e7fSMartin Schwidefsky 
171c6557e7fSMartin Schwidefsky /* Allow for i/o completion notification after primary interrupt status. */
172c6557e7fSMartin Schwidefsky #define CCWDEV_EARLY_NOTIFICATION	0x0001
173c6557e7fSMartin Schwidefsky /* Report all interrupt conditions. */
174c6557e7fSMartin Schwidefsky #define CCWDEV_REPORT_ALL	 	0x0002
175c6557e7fSMartin Schwidefsky /* Try to perform path grouping. */
176c6557e7fSMartin Schwidefsky #define CCWDEV_DO_PATHGROUP             0x0004
177c6557e7fSMartin Schwidefsky /* Allow forced onlining of boxed devices. */
178c6557e7fSMartin Schwidefsky #define CCWDEV_ALLOW_FORCE              0x0008
179454e1fa1SPeter Oberparleiter /* Try to use multipath mode. */
180454e1fa1SPeter Oberparleiter #define CCWDEV_DO_MULTIPATH		0x0010
181c6557e7fSMartin Schwidefsky 
182c6557e7fSMartin Schwidefsky extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
183c6557e7fSMartin Schwidefsky 			    unsigned long, __u8, unsigned long);
184c6557e7fSMartin Schwidefsky extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
185c6557e7fSMartin Schwidefsky 				    unsigned long, __u8, unsigned long, int);
186c6557e7fSMartin Schwidefsky extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
187c6557e7fSMartin Schwidefsky 				unsigned long, __u8, __u8, unsigned long);
188c6557e7fSMartin Schwidefsky extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
189c6557e7fSMartin Schwidefsky 					unsigned long, __u8, __u8,
190c6557e7fSMartin Schwidefsky 					unsigned long, int);
191c6557e7fSMartin Schwidefsky 
192c6557e7fSMartin Schwidefsky 
193c6557e7fSMartin Schwidefsky extern int ccw_device_resume(struct ccw_device *);
194c6557e7fSMartin Schwidefsky extern int ccw_device_halt(struct ccw_device *, unsigned long);
195c6557e7fSMartin Schwidefsky extern int ccw_device_clear(struct ccw_device *, unsigned long);
196c6557e7fSMartin Schwidefsky int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
197c6557e7fSMartin Schwidefsky 			    unsigned long intparm, u8 lpm, u8 key);
198c6557e7fSMartin Schwidefsky int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
199c6557e7fSMartin Schwidefsky 			    unsigned long, u8, u8);
200c6557e7fSMartin Schwidefsky int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
201c6557e7fSMartin Schwidefsky 			    unsigned long, u8, u8, int);
202c6557e7fSMartin Schwidefsky int ccw_device_tm_start(struct ccw_device *, struct tcw *,
203c6557e7fSMartin Schwidefsky 			    unsigned long, u8);
204c6557e7fSMartin Schwidefsky int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
205c6557e7fSMartin Schwidefsky 			    unsigned long, u8, int);
206c6557e7fSMartin Schwidefsky int ccw_device_tm_intrg(struct ccw_device *cdev);
207c6557e7fSMartin Schwidefsky 
208ce322ccdSSebastian Ott int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask);
209ce322ccdSSebastian Ott 
210c6557e7fSMartin Schwidefsky extern int ccw_device_set_online(struct ccw_device *cdev);
211c6557e7fSMartin Schwidefsky extern int ccw_device_set_offline(struct ccw_device *cdev);
212c6557e7fSMartin Schwidefsky 
213c6557e7fSMartin Schwidefsky 
214c6557e7fSMartin Schwidefsky extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
215c6557e7fSMartin Schwidefsky extern __u8 ccw_device_get_path_mask(struct ccw_device *);
216c6557e7fSMartin Schwidefsky extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
217c6557e7fSMartin Schwidefsky 
218c6557e7fSMartin Schwidefsky #define get_ccwdev_lock(x) (x)->ccwlock
219c6557e7fSMartin Schwidefsky 
220c6557e7fSMartin Schwidefsky #define to_ccwdev(n) container_of(n, struct ccw_device, dev)
221c6557e7fSMartin Schwidefsky #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
222c6557e7fSMartin Schwidefsky 
2231e532096SSebastian Ott extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
2241e532096SSebastian Ott extern void ccw_device_destroy_console(struct ccw_device *);
2251e532096SSebastian Ott extern int ccw_device_enable_console(struct ccw_device *);
226188561a4SSebastian Ott extern void ccw_device_wait_idle(struct ccw_device *);
227f10ccca7SSebastian Ott extern int ccw_device_force_console(struct ccw_device *);
228c6557e7fSMartin Schwidefsky 
229fd0457a6SMichael Ernst int ccw_device_siosl(struct ccw_device *);
230fd0457a6SMichael Ernst 
2319368dac4SCornelia Huck extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *);
2329368dac4SCornelia Huck 
2332bf29df7SSebastian Ott struct channel_path_desc *ccw_device_get_chp_desc(struct ccw_device *, int);
234c6557e7fSMartin Schwidefsky #endif /* _S390_CCWDEV_H_ */
235