Commit | Line | Data |
---|---|---|
6b7c5b94 | 1 | /* |
294aedcf | 2 | * Copyright (C) 2005 - 2010 ServerEngines |
6b7c5b94 SP |
3 | * All rights reserved. |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License version 2 | |
7 | * as published by the Free Software Foundation. The full GNU General | |
8 | * Public License is included in this distribution in the file called COPYING. | |
9 | * | |
10 | * Contact Information: | |
11 | * linux-drivers@serverengines.com | |
12 | * | |
13 | * ServerEngines | |
14 | * 209 N. Fair Oaks Ave | |
15 | * Sunnyvale, CA 94085 | |
16 | */ | |
17 | ||
18 | #include "be.h" | |
8788fdc2 | 19 | #include "be_cmds.h" |
6b7c5b94 SP |
20 | #include <linux/ethtool.h> |
21 | ||
22 | struct be_ethtool_stat { | |
23 | char desc[ETH_GSTRING_LEN]; | |
24 | int type; | |
25 | int size; | |
26 | int offset; | |
27 | }; | |
28 | ||
f6c4bf3e AK |
29 | enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT, |
30 | PMEMSTAT}; | |
6b7c5b94 SP |
31 | #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \ |
32 | offsetof(_struct, field) | |
33 | #define NETSTAT_INFO(field) #field, NETSTAT,\ | |
34 | FIELDINFO(struct net_device_stats,\ | |
35 | field) | |
3abcdeda SP |
36 | #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\ |
37 | FIELDINFO(struct be_tx_stats, field) | |
38 | #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\ | |
39 | FIELDINFO(struct be_rx_stats, field) | |
6b7c5b94 SP |
40 | #define MISCSTAT_INFO(field) #field, MISCSTAT,\ |
41 | FIELDINFO(struct be_rxf_stats, field) | |
42 | #define PORTSTAT_INFO(field) #field, PORTSTAT,\ | |
43 | FIELDINFO(struct be_port_rxf_stats, \ | |
44 | field) | |
45 | #define ERXSTAT_INFO(field) #field, ERXSTAT,\ | |
46 | FIELDINFO(struct be_erx_stats, field) | |
f6c4bf3e AK |
47 | #define PMEMSTAT_INFO(field) #field, PMEMSTAT,\ |
48 | FIELDINFO(struct be_pmem_stats, field) | |
6b7c5b94 SP |
49 | |
50 | static const struct be_ethtool_stat et_stats[] = { | |
51 | {NETSTAT_INFO(rx_packets)}, | |
52 | {NETSTAT_INFO(tx_packets)}, | |
53 | {NETSTAT_INFO(rx_bytes)}, | |
54 | {NETSTAT_INFO(tx_bytes)}, | |
55 | {NETSTAT_INFO(rx_errors)}, | |
56 | {NETSTAT_INFO(tx_errors)}, | |
57 | {NETSTAT_INFO(rx_dropped)}, | |
58 | {NETSTAT_INFO(tx_dropped)}, | |
3abcdeda SP |
59 | {DRVSTAT_TX_INFO(be_tx_rate)}, |
60 | {DRVSTAT_TX_INFO(be_tx_reqs)}, | |
61 | {DRVSTAT_TX_INFO(be_tx_wrbs)}, | |
62 | {DRVSTAT_TX_INFO(be_tx_stops)}, | |
63 | {DRVSTAT_TX_INFO(be_tx_events)}, | |
64 | {DRVSTAT_TX_INFO(be_tx_compl)}, | |
6b7c5b94 SP |
65 | {PORTSTAT_INFO(rx_unicast_frames)}, |
66 | {PORTSTAT_INFO(rx_multicast_frames)}, | |
67 | {PORTSTAT_INFO(rx_broadcast_frames)}, | |
68 | {PORTSTAT_INFO(rx_crc_errors)}, | |
69 | {PORTSTAT_INFO(rx_alignment_symbol_errors)}, | |
70 | {PORTSTAT_INFO(rx_pause_frames)}, | |
71 | {PORTSTAT_INFO(rx_control_frames)}, | |
72 | {PORTSTAT_INFO(rx_in_range_errors)}, | |
73 | {PORTSTAT_INFO(rx_out_range_errors)}, | |
74 | {PORTSTAT_INFO(rx_frame_too_long)}, | |
75 | {PORTSTAT_INFO(rx_address_match_errors)}, | |
76 | {PORTSTAT_INFO(rx_vlan_mismatch)}, | |
77 | {PORTSTAT_INFO(rx_dropped_too_small)}, | |
78 | {PORTSTAT_INFO(rx_dropped_too_short)}, | |
79 | {PORTSTAT_INFO(rx_dropped_header_too_small)}, | |
80 | {PORTSTAT_INFO(rx_dropped_tcp_length)}, | |
81 | {PORTSTAT_INFO(rx_dropped_runt)}, | |
82 | {PORTSTAT_INFO(rx_fifo_overflow)}, | |
83 | {PORTSTAT_INFO(rx_input_fifo_overflow)}, | |
84 | {PORTSTAT_INFO(rx_ip_checksum_errs)}, | |
85 | {PORTSTAT_INFO(rx_tcp_checksum_errs)}, | |
86 | {PORTSTAT_INFO(rx_udp_checksum_errs)}, | |
87 | {PORTSTAT_INFO(rx_non_rss_packets)}, | |
88 | {PORTSTAT_INFO(rx_ipv4_packets)}, | |
89 | {PORTSTAT_INFO(rx_ipv6_packets)}, | |
def824c0 AK |
90 | {PORTSTAT_INFO(rx_switched_unicast_packets)}, |
91 | {PORTSTAT_INFO(rx_switched_multicast_packets)}, | |
92 | {PORTSTAT_INFO(rx_switched_broadcast_packets)}, | |
6b7c5b94 SP |
93 | {PORTSTAT_INFO(tx_unicastframes)}, |
94 | {PORTSTAT_INFO(tx_multicastframes)}, | |
95 | {PORTSTAT_INFO(tx_broadcastframes)}, | |
96 | {PORTSTAT_INFO(tx_pauseframes)}, | |
97 | {PORTSTAT_INFO(tx_controlframes)}, | |
98 | {MISCSTAT_INFO(rx_drops_no_pbuf)}, | |
99 | {MISCSTAT_INFO(rx_drops_no_txpb)}, | |
100 | {MISCSTAT_INFO(rx_drops_no_erx_descr)}, | |
101 | {MISCSTAT_INFO(rx_drops_no_tpre_descr)}, | |
102 | {MISCSTAT_INFO(rx_drops_too_many_frags)}, | |
103 | {MISCSTAT_INFO(rx_drops_invalid_ring)}, | |
104 | {MISCSTAT_INFO(forwarded_packets)}, | |
f6c4bf3e AK |
105 | {MISCSTAT_INFO(rx_drops_mtu)}, |
106 | {MISCSTAT_INFO(port0_jabber_events)}, | |
107 | {MISCSTAT_INFO(port1_jabber_events)}, | |
108 | {PMEMSTAT_INFO(eth_red_drops)} | |
6b7c5b94 SP |
109 | }; |
110 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) | |
111 | ||
3abcdeda SP |
112 | /* Stats related to multi RX queues */ |
113 | static const struct be_ethtool_stat et_rx_stats[] = { | |
114 | {DRVSTAT_RX_INFO(rx_bytes)}, | |
115 | {DRVSTAT_RX_INFO(rx_pkts)}, | |
116 | {DRVSTAT_RX_INFO(rx_rate)}, | |
117 | {DRVSTAT_RX_INFO(rx_polls)}, | |
118 | {DRVSTAT_RX_INFO(rx_events)}, | |
119 | {DRVSTAT_RX_INFO(rx_compl)}, | |
120 | {DRVSTAT_RX_INFO(rx_mcast_pkts)}, | |
121 | {DRVSTAT_RX_INFO(rx_post_fail)}, | |
122 | {ERXSTAT_INFO(rx_drops_no_fragments)} | |
123 | }; | |
124 | #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) | |
125 | ||
ff33a6e2 S |
126 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
127 | "MAC Loopback test", | |
128 | "PHY Loopback test", | |
129 | "External Loopback test", | |
4ee77214 | 130 | "DDR DMA test", |
4276e47e | 131 | "Link test" |
ff33a6e2 S |
132 | }; |
133 | ||
134 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) | |
135 | #define BE_MAC_LOOPBACK 0x0 | |
136 | #define BE_PHY_LOOPBACK 0x1 | |
137 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 | |
fced9999 | 138 | #define BE_NO_LOOPBACK 0xff |
ff33a6e2 | 139 | |
6b7c5b94 SP |
140 | static void |
141 | be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) | |
142 | { | |
143 | struct be_adapter *adapter = netdev_priv(netdev); | |
144 | ||
145 | strcpy(drvinfo->driver, DRV_NAME); | |
146 | strcpy(drvinfo->version, DRV_VER); | |
147 | strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN); | |
148 | strcpy(drvinfo->bus_info, pci_name(adapter->pdev)); | |
149 | drvinfo->testinfo_len = 0; | |
150 | drvinfo->regdump_len = 0; | |
151 | drvinfo->eedump_len = 0; | |
152 | } | |
153 | ||
154 | static int | |
155 | be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) | |
156 | { | |
157 | struct be_adapter *adapter = netdev_priv(netdev); | |
3abcdeda | 158 | struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq; |
6b7c5b94 SP |
159 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
160 | ||
6b7c5b94 SP |
161 | coalesce->rx_coalesce_usecs = rx_eq->cur_eqd; |
162 | coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd; | |
163 | coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd; | |
164 | ||
165 | coalesce->tx_coalesce_usecs = tx_eq->cur_eqd; | |
166 | coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd; | |
167 | coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd; | |
168 | ||
169 | coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic; | |
170 | coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic; | |
171 | ||
172 | return 0; | |
173 | } | |
174 | ||
175 | /* | |
5be93b9a | 176 | * This routine is used to set interrup coalescing delay |
6b7c5b94 SP |
177 | */ |
178 | static int | |
179 | be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) | |
180 | { | |
181 | struct be_adapter *adapter = netdev_priv(netdev); | |
3abcdeda SP |
182 | struct be_rx_obj *rxo; |
183 | struct be_eq_obj *rx_eq; | |
6b7c5b94 SP |
184 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
185 | u32 tx_max, tx_min, tx_cur; | |
186 | u32 rx_max, rx_min, rx_cur; | |
3abcdeda | 187 | int status = 0, i; |
6b7c5b94 SP |
188 | |
189 | if (coalesce->use_adaptive_tx_coalesce == 1) | |
190 | return -EINVAL; | |
191 | ||
3abcdeda SP |
192 | for_all_rx_queues(adapter, rxo, i) { |
193 | rx_eq = &rxo->rx_eq; | |
194 | ||
195 | if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce) | |
196 | rx_eq->cur_eqd = 0; | |
197 | rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce; | |
198 | ||
199 | rx_max = coalesce->rx_coalesce_usecs_high; | |
200 | rx_min = coalesce->rx_coalesce_usecs_low; | |
201 | rx_cur = coalesce->rx_coalesce_usecs; | |
202 | ||
203 | if (rx_eq->enable_aic) { | |
204 | if (rx_max > BE_MAX_EQD) | |
205 | rx_max = BE_MAX_EQD; | |
206 | if (rx_min > rx_max) | |
207 | rx_min = rx_max; | |
208 | rx_eq->max_eqd = rx_max; | |
209 | rx_eq->min_eqd = rx_min; | |
210 | if (rx_eq->cur_eqd > rx_max) | |
211 | rx_eq->cur_eqd = rx_max; | |
212 | if (rx_eq->cur_eqd < rx_min) | |
213 | rx_eq->cur_eqd = rx_min; | |
214 | } else { | |
215 | if (rx_cur > BE_MAX_EQD) | |
216 | rx_cur = BE_MAX_EQD; | |
217 | if (rx_eq->cur_eqd != rx_cur) { | |
218 | status = be_cmd_modify_eqd(adapter, rx_eq->q.id, | |
219 | rx_cur); | |
220 | if (!status) | |
221 | rx_eq->cur_eqd = rx_cur; | |
222 | } | |
223 | } | |
6b7c5b94 | 224 | } |
6b7c5b94 SP |
225 | |
226 | tx_max = coalesce->tx_coalesce_usecs_high; | |
227 | tx_min = coalesce->tx_coalesce_usecs_low; | |
228 | tx_cur = coalesce->tx_coalesce_usecs; | |
229 | ||
230 | if (tx_cur > BE_MAX_EQD) | |
231 | tx_cur = BE_MAX_EQD; | |
232 | if (tx_eq->cur_eqd != tx_cur) { | |
8788fdc2 | 233 | status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur); |
6b7c5b94 SP |
234 | if (!status) |
235 | tx_eq->cur_eqd = tx_cur; | |
236 | } | |
237 | ||
6b7c5b94 SP |
238 | return 0; |
239 | } | |
240 | ||
241 | static u32 be_get_rx_csum(struct net_device *netdev) | |
242 | { | |
243 | struct be_adapter *adapter = netdev_priv(netdev); | |
244 | ||
245 | return adapter->rx_csum; | |
246 | } | |
247 | ||
248 | static int be_set_rx_csum(struct net_device *netdev, uint32_t data) | |
249 | { | |
250 | struct be_adapter *adapter = netdev_priv(netdev); | |
251 | ||
252 | if (data) | |
253 | adapter->rx_csum = true; | |
254 | else | |
255 | adapter->rx_csum = false; | |
256 | ||
257 | return 0; | |
258 | } | |
259 | ||
260 | static void | |
261 | be_get_ethtool_stats(struct net_device *netdev, | |
262 | struct ethtool_stats *stats, uint64_t *data) | |
263 | { | |
264 | struct be_adapter *adapter = netdev_priv(netdev); | |
3abcdeda | 265 | struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va); |
6b7c5b94 | 266 | struct be_erx_stats *erx_stats = &hw_stats->erx; |
3abcdeda | 267 | struct be_rx_obj *rxo; |
6b7c5b94 | 268 | void *p = NULL; |
3abcdeda | 269 | int i, j; |
6b7c5b94 SP |
270 | |
271 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { | |
272 | switch (et_stats[i].type) { | |
273 | case NETSTAT: | |
3abcdeda | 274 | p = &netdev->stats; |
6b7c5b94 | 275 | break; |
3abcdeda SP |
276 | case DRVSTAT_TX: |
277 | p = &adapter->tx_stats; | |
6b7c5b94 SP |
278 | break; |
279 | case PORTSTAT: | |
3abcdeda | 280 | p = &hw_stats->rxf.port[adapter->port_num]; |
6b7c5b94 SP |
281 | break; |
282 | case MISCSTAT: | |
3abcdeda | 283 | p = &hw_stats->rxf; |
6b7c5b94 | 284 | break; |
f6c4bf3e AK |
285 | case PMEMSTAT: |
286 | p = &hw_stats->pmem; | |
287 | break; | |
6b7c5b94 SP |
288 | } |
289 | ||
290 | p = (u8 *)p + et_stats[i].offset; | |
291 | data[i] = (et_stats[i].size == sizeof(u64)) ? | |
292 | *(u64 *)p: *(u32 *)p; | |
293 | } | |
3abcdeda SP |
294 | |
295 | for_all_rx_queues(adapter, rxo, j) { | |
296 | for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) { | |
297 | switch (et_rx_stats[i].type) { | |
298 | case DRVSTAT_RX: | |
299 | p = (u8 *)&rxo->stats + et_rx_stats[i].offset; | |
300 | break; | |
301 | case ERXSTAT: | |
302 | p = (u32 *)erx_stats + rxo->q.id; | |
303 | break; | |
304 | } | |
305 | data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] = | |
306 | (et_rx_stats[i].size == sizeof(u64)) ? | |
307 | *(u64 *)p: *(u32 *)p; | |
308 | } | |
309 | } | |
6b7c5b94 SP |
310 | } |
311 | ||
312 | static void | |
313 | be_get_stat_strings(struct net_device *netdev, uint32_t stringset, | |
314 | uint8_t *data) | |
315 | { | |
3abcdeda SP |
316 | struct be_adapter *adapter = netdev_priv(netdev); |
317 | int i, j; | |
318 | ||
6b7c5b94 SP |
319 | switch (stringset) { |
320 | case ETH_SS_STATS: | |
321 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { | |
322 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); | |
323 | data += ETH_GSTRING_LEN; | |
324 | } | |
3abcdeda SP |
325 | for (i = 0; i < adapter->num_rx_qs; i++) { |
326 | for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { | |
327 | sprintf(data, "rxq%d: %s", i, | |
328 | et_rx_stats[j].desc); | |
329 | data += ETH_GSTRING_LEN; | |
330 | } | |
331 | } | |
6b7c5b94 | 332 | break; |
ff33a6e2 S |
333 | case ETH_SS_TEST: |
334 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { | |
335 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); | |
336 | data += ETH_GSTRING_LEN; | |
337 | } | |
338 | break; | |
6b7c5b94 SP |
339 | } |
340 | } | |
341 | ||
15f0a394 | 342 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
6b7c5b94 | 343 | { |
3abcdeda SP |
344 | struct be_adapter *adapter = netdev_priv(netdev); |
345 | ||
15f0a394 | 346 | switch (stringset) { |
ff33a6e2 S |
347 | case ETH_SS_TEST: |
348 | return ETHTOOL_TESTS_NUM; | |
15f0a394 | 349 | case ETH_SS_STATS: |
3abcdeda SP |
350 | return ETHTOOL_STATS_NUM + |
351 | adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM; | |
15f0a394 BH |
352 | default: |
353 | return -EINVAL; | |
354 | } | |
6b7c5b94 SP |
355 | } |
356 | ||
357 | static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) | |
358 | { | |
0388f251 | 359 | struct be_adapter *adapter = netdev_priv(netdev); |
ee3cb629 AK |
360 | struct be_dma_mem phy_cmd; |
361 | struct be_cmd_resp_get_phy_info *resp; | |
362 | u8 mac_speed = 0; | |
0388f251 SB |
363 | u16 link_speed = 0; |
364 | bool link_up = false; | |
0dffc83e | 365 | int status; |
ee3cb629 | 366 | u16 intf_type; |
0dffc83e | 367 | |
48e9989e | 368 | if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) { |
0dffc83e AK |
369 | status = be_cmd_link_status_query(adapter, &link_up, |
370 | &mac_speed, &link_speed); | |
371 | ||
48e9989e | 372 | be_link_status_update(adapter, link_up); |
0dffc83e AK |
373 | /* link_speed is in units of 10 Mbps */ |
374 | if (link_speed) { | |
375 | ecmd->speed = link_speed*10; | |
376 | } else { | |
377 | switch (mac_speed) { | |
378 | case PHY_LINK_SPEED_1GBPS: | |
379 | ecmd->speed = SPEED_1000; | |
380 | break; | |
381 | case PHY_LINK_SPEED_10GBPS: | |
382 | ecmd->speed = SPEED_10000; | |
383 | break; | |
384 | } | |
385 | } | |
0388f251 | 386 | |
ee3cb629 | 387 | phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info); |
2b7bcebf IV |
388 | phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, |
389 | phy_cmd.size, &phy_cmd.dma, | |
390 | GFP_KERNEL); | |
ee3cb629 AK |
391 | if (!phy_cmd.va) { |
392 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); | |
393 | return -ENOMEM; | |
394 | } | |
395 | status = be_cmd_get_phy_info(adapter, &phy_cmd); | |
16c02145 | 396 | if (!status) { |
ee3cb629 AK |
397 | resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va; |
398 | intf_type = le16_to_cpu(resp->interface_type); | |
399 | ||
400 | switch (intf_type) { | |
401 | case PHY_TYPE_XFP_10GB: | |
402 | case PHY_TYPE_SFP_1GB: | |
403 | case PHY_TYPE_SFP_PLUS_10GB: | |
16c02145 | 404 | ecmd->port = PORT_FIBRE; |
16c02145 SB |
405 | break; |
406 | default: | |
407 | ecmd->port = PORT_TP; | |
16c02145 SB |
408 | break; |
409 | } | |
ee3cb629 AK |
410 | |
411 | switch (intf_type) { | |
412 | case PHY_TYPE_KR_10GB: | |
413 | case PHY_TYPE_KX4_10GB: | |
414 | ecmd->autoneg = AUTONEG_ENABLE; | |
16c02145 | 415 | ecmd->transceiver = XCVR_INTERNAL; |
ee3cb629 AK |
416 | break; |
417 | default: | |
418 | ecmd->autoneg = AUTONEG_DISABLE; | |
419 | ecmd->transceiver = XCVR_EXTERNAL; | |
420 | break; | |
421 | } | |
0388f251 | 422 | } |
0dffc83e AK |
423 | |
424 | /* Save for future use */ | |
425 | adapter->link_speed = ecmd->speed; | |
426 | adapter->port_type = ecmd->port; | |
16c02145 | 427 | adapter->transceiver = ecmd->transceiver; |
ee3cb629 | 428 | adapter->autoneg = ecmd->autoneg; |
2b7bcebf IV |
429 | dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va, |
430 | phy_cmd.dma); | |
0dffc83e AK |
431 | } else { |
432 | ecmd->speed = adapter->link_speed; | |
433 | ecmd->port = adapter->port_type; | |
16c02145 | 434 | ecmd->transceiver = adapter->transceiver; |
ee3cb629 | 435 | ecmd->autoneg = adapter->autoneg; |
0388f251 | 436 | } |
0dffc83e | 437 | |
6b7c5b94 | 438 | ecmd->duplex = DUPLEX_FULL; |
0388f251 | 439 | ecmd->phy_address = adapter->port_num; |
16c02145 SB |
440 | switch (ecmd->port) { |
441 | case PORT_FIBRE: | |
442 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); | |
443 | break; | |
444 | case PORT_TP: | |
445 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP); | |
446 | break; | |
447 | case PORT_AUI: | |
448 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI); | |
449 | break; | |
450 | } | |
0388f251 | 451 | |
ee3cb629 AK |
452 | if (ecmd->autoneg) { |
453 | ecmd->supported |= SUPPORTED_1000baseT_Full; | |
454 | ecmd->supported |= SUPPORTED_Autoneg; | |
455 | ecmd->advertising |= (ADVERTISED_10000baseT_Full | | |
456 | ADVERTISED_1000baseT_Full); | |
457 | } | |
458 | ||
6b7c5b94 SP |
459 | return 0; |
460 | } | |
461 | ||
462 | static void | |
463 | be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) | |
464 | { | |
465 | struct be_adapter *adapter = netdev_priv(netdev); | |
466 | ||
3abcdeda | 467 | ring->rx_max_pending = adapter->rx_obj[0].q.len; |
6b7c5b94 SP |
468 | ring->tx_max_pending = adapter->tx_obj.q.len; |
469 | ||
3abcdeda | 470 | ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used); |
6b7c5b94 SP |
471 | ring->tx_pending = atomic_read(&adapter->tx_obj.q.used); |
472 | } | |
473 | ||
474 | static void | |
475 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) | |
476 | { | |
477 | struct be_adapter *adapter = netdev_priv(netdev); | |
478 | ||
8788fdc2 | 479 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
03a980d1 | 480 | ecmd->autoneg = 0; |
6b7c5b94 SP |
481 | } |
482 | ||
483 | static int | |
484 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) | |
485 | { | |
486 | struct be_adapter *adapter = netdev_priv(netdev); | |
487 | int status; | |
488 | ||
03a980d1 | 489 | if (ecmd->autoneg != 0) |
6b7c5b94 | 490 | return -EINVAL; |
9e90c961 AK |
491 | adapter->tx_fc = ecmd->tx_pause; |
492 | adapter->rx_fc = ecmd->rx_pause; | |
6b7c5b94 | 493 | |
9e90c961 AK |
494 | status = be_cmd_set_flow_control(adapter, |
495 | adapter->tx_fc, adapter->rx_fc); | |
496 | if (status) | |
6b7c5b94 SP |
497 | dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); |
498 | ||
499 | return status; | |
500 | } | |
501 | ||
fad9ab2c SB |
502 | static int |
503 | be_phys_id(struct net_device *netdev, u32 data) | |
504 | { | |
505 | struct be_adapter *adapter = netdev_priv(netdev); | |
506 | int status; | |
507 | u32 cur; | |
508 | ||
fad9ab2c SB |
509 | be_cmd_get_beacon_state(adapter, adapter->port_num, &cur); |
510 | ||
511 | if (cur == BEACON_STATE_ENABLED) | |
512 | return 0; | |
513 | ||
514 | if (data < 2) | |
515 | data = 2; | |
516 | ||
517 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, | |
518 | BEACON_STATE_ENABLED); | |
519 | set_current_state(TASK_INTERRUPTIBLE); | |
520 | schedule_timeout(data*HZ); | |
521 | ||
522 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, | |
523 | BEACON_STATE_DISABLED); | |
524 | ||
525 | return status; | |
526 | } | |
527 | ||
dcf96f1f AK |
528 | static bool |
529 | be_is_wol_supported(struct be_adapter *adapter) | |
530 | { | |
531 | if (!be_physfn(adapter)) | |
532 | return false; | |
533 | else | |
534 | return true; | |
535 | } | |
536 | ||
71d8d1b5 AK |
537 | static void |
538 | be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | |
539 | { | |
540 | struct be_adapter *adapter = netdev_priv(netdev); | |
541 | ||
dcf96f1f AK |
542 | if (be_is_wol_supported(adapter)) |
543 | wol->supported = WAKE_MAGIC; | |
544 | ||
71d8d1b5 AK |
545 | if (adapter->wol) |
546 | wol->wolopts = WAKE_MAGIC; | |
547 | else | |
548 | wol->wolopts = 0; | |
549 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
71d8d1b5 AK |
550 | } |
551 | ||
552 | static int | |
553 | be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | |
554 | { | |
555 | struct be_adapter *adapter = netdev_priv(netdev); | |
556 | ||
557 | if (wol->wolopts & ~WAKE_MAGIC) | |
558 | return -EINVAL; | |
559 | ||
dcf96f1f | 560 | if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter)) |
71d8d1b5 AK |
561 | adapter->wol = true; |
562 | else | |
563 | adapter->wol = false; | |
564 | ||
565 | return 0; | |
566 | } | |
567 | ||
ff33a6e2 S |
568 | static int |
569 | be_test_ddr_dma(struct be_adapter *adapter) | |
570 | { | |
571 | int ret, i; | |
572 | struct be_dma_mem ddrdma_cmd; | |
215faf9c JP |
573 | static const u64 pattern[2] = { |
574 | 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL | |
575 | }; | |
ff33a6e2 S |
576 | |
577 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); | |
2b7bcebf IV |
578 | ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size, |
579 | &ddrdma_cmd.dma, GFP_KERNEL); | |
ff33a6e2 | 580 | if (!ddrdma_cmd.va) { |
2381a55c | 581 | dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); |
ff33a6e2 S |
582 | return -ENOMEM; |
583 | } | |
584 | ||
585 | for (i = 0; i < 2; i++) { | |
586 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], | |
587 | 4096, &ddrdma_cmd); | |
588 | if (ret != 0) | |
589 | goto err; | |
590 | } | |
591 | ||
592 | err: | |
2b7bcebf IV |
593 | dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, |
594 | ddrdma_cmd.dma); | |
ff33a6e2 S |
595 | return ret; |
596 | } | |
597 | ||
fced9999 SB |
598 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
599 | u64 *status) | |
600 | { | |
601 | be_cmd_set_loopback(adapter, adapter->port_num, | |
602 | loopback_type, 1); | |
603 | *status = be_cmd_loopback_test(adapter, adapter->port_num, | |
604 | loopback_type, 1500, | |
605 | 2, 0xabc); | |
606 | be_cmd_set_loopback(adapter, adapter->port_num, | |
607 | BE_NO_LOOPBACK, 1); | |
608 | return *status; | |
609 | } | |
610 | ||
ff33a6e2 S |
611 | static void |
612 | be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) | |
613 | { | |
614 | struct be_adapter *adapter = netdev_priv(netdev); | |
4276e47e SB |
615 | bool link_up; |
616 | u8 mac_speed = 0; | |
617 | u16 qos_link_speed = 0; | |
ff33a6e2 S |
618 | |
619 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); | |
620 | ||
621 | if (test->flags & ETH_TEST_FL_OFFLINE) { | |
fced9999 SB |
622 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, |
623 | &data[0]) != 0) { | |
ff33a6e2 | 624 | test->flags |= ETH_TEST_FL_FAILED; |
fced9999 SB |
625 | } |
626 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, | |
627 | &data[1]) != 0) { | |
ff33a6e2 | 628 | test->flags |= ETH_TEST_FL_FAILED; |
fced9999 SB |
629 | } |
630 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, | |
631 | &data[2]) != 0) { | |
ff33a6e2 | 632 | test->flags |= ETH_TEST_FL_FAILED; |
fced9999 | 633 | } |
8f47afe0 | 634 | } |
ff33a6e2 | 635 | |
8f47afe0 SB |
636 | if (be_test_ddr_dma(adapter) != 0) { |
637 | data[3] = 1; | |
638 | test->flags |= ETH_TEST_FL_FAILED; | |
ff33a6e2 S |
639 | } |
640 | ||
4276e47e SB |
641 | if (be_cmd_link_status_query(adapter, &link_up, &mac_speed, |
642 | &qos_link_speed) != 0) { | |
643 | test->flags |= ETH_TEST_FL_FAILED; | |
644 | data[4] = -1; | |
4ee77214 AK |
645 | } else if (!mac_speed) { |
646 | test->flags |= ETH_TEST_FL_FAILED; | |
4276e47e SB |
647 | data[4] = 1; |
648 | } | |
ff33a6e2 S |
649 | } |
650 | ||
84517482 AK |
651 | static int |
652 | be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) | |
653 | { | |
654 | struct be_adapter *adapter = netdev_priv(netdev); | |
655 | char file_name[ETHTOOL_FLASH_MAX_FILENAME]; | |
656 | u32 region; | |
657 | ||
658 | file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; | |
659 | strcpy(file_name, efl->data); | |
660 | region = efl->region; | |
661 | ||
662 | return be_load_fw(adapter, file_name); | |
663 | } | |
664 | ||
368c0ca2 SB |
665 | static int |
666 | be_get_eeprom_len(struct net_device *netdev) | |
667 | { | |
668 | return BE_READ_SEEPROM_LEN; | |
669 | } | |
670 | ||
671 | static int | |
672 | be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, | |
673 | uint8_t *data) | |
674 | { | |
675 | struct be_adapter *adapter = netdev_priv(netdev); | |
676 | struct be_dma_mem eeprom_cmd; | |
677 | struct be_cmd_resp_seeprom_read *resp; | |
678 | int status; | |
679 | ||
680 | if (!eeprom->len) | |
681 | return -EINVAL; | |
682 | ||
683 | eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); | |
684 | ||
685 | memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); | |
686 | eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); | |
2b7bcebf IV |
687 | eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size, |
688 | &eeprom_cmd.dma, GFP_KERNEL); | |
368c0ca2 SB |
689 | |
690 | if (!eeprom_cmd.va) { | |
691 | dev_err(&adapter->pdev->dev, | |
692 | "Memory allocation failure. Could not read eeprom\n"); | |
693 | return -ENOMEM; | |
694 | } | |
695 | ||
696 | status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); | |
697 | ||
698 | if (!status) { | |
699 | resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va; | |
c0ad9845 | 700 | memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); |
368c0ca2 | 701 | } |
2b7bcebf IV |
702 | dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, |
703 | eeprom_cmd.dma); | |
368c0ca2 SB |
704 | |
705 | return status; | |
706 | } | |
707 | ||
0fc0b732 | 708 | const struct ethtool_ops be_ethtool_ops = { |
6b7c5b94 SP |
709 | .get_settings = be_get_settings, |
710 | .get_drvinfo = be_get_drvinfo, | |
71d8d1b5 AK |
711 | .get_wol = be_get_wol, |
712 | .set_wol = be_set_wol, | |
6b7c5b94 | 713 | .get_link = ethtool_op_get_link, |
368c0ca2 SB |
714 | .get_eeprom_len = be_get_eeprom_len, |
715 | .get_eeprom = be_read_eeprom, | |
6b7c5b94 SP |
716 | .get_coalesce = be_get_coalesce, |
717 | .set_coalesce = be_set_coalesce, | |
718 | .get_ringparam = be_get_ringparam, | |
719 | .get_pauseparam = be_get_pauseparam, | |
720 | .set_pauseparam = be_set_pauseparam, | |
721 | .get_rx_csum = be_get_rx_csum, | |
722 | .set_rx_csum = be_set_rx_csum, | |
723 | .get_tx_csum = ethtool_op_get_tx_csum, | |
583e3f34 | 724 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
6b7c5b94 SP |
725 | .get_sg = ethtool_op_get_sg, |
726 | .set_sg = ethtool_op_set_sg, | |
727 | .get_tso = ethtool_op_get_tso, | |
728 | .set_tso = ethtool_op_set_tso, | |
729 | .get_strings = be_get_stat_strings, | |
fad9ab2c | 730 | .phys_id = be_phys_id, |
15f0a394 | 731 | .get_sset_count = be_get_sset_count, |
6b7c5b94 | 732 | .get_ethtool_stats = be_get_ethtool_stats, |
84517482 | 733 | .flash_device = be_do_flash, |
ff33a6e2 | 734 | .self_test = be_self_test, |
6b7c5b94 | 735 | }; |