blob: 9381c92cc779b14afbf940fe5b4f56f54ad7d125 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Sebastian Ott823d4942009-06-16 10:30:20 +02002 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Sebastian Ott823d4942009-06-16 10:30:20 +02004 * Author(s): Arnd Bergmann <arndb@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Sebastian Ott823d4942009-06-16 10:30:20 +02006 * Interface for CCW device drivers
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8#ifndef _S390_CCWDEV_H_
9#define _S390_CCWDEV_H_
10
11#include <linux/device.h>
12#include <linux/mod_devicetable.h>
Peter Oberparleiter83262d62008-07-14 09:58:51 +020013#include <asm/fcx.h>
Peter Oberparleiterde400d62011-10-30 15:16:04 +010014#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16/* structs from asm/cio.h */
17struct irb;
18struct ccw1;
Cornelia Huck9a92fe42007-05-10 15:45:42 +020019struct ccw_dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21/* simplified initializers for struct ccw_device:
22 * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
23 * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
24#define CCW_DEVICE(cu, cum) \
25 .cu_type=(cu), .cu_model=(cum), \
26 .match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE \
27 | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
28
29#define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm) \
30 .cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
31 .match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE \
32 | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) \
33 | CCW_DEVICE_ID_MATCH_DEVICE_TYPE \
34 | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
35
36/* scan through an array of device ids and return the first
37 * entry that matches the device.
38 *
39 * the array must end with an entry containing zero match_flags
40 */
41static inline const struct ccw_device_id *
42ccw_device_id_match(const struct ccw_device_id *array,
43 const struct ccw_device_id *match)
44{
45 const struct ccw_device_id *id = array;
46
47 for (id = array; id->match_flags; id++) {
48 if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
49 && (id->cu_type != match->cu_type))
50 continue;
51
52 if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
53 && (id->cu_model != match->cu_model))
54 continue;
55
56 if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
57 && (id->dev_type != match->dev_type))
58 continue;
59
60 if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
61 && (id->dev_model != match->dev_model))
62 continue;
63
64 return id;
65 }
66
Heiko Carstensd2c993d2006-07-12 16:41:55 +020067 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020070/**
71 * struct ccw_device - channel attached device
72 * @ccwlock: pointer to device lock
73 * @id: id of this device
74 * @drv: ccw driver for this device
75 * @dev: embedded device structure
76 * @online: online status of device
77 * @handler: interrupt handler
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 *
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020079 * @handler is a member of the device rather than the driver since a driver
80 * can have different interrupt handlers for different ccw devices
81 * (multi-subchannel drivers).
82 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct ccw_device {
84 spinlock_t *ccwlock;
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020085/* private: */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 struct ccw_device_private *private; /* cio private information */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020087/* public: */
88 struct ccw_device_id id;
89 struct ccw_driver *drv;
90 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 int online;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 void (*handler) (struct ccw_device *, unsigned long, struct irb *);
93};
94
Michael Ernst094f2102010-05-26 23:27:08 +020095/*
Sebastian Ott585b9542010-10-25 16:10:34 +020096 * Possible events used by the path_event notifier.
97 */
98#define PE_NONE 0x0
99#define PE_PATH_GONE 0x1 /* A path is no longer available. */
100#define PE_PATH_AVAILABLE 0x2 /* A path has become available and
101 was successfully verified. */
102#define PE_PATHGROUP_ESTABLISHED 0x4 /* A pathgroup was reset and had
103 to be established again. */
104
105/*
Michael Ernst094f2102010-05-26 23:27:08 +0200106 * Possible CIO actions triggered by the unit check handler.
107 */
108enum uc_todo {
109 UC_TODO_RETRY,
110 UC_TODO_RETRY_ON_NEW_PATH,
111 UC_TODO_STOP
112};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200114/**
115 * struct ccw driver - device driver for channel attached devices
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200116 * @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
Sebastian Ott585b9542010-10-25 16:10:34 +0200122 * @path_event: notify driver of channel path events
Cornelia Huck958974fb2007-10-12 16:11:21 +0200123 * @shutdown: called at device shutdown
Sebastian Ott823d4942009-06-16 10:30:20 +0200124 * @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
Michael Ernst094f2102010-05-26 23:27:08 +0200129 * @uc_handler: callback for unit check handler
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200130 * @driver: embedded device driver structure
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100131 * @int_class: interruption class to use for accounting interrupts
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200132 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133struct ccw_driver {
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200134 struct ccw_device_id *ids;
135 int (*probe) (struct ccw_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 void (*remove) (struct ccw_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 int (*set_online) (struct ccw_device *);
138 int (*set_offline) (struct ccw_device *);
139 int (*notify) (struct ccw_device *, int);
Sebastian Ott585b9542010-10-25 16:10:34 +0200140 void (*path_event) (struct ccw_device *, int *);
Cornelia Huck958974fb2007-10-12 16:11:21 +0200141 void (*shutdown) (struct ccw_device *);
Sebastian Ott823d4942009-06-16 10:30:20 +0200142 int (*prepare) (struct ccw_device *);
143 void (*complete) (struct ccw_device *);
144 int (*freeze)(struct ccw_device *);
145 int (*thaw) (struct ccw_device *);
146 int (*restore)(struct ccw_device *);
Michael Ernst094f2102010-05-26 23:27:08 +0200147 enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200148 struct device_driver driver;
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100149 enum interruption_class int_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
153 const char *bus_id);
154
155/* devices drivers call these during module load and unload.
156 * When a driver is registered, its probe method is called
157 * when new devices for its type pop up */
158extern int ccw_driver_register (struct ccw_driver *driver);
159extern void ccw_driver_unregister (struct ccw_driver *driver);
160
161struct ccw1;
162
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100163extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int ccw_device_set_options(struct ccw_device *, unsigned long);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100165extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100166int ccw_device_is_pathgroup(struct ccw_device *cdev);
167int ccw_device_is_multipath(struct ccw_device *cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/* Allow for i/o completion notification after primary interrupt status. */
170#define CCWDEV_EARLY_NOTIFICATION 0x0001
171/* Report all interrupt conditions. */
172#define CCWDEV_REPORT_ALL 0x0002
173/* Try to perform path grouping. */
174#define CCWDEV_DO_PATHGROUP 0x0004
175/* Allow forced onlining of boxed devices. */
176#define CCWDEV_ALLOW_FORCE 0x0008
Peter Oberparleiter454e1fa2009-12-07 12:51:30 +0100177/* Try to use multipath mode. */
178#define CCWDEV_DO_MULTIPATH 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
181 unsigned long, __u8, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
183 unsigned long, __u8, unsigned long, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
185 unsigned long, __u8, __u8, unsigned long);
186extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
187 unsigned long, __u8, __u8,
188 unsigned long, int);
189
190
191extern int ccw_device_resume(struct ccw_device *);
192extern int ccw_device_halt(struct ccw_device *, unsigned long);
193extern int ccw_device_clear(struct ccw_device *, unsigned long);
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200194int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
195 unsigned long intparm, u8 lpm, u8 key);
196int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
197 unsigned long, u8, u8);
198int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
199 unsigned long, u8, u8, int);
200int ccw_device_tm_start(struct ccw_device *, struct tcw *,
201 unsigned long, u8);
202int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
203 unsigned long, u8, int);
204int ccw_device_tm_intrg(struct ccw_device *cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Sebastian Ottce322cc2011-01-05 12:47:56 +0100206int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask);
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208extern int ccw_device_set_online(struct ccw_device *cdev);
209extern int ccw_device_set_offline(struct ccw_device *cdev);
210
211
212extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
213extern __u8 ccw_device_get_path_mask(struct ccw_device *);
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200214extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#define get_ccwdev_lock(x) (x)->ccwlock
217
218#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
219#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
220
221extern struct ccw_device *ccw_device_probe_console(void);
Martin Schwidefsky66648452009-06-16 10:30:28 +0200222extern int ccw_device_force_console(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Michael Ernstfd0457a2010-08-09 18:12:50 +0200224int ccw_device_siosl(struct ccw_device *);
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226// FIXME: these have to go
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227extern int _ccw_device_get_subchannel_number(struct ccw_device *);
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
230#endif /* _S390_CCWDEV_H_ */