From: Andrew Morton <[email-masked]>

commit 25176ed670121e1e0aae5c8161713c332b786538
Author: Corey Minyard <[email-masked]>
Date:   Tue Apr 21 12:24:04 2009 -0700

    ipmi: fix statistics counting issues
    
    Bela Lubkin noticed that the statistics for send IPMB and LAN commands
    in the IPMI driver could be incremented even if an error occurred.  Move
    the increments to the proper place to avoid this.
    
    Also add some statistics for retransmissions that failed, and some little
    helper functions to neaten up the code a little.
    
    Signed-off-by: Corey Minyard <[email-masked]>
    Cc: Bela Lubkin <[email-masked]>
    Signed-off-by: Andrew Morton <[email-masked]>
    Signed-off-by: Linus Torvalds <[email-masked]>

Signed-off-by: Andrew Morton <[email-masked]>
---

 drivers/char/ipmi/ipmi_msghandler.c |   73 +++++++-------------------
 1 file changed, 22 insertions(+), 51 deletions(-)

diff -puN drivers/char/ipmi/ipmi_msghandler.c~revert-2 drivers/char/ipmi/ipmi_msghandler.c
--- a/drivers/char/ipmi/ipmi_msghandler.c~revert-2
+++ a/drivers/char/ipmi/ipmi_msghandler.c
@@ -285,11 +285,6 @@ enum ipmi_stat_indexes {
 	/* Events that were received with the proper format. */
 	IPMI_STAT_events,
 
-	/* Retransmissions on IPMB that failed. */
-	IPMI_STAT_dropped_rexmit_ipmb_commands,
-
-	/* Retransmissions on LAN that failed. */
-	IPMI_STAT_dropped_rexmit_lan_commands,
 
 	/* This *must* remain last, add new values above this. */
 	IPMI_NUM_STATS
@@ -450,20 +445,6 @@ static DEFINE_MUTEX(smi_watchers_mutex);
 #define ipmi_get_stat(intf, stat) \
 	((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
 
-static int is_lan_addr(struct ipmi_addr *addr)
-{
-	return addr->addr_type == IPMI_LAN_ADDR_TYPE;
-}
-
-static int is_ipmb_addr(struct ipmi_addr *addr)
-{
-	return addr->addr_type == IPMI_IPMB_ADDR_TYPE;
-}
-
-static int is_ipmb_bcast_addr(struct ipmi_addr *addr)
-{
-	return addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE;
-}
 
 static void free_recv_msg_list(struct list_head *q)
 {
@@ -620,7 +601,8 @@ ipmi_addr_equal(struct ipmi_addr *addr1,
 		return (smi_addr1->lun == smi_addr2->lun);
 	}
 
-	if (is_ipmb_addr(addr1) || is_ipmb_bcast_addr(addr1)) {
+	if ((addr1->addr_type == IPMI_IPMB_ADDR_TYPE)
+	    || (addr1->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) {
 		struct ipmi_ipmb_addr *ipmb_addr1
 		    = (struct ipmi_ipmb_addr *) addr1;
 		struct ipmi_ipmb_addr *ipmb_addr2
@@ -630,7 +612,7 @@ ipmi_addr_equal(struct ipmi_addr *addr1,
 			&& (ipmb_addr1->lun == ipmb_addr2->lun));
 	}
 
-	if (is_lan_addr(addr1)) {
+	if (addr1->addr_type == IPMI_LAN_ADDR_TYPE) {
 		struct ipmi_lan_addr *lan_addr1
 			= (struct ipmi_lan_addr *) addr1;
 		struct ipmi_lan_addr *lan_addr2
@@ -662,13 +644,14 @@ int ipmi_validate_addr(struct ipmi_addr 
 	    || (addr->channel < 0))
 		return -EINVAL;
 
-	if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) {
+	if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
+	    || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) {
 		if (len < sizeof(struct ipmi_ipmb_addr))
 			return -EINVAL;
 		return 0;
 	}
 
-	if (is_lan_addr(addr)) {
+	if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
 		if (len < sizeof(struct ipmi_lan_addr))
 			return -EINVAL;
 		return 0;
@@ -1520,7 +1503,8 @@ static int i_ipmi_request(ipmi_user_t   
 			memcpy(&(smi_msg->data[2]), msg->data, msg->data_len);
 		smi_msg->data_size = msg->data_len + 2;
 		ipmi_inc_stat(intf, sent_local_commands);
-	} else if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) {
+	} else if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
+		   || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) {
 		struct ipmi_ipmb_addr *ipmb_addr;
 		unsigned char         ipmb_seq;
 		long                  seqid;
@@ -1599,6 +1583,8 @@ static int i_ipmi_request(ipmi_user_t   
 
 			spin_lock_irqsave(&(intf->seq_lock), flags);
 
+			ipmi_inc_stat(intf, sent_ipmb_commands);
+
 			/*
 			 * Create a sequence number with a 1 second
 			 * timeout and 4 retries.
@@ -1620,8 +1606,6 @@ static int i_ipmi_request(ipmi_user_t   
 				goto out_err;
 			}
 
-			ipmi_inc_stat(intf, sent_ipmb_commands);
-
 			/*
 			 * Store the sequence number in the message,
 			 * so that when the send message response
@@ -1651,7 +1635,7 @@ static int i_ipmi_request(ipmi_user_t   
 			 */
 			spin_unlock_irqrestore(&(intf->seq_lock), flags);
 		}
-	} else if (is_lan_addr(addr)) {
+	} else if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
 		struct ipmi_lan_addr  *lan_addr;
 		unsigned char         ipmb_seq;
 		long                  seqid;
@@ -1712,6 +1696,8 @@ static int i_ipmi_request(ipmi_user_t   
 
 			spin_lock_irqsave(&(intf->seq_lock), flags);
 
+			ipmi_inc_stat(intf, sent_lan_commands);
+
 			/*
 			 * Create a sequence number with a 1 second
 			 * timeout and 4 retries.
@@ -1733,8 +1719,6 @@ static int i_ipmi_request(ipmi_user_t   
 				goto out_err;
 			}
 
-			ipmi_inc_stat(intf, sent_lan_commands);
-
 			/*
 			 * Store the sequence number in the message,
 			 * so that when the send message response
@@ -1953,10 +1937,6 @@ static int stat_file_read_proc(char *pag
 		       ipmi_get_stat(intf, invalid_events));
 	out += sprintf(out, "events:                      %u\n",
 		       ipmi_get_stat(intf, events));
-	out += sprintf(out, "failed rexmit LAN msgs:      %u\n",
-		       ipmi_get_stat(intf, dropped_rexmit_lan_commands));
-	out += sprintf(out, "failed rexmit IPMB msgs:     %u\n",
-		       ipmi_get_stat(intf, dropped_rexmit_ipmb_commands));
 
 	return (out - ((char *) page));
 }
@@ -3750,7 +3730,7 @@ static void check_msg_timeout(ipmi_smi_t
 		list_add_tail(&msg->link, timeouts);
 		if (ent->broadcast)
 			ipmi_inc_stat(intf, timed_out_ipmb_broadcasts);
-		else if (is_lan_addr(&ent->recv_msg->addr))
+		else if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
 			ipmi_inc_stat(intf, timed_out_lan_commands);
 		else
 			ipmi_inc_stat(intf, timed_out_ipmb_commands);
@@ -3764,17 +3744,15 @@ static void check_msg_timeout(ipmi_smi_t
 		 */
 		ent->timeout = MAX_MSG_TIMEOUT;
 		ent->retries_left--;
+		if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
+			ipmi_inc_stat(intf, retransmitted_lan_commands);
+		else
+			ipmi_inc_stat(intf, retransmitted_ipmb_commands);
+
 		smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot,
 					    ent->seqid);
-		if (!smi_msg) {
-			if (is_lan_addr(&ent->recv_msg->addr))
-				ipmi_inc_stat(intf,
-					      dropped_rexmit_lan_commands);
-			else
-				ipmi_inc_stat(intf,
-					      dropped_rexmit_ipmb_commands);
+		if (!smi_msg)
 			return;
-		}
 
 		spin_unlock_irqrestore(&intf->seq_lock, *flags);
 
@@ -3786,17 +3764,10 @@ static void check_msg_timeout(ipmi_smi_t
 		 * resent.
 		 */
 		handlers = intf->handlers;
-		if (handlers) {
-			if (is_lan_addr(&ent->recv_msg->addr))
-				ipmi_inc_stat(intf,
-					      retransmitted_lan_commands);
-			else
-				ipmi_inc_stat(intf,
-					      retransmitted_ipmb_commands);
-
+		if (handlers)
 			intf->handlers->sender(intf->send_info,
 					       smi_msg, 0);
-		} else
+		else
 			ipmi_free_smi_msg(smi_msg);
 
 		spin_lock_irqsave(&intf->seq_lock, *flags);
_