Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright IBM Corp. 2002, 2009
0004  *
0005  * Author(s): Arnd Bergmann <arndb@de.ibm.com>
0006  *
0007  * Interface for CCW device drivers
0008  */
0009 #ifndef _S390_CCWDEV_H_
0010 #define _S390_CCWDEV_H_
0011 
0012 #include <linux/device.h>
0013 #include <linux/mod_devicetable.h>
0014 #include <asm/chsc.h>
0015 #include <asm/fcx.h>
0016 #include <asm/irq.h>
0017 #include <asm/schid.h>
0018 
0019 /* structs from asm/cio.h */
0020 struct irb;
0021 struct ccw1;
0022 struct ccw_dev_id;
0023 
0024 /* simplified initializers for struct ccw_device:
0025  * CCW_DEVICE and CCW_DEVICE_DEVTYPE initialize one
0026  * entry in your MODULE_DEVICE_TABLE and set the match_flag correctly */
0027 #define CCW_DEVICE(cu, cum)                         \
0028     .cu_type=(cu), .cu_model=(cum),                 \
0029     .match_flags=(CCW_DEVICE_ID_MATCH_CU_TYPE           \
0030            | (cum ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0))
0031 
0032 #define CCW_DEVICE_DEVTYPE(cu, cum, dev, devm)              \
0033     .cu_type=(cu), .cu_model=(cum), .dev_type=(dev), .dev_model=(devm),\
0034     .match_flags=CCW_DEVICE_ID_MATCH_CU_TYPE            \
0035            | ((cum) ? CCW_DEVICE_ID_MATCH_CU_MODEL : 0)     \
0036            | CCW_DEVICE_ID_MATCH_DEVICE_TYPE            \
0037            | ((devm) ? CCW_DEVICE_ID_MATCH_DEVICE_MODEL : 0)
0038 
0039 /* scan through an array of device ids and return the first
0040  * entry that matches the device.
0041  *
0042  * the array must end with an entry containing zero match_flags
0043  */
0044 static inline const struct ccw_device_id *
0045 ccw_device_id_match(const struct ccw_device_id *array,
0046             const struct ccw_device_id *match)
0047 {
0048     const struct ccw_device_id *id = array;
0049 
0050     for (id = array; id->match_flags; id++) {
0051         if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_TYPE)
0052             && (id->cu_type != match->cu_type))
0053             continue;
0054 
0055         if ((id->match_flags & CCW_DEVICE_ID_MATCH_CU_MODEL)
0056             && (id->cu_model != match->cu_model))
0057             continue;
0058 
0059         if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_TYPE)
0060             && (id->dev_type != match->dev_type))
0061             continue;
0062 
0063         if ((id->match_flags & CCW_DEVICE_ID_MATCH_DEVICE_MODEL)
0064             && (id->dev_model != match->dev_model))
0065             continue;
0066 
0067         return id;
0068     }
0069 
0070     return NULL;
0071 }
0072 
0073 /**
0074  * struct ccw_device - channel attached device
0075  * @ccwlock: pointer to device lock
0076  * @id: id of this device
0077  * @drv: ccw driver for this device
0078  * @dev: embedded device structure
0079  * @online: online status of device
0080  * @handler: interrupt handler
0081  *
0082  * @handler is a member of the device rather than the driver since a driver
0083  * can have different interrupt handlers for different ccw devices
0084  * (multi-subchannel drivers).
0085  */
0086 struct ccw_device {
0087     spinlock_t *ccwlock;
0088 /* private: */
0089     struct ccw_device_private *private; /* cio private information */
0090 /* public: */
0091     struct ccw_device_id id;
0092     struct ccw_driver *drv;
0093     struct device dev;
0094     int online;
0095     void (*handler) (struct ccw_device *, unsigned long, struct irb *);
0096 };
0097 
0098 /*
0099  * Possible events used by the path_event notifier.
0100  */
0101 #define PE_NONE             0x0
0102 #define PE_PATH_GONE            0x1 /* A path is no longer available. */
0103 #define PE_PATH_AVAILABLE       0x2 /* A path has become available and
0104                            was successfully verified. */
0105 #define PE_PATHGROUP_ESTABLISHED    0x4 /* A pathgroup was reset and had
0106                            to be established again. */
0107 #define PE_PATH_FCES_EVENT      0x8 /* The FCES Status of a path has
0108                          * changed. */
0109 
0110 /*
0111  * Possible CIO actions triggered by the unit check handler.
0112  */
0113 enum uc_todo {
0114     UC_TODO_RETRY,
0115     UC_TODO_RETRY_ON_NEW_PATH,
0116     UC_TODO_STOP
0117 };
0118 
0119 /**
0120  * struct ccw_driver - device driver for channel attached devices
0121  * @ids: ids supported by this driver
0122  * @probe: function called on probe
0123  * @remove: function called on remove
0124  * @set_online: called when setting device online
0125  * @set_offline: called when setting device offline
0126  * @notify: notify driver of device state changes
0127  * @path_event: notify driver of channel path events
0128  * @shutdown: called at device shutdown
0129  * @uc_handler: callback for unit check handler
0130  * @driver: embedded device driver structure
0131  * @int_class: interruption class to use for accounting interrupts
0132  */
0133 struct ccw_driver {
0134     struct ccw_device_id *ids;
0135     int (*probe) (struct ccw_device *);
0136     void (*remove) (struct ccw_device *);
0137     int (*set_online) (struct ccw_device *);
0138     int (*set_offline) (struct ccw_device *);
0139     int (*notify) (struct ccw_device *, int);
0140     void (*path_event) (struct ccw_device *, int *);
0141     void (*shutdown) (struct ccw_device *);
0142     enum uc_todo (*uc_handler) (struct ccw_device *, struct irb *);
0143     struct device_driver driver;
0144     enum interruption_class int_class;
0145 };
0146 
0147 extern struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
0148                           const char *bus_id);
0149 
0150 /* devices drivers call these during module load and unload.
0151  * When a driver is registered, its probe method is called
0152  * when new devices for its type pop up */
0153 extern int  ccw_driver_register   (struct ccw_driver *driver);
0154 extern void ccw_driver_unregister (struct ccw_driver *driver);
0155 extern int ccw_device_set_options_mask(struct ccw_device *, unsigned long);
0156 extern int ccw_device_set_options(struct ccw_device *, unsigned long);
0157 extern void ccw_device_clear_options(struct ccw_device *, unsigned long);
0158 int ccw_device_is_pathgroup(struct ccw_device *cdev);
0159 int ccw_device_is_multipath(struct ccw_device *cdev);
0160 
0161 /* Allow for i/o completion notification after primary interrupt status. */
0162 #define CCWDEV_EARLY_NOTIFICATION   0x0001
0163 /* Report all interrupt conditions. */
0164 #define CCWDEV_REPORT_ALL       0x0002
0165 /* Try to perform path grouping. */
0166 #define CCWDEV_DO_PATHGROUP             0x0004
0167 /* Allow forced onlining of boxed devices. */
0168 #define CCWDEV_ALLOW_FORCE              0x0008
0169 /* Try to use multipath mode. */
0170 #define CCWDEV_DO_MULTIPATH     0x0010
0171 
0172 extern int ccw_device_start(struct ccw_device *, struct ccw1 *,
0173                 unsigned long, __u8, unsigned long);
0174 extern int ccw_device_start_timeout(struct ccw_device *, struct ccw1 *,
0175                     unsigned long, __u8, unsigned long, int);
0176 extern int ccw_device_start_key(struct ccw_device *, struct ccw1 *,
0177                 unsigned long, __u8, __u8, unsigned long);
0178 extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
0179                     unsigned long, __u8, __u8,
0180                     unsigned long, int);
0181 
0182 
0183 extern int ccw_device_resume(struct ccw_device *);
0184 extern int ccw_device_halt(struct ccw_device *, unsigned long);
0185 extern int ccw_device_clear(struct ccw_device *, unsigned long);
0186 int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
0187                 unsigned long intparm, u8 lpm, u8 key);
0188 int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
0189                 unsigned long, u8, u8);
0190 int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
0191                 unsigned long, u8, u8, int);
0192 int ccw_device_tm_start(struct ccw_device *, struct tcw *,
0193                 unsigned long, u8);
0194 int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
0195                 unsigned long, u8, int);
0196 int ccw_device_tm_intrg(struct ccw_device *cdev);
0197 
0198 int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask);
0199 
0200 extern int ccw_device_set_online(struct ccw_device *cdev);
0201 extern int ccw_device_set_offline(struct ccw_device *cdev);
0202 
0203 
0204 extern struct ciw *ccw_device_get_ciw(struct ccw_device *, __u32 cmd);
0205 extern __u8 ccw_device_get_path_mask(struct ccw_device *);
0206 extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
0207 
0208 #define get_ccwdev_lock(x) (x)->ccwlock
0209 
0210 #define to_ccwdev(n) container_of(n, struct ccw_device, dev)
0211 #define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
0212 
0213 extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
0214 extern void ccw_device_destroy_console(struct ccw_device *);
0215 extern int ccw_device_enable_console(struct ccw_device *);
0216 extern void ccw_device_wait_idle(struct ccw_device *);
0217 extern int ccw_device_force_console(struct ccw_device *);
0218 
0219 extern void *ccw_device_dma_zalloc(struct ccw_device *cdev, size_t size);
0220 extern void ccw_device_dma_free(struct ccw_device *cdev,
0221                 void *cpu_addr, size_t size);
0222 
0223 int ccw_device_siosl(struct ccw_device *);
0224 
0225 extern void ccw_device_get_schid(struct ccw_device *, struct subchannel_id *);
0226 
0227 struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *, int);
0228 u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx);
0229 int ccw_device_pnso(struct ccw_device *cdev,
0230             struct chsc_pnso_area *pnso_area, u8 oc,
0231             struct chsc_pnso_resume_token resume_token, int cnc);
0232 int ccw_device_get_cssid(struct ccw_device *cdev, u8 *cssid);
0233 int ccw_device_get_iid(struct ccw_device *cdev, u8 *iid);
0234 int ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid);
0235 int ccw_device_get_chid(struct ccw_device *cdev, int chp_idx, u16 *chid);
0236 #endif /* _S390_CCWDEV_H_ */