Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
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 | |
| 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 | */ |
| 41 | static inline const struct ccw_device_id * |
| 42 | ccw_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 Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 67 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 70 | /** |
| 71 | * struct ccw_device - channel attached device |
| 72 | * @ccwlock: pointer to device lock |
| 73 | * @id: id of this device |
| 74 | * @drv: ccw driver for this device |
| 75 | * @dev: embedded device structure |
| 76 | * @online: online status of device |
| 77 | * @handler: interrupt handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 79 | * @handler is a member of the device rather than the driver since a driver |
| 80 | * can have different interrupt handlers for different ccw devices |
| 81 | * (multi-subchannel drivers). |
| 82 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | struct ccw_device { |
| 84 | spinlock_t *ccwlock; |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 85 | /* private: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct ccw_device_private *private; /* cio private information */ |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 87 | /* public: */ |
| 88 | struct ccw_device_id id; |
| 89 | struct ccw_driver *drv; |
| 90 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int online; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | void (*handler) (struct ccw_device *, unsigned long, struct irb *); |
| 93 | }; |
| 94 | |
| 95 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 96 | /** |
| 97 | * struct ccw driver - device driver for channel attached devices |
| 98 | * @owner: owning module |
| 99 | * @ids: ids supported by this driver |
| 100 | * @probe: function called on probe |
| 101 | * @remove: function called on remove |
| 102 | * @set_online: called when setting device online |
| 103 | * @set_offline: called when setting device offline |
| 104 | * @notify: notify driver of device state changes |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 105 | * @shutdown: called at device shutdown |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 106 | * @driver: embedded device driver structure |
| 107 | * @name: device driver name |
| 108 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | struct ccw_driver { |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 110 | struct module *owner; |
| 111 | struct ccw_device_id *ids; |
| 112 | int (*probe) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | void (*remove) (struct ccw_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | int (*set_online) (struct ccw_device *); |
| 115 | int (*set_offline) (struct ccw_device *); |
| 116 | int (*notify) (struct ccw_device *, int); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 117 | void (*shutdown) (struct ccw_device *); |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 118 | struct device_driver driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | char *name; |
| 120 | }; |
| 121 | |
| 122 | extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 123 | const char *bus_id); |
| 124 | |
| 125 | /* devices drivers call these during module load and unload. |
| 126 | * When a driver is registered, its probe method is called |
| 127 | * when new devices for its type pop up */ |
| 128 | extern int ccw_driver_register (struct ccw_driver *driver); |
| 129 | extern void ccw_driver_unregister (struct ccw_driver *driver); |
| 130 | |
| 131 | struct ccw1; |
| 132 | |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 133 | extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | extern int ccw_device_set_options(struct ccw_device *, unsigned long); |
Cornelia Huck | 4dd3cc5 | 2007-02-12 15:47:18 +0100 | [diff] [blame] | 135 | extern void ccw_device_clear_options(struct ccw_device *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* Allow for i/o completion notification after primary interrupt status. */ |
| 138 | #define CCWDEV_EARLY_NOTIFICATION 0x0001 |
| 139 | /* Report all interrupt conditions. */ |
| 140 | #define CCWDEV_REPORT_ALL 0x0002 |
| 141 | /* Try to perform path grouping. */ |
| 142 | #define CCWDEV_DO_PATHGROUP 0x0004 |
| 143 | /* Allow forced onlining of boxed devices. */ |
| 144 | #define CCWDEV_ALLOW_FORCE 0x0008 |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | extern int ccw_device_start(struct ccw_device *, struct ccw1 *, |
| 147 | unsigned long, __u8, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *, |
| 149 | unsigned long, __u8, unsigned long, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *, |
| 151 | unsigned long, __u8, __u8, unsigned long); |
| 152 | extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *, |
| 153 | unsigned long, __u8, __u8, |
| 154 | unsigned long, int); |
| 155 | |
| 156 | |
| 157 | extern int ccw_device_resume(struct ccw_device *); |
| 158 | extern int ccw_device_halt(struct ccw_device *, unsigned long); |
| 159 | extern int ccw_device_clear(struct ccw_device *, unsigned long); |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | extern int ccw_device_set_online(struct ccw_device *cdev); |
| 162 | extern int ccw_device_set_offline(struct ccw_device *cdev); |
| 163 | |
| 164 | |
| 165 | extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd); |
| 166 | extern __u8 ccw_device_get_path_mask(struct ccw_device *); |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 167 | 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] | 168 | |
| 169 | #define get_ccwdev_lock(x) (x)->ccwlock |
| 170 | |
| 171 | #define to_ccwdev(n) container_of(n, struct ccw_device, dev) |
| 172 | #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver) |
| 173 | |
| 174 | extern struct ccw_device *ccw_device_probe_console(void); |
| 175 | |
| 176 | // FIXME: these have to go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | extern int _ccw_device_get_subchannel_number(struct ccw_device *); |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | extern void *ccw_device_get_chp_desc(struct ccw_device *, int); |
| 180 | #endif /* _S390_CCWDEV_H_ */ |