driver-model.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. S/390 driver model interfaces
  2. -----------------------------
  3. 1. CCW devices
  4. --------------
  5. All devices which can be addressed by means of ccws are called 'CCW devices' -
  6. even if they aren't actually driven by ccws.
  7. All ccw devices are accessed via a subchannel, this is reflected in the
  8. structures under devices/:
  9. devices/
  10. - system/
  11. - css0/
  12. - 0.0.0000/0.0.0815/
  13. - 0.0.0001/0.0.4711/
  14. - 0.0.0002/
  15. - 0.1.0000/0.1.1234/
  16. ...
  17. In this example, device 0815 is accessed via subchannel 0 in subchannel set 0,
  18. device 4711 via subchannel 1 in subchannel set 0, and subchannel 2 is a non-I/O
  19. subchannel. Device 1234 is accessed via subchannel 0 in subchannel set 1.
  20. You should address a ccw device via its bus id (e.g. 0.0.4711); the device can
  21. be found under bus/ccw/devices/.
  22. All ccw devices export some data via sysfs.
  23. cutype: The control unit type / model.
  24. devtype: The device type / model, if applicable.
  25. availability: Can be 'good' or 'boxed'; 'no path' or 'no device' for
  26. disconnected devices.
  27. online: An interface to set the device online and offline.
  28. In the special case of the device being disconnected (see the
  29. notify function under 1.2), piping 0 to online will forcibly delete
  30. the device.
  31. The device drivers can add entries to export per-device data and interfaces.
  32. There is also some data exported on a per-subchannel basis (see under
  33. bus/css/devices/):
  34. chpids: Via which chpids the device is connected.
  35. pimpampom: The path installed, path available and path operational masks.
  36. There also might be additional data, for example for block devices.
  37. 1.1 Bringing up a ccw device
  38. ----------------------------
  39. This is done in several steps.
  40. a. Each driver can provide one or more parameter interfaces where parameters can
  41. be specified. These interfaces are also in the driver's responsibility.
  42. b. After a. has been performed, if necessary, the device is finally brought up
  43. via the 'online' interface.
  44. 1.2 Writing a driver for ccw devices
  45. ------------------------------------
  46. The basic struct ccw_device and struct ccw_driver data structures can be found
  47. under include/asm/ccwdev.h.
  48. struct ccw_device {
  49. spinlock_t *ccwlock;
  50. struct ccw_device_private *private;
  51. struct ccw_device_id id;
  52. struct ccw_driver *drv;
  53. struct device dev;
  54. int online;
  55. void (*handler) (struct ccw_device *dev, unsigned long intparm,
  56. struct irb *irb);
  57. };
  58. struct ccw_driver {
  59. struct module *owner;
  60. struct ccw_device_id *ids;
  61. int (*probe) (struct ccw_device *);
  62. int (*remove) (struct ccw_device *);
  63. int (*set_online) (struct ccw_device *);
  64. int (*set_offline) (struct ccw_device *);
  65. int (*notify) (struct ccw_device *, int);
  66. struct device_driver driver;
  67. char *name;
  68. };
  69. The 'private' field contains data needed for internal i/o operation only, and
  70. is not available to the device driver.
  71. Each driver should declare in a MODULE_DEVICE_TABLE into which CU types/models
  72. and/or device types/models it is interested. This information can later be found
  73. in the struct ccw_device_id fields:
  74. struct ccw_device_id {
  75. __u16 match_flags;
  76. __u16 cu_type;
  77. __u16 dev_type;
  78. __u8 cu_model;
  79. __u8 dev_model;
  80. unsigned long driver_info;
  81. };
  82. The functions in ccw_driver should be used in the following way:
  83. probe: This function is called by the device layer for each device the driver
  84. is interested in. The driver should only allocate private structures
  85. to put in dev->driver_data and create attributes (if needed). Also,
  86. the interrupt handler (see below) should be set here.
  87. int (*probe) (struct ccw_device *cdev);
  88. Parameters: cdev - the device to be probed.
  89. remove: This function is called by the device layer upon removal of the driver,
  90. the device or the module. The driver should perform cleanups here.
  91. int (*remove) (struct ccw_device *cdev);
  92. Parameters: cdev - the device to be removed.
  93. set_online: This function is called by the common I/O layer when the device is
  94. activated via the 'online' attribute. The driver should finally
  95. setup and activate the device here.
  96. int (*set_online) (struct ccw_device *);
  97. Parameters: cdev - the device to be activated. The common layer has
  98. verified that the device is not already online.
  99. set_offline: This function is called by the common I/O layer when the device is
  100. de-activated via the 'online' attribute. The driver should shut
  101. down the device, but not de-allocate its private data.
  102. int (*set_offline) (struct ccw_device *);
  103. Parameters: cdev - the device to be deactivated. The common layer has
  104. verified that the device is online.
  105. notify: This function is called by the common I/O layer for some state changes
  106. of the device.
  107. Signalled to the driver are:
  108. * In online state, device detached (CIO_GONE) or last path gone
  109. (CIO_NO_PATH). The driver must return !0 to keep the device; for
  110. return code 0, the device will be deleted as usual (also when no
  111. notify function is registered). If the driver wants to keep the
  112. device, it is moved into disconnected state.
  113. * In disconnected state, device operational again (CIO_OPER). The
  114. common I/O layer performs some sanity checks on device number and
  115. Device / CU to be reasonably sure if it is still the same device.
  116. If not, the old device is removed and a new one registered. By the
  117. return code of the notify function the device driver signals if it
  118. wants the device back: !0 for keeping, 0 to make the device being
  119. removed and re-registered.
  120. int (*notify) (struct ccw_device *, int);
  121. Parameters: cdev - the device whose state changed.
  122. event - the event that happened. This can be one of CIO_GONE,
  123. CIO_NO_PATH or CIO_OPER.
  124. The handler field of the struct ccw_device is meant to be set to the interrupt
  125. handler for the device. In order to accommodate drivers which use several
  126. distinct handlers (e.g. multi subchannel devices), this is a member of ccw_device
  127. instead of ccw_driver.
  128. The handler is registered with the common layer during set_online() processing
  129. before the driver is called, and is deregistered during set_offline() after the
  130. driver has been called. Also, after registering / before deregistering, path
  131. grouping resp. disbanding of the path group (if applicable) are performed.
  132. void (*handler) (struct ccw_device *dev, unsigned long intparm, struct irb *irb);
  133. Parameters: dev - the device the handler is called for
  134. intparm - the intparm which allows the device driver to identify
  135. the i/o the interrupt is associated with, or to recognize
  136. the interrupt as unsolicited.
  137. irb - interruption response block which contains the accumulated
  138. status.
  139. The device driver is called from the common ccw_device layer and can retrieve
  140. information about the interrupt from the irb parameter.
  141. 1.3 ccwgroup devices
  142. --------------------
  143. The ccwgroup mechanism is designed to handle devices consisting of multiple ccw
  144. devices, like lcs or ctc.
  145. The ccw driver provides a 'group' attribute. Piping bus ids of ccw devices to
  146. this attributes creates a ccwgroup device consisting of these ccw devices (if
  147. possible). This ccwgroup device can be set online or offline just like a normal
  148. ccw device.
  149. Each ccwgroup device also provides an 'ungroup' attribute to destroy the device
  150. again (only when offline). This is a generic ccwgroup mechanism (the driver does
  151. not need to implement anything beyond normal removal routines).
  152. A ccw device which is a member of a ccwgroup device carries a pointer to the
  153. ccwgroup device in the driver_data of its device struct. This field must not be
  154. touched by the driver - it should use the ccwgroup device's driver_data for its
  155. private data.
  156. To implement a ccwgroup driver, please refer to include/asm/ccwgroup.h. Keep in
  157. mind that most drivers will need to implement both a ccwgroup and a ccw driver
  158. (unless you have a meta ccw driver, like cu3088 for lcs and ctc).
  159. 2. Channel paths
  160. -----------------
  161. Channel paths show up, like subchannels, under the channel subsystem root (css0)
  162. and are called 'chp0.<chpid>'. They have no driver and do not belong to any bus.
  163. Please note, that unlike /proc/chpids in 2.4, the channel path objects reflect
  164. only the logical state and not the physical state, since we cannot track the
  165. latter consistently due to lacking machine support (we don't need to be aware
  166. of it anyway).
  167. status - Can be 'online' or 'offline'.
  168. Piping 'on' or 'off' sets the chpid logically online/offline.
  169. Piping 'on' to an online chpid triggers path reprobing for all devices
  170. the chpid connects to. This can be used to force the kernel to re-use
  171. a channel path the user knows to be online, but the machine hasn't
  172. created a machine check for.
  173. type - The physical type of the channel path.
  174. shared - Whether the channel path is shared.
  175. cmg - The channel measurement group.
  176. 3. System devices
  177. -----------------
  178. 3.1 xpram
  179. ---------
  180. xpram shows up under devices/system/ as 'xpram'.
  181. 3.2 cpus
  182. --------
  183. For each cpu, a directory is created under devices/system/cpu/. Each cpu has an
  184. attribute 'online' which can be 0 or 1.
  185. 4. Other devices
  186. ----------------
  187. 4.1 Netiucv
  188. -----------
  189. The netiucv driver creates an attribute 'connection' under
  190. bus/iucv/drivers/netiucv. Piping to this attribute creates a new netiucv
  191. connection to the specified host.
  192. Netiucv connections show up under devices/iucv/ as "netiucv<ifnum>". The interface
  193. number is assigned sequentially to the connections defined via the 'connection'
  194. attribute.
  195. user - shows the connection partner.
  196. buffer - maximum buffer size.
  197. Pipe to it to change buffer size.