@@ -156,6 +156,8 @@ static void bnx2x_storm_stats_post(struct bnx2x *bp)
156156 struct eth_query_ramrod_data ramrod_data = {0 };
157157 int i , rc ;
158158
159+ spin_lock_bh (& bp -> stats_lock );
160+
159161 ramrod_data .drv_counter = bp -> stats_counter ++ ;
160162 ramrod_data .collect_port = bp -> port .pmf ? 1 : 0 ;
161163 for_each_queue (bp , i )
@@ -169,6 +171,8 @@ static void bnx2x_storm_stats_post(struct bnx2x *bp)
169171 bp -> spq_left ++ ;
170172 bp -> stats_pending = 1 ;
171173 }
174+
175+ spin_unlock_bh (& bp -> stats_lock );
172176 }
173177}
174178
@@ -734,6 +738,14 @@ static int bnx2x_storm_stats_update(struct bnx2x *bp)
734738 struct host_func_stats * fstats = bnx2x_sp (bp , func_stats );
735739 struct bnx2x_eth_stats * estats = & bp -> eth_stats ;
736740 int i ;
741+ u16 cur_stats_counter ;
742+
743+ /* Make sure we use the value of the counter
744+ * used for sending the last stats ramrod.
745+ */
746+ spin_lock_bh (& bp -> stats_lock );
747+ cur_stats_counter = bp -> stats_counter - 1 ;
748+ spin_unlock_bh (& bp -> stats_lock );
737749
738750 memcpy (& (fstats -> total_bytes_received_hi ),
739751 & (bnx2x_sp (bp , func_stats_base )-> total_bytes_received_hi ),
@@ -761,25 +773,22 @@ static int bnx2x_storm_stats_update(struct bnx2x *bp)
761773 u32 diff ;
762774
763775 /* are storm stats valid? */
764- if ((u16 )(le16_to_cpu (xclient -> stats_counter ) + 1 ) !=
765- bp -> stats_counter ) {
776+ if (le16_to_cpu (xclient -> stats_counter ) != cur_stats_counter ) {
766777 DP (BNX2X_MSG_STATS , "[%d] stats not updated by xstorm"
767778 " xstorm counter (0x%x) != stats_counter (0x%x)\n" ,
768- i , xclient -> stats_counter , bp -> stats_counter );
779+ i , xclient -> stats_counter , cur_stats_counter + 1 );
769780 return -1 ;
770781 }
771- if ((u16 )(le16_to_cpu (tclient -> stats_counter ) + 1 ) !=
772- bp -> stats_counter ) {
782+ if (le16_to_cpu (tclient -> stats_counter ) != cur_stats_counter ) {
773783 DP (BNX2X_MSG_STATS , "[%d] stats not updated by tstorm"
774784 " tstorm counter (0x%x) != stats_counter (0x%x)\n" ,
775- i , tclient -> stats_counter , bp -> stats_counter );
785+ i , tclient -> stats_counter , cur_stats_counter + 1 );
776786 return -2 ;
777787 }
778- if ((u16 )(le16_to_cpu (uclient -> stats_counter ) + 1 ) !=
779- bp -> stats_counter ) {
788+ if (le16_to_cpu (uclient -> stats_counter ) != cur_stats_counter ) {
780789 DP (BNX2X_MSG_STATS , "[%d] stats not updated by ustorm"
781790 " ustorm counter (0x%x) != stats_counter (0x%x)\n" ,
782- i , uclient -> stats_counter , bp -> stats_counter );
791+ i , uclient -> stats_counter , cur_stats_counter + 1 );
783792 return -4 ;
784793 }
785794
@@ -1216,16 +1225,18 @@ static const struct {
12161225
12171226void bnx2x_stats_handle (struct bnx2x * bp , enum bnx2x_stats_event event )
12181227{
1219- enum bnx2x_stats_state state = bp -> stats_state ;
1228+ enum bnx2x_stats_state state ;
12201229
12211230 if (unlikely (bp -> panic ))
12221231 return ;
12231232
1224- bnx2x_stats_stm [state ][event ].action (bp );
1233+ /* Protect a state change flow */
1234+ spin_lock_bh (& bp -> stats_lock );
1235+ state = bp -> stats_state ;
12251236 bp -> stats_state = bnx2x_stats_stm [state ][event ].next_state ;
1237+ spin_unlock_bh (& bp -> stats_lock );
12261238
1227- /* Make sure the state has been "changed" */
1228- smp_wmb ();
1239+ bnx2x_stats_stm [state ][event ].action (bp );
12291240
12301241 if ((event != STATS_EVENT_UPDATE ) || netif_msg_timer (bp ))
12311242 DP (BNX2X_MSG_STATS , "state %d -> event %d -> state %d\n" ,
0 commit comments