#ifndef _SYS_IB_ADAPTERS_HERMON_CQ_H
#define _SYS_IB_ADAPTERS_HERMON_CQ_H
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ib/adapters/hermon/hermon_misc.h>
#ifdef __cplusplus
extern "C" {
#endif
#define HERMON_NUM_CQ_SHIFT 0x12
#define HERMON_CQ_MIN_SIZE ((PAGESIZE / 32) - 1)
#define HERMON_CQE_SUCCESS 0x0
#define HERMON_CQE_LOC_LEN_ERR 0x1
#define HERMON_CQE_LOC_OP_ERR 0x2
#define HERMON_CQE_LOC_PROT_ERR 0x4
#define HERMON_CQE_WR_FLUSHED_ERR 0x5
#define HERMON_CQE_MW_BIND_ERR 0x6
#define HERMON_CQE_BAD_RESPONSE_ERR 0x10
#define HERMON_CQE_LOCAL_ACCESS_ERR 0x11
#define HERMON_CQE_REM_INV_REQ_ERR 0x12
#define HERMON_CQE_REM_ACC_ERR 0x13
#define HERMON_CQE_REM_OP_ERR 0x14
#define HERMON_CQE_TRANS_TO_ERR 0x15
#define HERMON_CQE_RNRNAK_TO_ERR 0x16
#define HERMON_CQE_EEC_REM_ABORTED_ERR 0x22
#define HERMON_CQE_SND_NOP 0x0
#define HERMON_CQE_SND_SEND_INV 0x1
#define HERMON_CQE_SND_RDMAWR 0x8
#define HERMON_CQE_SND_RDMAWR_IMM 0x9
#define HERMON_CQE_SND_SEND 0xA
#define HERMON_CQE_SND_SEND_IMM 0xB
#define HERMON_CQE_SND_LSO 0xE
#define HERMON_CQE_SND_RDMARD 0x10
#define HERMON_CQE_SND_ATOMIC_CS 0x11
#define HERMON_CQE_SND_ATOMIC_FA 0x12
#define HERMON_CQE_SND_ATOMIC_CS_EX 0x14
#define HERMON_CQE_SND_ATOMIC_FC_EX 0x15
#define HERMON_CQE_SND_FRWR 0x19
#define HERMON_CQE_SND_LCL_INV 0x1B
#define HERMON_CQE_SND_CONFIG 0x1F
#define HERMON_CQE_SND_BIND_MW 0x18
#define HERMON_CQE_RCV_RDMAWR_IMM 0x00
#define HERMON_CQE_RCV_SEND 0x01
#define HERMON_CQE_RCV_SEND_IMM 0x02
#define HERMON_CQE_RCV_SEND_INV 0x03
#define HERMON_CQE_RCV_ERROR_CODE 0x1E
#define HERMON_CQE_RCV_RESIZE_CODE 0x16
#define HERMON_CQ_MAXNUMBER_MSK 0xFFFFFF
#define HERMON_CQH_MAX 32
typedef struct hermon_cq_sched_s {
char cqs_name[HERMON_CQH_MAX];
uint_t cqs_start_hid;
uint_t cqs_len;
uint_t cqs_next_alloc;
uint_t cqs_desired;
uint_t cqs_minimum;
uint_t cqs_refcnt;
} hermon_cq_sched_t;
#define HERMON_CQSCHED_NEXT_HID(cq_schedp) \
((atomic_inc_uint_nv(&(cq_schedp)->cqs_next_alloc) % \
(cq_schedp)->cqs_len) + (cq_schedp)->cqs_start_hid)
#define HERMON_HID_TO_EQNUM(state, hid) \
((state)->hs_rsvd_eqs + (hid) - 1)
#define HERMON_HID_VALID(state, hid) \
((uint_t)((hid) - 1) < (state)->hs_intrmsi_allocd)
#define HERMON_EQNUM_TO_HID(state, eqnum) \
((eqnum) - (state)->hs_rsvd_eqs + 1)
#define HERMON_CQ_ERREQNUM_GET(state) \
(state)->hs_cq_erreqnum
#define HERMON_CQE_ERR_STATUS_SHIFT 0
#define HERMON_CQE_ERR_STATUS_MASK 0xFF
#define HERMON_CQE_ERR_DBDCNT_MASK 0xFFFF
#define HERMON_CQE_SEND_ERR_OPCODE 0x1E
#define HERMON_CQE_RECV_ERR_OPCODE 0x1E
#define HERMON_CQ_IS_NORMAL 0
#define HERMON_CQ_IS_SPECIAL 1
#define HERMON_CQ_DEF_UAR_DOORBELL 0x11
#define HERMON_CD_DEF_UAR_DB_SHIFT 0x38
struct hermon_sw_cq_s {
kmutex_t cq_lock;
struct hermon_sw_cq_s *cq_resize_hdl;
uint32_t cq_consindx;
uint32_t cq_cqnum;
hermon_hw_cqe_t *cq_buf;
hermon_mrhdl_t cq_mrhdl;
uint32_t cq_bufsz;
uint32_t cq_log_cqsz;
uint_t cq_refcnt;
uint32_t cq_eqnum;
uint32_t cq_erreqnum;
uint_t cq_is_special;
uint_t cq_is_umap;
uint32_t cq_uarpg;
devmap_cookie_t cq_umap_dhp;
hermon_rsrc_t *cq_cqcrsrcp;
hermon_rsrc_t *cq_rsrcp;
uint_t cq_intmod_count;
uint_t cq_intmod_usec;
ddi_acc_handle_t cq_arm_ci_dbr_acchdl;
hermon_dbr_t *cq_arm_ci_vdbr;
uint64_t cq_arm_ci_pdbr;
uint64_t cq_dbr_mapoffset;
void *cq_hdlrarg;
avl_tree_t cq_wrid_wqhdr_avl_tree;
struct hermon_qalloc_info_s cq_cqinfo;
};
_NOTE(READ_ONLY_DATA(hermon_sw_cq_s::cq_cqnum
hermon_sw_cq_s::cq_erreqnum
hermon_sw_cq_s::cq_cqcrsrcp
hermon_sw_cq_s::cq_rsrcp
hermon_sw_cq_s::cq_hdlrarg
hermon_sw_cq_s::cq_is_umap
hermon_sw_cq_s::cq_uarpg))
_NOTE(DATA_READABLE_WITHOUT_LOCK(hermon_sw_cq_s::cq_bufsz
hermon_sw_cq_s::cq_consindx
hermon_sw_cq_s::cq_cqinfo))
_NOTE(MUTEX_PROTECTS_DATA(hermon_sw_cq_s::cq_lock,
hermon_sw_cq_s::cq_buf
hermon_sw_cq_s::cq_eqnum
hermon_sw_cq_s::cq_mrhdl
hermon_sw_cq_s::cq_refcnt
hermon_sw_cq_s::cq_is_special
hermon_sw_cq_s::cq_umap_dhp))
_NOTE(SCHEME_PROTECTS_DATA("safe sharing",
hermon_sw_cq_s::cq_intmod_count
hermon_sw_cq_s::cq_intmod_usec
hermon_sw_cq_s::cq_resize_hdl))
int hermon_cq_alloc(hermon_state_t *state, ibt_cq_hdl_t ibt_cqhdl,
ibt_cq_attr_t *attr_p, uint_t *actual_size, hermon_cqhdl_t *cqhdl,
uint_t sleepflag);
int hermon_cq_free(hermon_state_t *state, hermon_cqhdl_t *cqhdl,
uint_t sleepflag);
int hermon_cq_resize(hermon_state_t *state, hermon_cqhdl_t cqhdl,
uint_t req_size, uint_t *actual_size, uint_t sleepflag);
int hermon_cq_modify(hermon_state_t *state, hermon_cqhdl_t cqhdl,
uint_t count, uint_t usec, ibt_cq_handler_id_t hid, uint_t sleepflag);
int hermon_cq_notify(hermon_state_t *state, hermon_cqhdl_t cqhdl,
ibt_cq_notify_flags_t flags);
int hermon_cq_poll(hermon_state_t *state, hermon_cqhdl_t cqhdl, ibt_wc_t *wc_p,
uint_t num_wc, uint_t *num_polled);
int hermon_cq_sched_alloc(hermon_state_t *state, ibt_cq_sched_attr_t *attr,
hermon_cq_sched_t **cq_sched_pp);
int hermon_cq_sched_free(hermon_state_t *state, hermon_cq_sched_t *cq_schedp);
int hermon_cq_handler(hermon_state_t *state, hermon_eqhdl_t eq,
hermon_hw_eqe_t *eqe);
int hermon_cq_err_handler(hermon_state_t *state, hermon_eqhdl_t eq,
hermon_hw_eqe_t *eqe);
int hermon_cq_refcnt_inc(hermon_cqhdl_t cq, uint_t is_special);
void hermon_cq_refcnt_dec(hermon_cqhdl_t cq);
hermon_cqhdl_t hermon_cqhdl_from_cqnum(hermon_state_t *state, uint_t cqnum);
void hermon_cq_entries_flush(hermon_state_t *state, hermon_qphdl_t qp);
void hermon_cq_resize_helper(hermon_state_t *state, hermon_cqhdl_t cq);
int hermon_cq_sched_init(hermon_state_t *state);
void hermon_cq_sched_fini(hermon_state_t *state);
#ifdef __cplusplus
}
#endif
#endif