162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * CXL Flash Device Driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 662306a36Sopenharmony_ci * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 2015 IBM Corporation 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef _SISLITE_H 1262306a36Sopenharmony_ci#define _SISLITE_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/types.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_citypedef u16 ctx_hndl_t; 1762306a36Sopenharmony_citypedef u32 res_hndl_t; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define SIZE_4K 4096 2062306a36Sopenharmony_ci#define SIZE_64K 65536 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * IOARCB: 64 bytes, min 16 byte alignment required, host native endianness 2462306a36Sopenharmony_ci * except for SCSI CDB which remains big endian per SCSI standards. 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_cistruct sisl_ioarcb { 2762306a36Sopenharmony_ci u16 ctx_id; /* ctx_hndl_t */ 2862306a36Sopenharmony_ci u16 req_flags; 2962306a36Sopenharmony_ci#define SISL_REQ_FLAGS_RES_HNDL 0x8000U /* bit 0 (MSB) */ 3062306a36Sopenharmony_ci#define SISL_REQ_FLAGS_PORT_LUN_ID 0x0000U 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define SISL_REQ_FLAGS_SUP_UNDERRUN 0x4000U /* bit 1 */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define SISL_REQ_FLAGS_TIMEOUT_SECS 0x0000U /* bits 8,9 */ 3562306a36Sopenharmony_ci#define SISL_REQ_FLAGS_TIMEOUT_MSECS 0x0040U 3662306a36Sopenharmony_ci#define SISL_REQ_FLAGS_TIMEOUT_USECS 0x0080U 3762306a36Sopenharmony_ci#define SISL_REQ_FLAGS_TIMEOUT_CYCLES 0x00C0U 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define SISL_REQ_FLAGS_TMF_CMD 0x0004u /* bit 13 */ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define SISL_REQ_FLAGS_AFU_CMD 0x0002U /* bit 14 */ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define SISL_REQ_FLAGS_HOST_WRITE 0x0001U /* bit 15 (LSB) */ 4462306a36Sopenharmony_ci#define SISL_REQ_FLAGS_HOST_READ 0x0000U 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci union { 4762306a36Sopenharmony_ci u32 res_hndl; /* res_hndl_t */ 4862306a36Sopenharmony_ci u32 port_sel; /* this is a selection mask: 4962306a36Sopenharmony_ci * 0x1 -> port#0 can be selected, 5062306a36Sopenharmony_ci * 0x2 -> port#1 can be selected. 5162306a36Sopenharmony_ci * Can be bitwise ORed. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci }; 5462306a36Sopenharmony_ci u64 lun_id; 5562306a36Sopenharmony_ci u32 data_len; /* 4K for read/write */ 5662306a36Sopenharmony_ci u32 ioadl_len; 5762306a36Sopenharmony_ci union { 5862306a36Sopenharmony_ci u64 data_ea; /* min 16 byte aligned */ 5962306a36Sopenharmony_ci u64 ioadl_ea; 6062306a36Sopenharmony_ci }; 6162306a36Sopenharmony_ci u8 msi; /* LISN to send on RRQ write */ 6262306a36Sopenharmony_ci#define SISL_MSI_CXL_PFAULT 0 /* reserved for CXL page faults */ 6362306a36Sopenharmony_ci#define SISL_MSI_SYNC_ERROR 1 /* recommended for AFU sync error */ 6462306a36Sopenharmony_ci#define SISL_MSI_RRQ_UPDATED 2 /* recommended for IO completion */ 6562306a36Sopenharmony_ci#define SISL_MSI_ASYNC_ERROR 3 /* master only - for AFU async error */ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci u8 rrq; /* 0 for a single RRQ */ 6862306a36Sopenharmony_ci u16 timeout; /* in units specified by req_flags */ 6962306a36Sopenharmony_ci u32 rsvd1; 7062306a36Sopenharmony_ci u8 cdb[16]; /* must be in big endian */ 7162306a36Sopenharmony_ci#define SISL_AFU_CMD_SYNC 0xC0 /* AFU sync command */ 7262306a36Sopenharmony_ci#define SISL_AFU_CMD_LUN_PROVISION 0xD0 /* AFU LUN provision command */ 7362306a36Sopenharmony_ci#define SISL_AFU_CMD_DEBUG 0xE0 /* AFU debug command */ 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define SISL_AFU_LUN_PROVISION_CREATE 0x00 /* LUN provision create type */ 7662306a36Sopenharmony_ci#define SISL_AFU_LUN_PROVISION_DELETE 0x01 /* LUN provision delete type */ 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci union { 7962306a36Sopenharmony_ci u64 reserved; /* Reserved for IOARRIN mode */ 8062306a36Sopenharmony_ci struct sisl_ioasa *ioasa; /* IOASA EA for SQ Mode */ 8162306a36Sopenharmony_ci }; 8262306a36Sopenharmony_ci} __packed; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cistruct sisl_rc { 8562306a36Sopenharmony_ci u8 flags; 8662306a36Sopenharmony_ci#define SISL_RC_FLAGS_SENSE_VALID 0x80U 8762306a36Sopenharmony_ci#define SISL_RC_FLAGS_FCP_RSP_CODE_VALID 0x40U 8862306a36Sopenharmony_ci#define SISL_RC_FLAGS_OVERRUN 0x20U 8962306a36Sopenharmony_ci#define SISL_RC_FLAGS_UNDERRUN 0x10U 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci u8 afu_rc; 9262306a36Sopenharmony_ci#define SISL_AFU_RC_RHT_INVALID 0x01U /* user error */ 9362306a36Sopenharmony_ci#define SISL_AFU_RC_RHT_UNALIGNED 0x02U /* should never happen */ 9462306a36Sopenharmony_ci#define SISL_AFU_RC_RHT_OUT_OF_BOUNDS 0x03u /* user error */ 9562306a36Sopenharmony_ci#define SISL_AFU_RC_RHT_DMA_ERR 0x04u /* see afu_extra 9662306a36Sopenharmony_ci * may retry if afu_retry is off 9762306a36Sopenharmony_ci * possible on master exit 9862306a36Sopenharmony_ci */ 9962306a36Sopenharmony_ci#define SISL_AFU_RC_RHT_RW_PERM 0x05u /* no RW perms, user error */ 10062306a36Sopenharmony_ci#define SISL_AFU_RC_LXT_UNALIGNED 0x12U /* should never happen */ 10162306a36Sopenharmony_ci#define SISL_AFU_RC_LXT_OUT_OF_BOUNDS 0x13u /* user error */ 10262306a36Sopenharmony_ci#define SISL_AFU_RC_LXT_DMA_ERR 0x14u /* see afu_extra 10362306a36Sopenharmony_ci * may retry if afu_retry is off 10462306a36Sopenharmony_ci * possible on master exit 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_ci#define SISL_AFU_RC_LXT_RW_PERM 0x15u /* no RW perms, user error */ 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define SISL_AFU_RC_NOT_XLATE_HOST 0x1au /* possible if master exited */ 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci /* NO_CHANNELS means the FC ports selected by dest_port in 11162306a36Sopenharmony_ci * IOARCB or in the LXT entry are down when the AFU tried to select 11262306a36Sopenharmony_ci * a FC port. If the port went down on an active IO, it will set 11362306a36Sopenharmony_ci * fc_rc to =0x54(NOLOGI) or 0x57(LINKDOWN) instead. 11462306a36Sopenharmony_ci */ 11562306a36Sopenharmony_ci#define SISL_AFU_RC_NO_CHANNELS 0x20U /* see afu_extra, may retry */ 11662306a36Sopenharmony_ci#define SISL_AFU_RC_CAP_VIOLATION 0x21U /* either user error or 11762306a36Sopenharmony_ci * afu reset/master restart 11862306a36Sopenharmony_ci */ 11962306a36Sopenharmony_ci#define SISL_AFU_RC_OUT_OF_DATA_BUFS 0x30U /* always retry */ 12062306a36Sopenharmony_ci#define SISL_AFU_RC_DATA_DMA_ERR 0x31U /* see afu_extra 12162306a36Sopenharmony_ci * may retry if afu_retry is off 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci u8 scsi_rc; /* SCSI status byte, retry as appropriate */ 12562306a36Sopenharmony_ci#define SISL_SCSI_RC_CHECK 0x02U 12662306a36Sopenharmony_ci#define SISL_SCSI_RC_BUSY 0x08u 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci u8 fc_rc; /* retry */ 12962306a36Sopenharmony_ci /* 13062306a36Sopenharmony_ci * We should only see fc_rc=0x57 (LINKDOWN) or 0x54(NOLOGI) for 13162306a36Sopenharmony_ci * commands that are in flight when a link goes down or is logged out. 13262306a36Sopenharmony_ci * If the link is down or logged out before AFU selects the port, either 13362306a36Sopenharmony_ci * it will choose the other port or we will get afu_rc=0x20 (no_channel) 13462306a36Sopenharmony_ci * if there is no valid port to use. 13562306a36Sopenharmony_ci * 13662306a36Sopenharmony_ci * ABORTPEND/ABORTOK/ABORTFAIL/TGTABORT can be retried, typically these 13762306a36Sopenharmony_ci * would happen if a frame is dropped and something times out. 13862306a36Sopenharmony_ci * NOLOGI or LINKDOWN can be retried if the other port is up. 13962306a36Sopenharmony_ci * RESIDERR can be retried as well. 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * ABORTFAIL might indicate that lots of frames are getting CRC errors. 14262306a36Sopenharmony_ci * So it maybe retried once and reset the link if it happens again. 14362306a36Sopenharmony_ci * The link can also be reset on the CRC error threshold interrupt. 14462306a36Sopenharmony_ci */ 14562306a36Sopenharmony_ci#define SISL_FC_RC_ABORTPEND 0x52 /* exchange timeout or abort request */ 14662306a36Sopenharmony_ci#define SISL_FC_RC_WRABORTPEND 0x53 /* due to write XFER_RDY invalid */ 14762306a36Sopenharmony_ci#define SISL_FC_RC_NOLOGI 0x54 /* port not logged in, in-flight cmds */ 14862306a36Sopenharmony_ci#define SISL_FC_RC_NOEXP 0x55 /* FC protocol error or HW bug */ 14962306a36Sopenharmony_ci#define SISL_FC_RC_INUSE 0x56 /* tag already in use, HW bug */ 15062306a36Sopenharmony_ci#define SISL_FC_RC_LINKDOWN 0x57 /* link down, in-flight cmds */ 15162306a36Sopenharmony_ci#define SISL_FC_RC_ABORTOK 0x58 /* pending abort completed w/success */ 15262306a36Sopenharmony_ci#define SISL_FC_RC_ABORTFAIL 0x59 /* pending abort completed w/fail */ 15362306a36Sopenharmony_ci#define SISL_FC_RC_RESID 0x5A /* ioasa underrun/overrun flags set */ 15462306a36Sopenharmony_ci#define SISL_FC_RC_RESIDERR 0x5B /* actual data len does not match SCSI 15562306a36Sopenharmony_ci * reported len, possibly due to dropped 15662306a36Sopenharmony_ci * frames 15762306a36Sopenharmony_ci */ 15862306a36Sopenharmony_ci#define SISL_FC_RC_TGTABORT 0x5C /* command aborted by target */ 15962306a36Sopenharmony_ci}; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#define SISL_SENSE_DATA_LEN 20 /* Sense data length */ 16262306a36Sopenharmony_ci#define SISL_WWID_DATA_LEN 16 /* WWID data length */ 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci/* 16562306a36Sopenharmony_ci * IOASA: 64 bytes & must follow IOARCB, min 16 byte alignment required, 16662306a36Sopenharmony_ci * host native endianness 16762306a36Sopenharmony_ci */ 16862306a36Sopenharmony_cistruct sisl_ioasa { 16962306a36Sopenharmony_ci union { 17062306a36Sopenharmony_ci struct sisl_rc rc; 17162306a36Sopenharmony_ci u32 ioasc; 17262306a36Sopenharmony_ci#define SISL_IOASC_GOOD_COMPLETION 0x00000000U 17362306a36Sopenharmony_ci }; 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci union { 17662306a36Sopenharmony_ci u32 resid; 17762306a36Sopenharmony_ci u32 lunid_hi; 17862306a36Sopenharmony_ci }; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci u8 port; 18162306a36Sopenharmony_ci u8 afu_extra; 18262306a36Sopenharmony_ci /* when afu_rc=0x04, 0x14, 0x31 (_xxx_DMA_ERR): 18362306a36Sopenharmony_ci * afu_exta contains PSL response code. Useful codes are: 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci#define SISL_AFU_DMA_ERR_PAGE_IN 0x0A /* AFU_retry_on_pagein Action 18662306a36Sopenharmony_ci * Enabled N/A 18762306a36Sopenharmony_ci * Disabled retry 18862306a36Sopenharmony_ci */ 18962306a36Sopenharmony_ci#define SISL_AFU_DMA_ERR_INVALID_EA 0x0B /* this is a hard error 19062306a36Sopenharmony_ci * afu_rc Implies 19162306a36Sopenharmony_ci * 0x04, 0x14 master exit. 19262306a36Sopenharmony_ci * 0x31 user error. 19362306a36Sopenharmony_ci */ 19462306a36Sopenharmony_ci /* when afu rc=0x20 (no channels): 19562306a36Sopenharmony_ci * afu_extra bits [4:5]: available portmask, [6:7]: requested portmask. 19662306a36Sopenharmony_ci */ 19762306a36Sopenharmony_ci#define SISL_AFU_NO_CLANNELS_AMASK(afu_extra) (((afu_extra) & 0x0C) >> 2) 19862306a36Sopenharmony_ci#define SISL_AFU_NO_CLANNELS_RMASK(afu_extra) ((afu_extra) & 0x03) 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci u8 scsi_extra; 20162306a36Sopenharmony_ci u8 fc_extra; 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci union { 20462306a36Sopenharmony_ci u8 sense_data[SISL_SENSE_DATA_LEN]; 20562306a36Sopenharmony_ci struct { 20662306a36Sopenharmony_ci u32 lunid_lo; 20762306a36Sopenharmony_ci u8 wwid[SISL_WWID_DATA_LEN]; 20862306a36Sopenharmony_ci }; 20962306a36Sopenharmony_ci }; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci /* These fields are defined by the SISlite architecture for the 21262306a36Sopenharmony_ci * host to use as they see fit for their implementation. 21362306a36Sopenharmony_ci */ 21462306a36Sopenharmony_ci union { 21562306a36Sopenharmony_ci u64 host_use[4]; 21662306a36Sopenharmony_ci u8 host_use_b[32]; 21762306a36Sopenharmony_ci }; 21862306a36Sopenharmony_ci} __packed; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci#define SISL_RESP_HANDLE_T_BIT 0x1ULL /* Toggle bit */ 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci/* MMIO space is required to support only 64-bit access */ 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/* 22562306a36Sopenharmony_ci * This AFU has two mechanisms to deal with endian-ness. 22662306a36Sopenharmony_ci * One is a global configuration (in the afu_config) register 22762306a36Sopenharmony_ci * below that specifies the endian-ness of the host. 22862306a36Sopenharmony_ci * The other is a per context (i.e. application) specification 22962306a36Sopenharmony_ci * controlled by the endian_ctrl field here. Since the master 23062306a36Sopenharmony_ci * context is one such application the master context's 23162306a36Sopenharmony_ci * endian-ness is set to be the same as the host. 23262306a36Sopenharmony_ci * 23362306a36Sopenharmony_ci * As per the SISlite spec, the MMIO registers are always 23462306a36Sopenharmony_ci * big endian. 23562306a36Sopenharmony_ci */ 23662306a36Sopenharmony_ci#define SISL_ENDIAN_CTRL_BE 0x8000000000000080ULL 23762306a36Sopenharmony_ci#define SISL_ENDIAN_CTRL_LE 0x0000000000000000ULL 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci#ifdef __BIG_ENDIAN 24062306a36Sopenharmony_ci#define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_BE 24162306a36Sopenharmony_ci#else 24262306a36Sopenharmony_ci#define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_LE 24362306a36Sopenharmony_ci#endif 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci/* per context host transport MMIO */ 24662306a36Sopenharmony_cistruct sisl_host_map { 24762306a36Sopenharmony_ci __be64 endian_ctrl; /* Per context Endian Control. The AFU will 24862306a36Sopenharmony_ci * operate on whatever the context is of the 24962306a36Sopenharmony_ci * host application. 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci __be64 intr_status; /* this sends LISN# programmed in ctx_ctrl. 25362306a36Sopenharmony_ci * Only recovery in a PERM_ERR is a context 25462306a36Sopenharmony_ci * exit since there is no way to tell which 25562306a36Sopenharmony_ci * command caused the error. 25662306a36Sopenharmony_ci */ 25762306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_3_EA 0x0400ULL /* b53, user error */ 25862306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_2_EA 0x0200ULL /* b54, user error */ 25962306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_1_EA 0x0100ULL /* b55, user error */ 26062306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_3_PASID 0x0080ULL /* b56, user error */ 26162306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_2_PASID 0x0040ULL /* b57, user error */ 26262306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_LISN_1_PASID 0x0020ULL /* b58, user error */ 26362306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_CMDROOM 0x0010ULL /* b59, user error */ 26462306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_RCB_READ 0x0008ULL /* b60, user error */ 26562306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_SA_WRITE 0x0004ULL /* b61, user error */ 26662306a36Sopenharmony_ci#define SISL_ISTATUS_PERM_ERR_RRQ_WRITE 0x0002ULL /* b62, user error */ 26762306a36Sopenharmony_ci /* Page in wait accessing RCB/IOASA/RRQ is reported in b63. 26862306a36Sopenharmony_ci * Same error in data/LXT/RHT access is reported via IOASA. 26962306a36Sopenharmony_ci */ 27062306a36Sopenharmony_ci#define SISL_ISTATUS_TEMP_ERR_PAGEIN 0x0001ULL /* b63, can only be 27162306a36Sopenharmony_ci * generated when AFU 27262306a36Sopenharmony_ci * auto retry is 27362306a36Sopenharmony_ci * disabled. If user 27462306a36Sopenharmony_ci * can determine the 27562306a36Sopenharmony_ci * command that caused 27662306a36Sopenharmony_ci * the error, it can 27762306a36Sopenharmony_ci * be retried. 27862306a36Sopenharmony_ci */ 27962306a36Sopenharmony_ci#define SISL_ISTATUS_UNMASK (0x07FFULL) /* 1 means unmasked */ 28062306a36Sopenharmony_ci#define SISL_ISTATUS_MASK ~(SISL_ISTATUS_UNMASK) /* 1 means masked */ 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci __be64 intr_clear; 28362306a36Sopenharmony_ci __be64 intr_mask; 28462306a36Sopenharmony_ci __be64 ioarrin; /* only write what cmd_room permits */ 28562306a36Sopenharmony_ci __be64 rrq_start; /* start & end are both inclusive */ 28662306a36Sopenharmony_ci __be64 rrq_end; /* write sequence: start followed by end */ 28762306a36Sopenharmony_ci __be64 cmd_room; 28862306a36Sopenharmony_ci __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */ 28962306a36Sopenharmony_ci#define SISL_CTX_CTRL_UNMAP_SECTOR 0x8000000000000000ULL /* b0 */ 29062306a36Sopenharmony_ci#define SISL_CTX_CTRL_LISN_MASK (0xFFULL) 29162306a36Sopenharmony_ci __be64 mbox_w; /* restricted use */ 29262306a36Sopenharmony_ci __be64 sq_start; /* Submission Queue (R/W): write sequence and */ 29362306a36Sopenharmony_ci __be64 sq_end; /* inclusion semantics are the same as RRQ */ 29462306a36Sopenharmony_ci __be64 sq_head; /* Submission Queue Head (R): for debugging */ 29562306a36Sopenharmony_ci __be64 sq_tail; /* Submission Queue TAIL (R/W): next IOARCB */ 29662306a36Sopenharmony_ci __be64 sq_ctx_reset; /* Submission Queue Context Reset (R/W) */ 29762306a36Sopenharmony_ci}; 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci/* per context provisioning & control MMIO */ 30062306a36Sopenharmony_cistruct sisl_ctrl_map { 30162306a36Sopenharmony_ci __be64 rht_start; 30262306a36Sopenharmony_ci __be64 rht_cnt_id; 30362306a36Sopenharmony_ci /* both cnt & ctx_id args must be ULL */ 30462306a36Sopenharmony_ci#define SISL_RHT_CNT_ID(cnt, ctx_id) (((cnt) << 48) | ((ctx_id) << 32)) 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci __be64 ctx_cap; /* afu_rc below is when the capability is violated */ 30762306a36Sopenharmony_ci#define SISL_CTX_CAP_PROXY_ISSUE 0x8000000000000000ULL /* afu_rc 0x21 */ 30862306a36Sopenharmony_ci#define SISL_CTX_CAP_REAL_MODE 0x4000000000000000ULL /* afu_rc 0x21 */ 30962306a36Sopenharmony_ci#define SISL_CTX_CAP_HOST_XLATE 0x2000000000000000ULL /* afu_rc 0x1a */ 31062306a36Sopenharmony_ci#define SISL_CTX_CAP_PROXY_TARGET 0x1000000000000000ULL /* afu_rc 0x21 */ 31162306a36Sopenharmony_ci#define SISL_CTX_CAP_AFU_CMD 0x0000000000000008ULL /* afu_rc 0x21 */ 31262306a36Sopenharmony_ci#define SISL_CTX_CAP_GSCSI_CMD 0x0000000000000004ULL /* afu_rc 0x21 */ 31362306a36Sopenharmony_ci#define SISL_CTX_CAP_WRITE_CMD 0x0000000000000002ULL /* afu_rc 0x21 */ 31462306a36Sopenharmony_ci#define SISL_CTX_CAP_READ_CMD 0x0000000000000001ULL /* afu_rc 0x21 */ 31562306a36Sopenharmony_ci __be64 mbox_r; 31662306a36Sopenharmony_ci __be64 lisn_pasid[2]; 31762306a36Sopenharmony_ci /* pasid _a arg must be ULL */ 31862306a36Sopenharmony_ci#define SISL_LISN_PASID(_a, _b) (((_a) << 32) | (_b)) 31962306a36Sopenharmony_ci __be64 lisn_ea[3]; 32062306a36Sopenharmony_ci}; 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci/* single copy global regs */ 32362306a36Sopenharmony_cistruct sisl_global_regs { 32462306a36Sopenharmony_ci __be64 aintr_status; 32562306a36Sopenharmony_ci /* 32662306a36Sopenharmony_ci * In cxlflash, FC port/link are arranged in port pairs, each 32762306a36Sopenharmony_ci * gets a byte of status: 32862306a36Sopenharmony_ci * 32962306a36Sopenharmony_ci * *_OTHER: other err, FC_ERRCAP[31:20] 33062306a36Sopenharmony_ci * *_LOGO: target sent FLOGI/PLOGI/LOGO while logged in 33162306a36Sopenharmony_ci * *_CRC_T: CRC threshold exceeded 33262306a36Sopenharmony_ci * *_LOGI_R: login state machine timed out and retrying 33362306a36Sopenharmony_ci * *_LOGI_F: login failed, FC_ERROR[19:0] 33462306a36Sopenharmony_ci * *_LOGI_S: login succeeded 33562306a36Sopenharmony_ci * *_LINK_DN: link online to offline 33662306a36Sopenharmony_ci * *_LINK_UP: link offline to online 33762306a36Sopenharmony_ci */ 33862306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_OTHER 0x80000000ULL /* b32 */ 33962306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LOGO 0x40000000ULL /* b33 */ 34062306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_CRC_T 0x20000000ULL /* b34 */ 34162306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LOGI_R 0x10000000ULL /* b35 */ 34262306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LOGI_F 0x08000000ULL /* b36 */ 34362306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LOGI_S 0x04000000ULL /* b37 */ 34462306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LINK_DN 0x02000000ULL /* b38 */ 34562306a36Sopenharmony_ci#define SISL_ASTATUS_FC2_LINK_UP 0x01000000ULL /* b39 */ 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_OTHER 0x00800000ULL /* b40 */ 34862306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LOGO 0x00400000ULL /* b41 */ 34962306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_CRC_T 0x00200000ULL /* b42 */ 35062306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LOGI_R 0x00100000ULL /* b43 */ 35162306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LOGI_F 0x00080000ULL /* b44 */ 35262306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LOGI_S 0x00040000ULL /* b45 */ 35362306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LINK_DN 0x00020000ULL /* b46 */ 35462306a36Sopenharmony_ci#define SISL_ASTATUS_FC3_LINK_UP 0x00010000ULL /* b47 */ 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_OTHER 0x00008000ULL /* b48 */ 35762306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LOGO 0x00004000ULL /* b49 */ 35862306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_CRC_T 0x00002000ULL /* b50 */ 35962306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LOGI_R 0x00001000ULL /* b51 */ 36062306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LOGI_F 0x00000800ULL /* b52 */ 36162306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LOGI_S 0x00000400ULL /* b53 */ 36262306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LINK_DN 0x00000200ULL /* b54 */ 36362306a36Sopenharmony_ci#define SISL_ASTATUS_FC0_LINK_UP 0x00000100ULL /* b55 */ 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_OTHER 0x00000080ULL /* b56 */ 36662306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LOGO 0x00000040ULL /* b57 */ 36762306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_CRC_T 0x00000020ULL /* b58 */ 36862306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LOGI_R 0x00000010ULL /* b59 */ 36962306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LOGI_F 0x00000008ULL /* b60 */ 37062306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LOGI_S 0x00000004ULL /* b61 */ 37162306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LINK_DN 0x00000002ULL /* b62 */ 37262306a36Sopenharmony_ci#define SISL_ASTATUS_FC1_LINK_UP 0x00000001ULL /* b63 */ 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci#define SISL_FC_INTERNAL_UNMASK 0x0000000300000000ULL /* 1 means unmasked */ 37562306a36Sopenharmony_ci#define SISL_FC_INTERNAL_MASK ~(SISL_FC_INTERNAL_UNMASK) 37662306a36Sopenharmony_ci#define SISL_FC_INTERNAL_SHIFT 32 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ci#define SISL_FC_SHUTDOWN_NORMAL 0x0000000000000010ULL 37962306a36Sopenharmony_ci#define SISL_FC_SHUTDOWN_ABRUPT 0x0000000000000020ULL 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci#define SISL_STATUS_SHUTDOWN_ACTIVE 0x0000000000000010ULL 38262306a36Sopenharmony_ci#define SISL_STATUS_SHUTDOWN_COMPLETE 0x0000000000000020ULL 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci#define SISL_ASTATUS_UNMASK 0xFFFFFFFFULL /* 1 means unmasked */ 38562306a36Sopenharmony_ci#define SISL_ASTATUS_MASK ~(SISL_ASTATUS_UNMASK) /* 1 means masked */ 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci __be64 aintr_clear; 38862306a36Sopenharmony_ci __be64 aintr_mask; 38962306a36Sopenharmony_ci __be64 afu_ctrl; 39062306a36Sopenharmony_ci __be64 afu_hb; 39162306a36Sopenharmony_ci __be64 afu_scratch_pad; 39262306a36Sopenharmony_ci __be64 afu_port_sel; 39362306a36Sopenharmony_ci#define SISL_AFUCONF_AR_IOARCB 0x4000ULL 39462306a36Sopenharmony_ci#define SISL_AFUCONF_AR_LXT 0x2000ULL 39562306a36Sopenharmony_ci#define SISL_AFUCONF_AR_RHT 0x1000ULL 39662306a36Sopenharmony_ci#define SISL_AFUCONF_AR_DATA 0x0800ULL 39762306a36Sopenharmony_ci#define SISL_AFUCONF_AR_RSRC 0x0400ULL 39862306a36Sopenharmony_ci#define SISL_AFUCONF_AR_IOASA 0x0200ULL 39962306a36Sopenharmony_ci#define SISL_AFUCONF_AR_RRQ 0x0100ULL 40062306a36Sopenharmony_ci/* Aggregate all Auto Retry Bits */ 40162306a36Sopenharmony_ci#define SISL_AFUCONF_AR_ALL (SISL_AFUCONF_AR_IOARCB|SISL_AFUCONF_AR_LXT| \ 40262306a36Sopenharmony_ci SISL_AFUCONF_AR_RHT|SISL_AFUCONF_AR_DATA| \ 40362306a36Sopenharmony_ci SISL_AFUCONF_AR_RSRC|SISL_AFUCONF_AR_IOASA| \ 40462306a36Sopenharmony_ci SISL_AFUCONF_AR_RRQ) 40562306a36Sopenharmony_ci#ifdef __BIG_ENDIAN 40662306a36Sopenharmony_ci#define SISL_AFUCONF_ENDIAN 0x0000ULL 40762306a36Sopenharmony_ci#else 40862306a36Sopenharmony_ci#define SISL_AFUCONF_ENDIAN 0x0020ULL 40962306a36Sopenharmony_ci#endif 41062306a36Sopenharmony_ci#define SISL_AFUCONF_MBOX_CLR_READ 0x0010ULL 41162306a36Sopenharmony_ci __be64 afu_config; 41262306a36Sopenharmony_ci __be64 rsvd[0xf8]; 41362306a36Sopenharmony_ci __le64 afu_version; 41462306a36Sopenharmony_ci __be64 interface_version; 41562306a36Sopenharmony_ci#define SISL_INTVER_CAP_SHIFT 16 41662306a36Sopenharmony_ci#define SISL_INTVER_MAJ_SHIFT 8 41762306a36Sopenharmony_ci#define SISL_INTVER_CAP_MASK 0xFFFFFFFF00000000ULL 41862306a36Sopenharmony_ci#define SISL_INTVER_MAJ_MASK 0x00000000FFFF0000ULL 41962306a36Sopenharmony_ci#define SISL_INTVER_MIN_MASK 0x000000000000FFFFULL 42062306a36Sopenharmony_ci#define SISL_INTVER_CAP_IOARRIN_CMD_MODE 0x800000000000ULL 42162306a36Sopenharmony_ci#define SISL_INTVER_CAP_SQ_CMD_MODE 0x400000000000ULL 42262306a36Sopenharmony_ci#define SISL_INTVER_CAP_RESERVED_CMD_MODE_A 0x200000000000ULL 42362306a36Sopenharmony_ci#define SISL_INTVER_CAP_RESERVED_CMD_MODE_B 0x100000000000ULL 42462306a36Sopenharmony_ci#define SISL_INTVER_CAP_LUN_PROVISION 0x080000000000ULL 42562306a36Sopenharmony_ci#define SISL_INTVER_CAP_AFU_DEBUG 0x040000000000ULL 42662306a36Sopenharmony_ci#define SISL_INTVER_CAP_OCXL_LISN 0x020000000000ULL 42762306a36Sopenharmony_ci}; 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci#define CXLFLASH_NUM_FC_PORTS_PER_BANK 2 /* fixed # of ports per bank */ 43062306a36Sopenharmony_ci#define CXLFLASH_MAX_FC_BANKS 2 /* max # of banks supported */ 43162306a36Sopenharmony_ci#define CXLFLASH_MAX_FC_PORTS (CXLFLASH_NUM_FC_PORTS_PER_BANK * \ 43262306a36Sopenharmony_ci CXLFLASH_MAX_FC_BANKS) 43362306a36Sopenharmony_ci#define CXLFLASH_MAX_CONTEXT 512 /* number of contexts per AFU */ 43462306a36Sopenharmony_ci#define CXLFLASH_NUM_VLUNS 512 /* number of vluns per AFU/port */ 43562306a36Sopenharmony_ci#define CXLFLASH_NUM_REGS 512 /* number of registers per port */ 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_cistruct fc_port_bank { 43862306a36Sopenharmony_ci __be64 fc_port_regs[CXLFLASH_NUM_FC_PORTS_PER_BANK][CXLFLASH_NUM_REGS]; 43962306a36Sopenharmony_ci __be64 fc_port_luns[CXLFLASH_NUM_FC_PORTS_PER_BANK][CXLFLASH_NUM_VLUNS]; 44062306a36Sopenharmony_ci}; 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_cistruct sisl_global_map { 44362306a36Sopenharmony_ci union { 44462306a36Sopenharmony_ci struct sisl_global_regs regs; 44562306a36Sopenharmony_ci char page0[SIZE_4K]; /* page 0 */ 44662306a36Sopenharmony_ci }; 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci char page1[SIZE_4K]; /* page 1 */ 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci struct fc_port_bank bank[CXLFLASH_MAX_FC_BANKS]; /* pages 2 - 9 */ 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci /* pages 10 - 15 are reserved */ 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_ci}; 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci/* 45762306a36Sopenharmony_ci * CXL Flash Memory Map 45862306a36Sopenharmony_ci * 45962306a36Sopenharmony_ci * +-------------------------------+ 46062306a36Sopenharmony_ci * | 512 * 64 KB User MMIO | 46162306a36Sopenharmony_ci * | (per context) | 46262306a36Sopenharmony_ci * | User Accessible | 46362306a36Sopenharmony_ci * +-------------------------------+ 46462306a36Sopenharmony_ci * | 512 * 128 B per context | 46562306a36Sopenharmony_ci * | Provisioning and Control | 46662306a36Sopenharmony_ci * | Trusted Process accessible | 46762306a36Sopenharmony_ci * +-------------------------------+ 46862306a36Sopenharmony_ci * | 64 KB Global | 46962306a36Sopenharmony_ci * | Trusted Process accessible | 47062306a36Sopenharmony_ci * +-------------------------------+ 47162306a36Sopenharmony_ci */ 47262306a36Sopenharmony_cistruct cxlflash_afu_map { 47362306a36Sopenharmony_ci union { 47462306a36Sopenharmony_ci struct sisl_host_map host; 47562306a36Sopenharmony_ci char harea[SIZE_64K]; /* 64KB each */ 47662306a36Sopenharmony_ci } hosts[CXLFLASH_MAX_CONTEXT]; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci union { 47962306a36Sopenharmony_ci struct sisl_ctrl_map ctrl; 48062306a36Sopenharmony_ci char carea[cache_line_size()]; /* 128B each */ 48162306a36Sopenharmony_ci } ctrls[CXLFLASH_MAX_CONTEXT]; 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci union { 48462306a36Sopenharmony_ci struct sisl_global_map global; 48562306a36Sopenharmony_ci char garea[SIZE_64K]; /* 64KB single block */ 48662306a36Sopenharmony_ci }; 48762306a36Sopenharmony_ci}; 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ci/* 49062306a36Sopenharmony_ci * LXT - LBA Translation Table 49162306a36Sopenharmony_ci * LXT control blocks 49262306a36Sopenharmony_ci */ 49362306a36Sopenharmony_cistruct sisl_lxt_entry { 49462306a36Sopenharmony_ci u64 rlba_base; /* bits 0:47 is base 49562306a36Sopenharmony_ci * b48:55 is lun index 49662306a36Sopenharmony_ci * b58:59 is write & read perms 49762306a36Sopenharmony_ci * (if no perm, afu_rc=0x15) 49862306a36Sopenharmony_ci * b60:63 is port_sel mask 49962306a36Sopenharmony_ci */ 50062306a36Sopenharmony_ci}; 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_ci/* 50362306a36Sopenharmony_ci * RHT - Resource Handle Table 50462306a36Sopenharmony_ci * Per the SISlite spec, RHT entries are to be 16-byte aligned 50562306a36Sopenharmony_ci */ 50662306a36Sopenharmony_cistruct sisl_rht_entry { 50762306a36Sopenharmony_ci struct sisl_lxt_entry *lxt_start; 50862306a36Sopenharmony_ci u32 lxt_cnt; 50962306a36Sopenharmony_ci u16 rsvd; 51062306a36Sopenharmony_ci u8 fp; /* format & perm nibbles. 51162306a36Sopenharmony_ci * (if no perm, afu_rc=0x05) 51262306a36Sopenharmony_ci */ 51362306a36Sopenharmony_ci u8 nmask; 51462306a36Sopenharmony_ci} __packed __aligned(16); 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_cistruct sisl_rht_entry_f1 { 51762306a36Sopenharmony_ci u64 lun_id; 51862306a36Sopenharmony_ci union { 51962306a36Sopenharmony_ci struct { 52062306a36Sopenharmony_ci u8 valid; 52162306a36Sopenharmony_ci u8 rsvd[5]; 52262306a36Sopenharmony_ci u8 fp; 52362306a36Sopenharmony_ci u8 port_sel; 52462306a36Sopenharmony_ci }; 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_ci u64 dw; 52762306a36Sopenharmony_ci }; 52862306a36Sopenharmony_ci} __packed __aligned(16); 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ci/* make the fp byte */ 53162306a36Sopenharmony_ci#define SISL_RHT_FP(fmt, perm) (((fmt) << 4) | (perm)) 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci/* make the fp byte for a clone from a source fp and clone flags 53462306a36Sopenharmony_ci * flags must be only 2 LSB bits. 53562306a36Sopenharmony_ci */ 53662306a36Sopenharmony_ci#define SISL_RHT_FP_CLONE(src_fp, cln_flags) ((src_fp) & (0xFC | (cln_flags))) 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_ci#define RHT_PERM_READ 0x01U 53962306a36Sopenharmony_ci#define RHT_PERM_WRITE 0x02U 54062306a36Sopenharmony_ci#define RHT_PERM_RW (RHT_PERM_READ | RHT_PERM_WRITE) 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_ci/* extract the perm bits from a fp */ 54362306a36Sopenharmony_ci#define SISL_RHT_PERM(fp) ((fp) & RHT_PERM_RW) 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci#define PORT0 0x01U 54662306a36Sopenharmony_ci#define PORT1 0x02U 54762306a36Sopenharmony_ci#define PORT2 0x04U 54862306a36Sopenharmony_ci#define PORT3 0x08U 54962306a36Sopenharmony_ci#define PORT_MASK(_n) ((1 << (_n)) - 1) 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ci/* AFU Sync Mode byte */ 55262306a36Sopenharmony_ci#define AFU_LW_SYNC 0x0U 55362306a36Sopenharmony_ci#define AFU_HW_SYNC 0x1U 55462306a36Sopenharmony_ci#define AFU_GSYNC 0x2U 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ci/* Special Task Management Function CDB */ 55762306a36Sopenharmony_ci#define TMF_LUN_RESET 0x1U 55862306a36Sopenharmony_ci#define TMF_CLEAR_ACA 0x2U 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ci#endif /* _SISLITE_H */ 561