Skip to content

Commit 336aa67

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: show more ethtool statistics counters for P/Q/R/S
It looks like the P/Q/R/S series supports some more counters, generically named "Ethernet statistics counter", which we were not printing. Add them. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b8f1487 commit 336aa67

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed

drivers/net/dsa/sja1105/sja1105.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct sja1105_regs {
6060
u64 mac[SJA1105_NUM_PORTS];
6161
u64 mac_hl1[SJA1105_NUM_PORTS];
6262
u64 mac_hl2[SJA1105_NUM_PORTS];
63+
u64 ether_stats[SJA1105_NUM_PORTS];
6364
u64 qlevel[SJA1105_NUM_PORTS];
6465
};
6566

drivers/net/dsa/sja1105/sja1105_ethtool.c

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define SJA1105_SIZE_HL1_AREA (0x10 * 4)
88
#define SJA1105_SIZE_HL2_AREA (0x4 * 4)
99
#define SJA1105_SIZE_QLEVEL_AREA (0x8 * 4) /* 0x4 to 0xB */
10+
#define SJA1105_SIZE_ETHER_AREA (0x17 * 4)
1011

1112
struct sja1105_port_status_mac {
1213
u64 n_runt;
@@ -63,10 +64,37 @@ struct sja1105_port_status_hl2 {
6364
u64 qlevel[8]; /* Only for P/Q/R/S */
6465
};
6566

67+
struct sja1105_port_status_ether {
68+
u64 n_drops_nolearn;
69+
u64 n_drops_noroute;
70+
u64 n_drops_ill_dtag;
71+
u64 n_drops_dtag;
72+
u64 n_drops_sotag;
73+
u64 n_drops_sitag;
74+
u64 n_drops_utag;
75+
u64 n_tx_bytes_1024_2047;
76+
u64 n_tx_bytes_512_1023;
77+
u64 n_tx_bytes_256_511;
78+
u64 n_tx_bytes_128_255;
79+
u64 n_tx_bytes_65_127;
80+
u64 n_tx_bytes_64;
81+
u64 n_tx_mcast;
82+
u64 n_tx_bcast;
83+
u64 n_rx_bytes_1024_2047;
84+
u64 n_rx_bytes_512_1023;
85+
u64 n_rx_bytes_256_511;
86+
u64 n_rx_bytes_128_255;
87+
u64 n_rx_bytes_65_127;
88+
u64 n_rx_bytes_64;
89+
u64 n_rx_mcast;
90+
u64 n_rx_bcast;
91+
};
92+
6693
struct sja1105_port_status {
6794
struct sja1105_port_status_mac mac;
6895
struct sja1105_port_status_hl1 hl1;
6996
struct sja1105_port_status_hl2 hl2;
97+
struct sja1105_port_status_ether ether;
7098
};
7199

72100
static void
@@ -158,6 +186,58 @@ sja1105pqrs_port_status_qlevel_unpack(void *buf,
158186
}
159187
}
160188

189+
static void
190+
sja1105pqrs_port_status_ether_unpack(void *buf,
191+
struct sja1105_port_status_ether *status)
192+
{
193+
/* Make pointer arithmetic work on 4 bytes */
194+
u32 *p = buf;
195+
196+
sja1105_unpack(p + 0x16, &status->n_drops_nolearn, 31, 0, 4);
197+
sja1105_unpack(p + 0x15, &status->n_drops_noroute, 31, 0, 4);
198+
sja1105_unpack(p + 0x14, &status->n_drops_ill_dtag, 31, 0, 4);
199+
sja1105_unpack(p + 0x13, &status->n_drops_dtag, 31, 0, 4);
200+
sja1105_unpack(p + 0x12, &status->n_drops_sotag, 31, 0, 4);
201+
sja1105_unpack(p + 0x11, &status->n_drops_sitag, 31, 0, 4);
202+
sja1105_unpack(p + 0x10, &status->n_drops_utag, 31, 0, 4);
203+
sja1105_unpack(p + 0x0F, &status->n_tx_bytes_1024_2047, 31, 0, 4);
204+
sja1105_unpack(p + 0x0E, &status->n_tx_bytes_512_1023, 31, 0, 4);
205+
sja1105_unpack(p + 0x0D, &status->n_tx_bytes_256_511, 31, 0, 4);
206+
sja1105_unpack(p + 0x0C, &status->n_tx_bytes_128_255, 31, 0, 4);
207+
sja1105_unpack(p + 0x0B, &status->n_tx_bytes_65_127, 31, 0, 4);
208+
sja1105_unpack(p + 0x0A, &status->n_tx_bytes_64, 31, 0, 4);
209+
sja1105_unpack(p + 0x09, &status->n_tx_mcast, 31, 0, 4);
210+
sja1105_unpack(p + 0x08, &status->n_tx_bcast, 31, 0, 4);
211+
sja1105_unpack(p + 0x07, &status->n_rx_bytes_1024_2047, 31, 0, 4);
212+
sja1105_unpack(p + 0x06, &status->n_rx_bytes_512_1023, 31, 0, 4);
213+
sja1105_unpack(p + 0x05, &status->n_rx_bytes_256_511, 31, 0, 4);
214+
sja1105_unpack(p + 0x04, &status->n_rx_bytes_128_255, 31, 0, 4);
215+
sja1105_unpack(p + 0x03, &status->n_rx_bytes_65_127, 31, 0, 4);
216+
sja1105_unpack(p + 0x02, &status->n_rx_bytes_64, 31, 0, 4);
217+
sja1105_unpack(p + 0x01, &status->n_rx_mcast, 31, 0, 4);
218+
sja1105_unpack(p + 0x00, &status->n_rx_bcast, 31, 0, 4);
219+
}
220+
221+
static int
222+
sja1105pqrs_port_status_get_ether(struct sja1105_private *priv,
223+
struct sja1105_port_status_ether *ether,
224+
int port)
225+
{
226+
const struct sja1105_regs *regs = priv->info->regs;
227+
u8 packed_buf[SJA1105_SIZE_ETHER_AREA] = {0};
228+
int rc;
229+
230+
/* Ethernet statistics area */
231+
rc = sja1105_xfer_buf(priv, SPI_READ, regs->ether_stats[port],
232+
packed_buf, SJA1105_SIZE_ETHER_AREA);
233+
if (rc < 0)
234+
return rc;
235+
236+
sja1105pqrs_port_status_ether_unpack(packed_buf, ether);
237+
238+
return 0;
239+
}
240+
161241
static int sja1105_port_status_get_mac(struct sja1105_private *priv,
162242
struct sja1105_port_status_mac *status,
163243
int port)
@@ -241,7 +321,11 @@ static int sja1105_port_status_get(struct sja1105_private *priv,
241321
if (rc < 0)
242322
return rc;
243323

244-
return 0;
324+
if (priv->info->device_id == SJA1105E_DEVICE_ID ||
325+
priv->info->device_id == SJA1105T_DEVICE_ID)
326+
return 0;
327+
328+
return sja1105pqrs_port_status_get_ether(priv, &status->ether, port);
245329
}
246330

