#ifndef _EMLXS_OS_H
#define _EMLXS_OS_H
#ifdef __cplusplus
extern "C" {
#endif
#define EMLXS_MODREV2 2
#define EMLXS_MODREV3 3
#define EMLXS_MODREV4 4
#define EMLXS_MODREV5 5
#define EMLXS_MODREV2X 2
#define EMLXS_MODREV3X 3
#define DHCHAP_SUPPORT
#define SATURN_MSI_SUPPORT
#define MENLO_SUPPORT
#define MBOX_EXT_SUPPORT
#define DUMP_SUPPORT
#define SAN_DIAG_SUPPORT
#define FMA_SUPPORT
#define NODE_THROTTLE_SUPPORT
#ifdef S11
#define MSI_SUPPORT
#define SFCT_SUPPORT
#define MODFW_SUPPORT
#define EMLXS_MODREV EMLXS_MODREV5
#ifdef EMLXS_I386
#define EMLXS_MODREVX EMLXS_MODREV2X
#endif
#endif
#ifdef SFCT_SUPPORT
#define MODSYM_SUPPORT
#define FCIO_SUPPORT
#endif
#ifndef EMLXS_MODREV
#define EMLXS_MODREV 0
#endif
#ifndef EMLXS_MODREVX
#define EMLXS_MODREVX 0
#endif
#if defined(S10) || defined(S11)
#define S10S11
#endif
#include <sys/types.h>
#include <sys/varargs.h>
#include <sys/devops.h>
#include <sys/param.h>
#include <sys/user.h>
#include <sys/buf.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <sys/fcntl.h>
#include <sys/cmn_err.h>
#include <sys/stropts.h>
#include <sys/kmem.h>
#include <sys/errno.h>
#include <sys/open.h>
#include <sys/kmem.h>
#include <sys/poll.h>
#include <sys/thread.h>
#include <sys/taskq.h>
#include <sys/debug.h>
#include <sys/cpu.h>
#include <sys/autoconf.h>
#include <sys/conf.h>
#include <sys/stat.h>
#include <sys/var.h>
#include <sys/map.h>
#include <sys/file.h>
#include <sys/syslog.h>
#include <sys/disp.h>
#include <sys/taskq.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/promif.h>
#include <sys/ethernet.h>
#include <vm/seg_kmem.h>
#include <sys/utsname.h>
#include <sys/modctl.h>
#include <sys/scsi/scsi.h>
#include <sys/varargs.h>
#include <sys/atomic.h>
#ifdef S11
#include <sys/pci.h>
#include <sys/pcie.h>
#else
#define PCI_CAP_ID 0x0
#define PCI_CAP_NEXT_PTR 0x1
#define PCI_CAP_ID_REGS_OFF 0x2
#define PCI_CAP_MAX_PTR 0x30
#define PCI_CAP_PTR_OFF 0x40
#define PCI_CAP_PTR_MASK 0xFC
#define PCI_CAP_ID_PM 0x1
#define PCI_CAP_ID_AGP 0x2
#define PCI_CAP_ID_VPD 0x3
#define PCI_CAP_ID_SLOT_ID 0x4
#define PCI_CAP_ID_MSI 0x5
#define PCI_CAP_ID_cPCI_HS 0x6
#define PCI_CAP_ID_PCIX 0x7
#define PCI_CAP_ID_HT 0x8
#define PCI_CAP_ID_VS 0x9
#define PCI_CAP_ID_DEBUG_PORT 0xA
#define PCI_CAP_ID_cPCI_CRC 0xB
#define PCI_CAP_ID_PCI_HOTPLUG 0xC
#define PCI_CAP_ID_P2P_SUBSYS 0xD
#define PCI_CAP_ID_AGP_8X 0xE
#define PCI_CAP_ID_SECURE_DEV 0xF
#define PCI_CAP_ID_PCI_E 0x10
#define PCI_CAP_ID_MSI_X 0x11
#define PCI_CAP_ID_SATA 0x12
#define PCI_CAP_ID_FLR 0x13
#define PCI_PMCAP 0x2
#define PCI_PMCSR 0x4
#define PCI_PMCSR_BSE 0x6
#define PCI_PMDATA 0x7
#define PCI_PMCSR_D0 0x0
#define PCI_PMCSR_D1 0x1
#define PCI_PMCSR_D2 0x2
#define PCI_PMCSR_D3HOT 0x3
#define PCIE_CAP_ID PCI_CAP_ID
#define PCIE_CAP_NEXT_PTR PCI_CAP_NEXT_PTR
#define PCIE_PCIECAP 0x02
#define PCIE_DEVCAP 0x04
#define PCIE_DEVCTL 0x08
#define PCIE_DEVSTS 0x0A
#define PCIE_LINKCAP 0x0C
#define PCIE_LINKCTL 0x10
#define PCIE_LINKSTS 0x12
#define PCIE_SLOTCAP 0x14
#define PCIE_SLOTCTL 0x18
#define PCIE_SLOTSTS 0x1A
#define PCIE_ROOTCTL 0x1C
#define PCIE_ROOTSTS 0x20
#define PCIE_EXT_CAP 0x100
#define PCIE_EXT_CAP_ID_SHIFT 0
#define PCIE_EXT_CAP_ID_MASK 0xFFFF
#define PCIE_EXT_CAP_VER_SHIFT 16
#define PCIE_EXT_CAP_VER_MASK 0xF
#define PCIE_EXT_CAP_NEXT_PTR_SHIFT 20
#define PCIE_EXT_CAP_NEXT_PTR_MASK 0xFFF
#define PCIE_EXT_CAP_NEXT_PTR_NULL 0x0
#define PCIE_EXT_CAP_ID_AER 0x1
#define PCIE_EXT_CAP_ID_VC 0x2
#define PCIE_EXT_CAP_ID_SER 0x3
#define PCIE_EXT_CAP_ID_PWR_BUDGET 0x4
#define PCIE_EXT_CAP_ID_RC_LINK_DECL 0x5
#define PCIE_EXT_CAP_ID_RC_INT_LINKCTRL 0x6
#define PCIE_EXT_CAP_ID_RC_EVNT_CEA 0x7
#define PCIE_EXT_CAP_ID_MFVC 0x8
#define PCIE_EXT_CAP_ID_VC_WITH_MFVC 0x9
#define PCIE_EXT_CAP_ID_RCRB 0xA
#define PCIE_EXT_CAP_ID_VS 0xB
#define PCIE_EXT_CAP_ID_CAC 0xC
#define PCIE_EXT_CAP_ID_ACS 0xD
#define PCIE_EXT_CAP_ID_ARI 0xE
#define PCIE_EXT_CAP_ID_ATS 0xF
#endif
#include <emlxs_hbaapi.h>
#ifdef FMA_SUPPORT
#include <sys/ddifm.h>
#include <sys/fm/protocol.h>
#include <sys/fm/util.h>
#endif
#include <sys/fm/io/ddi.h>
#ifdef S11
#include <sys/fibre-channel/fc.h>
#include <sys/fibre-channel/impl/fc_fcaif.h>
#else
#include <sys/fibre-channel/fcio.h>
#include <sys/fibre-channel/fc.h>
#include <sys/fibre-channel/fc_appif.h>
#include <sys/fibre-channel/fc_types.h>
#include <sys/fibre-channel/impl/fc_error.h>
#include <sys/fibre-channel/impl/fc_fla.h>
#include <sys/fibre-channel/impl/fc_linkapp.h>
#include <sys/fibre-channel/impl/fcal.h>
#include <sys/fibre-channel/impl/fcgs2.h>
#include <sys/fibre-channel/impl/fcph.h>
#include <sys/fibre-channel/impl/fc_ulpif.h>
#include <sys/fibre-channel/impl/fc_fcaif.h>
#include <sys/fibre-channel/impl/fctl.h>
#include <sys/fibre-channel/impl/fctl_private.h>
#include <sys/fibre-channel/ulp/fcp.h>
#include <sys/fibre-channel/ulp/fcp_util.h>
#endif
#ifndef FC_HBA_PORTSPEED_8GBIT
#define FC_HBA_PORTSPEED_8GBIT 16
#endif
#ifndef FP_DEFAULT_SID
#define FP_DEFAULT_SID (0x000AE)
#endif
#ifndef FP_DEFAULT_DID
#define FP_DEFAULT_DID (0x000EA)
#endif
#ifdef MSI_SUPPORT
#pragma weak ddi_intr_get_supported_types
#pragma weak ddi_intr_get_nintrs
#pragma weak ddi_intr_add_handler
#pragma weak ddi_intr_remove_handler
#pragma weak ddi_intr_get_hilevel_pri
#pragma weak ddi_intr_enable
#pragma weak ddi_intr_disable
#pragma weak ddi_intr_get_cap
#pragma weak ddi_intr_get_pri
#pragma weak ddi_intr_alloc
#pragma weak ddi_intr_free
#pragma weak ddi_intr_block_enable
#pragma weak ddi_intr_block_disable
extern int ddi_intr_get_supported_types();
#endif
#ifndef MODSYM_SUPPORT
#pragma weak fc_fca_init
#pragma weak fc_fca_attach
#pragma weak fc_fca_detach
#endif
#ifndef DDI_DMA_RELAXED_ORDERING
#define DDI_DMA_RELAXED_ORDERING 0x400
#endif
#ifdef FMA_SUPPORT
#pragma weak ddi_fm_acc_err_clear
extern void ddi_fm_acc_err_clear();
#endif
#ifdef EMLXS_SPARC
#define EMLXS_BIG_ENDIAN
#endif
#ifdef EMLXS_I386
#define EMLXS_LITTLE_ENDIAN
#endif
#ifndef TASKQ_DYNAMIC
#define TASKQ_DYNAMIC 0x0004
#endif
#ifdef _LP64
#define DEAD_PTR 0xdeadbeefdeadbeef
#else
#define DEAD_PTR 0xdeadbeef
#endif
#ifndef FC_STATE_8GBIT_SPEED
#define FC_STATE_8GBIT_SPEED 0x0700
#endif
#define FC_STATE_QUAD_SPEED 0x0500
#ifndef BURSTSIZE
#define BURSTSIZE
#define BURST1 0x01
#define BURST2 0x02
#define BURST4 0x04
#define BURST8 0x08
#define BURST16 0x10
#define BURST32 0x20
#define BURST64 0x40
#ifdef _LP64
#define BURSTSIZE_MASK 0x7f
#else
#define BURSTSIZE_MASK 0x3f
#endif
#define DEFAULT_BURSTSIZE (BURSTSIZE_MASK)
#endif
#define PADDR_LO(addr) ((uint32_t)(((uint64_t)(addr)) & 0xffffffff))
#define PADDR_HI(addr) ((uint32_t)(((uint64_t)(addr)) >> 32))
#define PADDR(high, low) ((uint64_t)((((uint64_t)(high)) << 32) \
| (((uint64_t)(low)) & 0xffffffff)))
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define DMA_READ_WRITE 0
#define DMA_READ_ONLY 1
#define DMA_WRITE_ONLY 2
#define DMA_SUCC 1
#define MAX_FC_BRDS 256
#define BUSYWAIT_MS(ms) drv_usecwait((ms*1000))
#define BUSYWAIT_US(us) drv_usecwait(us)
#define EMLXS_MPDATA_SYNC(h, a, b, c) \
if (h) { \
(void) ddi_dma_sync((ddi_dma_handle_t)(h), \
(off_t)(a), (size_t)(b), (uint_t)c); \
}
#define PKT2PRIV(pkt) ((emlxs_buf_t *)(pkt)->pkt_fca_private)
#define PRIV2PKT(sbp) sbp->pkt
#define EMLXS_INUMBER 0
#define EMLXS_MSI_INUMBER 0
#define EMLXS_DMA_ALIGN BURST16
#define SBUS_FLASH_RD 0
#define SBUS_FLASH_RDWR 1
#define SBUS_DFLY_SLIM_RINDEX 2
#define SBUS_DFLY_CSR_RINDEX 3
#define SBUS_TITAN_CORE_RINDEX 4
#define SBUS_DFLY_PCI_CFG_RINDEX 5
#define SBUS_TITAN_PCI_CFG_RINDEX 6
#define SBUS_TITAN_CSR_RINDEX 7
#define PCI_CFG_RINDEX 0
#define PCI_SLIM_RINDEX 1
#define PCI_CSR_RINDEX 2
#define PCI_BAR0_RINDEX 1
#define PCI_BAR1_RINDEX 2
#define PCI_BAR2_RINDEX 3
#define EMLXS_MAX_UBUFS 65535
#define EMLXS_UB_TOKEN_OFFSET 0x100
typedef struct emlxs_ub_priv
{
fc_unsol_buf_t *ubp;
void *port;
uint32_t bpl_size;
uint8_t *bpl_virt;
uint64_t bpl_phys;
void *bpl_data_handle;
void *bpl_dma_handle;
uint32_t ip_ub_size;
uint8_t *ip_ub_virt;
ddi_dma_cookie_t ip_ub_dma_cookies[64];
ddi_acc_handle_t ip_ub_data_handle;
ddi_dma_handle_t ip_ub_dma_handle;
uint32_t ip_ub_cookie_cnt;
uint32_t FC4type;
uint16_t flags;
#define EMLXS_UB_FREE 0x0000
#define EMLXS_UB_IN_USE 0x0001
#define EMLXS_UB_REPLY 0x0002
#define EMLXS_UB_RESV 0x0004
#define EMLXS_UB_TIMEOUT 0x0008
#define EMLXS_UB_INTERCEPT 0x0010
uint16_t available;
uint32_t timeout;
uint32_t time;
uint32_t cmd;
uint32_t token;
struct emlxs_unsol_buf *pool;
struct emlxs_ub_priv *next;
} emlxs_ub_priv_t;
typedef struct emlxs_unsol_buf
{
struct emlxs_unsol_buf *pool_prev;
struct emlxs_unsol_buf *pool_next;
uint32_t pool_type;
uint32_t pool_buf_size;
uint32_t pool_nentries;
uint32_t pool_available;
uint32_t pool_flags;
#define POOL_DESTROY 0x00000001
uint32_t pool_free;
uint32_t pool_free_resv;
uint32_t pool_first_token;
uint32_t pool_last_token;
fc_unsol_buf_t *fc_ubufs;
} emlxs_unsol_buf_t;
#ifndef FC_REASON_NONE
#define FC_REASON_NONE 0
#endif
#ifndef FC_ACTION_NONE
#define FC_ACTION_NONE 0
#endif
typedef struct emlxs_xlat_err
{
uint32_t emlxs_status;
uint32_t pkt_state;
uint32_t pkt_reason;
uint32_t pkt_expln;
uint32_t pkt_action;
} emlxs_xlat_err_t;
typedef struct emlxs_table
{
uint32_t code;
char string[48];
} emlxs_table_t;
#define EMLXS_PATCH1 0x00000001
#define EMLXS_PATCH2 0x00000002
#define EMLXS_PATCH3 0x00000004
#define EMLXS_PATCH4 0x00000008
#define EMLXS_PATCH5 0x00000010
#define EMLXS_PATCH6 0x00000020
#define EMLXS_PATCH7 0x00000040
#define EMLXS_PATCH8 0x00000080
#define EMLXS_PATCH9 0x00000100
#define EMLXS_PATCH10 0x00000200
#define EMLXS_PATCH11 0x00000400
#define EMLXS_PATCH12 0x00000800
#define EMLXS_PATCH13 0x00001000
#define EMLXS_PATCH14 0x00002000
#define EMLXS_PATCH15 0x00004000
#define EMLXS_PATCH16 0x00008000
#define EMLXS_PATCH17 0x00010000
#define EMLXS_PATCH18 0x00020000
#define EMLXS_PATCH19 0x00040000
#define EMLXS_PATCH20 0x00080000
#define EMLXS_PATCH21 0x00100000
#define EMLXS_PATCH22 0x00200000
#define EMLXS_PATCH23 0x00400000
#define EMLXS_PATCH24 0x00800000
#define EMLXS_PATCH25 0x01000000
#define EMLXS_PATCH26 0x02000000
#define EMLXS_PATCH27 0x04000000
#define EMLXS_PATCH28 0x08000000
#define EMLXS_PATCH29 0x10000000
#define EMLXS_PATCH30 0x20000000
#define EMLXS_PATCH31 0x40000000
#define EMLXS_PATCH32 0x80000000
#define ULP_PATCH2 EMLXS_PATCH2
#define ULP_PATCH3 EMLXS_PATCH3
#define ULP_PATCH4 EMLXS_PATCH4
#define ULP_PATCH5 EMLXS_PATCH5
#define ULP_PATCH6 EMLXS_PATCH6
#define FCP_UNDERRUN_PATCH1 EMLXS_PATCH9
#define FCP_UNDERRUN_PATCH2 EMLXS_PATCH10
#define DEFAULT_PATCHES (ULP_PATCH2 | ULP_PATCH3 | \
ULP_PATCH5 | ULP_PATCH6 | \
FCP_UNDERRUN_PATCH1 | FCP_UNDERRUN_PATCH2)
#ifdef __cplusplus
}
#endif
#endif