blob: 4c2e1710f15724ad7d170adb25723683245a30e1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
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
70/* The struct ccw device is our replacement for the globally accessible
71 * ioinfo array. ioinfo will mutate into a subchannel device later.
72 *
73 * Reference: Documentation/s390/driver-model.txt */
74struct ccw_device {
75 spinlock_t *ccwlock;
76 struct ccw_device_private *private; /* cio private information */
77 struct ccw_device_id id; /* id of this device, driver_info is
78 set by ccw_find_driver */
79 struct ccw_driver *drv; /* */
80 struct device dev; /* */
81 int online;
82 /* This is sick, but a driver can have different interrupt handlers
83 for different ccw_devices (multi-subchannel drivers)... */
84 void (*handler) (struct ccw_device *, unsigned long, struct irb *);
85};
86
87
88/* Each ccw driver registers with the ccw root bus */
89struct ccw_driver {
90 struct module *owner; /* for automatic MOD_INC_USE_COUNT */
91 struct ccw_device_id *ids; /* probe driver with these devs */
92 int (*probe) (struct ccw_device *); /* ask driver to probe dev */
93 void (*remove) (struct ccw_device *);
94 /* device is no longer available */
95 int (*set_online) (struct ccw_device *);
96 int (*set_offline) (struct ccw_device *);
97 int (*notify) (struct ccw_device *, int);
98 struct device_driver driver; /* higher level structure, don't init
99 this from your driver */
100 char *name;
101};
102
103extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
104 const char *bus_id);
105
106/* devices drivers call these during module load and unload.
107 * When a driver is registered, its probe method is called
108 * when new devices for its type pop up */
109extern int ccw_driver_register (struct ccw_driver *driver);
110extern void ccw_driver_unregister (struct ccw_driver *driver);
111
112struct ccw1;
113
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100114extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern int ccw_device_set_options(struct ccw_device *, unsigned long);
Cornelia Huck4dd3cc52007-02-12 15:47:18 +0100116extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/* Allow for i/o completion notification after primary interrupt status. */
119#define CCWDEV_EARLY_NOTIFICATION 0x0001
120/* Report all interrupt conditions. */
121#define CCWDEV_REPORT_ALL 0x0002
122/* Try to perform path grouping. */
123#define CCWDEV_DO_PATHGROUP 0x0004
124/* Allow forced onlining of boxed devices. */
125#define CCWDEV_ALLOW_FORCE 0x0008
126
127/*
128 * ccw_device_start()
129 *
130 * Start a S/390 channel program. When the interrupt arrives, the
131 * IRQ handler is called, either immediately, delayed (dev-end missing,
132 * or sense required) or never (no IRQ handler registered).
133 * Depending on the action taken, ccw_device_start() returns:
134 * 0 - Success
135 * -EBUSY - Device busy, or status pending
136 * -ENODEV - Device not operational
137 * -EINVAL - Device invalid for operation
138 */
139extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
140 unsigned long, __u8, unsigned long);
141/*
142 * ccw_device_start_timeout()
143 *
144 * This function notifies the device driver if the channel program has not
145 * completed during the specified time. If a timeout occurs, the channel
146 * program is terminated via xsch(), hsch() or csch().
147 */
148extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
149 unsigned long, __u8, unsigned long, int);
150/*
151 * ccw_device_start_key()
152 * ccw_device_start_key_timeout()
153 *
154 * Same as ccw_device_start() and ccw_device_start_timeout(), except a
155 * storage key != default key can be provided for the I/O.
156 */
157extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
158 unsigned long, __u8, __u8, unsigned long);
159extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
160 unsigned long, __u8, __u8,
161 unsigned long, int);
162
163
164extern int ccw_device_resume(struct ccw_device *);
165extern int ccw_device_halt(struct ccw_device *, unsigned long);
166extern int ccw_device_clear(struct ccw_device *, unsigned long);
167
Cornelia Huck52706ec2007-05-04 18:47:50 +0200168extern int __deprecated read_dev_chars(struct ccw_device *cdev, void **buffer, int length);
169extern int __deprecated read_conf_data(struct ccw_device *cdev, void **buffer, int *length);
170extern int __deprecated read_conf_data_lpm(struct ccw_device *cdev, void **buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 int *length, __u8 lpm);
172
173extern int ccw_device_set_online(struct ccw_device *cdev);
174extern int ccw_device_set_offline(struct ccw_device *cdev);
175
176
177extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
178extern __u8 ccw_device_get_path_mask(struct ccw_device *);
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200179extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181#define get_ccwdev_lock(x) (x)->ccwlock
182
183#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
184#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
185
186extern struct ccw_device *ccw_device_probe_console(void);
187
188// FIXME: these have to go
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189extern int _ccw_device_get_subchannel_number(struct ccw_device *);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
192#endif /* _S390_CCWDEV_H_ */