driver-model.txt 9.0 KB

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