0001 ===========================
0002 Linux for S/390 and zSeries
0003 ===========================
0004
0005 Common Device Support (CDS)
0006 Device Driver I/O Support Routines
0007
0008 Authors:
0009 - Ingo Adlung
0010 - Cornelia Huck
0011
0012 Copyright, IBM Corp. 1999-2002
0013
0014 Introduction
0015 ============
0016
0017 This document describes the common device support routines for Linux/390.
0018 Different than other hardware architectures, ESA/390 has defined a unified
0019 I/O access method. This gives relief to the device drivers as they don't
0020 have to deal with different bus types, polling versus interrupt
0021 processing, shared versus non-shared interrupt processing, DMA versus port
0022 I/O (PIO), and other hardware features more. However, this implies that
0023 either every single device driver needs to implement the hardware I/O
0024 attachment functionality itself, or the operating system provides for a
0025 unified method to access the hardware, providing all the functionality that
0026 every single device driver would have to provide itself.
0027
0028 The document does not intend to explain the ESA/390 hardware architecture in
0029 every detail.This information can be obtained from the ESA/390 Principles of
0030 Operation manual (IBM Form. No. SA22-7201).
0031
0032 In order to build common device support for ESA/390 I/O interfaces, a
0033 functional layer was introduced that provides generic I/O access methods to
0034 the hardware.
0035
0036 The common device support layer comprises the I/O support routines defined
0037 below. Some of them implement common Linux device driver interfaces, while
0038 some of them are ESA/390 platform specific.
0039
0040 Note:
0041 In order to write a driver for S/390, you also need to look into the interface
0042 described in Documentation/s390/driver-model.rst.
0043
0044 Note for porting drivers from 2.4:
0045
0046 The major changes are:
0047
0048 * The functions use a ccw_device instead of an irq (subchannel).
0049 * All drivers must define a ccw_driver (see driver-model.txt) and the associated
0050 functions.
0051 * request_irq() and free_irq() are no longer done by the driver.
0052 * The oper_handler is (kindof) replaced by the probe() and set_online() functions
0053 of the ccw_driver.
0054 * The not_oper_handler is (kindof) replaced by the remove() and set_offline()
0055 functions of the ccw_driver.
0056 * The channel device layer is gone.
0057 * The interrupt handlers must be adapted to use a ccw_device as argument.
0058 Moreover, they don't return a devstat, but an irb.
0059 * Before initiating an io, the options must be set via ccw_device_set_options().
0060 * Instead of calling read_dev_chars()/read_conf_data(), the driver issues
0061 the channel program and handles the interrupt itself.
0062
0063 ccw_device_get_ciw()
0064 get commands from extended sense data.
0065
0066 ccw_device_start(), ccw_device_start_timeout(), ccw_device_start_key(), ccw_device_start_key_timeout()
0067 initiate an I/O request.
0068
0069 ccw_device_resume()
0070 resume channel program execution.
0071
0072 ccw_device_halt()
0073 terminate the current I/O request processed on the device.
0074
0075 do_IRQ()
0076 generic interrupt routine. This function is called by the interrupt entry
0077 routine whenever an I/O interrupt is presented to the system. The do_IRQ()
0078 routine determines the interrupt status and calls the device specific
0079 interrupt handler according to the rules (flags) defined during I/O request
0080 initiation with do_IO().
0081
0082 The next chapters describe the functions other than do_IRQ() in more details.
0083 The do_IRQ() interface is not described, as it is called from the Linux/390
0084 first level interrupt handler only and does not comprise a device driver
0085 callable interface. Instead, the functional description of do_IO() also
0086 describes the input to the device specific interrupt handler.
0087
0088 Note:
0089 All explanations apply also to the 64 bit architecture s390x.
0090
0091
0092 Common Device Support (CDS) for Linux/390 Device Drivers
0093 ========================================================
0094
0095 General Information
0096 -------------------
0097
0098 The following chapters describe the I/O related interface routines the
0099 Linux/390 common device support (CDS) provides to allow for device specific
0100 driver implementations on the IBM ESA/390 hardware platform. Those interfaces
0101 intend to provide the functionality required by every device driver
0102 implementation to allow to drive a specific hardware device on the ESA/390
0103 platform. Some of the interface routines are specific to Linux/390 and some
0104 of them can be found on other Linux platforms implementations too.
0105 Miscellaneous function prototypes, data declarations, and macro definitions
0106 can be found in the architecture specific C header file
0107 linux/arch/s390/include/asm/irq.h.
0108
0109 Overview of CDS interface concepts
0110 ----------------------------------
0111
0112 Different to other hardware platforms, the ESA/390 architecture doesn't define
0113 interrupt lines managed by a specific interrupt controller and bus systems
0114 that may or may not allow for shared interrupts, DMA processing, etc.. Instead,
0115 the ESA/390 architecture has implemented a so called channel subsystem, that
0116 provides a unified view of the devices physically attached to the systems.
0117 Though the ESA/390 hardware platform knows about a huge variety of different
0118 peripheral attachments like disk devices (aka. DASDs), tapes, communication
0119 controllers, etc. they can all be accessed by a well defined access method and
0120 they are presenting I/O completion a unified way : I/O interruptions. Every
0121 single device is uniquely identified to the system by a so called subchannel,
0122 where the ESA/390 architecture allows for 64k devices be attached.
0123
0124 Linux, however, was first built on the Intel PC architecture, with its two
0125 cascaded 8259 programmable interrupt controllers (PICs), that allow for a
0126 maximum of 15 different interrupt lines. All devices attached to such a system
0127 share those 15 interrupt levels. Devices attached to the ISA bus system must
0128 not share interrupt levels (aka. IRQs), as the ISA bus bases on edge triggered
0129 interrupts. MCA, EISA, PCI and other bus systems base on level triggered
0130 interrupts, and therewith allow for shared IRQs. However, if multiple devices
0131 present their hardware status by the same (shared) IRQ, the operating system
0132 has to call every single device driver registered on this IRQ in order to
0133 determine the device driver owning the device that raised the interrupt.
0134
0135 Up to kernel 2.4, Linux/390 used to provide interfaces via the IRQ (subchannel).
0136 For internal use of the common I/O layer, these are still there. However,
0137 device drivers should use the new calling interface via the ccw_device only.
0138
0139 During its startup the Linux/390 system checks for peripheral devices. Each
0140 of those devices is uniquely defined by a so called subchannel by the ESA/390
0141 channel subsystem. While the subchannel numbers are system generated, each
0142 subchannel also takes a user defined attribute, the so called device number.
0143 Both subchannel number and device number cannot exceed 65535. During sysfs
0144 initialisation, the information about control unit type and device types that
0145 imply specific I/O commands (channel command words - CCWs) in order to operate
0146 the device are gathered. Device drivers can retrieve this set of hardware
0147 information during their initialization step to recognize the devices they
0148 support using the information saved in the struct ccw_device given to them.
0149 This methods implies that Linux/390 doesn't require to probe for free (not
0150 armed) interrupt request lines (IRQs) to drive its devices with. Where
0151 applicable, the device drivers can use issue the READ DEVICE CHARACTERISTICS
0152 ccw to retrieve device characteristics in its online routine.
0153
0154 In order to allow for easy I/O initiation the CDS layer provides a
0155 ccw_device_start() interface that takes a device specific channel program (one
0156 or more CCWs) as input sets up the required architecture specific control blocks
0157 and initiates an I/O request on behalf of the device driver. The
0158 ccw_device_start() routine allows to specify whether it expects the CDS layer
0159 to notify the device driver for every interrupt it observes, or with final status
0160 only. See ccw_device_start() for more details. A device driver must never issue
0161 ESA/390 I/O commands itself, but must use the Linux/390 CDS interfaces instead.
0162
0163 For long running I/O request to be canceled, the CDS layer provides the
0164 ccw_device_halt() function. Some devices require to initially issue a HALT
0165 SUBCHANNEL (HSCH) command without having pending I/O requests. This function is
0166 also covered by ccw_device_halt().
0167
0168
0169 get_ciw() - get command information word
0170
0171 This call enables a device driver to get information about supported commands
0172 from the extended SenseID data.
0173
0174 ::
0175
0176 struct ciw *
0177 ccw_device_get_ciw(struct ccw_device *cdev, __u32 cmd);
0178
0179 ==== ========================================================
0180 cdev The ccw_device for which the command is to be retrieved.
0181 cmd The command type to be retrieved.
0182 ==== ========================================================
0183
0184 ccw_device_get_ciw() returns:
0185
0186 ===== ================================================================
0187 NULL No extended data available, invalid device or command not found.
0188 !NULL The command requested.
0189 ===== ================================================================
0190
0191 ::
0192
0193 ccw_device_start() - Initiate I/O Request
0194
0195 The ccw_device_start() routines is the I/O request front-end processor. All
0196 device driver I/O requests must be issued using this routine. A device driver
0197 must not issue ESA/390 I/O commands itself. Instead the ccw_device_start()
0198 routine provides all interfaces required to drive arbitrary devices.
0199
0200 This description also covers the status information passed to the device
0201 driver's interrupt handler as this is related to the rules (flags) defined
0202 with the associated I/O request when calling ccw_device_start().
0203
0204 ::
0205
0206 int ccw_device_start(struct ccw_device *cdev,
0207 struct ccw1 *cpa,
0208 unsigned long intparm,
0209 __u8 lpm,
0210 unsigned long flags);
0211 int ccw_device_start_timeout(struct ccw_device *cdev,
0212 struct ccw1 *cpa,
0213 unsigned long intparm,
0214 __u8 lpm,
0215 unsigned long flags,
0216 int expires);
0217 int ccw_device_start_key(struct ccw_device *cdev,
0218 struct ccw1 *cpa,
0219 unsigned long intparm,
0220 __u8 lpm,
0221 __u8 key,
0222 unsigned long flags);
0223 int ccw_device_start_key_timeout(struct ccw_device *cdev,
0224 struct ccw1 *cpa,
0225 unsigned long intparm,
0226 __u8 lpm,
0227 __u8 key,
0228 unsigned long flags,
0229 int expires);
0230
0231 ============= =============================================================
0232 cdev ccw_device the I/O is destined for
0233 cpa logical start address of channel program
0234 user_intparm user specific interrupt information; will be presented
0235 back to the device driver's interrupt handler. Allows a
0236 device driver to associate the interrupt with a
0237 particular I/O request.
0238 lpm defines the channel path to be used for a specific I/O
0239 request. A value of 0 will make cio use the opm.
0240 key the storage key to use for the I/O (useful for operating on a
0241 storage with a storage key != default key)
0242 flag defines the action to be performed for I/O processing
0243 expires timeout value in jiffies. The common I/O layer will terminate
0244 the running program after this and call the interrupt handler
0245 with ERR_PTR(-ETIMEDOUT) as irb.
0246 ============= =============================================================
0247
0248 Possible flag values are:
0249
0250 ========================= =============================================
0251 DOIO_ALLOW_SUSPEND channel program may become suspended
0252 DOIO_DENY_PREFETCH don't allow for CCW prefetch; usually
0253 this implies the channel program might
0254 become modified
0255 DOIO_SUPPRESS_INTER don't call the handler on intermediate status
0256 ========================= =============================================
0257
0258 The cpa parameter points to the first format 1 CCW of a channel program::
0259
0260 struct ccw1 {
0261 __u8 cmd_code;/* command code */
0262 __u8 flags; /* flags, like IDA addressing, etc. */
0263 __u16 count; /* byte count */
0264 __u32 cda; /* data address */
0265 } __attribute__ ((packed,aligned(8)));
0266
0267 with the following CCW flags values defined:
0268
0269 =================== =========================
0270 CCW_FLAG_DC data chaining
0271 CCW_FLAG_CC command chaining
0272 CCW_FLAG_SLI suppress incorrect length
0273 CCW_FLAG_SKIP skip
0274 CCW_FLAG_PCI PCI
0275 CCW_FLAG_IDA indirect addressing
0276 CCW_FLAG_SUSPEND suspend
0277 =================== =========================
0278
0279
0280 Via ccw_device_set_options(), the device driver may specify the following
0281 options for the device:
0282
0283 ========================= ======================================
0284 DOIO_EARLY_NOTIFICATION allow for early interrupt notification
0285 DOIO_REPORT_ALL report all interrupt conditions
0286 ========================= ======================================
0287
0288
0289 The ccw_device_start() function returns:
0290
0291 ======== ======================================================================
0292 0 successful completion or request successfully initiated
0293 -EBUSY The device is currently processing a previous I/O request, or there is
0294 a status pending at the device.
0295 -ENODEV cdev is invalid, the device is not operational or the ccw_device is
0296 not online.
0297 ======== ======================================================================
0298
0299 When the I/O request completes, the CDS first level interrupt handler will
0300 accumulate the status in a struct irb and then call the device interrupt handler.
0301 The intparm field will contain the value the device driver has associated with a
0302 particular I/O request. If a pending device status was recognized,
0303 intparm will be set to 0 (zero). This may happen during I/O initiation or delayed
0304 by an alert status notification. In any case this status is not related to the
0305 current (last) I/O request. In case of a delayed status notification no special
0306 interrupt will be presented to indicate I/O completion as the I/O request was
0307 never started, even though ccw_device_start() returned with successful completion.
0308
0309 The irb may contain an error value, and the device driver should check for this
0310 first:
0311
0312 ========== =================================================================
0313 -ETIMEDOUT the common I/O layer terminated the request after the specified
0314 timeout value
0315 -EIO the common I/O layer terminated the request due to an error state
0316 ========== =================================================================
0317
0318 If the concurrent sense flag in the extended status word (esw) in the irb is
0319 set, the field erw.scnt in the esw describes the number of device specific
0320 sense bytes available in the extended control word irb->scsw.ecw[]. No device
0321 sensing by the device driver itself is required.
0322
0323 The device interrupt handler can use the following definitions to investigate
0324 the primary unit check source coded in sense byte 0 :
0325
0326 ======================= ====
0327 SNS0_CMD_REJECT 0x80
0328 SNS0_INTERVENTION_REQ 0x40
0329 SNS0_BUS_OUT_CHECK 0x20
0330 SNS0_EQUIPMENT_CHECK 0x10
0331 SNS0_DATA_CHECK 0x08
0332 SNS0_OVERRUN 0x04
0333 SNS0_INCOMPL_DOMAIN 0x01
0334 ======================= ====
0335
0336 Depending on the device status, multiple of those values may be set together.
0337 Please refer to the device specific documentation for details.
0338
0339 The irb->scsw.cstat field provides the (accumulated) subchannel status :
0340
0341 ========================= ============================
0342 SCHN_STAT_PCI program controlled interrupt
0343 SCHN_STAT_INCORR_LEN incorrect length
0344 SCHN_STAT_PROG_CHECK program check
0345 SCHN_STAT_PROT_CHECK protection check
0346 SCHN_STAT_CHN_DATA_CHK channel data check
0347 SCHN_STAT_CHN_CTRL_CHK channel control check
0348 SCHN_STAT_INTF_CTRL_CHK interface control check
0349 SCHN_STAT_CHAIN_CHECK chaining check
0350 ========================= ============================
0351
0352 The irb->scsw.dstat field provides the (accumulated) device status :
0353
0354 ===================== =================
0355 DEV_STAT_ATTENTION attention
0356 DEV_STAT_STAT_MOD status modifier
0357 DEV_STAT_CU_END control unit end
0358 DEV_STAT_BUSY busy
0359 DEV_STAT_CHN_END channel end
0360 DEV_STAT_DEV_END device end
0361 DEV_STAT_UNIT_CHECK unit check
0362 DEV_STAT_UNIT_EXCEP unit exception
0363 ===================== =================
0364
0365 Please see the ESA/390 Principles of Operation manual for details on the
0366 individual flag meanings.
0367
0368 Usage Notes:
0369
0370 ccw_device_start() must be called disabled and with the ccw device lock held.
0371
0372 The device driver is allowed to issue the next ccw_device_start() call from
0373 within its interrupt handler already. It is not required to schedule a
0374 bottom-half, unless a non deterministically long running error recovery procedure
0375 or similar needs to be scheduled. During I/O processing the Linux/390 generic
0376 I/O device driver support has already obtained the IRQ lock, i.e. the handler
0377 must not try to obtain it again when calling ccw_device_start() or we end in a
0378 deadlock situation!
0379
0380 If a device driver relies on an I/O request to be completed prior to start the
0381 next it can reduce I/O processing overhead by chaining a NoOp I/O command
0382 CCW_CMD_NOOP to the end of the submitted CCW chain. This will force Channel-End
0383 and Device-End status to be presented together, with a single interrupt.
0384 However, this should be used with care as it implies the channel will remain
0385 busy, not being able to process I/O requests for other devices on the same
0386 channel. Therefore e.g. read commands should never use this technique, as the
0387 result will be presented by a single interrupt anyway.
0388
0389 In order to minimize I/O overhead, a device driver should use the
0390 DOIO_REPORT_ALL only if the device can report intermediate interrupt
0391 information prior to device-end the device driver urgently relies on. In this
0392 case all I/O interruptions are presented to the device driver until final
0393 status is recognized.
0394
0395 If a device is able to recover from asynchronously presented I/O errors, it can
0396 perform overlapping I/O using the DOIO_EARLY_NOTIFICATION flag. While some
0397 devices always report channel-end and device-end together, with a single
0398 interrupt, others present primary status (channel-end) when the channel is
0399 ready for the next I/O request and secondary status (device-end) when the data
0400 transmission has been completed at the device.
0401
0402 Above flag allows to exploit this feature, e.g. for communication devices that
0403 can handle lost data on the network to allow for enhanced I/O processing.
0404
0405 Unless the channel subsystem at any time presents a secondary status interrupt,
0406 exploiting this feature will cause only primary status interrupts to be
0407 presented to the device driver while overlapping I/O is performed. When a
0408 secondary status without error (alert status) is presented, this indicates
0409 successful completion for all overlapping ccw_device_start() requests that have
0410 been issued since the last secondary (final) status.
0411
0412 Channel programs that intend to set the suspend flag on a channel command word
0413 (CCW) must start the I/O operation with the DOIO_ALLOW_SUSPEND option or the
0414 suspend flag will cause a channel program check. At the time the channel program
0415 becomes suspended an intermediate interrupt will be generated by the channel
0416 subsystem.
0417
0418 ccw_device_resume() - Resume Channel Program Execution
0419
0420 If a device driver chooses to suspend the current channel program execution by
0421 setting the CCW suspend flag on a particular CCW, the channel program execution
0422 is suspended. In order to resume channel program execution the CIO layer
0423 provides the ccw_device_resume() routine.
0424
0425 ::
0426
0427 int ccw_device_resume(struct ccw_device *cdev);
0428
0429 ==== ================================================
0430 cdev ccw_device the resume operation is requested for
0431 ==== ================================================
0432
0433 The ccw_device_resume() function returns:
0434
0435 ========= ==============================================
0436 0 suspended channel program is resumed
0437 -EBUSY status pending
0438 -ENODEV cdev invalid or not-operational subchannel
0439 -EINVAL resume function not applicable
0440 -ENOTCONN there is no I/O request pending for completion
0441 ========= ==============================================
0442
0443 Usage Notes:
0444
0445 Please have a look at the ccw_device_start() usage notes for more details on
0446 suspended channel programs.
0447
0448 ccw_device_halt() - Halt I/O Request Processing
0449
0450 Sometimes a device driver might need a possibility to stop the processing of
0451 a long-running channel program or the device might require to initially issue
0452 a halt subchannel (HSCH) I/O command. For those purposes the ccw_device_halt()
0453 command is provided.
0454
0455 ccw_device_halt() must be called disabled and with the ccw device lock held.
0456
0457 ::
0458
0459 int ccw_device_halt(struct ccw_device *cdev,
0460 unsigned long intparm);
0461
0462 ======= =====================================================
0463 cdev ccw_device the halt operation is requested for
0464 intparm interruption parameter; value is only used if no I/O
0465 is outstanding, otherwise the intparm associated with
0466 the I/O request is returned
0467 ======= =====================================================
0468
0469 The ccw_device_halt() function returns:
0470
0471 ======= ==============================================================
0472 0 request successfully initiated
0473 -EBUSY the device is currently busy, or status pending.
0474 -ENODEV cdev invalid.
0475 -EINVAL The device is not operational or the ccw device is not online.
0476 ======= ==============================================================
0477
0478 Usage Notes:
0479
0480 A device driver may write a never-ending channel program by writing a channel
0481 program that at its end loops back to its beginning by means of a transfer in
0482 channel (TIC) command (CCW_CMD_TIC). Usually this is performed by network
0483 device drivers by setting the PCI CCW flag (CCW_FLAG_PCI). Once this CCW is
0484 executed a program controlled interrupt (PCI) is generated. The device driver
0485 can then perform an appropriate action. Prior to interrupt of an outstanding
0486 read to a network device (with or without PCI flag) a ccw_device_halt()
0487 is required to end the pending operation.
0488
0489 ::
0490
0491 ccw_device_clear() - Terminage I/O Request Processing
0492
0493 In order to terminate all I/O processing at the subchannel, the clear subchannel
0494 (CSCH) command is used. It can be issued via ccw_device_clear().
0495
0496 ccw_device_clear() must be called disabled and with the ccw device lock held.
0497
0498 ::
0499
0500 int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm);
0501
0502 ======= ===============================================
0503 cdev ccw_device the clear operation is requested for
0504 intparm interruption parameter (see ccw_device_halt())
0505 ======= ===============================================
0506
0507 The ccw_device_clear() function returns:
0508
0509 ======= ==============================================================
0510 0 request successfully initiated
0511 -ENODEV cdev invalid
0512 -EINVAL The device is not operational or the ccw device is not online.
0513 ======= ==============================================================
0514
0515 Miscellaneous Support Routines
0516 ------------------------------
0517
0518 This chapter describes various routines to be used in a Linux/390 device
0519 driver programming environment.
0520
0521 get_ccwdev_lock()
0522
0523 Get the address of the device specific lock. This is then used in
0524 spin_lock() / spin_unlock() calls.
0525
0526 ::
0527
0528 __u8 ccw_device_get_path_mask(struct ccw_device *cdev);
0529
0530 Get the mask of the path currently available for cdev.