1d0ae6124SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2aa43c215SJeff Kirsher /*
3aa43c215SJeff Kirsher * Copyright (C) 2003 - 2009 NetXen, Inc.
4aa43c215SJeff Kirsher * Copyright (C) 2009 - QLogic Corporation.
5aa43c215SJeff Kirsher * All rights reserved.
6aa43c215SJeff Kirsher */
7aa43c215SJeff Kirsher
8aa43c215SJeff Kirsher #include <linux/types.h>
9aa43c215SJeff Kirsher #include <linux/delay.h>
10aa43c215SJeff Kirsher #include <linux/pci.h>
11aa43c215SJeff Kirsher #include <asm/io.h>
12aa43c215SJeff Kirsher #include <linux/netdevice.h>
13aa43c215SJeff Kirsher #include <linux/ethtool.h>
14aa43c215SJeff Kirsher
15aa43c215SJeff Kirsher #include "netxen_nic.h"
16aa43c215SJeff Kirsher #include "netxen_nic_hw.h"
17aa43c215SJeff Kirsher
18aa43c215SJeff Kirsher struct netxen_nic_stats {
19aa43c215SJeff Kirsher char stat_string[ETH_GSTRING_LEN];
20aa43c215SJeff Kirsher int sizeof_stat;
21aa43c215SJeff Kirsher int stat_offset;
22aa43c215SJeff Kirsher };
23aa43c215SJeff Kirsher
24aa43c215SJeff Kirsher #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
25aa43c215SJeff Kirsher offsetof(struct netxen_adapter, m)
26aa43c215SJeff Kirsher
27aa43c215SJeff Kirsher #define NETXEN_NIC_PORT_WINDOW 0x10000
28aa43c215SJeff Kirsher #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
29aa43c215SJeff Kirsher
30aa43c215SJeff Kirsher static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
31aa43c215SJeff Kirsher {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
32aa43c215SJeff Kirsher {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
33aa43c215SJeff Kirsher {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
34aa43c215SJeff Kirsher {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
35aa43c215SJeff Kirsher {"csummed", NETXEN_NIC_STAT(stats.csummed)},
36aa43c215SJeff Kirsher {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
37aa43c215SJeff Kirsher {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
38aa43c215SJeff Kirsher {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
39aa43c215SJeff Kirsher {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
40aa43c215SJeff Kirsher };
41aa43c215SJeff Kirsher
42aa43c215SJeff Kirsher #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
43aa43c215SJeff Kirsher
44aa43c215SJeff Kirsher static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
45aa43c215SJeff Kirsher "Register_Test_on_offline",
46aa43c215SJeff Kirsher "Link_Test_on_offline"
47aa43c215SJeff Kirsher };
48aa43c215SJeff Kirsher
49aa43c215SJeff Kirsher #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
50aa43c215SJeff Kirsher
51aa43c215SJeff Kirsher #define NETXEN_NIC_REGS_COUNT 30
52aa43c215SJeff Kirsher #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
53aa43c215SJeff Kirsher #define NETXEN_MAX_EEPROM_LEN 1024
54aa43c215SJeff Kirsher
netxen_nic_get_eeprom_len(struct net_device * dev)55aa43c215SJeff Kirsher static int netxen_nic_get_eeprom_len(struct net_device *dev)
56aa43c215SJeff Kirsher {
57aa43c215SJeff Kirsher return NETXEN_FLASH_TOTAL_SIZE;
58aa43c215SJeff Kirsher }
59aa43c215SJeff Kirsher
60aa43c215SJeff Kirsher static void
netxen_nic_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * drvinfo)61aa43c215SJeff Kirsher netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
62aa43c215SJeff Kirsher {
63aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
64aa43c215SJeff Kirsher u32 fw_major = 0;
65aa43c215SJeff Kirsher u32 fw_minor = 0;
66aa43c215SJeff Kirsher u32 fw_build = 0;
67aa43c215SJeff Kirsher
68*f029c781SWolfram Sang strscpy(drvinfo->driver, netxen_nic_driver_name,
6968aad78cSRick Jones sizeof(drvinfo->driver));
70*f029c781SWolfram Sang strscpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID,
7168aad78cSRick Jones sizeof(drvinfo->version));
72aa43c215SJeff Kirsher fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
73aa43c215SJeff Kirsher fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
74aa43c215SJeff Kirsher fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
7568aad78cSRick Jones snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
7668aad78cSRick Jones "%d.%d.%d", fw_major, fw_minor, fw_build);
77aa43c215SJeff Kirsher
78*f029c781SWolfram Sang strscpy(drvinfo->bus_info, pci_name(adapter->pdev),
7968aad78cSRick Jones sizeof(drvinfo->bus_info));
80aa43c215SJeff Kirsher }
81aa43c215SJeff Kirsher
82aa43c215SJeff Kirsher static int
netxen_nic_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)8399f18f1dSPhilippe Reynes netxen_nic_get_link_ksettings(struct net_device *dev,
8499f18f1dSPhilippe Reynes struct ethtool_link_ksettings *cmd)
85aa43c215SJeff Kirsher {
86aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
87aa43c215SJeff Kirsher int check_sfp_module = 0;
8899f18f1dSPhilippe Reynes u32 supported, advertising;
89aa43c215SJeff Kirsher
90aa43c215SJeff Kirsher /* read which mode */
91aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
9299f18f1dSPhilippe Reynes supported = (SUPPORTED_10baseT_Half |
93aa43c215SJeff Kirsher SUPPORTED_10baseT_Full |
94aa43c215SJeff Kirsher SUPPORTED_100baseT_Half |
95aa43c215SJeff Kirsher SUPPORTED_100baseT_Full |
96aa43c215SJeff Kirsher SUPPORTED_1000baseT_Half |
97aa43c215SJeff Kirsher SUPPORTED_1000baseT_Full);
98aa43c215SJeff Kirsher
9999f18f1dSPhilippe Reynes advertising = (ADVERTISED_100baseT_Half |
100aa43c215SJeff Kirsher ADVERTISED_100baseT_Full |
101aa43c215SJeff Kirsher ADVERTISED_1000baseT_Half |
102aa43c215SJeff Kirsher ADVERTISED_1000baseT_Full);
103aa43c215SJeff Kirsher
10499f18f1dSPhilippe Reynes cmd->base.port = PORT_TP;
105aa43c215SJeff Kirsher
10699f18f1dSPhilippe Reynes cmd->base.speed = adapter->link_speed;
10799f18f1dSPhilippe Reynes cmd->base.duplex = adapter->link_duplex;
10899f18f1dSPhilippe Reynes cmd->base.autoneg = adapter->link_autoneg;
109aa43c215SJeff Kirsher
110aa43c215SJeff Kirsher } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
111aa43c215SJeff Kirsher u32 val;
112aa43c215SJeff Kirsher
113aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
114aa43c215SJeff Kirsher if (val == NETXEN_PORT_MODE_802_3_AP) {
11599f18f1dSPhilippe Reynes supported = SUPPORTED_1000baseT_Full;
11699f18f1dSPhilippe Reynes advertising = ADVERTISED_1000baseT_Full;
117aa43c215SJeff Kirsher } else {
11899f18f1dSPhilippe Reynes supported = SUPPORTED_10000baseT_Full;
11999f18f1dSPhilippe Reynes advertising = ADVERTISED_10000baseT_Full;
120aa43c215SJeff Kirsher }
121aa43c215SJeff Kirsher
122aa43c215SJeff Kirsher if (netif_running(dev) && adapter->has_link_events) {
12399f18f1dSPhilippe Reynes cmd->base.speed = adapter->link_speed;
12499f18f1dSPhilippe Reynes cmd->base.autoneg = adapter->link_autoneg;
12599f18f1dSPhilippe Reynes cmd->base.duplex = adapter->link_duplex;
126aa43c215SJeff Kirsher goto skip;
127aa43c215SJeff Kirsher }
128aa43c215SJeff Kirsher
12999f18f1dSPhilippe Reynes cmd->base.port = PORT_TP;
130aa43c215SJeff Kirsher
131aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
132aa43c215SJeff Kirsher u16 pcifn = adapter->ahw.pci_func;
133aa43c215SJeff Kirsher
134aa43c215SJeff Kirsher val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
13599f18f1dSPhilippe Reynes cmd->base.speed = P3_LINK_SPEED_MHZ *
13699f18f1dSPhilippe Reynes P3_LINK_SPEED_VAL(pcifn, val);
137aa43c215SJeff Kirsher } else
13899f18f1dSPhilippe Reynes cmd->base.speed = SPEED_10000;
139aa43c215SJeff Kirsher
14099f18f1dSPhilippe Reynes cmd->base.duplex = DUPLEX_FULL;
14199f18f1dSPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
142aa43c215SJeff Kirsher } else
143aa43c215SJeff Kirsher return -EIO;
144aa43c215SJeff Kirsher
145aa43c215SJeff Kirsher skip:
14699f18f1dSPhilippe Reynes cmd->base.phy_address = adapter->physical_port;
147aa43c215SJeff Kirsher
148aa43c215SJeff Kirsher switch (adapter->ahw.board_type) {
149aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB35_4G:
150aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_2G:
151aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_REF_QG:
152aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_4_GB:
153aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_4_GB_MM:
15499f18f1dSPhilippe Reynes supported |= SUPPORTED_Autoneg;
15599f18f1dSPhilippe Reynes advertising |= ADVERTISED_Autoneg;
156df561f66SGustavo A. R. Silva fallthrough;
157aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
158aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_CX4:
159aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_CX4_LP:
160aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10000_BASE_T:
16199f18f1dSPhilippe Reynes supported |= SUPPORTED_TP;
16299f18f1dSPhilippe Reynes advertising |= ADVERTISED_TP;
16399f18f1dSPhilippe Reynes cmd->base.port = PORT_TP;
16499f18f1dSPhilippe Reynes cmd->base.autoneg = (adapter->ahw.board_type ==
165aa43c215SJeff Kirsher NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
166aa43c215SJeff Kirsher (AUTONEG_DISABLE) : (adapter->link_autoneg);
167aa43c215SJeff Kirsher break;
168aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
169aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
170aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_IMEZ:
171aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_XG_LOM:
172aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_HMEZ:
17399f18f1dSPhilippe Reynes supported |= SUPPORTED_MII;
17499f18f1dSPhilippe Reynes advertising |= ADVERTISED_MII;
17599f18f1dSPhilippe Reynes cmd->base.port = PORT_MII;
17699f18f1dSPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
177aa43c215SJeff Kirsher break;
178aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
179aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_CT:
180aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_QT:
18199f18f1dSPhilippe Reynes advertising |= ADVERTISED_TP;
18299f18f1dSPhilippe Reynes supported |= SUPPORTED_TP;
183aa43c215SJeff Kirsher check_sfp_module = netif_running(dev) &&
184aa43c215SJeff Kirsher adapter->has_link_events;
185df561f66SGustavo A. R. Silva fallthrough;
186aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G:
187aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_XFP:
18899f18f1dSPhilippe Reynes supported |= SUPPORTED_FIBRE;
18999f18f1dSPhilippe Reynes advertising |= ADVERTISED_FIBRE;
19099f18f1dSPhilippe Reynes cmd->base.port = PORT_FIBRE;
19199f18f1dSPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
192aa43c215SJeff Kirsher break;
193aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_TP:
194aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
19599f18f1dSPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
19699f18f1dSPhilippe Reynes supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
19799f18f1dSPhilippe Reynes advertising |=
198aa43c215SJeff Kirsher (ADVERTISED_FIBRE | ADVERTISED_TP);
19999f18f1dSPhilippe Reynes cmd->base.port = PORT_FIBRE;
200aa43c215SJeff Kirsher check_sfp_module = netif_running(dev) &&
201aa43c215SJeff Kirsher adapter->has_link_events;
202aa43c215SJeff Kirsher } else {
20399f18f1dSPhilippe Reynes supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
20499f18f1dSPhilippe Reynes advertising |=
205aa43c215SJeff Kirsher (ADVERTISED_TP | ADVERTISED_Autoneg);
20699f18f1dSPhilippe Reynes cmd->base.port = PORT_TP;
207aa43c215SJeff Kirsher }
208aa43c215SJeff Kirsher break;
209aa43c215SJeff Kirsher default:
210aa43c215SJeff Kirsher printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
211aa43c215SJeff Kirsher adapter->ahw.board_type);
212aa43c215SJeff Kirsher return -EIO;
213aa43c215SJeff Kirsher }
214aa43c215SJeff Kirsher
215aa43c215SJeff Kirsher if (check_sfp_module) {
216aa43c215SJeff Kirsher switch (adapter->module_type) {
217aa43c215SJeff Kirsher case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
218aa43c215SJeff Kirsher case LINKEVENT_MODULE_OPTICAL_SRLR:
219aa43c215SJeff Kirsher case LINKEVENT_MODULE_OPTICAL_LRM:
220aa43c215SJeff Kirsher case LINKEVENT_MODULE_OPTICAL_SFP_1G:
22199f18f1dSPhilippe Reynes cmd->base.port = PORT_FIBRE;
222aa43c215SJeff Kirsher break;
223aa43c215SJeff Kirsher case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
224aa43c215SJeff Kirsher case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
225aa43c215SJeff Kirsher case LINKEVENT_MODULE_TWINAX:
22699f18f1dSPhilippe Reynes cmd->base.port = PORT_TP;
227aa43c215SJeff Kirsher break;
228aa43c215SJeff Kirsher default:
22999f18f1dSPhilippe Reynes cmd->base.port = -1;
230aa43c215SJeff Kirsher }
231aa43c215SJeff Kirsher }
232aa43c215SJeff Kirsher
23334d6fde1SSony Chacko if (!netif_running(dev) || !adapter->ahw.linkup) {
23499f18f1dSPhilippe Reynes cmd->base.duplex = DUPLEX_UNKNOWN;
23599f18f1dSPhilippe Reynes cmd->base.speed = SPEED_UNKNOWN;
23634d6fde1SSony Chacko }
23734d6fde1SSony Chacko
23899f18f1dSPhilippe Reynes ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
23999f18f1dSPhilippe Reynes supported);
24099f18f1dSPhilippe Reynes ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
24199f18f1dSPhilippe Reynes advertising);
24299f18f1dSPhilippe Reynes
243aa43c215SJeff Kirsher return 0;
244aa43c215SJeff Kirsher }
245aa43c215SJeff Kirsher
246aa43c215SJeff Kirsher static int
netxen_nic_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)24799f18f1dSPhilippe Reynes netxen_nic_set_link_ksettings(struct net_device *dev,
24899f18f1dSPhilippe Reynes const struct ethtool_link_ksettings *cmd)
249aa43c215SJeff Kirsher {
250aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
25199f18f1dSPhilippe Reynes u32 speed = cmd->base.speed;
252aa43c215SJeff Kirsher int ret;
253aa43c215SJeff Kirsher
254aa43c215SJeff Kirsher if (adapter->ahw.port_type != NETXEN_NIC_GBE)
255aa43c215SJeff Kirsher return -EOPNOTSUPP;
256aa43c215SJeff Kirsher
257aa43c215SJeff Kirsher if (!(adapter->capabilities & NX_FW_CAPABILITY_GBE_LINK_CFG))
258aa43c215SJeff Kirsher return -EOPNOTSUPP;
259aa43c215SJeff Kirsher
26099f18f1dSPhilippe Reynes ret = nx_fw_cmd_set_gbe_port(adapter, speed, cmd->base.duplex,
26199f18f1dSPhilippe Reynes cmd->base.autoneg);
262aa43c215SJeff Kirsher if (ret == NX_RCODE_NOT_SUPPORTED)
263aa43c215SJeff Kirsher return -EOPNOTSUPP;
264aa43c215SJeff Kirsher else if (ret)
265aa43c215SJeff Kirsher return -EIO;
266aa43c215SJeff Kirsher
267aa43c215SJeff Kirsher adapter->link_speed = speed;
26899f18f1dSPhilippe Reynes adapter->link_duplex = cmd->base.duplex;
26999f18f1dSPhilippe Reynes adapter->link_autoneg = cmd->base.autoneg;
270aa43c215SJeff Kirsher
271aa43c215SJeff Kirsher if (!netif_running(dev))
272aa43c215SJeff Kirsher return 0;
273aa43c215SJeff Kirsher
274aa43c215SJeff Kirsher dev->netdev_ops->ndo_stop(dev);
275aa43c215SJeff Kirsher return dev->netdev_ops->ndo_open(dev);
276aa43c215SJeff Kirsher }
277aa43c215SJeff Kirsher
netxen_nic_get_regs_len(struct net_device * dev)278aa43c215SJeff Kirsher static int netxen_nic_get_regs_len(struct net_device *dev)
279aa43c215SJeff Kirsher {
280aa43c215SJeff Kirsher return NETXEN_NIC_REGS_LEN;
281aa43c215SJeff Kirsher }
282aa43c215SJeff Kirsher
283aa43c215SJeff Kirsher static void
netxen_nic_get_regs(struct net_device * dev,struct ethtool_regs * regs,void * p)284aa43c215SJeff Kirsher netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
285aa43c215SJeff Kirsher {
286aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
287aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
288aa43c215SJeff Kirsher struct nx_host_sds_ring *sds_ring;
289aa43c215SJeff Kirsher u32 *regs_buff = p;
290aa43c215SJeff Kirsher int ring, i = 0;
291aa43c215SJeff Kirsher int port = adapter->physical_port;
292aa43c215SJeff Kirsher
293aa43c215SJeff Kirsher memset(p, 0, NETXEN_NIC_REGS_LEN);
294aa43c215SJeff Kirsher
295aa43c215SJeff Kirsher regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
296aa43c215SJeff Kirsher (adapter->pdev)->device;
297aa43c215SJeff Kirsher
298aa43c215SJeff Kirsher if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
299aa43c215SJeff Kirsher return;
300aa43c215SJeff Kirsher
301aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE);
302aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE);
303aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
304aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg);
305aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
306aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE);
307aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
308aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
309aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2);
310aa43c215SJeff Kirsher
311aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c);
312aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c);
313aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c);
314aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c);
315aa43c215SJeff Kirsher
316aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
317aa43c215SJeff Kirsher
318aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c);
319aa43c215SJeff Kirsher i += 2;
320aa43c215SJeff Kirsher
321aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3);
322aa43c215SJeff Kirsher regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer));
323aa43c215SJeff Kirsher
324aa43c215SJeff Kirsher } else {
325aa43c215SJeff Kirsher i++;
326aa43c215SJeff Kirsher
327aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter,
328aa43c215SJeff Kirsher NETXEN_NIU_XGE_CONFIG_0+(0x10000*port));
329aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter,
330aa43c215SJeff Kirsher NETXEN_NIU_XGE_CONFIG_1+(0x10000*port));
331aa43c215SJeff Kirsher
332aa43c215SJeff Kirsher regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE);
333aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter,
334aa43c215SJeff Kirsher adapter->tx_ring->crb_cmd_consumer);
335aa43c215SJeff Kirsher }
336aa43c215SJeff Kirsher
337aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer);
338aa43c215SJeff Kirsher
339aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter,
340aa43c215SJeff Kirsher recv_ctx->rds_rings[0].crb_rcv_producer);
341aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter,
342aa43c215SJeff Kirsher recv_ctx->rds_rings[1].crb_rcv_producer);
343aa43c215SJeff Kirsher
344aa43c215SJeff Kirsher regs_buff[i++] = adapter->max_sds_rings;
345aa43c215SJeff Kirsher
346aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) {
347aa43c215SJeff Kirsher sds_ring = &(recv_ctx->sds_rings[ring]);
348aa43c215SJeff Kirsher regs_buff[i++] = NXRDIO(adapter,
349aa43c215SJeff Kirsher sds_ring->crb_sts_consumer);
350aa43c215SJeff Kirsher }
351aa43c215SJeff Kirsher }
352aa43c215SJeff Kirsher
netxen_nic_test_link(struct net_device * dev)353aa43c215SJeff Kirsher static u32 netxen_nic_test_link(struct net_device *dev)
354aa43c215SJeff Kirsher {
355aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
356aa43c215SJeff Kirsher u32 val, port;
357aa43c215SJeff Kirsher
358aa43c215SJeff Kirsher port = adapter->physical_port;
359aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
360aa43c215SJeff Kirsher val = NXRD32(adapter, CRB_XG_STATE_P3);
361aa43c215SJeff Kirsher val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
362aa43c215SJeff Kirsher return (val == XG_LINK_UP_P3) ? 0 : 1;
363aa43c215SJeff Kirsher } else {
364aa43c215SJeff Kirsher val = NXRD32(adapter, CRB_XG_STATE);
365aa43c215SJeff Kirsher val = (val >> port*8) & 0xff;
366aa43c215SJeff Kirsher return (val == XG_LINK_UP) ? 0 : 1;
367aa43c215SJeff Kirsher }
368aa43c215SJeff Kirsher }
369aa43c215SJeff Kirsher
370aa43c215SJeff Kirsher static int
netxen_nic_get_eeprom(struct net_device * dev,struct ethtool_eeprom * eeprom,u8 * bytes)371aa43c215SJeff Kirsher netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
372aa43c215SJeff Kirsher u8 *bytes)
373aa43c215SJeff Kirsher {
374aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
375aa43c215SJeff Kirsher int offset;
376aa43c215SJeff Kirsher int ret;
377aa43c215SJeff Kirsher
378aa43c215SJeff Kirsher if (eeprom->len == 0)
379aa43c215SJeff Kirsher return -EINVAL;
380aa43c215SJeff Kirsher
381aa43c215SJeff Kirsher eeprom->magic = (adapter->pdev)->vendor |
382aa43c215SJeff Kirsher ((adapter->pdev)->device << 16);
383aa43c215SJeff Kirsher offset = eeprom->offset;
384aa43c215SJeff Kirsher
385aa43c215SJeff Kirsher ret = netxen_rom_fast_read_words(adapter, offset, bytes,
386aa43c215SJeff Kirsher eeprom->len);
387aa43c215SJeff Kirsher if (ret < 0)
388aa43c215SJeff Kirsher return ret;
389aa43c215SJeff Kirsher
390aa43c215SJeff Kirsher return 0;
391aa43c215SJeff Kirsher }
392aa43c215SJeff Kirsher
393aa43c215SJeff Kirsher static void
netxen_nic_get_ringparam(struct net_device * dev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)394aa43c215SJeff Kirsher netxen_nic_get_ringparam(struct net_device *dev,
39574624944SHao Chen struct ethtool_ringparam *ring,
39674624944SHao Chen struct kernel_ethtool_ringparam *kernel_ring,
39774624944SHao Chen struct netlink_ext_ack *extack)
398aa43c215SJeff Kirsher {
399aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
400aa43c215SJeff Kirsher
401aa43c215SJeff Kirsher ring->rx_pending = adapter->num_rxd;
402aa43c215SJeff Kirsher ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
403aa43c215SJeff Kirsher ring->rx_jumbo_pending += adapter->num_lro_rxd;
404aa43c215SJeff Kirsher ring->tx_pending = adapter->num_txd;
405aa43c215SJeff Kirsher
406aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
407aa43c215SJeff Kirsher ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
408aa43c215SJeff Kirsher ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
409aa43c215SJeff Kirsher } else {
410aa43c215SJeff Kirsher ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
411aa43c215SJeff Kirsher ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
412aa43c215SJeff Kirsher }
413aa43c215SJeff Kirsher
414aa43c215SJeff Kirsher ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
415aa43c215SJeff Kirsher }
416aa43c215SJeff Kirsher
417aa43c215SJeff Kirsher static u32
netxen_validate_ringparam(u32 val,u32 min,u32 max,char * r_name)418aa43c215SJeff Kirsher netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
419aa43c215SJeff Kirsher {
420aa43c215SJeff Kirsher u32 num_desc;
421aa43c215SJeff Kirsher num_desc = max(val, min);
422aa43c215SJeff Kirsher num_desc = min(num_desc, max);
423aa43c215SJeff Kirsher num_desc = roundup_pow_of_two(num_desc);
424aa43c215SJeff Kirsher
425aa43c215SJeff Kirsher if (val != num_desc) {
426aa43c215SJeff Kirsher printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
427aa43c215SJeff Kirsher netxen_nic_driver_name, r_name, num_desc, val);
428aa43c215SJeff Kirsher }
429aa43c215SJeff Kirsher
430aa43c215SJeff Kirsher return num_desc;
431aa43c215SJeff Kirsher }
432aa43c215SJeff Kirsher
433aa43c215SJeff Kirsher static int
netxen_nic_set_ringparam(struct net_device * dev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)434aa43c215SJeff Kirsher netxen_nic_set_ringparam(struct net_device *dev,
43574624944SHao Chen struct ethtool_ringparam *ring,
43674624944SHao Chen struct kernel_ethtool_ringparam *kernel_ring,
43774624944SHao Chen struct netlink_ext_ack *extack)
438aa43c215SJeff Kirsher {
439aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
440aa43c215SJeff Kirsher u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
441aa43c215SJeff Kirsher u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
442aa43c215SJeff Kirsher u16 num_rxd, num_jumbo_rxd, num_txd;
443aa43c215SJeff Kirsher
444aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
445aa43c215SJeff Kirsher return -EOPNOTSUPP;
446aa43c215SJeff Kirsher
447aa43c215SJeff Kirsher if (ring->rx_mini_pending)
448aa43c215SJeff Kirsher return -EOPNOTSUPP;
449aa43c215SJeff Kirsher
450aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
451aa43c215SJeff Kirsher max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
452aa43c215SJeff Kirsher max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
453aa43c215SJeff Kirsher }
454aa43c215SJeff Kirsher
455aa43c215SJeff Kirsher num_rxd = netxen_validate_ringparam(ring->rx_pending,
456aa43c215SJeff Kirsher MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
457aa43c215SJeff Kirsher
458aa43c215SJeff Kirsher num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
459aa43c215SJeff Kirsher MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
460aa43c215SJeff Kirsher
461aa43c215SJeff Kirsher num_txd = netxen_validate_ringparam(ring->tx_pending,
462aa43c215SJeff Kirsher MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
463aa43c215SJeff Kirsher
464aa43c215SJeff Kirsher if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
465aa43c215SJeff Kirsher num_jumbo_rxd == adapter->num_jumbo_rxd)
466aa43c215SJeff Kirsher return 0;
467aa43c215SJeff Kirsher
468aa43c215SJeff Kirsher adapter->num_rxd = num_rxd;
469aa43c215SJeff Kirsher adapter->num_jumbo_rxd = num_jumbo_rxd;
470aa43c215SJeff Kirsher adapter->num_txd = num_txd;
471aa43c215SJeff Kirsher
472aa43c215SJeff Kirsher return netxen_nic_reset_context(adapter);
473aa43c215SJeff Kirsher }
474aa43c215SJeff Kirsher
475aa43c215SJeff Kirsher static void
netxen_nic_get_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)476aa43c215SJeff Kirsher netxen_nic_get_pauseparam(struct net_device *dev,
477aa43c215SJeff Kirsher struct ethtool_pauseparam *pause)
478aa43c215SJeff Kirsher {
479aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
480aa43c215SJeff Kirsher __u32 val;
481aa43c215SJeff Kirsher int port = adapter->physical_port;
482aa43c215SJeff Kirsher
48315111025SFlavio Leitner pause->autoneg = 0;
48415111025SFlavio Leitner
485aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
486d8140b2fSSantosh Nayak if ((port < 0) || (port >= NETXEN_NIU_MAX_GBE_PORTS))
487aa43c215SJeff Kirsher return;
488aa43c215SJeff Kirsher /* get flow control settings */
489aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
490aa43c215SJeff Kirsher pause->rx_pause = netxen_gb_get_rx_flowctl(val);
491aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
492aa43c215SJeff Kirsher switch (port) {
493aa43c215SJeff Kirsher case 0:
494aa43c215SJeff Kirsher pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
495aa43c215SJeff Kirsher break;
496aa43c215SJeff Kirsher case 1:
497aa43c215SJeff Kirsher pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
498aa43c215SJeff Kirsher break;
499aa43c215SJeff Kirsher case 2:
500aa43c215SJeff Kirsher pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
501aa43c215SJeff Kirsher break;
502aa43c215SJeff Kirsher case 3:
503aa43c215SJeff Kirsher default:
504aa43c215SJeff Kirsher pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
505aa43c215SJeff Kirsher break;
506aa43c215SJeff Kirsher }
507aa43c215SJeff Kirsher } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
508ed3b856bSSantosh Nayak if ((port < 0) || (port >= NETXEN_NIU_MAX_XG_PORTS))
509aa43c215SJeff Kirsher return;
510aa43c215SJeff Kirsher pause->rx_pause = 1;
511aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
512aa43c215SJeff Kirsher if (port == 0)
513aa43c215SJeff Kirsher pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
514aa43c215SJeff Kirsher else
515aa43c215SJeff Kirsher pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
516aa43c215SJeff Kirsher } else {
517aa43c215SJeff Kirsher printk(KERN_ERR"%s: Unknown board type: %x\n",
518aa43c215SJeff Kirsher netxen_nic_driver_name, adapter->ahw.port_type);
519aa43c215SJeff Kirsher }
520aa43c215SJeff Kirsher }
521aa43c215SJeff Kirsher
522aa43c215SJeff Kirsher static int
netxen_nic_set_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)523aa43c215SJeff Kirsher netxen_nic_set_pauseparam(struct net_device *dev,
524aa43c215SJeff Kirsher struct ethtool_pauseparam *pause)
525aa43c215SJeff Kirsher {
526aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
527aa43c215SJeff Kirsher __u32 val;
528aa43c215SJeff Kirsher int port = adapter->physical_port;
52915111025SFlavio Leitner
53015111025SFlavio Leitner /* not supported */
53115111025SFlavio Leitner if (pause->autoneg)
53215111025SFlavio Leitner return -EINVAL;
53315111025SFlavio Leitner
534aa43c215SJeff Kirsher /* read mode */
535aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
536d8140b2fSSantosh Nayak if ((port < 0) || (port >= NETXEN_NIU_MAX_GBE_PORTS))
537aa43c215SJeff Kirsher return -EIO;
538aa43c215SJeff Kirsher /* set flow control */
539aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
540aa43c215SJeff Kirsher
541aa43c215SJeff Kirsher if (pause->rx_pause)
542aa43c215SJeff Kirsher netxen_gb_rx_flowctl(val);
543aa43c215SJeff Kirsher else
544aa43c215SJeff Kirsher netxen_gb_unset_rx_flowctl(val);
545aa43c215SJeff Kirsher
546aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
547aa43c215SJeff Kirsher val);
548aa43c215SJeff Kirsher /* set autoneg */
549aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
550aa43c215SJeff Kirsher switch (port) {
551aa43c215SJeff Kirsher case 0:
552aa43c215SJeff Kirsher if (pause->tx_pause)
553aa43c215SJeff Kirsher netxen_gb_unset_gb0_mask(val);
554aa43c215SJeff Kirsher else
555aa43c215SJeff Kirsher netxen_gb_set_gb0_mask(val);
556aa43c215SJeff Kirsher break;
557aa43c215SJeff Kirsher case 1:
558aa43c215SJeff Kirsher if (pause->tx_pause)
559aa43c215SJeff Kirsher netxen_gb_unset_gb1_mask(val);
560aa43c215SJeff Kirsher else
561aa43c215SJeff Kirsher netxen_gb_set_gb1_mask(val);
562aa43c215SJeff Kirsher break;
563aa43c215SJeff Kirsher case 2:
564aa43c215SJeff Kirsher if (pause->tx_pause)
565aa43c215SJeff Kirsher netxen_gb_unset_gb2_mask(val);
566aa43c215SJeff Kirsher else
567aa43c215SJeff Kirsher netxen_gb_set_gb2_mask(val);
568aa43c215SJeff Kirsher break;
569aa43c215SJeff Kirsher case 3:
570aa43c215SJeff Kirsher default:
571aa43c215SJeff Kirsher if (pause->tx_pause)
572aa43c215SJeff Kirsher netxen_gb_unset_gb3_mask(val);
573aa43c215SJeff Kirsher else
574aa43c215SJeff Kirsher netxen_gb_set_gb3_mask(val);
575aa43c215SJeff Kirsher break;
576aa43c215SJeff Kirsher }
577aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
578aa43c215SJeff Kirsher } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
579ed3b856bSSantosh Nayak if ((port < 0) || (port >= NETXEN_NIU_MAX_XG_PORTS))
580aa43c215SJeff Kirsher return -EIO;
581aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
582aa43c215SJeff Kirsher if (port == 0) {
583aa43c215SJeff Kirsher if (pause->tx_pause)
584aa43c215SJeff Kirsher netxen_xg_unset_xg0_mask(val);
585aa43c215SJeff Kirsher else
586aa43c215SJeff Kirsher netxen_xg_set_xg0_mask(val);
587aa43c215SJeff Kirsher } else {
588aa43c215SJeff Kirsher if (pause->tx_pause)
589aa43c215SJeff Kirsher netxen_xg_unset_xg1_mask(val);
590aa43c215SJeff Kirsher else
591aa43c215SJeff Kirsher netxen_xg_set_xg1_mask(val);
592aa43c215SJeff Kirsher }
593aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
594aa43c215SJeff Kirsher } else {
595aa43c215SJeff Kirsher printk(KERN_ERR "%s: Unknown board type: %x\n",
596aa43c215SJeff Kirsher netxen_nic_driver_name,
597aa43c215SJeff Kirsher adapter->ahw.port_type);
598aa43c215SJeff Kirsher }
599aa43c215SJeff Kirsher return 0;
600aa43c215SJeff Kirsher }
601aa43c215SJeff Kirsher
netxen_nic_reg_test(struct net_device * dev)602aa43c215SJeff Kirsher static int netxen_nic_reg_test(struct net_device *dev)
603aa43c215SJeff Kirsher {
604aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
605aa43c215SJeff Kirsher u32 data_read, data_written;
606aa43c215SJeff Kirsher
607aa43c215SJeff Kirsher data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
608aa43c215SJeff Kirsher if ((data_read & 0xffff) != adapter->pdev->vendor)
609aa43c215SJeff Kirsher return 1;
610aa43c215SJeff Kirsher
611aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
612aa43c215SJeff Kirsher return 0;
613aa43c215SJeff Kirsher
614aa43c215SJeff Kirsher data_written = (u32)0xa5a5a5a5;
615aa43c215SJeff Kirsher
616aa43c215SJeff Kirsher NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
617aa43c215SJeff Kirsher data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
618aa43c215SJeff Kirsher if (data_written != data_read)
619aa43c215SJeff Kirsher return 1;
620aa43c215SJeff Kirsher
621aa43c215SJeff Kirsher return 0;
622aa43c215SJeff Kirsher }
623aa43c215SJeff Kirsher
netxen_get_sset_count(struct net_device * dev,int sset)624aa43c215SJeff Kirsher static int netxen_get_sset_count(struct net_device *dev, int sset)
625aa43c215SJeff Kirsher {
626aa43c215SJeff Kirsher switch (sset) {
627aa43c215SJeff Kirsher case ETH_SS_TEST:
628aa43c215SJeff Kirsher return NETXEN_NIC_TEST_LEN;
629aa43c215SJeff Kirsher case ETH_SS_STATS:
630aa43c215SJeff Kirsher return NETXEN_NIC_STATS_LEN;
631aa43c215SJeff Kirsher default:
632aa43c215SJeff Kirsher return -EOPNOTSUPP;
633aa43c215SJeff Kirsher }
634aa43c215SJeff Kirsher }
635aa43c215SJeff Kirsher
636aa43c215SJeff Kirsher static void
netxen_nic_diag_test(struct net_device * dev,struct ethtool_test * eth_test,u64 * data)637aa43c215SJeff Kirsher netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
638aa43c215SJeff Kirsher u64 *data)
639aa43c215SJeff Kirsher {
640aa43c215SJeff Kirsher memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
641aa43c215SJeff Kirsher if ((data[0] = netxen_nic_reg_test(dev)))
642aa43c215SJeff Kirsher eth_test->flags |= ETH_TEST_FL_FAILED;
643aa43c215SJeff Kirsher /* link test */
644aa43c215SJeff Kirsher if ((data[1] = (u64) netxen_nic_test_link(dev)))
645aa43c215SJeff Kirsher eth_test->flags |= ETH_TEST_FL_FAILED;
646aa43c215SJeff Kirsher }
647aa43c215SJeff Kirsher
648aa43c215SJeff Kirsher static void
netxen_nic_get_strings(struct net_device * dev,u32 stringset,u8 * data)649aa43c215SJeff Kirsher netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
650aa43c215SJeff Kirsher {
651aa43c215SJeff Kirsher int index;
652aa43c215SJeff Kirsher
653aa43c215SJeff Kirsher switch (stringset) {
654aa43c215SJeff Kirsher case ETH_SS_TEST:
655aa43c215SJeff Kirsher memcpy(data, *netxen_nic_gstrings_test,
656aa43c215SJeff Kirsher NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
657aa43c215SJeff Kirsher break;
658aa43c215SJeff Kirsher case ETH_SS_STATS:
659aa43c215SJeff Kirsher for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
660aa43c215SJeff Kirsher memcpy(data + index * ETH_GSTRING_LEN,
661aa43c215SJeff Kirsher netxen_nic_gstrings_stats[index].stat_string,
662aa43c215SJeff Kirsher ETH_GSTRING_LEN);
663aa43c215SJeff Kirsher }
664aa43c215SJeff Kirsher break;
665aa43c215SJeff Kirsher }
666aa43c215SJeff Kirsher }
667aa43c215SJeff Kirsher
668aa43c215SJeff Kirsher static void
netxen_nic_get_ethtool_stats(struct net_device * dev,struct ethtool_stats * stats,u64 * data)669aa43c215SJeff Kirsher netxen_nic_get_ethtool_stats(struct net_device *dev,
670aa43c215SJeff Kirsher struct ethtool_stats *stats, u64 *data)
671aa43c215SJeff Kirsher {
672aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
673aa43c215SJeff Kirsher int index;
674aa43c215SJeff Kirsher
675aa43c215SJeff Kirsher for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
676aa43c215SJeff Kirsher char *p =
677aa43c215SJeff Kirsher (char *)adapter +
678aa43c215SJeff Kirsher netxen_nic_gstrings_stats[index].stat_offset;
679aa43c215SJeff Kirsher data[index] =
680aa43c215SJeff Kirsher (netxen_nic_gstrings_stats[index].sizeof_stat ==
681aa43c215SJeff Kirsher sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
682aa43c215SJeff Kirsher }
683aa43c215SJeff Kirsher }
684aa43c215SJeff Kirsher
685aa43c215SJeff Kirsher static void
netxen_nic_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)686aa43c215SJeff Kirsher netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
687aa43c215SJeff Kirsher {
688aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
689aa43c215SJeff Kirsher u32 wol_cfg = 0;
690aa43c215SJeff Kirsher
691aa43c215SJeff Kirsher wol->supported = 0;
692aa43c215SJeff Kirsher wol->wolopts = 0;
693aa43c215SJeff Kirsher
694aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
695aa43c215SJeff Kirsher return;
696aa43c215SJeff Kirsher
697aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
698aa43c215SJeff Kirsher if (wol_cfg & (1UL << adapter->portnum))
699aa43c215SJeff Kirsher wol->supported |= WAKE_MAGIC;
700aa43c215SJeff Kirsher
701aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
702aa43c215SJeff Kirsher if (wol_cfg & (1UL << adapter->portnum))
703aa43c215SJeff Kirsher wol->wolopts |= WAKE_MAGIC;
704aa43c215SJeff Kirsher }
705aa43c215SJeff Kirsher
706aa43c215SJeff Kirsher static int
netxen_nic_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)707aa43c215SJeff Kirsher netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
708aa43c215SJeff Kirsher {
709aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(dev);
710aa43c215SJeff Kirsher u32 wol_cfg = 0;
711aa43c215SJeff Kirsher
712aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
713aa43c215SJeff Kirsher return -EOPNOTSUPP;
714aa43c215SJeff Kirsher
715aa43c215SJeff Kirsher if (wol->wolopts & ~WAKE_MAGIC)
716aa43c215SJeff Kirsher return -EOPNOTSUPP;
717aa43c215SJeff Kirsher
718aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
719aa43c215SJeff Kirsher if (!(wol_cfg & (1 << adapter->portnum)))
720aa43c215SJeff Kirsher return -EOPNOTSUPP;
721aa43c215SJeff Kirsher
722aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
723aa43c215SJeff Kirsher if (wol->wolopts & WAKE_MAGIC)
724aa43c215SJeff Kirsher wol_cfg |= 1UL << adapter->portnum;
725aa43c215SJeff Kirsher else
726aa43c215SJeff Kirsher wol_cfg &= ~(1UL << adapter->portnum);
727aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
728aa43c215SJeff Kirsher
729aa43c215SJeff Kirsher return 0;
730aa43c215SJeff Kirsher }
731aa43c215SJeff Kirsher
732aa43c215SJeff Kirsher /*
733aa43c215SJeff Kirsher * Set the coalescing parameters. Currently only normal is supported.
734aa43c215SJeff Kirsher * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
735aa43c215SJeff Kirsher * firmware coalescing to default.
736aa43c215SJeff Kirsher */
netxen_set_intr_coalesce(struct net_device * netdev,struct ethtool_coalesce * ethcoal,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)737aa43c215SJeff Kirsher static int netxen_set_intr_coalesce(struct net_device *netdev,
738f3ccfda1SYufeng Mo struct ethtool_coalesce *ethcoal,
739f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
740f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
741aa43c215SJeff Kirsher {
742aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(netdev);
743aa43c215SJeff Kirsher
744aa43c215SJeff Kirsher if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
745aa43c215SJeff Kirsher return -EINVAL;
746aa43c215SJeff Kirsher
747aa43c215SJeff Kirsher if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
748aa43c215SJeff Kirsher return -EINVAL;
749aa43c215SJeff Kirsher
750aa43c215SJeff Kirsher /*
751aa43c215SJeff Kirsher * Return Error if unsupported values or
752aa43c215SJeff Kirsher * unsupported parameters are set.
753aa43c215SJeff Kirsher */
754aa43c215SJeff Kirsher if (ethcoal->rx_coalesce_usecs > 0xffff ||
755aa43c215SJeff Kirsher ethcoal->rx_max_coalesced_frames > 0xffff ||
756aa43c215SJeff Kirsher ethcoal->tx_coalesce_usecs > 0xffff ||
75764274771SJakub Kicinski ethcoal->tx_max_coalesced_frames > 0xffff)
758aa43c215SJeff Kirsher return -EINVAL;
759aa43c215SJeff Kirsher
760aa43c215SJeff Kirsher if (!ethcoal->rx_coalesce_usecs ||
761aa43c215SJeff Kirsher !ethcoal->rx_max_coalesced_frames) {
762aa43c215SJeff Kirsher adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
763aa43c215SJeff Kirsher adapter->coal.normal.data.rx_time_us =
764aa43c215SJeff Kirsher NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
765aa43c215SJeff Kirsher adapter->coal.normal.data.rx_packets =
766aa43c215SJeff Kirsher NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
767aa43c215SJeff Kirsher } else {
768aa43c215SJeff Kirsher adapter->coal.flags = 0;
769aa43c215SJeff Kirsher adapter->coal.normal.data.rx_time_us =
770aa43c215SJeff Kirsher ethcoal->rx_coalesce_usecs;
771aa43c215SJeff Kirsher adapter->coal.normal.data.rx_packets =
772aa43c215SJeff Kirsher ethcoal->rx_max_coalesced_frames;
773aa43c215SJeff Kirsher }
774aa43c215SJeff Kirsher adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
775aa43c215SJeff Kirsher adapter->coal.normal.data.tx_packets =
776aa43c215SJeff Kirsher ethcoal->tx_max_coalesced_frames;
777aa43c215SJeff Kirsher
778aa43c215SJeff Kirsher netxen_config_intr_coalesce(adapter);
779aa43c215SJeff Kirsher
780aa43c215SJeff Kirsher return 0;
781aa43c215SJeff Kirsher }
782aa43c215SJeff Kirsher
netxen_get_intr_coalesce(struct net_device * netdev,struct ethtool_coalesce * ethcoal,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)783aa43c215SJeff Kirsher static int netxen_get_intr_coalesce(struct net_device *netdev,
784f3ccfda1SYufeng Mo struct ethtool_coalesce *ethcoal,
785f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
786f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
787aa43c215SJeff Kirsher {
788aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(netdev);
789aa43c215SJeff Kirsher
790aa43c215SJeff Kirsher if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
791aa43c215SJeff Kirsher return -EINVAL;
792aa43c215SJeff Kirsher
793aa43c215SJeff Kirsher if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
794aa43c215SJeff Kirsher return -EINVAL;
795aa43c215SJeff Kirsher
796aa43c215SJeff Kirsher ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
797aa43c215SJeff Kirsher ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
798aa43c215SJeff Kirsher ethcoal->rx_max_coalesced_frames =
799aa43c215SJeff Kirsher adapter->coal.normal.data.rx_packets;
800aa43c215SJeff Kirsher ethcoal->tx_max_coalesced_frames =
801aa43c215SJeff Kirsher adapter->coal.normal.data.tx_packets;
802aa43c215SJeff Kirsher
803aa43c215SJeff Kirsher return 0;
804aa43c215SJeff Kirsher }
805aa43c215SJeff Kirsher
80683f18a55SManish chopra static int
netxen_get_dump_flag(struct net_device * netdev,struct ethtool_dump * dump)80783f18a55SManish chopra netxen_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
80883f18a55SManish chopra {
80983f18a55SManish chopra struct netxen_adapter *adapter = netdev_priv(netdev);
81083f18a55SManish chopra struct netxen_minidump *mdump = &adapter->mdump;
81183f18a55SManish chopra if (adapter->fw_mdump_rdy)
81283f18a55SManish chopra dump->len = mdump->md_dump_size;
81383f18a55SManish chopra else
81483f18a55SManish chopra dump->len = 0;
815a777c892SManish chopra
816a777c892SManish chopra if (!mdump->md_enabled)
817a777c892SManish chopra dump->flag = ETH_FW_DUMP_DISABLE;
818a777c892SManish chopra else
81983f18a55SManish chopra dump->flag = mdump->md_capture_mask;
820a777c892SManish chopra
82183f18a55SManish chopra dump->version = adapter->fw_version;
82283f18a55SManish chopra return 0;
82383f18a55SManish chopra }
82483f18a55SManish chopra
825d0ea5cbdSJesse Brandeburg /* Fw dump levels */
826d0ea5cbdSJesse Brandeburg static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
827d0ea5cbdSJesse Brandeburg
82883f18a55SManish chopra static int
netxen_set_dump(struct net_device * netdev,struct ethtool_dump * val)82983f18a55SManish chopra netxen_set_dump(struct net_device *netdev, struct ethtool_dump *val)
83083f18a55SManish chopra {
831d8c3e772SManish chopra int i;
83283f18a55SManish chopra struct netxen_adapter *adapter = netdev_priv(netdev);
83383f18a55SManish chopra struct netxen_minidump *mdump = &adapter->mdump;
83483f18a55SManish chopra
83583f18a55SManish chopra switch (val->flag) {
83683f18a55SManish chopra case NX_FORCE_FW_DUMP_KEY:
837a777c892SManish chopra if (!mdump->md_enabled) {
838a777c892SManish chopra netdev_info(netdev, "FW dump not enabled\n");
839a777c892SManish chopra return 0;
840a777c892SManish chopra }
84183f18a55SManish chopra if (adapter->fw_mdump_rdy) {
84283f18a55SManish chopra netdev_info(netdev, "Previous dump not cleared, not forcing dump\n");
843d8c3e772SManish chopra return 0;
84483f18a55SManish chopra }
84583f18a55SManish chopra netdev_info(netdev, "Forcing a fw dump\n");
84683f18a55SManish chopra nx_dev_request_reset(adapter);
84783f18a55SManish chopra break;
84883f18a55SManish chopra case NX_DISABLE_FW_DUMP:
84983f18a55SManish chopra if (mdump->md_enabled) {
85083f18a55SManish chopra netdev_info(netdev, "Disabling FW Dump\n");
85183f18a55SManish chopra mdump->md_enabled = 0;
85283f18a55SManish chopra }
85383f18a55SManish chopra break;
85483f18a55SManish chopra case NX_ENABLE_FW_DUMP:
85583f18a55SManish chopra if (!mdump->md_enabled) {
85683f18a55SManish chopra netdev_info(netdev, "Enabling FW dump\n");
85783f18a55SManish chopra mdump->md_enabled = 1;
85883f18a55SManish chopra }
85983f18a55SManish chopra break;
86083f18a55SManish chopra case NX_FORCE_FW_RESET:
86183f18a55SManish chopra netdev_info(netdev, "Forcing FW reset\n");
86283f18a55SManish chopra nx_dev_request_reset(adapter);
86383f18a55SManish chopra adapter->flags &= ~NETXEN_FW_RESET_OWNER;
86483f18a55SManish chopra break;
86583f18a55SManish chopra default:
866d8c3e772SManish chopra for (i = 0; i < ARRAY_SIZE(FW_DUMP_LEVELS); i++) {
867d8c3e772SManish chopra if (val->flag == FW_DUMP_LEVELS[i]) {
868d8c3e772SManish chopra mdump->md_capture_mask = val->flag;
869d8c3e772SManish chopra netdev_info(netdev,
870d8c3e772SManish chopra "Driver mask changed to: 0x%x\n",
87183f18a55SManish chopra mdump->md_capture_mask);
872d8c3e772SManish chopra return 0;
873d8c3e772SManish chopra }
87483f18a55SManish chopra }
87583f18a55SManish chopra netdev_info(netdev,
87683f18a55SManish chopra "Invalid dump level: 0x%x\n", val->flag);
87783f18a55SManish chopra return -EINVAL;
87883f18a55SManish chopra }
87983f18a55SManish chopra
880d8c3e772SManish chopra return 0;
88183f18a55SManish chopra }
88283f18a55SManish chopra
88383f18a55SManish chopra static int
netxen_get_dump_data(struct net_device * netdev,struct ethtool_dump * dump,void * buffer)88483f18a55SManish chopra netxen_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
88583f18a55SManish chopra void *buffer)
88683f18a55SManish chopra {
88783f18a55SManish chopra int i, copy_sz;
88883f18a55SManish chopra u32 *hdr_ptr, *data;
88983f18a55SManish chopra struct netxen_adapter *adapter = netdev_priv(netdev);
89083f18a55SManish chopra struct netxen_minidump *mdump = &adapter->mdump;
89183f18a55SManish chopra
89283f18a55SManish chopra
89383f18a55SManish chopra if (!adapter->fw_mdump_rdy) {
89483f18a55SManish chopra netdev_info(netdev, "Dump not available\n");
89583f18a55SManish chopra return -EINVAL;
89683f18a55SManish chopra }
89783f18a55SManish chopra /* Copy template header first */
89883f18a55SManish chopra copy_sz = mdump->md_template_size;
89983f18a55SManish chopra hdr_ptr = (u32 *) mdump->md_template;
90083f18a55SManish chopra data = buffer;
90183f18a55SManish chopra for (i = 0; i < copy_sz/sizeof(u32); i++)
90283f18a55SManish chopra *data++ = cpu_to_le32(*hdr_ptr++);
90383f18a55SManish chopra
90483f18a55SManish chopra /* Copy captured dump data */
90583f18a55SManish chopra memcpy(buffer + copy_sz,
90683f18a55SManish chopra mdump->md_capture_buff + mdump->md_template_size,
90783f18a55SManish chopra mdump->md_capture_size);
90883f18a55SManish chopra dump->len = copy_sz + mdump->md_capture_size;
90983f18a55SManish chopra dump->flag = mdump->md_capture_mask;
91083f18a55SManish chopra
91183f18a55SManish chopra /* Free dump area once data has been captured */
91283f18a55SManish chopra vfree(mdump->md_capture_buff);
91383f18a55SManish chopra mdump->md_capture_buff = NULL;
91483f18a55SManish chopra adapter->fw_mdump_rdy = 0;
91583f18a55SManish chopra netdev_info(netdev, "extracted the fw dump Successfully\n");
91683f18a55SManish chopra return 0;
91783f18a55SManish chopra }
91883f18a55SManish chopra
919aa43c215SJeff Kirsher const struct ethtool_ops netxen_nic_ethtool_ops = {
92064274771SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
92164274771SJakub Kicinski ETHTOOL_COALESCE_MAX_FRAMES,
922aa43c215SJeff Kirsher .get_drvinfo = netxen_nic_get_drvinfo,
923aa43c215SJeff Kirsher .get_regs_len = netxen_nic_get_regs_len,
924aa43c215SJeff Kirsher .get_regs = netxen_nic_get_regs,
925aa43c215SJeff Kirsher .get_link = ethtool_op_get_link,
926aa43c215SJeff Kirsher .get_eeprom_len = netxen_nic_get_eeprom_len,
927aa43c215SJeff Kirsher .get_eeprom = netxen_nic_get_eeprom,
928aa43c215SJeff Kirsher .get_ringparam = netxen_nic_get_ringparam,
929aa43c215SJeff Kirsher .set_ringparam = netxen_nic_set_ringparam,
930aa43c215SJeff Kirsher .get_pauseparam = netxen_nic_get_pauseparam,
931aa43c215SJeff Kirsher .set_pauseparam = netxen_nic_set_pauseparam,
932aa43c215SJeff Kirsher .get_wol = netxen_nic_get_wol,
933aa43c215SJeff Kirsher .set_wol = netxen_nic_set_wol,
934aa43c215SJeff Kirsher .self_test = netxen_nic_diag_test,
935aa43c215SJeff Kirsher .get_strings = netxen_nic_get_strings,
936aa43c215SJeff Kirsher .get_ethtool_stats = netxen_nic_get_ethtool_stats,
937aa43c215SJeff Kirsher .get_sset_count = netxen_get_sset_count,
938aa43c215SJeff Kirsher .get_coalesce = netxen_get_intr_coalesce,
939aa43c215SJeff Kirsher .set_coalesce = netxen_set_intr_coalesce,
94083f18a55SManish chopra .get_dump_flag = netxen_get_dump_flag,
94183f18a55SManish chopra .get_dump_data = netxen_get_dump_data,
94283f18a55SManish chopra .set_dump = netxen_set_dump,
94399f18f1dSPhilippe Reynes .get_link_ksettings = netxen_nic_get_link_ksettings,
94499f18f1dSPhilippe Reynes .set_link_ksettings = netxen_nic_set_link_ksettings,
945aa43c215SJeff Kirsher };
946