Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +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> |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 14 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | /* structs from asm/cio.h */ |
| 17 | struct irb; |
| 18 | struct ccw1; |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 19 | struct ccw_dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Cornelia Huck | 9368dac | 2012-05-30 16:03:22 +0200 | [diff] [blame^] | 21 | /* from asm/schid.h */ |
| 22 | struct subchannel_id; |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* simplified initializers for struct ccw_device: |
| 25 | * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one |
| 26 | * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */ |
| 27 | #define CCW_DEVICE(cu, cum) \ |
| 28 | .cu_type=(cu), .cu_model=(cum), \ |
| 29 | .match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE \ |
| 30 | | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0)) |
| 31 | |
| 32 | #define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm) \ |
| 33 | .cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\ |
| 34 | .match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE \ |
| 35 | | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) \ |
| 36 | | CCW_DEVICE_ID_MATCH_DEVICE_TYPE \ |
| 37 | | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0) |
| 38 | |
| 39 | /* scan through an array of device ids and return the first |
| 40 | * entry that matches the device. |
| 41 | * |
| 42 | * the array must end with an entry containing zero match_flags |
| 43 | */ |
| 44 | static inline const struct ccw_device_id * |
| 45 | ccw_device_id_match(const struct ccw_device_id *array, |
| 46 | const struct ccw_device_id *match) |
| 47 | { |
| 48 | const struct ccw_device_id *id = array; |
| 49 | |
| 50 | for (id = array; id->match_flags; id++) { |
| 51 | if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE) |
| 52 | && (id->cu_type != match->cu_type)) |
| 53 | continue; |
| 54 | |
| 55 | if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL) |
| 56 | && (id->cu_model != match->cu_model)) |
| 57 | continue; |
| 58 | |
| 59 | if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE) |
| 60 | && (id->dev_type != match->dev_type)) |
| 61 | continue; |
| 62 | |
| 63 | if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL) |
| 64 | && (id->dev_model != match->dev_model)) |
| 65 | continue; |
| 66 | |
| 67 | return id; |
| 68 | } |
| 69 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 70 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 73 | /** |
| 74 | * struct ccw_device - channel attached device |
| 75 | * @ccwlock: pointer to device lock |
| 76 | * @id: id of this device |
| 77 | * @drv: ccw driver for this device |
| 78 | * @dev: embedded device structure |
| 79 | * @online: online status of device |
| 80 | * @handler: interrupt handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 82 | * @handler is a member of the device rather than the driver since a driver |
| 83 | * can have different interrupt handlers for different ccw devices |
| 84 | * (multi-subchannel drivers). |
| 85 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct ccw_device { |
| 87 | spinlock_t *ccwlock; |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 88 | /* private: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | struct ccw_device_private *private; /* cio private information */ |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 90 | /* public: */ |
| 91 | struct ccw_device_id id; |
| 92 | struct ccw_driver *drv; |
| 93 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | int online; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | void (*handler) (struct ccw_device *, unsigned long, struct irb *); |
| 96 | }; |
| 97 | |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 98 | /* |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 99 | * Possible events used by the path_event notifier. |
| 100 | */ |
| 101 | #define PE_NONE 0x0 |
| 102 | #define PE_PATH_GONE 0x1 /* A path is no longer available. */ |
| 103 | #define PE_PATH_AVAILABLE 0x2 /* A path has become available and |
| 104 | was successfully verified. */ |
| 105 | #define PE_PATHGROUP_ESTABLISHED 0x4 /* A pathgroup was reset and had |
| 106 | to be established again. */ |
| 107 | |
| 108 | /* |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 109 | * Possible CIO actions triggered by the unit check handler. |
| 110 | */ |
| 111 | enum uc_todo { |
| 112 | UC_TODO_RETRY, |
| 113 | UC_TODO_RETRY_ON_NEW_PATH, |
| 114 | UC_TODO_STOP |
| 115 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 117 | /** |
| 118 | * struct ccw driver - device driver for channel attached devices |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 119 | * @ids: ids supported by this driver |
| 120 | * @probe: function called on probe |
| 121 | * @remove: function called on remove |
| 122 | * @set_online: called when setting device online |
| 123 | * @set_offline: called when setting device offline |
| 124 | * @notify: notify driver of device state changes |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 125 | * @path_event: notify driver of channel path events |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 126 | * @shutdown: called at device shutdown |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 127 | * @prepare: prepare for pm state transition |
| 128 | * @complete: undo work done in @prepare |
| 129 | * @freeze: callback for freezing during hibernation snapshotting |
| 130 | * @thaw: undo work done in @freeze |
| 131 | * @restore: callback for restoring after hibernation |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 132 | * @uc_handler: callback for unit check handler |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 133 | * @driver: embedded device driver structure |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 134 | * @int_class: interruption class to use for accounting interrupts |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 135 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | struct ccw_driver { |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 137 | struct ccw_device_id *ids; |
| 138 | int (*probe) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | void (*remove) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | int (*set_online) (struct ccw_device *); |
| 141 | int (*set_offline) (struct ccw_device *); |
| 142 | int (*notify) (struct ccw_device *, int); |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 143 | void (*path_event) (struct ccw_device *, int *); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 144 | void (*shutdown) (struct ccw_device *); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 145 | int (*prepare) (struct ccw_device *); |
| 146 | void (*complete) (struct ccw_device *); |
| 147 | int (*freeze)(struct ccw_device *); |
| 148 | int (*thaw) (struct ccw_device *); |
| 149 | int (*restore)(struct ccw_device *); |
Michael Ernst | 094f210 | 2010-05-26 23:27:08 +0200 | [diff] [blame] | 150 | enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *); |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 151 | struct device_driver driver; |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 152 | enum interruption_class int_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 156 | const char *bus_id); |
| 157 | |
| 158 | /* devices drivers call these during module load and unload. |
| 159 | * When a driver is registered, its probe method is called |
| 160 | * when new devices for its type pop up */ |
| 161 | extern int ccw_driver_register (struct ccw_driver *driver); |
| 162 | extern void ccw_driver_unregister (struct ccw_driver *driver); |
| 163 | |
| 164 | struct ccw1; |
| 165 | |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 166 | extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | extern int ccw_device_set_options(struct ccw_device *, unsigned long); |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 168 | extern void ccw_device_clear_options(struct ccw_device *, unsigned long); |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 169 | int ccw_device_is_pathgroup(struct ccw_device *cdev); |
| 170 | int ccw_device_is_multipath(struct ccw_device *cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* Allow for i/o completion notification after primary interrupt status. */ |
| 173 | #define CCWDEV_EARLY_NOTIFICATION 0x0001 |
| 174 | /* Report all interrupt conditions. */ |
| 175 | #define CCWDEV_REPORT_ALL 0x0002 |
| 176 | /* Try to perform path grouping. */ |
| 177 | #define CCWDEV_DO_PATHGROUP 0x0004 |
| 178 | /* Allow forced onlining of boxed devices. */ |
| 179 | #define CCWDEV_ALLOW_FORCE 0x0008 |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 180 | /* Try to use multipath mode. */ |
| 181 | #define CCWDEV_DO_MULTIPATH 0x0010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | extern int ccw_device_start(struct ccw_device *, struct ccw1 *, |
| 184 | unsigned long, __u8, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *, |
| 186 | unsigned long, __u8, unsigned long, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *, |
| 188 | unsigned long, __u8, __u8, unsigned long); |
| 189 | extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *, |
| 190 | unsigned long, __u8, __u8, |
| 191 | unsigned long, int); |
| 192 | |
| 193 | |
| 194 | extern int ccw_device_resume(struct ccw_device *); |
| 195 | extern int ccw_device_halt(struct ccw_device *, unsigned long); |
| 196 | extern int ccw_device_clear(struct ccw_device *, unsigned long); |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 197 | int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw, |
| 198 | unsigned long intparm, u8 lpm, u8 key); |
| 199 | int ccw_device_tm_start_key(struct ccw_device *, struct tcw *, |
| 200 | unsigned long, u8, u8); |
| 201 | int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *, |
| 202 | unsigned long, u8, u8, int); |
| 203 | int ccw_device_tm_start(struct ccw_device *, struct tcw *, |
| 204 | unsigned long, u8); |
| 205 | int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *, |
| 206 | unsigned long, u8, int); |
| 207 | int ccw_device_tm_intrg(struct ccw_device *cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Sebastian Ott | ce322cc | 2011-01-05 12:47:56 +0100 | [diff] [blame] | 209 | int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask); |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | extern int ccw_device_set_online(struct ccw_device *cdev); |
| 212 | extern int ccw_device_set_offline(struct ccw_device *cdev); |
| 213 | |
| 214 | |
| 215 | extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd); |
| 216 | extern __u8 ccw_device_get_path_mask(struct ccw_device *); |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 217 | 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] | 218 | |
| 219 | #define get_ccwdev_lock(x) (x)->ccwlock |
| 220 | |
| 221 | #define to_ccwdev(n) container_of(n, struct ccw_device, dev) |
| 222 | #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver) |
| 223 | |
| 224 | extern struct ccw_device *ccw_device_probe_console(void); |
Martin Schwidefsky | 6664845 | 2009-06-16 10:30:28 +0200 | [diff] [blame] | 225 | extern int ccw_device_force_console(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 227 | int ccw_device_siosl(struct ccw_device *); |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | // FIXME: these have to go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | extern int _ccw_device_get_subchannel_number(struct ccw_device *); |
| 231 | |
Cornelia Huck | 9368dac | 2012-05-30 16:03:22 +0200 | [diff] [blame^] | 232 | extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *); |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | extern void *ccw_device_get_chp_desc(struct ccw_device *, int); |
| 235 | #endif /* _S390_CCWDEV_H_ */ |