xref: /linux/drivers/net/ethernet/apm/xgene-v2/ethtool.c (revision ead5d1f4d877e92c051e1a1ade623d0d30e71619)
1*1ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2617d795cSIyappan Subramanian /*
3617d795cSIyappan Subramanian  * Applied Micro X-Gene SoC Ethernet v2 Driver
4617d795cSIyappan Subramanian  *
5617d795cSIyappan Subramanian  * Copyright (c) 2017, Applied Micro Circuits Corporation
6617d795cSIyappan Subramanian  * Author(s): Iyappan Subramanian <isubramanian@apm.com>
7617d795cSIyappan Subramanian  *	      Keyur Chudgar <kchudgar@apm.com>
8617d795cSIyappan Subramanian  */
9617d795cSIyappan Subramanian 
10617d795cSIyappan Subramanian #include "main.h"
11617d795cSIyappan Subramanian 
12617d795cSIyappan Subramanian #define XGE_STAT(m)		{ #m, offsetof(struct xge_pdata, stats.m) }
13e05ddafdSIyappan Subramanian #define XGE_EXTD_STAT(m, n)					\
14e05ddafdSIyappan Subramanian 	{							\
15e05ddafdSIyappan Subramanian 		#m,						\
16e05ddafdSIyappan Subramanian 		n,						\
17e05ddafdSIyappan Subramanian 		0						\
18e05ddafdSIyappan Subramanian 	}
19617d795cSIyappan Subramanian 
20617d795cSIyappan Subramanian static const struct xge_gstrings_stats gstrings_stats[] = {
21617d795cSIyappan Subramanian 	XGE_STAT(rx_packets),
22617d795cSIyappan Subramanian 	XGE_STAT(tx_packets),
23617d795cSIyappan Subramanian 	XGE_STAT(rx_bytes),
24617d795cSIyappan Subramanian 	XGE_STAT(tx_bytes),
25617d795cSIyappan Subramanian 	XGE_STAT(rx_errors)
26617d795cSIyappan Subramanian };
27617d795cSIyappan Subramanian 
28e05ddafdSIyappan Subramanian static struct xge_gstrings_extd_stats gstrings_extd_stats[] = {
29e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_64b_frame_cntr, TR64),
30e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_127b_frame_cntr, TR127),
31e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_255b_frame_cntr, TR255),
32e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_511b_frame_cntr, TR511),
33e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_1023b_frame_cntr, TR1K),
34e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_1518b_frame_cntr, TRMAX),
35e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_rx_1522b_frame_cntr, TRMGV),
36e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_fcs_error_cntr, RFCS),
37e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_multicast_pkt_cntr, RMCA),
38e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_broadcast_pkt_cntr, RBCA),
39e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_ctrl_frame_pkt_cntr, RXCF),
40e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_pause_frame_pkt_cntr, RXPF),
41e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_unk_opcode_cntr, RXUO),
42e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_align_err_cntr, RALN),
43e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_frame_len_err_cntr, RFLR),
44e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_code_err_cntr, RCDE),
45e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_carrier_sense_err_cntr, RCSE),
46e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_undersize_pkt_cntr, RUND),
47e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_oversize_pkt_cntr, ROVR),
48e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_fragments_cntr, RFRG),
49e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_jabber_cntr, RJBR),
50e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(rx_dropped_pkt_cntr, RDRP),
51e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_multicast_pkt_cntr, TMCA),
52e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_broadcast_pkt_cntr, TBCA),
53e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_pause_ctrl_frame_cntr, TXPF),
54e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_defer_pkt_cntr, TDFR),
55e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_excv_defer_pkt_cntr, TEDF),
56e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_single_col_pkt_cntr, TSCL),
57e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_multi_col_pkt_cntr, TMCL),
58e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_late_col_pkt_cntr, TLCL),
59e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_excv_col_pkt_cntr, TXCL),
60e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_total_col_cntr, TNCL),
61e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_pause_frames_hnrd_cntr, TPFH),
62e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_drop_frame_cntr, TDRP),
63e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_jabber_frame_cntr, TJBR),
64e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_fcs_error_cntr, TFCS),
65e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_ctrl_frame_cntr, TXCF),
66e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_oversize_frame_cntr, TOVR),
67e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_undersize_frame_cntr, TUND),
68e05ddafdSIyappan Subramanian 	XGE_EXTD_STAT(tx_fragments_cntr, TFRG)
69e05ddafdSIyappan Subramanian };
70e05ddafdSIyappan Subramanian 
71617d795cSIyappan Subramanian #define XGE_STATS_LEN		ARRAY_SIZE(gstrings_stats)
72e05ddafdSIyappan Subramanian #define XGE_EXTD_STATS_LEN	ARRAY_SIZE(gstrings_extd_stats)
73e05ddafdSIyappan Subramanian 
xge_mac_get_extd_stats(struct xge_pdata * pdata)74e05ddafdSIyappan Subramanian static void xge_mac_get_extd_stats(struct xge_pdata *pdata)
75e05ddafdSIyappan Subramanian {
76e05ddafdSIyappan Subramanian 	u32 data;
77e05ddafdSIyappan Subramanian 	int i;
78e05ddafdSIyappan Subramanian 
79e05ddafdSIyappan Subramanian 	for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
80e05ddafdSIyappan Subramanian 		data = xge_rd_csr(pdata, gstrings_extd_stats[i].addr);
81e05ddafdSIyappan Subramanian 		gstrings_extd_stats[i].value += data;
82e05ddafdSIyappan Subramanian 	}
83e05ddafdSIyappan Subramanian }
84617d795cSIyappan Subramanian 
xge_get_drvinfo(struct net_device * ndev,struct ethtool_drvinfo * info)85617d795cSIyappan Subramanian static void xge_get_drvinfo(struct net_device *ndev,
86617d795cSIyappan Subramanian 			    struct ethtool_drvinfo *info)
87617d795cSIyappan Subramanian {
88617d795cSIyappan Subramanian 	struct xge_pdata *pdata = netdev_priv(ndev);
89617d795cSIyappan Subramanian 	struct platform_device *pdev = pdata->pdev;
90617d795cSIyappan Subramanian 
91617d795cSIyappan Subramanian 	strcpy(info->driver, "xgene-enet-v2");
92617d795cSIyappan Subramanian 	sprintf(info->bus_info, "%s", pdev->name);
93617d795cSIyappan Subramanian }
94617d795cSIyappan Subramanian 
xge_get_strings(struct net_device * ndev,u32 stringset,u8 * data)95617d795cSIyappan Subramanian static void xge_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
96617d795cSIyappan Subramanian {
97617d795cSIyappan Subramanian 	u8 *p = data;
98617d795cSIyappan Subramanian 	int i;
99617d795cSIyappan Subramanian 
100617d795cSIyappan Subramanian 	if (stringset != ETH_SS_STATS)
101617d795cSIyappan Subramanian 		return;
102617d795cSIyappan Subramanian 
103617d795cSIyappan Subramanian 	for (i = 0; i < XGE_STATS_LEN; i++) {
104617d795cSIyappan Subramanian 		memcpy(p, gstrings_stats[i].name, ETH_GSTRING_LEN);
105617d795cSIyappan Subramanian 		p += ETH_GSTRING_LEN;
106617d795cSIyappan Subramanian 	}
107e05ddafdSIyappan Subramanian 
108e05ddafdSIyappan Subramanian 	for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
109e05ddafdSIyappan Subramanian 		memcpy(p, gstrings_extd_stats[i].name, ETH_GSTRING_LEN);
110e05ddafdSIyappan Subramanian 		p += ETH_GSTRING_LEN;
111e05ddafdSIyappan Subramanian 	}
112617d795cSIyappan Subramanian }
113617d795cSIyappan Subramanian 
xge_get_sset_count(struct net_device * ndev,int sset)114617d795cSIyappan Subramanian static int xge_get_sset_count(struct net_device *ndev, int sset)
115617d795cSIyappan Subramanian {
116617d795cSIyappan Subramanian 	if (sset != ETH_SS_STATS)
117617d795cSIyappan Subramanian 		return -EINVAL;
118617d795cSIyappan Subramanian 
119e05ddafdSIyappan Subramanian 	return XGE_STATS_LEN + XGE_EXTD_STATS_LEN;
120617d795cSIyappan Subramanian }
121617d795cSIyappan Subramanian 
xge_get_ethtool_stats(struct net_device * ndev,struct ethtool_stats * dummy,u64 * data)122617d795cSIyappan Subramanian static void xge_get_ethtool_stats(struct net_device *ndev,
123617d795cSIyappan Subramanian 				  struct ethtool_stats *dummy,
124617d795cSIyappan Subramanian 				  u64 *data)
125617d795cSIyappan Subramanian {
126617d795cSIyappan Subramanian 	void *pdata = netdev_priv(ndev);
127617d795cSIyappan Subramanian 	int i;
128617d795cSIyappan Subramanian 
129617d795cSIyappan Subramanian 	for (i = 0; i < XGE_STATS_LEN; i++)
130617d795cSIyappan Subramanian 		*data++ = *(u64 *)(pdata + gstrings_stats[i].offset);
131e05ddafdSIyappan Subramanian 
132e05ddafdSIyappan Subramanian 	xge_mac_get_extd_stats(pdata);
133e05ddafdSIyappan Subramanian 
134e05ddafdSIyappan Subramanian 	for (i = 0; i < XGE_EXTD_STATS_LEN; i++)
135e05ddafdSIyappan Subramanian 		*data++ = gstrings_extd_stats[i].value;
136617d795cSIyappan Subramanian }
137617d795cSIyappan Subramanian 
xge_get_link_ksettings(struct net_device * ndev,struct ethtool_link_ksettings * cmd)138617d795cSIyappan Subramanian static int xge_get_link_ksettings(struct net_device *ndev,
139617d795cSIyappan Subramanian 				  struct ethtool_link_ksettings *cmd)
140617d795cSIyappan Subramanian {
141617d795cSIyappan Subramanian 	struct phy_device *phydev = ndev->phydev;
142617d795cSIyappan Subramanian 
143617d795cSIyappan Subramanian 	if (!phydev)
144617d795cSIyappan Subramanian 		return -ENODEV;
145617d795cSIyappan Subramanian 
1465514174fSyuval.shaia@oracle.com 	phy_ethtool_ksettings_get(phydev, cmd);
1475514174fSyuval.shaia@oracle.com 
1485514174fSyuval.shaia@oracle.com 	return 0;
149617d795cSIyappan Subramanian }
150617d795cSIyappan Subramanian 
xge_set_link_ksettings(struct net_device * ndev,const struct ethtool_link_ksettings * cmd)151617d795cSIyappan Subramanian static int xge_set_link_ksettings(struct net_device *ndev,
152617d795cSIyappan Subramanian 				  const struct ethtool_link_ksettings *cmd)
153617d795cSIyappan Subramanian {
154617d795cSIyappan Subramanian 	struct phy_device *phydev = ndev->phydev;
155617d795cSIyappan Subramanian 
156617d795cSIyappan Subramanian 	if (!phydev)
157617d795cSIyappan Subramanian 		return -ENODEV;
158617d795cSIyappan Subramanian 
159617d795cSIyappan Subramanian 	return phy_ethtool_ksettings_set(phydev, cmd);
160617d795cSIyappan Subramanian }
161617d795cSIyappan Subramanian 
162617d795cSIyappan Subramanian static const struct ethtool_ops xge_ethtool_ops = {
163617d795cSIyappan Subramanian 	.get_drvinfo = xge_get_drvinfo,
164617d795cSIyappan Subramanian 	.get_link = ethtool_op_get_link,
165617d795cSIyappan Subramanian 	.get_strings = xge_get_strings,
166617d795cSIyappan Subramanian 	.get_sset_count = xge_get_sset_count,
167617d795cSIyappan Subramanian 	.get_ethtool_stats = xge_get_ethtool_stats,
168617d795cSIyappan Subramanian 	.get_link_ksettings = xge_get_link_ksettings,
169617d795cSIyappan Subramanian 	.set_link_ksettings = xge_set_link_ksettings,
170617d795cSIyappan Subramanian };
171617d795cSIyappan Subramanian 
xge_set_ethtool_ops(struct net_device * ndev)172617d795cSIyappan Subramanian void xge_set_ethtool_ops(struct net_device *ndev)
173617d795cSIyappan Subramanian {
174617d795cSIyappan Subramanian 	ndev->ethtool_ops = &xge_ethtool_ops;
175617d795cSIyappan Subramanian }
176