#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/modctl.h>
#include <sys/bitmap.h>
#include <sys/ib/adapters/hermon/hermon.h>
static int hermon_impl_mbox_alloc(hermon_state_t *state,
hermon_mboxlist_t *mblist, hermon_mbox_t **mb, uint_t mbox_wait);
static void hermon_impl_mbox_free(hermon_mboxlist_t *mblist,
hermon_mbox_t **mb);
static int hermon_impl_mboxlist_init(hermon_state_t *state,
hermon_mboxlist_t *mblist, uint_t num_mbox, hermon_rsrc_type_t type);
static void hermon_impl_mboxlist_fini(hermon_state_t *state,
hermon_mboxlist_t *mblist);
static int hermon_outstanding_cmd_alloc(hermon_state_t *state,
hermon_cmd_t **cmd_ptr, uint_t cmd_wait);
static void hermon_outstanding_cmd_free(hermon_state_t *state,
hermon_cmd_t **cmd_ptr);
static int hermon_write_hcr(hermon_state_t *state, hermon_cmd_post_t *cmdpost,
uint16_t token, int *hwerr);
static void hermon_mbox_sync(hermon_mbox_t *mbox, uint_t offset,
uint_t length, uint_t flag);
static void hermon_cmd_check_status(hermon_state_t *state, int status);
int
hermon_cmd_post(hermon_state_t *state, hermon_cmd_post_t *cmdpost)
{
hermon_cmd_t *cmdptr;
int status, retry_cnt, retry_cnt2, hw_err;
uint16_t token;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*cmdpost))
if (cmdpost->cp_flags == HERMON_CMD_NOSLEEP_SPIN) {
retry_cnt = HCA_PIO_RETRY_CNT;
do {
status = hermon_write_hcr(state, cmdpost, 0, &hw_err);
} while (status == HERMON_CMD_INTERNAL_ERR && retry_cnt-- > 0);
if (status != HERMON_CMD_SUCCESS) {
if ((retry_cnt == HCA_PIO_RETRY_CNT &&
hw_err == HCA_PIO_OK) ||
!hermon_cmd_retry_ok(cmdpost, status)) {
hermon_cmd_check_status(state, status);
return (status);
}
} else if (retry_cnt != HCA_PIO_RETRY_CNT) {
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_TRANSIENT);
}
} else {
ASSERT(HERMON_SLEEPFLAG_FOR_CONTEXT() != HERMON_NOSLEEP);
status = hermon_outstanding_cmd_alloc(state, &cmdptr,
cmdpost->cp_flags);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*cmdptr))
retry_cnt = HCA_PIO_RETRY_CNT;
retry:
cmdptr->cmd_status = HERMON_CMD_INVALID_STATUS;
token = (uint16_t)cmdptr->cmd_indx;
retry_cnt2 = HCA_PIO_RETRY_CNT;
do {
status = hermon_write_hcr(state, cmdpost, token,
&hw_err);
} while (status == HERMON_CMD_INTERNAL_ERR && retry_cnt2-- > 0);
if (status != HERMON_CMD_SUCCESS) {
if ((retry_cnt == HCA_PIO_RETRY_CNT &&
hw_err == HCA_PIO_OK) ||
!hermon_cmd_retry_ok(cmdpost, status)) {
hermon_cmd_check_status(state, status);
hermon_outstanding_cmd_free(state, &cmdptr);
return (status);
}
} else if (retry_cnt2 != HCA_PIO_RETRY_CNT) {
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_TRANSIENT);
}
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*cmdptr))
mutex_enter(&cmdptr->cmd_comp_lock);
while (cmdptr->cmd_status == HERMON_CMD_INVALID_STATUS) {
#ifndef __lock_lint
cv_wait(&cmdptr->cmd_comp_cv, &cmdptr->cmd_comp_lock);
#endif
}
mutex_exit(&cmdptr->cmd_comp_lock);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*cmdptr))
status = cmdptr->cmd_status;
if (status == HERMON_CMD_INTERNAL_ERR && retry_cnt-- > 0)
goto retry;
cmdpost->cp_outparm = cmdptr->cmd_outparm;
hermon_outstanding_cmd_free(state, &cmdptr);
if (status != HERMON_CMD_SUCCESS) {
if ((retry_cnt == HCA_PIO_RETRY_CNT &&
hw_err == HCA_PIO_OK) ||
!hermon_cmd_retry_ok(cmdpost, status)) {
hermon_cmd_check_status(state, status);
cmn_err(CE_NOTE, "hermon%d: post cmd failed "
"opcode (0x%x) status (0x%x)\n",
state->hs_instance, cmdpost->cp_opcode,
status);
return (status);
}
} else if (retry_cnt != HCA_PIO_RETRY_CNT) {
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_TRANSIENT);
}
}
return (HERMON_CMD_SUCCESS);
}
static void
hermon_cmd_check_status(hermon_state_t *state, int status)
{
switch (status) {
case HERMON_CMD_TIMEOUT_TOGGLE:
HERMON_FMANOTE(state, HERMON_FMA_TOTOG);
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_NON_FATAL);
break;
case HERMON_CMD_TIMEOUT_GOBIT:
HERMON_FMANOTE(state, HERMON_FMA_GOBIT);
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_NON_FATAL);
break;
case HERMON_CMD_INSUFF_RSRC:
HERMON_FMANOTE(state, HERMON_FMA_RSRC);
break;
case HERMON_CMD_INVALID_STATUS:
HERMON_FMANOTE(state, HERMON_FMA_CMDINV);
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_NON_FATAL);
break;
case HERMON_CMD_INTERNAL_ERR:
HERMON_FMANOTE(state, HERMON_FMA_HCRINT);
hermon_fm_ereport(state, HCA_IBA_ERR,
HCA_ERR_NON_FATAL);
break;
case HERMON_CMD_BAD_NVMEM:
HERMON_FMANOTE(state, HERMON_FMA_NVMEM);
break;
default:
break;
}
}
int
hermon_mbox_alloc(hermon_state_t *state, hermon_mbox_info_t *mbox_info,
uint_t mbox_wait)
{
int status;
uint_t sleep_context;
sleep_context = HERMON_SLEEPFLAG_FOR_CONTEXT();
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_INMBOX) {
if (sleep_context == HERMON_NOSLEEP) {
status = hermon_impl_mbox_alloc(state,
&state->hs_in_intr_mblist,
&mbox_info->mbi_in, mbox_wait);
ASSERT(status == HERMON_CMD_SUCCESS);
} else {
status = hermon_impl_mbox_alloc(state,
&state->hs_in_mblist, &mbox_info->mbi_in,
mbox_wait);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
}
}
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_OUTMBOX) {
if (sleep_context == HERMON_NOSLEEP) {
status = hermon_impl_mbox_alloc(state,
&state->hs_out_intr_mblist,
&mbox_info->mbi_out, mbox_wait);
ASSERT(status == HERMON_CMD_SUCCESS);
} else {
status = hermon_impl_mbox_alloc(state,
&state->hs_out_mblist, &mbox_info->mbi_out,
mbox_wait);
if (status != HERMON_CMD_SUCCESS) {
if (mbox_info->mbi_alloc_flags &
HERMON_ALLOC_INMBOX) {
hermon_impl_mbox_free(
&state->hs_in_mblist,
&mbox_info->mbi_in);
}
return (status);
}
}
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(mbox_info->mbi_sleep_context))
mbox_info->mbi_sleep_context = sleep_context;
return (HERMON_CMD_SUCCESS);
}
void
hermon_mbox_free(hermon_state_t *state, hermon_mbox_info_t *mbox_info)
{
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(mbox_info->mbi_sleep_context))
ASSERT(mbox_info->mbi_sleep_context == HERMON_SLEEPFLAG_FOR_CONTEXT());
if (mbox_info->mbi_sleep_context == HERMON_NOSLEEP) {
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_INMBOX) {
hermon_impl_mbox_free(&state->hs_in_intr_mblist,
&mbox_info->mbi_in);
}
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_OUTMBOX) {
hermon_impl_mbox_free(&state->hs_out_intr_mblist,
&mbox_info->mbi_out);
}
} else {
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_INMBOX) {
hermon_impl_mbox_free(&state->hs_in_mblist,
&mbox_info->mbi_in);
}
if (mbox_info->mbi_alloc_flags & HERMON_ALLOC_OUTMBOX) {
hermon_impl_mbox_free(&state->hs_out_mblist,
&mbox_info->mbi_out);
}
}
}
int
hermon_cmd_complete_handler(hermon_state_t *state, hermon_eqhdl_t eq,
hermon_hw_eqe_t *eqe)
{
hermon_cmd_t *cmdp;
cmdp = &state->hs_cmd_list.cml_cmd[HERMON_EQE_CMDTOKEN_GET(eq, eqe)];
mutex_enter(&cmdp->cmd_comp_lock);
cmdp->cmd_outparm = ((uint64_t)HERMON_EQE_CMDOUTP0_GET(eq, eqe) << 32) |
HERMON_EQE_CMDOUTP1_GET(eq, eqe);
cmdp->cmd_status = HERMON_EQE_CMDSTATUS_GET(eq, eqe);
cv_signal(&cmdp->cmd_comp_cv);
mutex_exit(&cmdp->cmd_comp_lock);
return (DDI_SUCCESS);
}
int
hermon_inmbox_list_init(hermon_state_t *state)
{
int status;
uint_t num_inmbox;
num_inmbox = (1 << state->hs_cfg_profile->cp_log_num_inmbox);
status = hermon_impl_mboxlist_init(state, &state->hs_in_mblist,
num_inmbox, HERMON_IN_MBOX);
if (status != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
hermon_intr_inmbox_list_init(hermon_state_t *state)
{
int status;
uint_t num_inmbox;
num_inmbox = (1 << state->hs_cfg_profile->cp_log_num_intr_inmbox);
status = hermon_impl_mboxlist_init(state, &state->hs_in_intr_mblist,
num_inmbox, HERMON_INTR_IN_MBOX);
if (status != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
hermon_outmbox_list_init(hermon_state_t *state)
{
int status;
uint_t num_outmbox;
num_outmbox = (1 << state->hs_cfg_profile->cp_log_num_outmbox);
status = hermon_impl_mboxlist_init(state, &state->hs_out_mblist,
num_outmbox, HERMON_OUT_MBOX);
if (status != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
hermon_intr_outmbox_list_init(hermon_state_t *state)
{
int status;
uint_t num_outmbox;
num_outmbox = (1 << state->hs_cfg_profile->cp_log_num_intr_outmbox);
status = hermon_impl_mboxlist_init(state, &state->hs_out_intr_mblist,
num_outmbox, HERMON_INTR_OUT_MBOX);
if (status != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
void
hermon_inmbox_list_fini(hermon_state_t *state)
{
hermon_impl_mboxlist_fini(state, &state->hs_in_mblist);
}
void
hermon_intr_inmbox_list_fini(hermon_state_t *state)
{
hermon_impl_mboxlist_fini(state, &state->hs_in_intr_mblist);
}
void
hermon_outmbox_list_fini(hermon_state_t *state)
{
hermon_impl_mboxlist_fini(state, &state->hs_out_mblist);
}
void
hermon_intr_outmbox_list_fini(hermon_state_t *state)
{
hermon_impl_mboxlist_fini(state, &state->hs_out_intr_mblist);
}
static int
hermon_impl_mbox_alloc(hermon_state_t *state, hermon_mboxlist_t *mblist,
hermon_mbox_t **mb, uint_t mbox_wait)
{
hermon_mbox_t *mbox_ptr;
uint_t index, next, prev;
uint_t count, countmax;
if (mbox_wait == HERMON_NOSLEEP) {
count = 0;
countmax = state->hs_cfg_profile->cp_cmd_poll_max;
mutex_enter(&mblist->mbl_lock);
mblist->mbl_pollers++;
while (mblist->mbl_entries_free == 0) {
mutex_exit(&mblist->mbl_lock);
if (++count > countmax) {
return (HERMON_CMD_INSUFF_RSRC);
}
drv_usecwait(state->hs_cfg_profile->cp_cmd_poll_delay);
mutex_enter(&mblist->mbl_lock);
}
mblist->mbl_pollers--;
} else {
mutex_enter(&mblist->mbl_lock);
while (mblist->mbl_entries_free == 0) {
mblist->mbl_waiters++;
#ifndef __lock_lint
cv_wait(&mblist->mbl_cv, &mblist->mbl_lock);
#endif
}
}
mbox_ptr = mblist->mbl_mbox;
index = mblist->mbl_head_indx;
next = mbox_ptr[index].mb_next;
prev = mbox_ptr[index].mb_prev;
mblist->mbl_mbox[next].mb_prev = prev;
mblist->mbl_mbox[prev].mb_next = next;
mblist->mbl_head_indx = next;
mblist->mbl_entries_free--;
*mb = &mbox_ptr[index];
mutex_exit(&mblist->mbl_lock);
return (HERMON_CMD_SUCCESS);
}
static void
hermon_impl_mbox_free(hermon_mboxlist_t *mblist, hermon_mbox_t **mb)
{
uint_t mbox_indx;
mutex_enter(&mblist->mbl_lock);
mbox_indx = (*mb)->mb_indx;
if (mblist->mbl_entries_free++ != 0) {
(*mb)->mb_next = mblist->mbl_head_indx;
(*mb)->mb_prev = mblist->mbl_tail_indx;
mblist->mbl_mbox[mblist->mbl_head_indx].mb_prev = mbox_indx;
mblist->mbl_mbox[mblist->mbl_tail_indx].mb_next = mbox_indx;
mblist->mbl_tail_indx = mbox_indx;
} else {
(*mb)->mb_next = mbox_indx;
(*mb)->mb_prev = mbox_indx;
mblist->mbl_tail_indx = mbox_indx;
mblist->mbl_head_indx = mbox_indx;
}
if (mblist->mbl_pollers > 0 && mblist->mbl_waiters > 0) {
mblist->mbl_signal = (mblist->mbl_signal + 1) % 2;
} else if (mblist->mbl_waiters > 0) {
mblist->mbl_signal = 1;
} else {
mblist->mbl_signal = 0;
}
if (mblist->mbl_signal) {
mblist->mbl_waiters--;
cv_signal(&mblist->mbl_cv);
}
*mb = NULL;
mutex_exit(&mblist->mbl_lock);
}
static int
hermon_impl_mboxlist_init(hermon_state_t *state, hermon_mboxlist_t *mblist,
uint_t num_mbox, hermon_rsrc_type_t type)
{
hermon_rsrc_t *rsrc;
ddi_dma_cookie_t dma_cookie;
uint_t dma_cookiecnt;
int status, i;
mblist->mbl_list_sz = num_mbox;
mblist->mbl_mbox = kmem_zalloc(mblist->mbl_list_sz *
sizeof (hermon_mbox_t), KM_SLEEP);
mblist->mbl_head_indx = 0;
mblist->mbl_tail_indx = mblist->mbl_list_sz - 1;
mblist->mbl_entries_free = mblist->mbl_list_sz;
mblist->mbl_waiters = 0;
mblist->mbl_num_alloc = 0;
mutex_init(&mblist->mbl_lock, NULL, MUTEX_DRIVER,
DDI_INTR_PRI(state->hs_intrmsi_pri));
cv_init(&mblist->mbl_cv, NULL, CV_DRIVER, NULL);
for (i = 0; i < mblist->mbl_list_sz; i++) {
status = hermon_rsrc_alloc(state, type, 1, HERMON_SLEEP,
&rsrc);
if (status != DDI_SUCCESS) {
goto mboxlist_init_fail;
}
mblist->mbl_mbox[i].mb_rsrcptr = rsrc;
mblist->mbl_mbox[i].mb_addr = rsrc->hr_addr;
mblist->mbl_mbox[i].mb_acchdl = rsrc->hr_acchdl;
status = ddi_dma_addr_bind_handle(rsrc->hr_dmahdl, NULL,
rsrc->hr_addr, rsrc->hr_len,
(DDI_DMA_RDWR | DDI_DMA_CONSISTENT),
DDI_DMA_SLEEP, NULL, &dma_cookie, &dma_cookiecnt);
if (status != DDI_SUCCESS) {
hermon_rsrc_free(state, &rsrc);
goto mboxlist_init_fail;
}
mblist->mbl_mbox[i].mb_mapaddr = dma_cookie.dmac_laddress;
mblist->mbl_mbox[i].mb_next = i+1;
mblist->mbl_mbox[i].mb_prev = i-1;
mblist->mbl_mbox[i].mb_indx = i;
mblist->mbl_num_alloc = i + 1;
}
mblist->mbl_mbox[mblist->mbl_head_indx].mb_prev =
mblist->mbl_tail_indx;
mblist->mbl_mbox[mblist->mbl_tail_indx].mb_next =
mblist->mbl_head_indx;
return (DDI_SUCCESS);
mboxlist_init_fail:
hermon_impl_mboxlist_fini(state, mblist);
return (DDI_FAILURE);
}
static void
hermon_impl_mboxlist_fini(hermon_state_t *state, hermon_mboxlist_t *mblist)
{
hermon_rsrc_t *rsrc;
int i, status;
for (i = 0; i < mblist->mbl_num_alloc; i++) {
rsrc = mblist->mbl_mbox[i].mb_rsrcptr;
status = ddi_dma_unbind_handle(rsrc->hr_dmahdl);
if (status != DDI_SUCCESS) {
HERMON_WARNING(state, "failed to unbind DMA mapping");
return;
}
hermon_rsrc_free(state, &rsrc);
}
mutex_destroy(&mblist->mbl_lock);
cv_destroy(&mblist->mbl_cv);
kmem_free(mblist->mbl_mbox, mblist->mbl_list_sz *
sizeof (hermon_mbox_t));
}
static int
hermon_outstanding_cmd_alloc(hermon_state_t *state, hermon_cmd_t **cmd_ptr,
uint_t cmd_wait)
{
hermon_cmdlist_t *cmd_list;
uint_t next, prev, head;
cmd_list = &state->hs_cmd_list;
mutex_enter(&cmd_list->cml_lock);
ASSERT(cmd_list->cml_num_alloc != 0);
while (cmd_list->cml_entries_free == 0) {
if (cmd_wait == HERMON_NOSLEEP) {
mutex_exit(&cmd_list->cml_lock);
return (HERMON_CMD_INSUFF_RSRC);
}
cmd_list->cml_waiters++;
#ifndef __lock_lint
cv_wait(&cmd_list->cml_cv, &cmd_list->cml_lock);
#endif
}
head = cmd_list->cml_head_indx;
*cmd_ptr = &cmd_list->cml_cmd[head];
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(**cmd_ptr))
next = (*cmd_ptr)->cmd_next;
prev = (*cmd_ptr)->cmd_prev;
(*cmd_ptr)->cmd_status = HERMON_CMD_INVALID_STATUS;
cmd_list->cml_cmd[next].cmd_prev = prev;
cmd_list->cml_cmd[prev].cmd_next = next;
cmd_list->cml_head_indx = next;
cmd_list->cml_entries_free--;
mutex_exit(&cmd_list->cml_lock);
return (HERMON_CMD_SUCCESS);
}
static void
hermon_outstanding_cmd_free(hermon_state_t *state, hermon_cmd_t **cmd_ptr)
{
hermon_cmdlist_t *cmd_list;
uint_t cmd_indx;
cmd_list = &state->hs_cmd_list;
mutex_enter(&cmd_list->cml_lock);
cmd_indx = (*cmd_ptr)->cmd_indx;
if (cmd_list->cml_entries_free++ != 0) {
(*cmd_ptr)->cmd_next = cmd_list->cml_head_indx;
(*cmd_ptr)->cmd_prev = cmd_list->cml_tail_indx;
cmd_list->cml_cmd[cmd_list->cml_head_indx].cmd_prev = cmd_indx;
cmd_list->cml_cmd[cmd_list->cml_tail_indx].cmd_next = cmd_indx;
cmd_list->cml_tail_indx = cmd_indx;
} else {
(*cmd_ptr)->cmd_next = cmd_indx;
(*cmd_ptr)->cmd_prev = cmd_indx;
cmd_list->cml_head_indx = cmd_indx;
cmd_list->cml_tail_indx = cmd_indx;
}
if (cmd_list->cml_waiters > 0) {
cmd_list->cml_waiters--;
cv_signal(&cmd_list->cml_cv);
}
*cmd_ptr = NULL;
mutex_exit(&cmd_list->cml_lock);
}
static int
hermon_write_hcr(hermon_state_t *state, hermon_cmd_post_t *cmdpost,
uint16_t token, int *hw_err)
{
hermon_hw_hcr_t *hcr;
uint_t status, count, countmax;
uint64_t hcrreg;
uint64_t togmask;
ddi_acc_handle_t cmdhdl = hermon_get_cmdhdl(state);
boolean_t hw_error = B_FALSE;
hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
#ifdef __lock_lint
mutex_enter(&state->hs_cmd_regs.hcr_lock);
#else
if (!HERMON_IN_FASTREBOOT(state)) {
mutex_enter(&state->hs_cmd_regs.hcr_lock);
}
#endif
hcr = state->hs_cmd_regs.hcr;
countmax = state->hs_cfg_profile->cp_cmd_poll_max;
togmask = (state->hs_cmd_toggle & 0x01) << HERMON_HCR_CMD_T_SHFT;
hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
fm_test);
count = 0;
for (;;) {
hcrreg = ddi_get32(cmdhdl, &hcr->cmd);
if (((hcrreg & HERMON_HCR_CMD_GO_MASK) == 0) &&
((hcrreg & HERMON_HCR_CMD_T_MASK) == togmask)) {
break;
}
drv_usecwait(state->hs_cfg_profile->cp_cmd_poll_delay);
if (++count > countmax) {
#ifdef __lock_lint
mutex_exit(&state->hs_cmd_regs.hcr_lock);
#else
if (!HERMON_IN_FASTREBOOT(state)) {
mutex_exit(&state->hs_cmd_regs.hcr_lock);
}
#endif
cmn_err(CE_NOTE, "write_hcr: cannot start cmd");
return (HERMON_CMD_TIMEOUT_GOBIT);
}
}
hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
fm_test);
if (fm_loop_cnt != HCA_PIO_RETRY_CNT) {
hw_error = B_TRUE;
}
state->hs_cmd_toggle++;
togmask = (state->hs_cmd_toggle & 0x01) << HERMON_HCR_CMD_T_SHFT;
hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
fm_test);
ddi_put64(cmdhdl, (uint64_t *)(void *)&hcr->in_param0,
cmdpost->cp_inparm);
hcrreg = ((uint64_t)cmdpost->cp_inmod << 32);
hcrreg = hcrreg | (cmdpost->cp_outparm >> 32);
ddi_put64(cmdhdl, (uint64_t *)(void *)&hcr->input_modifier, hcrreg);
hcrreg = (cmdpost->cp_outparm << 32);
hcrreg = hcrreg | ((uint32_t)token << HERMON_HCR_TOKEN_SHIFT);
ddi_put64(cmdhdl, (uint64_t *)(void *)&hcr->out_param1, hcrreg);
hcrreg = HERMON_HCR_CMD_GO_MASK;
hcrreg |= (state->hs_cmd_toggle & 0x01) << HERMON_HCR_CMD_T_SHFT;
if (cmdpost->cp_flags == HERMON_CMD_SLEEP_NOSPIN) {
hcrreg = hcrreg | HERMON_HCR_CMD_E_MASK;
}
hcrreg = hcrreg | (cmdpost->cp_opmod << HERMON_HCR_CMD_OPMOD_SHFT);
hcrreg = hcrreg | (cmdpost->cp_opcode);
ddi_put32(cmdhdl, &hcr->cmd, hcrreg);
hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
fm_test);
if (fm_loop_cnt != HCA_PIO_RETRY_CNT) {
hw_error = B_TRUE;
}
if (cmdpost->cp_flags == HERMON_CMD_NOSLEEP_SPIN) {
countmax = (state->hs_cfg_profile->cp_cmd_poll_max << 4);
hermon_pio_start(state, cmdhdl, pio_error, fm_loop_cnt,
fm_status, fm_test);
count = 0;
for (;;) {
hcrreg = ddi_get32(cmdhdl, &hcr->cmd);
if (((hcrreg & HERMON_HCR_CMD_GO_MASK) == 0) &&
((hcrreg & HERMON_HCR_CMD_T_MASK) == togmask)) {
break;
}
drv_usecwait(state->hs_cfg_profile->cp_cmd_poll_delay);
if (++count > countmax) {
#ifdef __lock_lint
mutex_exit(&state-> hs_cmd_regs.hcr_lock);
#else
if (!HERMON_IN_FASTREBOOT(state)) {
mutex_exit(&state->
hs_cmd_regs.hcr_lock);
}
#endif
cmn_err(CE_NOTE,
"write_hcr: cannot complete cmd");
return (HERMON_CMD_TIMEOUT_GOBIT);
}
}
status = (hcrreg >> HERMON_HCR_CMD_STATUS_SHFT);
hcrreg = ddi_get32(cmdhdl, &hcr->out_param0);
cmdpost->cp_outparm = hcrreg << 32;
hcrreg = ddi_get32(cmdhdl, &hcr->out_param1);
cmdpost->cp_outparm |= hcrreg;
hermon_pio_end(state, cmdhdl, pio_error, fm_loop_cnt, fm_status,
fm_test);
if (fm_loop_cnt != HCA_PIO_RETRY_CNT) {
hw_error = B_TRUE;
}
} else {
status = HERMON_CMD_SUCCESS;
}
#ifdef __lock_lint
mutex_exit(&state->hs_cmd_regs.hcr_lock);
#else
if (!HERMON_IN_FASTREBOOT(state)) {
mutex_exit(&state->hs_cmd_regs.hcr_lock);
}
#endif
if (hw_error == B_TRUE) {
*hw_err = HCA_PIO_TRANSIENT;
} else {
*hw_err = HCA_PIO_OK;
}
#ifdef FMA_TEST
if (hermon_test_num == -3) {
status = HERMON_CMD_INTERNAL_ERR;
}
#endif
return (status);
pio_error:
#ifdef __lock_lint
mutex_exit(&state->hs_cmd_regs.hcr_lock);
#else
if (!HERMON_IN_FASTREBOOT(state)) {
mutex_exit(&state->hs_cmd_regs.hcr_lock);
}
#endif
hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_NON_FATAL);
*hw_err = HCA_PIO_PERSISTENT;
return (HERMON_CMD_INVALID_STATUS);
}
int
hermon_outstanding_cmdlist_init(hermon_state_t *state)
{
uint_t num_outstanding_cmds, head, tail;
int i;
num_outstanding_cmds = (1 << state->hs_fw.log_max_cmd);
state->hs_cmd_list.cml_list_sz = num_outstanding_cmds;
state->hs_cmd_list.cml_head_indx = 0;
state->hs_cmd_list.cml_tail_indx = state->hs_cmd_list.cml_list_sz - 1;
state->hs_cmd_list.cml_entries_free = state->hs_cmd_list.cml_list_sz;
state->hs_cmd_list.cml_waiters = 0;
state->hs_cmd_list.cml_num_alloc = 0;
if (num_outstanding_cmds) {
state->hs_cmd_list.cml_cmd =
kmem_zalloc(state->hs_cmd_list.cml_list_sz *
sizeof (hermon_cmd_t), KM_SLEEP);
}
mutex_init(&state->hs_cmd_list.cml_lock, NULL, MUTEX_DRIVER,
DDI_INTR_PRI(state->hs_intrmsi_pri));
cv_init(&state->hs_cmd_list.cml_cv, NULL, CV_DRIVER, NULL);
for (i = 0; i < state->hs_cmd_list.cml_list_sz; i++) {
mutex_init(&state->hs_cmd_list.cml_cmd[i].cmd_comp_lock,
NULL, MUTEX_DRIVER, DDI_INTR_PRI(state->hs_intrmsi_pri));
cv_init(&state->hs_cmd_list.cml_cmd[i].cmd_comp_cv, NULL,
CV_DRIVER, NULL);
state->hs_cmd_list.cml_cmd[i].cmd_next = i+1;
state->hs_cmd_list.cml_cmd[i].cmd_prev = i-1;
state->hs_cmd_list.cml_cmd[i].cmd_indx = i;
state->hs_cmd_list.cml_num_alloc = i + 1;
}
if (num_outstanding_cmds) {
head = state->hs_cmd_list.cml_head_indx;
tail = state->hs_cmd_list.cml_tail_indx;
state->hs_cmd_list.cml_cmd[head].cmd_prev =
state->hs_cmd_list.cml_tail_indx;
state->hs_cmd_list.cml_cmd[tail].cmd_next =
state->hs_cmd_list.cml_head_indx;
}
return (DDI_SUCCESS);
}
void
hermon_outstanding_cmdlist_fini(hermon_state_t *state)
{
int i;
for (i = 0; i < state->hs_cmd_list.cml_num_alloc; i++) {
mutex_destroy(&state->hs_cmd_list.cml_cmd[i].cmd_comp_lock);
cv_destroy(&state->hs_cmd_list.cml_cmd[i].cmd_comp_cv);
}
mutex_destroy(&state->hs_cmd_list.cml_lock);
cv_destroy(&state->hs_cmd_list.cml_cv);
if (state->hs_cmd_list.cml_num_alloc) {
kmem_free(state->hs_cmd_list.cml_cmd,
state->hs_cmd_list.cml_list_sz * sizeof (hermon_cmd_t));
}
}
static void
hermon_mbox_sync(hermon_mbox_t *mbox, uint_t offset, uint_t length,
uint_t flag)
{
ddi_dma_handle_t dmahdl;
int status;
dmahdl = mbox->mb_rsrcptr->hr_dmahdl;
status = ddi_dma_sync(dmahdl, (off_t)offset, (size_t)length, flag);
if (status != DDI_SUCCESS) {
return;
}
}
int
hermon_init_hca_cmd_post(hermon_state_t *state,
hermon_hw_initqueryhca_t *inithca, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
ASSERT(sleepflag == HERMON_CMD_NOSLEEP_SPIN);
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_initqueryhca_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)inithca)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = INIT_HCA;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_close_hca_cmd_post(hermon_state_t *state, uint_t sleepflag)
{
hermon_cmd_post_t cmd;
int status;
ASSERT(sleepflag == HERMON_CMD_NOSLEEP_SPIN);
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = CLOSE_HCA;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_set_port_cmd_post(hermon_state_t *state, hermon_hw_set_port_t *initport,
uint_t port, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_set_port_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)initport)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = port;
cmd.cp_opcode = SET_PORT;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_init_port_cmd_post(hermon_state_t *state, uint_t port, uint_t sleepflag)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = port;
cmd.cp_opcode = INIT_PORT;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_close_port_cmd_post(hermon_state_t *state, uint_t port, uint_t sleepflag)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = port;
cmd.cp_opcode = CLOSE_PORT;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
#ifdef HERMON_NO_MOD_STAT_CFG
int
hermon_mod_stat_cfg_cmd_post(hermon_state_t *state)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
hermon_hw_mod_stat_cfg_t *mod;
hermon_hw_msg_in_mod_t inmod;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, HERMON_NOSLEEP);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
mod = (hermon_hw_mod_stat_cfg_t *)kmem_zalloc(
sizeof (hermon_hw_mod_stat_cfg_t), KM_SLEEP);
mod->srq_m = 1;
mod->srq = state->hs_cfg_profile->cp_srq_enable;
if (mod->srq) {
mod->log_max_srq = state->hs_cfg_profile->cp_log_num_srq;
} else {
mod->log_max_srq = 0;
}
size = sizeof (hermon_hw_mod_stat_cfg_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)mod)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = MOD_STAT_CFG;
cmd.cp_opmod = HERMON_MOD_STAT_CFG_PTR;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
kmem_free(mod, sizeof (hermon_hw_mod_stat_cfg_t));
hermon_mbox_free(state, &mbox_info);
return (status);
}
#endif
int
hermon_map_cmd_post(hermon_state_t *state, hermon_dma_info_t *dma,
uint16_t opcode, ddi_dma_cookie_t cookie, uint_t ccount)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
hermon_hw_vpm_t vpm;
uint64_t data;
uint64_t paddr, vaddr;
uint_t size;
int status, i, j, k = 0;
int max_mailbox_size;
int cookie_num_icm_pages;
int num_vpm_entries;
int log2_npages;
int npages;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, HERMON_SLEEP);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
cmd.cp_outparm = 0;
cmd.cp_opcode = opcode;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
vaddr = dma->icmaddr;
num_vpm_entries = 0;
size = sizeof (hermon_hw_vpm_t);
bzero(&vpm, size);
max_mailbox_size = HERMON_MBOX_SIZE / size;
while (ccount-- > 0) {
cookie_num_icm_pages = cookie.dmac_size / HERMON_PAGESIZE;
paddr = cookie.dmac_laddress;
for (i = cookie_num_icm_pages; i > 0; i -= npages) {
log2_npages = highbit(i) - 1;
npages = (1 << log2_npages);
while (((npages * HERMON_PAGESIZE - 1) & paddr) != 0) {
log2_npages--;
npages = (1 << log2_npages);
}
vpm.log2sz = log2_npages;
vpm.paddr_l = (uint32_t)(paddr >> 12);
vpm.paddr_h = (uint32_t)(paddr >> 32);
paddr += npages * HERMON_PAGESIZE;
if (opcode == MAP_ICM) {
vpm.vaddr_l = (uint32_t)(vaddr >> 12);
vpm.vaddr_h = (uint32_t)(vaddr >> 32);
vaddr += npages * HERMON_PAGESIZE;
}
for (j = 0; j < (size >> 3); j++, k++) {
data = ((uint64_t *)(void *)&vpm)[j];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + k),
data);
}
if (++num_vpm_entries == max_mailbox_size) {
hermon_mbox_sync(mbox_info.mbi_in, 0, (size *
num_vpm_entries), DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_inmod = num_vpm_entries;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
cmn_err(CE_NOTE, "hermon%d: %s cmd "
"failed (0x%x)", state->hs_instance,
opcode == MAP_FA ? "MAP_FA" :
opcode == MAP_ICM ? "MAP_ICM" :
opcode == MAP_ICM_AUX ? "MAP_ICMA" :
"UNKNOWN", status);
goto map_fail;
}
num_vpm_entries = k = 0;
}
}
if (ccount != 0) {
ddi_dma_nextcookie(dma->dma_hdl, &cookie);
}
}
if (num_vpm_entries) {
hermon_mbox_sync(mbox_info.mbi_in, 0, (size * num_vpm_entries),
DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_inmod = num_vpm_entries;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
cmn_err(CE_NOTE, "hermon%d: %s cmd "
"failed (0x%x)", state->hs_instance,
opcode == MAP_FA ? "MAP_FA" :
opcode == MAP_ICM ? "MAP_ICM" :
opcode == MAP_ICM_AUX ? "MAP_ICMA" :
"UNKNOWN", status);
goto map_fail;
}
}
map_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_unmap_fa_cmd_post(hermon_state_t *state)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = UNMAP_FA;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_run_fw_cmd_post(hermon_state_t *state)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = RUN_FW;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
#ifdef FMA_TEST
if (hermon_test_num == -2) {
status = HERMON_CMD_BAD_NVMEM;
HERMON_FMANOTE(state, HERMON_FMA_BADNVMEM);
}
#endif
return (status);
}
int
hermon_set_icm_size_cmd_post(hermon_state_t *state)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = (uint64_t)state->hs_icm_sz;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = SET_ICM_SIZE;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
state->hs_icma_sz = (uint64_t)(cmd.cp_outparm << HERMON_PAGESHIFT);
return (status);
}
int
hermon_unmap_icm_aux_cmd_post(hermon_state_t *state)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = UNMAP_ICM_AUX;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_unmap_icm_cmd_post(hermon_state_t *state, hermon_dma_info_t *dma_info)
{
hermon_cmd_post_t cmd;
uint64_t addr;
uint32_t npages;
int status;
if (dma_info != NULL) {
addr = dma_info->icmaddr;
npages = dma_info->length / HERMON_PAGESIZE;
} else {
addr = 0;
npages = state->hs_icm_sz / HERMON_PAGESIZE;
}
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = addr;
cmd.cp_outparm = 0;
cmd.cp_inmod = npages;
cmd.cp_opcode = UNMAP_ICM;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_mad_ifc_cmd_post(hermon_state_t *state, uint_t port,
uint_t sleepflag, uint32_t *mad, uint32_t *resp)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint_t size;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
bcopy(mad, mbox_info.mbi_in->mb_addr, size);
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_CHECK;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto mad_ifc_fail;
}
hermon_mbox_sync(mbox_info.mbi_out, 0, size, DDI_DMA_SYNC_FORCPU);
bcopy(mbox_info.mbi_out->mb_addr, resp, size);
mad_ifc_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getportinfo_cmd_post(hermon_state_t *state, uint_t port,
uint_t sleepflag, sm_portinfo_t *portinfo)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint32_t *mbox;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_MADHDR0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_PORTINFO);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], port);
for (i = 6; i < (size >> 2); i++) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[i], 0);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getportinfo_fail;
}
size = sizeof (sm_portinfo_t);
hermon_mbox_sync(mbox_info.mbi_out, HERMON_CMD_MADDATA_OFFSET,
size, DDI_DMA_SYNC_FORCPU);
bcopy((void *)((uintptr_t)mbox_info.mbi_out->mb_addr +
HERMON_CMD_MADDATA_OFFSET), portinfo, size);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*portinfo))
HERMON_GETPORTINFO_SWAP(portinfo);
getportinfo_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_is_ext_port_counters_supported(hermon_state_t *state, uint_t port,
uint_t sleepflag, int *ext_width_supported)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint32_t *mbox;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_PERF_GET);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4],
HERMON_CMD_CLASSPORTINFO);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], HERMON_CMD_PERFATTR);
hermon_mbox_sync(mbox_info.mbi_in, 0, HERMON_CMD_MAD_IFC_SIZE,
DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK | HERMON_CMD_BKEY_DONTCHECK;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto fail;
}
hermon_mbox_sync(mbox_info.mbi_out, 0, HERMON_CMD_MAD_IFC_SIZE,
DDI_DMA_SYNC_FORCPU);
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + 8));
*ext_width_supported = (data & (HERMON_IS_EXT_WIDTH_SUPPORTED |
HERMON_IS_EXT_WIDTH_SUPPORTED_NOIETF)) ? 1 : 0;
fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getextperfcntr_cmd_post(hermon_state_t *state, uint_t port,
uint_t sleepflag, hermon_hw_sm_extperfcntr_t *perfinfo)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint32_t *mbox;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_PERF_GET);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4],
HERMON_CMD_EXTPERFCNTRS);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], HERMON_CMD_PERFATTR);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[16], (port << 16));
hermon_mbox_sync(mbox_info.mbi_in, 0, HERMON_CMD_MAD_IFC_SIZE,
DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK | HERMON_CMD_BKEY_DONTCHECK;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto fail;
}
hermon_mbox_sync(mbox_info.mbi_out, 0, HERMON_CMD_MAD_IFC_SIZE,
DDI_DMA_SYNC_FORCPU);
for (i = 0; i < (sizeof (hermon_hw_sm_extperfcntr_t) >> 3); i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i + 8));
((uint64_t *)(void *)perfinfo)[i] = data;
}
fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getperfcntr_cmd_post(hermon_state_t *state, uint_t port,
uint_t sleepflag, hermon_hw_sm_perfcntr_t *perfinfo, int reset)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint32_t *mbox;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
if (reset) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0],
HERMON_CMD_PERF_SET);
} else {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0],
HERMON_CMD_PERF_GET);
}
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_PERFCNTRS);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], HERMON_CMD_PERFATTR);
if (reset) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[16],
((port << 16) | 0xf000));
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[22], 0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[23], 0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[24], 0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[25], 0);
} else
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[16], (port << 16));
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK | HERMON_CMD_BKEY_DONTCHECK;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getperfinfo_fail;
}
size = HERMON_CMD_MAD_IFC_SIZE;
hermon_mbox_sync(mbox_info.mbi_out, 0, size, DDI_DMA_SYNC_FORCPU);
if (reset == 0) {
size = sizeof (hermon_hw_sm_perfcntr_t);
for (i = 0; i < size >> 3; i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i + 8));
((uint64_t *)(void *)perfinfo)[i] = data;
}
}
getperfinfo_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getnodeinfo_cmd_post(hermon_state_t *state, uint_t sleepflag,
sm_nodeinfo_t *nodeinfo)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint32_t *mbox;
uint_t size;
int status, i;
ASSERT(sleepflag == HERMON_CMD_NOSLEEP_SPIN);
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_MADHDR0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_NODEINFO);
for (i = 5; i < (size >> 2); i++) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[i], 0);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = 1;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getnodeinfo_fail;
}
size = sizeof (sm_nodeinfo_t);
hermon_mbox_sync(mbox_info.mbi_out, HERMON_CMD_MADDATA_OFFSET,
size, DDI_DMA_SYNC_FORCPU);
bcopy((void *)((uintptr_t)mbox_info.mbi_out->mb_addr +
HERMON_CMD_MADDATA_OFFSET), nodeinfo, size);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*nodeinfo))
HERMON_GETNODEINFO_SWAP(nodeinfo);
getnodeinfo_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getnodedesc_cmd_post(hermon_state_t *state, uint_t sleepflag,
sm_nodedesc_t *nodedesc)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint32_t *mbox;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_MADHDR0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_NODEDESC);
for (i = 5; i < (size >> 2); i++) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[i], 0);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = 1;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getnodedesc_fail;
}
size = sizeof (sm_nodedesc_t);
hermon_mbox_sync(mbox_info.mbi_out, HERMON_CMD_MADDATA_OFFSET,
size, DDI_DMA_SYNC_FORCPU);
bcopy((void *)((uintptr_t)mbox_info.mbi_out->mb_addr +
HERMON_CMD_MADDATA_OFFSET), nodedesc, size);
getnodedesc_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getguidinfo_cmd_post(hermon_state_t *state, uint_t port,
uint_t guidblock, uint_t sleepflag, sm_guidinfo_t *guidinfo)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint32_t *mbox;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_MADHDR0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_GUIDINFO);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], guidblock);
for (i = 6; i < (size >> 2); i++) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[i], 0);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getguidinfo_fail;
}
size = sizeof (sm_guidinfo_t);
hermon_mbox_sync(mbox_info.mbi_out, HERMON_CMD_MADDATA_OFFSET,
size, DDI_DMA_SYNC_FORCPU);
bcopy((void *)((uintptr_t)mbox_info.mbi_out->mb_addr +
HERMON_CMD_MADDATA_OFFSET), guidinfo, size);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*guidinfo))
HERMON_GETGUIDINFO_SWAP(guidinfo);
getguidinfo_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_getpkeytable_cmd_post(hermon_state_t *state, uint_t port,
uint_t pkeyblock, uint_t sleepflag, sm_pkey_table_t *pkeytable)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint32_t *mbox;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX | HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_CMD_MAD_IFC_SIZE;
mbox = (uint32_t *)mbox_info.mbi_in->mb_addr;
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[0], HERMON_CMD_MADHDR0);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[1], HERMON_CMD_MADHDR1);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[2], HERMON_CMD_MADHDR2);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[3], HERMON_CMD_MADHDR3);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[4], HERMON_CMD_PKEYTBLE);
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[5], pkeyblock);
for (i = 6; i < (size >> 2); i++) {
ddi_put32(mbox_info.mbi_in->mb_acchdl, &mbox[i], 0);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = port;
cmd.cp_opcode = MAD_IFC;
cmd.cp_opmod = HERMON_CMD_MKEY_DONTCHECK;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto getpkeytable_fail;
}
size = sizeof (sm_pkey_table_t);
hermon_mbox_sync(mbox_info.mbi_out, HERMON_CMD_MADDATA_OFFSET,
size, DDI_DMA_SYNC_FORCPU);
bcopy((void *)((uintptr_t)mbox_info.mbi_out->mb_addr +
HERMON_CMD_MADDATA_OFFSET), pkeytable, size);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*pkeytable))
HERMON_GETPKEYTABLE_SWAP(pkeytable);
getpkeytable_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_write_mtt_cmd_post(hermon_state_t *state, hermon_rsrc_t *mtt,
uint64_t start_addr, uint_t nummtt, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status;
int i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr),
start_addr);
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + 1), 0x0);
for (i = 0; i < nummtt; i++) {
data = ((uint64_t *)mtt->hr_addr)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i + 2), data);
}
size = (nummtt << HERMON_MTT_SIZE_SHIFT) + HERMON_CMD_WRITEMTT_RSVD_SZ;
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = nummtt;
cmd.cp_opcode = WRITE_MTT;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
cmn_err(CE_CONT, "WRITE_MTT failed (0x%x)\n", status);
}
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_sync_tpt_cmd_post(hermon_state_t *state, uint_t sleepflag)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = SYNC_TPT;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_map_eq_cmd_post(hermon_state_t *state, uint_t map, uint_t eqcindx,
uint64_t eqmapmask, uint_t sleepflag)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = eqmapmask;
cmd.cp_outparm = 0;
cmd.cp_inmod = eqcindx;
if (map != HERMON_CMD_MAP_EQ_EVT_MAP) {
cmd.cp_inmod |= HERMON_CMD_UNMAP_EQ_MASK;
}
cmd.cp_opcode = MAP_EQ;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_resize_cq_cmd_post(hermon_state_t *state, hermon_hw_cqc_t *cqc,
uint_t cqcindx, uint32_t *prod_indx, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_cqc_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)(void *)cqc)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = cqcindx;
cmd.cp_opcode = MODIFY_CQ;
cmd.cp_opmod = RESIZE_CQ;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
*prod_indx = (cmd.cp_outparm >> 32);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_modify_cq_cmd_post(hermon_state_t *state, hermon_hw_cqc_t *cqc,
uint_t cqcindx, uint_t opmod, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_cqc_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)(void *)cqc)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = cqcindx;
cmd.cp_opcode = MODIFY_CQ;
cmd.cp_opmod = (uint16_t)opmod;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_cmn_qp_cmd_post(hermon_state_t *state, uint_t opcode,
hermon_hw_qpc_t *qp, uint_t qpindx, uint32_t opmask,
uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data, in_mapaddr, out_mapaddr;
uint_t size, flags, opmod;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
if (opcode == RTS2SQD_QP) {
flags = HERMON_CMD_REQ_SQD_EVENT;
in_mapaddr = 0;
out_mapaddr = 0;
opmod = 0;
} else if (opcode == TOERR_QP) {
in_mapaddr = 0;
out_mapaddr = 0;
opmod = 0;
flags = 0;
} else if (opcode == TORST_QP) {
in_mapaddr = 0;
out_mapaddr = 0;
opmod = HERMON_CMD_DIRECT_TO_RESET | HERMON_CMD_NO_OUTMBOX;
flags = 0;
} else {
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
in_mapaddr = mbox_info.mbi_in->mb_mapaddr;
out_mapaddr = 0;
flags = 0;
opmod = 0;
size = sizeof (hermon_hw_qpc_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)(void *)qp)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i + 1),
data);
}
ddi_put32(mbox_info.mbi_in->mb_acchdl,
((uint32_t *)mbox_info.mbi_in->mb_addr), opmask);
hermon_mbox_sync(mbox_info.mbi_in, 0, size + 8,
DDI_DMA_SYNC_FORDEV);
}
cmd.cp_inparm = in_mapaddr;
cmd.cp_outparm = out_mapaddr;
cmd.cp_inmod = qpindx | flags;
cmd.cp_opcode = (uint16_t)opcode;
cmd.cp_opmod = (uint16_t)opmod;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if ((opcode != RTS2SQD_QP) && (opcode != TOERR_QP) &&
(opcode != TORST_QP)) {
hermon_mbox_free(state, &mbox_info);
}
return (status);
}
int
hermon_cmn_query_cmd_post(hermon_state_t *state, uint_t opcode, uint_t opmod,
uint_t queryindx, void *query, uint_t size, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t offset;
int status, i;
bzero(&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
cmd.cp_inparm = 0;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = queryindx;
cmd.cp_opcode = (uint16_t)opcode;
cmd.cp_opmod = (uint16_t)opmod;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto cmn_query_fail;
}
hermon_mbox_sync(mbox_info.mbi_out, 0, size, DDI_DMA_SYNC_FORCPU);
offset = (opcode == QUERY_QP) ? 1 : 0;
for (i = 0; i < (size >> 3); i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i + offset));
((uint64_t *)query)[i] = data;
}
cmn_query_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_cmn_ownership_cmd_post(hermon_state_t *state, uint_t opcode,
void *hwrsrc, uint_t size, uint_t hwrsrcindx, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data, in_mapaddr, out_mapaddr;
uint_t direction, opmod;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
if ((opcode == HW2SW_MPT) || (opcode == HW2SW_EQ) ||
(opcode == HW2SW_CQ) || (opcode == HW2SW_SRQ)) {
direction = HERMON_CMD_RSRC_HW2SW;
} else if ((opcode == SW2HW_MPT) || (opcode == SW2HW_EQ) ||
(opcode == SW2HW_CQ) || (opcode == SW2HW_SRQ)) {
direction = HERMON_CMD_RSRC_SW2HW;
} else {
return (HERMON_CMD_INVALID_STATUS);
}
if (direction == HERMON_CMD_RSRC_HW2SW) {
if (hwrsrc != NULL) {
mbox_info.mbi_alloc_flags = HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info,
sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
in_mapaddr = 0;
out_mapaddr = mbox_info.mbi_out->mb_mapaddr;
opmod = HERMON_CMD_DO_OUTMBOX;
} else {
in_mapaddr = 0;
out_mapaddr = 0;
opmod = HERMON_CMD_NO_OUTMBOX;
}
} else {
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)hwrsrc)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i),
data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size,
DDI_DMA_SYNC_FORDEV);
in_mapaddr = mbox_info.mbi_in->mb_mapaddr;
out_mapaddr = 0;
opmod = 0;
}
cmd.cp_inparm = in_mapaddr;
cmd.cp_outparm = out_mapaddr;
cmd.cp_inmod = hwrsrcindx;
cmd.cp_opcode = (uint16_t)opcode;
cmd.cp_opmod = (uint16_t)opmod;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto cmn_ownership_fail;
}
if (direction == HERMON_CMD_RSRC_HW2SW && hwrsrc != NULL) {
hermon_mbox_sync(mbox_info.mbi_out, 0, size,
DDI_DMA_SYNC_FORCPU);
for (i = 0; i < (size >> 3); i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i));
((uint64_t *)hwrsrc)[i] = data;
}
}
cmn_ownership_fail:
if (hwrsrc != NULL) {
hermon_mbox_free(state, &mbox_info);
}
return (status);
}
int
hermon_conf_special_qp_cmd_post(hermon_state_t *state, uint_t qpindx,
uint_t qptype, uint_t sleepflag, uint_t opmod)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = qpindx & 0x00FFFFF8;
cmd.cp_opcode = CONF_SPECIAL_QP;
cmd.cp_opmod = (uint16_t)opmod;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_get_heart_beat_rq_cmd_post(hermon_state_t *state, uint_t qpindx,
uint64_t *outparm)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = qpindx;
cmd.cp_opcode = HEART_BEAT_RQ;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
*outparm = cmd.cp_outparm;
return (status);
}
int
hermon_mgid_hash_cmd_post(hermon_state_t *state, uint64_t mgid_h,
uint64_t mgid_l, uint64_t *mgid_hash, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + 0), mgid_h);
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + 1), mgid_l);
hermon_mbox_sync(mbox_info.mbi_in, 0, HERMON_CMD_MGIDHASH_SZ,
DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = MGID_HASH;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
*mgid_hash = cmd.cp_outparm;
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_read_mgm_cmd_post(hermon_state_t *state, hermon_hw_mcg_t *mcg,
uint_t mcgindx, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint32_t data32;
uint_t size, hdrsz, qplistsz;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
cmd.cp_inparm = 0;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = mcgindx;
cmd.cp_opcode = READ_MGM;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
goto read_mgm_fail;
}
size = HERMON_MCGMEM_SZ(state);
hermon_mbox_sync(mbox_info.mbi_out, 0, size, DDI_DMA_SYNC_FORCPU);
hdrsz = sizeof (hermon_hw_mcg_t);
for (i = 0; i < (hdrsz >> 3); i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i));
((uint64_t *)mcg)[i] = data;
}
qplistsz = size - hdrsz;
for (i = 0; i < (qplistsz >> 2); i++) {
data32 = ddi_get32(mbox_info.mbi_out->mb_acchdl,
((uint32_t *)mbox_info.mbi_out->mb_addr + i + 8));
((uint32_t *)mcg)[i + 8] = data32;
}
read_mgm_fail:
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_write_mgm_cmd_post(hermon_state_t *state, hermon_hw_mcg_t *mcg,
uint_t mcgindx, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size, hdrsz, qplistsz;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = HERMON_MCGMEM_SZ(state);
hdrsz = sizeof (hermon_hw_mcg_t);
for (i = 0; i < (hdrsz >> 3); i++) {
data = ((uint64_t *)mcg)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
qplistsz = size - hdrsz;
for (i = 0; i < (qplistsz >> 2); i++) {
data = ((uint32_t *)mcg)[i + 8];
ddi_put32(mbox_info.mbi_in->mb_acchdl,
((uint32_t *)mbox_info.mbi_in->mb_addr + i + 8), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = mcgindx;
cmd.cp_opcode = WRITE_MGM;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int hermon_resize_srq_cmd_post(hermon_state_t *state, hermon_hw_srqc_t *srq,
uint_t srqnum, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_srqc_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)(void *)srq)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = srqnum;
cmd.cp_opcode = RESIZE_SRQ;
cmd.cp_opmod = 0;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_modify_mpt_cmd_post(hermon_state_t *state, hermon_hw_dmpt_t *mpt,
uint_t mptindx, uint_t flags, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_dmpt_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)mpt)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = mptindx;
cmd.cp_opcode = MODIFY_MPT;
cmd.cp_opmod = (uint16_t)flags;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_config_fc_cmd_post(hermon_state_t *state, void *cfginfo, int enable,
int selector, int n_ports, int portnum, uint_t sleepflag)
{
hermon_mbox_info_t mbox_info;
hermon_cmd_post_t cmd;
uint64_t data;
uint32_t portid;
uint_t size;
int status, i;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_INMBOX;
status = hermon_mbox_alloc(state, &mbox_info, sleepflag);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
if (selector == HERMON_HW_FC_CONF_BASIC) {
size = sizeof (hermon_hw_config_fc_basic_t);
for (i = 0; i < (size >> 3); i++) {
data = ((uint64_t *)cfginfo)[i];
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
} else {
ASSERT(selector == HERMON_HW_FC_CONF_NPORT);
size = n_ports * sizeof (uint32_t);
for (i = 0; i < (size >> 3); i++) {
portid = ((uint32_t *)cfginfo)[i * 2];
data = (uint64_t)portid << 32;
if (i * 2 < n_ports) {
portid = ((uint32_t *)cfginfo)[i * 2 + 1];
data |= portid;
}
ddi_put64(mbox_info.mbi_in->mb_acchdl,
((uint64_t *)mbox_info.mbi_in->mb_addr + i), data);
}
}
hermon_mbox_sync(mbox_info.mbi_in, 0, size, DDI_DMA_SYNC_FORDEV);
cmd.cp_inparm = mbox_info.mbi_in->mb_mapaddr;
cmd.cp_outparm = 0;
cmd.cp_inmod = (uint32_t)(selector | portnum);
cmd.cp_opcode = CONFIG_FC;
cmd.cp_opmod = (uint16_t)enable;
cmd.cp_flags = sleepflag;
status = hermon_cmd_post(state, &cmd);
hermon_mbox_free(state, &mbox_info);
return (status);
}
int
hermon_sense_port_post(hermon_state_t *state, uint_t portnum,
uint32_t *protocol)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = (uint32_t)portnum;
cmd.cp_opcode = SENSE_PORT;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status == HERMON_CMD_SUCCESS) *protocol = (uint32_t)cmd.cp_outparm;
return (status);
}
int
hermon_config_int_mod(hermon_state_t *state, uint_t min_delay, uint_t vector)
{
hermon_cmd_post_t cmd;
int status;
uint64_t inparm = 0;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
inparm = (((uint64_t)min_delay & 0xFFFF) << 48) ||
(((uint64_t)vector & 0xFFFF) << 32);
cmd.cp_inparm = inparm;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = CONFIG_INT_MOD;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_nop_post(hermon_state_t *state, uint_t interval, uint_t sleep)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = interval;
cmd.cp_opcode = CMD_NOP;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_SLEEP_NOSPIN;
if (sleep) cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_hw_health_check(hermon_state_t *state, int *health)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = HW_HEALTH_CHECK;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
*health = (int)cmd.cp_outparm;
return (status);
}
int
hermon_setdebug_post(hermon_state_t *state)
{
hermon_cmd_post_t cmd;
int status;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
cmd.cp_inparm = 0xFFFFFFFFFFFFFFFF;
cmd.cp_outparm = 0;
cmd.cp_inmod = 0;
cmd.cp_opcode = SET_DEBUG_MSG;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
return (status);
}
int
hermon_read_mtt_cmd_post(hermon_state_t *state, uint64_t mtt_addr,
hermon_hw_mtt_t *mtt)
{
hermon_cmd_post_t cmd;
hermon_mbox_info_t mbox_info;
int i, status;
uint_t size;
uint64_t data;
bzero((void *)&cmd, sizeof (hermon_cmd_post_t));
mbox_info.mbi_alloc_flags = HERMON_ALLOC_OUTMBOX;
status = hermon_mbox_alloc(state, &mbox_info, HERMON_CMD_SLEEP_NOSPIN);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
cmd.cp_inparm = mtt_addr;
cmd.cp_outparm = mbox_info.mbi_out->mb_mapaddr;
cmd.cp_inmod = 1;
cmd.cp_opcode = READ_MTT;
cmd.cp_opmod = 0;
cmd.cp_flags = HERMON_CMD_NOSLEEP_SPIN;
status = hermon_cmd_post(state, &cmd);
if (status != HERMON_CMD_SUCCESS) {
return (status);
}
size = sizeof (hermon_hw_mtt_t);
hermon_mbox_sync(mbox_info.mbi_out, 0, size, DDI_DMA_SYNC_FORCPU);
for (i = 0; i < (size >> 3); i++) {
data = ddi_get64(mbox_info.mbi_out->mb_acchdl,
((uint64_t *)mbox_info.mbi_out->mb_addr + i));
((uint64_t *)(void *)mtt)[i] = data;
}
hermon_mbox_free(state, &mbox_info);
return (status);
}