Skip to content

Commit b65a372

Browse files
Matt Carlsondavem330
authored andcommitted
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: Matt Carlson <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 165f4d1 commit b65a372

File tree

1 file changed

+32
-24
lines changed
  • drivers/net/ethernet/broadcom

1 file changed

+32
-24
lines changed

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -731,44 +731,52 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum)
731731
tg3_ape_write32(tp, gnt + 4 * locknum, bit);
732732
}
733733

734-
static void tg3_ape_send_event(struct tg3 *tp, u32 event)
734+
static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us)
735735
{
736-
int i;
737736
u32 apedata;
738737

739-
/* NCSI does not support APE events */
740-
if (tg3_flag(tp, APE_HAS_NCSI))
741-
return;
738+
while (timeout_us) {
739+
if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
740+
return -EBUSY;
741+
742+
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
743+
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
744+
break;
745+
746+
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
747+
748+
udelay(10);
749+
timeout_us -= (timeout_us > 10) ? 10 : timeout_us;
750+
}
751+
752+
return timeout_us ? 0 : -EBUSY;
753+
}
754+
755+
static int tg3_ape_send_event(struct tg3 *tp, u32 event)
756+
{
757+
int err;
758+
u32 apedata;
742759

743760
apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
744761
if (apedata != APE_SEG_SIG_MAGIC)
745-
return;
762+
return -EAGAIN;
746763

747764
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
748765
if (!(apedata & APE_FW_STATUS_READY))
749-
return;
766+
return -EAGAIN;
750767

751768
/* Wait for up to 1 millisecond for APE to service previous event. */
752-
for (i = 0; i < 10; i++) {
753-
if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
754-
return;
755-
756-
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
757-
758-
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
759-
tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
760-
event | APE_EVENT_STATUS_EVENT_PENDING);
769+
err = tg3_ape_event_lock(tp, 1000);
770+
if (err)
771+
return err;
761772

762-
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
773+
tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
774+
event | APE_EVENT_STATUS_EVENT_PENDING);
763775

764-
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
765-
break;
776+
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
777+
tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
766778

767-
udelay(100);
768-
}
769-
770-
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
771-
tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
779+
return 0;
772780
}
773781

774782
static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)

0 commit comments

Comments
 (0)