diff options
Diffstat (limited to 'drivers/net/netxen/netxen_nic_ethtool.c')
-rw-r--r-- | drivers/net/netxen/netxen_nic_ethtool.c | 741 |
1 files changed, 741 insertions, 0 deletions
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c new file mode 100644 index 00000000000..9a914aeba5b --- /dev/null +++ b/drivers/net/netxen/netxen_nic_ethtool.c | |||
@@ -0,0 +1,741 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 - 2006 NetXen, Inc. | ||
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 | ||
7 | * as published by the Free Software Foundation; either version 2 | ||
8 | * of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
18 | * MA 02111-1307, USA. | ||
19 | * | ||
20 | * The full GNU General Public License is included in this distribution | ||
21 | * in the file called LICENSE. | ||
22 | * | ||
23 | * Contact Information: | ||
24 | * info@netxen.com | ||
25 | * NetXen, | ||
26 | * 3965 Freedom Circle, Fourth floor, | ||
27 | * Santa Clara, CA 95054 | ||
28 | * | ||
29 | * | ||
30 | * ethtool support for netxen nic | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/types.h> | ||
35 | #include <asm/uaccess.h> | ||
36 | #include <linux/pci.h> | ||
37 | #include <asm/io.h> | ||
38 | #include <linux/netdevice.h> | ||
39 | #include <linux/ethtool.h> | ||
40 | #include <linux/version.h> | ||
41 | |||
42 | #include "netxen_nic_hw.h" | ||
43 | #include "netxen_nic.h" | ||
44 | #include "netxen_nic_phan_reg.h" | ||
45 | #include "netxen_nic_ioctl.h" | ||
46 | |||
47 | struct netxen_nic_stats { | ||
48 | char stat_string[ETH_GSTRING_LEN]; | ||
49 | int sizeof_stat; | ||
50 | int stat_offset; | ||
51 | }; | ||
52 | |||
53 | #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_port *)0)->m), \ | ||
54 | offsetof(struct netxen_port, m) | ||
55 | |||
56 | #define NETXEN_NIC_PORT_WINDOW 0x10000 | ||
57 | #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF | ||
58 | |||
59 | static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = { | ||
60 | {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)}, | ||
61 | {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)}, | ||
62 | {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)}, | ||
63 | {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)}, | ||
64 | {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)}, | ||
65 | {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)}, | ||
66 | {"polled", NETXEN_NIC_STAT(stats.polled)}, | ||
67 | {"uphappy", NETXEN_NIC_STAT(stats.uphappy)}, | ||
68 | {"updropped", NETXEN_NIC_STAT(stats.updropped)}, | ||
69 | {"uplcong", NETXEN_NIC_STAT(stats.uplcong)}, | ||
70 | {"uphcong", NETXEN_NIC_STAT(stats.uphcong)}, | ||
71 | {"upmcong", NETXEN_NIC_STAT(stats.upmcong)}, | ||
72 | {"updunno", NETXEN_NIC_STAT(stats.updunno)}, | ||
73 | {"skb_freed", NETXEN_NIC_STAT(stats.skbfreed)}, | ||
74 | {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)}, | ||
75 | {"tx_null_skb", NETXEN_NIC_STAT(stats.txnullskb)}, | ||
76 | {"csummed", NETXEN_NIC_STAT(stats.csummed)}, | ||
77 | {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)}, | ||
78 | {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)}, | ||
79 | {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, | ||
80 | }; | ||
81 | |||
82 | #define NETXEN_NIC_STATS_LEN \ | ||
83 | sizeof(netxen_nic_gstrings_stats) / sizeof(struct netxen_nic_stats) | ||
84 | |||
85 | static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { | ||
86 | "Register_Test_offline", "EEPROM_Test_offline", | ||
87 | "Interrupt_Test_offline", "Loopback_Test_offline", | ||
88 | "Link_Test_on_offline" | ||
89 | }; | ||
90 | |||
91 | #define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN | ||
92 | |||
93 | #define NETXEN_NIC_REGS_COUNT 42 | ||
94 | #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32)) | ||
95 | #define NETXEN_MAX_EEPROM_LEN 1024 | ||
96 | |||
97 | static int netxen_nic_get_eeprom_len(struct net_device *dev) | ||
98 | { | ||
99 | struct netxen_port *port = netdev_priv(dev); | ||
100 | struct netxen_adapter *adapter = port->adapter; | ||
101 | int n; | ||
102 | |||
103 | if ((netxen_rom_fast_read(adapter, 0, &n) == 0) | ||
104 | && (n & NETXEN_ROM_ROUNDUP)) { | ||
105 | n &= ~NETXEN_ROM_ROUNDUP; | ||
106 | if (n < NETXEN_MAX_EEPROM_LEN) | ||
107 | return n; | ||
108 | } | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static void | ||
113 | netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) | ||
114 | { | ||
115 | struct netxen_port *port = netdev_priv(dev); | ||
116 | struct netxen_adapter *adapter = port->adapter; | ||
117 | u32 fw_major = 0; | ||
118 | u32 fw_minor = 0; | ||
119 | u32 fw_build = 0; | ||
120 | |||
121 | strncpy(drvinfo->driver, "netxen_nic", 32); | ||
122 | strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32); | ||
123 | fw_major = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
124 | NETXEN_FW_VERSION_MAJOR)); | ||
125 | fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter, | ||
126 | NETXEN_FW_VERSION_MINOR)); | ||
127 | fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB)); | ||
128 | sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build); | ||
129 | |||
130 | strncpy(drvinfo->bus_info, pci_name(port->pdev), 32); | ||
131 | drvinfo->n_stats = NETXEN_NIC_STATS_LEN; | ||
132 | drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN; | ||
133 | drvinfo->regdump_len = NETXEN_NIC_REGS_LEN; | ||
134 | drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev); | ||
135 | } | ||
136 | |||
137 | static int | ||
138 | netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
139 | { | ||
140 | struct netxen_port *port = netdev_priv(dev); | ||
141 | struct netxen_adapter *adapter = port->adapter; | ||
142 | struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg; | ||
143 | |||
144 | /* read which mode */ | ||
145 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
146 | ecmd->supported = (SUPPORTED_10baseT_Half | | ||
147 | SUPPORTED_10baseT_Full | | ||
148 | SUPPORTED_100baseT_Half | | ||
149 | SUPPORTED_100baseT_Full | | ||
150 | SUPPORTED_1000baseT_Half | | ||
151 | SUPPORTED_1000baseT_Full); | ||
152 | |||
153 | ecmd->advertising = (ADVERTISED_100baseT_Half | | ||
154 | ADVERTISED_100baseT_Full | | ||
155 | ADVERTISED_1000baseT_Half | | ||
156 | ADVERTISED_1000baseT_Full); | ||
157 | |||
158 | ecmd->port = PORT_TP; | ||
159 | |||
160 | if (netif_running(dev)) { | ||
161 | ecmd->speed = port->link_speed; | ||
162 | ecmd->duplex = port->link_duplex; | ||
163 | } else | ||
164 | return -EIO; /* link absent */ | ||
165 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
166 | ecmd->supported = (SUPPORTED_TP | | ||
167 | SUPPORTED_1000baseT_Full | | ||
168 | SUPPORTED_10000baseT_Full); | ||
169 | ecmd->advertising = (ADVERTISED_TP | | ||
170 | ADVERTISED_1000baseT_Full | | ||
171 | ADVERTISED_10000baseT_Full); | ||
172 | ecmd->port = PORT_TP; | ||
173 | |||
174 | ecmd->speed = SPEED_10000; | ||
175 | ecmd->duplex = DUPLEX_FULL; | ||
176 | ecmd->autoneg = AUTONEG_DISABLE; | ||
177 | } else | ||
178 | return -EIO; | ||
179 | |||
180 | ecmd->phy_address = port->portnum; | ||
181 | ecmd->transceiver = XCVR_EXTERNAL; | ||
182 | |||
183 | switch ((netxen_brdtype_t) boardinfo->board_type) { | ||
184 | case NETXEN_BRDTYPE_P2_SB35_4G: | ||
185 | case NETXEN_BRDTYPE_P2_SB31_2G: | ||
186 | ecmd->supported |= SUPPORTED_Autoneg; | ||
187 | ecmd->advertising |= ADVERTISED_Autoneg; | ||
188 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | ||
189 | ecmd->supported |= SUPPORTED_TP; | ||
190 | ecmd->advertising |= ADVERTISED_TP; | ||
191 | ecmd->port = PORT_TP; | ||
192 | ecmd->autoneg = (boardinfo->board_type == | ||
193 | NETXEN_BRDTYPE_P2_SB31_10G_CX4) ? | ||
194 | (AUTONEG_DISABLE) : (port->link_autoneg); | ||
195 | break; | ||
196 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | ||
197 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: | ||
198 | ecmd->supported |= SUPPORTED_MII; | ||
199 | ecmd->advertising |= ADVERTISED_MII; | ||
200 | ecmd->port = PORT_FIBRE; | ||
201 | ecmd->autoneg = AUTONEG_DISABLE; | ||
202 | break; | ||
203 | case NETXEN_BRDTYPE_P2_SB31_10G: | ||
204 | ecmd->supported |= SUPPORTED_FIBRE; | ||
205 | ecmd->advertising |= ADVERTISED_FIBRE; | ||
206 | ecmd->port = PORT_FIBRE; | ||
207 | ecmd->autoneg = AUTONEG_DISABLE; | ||
208 | break; | ||
209 | default: | ||
210 | printk(KERN_ERR "netxen-nic: Unsupported board model %d\n", | ||
211 | (netxen_brdtype_t) boardinfo->board_type); | ||
212 | return -EIO; | ||
213 | |||
214 | } | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static int | ||
220 | netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
221 | { | ||
222 | struct netxen_port *port = netdev_priv(dev); | ||
223 | struct netxen_adapter *adapter = port->adapter; | ||
224 | __le32 status; | ||
225 | |||
226 | /* read which mode */ | ||
227 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
228 | /* autonegotiation */ | ||
229 | if (adapter->ops->phy_write | ||
230 | && adapter->ops->phy_write(adapter, port->portnum, | ||
231 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
232 | (__le32) ecmd->autoneg) != 0) | ||
233 | return -EIO; | ||
234 | else | ||
235 | port->link_autoneg = ecmd->autoneg; | ||
236 | |||
237 | if (adapter->ops->phy_read | ||
238 | && adapter->ops->phy_read(adapter, port->portnum, | ||
239 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
240 | &status) != 0) | ||
241 | return -EIO; | ||
242 | |||
243 | /* speed */ | ||
244 | switch (ecmd->speed) { | ||
245 | case SPEED_10: | ||
246 | netxen_set_phy_speed(status, 0); | ||
247 | break; | ||
248 | case SPEED_100: | ||
249 | netxen_set_phy_speed(status, 1); | ||
250 | break; | ||
251 | case SPEED_1000: | ||
252 | netxen_set_phy_speed(status, 2); | ||
253 | break; | ||
254 | } | ||
255 | /* set duplex mode */ | ||
256 | if (ecmd->duplex == DUPLEX_HALF) | ||
257 | netxen_clear_phy_duplex(status); | ||
258 | if (ecmd->duplex == DUPLEX_FULL) | ||
259 | netxen_set_phy_duplex(status); | ||
260 | if (adapter->ops->phy_write | ||
261 | && adapter->ops->phy_write(adapter, port->portnum, | ||
262 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
263 | *((int *)&status)) != 0) | ||
264 | return -EIO; | ||
265 | else { | ||
266 | port->link_speed = ecmd->speed; | ||
267 | port->link_duplex = ecmd->duplex; | ||
268 | } | ||
269 | } else | ||
270 | return -EOPNOTSUPP; | ||
271 | |||
272 | if (netif_running(dev)) { | ||
273 | dev->stop(dev); | ||
274 | dev->open(dev); | ||
275 | } | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | static int netxen_nic_get_regs_len(struct net_device *dev) | ||
280 | { | ||
281 | return NETXEN_NIC_REGS_LEN; | ||
282 | } | ||
283 | |||
284 | struct netxen_niu_regs { | ||
285 | __le32 reg[NETXEN_NIC_REGS_COUNT]; | ||
286 | }; | ||
287 | |||
288 | static struct netxen_niu_regs niu_registers[] = { | ||
289 | { | ||
290 | /* GB Mode */ | ||
291 | { | ||
292 | NETXEN_NIU_GB_SERDES_RESET, | ||
293 | NETXEN_NIU_GB0_MII_MODE, | ||
294 | NETXEN_NIU_GB1_MII_MODE, | ||
295 | NETXEN_NIU_GB2_MII_MODE, | ||
296 | NETXEN_NIU_GB3_MII_MODE, | ||
297 | NETXEN_NIU_GB0_GMII_MODE, | ||
298 | NETXEN_NIU_GB1_GMII_MODE, | ||
299 | NETXEN_NIU_GB2_GMII_MODE, | ||
300 | NETXEN_NIU_GB3_GMII_MODE, | ||
301 | NETXEN_NIU_REMOTE_LOOPBACK, | ||
302 | NETXEN_NIU_GB0_HALF_DUPLEX, | ||
303 | NETXEN_NIU_GB1_HALF_DUPLEX, | ||
304 | NETXEN_NIU_RESET_SYS_FIFOS, | ||
305 | NETXEN_NIU_GB_CRC_DROP, | ||
306 | NETXEN_NIU_GB_DROP_WRONGADDR, | ||
307 | NETXEN_NIU_TEST_MUX_CTL, | ||
308 | |||
309 | NETXEN_NIU_GB_MAC_CONFIG_0(0), | ||
310 | NETXEN_NIU_GB_MAC_CONFIG_1(0), | ||
311 | NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0), | ||
312 | NETXEN_NIU_GB_MAX_FRAME_SIZE(0), | ||
313 | NETXEN_NIU_GB_TEST_REG(0), | ||
314 | NETXEN_NIU_GB_MII_MGMT_CONFIG(0), | ||
315 | NETXEN_NIU_GB_MII_MGMT_COMMAND(0), | ||
316 | NETXEN_NIU_GB_MII_MGMT_ADDR(0), | ||
317 | NETXEN_NIU_GB_MII_MGMT_CTRL(0), | ||
318 | NETXEN_NIU_GB_MII_MGMT_STATUS(0), | ||
319 | NETXEN_NIU_GB_MII_MGMT_INDICATE(0), | ||
320 | NETXEN_NIU_GB_INTERFACE_CTRL(0), | ||
321 | NETXEN_NIU_GB_INTERFACE_STATUS(0), | ||
322 | NETXEN_NIU_GB_STATION_ADDR_0(0), | ||
323 | NETXEN_NIU_GB_STATION_ADDR_1(0), | ||
324 | -1, | ||
325 | } | ||
326 | }, | ||
327 | { | ||
328 | /* XG Mode */ | ||
329 | { | ||
330 | NETXEN_NIU_XG_SINGLE_TERM, | ||
331 | NETXEN_NIU_XG_DRIVE_HI, | ||
332 | NETXEN_NIU_XG_DRIVE_LO, | ||
333 | NETXEN_NIU_XG_DTX, | ||
334 | NETXEN_NIU_XG_DEQ, | ||
335 | NETXEN_NIU_XG_WORD_ALIGN, | ||
336 | NETXEN_NIU_XG_RESET, | ||
337 | NETXEN_NIU_XG_POWER_DOWN, | ||
338 | NETXEN_NIU_XG_RESET_PLL, | ||
339 | NETXEN_NIU_XG_SERDES_LOOPBACK, | ||
340 | NETXEN_NIU_XG_DO_BYTE_ALIGN, | ||
341 | NETXEN_NIU_XG_TX_ENABLE, | ||
342 | NETXEN_NIU_XG_RX_ENABLE, | ||
343 | NETXEN_NIU_XG_STATUS, | ||
344 | NETXEN_NIU_XG_PAUSE_THRESHOLD, | ||
345 | NETXEN_NIU_XGE_CONFIG_0, | ||
346 | NETXEN_NIU_XGE_CONFIG_1, | ||
347 | NETXEN_NIU_XGE_IPG, | ||
348 | NETXEN_NIU_XGE_STATION_ADDR_0_HI, | ||
349 | NETXEN_NIU_XGE_STATION_ADDR_0_1, | ||
350 | NETXEN_NIU_XGE_STATION_ADDR_1_LO, | ||
351 | NETXEN_NIU_XGE_STATUS, | ||
352 | NETXEN_NIU_XGE_MAX_FRAME_SIZE, | ||
353 | NETXEN_NIU_XGE_PAUSE_FRAME_VALUE, | ||
354 | NETXEN_NIU_XGE_TX_BYTE_CNT, | ||
355 | NETXEN_NIU_XGE_TX_FRAME_CNT, | ||
356 | NETXEN_NIU_XGE_RX_BYTE_CNT, | ||
357 | NETXEN_NIU_XGE_RX_FRAME_CNT, | ||
358 | NETXEN_NIU_XGE_AGGR_ERROR_CNT, | ||
359 | NETXEN_NIU_XGE_MULTICAST_FRAME_CNT, | ||
360 | NETXEN_NIU_XGE_UNICAST_FRAME_CNT, | ||
361 | NETXEN_NIU_XGE_CRC_ERROR_CNT, | ||
362 | NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR, | ||
363 | NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR, | ||
364 | NETXEN_NIU_XGE_LOCAL_ERROR_CNT, | ||
365 | NETXEN_NIU_XGE_REMOTE_ERROR_CNT, | ||
366 | NETXEN_NIU_XGE_CONTROL_CHAR_CNT, | ||
367 | NETXEN_NIU_XGE_PAUSE_FRAME_CNT, | ||
368 | -1, | ||
369 | } | ||
370 | } | ||
371 | }; | ||
372 | |||
373 | static void | ||
374 | netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) | ||
375 | { | ||
376 | struct netxen_port *port = netdev_priv(dev); | ||
377 | struct netxen_adapter *adapter = port->adapter; | ||
378 | __le32 mode, *regs_buff = p; | ||
379 | void __iomem *addr; | ||
380 | int i, window; | ||
381 | |||
382 | memset(p, 0, NETXEN_NIC_REGS_LEN); | ||
383 | regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | | ||
384 | (port->pdev)->device; | ||
385 | /* which mode */ | ||
386 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, ®s_buff[0]); | ||
387 | mode = regs_buff[0]; | ||
388 | |||
389 | /* Common registers to all the modes */ | ||
390 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, | ||
391 | ®s_buff[2]); | ||
392 | /* GB/XGB Mode */ | ||
393 | mode = (mode / 2) - 1; | ||
394 | window = 0; | ||
395 | if (mode <= 1) { | ||
396 | for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) { | ||
397 | /* GB: port specific registers */ | ||
398 | if (mode == 0 && i >= 19) | ||
399 | window = port->portnum * NETXEN_NIC_PORT_WINDOW; | ||
400 | |||
401 | NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode]. | ||
402 | reg[i - 3] + window, | ||
403 | ®s_buff[i]); | ||
404 | } | ||
405 | |||
406 | } | ||
407 | } | ||
408 | |||
409 | static void | ||
410 | netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
411 | { | ||
412 | wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC; | ||
413 | /* options can be added depending upon the mode */ | ||
414 | wol->wolopts = 0; | ||
415 | } | ||
416 | |||
417 | static u32 netxen_nic_get_link(struct net_device *dev) | ||
418 | { | ||
419 | struct netxen_port *port = netdev_priv(dev); | ||
420 | struct netxen_adapter *adapter = port->adapter; | ||
421 | __le32 status; | ||
422 | |||
423 | /* read which mode */ | ||
424 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
425 | if (adapter->ops->phy_read | ||
426 | && adapter->ops->phy_read(adapter, port->portnum, | ||
427 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, | ||
428 | &status) != 0) | ||
429 | return -EIO; | ||
430 | else | ||
431 | return (netxen_get_phy_link(status)); | ||
432 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { | ||
433 | int val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); | ||
434 | return val == XG_LINK_UP; | ||
435 | } | ||
436 | return -EIO; | ||
437 | } | ||
438 | |||
439 | static int | ||
440 | netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, | ||
441 | u8 * bytes) | ||
442 | { | ||
443 | struct netxen_port *port = netdev_priv(dev); | ||
444 | struct netxen_adapter *adapter = port->adapter; | ||
445 | int offset; | ||
446 | |||
447 | if (eeprom->len == 0) | ||
448 | return -EINVAL; | ||
449 | |||
450 | eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16); | ||
451 | for (offset = 0; offset < eeprom->len; offset++) | ||
452 | if (netxen_rom_fast_read | ||
453 | (adapter, (8 * offset) + 8, (int *)eeprom->data) == -1) | ||
454 | return -EIO; | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static void | ||
459 | netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) | ||
460 | { | ||
461 | struct netxen_port *port = netdev_priv(dev); | ||
462 | struct netxen_adapter *adapter = port->adapter; | ||
463 | int i, j; | ||
464 | |||
465 | ring->rx_pending = 0; | ||
466 | for (i = 0; i < MAX_RCV_CTX; ++i) { | ||
467 | for (j = 0; j < NUM_RCV_DESC_RINGS; j++) | ||
468 | ring->rx_pending += | ||
469 | adapter->recv_ctx[i].rcv_desc[j].rcv_pending; | ||
470 | } | ||
471 | |||
472 | ring->rx_max_pending = adapter->max_rx_desc_count; | ||
473 | ring->tx_max_pending = adapter->max_tx_desc_count; | ||
474 | ring->rx_mini_max_pending = 0; | ||
475 | ring->rx_mini_pending = 0; | ||
476 | ring->rx_jumbo_max_pending = 0; | ||
477 | ring->rx_jumbo_pending = 0; | ||
478 | } | ||
479 | |||
480 | static void | ||
481 | netxen_nic_get_pauseparam(struct net_device *dev, | ||
482 | struct ethtool_pauseparam *pause) | ||
483 | { | ||
484 | struct netxen_port *port = netdev_priv(dev); | ||
485 | struct netxen_adapter *adapter = port->adapter; | ||
486 | __le32 val; | ||
487 | |||
488 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
489 | /* get flow control settings */ | ||
490 | netxen_nic_read_w0(adapter, | ||
491 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
492 | (u32 *) & val); | ||
493 | pause->rx_pause = netxen_gb_get_rx_flowctl(val); | ||
494 | pause->tx_pause = netxen_gb_get_tx_flowctl(val); | ||
495 | /* get autoneg settings */ | ||
496 | pause->autoneg = port->link_autoneg; | ||
497 | } | ||
498 | } | ||
499 | |||
500 | static int | ||
501 | netxen_nic_set_pauseparam(struct net_device *dev, | ||
502 | struct ethtool_pauseparam *pause) | ||
503 | { | ||
504 | struct netxen_port *port = netdev_priv(dev); | ||
505 | struct netxen_adapter *adapter = port->adapter; | ||
506 | __le32 val; | ||
507 | unsigned int autoneg; | ||
508 | |||
509 | /* read mode */ | ||
510 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { | ||
511 | /* set flow control */ | ||
512 | netxen_nic_read_w0(adapter, | ||
513 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
514 | (u32 *) & val); | ||
515 | if (pause->tx_pause) | ||
516 | netxen_gb_tx_flowctl(val); | ||
517 | else | ||
518 | netxen_gb_unset_tx_flowctl(val); | ||
519 | if (pause->rx_pause) | ||
520 | netxen_gb_rx_flowctl(val); | ||
521 | else | ||
522 | netxen_gb_unset_rx_flowctl(val); | ||
523 | |||
524 | netxen_nic_write_w0(adapter, | ||
525 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), | ||
526 | *(u32 *) (&val)); | ||
527 | /* set autoneg */ | ||
528 | autoneg = pause->autoneg; | ||
529 | if (adapter->ops->phy_write | ||
530 | && adapter->ops->phy_write(adapter, port->portnum, | ||
531 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, | ||
532 | (__le32) autoneg) != 0) | ||
533 | return -EIO; | ||
534 | else { | ||
535 | port->link_autoneg = pause->autoneg; | ||
536 | return 0; | ||
537 | } | ||
538 | } else | ||
539 | return -EOPNOTSUPP; | ||
540 | } | ||
541 | |||
542 | static int netxen_nic_reg_test(struct net_device *dev) | ||
543 | { | ||
544 | struct netxen_port *port = netdev_priv(dev); | ||
545 | struct netxen_adapter *adapter = port->adapter; | ||
546 | u32 data_read, data_written, save; | ||
547 | __le32 mode; | ||
548 | |||
549 | /* | ||
550 | * first test the "Read Only" registers by writing which mode | ||
551 | */ | ||
552 | netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); | ||
553 | if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */ | ||
554 | netxen_nic_read_w0(adapter, | ||
555 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), | ||
556 | &data_read); | ||
557 | |||
558 | save = data_read; | ||
559 | if (data_read) | ||
560 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
561 | else | ||
562 | data_written = NETXEN_NIC_INVALID_DATA; | ||
563 | netxen_nic_write_w0(adapter, | ||
564 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> | ||
565 | portnum), | ||
566 | data_written); | ||
567 | netxen_nic_read_w0(adapter, | ||
568 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), | ||
569 | &data_read); | ||
570 | |||
571 | if (data_written == data_read) { | ||
572 | netxen_nic_write_w0(adapter, | ||
573 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> | ||
574 | portnum), | ||
575 | save); | ||
576 | |||
577 | return 0; | ||
578 | } | ||
579 | |||
580 | /* netxen_niu_gb_mii_mgmt_indicators is read only */ | ||
581 | netxen_nic_read_w0(adapter, | ||
582 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
583 | portnum), | ||
584 | &data_read); | ||
585 | |||
586 | save = data_read; | ||
587 | if (data_read) | ||
588 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
589 | else | ||
590 | data_written = NETXEN_NIC_INVALID_DATA; | ||
591 | netxen_nic_write_w0(adapter, | ||
592 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
593 | portnum), | ||
594 | data_written); | ||
595 | |||
596 | netxen_nic_read_w0(adapter, | ||
597 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> | ||
598 | portnum), | ||
599 | &data_read); | ||
600 | |||
601 | if (data_written == data_read) { | ||
602 | netxen_nic_write_w0(adapter, | ||
603 | NETXEN_NIU_GB_MII_MGMT_INDICATE | ||
604 | (port->portnum), save); | ||
605 | return 0; | ||
606 | } | ||
607 | |||
608 | /* netxen_niu_gb_interface_status is read only */ | ||
609 | netxen_nic_read_w0(adapter, | ||
610 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
611 | portnum), | ||
612 | &data_read); | ||
613 | |||
614 | save = data_read; | ||
615 | if (data_read) | ||
616 | data_written = data_read & NETXEN_NIC_INVALID_DATA; | ||
617 | else | ||
618 | data_written = NETXEN_NIC_INVALID_DATA; | ||
619 | netxen_nic_write_w0(adapter, | ||
620 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
621 | portnum), | ||
622 | data_written); | ||
623 | |||
624 | netxen_nic_read_w0(adapter, | ||
625 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> | ||
626 | portnum), | ||
627 | &data_read); | ||
628 | |||
629 | if (data_written == data_read) { | ||
630 | netxen_nic_write_w0(adapter, | ||
631 | NETXEN_NIU_GB_INTERFACE_STATUS | ||
632 | (port->portnum), save); | ||
633 | |||
634 | return 0; | ||
635 | } | ||
636 | } /* GB Mode */ | ||
637 | return 1; | ||
638 | } | ||
639 | |||
640 | static int netxen_nic_diag_test_count(struct net_device *dev) | ||
641 | { | ||
642 | return NETXEN_NIC_TEST_LEN; | ||
643 | } | ||
644 | |||
645 | static void | ||
646 | netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test, | ||
647 | u64 * data) | ||
648 | { | ||
649 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */ | ||
650 | /* link test */ | ||
651 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) | ||
652 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
653 | |||
654 | if (netif_running(dev)) | ||
655 | dev->stop(dev); | ||
656 | |||
657 | /* register tests */ | ||
658 | if (!(data[0] = netxen_nic_reg_test(dev))) | ||
659 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
660 | /* other tests pass as of now */ | ||
661 | data[1] = data[2] = data[3] = 1; | ||
662 | if (netif_running(dev)) | ||
663 | dev->open(dev); | ||
664 | } else { /* online tests */ | ||
665 | /* link test */ | ||
666 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) | ||
667 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
668 | |||
669 | /* other tests pass by default */ | ||
670 | data[0] = data[1] = data[2] = data[3] = 1; | ||
671 | } | ||
672 | } | ||
673 | |||
674 | static void | ||
675 | netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data) | ||
676 | { | ||
677 | int index; | ||
678 | |||
679 | switch (stringset) { | ||
680 | case ETH_SS_TEST: | ||
681 | memcpy(data, *netxen_nic_gstrings_test, | ||
682 | NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN); | ||
683 | break; | ||
684 | case ETH_SS_STATS: | ||
685 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
686 | memcpy(data + index * ETH_GSTRING_LEN, | ||
687 | netxen_nic_gstrings_stats[index].stat_string, | ||
688 | ETH_GSTRING_LEN); | ||
689 | } | ||
690 | break; | ||
691 | } | ||
692 | } | ||
693 | |||
694 | static int netxen_nic_get_stats_count(struct net_device *dev) | ||
695 | { | ||
696 | return NETXEN_NIC_STATS_LEN; | ||
697 | } | ||
698 | |||
699 | static void | ||
700 | netxen_nic_get_ethtool_stats(struct net_device *dev, | ||
701 | struct ethtool_stats *stats, u64 * data) | ||
702 | { | ||
703 | struct netxen_port *port = netdev_priv(dev); | ||
704 | int index; | ||
705 | |||
706 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { | ||
707 | char *p = | ||
708 | (char *)port + netxen_nic_gstrings_stats[index].stat_offset; | ||
709 | data[index] = | ||
710 | (netxen_nic_gstrings_stats[index].sizeof_stat == | ||
711 | sizeof(u64)) ? *(u64 *) p : *(u32 *) p; | ||
712 | } | ||
713 | |||
714 | } | ||
715 | |||
716 | struct ethtool_ops netxen_nic_ethtool_ops = { | ||
717 | .get_settings = netxen_nic_get_settings, | ||
718 | .set_settings = netxen_nic_set_settings, | ||
719 | .get_drvinfo = netxen_nic_get_drvinfo, | ||
720 | .get_regs_len = netxen_nic_get_regs_len, | ||
721 | .get_regs = netxen_nic_get_regs, | ||
722 | .get_wol = netxen_nic_get_wol, | ||
723 | .get_link = netxen_nic_get_link, | ||
724 | .get_eeprom_len = netxen_nic_get_eeprom_len, | ||
725 | .get_eeprom = netxen_nic_get_eeprom, | ||
726 | .get_ringparam = netxen_nic_get_ringparam, | ||
727 | .get_pauseparam = netxen_nic_get_pauseparam, | ||
728 | .set_pauseparam = netxen_nic_set_pauseparam, | ||
729 | .get_tx_csum = ethtool_op_get_tx_csum, | ||
730 | .set_tx_csum = ethtool_op_set_tx_csum, | ||
731 | .get_sg = ethtool_op_get_sg, | ||
732 | .set_sg = ethtool_op_set_sg, | ||
733 | .get_tso = ethtool_op_get_tso, | ||
734 | .set_tso = ethtool_op_set_tso, | ||
735 | .self_test_count = netxen_nic_diag_test_count, | ||
736 | .self_test = netxen_nic_diag_test, | ||
737 | .get_strings = netxen_nic_get_strings, | ||
738 | .get_stats_count = netxen_nic_get_stats_count, | ||
739 | .get_ethtool_stats = netxen_nic_get_ethtool_stats, | ||
740 | .get_perm_addr = ethtool_op_get_perm_addr, | ||
741 | }; | ||