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