@@ -752,6 +752,85 @@ static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us)
752
752
return timeout_us ? 0 : - EBUSY ;
753
753
}
754
754
755
+ static int tg3_ape_wait_for_event (struct tg3 * tp , u32 timeout_us )
756
+ {
757
+ u32 i , apedata ;
758
+
759
+ for (i = 0 ; i < timeout_us / 10 ; i ++ ) {
760
+ apedata = tg3_ape_read32 (tp , TG3_APE_EVENT_STATUS );
761
+
762
+ if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING ))
763
+ break ;
764
+
765
+ udelay (10 );
766
+ }
767
+
768
+ return i == timeout_us / 10 ;
769
+ }
770
+
771
+ int tg3_ape_scratchpad_read (struct tg3 * tp , u32 * data , u32 base_off , u32 len )
772
+ {
773
+ int err ;
774
+ u32 i , bufoff , msgoff , maxlen , apedata ;
775
+
776
+ if (!tg3_flag (tp , APE_HAS_NCSI ))
777
+ return 0 ;
778
+
779
+ apedata = tg3_ape_read32 (tp , TG3_APE_SEG_SIG );
780
+ if (apedata != APE_SEG_SIG_MAGIC )
781
+ return - ENODEV ;
782
+
783
+ apedata = tg3_ape_read32 (tp , TG3_APE_FW_STATUS );
784
+ if (!(apedata & APE_FW_STATUS_READY ))
785
+ return - EAGAIN ;
786
+
787
+ bufoff = tg3_ape_read32 (tp , TG3_APE_SEG_MSG_BUF_OFF ) +
788
+ TG3_APE_SHMEM_BASE ;
789
+ msgoff = bufoff + 2 * sizeof (u32 );
790
+ maxlen = tg3_ape_read32 (tp , TG3_APE_SEG_MSG_BUF_LEN );
791
+
792
+ while (len ) {
793
+ u32 length ;
794
+
795
+ /* Cap xfer sizes to scratchpad limits. */
796
+ length = (len > maxlen ) ? maxlen : len ;
797
+ len -= length ;
798
+
799
+ apedata = tg3_ape_read32 (tp , TG3_APE_FW_STATUS );
800
+ if (!(apedata & APE_FW_STATUS_READY ))
801
+ return - EAGAIN ;
802
+
803
+ /* Wait for up to 1 msec for APE to service previous event. */
804
+ err = tg3_ape_event_lock (tp , 1000 );
805
+ if (err )
806
+ return err ;
807
+
808
+ apedata = APE_EVENT_STATUS_DRIVER_EVNT |
809
+ APE_EVENT_STATUS_SCRTCHPD_READ |
810
+ APE_EVENT_STATUS_EVENT_PENDING ;
811
+ tg3_ape_write32 (tp , TG3_APE_EVENT_STATUS , apedata );
812
+
813
+ tg3_ape_write32 (tp , bufoff , base_off );
814
+ tg3_ape_write32 (tp , bufoff + sizeof (u32 ), length );
815
+
816
+ tg3_ape_unlock (tp , TG3_APE_LOCK_MEM );
817
+ tg3_ape_write32 (tp , TG3_APE_EVENT , APE_EVENT_1 );
818
+
819
+ base_off += length ;
820
+
821
+ if (tg3_ape_wait_for_event (tp , 30000 ))
822
+ return - EAGAIN ;
823
+
824
+ for (i = 0 ; length ; i += 4 , length -= 4 ) {
825
+ u32 val = tg3_ape_read32 (tp , msgoff + i );
826
+ memcpy (data , & val , sizeof (u32 ));
827
+ data ++ ;
828
+ }
829
+ }
830
+
831
+ return 0 ;
832
+ }
833
+
755
834
static int tg3_ape_send_event (struct tg3 * tp , u32 event )
756
835
{
757
836
int err ;
0 commit comments