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