Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2002, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 4 | * Author(s): Arnd Bergmann <arndb@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 6 | * Interface for CCW device drivers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | #ifndef _S390_CCWDEV_H_ |
| 9 | #define _S390_CCWDEV_H_ |
| 10 | |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/mod_devicetable.h> |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 13 | #include <asm/fcx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | /* structs from asm/cio.h */ |
| 16 | struct irb; |
| 17 | struct ccw1; |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 18 | struct ccw_dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 66 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 69 | /** |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 78 | * @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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct ccw_device { |
| 83 | spinlock_t *ccwlock; |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 84 | /* private: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | struct ccw_device_private *private; /* cio private information */ |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 86 | /* public: */ |
| 87 | struct ccw_device_id id; |
| 88 | struct ccw_driver *drv; |
| 89 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | int online; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | void (*handler) (struct ccw_device *, unsigned long, struct irb *); |
| 92 | }; |
| 93 | |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 94 | /* |
| 95 | * Possible CIO actions triggered by the unit check handler. |
| 96 | */ |
| 97 | enum uc_todo { |
| 98 | UC_TODO_RETRY, |
| 99 | UC_TODO_RETRY_ON_NEW_PATH, |
| 100 | UC_TODO_STOP |
| 101 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 103 | /** |
| 104 | * struct ccw driver - device driver for channel attached devices |
| 105 | * @owner: owning module |
| 106 | * @ids: ids supported by this driver |
| 107 | * @probe: function called on probe |
| 108 | * @remove: function called on remove |
| 109 | * @set_online: called when setting device online |
| 110 | * @set_offline: called when setting device offline |
| 111 | * @notify: notify driver of device state changes |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 112 | * @shutdown: called at device shutdown |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 113 | * @prepare: prepare for pm state transition |
| 114 | * @complete: undo work done in @prepare |
| 115 | * @freeze: callback for freezing during hibernation snapshotting |
| 116 | * @thaw: undo work done in @freeze |
| 117 | * @restore: callback for restoring after hibernation |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 118 | * @uc_handler: callback for unit check handler |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 119 | * @driver: embedded device driver structure |
| 120 | * @name: device driver name |
| 121 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | struct ccw_driver { |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 123 | struct module *owner; |
| 124 | struct ccw_device_id *ids; |
| 125 | int (*probe) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | void (*remove) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int (*set_online) (struct ccw_device *); |
| 128 | int (*set_offline) (struct ccw_device *); |
| 129 | int (*notify) (struct ccw_device *, int); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 130 | void (*shutdown) (struct ccw_device *); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 131 | int (*prepare) (struct ccw_device *); |
| 132 | void (*complete) (struct ccw_device *); |
| 133 | int (*freeze)(struct ccw_device *); |
| 134 | int (*thaw) (struct ccw_device *); |
| 135 | int (*restore)(struct ccw_device *); |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 136 | enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *); |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 137 | struct device_driver driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | char *name; |
| 139 | }; |
| 140 | |
| 141 | extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 142 | const char *bus_id); |
| 143 | |
| 144 | /* devices drivers call these during module load and unload. |
| 145 | * When a driver is registered, its probe method is called |
| 146 | * when new devices for its type pop up */ |
| 147 | extern int ccw_driver_register (struct ccw_driver *driver); |
| 148 | extern void ccw_driver_unregister (struct ccw_driver *driver); |
| 149 | |
| 150 | struct ccw1; |
| 151 | |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 152 | extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | extern int ccw_device_set_options(struct ccw_device *, unsigned long); |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 154 | extern void ccw_device_clear_options(struct ccw_device *, unsigned long); |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 155 | int ccw_device_is_pathgroup(struct ccw_device *cdev); |
| 156 | int ccw_device_is_multipath(struct ccw_device *cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | /* Allow for i/o completion notification after primary interrupt status. */ |
| 159 | #define CCWDEV_EARLY_NOTIFICATION 0x0001 |
| 160 | /* Report all interrupt conditions. */ |
| 161 | #define CCWDEV_REPORT_ALL 0x0002 |
| 162 | /* Try to perform path grouping. */ |
| 163 | #define CCWDEV_DO_PATHGROUP 0x0004 |
| 164 | /* Allow forced onlining of boxed devices. */ |
| 165 | #define CCWDEV_ALLOW_FORCE 0x0008 |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 166 | /* Try to use multipath mode. */ |
| 167 | #define CCWDEV_DO_MULTIPATH 0x0010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | extern int ccw_device_start(struct ccw_device *, struct ccw1 *, |
| 170 | unsigned long, __u8, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *, |
| 172 | unsigned long, __u8, unsigned long, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *, |
| 174 | unsigned long, __u8, __u8, unsigned long); |
| 175 | extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *, |
| 176 | unsigned long, __u8, __u8, |
| 177 | unsigned long, int); |
| 178 | |
| 179 | |
| 180 | extern int ccw_device_resume(struct ccw_device *); |
| 181 | extern int ccw_device_halt(struct ccw_device *, unsigned long); |
| 182 | extern int ccw_device_clear(struct ccw_device *, unsigned long); |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 183 | int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw, |
| 184 | unsigned long intparm, u8 lpm, u8 key); |
| 185 | int ccw_device_tm_start_key(struct ccw_device *, struct tcw *, |
| 186 | unsigned long, u8, u8); |
| 187 | int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *, |
| 188 | unsigned long, u8, u8, int); |
| 189 | int ccw_device_tm_start(struct ccw_device *, struct tcw *, |
| 190 | unsigned long, u8); |
| 191 | int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *, |
| 192 | unsigned long, u8, int); |
| 193 | int ccw_device_tm_intrg(struct ccw_device *cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | extern int ccw_device_set_online(struct ccw_device *cdev); |
| 196 | extern int ccw_device_set_offline(struct ccw_device *cdev); |
| 197 | |
| 198 | |
| 199 | extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd); |
| 200 | extern __u8 ccw_device_get_path_mask(struct ccw_device *); |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 201 | extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | #define get_ccwdev_lock(x) (x)->ccwlock |
| 204 | |
| 205 | #define to_ccwdev(n) container_of(n, struct ccw_device, dev) |
| 206 | #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver) |
| 207 | |
| 208 | extern struct ccw_device *ccw_device_probe_console(void); |
Martin Schwidefsky | 6664845 | 2009-06-16 10:30:28 +0200 | [diff] [blame] | 209 | extern int ccw_device_force_console(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 211 | int ccw_device_siosl(struct ccw_device *); |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | // FIXME: these have to go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | extern int _ccw_device_get_subchannel_number(struct ccw_device *); |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | extern void *ccw_device_get_chp_desc(struct ccw_device *, int); |
| 217 | #endif /* _S390_CCWDEV_H_ */ |