ksz9477.c (de6dd626d7082eda383ec77a5e06093c82122d10) ksz9477.c (c6101dd7ffb8b7f940e3fc4a22ce4023f8184f0d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Microchip KSZ9477 switch driver main logic
4 *
5 * Copyright (C) 2017-2019 Microchip Technology Inc.
6 */
7
8#include <linux/kernel.h>

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

60 { 0x1E, "tx_single_col" },
61 { 0x1F, "tx_mult_col" },
62 { 0x80, "rx_total" },
63 { 0x81, "tx_total" },
64 { 0x82, "rx_discards" },
65 { 0x83, "tx_discards" },
66};
67
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Microchip KSZ9477 switch driver main logic
4 *
5 * Copyright (C) 2017-2019 Microchip Technology Inc.
6 */
7
8#include <linux/kernel.h>

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

60 { 0x1E, "tx_single_col" },
61 { 0x1F, "tx_mult_col" },
62 { 0x80, "rx_total" },
63 { 0x81, "tx_total" },
64 { 0x82, "rx_discards" },
65 { 0x83, "tx_discards" },
66};
67
68struct ksz9477_stats_raw {
69 u64 rx_hi;
70 u64 rx_undersize;
71 u64 rx_fragments;
72 u64 rx_oversize;
73 u64 rx_jabbers;
74 u64 rx_symbol_err;
75 u64 rx_crc_err;
76 u64 rx_align_err;
77 u64 rx_mac_ctrl;
78 u64 rx_pause;
79 u64 rx_bcast;
80 u64 rx_mcast;
81 u64 rx_ucast;
82 u64 rx_64_or_less;
83 u64 rx_65_127;
84 u64 rx_128_255;
85 u64 rx_256_511;
86 u64 rx_512_1023;
87 u64 rx_1024_1522;
88 u64 rx_1523_2000;
89 u64 rx_2001;
90 u64 tx_hi;
91 u64 tx_late_col;
92 u64 tx_pause;
93 u64 tx_bcast;
94 u64 tx_mcast;
95 u64 tx_ucast;
96 u64 tx_deferred;
97 u64 tx_total_col;
98 u64 tx_exc_col;
99 u64 tx_single_col;
100 u64 tx_mult_col;
101 u64 rx_total;
102 u64 tx_total;
103 u64 rx_discards;
104 u64 tx_discards;
105};
106
107static void ksz9477_r_mib_stats64(struct ksz_device *dev, int port)
108{
109 struct rtnl_link_stats64 *stats;
110 struct ksz9477_stats_raw *raw;
111 struct ksz_port_mib *mib;
112
113 mib = &dev->ports[port].mib;
114 stats = &mib->stats64;
115 raw = (struct ksz9477_stats_raw *)mib->counters;
116
117 spin_lock(&mib->stats64_lock);
118
119 stats->rx_packets = raw->rx_bcast + raw->rx_mcast + raw->rx_ucast;
120 stats->tx_packets = raw->tx_bcast + raw->tx_mcast + raw->tx_ucast;
121
122 /* HW counters are counting bytes + FCS which is not acceptable
123 * for rtnl_link_stats64 interface
124 */
125 stats->rx_bytes = raw->rx_total - stats->rx_packets * ETH_FCS_LEN;
126 stats->tx_bytes = raw->tx_total - stats->tx_packets * ETH_FCS_LEN;
127
128 stats->rx_length_errors = raw->rx_undersize + raw->rx_fragments +
129 raw->rx_oversize;
130
131 stats->rx_crc_errors = raw->rx_crc_err;
132 stats->rx_frame_errors = raw->rx_align_err;
133 stats->rx_dropped = raw->rx_discards;
134 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
135 stats->rx_frame_errors + stats->rx_dropped;
136
137 stats->tx_window_errors = raw->tx_late_col;
138 stats->tx_fifo_errors = raw->tx_discards;
139 stats->tx_aborted_errors = raw->tx_exc_col;
140 stats->tx_errors = stats->tx_window_errors + stats->tx_fifo_errors +
141 stats->tx_aborted_errors;
142
143 stats->multicast = raw->rx_mcast;
144 stats->collisions = raw->tx_total_col;
145
146 spin_unlock(&mib->stats64_lock);
147}
148
149static void ksz9477_get_stats64(struct dsa_switch *ds, int port,
150 struct rtnl_link_stats64 *s)
151{
152 struct ksz_device *dev = ds->priv;
153 struct ksz_port_mib *mib;
154
155 mib = &dev->ports[port].mib;
156
157 spin_lock(&mib->stats64_lock);
158 memcpy(s, &mib->stats64, sizeof(*s));
159 spin_unlock(&mib->stats64_lock);
160}
161
162static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
163{
164 regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0);
165}
166
167static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 bits,
168 bool set)
169{

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

1457 .port_vlan_del = ksz9477_port_vlan_del,
1458 .port_fdb_dump = ksz9477_port_fdb_dump,
1459 .port_fdb_add = ksz9477_port_fdb_add,
1460 .port_fdb_del = ksz9477_port_fdb_del,
1461 .port_mdb_add = ksz9477_port_mdb_add,
1462 .port_mdb_del = ksz9477_port_mdb_del,
1463 .port_mirror_add = ksz9477_port_mirror_add,
1464 .port_mirror_del = ksz9477_port_mirror_del,
68static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
69{
70 regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0);
71}
72
73static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 bits,
74 bool set)
75{

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

1363 .port_vlan_del = ksz9477_port_vlan_del,
1364 .port_fdb_dump = ksz9477_port_fdb_dump,
1365 .port_fdb_add = ksz9477_port_fdb_add,
1366 .port_fdb_del = ksz9477_port_fdb_del,
1367 .port_mdb_add = ksz9477_port_mdb_add,
1368 .port_mdb_del = ksz9477_port_mdb_del,
1369 .port_mirror_add = ksz9477_port_mirror_add,
1370 .port_mirror_del = ksz9477_port_mirror_del,
1465 .get_stats64 = ksz9477_get_stats64,
1371 .get_stats64 = ksz_get_stats64,
1466 .port_change_mtu = ksz9477_change_mtu,
1467 .port_max_mtu = ksz9477_max_mtu,
1468};
1469
1470static u32 ksz9477_get_port_addr(int port, int offset)
1471{
1472 return PORT_CTRL_ADDR(port, offset);
1473}

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

