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