summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/apm/xgene-v2/ethtool.c
blob: a58250c1b57a5e7a4dacd4a7778ecefb0e3c041f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Applied Micro X-Gene SoC Ethernet v2 Driver
 *
 * Copyright (c) 2017, Applied Micro Circuits Corporation
 * Author(s): Iyappan Subramanian <isubramanian@apm.com>
 *	      Keyur Chudgar <kchudgar@apm.com>
 */

#include "main.h"

#define XGE_STAT(m)		{ #m, offsetof(struct xge_pdata, stats.m) }
#define XGE_EXTD_STAT(m, n)					\
	{							\
		#m,						\
		n,						\
		0						\
	}

static const struct xge_gstrings_stats gstrings_stats[] = {
	XGE_STAT(rx_packets),
	XGE_STAT(tx_packets),
	XGE_STAT(rx_bytes),
	XGE_STAT(tx_bytes),
	XGE_STAT(rx_errors)
};

static struct xge_gstrings_extd_stats gstrings_extd_stats[] = {
	XGE_EXTD_STAT(tx_rx_64b_frame_cntr, TR64),
	XGE_EXTD_STAT(tx_rx_127b_frame_cntr, TR127),
	XGE_EXTD_STAT(tx_rx_255b_frame_cntr, TR255),
	XGE_EXTD_STAT(tx_rx_511b_frame_cntr, TR511),
	XGE_EXTD_STAT(tx_rx_1023b_frame_cntr, TR1K),
	XGE_EXTD_STAT(tx_rx_1518b_frame_cntr, TRMAX),
	XGE_EXTD_STAT(tx_rx_1522b_frame_cntr, TRMGV),
	XGE_EXTD_STAT(rx_fcs_error_cntr, RFCS),
	XGE_EXTD_STAT(rx_multicast_pkt_cntr, RMCA),
	XGE_EXTD_STAT(rx_broadcast_pkt_cntr, RBCA),
	XGE_EXTD_STAT(rx_ctrl_frame_pkt_cntr, RXCF),
	XGE_EXTD_STAT(rx_pause_frame_pkt_cntr, RXPF),
	XGE_EXTD_STAT(rx_unk_opcode_cntr, RXUO),
	XGE_EXTD_STAT(rx_align_err_cntr, RALN),
	XGE_EXTD_STAT(rx_frame_len_err_cntr, RFLR),
	XGE_EXTD_STAT(rx_code_err_cntr, RCDE),
	XGE_EXTD_STAT(rx_carrier_sense_err_cntr, RCSE),
	XGE_EXTD_STAT(rx_undersize_pkt_cntr, RUND),
	XGE_EXTD_STAT(rx_oversize_pkt_cntr, ROVR),
	XGE_EXTD_STAT(rx_fragments_cntr, RFRG),
	XGE_EXTD_STAT(rx_jabber_cntr, RJBR),
	XGE_EXTD_STAT(rx_dropped_pkt_cntr, RDRP),
	XGE_EXTD_STAT(tx_multicast_pkt_cntr, TMCA),
	XGE_EXTD_STAT(tx_broadcast_pkt_cntr, TBCA),
	XGE_EXTD_STAT(tx_pause_ctrl_frame_cntr, TXPF),
	XGE_EXTD_STAT(tx_defer_pkt_cntr, TDFR),
	XGE_EXTD_STAT(tx_excv_defer_pkt_cntr, TEDF),
	XGE_EXTD_STAT(tx_single_col_pkt_cntr, TSCL),
	XGE_EXTD_STAT(tx_multi_col_pkt_cntr, TMCL),
	XGE_EXTD_STAT(tx_late_col_pkt_cntr, TLCL),
	XGE_EXTD_STAT(tx_excv_col_pkt_cntr, TXCL),
	XGE_EXTD_STAT(tx_total_col_cntr, TNCL),
	XGE_EXTD_STAT(tx_pause_frames_hnrd_cntr, TPFH),
	XGE_EXTD_STAT(tx_drop_frame_cntr, TDRP),
	XGE_EXTD_STAT(tx_jabber_frame_cntr, TJBR),
	XGE_EXTD_STAT(tx_fcs_error_cntr, TFCS),
	XGE_EXTD_STAT(tx_ctrl_frame_cntr, TXCF),
	XGE_EXTD_STAT(tx_oversize_frame_cntr, TOVR),
	XGE_EXTD_STAT(tx_undersize_frame_cntr, TUND),
	XGE_EXTD_STAT(tx_fragments_cntr, TFRG)
};

