[patch 04/10] firedtv: use hpsb_node_read(), _write(), _lock()

Stefan Richter stefanr at s5r6.in-berlin.de
Mon Sep 29 17:18:30 UTC 2008


because they are simpler and treat the node generation more correctly.
While we are at it, clean up and simplify surrounding code.

Signed-off-by: Stefan Richter <stefanr at s5r6.in-berlin.de>
---
 drivers/media/dvb/firesat/avc_api.c      |  133 +++++++----------------
 drivers/media/dvb/firesat/cmp.c          |    7 -
 drivers/media/dvb/firesat/firesat.h      |   10 -
 drivers/media/dvb/firesat/firesat_1394.c |   24 +---
 drivers/media/dvb/firesat/firesat_iso.c  |    3 
 5 files changed, 58 insertions(+), 119 deletions(-)

Index: linux/drivers/media/dvb/firesat/avc_api.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/avc_api.c
+++ linux/drivers/media/dvb/firesat/avc_api.c
@@ -13,12 +13,13 @@
 
 #include <linux/crc32.h>
 #include <linux/delay.h>
+#include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
+#include <linux/string.h>
 #include <linux/wait.h>
 #include <linux/workqueue.h>
-#include <asm/atomic.h>
 
 #include <ieee1394_transactions.h>
 #include <nodemgr.h>
@@ -35,13 +36,6 @@ static unsigned int avc_comm_debug = 0;
 module_param(avc_comm_debug, int, 0644);
 MODULE_PARM_DESC(avc_comm_debug, "debug logging level [0..2] of AV/C communication, default is 0 (no)");
 
