1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/types.h>
4 #include <linux/module.h>
5 #include <linux/list.h>
7 #include <linux/dma-mapping.h>
8 #include <linux/pagemap.h>
9 #include <linux/sched.h>
10 #include <linux/dmapool.h>
11 #include <linux/mempool.h>
12 #include <linux/spinlock.h>
13 #include <linux/kthread.h>
14 #include <linux/interrupt.h>
15 #include <linux/errno.h>
16 #include <linux/ioport.h>
19 #include <linux/ipv6.h>
21 #include <linux/tcp.h>
22 #include <linux/udp.h>
23 #include <linux/if_arp.h>
24 #include <linux/if_ether.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/ethtool.h>
28 #include <linux/skbuff.h>
29 #include <linux/rtnetlink.h>
30 #include <linux/if_vlan.h>
31 #include <linux/delay.h>
33 #include <linux/vmalloc.h>
38 char stat_string[ETH_GSTRING_LEN];
43 #define QL_SIZEOF(m) sizeof_field(struct ql_adapter, m)
44 #define QL_OFF(m) offsetof(struct ql_adapter, m)
46 static const struct ql_stats ql_gstrings_stats[] = {
47 {"tx_pkts", QL_SIZEOF(nic_stats.tx_pkts), QL_OFF(nic_stats.tx_pkts)},
48 {"tx_bytes", QL_SIZEOF(nic_stats.tx_bytes), QL_OFF(nic_stats.tx_bytes)},
49 {"tx_mcast_pkts", QL_SIZEOF(nic_stats.tx_mcast_pkts),
50 QL_OFF(nic_stats.tx_mcast_pkts)},
51 {"tx_bcast_pkts", QL_SIZEOF(nic_stats.tx_bcast_pkts),
52 QL_OFF(nic_stats.tx_bcast_pkts)},
53 {"tx_ucast_pkts", QL_SIZEOF(nic_stats.tx_ucast_pkts),
54 QL_OFF(nic_stats.tx_ucast_pkts)},
55 {"tx_ctl_pkts", QL_SIZEOF(nic_stats.tx_ctl_pkts),
56 QL_OFF(nic_stats.tx_ctl_pkts)},
57 {"tx_pause_pkts", QL_SIZEOF(nic_stats.tx_pause_pkts),
58 QL_OFF(nic_stats.tx_pause_pkts)},
59 {"tx_64_pkts", QL_SIZEOF(nic_stats.tx_64_pkt),
60 QL_OFF(nic_stats.tx_64_pkt)},
61 {"tx_65_to_127_pkts", QL_SIZEOF(nic_stats.tx_65_to_127_pkt),
62 QL_OFF(nic_stats.tx_65_to_127_pkt)},
63 {"tx_128_to_255_pkts", QL_SIZEOF(nic_stats.tx_128_to_255_pkt),
64 QL_OFF(nic_stats.tx_128_to_255_pkt)},
65 {"tx_256_511_pkts", QL_SIZEOF(nic_stats.tx_256_511_pkt),
66 QL_OFF(nic_stats.tx_256_511_pkt)},
67 {"tx_512_to_1023_pkts", QL_SIZEOF(nic_stats.tx_512_to_1023_pkt),
68 QL_OFF(nic_stats.tx_512_to_1023_pkt)},
69 {"tx_1024_to_1518_pkts", QL_SIZEOF(nic_stats.tx_1024_to_1518_pkt),
70 QL_OFF(nic_stats.tx_1024_to_1518_pkt)},
71 {"tx_1519_to_max_pkts", QL_SIZEOF(nic_stats.tx_1519_to_max_pkt),
72 QL_OFF(nic_stats.tx_1519_to_max_pkt)},
73 {"tx_undersize_pkts", QL_SIZEOF(nic_stats.tx_undersize_pkt),
74 QL_OFF(nic_stats.tx_undersize_pkt)},
75 {"tx_oversize_pkts", QL_SIZEOF(nic_stats.tx_oversize_pkt),
76 QL_OFF(nic_stats.tx_oversize_pkt)},
77 {"rx_bytes", QL_SIZEOF(nic_stats.rx_bytes), QL_OFF(nic_stats.rx_bytes)},
78 {"rx_bytes_ok", QL_SIZEOF(nic_stats.rx_bytes_ok),
79 QL_OFF(nic_stats.rx_bytes_ok)},
80 {"rx_pkts", QL_SIZEOF(nic_stats.rx_pkts), QL_OFF(nic_stats.rx_pkts)},
81 {"rx_pkts_ok", QL_SIZEOF(nic_stats.rx_pkts_ok),
82 QL_OFF(nic_stats.rx_pkts_ok)},
83 {"rx_bcast_pkts", QL_SIZEOF(nic_stats.rx_bcast_pkts),
84 QL_OFF(nic_stats.rx_bcast_pkts)},
85 {"rx_mcast_pkts", QL_SIZEOF(nic_stats.rx_mcast_pkts),
86 QL_OFF(nic_stats.rx_mcast_pkts)},
87 {"rx_ucast_pkts", QL_SIZEOF(nic_stats.rx_ucast_pkts),
88 QL_OFF(nic_stats.rx_ucast_pkts)},
89 {"rx_undersize_pkts", QL_SIZEOF(nic_stats.rx_undersize_pkts),
90 QL_OFF(nic_stats.rx_undersize_pkts)},
91 {"rx_oversize_pkts", QL_SIZEOF(nic_stats.rx_oversize_pkts),
92 QL_OFF(nic_stats.rx_oversize_pkts)},
93 {"rx_jabber_pkts", QL_SIZEOF(nic_stats.rx_jabber_pkts),
94 QL_OFF(nic_stats.rx_jabber_pkts)},
95 {"rx_undersize_fcerr_pkts",
96 QL_SIZEOF(nic_stats.rx_undersize_fcerr_pkts),
97 QL_OFF(nic_stats.rx_undersize_fcerr_pkts)},
98 {"rx_drop_events", QL_SIZEOF(nic_stats.rx_drop_events),
99 QL_OFF(nic_stats.rx_drop_events)},
100 {"rx_fcerr_pkts", QL_SIZEOF(nic_stats.rx_fcerr_pkts),
101 QL_OFF(nic_stats.rx_fcerr_pkts)},
102 {"rx_align_err", QL_SIZEOF(nic_stats.rx_align_err),
103 QL_OFF(nic_stats.rx_align_err)},
104 {"rx_symbol_err", QL_SIZEOF(nic_stats.rx_symbol_err),
105 QL_OFF(nic_stats.rx_symbol_err)},
106 {"rx_mac_err", QL_SIZEOF(nic_stats.rx_mac_err),
107 QL_OFF(nic_stats.rx_mac_err)},
108 {"rx_ctl_pkts", QL_SIZEOF(nic_stats.rx_ctl_pkts),
109 QL_OFF(nic_stats.rx_ctl_pkts)},
110 {"rx_pause_pkts", QL_SIZEOF(nic_stats.rx_pause_pkts),
111 QL_OFF(nic_stats.rx_pause_pkts)},
112 {"rx_64_pkts", QL_SIZEOF(nic_stats.rx_64_pkts),
113 QL_OFF(nic_stats.rx_64_pkts)},
114 {"rx_65_to_127_pkts", QL_SIZEOF(nic_stats.rx_65_to_127_pkts),
115 QL_OFF(nic_stats.rx_65_to_127_pkts)},
116 {"rx_128_255_pkts", QL_SIZEOF(nic_stats.rx_128_255_pkts),
117 QL_OFF(nic_stats.rx_128_255_pkts)},
118 {"rx_256_511_pkts", QL_SIZEOF(nic_stats.rx_256_511_pkts),
119 QL_OFF(nic_stats.rx_256_511_pkts)},
120 {"rx_512_to_1023_pkts", QL_SIZEOF(nic_stats.rx_512_to_1023_pkts),
121 QL_OFF(nic_stats.rx_512_to_1023_pkts)},
122 {"rx_1024_to_1518_pkts", QL_SIZEOF(nic_stats.rx_1024_to_1518_pkts),
123 QL_OFF(nic_stats.rx_1024_to_1518_pkts)},
124 {"rx_1519_to_max_pkts", QL_SIZEOF(nic_stats.rx_1519_to_max_pkts),
125 QL_OFF(nic_stats.rx_1519_to_max_pkts)},
126 {"rx_len_err_pkts", QL_SIZEOF(nic_stats.rx_len_err_pkts),
127 QL_OFF(nic_stats.rx_len_err_pkts)},
128 {"rx_code_err", QL_SIZEOF(nic_stats.rx_code_err),
129 QL_OFF(nic_stats.rx_code_err)},
130 {"rx_oversize_err", QL_SIZEOF(nic_stats.rx_oversize_err),
131 QL_OFF(nic_stats.rx_oversize_err)},
132 {"rx_undersize_err", QL_SIZEOF(nic_stats.rx_undersize_err),
133 QL_OFF(nic_stats.rx_undersize_err)},
134 {"rx_preamble_err", QL_SIZEOF(nic_stats.rx_preamble_err),
135 QL_OFF(nic_stats.rx_preamble_err)},
136 {"rx_frame_len_err", QL_SIZEOF(nic_stats.rx_frame_len_err),
137 QL_OFF(nic_stats.rx_frame_len_err)},
138 {"rx_crc_err", QL_SIZEOF(nic_stats.rx_crc_err),
139 QL_OFF(nic_stats.rx_crc_err)},
140 {"rx_err_count", QL_SIZEOF(nic_stats.rx_err_count),
141 QL_OFF(nic_stats.rx_err_count)},
142 {"tx_cbfc_pause_frames0", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames0),
143 QL_OFF(nic_stats.tx_cbfc_pause_frames0)},
144 {"tx_cbfc_pause_frames1", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames1),
145 QL_OFF(nic_stats.tx_cbfc_pause_frames1)},
146 {"tx_cbfc_pause_frames2", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames2),
147 QL_OFF(nic_stats.tx_cbfc_pause_frames2)},
148 {"tx_cbfc_pause_frames3", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames3),
149 QL_OFF(nic_stats.tx_cbfc_pause_frames3)},
150 {"tx_cbfc_pause_frames4", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames4),
151 QL_OFF(nic_stats.tx_cbfc_pause_frames4)},
152 {"tx_cbfc_pause_frames5", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames5),
153 QL_OFF(nic_stats.tx_cbfc_pause_frames5)},
154 {"tx_cbfc_pause_frames6", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames6),
155 QL_OFF(nic_stats.tx_cbfc_pause_frames6)},
156 {"tx_cbfc_pause_frames7", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames7),
157 QL_OFF(nic_stats.tx_cbfc_pause_frames7)},
158 {"rx_cbfc_pause_frames0", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames0),
159 QL_OFF(nic_stats.rx_cbfc_pause_frames0)},
160 {"rx_cbfc_pause_frames1", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames1),
161 QL_OFF(nic_stats.rx_cbfc_pause_frames1)},
162 {"rx_cbfc_pause_frames2", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames2),
163 QL_OFF(nic_stats.rx_cbfc_pause_frames2)},
164 {"rx_cbfc_pause_frames3", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames3),
165 QL_OFF(nic_stats.rx_cbfc_pause_frames3)},
166 {"rx_cbfc_pause_frames4", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames4),
167 QL_OFF(nic_stats.rx_cbfc_pause_frames4)},
168 {"rx_cbfc_pause_frames5", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames5),
169 QL_OFF(nic_stats.rx_cbfc_pause_frames5)},
170 {"rx_cbfc_pause_frames6", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames6),
171 QL_OFF(nic_stats.rx_cbfc_pause_frames6)},
172 {"rx_cbfc_pause_frames7", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames7),
173 QL_OFF(nic_stats.rx_cbfc_pause_frames7)},
174 {"rx_nic_fifo_drop", QL_SIZEOF(nic_stats.rx_nic_fifo_drop),
175 QL_OFF(nic_stats.rx_nic_fifo_drop)},
178 static const char ql_gstrings_test[][ETH_GSTRING_LEN] = {
179 "Loopback test (offline)"
181 #define QLGE_TEST_LEN (sizeof(ql_gstrings_test) / ETH_GSTRING_LEN)
182 #define QLGE_STATS_LEN ARRAY_SIZE(ql_gstrings_stats)
183 #define QLGE_RCV_MAC_ERR_STATS 7
185 static int ql_update_ring_coalescing(struct ql_adapter *qdev)
188 struct rx_ring *rx_ring;
191 if (!netif_running(qdev->ndev))
194 /* Skip the default queue, and update the outbound handler
195 * queues if they changed.
197 cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
198 if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
199 le16_to_cpu(cqicb->pkt_delay) != qdev->tx_max_coalesced_frames) {
200 for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
201 rx_ring = &qdev->rx_ring[i];
202 cqicb = (struct cqicb *)rx_ring;
203 cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
205 cpu_to_le16(qdev->tx_max_coalesced_frames);
206 cqicb->flags = FLAGS_LI;
207 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
208 CFG_LCQ, rx_ring->cq_id);
210 netif_err(qdev, ifup, qdev->ndev,
211 "Failed to load CQICB.\n");
217 /* Update the inbound (RSS) handler queues if they changed. */
218 cqicb = (struct cqicb *)&qdev->rx_ring[0];
219 if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
220 le16_to_cpu(cqicb->pkt_delay) != qdev->rx_max_coalesced_frames) {
221 for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
222 rx_ring = &qdev->rx_ring[i];
223 cqicb = (struct cqicb *)rx_ring;
224 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
226 cpu_to_le16(qdev->rx_max_coalesced_frames);
227 cqicb->flags = FLAGS_LI;
228 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
229 CFG_LCQ, rx_ring->cq_id);
231 netif_err(qdev, ifup, qdev->ndev,
232 "Failed to load CQICB.\n");
241 static void ql_update_stats(struct ql_adapter *qdev)
245 u64 *iter = &qdev->nic_stats.tx_pkts;
247 spin_lock(&qdev->stats_lock);
248 if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
249 netif_err(qdev, drv, qdev->ndev,
250 "Couldn't get xgmac sem.\n");
256 for (i = 0x200; i < 0x280; i += 8) {
257 if (ql_read_xgmac_reg64(qdev, i, &data)) {
258 netif_err(qdev, drv, qdev->ndev,
259 "Error reading status register 0x%.04x.\n",
270 for (i = 0x300; i < 0x3d0; i += 8) {
271 if (ql_read_xgmac_reg64(qdev, i, &data)) {
272 netif_err(qdev, drv, qdev->ndev,
273 "Error reading status register 0x%.04x.\n",
281 /* Update receive mac error statistics */
282 iter += QLGE_RCV_MAC_ERR_STATS;
285 * Get Per-priority TX pause frame counter statistics.
287 for (i = 0x500; i < 0x540; i += 8) {
288 if (ql_read_xgmac_reg64(qdev, i, &data)) {
289 netif_err(qdev, drv, qdev->ndev,
290 "Error reading status register 0x%.04x.\n",
299 * Get Per-priority RX pause frame counter statistics.
301 for (i = 0x568; i < 0x5a8; i += 8) {
302 if (ql_read_xgmac_reg64(qdev, i, &data)) {
303 netif_err(qdev, drv, qdev->ndev,
304 "Error reading status register 0x%.04x.\n",
313 * Get RX NIC FIFO DROP statistics.
315 if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) {
316 netif_err(qdev, drv, qdev->ndev,
317 "Error reading status register 0x%.04x.\n", i);
322 ql_sem_unlock(qdev, qdev->xg_sem_mask);
324 spin_unlock(&qdev->stats_lock);
329 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
335 memcpy(buf, *ql_gstrings_test, QLGE_TEST_LEN * ETH_GSTRING_LEN);
338 for (index = 0; index < QLGE_STATS_LEN; index++) {
339 memcpy(buf + index * ETH_GSTRING_LEN,
340 ql_gstrings_stats[index].stat_string,
347 static int ql_get_sset_count(struct net_device *dev, int sset)
351 return QLGE_TEST_LEN;
353 return QLGE_STATS_LEN;
360 ql_get_ethtool_stats(struct net_device *ndev,
361 struct ethtool_stats *stats, u64 *data)
363 struct ql_adapter *qdev = netdev_priv(ndev);
366 length = QLGE_STATS_LEN;
367 ql_update_stats(qdev);
369 for (index = 0; index < length; index++) {
370 char *p = (char *)qdev +
371 ql_gstrings_stats[index].stat_offset;
372 *data++ = (ql_gstrings_stats[index].sizeof_stat ==
373 sizeof(u64)) ? *(u64 *)p : (*(u32 *)p);
377 static int ql_get_link_ksettings(struct net_device *ndev,
378 struct ethtool_link_ksettings *ecmd)
380 struct ql_adapter *qdev = netdev_priv(ndev);
381 u32 supported, advertising;
383 supported = SUPPORTED_10000baseT_Full;
384 advertising = ADVERTISED_10000baseT_Full;
386 if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
387 STS_LINK_TYPE_10GBASET) {
388 supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
389 advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
390 ecmd->base.port = PORT_TP;
391 ecmd->base.autoneg = AUTONEG_ENABLE;
393 supported |= SUPPORTED_FIBRE;
394 advertising |= ADVERTISED_FIBRE;
395 ecmd->base.port = PORT_FIBRE;
398 ecmd->base.speed = SPEED_10000;
399 ecmd->base.duplex = DUPLEX_FULL;
401 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
403 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.advertising,
409 static void ql_get_drvinfo(struct net_device *ndev,
410 struct ethtool_drvinfo *drvinfo)
412 struct ql_adapter *qdev = netdev_priv(ndev);
414 strlcpy(drvinfo->driver, qlge_driver_name, sizeof(drvinfo->driver));
415 strlcpy(drvinfo->version, qlge_driver_version,
416 sizeof(drvinfo->version));
417 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
419 (qdev->fw_rev_id & 0x00ff0000) >> 16,
420 (qdev->fw_rev_id & 0x0000ff00) >> 8,
421 (qdev->fw_rev_id & 0x000000ff));
422 strlcpy(drvinfo->bus_info, pci_name(qdev->pdev),
423 sizeof(drvinfo->bus_info));
426 static void ql_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
428 struct ql_adapter *qdev = netdev_priv(ndev);
429 unsigned short ssys_dev = qdev->pdev->subsystem_device;
431 /* WOL is only supported for mezz card. */
432 if (ssys_dev == QLGE_MEZZ_SSYS_ID_068 ||
433 ssys_dev == QLGE_MEZZ_SSYS_ID_180) {
434 wol->supported = WAKE_MAGIC;
435 wol->wolopts = qdev->wol;
439 static int ql_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
441 struct ql_adapter *qdev = netdev_priv(ndev);
442 unsigned short ssys_dev = qdev->pdev->subsystem_device;
444 /* WOL is only supported for mezz card. */
445 if (ssys_dev != QLGE_MEZZ_SSYS_ID_068 &&
446 ssys_dev != QLGE_MEZZ_SSYS_ID_180) {
447 netif_info(qdev, drv, qdev->ndev,
448 "WOL is only supported for mezz card\n");
451 if (wol->wolopts & ~WAKE_MAGIC)
453 qdev->wol = wol->wolopts;
455 netif_info(qdev, drv, qdev->ndev, "Set wol option 0x%x\n", qdev->wol);
459 static int ql_set_phys_id(struct net_device *ndev,
460 enum ethtool_phys_id_state state)
463 struct ql_adapter *qdev = netdev_priv(ndev);
466 case ETHTOOL_ID_ACTIVE:
467 /* Save the current LED settings */
468 if (ql_mb_get_led_cfg(qdev))
472 ql_mb_set_led_cfg(qdev, QL_LED_BLINK);
475 case ETHTOOL_ID_INACTIVE:
476 /* Restore LED settings */
477 if (ql_mb_set_led_cfg(qdev, qdev->led_config))
486 static int ql_start_loopback(struct ql_adapter *qdev)
488 if (netif_carrier_ok(qdev->ndev)) {
489 set_bit(QL_LB_LINK_UP, &qdev->flags);
490 netif_carrier_off(qdev->ndev);
492 clear_bit(QL_LB_LINK_UP, &qdev->flags);
493 qdev->link_config |= CFG_LOOPBACK_PCS;
494 return ql_mb_set_port_cfg(qdev);
497 static void ql_stop_loopback(struct ql_adapter *qdev)
499 qdev->link_config &= ~CFG_LOOPBACK_PCS;
500 ql_mb_set_port_cfg(qdev);
501 if (test_bit(QL_LB_LINK_UP, &qdev->flags)) {
502 netif_carrier_on(qdev->ndev);
503 clear_bit(QL_LB_LINK_UP, &qdev->flags);
507 static void ql_create_lb_frame(struct sk_buff *skb,
508 unsigned int frame_size)
510 memset(skb->data, 0xFF, frame_size);
512 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
513 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
514 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
517 void ql_check_lb_frame(struct ql_adapter *qdev,
520 unsigned int frame_size = skb->len;
522 if ((*(skb->data + 3) == 0xFF) &&
523 (*(skb->data + frame_size / 2 + 10) == 0xBE) &&
524 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
525 atomic_dec(&qdev->lb_count);
530 static int ql_run_loopback_test(struct ql_adapter *qdev)
535 unsigned int size = SMALL_BUF_MAP_SIZE;
537 for (i = 0; i < 64; i++) {
538 skb = netdev_alloc_skb(qdev->ndev, size);
542 skb->queue_mapping = 0;
544 ql_create_lb_frame(skb, size);
545 rc = ql_lb_send(skb, qdev->ndev);
546 if (rc != NETDEV_TX_OK)
548 atomic_inc(&qdev->lb_count);
550 /* Give queue time to settle before testing results. */
552 ql_clean_lb_rx_ring(&qdev->rx_ring[0], 128);
553 return atomic_read(&qdev->lb_count) ? -EIO : 0;
556 static int ql_loopback_test(struct ql_adapter *qdev, u64 *data)
558 *data = ql_start_loopback(qdev);
561 *data = ql_run_loopback_test(qdev);
563 ql_stop_loopback(qdev);
567 static void ql_self_test(struct net_device *ndev,
568 struct ethtool_test *eth_test, u64 *data)
570 struct ql_adapter *qdev = netdev_priv(ndev);
572 memset(data, 0, sizeof(u64) * QLGE_TEST_LEN);
574 if (netif_running(ndev)) {
575 set_bit(QL_SELFTEST, &qdev->flags);
576 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
578 if (ql_loopback_test(qdev, &data[0]))
579 eth_test->flags |= ETH_TEST_FL_FAILED;
585 clear_bit(QL_SELFTEST, &qdev->flags);
586 /* Give link time to come up after
587 * port configuration changes.
589 msleep_interruptible(4 * 1000);
591 netif_err(qdev, drv, qdev->ndev,
592 "is down, Loopback test will fail.\n");
593 eth_test->flags |= ETH_TEST_FL_FAILED;
597 static int ql_get_regs_len(struct net_device *ndev)
599 struct ql_adapter *qdev = netdev_priv(ndev);
601 if (!test_bit(QL_FRC_COREDUMP, &qdev->flags))
602 return sizeof(struct ql_mpi_coredump);
604 return sizeof(struct ql_reg_dump);
607 static void ql_get_regs(struct net_device *ndev,
608 struct ethtool_regs *regs, void *p)
610 struct ql_adapter *qdev = netdev_priv(ndev);
612 ql_get_dump(qdev, p);
613 qdev->core_is_dumped = 0;
614 if (!test_bit(QL_FRC_COREDUMP, &qdev->flags))
615 regs->len = sizeof(struct ql_mpi_coredump);
617 regs->len = sizeof(struct ql_reg_dump);
620 static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
622 struct ql_adapter *qdev = netdev_priv(dev);
624 c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
625 c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
627 /* This chip coalesces as follows:
628 * If a packet arrives, hold off interrupts until
629 * cqicb->int_delay expires, but if no other packets arrive don't
630 * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
631 * timer to coalesce on a frame basis. So, we have to take ethtool's
632 * max_coalesced_frames value and convert it to a delay in microseconds.
633 * We do this by using a basic thoughput of 1,000,000 frames per
634 * second @ (1024 bytes). This means one frame per usec. So it's a
635 * simple one to one ratio.
637 c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
638 c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
643 static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
645 struct ql_adapter *qdev = netdev_priv(ndev);
647 /* Validate user parameters. */
648 if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
650 /* Don't wait more than 10 usec. */
651 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
653 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
655 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
658 /* Verify a change took place before updating the hardware. */
659 if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
660 qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
661 qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
662 qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
665 qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
666 qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
667 qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
668 qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
670 return ql_update_ring_coalescing(qdev);
673 static void ql_get_pauseparam(struct net_device *netdev,
674 struct ethtool_pauseparam *pause)
676 struct ql_adapter *qdev = netdev_priv(netdev);
678 ql_mb_get_port_cfg(qdev);
679 if (qdev->link_config & CFG_PAUSE_STD) {
685 static int ql_set_pauseparam(struct net_device *netdev,
686 struct ethtool_pauseparam *pause)
688 struct ql_adapter *qdev = netdev_priv(netdev);
691 if ((pause->rx_pause) && (pause->tx_pause))
692 qdev->link_config |= CFG_PAUSE_STD;
693 else if (!pause->rx_pause && !pause->tx_pause)
694 qdev->link_config &= ~CFG_PAUSE_STD;
698 status = ql_mb_set_port_cfg(qdev);
702 static u32 ql_get_msglevel(struct net_device *ndev)
704 struct ql_adapter *qdev = netdev_priv(ndev);
706 return qdev->msg_enable;
709 static void ql_set_msglevel(struct net_device *ndev, u32 value)
711 struct ql_adapter *qdev = netdev_priv(ndev);
713 qdev->msg_enable = value;
716 const struct ethtool_ops qlge_ethtool_ops = {
717 .get_drvinfo = ql_get_drvinfo,
718 .get_wol = ql_get_wol,
719 .set_wol = ql_set_wol,
720 .get_regs_len = ql_get_regs_len,
721 .get_regs = ql_get_regs,
722 .get_msglevel = ql_get_msglevel,
723 .set_msglevel = ql_set_msglevel,
724 .get_link = ethtool_op_get_link,
725 .set_phys_id = ql_set_phys_id,
726 .self_test = ql_self_test,
727 .get_pauseparam = ql_get_pauseparam,
728 .set_pauseparam = ql_set_pauseparam,
729 .get_coalesce = ql_get_coalesce,
730 .set_coalesce = ql_set_coalesce,
731 .get_sset_count = ql_get_sset_count,
732 .get_strings = ql_get_strings,
733 .get_ethtool_stats = ql_get_ethtool_stats,
734 .get_link_ksettings = ql_get_link_ksettings,