Title: [9823] trunk/drivers/staging/icc: [#4788] bf561 inter-core communication driver: add CMD_SM_ACTIVE
Revision
9823
Author
steven.miao
Date
2011-04-08 02:04:43 -0400 (Fri, 08 Apr 2011)

Log Message

[#4788] bf561 inter-core communication driver: add CMD_SM_ACTIVE
add CMD_SM_ACTIVE to get remote session's acvtive status
code cleanup

Modified Paths

Diff

Modified: trunk/drivers/staging/icc/core/protocol.c (9822 => 9823)


--- trunk/drivers/staging/icc/core/protocol.c	2011-04-07 06:13:48 UTC (rev 9822)
+++ trunk/drivers/staging/icc/core/protocol.c	2011-04-08 06:04:43 UTC (rev 9823)
@@ -16,6 +16,8 @@
 #include <icc.h>
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
+#include <linux/wait.h>
+#include <linux/sched.h>
 
 #define DEBUG
 #ifdef DEBUG
@@ -298,6 +300,27 @@
 					0, SM_SESSION_PACKET_CONNECT_DONE);
 }
 
+int sm_send_session_active(struct sm_session *session, sm_uint32_t remote_ep,
+			sm_uint32_t dst_cpu)
+{
+	return sm_send_control_msg(session, remote_ep, dst_cpu, 0,
+					0, SM_SESSION_PACKET_ACTIVE);
+}
+
+int sm_send_session_active_ack(struct sm_session *session, sm_uint32_t remote_ep,
+			sm_uint32_t dst_cpu)
+{
+	return sm_send_control_msg(session, remote_ep, dst_cpu, SM_OPEN,
+					0, SM_SESSION_PACKET_ACTIVE_ACK);
+}
+
+int sm_send_session_active_noack(struct sm_session *session, sm_uint32_t remote_ep,
+			sm_uint32_t dst_cpu)
+{
+	return sm_send_control_msg(session, remote_ep, dst_cpu, 0,
+					0, SM_SESSION_PACKET_ACTIVE_ACK);
+}
+
 int sm_send_close_ack(struct sm_session *session, sm_uint32_t remote_ep,
 			sm_uint32_t dst_cpu)
 {
@@ -456,6 +479,26 @@
 		return -EAGAIN;
 }
 
+static int sm_get_remote_session_active(sm_uint32_t session_idx, sm_uint32_t dst_ep, sm_uint32_t dst_cpu)
+{
+	struct sm_session *session;
+	session = sm_index_to_session(session_idx);
+	if (!session)
+		return -EINVAL;
+	session->type = SP_SESSION_PACKET;
+	sm_send_session_active(session, dst_ep, dst_cpu);
+	mutex_unlock(&icc_info->sessions_table->lock);
+	wait_event_interruptible_timeout(session->rx_wait,
+				(session->flags & SM_ACTIVE), 5);
+	mutex_lock(&icc_info->sessions_table->lock);
+
+	if (session->flags & SM_ACTIVE) {
+		sm_debug("received active ack\n");
+		return 0;
+	}
+	return -EAGAIN;
+}
+
 static int sm_connect_session(sm_uint32_t session_idx, sm_uint32_t dst_ep, sm_uint32_t dst_cpu)
 {
 	struct sm_session *session;
@@ -652,6 +695,9 @@
 	case CMD_SM_CLOSE:
 		ret = sm_close_session(session_idx);
 		break;
+	case CMD_SM_ACTIVE:
+		ret = sm_get_remote_session_active(session_idx, remote_ep, dst_cpu);
+		break;
 	case CMD_SM_SHUTDOWN:
 		ret = sm_destroy_session(session_idx);
 		break;
@@ -717,6 +763,8 @@
 
 	message->dst = cpu;
 	message->src = "" ^ 1;
+	if (session->handle)
+		session->handle(message, session);
 	list_add(&message->next, &session->rx_messages);
 	session->n_avail++;
 	sm_debug("%s wakeup wait thread\n", __func__);
@@ -758,7 +806,7 @@
 		/* icc queue is FIFO, so handle first message */
 		list_for_each_entry(uncompleted, &session->tx_messages, next) {
 			if ((uncompleted->msg.payload == msg->payload) &&
-					(uncompleted->msg.dst_ep != msg->src_ep)) {
+					(uncompleted->msg.dst_ep == msg->src_ep)) {
 				sm_debug("ack matched free buf %x\n", msg->payload);
 				goto matched;
 			}
@@ -790,6 +838,20 @@
 		sm_debug("%s connect done\n", __func__);
 		session->flags = SM_CONNECT;
 		break;
+	case SM_SESSION_PACKET_ACTIVE:
+		if (session->flags & SM_OPEN)
+			sm_send_session_active_ack(session, msg->src_ep, cpu ^ 1);
+		else
+			sm_send_session_active_noack(session, msg->src_ep, cpu ^ 1);
+		break;
+	case SM_SESSION_PACKET_ACTIVE_ACK:
+		if (session->flags & SM_OPEN) {
+			if (msg->payload == SM_OPEN) {
+				session->flags |= SM_ACTIVE;
+				wake_up(&session->rx_wait);
+			}
+		}
+		break;
 	case SM_SESSION_PACKET_CLOSE:
 		session->remote_ep = 0;
 		session->flags = 0;

Modified: trunk/drivers/staging/icc/include/icc.h (9822 => 9823)


--- trunk/drivers/staging/icc/include/icc.h	2011-04-07 06:13:48 UTC (rev 9822)
+++ trunk/drivers/staging/icc/include/icc.h	2011-04-08 06:04:43 UTC (rev 9823)
@@ -36,6 +36,7 @@
 #define SM_CONNECT 0x1
 #define SM_CONNECTING 0x2
 #define SM_OPEN 0x4
+#define SM_ACTIVE 0x8
 
 #define SM_BAD_ENDPOINT SM_MSG_TYPE(0, 0)
 #define SM_BAD_MSG SM_MSG_TYPE(0, 1)
@@ -142,7 +143,7 @@
 
 struct sm_proto {
 	int (*sendmsg)(struct sm_message *msg, struct sm_session *session);
-	int (*recvmsg)(struct sm_message *msg, struct sm_session *session);
+	int (*recvmsg)(struct sm_msg *msg, struct sm_session *session);
 	int (*shutdown)(struct sm_session *session);
 	int (*error)(struct sm_message *msg, struct sm_session *session);
 };
@@ -168,6 +169,7 @@
 #define CMD_SM_GET_SESSION_STATUS _IO('m', 9)
 #define CMD_SM_OPEN _IO('m', 10)
 #define CMD_SM_CLOSE _IO('m', 11)
+#define CMD_SM_ACTIVE _IO('m', 12)
 
 #define MAX_TASK_NAME 64
 struct sm_node_status {
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to