xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/intel/igc/igc_ethtool.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright (c)  2018 Intel Corporation */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun /* ethtool support for igc */
5*4882a593Smuzhiyun #include <linux/if_vlan.h>
6*4882a593Smuzhiyun #include <linux/pm_runtime.h>
7*4882a593Smuzhiyun #include <linux/mdio.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include "igc.h"
10*4882a593Smuzhiyun #include "igc_diag.h"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /* forward declaration */
13*4882a593Smuzhiyun struct igc_stats {
14*4882a593Smuzhiyun 	char stat_string[ETH_GSTRING_LEN];
15*4882a593Smuzhiyun 	int sizeof_stat;
16*4882a593Smuzhiyun 	int stat_offset;
17*4882a593Smuzhiyun };
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define IGC_STAT(_name, _stat) { \
20*4882a593Smuzhiyun 	.stat_string = _name, \
21*4882a593Smuzhiyun 	.sizeof_stat = sizeof_field(struct igc_adapter, _stat), \
22*4882a593Smuzhiyun 	.stat_offset = offsetof(struct igc_adapter, _stat) \
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun static const struct igc_stats igc_gstrings_stats[] = {
26*4882a593Smuzhiyun 	IGC_STAT("rx_packets", stats.gprc),
27*4882a593Smuzhiyun 	IGC_STAT("tx_packets", stats.gptc),
28*4882a593Smuzhiyun 	IGC_STAT("rx_bytes", stats.gorc),
29*4882a593Smuzhiyun 	IGC_STAT("tx_bytes", stats.gotc),
30*4882a593Smuzhiyun 	IGC_STAT("rx_broadcast", stats.bprc),
31*4882a593Smuzhiyun 	IGC_STAT("tx_broadcast", stats.bptc),
32*4882a593Smuzhiyun 	IGC_STAT("rx_multicast", stats.mprc),
33*4882a593Smuzhiyun 	IGC_STAT("tx_multicast", stats.mptc),
34*4882a593Smuzhiyun 	IGC_STAT("multicast", stats.mprc),
35*4882a593Smuzhiyun 	IGC_STAT("collisions", stats.colc),
36*4882a593Smuzhiyun 	IGC_STAT("rx_crc_errors", stats.crcerrs),
37*4882a593Smuzhiyun 	IGC_STAT("rx_no_buffer_count", stats.rnbc),
38*4882a593Smuzhiyun 	IGC_STAT("rx_missed_errors", stats.mpc),
39*4882a593Smuzhiyun 	IGC_STAT("tx_aborted_errors", stats.ecol),
40*4882a593Smuzhiyun 	IGC_STAT("tx_carrier_errors", stats.tncrs),
41*4882a593Smuzhiyun 	IGC_STAT("tx_window_errors", stats.latecol),
42*4882a593Smuzhiyun 	IGC_STAT("tx_abort_late_coll", stats.latecol),
43*4882a593Smuzhiyun 	IGC_STAT("tx_deferred_ok", stats.dc),
44*4882a593Smuzhiyun 	IGC_STAT("tx_single_coll_ok", stats.scc),
45*4882a593Smuzhiyun 	IGC_STAT("tx_multi_coll_ok", stats.mcc),
46*4882a593Smuzhiyun 	IGC_STAT("tx_timeout_count", tx_timeout_count),
47*4882a593Smuzhiyun 	IGC_STAT("rx_long_length_errors", stats.roc),
48*4882a593Smuzhiyun 	IGC_STAT("rx_short_length_errors", stats.ruc),
49*4882a593Smuzhiyun 	IGC_STAT("rx_align_errors", stats.algnerrc),
50*4882a593Smuzhiyun 	IGC_STAT("tx_tcp_seg_good", stats.tsctc),
51*4882a593Smuzhiyun 	IGC_STAT("tx_tcp_seg_failed", stats.tsctfc),
52*4882a593Smuzhiyun 	IGC_STAT("rx_flow_control_xon", stats.xonrxc),
53*4882a593Smuzhiyun 	IGC_STAT("rx_flow_control_xoff", stats.xoffrxc),
54*4882a593Smuzhiyun 	IGC_STAT("tx_flow_control_xon", stats.xontxc),
55*4882a593Smuzhiyun 	IGC_STAT("tx_flow_control_xoff", stats.xofftxc),
56*4882a593Smuzhiyun 	IGC_STAT("rx_long_byte_count", stats.gorc),
57*4882a593Smuzhiyun 	IGC_STAT("tx_dma_out_of_sync", stats.doosync),
58*4882a593Smuzhiyun 	IGC_STAT("tx_smbus", stats.mgptc),
59*4882a593Smuzhiyun 	IGC_STAT("rx_smbus", stats.mgprc),
60*4882a593Smuzhiyun 	IGC_STAT("dropped_smbus", stats.mgpdc),
61*4882a593Smuzhiyun 	IGC_STAT("os2bmc_rx_by_bmc", stats.o2bgptc),
62*4882a593Smuzhiyun 	IGC_STAT("os2bmc_tx_by_bmc", stats.b2ospc),
63*4882a593Smuzhiyun 	IGC_STAT("os2bmc_tx_by_host", stats.o2bspc),
64*4882a593Smuzhiyun 	IGC_STAT("os2bmc_rx_by_host", stats.b2ogprc),
65*4882a593Smuzhiyun 	IGC_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
66*4882a593Smuzhiyun 	IGC_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
67*4882a593Smuzhiyun 	IGC_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun #define IGC_NETDEV_STAT(_net_stat) { \
71*4882a593Smuzhiyun 	.stat_string = __stringify(_net_stat), \
72*4882a593Smuzhiyun 	.sizeof_stat = sizeof_field(struct rtnl_link_stats64, _net_stat), \
73*4882a593Smuzhiyun 	.stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun static const struct igc_stats igc_gstrings_net_stats[] = {
77*4882a593Smuzhiyun 	IGC_NETDEV_STAT(rx_errors),
78*4882a593Smuzhiyun 	IGC_NETDEV_STAT(tx_errors),
79*4882a593Smuzhiyun 	IGC_NETDEV_STAT(tx_dropped),
80*4882a593Smuzhiyun 	IGC_NETDEV_STAT(rx_length_errors),
81*4882a593Smuzhiyun 	IGC_NETDEV_STAT(rx_over_errors),
82*4882a593Smuzhiyun 	IGC_NETDEV_STAT(rx_frame_errors),
83*4882a593Smuzhiyun 	IGC_NETDEV_STAT(rx_fifo_errors),
84*4882a593Smuzhiyun 	IGC_NETDEV_STAT(tx_fifo_errors),
85*4882a593Smuzhiyun 	IGC_NETDEV_STAT(tx_heartbeat_errors)
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun enum igc_diagnostics_results {
89*4882a593Smuzhiyun 	TEST_REG = 0,
90*4882a593Smuzhiyun 	TEST_EEP,
91*4882a593Smuzhiyun 	TEST_IRQ,
92*4882a593Smuzhiyun 	TEST_LOOP,
93*4882a593Smuzhiyun 	TEST_LINK
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
97*4882a593Smuzhiyun 	[TEST_REG]  = "Register test  (offline)",
98*4882a593Smuzhiyun 	[TEST_EEP]  = "Eeprom test    (offline)",
99*4882a593Smuzhiyun 	[TEST_IRQ]  = "Interrupt test (offline)",
100*4882a593Smuzhiyun 	[TEST_LOOP] = "Loopback test  (offline)",
101*4882a593Smuzhiyun 	[TEST_LINK] = "Link test   (on/offline)"
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define IGC_GLOBAL_STATS_LEN	\
107*4882a593Smuzhiyun 	(sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
108*4882a593Smuzhiyun #define IGC_NETDEV_STATS_LEN	\
109*4882a593Smuzhiyun 	(sizeof(igc_gstrings_net_stats) / sizeof(struct igc_stats))
110*4882a593Smuzhiyun #define IGC_RX_QUEUE_STATS_LEN \
111*4882a593Smuzhiyun 	(sizeof(struct igc_rx_queue_stats) / sizeof(u64))
112*4882a593Smuzhiyun #define IGC_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
113*4882a593Smuzhiyun #define IGC_QUEUE_STATS_LEN \
114*4882a593Smuzhiyun 	((((struct igc_adapter *)netdev_priv(netdev))->num_rx_queues * \
115*4882a593Smuzhiyun 	  IGC_RX_QUEUE_STATS_LEN) + \
116*4882a593Smuzhiyun 	 (((struct igc_adapter *)netdev_priv(netdev))->num_tx_queues * \
117*4882a593Smuzhiyun 	  IGC_TX_QUEUE_STATS_LEN))
118*4882a593Smuzhiyun #define IGC_STATS_LEN \
119*4882a593Smuzhiyun 	(IGC_GLOBAL_STATS_LEN + IGC_NETDEV_STATS_LEN + IGC_QUEUE_STATS_LEN)
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun static const char igc_priv_flags_strings[][ETH_GSTRING_LEN] = {
122*4882a593Smuzhiyun #define IGC_PRIV_FLAGS_LEGACY_RX	BIT(0)
123*4882a593Smuzhiyun 	"legacy-rx",
124*4882a593Smuzhiyun };
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun #define IGC_PRIV_FLAGS_STR_LEN ARRAY_SIZE(igc_priv_flags_strings)
127*4882a593Smuzhiyun 
igc_ethtool_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)128*4882a593Smuzhiyun static void igc_ethtool_get_drvinfo(struct net_device *netdev,
129*4882a593Smuzhiyun 				    struct ethtool_drvinfo *drvinfo)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	strlcpy(drvinfo->driver,  igc_driver_name, sizeof(drvinfo->driver));
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	/* add fw_version here */
136*4882a593Smuzhiyun 	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
137*4882a593Smuzhiyun 		sizeof(drvinfo->bus_info));
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	drvinfo->n_priv_flags = IGC_PRIV_FLAGS_STR_LEN;
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun 
igc_ethtool_get_regs_len(struct net_device * netdev)142*4882a593Smuzhiyun static int igc_ethtool_get_regs_len(struct net_device *netdev)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	return IGC_REGS_LEN * sizeof(u32);
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun 
igc_ethtool_get_regs(struct net_device * netdev,struct ethtool_regs * regs,void * p)147*4882a593Smuzhiyun static void igc_ethtool_get_regs(struct net_device *netdev,
148*4882a593Smuzhiyun 				 struct ethtool_regs *regs, void *p)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
151*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
152*4882a593Smuzhiyun 	u32 *regs_buff = p;
153*4882a593Smuzhiyun 	u8 i;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	memset(p, 0, IGC_REGS_LEN * sizeof(u32));
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	regs->version = (2u << 24) | (hw->revision_id << 16) | hw->device_id;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	/* General Registers */
160*4882a593Smuzhiyun 	regs_buff[0] = rd32(IGC_CTRL);
161*4882a593Smuzhiyun 	regs_buff[1] = rd32(IGC_STATUS);
162*4882a593Smuzhiyun 	regs_buff[2] = rd32(IGC_CTRL_EXT);
163*4882a593Smuzhiyun 	regs_buff[3] = rd32(IGC_MDIC);
164*4882a593Smuzhiyun 	regs_buff[4] = rd32(IGC_CONNSW);
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	/* NVM Register */
167*4882a593Smuzhiyun 	regs_buff[5] = rd32(IGC_EECD);
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 	/* Interrupt */
170*4882a593Smuzhiyun 	/* Reading EICS for EICR because they read the
171*4882a593Smuzhiyun 	 * same but EICS does not clear on read
172*4882a593Smuzhiyun 	 */
173*4882a593Smuzhiyun 	regs_buff[6] = rd32(IGC_EICS);
174*4882a593Smuzhiyun 	regs_buff[7] = rd32(IGC_EICS);
175*4882a593Smuzhiyun 	regs_buff[8] = rd32(IGC_EIMS);
176*4882a593Smuzhiyun 	regs_buff[9] = rd32(IGC_EIMC);
177*4882a593Smuzhiyun 	regs_buff[10] = rd32(IGC_EIAC);
178*4882a593Smuzhiyun 	regs_buff[11] = rd32(IGC_EIAM);
179*4882a593Smuzhiyun 	/* Reading ICS for ICR because they read the
180*4882a593Smuzhiyun 	 * same but ICS does not clear on read
181*4882a593Smuzhiyun 	 */
182*4882a593Smuzhiyun 	regs_buff[12] = rd32(IGC_ICS);
183*4882a593Smuzhiyun 	regs_buff[13] = rd32(IGC_ICS);
184*4882a593Smuzhiyun 	regs_buff[14] = rd32(IGC_IMS);
185*4882a593Smuzhiyun 	regs_buff[15] = rd32(IGC_IMC);
186*4882a593Smuzhiyun 	regs_buff[16] = rd32(IGC_IAC);
187*4882a593Smuzhiyun 	regs_buff[17] = rd32(IGC_IAM);
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 	/* Flow Control */
190*4882a593Smuzhiyun 	regs_buff[18] = rd32(IGC_FCAL);
191*4882a593Smuzhiyun 	regs_buff[19] = rd32(IGC_FCAH);
192*4882a593Smuzhiyun 	regs_buff[20] = rd32(IGC_FCTTV);
193*4882a593Smuzhiyun 	regs_buff[21] = rd32(IGC_FCRTL);
194*4882a593Smuzhiyun 	regs_buff[22] = rd32(IGC_FCRTH);
195*4882a593Smuzhiyun 	regs_buff[23] = rd32(IGC_FCRTV);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	/* Receive */
198*4882a593Smuzhiyun 	regs_buff[24] = rd32(IGC_RCTL);
199*4882a593Smuzhiyun 	regs_buff[25] = rd32(IGC_RXCSUM);
200*4882a593Smuzhiyun 	regs_buff[26] = rd32(IGC_RLPML);
201*4882a593Smuzhiyun 	regs_buff[27] = rd32(IGC_RFCTL);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	/* Transmit */
204*4882a593Smuzhiyun 	regs_buff[28] = rd32(IGC_TCTL);
205*4882a593Smuzhiyun 	regs_buff[29] = rd32(IGC_TIPG);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	/* Wake Up */
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	/* MAC */
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	/* Statistics */
212*4882a593Smuzhiyun 	regs_buff[30] = adapter->stats.crcerrs;
213*4882a593Smuzhiyun 	regs_buff[31] = adapter->stats.algnerrc;
214*4882a593Smuzhiyun 	regs_buff[32] = adapter->stats.symerrs;
215*4882a593Smuzhiyun 	regs_buff[33] = adapter->stats.rxerrc;
216*4882a593Smuzhiyun 	regs_buff[34] = adapter->stats.mpc;
217*4882a593Smuzhiyun 	regs_buff[35] = adapter->stats.scc;
218*4882a593Smuzhiyun 	regs_buff[36] = adapter->stats.ecol;
219*4882a593Smuzhiyun 	regs_buff[37] = adapter->stats.mcc;
220*4882a593Smuzhiyun 	regs_buff[38] = adapter->stats.latecol;
221*4882a593Smuzhiyun 	regs_buff[39] = adapter->stats.colc;
222*4882a593Smuzhiyun 	regs_buff[40] = adapter->stats.dc;
223*4882a593Smuzhiyun 	regs_buff[41] = adapter->stats.tncrs;
224*4882a593Smuzhiyun 	regs_buff[42] = adapter->stats.sec;
225*4882a593Smuzhiyun 	regs_buff[43] = adapter->stats.htdpmc;
226*4882a593Smuzhiyun 	regs_buff[44] = adapter->stats.rlec;
227*4882a593Smuzhiyun 	regs_buff[45] = adapter->stats.xonrxc;
228*4882a593Smuzhiyun 	regs_buff[46] = adapter->stats.xontxc;
229*4882a593Smuzhiyun 	regs_buff[47] = adapter->stats.xoffrxc;
230*4882a593Smuzhiyun 	regs_buff[48] = adapter->stats.xofftxc;
231*4882a593Smuzhiyun 	regs_buff[49] = adapter->stats.fcruc;
232*4882a593Smuzhiyun 	regs_buff[50] = adapter->stats.prc64;
233*4882a593Smuzhiyun 	regs_buff[51] = adapter->stats.prc127;
234*4882a593Smuzhiyun 	regs_buff[52] = adapter->stats.prc255;
235*4882a593Smuzhiyun 	regs_buff[53] = adapter->stats.prc511;
236*4882a593Smuzhiyun 	regs_buff[54] = adapter->stats.prc1023;
237*4882a593Smuzhiyun 	regs_buff[55] = adapter->stats.prc1522;
238*4882a593Smuzhiyun 	regs_buff[56] = adapter->stats.gprc;
239*4882a593Smuzhiyun 	regs_buff[57] = adapter->stats.bprc;
240*4882a593Smuzhiyun 	regs_buff[58] = adapter->stats.mprc;
241*4882a593Smuzhiyun 	regs_buff[59] = adapter->stats.gptc;
242*4882a593Smuzhiyun 	regs_buff[60] = adapter->stats.gorc;
243*4882a593Smuzhiyun 	regs_buff[61] = adapter->stats.gotc;
244*4882a593Smuzhiyun 	regs_buff[62] = adapter->stats.rnbc;
245*4882a593Smuzhiyun 	regs_buff[63] = adapter->stats.ruc;
246*4882a593Smuzhiyun 	regs_buff[64] = adapter->stats.rfc;
247*4882a593Smuzhiyun 	regs_buff[65] = adapter->stats.roc;
248*4882a593Smuzhiyun 	regs_buff[66] = adapter->stats.rjc;
249*4882a593Smuzhiyun 	regs_buff[67] = adapter->stats.mgprc;
250*4882a593Smuzhiyun 	regs_buff[68] = adapter->stats.mgpdc;
251*4882a593Smuzhiyun 	regs_buff[69] = adapter->stats.mgptc;
252*4882a593Smuzhiyun 	regs_buff[70] = adapter->stats.tor;
253*4882a593Smuzhiyun 	regs_buff[71] = adapter->stats.tot;
254*4882a593Smuzhiyun 	regs_buff[72] = adapter->stats.tpr;
255*4882a593Smuzhiyun 	regs_buff[73] = adapter->stats.tpt;
256*4882a593Smuzhiyun 	regs_buff[74] = adapter->stats.ptc64;
257*4882a593Smuzhiyun 	regs_buff[75] = adapter->stats.ptc127;
258*4882a593Smuzhiyun 	regs_buff[76] = adapter->stats.ptc255;
259*4882a593Smuzhiyun 	regs_buff[77] = adapter->stats.ptc511;
260*4882a593Smuzhiyun 	regs_buff[78] = adapter->stats.ptc1023;
261*4882a593Smuzhiyun 	regs_buff[79] = adapter->stats.ptc1522;
262*4882a593Smuzhiyun 	regs_buff[80] = adapter->stats.mptc;
263*4882a593Smuzhiyun 	regs_buff[81] = adapter->stats.bptc;
264*4882a593Smuzhiyun 	regs_buff[82] = adapter->stats.tsctc;
265*4882a593Smuzhiyun 	regs_buff[83] = adapter->stats.iac;
266*4882a593Smuzhiyun 	regs_buff[84] = adapter->stats.rpthc;
267*4882a593Smuzhiyun 	regs_buff[85] = adapter->stats.hgptc;
268*4882a593Smuzhiyun 	regs_buff[86] = adapter->stats.hgorc;
269*4882a593Smuzhiyun 	regs_buff[87] = adapter->stats.hgotc;
270*4882a593Smuzhiyun 	regs_buff[88] = adapter->stats.lenerrs;
271*4882a593Smuzhiyun 	regs_buff[89] = adapter->stats.scvpc;
272*4882a593Smuzhiyun 	regs_buff[90] = adapter->stats.hrmpc;
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
275*4882a593Smuzhiyun 		regs_buff[91 + i] = rd32(IGC_SRRCTL(i));
276*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
277*4882a593Smuzhiyun 		regs_buff[95 + i] = rd32(IGC_PSRTYPE(i));
278*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
279*4882a593Smuzhiyun 		regs_buff[99 + i] = rd32(IGC_RDBAL(i));
280*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
281*4882a593Smuzhiyun 		regs_buff[103 + i] = rd32(IGC_RDBAH(i));
282*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
283*4882a593Smuzhiyun 		regs_buff[107 + i] = rd32(IGC_RDLEN(i));
284*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
285*4882a593Smuzhiyun 		regs_buff[111 + i] = rd32(IGC_RDH(i));
286*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
287*4882a593Smuzhiyun 		regs_buff[115 + i] = rd32(IGC_RDT(i));
288*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
289*4882a593Smuzhiyun 		regs_buff[119 + i] = rd32(IGC_RXDCTL(i));
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	for (i = 0; i < 10; i++)
292*4882a593Smuzhiyun 		regs_buff[123 + i] = rd32(IGC_EITR(i));
293*4882a593Smuzhiyun 	for (i = 0; i < 16; i++)
294*4882a593Smuzhiyun 		regs_buff[139 + i] = rd32(IGC_RAL(i));
295*4882a593Smuzhiyun 	for (i = 0; i < 16; i++)
296*4882a593Smuzhiyun 		regs_buff[145 + i] = rd32(IGC_RAH(i));
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
299*4882a593Smuzhiyun 		regs_buff[149 + i] = rd32(IGC_TDBAL(i));
300*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
301*4882a593Smuzhiyun 		regs_buff[152 + i] = rd32(IGC_TDBAH(i));
302*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
303*4882a593Smuzhiyun 		regs_buff[156 + i] = rd32(IGC_TDLEN(i));
304*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
305*4882a593Smuzhiyun 		regs_buff[160 + i] = rd32(IGC_TDH(i));
306*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
307*4882a593Smuzhiyun 		regs_buff[164 + i] = rd32(IGC_TDT(i));
308*4882a593Smuzhiyun 	for (i = 0; i < 4; i++)
309*4882a593Smuzhiyun 		regs_buff[168 + i] = rd32(IGC_TXDCTL(i));
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* XXX: Due to a bug few lines above, RAL and RAH registers are
312*4882a593Smuzhiyun 	 * overwritten. To preserve the ABI, we write these registers again in
313*4882a593Smuzhiyun 	 * regs_buff.
314*4882a593Smuzhiyun 	 */
315*4882a593Smuzhiyun 	for (i = 0; i < 16; i++)
316*4882a593Smuzhiyun 		regs_buff[172 + i] = rd32(IGC_RAL(i));
317*4882a593Smuzhiyun 	for (i = 0; i < 16; i++)
318*4882a593Smuzhiyun 		regs_buff[188 + i] = rd32(IGC_RAH(i));
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	regs_buff[204] = rd32(IGC_VLANPQF);
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 	for (i = 0; i < 8; i++)
323*4882a593Smuzhiyun 		regs_buff[205 + i] = rd32(IGC_ETQF(i));
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	regs_buff[213] = adapter->stats.tlpic;
326*4882a593Smuzhiyun 	regs_buff[214] = adapter->stats.rlpic;
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun 
igc_ethtool_get_wol(struct net_device * netdev,struct ethtool_wolinfo * wol)329*4882a593Smuzhiyun static void igc_ethtool_get_wol(struct net_device *netdev,
330*4882a593Smuzhiyun 				struct ethtool_wolinfo *wol)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	wol->wolopts = 0;
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
337*4882a593Smuzhiyun 		return;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	wol->supported = WAKE_UCAST | WAKE_MCAST |
340*4882a593Smuzhiyun 			 WAKE_BCAST | WAKE_MAGIC |
341*4882a593Smuzhiyun 			 WAKE_PHY;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	/* apply any specific unsupported masks here */
344*4882a593Smuzhiyun 	switch (adapter->hw.device_id) {
345*4882a593Smuzhiyun 	default:
346*4882a593Smuzhiyun 		break;
347*4882a593Smuzhiyun 	}
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	if (adapter->wol & IGC_WUFC_EX)
350*4882a593Smuzhiyun 		wol->wolopts |= WAKE_UCAST;
351*4882a593Smuzhiyun 	if (adapter->wol & IGC_WUFC_MC)
352*4882a593Smuzhiyun 		wol->wolopts |= WAKE_MCAST;
353*4882a593Smuzhiyun 	if (adapter->wol & IGC_WUFC_BC)
354*4882a593Smuzhiyun 		wol->wolopts |= WAKE_BCAST;
355*4882a593Smuzhiyun 	if (adapter->wol & IGC_WUFC_MAG)
356*4882a593Smuzhiyun 		wol->wolopts |= WAKE_MAGIC;
357*4882a593Smuzhiyun 	if (adapter->wol & IGC_WUFC_LNKC)
358*4882a593Smuzhiyun 		wol->wolopts |= WAKE_PHY;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun 
igc_ethtool_set_wol(struct net_device * netdev,struct ethtool_wolinfo * wol)361*4882a593Smuzhiyun static int igc_ethtool_set_wol(struct net_device *netdev,
362*4882a593Smuzhiyun 			       struct ethtool_wolinfo *wol)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_FILTER))
367*4882a593Smuzhiyun 		return -EOPNOTSUPP;
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun 	if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
370*4882a593Smuzhiyun 		return wol->wolopts ? -EOPNOTSUPP : 0;
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	/* these settings will always override what we currently have */
373*4882a593Smuzhiyun 	adapter->wol = 0;
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun 	if (wol->wolopts & WAKE_UCAST)
376*4882a593Smuzhiyun 		adapter->wol |= IGC_WUFC_EX;
377*4882a593Smuzhiyun 	if (wol->wolopts & WAKE_MCAST)
378*4882a593Smuzhiyun 		adapter->wol |= IGC_WUFC_MC;
379*4882a593Smuzhiyun 	if (wol->wolopts & WAKE_BCAST)
380*4882a593Smuzhiyun 		adapter->wol |= IGC_WUFC_BC;
381*4882a593Smuzhiyun 	if (wol->wolopts & WAKE_MAGIC)
382*4882a593Smuzhiyun 		adapter->wol |= IGC_WUFC_MAG;
383*4882a593Smuzhiyun 	if (wol->wolopts & WAKE_PHY)
384*4882a593Smuzhiyun 		adapter->wol |= IGC_WUFC_LNKC;
385*4882a593Smuzhiyun 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun 	return 0;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun 
igc_ethtool_get_msglevel(struct net_device * netdev)390*4882a593Smuzhiyun static u32 igc_ethtool_get_msglevel(struct net_device *netdev)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun 	return adapter->msg_enable;
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun 
igc_ethtool_set_msglevel(struct net_device * netdev,u32 data)397*4882a593Smuzhiyun static void igc_ethtool_set_msglevel(struct net_device *netdev, u32 data)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	adapter->msg_enable = data;
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun 
igc_ethtool_nway_reset(struct net_device * netdev)404*4882a593Smuzhiyun static int igc_ethtool_nway_reset(struct net_device *netdev)
405*4882a593Smuzhiyun {
406*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun 	if (netif_running(netdev))
409*4882a593Smuzhiyun 		igc_reinit_locked(adapter);
410*4882a593Smuzhiyun 	return 0;
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun 
igc_ethtool_get_link(struct net_device * netdev)413*4882a593Smuzhiyun static u32 igc_ethtool_get_link(struct net_device *netdev)
414*4882a593Smuzhiyun {
415*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
416*4882a593Smuzhiyun 	struct igc_mac_info *mac = &adapter->hw.mac;
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun 	/* If the link is not reported up to netdev, interrupts are disabled,
419*4882a593Smuzhiyun 	 * and so the physical link state may have changed since we last
420*4882a593Smuzhiyun 	 * looked. Set get_link_status to make sure that the true link
421*4882a593Smuzhiyun 	 * state is interrogated, rather than pulling a cached and possibly
422*4882a593Smuzhiyun 	 * stale link state from the driver.
423*4882a593Smuzhiyun 	 */
424*4882a593Smuzhiyun 	if (!netif_carrier_ok(netdev))
425*4882a593Smuzhiyun 		mac->get_link_status = 1;
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	return igc_has_link(adapter);
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun 
igc_ethtool_get_eeprom_len(struct net_device * netdev)430*4882a593Smuzhiyun static int igc_ethtool_get_eeprom_len(struct net_device *netdev)
431*4882a593Smuzhiyun {
432*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	return adapter->hw.nvm.word_size * 2;
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun 
igc_ethtool_get_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)437*4882a593Smuzhiyun static int igc_ethtool_get_eeprom(struct net_device *netdev,
438*4882a593Smuzhiyun 				  struct ethtool_eeprom *eeprom, u8 *bytes)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
441*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
442*4882a593Smuzhiyun 	int first_word, last_word;
443*4882a593Smuzhiyun 	u16 *eeprom_buff;
444*4882a593Smuzhiyun 	int ret_val = 0;
445*4882a593Smuzhiyun 	u16 i;
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun 	if (eeprom->len == 0)
448*4882a593Smuzhiyun 		return -EINVAL;
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun 	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun 	first_word = eeprom->offset >> 1;
453*4882a593Smuzhiyun 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun 	eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
456*4882a593Smuzhiyun 				    GFP_KERNEL);
457*4882a593Smuzhiyun 	if (!eeprom_buff)
458*4882a593Smuzhiyun 		return -ENOMEM;
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun 	if (hw->nvm.type == igc_nvm_eeprom_spi) {
461*4882a593Smuzhiyun 		ret_val = hw->nvm.ops.read(hw, first_word,
462*4882a593Smuzhiyun 					   last_word - first_word + 1,
463*4882a593Smuzhiyun 					   eeprom_buff);
464*4882a593Smuzhiyun 	} else {
465*4882a593Smuzhiyun 		for (i = 0; i < last_word - first_word + 1; i++) {
466*4882a593Smuzhiyun 			ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
467*4882a593Smuzhiyun 						   &eeprom_buff[i]);
468*4882a593Smuzhiyun 			if (ret_val)
469*4882a593Smuzhiyun 				break;
470*4882a593Smuzhiyun 		}
471*4882a593Smuzhiyun 	}
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	/* Device's eeprom is always little-endian, word addressable */
474*4882a593Smuzhiyun 	for (i = 0; i < last_word - first_word + 1; i++)
475*4882a593Smuzhiyun 		le16_to_cpus(&eeprom_buff[i]);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun 	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
478*4882a593Smuzhiyun 	       eeprom->len);
479*4882a593Smuzhiyun 	kfree(eeprom_buff);
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun 	return ret_val;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun 
igc_ethtool_set_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)484*4882a593Smuzhiyun static int igc_ethtool_set_eeprom(struct net_device *netdev,
485*4882a593Smuzhiyun 				  struct ethtool_eeprom *eeprom, u8 *bytes)
486*4882a593Smuzhiyun {
487*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
488*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
489*4882a593Smuzhiyun 	int max_len, first_word, last_word, ret_val = 0;
490*4882a593Smuzhiyun 	u16 *eeprom_buff;
491*4882a593Smuzhiyun 	void *ptr;
492*4882a593Smuzhiyun 	u16 i;
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun 	if (eeprom->len == 0)
495*4882a593Smuzhiyun 		return -EOPNOTSUPP;
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun 	if (hw->mac.type >= igc_i225 &&
498*4882a593Smuzhiyun 	    !igc_get_flash_presence_i225(hw)) {
499*4882a593Smuzhiyun 		return -EOPNOTSUPP;
500*4882a593Smuzhiyun 	}
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
503*4882a593Smuzhiyun 		return -EFAULT;
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun 	max_len = hw->nvm.word_size * 2;
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	first_word = eeprom->offset >> 1;
508*4882a593Smuzhiyun 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
509*4882a593Smuzhiyun 	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
510*4882a593Smuzhiyun 	if (!eeprom_buff)
511*4882a593Smuzhiyun 		return -ENOMEM;
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun 	ptr = (void *)eeprom_buff;
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun 	if (eeprom->offset & 1) {
516*4882a593Smuzhiyun 		/* need read/modify/write of first changed EEPROM word
517*4882a593Smuzhiyun 		 * only the second byte of the word is being modified
518*4882a593Smuzhiyun 		 */
519*4882a593Smuzhiyun 		ret_val = hw->nvm.ops.read(hw, first_word, 1,
520*4882a593Smuzhiyun 					    &eeprom_buff[0]);
521*4882a593Smuzhiyun 		ptr++;
522*4882a593Smuzhiyun 	}
523*4882a593Smuzhiyun 	if (((eeprom->offset + eeprom->len) & 1) && ret_val == 0) {
524*4882a593Smuzhiyun 		/* need read/modify/write of last changed EEPROM word
525*4882a593Smuzhiyun 		 * only the first byte of the word is being modified
526*4882a593Smuzhiyun 		 */
527*4882a593Smuzhiyun 		ret_val = hw->nvm.ops.read(hw, last_word, 1,
528*4882a593Smuzhiyun 				   &eeprom_buff[last_word - first_word]);
529*4882a593Smuzhiyun 	}
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun 	/* Device's eeprom is always little-endian, word addressable */
532*4882a593Smuzhiyun 	for (i = 0; i < last_word - first_word + 1; i++)
533*4882a593Smuzhiyun 		le16_to_cpus(&eeprom_buff[i]);
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	memcpy(ptr, bytes, eeprom->len);
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 	for (i = 0; i < last_word - first_word + 1; i++)
538*4882a593Smuzhiyun 		eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun 	ret_val = hw->nvm.ops.write(hw, first_word,
541*4882a593Smuzhiyun 				    last_word - first_word + 1, eeprom_buff);
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun 	/* Update the checksum if nvm write succeeded */
544*4882a593Smuzhiyun 	if (ret_val == 0)
545*4882a593Smuzhiyun 		hw->nvm.ops.update(hw);
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun 	/* check if need: igc_set_fw_version(adapter); */
548*4882a593Smuzhiyun 	kfree(eeprom_buff);
549*4882a593Smuzhiyun 	return ret_val;
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun 
igc_ethtool_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring)552*4882a593Smuzhiyun static void igc_ethtool_get_ringparam(struct net_device *netdev,
553*4882a593Smuzhiyun 				      struct ethtool_ringparam *ring)
554*4882a593Smuzhiyun {
555*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	ring->rx_max_pending = IGC_MAX_RXD;
558*4882a593Smuzhiyun 	ring->tx_max_pending = IGC_MAX_TXD;
559*4882a593Smuzhiyun 	ring->rx_pending = adapter->rx_ring_count;
560*4882a593Smuzhiyun 	ring->tx_pending = adapter->tx_ring_count;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun 
igc_ethtool_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring)563*4882a593Smuzhiyun static int igc_ethtool_set_ringparam(struct net_device *netdev,
564*4882a593Smuzhiyun 				     struct ethtool_ringparam *ring)
565*4882a593Smuzhiyun {
566*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
567*4882a593Smuzhiyun 	struct igc_ring *temp_ring;
568*4882a593Smuzhiyun 	u16 new_rx_count, new_tx_count;
569*4882a593Smuzhiyun 	int i, err = 0;
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun 	if (ring->rx_mini_pending || ring->rx_jumbo_pending)
572*4882a593Smuzhiyun 		return -EINVAL;
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun 	new_rx_count = min_t(u32, ring->rx_pending, IGC_MAX_RXD);
575*4882a593Smuzhiyun 	new_rx_count = max_t(u16, new_rx_count, IGC_MIN_RXD);
576*4882a593Smuzhiyun 	new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun 	new_tx_count = min_t(u32, ring->tx_pending, IGC_MAX_TXD);
579*4882a593Smuzhiyun 	new_tx_count = max_t(u16, new_tx_count, IGC_MIN_TXD);
580*4882a593Smuzhiyun 	new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
581*4882a593Smuzhiyun 
582*4882a593Smuzhiyun 	if (new_tx_count == adapter->tx_ring_count &&
583*4882a593Smuzhiyun 	    new_rx_count == adapter->rx_ring_count) {
584*4882a593Smuzhiyun 		/* nothing to do */
585*4882a593Smuzhiyun 		return 0;
586*4882a593Smuzhiyun 	}
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
589*4882a593Smuzhiyun 		usleep_range(1000, 2000);
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun 	if (!netif_running(adapter->netdev)) {
592*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_tx_queues; i++)
593*4882a593Smuzhiyun 			adapter->tx_ring[i]->count = new_tx_count;
594*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_rx_queues; i++)
595*4882a593Smuzhiyun 			adapter->rx_ring[i]->count = new_rx_count;
596*4882a593Smuzhiyun 		adapter->tx_ring_count = new_tx_count;
597*4882a593Smuzhiyun 		adapter->rx_ring_count = new_rx_count;
598*4882a593Smuzhiyun 		goto clear_reset;
599*4882a593Smuzhiyun 	}
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	if (adapter->num_tx_queues > adapter->num_rx_queues)
602*4882a593Smuzhiyun 		temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
603*4882a593Smuzhiyun 					       adapter->num_tx_queues));
604*4882a593Smuzhiyun 	else
605*4882a593Smuzhiyun 		temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
606*4882a593Smuzhiyun 					       adapter->num_rx_queues));
607*4882a593Smuzhiyun 
608*4882a593Smuzhiyun 	if (!temp_ring) {
609*4882a593Smuzhiyun 		err = -ENOMEM;
610*4882a593Smuzhiyun 		goto clear_reset;
611*4882a593Smuzhiyun 	}
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	igc_down(adapter);
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun 	/* We can't just free everything and then setup again,
616*4882a593Smuzhiyun 	 * because the ISRs in MSI-X mode get passed pointers
617*4882a593Smuzhiyun 	 * to the Tx and Rx ring structs.
618*4882a593Smuzhiyun 	 */
619*4882a593Smuzhiyun 	if (new_tx_count != adapter->tx_ring_count) {
620*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_tx_queues; i++) {
621*4882a593Smuzhiyun 			memcpy(&temp_ring[i], adapter->tx_ring[i],
622*4882a593Smuzhiyun 			       sizeof(struct igc_ring));
623*4882a593Smuzhiyun 
624*4882a593Smuzhiyun 			temp_ring[i].count = new_tx_count;
625*4882a593Smuzhiyun 			err = igc_setup_tx_resources(&temp_ring[i]);
626*4882a593Smuzhiyun 			if (err) {
627*4882a593Smuzhiyun 				while (i) {
628*4882a593Smuzhiyun 					i--;
629*4882a593Smuzhiyun 					igc_free_tx_resources(&temp_ring[i]);
630*4882a593Smuzhiyun 				}
631*4882a593Smuzhiyun 				goto err_setup;
632*4882a593Smuzhiyun 			}
633*4882a593Smuzhiyun 		}
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_tx_queues; i++) {
636*4882a593Smuzhiyun 			igc_free_tx_resources(adapter->tx_ring[i]);
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun 			memcpy(adapter->tx_ring[i], &temp_ring[i],
639*4882a593Smuzhiyun 			       sizeof(struct igc_ring));
640*4882a593Smuzhiyun 		}
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun 		adapter->tx_ring_count = new_tx_count;
643*4882a593Smuzhiyun 	}
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun 	if (new_rx_count != adapter->rx_ring_count) {
646*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_rx_queues; i++) {
647*4882a593Smuzhiyun 			memcpy(&temp_ring[i], adapter->rx_ring[i],
648*4882a593Smuzhiyun 			       sizeof(struct igc_ring));
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 			temp_ring[i].count = new_rx_count;
651*4882a593Smuzhiyun 			err = igc_setup_rx_resources(&temp_ring[i]);
652*4882a593Smuzhiyun 			if (err) {
653*4882a593Smuzhiyun 				while (i) {
654*4882a593Smuzhiyun 					i--;
655*4882a593Smuzhiyun 					igc_free_rx_resources(&temp_ring[i]);
656*4882a593Smuzhiyun 				}
657*4882a593Smuzhiyun 				goto err_setup;
658*4882a593Smuzhiyun 			}
659*4882a593Smuzhiyun 		}
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_rx_queues; i++) {
662*4882a593Smuzhiyun 			igc_free_rx_resources(adapter->rx_ring[i]);
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 			memcpy(adapter->rx_ring[i], &temp_ring[i],
665*4882a593Smuzhiyun 			       sizeof(struct igc_ring));
666*4882a593Smuzhiyun 		}
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 		adapter->rx_ring_count = new_rx_count;
669*4882a593Smuzhiyun 	}
670*4882a593Smuzhiyun err_setup:
671*4882a593Smuzhiyun 	igc_up(adapter);
672*4882a593Smuzhiyun 	vfree(temp_ring);
673*4882a593Smuzhiyun clear_reset:
674*4882a593Smuzhiyun 	clear_bit(__IGC_RESETTING, &adapter->state);
675*4882a593Smuzhiyun 	return err;
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun 
igc_ethtool_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)678*4882a593Smuzhiyun static void igc_ethtool_get_pauseparam(struct net_device *netdev,
679*4882a593Smuzhiyun 				       struct ethtool_pauseparam *pause)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
682*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun 	pause->autoneg =
685*4882a593Smuzhiyun 		(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
686*4882a593Smuzhiyun 
687*4882a593Smuzhiyun 	if (hw->fc.current_mode == igc_fc_rx_pause) {
688*4882a593Smuzhiyun 		pause->rx_pause = 1;
689*4882a593Smuzhiyun 	} else if (hw->fc.current_mode == igc_fc_tx_pause) {
690*4882a593Smuzhiyun 		pause->tx_pause = 1;
691*4882a593Smuzhiyun 	} else if (hw->fc.current_mode == igc_fc_full) {
692*4882a593Smuzhiyun 		pause->rx_pause = 1;
693*4882a593Smuzhiyun 		pause->tx_pause = 1;
694*4882a593Smuzhiyun 	}
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun 
igc_ethtool_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)697*4882a593Smuzhiyun static int igc_ethtool_set_pauseparam(struct net_device *netdev,
698*4882a593Smuzhiyun 				      struct ethtool_pauseparam *pause)
699*4882a593Smuzhiyun {
700*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
701*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
702*4882a593Smuzhiyun 	int retval = 0;
703*4882a593Smuzhiyun 
704*4882a593Smuzhiyun 	adapter->fc_autoneg = pause->autoneg;
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
707*4882a593Smuzhiyun 		usleep_range(1000, 2000);
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun 	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
710*4882a593Smuzhiyun 		hw->fc.requested_mode = igc_fc_default;
711*4882a593Smuzhiyun 		if (netif_running(adapter->netdev)) {
712*4882a593Smuzhiyun 			igc_down(adapter);
713*4882a593Smuzhiyun 			igc_up(adapter);
714*4882a593Smuzhiyun 		} else {
715*4882a593Smuzhiyun 			igc_reset(adapter);
716*4882a593Smuzhiyun 		}
717*4882a593Smuzhiyun 	} else {
718*4882a593Smuzhiyun 		if (pause->rx_pause && pause->tx_pause)
719*4882a593Smuzhiyun 			hw->fc.requested_mode = igc_fc_full;
720*4882a593Smuzhiyun 		else if (pause->rx_pause && !pause->tx_pause)
721*4882a593Smuzhiyun 			hw->fc.requested_mode = igc_fc_rx_pause;
722*4882a593Smuzhiyun 		else if (!pause->rx_pause && pause->tx_pause)
723*4882a593Smuzhiyun 			hw->fc.requested_mode = igc_fc_tx_pause;
724*4882a593Smuzhiyun 		else if (!pause->rx_pause && !pause->tx_pause)
725*4882a593Smuzhiyun 			hw->fc.requested_mode = igc_fc_none;
726*4882a593Smuzhiyun 
727*4882a593Smuzhiyun 		hw->fc.current_mode = hw->fc.requested_mode;
728*4882a593Smuzhiyun 
729*4882a593Smuzhiyun 		retval = ((hw->phy.media_type == igc_media_type_copper) ?
730*4882a593Smuzhiyun 			  igc_force_mac_fc(hw) : igc_setup_link(hw));
731*4882a593Smuzhiyun 	}
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun 	clear_bit(__IGC_RESETTING, &adapter->state);
734*4882a593Smuzhiyun 	return retval;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun 
igc_ethtool_get_strings(struct net_device * netdev,u32 stringset,u8 * data)737*4882a593Smuzhiyun static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
738*4882a593Smuzhiyun 				    u8 *data)
739*4882a593Smuzhiyun {
740*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
741*4882a593Smuzhiyun 	u8 *p = data;
742*4882a593Smuzhiyun 	int i;
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun 	switch (stringset) {
745*4882a593Smuzhiyun 	case ETH_SS_TEST:
746*4882a593Smuzhiyun 		memcpy(data, *igc_gstrings_test,
747*4882a593Smuzhiyun 		       IGC_TEST_LEN * ETH_GSTRING_LEN);
748*4882a593Smuzhiyun 		break;
749*4882a593Smuzhiyun 	case ETH_SS_STATS:
750*4882a593Smuzhiyun 		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) {
751*4882a593Smuzhiyun 			memcpy(p, igc_gstrings_stats[i].stat_string,
752*4882a593Smuzhiyun 			       ETH_GSTRING_LEN);
753*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
754*4882a593Smuzhiyun 		}
755*4882a593Smuzhiyun 		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) {
756*4882a593Smuzhiyun 			memcpy(p, igc_gstrings_net_stats[i].stat_string,
757*4882a593Smuzhiyun 			       ETH_GSTRING_LEN);
758*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
759*4882a593Smuzhiyun 		}
760*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_tx_queues; i++) {
761*4882a593Smuzhiyun 			sprintf(p, "tx_queue_%u_packets", i);
762*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
763*4882a593Smuzhiyun 			sprintf(p, "tx_queue_%u_bytes", i);
764*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
765*4882a593Smuzhiyun 			sprintf(p, "tx_queue_%u_restart", i);
766*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
767*4882a593Smuzhiyun 		}
768*4882a593Smuzhiyun 		for (i = 0; i < adapter->num_rx_queues; i++) {
769*4882a593Smuzhiyun 			sprintf(p, "rx_queue_%u_packets", i);
770*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
771*4882a593Smuzhiyun 			sprintf(p, "rx_queue_%u_bytes", i);
772*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
773*4882a593Smuzhiyun 			sprintf(p, "rx_queue_%u_drops", i);
774*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
775*4882a593Smuzhiyun 			sprintf(p, "rx_queue_%u_csum_err", i);
776*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
777*4882a593Smuzhiyun 			sprintf(p, "rx_queue_%u_alloc_failed", i);
778*4882a593Smuzhiyun 			p += ETH_GSTRING_LEN;
779*4882a593Smuzhiyun 		}
780*4882a593Smuzhiyun 		/* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
781*4882a593Smuzhiyun 		break;
782*4882a593Smuzhiyun 	case ETH_SS_PRIV_FLAGS:
783*4882a593Smuzhiyun 		memcpy(data, igc_priv_flags_strings,
784*4882a593Smuzhiyun 		       IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
785*4882a593Smuzhiyun 		break;
786*4882a593Smuzhiyun 	}
787*4882a593Smuzhiyun }
788*4882a593Smuzhiyun 
igc_ethtool_get_sset_count(struct net_device * netdev,int sset)789*4882a593Smuzhiyun static int igc_ethtool_get_sset_count(struct net_device *netdev, int sset)
790*4882a593Smuzhiyun {
791*4882a593Smuzhiyun 	switch (sset) {
792*4882a593Smuzhiyun 	case ETH_SS_STATS:
793*4882a593Smuzhiyun 		return IGC_STATS_LEN;
794*4882a593Smuzhiyun 	case ETH_SS_TEST:
795*4882a593Smuzhiyun 		return IGC_TEST_LEN;
796*4882a593Smuzhiyun 	case ETH_SS_PRIV_FLAGS:
797*4882a593Smuzhiyun 		return IGC_PRIV_FLAGS_STR_LEN;
798*4882a593Smuzhiyun 	default:
799*4882a593Smuzhiyun 		return -ENOTSUPP;
800*4882a593Smuzhiyun 	}
801*4882a593Smuzhiyun }
802*4882a593Smuzhiyun 
igc_ethtool_get_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)803*4882a593Smuzhiyun static void igc_ethtool_get_stats(struct net_device *netdev,
804*4882a593Smuzhiyun 				  struct ethtool_stats *stats, u64 *data)
805*4882a593Smuzhiyun {
806*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
807*4882a593Smuzhiyun 	struct rtnl_link_stats64 *net_stats = &adapter->stats64;
808*4882a593Smuzhiyun 	unsigned int start;
809*4882a593Smuzhiyun 	struct igc_ring *ring;
810*4882a593Smuzhiyun 	int i, j;
811*4882a593Smuzhiyun 	char *p;
812*4882a593Smuzhiyun 
813*4882a593Smuzhiyun 	spin_lock(&adapter->stats64_lock);
814*4882a593Smuzhiyun 	igc_update_stats(adapter);
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun 	for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) {
817*4882a593Smuzhiyun 		p = (char *)adapter + igc_gstrings_stats[i].stat_offset;
818*4882a593Smuzhiyun 		data[i] = (igc_gstrings_stats[i].sizeof_stat ==
819*4882a593Smuzhiyun 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
820*4882a593Smuzhiyun 	}
821*4882a593Smuzhiyun 	for (j = 0; j < IGC_NETDEV_STATS_LEN; j++, i++) {
822*4882a593Smuzhiyun 		p = (char *)net_stats + igc_gstrings_net_stats[j].stat_offset;
823*4882a593Smuzhiyun 		data[i] = (igc_gstrings_net_stats[j].sizeof_stat ==
824*4882a593Smuzhiyun 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
825*4882a593Smuzhiyun 	}
826*4882a593Smuzhiyun 	for (j = 0; j < adapter->num_tx_queues; j++) {
827*4882a593Smuzhiyun 		u64	restart2;
828*4882a593Smuzhiyun 
829*4882a593Smuzhiyun 		ring = adapter->tx_ring[j];
830*4882a593Smuzhiyun 		do {
831*4882a593Smuzhiyun 			start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
832*4882a593Smuzhiyun 			data[i]   = ring->tx_stats.packets;
833*4882a593Smuzhiyun 			data[i + 1] = ring->tx_stats.bytes;
834*4882a593Smuzhiyun 			data[i + 2] = ring->tx_stats.restart_queue;
835*4882a593Smuzhiyun 		} while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
836*4882a593Smuzhiyun 		do {
837*4882a593Smuzhiyun 			start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
838*4882a593Smuzhiyun 			restart2  = ring->tx_stats.restart_queue2;
839*4882a593Smuzhiyun 		} while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
840*4882a593Smuzhiyun 		data[i + 2] += restart2;
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun 		i += IGC_TX_QUEUE_STATS_LEN;
843*4882a593Smuzhiyun 	}
844*4882a593Smuzhiyun 	for (j = 0; j < adapter->num_rx_queues; j++) {
845*4882a593Smuzhiyun 		ring = adapter->rx_ring[j];
846*4882a593Smuzhiyun 		do {
847*4882a593Smuzhiyun 			start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
848*4882a593Smuzhiyun 			data[i]   = ring->rx_stats.packets;
849*4882a593Smuzhiyun 			data[i + 1] = ring->rx_stats.bytes;
850*4882a593Smuzhiyun 			data[i + 2] = ring->rx_stats.drops;
851*4882a593Smuzhiyun 			data[i + 3] = ring->rx_stats.csum_err;
852*4882a593Smuzhiyun 			data[i + 4] = ring->rx_stats.alloc_failed;
853*4882a593Smuzhiyun 		} while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
854*4882a593Smuzhiyun 		i += IGC_RX_QUEUE_STATS_LEN;
855*4882a593Smuzhiyun 	}
856*4882a593Smuzhiyun 	spin_unlock(&adapter->stats64_lock);
857*4882a593Smuzhiyun }
858*4882a593Smuzhiyun 
igc_ethtool_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec)859*4882a593Smuzhiyun static int igc_ethtool_get_coalesce(struct net_device *netdev,
860*4882a593Smuzhiyun 				    struct ethtool_coalesce *ec)
861*4882a593Smuzhiyun {
862*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun 	if (adapter->rx_itr_setting <= 3)
865*4882a593Smuzhiyun 		ec->rx_coalesce_usecs = adapter->rx_itr_setting;
866*4882a593Smuzhiyun 	else
867*4882a593Smuzhiyun 		ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun 	if (!(adapter->flags & IGC_FLAG_QUEUE_PAIRS)) {
870*4882a593Smuzhiyun 		if (adapter->tx_itr_setting <= 3)
871*4882a593Smuzhiyun 			ec->tx_coalesce_usecs = adapter->tx_itr_setting;
872*4882a593Smuzhiyun 		else
873*4882a593Smuzhiyun 			ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
874*4882a593Smuzhiyun 	}
875*4882a593Smuzhiyun 
876*4882a593Smuzhiyun 	return 0;
877*4882a593Smuzhiyun }
878*4882a593Smuzhiyun 
igc_ethtool_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec)879*4882a593Smuzhiyun static int igc_ethtool_set_coalesce(struct net_device *netdev,
880*4882a593Smuzhiyun 				    struct ethtool_coalesce *ec)
881*4882a593Smuzhiyun {
882*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
883*4882a593Smuzhiyun 	int i;
884*4882a593Smuzhiyun 
885*4882a593Smuzhiyun 	if (ec->rx_coalesce_usecs > IGC_MAX_ITR_USECS ||
886*4882a593Smuzhiyun 	    (ec->rx_coalesce_usecs > 3 &&
887*4882a593Smuzhiyun 	     ec->rx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
888*4882a593Smuzhiyun 	    ec->rx_coalesce_usecs == 2)
889*4882a593Smuzhiyun 		return -EINVAL;
890*4882a593Smuzhiyun 
891*4882a593Smuzhiyun 	if (ec->tx_coalesce_usecs > IGC_MAX_ITR_USECS ||
892*4882a593Smuzhiyun 	    (ec->tx_coalesce_usecs > 3 &&
893*4882a593Smuzhiyun 	     ec->tx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
894*4882a593Smuzhiyun 	    ec->tx_coalesce_usecs == 2)
895*4882a593Smuzhiyun 		return -EINVAL;
896*4882a593Smuzhiyun 
897*4882a593Smuzhiyun 	if ((adapter->flags & IGC_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
898*4882a593Smuzhiyun 		return -EINVAL;
899*4882a593Smuzhiyun 
900*4882a593Smuzhiyun 	/* If ITR is disabled, disable DMAC */
901*4882a593Smuzhiyun 	if (ec->rx_coalesce_usecs == 0) {
902*4882a593Smuzhiyun 		if (adapter->flags & IGC_FLAG_DMAC)
903*4882a593Smuzhiyun 			adapter->flags &= ~IGC_FLAG_DMAC;
904*4882a593Smuzhiyun 	}
905*4882a593Smuzhiyun 
906*4882a593Smuzhiyun 	/* convert to rate of irq's per second */
907*4882a593Smuzhiyun 	if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
908*4882a593Smuzhiyun 		adapter->rx_itr_setting = ec->rx_coalesce_usecs;
909*4882a593Smuzhiyun 	else
910*4882a593Smuzhiyun 		adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
911*4882a593Smuzhiyun 
912*4882a593Smuzhiyun 	/* convert to rate of irq's per second */
913*4882a593Smuzhiyun 	if (adapter->flags & IGC_FLAG_QUEUE_PAIRS)
914*4882a593Smuzhiyun 		adapter->tx_itr_setting = adapter->rx_itr_setting;
915*4882a593Smuzhiyun 	else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
916*4882a593Smuzhiyun 		adapter->tx_itr_setting = ec->tx_coalesce_usecs;
917*4882a593Smuzhiyun 	else
918*4882a593Smuzhiyun 		adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun 	for (i = 0; i < adapter->num_q_vectors; i++) {
921*4882a593Smuzhiyun 		struct igc_q_vector *q_vector = adapter->q_vector[i];
922*4882a593Smuzhiyun 
923*4882a593Smuzhiyun 		q_vector->tx.work_limit = adapter->tx_work_limit;
924*4882a593Smuzhiyun 		if (q_vector->rx.ring)
925*4882a593Smuzhiyun 			q_vector->itr_val = adapter->rx_itr_setting;
926*4882a593Smuzhiyun 		else
927*4882a593Smuzhiyun 			q_vector->itr_val = adapter->tx_itr_setting;
928*4882a593Smuzhiyun 		if (q_vector->itr_val && q_vector->itr_val <= 3)
929*4882a593Smuzhiyun 			q_vector->itr_val = IGC_START_ITR;
930*4882a593Smuzhiyun 		q_vector->set_itr = 1;
931*4882a593Smuzhiyun 	}
932*4882a593Smuzhiyun 
933*4882a593Smuzhiyun 	return 0;
934*4882a593Smuzhiyun }
935*4882a593Smuzhiyun 
936*4882a593Smuzhiyun #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
igc_ethtool_get_nfc_rule(struct igc_adapter * adapter,struct ethtool_rxnfc * cmd)937*4882a593Smuzhiyun static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,
938*4882a593Smuzhiyun 				    struct ethtool_rxnfc *cmd)
939*4882a593Smuzhiyun {
940*4882a593Smuzhiyun 	struct ethtool_rx_flow_spec *fsp = &cmd->fs;
941*4882a593Smuzhiyun 	struct igc_nfc_rule *rule = NULL;
942*4882a593Smuzhiyun 
943*4882a593Smuzhiyun 	cmd->data = IGC_MAX_RXNFC_RULES;
944*4882a593Smuzhiyun 
945*4882a593Smuzhiyun 	mutex_lock(&adapter->nfc_rule_lock);
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun 	rule = igc_get_nfc_rule(adapter, fsp->location);
948*4882a593Smuzhiyun 	if (!rule)
949*4882a593Smuzhiyun 		goto out;
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun 	fsp->flow_type = ETHER_FLOW;
952*4882a593Smuzhiyun 	fsp->ring_cookie = rule->action;
953*4882a593Smuzhiyun 
954*4882a593Smuzhiyun 	if (rule->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE) {
955*4882a593Smuzhiyun 		fsp->h_u.ether_spec.h_proto = htons(rule->filter.etype);
956*4882a593Smuzhiyun 		fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
957*4882a593Smuzhiyun 	}
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun 	if (rule->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI) {
960*4882a593Smuzhiyun 		fsp->flow_type |= FLOW_EXT;
961*4882a593Smuzhiyun 		fsp->h_ext.vlan_tci = htons(rule->filter.vlan_tci);
962*4882a593Smuzhiyun 		fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK);
963*4882a593Smuzhiyun 	}
964*4882a593Smuzhiyun 
965*4882a593Smuzhiyun 	if (rule->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR) {
966*4882a593Smuzhiyun 		ether_addr_copy(fsp->h_u.ether_spec.h_dest,
967*4882a593Smuzhiyun 				rule->filter.dst_addr);
968*4882a593Smuzhiyun 		eth_broadcast_addr(fsp->m_u.ether_spec.h_dest);
969*4882a593Smuzhiyun 	}
970*4882a593Smuzhiyun 
971*4882a593Smuzhiyun 	if (rule->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR) {
972*4882a593Smuzhiyun 		ether_addr_copy(fsp->h_u.ether_spec.h_source,
973*4882a593Smuzhiyun 				rule->filter.src_addr);
974*4882a593Smuzhiyun 		eth_broadcast_addr(fsp->m_u.ether_spec.h_source);
975*4882a593Smuzhiyun 	}
976*4882a593Smuzhiyun 
977*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
978*4882a593Smuzhiyun 	return 0;
979*4882a593Smuzhiyun 
980*4882a593Smuzhiyun out:
981*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
982*4882a593Smuzhiyun 	return -EINVAL;
983*4882a593Smuzhiyun }
984*4882a593Smuzhiyun 
igc_ethtool_get_nfc_rules(struct igc_adapter * adapter,struct ethtool_rxnfc * cmd,u32 * rule_locs)985*4882a593Smuzhiyun static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,
986*4882a593Smuzhiyun 				     struct ethtool_rxnfc *cmd,
987*4882a593Smuzhiyun 				     u32 *rule_locs)
988*4882a593Smuzhiyun {
989*4882a593Smuzhiyun 	struct igc_nfc_rule *rule;
990*4882a593Smuzhiyun 	int cnt = 0;
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun 	cmd->data = IGC_MAX_RXNFC_RULES;
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun 	mutex_lock(&adapter->nfc_rule_lock);
995*4882a593Smuzhiyun 
996*4882a593Smuzhiyun 	list_for_each_entry(rule, &adapter->nfc_rule_list, list) {
997*4882a593Smuzhiyun 		if (cnt == cmd->rule_cnt) {
998*4882a593Smuzhiyun 			mutex_unlock(&adapter->nfc_rule_lock);
999*4882a593Smuzhiyun 			return -EMSGSIZE;
1000*4882a593Smuzhiyun 		}
1001*4882a593Smuzhiyun 		rule_locs[cnt] = rule->location;
1002*4882a593Smuzhiyun 		cnt++;
1003*4882a593Smuzhiyun 	}
1004*4882a593Smuzhiyun 
1005*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
1006*4882a593Smuzhiyun 
1007*4882a593Smuzhiyun 	cmd->rule_cnt = cnt;
1008*4882a593Smuzhiyun 
1009*4882a593Smuzhiyun 	return 0;
1010*4882a593Smuzhiyun }
1011*4882a593Smuzhiyun 
igc_ethtool_get_rss_hash_opts(struct igc_adapter * adapter,struct ethtool_rxnfc * cmd)1012*4882a593Smuzhiyun static int igc_ethtool_get_rss_hash_opts(struct igc_adapter *adapter,
1013*4882a593Smuzhiyun 					 struct ethtool_rxnfc *cmd)
1014*4882a593Smuzhiyun {
1015*4882a593Smuzhiyun 	cmd->data = 0;
1016*4882a593Smuzhiyun 
1017*4882a593Smuzhiyun 	/* Report default options for RSS on igc */
1018*4882a593Smuzhiyun 	switch (cmd->flow_type) {
1019*4882a593Smuzhiyun 	case TCP_V4_FLOW:
1020*4882a593Smuzhiyun 		cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1021*4882a593Smuzhiyun 		fallthrough;
1022*4882a593Smuzhiyun 	case UDP_V4_FLOW:
1023*4882a593Smuzhiyun 		if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1024*4882a593Smuzhiyun 			cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1025*4882a593Smuzhiyun 		fallthrough;
1026*4882a593Smuzhiyun 	case SCTP_V4_FLOW:
1027*4882a593Smuzhiyun 	case AH_ESP_V4_FLOW:
1028*4882a593Smuzhiyun 	case AH_V4_FLOW:
1029*4882a593Smuzhiyun 	case ESP_V4_FLOW:
1030*4882a593Smuzhiyun 	case IPV4_FLOW:
1031*4882a593Smuzhiyun 		cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1032*4882a593Smuzhiyun 		break;
1033*4882a593Smuzhiyun 	case TCP_V6_FLOW:
1034*4882a593Smuzhiyun 		cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1035*4882a593Smuzhiyun 		fallthrough;
1036*4882a593Smuzhiyun 	case UDP_V6_FLOW:
1037*4882a593Smuzhiyun 		if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1038*4882a593Smuzhiyun 			cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1039*4882a593Smuzhiyun 		fallthrough;
1040*4882a593Smuzhiyun 	case SCTP_V6_FLOW:
1041*4882a593Smuzhiyun 	case AH_ESP_V6_FLOW:
1042*4882a593Smuzhiyun 	case AH_V6_FLOW:
1043*4882a593Smuzhiyun 	case ESP_V6_FLOW:
1044*4882a593Smuzhiyun 	case IPV6_FLOW:
1045*4882a593Smuzhiyun 		cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1046*4882a593Smuzhiyun 		break;
1047*4882a593Smuzhiyun 	default:
1048*4882a593Smuzhiyun 		return -EINVAL;
1049*4882a593Smuzhiyun 	}
1050*4882a593Smuzhiyun 
1051*4882a593Smuzhiyun 	return 0;
1052*4882a593Smuzhiyun }
1053*4882a593Smuzhiyun 
igc_ethtool_get_rxnfc(struct net_device * dev,struct ethtool_rxnfc * cmd,u32 * rule_locs)1054*4882a593Smuzhiyun static int igc_ethtool_get_rxnfc(struct net_device *dev,
1055*4882a593Smuzhiyun 				 struct ethtool_rxnfc *cmd, u32 *rule_locs)
1056*4882a593Smuzhiyun {
1057*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(dev);
1058*4882a593Smuzhiyun 
1059*4882a593Smuzhiyun 	switch (cmd->cmd) {
1060*4882a593Smuzhiyun 	case ETHTOOL_GRXRINGS:
1061*4882a593Smuzhiyun 		cmd->data = adapter->num_rx_queues;
1062*4882a593Smuzhiyun 		return 0;
1063*4882a593Smuzhiyun 	case ETHTOOL_GRXCLSRLCNT:
1064*4882a593Smuzhiyun 		cmd->rule_cnt = adapter->nfc_rule_count;
1065*4882a593Smuzhiyun 		return 0;
1066*4882a593Smuzhiyun 	case ETHTOOL_GRXCLSRULE:
1067*4882a593Smuzhiyun 		return igc_ethtool_get_nfc_rule(adapter, cmd);
1068*4882a593Smuzhiyun 	case ETHTOOL_GRXCLSRLALL:
1069*4882a593Smuzhiyun 		return igc_ethtool_get_nfc_rules(adapter, cmd, rule_locs);
1070*4882a593Smuzhiyun 	case ETHTOOL_GRXFH:
1071*4882a593Smuzhiyun 		return igc_ethtool_get_rss_hash_opts(adapter, cmd);
1072*4882a593Smuzhiyun 	default:
1073*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1074*4882a593Smuzhiyun 	}
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun 
1077*4882a593Smuzhiyun #define UDP_RSS_FLAGS (IGC_FLAG_RSS_FIELD_IPV4_UDP | \
1078*4882a593Smuzhiyun 		       IGC_FLAG_RSS_FIELD_IPV6_UDP)
igc_ethtool_set_rss_hash_opt(struct igc_adapter * adapter,struct ethtool_rxnfc * nfc)1079*4882a593Smuzhiyun static int igc_ethtool_set_rss_hash_opt(struct igc_adapter *adapter,
1080*4882a593Smuzhiyun 					struct ethtool_rxnfc *nfc)
1081*4882a593Smuzhiyun {
1082*4882a593Smuzhiyun 	u32 flags = adapter->flags;
1083*4882a593Smuzhiyun 
1084*4882a593Smuzhiyun 	/* RSS does not support anything other than hashing
1085*4882a593Smuzhiyun 	 * to queues on src and dst IPs and ports
1086*4882a593Smuzhiyun 	 */
1087*4882a593Smuzhiyun 	if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1088*4882a593Smuzhiyun 			  RXH_L4_B_0_1 | RXH_L4_B_2_3))
1089*4882a593Smuzhiyun 		return -EINVAL;
1090*4882a593Smuzhiyun 
1091*4882a593Smuzhiyun 	switch (nfc->flow_type) {
1092*4882a593Smuzhiyun 	case TCP_V4_FLOW:
1093*4882a593Smuzhiyun 	case TCP_V6_FLOW:
1094*4882a593Smuzhiyun 		if (!(nfc->data & RXH_IP_SRC) ||
1095*4882a593Smuzhiyun 		    !(nfc->data & RXH_IP_DST) ||
1096*4882a593Smuzhiyun 		    !(nfc->data & RXH_L4_B_0_1) ||
1097*4882a593Smuzhiyun 		    !(nfc->data & RXH_L4_B_2_3))
1098*4882a593Smuzhiyun 			return -EINVAL;
1099*4882a593Smuzhiyun 		break;
1100*4882a593Smuzhiyun 	case UDP_V4_FLOW:
1101*4882a593Smuzhiyun 		if (!(nfc->data & RXH_IP_SRC) ||
1102*4882a593Smuzhiyun 		    !(nfc->data & RXH_IP_DST))
1103*4882a593Smuzhiyun 			return -EINVAL;
1104*4882a593Smuzhiyun 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1105*4882a593Smuzhiyun 		case 0:
1106*4882a593Smuzhiyun 			flags &= ~IGC_FLAG_RSS_FIELD_IPV4_UDP;
1107*4882a593Smuzhiyun 			break;
1108*4882a593Smuzhiyun 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1109*4882a593Smuzhiyun 			flags |= IGC_FLAG_RSS_FIELD_IPV4_UDP;
1110*4882a593Smuzhiyun 			break;
1111*4882a593Smuzhiyun 		default:
1112*4882a593Smuzhiyun 			return -EINVAL;
1113*4882a593Smuzhiyun 		}
1114*4882a593Smuzhiyun 		break;
1115*4882a593Smuzhiyun 	case UDP_V6_FLOW:
1116*4882a593Smuzhiyun 		if (!(nfc->data & RXH_IP_SRC) ||
1117*4882a593Smuzhiyun 		    !(nfc->data & RXH_IP_DST))
1118*4882a593Smuzhiyun 			return -EINVAL;
1119*4882a593Smuzhiyun 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1120*4882a593Smuzhiyun 		case 0:
1121*4882a593Smuzhiyun 			flags &= ~IGC_FLAG_RSS_FIELD_IPV6_UDP;
1122*4882a593Smuzhiyun 			break;
1123*4882a593Smuzhiyun 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1124*4882a593Smuzhiyun 			flags |= IGC_FLAG_RSS_FIELD_IPV6_UDP;
1125*4882a593Smuzhiyun 			break;
1126*4882a593Smuzhiyun 		default:
1127*4882a593Smuzhiyun 			return -EINVAL;
1128*4882a593Smuzhiyun 		}
1129*4882a593Smuzhiyun 		break;
1130*4882a593Smuzhiyun 	case AH_ESP_V4_FLOW:
1131*4882a593Smuzhiyun 	case AH_V4_FLOW:
1132*4882a593Smuzhiyun 	case ESP_V4_FLOW:
1133*4882a593Smuzhiyun 	case SCTP_V4_FLOW:
1134*4882a593Smuzhiyun 	case AH_ESP_V6_FLOW:
1135*4882a593Smuzhiyun 	case AH_V6_FLOW:
1136*4882a593Smuzhiyun 	case ESP_V6_FLOW:
1137*4882a593Smuzhiyun 	case SCTP_V6_FLOW:
1138*4882a593Smuzhiyun 		if (!(nfc->data & RXH_IP_SRC) ||
1139*4882a593Smuzhiyun 		    !(nfc->data & RXH_IP_DST) ||
1140*4882a593Smuzhiyun 		    (nfc->data & RXH_L4_B_0_1) ||
1141*4882a593Smuzhiyun 		    (nfc->data & RXH_L4_B_2_3))
1142*4882a593Smuzhiyun 			return -EINVAL;
1143*4882a593Smuzhiyun 		break;
1144*4882a593Smuzhiyun 	default:
1145*4882a593Smuzhiyun 		return -EINVAL;
1146*4882a593Smuzhiyun 	}
1147*4882a593Smuzhiyun 
1148*4882a593Smuzhiyun 	/* if we changed something we need to update flags */
1149*4882a593Smuzhiyun 	if (flags != adapter->flags) {
1150*4882a593Smuzhiyun 		struct igc_hw *hw = &adapter->hw;
1151*4882a593Smuzhiyun 		u32 mrqc = rd32(IGC_MRQC);
1152*4882a593Smuzhiyun 
1153*4882a593Smuzhiyun 		if ((flags & UDP_RSS_FLAGS) &&
1154*4882a593Smuzhiyun 		    !(adapter->flags & UDP_RSS_FLAGS))
1155*4882a593Smuzhiyun 			netdev_err(adapter->netdev,
1156*4882a593Smuzhiyun 				   "Enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
1157*4882a593Smuzhiyun 
1158*4882a593Smuzhiyun 		adapter->flags = flags;
1159*4882a593Smuzhiyun 
1160*4882a593Smuzhiyun 		/* Perform hash on these packet types */
1161*4882a593Smuzhiyun 		mrqc |= IGC_MRQC_RSS_FIELD_IPV4 |
1162*4882a593Smuzhiyun 			IGC_MRQC_RSS_FIELD_IPV4_TCP |
1163*4882a593Smuzhiyun 			IGC_MRQC_RSS_FIELD_IPV6 |
1164*4882a593Smuzhiyun 			IGC_MRQC_RSS_FIELD_IPV6_TCP;
1165*4882a593Smuzhiyun 
1166*4882a593Smuzhiyun 		mrqc &= ~(IGC_MRQC_RSS_FIELD_IPV4_UDP |
1167*4882a593Smuzhiyun 			  IGC_MRQC_RSS_FIELD_IPV6_UDP);
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun 		if (flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1170*4882a593Smuzhiyun 			mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP;
1171*4882a593Smuzhiyun 
1172*4882a593Smuzhiyun 		if (flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1173*4882a593Smuzhiyun 			mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP;
1174*4882a593Smuzhiyun 
1175*4882a593Smuzhiyun 		wr32(IGC_MRQC, mrqc);
1176*4882a593Smuzhiyun 	}
1177*4882a593Smuzhiyun 
1178*4882a593Smuzhiyun 	return 0;
1179*4882a593Smuzhiyun }
1180*4882a593Smuzhiyun 
igc_ethtool_init_nfc_rule(struct igc_nfc_rule * rule,const struct ethtool_rx_flow_spec * fsp)1181*4882a593Smuzhiyun static void igc_ethtool_init_nfc_rule(struct igc_nfc_rule *rule,
1182*4882a593Smuzhiyun 				      const struct ethtool_rx_flow_spec *fsp)
1183*4882a593Smuzhiyun {
1184*4882a593Smuzhiyun 	INIT_LIST_HEAD(&rule->list);
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun 	rule->action = fsp->ring_cookie;
1187*4882a593Smuzhiyun 	rule->location = fsp->location;
1188*4882a593Smuzhiyun 
1189*4882a593Smuzhiyun 	if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) {
1190*4882a593Smuzhiyun 		rule->filter.vlan_tci = ntohs(fsp->h_ext.vlan_tci);
1191*4882a593Smuzhiyun 		rule->filter.match_flags |= IGC_FILTER_FLAG_VLAN_TCI;
1192*4882a593Smuzhiyun 	}
1193*4882a593Smuzhiyun 
1194*4882a593Smuzhiyun 	if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) {
1195*4882a593Smuzhiyun 		rule->filter.etype = ntohs(fsp->h_u.ether_spec.h_proto);
1196*4882a593Smuzhiyun 		rule->filter.match_flags = IGC_FILTER_FLAG_ETHER_TYPE;
1197*4882a593Smuzhiyun 	}
1198*4882a593Smuzhiyun 
1199*4882a593Smuzhiyun 	/* Both source and destination address filters only support the full
1200*4882a593Smuzhiyun 	 * mask.
1201*4882a593Smuzhiyun 	 */
1202*4882a593Smuzhiyun 	if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_source)) {
1203*4882a593Smuzhiyun 		rule->filter.match_flags |= IGC_FILTER_FLAG_SRC_MAC_ADDR;
1204*4882a593Smuzhiyun 		ether_addr_copy(rule->filter.src_addr,
1205*4882a593Smuzhiyun 				fsp->h_u.ether_spec.h_source);
1206*4882a593Smuzhiyun 	}
1207*4882a593Smuzhiyun 
1208*4882a593Smuzhiyun 	if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_dest)) {
1209*4882a593Smuzhiyun 		rule->filter.match_flags |= IGC_FILTER_FLAG_DST_MAC_ADDR;
1210*4882a593Smuzhiyun 		ether_addr_copy(rule->filter.dst_addr,
1211*4882a593Smuzhiyun 				fsp->h_u.ether_spec.h_dest);
1212*4882a593Smuzhiyun 	}
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun /**
1216*4882a593Smuzhiyun  * igc_ethtool_check_nfc_rule() - Check if NFC rule is valid
1217*4882a593Smuzhiyun  * @adapter: Pointer to adapter
1218*4882a593Smuzhiyun  * @rule: Rule under evaluation
1219*4882a593Smuzhiyun  *
1220*4882a593Smuzhiyun  * The driver doesn't support rules with multiple matches so if more than
1221*4882a593Smuzhiyun  * one bit in filter flags is set, @rule is considered invalid.
1222*4882a593Smuzhiyun  *
1223*4882a593Smuzhiyun  * Also, if there is already another rule with the same filter in a different
1224*4882a593Smuzhiyun  * location, @rule is considered invalid.
1225*4882a593Smuzhiyun  *
1226*4882a593Smuzhiyun  * Context: Expects adapter->nfc_rule_lock to be held by caller.
1227*4882a593Smuzhiyun  *
1228*4882a593Smuzhiyun  * Return: 0 in case of success, negative errno code otherwise.
1229*4882a593Smuzhiyun  */
igc_ethtool_check_nfc_rule(struct igc_adapter * adapter,struct igc_nfc_rule * rule)1230*4882a593Smuzhiyun static int igc_ethtool_check_nfc_rule(struct igc_adapter *adapter,
1231*4882a593Smuzhiyun 				      struct igc_nfc_rule *rule)
1232*4882a593Smuzhiyun {
1233*4882a593Smuzhiyun 	struct net_device *dev = adapter->netdev;
1234*4882a593Smuzhiyun 	u8 flags = rule->filter.match_flags;
1235*4882a593Smuzhiyun 	struct igc_nfc_rule *tmp;
1236*4882a593Smuzhiyun 
1237*4882a593Smuzhiyun 	if (!flags) {
1238*4882a593Smuzhiyun 		netdev_dbg(dev, "Rule with no match\n");
1239*4882a593Smuzhiyun 		return -EINVAL;
1240*4882a593Smuzhiyun 	}
1241*4882a593Smuzhiyun 
1242*4882a593Smuzhiyun 	if (flags & (flags - 1)) {
1243*4882a593Smuzhiyun 		netdev_dbg(dev, "Rule with multiple matches not supported\n");
1244*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1245*4882a593Smuzhiyun 	}
1246*4882a593Smuzhiyun 
1247*4882a593Smuzhiyun 	list_for_each_entry(tmp, &adapter->nfc_rule_list, list) {
1248*4882a593Smuzhiyun 		if (!memcmp(&rule->filter, &tmp->filter,
1249*4882a593Smuzhiyun 			    sizeof(rule->filter)) &&
1250*4882a593Smuzhiyun 		    tmp->location != rule->location) {
1251*4882a593Smuzhiyun 			netdev_dbg(dev, "Rule already exists\n");
1252*4882a593Smuzhiyun 			return -EEXIST;
1253*4882a593Smuzhiyun 		}
1254*4882a593Smuzhiyun 	}
1255*4882a593Smuzhiyun 
1256*4882a593Smuzhiyun 	return 0;
1257*4882a593Smuzhiyun }
1258*4882a593Smuzhiyun 
igc_ethtool_add_nfc_rule(struct igc_adapter * adapter,struct ethtool_rxnfc * cmd)1259*4882a593Smuzhiyun static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,
1260*4882a593Smuzhiyun 				    struct ethtool_rxnfc *cmd)
1261*4882a593Smuzhiyun {
1262*4882a593Smuzhiyun 	struct net_device *netdev = adapter->netdev;
1263*4882a593Smuzhiyun 	struct ethtool_rx_flow_spec *fsp =
1264*4882a593Smuzhiyun 		(struct ethtool_rx_flow_spec *)&cmd->fs;
1265*4882a593Smuzhiyun 	struct igc_nfc_rule *rule, *old_rule;
1266*4882a593Smuzhiyun 	int err;
1267*4882a593Smuzhiyun 
1268*4882a593Smuzhiyun 	if (!(netdev->hw_features & NETIF_F_NTUPLE)) {
1269*4882a593Smuzhiyun 		netdev_dbg(netdev, "N-tuple filters disabled\n");
1270*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1271*4882a593Smuzhiyun 	}
1272*4882a593Smuzhiyun 
1273*4882a593Smuzhiyun 	if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW) {
1274*4882a593Smuzhiyun 		netdev_dbg(netdev, "Only ethernet flow type is supported\n");
1275*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1276*4882a593Smuzhiyun 	}
1277*4882a593Smuzhiyun 
1278*4882a593Smuzhiyun 	if ((fsp->flow_type & FLOW_EXT) &&
1279*4882a593Smuzhiyun 	    fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK)) {
1280*4882a593Smuzhiyun 		netdev_dbg(netdev, "VLAN mask not supported\n");
1281*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1282*4882a593Smuzhiyun 	}
1283*4882a593Smuzhiyun 
1284*4882a593Smuzhiyun 	if (fsp->ring_cookie >= adapter->num_rx_queues) {
1285*4882a593Smuzhiyun 		netdev_dbg(netdev, "Invalid action\n");
1286*4882a593Smuzhiyun 		return -EINVAL;
1287*4882a593Smuzhiyun 	}
1288*4882a593Smuzhiyun 
1289*4882a593Smuzhiyun 	if (fsp->location >= IGC_MAX_RXNFC_RULES) {
1290*4882a593Smuzhiyun 		netdev_dbg(netdev, "Invalid location\n");
1291*4882a593Smuzhiyun 		return -EINVAL;
1292*4882a593Smuzhiyun 	}
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun 	rule = kzalloc(sizeof(*rule), GFP_KERNEL);
1295*4882a593Smuzhiyun 	if (!rule)
1296*4882a593Smuzhiyun 		return -ENOMEM;
1297*4882a593Smuzhiyun 
1298*4882a593Smuzhiyun 	igc_ethtool_init_nfc_rule(rule, fsp);
1299*4882a593Smuzhiyun 
1300*4882a593Smuzhiyun 	mutex_lock(&adapter->nfc_rule_lock);
1301*4882a593Smuzhiyun 
1302*4882a593Smuzhiyun 	err = igc_ethtool_check_nfc_rule(adapter, rule);
1303*4882a593Smuzhiyun 	if (err)
1304*4882a593Smuzhiyun 		goto err;
1305*4882a593Smuzhiyun 
1306*4882a593Smuzhiyun 	old_rule = igc_get_nfc_rule(adapter, fsp->location);
1307*4882a593Smuzhiyun 	if (old_rule)
1308*4882a593Smuzhiyun 		igc_del_nfc_rule(adapter, old_rule);
1309*4882a593Smuzhiyun 
1310*4882a593Smuzhiyun 	err = igc_add_nfc_rule(adapter, rule);
1311*4882a593Smuzhiyun 	if (err)
1312*4882a593Smuzhiyun 		goto err;
1313*4882a593Smuzhiyun 
1314*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
1315*4882a593Smuzhiyun 	return 0;
1316*4882a593Smuzhiyun 
1317*4882a593Smuzhiyun err:
1318*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
1319*4882a593Smuzhiyun 	kfree(rule);
1320*4882a593Smuzhiyun 	return err;
1321*4882a593Smuzhiyun }
1322*4882a593Smuzhiyun 
igc_ethtool_del_nfc_rule(struct igc_adapter * adapter,struct ethtool_rxnfc * cmd)1323*4882a593Smuzhiyun static int igc_ethtool_del_nfc_rule(struct igc_adapter *adapter,
1324*4882a593Smuzhiyun 				    struct ethtool_rxnfc *cmd)
1325*4882a593Smuzhiyun {
1326*4882a593Smuzhiyun 	struct ethtool_rx_flow_spec *fsp =
1327*4882a593Smuzhiyun 		(struct ethtool_rx_flow_spec *)&cmd->fs;
1328*4882a593Smuzhiyun 	struct igc_nfc_rule *rule;
1329*4882a593Smuzhiyun 
1330*4882a593Smuzhiyun 	mutex_lock(&adapter->nfc_rule_lock);
1331*4882a593Smuzhiyun 
1332*4882a593Smuzhiyun 	rule = igc_get_nfc_rule(adapter, fsp->location);
1333*4882a593Smuzhiyun 	if (!rule) {
1334*4882a593Smuzhiyun 		mutex_unlock(&adapter->nfc_rule_lock);
1335*4882a593Smuzhiyun 		return -EINVAL;
1336*4882a593Smuzhiyun 	}
1337*4882a593Smuzhiyun 
1338*4882a593Smuzhiyun 	igc_del_nfc_rule(adapter, rule);
1339*4882a593Smuzhiyun 
1340*4882a593Smuzhiyun 	mutex_unlock(&adapter->nfc_rule_lock);
1341*4882a593Smuzhiyun 	return 0;
1342*4882a593Smuzhiyun }
1343*4882a593Smuzhiyun 
igc_ethtool_set_rxnfc(struct net_device * dev,struct ethtool_rxnfc * cmd)1344*4882a593Smuzhiyun static int igc_ethtool_set_rxnfc(struct net_device *dev,
1345*4882a593Smuzhiyun 				 struct ethtool_rxnfc *cmd)
1346*4882a593Smuzhiyun {
1347*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(dev);
1348*4882a593Smuzhiyun 
1349*4882a593Smuzhiyun 	switch (cmd->cmd) {
1350*4882a593Smuzhiyun 	case ETHTOOL_SRXFH:
1351*4882a593Smuzhiyun 		return igc_ethtool_set_rss_hash_opt(adapter, cmd);
1352*4882a593Smuzhiyun 	case ETHTOOL_SRXCLSRLINS:
1353*4882a593Smuzhiyun 		return igc_ethtool_add_nfc_rule(adapter, cmd);
1354*4882a593Smuzhiyun 	case ETHTOOL_SRXCLSRLDEL:
1355*4882a593Smuzhiyun 		return igc_ethtool_del_nfc_rule(adapter, cmd);
1356*4882a593Smuzhiyun 	default:
1357*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1358*4882a593Smuzhiyun 	}
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun 
igc_write_rss_indir_tbl(struct igc_adapter * adapter)1361*4882a593Smuzhiyun void igc_write_rss_indir_tbl(struct igc_adapter *adapter)
1362*4882a593Smuzhiyun {
1363*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
1364*4882a593Smuzhiyun 	u32 reg = IGC_RETA(0);
1365*4882a593Smuzhiyun 	u32 shift = 0;
1366*4882a593Smuzhiyun 	int i = 0;
1367*4882a593Smuzhiyun 
1368*4882a593Smuzhiyun 	while (i < IGC_RETA_SIZE) {
1369*4882a593Smuzhiyun 		u32 val = 0;
1370*4882a593Smuzhiyun 		int j;
1371*4882a593Smuzhiyun 
1372*4882a593Smuzhiyun 		for (j = 3; j >= 0; j--) {
1373*4882a593Smuzhiyun 			val <<= 8;
1374*4882a593Smuzhiyun 			val |= adapter->rss_indir_tbl[i + j];
1375*4882a593Smuzhiyun 		}
1376*4882a593Smuzhiyun 
1377*4882a593Smuzhiyun 		wr32(reg, val << shift);
1378*4882a593Smuzhiyun 		reg += 4;
1379*4882a593Smuzhiyun 		i += 4;
1380*4882a593Smuzhiyun 	}
1381*4882a593Smuzhiyun }
1382*4882a593Smuzhiyun 
igc_ethtool_get_rxfh_indir_size(struct net_device * netdev)1383*4882a593Smuzhiyun static u32 igc_ethtool_get_rxfh_indir_size(struct net_device *netdev)
1384*4882a593Smuzhiyun {
1385*4882a593Smuzhiyun 	return IGC_RETA_SIZE;
1386*4882a593Smuzhiyun }
1387*4882a593Smuzhiyun 
igc_ethtool_get_rxfh(struct net_device * netdev,u32 * indir,u8 * key,u8 * hfunc)1388*4882a593Smuzhiyun static int igc_ethtool_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
1389*4882a593Smuzhiyun 				u8 *hfunc)
1390*4882a593Smuzhiyun {
1391*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1392*4882a593Smuzhiyun 	int i;
1393*4882a593Smuzhiyun 
1394*4882a593Smuzhiyun 	if (hfunc)
1395*4882a593Smuzhiyun 		*hfunc = ETH_RSS_HASH_TOP;
1396*4882a593Smuzhiyun 	if (!indir)
1397*4882a593Smuzhiyun 		return 0;
1398*4882a593Smuzhiyun 	for (i = 0; i < IGC_RETA_SIZE; i++)
1399*4882a593Smuzhiyun 		indir[i] = adapter->rss_indir_tbl[i];
1400*4882a593Smuzhiyun 
1401*4882a593Smuzhiyun 	return 0;
1402*4882a593Smuzhiyun }
1403*4882a593Smuzhiyun 
igc_ethtool_set_rxfh(struct net_device * netdev,const u32 * indir,const u8 * key,const u8 hfunc)1404*4882a593Smuzhiyun static int igc_ethtool_set_rxfh(struct net_device *netdev, const u32 *indir,
1405*4882a593Smuzhiyun 				const u8 *key, const u8 hfunc)
1406*4882a593Smuzhiyun {
1407*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1408*4882a593Smuzhiyun 	u32 num_queues;
1409*4882a593Smuzhiyun 	int i;
1410*4882a593Smuzhiyun 
1411*4882a593Smuzhiyun 	/* We do not allow change in unsupported parameters */
1412*4882a593Smuzhiyun 	if (key ||
1413*4882a593Smuzhiyun 	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1414*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1415*4882a593Smuzhiyun 	if (!indir)
1416*4882a593Smuzhiyun 		return 0;
1417*4882a593Smuzhiyun 
1418*4882a593Smuzhiyun 	num_queues = adapter->rss_queues;
1419*4882a593Smuzhiyun 
1420*4882a593Smuzhiyun 	/* Verify user input. */
1421*4882a593Smuzhiyun 	for (i = 0; i < IGC_RETA_SIZE; i++)
1422*4882a593Smuzhiyun 		if (indir[i] >= num_queues)
1423*4882a593Smuzhiyun 			return -EINVAL;
1424*4882a593Smuzhiyun 
1425*4882a593Smuzhiyun 	for (i = 0; i < IGC_RETA_SIZE; i++)
1426*4882a593Smuzhiyun 		adapter->rss_indir_tbl[i] = indir[i];
1427*4882a593Smuzhiyun 
1428*4882a593Smuzhiyun 	igc_write_rss_indir_tbl(adapter);
1429*4882a593Smuzhiyun 
1430*4882a593Smuzhiyun 	return 0;
1431*4882a593Smuzhiyun }
1432*4882a593Smuzhiyun 
igc_ethtool_get_channels(struct net_device * netdev,struct ethtool_channels * ch)1433*4882a593Smuzhiyun static void igc_ethtool_get_channels(struct net_device *netdev,
1434*4882a593Smuzhiyun 				     struct ethtool_channels *ch)
1435*4882a593Smuzhiyun {
1436*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1437*4882a593Smuzhiyun 
1438*4882a593Smuzhiyun 	/* Report maximum channels */
1439*4882a593Smuzhiyun 	ch->max_combined = igc_get_max_rss_queues(adapter);
1440*4882a593Smuzhiyun 
1441*4882a593Smuzhiyun 	/* Report info for other vector */
1442*4882a593Smuzhiyun 	if (adapter->flags & IGC_FLAG_HAS_MSIX) {
1443*4882a593Smuzhiyun 		ch->max_other = NON_Q_VECTORS;
1444*4882a593Smuzhiyun 		ch->other_count = NON_Q_VECTORS;
1445*4882a593Smuzhiyun 	}
1446*4882a593Smuzhiyun 
1447*4882a593Smuzhiyun 	ch->combined_count = adapter->rss_queues;
1448*4882a593Smuzhiyun }
1449*4882a593Smuzhiyun 
igc_ethtool_set_channels(struct net_device * netdev,struct ethtool_channels * ch)1450*4882a593Smuzhiyun static int igc_ethtool_set_channels(struct net_device *netdev,
1451*4882a593Smuzhiyun 				    struct ethtool_channels *ch)
1452*4882a593Smuzhiyun {
1453*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1454*4882a593Smuzhiyun 	unsigned int count = ch->combined_count;
1455*4882a593Smuzhiyun 	unsigned int max_combined = 0;
1456*4882a593Smuzhiyun 
1457*4882a593Smuzhiyun 	/* Verify they are not requesting separate vectors */
1458*4882a593Smuzhiyun 	if (!count || ch->rx_count || ch->tx_count)
1459*4882a593Smuzhiyun 		return -EINVAL;
1460*4882a593Smuzhiyun 
1461*4882a593Smuzhiyun 	/* Verify other_count is valid and has not been changed */
1462*4882a593Smuzhiyun 	if (ch->other_count != NON_Q_VECTORS)
1463*4882a593Smuzhiyun 		return -EINVAL;
1464*4882a593Smuzhiyun 
1465*4882a593Smuzhiyun 	/* Verify the number of channels doesn't exceed hw limits */
1466*4882a593Smuzhiyun 	max_combined = igc_get_max_rss_queues(adapter);
1467*4882a593Smuzhiyun 	if (count > max_combined)
1468*4882a593Smuzhiyun 		return -EINVAL;
1469*4882a593Smuzhiyun 
1470*4882a593Smuzhiyun 	if (count != adapter->rss_queues) {
1471*4882a593Smuzhiyun 		adapter->rss_queues = count;
1472*4882a593Smuzhiyun 		igc_set_flag_queue_pairs(adapter, max_combined);
1473*4882a593Smuzhiyun 
1474*4882a593Smuzhiyun 		/* Hardware has to reinitialize queues and interrupts to
1475*4882a593Smuzhiyun 		 * match the new configuration.
1476*4882a593Smuzhiyun 		 */
1477*4882a593Smuzhiyun 		return igc_reinit_queues(adapter);
1478*4882a593Smuzhiyun 	}
1479*4882a593Smuzhiyun 
1480*4882a593Smuzhiyun 	return 0;
1481*4882a593Smuzhiyun }
1482*4882a593Smuzhiyun 
igc_ethtool_get_ts_info(struct net_device * dev,struct ethtool_ts_info * info)1483*4882a593Smuzhiyun static int igc_ethtool_get_ts_info(struct net_device *dev,
1484*4882a593Smuzhiyun 				   struct ethtool_ts_info *info)
1485*4882a593Smuzhiyun {
1486*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(dev);
1487*4882a593Smuzhiyun 
1488*4882a593Smuzhiyun 	if (adapter->ptp_clock)
1489*4882a593Smuzhiyun 		info->phc_index = ptp_clock_index(adapter->ptp_clock);
1490*4882a593Smuzhiyun 	else
1491*4882a593Smuzhiyun 		info->phc_index = -1;
1492*4882a593Smuzhiyun 
1493*4882a593Smuzhiyun 	switch (adapter->hw.mac.type) {
1494*4882a593Smuzhiyun 	case igc_i225:
1495*4882a593Smuzhiyun 		info->so_timestamping =
1496*4882a593Smuzhiyun 			SOF_TIMESTAMPING_TX_SOFTWARE |
1497*4882a593Smuzhiyun 			SOF_TIMESTAMPING_RX_SOFTWARE |
1498*4882a593Smuzhiyun 			SOF_TIMESTAMPING_SOFTWARE |
1499*4882a593Smuzhiyun 			SOF_TIMESTAMPING_TX_HARDWARE |
1500*4882a593Smuzhiyun 			SOF_TIMESTAMPING_RX_HARDWARE |
1501*4882a593Smuzhiyun 			SOF_TIMESTAMPING_RAW_HARDWARE;
1502*4882a593Smuzhiyun 
1503*4882a593Smuzhiyun 		info->tx_types =
1504*4882a593Smuzhiyun 			BIT(HWTSTAMP_TX_OFF) |
1505*4882a593Smuzhiyun 			BIT(HWTSTAMP_TX_ON);
1506*4882a593Smuzhiyun 
1507*4882a593Smuzhiyun 		info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
1508*4882a593Smuzhiyun 		info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL);
1509*4882a593Smuzhiyun 
1510*4882a593Smuzhiyun 		return 0;
1511*4882a593Smuzhiyun 	default:
1512*4882a593Smuzhiyun 		return -EOPNOTSUPP;
1513*4882a593Smuzhiyun 	}
1514*4882a593Smuzhiyun }
1515*4882a593Smuzhiyun 
igc_ethtool_get_priv_flags(struct net_device * netdev)1516*4882a593Smuzhiyun static u32 igc_ethtool_get_priv_flags(struct net_device *netdev)
1517*4882a593Smuzhiyun {
1518*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1519*4882a593Smuzhiyun 	u32 priv_flags = 0;
1520*4882a593Smuzhiyun 
1521*4882a593Smuzhiyun 	if (adapter->flags & IGC_FLAG_RX_LEGACY)
1522*4882a593Smuzhiyun 		priv_flags |= IGC_PRIV_FLAGS_LEGACY_RX;
1523*4882a593Smuzhiyun 
1524*4882a593Smuzhiyun 	return priv_flags;
1525*4882a593Smuzhiyun }
1526*4882a593Smuzhiyun 
igc_ethtool_set_priv_flags(struct net_device * netdev,u32 priv_flags)1527*4882a593Smuzhiyun static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1528*4882a593Smuzhiyun {
1529*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1530*4882a593Smuzhiyun 	unsigned int flags = adapter->flags;
1531*4882a593Smuzhiyun 
1532*4882a593Smuzhiyun 	flags &= ~IGC_FLAG_RX_LEGACY;
1533*4882a593Smuzhiyun 	if (priv_flags & IGC_PRIV_FLAGS_LEGACY_RX)
1534*4882a593Smuzhiyun 		flags |= IGC_FLAG_RX_LEGACY;
1535*4882a593Smuzhiyun 
1536*4882a593Smuzhiyun 	if (flags != adapter->flags) {
1537*4882a593Smuzhiyun 		adapter->flags = flags;
1538*4882a593Smuzhiyun 
1539*4882a593Smuzhiyun 		/* reset interface to repopulate queues */
1540*4882a593Smuzhiyun 		if (netif_running(netdev))
1541*4882a593Smuzhiyun 			igc_reinit_locked(adapter);
1542*4882a593Smuzhiyun 	}
1543*4882a593Smuzhiyun 
1544*4882a593Smuzhiyun 	return 0;
1545*4882a593Smuzhiyun }
1546*4882a593Smuzhiyun 
igc_ethtool_get_eee(struct net_device * netdev,struct ethtool_eee * edata)1547*4882a593Smuzhiyun static int igc_ethtool_get_eee(struct net_device *netdev,
1548*4882a593Smuzhiyun 			       struct ethtool_eee *edata)
1549*4882a593Smuzhiyun {
1550*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1551*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
1552*4882a593Smuzhiyun 	u32 eeer;
1553*4882a593Smuzhiyun 
1554*4882a593Smuzhiyun 	if (hw->dev_spec._base.eee_enable)
1555*4882a593Smuzhiyun 		edata->advertised =
1556*4882a593Smuzhiyun 			mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
1557*4882a593Smuzhiyun 
1558*4882a593Smuzhiyun 	*edata = adapter->eee;
1559*4882a593Smuzhiyun 	edata->supported = SUPPORTED_Autoneg;
1560*4882a593Smuzhiyun 
1561*4882a593Smuzhiyun 	eeer = rd32(IGC_EEER);
1562*4882a593Smuzhiyun 
1563*4882a593Smuzhiyun 	/* EEE status on negotiated link */
1564*4882a593Smuzhiyun 	if (eeer & IGC_EEER_EEE_NEG)
1565*4882a593Smuzhiyun 		edata->eee_active = true;
1566*4882a593Smuzhiyun 
1567*4882a593Smuzhiyun 	if (eeer & IGC_EEER_TX_LPI_EN)
1568*4882a593Smuzhiyun 		edata->tx_lpi_enabled = true;
1569*4882a593Smuzhiyun 
1570*4882a593Smuzhiyun 	edata->eee_enabled = hw->dev_spec._base.eee_enable;
1571*4882a593Smuzhiyun 
1572*4882a593Smuzhiyun 	edata->advertised = SUPPORTED_Autoneg;
1573*4882a593Smuzhiyun 	edata->lp_advertised = SUPPORTED_Autoneg;
1574*4882a593Smuzhiyun 
1575*4882a593Smuzhiyun 	/* Report correct negotiated EEE status for devices that
1576*4882a593Smuzhiyun 	 * wrongly report EEE at half-duplex
1577*4882a593Smuzhiyun 	 */
1578*4882a593Smuzhiyun 	if (adapter->link_duplex == HALF_DUPLEX) {
1579*4882a593Smuzhiyun 		edata->eee_enabled = false;
1580*4882a593Smuzhiyun 		edata->eee_active = false;
1581*4882a593Smuzhiyun 		edata->tx_lpi_enabled = false;
1582*4882a593Smuzhiyun 		edata->advertised &= ~edata->advertised;
1583*4882a593Smuzhiyun 	}
1584*4882a593Smuzhiyun 
1585*4882a593Smuzhiyun 	return 0;
1586*4882a593Smuzhiyun }
1587*4882a593Smuzhiyun 
igc_ethtool_set_eee(struct net_device * netdev,struct ethtool_eee * edata)1588*4882a593Smuzhiyun static int igc_ethtool_set_eee(struct net_device *netdev,
1589*4882a593Smuzhiyun 			       struct ethtool_eee *edata)
1590*4882a593Smuzhiyun {
1591*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1592*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
1593*4882a593Smuzhiyun 	struct ethtool_eee eee_curr;
1594*4882a593Smuzhiyun 	s32 ret_val;
1595*4882a593Smuzhiyun 
1596*4882a593Smuzhiyun 	memset(&eee_curr, 0, sizeof(struct ethtool_eee));
1597*4882a593Smuzhiyun 
1598*4882a593Smuzhiyun 	ret_val = igc_ethtool_get_eee(netdev, &eee_curr);
1599*4882a593Smuzhiyun 	if (ret_val) {
1600*4882a593Smuzhiyun 		netdev_err(netdev,
1601*4882a593Smuzhiyun 			   "Problem setting EEE advertisement options\n");
1602*4882a593Smuzhiyun 		return -EINVAL;
1603*4882a593Smuzhiyun 	}
1604*4882a593Smuzhiyun 
1605*4882a593Smuzhiyun 	if (eee_curr.eee_enabled) {
1606*4882a593Smuzhiyun 		if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
1607*4882a593Smuzhiyun 			netdev_err(netdev,
1608*4882a593Smuzhiyun 				   "Setting EEE tx-lpi is not supported\n");
1609*4882a593Smuzhiyun 			return -EINVAL;
1610*4882a593Smuzhiyun 		}
1611*4882a593Smuzhiyun 
1612*4882a593Smuzhiyun 		/* Tx LPI timer is not implemented currently */
1613*4882a593Smuzhiyun 		if (edata->tx_lpi_timer) {
1614*4882a593Smuzhiyun 			netdev_err(netdev,
1615*4882a593Smuzhiyun 				   "Setting EEE Tx LPI timer is not supported\n");
1616*4882a593Smuzhiyun 			return -EINVAL;
1617*4882a593Smuzhiyun 		}
1618*4882a593Smuzhiyun 	} else if (!edata->eee_enabled) {
1619*4882a593Smuzhiyun 		netdev_err(netdev,
1620*4882a593Smuzhiyun 			   "Setting EEE options are not supported with EEE disabled\n");
1621*4882a593Smuzhiyun 		return -EINVAL;
1622*4882a593Smuzhiyun 	}
1623*4882a593Smuzhiyun 
1624*4882a593Smuzhiyun 	adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
1625*4882a593Smuzhiyun 	if (hw->dev_spec._base.eee_enable != edata->eee_enabled) {
1626*4882a593Smuzhiyun 		hw->dev_spec._base.eee_enable = edata->eee_enabled;
1627*4882a593Smuzhiyun 		adapter->flags |= IGC_FLAG_EEE;
1628*4882a593Smuzhiyun 
1629*4882a593Smuzhiyun 		/* reset link */
1630*4882a593Smuzhiyun 		if (netif_running(netdev))
1631*4882a593Smuzhiyun 			igc_reinit_locked(adapter);
1632*4882a593Smuzhiyun 		else
1633*4882a593Smuzhiyun 			igc_reset(adapter);
1634*4882a593Smuzhiyun 	}
1635*4882a593Smuzhiyun 
1636*4882a593Smuzhiyun 	return 0;
1637*4882a593Smuzhiyun }
1638*4882a593Smuzhiyun 
igc_ethtool_begin(struct net_device * netdev)1639*4882a593Smuzhiyun static int igc_ethtool_begin(struct net_device *netdev)
1640*4882a593Smuzhiyun {
1641*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1642*4882a593Smuzhiyun 
1643*4882a593Smuzhiyun 	pm_runtime_get_sync(&adapter->pdev->dev);
1644*4882a593Smuzhiyun 	return 0;
1645*4882a593Smuzhiyun }
1646*4882a593Smuzhiyun 
igc_ethtool_complete(struct net_device * netdev)1647*4882a593Smuzhiyun static void igc_ethtool_complete(struct net_device *netdev)
1648*4882a593Smuzhiyun {
1649*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1650*4882a593Smuzhiyun 
1651*4882a593Smuzhiyun 	pm_runtime_put(&adapter->pdev->dev);
1652*4882a593Smuzhiyun }
1653*4882a593Smuzhiyun 
igc_ethtool_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)1654*4882a593Smuzhiyun static int igc_ethtool_get_link_ksettings(struct net_device *netdev,
1655*4882a593Smuzhiyun 					  struct ethtool_link_ksettings *cmd)
1656*4882a593Smuzhiyun {
1657*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1658*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
1659*4882a593Smuzhiyun 	u32 status;
1660*4882a593Smuzhiyun 	u32 speed;
1661*4882a593Smuzhiyun 
1662*4882a593Smuzhiyun 	ethtool_link_ksettings_zero_link_mode(cmd, supported);
1663*4882a593Smuzhiyun 	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
1664*4882a593Smuzhiyun 
1665*4882a593Smuzhiyun 	/* supported link modes */
1666*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
1667*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Full);
1668*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Half);
1669*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Full);
1670*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
1671*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, 2500baseT_Full);
1672*4882a593Smuzhiyun 
1673*4882a593Smuzhiyun 	/* twisted pair */
1674*4882a593Smuzhiyun 	cmd->base.port = PORT_TP;
1675*4882a593Smuzhiyun 	cmd->base.phy_address = hw->phy.addr;
1676*4882a593Smuzhiyun 
1677*4882a593Smuzhiyun 	/* advertising link modes */
1678*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_10_HALF)
1679*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Half);
1680*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_10_FULL)
1681*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Full);
1682*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_100_HALF)
1683*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Half);
1684*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)
1685*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Full);
1686*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_1000_FULL)
1687*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
1688*4882a593Smuzhiyun 	if (hw->phy.autoneg_advertised & ADVERTISE_2500_FULL)
1689*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, 2500baseT_Full);
1690*4882a593Smuzhiyun 
1691*4882a593Smuzhiyun 	/* set autoneg settings */
1692*4882a593Smuzhiyun 	if (hw->mac.autoneg == 1) {
1693*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
1694*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising,
1695*4882a593Smuzhiyun 						     Autoneg);
1696*4882a593Smuzhiyun 	}
1697*4882a593Smuzhiyun 
1698*4882a593Smuzhiyun 	/* Set pause flow control settings */
1699*4882a593Smuzhiyun 	ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
1700*4882a593Smuzhiyun 
1701*4882a593Smuzhiyun 	switch (hw->fc.requested_mode) {
1702*4882a593Smuzhiyun 	case igc_fc_full:
1703*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1704*4882a593Smuzhiyun 		break;
1705*4882a593Smuzhiyun 	case igc_fc_rx_pause:
1706*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1707*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising,
1708*4882a593Smuzhiyun 						     Asym_Pause);
1709*4882a593Smuzhiyun 		break;
1710*4882a593Smuzhiyun 	case igc_fc_tx_pause:
1711*4882a593Smuzhiyun 		ethtool_link_ksettings_add_link_mode(cmd, advertising,
1712*4882a593Smuzhiyun 						     Asym_Pause);
1713*4882a593Smuzhiyun 		break;
1714*4882a593Smuzhiyun 	default:
1715*4882a593Smuzhiyun 		break;
1716*4882a593Smuzhiyun 	}
1717*4882a593Smuzhiyun 
1718*4882a593Smuzhiyun 	status = pm_runtime_suspended(&adapter->pdev->dev) ?
1719*4882a593Smuzhiyun 		 0 : rd32(IGC_STATUS);
1720*4882a593Smuzhiyun 
1721*4882a593Smuzhiyun 	if (status & IGC_STATUS_LU) {
1722*4882a593Smuzhiyun 		if (status & IGC_STATUS_SPEED_1000) {
1723*4882a593Smuzhiyun 			/* For I225, STATUS will indicate 1G speed in both
1724*4882a593Smuzhiyun 			 * 1 Gbps and 2.5 Gbps link modes.
1725*4882a593Smuzhiyun 			 * An additional bit is used
1726*4882a593Smuzhiyun 			 * to differentiate between 1 Gbps and 2.5 Gbps.
1727*4882a593Smuzhiyun 			 */
1728*4882a593Smuzhiyun 			if (hw->mac.type == igc_i225 &&
1729*4882a593Smuzhiyun 			    (status & IGC_STATUS_SPEED_2500)) {
1730*4882a593Smuzhiyun 				speed = SPEED_2500;
1731*4882a593Smuzhiyun 			} else {
1732*4882a593Smuzhiyun 				speed = SPEED_1000;
1733*4882a593Smuzhiyun 			}
1734*4882a593Smuzhiyun 		} else if (status & IGC_STATUS_SPEED_100) {
1735*4882a593Smuzhiyun 			speed = SPEED_100;
1736*4882a593Smuzhiyun 		} else {
1737*4882a593Smuzhiyun 			speed = SPEED_10;
1738*4882a593Smuzhiyun 		}
1739*4882a593Smuzhiyun 		if ((status & IGC_STATUS_FD) ||
1740*4882a593Smuzhiyun 		    hw->phy.media_type != igc_media_type_copper)
1741*4882a593Smuzhiyun 			cmd->base.duplex = DUPLEX_FULL;
1742*4882a593Smuzhiyun 		else
1743*4882a593Smuzhiyun 			cmd->base.duplex = DUPLEX_HALF;
1744*4882a593Smuzhiyun 	} else {
1745*4882a593Smuzhiyun 		speed = SPEED_UNKNOWN;
1746*4882a593Smuzhiyun 		cmd->base.duplex = DUPLEX_UNKNOWN;
1747*4882a593Smuzhiyun 	}
1748*4882a593Smuzhiyun 	cmd->base.speed = speed;
1749*4882a593Smuzhiyun 	if (hw->mac.autoneg)
1750*4882a593Smuzhiyun 		cmd->base.autoneg = AUTONEG_ENABLE;
1751*4882a593Smuzhiyun 	else
1752*4882a593Smuzhiyun 		cmd->base.autoneg = AUTONEG_DISABLE;
1753*4882a593Smuzhiyun 
1754*4882a593Smuzhiyun 	/* MDI-X => 2; MDI =>1; Invalid =>0 */
1755*4882a593Smuzhiyun 	if (hw->phy.media_type == igc_media_type_copper)
1756*4882a593Smuzhiyun 		cmd->base.eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
1757*4882a593Smuzhiyun 						      ETH_TP_MDI;
1758*4882a593Smuzhiyun 	else
1759*4882a593Smuzhiyun 		cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
1760*4882a593Smuzhiyun 
1761*4882a593Smuzhiyun 	if (hw->phy.mdix == AUTO_ALL_MODES)
1762*4882a593Smuzhiyun 		cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
1763*4882a593Smuzhiyun 	else
1764*4882a593Smuzhiyun 		cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
1765*4882a593Smuzhiyun 
1766*4882a593Smuzhiyun 	return 0;
1767*4882a593Smuzhiyun }
1768*4882a593Smuzhiyun 
1769*4882a593Smuzhiyun static int
igc_ethtool_set_link_ksettings(struct net_device * netdev,const struct ethtool_link_ksettings * cmd)1770*4882a593Smuzhiyun igc_ethtool_set_link_ksettings(struct net_device *netdev,
1771*4882a593Smuzhiyun 			       const struct ethtool_link_ksettings *cmd)
1772*4882a593Smuzhiyun {
1773*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1774*4882a593Smuzhiyun 	struct net_device *dev = adapter->netdev;
1775*4882a593Smuzhiyun 	struct igc_hw *hw = &adapter->hw;
1776*4882a593Smuzhiyun 	u32 advertising;
1777*4882a593Smuzhiyun 
1778*4882a593Smuzhiyun 	/* When adapter in resetting mode, autoneg/speed/duplex
1779*4882a593Smuzhiyun 	 * cannot be changed
1780*4882a593Smuzhiyun 	 */
1781*4882a593Smuzhiyun 	if (igc_check_reset_block(hw)) {
1782*4882a593Smuzhiyun 		netdev_err(dev, "Cannot change link characteristics when reset is active\n");
1783*4882a593Smuzhiyun 		return -EINVAL;
1784*4882a593Smuzhiyun 	}
1785*4882a593Smuzhiyun 
1786*4882a593Smuzhiyun 	/* MDI setting is only allowed when autoneg enabled because
1787*4882a593Smuzhiyun 	 * some hardware doesn't allow MDI setting when speed or
1788*4882a593Smuzhiyun 	 * duplex is forced.
1789*4882a593Smuzhiyun 	 */
1790*4882a593Smuzhiyun 	if (cmd->base.eth_tp_mdix_ctrl) {
1791*4882a593Smuzhiyun 		if (cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO &&
1792*4882a593Smuzhiyun 		    cmd->base.autoneg != AUTONEG_ENABLE) {
1793*4882a593Smuzhiyun 			netdev_err(dev, "Forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
1794*4882a593Smuzhiyun 			return -EINVAL;
1795*4882a593Smuzhiyun 		}
1796*4882a593Smuzhiyun 	}
1797*4882a593Smuzhiyun 
1798*4882a593Smuzhiyun 	while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
1799*4882a593Smuzhiyun 		usleep_range(1000, 2000);
1800*4882a593Smuzhiyun 
1801*4882a593Smuzhiyun 	ethtool_convert_link_mode_to_legacy_u32(&advertising,
1802*4882a593Smuzhiyun 						cmd->link_modes.advertising);
1803*4882a593Smuzhiyun 	/* Converting to legacy u32 drops ETHTOOL_LINK_MODE_2500baseT_Full_BIT.
1804*4882a593Smuzhiyun 	 * We have to check this and convert it to ADVERTISE_2500_FULL
1805*4882a593Smuzhiyun 	 * (aka ETHTOOL_LINK_MODE_2500baseX_Full_BIT) explicitly.
1806*4882a593Smuzhiyun 	 */
1807*4882a593Smuzhiyun 	if (ethtool_link_ksettings_test_link_mode(cmd, advertising, 2500baseT_Full))
1808*4882a593Smuzhiyun 		advertising |= ADVERTISE_2500_FULL;
1809*4882a593Smuzhiyun 
1810*4882a593Smuzhiyun 	if (cmd->base.autoneg == AUTONEG_ENABLE) {
1811*4882a593Smuzhiyun 		hw->mac.autoneg = 1;
1812*4882a593Smuzhiyun 		hw->phy.autoneg_advertised = advertising;
1813*4882a593Smuzhiyun 		if (adapter->fc_autoneg)
1814*4882a593Smuzhiyun 			hw->fc.requested_mode = igc_fc_default;
1815*4882a593Smuzhiyun 	} else {
1816*4882a593Smuzhiyun 		netdev_info(dev, "Force mode currently not supported\n");
1817*4882a593Smuzhiyun 	}
1818*4882a593Smuzhiyun 
1819*4882a593Smuzhiyun 	/* MDI-X => 2; MDI => 1; Auto => 3 */
1820*4882a593Smuzhiyun 	if (cmd->base.eth_tp_mdix_ctrl) {
1821*4882a593Smuzhiyun 		/* fix up the value for auto (3 => 0) as zero is mapped
1822*4882a593Smuzhiyun 		 * internally to auto
1823*4882a593Smuzhiyun 		 */
1824*4882a593Smuzhiyun 		if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
1825*4882a593Smuzhiyun 			hw->phy.mdix = AUTO_ALL_MODES;
1826*4882a593Smuzhiyun 		else
1827*4882a593Smuzhiyun 			hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
1828*4882a593Smuzhiyun 	}
1829*4882a593Smuzhiyun 
1830*4882a593Smuzhiyun 	/* reset the link */
1831*4882a593Smuzhiyun 	if (netif_running(adapter->netdev)) {
1832*4882a593Smuzhiyun 		igc_down(adapter);
1833*4882a593Smuzhiyun 		igc_up(adapter);
1834*4882a593Smuzhiyun 	} else {
1835*4882a593Smuzhiyun 		igc_reset(adapter);
1836*4882a593Smuzhiyun 	}
1837*4882a593Smuzhiyun 
1838*4882a593Smuzhiyun 	clear_bit(__IGC_RESETTING, &adapter->state);
1839*4882a593Smuzhiyun 
1840*4882a593Smuzhiyun 	return 0;
1841*4882a593Smuzhiyun }
1842*4882a593Smuzhiyun 
igc_ethtool_diag_test(struct net_device * netdev,struct ethtool_test * eth_test,u64 * data)1843*4882a593Smuzhiyun static void igc_ethtool_diag_test(struct net_device *netdev,
1844*4882a593Smuzhiyun 				  struct ethtool_test *eth_test, u64 *data)
1845*4882a593Smuzhiyun {
1846*4882a593Smuzhiyun 	struct igc_adapter *adapter = netdev_priv(netdev);
1847*4882a593Smuzhiyun 	bool if_running = netif_running(netdev);
1848*4882a593Smuzhiyun 
1849*4882a593Smuzhiyun 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1850*4882a593Smuzhiyun 		netdev_info(adapter->netdev, "Offline testing starting");
1851*4882a593Smuzhiyun 		set_bit(__IGC_TESTING, &adapter->state);
1852*4882a593Smuzhiyun 
1853*4882a593Smuzhiyun 		/* Link test performed before hardware reset so autoneg doesn't
1854*4882a593Smuzhiyun 		 * interfere with test result
1855*4882a593Smuzhiyun 		 */
1856*4882a593Smuzhiyun 		if (!igc_link_test(adapter, &data[TEST_LINK]))
1857*4882a593Smuzhiyun 			eth_test->flags |= ETH_TEST_FL_FAILED;
1858*4882a593Smuzhiyun 
1859*4882a593Smuzhiyun 		if (if_running)
1860*4882a593Smuzhiyun 			igc_close(netdev);
1861*4882a593Smuzhiyun 		else
1862*4882a593Smuzhiyun 			igc_reset(adapter);
1863*4882a593Smuzhiyun 
1864*4882a593Smuzhiyun 		netdev_info(adapter->netdev, "Register testing starting");
1865*4882a593Smuzhiyun 		if (!igc_reg_test(adapter, &data[TEST_REG]))
1866*4882a593Smuzhiyun 			eth_test->flags |= ETH_TEST_FL_FAILED;
1867*4882a593Smuzhiyun 
1868*4882a593Smuzhiyun 		igc_reset(adapter);
1869*4882a593Smuzhiyun 
1870*4882a593Smuzhiyun 		netdev_info(adapter->netdev, "EEPROM testing starting");
1871*4882a593Smuzhiyun 		if (!igc_eeprom_test(adapter, &data[TEST_EEP]))
1872*4882a593Smuzhiyun 			eth_test->flags |= ETH_TEST_FL_FAILED;
1873*4882a593Smuzhiyun 
1874*4882a593Smuzhiyun 		igc_reset(adapter);
1875*4882a593Smuzhiyun 
1876*4882a593Smuzhiyun 		/* loopback and interrupt tests
1877*4882a593Smuzhiyun 		 * will be implemented in the future
1878*4882a593Smuzhiyun 		 */
1879*4882a593Smuzhiyun 		data[TEST_LOOP] = 0;
1880*4882a593Smuzhiyun 		data[TEST_IRQ] = 0;
1881*4882a593Smuzhiyun 
1882*4882a593Smuzhiyun 		clear_bit(__IGC_TESTING, &adapter->state);
1883*4882a593Smuzhiyun 		if (if_running)
1884*4882a593Smuzhiyun 			igc_open(netdev);
1885*4882a593Smuzhiyun 	} else {
1886*4882a593Smuzhiyun 		netdev_info(adapter->netdev, "Online testing starting");
1887*4882a593Smuzhiyun 
1888*4882a593Smuzhiyun 		/* register, eeprom, intr and loopback tests not run online */
1889*4882a593Smuzhiyun 		data[TEST_REG] = 0;
1890*4882a593Smuzhiyun 		data[TEST_EEP] = 0;
1891*4882a593Smuzhiyun 		data[TEST_IRQ] = 0;
1892*4882a593Smuzhiyun 		data[TEST_LOOP] = 0;
1893*4882a593Smuzhiyun 
1894*4882a593Smuzhiyun 		if (!igc_link_test(adapter, &data[TEST_LINK]))
1895*4882a593Smuzhiyun 			eth_test->flags |= ETH_TEST_FL_FAILED;
1896*4882a593Smuzhiyun 	}
1897*4882a593Smuzhiyun 
1898*4882a593Smuzhiyun 	msleep_interruptible(4 * 1000);
1899*4882a593Smuzhiyun }
1900*4882a593Smuzhiyun 
1901*4882a593Smuzhiyun static const struct ethtool_ops igc_ethtool_ops = {
1902*4882a593Smuzhiyun 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS,
1903*4882a593Smuzhiyun 	.get_drvinfo		= igc_ethtool_get_drvinfo,
1904*4882a593Smuzhiyun 	.get_regs_len		= igc_ethtool_get_regs_len,
1905*4882a593Smuzhiyun 	.get_regs		= igc_ethtool_get_regs,
1906*4882a593Smuzhiyun 	.get_wol		= igc_ethtool_get_wol,
1907*4882a593Smuzhiyun 	.set_wol		= igc_ethtool_set_wol,
1908*4882a593Smuzhiyun 	.get_msglevel		= igc_ethtool_get_msglevel,
1909*4882a593Smuzhiyun 	.set_msglevel		= igc_ethtool_set_msglevel,
1910*4882a593Smuzhiyun 	.nway_reset		= igc_ethtool_nway_reset,
1911*4882a593Smuzhiyun 	.get_link		= igc_ethtool_get_link,
1912*4882a593Smuzhiyun 	.get_eeprom_len		= igc_ethtool_get_eeprom_len,
1913*4882a593Smuzhiyun 	.get_eeprom		= igc_ethtool_get_eeprom,
1914*4882a593Smuzhiyun 	.set_eeprom		= igc_ethtool_set_eeprom,
1915*4882a593Smuzhiyun 	.get_ringparam		= igc_ethtool_get_ringparam,
1916*4882a593Smuzhiyun 	.set_ringparam		= igc_ethtool_set_ringparam,
1917*4882a593Smuzhiyun 	.get_pauseparam		= igc_ethtool_get_pauseparam,
1918*4882a593Smuzhiyun 	.set_pauseparam		= igc_ethtool_set_pauseparam,
1919*4882a593Smuzhiyun 	.get_strings		= igc_ethtool_get_strings,
1920*4882a593Smuzhiyun 	.get_sset_count		= igc_ethtool_get_sset_count,
1921*4882a593Smuzhiyun 	.get_ethtool_stats	= igc_ethtool_get_stats,
1922*4882a593Smuzhiyun 	.get_coalesce		= igc_ethtool_get_coalesce,
1923*4882a593Smuzhiyun 	.set_coalesce		= igc_ethtool_set_coalesce,
1924*4882a593Smuzhiyun 	.get_rxnfc		= igc_ethtool_get_rxnfc,
1925*4882a593Smuzhiyun 	.set_rxnfc		= igc_ethtool_set_rxnfc,
1926*4882a593Smuzhiyun 	.get_rxfh_indir_size	= igc_ethtool_get_rxfh_indir_size,
1927*4882a593Smuzhiyun 	.get_rxfh		= igc_ethtool_get_rxfh,
1928*4882a593Smuzhiyun 	.set_rxfh		= igc_ethtool_set_rxfh,
1929*4882a593Smuzhiyun 	.get_ts_info		= igc_ethtool_get_ts_info,
1930*4882a593Smuzhiyun 	.get_channels		= igc_ethtool_get_channels,
1931*4882a593Smuzhiyun 	.set_channels		= igc_ethtool_set_channels,
1932*4882a593Smuzhiyun 	.get_priv_flags		= igc_ethtool_get_priv_flags,
1933*4882a593Smuzhiyun 	.set_priv_flags		= igc_ethtool_set_priv_flags,
1934*4882a593Smuzhiyun 	.get_eee		= igc_ethtool_get_eee,
1935*4882a593Smuzhiyun 	.set_eee		= igc_ethtool_set_eee,
1936*4882a593Smuzhiyun 	.begin			= igc_ethtool_begin,
1937*4882a593Smuzhiyun 	.complete		= igc_ethtool_complete,
1938*4882a593Smuzhiyun 	.get_link_ksettings	= igc_ethtool_get_link_ksettings,
1939*4882a593Smuzhiyun 	.set_link_ksettings	= igc_ethtool_set_link_ksettings,
1940*4882a593Smuzhiyun 	.self_test		= igc_ethtool_diag_test,
1941*4882a593Smuzhiyun };
1942*4882a593Smuzhiyun 
igc_ethtool_set_ops(struct net_device * netdev)1943*4882a593Smuzhiyun void igc_ethtool_set_ops(struct net_device *netdev)
1944*4882a593Smuzhiyun {
1945*4882a593Smuzhiyun 	netdev->ethtool_ops = &igc_ethtool_ops;
1946*4882a593Smuzhiyun }
1947