/** * crystalhd_dioq_find_and_fetch - Search the tag and Fetch element * @ioq: DIO queue instance * @tag: Tag to search for. * * Return: * element from the head.. * * Search TAG and remove the element. */ void *crystalhd_dioq_find_and_fetch(crystalhd_dioq_t *ioq, uint32_t tag) { unsigned long flags = 0; crystalhd_elem_t *tmp; crystalhd_elem_t *ret = NULL; void *data = NULL; if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG)) { dev_err(chddev(), "%s: Invalid arg\n", __func__); return data; } spin_lock_irqsave(&ioq->lock, flags); tmp = ioq->head; while (tmp != (crystalhd_elem_t *)&ioq->head) { if (tmp->tag == tag) { ret = tmp; tmp->flink->blink = tmp->blink; tmp->blink->flink = tmp->flink; ioq->count--; break; } tmp = tmp->flink; } spin_unlock_irqrestore(&ioq->lock, flags); if (ret) { data = ret->data; crystalhd_free_elem(ioq->adp, ret); } return data; }
/** * crystalhd_dioq_fetch - Fetch element from head. * @ioq: DIO queue instance * * Return: * data element from the head.. * * Remove an element from Queue. */ void *crystalhd_dioq_fetch(struct crystalhd_dioq *ioq) { unsigned long flags = 0; struct crystalhd_elem *tmp; struct crystalhd_elem *ret = NULL; void *data = NULL; if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG)) { dev_err(chddev(), "%s: Invalid arg\n", __func__); if(!ioq) dev_err(chddev(), "ioq not initialized\n"); else dev_err(chddev(), "ioq invalid signature\n"); return data; } spin_lock_irqsave(&ioq->lock, flags); tmp = ioq->head; if (tmp != (struct crystalhd_elem *)&ioq->head) { ret = tmp; tmp->flink->blink = tmp->blink; tmp->blink->flink = tmp->flink; ioq->count--; } spin_unlock_irqrestore(&ioq->lock, flags); if (ret) { data = ret->data; crystalhd_free_elem(ioq->adp, ret); } return data; }
/** * crystalhd_create_elem_pool - List element pool creation. * @adp: Adapter instance * @pool_size: Number of elements in the pool. * * Return: * 0 - success, <0 error * * Create general purpose list element pool to hold pending, * and active requests. */ int crystalhd_create_elem_pool(struct crystalhd_adp *adp, uint32_t pool_size) { uint32_t i; struct crystalhd_elem *temp; if (!adp || !pool_size) return -EINVAL; for (i = 0; i < pool_size; i++) { temp = kzalloc(sizeof(*temp), GFP_KERNEL); if (!temp) { dev_err(&adp->pdev->dev, "kzalloc failed\n"); return -ENOMEM; } crystalhd_free_elem(adp, temp); } dev_dbg(&adp->pdev->dev, "allocated %d elem\n", pool_size); return 0; }