-/* Frees an allocated packet */
-static void avc_free_packet(struct hpsb_packet *packet)
-{
-	hpsb_free_tlabel(packet);
-	hpsb_free_packet(packet);
-}
-
 static const char* get_ctype_string(__u8 ctype)
 {
 	switch(ctype)
@@ -166,75 +160,46 @@ static void log_response_frame(const AVC
 }
 
 static int __AVCWrite(struct firesat *firesat, const AVCCmdFrm *CmdFrm,
-		      AVCRspFrm *RspFrm) {
-	struct hpsb_packet *packet;
-	struct node_entry *ne;
-	int num_tries = 0;
-	int packet_ok = 0;
-
-	ne = firesat->nodeentry;
-	if(!ne) {
-		printk(KERN_ERR "%s: lost node!\n",__func__);
-		return -EIO;
-	}
-
-	/* need all input data */
-	if(!firesat || !ne || !CmdFrm) {
-		printk(KERN_ERR "%s: missing input data!\n",__func__);
-		return -EINVAL;
-	}
+		      AVCRspFrm *RspFrm)
+{
+	int err, retry;
 
-	if (avc_comm_debug > 0) {
+	if (avc_comm_debug > 0)
 		log_command_frame(CmdFrm);
-	}
 
-	if(RspFrm)
-		atomic_set(&firesat->avc_reply_received, 0);
+	if (RspFrm)
+		firesat->avc_reply_received = false;
 
-	while (packet_ok == 0 && num_tries < 6) {
-		num_tries++;
-		packet_ok = 1;
-		packet = hpsb_make_writepacket(ne->host, ne->nodeid,
-					       COMMAND_REGISTER,
-					       (quadlet_t*)CmdFrm,
-					       CmdFrm->length);
-		hpsb_set_packet_complete_task(packet,
-					      (void (*)(void*))avc_free_packet,
-					      packet);
-		hpsb_node_fill_packet(ne, packet);
-
-		if (hpsb_send_packet(packet) < 0) {
-			avc_free_packet(packet);
-			atomic_set(&firesat->avc_reply_received, 1);
-			printk(KERN_ERR "%s: send failed!\n",__func__);
-			return -EIO;
+	for (retry = 0; retry < 6; retry++) {
+		err = hpsb_node_write(firesat->ud->ne, COMMAND_REGISTER,
+				      (quadlet_t *)CmdFrm, CmdFrm->length);
+		if (err) {
+			firesat->avc_reply_received = true;
+			dev_err(&firesat->ud->device,
+				"FCP command write failed\n");
+			return err;
 		}
 
-		if(RspFrm) {
-			// AV/C specs say that answers should be send within
-			// 150 ms so let's time out after 200 ms
-			if (wait_event_timeout(firesat->avc_wait,
-					       atomic_read(&firesat->avc_reply_received) == 1,
-					       HZ / 5) == 0) {
-				packet_ok = 0;
-			}
-			else {
-				memcpy(RspFrm, firesat->respfrm,
-				       firesat->resp_length);
-				RspFrm->length = firesat->resp_length;
-				if (avc_comm_debug > 0) {
-					log_response_frame(RspFrm);
-				}
-			}
+		if (!RspFrm)
+			return 0;
+
+		/*
+		 * AV/C specs say that answers should be sent within 150 ms.
+		 * Time out after 200 ms.
+		 */
+		if (wait_event_timeout(firesat->avc_wait,
+				       firesat->avc_reply_received,
+				       HZ / 5) != 0) {
+			memcpy(RspFrm, firesat->respfrm, firesat->resp_length);
+			RspFrm->length = firesat->resp_length;
+			if (avc_comm_debug > 0)
+				log_response_frame(RspFrm);
+
+			return 0;
 		}
 	}
-	if (packet_ok == 0) {
-		printk(KERN_ERR "%s: AV/C response timed out 6 times.\n",
-		       __func__);
-		return -ETIMEDOUT;
-	}
-
-	return 0;
+	dev_err(&firesat->ud->device, "FCP response timed out\n");
+	return -ETIMEDOUT;
 }
 
 int AVCWrite(struct firesat*firesat, const AVCCmdFrm *CmdFrm, AVCRspFrm *RspFrm)
@@ -264,34 +229,22 @@ int AVCRecv(struct firesat *firesat, u8 
 					  RspFrm->operand[5]);
 			schedule_work(&firesat->remote_ctrl_work);
 		} else if (RspFrm->resp != INTERIM) {
-			printk(KERN_INFO "firedtv: remote control result = "
-			       "%d\n", RspFrm->resp);
+			dev_info(&firesat->ud->device,
+				 "remote control result = %d\n", RspFrm->resp);
 		}
 		return 0;
 	}
 
-	if(atomic_read(&firesat->avc_reply_received) == 1) {
-		printk(KERN_ERR "%s: received out-of-order AVC response, "
-		       "ignored\n",__func__);
-		return -EINVAL;
+	if (firesat->avc_reply_received) {
+		dev_err(&firesat->ud->device,
+			"received out-of-order AVC response, ignored\n");
+		return -EIO;
 	}
-//	AVCRspFrm *resp=(AVCRspFrm *)data;
-//	int k;
-
-//	printk(KERN_INFO "resp=0x%x\n",resp->resp);
-//	printk(KERN_INFO "cts=0x%x\n",resp->cts);
-//	printk(KERN_INFO "suid=0x%x\n",resp->suid);
-//	printk(KERN_INFO "sutyp=0x%x\n",resp->sutyp);
-//	printk(KERN_INFO "opcode=0x%x\n",resp->opcode);
-//	printk(KERN_INFO "length=%d\n",resp->length);
-
-//	for(k=0;k<2;k++)
-//		printk(KERN_INFO "operand[%d]=%02x\n",k,resp->operand[k]);
 
-	memcpy(firesat->respfrm,data,length);
-	firesat->resp_length=length;
+	memcpy(firesat->respfrm, data, length);
+	firesat->resp_length = length;
 
-	atomic_set(&firesat->avc_reply_received, 1);
+	firesat->avc_reply_received = true;
 	wake_up(&firesat->avc_wait);
 
 	return 0;
Index: linux/drivers/media/dvb/firesat/cmp.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/cmp.c
+++ linux/drivers/media/dvb/firesat/cmp.c
@@ -49,8 +49,7 @@ static int cmp_read(struct firesat *fire
 	if (mutex_lock_interruptible(&firesat->avc_mutex))
 		return -EINTR;
 
-	ret = hpsb_read(firesat->host, firesat->nodeentry->nodeid,
-			firesat->nodeentry->generation, addr, buf, len);
+	ret = hpsb_node_read(firesat->ud->ne, addr, buf, len);
 
 	mutex_unlock(&firesat->avc_mutex);
 	return ret;
@@ -64,9 +63,7 @@ static int cmp_lock(struct firesat *fire
 	if (mutex_lock_interruptible(&firesat->avc_mutex))
 		return -EINTR;
 
-	ret = hpsb_lock(firesat->host, firesat->nodeentry->nodeid,
-			firesat->nodeentry->generation,
-			addr, ext_tcode, data, arg);
+	ret = hpsb_node_lock(firesat->ud->ne, addr, ext_tcode, data, arg);
 
 	mutex_unlock(&firesat->avc_mutex);
 	return ret;
Index: linux/drivers/media/dvb/firesat/firesat.h
===================================================================
--- linux.orig/drivers/media/dvb/firesat/firesat.h
+++ linux/drivers/media/dvb/firesat/firesat.h
@@ -21,7 +21,6 @@
 #include <linux/types.h>
 #include <linux/wait.h>
 #include <linux/workqueue.h>
-#include <asm/atomic.h>
 
 #include <demux.h>
 #include <dmxdev.h>
@@ -129,7 +128,7 @@ enum model_type {
 
 struct hpsb_host;
 struct hpsb_iso;
-struct node_entry;
+struct unit_directory;
 
 struct firesat {
 	struct dvb_demux dvb_demux;
@@ -149,7 +148,7 @@ struct firesat {
 
 	struct mutex			avc_mutex;
 	wait_queue_head_t		avc_wait;
-	atomic_t			avc_reply_received;
+	bool				avc_reply_received;
 	struct work_struct		remote_ctrl_work;
 
 	struct firesat_channel {
@@ -167,10 +166,7 @@ struct firesat {
 	void *respfrm;
 	int resp_length;
 
-	struct hpsb_host *host;
-	u64 guid;			/* GUID of this node */
-	u32 guid_vendor_id;		/* Top 24bits of guid */
-	struct node_entry *nodeentry;
+	struct unit_directory *ud;
 
 	enum model_type type;
 	char subunit;
Index: linux/drivers/media/dvb/firesat/firesat_1394.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/firesat_1394.c
+++ linux/drivers/media/dvb/firesat/firesat_1394.c
@@ -21,7 +21,6 @@
 #include <linux/spinlock.h>
 #include <linux/string.h>
 #include <linux/types.h>
-#include <asm/atomic.h>
 
 #include <dmxdev.h>
 #include <dvb_demux.h>
@@ -98,8 +97,8 @@ static void fcp_request(struct hpsb_host
 
 		spin_lock_irqsave(&firesat_list_lock, flags);
 		list_for_each_entry(firesat_entry,&firesat_list,list) {
-			if (firesat_entry->host == host &&
-			    firesat_entry->nodeentry->nodeid == nodeid &&
+			if (firesat_entry->ud->ne->host == host &&
+			    firesat_entry->ud->ne->nodeid == nodeid &&
 			    (firesat_entry->subunit == (data[1]&0x7) ||
 			     (firesat_entry->subunit == 0 &&
 			      (data[1]&0x7) == 0x7))) {
@@ -163,10 +162,7 @@ static int firesat_probe(struct device *
 
 		memset(firesat, 0, sizeof (struct firesat));
 
-		firesat->host		= ud->ne->host;
-		firesat->guid		= ud->ne->guid;
-		firesat->guid_vendor_id = ud->ne->guid_vendor_id;
-		firesat->nodeentry	= ud->ne;
+		firesat->ud		= ud;
 		firesat->isochannel	= -1;
 		firesat->tone		= 0xff;
 		firesat->voltage	= 0xff;
@@ -180,7 +176,7 @@ static int firesat_probe(struct device *
 
 		mutex_init(&firesat->avc_mutex);
 		init_waitqueue_head(&firesat->avc_wait);
-		atomic_set(&firesat->avc_reply_received, 1);
+		firesat->avc_reply_received = true;
 		mutex_init(&firesat->demux_mutex);
 		INIT_WORK(&firesat->remote_ctrl_work, avc_remote_ctrl_work);
 
@@ -287,16 +283,12 @@ static int firesat_update(struct unit_di
 {
 	struct firesat **firesats = ud->device.driver_data;
 	int k;
-	// loop over subunits
 
 	for (k = 0; k < 2; k++)
-		if (firesats[k]) {
-			firesats[k]->nodeentry = ud->ne;
-
-			if (firesats[k]->isochannel >= 0)
-				try_CMPEstablishPPconnection(firesats[k], firesats[k]->subunit, firesats[k]->isochannel);
-		}
-
+		if (firesats[k] && firesats[k]->isochannel >= 0)
+			try_CMPEstablishPPconnection(firesats[k],
+						     firesats[k]->subunit,
+						     firesats[k]->isochannel);
 	return 0;
 }
 
Index: linux/drivers/media/dvb/firesat/firesat_iso.c
===================================================================
--- linux.orig/drivers/media/dvb/firesat/firesat_iso.c
+++ linux/drivers/media/dvb/firesat/firesat_iso.c
@@ -18,6 +18,7 @@
 
 #include <dma.h>
 #include <iso.h>
+#include <nodemgr.h>
 
 #include "firesat.h"
 
@@ -36,7 +37,7 @@ int setup_iso_channel(struct firesat *fi
 {
 	int result;
 	firesat->iso_handle =
-		hpsb_iso_recv_init(firesat->host,
+		hpsb_iso_recv_init(firesat->ud->ne->host,
 				   256 * 200, //data_buf_size,
 				   256, //buf_packets,
 				   firesat->isochannel,

-- 
Stefan Richter
-=====-==--- =--= ===-=
http://arcgraph.de/sr/




More information about the devel mailing list