aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet
diff options
context:
space:
mode:
authorYuval Mintz <Yuval.Mintz@qlogic.com>2015-06-01 08:08:18 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-01 15:04:31 -0400
commitc6e36d8c1a76be7a7afa2669483857dadec1e99c (patch)
tree6ba06f3353eaff41b0a9ccc01d9418033a3e4ed5 /drivers/net/ethernet
parent31a418986a5852034d520a5bab546821ff1ccf3d (diff)
bnx2x: Move statistics implementation into semaphores
Commit dff173de84958 ("bnx2x: Fix statistics locking scheme") changed the bnx2x locking around statistics state into using a mutex - but the lock is being accessed via a timer which is forbidden. [If compiled with CONFIG_DEBUG_MUTEXES, logs show a warning about accessing the mutex in interrupt context] This moves the implementation into using a semaphore [with size '1'] instead. Signed-off-by: Yuval Mintz <Yuval.Mintz@qlogic.com> Signed-off-by: Ariel Elior <Ariel.Elior@qlogic.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet')
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c9
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c20
3 files changed, 20 insertions, 11 deletions
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index a3b0f7a0c61e..1f82a04ce01a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -1774,7 +1774,7 @@ struct bnx2x {
1774 int stats_state; 1774 int stats_state;
1775 1775
1776 /* used for synchronization of concurrent threads statistics handling */ 1776 /* used for synchronization of concurrent threads statistics handling */
1777 struct mutex stats_lock; 1777 struct semaphore stats_lock;
1778 1778
1779 /* used by dmae command loader */ 1779 /* used by dmae command loader */
1780 struct dmae_command stats_dmae; 1780 struct dmae_command stats_dmae;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index fd52ce95127e..33501bcddc48 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -12054,7 +12054,7 @@ static int bnx2x_init_bp(struct bnx2x *bp)
12054 mutex_init(&bp->port.phy_mutex); 12054 mutex_init(&bp->port.phy_mutex);
12055 mutex_init(&bp->fw_mb_mutex); 12055 mutex_init(&bp->fw_mb_mutex);
12056 mutex_init(&bp->drv_info_mutex); 12056 mutex_init(&bp->drv_info_mutex);
12057 mutex_init(&bp->stats_lock); 12057 sema_init(&bp->stats_lock, 1);
12058 bp->drv_info_mng_owner = false; 12058 bp->drv_info_mng_owner = false;
12059 12059
12060 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); 12060 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
@@ -13690,9 +13690,10 @@ static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
13690 cancel_delayed_work_sync(&bp->sp_task); 13690 cancel_delayed_work_sync(&bp->sp_task);
13691 cancel_delayed_work_sync(&bp->period_task); 13691 cancel_delayed_work_sync(&bp->period_task);
13692 13692
13693 mutex_lock(&bp->stats_lock); 13693 if (!down_timeout(&bp->stats_lock, HZ / 10)) {
13694 bp->stats_state = STATS_STATE_DISABLED; 13694 bp->stats_state = STATS_STATE_DISABLED;
13695 mutex_unlock(&bp->stats_lock); 13695 up(&bp->stats_lock);
13696 }
13696 13697
13697 bnx2x_save_statistics(bp); 13698 bnx2x_save_statistics(bp);
13698 13699
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
index 266b055c2360..69d699f0730a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
@@ -1372,19 +1372,23 @@ void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
1372 * that context in case someone is in the middle of a transition. 1372 * that context in case someone is in the middle of a transition.
1373 * For other events, wait a bit until lock is taken. 1373 * For other events, wait a bit until lock is taken.
1374 */ 1374 */
1375 if (!mutex_trylock(&bp->stats_lock)) { 1375 if (down_trylock(&bp->stats_lock)) {
1376 if (event == STATS_EVENT_UPDATE) 1376 if (event == STATS_EVENT_UPDATE)
1377 return; 1377 return;
1378 1378
1379 DP(BNX2X_MSG_STATS, 1379 DP(BNX2X_MSG_STATS,
1380 "Unlikely stats' lock contention [event %d]\n", event); 1380 "Unlikely stats' lock contention [event %d]\n", event);
1381 mutex_lock(&bp->stats_lock); 1381 if (unlikely(down_timeout(&bp->stats_lock, HZ / 10))) {
1382 BNX2X_ERR("Failed to take stats lock [event %d]\n",
1383 event);
1384 return;
1385 }
1382 } 1386 }
1383 1387
1384 bnx2x_stats_stm[state][event].action(bp); 1388 bnx2x_stats_stm[state][event].action(bp);
1385 bp->stats_state = bnx2x_stats_stm[state][event].next_state; 1389 bp->stats_state = bnx2x_stats_stm[state][event].next_state;
1386 1390
1387 mutex_unlock(&bp->stats_lock); 1391 up(&bp->stats_lock);
1388 1392
1389 if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp)) 1393 if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp))
1390 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", 1394 DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
@@ -1970,7 +1974,11 @@ int bnx2x_stats_safe_exec(struct bnx2x *bp,
1970 /* Wait for statistics to end [while blocking further requests], 1974 /* Wait for statistics to end [while blocking further requests],
1971 * then run supplied function 'safely'. 1975 * then run supplied function 'safely'.
1972 */ 1976 */
1973 mutex_lock(&bp->stats_lock); 1977 rc = down_timeout(&bp->stats_lock, HZ / 10);
1978 if (unlikely(rc)) {
1979 BNX2X_ERR("Failed to take statistics lock for safe execution\n");
1980 goto out_no_lock;
1981 }
1974 1982
1975 bnx2x_stats_comp(bp); 1983 bnx2x_stats_comp(bp);
1976 while (bp->stats_pending && cnt--) 1984 while (bp->stats_pending && cnt--)
@@ -1988,7 +1996,7 @@ out:
1988 /* No need to restart statistics - if they're enabled, the timer 1996 /* No need to restart statistics - if they're enabled, the timer
1989 * will restart the statistics. 1997 * will restart the statistics.
1990 */ 1998 */
1991 mutex_unlock(&bp->stats_lock); 1999 up(&bp->stats_lock);
1992 2000out_no_lock:
1993 return rc; 2001 return rc;
1994} 2002}