2 * Copyright (C) 2009 - QLogic Corporation.
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.
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.
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,
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/types.h>
26 #include <linux/delay.h>
27 #include <linux/pci.h>
29 #include <linux/netdevice.h>
30 #include <linux/ethtool.h>
35 char stat_string[ETH_GSTRING_LEN];
40 #define QLC_SIZEOF(m) FIELD_SIZEOF(struct qlcnic_adapter, m)
41 #define QLC_OFF(m) offsetof(struct qlcnic_adapter, m)
43 static const struct qlcnic_stats qlcnic_gstrings_stats[] = {
45 QLC_SIZEOF(stats.xmitcalled), QLC_OFF(stats.xmitcalled)},
47 QLC_SIZEOF(stats.xmitfinished), QLC_OFF(stats.xmitfinished)},
49 QLC_SIZEOF(stats.rxdropped), QLC_OFF(stats.rxdropped)},
51 QLC_SIZEOF(stats.txdropped), QLC_OFF(stats.txdropped)},
53 QLC_SIZEOF(stats.csummed), QLC_OFF(stats.csummed)},
55 QLC_SIZEOF(stats.rx_pkts), QLC_OFF(stats.rx_pkts)},
57 QLC_SIZEOF(stats.lro_pkts), QLC_OFF(stats.lro_pkts)},
59 QLC_SIZEOF(stats.rxbytes), QLC_OFF(stats.rxbytes)},
61 QLC_SIZEOF(stats.txbytes), QLC_OFF(stats.txbytes)},
64 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
66 static const char qlcnic_gstrings_test[][ETH_GSTRING_LEN] = {
67 "Register_Test_on_offline",
68 "Link_Test_on_offline",
69 "Interrupt_Test_offline"
72 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
74 #define QLCNIC_RING_REGS_COUNT 20
75 #define QLCNIC_RING_REGS_LEN (QLCNIC_RING_REGS_COUNT * sizeof(u32))
76 #define QLCNIC_MAX_EEPROM_LEN 1024
78 static const u32 diag_registers[] = {
82 CRB_FW_CAPABILITIES_1,
84 QLCNIC_CRB_DEV_REF_COUNT,
87 QLCNIC_CRB_DRV_SCRATCH,
88 QLCNIC_CRB_DEV_PARTITION_INFO,
89 QLCNIC_CRB_DRV_IDC_VER,
90 QLCNIC_PEG_ALIVE_COUNTER,
91 QLCNIC_PEG_HALT_STATUS1,
92 QLCNIC_PEG_HALT_STATUS2,
93 QLCNIC_CRB_PEG_NET_0+0x3c,
94 QLCNIC_CRB_PEG_NET_1+0x3c,
95 QLCNIC_CRB_PEG_NET_2+0x3c,
96 QLCNIC_CRB_PEG_NET_4+0x3c,
100 static int qlcnic_get_regs_len(struct net_device *dev)
102 return sizeof(diag_registers) + QLCNIC_RING_REGS_LEN;
105 static int qlcnic_get_eeprom_len(struct net_device *dev)
107 return QLCNIC_FLASH_TOTAL_SIZE;
111 qlcnic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
113 struct qlcnic_adapter *adapter = netdev_priv(dev);
114 u32 fw_major, fw_minor, fw_build;
116 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
117 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
118 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
119 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
121 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
122 strlcpy(drvinfo->driver, qlcnic_driver_name, 32);
123 strlcpy(drvinfo->version, QLCNIC_LINUX_VERSIONID, 32);
127 qlcnic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
129 struct qlcnic_adapter *adapter = netdev_priv(dev);
130 int check_sfp_module = 0;
131 u16 pcifn = adapter->ahw.pci_func;
133 /* read which mode */
134 if (adapter->ahw.port_type == QLCNIC_GBE) {
135 ecmd->supported = (SUPPORTED_10baseT_Half |
136 SUPPORTED_10baseT_Full |
137 SUPPORTED_100baseT_Half |
138 SUPPORTED_100baseT_Full |
139 SUPPORTED_1000baseT_Half |
140 SUPPORTED_1000baseT_Full);
142 ecmd->advertising = (ADVERTISED_100baseT_Half |
143 ADVERTISED_100baseT_Full |
144 ADVERTISED_1000baseT_Half |
145 ADVERTISED_1000baseT_Full);
147 ecmd->speed = adapter->link_speed;
148 ecmd->duplex = adapter->link_duplex;
149 ecmd->autoneg = adapter->link_autoneg;
151 } else if (adapter->ahw.port_type == QLCNIC_XGBE) {
154 val = QLCRD32(adapter, QLCNIC_PORT_MODE_ADDR);
155 if (val == QLCNIC_PORT_MODE_802_3_AP) {
156 ecmd->supported = SUPPORTED_1000baseT_Full;
157 ecmd->advertising = ADVERTISED_1000baseT_Full;
159 ecmd->supported = SUPPORTED_10000baseT_Full;
160 ecmd->advertising = ADVERTISED_10000baseT_Full;
163 if (netif_running(dev) && adapter->has_link_events) {
164 ecmd->speed = adapter->link_speed;
165 ecmd->autoneg = adapter->link_autoneg;
166 ecmd->duplex = adapter->link_duplex;
170 val = QLCRD32(adapter, P3_LINK_SPEED_REG(pcifn));
171 ecmd->speed = P3_LINK_SPEED_MHZ *
172 P3_LINK_SPEED_VAL(pcifn, val);
173 ecmd->duplex = DUPLEX_FULL;
174 ecmd->autoneg = AUTONEG_DISABLE;
179 ecmd->phy_address = adapter->physical_port;
180 ecmd->transceiver = XCVR_EXTERNAL;
182 switch (adapter->ahw.board_type) {
183 case QLCNIC_BRDTYPE_P3_REF_QG:
184 case QLCNIC_BRDTYPE_P3_4_GB:
185 case QLCNIC_BRDTYPE_P3_4_GB_MM:
187 ecmd->supported |= SUPPORTED_Autoneg;
188 ecmd->advertising |= ADVERTISED_Autoneg;
189 case QLCNIC_BRDTYPE_P3_10G_CX4:
190 case QLCNIC_BRDTYPE_P3_10G_CX4_LP:
191 case QLCNIC_BRDTYPE_P3_10000_BASE_T:
192 ecmd->supported |= SUPPORTED_TP;
193 ecmd->advertising |= ADVERTISED_TP;
194 ecmd->port = PORT_TP;
195 ecmd->autoneg = adapter->link_autoneg;
197 case QLCNIC_BRDTYPE_P3_IMEZ:
198 case QLCNIC_BRDTYPE_P3_XG_LOM:
199 case QLCNIC_BRDTYPE_P3_HMEZ:
200 ecmd->supported |= SUPPORTED_MII;
201 ecmd->advertising |= ADVERTISED_MII;
202 ecmd->port = PORT_MII;
203 ecmd->autoneg = AUTONEG_DISABLE;
205 case QLCNIC_BRDTYPE_P3_10G_SFP_PLUS:
206 case QLCNIC_BRDTYPE_P3_10G_SFP_CT:
207 case QLCNIC_BRDTYPE_P3_10G_SFP_QT:
208 ecmd->advertising |= ADVERTISED_TP;
209 ecmd->supported |= SUPPORTED_TP;
210 check_sfp_module = netif_running(dev) &&
211 adapter->has_link_events;
212 case QLCNIC_BRDTYPE_P3_10G_XFP:
213 ecmd->supported |= SUPPORTED_FIBRE;
214 ecmd->advertising |= ADVERTISED_FIBRE;
215 ecmd->port = PORT_FIBRE;
216 ecmd->autoneg = AUTONEG_DISABLE;
218 case QLCNIC_BRDTYPE_P3_10G_TP:
219 if (adapter->ahw.port_type == QLCNIC_XGBE) {
220 ecmd->autoneg = AUTONEG_DISABLE;
221 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
223 (ADVERTISED_FIBRE | ADVERTISED_TP);
224 ecmd->port = PORT_FIBRE;
225 check_sfp_module = netif_running(dev) &&
226 adapter->has_link_events;
228 ecmd->autoneg = AUTONEG_ENABLE;
229 ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
231 (ADVERTISED_TP | ADVERTISED_Autoneg);
232 ecmd->port = PORT_TP;
236 dev_err(&adapter->pdev->dev, "Unsupported board model %d\n",
237 adapter->ahw.board_type);
241 if (check_sfp_module) {
242 switch (adapter->module_type) {
243 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
244 case LINKEVENT_MODULE_OPTICAL_SRLR:
245 case LINKEVENT_MODULE_OPTICAL_LRM:
246 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
247 ecmd->port = PORT_FIBRE;
249 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
250 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
251 case LINKEVENT_MODULE_TWINAX:
252 ecmd->port = PORT_TP;
255 ecmd->port = PORT_OTHER;
263 qlcnic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
265 struct qlcnic_adapter *adapter = netdev_priv(dev);
268 /* read which mode */
269 if (adapter->ahw.port_type == QLCNIC_GBE) {
270 /* autonegotiation */
271 if (qlcnic_fw_cmd_set_phy(adapter,
272 QLCNIC_NIU_GB_MII_MGMT_ADDR_AUTONEG,
276 adapter->link_autoneg = ecmd->autoneg;
278 if (qlcnic_fw_cmd_query_phy(adapter,
279 QLCNIC_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
283 switch (ecmd->speed) {
285 qlcnic_set_phy_speed(status, 0);
288 qlcnic_set_phy_speed(status, 1);
291 qlcnic_set_phy_speed(status, 2);
295 if (ecmd->duplex == DUPLEX_HALF)
296 qlcnic_clear_phy_duplex(status);
297 if (ecmd->duplex == DUPLEX_FULL)
298 qlcnic_set_phy_duplex(status);
299 if (qlcnic_fw_cmd_set_phy(adapter,
300 QLCNIC_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
301 *((int *)&status)) != 0)
304 adapter->link_speed = ecmd->speed;
305 adapter->link_duplex = ecmd->duplex;
310 if (!netif_running(dev))
313 dev->netdev_ops->ndo_stop(dev);
314 return dev->netdev_ops->ndo_open(dev);
318 qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
320 struct qlcnic_adapter *adapter = netdev_priv(dev);
321 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
322 struct qlcnic_host_sds_ring *sds_ring;
326 memset(p, 0, qlcnic_get_regs_len(dev));
327 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
328 (adapter->pdev)->device;
330 for (i = 0; diag_registers[i] != -1; i++)
331 regs_buff[i] = QLCRD32(adapter, diag_registers[i]);
333 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
336 regs_buff[i++] = 0xFFEFCDAB; /* Marker btw regs and ring count*/
338 regs_buff[i++] = 1; /* No. of tx ring */
339 regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer));
340 regs_buff[i++] = readl(adapter->tx_ring->crb_cmd_producer);
342 regs_buff[i++] = 2; /* No. of rx ring */
343 regs_buff[i++] = readl(recv_ctx->rds_rings[0].crb_rcv_producer);
344 regs_buff[i++] = readl(recv_ctx->rds_rings[1].crb_rcv_producer);
346 regs_buff[i++] = adapter->max_sds_rings;
348 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
349 sds_ring = &(recv_ctx->sds_rings[ring]);
350 regs_buff[i++] = readl(sds_ring->crb_sts_consumer);
354 static u32 qlcnic_test_link(struct net_device *dev)
356 struct qlcnic_adapter *adapter = netdev_priv(dev);
359 val = QLCRD32(adapter, CRB_XG_STATE_P3);
360 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
361 return (val == XG_LINK_UP_P3) ? 0 : 1;
365 qlcnic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
368 struct qlcnic_adapter *adapter = netdev_priv(dev);
372 if (eeprom->len == 0)
375 eeprom->magic = (adapter->pdev)->vendor |
376 ((adapter->pdev)->device << 16);
377 offset = eeprom->offset;
379 ret = qlcnic_rom_fast_read_words(adapter, offset, bytes,
388 qlcnic_get_ringparam(struct net_device *dev,
389 struct ethtool_ringparam *ring)
391 struct qlcnic_adapter *adapter = netdev_priv(dev);
393 ring->rx_pending = adapter->num_rxd;
394 ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
395 ring->rx_jumbo_pending += adapter->num_lro_rxd;
396 ring->tx_pending = adapter->num_txd;
398 if (adapter->ahw.port_type == QLCNIC_GBE) {
399 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
400 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
402 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
403 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
406 ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
408 ring->rx_mini_max_pending = 0;
409 ring->rx_mini_pending = 0;
413 qlcnic_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
416 num_desc = max(val, min);
417 num_desc = min(num_desc, max);
418 num_desc = roundup_pow_of_two(num_desc);
420 if (val != num_desc) {
421 printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
422 qlcnic_driver_name, r_name, num_desc, val);
429 qlcnic_set_ringparam(struct net_device *dev,
430 struct ethtool_ringparam *ring)
432 struct qlcnic_adapter *adapter = netdev_priv(dev);
433 u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
434 u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
435 u16 num_rxd, num_jumbo_rxd, num_txd;
438 if (ring->rx_mini_pending)
441 if (adapter->ahw.port_type == QLCNIC_GBE) {
442 max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
443 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
446 num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
447 MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
449 num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
450 MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
452 num_txd = qlcnic_validate_ringparam(ring->tx_pending,
453 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
455 if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
456 num_jumbo_rxd == adapter->num_jumbo_rxd)
459 adapter->num_rxd = num_rxd;
460 adapter->num_jumbo_rxd = num_jumbo_rxd;
461 adapter->num_txd = num_txd;
463 return qlcnic_reset_context(adapter);
467 qlcnic_get_pauseparam(struct net_device *netdev,
468 struct ethtool_pauseparam *pause)
470 struct qlcnic_adapter *adapter = netdev_priv(netdev);
471 int port = adapter->physical_port;
474 if (adapter->ahw.port_type == QLCNIC_GBE) {
475 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
477 /* get flow control settings */
478 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port));
479 pause->rx_pause = qlcnic_gb_get_rx_flowctl(val);
480 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL);
483 pause->tx_pause = !(qlcnic_gb_get_gb0_mask(val));
486 pause->tx_pause = !(qlcnic_gb_get_gb1_mask(val));
489 pause->tx_pause = !(qlcnic_gb_get_gb2_mask(val));
493 pause->tx_pause = !(qlcnic_gb_get_gb3_mask(val));
496 } else if (adapter->ahw.port_type == QLCNIC_XGBE) {
497 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
500 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL);
502 pause->tx_pause = !(qlcnic_xg_get_xg0_mask(val));
504 pause->tx_pause = !(qlcnic_xg_get_xg1_mask(val));
506 dev_err(&netdev->dev, "Unknown board type: %x\n",
507 adapter->ahw.port_type);
512 qlcnic_set_pauseparam(struct net_device *netdev,
513 struct ethtool_pauseparam *pause)
515 struct qlcnic_adapter *adapter = netdev_priv(netdev);
516 int port = adapter->physical_port;
520 if (adapter->ahw.port_type == QLCNIC_GBE) {
521 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
523 /* set flow control */
524 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port));
527 qlcnic_gb_rx_flowctl(val);
529 qlcnic_gb_unset_rx_flowctl(val);
531 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port),
534 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL);
538 qlcnic_gb_unset_gb0_mask(val);
540 qlcnic_gb_set_gb0_mask(val);
544 qlcnic_gb_unset_gb1_mask(val);
546 qlcnic_gb_set_gb1_mask(val);
550 qlcnic_gb_unset_gb2_mask(val);
552 qlcnic_gb_set_gb2_mask(val);
557 qlcnic_gb_unset_gb3_mask(val);
559 qlcnic_gb_set_gb3_mask(val);
562 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, val);
563 } else if (adapter->ahw.port_type == QLCNIC_XGBE) {
564 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
566 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL);
569 qlcnic_xg_unset_xg0_mask(val);
571 qlcnic_xg_set_xg0_mask(val);
574 qlcnic_xg_unset_xg1_mask(val);
576 qlcnic_xg_set_xg1_mask(val);
578 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, val);
580 dev_err(&netdev->dev, "Unknown board type: %x\n",
581 adapter->ahw.port_type);
586 static int qlcnic_reg_test(struct net_device *dev)
588 struct qlcnic_adapter *adapter = netdev_priv(dev);
589 u32 data_read, data_written;
591 data_read = QLCRD32(adapter, QLCNIC_PCIX_PH_REG(0));
592 if ((data_read & 0xffff) != adapter->pdev->vendor)
595 data_written = (u32)0xa5a5a5a5;
597 QLCWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
598 data_read = QLCRD32(adapter, CRB_SCRATCHPAD_TEST);
599 if (data_written != data_read)
605 static int qlcnic_get_sset_count(struct net_device *dev, int sset)
609 return QLCNIC_TEST_LEN;
611 return QLCNIC_STATS_LEN;
617 static int qlcnic_irq_test(struct net_device *netdev)
619 struct qlcnic_adapter *adapter = netdev_priv(netdev);
620 int max_sds_rings = adapter->max_sds_rings;
623 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
626 ret = qlcnic_diag_alloc_res(netdev, QLCNIC_INTERRUPT_TEST);
630 adapter->diag_cnt = 0;
631 ret = qlcnic_issue_cmd(adapter, adapter->ahw.pci_func,
632 QLCHAL_VERSION, adapter->portnum, 0, 0, 0x00000011);
638 ret = !adapter->diag_cnt;
641 qlcnic_diag_free_res(netdev, max_sds_rings);
644 adapter->max_sds_rings = max_sds_rings;
645 clear_bit(__QLCNIC_RESETTING, &adapter->state);
650 qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
653 memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
655 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
656 data[2] = qlcnic_irq_test(dev);
658 eth_test->flags |= ETH_TEST_FL_FAILED;
661 data[0] = qlcnic_reg_test(dev);
663 eth_test->flags |= ETH_TEST_FL_FAILED;
666 data[1] = (u64) qlcnic_test_link(dev);
668 eth_test->flags |= ETH_TEST_FL_FAILED;
672 qlcnic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
678 memcpy(data, *qlcnic_gstrings_test,
679 QLCNIC_TEST_LEN * ETH_GSTRING_LEN);
682 for (index = 0; index < QLCNIC_STATS_LEN; index++) {
683 memcpy(data + index * ETH_GSTRING_LEN,
684 qlcnic_gstrings_stats[index].stat_string,
692 qlcnic_get_ethtool_stats(struct net_device *dev,
693 struct ethtool_stats *stats, u64 * data)
695 struct qlcnic_adapter *adapter = netdev_priv(dev);
698 for (index = 0; index < QLCNIC_STATS_LEN; index++) {
701 qlcnic_gstrings_stats[index].stat_offset;
703 (qlcnic_gstrings_stats[index].sizeof_stat ==
704 sizeof(u64)) ? *(u64 *)p:(*(u32 *)p);
708 static u32 qlcnic_get_rx_csum(struct net_device *dev)
710 struct qlcnic_adapter *adapter = netdev_priv(dev);
711 return adapter->rx_csum;
714 static int qlcnic_set_rx_csum(struct net_device *dev, u32 data)
716 struct qlcnic_adapter *adapter = netdev_priv(dev);
717 adapter->rx_csum = !!data;
721 static u32 qlcnic_get_tso(struct net_device *dev)
723 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
726 static int qlcnic_set_tso(struct net_device *dev, u32 data)
729 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
731 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
736 static int qlcnic_blink_led(struct net_device *dev, u32 val)
738 struct qlcnic_adapter *adapter = netdev_priv(dev);
741 ret = qlcnic_config_led(adapter, 1, 0xf);
743 dev_err(&adapter->pdev->dev,
744 "Failed to set LED blink state.\n");
748 msleep_interruptible(val * 1000);
750 ret = qlcnic_config_led(adapter, 0, 0xf);
752 dev_err(&adapter->pdev->dev,
753 "Failed to reset LED blink state.\n");
761 qlcnic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
763 struct qlcnic_adapter *adapter = netdev_priv(dev);
769 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV);
770 if (wol_cfg & (1UL << adapter->portnum))
771 wol->supported |= WAKE_MAGIC;
773 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG);
774 if (wol_cfg & (1UL << adapter->portnum))
775 wol->wolopts |= WAKE_MAGIC;
779 qlcnic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
781 struct qlcnic_adapter *adapter = netdev_priv(dev);
784 if (wol->wolopts & ~WAKE_MAGIC)
787 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV);
788 if (!(wol_cfg & (1 << adapter->portnum)))
791 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG);
792 if (wol->wolopts & WAKE_MAGIC)
793 wol_cfg |= 1UL << adapter->portnum;
795 wol_cfg &= ~(1UL << adapter->portnum);
797 QLCWR32(adapter, QLCNIC_WOL_CONFIG, wol_cfg);
803 * Set the coalescing parameters. Currently only normal is supported.
804 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
805 * firmware coalescing to default.
807 static int qlcnic_set_intr_coalesce(struct net_device *netdev,
808 struct ethtool_coalesce *ethcoal)
810 struct qlcnic_adapter *adapter = netdev_priv(netdev);
812 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
816 * Return Error if unsupported values or
817 * unsupported parameters are set.
819 if (ethcoal->rx_coalesce_usecs > 0xffff ||
820 ethcoal->rx_max_coalesced_frames > 0xffff ||
821 ethcoal->tx_coalesce_usecs > 0xffff ||
822 ethcoal->tx_max_coalesced_frames > 0xffff ||
823 ethcoal->rx_coalesce_usecs_irq ||
824 ethcoal->rx_max_coalesced_frames_irq ||
825 ethcoal->tx_coalesce_usecs_irq ||
826 ethcoal->tx_max_coalesced_frames_irq ||
827 ethcoal->stats_block_coalesce_usecs ||
828 ethcoal->use_adaptive_rx_coalesce ||
829 ethcoal->use_adaptive_tx_coalesce ||
830 ethcoal->pkt_rate_low ||
831 ethcoal->rx_coalesce_usecs_low ||
832 ethcoal->rx_max_coalesced_frames_low ||
833 ethcoal->tx_coalesce_usecs_low ||
834 ethcoal->tx_max_coalesced_frames_low ||
835 ethcoal->pkt_rate_high ||
836 ethcoal->rx_coalesce_usecs_high ||
837 ethcoal->rx_max_coalesced_frames_high ||
838 ethcoal->tx_coalesce_usecs_high ||
839 ethcoal->tx_max_coalesced_frames_high)
842 if (!ethcoal->rx_coalesce_usecs ||
843 !ethcoal->rx_max_coalesced_frames) {
844 adapter->coal.flags = QLCNIC_INTR_DEFAULT;
845 adapter->coal.normal.data.rx_time_us =
846 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
847 adapter->coal.normal.data.rx_packets =
848 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
850 adapter->coal.flags = 0;
851 adapter->coal.normal.data.rx_time_us =
852 ethcoal->rx_coalesce_usecs;
853 adapter->coal.normal.data.rx_packets =
854 ethcoal->rx_max_coalesced_frames;
856 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
857 adapter->coal.normal.data.tx_packets =
858 ethcoal->tx_max_coalesced_frames;
860 qlcnic_config_intr_coalesce(adapter);
865 static int qlcnic_get_intr_coalesce(struct net_device *netdev,
866 struct ethtool_coalesce *ethcoal)
868 struct qlcnic_adapter *adapter = netdev_priv(netdev);
870 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
873 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
874 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
875 ethcoal->rx_max_coalesced_frames =
876 adapter->coal.normal.data.rx_packets;
877 ethcoal->tx_max_coalesced_frames =
878 adapter->coal.normal.data.tx_packets;
883 static int qlcnic_set_flags(struct net_device *netdev, u32 data)
885 struct qlcnic_adapter *adapter = netdev_priv(netdev);
888 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO))
891 ethtool_op_set_flags(netdev, data);
893 hw_lro = (data & ETH_FLAG_LRO) ? QLCNIC_LRO_ENABLED : 0;
895 if (qlcnic_config_hw_lro(adapter, hw_lro))
898 if ((hw_lro == 0) && qlcnic_send_lro_cleanup(adapter))
905 const struct ethtool_ops qlcnic_ethtool_ops = {
906 .get_settings = qlcnic_get_settings,
907 .set_settings = qlcnic_set_settings,
908 .get_drvinfo = qlcnic_get_drvinfo,
909 .get_regs_len = qlcnic_get_regs_len,
910 .get_regs = qlcnic_get_regs,
911 .get_link = ethtool_op_get_link,
912 .get_eeprom_len = qlcnic_get_eeprom_len,
913 .get_eeprom = qlcnic_get_eeprom,
914 .get_ringparam = qlcnic_get_ringparam,
915 .set_ringparam = qlcnic_set_ringparam,
916 .get_pauseparam = qlcnic_get_pauseparam,
917 .set_pauseparam = qlcnic_set_pauseparam,
918 .set_tx_csum = ethtool_op_set_tx_csum,
919 .set_sg = ethtool_op_set_sg,
920 .get_tso = qlcnic_get_tso,
921 .set_tso = qlcnic_set_tso,
922 .get_wol = qlcnic_get_wol,
923 .set_wol = qlcnic_set_wol,
924 .self_test = qlcnic_diag_test,
925 .get_strings = qlcnic_get_strings,
926 .get_ethtool_stats = qlcnic_get_ethtool_stats,
927 .get_sset_count = qlcnic_get_sset_count,
928 .get_rx_csum = qlcnic_get_rx_csum,
929 .set_rx_csum = qlcnic_set_rx_csum,
930 .get_coalesce = qlcnic_get_intr_coalesce,
931 .set_coalesce = qlcnic_set_intr_coalesce,
932 .get_flags = ethtool_op_get_flags,
933 .set_flags = qlcnic_set_flags,
934 .phys_id = qlcnic_blink_led,