#include <oce_impl.h>
uint16_t
oce_drain_mq_cq(void *arg)
{
struct oce_mq_cqe *cqe = NULL;
uint16_t num_cqe = 0;
link_state_t link_status;
struct oce_async_cqe_link_state *acqe;
struct oce_mq *mq;
struct oce_cq *cq;
struct oce_dev *dev;
mq = (struct oce_mq *)arg;
cq = mq->cq;
dev = mq->parent;
mutex_enter(&mq->lock);
cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe);
while (cqe->u0.dw[3]) {
DW_SWAP(u32ptr(cqe), sizeof (struct oce_mq_cqe));
if (cqe->u0.s.async_event) {
acqe = (struct oce_async_cqe_link_state *)cqe;
if (acqe->u0.s.event_code ==
ASYNC_EVENT_CODE_LINK_STATE) {
link_status = ((acqe->u0.s.link_status &
~ASYNC_EVENT_LOGICAL) ==
ASYNC_EVENT_LINK_UP) ?
LINK_STATE_UP: LINK_STATE_DOWN;
mac_link_update(dev->mac_handle, link_status);
dev->link_status = link_status;
dev->link_speed = -1;
}
}
cqe->u0.dw[3] = 0;
RING_GET(cq->ring, 1);
cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe);
num_cqe++;
}
mutex_exit(&mq->lock);
oce_arm_cq(dev, cq->cq_id, num_cqe, B_TRUE);
return (num_cqe);
}
int
oce_start_mq(struct oce_mq *mq)
{
oce_arm_cq(mq->parent, mq->cq->cq_id, 0, B_TRUE);
return (0);
}
void
oce_clean_mq(struct oce_mq *mq)
{
struct oce_cq *cq;
struct oce_dev *dev;
uint16_t num_cqe = 0;
struct oce_mq_cqe *cqe = NULL;
cq = mq->cq;
dev = mq->parent;
cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe);
while (cqe->u0.dw[3]) {
DW_SWAP(u32ptr(cqe), sizeof (struct oce_mq_cqe));
cqe->u0.dw[3] = 0;
RING_GET(cq->ring, 1);
cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe);
num_cqe++;
}
if (num_cqe)
oce_arm_cq(dev, cq->cq_id, num_cqe, B_FALSE);
oce_drain_eq(mq->cq->eq);
}