@@ -830,7 +830,10 @@ qca8k_mib_init(struct qca8k_priv *priv)
830830 int ret ;
831831
832832 mutex_lock (& priv -> reg_mutex );
833- ret = regmap_set_bits (priv -> regmap , QCA8K_REG_MIB , QCA8K_MIB_FLUSH | QCA8K_MIB_BUSY );
833+ ret = regmap_update_bits (priv -> regmap , QCA8K_REG_MIB ,
834+ QCA8K_MIB_FUNC | QCA8K_MIB_BUSY ,
835+ FIELD_PREP (QCA8K_MIB_FUNC , QCA8K_MIB_FLUSH ) |
836+ QCA8K_MIB_BUSY );
834837 if (ret )
835838 goto exit ;
836839
@@ -1901,6 +1904,97 @@ qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
19011904 ETH_GSTRING_LEN );
19021905}
19031906
1907+ static void qca8k_mib_autocast_handler (struct dsa_switch * ds , struct sk_buff * skb )
1908+ {
1909+ const struct qca8k_match_data * match_data ;
1910+ struct qca8k_mib_eth_data * mib_eth_data ;
1911+ struct qca8k_priv * priv = ds -> priv ;
1912+ const struct qca8k_mib_desc * mib ;
1913+ struct mib_ethhdr * mib_ethhdr ;
1914+ int i , mib_len , offset = 0 ;
1915+ u64 * data ;
1916+ u8 port ;
1917+
1918+ mib_ethhdr = (struct mib_ethhdr * )skb_mac_header (skb );
1919+ mib_eth_data = & priv -> mib_eth_data ;
1920+
1921+ /* The switch autocast every port. Ignore other packet and
1922+ * parse only the requested one.
1923+ */
1924+ port = FIELD_GET (QCA_HDR_RECV_SOURCE_PORT , ntohs (mib_ethhdr -> hdr ));
1925+ if (port != mib_eth_data -> req_port )
1926+ goto exit ;
1927+
1928+ match_data = device_get_match_data (priv -> dev );
1929+ data = mib_eth_data -> data ;
1930+
1931+ for (i = 0 ; i < match_data -> mib_count ; i ++ ) {
1932+ mib = & ar8327_mib [i ];
1933+
1934+ /* First 3 mib are present in the skb head */
1935+ if (i < 3 ) {
1936+ data [i ] = mib_ethhdr -> data [i ];
1937+ continue ;
1938+ }
1939+
1940+ mib_len = sizeof (uint32_t );
1941+
1942+ /* Some mib are 64 bit wide */
1943+ if (mib -> size == 2 )
1944+ mib_len = sizeof (uint64_t );
1945+
1946+ /* Copy the mib value from packet to the */
1947+ memcpy (data + i , skb -> data + offset , mib_len );
1948+
1949+ /* Set the offset for the next mib */
1950+ offset += mib_len ;
1951+ }
1952+
1953+ exit :
1954+ /* Complete on receiving all the mib packet */
1955+ if (refcount_dec_and_test (& mib_eth_data -> port_parsed ))
1956+ complete (& mib_eth_data -> rw_done );
1957+ }
1958+
1959+ static int
1960+ qca8k_get_ethtool_stats_eth (struct dsa_switch * ds , int port , u64 * data )
1961+ {
1962+ struct dsa_port * dp = dsa_to_port (ds , port );
1963+ struct qca8k_mib_eth_data * mib_eth_data ;
1964+ struct qca8k_priv * priv = ds -> priv ;
1965+ int ret ;
1966+
1967+ mib_eth_data = & priv -> mib_eth_data ;
1968+
1969+ mutex_lock (& mib_eth_data -> mutex );
1970+
1971+ reinit_completion (& mib_eth_data -> rw_done );
1972+
1973+ mib_eth_data -> req_port = dp -> index ;
1974+ mib_eth_data -> data = data ;
1975+ refcount_set (& mib_eth_data -> port_parsed , QCA8K_NUM_PORTS );
1976+
1977+ mutex_lock (& priv -> reg_mutex );
1978+
1979+ /* Send mib autocast request */
1980+ ret = regmap_update_bits (priv -> regmap , QCA8K_REG_MIB ,
1981+ QCA8K_MIB_FUNC | QCA8K_MIB_BUSY ,
1982+ FIELD_PREP (QCA8K_MIB_FUNC , QCA8K_MIB_CAST ) |
1983+ QCA8K_MIB_BUSY );
1984+
1985+ mutex_unlock (& priv -> reg_mutex );
1986+
1987+ if (ret )
1988+ goto exit ;
1989+
1990+ ret = wait_for_completion_timeout (& mib_eth_data -> rw_done , QCA8K_ETHERNET_TIMEOUT );
1991+
1992+ exit :
1993+ mutex_unlock (& mib_eth_data -> mutex );
1994+
1995+ return ret ;
1996+ }
1997+
19041998static void
19051999qca8k_get_ethtool_stats (struct dsa_switch * ds , int port ,
19062000 uint64_t * data )
@@ -1912,6 +2006,10 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
19122006 u32 hi = 0 ;
19132007 int ret ;
19142008
2009+ if (priv -> mgmt_master &&
2010+ qca8k_get_ethtool_stats_eth (ds , port , data ) > 0 )
2011+ return ;
2012+
19152013 match_data = of_device_get_match_data (priv -> dev );
19162014
19172015 for (i = 0 ; i < match_data -> mib_count ; i ++ ) {
@@ -2593,9 +2691,11 @@ qca8k_master_change(struct dsa_switch *ds, const struct net_device *master,
25932691 return ;
25942692
25952693 mutex_lock (& priv -> mgmt_eth_data .mutex );
2694+ mutex_lock (& priv -> mib_eth_data .mutex );
25962695
25972696 priv -> mgmt_master = operational ? (struct net_device * )master : NULL ;
25982697
2698+ mutex_unlock (& priv -> mib_eth_data .mutex );
25992699 mutex_unlock (& priv -> mgmt_eth_data .mutex );
26002700}
26012701
@@ -2609,6 +2709,7 @@ static int qca8k_connect_tag_protocol(struct dsa_switch *ds,
26092709 tagger_data = ds -> tagger_data ;
26102710
26112711 tagger_data -> rw_reg_ack_handler = qca8k_rw_reg_ack_handler ;
2712+ tagger_data -> mib_autocast_handler = qca8k_mib_autocast_handler ;
26122713
26132714 break ;
26142715 default :
@@ -2737,6 +2838,9 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
27372838 mutex_init (& priv -> mgmt_eth_data .mutex );
27382839 init_completion (& priv -> mgmt_eth_data .rw_done );
27392840
2841+ mutex_init (& priv -> mib_eth_data .mutex );
2842+ init_completion (& priv -> mib_eth_data .rw_done );
2843+
27402844 priv -> ds -> dev = & mdiodev -> dev ;
27412845 priv -> ds -> num_ports = QCA8K_NUM_PORTS ;
27422846 priv -> ds -> priv = priv ;
0 commit comments