@@ -731,44 +731,52 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum)
731
731
tg3_ape_write32 (tp , gnt + 4 * locknum , bit );
732
732
}
733
733
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 )
735
735
{
736
- int i ;
737
736
u32 apedata ;
738
737
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 ;
742
759
743
760
apedata = tg3_ape_read32 (tp , TG3_APE_SEG_SIG );
744
761
if (apedata != APE_SEG_SIG_MAGIC )
745
- return ;
762
+ return - EAGAIN ;
746
763
747
764
apedata = tg3_ape_read32 (tp , TG3_APE_FW_STATUS );
748
765
if (!(apedata & APE_FW_STATUS_READY ))
749
- return ;
766
+ return - EAGAIN ;
750
767
751
768
/* 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 ;
761
772
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 );
763
775
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 ) ;
766
778
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 ;
772
780
}
773
781
774
782
static void tg3_ape_driver_state_change (struct tg3 * tp , int kind )
0 commit comments