#ifndef _IC_SIISATAREG_H_
#define _IC_SIISATAREG_H_
#include <sys/cdefs.h>
#define SIISATA_MAX_PORTS 4
#define SIISATA_MAX_SLOTS 31
struct siisata_sge {
#if 0
uint32_t sge_dal;
uint32_t sge_dah;
#else
uint64_t sge_da;
#endif
uint32_t sge_dc;
uint32_t sge_flags;
#define SGE_FLAG_TRM __BIT(31)
#define SGE_FLAG_LNK __BIT(30)
#define SGE_FLAG_DRD __BIT(29)
#define SGE_FLAG_XCF __BIT(28)
} __packed __aligned(8);
struct siisata_sgt {
struct siisata_sge sgt_sge[4];
} __packed __aligned(8);
struct siisata_prb {
uint16_t prb_control;
#define PRB_CF_PROTOCOL_OVERRIDE __BIT(0)
#define PRB_CF_RETRANSMIT __BIT(1)
#define PRB_CF_EXTERNAL_COMMAND __BIT(2)
#define PRB_CF_RECEIVE __BIT(3)
#define PRB_CF_PACKET_READ __BIT(4)
#define PRB_CF_PACKET_WRITE __BIT(5)
#define PRB_CF_INTERRUPT_MASK __BIT(6)
#define PRB_CF_SOFT_RESET __BIT(7)
uint16_t prb_protocol_override;
#define PRB_PO_PACKET __BIT(0)
#define PRB_PO_LCQ __BIT(1)
#define PRB_PO_NCQ __BIT(2)
#define PRB_PO_READ __BIT(3)
#define PRB_PO_WRITE __BIT(4)
#define PRB_PO_TRANSPARENT __BIT(5)
uint32_t prb_transfer_count;
uint8_t prb_fis[20];
uint32_t prb_reserved_0x1C;
uint8_t prb_atapi[16];
struct siisata_sge prb_sge[1];
} __packed __aligned(8);
#define SIISATA_NSGE ((MAXPHYS/PAGE_SIZE) + 1)
#define SIISATA_CMD_ALIGN 0x7f
#define SIISATA_CMD_SIZE \
( ( sizeof(struct siisata_prb) + (SIISATA_NSGE - 1) * sizeof(struct siisata_sge) + SIISATA_CMD_ALIGN ) & ~SIISATA_CMD_ALIGN )
#define SIISATA_PCI_BAR0 0x10
#define SIISATA_PCI_BAR1 0x18
#define SIISATA_PCI_BAR2 0x20
#define SIISATA_CARDBUS_BAR0 SIISATA_PCI_BAR0
#define SIISATA_CARDBUS_BAR1 SIISATA_PCI_BAR1
#define SIISATA_CARDBUS_BAR2 SIISATA_PCI_BAR2
#define GR_PXSS(n) (n*4)
#define GR_GC 0x40
#define GR_GIS 0x44
#define GR_PHYC 0x48
#define GR_BIST_CONTROL 0x50
#define GR_BIST_PATTERN 0x54
#define GR_BIST_STATUS 0x58
#define GR_SII3132_IICCONTROL 0x60
#define GR_SII3132_IICSTATUS 0x64
#define GR_SII3132_IICSLAVEADDR 0x68
#define GR_SII3132_IICDATA 0x6c
#define GR_FLSHADDR 0x70
#define GR_FLSHDATA 0x74
#define GR_SII3124_IICADDR 0x78
#define GR_SII3124_IICDATA 0x7c
#define GR_GC_GLBLRST __BIT(31)
#define GR_GC_MSIACK __BIT(30)
#define GR_GC_I2CINTEN __BIT(29)
#define GR_GC_PERRRPTDSBL __BIT(28)
#define GR_GC_3GBPS __BIT(24)
#define GR_GC_REQ64 __BIT(20)
#define GR_GC_DEVSEL __BIT(19)
#define GR_GC_STOP __BIT(18)
#define GR_GC_TRDY __BIT(17)
#define GR_GC_M66EN __BIT(16)
#define GR_GC_PXIE_MASK __BITS(SIISATA_MAX_PORTS - 1, 0)
#define GR_GC_PXIE(n) __SHIFTIN(__BIT(n), GR_GC_PXIE_MASK)
#define GR_GIS_I2C __BIT(29)
#define GR_GIS_PXIS_MASK __BITS(SIISATA_MAX_PORTS - 1, 0)
#define GR_GIS_PXIS(n) __SHIFTIN(__BIT(n), GR_GIS_PXIS_MASK)
#define PR_PORT_SIZE 0x2000
#define PR_SLOT_SIZE 0x80
#define PRO(p) (PR_PORT_SIZE * p)
#define PRX(p,r) (PRO(p) + r)
#define PRSX(p,s,o) (PRX(p, PR_SLOT_SIZE * s + o))
#define PRSO_RTC 0x04
#define PRSO_FIS 0x08
#define PRO_PMPSTS(i) (0x0f80 + i * 8)
#define PRO_PMPQACT(i) (0x0f80 + i * 8 + 4)
#define PRO_PCS 0x1000
#define PRO_PS PRO_PCS
#define PRO_PCC 0x1004
#define PRO_PIS 0x1008
#define PRO_PIES 0x1010
#define PRO_PIEC 0x1014
#define PRO_32BAUA 0x101c
#define PRO_PCEF 0x1020
#define PRO_PCE 0x1024
#define PRO_PFISC 0x1028
#define PRO_PCIRFIFOT 0x102c
#define PRO_P8B10BDEC 0x1040
#define PRO_PCRCEC 0x1044
#define PRO_PHEC 0x1048
#define PRO_PPHYC 0x1050
#define PRO_PSS 0x1800
#define PRO_CAR 0x1c00
#define PRO_CARX(p,s) (PRX(p, PRO_CAR) + (s) * sizeof(uint64_t))
#define PRO_PCR 0x1e04
#define PRO_PCR_SLOT(x) (((x) & __BITS(4, 0)) >> 0)
#define PRO_PCR_PMP(x) (((x) & __BITS(8, 5)) >> 5)
#define PRO_SCONTROL 0x1f00
#define PRO_SSTATUS 0x1f04
#define PRO_SERROR 0x1f08
#define PRO_SACTIVE 0x1f0c
#define PR_PCE_DEVICEERROR 1
#define PR_PCE_SDBERROR 2
#define PR_PCE_DATAFISERROR 3
#define PR_PCE_SENDFISERROR 4
#define PR_PCE_INCONSISTENTSTATE 5
#define PR_PCE_DIRECTIONERROR 6
#define PR_PCE_UNDERRUNERROR 7
#define PR_PCE_OVERRUNERROR 8
#define PR_PCE_LINKFIFOOVERRUN 9
#define PR_PCE_PACKETPROTOCOLERROR 11
#define PR_PCE_PLDSGTERRORBOUNDARY 16
#define PR_PCE_PLDSGTERRORTARGETABORT 17
#define PR_PCE_PLDSGTERRORMASTERABORT 18
#define PR_PCE_PLDSGTERRORPCIPERR 19
#define PR_PCE_PLDCMDERRORBOUNDARY 24
#define PR_PCE_PLDCMDERRORTARGETABORT 25
#define PR_PCE_PLDCMDERRORMASTERABORT 26
#define PR_PCE_PLDCMDERRORPCIPERR 27
#define PR_PCE_PSDERRORTARGETABORT 33
#define PR_PCE_PSDERRORMASTERABORT 34
#define PR_PCE_PSDERRORPCIPERR 35
#define PR_PCE_SENDSERVICEERROROR 36
#define PR_PIS_UNMASKED_SHIFT 16
#define PR_PIS_CMDCMPL __BIT(0)
#define PR_PIS_CMDERRR __BIT(1)
#define PR_PIS_PRTRDY __BIT(2)
#define PR_PIS_PMCHNG __BIT(3)
#define PR_PIS_PHYRDYCHG __BIT(4)
#define PR_PIS_COMWAKE __BIT(5)
#define PR_PIS_UNRECFIS __BIT(6)
#define PR_PIS_DEVEXCHG __BIT(7)
#define PR_PIS_8B10BDET __BIT(8)
#define PR_PIS_CRCET __BIT(9)
#define PR_PIS_HET __BIT(10)
#define PR_PIS_SDBN __BIT(11)
#define PR_PC_PORT_RESET __BIT(0)
#define PR_PC_DEVICE_RESET __BIT(1)
#define PR_PC_PORT_INITIALIZE __BIT(2)
#define PR_PC_INCOR __BIT(3)
#define PR_PC_LED_DISABLE __BIT(4)
#define PR_PC_PACKET_LENGTH __BIT(5)
#define PR_PC_RESUME __BIT(6)
#define PR_PC_TXBIST __BIT(7)
#define PR_PC_CONT_DISABLE __BIT(8)
#define PR_PC_SCRAMBLER_DISABLE __BIT(9)
#define PR_PC_32BA __BIT(10)
#define PR_PC_INTERLOCK_REJECT __BIT(11)
#define PR_PC_INTERLOCK_ACCEPT __BIT(12)
#define PR_PC_PMP_ENABLE __BIT(13)
#define PR_PC_AIA __BIT(14)
#define PR_PC_LED_ON __BIT(15)
#define PR_PS_ACTIVE_SLOT_MASK __BITS(20,16)
#define PR_PS_ACTIVE_SLOT(x) __SHIFTOUT((x), PR_PS_ACTIVE_SLOT_MASK)
#define PR_PC_OOB_BYPASS __BIT(25)
#define PR_PS_PORT_READY __BIT(31)
#define PR_PSS_ATTENTION __BIT(31)
#define PR_PSS_SLOT_MASK __BITS(30, 0)
#define PR_PXSS(n) __SHIFTIN(__BIT(n), PR_PSS_SLOT_MASK)
#endif