aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/benet/be_ethtool.c
blob: 027af85707aa21934be37af9e6ced570490bbef2 (plain) (blame)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 * Copyright (C) 2005 - 2008 ServerEngines
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.  The full GNU General
 * Public License is included in this distribution in the file called COPYING.
 *
 * Contact Information:
 * linux-drivers@serverengines.com
 *
 * ServerEngines
 * 209 N. Fair Oaks Ave
 * Sunnyvale, CA 94085
 */
/*
 * be_ethtool.c
 *
 * 	This file contains various functions that ethtool can use
 * 	to talk to the driver and the BE H/W.
 */

#include "benet.h"

#include <linux/ethtool.h>

static const char benet_gstrings_stats[][ETH_GSTRING_LEN] = {
/* net_device_stats */
	"rx_packets",
	"tx_packets",
	"rx_bytes",
	"tx_bytes",
	"rx_errors",
	"tx_errors",
	"rx_dropped",
	"tx_dropped",
	"multicast",
	"collisions",
	"rx_length_errors",
	"rx_over_errors",
	"rx_crc_errors",
	"rx_frame_errors",
	"rx_fifo_errors",
	"rx_missed_errors",
	"tx_aborted_errors",
	"tx_carrier_errors",
	"tx_fifo_errors",
	"tx_heartbeat_errors",
	"tx_window_errors",
	"rx_compressed",
	"tc_compressed",
/* BE driver Stats */
	"bes_tx_reqs",
	"bes_tx_fails",
	"bes_fwd_reqs",
	"bes_tx_wrbs",
	"bes_interrupts",
	"bes_events",
	"bes_tx_events",
	"bes_rx_events",
	"bes_tx_compl",
	"bes_rx_compl",
	"bes_ethrx_post_fail",
	"bes_802_3_dropped_frames",
	"bes_802_3_malformed_frames",
	"bes_rx_misc_pkts",
	"bes_eth_tx_rate",
	"bes_eth_rx_rate",
	"Num Packets collected",
	"Num Times Flushed",
};

#define NET_DEV_STATS_LEN \
	(sizeof(struct net_device_stats)/sizeof(unsigned long))

#define BENET_STATS_LEN  ARRAY_SIZE(benet_gstrings_stats)

static void
be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;

	strncpy(drvinfo->driver, be_driver_name, 32);
	strncpy(drvinfo->version, be_drvr_ver, 32);
	strncpy(drvinfo->fw_version, be_fw_ver, 32);
	strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
	drvinfo->testinfo_len = 0;
	drvinfo->regdump_len = 0;
	drvinfo->eedump_len = 0;
}

static int
be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;

	coalesce->rx_max_coalesced_frames = adapter->max_rx_coal;

	coalesce->rx_coalesce_usecs = adapter->cur_eqd;
	coalesce->rx_coalesce_usecs_high = adapter->max_eqd;
	coalesce->rx_coalesce_usecs_low = adapter->min_eqd;

	coalesce->tx_coalesce_usecs = adapter->cur_eqd;
	coalesce->tx_coalesce_usecs_high = adapter->max_eqd;
	coalesce->tx_coalesce_usecs_low = adapter->min_eqd;

	coalesce->use_adaptive_rx_coalesce = adapter->enable_aic;
	coalesce->use_adaptive_tx_coalesce = adapter->enable_aic;

	return 0;
}

/*
 * This routine is used to set interrup coalescing delay *as well as*
 * the number of pkts to coalesce for LRO.
 */
static int
be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;
	struct be_eq_object *eq_objectp;
	u32 max, min, cur;
	int status;

	adapter->max_rx_coal = coalesce->rx_max_coalesced_frames;
	if (adapter->max_rx_coal >= BE_LRO_MAX_PKTS)
		adapter->max_rx_coal = BE_LRO_MAX_PKTS;

	if (adapter->enable_aic == 0 &&
		coalesce->use_adaptive_rx_coalesce == 1) {
		/* if AIC is being turned on now, start with an EQD of 0 */
		adapter->cur_eqd = 0;
	}
	adapter->enable_aic = coalesce->use_adaptive_rx_coalesce;

	/* round off to nearest multiple of 8 */
	max = (((coalesce->rx_coalesce_usecs_high + 4) >> 3) << 3);
	min = (((coalesce->rx_coalesce_usecs_low + 4) >> 3) << 3);
	cur = (((coalesce->rx_coalesce_usecs + 4) >> 3) << 3);

	if (adapter->enable_aic) {
		/* accept low and high if AIC is enabled */
		if (max > MAX_EQD)
			max = MAX_EQD;
		if (min > max)
			min = max;
		adapter->max_eqd = max;
		adapter->min_eqd = min;
		if (adapter->cur_eqd > max)
			adapter->cur_eqd = max;
		if (adapter->cur_eqd < min)
			adapter->cur_eqd = min;
	} else {
		/* accept specified coalesce_usecs only if AIC is disabled */
		if (cur > MAX_EQD)
			cur = MAX_EQD;
		eq_objectp = &pnob->event_q_obj;
		status =
		    be_eq_modify_delay(&pnob->fn_obj, 1, &eq_objectp, &cur,
				       NULL, NULL, NULL);
		if (status == BE_SUCCESS)
			adapter->cur_eqd = cur;
	}
	return 0;
}

static u32 be_get_rx_csum(struct net_device *netdev)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;
	return adapter->rx_csum;
}

