xref: /openbmc/linux/arch/s390/include/asm/ccwdev.h (revision 0c6924c2)
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>
14a0138f59SAlexandra Winter #include <asm/chsc.h>
15c6557e7fSMartin Schwidefsky #include <asm/fcx.h>
16de400d6bSPeter Oberparleiter #include <asm/irq.h>
171f1c9610SCornelia Huck #include <asm/schid.h>
18*0c6924c2SVineeth Vijayan #include <linux/mutex.h>
19c6557e7fSMartin Schwidefsky 
20c6557e7fSMartin Schwidefsky /* structs from asm/cio.h */
21c6557e7fSMartin Schwidefsky struct irb;
22c6557e7fSMartin Schwidefsky struct ccw1;
23c6557e7fSMartin Schwidefsky struct ccw_dev_id;
24c6557e7fSMartin Schwidefsky 
25c6557e7fSMartin Schwidefsky /* simplified initializers for struct ccw_device:
26c6557e7fSMartin Schwidefsky  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
27c6557e7fSMartin Schwidefsky  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
28c6557e7fSMartin Schwidefsky #define CCW_DEVICE(cu, cum) 						\
29c6557e7fSMartin Schwidefsky 	.cu_type=(cu), .cu_model=(cum),					\
30c6557e7fSMartin Schwidefsky 	.match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE			\
31c6557e7fSMartin Schwidefsky 		   | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
32c6557e7fSMartin Schwidefsky 
33c6557e7fSMartin Schwidefsky #define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm)				\
34c6557e7fSMartin Schwidefsky 	.cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
35c6557e7fSMartin Schwidefsky 	.match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE			\
36c6557e7fSMartin Schwidefsky 		   | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) 	\
37c6557e7fSMartin Schwidefsky 		   | CCW_DEVICE_ID_MATCH_DEVICE_TYPE			\
38c6557e7fSMartin Schwidefsky 		   | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
39c6557e7fSMartin Schwidefsky 
40c6557e7fSMartin Schwidefsky /* scan through an array of device ids and return the first
41c6557e7fSMartin Schwidefsky  * entry that matches the device.
42c6557e7fSMartin Schwidefsky  *
43c6557e7fSMartin Schwidefsky  * the array must end with an entry containing zero match_flags
44c6557e7fSMartin Schwidefsky  */
45c6557e7fSMartin Schwidefsky static inline const struct ccw_device_id *
ccw_device_id_match(const struct ccw_device_id * array,const struct ccw_device_id * match)46c6557e7fSMartin Schwidefsky ccw_device_id_match(const struct ccw_device_id *array,
47c6557e7fSMartin Schwidefsky 			const struct ccw_device_id *match)
48c6557e7fSMartin Schwidefsky {
49c6557e7fSMartin Schwidefsky 	const struct ccw_device_id *id = array;
50c6557e7fSMartin Schwidefsky 
51c6557e7fSMartin Schwidefsky 	for (id = array; id->match_flags; id++) {
52c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
53c6557e7fSMartin Schwidefsky 		    && (id->cu_type != match->cu_type))
54c6557e7fSMartin Schwidefsky 			continue;
55c6557e7fSMartin Schwidefsky 
56c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
57c6557e7fSMartin Schwidefsky 		    && (id->cu_model != match->cu_model))
58c6557e7fSMartin Schwidefsky 			continue;
59c6557e7fSMartin Schwidefsky 
60c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
61c6557e7fSMartin Schwidefsky 		    && (id->dev_type != match->dev_type))
62c6557e7fSMartin Schwidefsky 			continue;
63c6557e7fSMartin Schwidefsky 
64c6557e7fSMartin Schwidefsky 		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
65c6557e7fSMartin Schwidefsky 		    && (id->dev_model != match->dev_model))
66c6557e7fSMartin Schwidefsky 			continue;
67c6557e7fSMartin Schwidefsky 
68c6557e7fSMartin Schwidefsky 		return id;
69c6557e7fSMartin Schwidefsky 	}
70c6557e7fSMartin Schwidefsky 
71c6557e7fSMartin Schwidefsky 	return NULL;
72c6557e7fSMartin Schwidefsky }
73c6557e7fSMartin Schwidefsky 
74c6557e7fSMartin Schwidefsky /**
75c6557e7fSMartin Schwidefsky  * struct ccw_device - channel attached device
76c6557e7fSMartin Schwidefsky  * @ccwlock: pointer to device lock
77c6557e7fSMartin Schwidefsky  * @id: id of this device
78c6557e7fSMartin Schwidefsky  * @drv: ccw driver for this device
79c6557e7fSMartin Schwidefsky  * @dev: embedded device structure
80c6557e7fSMartin Schwidefsky  * @online: online status of device
81c6557e7fSMartin Schwidefsky  * @handler: interrupt handler
82c6557e7fSMartin Schwidefsky  *
83c6557e7fSMartin Schwidefsky  * @handler is a member of the device rather than the driver since a driver
84c6557e7fSMartin Schwidefsky  * can have different interrupt handlers for different ccw devices
85c6557e7fSMartin Schwidefsky  * (multi-subchannel drivers).
86c6557e7fSMartin Schwidefsky  */
87c6557e7fSMartin Schwidefsky struct ccw_device {
88c6557e7fSMartin Schwidefsky 	spinlock_t *ccwlock;
89c6557e7fSMartin Schwidefsky /* private: */
90c6557e7fSMartin Schwidefsky 	struct ccw_device_private *private;	/* cio private information */
91*0c6924c2SVineeth Vijayan 	struct mutex reg_mutex;
92c6557e7fSMartin Schwidefsky /* public: */
93c6557e7fSMartin Schwidefsky 	struct ccw_device_id id;
94c6557e7fSMartin Schwidefsky 	struct ccw_driver *drv;
95c6557e7fSMartin Schwidefsky 	struct device dev;
96c6557e7fSMartin Schwidefsky 	int online;
97c6557e7fSMartin Schwidefsky 	void (*handler) (struct ccw_device *, unsigned long, struct irb *);
98c6557e7fSMartin Schwidefsky };
99c6557e7fSMartin Schwidefsky 
100094f2100SMichael Ernst /*
101585b954eSSebastian Ott  * Possible events used by the path_event notifier.
102585b954eSSebastian Ott  */
103585b954eSSebastian Ott #define PE_NONE				0x0
104585b954eSSebastian Ott #define PE_PATH_GONE			0x1 /* A path is no longer available. */
105585b954eSSebastian Ott #define PE_PATH_AVAILABLE		0x2 /* A path has become available and
106585b954eSSebastian Ott 					       was successfully verified. */
107585b954eSSebastian Ott #define PE_PATHGROUP_ESTABLISHED	0x4 /* A pathgroup was reset and had
108585b954eSSebastian Ott 					       to be established again. */
10932ef9388SVineeth Vijayan #define PE_PATH_FCES_EVENT		0x8 /* The FCES Status of a path has
11032ef9388SVineeth Vijayan 					     * changed. */
111585b954eSSebastian Ott 
112585b954eSSebastian Ott /*
113094f2100SMichael Ernst  * Possible CIO actions triggered by the unit check handler.
114094f2100SMichael Ernst  */
115094f2100SMichael Ernst enum uc_todo {
116094f2100SMichael Ernst 	UC_TODO_RETRY,
117094f2100SMichael Ernst 	UC_TODO_RETRY_ON_NEW_PATH,
118094f2100SMichael Ernst 	UC_TODO_STOP
119094f2100SMichael Ernst };
120c6557e7fSMartin Schwidefsky 
121c6557e7fSMartin Schwidefsky /**
1225ec11d09SMauro Carvalho Chehab  * struct ccw_driver - device driver for channel attached devices
123c6557e7fSMartin Schwidefsky  * @ids: ids supported by this driver
124c6557e7fSMartin Schwidefsky  * @probe: function called on probe
125c6557e7fSMartin Schwidefsky  * @remove: function called on remove
126c6557e7fSMartin Schwidefsky  * @set_online: called when setting device online
127c6557e7fSMartin Schwidefsky  * @set_offline: called when setting device offline
128c6557e7fSMartin Schwidefsky  * @notify: notify driver of device state changes
129585b954eSSebastian Ott  * @path_event: notify driver of channel path events
130c6557e7fSMartin Schwidefsky  * @shutdown: called at device shutdown
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 *);
144094f2100SMichael Ernst 	enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
145c6557e7fSMartin Schwidefsky 	struct device_driver driver;
146de400d6bSPeter Oberparleiter 	enum interruption_class int_class;
147c6557e7fSMartin Schwidefsky };
148c6557e7fSMartin Schwidefsky 
149c6557e7fSMartin Schwidefsky extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
150c6557e7fSMartin Schwidefsky 					      const char *bus_id);
151c6557e7fSMartin Schwidefsky 
152c6557e7fSMartin Schwidefsky /* devices drivers call these during module load and unload.
153c6557e7fSMartin Schwidefsky  * When a driver is registered, its probe method is called
154c6557e7fSMartin Schwidefsky  * when new devices for its type pop up */
155c6557e7fSMartin Schwidefsky extern int  ccw_driver_register   (struct ccw_driver *driver);
156c6557e7fSMartin Schwidefsky extern void ccw_driver_unregister (struct ccw_driver *driver);
157c6557e7fSMartin Schwidefsky extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
158c6557e7fSMartin Schwidefsky extern int ccw_device_set_options(struct ccw_device *, unsigned long);
159c6557e7fSMartin Schwidefsky extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
160454e1fa1SPeter Oberparleiter int ccw_device_is_pathgroup(struct ccw_device *cdev);
161454e1fa1SPeter Oberparleiter int ccw_device_is_multipath(struct ccw_device *cdev);
162c6557e7fSMartin Schwidefsky 
163c6557e7fSMartin Schwidefsky /* Allow for i/o completion notification after primary interrupt status. */
164c6557e7fSMartin Schwidefsky #define CCWDEV_EARLY_NOTIFICATION	0x0001
165c6557e7fSMartin Schwidefsky /* Report all interrupt conditions. */
166c6557e7fSMartin Schwidefsky #define CCWDEV_REPORT_ALL	 	0x0002
167c6557e7fSMartin Schwidefsky /* Try to perform path grouping. */
168c6557e7fSMartin Schwidefsky #define CCWDEV_DO_PATHGROUP             0x0004
169c6557e7fSMartin Schwidefsky /* Allow forced onlining of boxed devices. */
170c6557e7fSMartin Schwidefsky #define CCWDEV_ALLOW_FORCE              0x0008
171454e1fa1SPeter Oberparleiter /* Try to use multipath mode. */
172454e1fa1SPeter Oberparleiter #define CCWDEV_DO_MULTIPATH		0x0010
173c6557e7fSMartin Schwidefsky 
174c6557e7fSMartin Schwidefsky extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
175c6557e7fSMartin Schwidefsky 			    unsigned long, __u8, unsigned long);
176c6557e7fSMartin Schwidefsky extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
177c6557e7fSMartin Schwidefsky 				    unsigned long, __u8, unsigned long, int);
178c6557e7fSMartin Schwidefsky extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
179c6557e7fSMartin Schwidefsky 				unsigned long, __u8, __u8, unsigned long);
180c6557e7fSMartin Schwidefsky extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
181c6557e7fSMartin Schwidefsky 					unsigned long, __u8, __u8,
182c6557e7fSMartin Schwidefsky 					unsigned long, int);
183c6557e7fSMartin Schwidefsky 
184c6557e7fSMartin Schwidefsky 
185c6557e7fSMartin Schwidefsky extern int ccw_device_resume(struct ccw_device *);
186c6557e7fSMartin Schwidefsky extern int ccw_device_halt(struct ccw_device *, unsigned long);
187c6557e7fSMartin Schwidefsky extern int ccw_device_clear(struct ccw_device *, unsigned long);
188c6557e7fSMartin Schwidefsky int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
189c6557e7fSMartin Schwidefsky 			    unsigned long intparm, u8 lpm, u8 key);
190c6557e7fSMartin Schwidefsky int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
191c6557e7fSMartin Schwidefsky 			    unsigned long, u8, u8);
192c6557e7fSMartin Schwidefsky int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
193c6557e7fSMartin Schwidefsky 			    unsigned long, u8, u8, int);
194c6557e7fSMartin Schwidefsky int ccw_device_tm_start(struct ccw_device *, struct tcw *,
195c6557e7fSMartin Schwidefsky 			    unsigned long, u8);
196c6557e7fSMartin Schwidefsky int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
197c6557e7fSMartin Schwidefsky 			    unsigned long, u8, int);
198c6557e7fSMartin Schwidefsky int ccw_device_tm_intrg(struct ccw_device *cdev);
199c6557e7fSMartin Schwidefsky 
200ce322ccdSSebastian Ott int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask);
201ce322ccdSSebastian Ott 
202c6557e7fSMartin Schwidefsky extern int ccw_device_set_online(struct ccw_device *cdev);
203c6557e7fSMartin Schwidefsky extern int ccw_device_set_offline(struct ccw_device *cdev);
204c6557e7fSMartin Schwidefsky 
205c6557e7fSMartin Schwidefsky 
206c6557e7fSMartin Schwidefsky extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
207c6557e7fSMartin Schwidefsky extern __u8 ccw_device_get_path_mask(struct ccw_device *);
208c6557e7fSMartin Schwidefsky extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
209c6557e7fSMartin Schwidefsky 
210c6557e7fSMartin Schwidefsky #define get_ccwdev_lock(x) (x)->ccwlock
211c6557e7fSMartin Schwidefsky 
212c6557e7fSMartin Schwidefsky #define to_ccwdev(n) container_of(n, struct ccw_device, dev)
213c6557e7fSMartin Schwidefsky #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
214c6557e7fSMartin Schwidefsky 
2151e532096SSebastian Ott extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
2161e532096SSebastian Ott extern void ccw_device_destroy_console(struct ccw_device *);
2171e532096SSebastian Ott extern int ccw_device_enable_console(struct ccw_device *);
218188561a4SSebastian Ott extern void ccw_device_wait_idle(struct ccw_device *);
219c6557e7fSMartin Schwidefsky 
22037db8985SHalil Pasic extern void *ccw_device_dma_zalloc(struct ccw_device *cdev, size_t size);
22137db8985SHalil Pasic extern void ccw_device_dma_free(struct ccw_device *cdev,
22237db8985SHalil Pasic 				void *cpu_addr, size_t size);
22337db8985SHalil Pasic 
224fd0457a6SMichael Ernst int ccw_device_siosl(struct ccw_device *);
225fd0457a6SMichael Ernst 
2269368dac4SCornelia Huck extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *);
2279368dac4SCornelia Huck 
228ded27d8dSSebastian Ott struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *, int);
22919965230SSebastian Ott u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx);
230a0138f59SAlexandra Winter int ccw_device_pnso(struct ccw_device *cdev,
2314fea49a7SAlexandra Winter 		    struct chsc_pnso_area *pnso_area, u8 oc,
2324fea49a7SAlexandra Winter 		    struct chsc_pnso_resume_token resume_token, int cnc);
233b983aa1fSAlexandra Winter int ccw_device_get_cssid(struct ccw_device *cdev, u8 *cssid);
234b983aa1fSAlexandra Winter int ccw_device_get_iid(struct ccw_device *cdev, u8 *iid);
235b983aa1fSAlexandra Winter int ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid);
236b983aa1fSAlexandra Winter int ccw_device_get_chid(struct ccw_device *cdev, int chp_idx, u16 *chid);
237c6557e7fSMartin Schwidefsky #endif /* _S390_CCWDEV_H_ */
238