Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * Wireless Host Controller (WHC) asynchronous schedule management.
  3 *
  4 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License version
  8 * 2 as published by the Free Software Foundation.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17 */
 18#include <linux/kernel.h>
 19#include <linux/gfp.h>
 20#include <linux/dma-mapping.h>
 21#include <linux/uwb/umc.h>
 22#include <linux/usb.h>
 23
 24#include "../../wusbcore/wusbhc.h"
 25
 26#include "whcd.h"
 27
 28static void qset_get_next_prev(struct whc *whc, struct whc_qset *qset,
 29			       struct whc_qset **next, struct whc_qset **prev)
 30{
 31	struct list_head *n, *p;
 32
 33	BUG_ON(list_empty(&whc->async_list));
 34
 35	n = qset->list_node.next;
 36	if (n == &whc->async_list)
 37		n = n->next;
 38	p = qset->list_node.prev;
 39	if (p == &whc->async_list)
 40		p = p->prev;
 41
 42	*next = container_of(n, struct whc_qset, list_node);
 43	*prev = container_of(p, struct whc_qset, list_node);
 44
 45}
 46
 47static void asl_qset_insert_begin(struct whc *whc, struct whc_qset *qset)
 48{
 49	list_move(&qset->list_node, &whc->async_list);
 50	qset->in_sw_list = true;
 51}
 52
 53static void asl_qset_insert(struct whc *whc, struct whc_qset *qset)
 54{
 55	struct whc_qset *next, *prev;
 56
 57	qset_clear(whc, qset);
 58
 59	/* Link into ASL. */
 60	qset_get_next_prev(whc, qset, &next, &prev);
 61	whc_qset_set_link_ptr(&qset->qh.link, next->qset_dma);
 62	whc_qset_set_link_ptr(&prev->qh.link, qset->qset_dma);
 63	qset->in_hw_list = true;
 64}
 65
 66static void asl_qset_remove(struct whc *whc, struct whc_qset *qset)
 67{
 68	struct whc_qset *prev, *next;
 69
 70	qset_get_next_prev(whc, qset, &next, &prev);
 71
 72	list_move(&qset->list_node, &whc->async_removed_list);
 73	qset->in_sw_list = false;
 74
 75	/*
 76	 * No more qsets in the ASL?  The caller must stop the ASL as
 77	 * it's no longer valid.
 78	 */
 79	if (list_empty(&whc->async_list))
 80		return;
 81
 82	/* Remove from ASL. */
 83	whc_qset_set_link_ptr(&prev->qh.link, next->qset_dma);
 84	qset->in_hw_list = false;
 85}
 86
 87/**
 88 * process_qset - process any recently inactivated or halted qTDs in a
 89 * qset.
 90 *
 91 * After inactive qTDs are removed, new qTDs can be added if the
 92 * urb queue still contains URBs.
 93 *
 94 * Returns any additional WUSBCMD bits for the ASL sync command (i.e.,
 95 * WUSBCMD_ASYNC_QSET_RM if a halted qset was removed).
 96 */
 97static uint32_t process_qset(struct whc *whc, struct whc_qset *qset)
 98{
 99	enum whc_update update = 0;
100	uint32_t status = 0;
101
102	while (qset->ntds) {
103		struct whc_qtd *td;
104		int t;
105
106		t = qset->td_start;
107		td = &qset->qtd[qset->td_start];
108		status = le32_to_cpu(td->status);
109
110		/*
111		 * Nothing to do with a still active qTD.
112		 */
113		if (status & QTD_STS_ACTIVE)
114			break;
115
116		if (status & QTD_STS_HALTED) {
117			/* Ug, an error. */
118			process_halted_qtd(whc, qset, td);
119			/* A halted qTD always triggers an update
120			   because the qset was either removed or
121			   reactivated. */
122			update |= WHC_UPDATE_UPDATED;
123			goto done;
124		}
125
126		/* Mmm, a completed qTD. */
127		process_inactive_qtd(whc, qset, td);
128	}
129
130	if (!qset->remove)
131		update |= qset_add_qtds(whc, qset);
132
133done:
134	/*
135	 * Remove this qset from the ASL if requested, but only if has
136	 * no qTDs.
137	 */
138	if (qset->remove && qset->ntds == 0) {
139		asl_qset_remove(whc, qset);
140		update |= WHC_UPDATE_REMOVED;
141	}
142	return update;
143}
144
145void asl_start(struct whc *whc)
146{
147	struct whc_qset *qset;
148
149	qset = list_first_entry(&whc->async_list, struct whc_qset, list_node);
150
151	le_writeq(qset->qset_dma | QH_LINK_NTDS(8), whc->base + WUSBASYNCLISTADDR);
152
153	whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, WUSBCMD_ASYNC_EN);
154	whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
155		      WUSBSTS_ASYNC_SCHED, WUSBSTS_ASYNC_SCHED,
156		      1000, "start ASL");
157}
158
159void asl_stop(struct whc *whc)
160{
161	whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, 0);
162	whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
163		      WUSBSTS_ASYNC_SCHED, 0,
164		      1000, "stop ASL");
165}
166
167/**
168 * asl_update - request an ASL update and wait for the hardware to be synced
169 * @whc: the WHCI HC
170 * @wusbcmd: WUSBCMD value to start the update.
171 *
172 * If the WUSB HC is inactive (i.e., the ASL is stopped) then the
173 * update must be skipped as the hardware may not respond to update
174 * requests.
175 */
176void asl_update(struct whc *whc, uint32_t wusbcmd)
177{
178	struct wusbhc *wusbhc = &whc->wusbhc;
179	long t;
180
181	mutex_lock(&wusbhc->mutex);
182	if (wusbhc->active) {
183		whc_write_wusbcmd(whc, wusbcmd, wusbcmd);
184		t = wait_event_timeout(
185			whc->async_list_wq,
186			(le_readl(whc->base + WUSBCMD) & WUSBCMD_ASYNC_UPDATED) == 0,
187			msecs_to_jiffies(1000));
188		if (t == 0)
189			whc_hw_error(whc, "ASL update timeout");
190	}
191	mutex_unlock(&wusbhc->mutex);
192}
193
194/**
195 * scan_async_work - scan the ASL for qsets to process.
196 *
197 * Process each qset in the ASL in turn and then signal the WHC that
198 * the ASL has been updated.
199 *
200 * Then start, stop or update the asynchronous schedule as required.
201 */
202void scan_async_work(struct work_struct *work)
203{
204	struct whc *whc = container_of(work, struct whc, async_work);
205	struct whc_qset *qset, *t;
206	enum whc_update update = 0;
207
208	spin_lock_irq(&whc->lock);
209
210	/*
211	 * Transerve the software list backwards so new qsets can be
212	 * safely inserted into the ASL without making it non-circular.
213	 */
214	list_for_each_entry_safe_reverse(qset, t, &whc->async_list, list_node) {
215		if (!qset->in_hw_list) {
216			asl_qset_insert(whc, qset);
217			update |= WHC_UPDATE_ADDED;
218		}
219
220		update |= process_qset(whc, qset);
221	}
222
223	spin_unlock_irq(&whc->lock);
224
225	if (update) {
226		uint32_t wusbcmd = WUSBCMD_ASYNC_UPDATED | WUSBCMD_ASYNC_SYNCED_DB;
227		if (update & WHC_UPDATE_REMOVED)
228			wusbcmd |= WUSBCMD_ASYNC_QSET_RM;
229		asl_update(whc, wusbcmd);
230	}
231
232	/*
233	 * Now that the ASL is updated, complete the removal of any
234	 * removed qsets.
235	 *
236	 * If the qset was to be reset, do so and reinsert it into the
237	 * ASL if it has pending transfers.
238	 */
239	spin_lock_irq(&whc->lock);
240
241	list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) {
242		qset_remove_complete(whc, qset);
243		if (qset->reset) {
244			qset_reset(whc, qset);
245			if (!list_empty(&qset->stds)) {
246				asl_qset_insert_begin(whc, qset);
247				queue_work(whc->workqueue, &whc->async_work);
248			}
249		}
250	}
251
252	spin_unlock_irq(&whc->lock);
253}
254
255/**
256 * asl_urb_enqueue - queue an URB onto the asynchronous list (ASL).
257 * @whc: the WHCI host controller
258 * @urb: the URB to enqueue
259 * @mem_flags: flags for any memory allocations
260 *
261 * The qset for the endpoint is obtained and the urb queued on to it.
262 *
263 * Work is scheduled to update the hardware's view of the ASL.
264 */
265int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags)
266{
267	struct whc_qset *qset;
268	int err;
269	unsigned long flags;
270
271	spin_lock_irqsave(&whc->lock, flags);
272
273	err = usb_hcd_link_urb_to_ep(&whc->wusbhc.usb_hcd, urb);
274	if (err < 0) {
275		spin_unlock_irqrestore(&whc->lock, flags);
276		return err;
277	}
278
279	qset = get_qset(whc, urb, GFP_ATOMIC);
280	if (qset == NULL)
281		err = -ENOMEM;
282	else
283		err = qset_add_urb(whc, qset, urb, GFP_ATOMIC);
284	if (!err) {
285		if (!qset->in_sw_list && !qset->remove)
286			asl_qset_insert_begin(whc, qset);
287	} else
288		usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb);
289
290	spin_unlock_irqrestore(&whc->lock, flags);
291
292	if (!err)
293		queue_work(whc->workqueue, &whc->async_work);
294
295	return err;
296}
297
298/**
299 * asl_urb_dequeue - remove an URB (qset) from the async list.
300 * @whc: the WHCI host controller
301 * @urb: the URB to dequeue
302 * @status: the current status of the URB
303 *
304 * URBs that do yet have qTDs can simply be removed from the software
305 * queue, otherwise the qset must be removed from the ASL so the qTDs
306 * can be removed.
307 */
308int asl_urb_dequeue(struct whc *whc, struct urb *urb, int status)
309{
310	struct whc_urb *wurb = urb->hcpriv;
311	struct whc_qset *qset = wurb->qset;
312	struct whc_std *std, *t;
313	bool has_qtd = false;
314	int ret;
315	unsigned long flags;
316
317	spin_lock_irqsave(&whc->lock, flags);
318
319	ret = usb_hcd_check_unlink_urb(&whc->wusbhc.usb_hcd, urb, status);
320	if (ret < 0)
321		goto out;
322
323	list_for_each_entry_safe(std, t, &qset->stds, list_node) {
324		if (std->urb == urb) {
325			if (std->qtd)
326				has_qtd = true;
327			qset_free_std(whc, std);
328		} else
329			std->qtd = NULL; /* so this std is re-added when the qset is */
330	}
331
332	if (has_qtd) {
333		asl_qset_remove(whc, qset);
334		wurb->status = status;
335		wurb->is_async = true;
336		queue_work(whc->workqueue, &wurb->dequeue_work);
337	} else
338		qset_remove_urb(whc, qset, urb, status);
339out:
340	spin_unlock_irqrestore(&whc->lock, flags);
341
342	return ret;
343}
344
345/**
346 * asl_qset_delete - delete a qset from the ASL
347 */
348void asl_qset_delete(struct whc *whc, struct whc_qset *qset)
349{
350	qset->remove = 1;
351	queue_work(whc->workqueue, &whc->async_work);
352	qset_delete(whc, qset);
353}
354
355/**
356 * asl_init - initialize the asynchronous schedule list
357 *
358 * A dummy qset with no qTDs is added to the ASL to simplify removing
359 * qsets (no need to stop the ASL when the last qset is removed).
360 */
361int asl_init(struct whc *whc)
362{
363	struct whc_qset *qset;
364
365	qset = qset_alloc(whc, GFP_KERNEL);
366	if (qset == NULL)
367		return -ENOMEM;
368
369	asl_qset_insert_begin(whc, qset);
370	asl_qset_insert(whc, qset);
371
372	return 0;
373}
374
375/**
376 * asl_clean_up - free ASL resources
377 *
378 * The ASL is stopped and empty except for the dummy qset.
379 */
380void asl_clean_up(struct whc *whc)
381{
382	struct whc_qset *qset;
383
384	if (!list_empty(&whc->async_list)) {
385		qset = list_first_entry(&whc->async_list, struct whc_qset, list_node);
386		list_del(&qset->list_node);
387		qset_free(whc, qset);
388	}
389}
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Wireless Host Controller (WHC) asynchronous schedule management.
  4 *
  5 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7#include <linux/kernel.h>
  8#include <linux/gfp.h>
  9#include <linux/dma-mapping.h>
 10#include <linux/uwb/umc.h>
 11#include <linux/usb.h>
 12
 13#include "../../wusbcore/wusbhc.h"
 14
 15#include "whcd.h"
 16
 17static void qset_get_next_prev(struct whc *whc, struct whc_qset *qset,
 18			       struct whc_qset **next, struct whc_qset **prev)
 19{
 20	struct list_head *n, *p;
 21
 22	BUG_ON(list_empty(&whc->async_list));
 23
 24	n = qset->list_node.next;
 25	if (n == &whc->async_list)
 26		n = n->next;
 27	p = qset->list_node.prev;
 28	if (p == &whc->async_list)
 29		p = p->prev;
 30
 31	*next = container_of(n, struct whc_qset, list_node);
 32	*prev = container_of(p, struct whc_qset, list_node);
 33
 34}
 35
 36static void asl_qset_insert_begin(struct whc *whc, struct whc_qset *qset)
 37{
 38	list_move(&qset->list_node, &whc->async_list);
 39	qset->in_sw_list = true;
 40}
 41
 42static void asl_qset_insert(struct whc *whc, struct whc_qset *qset)
 43{
 44	struct whc_qset *next, *prev;
 45
 46	qset_clear(whc, qset);
 47
 48	/* Link into ASL. */
 49	qset_get_next_prev(whc, qset, &next, &prev);
 50	whc_qset_set_link_ptr(&qset->qh.link, next->qset_dma);
 51	whc_qset_set_link_ptr(&prev->qh.link, qset->qset_dma);
 52	qset->in_hw_list = true;
 53}
 54
 55static void asl_qset_remove(struct whc *whc, struct whc_qset *qset)
 56{
 57	struct whc_qset *prev, *next;
 58
 59	qset_get_next_prev(whc, qset, &next, &prev);
 60
 61	list_move(&qset->list_node, &whc->async_removed_list);
 62	qset->in_sw_list = false;
 63
 64	/*
 65	 * No more qsets in the ASL?  The caller must stop the ASL as
 66	 * it's no longer valid.
 67	 */
 68	if (list_empty(&whc->async_list))
 69		return;
 70
 71	/* Remove from ASL. */
 72	whc_qset_set_link_ptr(&prev->qh.link, next->qset_dma);
 73	qset->in_hw_list = false;
 74}
 75
 76/**
 77 * process_qset - process any recently inactivated or halted qTDs in a
 78 * qset.
 79 *
 80 * After inactive qTDs are removed, new qTDs can be added if the
 81 * urb queue still contains URBs.
 82 *
 83 * Returns any additional WUSBCMD bits for the ASL sync command (i.e.,
 84 * WUSBCMD_ASYNC_QSET_RM if a halted qset was removed).
 85 */
 86static uint32_t process_qset(struct whc *whc, struct whc_qset *qset)
 87{
 88	enum whc_update update = 0;
 89	uint32_t status = 0;
 90
 91	while (qset->ntds) {
 92		struct whc_qtd *td;
 
 93
 
 94		td = &qset->qtd[qset->td_start];
 95		status = le32_to_cpu(td->status);
 96
 97		/*
 98		 * Nothing to do with a still active qTD.
 99		 */
100		if (status & QTD_STS_ACTIVE)
101			break;
102
103		if (status & QTD_STS_HALTED) {
104			/* Ug, an error. */
105			process_halted_qtd(whc, qset, td);
106			/* A halted qTD always triggers an update
107			   because the qset was either removed or
108			   reactivated. */
109			update |= WHC_UPDATE_UPDATED;
110			goto done;
111		}
112
113		/* Mmm, a completed qTD. */
114		process_inactive_qtd(whc, qset, td);
115	}
116
117	if (!qset->remove)
118		update |= qset_add_qtds(whc, qset);
119
120done:
121	/*
122	 * Remove this qset from the ASL if requested, but only if has
123	 * no qTDs.
124	 */
125	if (qset->remove && qset->ntds == 0) {
126		asl_qset_remove(whc, qset);
127		update |= WHC_UPDATE_REMOVED;
128	}
129	return update;
130}
131
132void asl_start(struct whc *whc)
133{
134	struct whc_qset *qset;
135
136	qset = list_first_entry(&whc->async_list, struct whc_qset, list_node);
137
138	le_writeq(qset->qset_dma | QH_LINK_NTDS(8), whc->base + WUSBASYNCLISTADDR);
139
140	whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, WUSBCMD_ASYNC_EN);
141	whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
142		      WUSBSTS_ASYNC_SCHED, WUSBSTS_ASYNC_SCHED,
143		      1000, "start ASL");
144}
145
146void asl_stop(struct whc *whc)
147{
148	whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, 0);
149	whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
150		      WUSBSTS_ASYNC_SCHED, 0,
151		      1000, "stop ASL");
152}
153
154/**
155 * asl_update - request an ASL update and wait for the hardware to be synced
156 * @whc: the WHCI HC
157 * @wusbcmd: WUSBCMD value to start the update.
158 *
159 * If the WUSB HC is inactive (i.e., the ASL is stopped) then the
160 * update must be skipped as the hardware may not respond to update
161 * requests.
162 */
163void asl_update(struct whc *whc, uint32_t wusbcmd)
164{
165	struct wusbhc *wusbhc = &whc->wusbhc;
166	long t;
167
168	mutex_lock(&wusbhc->mutex);
169	if (wusbhc->active) {
170		whc_write_wusbcmd(whc, wusbcmd, wusbcmd);
171		t = wait_event_timeout(
172			whc->async_list_wq,
173			(le_readl(whc->base + WUSBCMD) & WUSBCMD_ASYNC_UPDATED) == 0,
174			msecs_to_jiffies(1000));
175		if (t == 0)
176			whc_hw_error(whc, "ASL update timeout");
177	}
178	mutex_unlock(&wusbhc->mutex);
179}
180
181/**
182 * scan_async_work - scan the ASL for qsets to process.
183 *
184 * Process each qset in the ASL in turn and then signal the WHC that
185 * the ASL has been updated.
186 *
187 * Then start, stop or update the asynchronous schedule as required.
188 */
189void scan_async_work(struct work_struct *work)
190{
191	struct whc *whc = container_of(work, struct whc, async_work);
192	struct whc_qset *qset, *t;
193	enum whc_update update = 0;
194
195	spin_lock_irq(&whc->lock);
196
197	/*
198	 * Transerve the software list backwards so new qsets can be
199	 * safely inserted into the ASL without making it non-circular.
200	 */
201	list_for_each_entry_safe_reverse(qset, t, &whc->async_list, list_node) {
202		if (!qset->in_hw_list) {
203			asl_qset_insert(whc, qset);
204			update |= WHC_UPDATE_ADDED;
205		}
206
207		update |= process_qset(whc, qset);
208	}
209
210	spin_unlock_irq(&whc->lock);
211
212	if (update) {
213		uint32_t wusbcmd = WUSBCMD_ASYNC_UPDATED | WUSBCMD_ASYNC_SYNCED_DB;
214		if (update & WHC_UPDATE_REMOVED)
215			wusbcmd |= WUSBCMD_ASYNC_QSET_RM;
216		asl_update(whc, wusbcmd);
217	}
218
219	/*
220	 * Now that the ASL is updated, complete the removal of any
221	 * removed qsets.
222	 *
223	 * If the qset was to be reset, do so and reinsert it into the
224	 * ASL if it has pending transfers.
225	 */
226	spin_lock_irq(&whc->lock);
227
228	list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) {
229		qset_remove_complete(whc, qset);
230		if (qset->reset) {
231			qset_reset(whc, qset);
232			if (!list_empty(&qset->stds)) {
233				asl_qset_insert_begin(whc, qset);
234				queue_work(whc->workqueue, &whc->async_work);
235			}
236		}
237	}
238
239	spin_unlock_irq(&whc->lock);
240}
241
242/**
243 * asl_urb_enqueue - queue an URB onto the asynchronous list (ASL).
244 * @whc: the WHCI host controller
245 * @urb: the URB to enqueue
246 * @mem_flags: flags for any memory allocations
247 *
248 * The qset for the endpoint is obtained and the urb queued on to it.
249 *
250 * Work is scheduled to update the hardware's view of the ASL.
251 */
252int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags)
253{
254	struct whc_qset *qset;
255	int err;
256	unsigned long flags;
257
258	spin_lock_irqsave(&whc->lock, flags);
259
260	err = usb_hcd_link_urb_to_ep(&whc->wusbhc.usb_hcd, urb);
261	if (err < 0) {
262		spin_unlock_irqrestore(&whc->lock, flags);
263		return err;
264	}
265
266	qset = get_qset(whc, urb, GFP_ATOMIC);
267	if (qset == NULL)
268		err = -ENOMEM;
269	else
270		err = qset_add_urb(whc, qset, urb, GFP_ATOMIC);
271	if (!err) {
272		if (!qset->in_sw_list && !qset->remove)
273			asl_qset_insert_begin(whc, qset);
274	} else
275		usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb);
276
277	spin_unlock_irqrestore(&whc->lock, flags);
278
279	if (!err)
280		queue_work(whc->workqueue, &whc->async_work);
281
282	return err;
283}
284
285/**
286 * asl_urb_dequeue - remove an URB (qset) from the async list.
287 * @whc: the WHCI host controller
288 * @urb: the URB to dequeue
289 * @status: the current status of the URB
290 *
291 * URBs that do yet have qTDs can simply be removed from the software
292 * queue, otherwise the qset must be removed from the ASL so the qTDs
293 * can be removed.
294 */
295int asl_urb_dequeue(struct whc *whc, struct urb *urb, int status)
296{
297	struct whc_urb *wurb = urb->hcpriv;
298	struct whc_qset *qset = wurb->qset;
299	struct whc_std *std, *t;
300	bool has_qtd = false;
301	int ret;
302	unsigned long flags;
303
304	spin_lock_irqsave(&whc->lock, flags);
305
306	ret = usb_hcd_check_unlink_urb(&whc->wusbhc.usb_hcd, urb, status);
307	if (ret < 0)
308		goto out;
309
310	list_for_each_entry_safe(std, t, &qset->stds, list_node) {
311		if (std->urb == urb) {
312			if (std->qtd)
313				has_qtd = true;
314			qset_free_std(whc, std);
315		} else
316			std->qtd = NULL; /* so this std is re-added when the qset is */
317	}
318
319	if (has_qtd) {
320		asl_qset_remove(whc, qset);
321		wurb->status = status;
322		wurb->is_async = true;
323		queue_work(whc->workqueue, &wurb->dequeue_work);
324	} else
325		qset_remove_urb(whc, qset, urb, status);
326out:
327	spin_unlock_irqrestore(&whc->lock, flags);
328
329	return ret;
330}
331
332/**
333 * asl_qset_delete - delete a qset from the ASL
334 */
335void asl_qset_delete(struct whc *whc, struct whc_qset *qset)
336{
337	qset->remove = 1;
338	queue_work(whc->workqueue, &whc->async_work);
339	qset_delete(whc, qset);
340}
341
342/**
343 * asl_init - initialize the asynchronous schedule list
344 *
345 * A dummy qset with no qTDs is added to the ASL to simplify removing
346 * qsets (no need to stop the ASL when the last qset is removed).
347 */
348int asl_init(struct whc *whc)
349{
350	struct whc_qset *qset;
351
352	qset = qset_alloc(whc, GFP_KERNEL);
353	if (qset == NULL)
354		return -ENOMEM;
355
356	asl_qset_insert_begin(whc, qset);
357	asl_qset_insert(whc, qset);
358
359	return 0;
360}
361
362/**
363 * asl_clean_up - free ASL resources
364 *
365 * The ASL is stopped and empty except for the dummy qset.
366 */
367void asl_clean_up(struct whc *whc)
368{
369	struct whc_qset *qset;
370
371	if (!list_empty(&whc->async_list)) {
372		qset = list_first_entry(&whc->async_list, struct whc_qset, list_node);
373		list_del(&qset->list_node);
374		qset_free(whc, qset);
375	}
376}