aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/sfc
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2013-08-27 18:04:29 -0400
committerBen Hutchings <bhutchings@solarflare.com>2013-08-29 13:12:04 -0400
commit251111d9a1bd9a26e25446d876156bf265858cb5 (patch)
tree7e4a93373f504f199e8542d772c3fe10f6f3cd70 /drivers/net/ethernet/sfc
parent2f4bcdcca796ca7d385e3f870e552a2d85f0a7c9 (diff)
sfc: Remove unnecessary use of atomic_t
We can set, get and compare-and-exchange without using atomic_t. Change efx_mcdi_iface::state to the enum type we really wanted it to be. Suggested-by: David Miller <davem@davemloft.net> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Diffstat (limited to 'drivers/net/ethernet/sfc')
-rw-r--r--drivers/net/ethernet/sfc/mcdi.c28
-rw-r--r--drivers/net/ethernet/sfc/mcdi.h2
2 files changed, 13 insertions, 17 deletions
diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c
index 89bc194a55f7..c616fb52d1d5 100644
--- a/drivers/net/ethernet/sfc/mcdi.c
+++ b/drivers/net/ethernet/sfc/mcdi.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <asm/cmpxchg.h>
11#include "net_driver.h" 12#include "net_driver.h"
12#include "nic.h" 13#include "nic.h"
13#include "io.h" 14#include "io.h"
@@ -53,7 +54,7 @@ int efx_mcdi_init(struct efx_nic *efx)
53 mcdi = efx_mcdi(efx); 54 mcdi = efx_mcdi(efx);
54 init_waitqueue_head(&mcdi->wq); 55 init_waitqueue_head(&mcdi->wq);
55 spin_lock_init(&mcdi->iface_lock); 56 spin_lock_init(&mcdi->iface_lock);
56 atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); 57 mcdi->state = MCDI_STATE_QUIESCENT;
57 mcdi->mode = MCDI_MODE_POLL; 58 mcdi->mode = MCDI_MODE_POLL;
58 59
59 (void) efx_mcdi_poll_reboot(efx); 60 (void) efx_mcdi_poll_reboot(efx);
@@ -65,8 +66,7 @@ int efx_mcdi_init(struct efx_nic *efx)
65 66
66void efx_mcdi_fini(struct efx_nic *efx) 67void efx_mcdi_fini(struct efx_nic *efx)
67{ 68{
68 BUG_ON(efx->mcdi && 69 BUG_ON(efx->mcdi && efx->mcdi->iface.state != MCDI_STATE_QUIESCENT);
69 atomic_read(&efx->mcdi->iface.state) != MCDI_STATE_QUIESCENT);
70 kfree(efx->mcdi); 70 kfree(efx->mcdi);
71} 71}
72 72
@@ -78,7 +78,7 @@ static void efx_mcdi_send_request(struct efx_nic *efx, unsigned cmd,
78 size_t hdr_len; 78 size_t hdr_len;
79 u32 xflags, seqno; 79 u32 xflags, seqno;
80 80
81 BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT); 81 BUG_ON(mcdi->state == MCDI_STATE_QUIESCENT);
82 82
83 /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */ 83 /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
84 spin_lock_bh(&mcdi->iface_lock); 84 spin_lock_bh(&mcdi->iface_lock);
@@ -258,20 +258,17 @@ static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi)
258 /* Wait until the interface becomes QUIESCENT and we win the race 258 /* Wait until the interface becomes QUIESCENT and we win the race
259 * to mark it RUNNING. */ 259 * to mark it RUNNING. */
260 wait_event(mcdi->wq, 260 wait_event(mcdi->wq,
261 atomic_cmpxchg(&mcdi->state, 261 cmpxchg(&mcdi->state,
262 MCDI_STATE_QUIESCENT, 262 MCDI_STATE_QUIESCENT, MCDI_STATE_RUNNING) ==
263 MCDI_STATE_RUNNING) 263 MCDI_STATE_QUIESCENT);
264 == MCDI_STATE_QUIESCENT);
265} 264}
266 265
267static int efx_mcdi_await_completion(struct efx_nic *efx) 266static int efx_mcdi_await_completion(struct efx_nic *efx)
268{ 267{
269 struct efx_mcdi_iface *mcdi = efx_mcdi(efx); 268 struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
270 269
271 if (wait_event_timeout( 270 if (wait_event_timeout(mcdi->wq, mcdi->state == MCDI_STATE_COMPLETED,
272 mcdi->wq, 271 MCDI_RPC_TIMEOUT) == 0)
273 atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
274 MCDI_RPC_TIMEOUT) == 0)
275 return -ETIMEDOUT; 272 return -ETIMEDOUT;
276 273
277 /* Check if efx_mcdi_set_mode() switched us back to polled completions. 274 /* Check if efx_mcdi_set_mode() switched us back to polled completions.
@@ -296,9 +293,8 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
296 * QUIESCENT. [A subsequent invocation would increment seqno, so would 293 * QUIESCENT. [A subsequent invocation would increment seqno, so would
297 * have failed the seqno check]. 294 * have failed the seqno check].
298 */ 295 */
299 if (atomic_cmpxchg(&mcdi->state, 296 if (cmpxchg(&mcdi->state, MCDI_STATE_RUNNING, MCDI_STATE_COMPLETED) ==
300 MCDI_STATE_RUNNING, 297 MCDI_STATE_RUNNING) {
301 MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) {
302 wake_up(&mcdi->wq); 298 wake_up(&mcdi->wq);
303 return true; 299 return true;
304 } 300 }
@@ -308,7 +304,7 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
308 304
309static void efx_mcdi_release(struct efx_mcdi_iface *mcdi) 305static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
310{ 306{
311 atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); 307 mcdi->state = MCDI_STATE_QUIESCENT;
312 wake_up(&mcdi->wq); 308 wake_up(&mcdi->wq);
313} 309}
314 310
diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h
index 303d9e88a27f..6c0363a2abdf 100644
--- a/drivers/net/ethernet/sfc/mcdi.h
+++ b/drivers/net/ethernet/sfc/mcdi.h
@@ -46,7 +46,7 @@ enum efx_mcdi_mode {
46 * @resp_data_len: Response data (SDU or error) length 46 * @resp_data_len: Response data (SDU or error) length
47 */ 47 */
48struct efx_mcdi_iface { 48struct efx_mcdi_iface {
49 atomic_t state; 49 enum efx_mcdi_state state;
50 enum efx_mcdi_mode mode; 50 enum efx_mcdi_mode mode;
51 wait_queue_head_t wq; 51 wait_queue_head_t wq;
52 spinlock_t iface_lock; 52 spinlock_t iface_lock;