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