247331
static char sja1105_port_stats[][ETH_GSTRING_LEN] = {
@@ -308,6 +392,30 @@ static char sja1105pqrs_extra_port_stats[][ETH_GSTRING_LEN] = {
308392
"qlevel_5",
309393
"qlevel_6",
310394
"qlevel_7",
395+
/* Ether Stats */
396+
"n_drops_nolearn",
397+
"n_drops_noroute",
398+
"n_drops_ill_dtag",
399+
"n_drops_dtag",
400+
"n_drops_sotag",
401+
"n_drops_sitag",
402+
"n_drops_utag",
403+
"n_tx_bytes_1024_2047",
404+
"n_tx_bytes_512_1023",
405+
"n_tx_bytes_256_511",
406+
"n_tx_bytes_128_255",
407+
"n_tx_bytes_65_127",
408+
"n_tx_bytes_64",
409+
"n_tx_mcast",
410+
"n_tx_bcast",
411+
"n_rx_bytes_1024_2047",
412+
"n_rx_bytes_512_1023",
413+
"n_rx_bytes_256_511",
414+
"n_rx_bytes_128_255",
415+
"n_rx_bytes_65_127",
416+
"n_rx_bytes_64",
417+
"n_rx_mcast",
418+
"n_rx_bcast",
311419
};
312420

313421
void sja1105_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data)
@@ -376,6 +484,29 @@ void sja1105_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data)
376484
data[k++] = status.hl2.qlevel_hwm[i];
377485
data[k++] = status.hl2.qlevel[i];
378486
}
487+
data[k++] = status.ether.n_drops_nolearn;
488+
data[k++] = status.ether.n_drops_noroute;
489+
data[k++] = status.ether.n_drops_ill_dtag;
490+
data[k++] = status.ether.n_drops_dtag;
491+
data[k++] = status.ether.n_drops_sotag;
492+
data[k++] = status.ether.n_drops_sitag;
493+
data[k++] = status.ether.n_drops_utag;
494+
data[k++] = status.ether.n_tx_bytes_1024_2047;
495+
data[k++] = status.ether.n_tx_bytes_512_1023;
496+
data[k++] = status.ether.n_tx_bytes_256_511;
497+
data[k++] = status.ether.n_tx_bytes_128_255;
498+
data[k++] = status.ether.n_tx_bytes_65_127;
499+
data[k++] = status.ether.n_tx_bytes_64;
500+
data[k++] = status.ether.n_tx_mcast;
501+
data[k++] = status.ether.n_tx_bcast;
502+
data[k++] = status.ether.n_rx_bytes_1024_2047;
503+
data[k++] = status.ether.n_rx_bytes_512_1023;
504+
data[k++] = status.ether.n_rx_bytes_256_511;
505+
data[k++] = status.ether.n_rx_bytes_128_255;
506+
data[k++] = status.ether.n_rx_bytes_65_127;
507+
data[k++] = status.ether.n_rx_bytes_64;
508+
data[k++] = status.ether.n_rx_mcast;
509+
data[k++] = status.ether.n_rx_bcast;
379510
}
380511

381512
void sja1105_get_strings(struct dsa_switch *ds, int port,

drivers/net/dsa/sja1105/sja1105_spi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ static struct sja1105_regs sja1105pqrs_regs = {
482482
.mac = {0x200, 0x202, 0x204, 0x206, 0x208},
483483
.mac_hl1 = {0x400, 0x410, 0x420, 0x430, 0x440},
484484
.mac_hl2 = {0x600, 0x610, 0x620, 0x630, 0x640},
485+
.ether_stats = {0x1400, 0x1418, 0x1430, 0x1448, 0x1460},
485486
/* UM11040.pdf, Table 114 */
486487
.mii_tx_clk = {0x100013, 0x100019, 0x10001F, 0x100025, 0x10002B},
487488
.mii_rx_clk = {0x100014, 0x10001A, 0x100020, 0x100026, 0x10002C},

0 commit comments

Comments
 (0)