#define XGE_STATS_LEN		ARRAY_SIZE(gstrings_stats)
#define XGE_EXTD_STATS_LEN	ARRAY_SIZE(gstrings_extd_stats)

static void xge_mac_get_extd_stats(struct xge_pdata *pdata)
{
	u32 data;
	int i;

	for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
		data = xge_rd_csr(pdata, gstrings_extd_stats[i].addr);
		gstrings_extd_stats[i].value += data;
	}
}

static void xge_get_drvinfo(struct net_device *ndev,
			    struct ethtool_drvinfo *info)
{
	struct xge_pdata *pdata = netdev_priv(ndev);
	struct platform_device *pdev = pdata->pdev;

	strcpy(info->driver, "xgene-enet-v2");
	strcpy(info->version, XGENE_ENET_V2_VERSION);
	snprintf(info->fw_version, ETHTOOL_FWVERS_LEN, "N/A");
	sprintf(info->bus_info, "%s", pdev->name);
}

static void xge_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
{
	u8 *p = data;
	int i;

	if (stringset != ETH_SS_STATS)
		return;

	for (i = 0; i < XGE_STATS_LEN; i++) {
		memcpy(p, gstrings_stats[i].name, ETH_GSTRING_LEN);
		p += ETH_GSTRING_LEN;
	}

	for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
		memcpy(p, gstrings_extd_stats[i].name, ETH_GSTRING_LEN);
		p += ETH_GSTRING_LEN;
	}
}

static int xge_get_sset_count(struct net_device *ndev, int sset)
{
	if (sset != ETH_SS_STATS)
		return -EINVAL;

	return XGE_STATS_LEN + XGE_EXTD_STATS_LEN;
}

static void xge_get_ethtool_stats(struct net_device *ndev,
				  struct ethtool_stats *dummy,
				  u64 *data)
{
	void *pdata = netdev_priv(ndev);
	int i;

	for (i = 0; i < XGE_STATS_LEN; i++)
		*data++ = *(u64 *)(pdata + gstrings_stats[i].offset);

	xge_mac_get_extd_stats(pdata);

	for (i = 0; i < XGE_EXTD_STATS_LEN; i++)
		*data++ = gstrings_extd_stats[i].value;
}

static int xge_get_link_ksettings(struct net_device *ndev,
				  struct ethtool_link_ksettings *cmd)
{
	struct phy_device *phydev = ndev->phydev;

	if (!phydev)
		return -ENODEV;

	phy_ethtool_ksettings_get(phydev, cmd);

	return 0;
}

static int xge_set_link_ksettings(struct net_device *ndev,
				  const struct ethtool_link_ksettings *cmd)
{
	struct phy_device *phydev = ndev->phydev;

	if (!phydev)
		return -ENODEV;

	return phy_ethtool_ksettings_set(phydev, cmd);
}

static const struct ethtool_ops xge_ethtool_ops = {
	.get_drvinfo = xge_get_drvinfo,
	.get_link = ethtool_op_get_link,
	.get_strings = xge_get_strings,
	.get_sset_count = xge_get_sset_count,
	.get_ethtool_stats = xge_get_ethtool_stats,
	.get_link_ksettings = xge_get_link_ksettings,
	.set_link_ksettings = xge_set_link_ksettings,
};

void xge_set_ethtool_ops(struct net_device *ndev)
{
	ndev->ethtool_ops = &xge_ethtool_ops;
}