/* SPDX-License-Identifier: GPL-2.0 */1/*2* Common interface for I/O on S/3903*/4#ifndef _ASM_S390_CIO_H_5#define _ASM_S390_CIO_H_67#include <linux/bitops.h>8#include <linux/genalloc.h>9#include <asm/dma-types.h>10#include <asm/types.h>11#include <asm/tpi.h>1213#define LPM_ANYPATH 0xff14#define __MAX_CSSID 015#define __MAX_SUBCHANNEL 6553516#define __MAX_SSID 31718#include <asm/scsw.h>1920#define CCW_MAX_BYTE_COUNT 655352122/**23* struct ccw1 - channel command word24* @cmd_code: command code25* @flags: flags, like IDA addressing, etc.26* @count: byte count27* @cda: data address28*29* The ccw is the basic structure to build channel programs that perform30* operations with the device or the control unit. Only Format-1 channel31* command words are supported.32*/33struct ccw1 {34__u8 cmd_code;35__u8 flags;36__u16 count;37dma32_t cda;38} __attribute__ ((packed,aligned(8)));3940/**41* struct ccw0 - channel command word42* @cmd_code: command code43* @cda: data address44* @flags: flags, like IDA addressing, etc.45* @reserved: will be ignored46* @count: byte count47*48* The format-0 ccw structure.49*/50struct ccw0 {51__u8 cmd_code;52__u32 cda : 24;53__u8 flags;54__u8 reserved;55__u16 count;56} __packed __aligned(8);5758#define CCW_FLAG_DC 0x8059#define CCW_FLAG_CC 0x4060#define CCW_FLAG_SLI 0x2061#define CCW_FLAG_SKIP 0x1062#define CCW_FLAG_PCI 0x0863#define CCW_FLAG_IDA 0x0464#define CCW_FLAG_SUSPEND 0x026566#define CCW_CMD_READ_IPL 0x0267#define CCW_CMD_NOOP 0x0368#define CCW_CMD_BASIC_SENSE 0x0469#define CCW_CMD_TIC 0x0870#define CCW_CMD_STLCK 0x1471#define CCW_CMD_SENSE_PGID 0x3472#define CCW_CMD_SUSPEND_RECONN 0x5B73#define CCW_CMD_RDC 0x6474#define CCW_CMD_RELEASE 0x9475#define CCW_CMD_SET_PGID 0xAF76#define CCW_CMD_SENSE_ID 0xE477#define CCW_CMD_DCTL 0xF37879#define SENSE_MAX_COUNT 0x208081/**82* struct erw - extended report word83* @res0: reserved84* @auth: authorization check85* @pvrf: path-verification-required flag86* @cpt: channel-path timeout87* @fsavf: failing storage address validity flag88* @cons: concurrent sense89* @scavf: secondary ccw address validity flag90* @fsaf: failing storage address format91* @scnt: sense count, if @cons == %192* @res16: reserved93*/94struct erw {95__u32 res0 : 3;96__u32 auth : 1;97__u32 pvrf : 1;98__u32 cpt : 1;99__u32 fsavf : 1;100__u32 cons : 1;101__u32 scavf : 1;102__u32 fsaf : 1;103__u32 scnt : 6;104__u32 res16 : 16;105} __attribute__ ((packed));106107/**108* struct erw_eadm - EADM Subchannel extended report word109* @b: aob error110* @r: arsb error111*/112struct erw_eadm {113__u32 : 16;114__u32 b : 1;115__u32 r : 1;116__u32 : 14;117} __packed;118119/**120* struct sublog - subchannel logout area121* @res0: reserved122* @esf: extended status flags123* @lpum: last path used mask124* @arep: ancillary report125* @fvf: field-validity flags126* @sacc: storage access code127* @termc: termination code128* @devsc: device-status check129* @serr: secondary error130* @ioerr: i/o-error alert131* @seqc: sequence code132*/133struct sublog {134__u32 res0 : 1;135__u32 esf : 7;136__u32 lpum : 8;137__u32 arep : 1;138__u32 fvf : 5;139__u32 sacc : 2;140__u32 termc : 2;141__u32 devsc : 1;142__u32 serr : 1;143__u32 ioerr : 1;144__u32 seqc : 3;145} __attribute__ ((packed));146147/**148* struct esw0 - Format 0 Extended Status Word (ESW)149* @sublog: subchannel logout150* @erw: extended report word151* @faddr: failing storage address152* @saddr: secondary ccw address153*/154struct esw0 {155struct sublog sublog;156struct erw erw;157dma32_t faddr[2];158dma32_t saddr;159} __attribute__ ((packed));160161/**162* struct esw1 - Format 1 Extended Status Word (ESW)163* @zero0: reserved zeros164* @lpum: last path used mask165* @zero16: reserved zeros166* @erw: extended report word167* @zeros: three fullwords of zeros168*/169struct esw1 {170__u8 zero0;171__u8 lpum;172__u16 zero16;173struct erw erw;174__u32 zeros[3];175} __attribute__ ((packed));176177/**178* struct esw2 - Format 2 Extended Status Word (ESW)179* @zero0: reserved zeros180* @lpum: last path used mask181* @dcti: device-connect-time interval182* @erw: extended report word183* @zeros: three fullwords of zeros184*/185struct esw2 {186__u8 zero0;187__u8 lpum;188__u16 dcti;189struct erw erw;190__u32 zeros[3];191} __attribute__ ((packed));192193/**194* struct esw3 - Format 3 Extended Status Word (ESW)195* @zero0: reserved zeros196* @lpum: last path used mask197* @res: reserved198* @erw: extended report word199* @zeros: three fullwords of zeros200*/201struct esw3 {202__u8 zero0;203__u8 lpum;204__u16 res;205struct erw erw;206__u32 zeros[3];207} __attribute__ ((packed));208209/**210* struct esw_eadm - EADM Subchannel Extended Status Word (ESW)211* @sublog: subchannel logout212* @erw: extended report word213*/214struct esw_eadm {215__u32 sublog;216struct erw_eadm erw;217__u32 : 32;218__u32 : 32;219__u32 : 32;220} __packed;221222/**223* struct irb - interruption response block224* @scsw: subchannel status word225* @esw: extended status word226* @ecw: extended control word227*228* The irb that is handed to the device driver when an interrupt occurs. For229* solicited interrupts, the common I/O layer already performs checks whether230* a field is valid; a field not being valid is always passed as %0.231* If a unit check occurred, @ecw may contain sense data; this is retrieved232* by the common I/O layer itself if the device doesn't support concurrent233* sense (so that the device driver never needs to perform basic sense itself).234* For unsolicited interrupts, the irb is passed as-is (expect for sense data,235* if applicable).236*/237struct irb {238union scsw scsw;239union {240struct esw0 esw0;241struct esw1 esw1;242struct esw2 esw2;243struct esw3 esw3;244struct esw_eadm eadm;245} esw;246__u8 ecw[32];247} __attribute__ ((packed,aligned(4)));248249/**250* struct ciw - command information word (CIW) layout251* @et: entry type252* @reserved: reserved bits253* @ct: command type254* @cmd: command code255* @count: command count256*/257struct ciw {258__u32 et : 2;259__u32 reserved : 2;260__u32 ct : 4;261__u32 cmd : 8;262__u32 count : 16;263} __attribute__ ((packed));264265#define CIW_TYPE_RCD 0x0 /* read configuration data */266#define CIW_TYPE_SII 0x1 /* set interface identifier */267#define CIW_TYPE_RNI 0x2 /* read node identifier */268269/*270* Node Descriptor as defined in SA22-7204, "Common I/O-Device Commands"271*/272273#define ND_VALIDITY_VALID 0274#define ND_VALIDITY_OUTDATED 1275#define ND_VALIDITY_INVALID 2276277struct node_descriptor {278/* Flags. */279union {280struct {281u32 validity:3;282u32 reserved:5;283} __packed;284u8 byte0;285} __packed;286287/* Node parameters. */288u32 params:24;289290/* Node ID. */291char type[6];292char model[3];293char manufacturer[3];294char plant[2];295char seq[12];296u16 tag;297} __packed;298299/*300* Flags used as input parameters for do_IO()301*/302#define DOIO_ALLOW_SUSPEND 0x0001 /* allow for channel prog. suspend */303#define DOIO_DENY_PREFETCH 0x0002 /* don't allow for CCW prefetch */304#define DOIO_SUPPRESS_INTER 0x0004 /* suppress intermediate inter. */305/* ... for suspended CCWs */306/* Device or subchannel gone. */307#define CIO_GONE 0x0001308/* No path to device. */309#define CIO_NO_PATH 0x0002310/* Device has appeared. */311#define CIO_OPER 0x0004312/* Sick revalidation of device. */313#define CIO_REVALIDATE 0x0008314/* Device did not respond in time. */315#define CIO_BOXED 0x0010316317/**318* struct ccw_dev_id - unique identifier for ccw devices319* @ssid: subchannel set id320* @devno: device number321*322* This structure is not directly based on any hardware structure. The323* hardware identifies a device by its device number and its subchannel,324* which is in turn identified by its id. In order to get a unique identifier325* for ccw devices across subchannel sets, @struct ccw_dev_id has been326* introduced.327*/328struct ccw_dev_id {329u8 ssid;330u16 devno;331};332333/**334* ccw_dev_id_is_equal() - compare two ccw_dev_ids335* @dev_id1: a ccw_dev_id336* @dev_id2: another ccw_dev_id337* Returns:338* %1 if the two structures are equal field-by-field,339* %0 if not.340* Context:341* any342*/343static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,344struct ccw_dev_id *dev_id2)345{346if ((dev_id1->ssid == dev_id2->ssid) &&347(dev_id1->devno == dev_id2->devno))348return 1;349return 0;350}351352/**353* pathmask_to_pos() - find the position of the left-most bit in a pathmask354* @mask: pathmask with at least one bit set355*/356static inline u8 pathmask_to_pos(u8 mask)357{358return 8 - ffs(mask);359}360361extern void css_schedule_reprobe(void);362363extern void *cio_dma_zalloc(size_t size);364extern void cio_dma_free(void *cpu_addr, size_t size);365extern struct device *cio_get_dma_css_dev(void);366367void *cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,368size_t size);369void *__cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,370size_t size, dma32_t *dma_handle);371void cio_gp_dma_free(struct gen_pool *gp_dma, void *cpu_addr, size_t size);372void cio_gp_dma_destroy(struct gen_pool *gp_dma, struct device *dma_dev);373struct gen_pool *cio_gp_dma_create(struct device *dma_dev, int nr_pages);374375/* Function from drivers/s390/cio/chsc.c */376int chsc_sstpc(void *page, unsigned int op, u16 ctrl, long *clock_delta);377int chsc_sstpi(void *page, void *result, size_t size);378int chsc_stzi(void *page, void *result, size_t size);379int chsc_sgib(u32 origin);380int chsc_scud(u16 cu, u64 *esm, u8 *esm_valid);381382#endif383384385