5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
10 * Copyright(c) 2015 Intel Corporation.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
23 * Copyright(c) 2015 Intel Corporation.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
29 * - Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * - Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
35 * - Neither the name of Intel Corporation nor the names of its
36 * contributors may be used to endorse or promote products derived
37 * from this software without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <linux/list.h>
54 #include <linux/workqueue.h>
55 #include <linux/sched.h>
58 * typedef (*restart_t)() - restart callback
59 * @work: pointer to work structure
61 typedef void (*restart_t)(struct work_struct *work);
66 * struct iowait - linkage for delayed progress/waiting
67 * @list: used to add/insert into QP/PQ wait lists
68 * @tx_head: overflow list of sdma_txreq's
69 * @sleep: no space callback
70 * @wakeup: space callback
71 * @iowork: workqueue overhead
72 * @wait_dma: wait for sdma_busy == 0
73 * @sdma_busy: # of packets in flight
74 * @count: total number of descriptors in tx_head'ed list
75 * @tx_limit: limit for overflow queuing
76 * @tx_count: number of tx entry's in tx_head'ed list
78 * This is to be embedded in user's state structure
81 * The sleep and wakeup members are a
82 * bit misnamed. They do not strictly
83 * speaking sleep or wake up, but they
84 * are callbacks for the ULP to implement
85 * what ever queuing/dequeuing of
86 * the embedded iowait and its containing struct
87 * when a resource shortage like SDMA ring space is seen.
89 * Both potentially have locks help
90 * so sleeping is not allowed.
92 * The wait_dma member along with the iow
96 struct list_head list;
97 struct list_head tx_head;
99 struct sdma_engine *sde,
101 struct sdma_txreq *tx,
103 void (*wakeup)(struct iowait *wait, int reason);
104 struct work_struct iowork;
105 wait_queue_head_t wait_dma;
112 #define SDMA_AVAIL_REASON 0
115 * iowait_init() - initialize wait structure
116 * @wait: wait struct to initialize
117 * @tx_limit: limit for overflow queuing
118 * @func: restart function for workqueue
119 * @sleep: sleep function for no space
120 * @wakeup: wakeup function for no space
122 * This function initializes the iowait
123 * structure embedded in the QP or PQ.
127 static inline void iowait_init(
130 void (*func)(struct work_struct *work),
132 struct sdma_engine *sde,
134 struct sdma_txreq *tx,
136 void (*wakeup)(struct iowait *wait, int reason))
139 INIT_LIST_HEAD(&wait->list);
140 INIT_LIST_HEAD(&wait->tx_head);
141 INIT_WORK(&wait->iowork, func);
142 init_waitqueue_head(&wait->wait_dma);
143 atomic_set(&wait->sdma_busy, 0);
144 wait->tx_limit = tx_limit;
146 wait->wakeup = wakeup;
150 * iowait_schedule() - initialize wait structure
151 * @wait: wait struct to schedule
152 * @wq: workqueue for schedule
154 static inline void iowait_schedule(
156 struct workqueue_struct *wq)
158 queue_work(wq, &wait->iowork);
162 * iowait_sdma_drain() - wait for DMAs to drain
164 * @wait: iowait structure
166 * This will delay until the iowait sdmas have
169 static inline void iowait_sdma_drain(struct iowait *wait)
171 wait_event(wait->wait_dma, !atomic_read(&wait->sdma_busy));
175 * iowait_drain_wakeup() - trigger iowait_drain() waiter
177 * @wait: iowait structure
179 * This will trigger any waiters.
181 static inline void iowait_drain_wakeup(struct iowait *wait)
183 wake_up(&wait->wait_dma);