1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
3 #include <linux/init.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
7 #include <uapi/linux/idxd.h>
11 static struct idxd_desc *__get_desc(struct idxd_wq *wq, int idx, int cpu)
13 struct idxd_desc *desc;
15 desc = wq->descs[idx];
16 memset(desc->hw, 0, sizeof(struct dsa_hw_desc));
17 memset(desc->completion, 0, sizeof(struct dsa_completion_record));
22 struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)
25 struct idxd_device *idxd = wq->idxd;
26 DEFINE_SBQ_WAIT(wait);
27 struct sbq_wait_state *ws;
28 struct sbitmap_queue *sbq;
30 if (idxd->state != IDXD_DEV_ENABLED)
34 idx = sbitmap_queue_get(sbq, &cpu);
36 if (optype == IDXD_OP_NONBLOCK)
37 return ERR_PTR(-EAGAIN);
39 return __get_desc(wq, idx, cpu);
44 sbitmap_prepare_to_wait(sbq, ws, &wait, TASK_INTERRUPTIBLE);
45 if (signal_pending_state(TASK_INTERRUPTIBLE, current))
47 idx = sbitmap_queue_get(sbq, &cpu);
53 sbitmap_finish_wait(sbq, ws, &wait);
55 return ERR_PTR(-EAGAIN);
57 return __get_desc(wq, idx, cpu);
60 void idxd_free_desc(struct idxd_wq *wq, struct idxd_desc *desc)
65 sbitmap_queue_clear(&wq->sbq, desc->id, cpu);
68 int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
70 struct idxd_device *idxd = wq->idxd;
71 int vec = desc->hw->int_handle;
74 if (idxd->state != IDXD_DEV_ENABLED)
79 * The wmb() flushes writes to coherent DMA data before possibly
80 * triggering a DMA read. The wmb() is necessary even on UP because
81 * the recipient is a device.
84 iosubmit_cmds512(portal, desc->hw, 1);
87 * Pending the descriptor to the lockless list for the irq_entry
88 * that we designated the descriptor to.
90 if (desc->hw->flags & IDXD_OP_FLAG_RCI)
91 llist_add(&desc->llnode,
92 &idxd->irq_entries[vec].pending_llist);