Commit | Line | Data |
---|---|---|
86641094 | 1 | /* Intel(R) Ethernet Switch Host Interface Driver |
9de6a1a6 | 2 | * Copyright(c) 2013 - 2016 Intel Corporation. |
82dd0f7e AD |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * The full GNU General Public License is included in this distribution in | |
14 | * the file called "COPYING". | |
15 | * | |
16 | * Contact Information: | |
17 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
18 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
19 | */ | |
20 | ||
eb51bbaf SR |
21 | #include <linux/vmalloc.h> |
22 | ||
82dd0f7e AD |
23 | #include "fm10k.h" |
24 | ||
25 | struct fm10k_stats { | |
26 | char stat_string[ETH_GSTRING_LEN]; | |
27 | int sizeof_stat; | |
28 | int stat_offset; | |
29 | }; | |
30 | ||
31 | #define FM10K_NETDEV_STAT(_net_stat) { \ | |
32 | .stat_string = #_net_stat, \ | |
33 | .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \ | |
34 | .stat_offset = offsetof(struct net_device_stats, _net_stat) \ | |
35 | } | |
36 | ||
37 | static const struct fm10k_stats fm10k_gstrings_net_stats[] = { | |
38 | FM10K_NETDEV_STAT(tx_packets), | |
39 | FM10K_NETDEV_STAT(tx_bytes), | |
40 | FM10K_NETDEV_STAT(tx_errors), | |
41 | FM10K_NETDEV_STAT(rx_packets), | |
42 | FM10K_NETDEV_STAT(rx_bytes), | |
43 | FM10K_NETDEV_STAT(rx_errors), | |
44 | FM10K_NETDEV_STAT(rx_dropped), | |
45 | ||
46 | /* detailed Rx errors */ | |
47 | FM10K_NETDEV_STAT(rx_length_errors), | |
48 | FM10K_NETDEV_STAT(rx_crc_errors), | |
49 | FM10K_NETDEV_STAT(rx_fifo_errors), | |
50 | }; | |
51 | ||
52 | #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats) | |
53 | ||
54 | #define FM10K_STAT(_name, _stat) { \ | |
55 | .stat_string = _name, \ | |
56 | .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \ | |
57 | .stat_offset = offsetof(struct fm10k_intfc, _stat) \ | |
58 | } | |
59 | ||
fbdb159f | 60 | static const struct fm10k_stats fm10k_gstrings_global_stats[] = { |
82dd0f7e AD |
61 | FM10K_STAT("tx_restart_queue", restart_queue), |
62 | FM10K_STAT("tx_busy", tx_busy), | |
63 | FM10K_STAT("tx_csum_errors", tx_csum_errors), | |
64 | FM10K_STAT("rx_alloc_failed", alloc_failed), | |
65 | FM10K_STAT("rx_csum_errors", rx_csum_errors), | |
82dd0f7e AD |
66 | |
67 | FM10K_STAT("tx_packets_nic", tx_packets_nic), | |
68 | FM10K_STAT("tx_bytes_nic", tx_bytes_nic), | |
69 | FM10K_STAT("rx_packets_nic", rx_packets_nic), | |
70 | FM10K_STAT("rx_bytes_nic", rx_bytes_nic), | |
71 | FM10K_STAT("rx_drops_nic", rx_drops_nic), | |
72 | FM10K_STAT("rx_overrun_pf", rx_overrun_pf), | |
73 | FM10K_STAT("rx_overrun_vf", rx_overrun_vf), | |
74 | ||
82dd0f7e AD |
75 | FM10K_STAT("swapi_status", hw.swapi.status), |
76 | FM10K_STAT("mac_rules_used", hw.swapi.mac.used), | |
77 | FM10K_STAT("mac_rules_avail", hw.swapi.mac.avail), | |
78 | ||
e05546ec | 79 | FM10K_STAT("tx_hang_count", tx_timeout_count), |
82dd0f7e AD |
80 | }; |
81 | ||
fbdb159f JK |
82 | static const struct fm10k_stats fm10k_gstrings_pf_stats[] = { |
83 | FM10K_STAT("timeout", stats.timeout.count), | |
84 | FM10K_STAT("ur", stats.ur.count), | |
85 | FM10K_STAT("ca", stats.ca.count), | |
86 | FM10K_STAT("um", stats.um.count), | |
87 | FM10K_STAT("xec", stats.xec.count), | |
88 | FM10K_STAT("vlan_drop", stats.vlan_drop.count), | |
89 | FM10K_STAT("loopback_drop", stats.loopback_drop.count), | |
90 | FM10K_STAT("nodesc_drop", stats.nodesc_drop.count), | |
91 | }; | |
92 | ||
80043f3b JK |
93 | #define FM10K_MBX_STAT(_name, _stat) { \ |
94 | .stat_string = _name, \ | |
95 | .sizeof_stat = FIELD_SIZEOF(struct fm10k_mbx_info, _stat), \ | |
96 | .stat_offset = offsetof(struct fm10k_mbx_info, _stat) \ | |
97 | } | |
98 | ||
99 | static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = { | |
100 | FM10K_MBX_STAT("mbx_tx_busy", tx_busy), | |
5680ea69 | 101 | FM10K_MBX_STAT("mbx_tx_dropped", tx_dropped), |
80043f3b JK |
102 | FM10K_MBX_STAT("mbx_tx_messages", tx_messages), |
103 | FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords), | |
17d39fac | 104 | FM10K_MBX_STAT("mbx_tx_mbmem_pulled", tx_mbmem_pulled), |
80043f3b JK |
105 | FM10K_MBX_STAT("mbx_rx_messages", rx_messages), |
106 | FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords), | |
107 | FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err), | |
17d39fac | 108 | FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed), |
80043f3b JK |
109 | }; |
110 | ||
09401ae2 JK |
111 | #define FM10K_QUEUE_STAT(_name, _stat) { \ |
112 | .stat_string = _name, \ | |
113 | .sizeof_stat = FIELD_SIZEOF(struct fm10k_ring, _stat), \ | |
114 | .stat_offset = offsetof(struct fm10k_ring, _stat) \ | |
115 | } | |
116 | ||
117 | static const struct fm10k_stats fm10k_gstrings_queue_stats[] = { | |
118 | FM10K_QUEUE_STAT("packets", stats.packets), | |
119 | FM10K_QUEUE_STAT("bytes", stats.bytes), | |
120 | }; | |
121 | ||
fbdb159f JK |
122 | #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats) |
123 | #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats) | |
80043f3b | 124 | #define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats) |
09401ae2 | 125 | #define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats) |
82dd0f7e | 126 | |
c0e61781 | 127 | #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \ |
80043f3b JK |
128 | FM10K_NETDEV_STATS_LEN + \ |
129 | FM10K_MBX_STATS_LEN) | |
82dd0f7e | 130 | |
5cb8db4a AD |
131 | static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = { |
132 | "Mailbox test (on/offline)" | |
133 | }; | |
134 | ||
135 | #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN) | |
136 | ||
137 | enum fm10k_self_test_types { | |
138 | FM10K_TEST_MBX, | |
139 | FM10K_TEST_MAX = FM10K_TEST_LEN | |
140 | }; | |
141 | ||
80043f3b | 142 | enum { |
80043f3b JK |
143 | FM10K_PRV_FLAG_LEN, |
144 | }; | |
145 | ||
146 | static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = { | |
80043f3b JK |
147 | }; |
148 | ||
d2e0721b JK |
149 | static void fm10k_add_stat_strings(char **p, const char *prefix, |
150 | const struct fm10k_stats stats[], | |
151 | const unsigned int size) | |
152 | { | |
153 | unsigned int i; | |
154 | ||
155 | for (i = 0; i < size; i++) { | |
156 | snprintf(*p, ETH_GSTRING_LEN, "%s%s", | |
157 | prefix, stats[i].stat_string); | |
158 | *p += ETH_GSTRING_LEN; | |
159 | } | |
160 | } | |
161 | ||
80043f3b | 162 | static void fm10k_get_stat_strings(struct net_device *dev, u8 *data) |
82dd0f7e | 163 | { |
29a928ee | 164 | struct fm10k_intfc *interface = netdev_priv(dev); |
82dd0f7e | 165 | char *p = (char *)data; |
c0e58e93 | 166 | unsigned int i; |
82dd0f7e | 167 | |
d2e0721b JK |
168 | fm10k_add_stat_strings(&p, "", fm10k_gstrings_net_stats, |
169 | FM10K_NETDEV_STATS_LEN); | |
80043f3b | 170 | |
d2e0721b JK |
171 | fm10k_add_stat_strings(&p, "", fm10k_gstrings_global_stats, |
172 | FM10K_GLOBAL_STATS_LEN); | |
80043f3b | 173 | |
d2e0721b JK |
174 | fm10k_add_stat_strings(&p, "", fm10k_gstrings_mbx_stats, |
175 | FM10K_MBX_STATS_LEN); | |
80043f3b | 176 | |
d2e0721b JK |
177 | if (interface->hw.mac.type != fm10k_mac_vf) |
178 | fm10k_add_stat_strings(&p, "", fm10k_gstrings_pf_stats, | |
179 | FM10K_PF_STATS_LEN); | |
82dd0f7e | 180 | |
80043f3b | 181 | for (i = 0; i < interface->hw.mac.max_queues; i++) { |
09401ae2 JK |
182 | char prefix[ETH_GSTRING_LEN]; |
183 | ||
184 | snprintf(prefix, ETH_GSTRING_LEN, "tx_queue_%u_", i); | |
185 | fm10k_add_stat_strings(&p, prefix, | |
186 | fm10k_gstrings_queue_stats, | |
187 | FM10K_QUEUE_STATS_LEN); | |
188 | ||
189 | snprintf(prefix, ETH_GSTRING_LEN, "rx_queue_%u_", i); | |
190 | fm10k_add_stat_strings(&p, prefix, | |
191 | fm10k_gstrings_queue_stats, | |
192 | FM10K_QUEUE_STATS_LEN); | |
80043f3b JK |
193 | } |
194 | } | |
195 | ||
196 | static void fm10k_get_strings(struct net_device *dev, | |
197 | u32 stringset, u8 *data) | |
198 | { | |
199 | char *p = (char *)data; | |
200 | ||
201 | switch (stringset) { | |
202 | case ETH_SS_TEST: | |
203 | memcpy(data, *fm10k_gstrings_test, | |
204 | FM10K_TEST_LEN * ETH_GSTRING_LEN); | |
205 | break; | |
206 | case ETH_SS_STATS: | |
207 | fm10k_get_stat_strings(dev, data); | |
208 | break; | |
209 | case ETH_SS_PRIV_FLAGS: | |
210 | memcpy(p, fm10k_prv_flags, | |
211 | FM10K_PRV_FLAG_LEN * ETH_GSTRING_LEN); | |
82dd0f7e AD |
212 | break; |
213 | } | |
214 | } | |
215 | ||
216 | static int fm10k_get_sset_count(struct net_device *dev, int sset) | |
217 | { | |
c0e61781 JK |
218 | struct fm10k_intfc *interface = netdev_priv(dev); |
219 | struct fm10k_hw *hw = &interface->hw; | |
220 | int stats_len = FM10K_STATIC_STATS_LEN; | |
221 | ||
82dd0f7e | 222 | switch (sset) { |
5cb8db4a AD |
223 | case ETH_SS_TEST: |
224 | return FM10K_TEST_LEN; | |
82dd0f7e | 225 | case ETH_SS_STATS: |
09401ae2 | 226 | stats_len += hw->mac.max_queues * 2 * FM10K_QUEUE_STATS_LEN; |
fbdb159f JK |
227 | |
228 | if (hw->mac.type != fm10k_mac_vf) | |
229 | stats_len += FM10K_PF_STATS_LEN; | |
230 | ||
c0e61781 | 231 | return stats_len; |
80043f3b JK |
232 | case ETH_SS_PRIV_FLAGS: |
233 | return FM10K_PRV_FLAG_LEN; | |
82dd0f7e AD |
234 | default: |
235 | return -EOPNOTSUPP; | |
236 | } | |
237 | } | |
238 | ||
d2e0721b JK |
239 | static void fm10k_add_ethtool_stats(u64 **data, void *pointer, |
240 | const struct fm10k_stats stats[], | |
241 | const unsigned int size) | |
242 | { | |
243 | unsigned int i; | |
244 | char *p; | |
245 | ||
d2e0721b | 246 | if (!pointer) { |
09401ae2 JK |
247 | /* memory is not zero allocated so we have to clear it */ |
248 | for (i = 0; i < size; i++) | |
249 | *((*data)++) = 0; | |
d2e0721b JK |
250 | return; |
251 | } | |
252 | ||
253 | for (i = 0; i < size; i++) { | |
254 | p = (char *)pointer + stats[i].stat_offset; | |
255 | ||
256 | switch (stats[i].sizeof_stat) { | |
257 | case sizeof(u64): | |
258 | *((*data)++) = *(u64 *)p; | |
259 | break; | |
260 | case sizeof(u32): | |
261 | *((*data)++) = *(u32 *)p; | |
262 | break; | |
263 | case sizeof(u16): | |
264 | *((*data)++) = *(u16 *)p; | |
265 | break; | |
266 | case sizeof(u8): | |
267 | *((*data)++) = *(u8 *)p; | |
268 | break; | |
269 | default: | |
270 | *((*data)++) = 0; | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
82dd0f7e | 275 | static void fm10k_get_ethtool_stats(struct net_device *netdev, |
de445199 JK |
276 | struct ethtool_stats __always_unused *stats, |
277 | u64 *data) | |
82dd0f7e | 278 | { |
82dd0f7e AD |
279 | struct fm10k_intfc *interface = netdev_priv(netdev); |
280 | struct net_device_stats *net_stats = &netdev->stats; | |
09401ae2 | 281 | int i; |
82dd0f7e AD |
282 | |
283 | fm10k_update_stats(interface); | |
284 | ||
d2e0721b JK |
285 | fm10k_add_ethtool_stats(&data, net_stats, fm10k_gstrings_net_stats, |
286 | FM10K_NETDEV_STATS_LEN); | |
82dd0f7e | 287 | |
d2e0721b JK |
288 | fm10k_add_ethtool_stats(&data, interface, fm10k_gstrings_global_stats, |
289 | FM10K_GLOBAL_STATS_LEN); | |
82dd0f7e | 290 | |
d2e0721b JK |
291 | fm10k_add_ethtool_stats(&data, &interface->hw.mbx, |
292 | fm10k_gstrings_mbx_stats, | |
293 | FM10K_MBX_STATS_LEN); | |
80043f3b JK |
294 | |
295 | if (interface->hw.mac.type != fm10k_mac_vf) { | |
d2e0721b JK |
296 | fm10k_add_ethtool_stats(&data, interface, |
297 | fm10k_gstrings_pf_stats, | |
298 | FM10K_PF_STATS_LEN); | |
80043f3b JK |
299 | } |
300 | ||
29a928ee | 301 | for (i = 0; i < interface->hw.mac.max_queues; i++) { |
82dd0f7e | 302 | struct fm10k_ring *ring; |
82dd0f7e AD |
303 | |
304 | ring = interface->tx_ring[i]; | |
09401ae2 JK |
305 | fm10k_add_ethtool_stats(&data, ring, |
306 | fm10k_gstrings_queue_stats, | |
307 | FM10K_QUEUE_STATS_LEN); | |
82dd0f7e AD |
308 | |
309 | ring = interface->rx_ring[i]; | |
09401ae2 JK |
310 | fm10k_add_ethtool_stats(&data, ring, |
311 | fm10k_gstrings_queue_stats, | |
312 | FM10K_QUEUE_STATS_LEN); | |
82dd0f7e AD |
313 | } |
314 | } | |
315 | ||
316 | /* If function below adds more registers this define needs to be updated */ | |
317 | #define FM10K_REGS_LEN_Q 29 | |
318 | ||
319 | static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i) | |
320 | { | |
321 | int idx = 0; | |
322 | ||
323 | buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i)); | |
324 | buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i)); | |
325 | buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i)); | |
326 | buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i)); | |
327 | buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i)); | |
328 | buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i)); | |
329 | buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i)); | |
330 | buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i)); | |
331 | buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i)); | |
332 | buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i)); | |
333 | buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i)); | |
334 | buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i)); | |
335 | buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i)); | |
336 | buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i)); | |
337 | buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i)); | |
338 | buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i)); | |
339 | buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i)); | |
340 | buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i)); | |
341 | buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i)); | |
342 | buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i)); | |
343 | buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i)); | |
344 | buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i)); | |
345 | buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i)); | |
346 | buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i)); | |
347 | buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i)); | |
348 | buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i)); | |
349 | buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i)); | |
350 | buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i)); | |
351 | buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i)); | |
352 | ||
353 | BUG_ON(idx != FM10K_REGS_LEN_Q); | |
354 | } | |
355 | ||
356 | /* If function above adds more registers this define needs to be updated */ | |
357 | #define FM10K_REGS_LEN_VSI 43 | |
358 | ||
359 | static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i) | |
360 | { | |
361 | int idx = 0, j; | |
362 | ||
363 | buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i)); | |
364 | for (j = 0; j < 10; j++) | |
365 | buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j)); | |
366 | for (j = 0; j < 32; j++) | |
367 | buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j)); | |
368 | ||
369 | BUG_ON(idx != FM10K_REGS_LEN_VSI); | |
370 | } | |
371 | ||
372 | static void fm10k_get_regs(struct net_device *netdev, | |
373 | struct ethtool_regs *regs, void *p) | |
374 | { | |
375 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
376 | struct fm10k_hw *hw = &interface->hw; | |
377 | u32 *buff = p; | |
378 | u16 i; | |
379 | ||
fcdb0a99 | 380 | regs->version = BIT(24) | (hw->revision_id << 16) | hw->device_id; |
82dd0f7e AD |
381 | |
382 | switch (hw->mac.type) { | |
383 | case fm10k_mac_pf: | |
384 | /* General PF Registers */ | |
385 | *(buff++) = fm10k_read_reg(hw, FM10K_CTRL); | |
386 | *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT); | |
387 | *(buff++) = fm10k_read_reg(hw, FM10K_GCR); | |
388 | *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT); | |
389 | ||
390 | for (i = 0; i < 8; i++) { | |
391 | *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i)); | |
392 | *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i)); | |
393 | } | |
394 | ||
395 | for (i = 0; i < 65; i++) { | |
396 | fm10k_get_reg_vsi(hw, buff, i); | |
397 | buff += FM10K_REGS_LEN_VSI; | |
398 | } | |
399 | ||
400 | *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL); | |
401 | *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2); | |
402 | ||
403 | for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) { | |
404 | fm10k_get_reg_q(hw, buff, i); | |
405 | buff += FM10K_REGS_LEN_Q; | |
406 | } | |
407 | ||
408 | *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL); | |
409 | ||
410 | for (i = 0; i < 8; i++) | |
411 | *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i)); | |
412 | ||
413 | /* Interrupt Throttling Registers */ | |
414 | for (i = 0; i < 130; i++) | |
415 | *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i)); | |
416 | ||
5cb8db4a AD |
417 | break; |
418 | case fm10k_mac_vf: | |
419 | /* General VF registers */ | |
420 | *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL); | |
421 | *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP); | |
422 | *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME); | |
423 | ||
424 | /* Interrupt Throttling Registers */ | |
425 | for (i = 0; i < 8; i++) | |
426 | *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i)); | |
427 | ||
428 | fm10k_get_reg_vsi(hw, buff, 0); | |
429 | buff += FM10K_REGS_LEN_VSI; | |
430 | ||
431 | for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) { | |
432 | if (i < hw->mac.max_queues) | |
433 | fm10k_get_reg_q(hw, buff, i); | |
434 | else | |
435 | memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q); | |
436 | buff += FM10K_REGS_LEN_Q; | |
437 | } | |
438 | ||
82dd0f7e AD |
439 | break; |
440 | default: | |
441 | return; | |
442 | } | |
443 | } | |
444 | ||
445 | /* If function above adds more registers these define need to be updated */ | |
446 | #define FM10K_REGS_LEN_PF \ | |
447 | (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q)) | |
5cb8db4a AD |
448 | #define FM10K_REGS_LEN_VF \ |
449 | (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q)) | |
82dd0f7e AD |
450 | |
451 | static int fm10k_get_regs_len(struct net_device *netdev) | |
452 | { | |
453 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
454 | struct fm10k_hw *hw = &interface->hw; | |
455 | ||
456 | switch (hw->mac.type) { | |
457 | case fm10k_mac_pf: | |
458 | return FM10K_REGS_LEN_PF * sizeof(u32); | |
5cb8db4a AD |
459 | case fm10k_mac_vf: |
460 | return FM10K_REGS_LEN_VF * sizeof(u32); | |
82dd0f7e AD |
461 | default: |
462 | return 0; | |
463 | } | |
464 | } | |
465 | ||
466 | static void fm10k_get_drvinfo(struct net_device *dev, | |
467 | struct ethtool_drvinfo *info) | |
468 | { | |
469 | struct fm10k_intfc *interface = netdev_priv(dev); | |
470 | ||
471 | strncpy(info->driver, fm10k_driver_name, | |
472 | sizeof(info->driver) - 1); | |
473 | strncpy(info->version, fm10k_driver_version, | |
474 | sizeof(info->version) - 1); | |
475 | strncpy(info->bus_info, pci_name(interface->pdev), | |
476 | sizeof(info->bus_info) - 1); | |
82dd0f7e AD |
477 | } |
478 | ||
479 | static void fm10k_get_pauseparam(struct net_device *dev, | |
480 | struct ethtool_pauseparam *pause) | |
481 | { | |
482 | struct fm10k_intfc *interface = netdev_priv(dev); | |
483 | ||
484 | /* record fixed values for autoneg and tx pause */ | |
485 | pause->autoneg = 0; | |
486 | pause->tx_pause = 1; | |
487 | ||
488 | pause->rx_pause = interface->rx_pause ? 1 : 0; | |
489 | } | |
490 | ||
491 | static int fm10k_set_pauseparam(struct net_device *dev, | |
492 | struct ethtool_pauseparam *pause) | |
493 | { | |
494 | struct fm10k_intfc *interface = netdev_priv(dev); | |
495 | struct fm10k_hw *hw = &interface->hw; | |
496 | ||
497 | if (pause->autoneg || !pause->tx_pause) | |
498 | return -EINVAL; | |
499 | ||
500 | /* we can only support pause on the PF to avoid head-of-line blocking */ | |
501 | if (hw->mac.type == fm10k_mac_pf) | |
502 | interface->rx_pause = pause->rx_pause ? ~0 : 0; | |
503 | else if (pause->rx_pause) | |
504 | return -EINVAL; | |
505 | ||
506 | if (netif_running(dev)) | |
507 | fm10k_update_rx_drop_en(interface); | |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
512 | static u32 fm10k_get_msglevel(struct net_device *netdev) | |
513 | { | |
514 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
515 | ||
516 | return interface->msg_enable; | |
517 | } | |
518 | ||
519 | static void fm10k_set_msglevel(struct net_device *netdev, u32 data) | |
520 | { | |
521 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
522 | ||
523 | interface->msg_enable = data; | |
524 | } | |
525 | ||
526 | static void fm10k_get_ringparam(struct net_device *netdev, | |
527 | struct ethtool_ringparam *ring) | |
528 | { | |
529 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
530 | ||
531 | ring->rx_max_pending = FM10K_MAX_RXD; | |
532 | ring->tx_max_pending = FM10K_MAX_TXD; | |
533 | ring->rx_mini_max_pending = 0; | |
534 | ring->rx_jumbo_max_pending = 0; | |
535 | ring->rx_pending = interface->rx_ring_count; | |
536 | ring->tx_pending = interface->tx_ring_count; | |
537 | ring->rx_mini_pending = 0; | |
538 | ring->rx_jumbo_pending = 0; | |
539 | } | |
540 | ||
541 | static int fm10k_set_ringparam(struct net_device *netdev, | |
542 | struct ethtool_ringparam *ring) | |
543 | { | |
544 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
545 | struct fm10k_ring *temp_ring; | |
546 | int i, err = 0; | |
547 | u32 new_rx_count, new_tx_count; | |
548 | ||
549 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) | |
550 | return -EINVAL; | |
551 | ||
552 | new_tx_count = clamp_t(u32, ring->tx_pending, | |
553 | FM10K_MIN_TXD, FM10K_MAX_TXD); | |
554 | new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE); | |
555 | ||
556 | new_rx_count = clamp_t(u32, ring->rx_pending, | |
557 | FM10K_MIN_RXD, FM10K_MAX_RXD); | |
558 | new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE); | |
559 | ||
560 | if ((new_tx_count == interface->tx_ring_count) && | |
561 | (new_rx_count == interface->rx_ring_count)) { | |
562 | /* nothing to do */ | |
563 | return 0; | |
564 | } | |
565 | ||
566 | while (test_and_set_bit(__FM10K_RESETTING, &interface->state)) | |
567 | usleep_range(1000, 2000); | |
568 | ||
569 | if (!netif_running(interface->netdev)) { | |
570 | for (i = 0; i < interface->num_tx_queues; i++) | |
571 | interface->tx_ring[i]->count = new_tx_count; | |
572 | for (i = 0; i < interface->num_rx_queues; i++) | |
573 | interface->rx_ring[i]->count = new_rx_count; | |
574 | interface->tx_ring_count = new_tx_count; | |
575 | interface->rx_ring_count = new_rx_count; | |
576 | goto clear_reset; | |
577 | } | |
578 | ||
579 | /* allocate temporary buffer to store rings in */ | |
580 | i = max_t(int, interface->num_tx_queues, interface->num_rx_queues); | |
581 | temp_ring = vmalloc(i * sizeof(struct fm10k_ring)); | |
582 | ||
583 | if (!temp_ring) { | |
584 | err = -ENOMEM; | |
585 | goto clear_reset; | |
586 | } | |
587 | ||
588 | fm10k_down(interface); | |
589 | ||
590 | /* Setup new Tx resources and free the old Tx resources in that order. | |
591 | * We can then assign the new resources to the rings via a memcpy. | |
592 | * The advantage to this approach is that we are guaranteed to still | |
593 | * have resources even in the case of an allocation failure. | |
594 | */ | |
595 | if (new_tx_count != interface->tx_ring_count) { | |
596 | for (i = 0; i < interface->num_tx_queues; i++) { | |
597 | memcpy(&temp_ring[i], interface->tx_ring[i], | |
598 | sizeof(struct fm10k_ring)); | |
599 | ||
600 | temp_ring[i].count = new_tx_count; | |
601 | err = fm10k_setup_tx_resources(&temp_ring[i]); | |
602 | if (err) { | |
603 | while (i) { | |
604 | i--; | |
605 | fm10k_free_tx_resources(&temp_ring[i]); | |
606 | } | |
607 | goto err_setup; | |
608 | } | |
609 | } | |
610 | ||
611 | for (i = 0; i < interface->num_tx_queues; i++) { | |
612 | fm10k_free_tx_resources(interface->tx_ring[i]); | |
613 | ||
614 | memcpy(interface->tx_ring[i], &temp_ring[i], | |
615 | sizeof(struct fm10k_ring)); | |
616 | } | |
617 | ||
618 | interface->tx_ring_count = new_tx_count; | |
619 | } | |
620 | ||
621 | /* Repeat the process for the Rx rings if needed */ | |
622 | if (new_rx_count != interface->rx_ring_count) { | |
623 | for (i = 0; i < interface->num_rx_queues; i++) { | |
624 | memcpy(&temp_ring[i], interface->rx_ring[i], | |
625 | sizeof(struct fm10k_ring)); | |
626 | ||
627 | temp_ring[i].count = new_rx_count; | |
628 | err = fm10k_setup_rx_resources(&temp_ring[i]); | |
629 | if (err) { | |
630 | while (i) { | |
631 | i--; | |
632 | fm10k_free_rx_resources(&temp_ring[i]); | |
633 | } | |
634 | goto err_setup; | |
635 | } | |
636 | } | |
637 | ||
638 | for (i = 0; i < interface->num_rx_queues; i++) { | |
639 | fm10k_free_rx_resources(interface->rx_ring[i]); | |
640 | ||
641 | memcpy(interface->rx_ring[i], &temp_ring[i], | |
642 | sizeof(struct fm10k_ring)); | |
643 | } | |
644 | ||
645 | interface->rx_ring_count = new_rx_count; | |
646 | } | |
647 | ||
648 | err_setup: | |
649 | fm10k_up(interface); | |
650 | vfree(temp_ring); | |
651 | clear_reset: | |
652 | clear_bit(__FM10K_RESETTING, &interface->state); | |
653 | return err; | |
654 | } | |
655 | ||
656 | static int fm10k_get_coalesce(struct net_device *dev, | |
657 | struct ethtool_coalesce *ec) | |
658 | { | |
659 | struct fm10k_intfc *interface = netdev_priv(dev); | |
660 | ||
584373f5 | 661 | ec->use_adaptive_tx_coalesce = ITR_IS_ADAPTIVE(interface->tx_itr); |
82dd0f7e AD |
662 | ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE; |
663 | ||
584373f5 | 664 | ec->use_adaptive_rx_coalesce = ITR_IS_ADAPTIVE(interface->rx_itr); |
82dd0f7e AD |
665 | ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE; |
666 | ||
667 | return 0; | |
668 | } | |
669 | ||
670 | static int fm10k_set_coalesce(struct net_device *dev, | |
671 | struct ethtool_coalesce *ec) | |
672 | { | |
673 | struct fm10k_intfc *interface = netdev_priv(dev); | |
674 | struct fm10k_q_vector *qv; | |
675 | u16 tx_itr, rx_itr; | |
676 | int i; | |
677 | ||
678 | /* verify limits */ | |
679 | if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) || | |
680 | (ec->tx_coalesce_usecs > FM10K_ITR_MAX)) | |
681 | return -EINVAL; | |
682 | ||
683 | /* record settings */ | |
684 | tx_itr = ec->tx_coalesce_usecs; | |
685 | rx_itr = ec->rx_coalesce_usecs; | |
686 | ||
687 | /* set initial values for adaptive ITR */ | |
688 | if (ec->use_adaptive_tx_coalesce) | |
436ea956 | 689 | tx_itr = FM10K_ITR_ADAPTIVE | FM10K_TX_ITR_DEFAULT; |
82dd0f7e AD |
690 | |
691 | if (ec->use_adaptive_rx_coalesce) | |
436ea956 | 692 | rx_itr = FM10K_ITR_ADAPTIVE | FM10K_RX_ITR_DEFAULT; |
82dd0f7e AD |
693 | |
694 | /* update interface */ | |
695 | interface->tx_itr = tx_itr; | |
696 | interface->rx_itr = rx_itr; | |
697 | ||
698 | /* update q_vectors */ | |
699 | for (i = 0; i < interface->num_q_vectors; i++) { | |
700 | qv = interface->q_vector[i]; | |
701 | qv->tx.itr = tx_itr; | |
702 | qv->rx.itr = rx_itr; | |
703 | } | |
704 | ||
705 | return 0; | |
706 | } | |
707 | ||
708 | static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface, | |
709 | struct ethtool_rxnfc *cmd) | |
710 | { | |
711 | cmd->data = 0; | |
712 | ||
713 | /* Report default options for RSS on fm10k */ | |
714 | switch (cmd->flow_type) { | |
715 | case TCP_V4_FLOW: | |
716 | case TCP_V6_FLOW: | |
717 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
718 | /* fall through */ | |
719 | case UDP_V4_FLOW: | |
720 | if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP) | |
721 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
722 | /* fall through */ | |
723 | case SCTP_V4_FLOW: | |
724 | case SCTP_V6_FLOW: | |
725 | case AH_ESP_V4_FLOW: | |
726 | case AH_ESP_V6_FLOW: | |
727 | case AH_V4_FLOW: | |
728 | case AH_V6_FLOW: | |
729 | case ESP_V4_FLOW: | |
730 | case ESP_V6_FLOW: | |
731 | case IPV4_FLOW: | |
732 | case IPV6_FLOW: | |
733 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; | |
734 | break; | |
735 | case UDP_V6_FLOW: | |
736 | if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP) | |
737 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
738 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; | |
739 | break; | |
740 | default: | |
741 | return -EINVAL; | |
742 | } | |
743 | ||
744 | return 0; | |
745 | } | |
746 | ||
747 | static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, | |
de445199 | 748 | u32 __always_unused *rule_locs) |
82dd0f7e AD |
749 | { |
750 | struct fm10k_intfc *interface = netdev_priv(dev); | |
751 | int ret = -EOPNOTSUPP; | |
752 | ||
753 | switch (cmd->cmd) { | |
754 | case ETHTOOL_GRXRINGS: | |
755 | cmd->data = interface->num_rx_queues; | |
756 | ret = 0; | |
757 | break; | |
758 | case ETHTOOL_GRXFH: | |
759 | ret = fm10k_get_rss_hash_opts(interface, cmd); | |
760 | break; | |
761 | default: | |
762 | break; | |
763 | } | |
764 | ||
765 | return ret; | |
766 | } | |
767 | ||
768 | #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \ | |
769 | FM10K_FLAG_RSS_FIELD_IPV6_UDP) | |
770 | static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface, | |
771 | struct ethtool_rxnfc *nfc) | |
772 | { | |
773 | u32 flags = interface->flags; | |
774 | ||
775 | /* RSS does not support anything other than hashing | |
776 | * to queues on src and dst IPs and ports | |
777 | */ | |
778 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | | |
779 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) | |
780 | return -EINVAL; | |
781 | ||
782 | switch (nfc->flow_type) { | |
783 | case TCP_V4_FLOW: | |
784 | case TCP_V6_FLOW: | |
785 | if (!(nfc->data & RXH_IP_SRC) || | |
786 | !(nfc->data & RXH_IP_DST) || | |
787 | !(nfc->data & RXH_L4_B_0_1) || | |
788 | !(nfc->data & RXH_L4_B_2_3)) | |
789 | return -EINVAL; | |
790 | break; | |
791 | case UDP_V4_FLOW: | |
792 | if (!(nfc->data & RXH_IP_SRC) || | |
793 | !(nfc->data & RXH_IP_DST)) | |
794 | return -EINVAL; | |
795 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
796 | case 0: | |
797 | flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP; | |
798 | break; | |
799 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
800 | flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP; | |
801 | break; | |
802 | default: | |
803 | return -EINVAL; | |
804 | } | |
805 | break; | |
806 | case UDP_V6_FLOW: | |
807 | if (!(nfc->data & RXH_IP_SRC) || | |
808 | !(nfc->data & RXH_IP_DST)) | |
809 | return -EINVAL; | |
810 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
811 | case 0: | |
812 | flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP; | |
813 | break; | |
814 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
815 | flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP; | |
816 | break; | |
817 | default: | |
818 | return -EINVAL; | |
819 | } | |
820 | break; | |
821 | case AH_ESP_V4_FLOW: | |
822 | case AH_V4_FLOW: | |
823 | case ESP_V4_FLOW: | |
824 | case SCTP_V4_FLOW: | |
825 | case AH_ESP_V6_FLOW: | |
826 | case AH_V6_FLOW: | |
827 | case ESP_V6_FLOW: | |
828 | case SCTP_V6_FLOW: | |
829 | if (!(nfc->data & RXH_IP_SRC) || | |
830 | !(nfc->data & RXH_IP_DST) || | |
831 | (nfc->data & RXH_L4_B_0_1) || | |
832 | (nfc->data & RXH_L4_B_2_3)) | |
833 | return -EINVAL; | |
834 | break; | |
835 | default: | |
836 | return -EINVAL; | |
837 | } | |
838 | ||
839 | /* if we changed something we need to update flags */ | |
840 | if (flags != interface->flags) { | |
841 | struct fm10k_hw *hw = &interface->hw; | |
842 | u32 mrqc; | |
843 | ||
844 | if ((flags & UDP_RSS_FLAGS) && | |
845 | !(interface->flags & UDP_RSS_FLAGS)) | |
846 | netif_warn(interface, drv, interface->netdev, | |
847 | "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n"); | |
848 | ||
849 | interface->flags = flags; | |
850 | ||
851 | /* Perform hash on these packet types */ | |
852 | mrqc = FM10K_MRQC_IPV4 | | |
853 | FM10K_MRQC_TCP_IPV4 | | |
854 | FM10K_MRQC_IPV6 | | |
855 | FM10K_MRQC_TCP_IPV6; | |
856 | ||
857 | if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP) | |
858 | mrqc |= FM10K_MRQC_UDP_IPV4; | |
859 | if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP) | |
860 | mrqc |= FM10K_MRQC_UDP_IPV6; | |
861 | ||
862 | fm10k_write_reg(hw, FM10K_MRQC(0), mrqc); | |
863 | } | |
864 | ||
865 | return 0; | |
866 | } | |
867 | ||
868 | static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) | |
869 | { | |
870 | struct fm10k_intfc *interface = netdev_priv(dev); | |
871 | int ret = -EOPNOTSUPP; | |
872 | ||
873 | switch (cmd->cmd) { | |
874 | case ETHTOOL_SRXFH: | |
875 | ret = fm10k_set_rss_hash_opt(interface, cmd); | |
876 | break; | |
877 | default: | |
878 | break; | |
879 | } | |
880 | ||
881 | return ret; | |
882 | } | |
883 | ||
5cb8db4a AD |
884 | static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data) |
885 | { | |
886 | struct fm10k_hw *hw = &interface->hw; | |
887 | struct fm10k_mbx_info *mbx = &hw->mbx; | |
888 | u32 attr_flag, test_msg[6]; | |
889 | unsigned long timeout; | |
c4114e3d | 890 | int err = -EINVAL; |
5cb8db4a AD |
891 | |
892 | /* For now this is a VF only feature */ | |
893 | if (hw->mac.type != fm10k_mac_vf) | |
894 | return 0; | |
895 | ||
896 | /* loop through both nested and unnested attribute types */ | |
fcdb0a99 BA |
897 | for (attr_flag = BIT(FM10K_TEST_MSG_UNSET); |
898 | attr_flag < BIT(2 * FM10K_TEST_MSG_NESTED); | |
5cb8db4a AD |
899 | attr_flag += attr_flag) { |
900 | /* generate message to be tested */ | |
901 | fm10k_tlv_msg_test_create(test_msg, attr_flag); | |
902 | ||
903 | fm10k_mbx_lock(interface); | |
904 | mbx->test_result = FM10K_NOT_IMPLEMENTED; | |
905 | err = mbx->ops.enqueue_tx(hw, mbx, test_msg); | |
906 | fm10k_mbx_unlock(interface); | |
907 | ||
908 | /* wait up to 1 second for response */ | |
909 | timeout = jiffies + HZ; | |
910 | do { | |
911 | if (err < 0) | |
912 | goto err_out; | |
913 | ||
914 | usleep_range(500, 1000); | |
915 | ||
916 | fm10k_mbx_lock(interface); | |
917 | mbx->ops.process(hw, mbx); | |
918 | fm10k_mbx_unlock(interface); | |
919 | ||
920 | err = mbx->test_result; | |
921 | if (!err) | |
922 | break; | |
923 | } while (time_is_after_jiffies(timeout)); | |
924 | ||
925 | /* reporting errors */ | |
926 | if (err) | |
927 | goto err_out; | |
928 | } | |
929 | ||
930 | err_out: | |
931 | *data = err < 0 ? (attr_flag) : (err > 0); | |
932 | return err; | |
933 | } | |
934 | ||
935 | static void fm10k_self_test(struct net_device *dev, | |
936 | struct ethtool_test *eth_test, u64 *data) | |
937 | { | |
938 | struct fm10k_intfc *interface = netdev_priv(dev); | |
939 | struct fm10k_hw *hw = &interface->hw; | |
940 | ||
941 | memset(data, 0, sizeof(*data) * FM10K_TEST_LEN); | |
942 | ||
943 | if (FM10K_REMOVED(hw)) { | |
944 | netif_err(interface, drv, dev, | |
945 | "Interface removed - test blocked\n"); | |
946 | eth_test->flags |= ETH_TEST_FL_FAILED; | |
947 | return; | |
948 | } | |
949 | ||
950 | if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX])) | |
951 | eth_test->flags |= ETH_TEST_FL_FAILED; | |
952 | } | |
953 | ||
80043f3b JK |
954 | static u32 fm10k_get_priv_flags(struct net_device *netdev) |
955 | { | |
3ef2f563 | 956 | return 0; |
80043f3b JK |
957 | } |
958 | ||
959 | static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags) | |
960 | { | |
fcdb0a99 | 961 | if (priv_flags >= BIT(FM10K_PRV_FLAG_LEN)) |
80043f3b JK |
962 | return -EINVAL; |
963 | ||
80043f3b JK |
964 | return 0; |
965 | } | |
966 | ||
0ea7fae4 | 967 | u32 fm10k_get_reta_size(struct net_device __always_unused *netdev) |
82dd0f7e AD |
968 | { |
969 | return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG; | |
970 | } | |
971 | ||
0ea7fae4 JK |
972 | void fm10k_write_reta(struct fm10k_intfc *interface, const u32 *indir) |
973 | { | |
540a5d85 | 974 | u16 rss_i = interface->ring_feature[RING_F_RSS].indices; |
0ea7fae4 | 975 | struct fm10k_hw *hw = &interface->hw; |
540a5d85 JK |
976 | u32 table[4]; |
977 | int i, j; | |
0ea7fae4 JK |
978 | |
979 | /* record entries to reta table */ | |
540a5d85 JK |
980 | for (i = 0; i < FM10K_RETA_SIZE; i++) { |
981 | u32 reta, n; | |
982 | ||
983 | /* generate a new table if we weren't given one */ | |
984 | for (j = 0; j < 4; j++) { | |
985 | if (indir) | |
986 | n = indir[i + j]; | |
987 | else | |
988 | n = ethtool_rxfh_indir_default(i + j, rss_i); | |
989 | ||
990 | table[j] = n; | |
991 | } | |
992 | ||
993 | reta = table[0] | | |
994 | (table[1] << 8) | | |
995 | (table[2] << 16) | | |
996 | (table[3] << 24); | |
0ea7fae4 JK |
997 | |
998 | if (interface->reta[i] == reta) | |
999 | continue; | |
1000 | ||
1001 | interface->reta[i] = reta; | |
1002 | fm10k_write_reg(hw, FM10K_RETA(0, i), reta); | |
1003 | } | |
1004 | } | |
1005 | ||
82dd0f7e AD |
1006 | static int fm10k_get_reta(struct net_device *netdev, u32 *indir) |
1007 | { | |
1008 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
1009 | int i; | |
1010 | ||
1011 | if (!indir) | |
1012 | return 0; | |
1013 | ||
1014 | for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) { | |
1015 | u32 reta = interface->reta[i]; | |
1016 | ||
1017 | indir[0] = (reta << 24) >> 24; | |
1018 | indir[1] = (reta << 16) >> 24; | |
1019 | indir[2] = (reta << 8) >> 24; | |
1020 | indir[3] = (reta) >> 24; | |
1021 | } | |
1022 | ||
1023 | return 0; | |
1024 | } | |
1025 | ||
1026 | static int fm10k_set_reta(struct net_device *netdev, const u32 *indir) | |
1027 | { | |
1028 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
82dd0f7e AD |
1029 | int i; |
1030 | u16 rss_i; | |
1031 | ||
1032 | if (!indir) | |
1033 | return 0; | |
1034 | ||
1035 | /* Verify user input. */ | |
1036 | rss_i = interface->ring_feature[RING_F_RSS].indices; | |
1037 | for (i = fm10k_get_reta_size(netdev); i--;) { | |
1038 | if (indir[i] < rss_i) | |
1039 | continue; | |
1040 | return -EINVAL; | |
1041 | } | |
1042 | ||
0ea7fae4 | 1043 | fm10k_write_reta(interface, indir); |
82dd0f7e AD |
1044 | |
1045 | return 0; | |
1046 | } | |
1047 | ||
de445199 | 1048 | static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev) |
82dd0f7e AD |
1049 | { |
1050 | return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG; | |
1051 | } | |
1052 | ||
892311f6 EP |
1053 | static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key, |
1054 | u8 *hfunc) | |
82dd0f7e AD |
1055 | { |
1056 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
1057 | int i, err; | |
1058 | ||
892311f6 EP |
1059 | if (hfunc) |
1060 | *hfunc = ETH_RSS_HASH_TOP; | |
1061 | ||
82dd0f7e AD |
1062 | err = fm10k_get_reta(netdev, indir); |
1063 | if (err || !key) | |
1064 | return err; | |
1065 | ||
1066 | for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) | |
1067 | *(__le32 *)key = cpu_to_le32(interface->rssrk[i]); | |
1068 | ||
1069 | return 0; | |
1070 | } | |
1071 | ||
1072 | static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir, | |
892311f6 | 1073 | const u8 *key, const u8 hfunc) |
82dd0f7e AD |
1074 | { |
1075 | struct fm10k_intfc *interface = netdev_priv(netdev); | |
1076 | struct fm10k_hw *hw = &interface->hw; | |
1077 | int i, err; | |
1078 | ||
892311f6 EP |
1079 | /* We do not allow change in unsupported parameters */ |
1080 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) | |
1081 | return -EOPNOTSUPP; | |
1082 | ||
82dd0f7e AD |
1083 | err = fm10k_set_reta(netdev, indir); |
1084 | if (err || !key) | |
1085 | return err; | |
1086 | ||
1087 | for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) { | |
1088 | u32 rssrk = le32_to_cpu(*(__le32 *)key); | |
1089 | ||
1090 | if (interface->rssrk[i] == rssrk) | |
1091 | continue; | |
1092 | ||
1093 | interface->rssrk[i] = rssrk; | |
1094 | fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk); | |
1095 | } | |
1096 | ||
1097 | return 0; | |
1098 | } | |
1099 | ||
aa3ac822 AD |
1100 | static unsigned int fm10k_max_channels(struct net_device *dev) |
1101 | { | |
1102 | struct fm10k_intfc *interface = netdev_priv(dev); | |
1103 | unsigned int max_combined = interface->hw.mac.max_queues; | |
1104 | u8 tcs = netdev_get_num_tc(dev); | |
1105 | ||
1106 | /* For QoS report channels per traffic class */ | |
1107 | if (tcs > 1) | |
fcdb0a99 | 1108 | max_combined = BIT((fls(max_combined / tcs) - 1)); |
aa3ac822 AD |
1109 | |
1110 | return max_combined; | |
1111 | } | |
1112 | ||
1113 | static void fm10k_get_channels(struct net_device *dev, | |
1114 | struct ethtool_channels *ch) | |
1115 | { | |
1116 | struct fm10k_intfc *interface = netdev_priv(dev); | |
1117 | struct fm10k_hw *hw = &interface->hw; | |
1118 | ||
1119 | /* report maximum channels */ | |
1120 | ch->max_combined = fm10k_max_channels(dev); | |
1121 | ||
1122 | /* report info for other vector */ | |
1123 | ch->max_other = NON_Q_VECTORS(hw); | |
1124 | ch->other_count = ch->max_other; | |
1125 | ||
1126 | /* record RSS queues */ | |
1127 | ch->combined_count = interface->ring_feature[RING_F_RSS].indices; | |
1128 | } | |
1129 | ||
1130 | static int fm10k_set_channels(struct net_device *dev, | |
1131 | struct ethtool_channels *ch) | |
1132 | { | |
1133 | struct fm10k_intfc *interface = netdev_priv(dev); | |
1134 | unsigned int count = ch->combined_count; | |
1135 | struct fm10k_hw *hw = &interface->hw; | |
1136 | ||
1137 | /* verify they are not requesting separate vectors */ | |
1138 | if (!count || ch->rx_count || ch->tx_count) | |
1139 | return -EINVAL; | |
1140 | ||
1141 | /* verify other_count has not changed */ | |
1142 | if (ch->other_count != NON_Q_VECTORS(hw)) | |
1143 | return -EINVAL; | |
1144 | ||
1145 | /* verify the number of channels does not exceed hardware limits */ | |
1146 | if (count > fm10k_max_channels(dev)) | |
1147 | return -EINVAL; | |
1148 | ||
1149 | interface->ring_feature[RING_F_RSS].limit = count; | |
1150 | ||
1151 | /* use setup TC to update any traffic class queue mapping */ | |
1152 | return fm10k_setup_tc(dev, netdev_get_num_tc(dev)); | |
1153 | } | |
1154 | ||
82dd0f7e AD |
1155 | static const struct ethtool_ops fm10k_ethtool_ops = { |
1156 | .get_strings = fm10k_get_strings, | |
1157 | .get_sset_count = fm10k_get_sset_count, | |
1158 | .get_ethtool_stats = fm10k_get_ethtool_stats, | |
1159 | .get_drvinfo = fm10k_get_drvinfo, | |
1160 | .get_link = ethtool_op_get_link, | |
1161 | .get_pauseparam = fm10k_get_pauseparam, | |
1162 | .set_pauseparam = fm10k_set_pauseparam, | |
1163 | .get_msglevel = fm10k_get_msglevel, | |
1164 | .set_msglevel = fm10k_set_msglevel, | |
1165 | .get_ringparam = fm10k_get_ringparam, | |
1166 | .set_ringparam = fm10k_set_ringparam, | |
1167 | .get_coalesce = fm10k_get_coalesce, | |
1168 | .set_coalesce = fm10k_set_coalesce, | |
1169 | .get_rxnfc = fm10k_get_rxnfc, | |
1170 | .set_rxnfc = fm10k_set_rxnfc, | |
1171 | .get_regs = fm10k_get_regs, | |
1172 | .get_regs_len = fm10k_get_regs_len, | |
5cb8db4a | 1173 | .self_test = fm10k_self_test, |
80043f3b JK |
1174 | .get_priv_flags = fm10k_get_priv_flags, |
1175 | .set_priv_flags = fm10k_set_priv_flags, | |
82dd0f7e AD |
1176 | .get_rxfh_indir_size = fm10k_get_reta_size, |
1177 | .get_rxfh_key_size = fm10k_get_rssrk_size, | |
1178 | .get_rxfh = fm10k_get_rssh, | |
1179 | .set_rxfh = fm10k_set_rssh, | |
aa3ac822 AD |
1180 | .get_channels = fm10k_get_channels, |
1181 | .set_channels = fm10k_set_channels, | |
82dd0f7e AD |
1182 | }; |
1183 | ||
1184 | void fm10k_set_ethtool_ops(struct net_device *dev) | |
1185 | { | |
1186 | dev->ethtool_ops = &fm10k_ethtool_ops; | |
1187 | } |