diff options
author | Vladislav Zolotarov <vladz@broadcom.com> | 2010-07-21 01:59:14 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-07-21 14:11:55 -0400 |
commit | d0996faeec8b3ab5bda65074c274bc67baf13501 (patch) | |
tree | 87d7e5c799e3dc2426c9f4245ebf0c0e17df7007 /drivers | |
parent | a13773a53faa28cf79982601b6fc9ddb0ca45f36 (diff) |
bnx2x: Protect statistics ramrod and sequence number
Bug fix: Protect statistics ramrod sending code and a statistics counter update
with a spinlock. Otherwise there was a race condition that would allow sending
a statistics ramrods with the same sequence number or with sequence numbers not
in a natural order, which would cause a FW assert.
Signed-off-by: Vladislav Zolotarov <vladz@broadcom.com>
Signed-off-by: Dmitry Kravkov <dmitry@broadcom.com>
Signed-off-by: Eilon Greenstein <eilong@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/bnx2x_main.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/drivers/net/bnx2x_main.c b/drivers/net/bnx2x_main.c index 3dc876ce6e1f..b86e47be9967 100644 --- a/drivers/net/bnx2x_main.c +++ b/drivers/net/bnx2x_main.c | |||
@@ -3789,6 +3789,8 @@ static void bnx2x_storm_stats_post(struct bnx2x *bp) | |||
3789 | struct eth_query_ramrod_data ramrod_data = {0}; | 3789 | struct eth_query_ramrod_data ramrod_data = {0}; |
3790 | int i, rc; | 3790 | int i, rc; |
3791 | 3791 | ||
3792 | spin_lock_bh(&bp->stats_lock); | ||
3793 | |||
3792 | ramrod_data.drv_counter = bp->stats_counter++; | 3794 | ramrod_data.drv_counter = bp->stats_counter++; |
3793 | ramrod_data.collect_port = bp->port.pmf ? 1 : 0; | 3795 | ramrod_data.collect_port = bp->port.pmf ? 1 : 0; |
3794 | for_each_queue(bp, i) | 3796 | for_each_queue(bp, i) |
@@ -3802,6 +3804,8 @@ static void bnx2x_storm_stats_post(struct bnx2x *bp) | |||
3802 | bp->spq_left++; | 3804 | bp->spq_left++; |
3803 | bp->stats_pending = 1; | 3805 | bp->stats_pending = 1; |
3804 | } | 3806 | } |
3807 | |||
3808 | spin_unlock_bh(&bp->stats_lock); | ||
3805 | } | 3809 | } |
3806 | } | 3810 | } |
3807 | 3811 | ||
@@ -4367,6 +4371,14 @@ static int bnx2x_storm_stats_update(struct bnx2x *bp) | |||
4367 | struct host_func_stats *fstats = bnx2x_sp(bp, func_stats); | 4371 | struct host_func_stats *fstats = bnx2x_sp(bp, func_stats); |
4368 | struct bnx2x_eth_stats *estats = &bp->eth_stats; | 4372 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
4369 | int i; | 4373 | int i; |
4374 | u16 cur_stats_counter; | ||
4375 | |||
4376 | /* Make sure we use the value of the counter | ||
4377 | * used for sending the last stats ramrod. | ||
4378 | */ | ||
4379 | spin_lock_bh(&bp->stats_lock); | ||
4380 | cur_stats_counter = bp->stats_counter - 1; | ||
4381 | spin_unlock_bh(&bp->stats_lock); | ||
4370 | 4382 | ||
4371 | memcpy(&(fstats->total_bytes_received_hi), | 4383 | memcpy(&(fstats->total_bytes_received_hi), |
4372 | &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi), | 4384 | &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi), |
@@ -4394,25 +4406,22 @@ static int bnx2x_storm_stats_update(struct bnx2x *bp) | |||
4394 | u32 diff; | 4406 | u32 diff; |
4395 | 4407 | ||
4396 | /* are storm stats valid? */ | 4408 | /* are storm stats valid? */ |
4397 | if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) != | 4409 | if (le16_to_cpu(xclient->stats_counter) != cur_stats_counter) { |
4398 | bp->stats_counter) { | ||
4399 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm" | 4410 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm" |
4400 | " xstorm counter (0x%x) != stats_counter (0x%x)\n", | 4411 | " xstorm counter (0x%x) != stats_counter (0x%x)\n", |
4401 | i, xclient->stats_counter, bp->stats_counter); | 4412 | i, xclient->stats_counter, cur_stats_counter + 1); |
4402 | return -1; | 4413 | return -1; |
4403 | } | 4414 | } |
4404 | if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) != | 4415 | if (le16_to_cpu(tclient->stats_counter) != cur_stats_counter) { |
4405 | bp->stats_counter) { | ||
4406 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm" | 4416 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm" |
4407 | " tstorm counter (0x%x) != stats_counter (0x%x)\n", | 4417 | " tstorm counter (0x%x) != stats_counter (0x%x)\n", |
4408 | i, tclient->stats_counter, bp->stats_counter); | 4418 | i, tclient->stats_counter, cur_stats_counter + 1); |
4409 | return -2; | 4419 | return -2; |
4410 | } | 4420 | } |
4411 | if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) != | 4421 | if (le16_to_cpu(uclient->stats_counter) != cur_stats_counter) { |
4412 | bp->stats_counter) { | ||
4413 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm" | 4422 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm" |
4414 | " ustorm counter (0x%x) != stats_counter (0x%x)\n", | 4423 | " ustorm counter (0x%x) != stats_counter (0x%x)\n", |
4415 | i, uclient->stats_counter, bp->stats_counter); | 4424 | i, uclient->stats_counter, cur_stats_counter + 1); |
4416 | return -4; | 4425 | return -4; |
4417 | } | 4426 | } |
4418 | 4427 | ||