ocelot.c (a8fd48b50deaa20808bbf0f6685f6f1acba6a64c) ocelot.c (1e1caa9735f90b5452fc48685c23552e56aa1920)
1// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi Ocelot Switch driver
4 *
5 * Copyright (c) 2017 Microsemi Corporation
6 */
7#include <linux/etherdevice.h>
8#include <linux/ethtool.h>

--- 945 unchanged lines hidden (view full) ---

954 if (sset != ETH_SS_STATS)
955 return;
956
957 for (i = 0; i < ocelot->num_stats; i++)
958 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name,
959 ETH_GSTRING_LEN);
960}
961
1// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi Ocelot Switch driver
4 *
5 * Copyright (c) 2017 Microsemi Corporation
6 */
7#include <linux/etherdevice.h>
8#include <linux/ethtool.h>

--- 945 unchanged lines hidden (view full) ---

954 if (sset != ETH_SS_STATS)
955 return;
956
957 for (i = 0; i < ocelot->num_stats; i++)
958 memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name,
959 ETH_GSTRING_LEN);
960}
961
962static void ocelot_check_stats(struct work_struct *work)
962static void ocelot_update_stats(struct ocelot *ocelot)
963{
963{
964 struct delayed_work *del_work = to_delayed_work(work);
965 struct ocelot *ocelot = container_of(del_work, struct ocelot, stats_work);
966 int i, j;
967
968 mutex_lock(&ocelot->stats_lock);
969
970 for (i = 0; i < ocelot->num_phys_ports; i++) {
971 /* Configure the port to read the stats from */
972 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
973

--- 7 unchanged lines hidden (view full) ---

981 if (val < (ocelot->stats[idx] & U32_MAX))
982 ocelot->stats[idx] += (u64)1 << 32;
983
984 ocelot->stats[idx] = (ocelot->stats[idx] &
985 ~(u64)U32_MAX) + val;
986 }
987 }
988
964 int i, j;
965
966 mutex_lock(&ocelot->stats_lock);
967
968 for (i = 0; i < ocelot->num_phys_ports; i++) {
969 /* Configure the port to read the stats from */
970 ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
971

--- 7 unchanged lines hidden (view full) ---

979 if (val < (ocelot->stats[idx] & U32_MAX))
980 ocelot->stats[idx] += (u64)1 << 32;
981
982 ocelot->stats[idx] = (ocelot->stats[idx] &
983 ~(u64)U32_MAX) + val;
984 }
985 }
986
989 cancel_delayed_work(&ocelot->stats_work);
987 mutex_unlock(&ocelot->stats_lock);
988}
989
990static void ocelot_check_stats_work(struct work_struct *work)
991{
992 struct delayed_work *del_work = to_delayed_work(work);
993 struct ocelot *ocelot = container_of(del_work, struct ocelot,
994 stats_work);
995
996 ocelot_update_stats(ocelot);
997
990 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
991 OCELOT_STATS_CHECK_DELAY);
998 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
999 OCELOT_STATS_CHECK_DELAY);
992
993 mutex_unlock(&ocelot->stats_lock);
994}
995
996static void ocelot_get_ethtool_stats(struct net_device *dev,
997 struct ethtool_stats *stats, u64 *data)
998{
999 struct ocelot_port *port = netdev_priv(dev);
1000 struct ocelot *ocelot = port->ocelot;
1001 int i;
1002
1003 /* check and update now */
1000}
1001
1002static void ocelot_get_ethtool_stats(struct net_device *dev,
1003 struct ethtool_stats *stats, u64 *data)
1004{
1005 struct ocelot_port *port = netdev_priv(dev);
1006 struct ocelot *ocelot = port->ocelot;
1007 int i;
1008
1009 /* check and update now */
1004 ocelot_check_stats(&ocelot->stats_work.work);
1010 ocelot_update_stats(ocelot);
1005
1006 /* Copy all counters */
1007 for (i = 0; i < ocelot->num_stats; i++)
1008 *data++ = ocelot->stats[port->chip_port * ocelot->num_stats + i];
1009}
1010
1011static int ocelot_get_sset_count(struct net_device *dev, int sset)
1012{

--- 791 unchanged lines hidden (view full) ---

1804 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
1805 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
1806 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG);
1807 for (i = 0; i < 16; i++)
1808 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
1809 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
1810 ANA_CPUQ_8021_CFG, i);
1811
1011
1012 /* Copy all counters */
1013 for (i = 0; i < ocelot->num_stats; i++)
1014 *data++ = ocelot->stats[port->chip_port * ocelot->num_stats + i];
1015}
1016
1017static int ocelot_get_sset_count(struct net_device *dev, int sset)
1018{

--- 791 unchanged lines hidden (view full) ---

1810 ANA_CPUQ_CFG_CPUQ_IPMC_CTRL(6) |
1811 ANA_CPUQ_CFG_CPUQ_IGMP(6) |
1812 ANA_CPUQ_CFG_CPUQ_MLD(6), ANA_CPUQ_CFG);
1813 for (i = 0; i < 16; i++)
1814 ocelot_write_rix(ocelot, ANA_CPUQ_8021_CFG_CPUQ_GARP_VAL(6) |
1815 ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
1816 ANA_CPUQ_8021_CFG, i);
1817
1812 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats);
1818 INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work);
1813 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
1814 OCELOT_STATS_CHECK_DELAY);
1815 return 0;
1816}
1817EXPORT_SYMBOL(ocelot_init);
1818
1819void ocelot_deinit(struct ocelot *ocelot)
1820{
1821 destroy_workqueue(ocelot->stats_queue);
1822 mutex_destroy(&ocelot->stats_lock);
1823}
1824EXPORT_SYMBOL(ocelot_deinit);
1825
1826MODULE_LICENSE("Dual MIT/GPL");
1819 queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
1820 OCELOT_STATS_CHECK_DELAY);
1821 return 0;
1822}
1823EXPORT_SYMBOL(ocelot_init);
1824
1825void ocelot_deinit(struct ocelot *ocelot)
1826{
1827 destroy_workqueue(ocelot->stats_queue);
1828 mutex_destroy(&ocelot->stats_lock);
1829}
1830EXPORT_SYMBOL(ocelot_deinit);
1831
1832MODULE_LICENSE("Dual MIT/GPL");