vserver 2.0 rc7
[linux-2.6.git] / include / asm-s390 / ccwdev.h
1 /*
2  *  include/asm-s390/ccwdev.h
3  *  include/asm-s390x/ccwdev.h
4  *
5  *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Arnd Bergmann <arndb@de.ibm.com>
7  *
8  *  Interface for CCW device drivers
9  */
10 #ifndef _S390_CCWDEV_H_
11 #define _S390_CCWDEV_H_
12
13 #include <linux/device.h>
14 #include <linux/mod_devicetable.h>
15
16 /* structs from asm/cio.h */
17 struct irb;
18 struct ccw1;
19
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  */
40 static inline const struct ccw_device_id *
41 ccw_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
66         return 0;
67 }
68
69 /* The struct ccw device is our replacement for the globally accessible
70  * ioinfo array. ioinfo will mutate into a subchannel device later.
71  *
72  * Reference: Documentation/s390/driver-model.txt */
73 struct ccw_device {
74         spinlock_t *ccwlock;
75         struct ccw_device_private *private;     /* cio private information */
76         struct ccw_device_id id;        /* id of this device, driver_info is
77                                            set by ccw_find_driver */
78         struct ccw_driver *drv;         /* */
79         struct device dev;              /* */
80         int online;
81         /* This is sick, but a driver can have different interrupt handlers 
82            for different ccw_devices (multi-subchannel drivers)... */
83         void (*handler) (struct ccw_device *, unsigned long, struct irb *);
84 };
85
86
87 /* Each ccw driver registers with the ccw root bus */
88 struct ccw_driver {
89         struct module *owner;           /* for automatic MOD_INC_USE_COUNT   */
90         struct ccw_device_id *ids;      /* probe driver with these devs      */
91         int (*probe) (struct ccw_device *); /* ask driver to probe dev       */
92         void (*remove) (struct ccw_device *);
93                                         /* device is no longer available     */
94         int (*set_online) (struct ccw_device *);
95         int (*set_offline) (struct ccw_device *);
96         int (*notify) (struct ccw_device *, int);
97         struct device_driver driver;    /* higher level structure, don't init
98                                            this from your driver             */
99         char *name;
100 };
101
102 extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
103                                               const char *bus_id);
104
105 /* devices drivers call these during module load and unload.
106  * When a driver is registered, its probe method is called
107  * when new devices for its type pop up */
108 extern int  ccw_driver_register   (struct ccw_driver *driver);
109 extern void ccw_driver_unregister (struct ccw_driver *driver);
110
111 struct ccw1;
112
113 extern int ccw_device_set_options(struct ccw_device *, unsigned long);
114
115 /* Allow for i/o completion notification after primary interrupt status. */
116 #define CCWDEV_EARLY_NOTIFICATION       0x0001
117 /* Report all interrupt conditions. */
118 #define CCWDEV_REPORT_ALL               0x0002
119 /* Try to perform path grouping. */
120 #define CCWDEV_DO_PATHGROUP             0x0004
121 /* Allow forced onlining of boxed devices. */
122 #define CCWDEV_ALLOW_FORCE              0x0008
123
124 /*
125  * ccw_device_start()
126  *
127  *  Start a S/390 channel program. When the interrupt arrives, the
128  *  IRQ handler is called, either immediately, delayed (dev-end missing,
129  *  or sense required) or never (no IRQ handler registered).
130  *  Depending on the action taken, ccw_device_start() returns:  
131  *                           0       - Success
132  *                           -EBUSY  - Device busy, or status pending
133  *                           -ENODEV - Device not operational
134  *                           -EINVAL - Device invalid for operation
135  */
136 extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
137                             unsigned long, __u8, unsigned long);
138 /*
139  * ccw_device_start_timeout()
140  *
141  * This function notifies the device driver if the channel program has not
142  * completed during the specified time. If a timeout occurs, the channel
143  * program is terminated via xsch(), hsch() or csch().
144  */
145 extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
146                                     unsigned long, __u8, unsigned long, int);
147 /*
148  * ccw_device_start_key()
149  * ccw_device_start_key_timeout()
150  *
151  * Same as ccw_device_start() and ccw_device_start_timeout(), except a
152  * storage key != default key can be provided for the I/O.
153  */
154 extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
155                                 unsigned long, __u8, __u8, unsigned long);
156 extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
157                                         unsigned long, __u8, __u8,
158                                         unsigned long, int);
159
160
161 extern int ccw_device_resume(struct ccw_device *);
162 extern int ccw_device_halt(struct ccw_device *, unsigned long);
163 extern int ccw_device_clear(struct ccw_device *, unsigned long);
164
165 extern int read_dev_chars(struct ccw_device *cdev, void **buffer, int length);
166 extern int read_conf_data(struct ccw_device *cdev, void **buffer, int *length);
167 extern int read_conf_data_lpm(struct ccw_device *cdev, void **buffer,
168                               int *length, __u8 lpm);
169
170 extern int ccw_device_set_online(struct ccw_device *cdev);
171 extern int ccw_device_set_offline(struct ccw_device *cdev);
172
173
174 extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
175 extern __u8 ccw_device_get_path_mask(struct ccw_device *);
176
177 #define get_ccwdev_lock(x) (x)->ccwlock
178
179 #define to_ccwdev(n) container_of(n, struct ccw_device, dev)
180 #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
181
182 extern struct ccw_device *ccw_device_probe_console(void);
183
184 // FIXME: these have to go
185 extern int _ccw_device_get_device_number(struct ccw_device *);
186 extern int _ccw_device_get_subchannel_number(struct ccw_device *);
187
188 extern struct device *s390_root_dev_register(const char *);
189 extern void s390_root_dev_unregister(struct device *);
190
191 extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
192 #endif /* _S390_CCWDEV_H_ */