-
-void
-ionic_q_flush(struct ionic_queue *q)
-{
- writeq(IONIC_DBELL_QID(q->hw_index) | q->head_idx, q->db);
-}
-
-void
-ionic_q_post(struct ionic_queue *q, bool ring_doorbell, desc_cb cb,
- void *cb_arg)
-{
- struct ionic_desc_info *head = &q->info[q->head_idx];
-
- head->cb = cb;
- head->cb_arg = cb_arg;
-
- q->head_idx = (q->head_idx + 1) & (q->num_descs - 1);
-
- if (ring_doorbell)
- ionic_q_flush(q);
-}
-
-uint32_t
-ionic_q_space_avail(struct ionic_queue *q)
-{
- uint32_t avail = q->tail_idx;
-
- if (q->head_idx >= avail)
- avail += q->num_descs - q->head_idx - 1;
- else
- avail -= q->head_idx + 1;
-
- return avail;
-}
-
-bool
-ionic_q_has_space(struct ionic_queue *q, uint32_t want)
-{
- return ionic_q_space_avail(q) >= want;
-}
-
-void
-ionic_q_service(struct ionic_queue *q, uint32_t cq_desc_index,
- uint32_t stop_index, void *service_cb_arg)
-{
- struct ionic_desc_info *desc_info;
- uint32_t curr_q_tail_idx;
-
- do {
- desc_info = &q->info[q->tail_idx];
-
- if (desc_info->cb)
- desc_info->cb(q, q->tail_idx, cq_desc_index,
- desc_info->cb_arg, service_cb_arg);
-
- desc_info->cb = NULL;
- desc_info->cb_arg = NULL;
-
- curr_q_tail_idx = q->tail_idx;
- q->tail_idx = (q->tail_idx + 1) & (q->num_descs - 1);
-
- } while (curr_q_tail_idx != stop_index);
-}
-
-static void
-ionic_adminq_cb(struct ionic_queue *q,
- uint32_t q_desc_index, uint32_t cq_desc_index,
- void *cb_arg, void *service_cb_arg __rte_unused)
-{
- struct ionic_admin_ctx *ctx = cb_arg;
- struct ionic_admin_comp *cq_desc_base = q->bound_cq->base;
- struct ionic_admin_comp *cq_desc = &cq_desc_base[cq_desc_index];
-
- if (unlikely(cq_desc->comp_index != q_desc_index)) {
- IONIC_WARN_ON(cq_desc->comp_index != q_desc_index);
- return;
- }
-
- memcpy(&ctx->comp, cq_desc, sizeof(*cq_desc));
-
- ctx->pending_work = false; /* done */
-}
-
-/** ionic_adminq_post - Post an admin command.
- * @lif: Handle to lif.
- * @cmd_ctx: Api admin command context.
- *
- * Post the command to an admin queue in the ethernet driver. If this command
- * succeeds, then the command has been posted, but that does not indicate a
- * completion. If this command returns success, then the completion callback
- * will eventually be called.
- *
- * Return: zero or negative error status.
- */
-int
-ionic_adminq_post(struct ionic_lif *lif, struct ionic_admin_ctx *ctx)
-{
- struct ionic_queue *adminq = &lif->adminqcq->q;
- struct ionic_admin_cmd *q_desc_base = adminq->base;
- struct ionic_admin_cmd *q_desc;
- int err = 0;
-
- rte_spinlock_lock(&lif->adminq_lock);
-
- if (!ionic_q_has_space(adminq, 1)) {
- err = -ENOSPC;
- goto err_out;
- }
-
- q_desc = &q_desc_base[adminq->head_idx];
-
- memcpy(q_desc, &ctx->cmd, sizeof(ctx->cmd));
-
- ionic_q_post(adminq, true, ionic_adminq_cb, ctx);
-
-err_out:
- rte_spinlock_unlock(&lif->adminq_lock);
-
- return err;
-}