1648
1649static const struct ksz_dev_ops ksz9477_dev_ops = {
1650 .get_port_addr = ksz9477_get_port_addr,
1651 .cfg_port_member = ksz9477_cfg_port_member,
1652 .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
1653 .port_setup = ksz9477_port_setup,
1654 .r_mib_cnt = ksz9477_r_mib_cnt,
1655 .r_mib_pkt = ksz9477_r_mib_pkt,
1372 .port_change_mtu = ksz9477_change_mtu,
1373 .port_max_mtu = ksz9477_max_mtu,
1374};
1375
1376static u32 ksz9477_get_port_addr(int port, int offset)
1377{
1378 return PORT_CTRL_ADDR(port, offset);
1379}

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

1554
1555static const struct ksz_dev_ops ksz9477_dev_ops = {
1556 .get_port_addr = ksz9477_get_port_addr,
1557 .cfg_port_member = ksz9477_cfg_port_member,
1558 .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
1559 .port_setup = ksz9477_port_setup,
1560 .r_mib_cnt = ksz9477_r_mib_cnt,
1561 .r_mib_pkt = ksz9477_r_mib_pkt,
1656 .r_mib_stat64 = ksz9477_r_mib_stats64,
1562 .r_mib_stat64 = ksz_r_mib_stats64,
1657 .freeze_mib = ksz9477_freeze_mib,
1658 .port_init_cnt = ksz9477_port_init_cnt,
1659 .shutdown = ksz9477_reset_switch,
1660 .detect = ksz9477_switch_detect,
1661 .init = ksz9477_switch_init,
1662 .exit = ksz9477_switch_exit,
1663};
1664

--- 31 unchanged lines hidden ---
1563 .freeze_mib = ksz9477_freeze_mib,
1564 .port_init_cnt = ksz9477_port_init_cnt,
1565 .shutdown = ksz9477_reset_switch,
1566 .detect = ksz9477_switch_detect,
1567 .init = ksz9477_switch_init,
1568 .exit = ksz9477_switch_exit,
1569};
1570

--- 31 unchanged lines hidden ---