blob: 2a541955117688b23de8b40557dfd944d1dce02c [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/* structs from asm/cio.h */
16struct irb;
17struct ccw1;
Cornelia Huck9a92fe42007-05-10 15:45:42 +020018struct ccw_dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20/* simplified initializers for struct ccw_device:
21 * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
22 * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
23#define CCW_DEVICE(cu, cum) \
24 .cu_type=(cu), .cu_model=(cum), \
25 .match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE \
26 | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
27
28#define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm) \
29 .cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
30 .match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE \
31 | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) \
32 | CCW_DEVICE_ID_MATCH_DEVICE_TYPE \
33 | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
34
35/* scan through an array of device ids and return the first
36 * entry that matches the device.
37 *
38 * the array must end with an entry containing zero match_flags
39 */
40static inline const struct ccw_device_id *
41ccw_device_id_match(const struct ccw_device_id *array,
42 const struct ccw_device_id *match)
43{
44 const struct ccw_device_id *id = array;
45
46 for (id = array; id->match_flags; id++) {
47 if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
48 && (id->cu_type != match->cu_type))
49 continue;
50
51 if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
52 && (id->cu_model != match->cu_model))
53 continue;
54
55 if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
56 && (id->dev_type != match->dev_type))
57 continue;
58
59 if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
60 && (id->dev_model != match->dev_model))
61 continue;
62
63 return id;
64 }
65
Heiko Carstensd2c993d2006-07-12 16:41:55 +020066 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020069/**
70 * struct ccw_device - channel attached device
71 * @ccwlock: pointer to device lock
72 * @id: id of this device
73 * @drv: ccw driver for this device
74 * @dev: embedded device structure
75 * @online: online status of device
76 * @handler: interrupt handler
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 *
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020078 * @handler is a member of the device rather than the driver since a driver
79 * can have different interrupt handlers for different ccw devices
80 * (multi-subchannel drivers).
81 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082struct ccw_device {
83 spinlock_t *ccwlock;
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020084/* private: */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct ccw_device_private *private; /* cio private information */
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020086/* public: */
87 struct ccw_device_id id;
88 struct ccw_driver *drv;
89 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 int online;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 void (*handler) (struct ccw_device *, unsigned long, struct irb *);
92};
93
94
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +020095/**
96 * struct ccw driver - device driver for channel attached devices
97 * @owner: owning module
98 * @ids: ids supported by this driver
99 * @probe: function called on probe
100 * @remove: function called on remove
101 * @set_online: called when setting device online
102 * @set_offline: called when setting device offline
103 * @notify: notify driver of device state changes
Cornelia Huck958974fb2007-10-12 16:11:21 +0200104 * @shutdown: called at device shutdown
Sebastian Ott823d4942009-06-16 10:30:20 +0200105 * @prepare: prepare for pm state transition
106 * @complete: undo work done in @prepare
107 * @freeze: callback for freezing during hibernation snapshotting
108 * @thaw: undo work done in @freeze
109 * @restore: callback for restoring after hibernation
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200110 * @driver: embedded device driver structure
111 * @name: device driver name
112 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113struct ccw_driver {
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200114 struct module *owner;
115 struct ccw_device_id *ids;
116 int (*probe) (struct ccw_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 void (*remove) (struct ccw_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 int (*set_online) (struct ccw_device *);
119 int (*set_offline) (struct ccw_device *);
120 int (*notify) (struct ccw_device *, int);
Cornelia Huck958974fb2007-10-12 16:11:21 +0200121 void (*shutdown) (struct ccw_device *);
Sebastian Ott823d4942009-06-16 10:30:20 +0200122 int (*prepare) (struct ccw_device *);
123 void (*complete) (struct ccw_device *);
124 int (*freeze)(struct ccw_device *);
125 int (*thaw) (struct ccw_device *);
126 int (*restore)(struct ccw_device *);
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200127 struct device_driver driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 char *name;
129};
130
131extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
132 const char *bus_id);
133
134/* devices drivers call these during module load and unload.
135 * When a driver is registered, its probe method is called
136 * when new devices for its type pop up */
137extern int ccw_driver_register (struct ccw_driver *driver);
138extern void ccw_driver_unregister (struct ccw_driver *driver);
139
140struct ccw1;
141
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100142extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143extern int ccw_device_set_options(struct ccw_device *, unsigned long);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100144extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146/* Allow for i/o completion notification after primary interrupt status. */
147#define CCWDEV_EARLY_NOTIFICATION 0x0001
148/* Report all interrupt conditions. */
149#define CCWDEV_REPORT_ALL 0x0002
150/* Try to perform path grouping. */
151#define CCWDEV_DO_PATHGROUP 0x0004
152/* Allow forced onlining of boxed devices. */
153#define CCWDEV_ALLOW_FORCE 0x0008
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
156 unsigned long, __u8, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
158 unsigned long, __u8, unsigned long, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
160 unsigned long, __u8, __u8, unsigned long);
161extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
162 unsigned long, __u8, __u8,
163 unsigned long, int);
164
165
166extern int ccw_device_resume(struct ccw_device *);
167extern int ccw_device_halt(struct ccw_device *, unsigned long);
168extern int ccw_device_clear(struct ccw_device *, unsigned long);
Peter Oberparleiter83262d62008-07-14 09:58:51 +0200169int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
170 unsigned long intparm, u8 lpm, u8 key);
171int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
172 unsigned long, u8, u8);
173int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
174 unsigned long, u8, u8, int);
175int ccw_device_tm_start(struct ccw_device *, struct tcw *,
176 unsigned long, u8);
177int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
178 unsigned long, u8, int);
179int ccw_device_tm_intrg(struct ccw_device *cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181extern int ccw_device_set_online(struct ccw_device *cdev);
182extern int ccw_device_set_offline(struct ccw_device *cdev);
183
184
185extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
186extern __u8 ccw_device_get_path_mask(struct ccw_device *);
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200187extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189#define get_ccwdev_lock(x) (x)->ccwlock
190
191#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
192#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
193
194extern struct ccw_device *ccw_device_probe_console(void);
Martin Schwidefsky66648452009-06-16 10:30:28 +0200195extern int ccw_device_force_console(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197// FIXME: these have to go
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198extern int _ccw_device_get_subchannel_number(struct ccw_device *);
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
201#endif /* _S390_CCWDEV_H_ */