patch-2.4.22 linux-2.4.22/drivers/ieee1394/iso.c

Next file: linux-2.4.22/drivers/ieee1394/iso.h
Previous file: linux-2.4.22/drivers/ieee1394/ieee1394_types.h
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/drivers/ieee1394/iso.c linux-2.4.22/drivers/ieee1394/iso.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/slab.h>
+#include <linux/sched.h>
 #include "iso.h"
 
 void hpsb_iso_stop(struct hpsb_iso *iso)
@@ -24,7 +25,7 @@
 
 void hpsb_iso_shutdown(struct hpsb_iso *iso)
 {
-	if(iso->flags & HPSB_ISO_DRIVER_INIT) {
+	if (iso->flags & HPSB_ISO_DRIVER_INIT) {
 		hpsb_iso_stop(iso);
 		iso->host->driver->isoctl(iso, iso->type == HPSB_ISO_XMIT ?
 					  XMIT_SHUTDOWN : RECV_SHUTDOWN, 0);
@@ -32,7 +33,6 @@
 	}
 
 	dma_region_free(&iso->data_buf);
-	kfree(iso->infos);
 	kfree(iso);
 }
 
@@ -47,7 +47,7 @@
 	int dma_direction;
 
 	/* make sure driver supports the ISO API */
-	if(!host->driver->isoctl) {
+	if (!host->driver->isoctl) {
 		printk(KERN_INFO "ieee1394: host driver '%s' does not support the rawiso API\n",
 		       host->driver->name);
 		return NULL;
@@ -55,29 +55,26 @@
 
 	/* sanitize parameters */
 
-	if(buf_packets < 2)
+	if (buf_packets < 2)
 		buf_packets = 2;
 
-	if(irq_interval < 1 || irq_interval > buf_packets / 2)
+	if (irq_interval < 1 || irq_interval > buf_packets / 2)
 		irq_interval = buf_packets / 2;
 
-	if(channel < -1 || channel >= 64)
+	if (channel < -1 || channel >= 64)
 		return NULL;
 
 	/* channel = -1 is OK for multi-channel recv but not for xmit */
-	if(type == HPSB_ISO_XMIT && channel < 0)
+	if (type == HPSB_ISO_XMIT && channel < 0)
 		return NULL;
 
 	/* allocate and write the struct hpsb_iso */
 
-	iso = kmalloc(sizeof(*iso), SLAB_KERNEL);
-	if(!iso)
+	iso = kmalloc(sizeof(*iso) + buf_packets * sizeof(struct hpsb_iso_packet_info), GFP_KERNEL);
+	if (!iso)
 		return NULL;
 
-	/* allocate ringbuffer of packet descriptors */
-	iso->infos = kmalloc(buf_packets * sizeof(struct hpsb_iso_packet_info), SLAB_KERNEL);
-	if(!iso->infos)
-		return NULL;
+	iso->infos = (struct hpsb_iso_packet_info *)(iso + 1);
 
 	iso->type = type;
 	iso->host = host;
@@ -93,7 +90,7 @@
 	iso->first_packet = 0;
 	spin_lock_init(&iso->lock);
 
-	if(iso->type == HPSB_ISO_XMIT) {
+	if (iso->type == HPSB_ISO_XMIT) {
 		iso->n_ready_packets = iso->buf_packets;
 		dma_direction = PCI_DMA_TODEVICE;
 	} else {
@@ -106,7 +103,7 @@
 	iso->prebuffer = 0;
 
 	/* allocate the packet buffer */
-	if(dma_region_alloc(&iso->data_buf, iso->buf_size, host->pdev, dma_direction))
+	if (dma_region_alloc(&iso->data_buf, iso->buf_size, host->pdev, dma_direction))
 		goto err;
 
 	return iso;
@@ -140,13 +137,13 @@
 	struct hpsb_iso *iso = hpsb_iso_common_init(host, HPSB_ISO_XMIT,
 						    data_buf_size, buf_packets,
 						    channel, irq_interval, callback);
-	if(!iso)
+	if (!iso)
 		return NULL;
 
 	iso->speed = speed;
 
 	/* tell the driver to start working */
-	if(host->driver->isoctl(iso, XMIT_INIT, 0))
+	if (host->driver->isoctl(iso, XMIT_INIT, 0))
 		goto err;
 
 	iso->flags |= HPSB_ISO_DRIVER_INIT;
@@ -167,11 +164,11 @@
 	struct hpsb_iso *iso = hpsb_iso_common_init(host, HPSB_ISO_RECV,
 						    data_buf_size, buf_packets,
 						    channel, irq_interval, callback);
-	if(!iso)
+	if (!iso)
 		return NULL;
 
 	/* tell the driver to start working */
-	if(host->driver->isoctl(iso, RECV_INIT, 0))
+	if (host->driver->isoctl(iso, RECV_INIT, 0))
 		goto err;
 
 	iso->flags |= HPSB_ISO_DRIVER_INIT;
@@ -184,29 +181,36 @@
 
 int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel)
 {
-	if(iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
+	if (iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
 		return -EINVAL;
 	return iso->host->driver->isoctl(iso, RECV_LISTEN_CHANNEL, channel);
 }
 
 int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel)
 {
-       if(iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
+       if (iso->type != HPSB_ISO_RECV || iso->channel != -1 || channel >= 64)
                return -EINVAL;
        return iso->host->driver->isoctl(iso, RECV_UNLISTEN_CHANNEL, channel);
 }
 
 int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask)
 {
-	if(iso->type != HPSB_ISO_RECV || iso->channel != -1)
+	if (iso->type != HPSB_ISO_RECV || iso->channel != -1)
 		return -EINVAL;
 	return iso->host->driver->isoctl(iso, RECV_SET_CHANNEL_MASK, (unsigned long) &mask);
 }
 
+int hpsb_iso_recv_flush(struct hpsb_iso *iso)
+{
+	if (iso->type != HPSB_ISO_RECV)
+		return -EINVAL;
+	return iso->host->driver->isoctl(iso, RECV_FLUSH, 0);
+}
+
 static int do_iso_xmit_start(struct hpsb_iso *iso, int cycle)
 {
 	int retval = iso->host->driver->isoctl(iso, XMIT_START, cycle);
-	if(retval)
+	if (retval)
 		return retval;
 
 	iso->flags |= HPSB_ISO_DRIVER_STARTED;
@@ -215,25 +219,25 @@
 
 int hpsb_iso_xmit_start(struct hpsb_iso *iso, int cycle, int prebuffer)
 {
-	if(iso->type != HPSB_ISO_XMIT)
+	if (iso->type != HPSB_ISO_XMIT)
 		return -1;
 
-	if(iso->flags & HPSB_ISO_DRIVER_STARTED)
+	if (iso->flags & HPSB_ISO_DRIVER_STARTED)
 		return 0;
 
-	if(cycle < -1)
+	if (cycle < -1)
 		cycle = -1;
-	else if(cycle >= 8000)
+	else if (cycle >= 8000)
 		cycle %= 8000;
 
 	iso->xmit_cycle = cycle;
 
-	if(prebuffer < 0)
+	if (prebuffer < 0)
 		prebuffer = iso->buf_packets;
-	else if(prebuffer == 0)
+	else if (prebuffer == 0)
 		prebuffer = 1;
 
-	if(prebuffer > iso->buf_packets)
+	if (prebuffer > iso->buf_packets)
 		prebuffer = iso->buf_packets;
 
 	iso->prebuffer = prebuffer;
@@ -250,20 +254,20 @@
 	int retval = 0;
 	int isoctl_args[3];
 
-	if(iso->type != HPSB_ISO_RECV)
+	if (iso->type != HPSB_ISO_RECV)
 		return -1;
 
-	if(iso->flags & HPSB_ISO_DRIVER_STARTED)
+	if (iso->flags & HPSB_ISO_DRIVER_STARTED)
 		return 0;
 
-	if(cycle < -1)
+	if (cycle < -1)
 		cycle = -1;
-	else if(cycle >= 8000)
+	else if (cycle >= 8000)
 		cycle %= 8000;
 
 	isoctl_args[0] = cycle;
 	
-	if(tag_mask < 0)
+	if (tag_mask < 0)
 		/* match all tags */
 		tag_mask = 0xF;
 	isoctl_args[1] = tag_mask;
@@ -271,7 +275,7 @@
 	isoctl_args[2] = sync;
 
 	retval = iso->host->driver->isoctl(iso, RECV_START, (unsigned long) &isoctl_args[0]);
-	if(retval)
+	if (retval)
 		return retval;
 
 	iso->flags |= HPSB_ISO_DRIVER_STARTED;
@@ -285,15 +289,15 @@
 				     unsigned int offset, unsigned short len,
 				     unsigned int *out_offset, unsigned short *out_len)
 {
-	if(offset >= iso->buf_size)
+	if (offset >= iso->buf_size)
 		return -EFAULT;
 
 	/* make sure the packet does not go beyond the end of the buffer */
-	if(offset + len > iso->buf_size)
+	if (offset + len > iso->buf_size)
 		return -EFAULT;
 
 	/* check for wrap-around */
-	if(offset + len < offset)
+	if (offset + len < offset)
 		return -EFAULT;
 
 	/* now we can trust 'offset' and 'length' */
@@ -310,18 +314,18 @@
 	unsigned long flags;
 	int rv;
 
-	if(iso->type != HPSB_ISO_XMIT)
+	if (iso->type != HPSB_ISO_XMIT)
 		return -EINVAL;
 
 	/* is there space in the buffer? */
-	if(iso->n_ready_packets <= 0) {
+	if (iso->n_ready_packets <= 0) {
 		return -EBUSY;
 	}
 
 	info = &iso->infos[iso->first_packet];
 
 	/* check for bogus offset/length */
-	if(hpsb_iso_check_offset_len(iso, offset, len, &info->offset, &info->len))
+	if (hpsb_iso_check_offset_len(iso, offset, len, &info->offset, &info->len))
 		return -EFAULT;
 
 	info->tag = tag;
@@ -330,7 +334,7 @@
 	spin_lock_irqsave(&iso->lock, flags);
 
 	rv = iso->host->driver->isoctl(iso, XMIT_QUEUE, (unsigned long) info);
-	if(rv)
+	if (rv)
 		goto out;
 
 	/* increment cursors */
@@ -338,9 +342,9 @@
 	iso->xmit_cycle = (iso->xmit_cycle+1) % 8000;
 	iso->n_ready_packets--;
 
-	if(iso->prebuffer != 0) {
+	if (iso->prebuffer != 0) {
 		iso->prebuffer--;
-		if(iso->prebuffer <= 0) {
+		if (iso->prebuffer <= 0) {
 			iso->prebuffer = 0;
 			rv = do_iso_xmit_start(iso, iso->start_cycle);
 		}
@@ -353,7 +357,7 @@
 
 int hpsb_iso_xmit_sync(struct hpsb_iso *iso)
 {
-	if(iso->type != HPSB_ISO_XMIT)
+	if (iso->type != HPSB_ISO_XMIT)
 		return -EINVAL;
 
 	return wait_event_interruptible(iso->waitq, hpsb_iso_n_ready(iso) == iso->buf_packets);
@@ -374,7 +378,7 @@
 	iso->n_ready_packets++;
 	iso->pkt_dma = (iso->pkt_dma + 1) % iso->buf_packets;
 
-	if(iso->n_ready_packets == iso->buf_packets || error != 0) {
+	if (iso->n_ready_packets == iso->buf_packets || error != 0) {
 		/* the buffer has run empty! */
 		atomic_inc(&iso->overflows);
 	}
@@ -388,7 +392,7 @@
 	unsigned long flags;
 	spin_lock_irqsave(&iso->lock, flags);
 
-	if(iso->n_ready_packets == iso->buf_packets) {
+	if (iso->n_ready_packets == iso->buf_packets) {
 		/* overflow! */
 		atomic_inc(&iso->overflows);
 	} else {
@@ -413,14 +417,14 @@
 	unsigned int i;
 	int rv = 0;
 
-	if(iso->type != HPSB_ISO_RECV)
+	if (iso->type != HPSB_ISO_RECV)
 		return -1;
 
 	spin_lock_irqsave(&iso->lock, flags);
-	for(i = 0; i < n_packets; i++) {
+	for (i = 0; i < n_packets; i++) {
 		rv = iso->host->driver->isoctl(iso, RECV_RELEASE,
 					       (unsigned long) &iso->infos[iso->first_packet]);
-		if(rv)
+		if (rv)
 			break;
 
 		iso->first_packet = (iso->first_packet+1) % iso->buf_packets;
@@ -434,6 +438,6 @@
 {
 	wake_up_interruptible(&iso->waitq);
 
-	if(iso->callback)
+	if (iso->callback)
 		iso->callback(iso);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)