static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;

	if (data)
		adapter->rx_csum = 1;
	else
		adapter->rx_csum = 0;

	return 0;
}

static void
be_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
{
	switch (stringset) {
	case ETH_SS_STATS:
		memcpy(data, *benet_gstrings_stats,
		       sizeof(benet_gstrings_stats));
		break;
	}
}

static int be_get_stats_count(struct net_device *netdev)
{
	return BENET_STATS_LEN;
}

static void
be_get_ethtool_stats(struct net_device *netdev,
		     struct ethtool_stats *stats, uint64_t *data)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	struct be_adapter *adapter = pnob->adapter;
	int i;

	benet_get_stats(netdev);

	for (i = 0; i <= NET_DEV_STATS_LEN; i++)
		data[i] = ((unsigned long *)&adapter->benet_stats)[i];

	data[i] = adapter->be_stat.bes_tx_reqs;
	data[i++] = adapter->be_stat.bes_tx_fails;
	data[i++] = adapter->be_stat.bes_fwd_reqs;
	data[i++] = adapter->be_stat.bes_tx_wrbs;

	data[i++] = adapter->be_stat.bes_ints;
	data[i++] = adapter->be_stat.bes_events;
	data[i++] = adapter->be_stat.bes_tx_events;
	data[i++] = adapter->be_stat.bes_rx_events;
	data[i++] = adapter->be_stat.bes_tx_compl;
	data[i++] = adapter->be_stat.bes_rx_compl;
	data[i++] = adapter->be_stat.bes_ethrx_post_fail;
	data[i++] = adapter->be_stat.bes_802_3_dropped_frames;
	data[i++] = adapter->be_stat.bes_802_3_malformed_frames;
	data[i++] = adapter->be_stat.bes_rx_misc_pkts;
	data[i++] = adapter->be_stat.bes_eth_tx_rate;
	data[i++] = adapter->be_stat.bes_eth_rx_rate;
	data[i++] = adapter->be_stat.bes_rx_coal;
	data[i++] = adapter->be_stat.bes_rx_flush;

}

static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
	ecmd->speed = SPEED_10000;
	ecmd->duplex = DUPLEX_FULL;
	ecmd->autoneg = AUTONEG_DISABLE;
	return 0;
}

/* Get the Ring parameters from the pnob */
static void
be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
{
	struct be_net_object *pnob = netdev_priv(netdev);

	/* Pre Set Maxims */
	ring->rx_max_pending = pnob->rx_q_len;
	ring->rx_mini_max_pending = ring->rx_mini_max_pending;
	ring->rx_jumbo_max_pending = ring->rx_jumbo_max_pending;
	ring->tx_max_pending = pnob->tx_q_len;

	/* Current hardware Settings                */
	ring->rx_pending = atomic_read(&pnob->rx_q_posted);
	ring->rx_mini_pending = ring->rx_mini_pending;
	ring->rx_jumbo_pending = ring->rx_jumbo_pending;
	ring->tx_pending = atomic_read(&pnob->tx_q_used);

}

static void
be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	bool rxfc, txfc;
	int status;

	status = be_eth_get_flow_control(&pnob->fn_obj, &txfc, &rxfc);
	if (status != BE_SUCCESS) {
		dev_info(&netdev->dev, "Unable to get pause frame settings\n");
		/* return defaults */
		ecmd->rx_pause = 1;
		ecmd->tx_pause = 0;
		ecmd->autoneg = AUTONEG_ENABLE;
		return;
	}

	if (txfc == true)
		ecmd->tx_pause = 1;
	else
		ecmd->tx_pause = 0;

	if (rxfc == true)
		ecmd->rx_pause = 1;
	else
		ecmd->rx_pause = 0;

	ecmd->autoneg = AUTONEG_ENABLE;
}

static int
be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
{
	struct be_net_object *pnob = netdev_priv(netdev);
	bool txfc, rxfc;
	int status;

	if (ecmd->autoneg != AUTONEG_ENABLE)
		return -EINVAL;

	if (ecmd->tx_pause)
		txfc = true;
	else
		txfc = false;

	if (ecmd->rx_pause)
		rxfc = true;
	else
		rxfc = false;

	status = be_eth_set_flow_control(&pnob->fn_obj, txfc, rxfc);
	if (status != BE_SUCCESS) {
		dev_info(&netdev->dev, "Unable to set pause frame settings\n");
		return -1;
	}
	return 0;
}

struct ethtool_ops be_ethtool_ops = {
	.get_settings = be_get_settings,
	.get_drvinfo = be_get_drvinfo,
	.get_link = ethtool_op_get_link,
	.get_coalesce = be_get_coalesce,
	.set_coalesce = be_set_coalesce,
	.get_ringparam = be_get_ringparam,
	.get_pauseparam = be_get_pauseparam,
	.set_pauseparam = be_set_pauseparam,
	.get_rx_csum = be_get_rx_csum,
	.set_rx_csum = be_set_rx_csum,
	.get_tx_csum = ethtool_op_get_tx_csum,
	.set_tx_csum = ethtool_op_set_tx_csum,
	.get_sg = ethtool_op_get_sg,
	.set_sg = ethtool_op_set_sg,
	.get_tso = ethtool_op_get_tso,
	.set_tso = ethtool_op_set_tso,
	.get_strings = be_get_strings,
	.get_stats_count = be_get_stats_count,
	.get_ethtool_stats = be_get_ethtool_stats,
};