ccwdev.h 7.2 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 * Copyright  IBM Corp. 2002, 2009
L
Linus Torvalds 已提交
3
 *
4
 * Author(s): Arnd Bergmann <arndb@de.ibm.com>
L
Linus Torvalds 已提交
5
 *
6
 * Interface for CCW device drivers
L
Linus Torvalds 已提交
7 8 9 10 11 12
 */
#ifndef _S390_CCWDEV_H_
#define _S390_CCWDEV_H_

#include <linux/device.h>
#include <linux/mod_devicetable.h>
13
#include <asm/fcx.h>
L
Linus Torvalds 已提交
14 15 16 17

/* structs from asm/cio.h */
struct irb;
struct ccw1;
18
struct ccw_dev_id;
L
Linus Torvalds 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

/* simplified initializers for struct ccw_device:
 * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
 * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
#define CCW_DEVICE(cu, cum) 						\
	.cu_type=(cu), .cu_model=(cum),					\
	.match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE			\
		   | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))

#define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm)				\
	.cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
	.match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE			\
		   | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0) 	\
		   | CCW_DEVICE_ID_MATCH_DEVICE_TYPE			\
		   | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)

/* scan through an array of device ids and return the first
 * entry that matches the device.
 *
 * the array must end with an entry containing zero match_flags
 */
static inline const struct ccw_device_id *
ccw_device_id_match(const struct ccw_device_id *array,
			const struct ccw_device_id *match)
{
	const struct ccw_device_id *id = array;

	for (id = array; id->match_flags; id++) {
		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
		    && (id->cu_type != match->cu_type))
			continue;

		if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
		    && (id->cu_model != match->cu_model))
			continue;

		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
		    && (id->dev_type != match->dev_type))
			continue;

		if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
		    && (id->dev_model != match->dev_model))
			continue;

		return id;
	}

H
Heiko Carstens 已提交
66
	return NULL;
L
Linus Torvalds 已提交
67 68
}

C
Cornelia Huck 已提交
69 70 71 72 73 74 75 76
/**
 * struct ccw_device - channel attached device
 * @ccwlock: pointer to device lock
 * @id: id of this device
 * @drv: ccw driver for this device
 * @dev: embedded device structure
 * @online: online status of device
 * @handler: interrupt handler
L
Linus Torvalds 已提交
77
 *
C
Cornelia Huck 已提交
78 79 80 81
 * @handler is a member of the device rather than the driver since a driver
 * can have different interrupt handlers for different ccw devices
 * (multi-subchannel drivers).
 */
L
Linus Torvalds 已提交
82 83
struct ccw_device {
	spinlock_t *ccwlock;
C
Cornelia Huck 已提交
84
/* private: */
L
Linus Torvalds 已提交
85
	struct ccw_device_private *private;	/* cio private information */
C
Cornelia Huck 已提交
86 87 88 89
/* public: */
	struct ccw_device_id id;
	struct ccw_driver *drv;
	struct device dev;
L
Linus Torvalds 已提交
90 91 92 93
	int online;
	void (*handler) (struct ccw_device *, unsigned long, struct irb *);
};

94 95 96 97 98 99 100 101
/*
 * Possible CIO actions triggered by the unit check handler.
 */
enum uc_todo {
	UC_TODO_RETRY,
	UC_TODO_RETRY_ON_NEW_PATH,
	UC_TODO_STOP
};
L
Linus Torvalds 已提交
102

C
Cornelia Huck 已提交
103 104 105 106 107 108 109 110 111
/**
 * struct ccw driver - device driver for channel attached devices
 * @owner: owning module
 * @ids: ids supported by this driver
 * @probe: function called on probe
 * @remove: function called on remove
 * @set_online: called when setting device online
 * @set_offline: called when setting device offline
 * @notify: notify driver of device state changes
112
 * @shutdown: called at device shutdown
113 114 115 116 117
 * @prepare: prepare for pm state transition
 * @complete: undo work done in @prepare
 * @freeze: callback for freezing during hibernation snapshotting
 * @thaw: undo work done in @freeze
 * @restore: callback for restoring after hibernation
118
 * @uc_handler: callback for unit check handler
C
Cornelia Huck 已提交
119 120 121
 * @driver: embedded device driver structure
 * @name: device driver name
 */
