ccwdev.h 8.2 KB

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