S/390 driver model interfaces
-----------------------------

1. CCW devices
--------------

All devices which can be addressed by means of ccws are called 'CCW devices' -
even if they aren't actually driven by ccws.

All ccw devices are accessed via a subchannel, this is reflected in the 
structures under root/:

root/
     - sys
     - legacy
     - css0/
           - 0:0000/0:0815/
	   - 0:0001/0:4711/
	   - 0:0002/
	   ...

In this example, device 0815 is accessed via subchannel 0, device 4711 via 
subchannel 1, and subchannel 2 is a non-I/O subchannel.

You should address a ccw device via its bus id (e.g. 0:4711); the device can
be found under bus/ccw/devices/.

All ccw devices export some data via sysfs additional to the standard 'name'
and 'power' entries.

cutype:	    The control unit type / model.

devtype:    The device type / model, if applicable.

online:     An interface to set the device online and offline.

The device drivers can add entries to export per-device data and interfaces.

There is also some data exported on a per-subchannel basis (see under
bus/css/devices/):

chpids:	    Via which chpids the device is connected.

pimpampom:  The path installed, path available and path operational masks.

There also might be additional data, for example for block devices.


1.1 Bringing up a ccw device
----------------------------

This is done in several steps.

a. Each driver can provide one or more parameter interfaces where parameters can
   be specified. These interfaces are also in the driver's responsibility.
b. After a. has been performed, if necessary, the device is finally brought up
   via the 'online' interface.


1.2 Writing a driver for ccw devices
------------------------------------

The basic struct ccw_device and struct ccw_driver data structures can be found
under include/asm/ccwdev.h.

struct ccw_device {
        spinlock_t *ccwlock;
        struct ccw_device_private *private;
	struct ccw_device_id id;	

	struct ccw_driver *drv;		
	struct device dev;		
	int online;

	void (*handler) (struct ccw_device *dev, unsigned long intparm,
                         struct irb *irb);
};

struct ccw_driver {
	struct module *owner;		
	struct ccw_device_id *ids;	
	int (*probe) (struct ccw_device *); 
	int (*remove) (struct ccw_device *);
	int (*set_online) (struct ccw_device *);
	int (*set_offline) (struct ccw_device *);
	struct device_driver driver;
	char *name;
};

The 'private' field contains data needed for internal i/o operation only, and
is not available to the device driver.

Each driver should declare in a MODULE_DEVICE_TABLE into which CU types/models
and/or device types/models it is interested. This information can later be found
found in the struct ccw_device_id fields:

struct ccw_device_id {
	__u16	match_flags;	

	__u16	cu_type;	
	__u16	dev_type;	
	__u8	cu_model;	
	__u8	dev_model;	

	unsigned long driver_info;
};

The functions in ccw_driver should be used in the following way:
probe:   This function is called by the device layer for each device the driver
	 is interested in. The driver should only allocate private structures
	 to put in dev->driver_data and create attributes (if needed). Also,
	 the interrupt handler (see below) should be set here.

int (*probe) (struct ccw_device *cdev); 

Parameters:  cdev     - the device to be probed.


remove:  This function is called by the device layer upon removal of the driver,
	 the device or the module. The driver should perform cleanups here.

int (*remove) (struct ccw_device *cdev);

Parameters:   cdev    - the device to be removed.


set_online: This function is called by the common I/O layer when the device is
	    activated via the 'online' attribute. The driver should finally
	    setup and activate the device here.

int (*set_online) (struct ccw_device *);

Parameters:   cdev	- the device to be activated. The common layer has
			  verified that the device is not already online.


set_offline: This function is called by the common I/O layer when the device is
	     de-activated via the 'online' attribute. The driver should shut
	     down the device, but not de-allocate its private data.

int (*set_offline) (struct ccw_device *);

Parameters:   cdev       - the device to be deactivated. The common layer has
			   verified that the device is online.


The handler field of the struct ccw_device is meant to be set to the interrupt
handler for the device. In order to accommodate drivers which use several 
distinct handlers (e.g. multi subchannel devices), this is a member of ccw_device
instead of ccw_driver.
The handler is registered with the common layer during set_online() processing
before the driver is called, and is deregistered during set_offline() after the
driver has been called. Also, after registering / before deregistering, path 
grouping resp. disbanding of the path group (if applicable) are performed.

void (*handler) (struct ccw_device *dev, unsigned long intparm, struct irb *irb);

Parameters:	dev	- the device the handler is called for
		intparm - the intparm which allows the device driver to identify
                          the i/o the interrupt is associated with, or to recognize
                          the interrupt as unsolicited.
                irb     - interruption response block which contains the accumulated
                          status.

The device driver is called from the common ccw_device layer and can retrieve 
information about the interrupt from the irb parameter.


1.3 ccwgroup devices
--------------------

The ccwgroup mechanism is designed to handle devices consisting of multiple ccw
devices, like lcs or ctc.

The ccw driver provides a 'group' attribute. Piping bus ids of ccw devices to
this attributes creates a ccwgroup device consisting of these ccw devices (if
possible). This ccwgroup device can be set online or offline just like a normal
ccw device.

To implement a ccwgroup driver, please refer to include/asm/ccwgroup.h. Keep in
mind that most drivers will need to implement both a ccwgroup and a ccw driver
(unless you have a meta ccw driver, like cu3088 for lcs and ctc).


2. Channel paths
-----------------

Channel paths show up, like subchannels, under the channel subsystem root (css0)
and are called 'chp<chpid>'. They have no driver and do not belong to any bus.

status - Can be 'online', 'logically offline' or 'n/a'.
	 Piping 'on' or 'off' sets the chpid logically online/offline.


3. System devices
-----------------

Note: cpus may yet be added here.

3.1 xpram 
---------

xpram shows up under sys/ as 'xpram'.


4. Other devices
----------------

4.1 Netiucv
-----------

The netiucv driver creates an attribute 'connection' under
bus/iucv/drivers/NETIUCV. Piping to this attibute creates a new netiucv
connection to the specified host.

Netiucv connections show up under devices/iucv/ as "netiucv<ifnum>". The interface
number is assigned sequentially to the connections defined via the 'connection'
attribute. 'name' shows the connection partner.

buffer			  - maximum buffer size.
			    Pipe to it to change buffer size.


