@@ -32,47 +32,15 @@ static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs)
32
32
33
33
/* String, offset, and register size in bytes if different from 4 bytes */
34
34
static const struct mt7530_mib_desc mt7530_mib [] = {
35
- MIB_DESC (1 , 0x00 , "TxDrop" ),
36
- MIB_DESC (1 , 0x04 , "TxCrcErr" ),
37
- MIB_DESC (1 , 0x08 , "TxUnicast" ),
38
- MIB_DESC (1 , 0x0c , "TxMulticast" ),
39
- MIB_DESC (1 , 0x10 , "TxBroadcast" ),
40
- MIB_DESC (1 , 0x14 , "TxCollision" ),
41
- MIB_DESC (1 , 0x18 , "TxSingleCollision" ),
42
- MIB_DESC (1 , 0x1c , "TxMultipleCollision" ),
43
- MIB_DESC (1 , 0x20 , "TxDeferred" ),
44
- MIB_DESC (1 , 0x24 , "TxLateCollision" ),
45
- MIB_DESC (1 , 0x28 , "TxExcessiveCollistion" ),
46
- MIB_DESC (1 , 0x2c , "TxPause" ),
47
- MIB_DESC (1 , 0x30 , "TxPktSz64" ),
48
- MIB_DESC (1 , 0x34 , "TxPktSz65To127" ),
49
- MIB_DESC (1 , 0x38 , "TxPktSz128To255" ),
50
- MIB_DESC (1 , 0x3c , "TxPktSz256To511" ),
51
- MIB_DESC (1 , 0x40 , "TxPktSz512To1023" ),
52
- MIB_DESC (1 , 0x44 , "Tx1024ToMax" ),
53
- MIB_DESC (2 , 0x48 , "TxBytes" ),
54
- MIB_DESC (1 , 0x60 , "RxDrop" ),
55
- MIB_DESC (1 , 0x64 , "RxFiltering" ),
56
- MIB_DESC (1 , 0x68 , "RxUnicast" ),
57
- MIB_DESC (1 , 0x6c , "RxMulticast" ),
58
- MIB_DESC (1 , 0x70 , "RxBroadcast" ),
59
- MIB_DESC (1 , 0x74 , "RxAlignErr" ),
60
- MIB_DESC (1 , 0x78 , "RxCrcErr" ),
61
- MIB_DESC (1 , 0x7c , "RxUnderSizeErr" ),
62
- MIB_DESC (1 , 0x80 , "RxFragErr" ),
63
- MIB_DESC (1 , 0x84 , "RxOverSzErr" ),
64
- MIB_DESC (1 , 0x88 , "RxJabberErr" ),
65
- MIB_DESC (1 , 0x8c , "RxPause" ),
66
- MIB_DESC (1 , 0x90 , "RxPktSz64" ),
67
- MIB_DESC (1 , 0x94 , "RxPktSz65To127" ),
68
- MIB_DESC (1 , 0x98 , "RxPktSz128To255" ),
69
- MIB_DESC (1 , 0x9c , "RxPktSz256To511" ),
70
- MIB_DESC (1 , 0xa0 , "RxPktSz512To1023" ),
71
- MIB_DESC (1 , 0xa4 , "RxPktSz1024ToMax" ),
72
- MIB_DESC (2 , 0xa8 , "RxBytes" ),
73
- MIB_DESC (1 , 0xb0 , "RxCtrlDrop" ),
74
- MIB_DESC (1 , 0xb4 , "RxIngressDrop" ),
75
- MIB_DESC (1 , 0xb8 , "RxArlDrop" ),
35
+ MIB_DESC (1 , MT7530_PORT_MIB_TX_DROP , "TxDrop" ),
36
+ MIB_DESC (1 , MT7530_PORT_MIB_TX_CRC_ERR , "TxCrcErr" ),
37
+ MIB_DESC (1 , MT7530_PORT_MIB_TX_COLLISION , "TxCollision" ),
38
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_DROP , "RxDrop" ),
39
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_FILTERING , "RxFiltering" ),
40
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_CRC_ERR , "RxCrcErr" ),
41
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_CTRL_DROP , "RxCtrlDrop" ),
42
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_INGRESS_DROP , "RxIngressDrop" ),
43
+ MIB_DESC (1 , MT7530_PORT_MIB_RX_ARL_DROP , "RxArlDrop" ),
76
44
};
77
45
78
46
static void
@@ -789,24 +757,34 @@ mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset,
789
757
ethtool_puts (& data , mt7530_mib [i ].name );
790
758
}
791
759
760
+ static void
761
+ mt7530_read_port_stats (struct mt7530_priv * priv , int port ,
762
+ u32 offset , u8 size , uint64_t * data )
763
+ {
764
+ u32 val , reg = MT7530_PORT_MIB_COUNTER (port ) + offset ;
765
+
766
+ val = mt7530_read (priv , reg );
767
+ * data = val ;
768
+
769
+ if (size == 2 ) {
770
+ val = mt7530_read (priv , reg + 4 );
771
+ * data |= (u64 )val << 32 ;
772
+ }
773
+ }
774
+
792
775
static void
793
776
mt7530_get_ethtool_stats (struct dsa_switch * ds , int port ,
794
777
uint64_t * data )
795
778
{
796
779
struct mt7530_priv * priv = ds -> priv ;
797
780
const struct mt7530_mib_desc * mib ;
798
- u32 reg , i ;
799
- u64 hi ;
781
+ int i ;
800
782
801
783
for (i = 0 ; i < ARRAY_SIZE (mt7530_mib ); i ++ ) {
802
784
mib = & mt7530_mib [i ];
803
- reg = MT7530_PORT_MIB_COUNTER (port ) + mib -> offset ;
804
785
805
- data [i ] = mt7530_read (priv , reg );
806
- if (mib -> size == 2 ) {
807
- hi = mt7530_read (priv , reg + 4 );
808
- data [i ] |= hi << 32 ;
809
- }
786
+ mt7530_read_port_stats (priv , port , mib -> offset , mib -> size ,
787
+ data + i );
810
788
}
811
789
}
812
790
@@ -819,6 +797,172 @@ mt7530_get_sset_count(struct dsa_switch *ds, int port, int sset)
819
797
return ARRAY_SIZE (mt7530_mib );
820
798
}
821
799
800
+ static void mt7530_get_eth_mac_stats (struct dsa_switch * ds , int port ,
801
+ struct ethtool_eth_mac_stats * mac_stats )
802
+ {
803
+ struct mt7530_priv * priv = ds -> priv ;
804
+
805
+ /* MIB counter doesn't provide a FramesTransmittedOK but instead
806
+ * provide stats for Unicast, Broadcast and Multicast frames separately.
807
+ * To simulate a global frame counter, read Unicast and addition Multicast
808
+ * and Broadcast later
809
+ */
810
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_UNICAST , 1 ,
811
+ & mac_stats -> FramesTransmittedOK );
812
+
813
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_SINGLE_COLLISION , 1 ,
814
+ & mac_stats -> SingleCollisionFrames );
815
+
816
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_MULTIPLE_COLLISION , 1 ,
817
+ & mac_stats -> MultipleCollisionFrames );
818
+
819
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_UNICAST , 1 ,
820
+ & mac_stats -> FramesReceivedOK );
821
+
822
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_BYTES , 2 ,
823
+ & mac_stats -> OctetsTransmittedOK );
824
+
825
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_ALIGN_ERR , 1 ,
826
+ & mac_stats -> AlignmentErrors );
827
+
828
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_DEFERRED , 1 ,
829
+ & mac_stats -> FramesWithDeferredXmissions );
830
+
831
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_LATE_COLLISION , 1 ,
832
+ & mac_stats -> LateCollisions );
833
+
834
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_EXCESSIVE_COLLISION , 1 ,
835
+ & mac_stats -> FramesAbortedDueToXSColls );
836
+
837
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_BYTES , 2 ,
838
+ & mac_stats -> OctetsReceivedOK );
839
+
840
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_MULTICAST , 1 ,
841
+ & mac_stats -> MulticastFramesXmittedOK );
842
+ mac_stats -> FramesTransmittedOK += mac_stats -> MulticastFramesXmittedOK ;
843
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_BROADCAST , 1 ,
844
+ & mac_stats -> BroadcastFramesXmittedOK );
845
+ mac_stats -> FramesTransmittedOK += mac_stats -> BroadcastFramesXmittedOK ;
846
+
847
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_MULTICAST , 1 ,
848
+ & mac_stats -> MulticastFramesReceivedOK );
849
+ mac_stats -> FramesReceivedOK += mac_stats -> MulticastFramesReceivedOK ;
850
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_BROADCAST , 1 ,
851
+ & mac_stats -> BroadcastFramesReceivedOK );
852
+ mac_stats -> FramesReceivedOK += mac_stats -> BroadcastFramesReceivedOK ;
853
+ }
854
+
855
+ static const struct ethtool_rmon_hist_range mt7530_rmon_ranges [] = {
856
+ { 0 , 64 },
857
+ { 65 , 127 },
858
+ { 128 , 255 },
859
+ { 256 , 511 },
860
+ { 512 , 1023 },
861
+ { 1024 , MT7530_MAX_MTU },
862
+ {}
863
+ };
864
+
865
+ static void mt7530_get_rmon_stats (struct dsa_switch * ds , int port ,
866
+ struct ethtool_rmon_stats * rmon_stats ,
867
+ const struct ethtool_rmon_hist_range * * ranges )
868
+ {
869
+ struct mt7530_priv * priv = ds -> priv ;
870
+
871
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_UNDER_SIZE_ERR , 1 ,
872
+ & rmon_stats -> undersize_pkts );
873
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_OVER_SZ_ERR , 1 ,
874
+ & rmon_stats -> oversize_pkts );
875
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_FRAG_ERR , 1 ,
876
+ & rmon_stats -> fragments );
877
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_JABBER_ERR , 1 ,
878
+ & rmon_stats -> jabbers );
879
+
880
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_64 , 1 ,
881
+ & rmon_stats -> hist [0 ]);
882
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_65_TO_127 , 1 ,
883
+ & rmon_stats -> hist [1 ]);
884
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_128_TO_255 , 1 ,
885
+ & rmon_stats -> hist [2 ]);
886
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_256_TO_511 , 1 ,
887
+ & rmon_stats -> hist [3 ]);
888
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_512_TO_1023 , 1 ,
889
+ & rmon_stats -> hist [4 ]);
890
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PKT_SZ_1024_TO_MAX , 1 ,
891
+ & rmon_stats -> hist [5 ]);
892
+
893
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_64 , 1 ,
894
+ & rmon_stats -> hist_tx [0 ]);
895
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_65_TO_127 , 1 ,
896
+ & rmon_stats -> hist_tx [1 ]);
897
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_128_TO_255 , 1 ,
898
+ & rmon_stats -> hist_tx [2 ]);
899
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_256_TO_511 , 1 ,
900
+ & rmon_stats -> hist_tx [3 ]);
901
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_512_TO_1023 , 1 ,
902
+ & rmon_stats -> hist_tx [4 ]);
903
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PKT_SZ_1024_TO_MAX , 1 ,
904
+ & rmon_stats -> hist_tx [5 ]);
905
+
906
+ * ranges = mt7530_rmon_ranges ;
907
+ }
908
+
909
+ static void mt7530_get_stats64 (struct dsa_switch * ds , int port ,
910
+ struct rtnl_link_stats64 * storage )
911
+ {
912
+ struct mt7530_priv * priv = ds -> priv ;
913
+ uint64_t data ;
914
+
915
+ /* MIB counter doesn't provide a FramesTransmittedOK but instead
916
+ * provide stats for Unicast, Broadcast and Multicast frames separately.
917
+ * To simulate a global frame counter, read Unicast and addition Multicast
918
+ * and Broadcast later
919
+ */
920
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_UNICAST , 1 ,
921
+ & storage -> rx_packets );
922
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_MULTICAST , 1 ,
923
+ & storage -> multicast );
924
+ storage -> rx_packets += storage -> multicast ;
925
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_BROADCAST , 1 ,
926
+ & data );
927
+ storage -> rx_packets += data ;
928
+
929
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_UNICAST , 1 ,
930
+ & storage -> tx_packets );
931
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_MULTICAST , 1 ,
932
+ & data );
933
+ storage -> tx_packets += data ;
934
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_BROADCAST , 1 ,
935
+ & data );
936
+ storage -> tx_packets += data ;
937
+
938
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_BYTES , 2 ,
939
+ & storage -> rx_bytes );
940
+
941
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_BYTES , 2 ,
942
+ & storage -> tx_bytes );
943
+
944
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_DROP , 1 ,
945
+ & storage -> rx_dropped );
946
+
947
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_DROP , 1 ,
948
+ & storage -> tx_dropped );
949
+
950
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_CRC_ERR , 1 ,
951
+ & storage -> rx_crc_errors );
952
+ }
953
+
954
+ static void mt7530_get_eth_ctrl_stats (struct dsa_switch * ds , int port ,
955
+ struct ethtool_eth_ctrl_stats * ctrl_stats )
956
+ {
957
+ struct mt7530_priv * priv = ds -> priv ;
958
+
959
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_TX_PAUSE , 1 ,
960
+ & ctrl_stats -> MACControlFramesTransmitted );
961
+
962
+ mt7530_read_port_stats (priv , port , MT7530_PORT_MIB_RX_PAUSE , 1 ,
963
+ & ctrl_stats -> MACControlFramesReceived );
964
+ }
965
+
822
966
static int
823
967
mt7530_set_ageing_time (struct dsa_switch * ds , unsigned int msecs )
824
968
{
@@ -3105,6 +3249,10 @@ const struct dsa_switch_ops mt7530_switch_ops = {
3105
3249
.get_strings = mt7530_get_strings ,
3106
3250
.get_ethtool_stats = mt7530_get_ethtool_stats ,
3107
3251
.get_sset_count = mt7530_get_sset_count ,
3252
+ .get_eth_mac_stats = mt7530_get_eth_mac_stats ,
3253
+ .get_rmon_stats = mt7530_get_rmon_stats ,
3254
+ .get_eth_ctrl_stats = mt7530_get_eth_ctrl_stats ,
3255
+ .get_stats64 = mt7530_get_stats64 ,
3108
3256
.set_ageing_time = mt7530_set_ageing_time ,
3109
3257
.port_enable = mt7530_port_enable ,
3110
3258
.port_disable = mt7530_port_disable ,
0 commit comments