L
Linus Torvalds 已提交
122
struct ccw_driver {
C
Cornelia Huck 已提交
123 124 125
	struct module *owner;
	struct ccw_device_id *ids;
	int (*probe) (struct ccw_device *);
L
Linus Torvalds 已提交
126 127 128 129
	void (*remove) (struct ccw_device *);
	int (*set_online) (struct ccw_device *);
	int (*set_offline) (struct ccw_device *);
	int (*notify) (struct ccw_device *, int);
130
	void (*shutdown) (struct ccw_device *);
131 132 133 134 135
	int (*prepare) (struct ccw_device *);
	void (*complete) (struct ccw_device *);
	int (*freeze)(struct ccw_device *);
	int (*thaw) (struct ccw_device *);
	int (*restore)(struct ccw_device *);
136
	enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
C
Cornelia Huck 已提交
137
	struct device_driver driver;
L
Linus Torvalds 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151
	char *name;
};

extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
					      const char *bus_id);

/* devices drivers call these during module load and unload.
 * When a driver is registered, its probe method is called
 * when new devices for its type pop up */
extern int  ccw_driver_register   (struct ccw_driver *driver);
extern void ccw_driver_unregister (struct ccw_driver *driver);

struct ccw1;

152
extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
L
Linus Torvalds 已提交
153
extern int ccw_device_set_options(struct ccw_device *, unsigned long);
154
extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
155 156
int ccw_device_is_pathgroup(struct ccw_device *cdev);
int ccw_device_is_multipath(struct ccw_device *cdev);
L
Linus Torvalds 已提交
157 158 159 160 161 162 163 164 165

/* Allow for i/o completion notification after primary interrupt status. */
#define CCWDEV_EARLY_NOTIFICATION	0x0001
/* Report all interrupt conditions. */
#define CCWDEV_REPORT_ALL	 	0x0002
/* Try to perform path grouping. */
#define CCWDEV_DO_PATHGROUP             0x0004
/* Allow forced onlining of boxed devices. */
#define CCWDEV_ALLOW_FORCE              0x0008
166 167
/* Try to use multipath mode. */
#define CCWDEV_DO_MULTIPATH		0x0010
L
Linus Torvalds 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
			    unsigned long, __u8, unsigned long);
extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
				    unsigned long, __u8, unsigned long, int);
extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
				unsigned long, __u8, __u8, unsigned long);
extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
					unsigned long, __u8, __u8,
					unsigned long, int);


extern int ccw_device_resume(struct ccw_device *);
extern int ccw_device_halt(struct ccw_device *, unsigned long);
extern int ccw_device_clear(struct ccw_device *, unsigned long);
183 184 185 186 187 188 189 190 191 192 193
int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
			    unsigned long intparm, u8 lpm, u8 key);
int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
			    unsigned long, u8, u8);
int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
			    unsigned long, u8, u8, int);
int ccw_device_tm_start(struct ccw_device *, struct tcw *,
			    unsigned long, u8);
int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
			    unsigned long, u8, int);
int ccw_device_tm_intrg(struct ccw_device *cdev);
L
Linus Torvalds 已提交
194 195 196 197 198 199 200

extern int ccw_device_set_online(struct ccw_device *cdev);
extern int ccw_device_set_offline(struct ccw_device *cdev);


extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
extern __u8 ccw_device_get_path_mask(struct ccw_device *);
201
extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
L
Linus Torvalds 已提交
202 203 204 205 206 207 208

#define get_ccwdev_lock(x) (x)->ccwlock

#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)

extern struct ccw_device *ccw_device_probe_console(void);
209
extern int ccw_device_force_console(void);
L
Linus Torvalds 已提交
210

M
Michael Ernst 已提交
211 212
int ccw_device_siosl(struct ccw_device *);

L
Linus Torvalds 已提交
213 214 215 216 217
// FIXME: these have to go
extern int _ccw_device_get_subchannel_number(struct ccw_device *);

extern void *ccw_device_get_chp_desc(struct ccw_device *, int);
#endif /* _S390_CCWDEV_H_ */