ccwdev.h 8.1 KB

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