Commit b65a372b authored by Matt Carlson's avatar Matt Carlson Committed by David S. Miller

tg3: Add common function tg3_ape_event_lock()

by refactoring code in tg3_ape_send_event().  The common function will
be used in subsequent patches.
Signed-off-by: default avatarMatt Carlson <mcarlson@broadcom.com>
Signed-off-by: default avatarMichael Chan <mchan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 165f4d1c
...@@ -731,44 +731,52 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum) ...@@ -731,44 +731,52 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum)
tg3_ape_write32(tp, gnt + 4 * locknum, bit); tg3_ape_write32(tp, gnt + 4 * locknum, bit);
} }
static void tg3_ape_send_event(struct tg3 *tp, u32 event) static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us)
{ {
int i;
u32 apedata; u32 apedata;
/* NCSI does not support APE events */ while (timeout_us) {
if (tg3_flag(tp, APE_HAS_NCSI)) if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
return; return -EBUSY;
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
break;
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
udelay(10);
timeout_us -= (timeout_us > 10) ? 10 : timeout_us;
}
return timeout_us ? 0 : -EBUSY;
}
static int tg3_ape_send_event(struct tg3 *tp, u32 event)
{
int err;
u32 apedata;
apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
if (apedata != APE_SEG_SIG_MAGIC) if (apedata != APE_SEG_SIG_MAGIC)
return; return -EAGAIN;
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
if (!(apedata & APE_FW_STATUS_READY)) if (!(apedata & APE_FW_STATUS_READY))
return; return -EAGAIN;
/* Wait for up to 1 millisecond for APE to service previous event. */ /* Wait for up to 1 millisecond for APE to service previous event. */
for (i = 0; i < 10; i++) { err = tg3_ape_event_lock(tp, 1000);
if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) if (err)
return; return err;
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
event | APE_EVENT_STATUS_EVENT_PENDING);
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
event | APE_EVENT_STATUS_EVENT_PENDING);
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
break; tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
udelay(100); return 0;
}
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
} }
static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment