提交 251111d9 编写于 作者: B Ben Hutchings

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: NDavid Miller <davem@davemloft.net>
Signed-off-by: NBen Hutchings <bhutchings@solarflare.com>
上级 2f4bcdcc
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/cmpxchg.h>
#include "net_driver.h" #include "net_driver.h"
#include "nic.h" #include "nic.h"
#include "io.h" #include "io.h"
...@@ -53,7 +54,7 @@ int efx_mcdi_init(struct efx_nic *efx) ...@@ -53,7 +54,7 @@ int efx_mcdi_init(struct efx_nic *efx)
mcdi = efx_mcdi(efx); mcdi = efx_mcdi(efx);
init_waitqueue_head(&mcdi->wq); init_waitqueue_head(&mcdi->wq);
spin_lock_init(&mcdi->iface_lock); spin_lock_init(&mcdi->iface_lock);
atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); mcdi->state = MCDI_STATE_QUIESCENT;
mcdi->mode = MCDI_MODE_POLL; mcdi->mode = MCDI_MODE_POLL;
(void) efx_mcdi_poll_reboot(efx); (void) efx_mcdi_poll_reboot(efx);
...@@ -65,8 +66,7 @@ int efx_mcdi_init(struct efx_nic *efx) ...@@ -65,8 +66,7 @@ int efx_mcdi_init(struct efx_nic *efx)
void efx_mcdi_fini(struct efx_nic *efx) void efx_mcdi_fini(struct efx_nic *efx)
{ {
BUG_ON(efx->mcdi && BUG_ON(efx->mcdi && efx->mcdi->iface.state != MCDI_STATE_QUIESCENT);
atomic_read(&efx->mcdi->iface.state) != MCDI_STATE_QUIESCENT);
kfree(efx->mcdi); kfree(efx->mcdi);
} }
...@@ -78,7 +78,7 @@ static void efx_mcdi_send_request(struct efx_nic *efx, unsigned cmd, ...@@ -78,7 +78,7 @@ static void efx_mcdi_send_request(struct efx_nic *efx, unsigned cmd,
size_t hdr_len; size_t hdr_len;
u32 xflags, seqno; u32 xflags, seqno;
BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT); BUG_ON(mcdi->state == MCDI_STATE_QUIESCENT);
/* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */ /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
spin_lock_bh(&mcdi->iface_lock); spin_lock_bh(&mcdi->iface_lock);
...@@ -258,19 +258,16 @@ static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi) ...@@ -258,19 +258,16 @@ static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi)
/* Wait until the interface becomes QUIESCENT and we win the race /* Wait until the interface becomes QUIESCENT and we win the race
* to mark it RUNNING. */ * to mark it RUNNING. */
wait_event(mcdi->wq, wait_event(mcdi->wq,
atomic_cmpxchg(&mcdi->state, cmpxchg(&mcdi->state,
MCDI_STATE_QUIESCENT, MCDI_STATE_QUIESCENT, MCDI_STATE_RUNNING) ==
MCDI_STATE_RUNNING) MCDI_STATE_QUIESCENT);
== MCDI_STATE_QUIESCENT);
} }
static int efx_mcdi_await_completion(struct efx_nic *efx) static int efx_mcdi_await_completion(struct efx_nic *efx)
{ {
struct efx_mcdi_iface *mcdi = efx_mcdi(efx); struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
if (wait_event_timeout( if (wait_event_timeout(mcdi->wq, mcdi->state == MCDI_STATE_COMPLETED,
mcdi->wq,
atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
MCDI_RPC_TIMEOUT) == 0) MCDI_RPC_TIMEOUT) == 0)
return -ETIMEDOUT; return -ETIMEDOUT;
...@@ -296,9 +293,8 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi) ...@@ -296,9 +293,8 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
* QUIESCENT. [A subsequent invocation would increment seqno, so would * QUIESCENT. [A subsequent invocation would increment seqno, so would
* have failed the seqno check]. * have failed the seqno check].
*/ */
if (atomic_cmpxchg(&mcdi->state, if (cmpxchg(&mcdi->state, MCDI_STATE_RUNNING, MCDI_STATE_COMPLETED) ==
MCDI_STATE_RUNNING, MCDI_STATE_RUNNING) {
MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) {
wake_up(&mcdi->wq); wake_up(&mcdi->wq);
return true; return true;
} }
...@@ -308,7 +304,7 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi) ...@@ -308,7 +304,7 @@ static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
static void efx_mcdi_release(struct efx_mcdi_iface *mcdi) static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
{ {
atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); mcdi->state = MCDI_STATE_QUIESCENT;
wake_up(&mcdi->wq); wake_up(&mcdi->wq);
} }
......
...@@ -46,7 +46,7 @@ enum efx_mcdi_mode { ...@@ -46,7 +46,7 @@ enum efx_mcdi_mode {
* @resp_data_len: Response data (SDU or error) length * @resp_data_len: Response data (SDU or error) length
*/ */
struct efx_mcdi_iface { struct efx_mcdi_iface {
atomic_t state; enum efx_mcdi_state state;
enum efx_mcdi_mode mode; enum efx_mcdi_mode mode;
wait_queue_head_t wq; wait_queue_head_t wq;
spinlock_t iface_lock; spinlock_t iface_lock;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册