#ifndef _QL_INLINE_H_
#define _QL_INLINE_H_
#define QL8_SEMLOCK_TIMEOUT 1000
static __inline int
qla_sem_lock(qla_host_t *ha, uint32_t sem_reg, uint32_t id_reg, uint32_t id_val)
{
int count = QL8_SEMLOCK_TIMEOUT;
while (count) {
if ((READ_REG32(ha, sem_reg) & BIT_0))
break;
count--;
if (!count)
return(-1);
qla_mdelay(__func__, 10);
}
if (id_reg)
WRITE_REG32(ha, id_reg, id_val);
return(0);
}
static __inline void
qla_sem_unlock(qla_host_t *ha, uint32_t sem_reg)
{
READ_REG32(ha, sem_reg);
}
static __inline int
qla_get_ifq_snd_maxlen(qla_host_t *ha)
{
return(((NUM_TX_DESCRIPTORS * 4) - 1));
}
static __inline uint32_t
qla_get_optics(qla_host_t *ha)
{
uint32_t link_speed;
link_speed = READ_REG32(ha, Q8_LINK_SPEED_0);
if (ha->pci_func == 0)
link_speed = link_speed & 0xFF;
else
link_speed = (link_speed >> 8) & 0xFF;
switch (link_speed) {
case 0x1:
link_speed = IFM_100_FX;
break;
case 0x10:
link_speed = IFM_1000_SX;
break;
default:
if ((ha->hw.module_type == 0x4) ||
(ha->hw.module_type == 0x5) ||
(ha->hw.module_type == 0x6))
link_speed = (IFM_10G_TWINAX);
else
link_speed = (IFM_10G_LR | IFM_10G_SR);
break;
}
return(link_speed);
}
static __inline uint8_t *
qla_get_mac_addr(qla_host_t *ha)
{
return (ha->hw.mac_addr);
}
static __inline void
qla_set_hw_rcv_desc(qla_host_t *ha, uint32_t r_idx, uint32_t index,
uint32_t handle, bus_addr_t paddr, uint32_t buf_size)
{
volatile q80_recv_desc_t *rcv_desc;
rcv_desc = (q80_recv_desc_t *)ha->hw.dma_buf.rds_ring[r_idx].dma_b;
rcv_desc += index;
rcv_desc->handle = (uint16_t)handle;
rcv_desc->buf_size = buf_size;
rcv_desc->buf_addr = paddr;
return;
}
static __inline void
qla_init_hw_rcv_descriptors(qla_host_t *ha)
{
int i;
for (i = 0; i < ha->hw.num_rds_rings; i++)
bzero((void *)ha->hw.dma_buf.rds_ring[i].dma_b,
(sizeof(q80_recv_desc_t) * NUM_RX_DESCRIPTORS));
}
#define QLA_LOCK_DEFAULT_MS_TIMEOUT 3000
#ifndef QLA_LOCK_NO_SLEEP
#define QLA_LOCK_NO_SLEEP 0
#endif
static __inline int
qla_lock(qla_host_t *ha, const char *str, uint32_t timeout_ms,
uint32_t no_sleep)
{
int ret = -1;
while (1) {
mtx_lock(&ha->hw_lock);
if (ha->qla_detach_active || ha->offline) {
mtx_unlock(&ha->hw_lock);
break;
}
if (!ha->hw_lock_held) {
ha->hw_lock_held = 1;
ha->qla_lock = str;
ret = 0;
mtx_unlock(&ha->hw_lock);
break;
}
mtx_unlock(&ha->hw_lock);
if (--timeout_ms == 0) {
ha->hw_lock_failed++;
break;
} else {
if (no_sleep)
DELAY(1000);
else
qla_mdelay(__func__, 1);
}
}
return (ret);
}
static __inline void
qla_unlock(qla_host_t *ha, const char *str)
{
mtx_lock(&ha->hw_lock);
ha->hw_lock_held = 0;
ha->qla_unlock = str;
mtx_unlock(&ha->hw_lock);
return;
}
#endif