blob: 1cf6487b65ba8ce9c2b042d0dc5bcbcf03369f50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IEEE 1394 for Linux
3 *
4 * kernel ISO transmission/reception
5 *
6 * Copyright (C) 2002 Maas Digital LLC
7 *
8 * This code is licensed under the GPL. See the file COPYING in the root
9 * directory of the kernel sources for details.
10 */
11
Stefan Richterde4394f2006-07-03 12:02:29 -040012#include <linux/pci.h>
Andrew Mortonb9e5eb02007-04-26 00:16:04 -070013#include <linux/sched.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070014#include <linux/mm.h>
Stefan Richterde4394f2006-07-03 12:02:29 -040015#include <linux/slab.h>
16
17#include "hosts.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "iso.h"
19
Stefan Richterafd65462007-03-05 03:06:23 +010020/**
21 * hpsb_iso_stop - stop DMA
22 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023void hpsb_iso_stop(struct hpsb_iso *iso)
24{
25 if (!(iso->flags & HPSB_ISO_DRIVER_STARTED))
26 return;
27
28 iso->host->driver->isoctl(iso, iso->type == HPSB_ISO_XMIT ?
29 XMIT_STOP : RECV_STOP, 0);
30 iso->flags &= ~HPSB_ISO_DRIVER_STARTED;
31}
32
Stefan Richterafd65462007-03-05 03:06:23 +010033/**
34 * hpsb_iso_shutdown - deallocate buffer and DMA context
35 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036void hpsb_iso_shutdown(struct hpsb_iso *iso)
37{
38 if (iso->flags & HPSB_ISO_DRIVER_INIT) {
39 hpsb_iso_stop(iso);
40 iso->host->driver->isoctl(iso, iso->type == HPSB_ISO_XMIT ?
41 XMIT_SHUTDOWN : RECV_SHUTDOWN, 0);
42 iso->flags &= ~HPSB_ISO_DRIVER_INIT;
43 }
44
45 dma_region_free(&iso->data_buf);
46 kfree(iso);
47}
48
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050049static struct hpsb_iso *hpsb_iso_common_init(struct hpsb_host *host,
50 enum hpsb_iso_type type,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 unsigned int data_buf_size,
52 unsigned int buf_packets,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050053 int channel, int dma_mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int irq_interval,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050055 void (*callback) (struct hpsb_iso
56 *))
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 struct hpsb_iso *iso;
59 int dma_direction;
60
61 /* make sure driver supports the ISO API */
62 if (!host->driver->isoctl) {
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050063 printk(KERN_INFO
64 "ieee1394: host driver '%s' does not support the rawiso API\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 host->driver->name);
66 return NULL;
67 }
68
69 /* sanitize parameters */
70
71 if (buf_packets < 2)
72 buf_packets = 2;
73
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050074 if ((dma_mode < HPSB_ISO_DMA_DEFAULT)
75 || (dma_mode > HPSB_ISO_DMA_PACKET_PER_BUFFER))
76 dma_mode = HPSB_ISO_DMA_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Ben Collins1934b8b2005-07-09 20:01:23 -040078 if ((irq_interval < 0) || (irq_interval > buf_packets / 4))
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050079 irq_interval = buf_packets / 4;
80 if (irq_interval == 0) /* really interrupt for each packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 irq_interval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 if (channel < -1 || channel >= 64)
84 return NULL;
85
86 /* channel = -1 is OK for multi-channel recv but not for xmit */
87 if (type == HPSB_ISO_XMIT && channel < 0)
88 return NULL;
89
90 /* allocate and write the struct hpsb_iso */
91
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -050092 iso =
93 kmalloc(sizeof(*iso) +
94 buf_packets * sizeof(struct hpsb_iso_packet_info),
95 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (!iso)
97 return NULL;
98
99 iso->infos = (struct hpsb_iso_packet_info *)(iso + 1);
100
101 iso->type = type;
102 iso->host = host;
103 iso->hostdata = NULL;
104 iso->callback = callback;
105 init_waitqueue_head(&iso->waitq);
106 iso->channel = channel;
107 iso->irq_interval = irq_interval;
108 iso->dma_mode = dma_mode;
109 dma_region_init(&iso->data_buf);
110 iso->buf_size = PAGE_ALIGN(data_buf_size);
111 iso->buf_packets = buf_packets;
112 iso->pkt_dma = 0;
113 iso->first_packet = 0;
114 spin_lock_init(&iso->lock);
115
116 if (iso->type == HPSB_ISO_XMIT) {
117 iso->n_ready_packets = iso->buf_packets;
118 dma_direction = PCI_DMA_TODEVICE;
119 } else {
120 iso->n_ready_packets = 0;
121 dma_direction = PCI_DMA_FROMDEVICE;
122 }
123
124 atomic_set(&iso->overflows, 0);
Ben Collins1934b8b2005-07-09 20:01:23 -0400125 iso->bytes_discarded = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 iso->flags = 0;
127 iso->prebuffer = 0;
128
129 /* allocate the packet buffer */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500130 if (dma_region_alloc
131 (&iso->data_buf, iso->buf_size, host->pdev, dma_direction))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 goto err;
133
134 return iso;
135
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500136 err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 hpsb_iso_shutdown(iso);
138 return NULL;
139}
140
Stefan Richterafd65462007-03-05 03:06:23 +0100141/**
142 * hpsb_iso_n_ready - returns number of packets ready to send or receive
143 */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500144int hpsb_iso_n_ready(struct hpsb_iso *iso)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 unsigned long flags;
147 int val;
148
149 spin_lock_irqsave(&iso->lock, flags);
150 val = iso->n_ready_packets;
151 spin_unlock_irqrestore(&iso->lock, flags);
152
153 return val;
154}
155
Stefan Richterafd65462007-03-05 03:06:23 +0100156/**
157 * hpsb_iso_xmit_init - allocate the buffer and DMA context
158 */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500159struct hpsb_iso *hpsb_iso_xmit_init(struct hpsb_host *host,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 unsigned int data_buf_size,
161 unsigned int buf_packets,
162 int channel,
163 int speed,
164 int irq_interval,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500165 void (*callback) (struct hpsb_iso *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 struct hpsb_iso *iso = hpsb_iso_common_init(host, HPSB_ISO_XMIT,
168 data_buf_size, buf_packets,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500169 channel,
170 HPSB_ISO_DMA_DEFAULT,
171 irq_interval, callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (!iso)
173 return NULL;
174
175 iso->speed = speed;
176
177 /* tell the driver to start working */
178 if (host->driver->isoctl(iso, XMIT_INIT, 0))
179 goto err;
180
181 iso->flags |= HPSB_ISO_DRIVER_INIT;
182 return iso;
183
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500184 err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 hpsb_iso_shutdown(iso);
186 return NULL;
187}
188
Stefan Richterafd65462007-03-05 03:06:23 +0100189/**
190 * hpsb_iso_recv_init - allocate the buffer and DMA context
191 *
192 * Note, if channel = -1, multi-channel receive is enabled.
193 */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500194struct hpsb_iso *hpsb_iso_recv_init(struct hpsb_host *host,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 unsigned int data_buf_size,
196 unsigned int buf_packets,
197 int channel,
198 int dma_mode,
199 int irq_interval,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500200 void (*callback) (struct hpsb_iso *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 struct hpsb_iso *iso = hpsb_iso_common_init(host, HPSB_ISO_RECV,
203 data_buf_size, buf_packets,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500204 channel, dma_mode,
205 irq_interval, callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (!iso)
207 return NULL;
208
209 /* tell the driver to start working */
210 if (host->driver->isoctl(iso, RECV_INIT, 0))
211 goto err;
212
213 iso->flags |= HPSB_ISO_DRIVER_INIT;
214 return iso;
215
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500216 err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 hpsb_iso_shutdown(iso);
218 return NULL;
219}
220
Stefan Richterafd65462007-03-05 03:06:23 +0100221/**
222 * hpsb_iso_recv_listen_channel
223 *
224 * multi-channel only
225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel)
227{
228 if (iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
229 return -EINVAL;
230 return iso->host->driver->isoctl(iso, RECV_LISTEN_CHANNEL, channel);
231}
232
Stefan Richterafd65462007-03-05 03:06:23 +0100233/**
234 * hpsb_iso_recv_unlisten_channel
235 *
236 * multi-channel only
237 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel)
239{
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500240 if (iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
241 return -EINVAL;
242 return iso->host->driver->isoctl(iso, RECV_UNLISTEN_CHANNEL, channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Stefan Richterafd65462007-03-05 03:06:23 +0100245/**
246 * hpsb_iso_recv_set_channel_mask
247 *
248 * multi-channel only
249 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask)
251{
252 if (iso->type != HPSB_ISO_RECV || iso->channel != -1)
253 return -EINVAL;
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500254 return iso->host->driver->isoctl(iso, RECV_SET_CHANNEL_MASK,
255 (unsigned long)&mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
Stefan Richterafd65462007-03-05 03:06:23 +0100258/**
259 * hpsb_iso_recv_flush - check for arrival of new packets
260 *
261 * check for arrival of new packets immediately (even if irq_interval
262 * has not yet been reached)
263 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264int hpsb_iso_recv_flush(struct hpsb_iso *iso)
265{
266 if (iso->type != HPSB_ISO_RECV)
267 return -EINVAL;
268 return iso->host->driver->isoctl(iso, RECV_FLUSH, 0);
269}
270
271static int do_iso_xmit_start(struct hpsb_iso *iso, int cycle)
272{
273 int retval = iso->host->driver->isoctl(iso, XMIT_START, cycle);
274 if (retval)
275 return retval;
276
277 iso->flags |= HPSB_ISO_DRIVER_STARTED;
278 return retval;
279}
280
Stefan Richterafd65462007-03-05 03:06:23 +0100281/**
282 * hpsb_iso_xmit_start - start DMA
283 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284int hpsb_iso_xmit_start(struct hpsb_iso *iso, int cycle, int prebuffer)
285{
286 if (iso->type != HPSB_ISO_XMIT)
287 return -1;
288
289 if (iso->flags & HPSB_ISO_DRIVER_STARTED)
290 return 0;
291
292 if (cycle < -1)
293 cycle = -1;
294 else if (cycle >= 8000)
295 cycle %= 8000;
296
297 iso->xmit_cycle = cycle;
298
299 if (prebuffer < 0)
Ben Collins1934b8b2005-07-09 20:01:23 -0400300 prebuffer = iso->buf_packets - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 else if (prebuffer == 0)
302 prebuffer = 1;
303
Ben Collins1934b8b2005-07-09 20:01:23 -0400304 if (prebuffer >= iso->buf_packets)
305 prebuffer = iso->buf_packets - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 iso->prebuffer = prebuffer;
308
309 /* remember the starting cycle; DMA will commence from xmit_queue_packets()
310 once enough packets have been buffered */
311 iso->start_cycle = cycle;
312
313 return 0;
314}
315
Stefan Richterafd65462007-03-05 03:06:23 +0100316/**
317 * hpsb_iso_recv_start - start DMA
318 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319int hpsb_iso_recv_start(struct hpsb_iso *iso, int cycle, int tag_mask, int sync)
320{
321 int retval = 0;
322 int isoctl_args[3];
323
324 if (iso->type != HPSB_ISO_RECV)
325 return -1;
326
327 if (iso->flags & HPSB_ISO_DRIVER_STARTED)
328 return 0;
329
330 if (cycle < -1)
331 cycle = -1;
332 else if (cycle >= 8000)
333 cycle %= 8000;
334
335 isoctl_args[0] = cycle;
336
337 if (tag_mask < 0)
338 /* match all tags */
339 tag_mask = 0xF;
340 isoctl_args[1] = tag_mask;
341
342 isoctl_args[2] = sync;
343
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500344 retval =
345 iso->host->driver->isoctl(iso, RECV_START,
346 (unsigned long)&isoctl_args[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (retval)
348 return retval;
349
350 iso->flags |= HPSB_ISO_DRIVER_STARTED;
351 return retval;
352}
353
354/* check to make sure the user has not supplied bogus values of offset/len
Stefan Richterafd65462007-03-05 03:06:23 +0100355 * that would cause the kernel to access memory outside the buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356static int hpsb_iso_check_offset_len(struct hpsb_iso *iso,
357 unsigned int offset, unsigned short len,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500358 unsigned int *out_offset,
359 unsigned short *out_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 if (offset >= iso->buf_size)
362 return -EFAULT;
363
364 /* make sure the packet does not go beyond the end of the buffer */
365 if (offset + len > iso->buf_size)
366 return -EFAULT;
367
368 /* check for wrap-around */
369 if (offset + len < offset)
370 return -EFAULT;
371
372 /* now we can trust 'offset' and 'length' */
373 *out_offset = offset;
374 *out_len = len;
375
376 return 0;
377}
378
Stefan Richterafd65462007-03-05 03:06:23 +0100379/**
380 * hpsb_iso_xmit_queue_packet - queue a packet for transmission.
381 *
382 * @offset is relative to the beginning of the DMA buffer, where the packet's
383 * data payload should already have been placed.
384 */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500385int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
386 u8 tag, u8 sy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
388 struct hpsb_iso_packet_info *info;
389 unsigned long flags;
390 int rv;
391
392 if (iso->type != HPSB_ISO_XMIT)
393 return -EINVAL;
394
395 /* is there space in the buffer? */
396 if (iso->n_ready_packets <= 0) {
397 return -EBUSY;
398 }
399
400 info = &iso->infos[iso->first_packet];
401
402 /* check for bogus offset/length */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500403 if (hpsb_iso_check_offset_len
404 (iso, offset, len, &info->offset, &info->len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return -EFAULT;
406
407 info->tag = tag;
408 info->sy = sy;
409
410 spin_lock_irqsave(&iso->lock, flags);
411
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500412 rv = iso->host->driver->isoctl(iso, XMIT_QUEUE, (unsigned long)info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 if (rv)
414 goto out;
415
416 /* increment cursors */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500417 iso->first_packet = (iso->first_packet + 1) % iso->buf_packets;
418 iso->xmit_cycle = (iso->xmit_cycle + 1) % 8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 iso->n_ready_packets--;
420
421 if (iso->prebuffer != 0) {
422 iso->prebuffer--;
423 if (iso->prebuffer <= 0) {
424 iso->prebuffer = 0;
425 rv = do_iso_xmit_start(iso, iso->start_cycle);
426 }
427 }
428
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500429 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 spin_unlock_irqrestore(&iso->lock, flags);
431 return rv;
432}
433
Stefan Richterafd65462007-03-05 03:06:23 +0100434/**
435 * hpsb_iso_xmit_sync - wait until all queued packets have been transmitted
436 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437int hpsb_iso_xmit_sync(struct hpsb_iso *iso)
438{
439 if (iso->type != HPSB_ISO_XMIT)
440 return -EINVAL;
441
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500442 return wait_event_interruptible(iso->waitq,
443 hpsb_iso_n_ready(iso) ==
444 iso->buf_packets);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
446
Stefan Richterafd65462007-03-05 03:06:23 +0100447/**
448 * hpsb_iso_packet_sent
449 *
450 * Available to low-level drivers.
451 *
452 * Call after a packet has been transmitted to the bus (interrupt context is
453 * OK). @cycle is the _exact_ cycle the packet was sent on. @error should be
454 * non-zero if some sort of error occurred when sending the packet.
455 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error)
457{
458 unsigned long flags;
459 spin_lock_irqsave(&iso->lock, flags);
460
461 /* predict the cycle of the next packet to be queued */
462
463 /* jump ahead by the number of packets that are already buffered */
464 cycle += iso->buf_packets - iso->n_ready_packets;
465 cycle %= 8000;
466
467 iso->xmit_cycle = cycle;
468 iso->n_ready_packets++;
469 iso->pkt_dma = (iso->pkt_dma + 1) % iso->buf_packets;
470
471 if (iso->n_ready_packets == iso->buf_packets || error != 0) {
472 /* the buffer has run empty! */
473 atomic_inc(&iso->overflows);
474 }
475
476 spin_unlock_irqrestore(&iso->lock, flags);
477}
478
Stefan Richterafd65462007-03-05 03:06:23 +0100479/**
480 * hpsb_iso_packet_received
481 *
482 * Available to low-level drivers.
483 *
484 * Call after a packet has been received (interrupt context is OK).
485 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500487 u16 total_len, u16 cycle, u8 channel, u8 tag,
488 u8 sy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 unsigned long flags;
491 spin_lock_irqsave(&iso->lock, flags);
492
493 if (iso->n_ready_packets == iso->buf_packets) {
494 /* overflow! */
495 atomic_inc(&iso->overflows);
Ben Collins1934b8b2005-07-09 20:01:23 -0400496 /* Record size of this discarded packet */
497 iso->bytes_discarded += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 } else {
499 struct hpsb_iso_packet_info *info = &iso->infos[iso->pkt_dma];
500 info->offset = offset;
501 info->len = len;
Ben Collins1934b8b2005-07-09 20:01:23 -0400502 info->total_len = total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 info->cycle = cycle;
504 info->channel = channel;
505 info->tag = tag;
506 info->sy = sy;
507
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500508 iso->pkt_dma = (iso->pkt_dma + 1) % iso->buf_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 iso->n_ready_packets++;
510 }
511
512 spin_unlock_irqrestore(&iso->lock, flags);
513}
514
Stefan Richterafd65462007-03-05 03:06:23 +0100515/**
516 * hpsb_iso_recv_release_packets - release packets, reuse buffer
517 *
518 * @n_packets have been read out of the buffer, re-use the buffer space
519 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520int hpsb_iso_recv_release_packets(struct hpsb_iso *iso, unsigned int n_packets)
521{
522 unsigned long flags;
523 unsigned int i;
524 int rv = 0;
525
526 if (iso->type != HPSB_ISO_RECV)
527 return -1;
528
529 spin_lock_irqsave(&iso->lock, flags);
530 for (i = 0; i < n_packets; i++) {
531 rv = iso->host->driver->isoctl(iso, RECV_RELEASE,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500532 (unsigned long)&iso->infos[iso->
533 first_packet]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (rv)
535 break;
536
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500537 iso->first_packet = (iso->first_packet + 1) % iso->buf_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 iso->n_ready_packets--;
Ben Collins1934b8b2005-07-09 20:01:23 -0400539
540 /* release memory from packets discarded when queue was full */
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500541 if (iso->n_ready_packets == 0) { /* Release only after all prior packets handled */
Ben Collins1934b8b2005-07-09 20:01:23 -0400542 if (iso->bytes_discarded != 0) {
543 struct hpsb_iso_packet_info inf;
544 inf.total_len = iso->bytes_discarded;
545 iso->host->driver->isoctl(iso, RECV_RELEASE,
Jens-Michael Hoffmann066ef9c2005-11-22 12:35:23 -0500546 (unsigned long)&inf);
Ben Collins1934b8b2005-07-09 20:01:23 -0400547 iso->bytes_discarded = 0;
548 }
549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551 spin_unlock_irqrestore(&iso->lock, flags);
552 return rv;
553}
554
Stefan Richterafd65462007-03-05 03:06:23 +0100555/**
556 * hpsb_iso_wake
557 *
558 * Available to low-level drivers.
559 *
560 * Call to wake waiting processes after buffer space has opened up.
561 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562void hpsb_iso_wake(struct hpsb_iso *iso)
563{
564 wake_up_interruptible(&iso->waitq);
565
566 if (iso->callback)
567 iso->callback(iso);
568}