qlge: Add ethtool wake on LAN function.
[linux-2.6.git] / drivers / net / qlge / qlge_ethtool.c
blob019f35fb10c1acb297a310d31ea0689602cb4353
1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/types.h>
4 #include <linux/module.h>
5 #include <linux/list.h>
6 #include <linux/pci.h>
7 #include <linux/dma-mapping.h>
8 #include <linux/pagemap.h>
9 #include <linux/sched.h>
10 #include <linux/slab.h>
11 #include <linux/dmapool.h>
12 #include <linux/mempool.h>
13 #include <linux/spinlock.h>
14 #include <linux/kthread.h>
15 #include <linux/interrupt.h>
16 #include <linux/errno.h>
17 #include <linux/ioport.h>
18 #include <linux/in.h>
19 #include <linux/ip.h>
20 #include <linux/ipv6.h>
21 #include <net/ipv6.h>
22 #include <linux/tcp.h>
23 #include <linux/udp.h>
24 #include <linux/if_arp.h>
25 #include <linux/if_ether.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ethtool.h>
29 #include <linux/skbuff.h>
30 #include <linux/rtnetlink.h>
31 #include <linux/if_vlan.h>
32 #include <linux/delay.h>
33 #include <linux/mm.h>
34 #include <linux/vmalloc.h>
37 #include "qlge.h"
39 static int ql_update_ring_coalescing(struct ql_adapter *qdev)
41 int i, status = 0;
42 struct rx_ring *rx_ring;
43 struct cqicb *cqicb;
45 if (!netif_running(qdev->ndev))
46 return status;
48 /* Skip the default queue, and update the outbound handler
49 * queues if they changed.
51 cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
52 if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
53 le16_to_cpu(cqicb->pkt_delay) !=
54 qdev->tx_max_coalesced_frames) {
55 for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
56 rx_ring = &qdev->rx_ring[i];
57 cqicb = (struct cqicb *)rx_ring;
58 cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
59 cqicb->pkt_delay =
60 cpu_to_le16(qdev->tx_max_coalesced_frames);
61 cqicb->flags = FLAGS_LI;
62 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
63 CFG_LCQ, rx_ring->cq_id);
64 if (status) {
65 QPRINTK(qdev, IFUP, ERR,
66 "Failed to load CQICB.\n");
67 goto exit;
72 /* Update the inbound (RSS) handler queues if they changed. */
73 cqicb = (struct cqicb *)&qdev->rx_ring[0];
74 if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
75 le16_to_cpu(cqicb->pkt_delay) !=
76 qdev->rx_max_coalesced_frames) {
77 for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
78 rx_ring = &qdev->rx_ring[i];
79 cqicb = (struct cqicb *)rx_ring;
80 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
81 cqicb->pkt_delay =
82 cpu_to_le16(qdev->rx_max_coalesced_frames);
83 cqicb->flags = FLAGS_LI;
84 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
85 CFG_LCQ, rx_ring->cq_id);
86 if (status) {
87 QPRINTK(qdev, IFUP, ERR,
88 "Failed to load CQICB.\n");
89 goto exit;
93 exit:
94 return status;
97 static void ql_update_stats(struct ql_adapter *qdev)
99 u32 i;
100 u64 data;
101 u64 *iter = &qdev->nic_stats.tx_pkts;
103 spin_lock(&qdev->stats_lock);
104 if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
105 QPRINTK(qdev, DRV, ERR,
106 "Couldn't get xgmac sem.\n");
107 goto quit;
110 * Get TX statistics.
112 for (i = 0x200; i < 0x280; i += 8) {
113 if (ql_read_xgmac_reg64(qdev, i, &data)) {
114 QPRINTK(qdev, DRV, ERR,
115 "Error reading status register 0x%.04x.\n", i);
116 goto end;
117 } else
118 *iter = data;
119 iter++;
123 * Get RX statistics.
125 for (i = 0x300; i < 0x3d0; i += 8) {
126 if (ql_read_xgmac_reg64(qdev, i, &data)) {
127 QPRINTK(qdev, DRV, ERR,
128 "Error reading status register 0x%.04x.\n", i);
129 goto end;
130 } else
131 *iter = data;
132 iter++;
136 * Get Per-priority TX pause frame counter statistics.
138 for (i = 0x500; i < 0x540; i += 8) {
139 if (ql_read_xgmac_reg64(qdev, i, &data)) {
140 QPRINTK(qdev, DRV, ERR,
141 "Error reading status register 0x%.04x.\n", i);
142 goto end;
143 } else
144 *iter = data;
145 iter++;
149 * Get Per-priority RX pause frame counter statistics.
151 for (i = 0x568; i < 0x5a8; i += 8) {
152 if (ql_read_xgmac_reg64(qdev, i, &data)) {
153 QPRINTK(qdev, DRV, ERR,
154 "Error reading status register 0x%.04x.\n", i);
155 goto end;
156 } else
157 *iter = data;
158 iter++;
162 * Get RX NIC FIFO DROP statistics.
164 if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) {
165 QPRINTK(qdev, DRV, ERR,
166 "Error reading status register 0x%.04x.\n", i);
167 goto end;
168 } else
169 *iter = data;
170 end:
171 ql_sem_unlock(qdev, qdev->xg_sem_mask);
172 quit:
173 spin_unlock(&qdev->stats_lock);
175 QL_DUMP_STAT(qdev);
177 return;
180 static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
181 {"tx_pkts"},
182 {"tx_bytes"},
183 {"tx_mcast_pkts"},
184 {"tx_bcast_pkts"},
185 {"tx_ucast_pkts"},
186 {"tx_ctl_pkts"},
187 {"tx_pause_pkts"},
188 {"tx_64_pkts"},
189 {"tx_65_to_127_pkts"},
190 {"tx_128_to_255_pkts"},
191 {"tx_256_511_pkts"},
192 {"tx_512_to_1023_pkts"},
193 {"tx_1024_to_1518_pkts"},
194 {"tx_1519_to_max_pkts"},
195 {"tx_undersize_pkts"},
196 {"tx_oversize_pkts"},
197 {"rx_bytes"},
198 {"rx_bytes_ok"},
199 {"rx_pkts"},
200 {"rx_pkts_ok"},
201 {"rx_bcast_pkts"},
202 {"rx_mcast_pkts"},
203 {"rx_ucast_pkts"},
204 {"rx_undersize_pkts"},
205 {"rx_oversize_pkts"},
206 {"rx_jabber_pkts"},
207 {"rx_undersize_fcerr_pkts"},
208 {"rx_drop_events"},
209 {"rx_fcerr_pkts"},
210 {"rx_align_err"},
211 {"rx_symbol_err"},
212 {"rx_mac_err"},
213 {"rx_ctl_pkts"},
214 {"rx_pause_pkts"},
215 {"rx_64_pkts"},
216 {"rx_65_to_127_pkts"},
217 {"rx_128_255_pkts"},
218 {"rx_256_511_pkts"},
219 {"rx_512_to_1023_pkts"},
220 {"rx_1024_to_1518_pkts"},
221 {"rx_1519_to_max_pkts"},
222 {"rx_len_err_pkts"},
223 {"tx_cbfc_pause_frames0"},
224 {"tx_cbfc_pause_frames1"},
225 {"tx_cbfc_pause_frames2"},
226 {"tx_cbfc_pause_frames3"},
227 {"tx_cbfc_pause_frames4"},
228 {"tx_cbfc_pause_frames5"},
229 {"tx_cbfc_pause_frames6"},
230 {"tx_cbfc_pause_frames7"},
231 {"rx_cbfc_pause_frames0"},
232 {"rx_cbfc_pause_frames1"},
233 {"rx_cbfc_pause_frames2"},
234 {"rx_cbfc_pause_frames3"},
235 {"rx_cbfc_pause_frames4"},
236 {"rx_cbfc_pause_frames5"},
237 {"rx_cbfc_pause_frames6"},
238 {"rx_cbfc_pause_frames7"},
239 {"rx_nic_fifo_drop"},
242 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
244 switch (stringset) {
245 case ETH_SS_STATS:
246 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
247 break;
251 static int ql_get_sset_count(struct net_device *dev, int sset)
253 switch (sset) {
254 case ETH_SS_STATS:
255 return ARRAY_SIZE(ql_stats_str_arr);
256 default:
257 return -EOPNOTSUPP;
261 static void
262 ql_get_ethtool_stats(struct net_device *ndev,
263 struct ethtool_stats *stats, u64 *data)
265 struct ql_adapter *qdev = netdev_priv(ndev);
266 struct nic_stats *s = &qdev->nic_stats;
268 ql_update_stats(qdev);
270 *data++ = s->tx_pkts;
271 *data++ = s->tx_bytes;
272 *data++ = s->tx_mcast_pkts;
273 *data++ = s->tx_bcast_pkts;
274 *data++ = s->tx_ucast_pkts;
275 *data++ = s->tx_ctl_pkts;
276 *data++ = s->tx_pause_pkts;
277 *data++ = s->tx_64_pkt;
278 *data++ = s->tx_65_to_127_pkt;
279 *data++ = s->tx_128_to_255_pkt;
280 *data++ = s->tx_256_511_pkt;
281 *data++ = s->tx_512_to_1023_pkt;
282 *data++ = s->tx_1024_to_1518_pkt;
283 *data++ = s->tx_1519_to_max_pkt;
284 *data++ = s->tx_undersize_pkt;
285 *data++ = s->tx_oversize_pkt;
286 *data++ = s->rx_bytes;
287 *data++ = s->rx_bytes_ok;
288 *data++ = s->rx_pkts;
289 *data++ = s->rx_pkts_ok;
290 *data++ = s->rx_bcast_pkts;
291 *data++ = s->rx_mcast_pkts;
292 *data++ = s->rx_ucast_pkts;
293 *data++ = s->rx_undersize_pkts;
294 *data++ = s->rx_oversize_pkts;
295 *data++ = s->rx_jabber_pkts;
296 *data++ = s->rx_undersize_fcerr_pkts;
297 *data++ = s->rx_drop_events;
298 *data++ = s->rx_fcerr_pkts;
299 *data++ = s->rx_align_err;
300 *data++ = s->rx_symbol_err;
301 *data++ = s->rx_mac_err;
302 *data++ = s->rx_ctl_pkts;
303 *data++ = s->rx_pause_pkts;
304 *data++ = s->rx_64_pkts;
305 *data++ = s->rx_65_to_127_pkts;
306 *data++ = s->rx_128_255_pkts;
307 *data++ = s->rx_256_511_pkts;
308 *data++ = s->rx_512_to_1023_pkts;
309 *data++ = s->rx_1024_to_1518_pkts;
310 *data++ = s->rx_1519_to_max_pkts;
311 *data++ = s->rx_len_err_pkts;
312 *data++ = s->tx_cbfc_pause_frames0;
313 *data++ = s->tx_cbfc_pause_frames1;
314 *data++ = s->tx_cbfc_pause_frames2;
315 *data++ = s->tx_cbfc_pause_frames3;
316 *data++ = s->tx_cbfc_pause_frames4;
317 *data++ = s->tx_cbfc_pause_frames5;
318 *data++ = s->tx_cbfc_pause_frames6;
319 *data++ = s->tx_cbfc_pause_frames7;
320 *data++ = s->rx_cbfc_pause_frames0;
321 *data++ = s->rx_cbfc_pause_frames1;
322 *data++ = s->rx_cbfc_pause_frames2;
323 *data++ = s->rx_cbfc_pause_frames3;
324 *data++ = s->rx_cbfc_pause_frames4;
325 *data++ = s->rx_cbfc_pause_frames5;
326 *data++ = s->rx_cbfc_pause_frames6;
327 *data++ = s->rx_cbfc_pause_frames7;
328 *data++ = s->rx_nic_fifo_drop;
331 static int ql_get_settings(struct net_device *ndev,
332 struct ethtool_cmd *ecmd)
334 struct ql_adapter *qdev = netdev_priv(ndev);
336 ecmd->supported = SUPPORTED_10000baseT_Full;
337 ecmd->advertising = ADVERTISED_10000baseT_Full;
338 ecmd->autoneg = AUTONEG_ENABLE;
339 ecmd->transceiver = XCVR_EXTERNAL;
340 if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
341 STS_LINK_TYPE_10GBASET) {
342 ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
343 ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
344 ecmd->port = PORT_TP;
345 } else {
346 ecmd->supported |= SUPPORTED_FIBRE;
347 ecmd->advertising |= ADVERTISED_FIBRE;
348 ecmd->port = PORT_FIBRE;
351 ecmd->speed = SPEED_10000;
352 ecmd->duplex = DUPLEX_FULL;
354 return 0;
357 static void ql_get_drvinfo(struct net_device *ndev,
358 struct ethtool_drvinfo *drvinfo)
360 struct ql_adapter *qdev = netdev_priv(ndev);
361 strncpy(drvinfo->driver, qlge_driver_name, 32);
362 strncpy(drvinfo->version, qlge_driver_version, 32);
363 snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
364 (qdev->fw_rev_id & 0x00ff0000) >> 16,
365 (qdev->fw_rev_id & 0x0000ff00) >> 8,
366 (qdev->fw_rev_id & 0x000000ff));
367 strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
368 drvinfo->n_stats = 0;
369 drvinfo->testinfo_len = 0;
370 drvinfo->regdump_len = 0;
371 drvinfo->eedump_len = 0;
374 static void ql_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
376 struct ql_adapter *qdev = netdev_priv(ndev);
377 /* What we support. */
378 wol->supported = WAKE_MAGIC;
379 /* What we've currently got set. */
380 wol->wolopts = qdev->wol;
383 static int ql_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
385 struct ql_adapter *qdev = netdev_priv(ndev);
386 int status;
388 if (wol->wolopts & ~WAKE_MAGIC)
389 return -EINVAL;
390 qdev->wol = wol->wolopts;
392 QPRINTK(qdev, DRV, INFO, "Set wol option 0x%x on %s\n",
393 qdev->wol, ndev->name);
394 if (!qdev->wol) {
395 u32 wol = 0;
396 status = ql_mb_wol_mode(qdev, wol);
397 QPRINTK(qdev, DRV, ERR, "WOL %s (wol code 0x%x) on %s\n",
398 (status == 0) ? "cleared sucessfully" : "clear failed",
399 wol, qdev->ndev->name);
402 return 0;
405 static int ql_phys_id(struct net_device *ndev, u32 data)
407 struct ql_adapter *qdev = netdev_priv(ndev);
408 u32 led_reg, i;
409 int status;
411 /* Save the current LED settings */
412 status = ql_mb_get_led_cfg(qdev);
413 if (status)
414 return status;
415 led_reg = qdev->led_config;
417 /* Start blinking the led */
418 if (!data || data > 300)
419 data = 300;
421 for (i = 0; i < (data * 10); i++)
422 ql_mb_set_led_cfg(qdev, QL_LED_BLINK);
424 /* Restore LED settings */
425 status = ql_mb_set_led_cfg(qdev, led_reg);
426 if (status)
427 return status;
429 return 0;
431 static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
433 struct ql_adapter *qdev = netdev_priv(dev);
435 c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
436 c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
438 /* This chip coalesces as follows:
439 * If a packet arrives, hold off interrupts until
440 * cqicb->int_delay expires, but if no other packets arrive don't
441 * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
442 * timer to coalesce on a frame basis. So, we have to take ethtool's
443 * max_coalesced_frames value and convert it to a delay in microseconds.
444 * We do this by using a basic thoughput of 1,000,000 frames per
445 * second @ (1024 bytes). This means one frame per usec. So it's a
446 * simple one to one ratio.
448 c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
449 c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
451 return 0;
454 static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
456 struct ql_adapter *qdev = netdev_priv(ndev);
458 /* Validate user parameters. */
459 if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
460 return -EINVAL;
461 /* Don't wait more than 10 usec. */
462 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
463 return -EINVAL;
464 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
465 return -EINVAL;
466 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
467 return -EINVAL;
469 /* Verify a change took place before updating the hardware. */
470 if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
471 qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
472 qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
473 qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
474 return 0;
476 qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
477 qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
478 qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
479 qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
481 return ql_update_ring_coalescing(qdev);
484 static void ql_get_pauseparam(struct net_device *netdev,
485 struct ethtool_pauseparam *pause)
487 struct ql_adapter *qdev = netdev_priv(netdev);
489 ql_mb_get_port_cfg(qdev);
490 if (qdev->link_config & CFG_PAUSE_STD) {
491 pause->rx_pause = 1;
492 pause->tx_pause = 1;
496 static int ql_set_pauseparam(struct net_device *netdev,
497 struct ethtool_pauseparam *pause)
499 struct ql_adapter *qdev = netdev_priv(netdev);
500 int status = 0;
502 if ((pause->rx_pause) && (pause->tx_pause))
503 qdev->link_config |= CFG_PAUSE_STD;
504 else if (!pause->rx_pause && !pause->tx_pause)
505 qdev->link_config &= ~CFG_PAUSE_STD;
506 else
507 return -EINVAL;
509 status = ql_mb_set_port_cfg(qdev);
510 if (status)
511 return status;
512 return status;
515 static u32 ql_get_rx_csum(struct net_device *netdev)
517 struct ql_adapter *qdev = netdev_priv(netdev);
518 return qdev->rx_csum;
521 static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
523 struct ql_adapter *qdev = netdev_priv(netdev);
524 qdev->rx_csum = data;
525 return 0;
528 static int ql_set_tso(struct net_device *ndev, uint32_t data)
531 if (data) {
532 ndev->features |= NETIF_F_TSO;
533 ndev->features |= NETIF_F_TSO6;
534 } else {
535 ndev->features &= ~NETIF_F_TSO;
536 ndev->features &= ~NETIF_F_TSO6;
538 return 0;
541 static u32 ql_get_msglevel(struct net_device *ndev)
543 struct ql_adapter *qdev = netdev_priv(ndev);
544 return qdev->msg_enable;
547 static void ql_set_msglevel(struct net_device *ndev, u32 value)
549 struct ql_adapter *qdev = netdev_priv(ndev);
550 qdev->msg_enable = value;
553 const struct ethtool_ops qlge_ethtool_ops = {
554 .get_settings = ql_get_settings,
555 .get_drvinfo = ql_get_drvinfo,
556 .get_wol = ql_get_wol,
557 .set_wol = ql_set_wol,
558 .get_msglevel = ql_get_msglevel,
559 .set_msglevel = ql_set_msglevel,
560 .get_link = ethtool_op_get_link,
561 .phys_id = ql_phys_id,
562 .get_pauseparam = ql_get_pauseparam,
563 .set_pauseparam = ql_set_pauseparam,
564 .get_rx_csum = ql_get_rx_csum,
565 .set_rx_csum = ql_set_rx_csum,
566 .get_tx_csum = ethtool_op_get_tx_csum,
567 .set_tx_csum = ethtool_op_set_tx_csum,
568 .get_sg = ethtool_op_get_sg,
569 .set_sg = ethtool_op_set_sg,
570 .get_tso = ethtool_op_get_tso,
571 .set_tso = ql_set_tso,
572 .get_coalesce = ql_get_coalesce,
573 .set_coalesce = ql_set_coalesce,
574 .get_sset_count = ql_get_sset_count,
575 .get_strings = ql_get_strings,
576 .get_ethtool_stats = ql_get_ethtool_stats,