cds.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. Linux for S/390 and zSeries
  2. Common Device Support (CDS)
  3. Device Driver I/O Support Routines
  4. Authors : Ingo Adlung
  5. Cornelia Huck
  6. Copyright, IBM Corp. 1999-2002
  7. Introduction
  8. This document describes the common device support routines for Linux/390.
  9. Different than other hardware architectures, ESA/390 has defined a unified
  10. I/O access method. This gives relief to the device drivers as they don't
  11. have to deal with different bus types, polling versus interrupt
  12. processing, shared versus non-shared interrupt processing, DMA versus port
  13. I/O (PIO), and other hardware features more. However, this implies that
  14. either every single device driver needs to implement the hardware I/O
  15. attachment functionality itself, or the operating system provides for a
  16. unified method to access the hardware, providing all the functionality that
  17. every single device driver would have to provide itself.
  18. The document does not intend to explain the ESA/390 hardware architecture in
  19. every detail.This information can be obtained from the ESA/390 Principles of
  20. Operation manual (IBM Form. No. SA22-7201).
  21. In order to build common device support for ESA/390 I/O interfaces, a
  22. functional layer was introduced that provides generic I/O access methods to
  23. the hardware.
  24. The common device support layer comprises the I/O support routines defined
  25. below. Some of them implement common Linux device driver interfaces, while
  26. some of them are ESA/390 platform specific.
  27. Note:
  28. In order to write a driver for S/390, you also need to look into the interface
  29. described in Documentation/s390/driver-model.txt.
  30. Note for porting drivers from 2.4:
  31. The major changes are:
  32. * The functions use a ccw_device instead of an irq (subchannel).
  33. * All drivers must define a ccw_driver (see driver-model.txt) and the associated
  34. functions.
  35. * request_irq() and free_irq() are no longer done by the driver.
  36. * The oper_handler is (kindof) replaced by the probe() and set_online() functions
  37. of the ccw_driver.
  38. * The not_oper_handler is (kindof) replaced by the remove() and set_offline()
  39. functions of the ccw_driver.
  40. * The channel device layer is gone.
  41. * The interrupt handlers must be adapted to use a ccw_device as argument.
  42. Moreover, they don't return a devstat, but an irb.
  43. * Before initiating an io, the options must be set via ccw_device_set_options().
  44. read_dev_chars()
  45. read device characteristics
  46. read_conf_data()
  47. read_conf_data_lpm()
  48. read configuration data.
  49. ccw_device_get_ciw()
  50. get commands from extended sense data.
  51. ccw_device_start()
  52. ccw_device_start_timeout()
  53. ccw_device_start_key()
  54. ccw_device_start_key_timeout()
  55. initiate an I/O request.
  56. ccw_device_resume()
  57. resume channel program execution.
  58. ccw_device_halt()
  59. terminate the current I/O request processed on the device.
  60. do_IRQ()
  61. generic interrupt routine. This function is called by the interrupt entry
  62. routine whenever an I/O interrupt is presented to the system. The do_IRQ()
  63. routine determines the interrupt status and calls the device specific
  64. interrupt handler according to the rules (flags) defined during I/O request
  65. initiation with do_IO().
  66. The next chapters describe the functions other than do_IRQ() in more details.
  67. The do_IRQ() interface is not described, as it is called from the Linux/390
  68. first level interrupt handler only and does not comprise a device driver
  69. callable interface. Instead, the functional description of do_IO() also
  70. describes the input to the device specific interrupt handler.
  71. Note: All explanations apply also to the 64 bit architecture s390x.
  72. Common Device Support (CDS) for Linux/390 Device Drivers
  73. General Information
  74. The following chapters describe the I/O related interface routines the
  75. Linux/390 common device support (CDS) provides to allow for device specific
  76. driver implementations on the IBM ESA/390 hardware platform. Those interfaces
  77. intend to provide the functionality required by every device driver
  78. implementaion to allow to drive a specific hardware device on the ESA/390
  79. platform. Some of the interface routines are specific to Linux/390 and some
  80. of them can be found on other Linux platforms implementations too.
  81. Miscellaneous function prototypes, data declarations, and macro definitions
  82. can be found in the architecture specific C header file
  83. linux/include/asm-s390/irq.h.
  84. Overview of CDS interface concepts
  85. Different to other hardware platforms, the ESA/390 architecture doesn't define
  86. interrupt lines managed by a specific interrupt controller and bus systems
  87. that may or may not allow for shared interrupts, DMA processing, etc.. Instead,
  88. the ESA/390 architecture has implemented a so called channel subsystem, that
  89. provides a unified view of the devices physically attached to the systems.
  90. Though the ESA/390 hardware platform knows about a huge variety of different
  91. peripheral attachments like disk devices (aka. DASDs), tapes, communication
  92. controllers, etc. they can all by accessed by a well defined access method and
  93. they are presenting I/O completion a unified way : I/O interruptions. Every
  94. single device is uniquely identified to the system by a so called subchannel,
  95. where the ESA/390 architecture allows for 64k devices be attached.
  96. Linux, however, was first built on the Intel PC architecture, with its two
  97. cascaded 8259 programmable interrupt controllers (PICs), that allow for a
  98. maximum of 15 different interrupt lines. All devices attached to such a system
  99. share those 15 interrupt levels. Devices attached to the ISA bus system must
  100. not share interrupt levels (aka. IRQs), as the ISA bus bases on edge triggered
  101. interrupts. MCA, EISA, PCI and other bus systems base on level triggered
  102. interrupts, and therewith allow for shared IRQs. However, if multiple devices
  103. present their hardware status by the same (shared) IRQ, the operating system
  104. has to call every single device driver registered on this IRQ in order to
  105. determine the device driver owning the device that raised the interrupt.
  106. In order not to introduce a new I/O concept to the common Linux code,
  107. Linux/390 preserves the IRQ concept and semantically maps the ESA/390
  108. subchannels to Linux as IRQs. This allows Linux/390 to support up to 64k
  109. different IRQs, uniquely representing a single device each.
  110. Up to kernel 2.4, Linux/390 used to provide interfaces via the IRQ (subchannel).
  111. For internal use of the common I/O layer, these are still there. However,
  112. device drivers should use the new calling interface via the ccw_device only.
  113. During its startup the Linux/390 system checks for peripheral devices. Each
  114. of those devices is uniquely defined by a so called subchannel by the ESA/390
  115. channel subsystem. While the subchannel numbers are system generated, each
  116. subchannel also takes a user defined attribute, the so called device number.
  117. Both subchannel number and device number cannot exceed 65535. During driverfs
  118. initialisation, the information about control unit type and device types that
  119. imply specific I/O commands (channel command words - CCWs) in order to operate
  120. the device are gathered. Device drivers can retrieve this set of hardware
  121. information during their initialization step to recognize the devices they
  122. support using the information saved in the struct ccw_device given to them.
  123. This methods implies that Linux/390 doesn't require to probe for free (not
  124. armed) interrupt request lines (IRQs) to drive its devices with. Where
  125. applicable, the device drivers can use the read_dev_chars() to retrieve device
  126. characteristics. This can be done without having to request device ownership
  127. previously.
  128. In order to allow for easy I/O initiation the CDS layer provides a
  129. ccw_device_start() interface that takes a device specific channel program (one
  130. or more CCWs) as input sets up the required architecture specific control blocks
  131. and initiates an I/O request on behalf of the device driver. The
  132. ccw_device_start() routine allows to specify whether it expects the CDS layer
  133. to notify the device driver for every interrupt it observes, or with final status
  134. only. See ccw_device_start() for more details. A device driver must never issue
  135. ESA/390 I/O commands itself, but must use the Linux/390 CDS interfaces instead.
  136. For long running I/O request to be canceled, the CDS layer provides the
  137. ccw_device_halt() function. Some devices require to initially issue a HALT
  138. SUBCHANNEL (HSCH) command without having pending I/O requests. This function is
  139. also covered by ccw_device_halt().
  140. read_dev_chars() - Read Device Characteristics
  141. This routine returns the characteristics for the device specified.
  142. The function is meant to be called with the device already enabled; that is,
  143. at earliest during set_online() processing.
  144. The ccw_device must not be locked prior to calling read_dev_chars().
  145. The function may be called enabled or disabled.
  146. int read_dev_chars(struct ccw_device *cdev, void **buffer, int length );
  147. cdev - the ccw_device the information is requested for.
  148. buffer - pointer to a buffer pointer. The buffer pointer itself
  149. must contain a valid buffer area.
  150. length - length of the buffer provided.
  151. The read_dev_chars() function returns :
  152. 0 - successful completion
  153. -ENODEV - cdev invalid
  154. -EINVAL - an invalid parameter was detected, or the function was called early.
  155. -EBUSY - an irrecoverable I/O error occurred or the device is not
  156. operational.
  157. read_conf_data(), read_conf_data_lpm() - Read Configuration Data
  158. Retrieve the device dependent configuration data. Please have a look at your
  159. device dependent I/O commands for the device specific layout of the node
  160. descriptor elements. read_conf_data_lpm() will retrieve the configuration data
  161. for a specific path.
  162. The function is meant to be called with the device already enabled; that is,
  163. at earliest during set_online() processing.
  164. The function may be called enabled or disabled, but the device must not be
  165. locked
  166. int read_conf_data(struct ccw_device, void **buffer, int *length);
  167. int read_conf_data_lpm(struct ccw_device, void **buffer, int *length, __u8 lpm);
  168. cdev - the ccw_device the data is requested for.
  169. buffer - Pointer to a buffer pointer. The read_conf_data() routine
  170. will allocate a buffer and initialize the buffer pointer
  171. accordingly. It's the device driver's responsibility to
  172. release the kernel memory if no longer needed.
  173. length - Length of the buffer allocated and retrieved.
  174. lpm - Logical path mask to be used for retrieving the data. If
  175. zero the data is retrieved on the next path available.
  176. The read_conf_data() function returns :
  177. 0 - Successful completion
  178. -ENODEV - cdev invalid.
  179. -EINVAL - An invalid parameter was detected, or the function was called early.
  180. -EIO - An irrecoverable I/O error occurred or the device is
  181. not operational.
  182. -ENOMEM - The read_conf_data() routine couldn't obtain storage.
  183. -EOPNOTSUPP - The device doesn't support the read configuration
  184. data command.
  185. get_ciw() - get command information word
  186. This call enables a device driver to get information about supported commands
  187. from the extended SenseID data.
  188. struct ciw *
  189. ccw_device_get_ciw(struct ccw_device *cdev, __u32 cmd);
  190. cdev - The ccw_device for which the command is to be retrieved.
  191. cmd - The command type to be retrieved.
  192. ccw_device_get_ciw() returns:
  193. NULL - No extended data available, invalid device or command not found.
  194. !NULL - The command requested.
  195. ccw_device_start() - Initiate I/O Request
  196. The ccw_device_start() routines is the I/O request front-end processor. All
  197. device driver I/O requests must be issued using this routine. A device driver
  198. must not issue ESA/390 I/O commands itself. Instead the ccw_device_start()
  199. routine provides all interfaces required to drive arbitrary devices.
  200. This description also covers the status information passed to the device
  201. driver's interrupt handler as this is related to the rules (flags) defined
  202. with the associated I/O request when calling ccw_device_start().
  203. int ccw_device_start(struct ccw_device *cdev,
  204. struct ccw1 *cpa,
  205. unsigned long intparm,
  206. __u8 lpm,
  207. unsigned long flags);
  208. int ccw_device_start_timeout(struct ccw_device *cdev,
  209. struct ccw1 *cpa,
  210. unsigned long intparm,
  211. __u8 lpm,
  212. unsigned long flags,
  213. int expires);
  214. int ccw_device_start_key(struct ccw_device *cdev,
  215. struct ccw1 *cpa,
  216. unsigned long intparm,
  217. __u8 lpm,
  218. __u8 key,
  219. unsigned long flags);
  220. int ccw_device_start_key_timeout(struct ccw_device *cdev,
  221. struct ccw1 *cpa,
  222. unsigned long intparm,
  223. __u8 lpm,
  224. __u8 key,
  225. unsigned long flags,
  226. int expires);
  227. cdev : ccw_device the I/O is destined for
  228. cpa : logical start address of channel program
  229. user_intparm : user specific interrupt information; will be presented
  230. back to the device driver's interrupt handler. Allows a
  231. device driver to associate the interrupt with a
  232. particular I/O request.
  233. lpm : defines the channel path to be used for a specific I/O
  234. request. A value of 0 will make cio use the opm.
  235. key : the storage key to use for the I/O (useful for operating on a
  236. storage with a storage key != default key)
  237. flag : defines the action to be performed for I/O processing
  238. expires : timeout value in jiffies. The common I/O layer will terminate
  239. the running program after this and call the interrupt handler
  240. with ERR_PTR(-ETIMEDOUT) as irb.
  241. Possible flag values are :
  242. DOIO_ALLOW_SUSPEND - channel program may become suspended
  243. DOIO_DENY_PREFETCH - don't allow for CCW prefetch; usually
  244. this implies the channel program might
  245. become modified
  246. DOIO_SUPPRESS_INTER - don't call the handler on intermediate status
  247. The cpa parameter points to the first format 1 CCW of a channel program :
  248. struct ccw1 {
  249. __u8 cmd_code;/* command code */
  250. __u8 flags; /* flags, like IDA addressing, etc. */
  251. __u16 count; /* byte count */
  252. __u32 cda; /* data address */
  253. } __attribute__ ((packed,aligned(8)));
  254. with the following CCW flags values defined :
  255. CCW_FLAG_DC - data chaining
  256. CCW_FLAG_CC - command chaining
  257. CCW_FLAG_SLI - suppress incorrect length
  258. CCW_FLAG_SKIP - skip
  259. CCW_FLAG_PCI - PCI
  260. CCW_FLAG_IDA - indirect addressing
  261. CCW_FLAG_SUSPEND - suspend
  262. Via ccw_device_set_options(), the device driver may specify the following
  263. options for the device:
  264. DOIO_EARLY_NOTIFICATION - allow for early interrupt notification
  265. DOIO_REPORT_ALL - report all interrupt conditions
  266. The ccw_device_start() function returns :
  267. 0 - successful completion or request successfully initiated
  268. -EBUSY - The device is currently processing a previous I/O request, or ther is
  269. a status pending at the device.
  270. -ENODEV - cdev is invalid, the device is not operational or the ccw_device is
  271. not online.
  272. When the I/O request completes, the CDS first level interrupt handler will
  273. accumulate the status in a struct irb and then call the device interrupt handler.
  274. The intparm field will contain the value the device driver has associated with a
  275. particular I/O request. If a pending device status was recognized,
  276. intparm will be set to 0 (zero). This may happen during I/O initiation or delayed
  277. by an alert status notification. In any case this status is not related to the
  278. current (last) I/O request. In case of a delayed status notification no special
  279. interrupt will be presented to indicate I/O completion as the I/O request was
  280. never started, even though ccw_device_start() returned with successful completion.
  281. The irb may contain an error value, and the device driver should check for this
  282. first:
  283. -ETIMEDOUT: the common I/O layer terminated the request after the specified
  284. timeout value
  285. -EIO: the common I/O layer terminated the request due to an error state
  286. If the concurrent sense flag in the extended status word in the irb is set, the
  287. field irb->scsw.count describes the numer of device specific sense bytes
  288. available in the extended control word irb->scsw.ecw[0]. No device sensing by
  289. the device driver itself is required.
  290. The device interrupt handler can use the following definitions to investigate
  291. the primary unit check source coded in sense byte 0 :
  292. SNS0_CMD_REJECT 0x80
  293. SNS0_INTERVENTION_REQ 0x40
  294. SNS0_BUS_OUT_CHECK 0x20
  295. SNS0_EQUIPMENT_CHECK 0x10
  296. SNS0_DATA_CHECK 0x08
  297. SNS0_OVERRUN 0x04
  298. SNS0_INCOMPL_DOMAIN 0x01
  299. Depending on the device status, multiple of those values may be set together.
  300. Please refer to the device specific documentation for details.
  301. The irb->scsw.cstat field provides the (accumulated) subchannel status :
  302. SCHN_STAT_PCI - program controlled interrupt
  303. SCHN_STAT_INCORR_LEN - incorrect length
  304. SCHN_STAT_PROG_CHECK - program check
  305. SCHN_STAT_PROT_CHECK - protection check
  306. SCHN_STAT_CHN_DATA_CHK - channel data check
  307. SCHN_STAT_CHN_CTRL_CHK - channel control check
  308. SCHN_STAT_INTF_CTRL_CHK - interface control check
  309. SCHN_STAT_CHAIN_CHECK - chaining check
  310. The irb->scsw.dstat field provides the (accumulated) device status :
  311. DEV_STAT_ATTENTION - attention
  312. DEV_STAT_STAT_MOD - status modifier
  313. DEV_STAT_CU_END - control unit end
  314. DEV_STAT_BUSY - busy
  315. DEV_STAT_CHN_END - channel end
  316. DEV_STAT_DEV_END - device end
  317. DEV_STAT_UNIT_CHECK - unit check
  318. DEV_STAT_UNIT_EXCEP - unit exception
  319. Please see the ESA/390 Principles of Operation manual for details on the
  320. individual flag meanings.
  321. Usage Notes :
  322. ccw_device_start() must be called disabled and with the ccw device lock held.
  323. The device driver is allowed to issue the next ccw_device_start() call from
  324. within its interrupt handler already. It is not required to schedule a
  325. bottom-half, unless an non deterministically long running error recovery procedure
  326. or similar needs to be scheduled. During I/O processing the Linux/390 generic
  327. I/O device driver support has already obtained the IRQ lock, i.e. the handler
  328. must not try to obtain it again when calling ccw_device_start() or we end in a
  329. deadlock situation!
  330. If a device driver relies on an I/O request to be completed prior to start the
  331. next it can reduce I/O processing overhead by chaining a NoOp I/O command
  332. CCW_CMD_NOOP to the end of the submitted CCW chain. This will force Channel-End
  333. and Device-End status to be presented together, with a single interrupt.
  334. However, this should be used with care as it implies the channel will remain
  335. busy, not being able to process I/O requests for other devices on the same
  336. channel. Therefore e.g. read commands should never use this technique, as the
  337. result will be presented by a single interrupt anyway.
  338. In order to minimize I/O overhead, a device driver should use the
  339. DOIO_REPORT_ALL only if the device can report intermediate interrupt
  340. information prior to device-end the device driver urgently relies on. In this
  341. case all I/O interruptions are presented to the device driver until final
  342. status is recognized.
  343. If a device is able to recover from asynchronosly presented I/O errors, it can
  344. perform overlapping I/O using the DOIO_EARLY_NOTIFICATION flag. While some
  345. devices always report channel-end and device-end together, with a single
  346. interrupt, others present primary status (channel-end) when the channel is
  347. ready for the next I/O request and secondary status (device-end) when the data
  348. transmission has been completed at the device.
  349. Above flag allows to exploit this feature, e.g. for communication devices that
  350. can handle lost data on the network to allow for enhanced I/O processing.
  351. Unless the channel subsystem at any time presents a secondary status interrupt,
  352. exploiting this feature will cause only primary status interrupts to be
  353. presented to the device driver while overlapping I/O is performed. When a
  354. secondary status without error (alert status) is presented, this indicates
  355. successful completion for all overlapping ccw_device_start() requests that have
  356. been issued since the last secondary (final) status.
  357. Channel programs that intend to set the suspend flag on a channel command word
  358. (CCW) must start the I/O operation with the DOIO_ALLOW_SUSPEND option or the
  359. suspend flag will cause a channel program check. At the time the channel program
  360. becomes suspended an intermediate interrupt will be generated by the channel
  361. subsystem.
  362. ccw_device_resume() - Resume Channel Program Execution
  363. If a device driver chooses to suspend the current channel program execution by
  364. setting the CCW suspend flag on a particular CCW, the channel program execution
  365. is suspended. In order to resume channel program execution the CIO layer
  366. provides the ccw_device_resume() routine.
  367. int ccw_device_resume(struct ccw_device *cdev);
  368. cdev - ccw_device the resume operation is requested for
  369. The ccw_device_resume() function returns:
  370. 0 - suspended channel program is resumed
  371. -EBUSY - status pending
  372. -ENODEV - cdev invalid or not-operational subchannel
  373. -EINVAL - resume function not applicable
  374. -ENOTCONN - there is no I/O request pending for completion
  375. Usage Notes:
  376. Please have a look at the ccw_device_start() usage notes for more details on
  377. suspended channel programs.
  378. ccw_device_halt() - Halt I/O Request Processing
  379. Sometimes a device driver might need a possibility to stop the processing of
  380. a long-running channel program or the device might require to initially issue
  381. a halt subchannel (HSCH) I/O command. For those purposes the ccw_device_halt()
  382. command is provided.
  383. ccw_device_halt() must be called disabled and with the ccw device lock held.
  384. int ccw_device_halt(struct ccw_device *cdev,
  385. unsigned long intparm);
  386. cdev : ccw_device the halt operation is requested for
  387. intparm : interruption parameter; value is only used if no I/O
  388. is outstanding, otherwise the intparm associated with
  389. the I/O request is returned
  390. The ccw_device_halt() function returns :
  391. 0 - request successfully initiated
  392. -EBUSY - the device is currently busy, or status pending.
  393. -ENODEV - cdev invalid.
  394. -EINVAL - The device is not operational or the ccw device is not online.
  395. Usage Notes :
  396. A device driver may write a never-ending channel program by writing a channel
  397. program that at its end loops back to its beginning by means of a transfer in
  398. channel (TIC) command (CCW_CMD_TIC). Usually this is performed by network
  399. device drivers by setting the PCI CCW flag (CCW_FLAG_PCI). Once this CCW is
  400. executed a program controlled interrupt (PCI) is generated. The device driver
  401. can then perform an appropriate action. Prior to interrupt of an outstanding
  402. read to a network device (with or without PCI flag) a ccw_device_halt()
  403. is required to end the pending operation.
  404. ccw_device_clear() - Terminage I/O Request Processing
  405. In order to terminate all I/O processing at the subchannel, the clear subchannel
  406. (CSCH) command is used. It can be issued via ccw_device_clear().
  407. ccw_device_clear() must be called disabled and with the ccw device lock held.
  408. int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm);
  409. cdev: ccw_device the clear operation is requested for
  410. intparm: interruption parameter (see ccw_device_halt())
  411. The ccw_device_clear() function returns:
  412. 0 - request successfully initiated
  413. -ENODEV - cdev invalid
  414. -EINVAL - The device is not operational or the ccw device is not online.
  415. Miscellaneous Support Routines
  416. This chapter describes various routines to be used in a Linux/390 device
  417. driver programming environment.
  418. get_ccwdev_lock()
  419. Get the address of the device specific lock. This is then used in
  420. spin_lock() / spin_unlock() calls.
  421. __u8 ccw_device_get_path_mask(struct ccw_device *cdev);
  422. Get the mask of the path currently available for cdev.