/* 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/**21* struct ccw1 - channel command word22* @cmd_code: command code23* @flags: flags, like IDA addressing, etc.24* @count: byte count25* @cda: data address26*27* The ccw is the basic structure to build channel programs that perform28* operations with the device or the control unit. Only Format-1 channel29* command words are supported.30*/31struct ccw1 {32__u8 cmd_code;33__u8 flags;34__u16 count;35dma32_t cda;36} __attribute__ ((packed,aligned(8)));3738/**39* struct ccw0 - channel command word40* @cmd_code: command code41* @cda: data address42* @flags: flags, like IDA addressing, etc.43* @reserved: will be ignored44* @count: byte count45*46* The format-0 ccw structure.47*/48struct ccw0 {49__u8 cmd_code;50__u32 cda : 24;51__u8 flags;52__u8 reserved;53__u16 count;54} __packed __aligned(8);5556#define CCW_FLAG_DC 0x8057#define CCW_FLAG_CC 0x4058#define CCW_FLAG_SLI 0x2059#define CCW_FLAG_SKIP 0x1060#define CCW_FLAG_PCI 0x0861#define CCW_FLAG_IDA 0x0462#define CCW_FLAG_SUSPEND 0x026364#define CCW_CMD_READ_IPL 0x0265#define CCW_CMD_NOOP 0x0366#define CCW_CMD_BASIC_SENSE 0x0467#define CCW_CMD_TIC 0x0868#define CCW_CMD_STLCK 0x1469#define CCW_CMD_SENSE_PGID 0x3470#define CCW_CMD_SUSPEND_RECONN 0x5B71#define CCW_CMD_RDC 0x6472#define CCW_CMD_RELEASE 0x9473#define CCW_CMD_SET_PGID 0xAF74#define CCW_CMD_SENSE_ID 0xE475#define CCW_CMD_DCTL 0xF37677#define SENSE_MAX_COUNT 0x207879/**80* struct erw - extended report word81* @res0: reserved82* @auth: authorization check83* @pvrf: path-verification-required flag84* @cpt: channel-path timeout85* @fsavf: failing storage address validity flag86* @cons: concurrent sense87* @scavf: secondary ccw address validity flag88* @fsaf: failing storage address format89* @scnt: sense count, if @cons == %190* @res16: reserved91*/92struct erw {93__u32 res0 : 3;94__u32 auth : 1;95__u32 pvrf : 1;96__u32 cpt : 1;97__u32 fsavf : 1;98__u32 cons : 1;99__u32 scavf : 1;100__u32 fsaf : 1;101__u32 scnt : 6;102__u32 res16 : 16;103} __attribute__ ((packed));104105/**106* struct erw_eadm - EADM Subchannel extended report word107* @b: aob error108* @r: arsb error109*/110struct erw_eadm {111__u32 : 16;112__u32 b : 1;113__u32 r : 1;114__u32 : 14;115} __packed;116117/**118* struct sublog - subchannel logout area119* @res0: reserved120* @esf: extended status flags121* @lpum: last path used mask122* @arep: ancillary report123* @fvf: field-validity flags124* @sacc: storage access code125* @termc: termination code126* @devsc: device-status check127* @serr: secondary error128* @ioerr: i/o-error alert129* @seqc: sequence code130*/131struct sublog {132__u32 res0 : 1;133__u32 esf : 7;134__u32 lpum : 8;135__u32 arep : 1;136__u32 fvf : 5;137__u32 sacc : 2;138__u32 termc : 2;139__u32 devsc : 1;140__u32 serr : 1;141__u32 ioerr : 1;142__u32 seqc : 3;143} __attribute__ ((packed));144145/**146* struct esw0 - Format 0 Extended Status Word (ESW)147* @sublog: subchannel logout148* @erw: extended report word149* @faddr: failing storage address150* @saddr: secondary ccw address151*/152struct esw0 {153struct sublog sublog;154struct erw erw;155dma32_t faddr[2];156dma32_t saddr;157} __attribute__ ((packed));158159/**160* struct esw1 - Format 1 Extended Status Word (ESW)161* @zero0: reserved zeros162* @lpum: last path used mask163* @zero16: reserved zeros164* @erw: extended report word165* @zeros: three fullwords of zeros166*/167struct esw1 {168__u8 zero0;169__u8 lpum;170__u16 zero16;171struct erw erw;172__u32 zeros[3];173} __attribute__ ((packed));174175/**176* struct esw2 - Format 2 Extended Status Word (ESW)177* @zero0: reserved zeros178* @lpum: last path used mask179* @dcti: device-connect-time interval180* @erw: extended report word181* @zeros: three fullwords of zeros182*/183struct esw2 {184__u8 zero0;185__u8 lpum;186__u16 dcti;187struct erw erw;188__u32 zeros[3];189} __attribute__ ((packed));190191/**192* struct esw3 - Format 3 Extended Status Word (ESW)193* @zero0: reserved zeros194* @lpum: last path used mask195* @res: reserved196* @erw: extended report word197* @zeros: three fullwords of zeros198*/199struct esw3 {200__u8 zero0;201__u8 lpum;202__u16 res;203struct erw erw;204__u32 zeros[3];205} __attribute__ ((packed));206207/**208* struct esw_eadm - EADM Subchannel Extended Status Word (ESW)209* @sublog: subchannel logout210* @erw: extended report word211*/212struct esw_eadm {213__u32 sublog;214struct erw_eadm erw;215__u32 : 32;216__u32 : 32;217__u32 : 32;218} __packed;219220/**221* struct irb - interruption response block222* @scsw: subchannel status word223* @esw: extended status word224* @ecw: extended control word225*226* The irb that is handed to the device driver when an interrupt occurs. For227* solicited interrupts, the common I/O layer already performs checks whether228* a field is valid; a field not being valid is always passed as %0.229* If a unit check occurred, @ecw may contain sense data; this is retrieved230* by the common I/O layer itself if the device doesn't support concurrent231* sense (so that the device driver never needs to perform basic sense itself).232* For unsolicited interrupts, the irb is passed as-is (expect for sense data,233* if applicable).234*/235struct irb {236union scsw scsw;237union {238struct esw0 esw0;239struct esw1 esw1;240struct esw2 esw2;241struct esw3 esw3;242struct esw_eadm eadm;243} esw;244__u8 ecw[32];245} __attribute__ ((packed,aligned(4)));246247/**248* struct ciw - command information word (CIW) layout249* @et: entry type250* @reserved: reserved bits251* @ct: command type252* @cmd: command code253* @count: command count254*/255struct ciw {256__u32 et : 2;257__u32 reserved : 2;258__u32 ct : 4;259__u32 cmd : 8;260__u32 count : 16;261} __attribute__ ((packed));262263#define CIW_TYPE_RCD 0x0 /* read configuration data */264#define CIW_TYPE_SII 0x1 /* set interface identifier */265#define CIW_TYPE_RNI 0x2 /* read node identifier */266267/*268* Node Descriptor as defined in SA22-7204, "Common I/O-Device Commands"269*/270271#define ND_VALIDITY_VALID 0272#define ND_VALIDITY_OUTDATED 1273#define ND_VALIDITY_INVALID 2274275struct node_descriptor {276/* Flags. */277union {278struct {279u32 validity:3;280u32 reserved:5;281} __packed;282u8 byte0;283} __packed;284285/* Node parameters. */286u32 params:24;287288/* Node ID. */289char type[6];290char model[3];291char manufacturer[3];292char plant[2];293char seq[12];294u16 tag;295} __packed;296297/*298* Flags used as input parameters for do_IO()299*/300#define DOIO_ALLOW_SUSPEND 0x0001 /* allow for channel prog. suspend */301#define DOIO_DENY_PREFETCH 0x0002 /* don't allow for CCW prefetch */302#define DOIO_SUPPRESS_INTER 0x0004 /* suppress intermediate inter. */303/* ... for suspended CCWs */304/* Device or subchannel gone. */305#define CIO_GONE 0x0001306/* No path to device. */307#define CIO_NO_PATH 0x0002308/* Device has appeared. */309#define CIO_OPER 0x0004310/* Sick revalidation of device. */311#define CIO_REVALIDATE 0x0008312/* Device did not respond in time. */313#define CIO_BOXED 0x0010314315/**316* struct ccw_dev_id - unique identifier for ccw devices317* @ssid: subchannel set id318* @devno: device number319*320* This structure is not directly based on any hardware structure. The321* hardware identifies a device by its device number and its subchannel,322* which is in turn identified by its id. In order to get a unique identifier323* for ccw devices across subchannel sets, @struct ccw_dev_id has been324* introduced.325*/326struct ccw_dev_id {327u8 ssid;328u16 devno;329};330331/**332* ccw_dev_id_is_equal() - compare two ccw_dev_ids333* @dev_id1: a ccw_dev_id334* @dev_id2: another ccw_dev_id335* Returns:336* %1 if the two structures are equal field-by-field,337* %0 if not.338* Context:339* any340*/341static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,342struct ccw_dev_id *dev_id2)343{344if ((dev_id1->ssid == dev_id2->ssid) &&345(dev_id1->devno == dev_id2->devno))346return 1;347return 0;348}349350/**351* pathmask_to_pos() - find the position of the left-most bit in a pathmask352* @mask: pathmask with at least one bit set353*/354static inline u8 pathmask_to_pos(u8 mask)355{356return 8 - ffs(mask);357}358359extern void css_schedule_reprobe(void);360361extern void *cio_dma_zalloc(size_t size);362extern void cio_dma_free(void *cpu_addr, size_t size);363extern struct device *cio_get_dma_css_dev(void);364365void *cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,366size_t size);367void *__cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,368size_t size, dma32_t *dma_handle);369void cio_gp_dma_free(struct gen_pool *gp_dma, void *cpu_addr, size_t size);370void cio_gp_dma_destroy(struct gen_pool *gp_dma, struct device *dma_dev);371struct gen_pool *cio_gp_dma_create(struct device *dma_dev, int nr_pages);372373/* Function from drivers/s390/cio/chsc.c */374int chsc_sstpc(void *page, unsigned int op, u16 ctrl, long *clock_delta);375int chsc_sstpi(void *page, void *result, size_t size);376int chsc_stzi(void *page, void *result, size_t size);377int chsc_sgib(u32 origin);378int chsc_scud(u16 cu, u64 *esm, u8 *esm_valid);379380#endif381382383