aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/ioat/dma_v2.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-09-08 15:01:49 -0400
committerDan Williams <dan.j.williams@intel.com>2009-09-08 20:30:24 -0400
commit09c8a5b85e5f1e74a19bdd7c85547429d51df1cd (patch)
tree9bb255d9f596ab062996de49032875e8b9253971 /drivers/dma/ioat/dma_v2.c
parentad643f54c8514998333bc6c7b201fda2267496be (diff)
ioat: switch watchdog and reset handler from workqueue to timer
In order to support dynamic resizing of the descriptor ring or polling for a descriptor in the presence of a hung channel the reset handler needs to make progress while in a non-preemptible context. The current workqueue implementation precludes polling channel reset completion under spin_lock(). This conversion also allows us to return to opportunistic cleanup in the ioat2 case as the timer implementation guarantees at least one cleanup after every descriptor is submitted. This means the worst case completion latency becomes the timer frequency (for exceptional circumstances), but with the benefit of avoiding busy waiting when the lock is contended. Signed-off-by: Maciej Sosnowski <maciej.sosnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/dma/ioat/dma_v2.c')
-rw-r--r--drivers/dma/ioat/dma_v2.c321
1 files changed, 138 insertions, 183 deletions
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 1aa2974e7a9..72e59a0d0f2 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -49,7 +49,7 @@ static void __ioat2_issue_pending(struct ioat2_dma_chan *ioat)
49 void * __iomem reg_base = ioat->base.reg_base; 49 void * __iomem reg_base = ioat->base.reg_base;
50 50
51 ioat->pending = 0; 51 ioat->pending = 0;
52 ioat->dmacount += ioat2_ring_pending(ioat); 52 ioat->dmacount += ioat2_ring_pending(ioat);;
53 ioat->issued = ioat->head; 53 ioat->issued = ioat->head;
54 /* make descriptor updates globally visible before notifying channel */ 54 /* make descriptor updates globally visible before notifying channel */
55 wmb(); 55 wmb();
@@ -92,7 +92,6 @@ static void ioat2_update_pending(struct ioat2_dma_chan *ioat)
92 92
93static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat) 93static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
94{ 94{
95 void __iomem *reg_base = ioat->base.reg_base;
96 struct ioat_ring_ent *desc; 95 struct ioat_ring_ent *desc;
97 struct ioat_dma_descriptor *hw; 96 struct ioat_dma_descriptor *hw;
98 int idx; 97 int idx;
@@ -118,10 +117,7 @@ static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
118 hw->src_addr = 0; 117 hw->src_addr = 0;
119 hw->dst_addr = 0; 118 hw->dst_addr = 0;
120 async_tx_ack(&desc->txd); 119 async_tx_ack(&desc->txd);
121 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF, 120 ioat2_set_chainaddr(ioat, desc->txd.phys);
122 reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
123 writel(((u64) desc->txd.phys) >> 32,
124 reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
125 dump_desc_dbg(ioat, desc); 121 dump_desc_dbg(ioat, desc);
126 __ioat2_issue_pending(ioat); 122 __ioat2_issue_pending(ioat);
127} 123}
@@ -133,177 +129,14 @@ static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
133 spin_unlock_bh(&ioat->ring_lock); 129 spin_unlock_bh(&ioat->ring_lock);
134} 130}
135 131
136static void ioat2_cleanup(struct ioat2_dma_chan *ioat); 132static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
137
138/**
139 * ioat2_reset_part2 - reinit the channel after a reset
140 */
141static void ioat2_reset_part2(struct work_struct *work)
142{
143 struct ioat_chan_common *chan;
144 struct ioat2_dma_chan *ioat;
145
146 chan = container_of(work, struct ioat_chan_common, work.work);
147 ioat = container_of(chan, struct ioat2_dma_chan, base);
148
149 /* ensure that ->tail points to the stalled descriptor
150 * (ioat->pending is set to 2 at this point so no new
151 * descriptors will be issued while we perform this cleanup)
152 */
153 ioat2_cleanup(ioat);
154
155 spin_lock_bh(&chan->cleanup_lock);
156 spin_lock_bh(&ioat->ring_lock);
157
158 /* set the tail to be re-issued */
159 ioat->issued = ioat->tail;
160 ioat->dmacount = 0;
161
162 dev_dbg(to_dev(&ioat->base),
163 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
164 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
165
166 if (ioat2_ring_pending(ioat)) {
167 struct ioat_ring_ent *desc;
168
169 desc = ioat2_get_ring_ent(ioat, ioat->tail);
170 writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
171 chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
172 writel(((u64) desc->txd.phys) >> 32,
173 chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
174 __ioat2_issue_pending(ioat);
175 } else
176 __ioat2_start_null_desc(ioat);
177
178 spin_unlock_bh(&ioat->ring_lock);
179 spin_unlock_bh(&chan->cleanup_lock);
180
181 dev_info(to_dev(chan),
182 "chan%d reset - %d descs waiting, %d total desc\n",
183 chan_num(chan), ioat->dmacount, 1 << ioat->alloc_order);
184}
185
186/**
187 * ioat2_reset_channel - restart a channel
188 * @ioat: IOAT DMA channel handle
189 */
190static void ioat2_reset_channel(struct ioat2_dma_chan *ioat)
191{ 133{
192 u32 chansts, chanerr;
193 struct ioat_chan_common *chan = &ioat->base; 134 struct ioat_chan_common *chan = &ioat->base;
194 u16 active; 135 struct dma_async_tx_descriptor *tx;
195
196 spin_lock_bh(&ioat->ring_lock);
197 active = ioat2_ring_active(ioat);
198 spin_unlock_bh(&ioat->ring_lock);
199 if (!active)
200 return;
201
202 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
203 chansts = *chan->completion & IOAT_CHANSTS_DMA_TRANSFER_STATUS;
204 if (chanerr) {
205 dev_err(to_dev(chan),
206 "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
207 chan_num(chan), chansts, chanerr);
208 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
209 }
210
211 spin_lock_bh(&ioat->ring_lock);
212 ioat->pending = 2;
213 writeb(IOAT_CHANCMD_RESET,
214 chan->reg_base
215 + IOAT_CHANCMD_OFFSET(chan->device->version));
216 spin_unlock_bh(&ioat->ring_lock);
217 schedule_delayed_work(&chan->work, RESET_DELAY);
218}
219
220/**
221 * ioat2_chan_watchdog - watch for stuck channels
222 */
223static void ioat2_chan_watchdog(struct work_struct *work)
224{
225 struct ioatdma_device *device =
226 container_of(work, struct ioatdma_device, work.work);
227 struct ioat2_dma_chan *ioat;
228 struct ioat_chan_common *chan;
229 u16 active;
230 int i;
231
232 dev_dbg(&device->pdev->dev, "%s\n", __func__);
233
234 for (i = 0; i < device->common.chancnt; i++) {
235 chan = ioat_chan_by_index(device, i);
236 ioat = container_of(chan, struct ioat2_dma_chan, base);
237
238 /*
239 * for version 2.0 if there are descriptors yet to be processed
240 * and the last completed hasn't changed since the last watchdog
241 * if they haven't hit the pending level
242 * issue the pending to push them through
243 * else
244 * try resetting the channel
245 */
246 spin_lock_bh(&ioat->ring_lock);
247 active = ioat2_ring_active(ioat);
248 spin_unlock_bh(&ioat->ring_lock);
249
250 if (active &&
251 chan->last_completion &&
252 chan->last_completion == chan->watchdog_completion) {
253
254 if (ioat->pending == 1)
255 ioat2_issue_pending(&chan->common);
256 else {
257 ioat2_reset_channel(ioat);
258 chan->watchdog_completion = 0;
259 }
260 } else {
261 chan->last_compl_desc_addr_hw = 0;
262 chan->watchdog_completion = chan->last_completion;
263 }
264 chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie;
265 }
266 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
267}
268
269/**
270 * ioat2_cleanup - clean finished descriptors (advance tail pointer)
271 * @chan: ioat channel to be cleaned up
272 */
273static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
274{
275 struct ioat_chan_common *chan = &ioat->base;
276 unsigned long phys_complete;
277 struct ioat_ring_ent *desc; 136 struct ioat_ring_ent *desc;
278 bool seen_current = false; 137 bool seen_current = false;
279 u16 active; 138 u16 active;
280 int i; 139 int i;
281 struct dma_async_tx_descriptor *tx;
282
283 prefetch(chan->completion);
284
285 spin_lock_bh(&chan->cleanup_lock);
286 phys_complete = ioat_get_current_completion(chan);
287 if (phys_complete == chan->last_completion) {
288 spin_unlock_bh(&chan->cleanup_lock);
289 /*
290 * perhaps we're stuck so hard that the watchdog can't go off?
291 * try to catch it after WATCHDOG_DELAY seconds
292 */
293 if (chan->device->version < IOAT_VER_3_0) {
294 unsigned long tmo;
295
296 tmo = chan->last_completion_time + HZ*WATCHDOG_DELAY;
297 if (time_after(jiffies, tmo)) {
298 ioat2_chan_watchdog(&(chan->device->work.work));
299 chan->last_completion_time = jiffies;
300 }
301 }
302 return;
303 }
304 chan->last_completion_time = jiffies;
305
306 spin_lock_bh(&ioat->ring_lock);
307 140
308 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n", 141 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
309 __func__, ioat->head, ioat->tail, ioat->issued); 142 __func__, ioat->head, ioat->tail, ioat->issued);
@@ -329,10 +162,42 @@ static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
329 } 162 }
330 ioat->tail += i; 163 ioat->tail += i;
331 BUG_ON(!seen_current); /* no active descs have written a completion? */ 164 BUG_ON(!seen_current); /* no active descs have written a completion? */
332 spin_unlock_bh(&ioat->ring_lock);
333 165
334 chan->last_completion = phys_complete; 166 chan->last_completion = phys_complete;
167 if (ioat->head == ioat->tail) {
168 dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
169 __func__);
170 clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
171 }
172}
173
174/**
175 * ioat2_cleanup - clean finished descriptors (advance tail pointer)
176 * @chan: ioat channel to be cleaned up
177 */
178static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
179{
180 struct ioat_chan_common *chan = &ioat->base;
181 unsigned long phys_complete;
335 182
183 prefetch(chan->completion);
184
185 if (!spin_trylock_bh(&chan->cleanup_lock))
186 return;
187
188 if (!ioat_cleanup_preamble(chan, &phys_complete)) {
189 spin_unlock_bh(&chan->cleanup_lock);
190 return;
191 }
192
193 if (!spin_trylock_bh(&ioat->ring_lock)) {
194 spin_unlock_bh(&chan->cleanup_lock);
195 return;
196 }
197
198 __cleanup(ioat, phys_complete);
199
200 spin_unlock_bh(&ioat->ring_lock);
336 spin_unlock_bh(&chan->cleanup_lock); 201 spin_unlock_bh(&chan->cleanup_lock);
337} 202}
338 203
@@ -344,6 +209,90 @@ static void ioat2_cleanup_tasklet(unsigned long data)
344 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 209 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
345} 210}
346 211
212static void __restart_chan(struct ioat2_dma_chan *ioat)
213{
214 struct ioat_chan_common *chan = &ioat->base;
215
216 /* set the tail to be re-issued */
217 ioat->issued = ioat->tail;
218 ioat->dmacount = 0;
219 set_bit(IOAT_COMPLETION_PENDING, &chan->state);
220 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
221
222 dev_dbg(to_dev(chan),
223 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
224 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
225
226 if (ioat2_ring_pending(ioat)) {
227 struct ioat_ring_ent *desc;
228
229 desc = ioat2_get_ring_ent(ioat, ioat->tail);
230 ioat2_set_chainaddr(ioat, desc->txd.phys);
231 __ioat2_issue_pending(ioat);
232 } else
233 __ioat2_start_null_desc(ioat);
234}
235
236static void ioat2_restart_channel(struct ioat2_dma_chan *ioat)
237{
238 struct ioat_chan_common *chan = &ioat->base;
239 unsigned long phys_complete;
240 u32 status;
241
242 status = ioat_chansts(chan);
243 if (is_ioat_active(status) || is_ioat_idle(status))
244 ioat_suspend(chan);
245 while (is_ioat_active(status) || is_ioat_idle(status)) {
246 status = ioat_chansts(chan);
247 cpu_relax();
248 }
249
250 if (ioat_cleanup_preamble(chan, &phys_complete))
251 __cleanup(ioat, phys_complete);
252
253 __restart_chan(ioat);
254}
255
256static void ioat2_timer_event(unsigned long data)
257{
258 struct ioat2_dma_chan *ioat = (void *) data;
259 struct ioat_chan_common *chan = &ioat->base;
260
261 spin_lock_bh(&chan->cleanup_lock);
262 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
263 unsigned long phys_complete;
264 u64 status;
265
266 spin_lock_bh(&ioat->ring_lock);
267 status = ioat_chansts(chan);
268
269 /* when halted due to errors check for channel
270 * programming errors before advancing the completion state
271 */
272 if (is_ioat_halted(status)) {
273 u32 chanerr;
274
275 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
276 BUG_ON(is_ioat_bug(chanerr));
277 }
278
279 /* if we haven't made progress and we have already
280 * acknowledged a pending completion once, then be more
281 * forceful with a restart
282 */
283 if (ioat_cleanup_preamble(chan, &phys_complete))
284 __cleanup(ioat, phys_complete);
285 else if (test_bit(IOAT_COMPLETION_ACK, &chan->state))
286 ioat2_restart_channel(ioat);
287 else {
288 set_bit(IOAT_COMPLETION_ACK, &chan->state);
289 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
290 }
291 spin_unlock_bh(&ioat->ring_lock);
292 }
293 spin_unlock_bh(&chan->cleanup_lock);
294}
295
347/** 296/**
348 * ioat2_enumerate_channels - find and initialize the device's channels 297 * ioat2_enumerate_channels - find and initialize the device's channels
349 * @device: the device to be enumerated 298 * @device: the device to be enumerated
@@ -381,7 +330,7 @@ static int ioat2_enumerate_channels(struct ioatdma_device *device)
381 break; 330 break;
382 331
383 ioat_init_channel(device, &ioat->base, i, 332 ioat_init_channel(device, &ioat->base, i,
384 ioat2_reset_part2, 333 ioat2_timer_event,
385 ioat2_cleanup_tasklet, 334 ioat2_cleanup_tasklet,
386 (unsigned long) ioat); 335 (unsigned long) ioat);
387 ioat->xfercap_log = xfercap_log; 336 ioat->xfercap_log = xfercap_log;
@@ -395,6 +344,7 @@ static dma_cookie_t ioat2_tx_submit_unlock(struct dma_async_tx_descriptor *tx)
395{ 344{
396 struct dma_chan *c = tx->chan; 345 struct dma_chan *c = tx->chan;
397 struct ioat2_dma_chan *ioat = to_ioat2_chan(c); 346 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
347 struct ioat_chan_common *chan = &ioat->base;
398 dma_cookie_t cookie = c->cookie; 348 dma_cookie_t cookie = c->cookie;
399 349
400 cookie++; 350 cookie++;
@@ -404,6 +354,8 @@ static dma_cookie_t ioat2_tx_submit_unlock(struct dma_async_tx_descriptor *tx)
404 c->cookie = cookie; 354 c->cookie = cookie;
405 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie); 355 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
406 356
357 if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
358 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
407 ioat2_update_pending(ioat); 359 ioat2_update_pending(ioat);
408 spin_unlock_bh(&ioat->ring_lock); 360 spin_unlock_bh(&ioat->ring_lock);
409 361
@@ -543,9 +495,18 @@ static int ioat2_alloc_and_lock(u16 *idx, struct ioat2_dma_chan *ioat, int num_d
543 ioat->issued); 495 ioat->issued);
544 spin_unlock_bh(&ioat->ring_lock); 496 spin_unlock_bh(&ioat->ring_lock);
545 497
546 /* do direct reclaim in the allocation failure case */ 498 /* progress reclaim in the allocation failure case we
547 ioat2_cleanup(ioat); 499 * may be called under bh_disabled so we need to trigger
548 500 * the timer event directly
501 */
502 spin_lock_bh(&chan->cleanup_lock);
503 if (jiffies > chan->timer.expires &&
504 timer_pending(&chan->timer)) {
505 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
506 spin_unlock_bh(&chan->cleanup_lock);
507 ioat2_timer_event((unsigned long) ioat);
508 } else
509 spin_unlock_bh(&chan->cleanup_lock);
549 return -ENOMEM; 510 return -ENOMEM;
550 } 511 }
551 512
@@ -624,6 +585,7 @@ static void ioat2_free_chan_resources(struct dma_chan *c)
624 return; 585 return;
625 586
626 tasklet_disable(&chan->cleanup_task); 587 tasklet_disable(&chan->cleanup_task);
588 del_timer_sync(&chan->timer);
627 ioat2_cleanup(ioat); 589 ioat2_cleanup(ioat);
628 590
629 /* Delay 100ms after reset to allow internal DMA logic to quiesce 591 /* Delay 100ms after reset to allow internal DMA logic to quiesce
@@ -663,10 +625,6 @@ static void ioat2_free_chan_resources(struct dma_chan *c)
663 chan->completion_dma = 0; 625 chan->completion_dma = 0;
664 ioat->pending = 0; 626 ioat->pending = 0;
665 ioat->dmacount = 0; 627 ioat->dmacount = 0;
666 chan->watchdog_completion = 0;
667 chan->last_compl_desc_addr_hw = 0;
668 chan->watchdog_tcp_cookie = 0;
669 chan->watchdog_last_tcp_cookie = 0;
670} 628}
671 629
672static enum dma_status 630static enum dma_status
@@ -716,9 +674,6 @@ int __devinit ioat2_dma_probe(struct ioatdma_device *device, int dca)
716 if (dca) 674 if (dca)
717 device->dca = ioat2_dca_init(pdev, device->reg_base); 675 device->dca = ioat2_dca_init(pdev, device->reg_base);
718 676
719 INIT_DELAYED_WORK(&device->work, ioat2_chan_watchdog);
720 schedule_delayed_work(&device->work, WATCHDOG_DELAY);
721
722 return err; 677 return err;
723} 678}
724 679