blob: dfb5c800cea21bf30419da2e21b649056b9b1ee2 [file] [log] [blame]
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001#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>
Ron Mercerc4e84bd2008-09-18 11:56:28 -040032#include <linux/delay.h>
33#include <linux/mm.h>
34#include <linux/vmalloc.h>
35
Ron Mercerc4e84bd2008-09-18 11:56:28 -040036
37#include "qlge.h"
38
39static int ql_update_ring_coalescing(struct ql_adapter *qdev)
40{
41 int i, status = 0;
42 struct rx_ring *rx_ring;
43 struct cqicb *cqicb;
44
45 if (!netif_running(qdev->ndev))
46 return status;
47
Ron Mercerc4e84bd2008-09-18 11:56:28 -040048 /* Skip the default queue, and update the outbound handler
49 * queues if they changed.
50 */
Ron Mercerb2014ff2009-08-27 11:02:09 +000051 cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
Ron Mercerc4e84bd2008-09-18 11:56:28 -040052 if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
Ron Mercerb2014ff2009-08-27 11:02:09 +000053 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++) {
Ron Mercerc4e84bd2008-09-18 11:56:28 -040056 rx_ring = &qdev->rx_ring[i];
57 cqicb = (struct cqicb *)rx_ring;
Ron Mercer8306c952009-01-05 18:17:33 -080058 cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
Ron Mercerc4e84bd2008-09-18 11:56:28 -040059 cqicb->pkt_delay =
Ron Mercer8306c952009-01-05 18:17:33 -080060 cpu_to_le16(qdev->tx_max_coalesced_frames);
Ron Mercerc4e84bd2008-09-18 11:56:28 -040061 cqicb->flags = FLAGS_LI;
Ron Mercere3324712009-07-02 06:06:13 +000062 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
Ron Mercerc4e84bd2008-09-18 11:56:28 -040063 CFG_LCQ, rx_ring->cq_id);
64 if (status) {
65 QPRINTK(qdev, IFUP, ERR,
66 "Failed to load CQICB.\n");
67 goto exit;
68 }
69 }
70 }
71
72 /* Update the inbound (RSS) handler queues if they changed. */
Ron Mercerb2014ff2009-08-27 11:02:09 +000073 cqicb = (struct cqicb *)&qdev->rx_ring[0];
Ron Mercerc4e84bd2008-09-18 11:56:28 -040074 if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
Ron Mercerb2014ff2009-08-27 11:02:09 +000075 le16_to_cpu(cqicb->pkt_delay) !=
76 qdev->rx_max_coalesced_frames) {
77 for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
Ron Mercerc4e84bd2008-09-18 11:56:28 -040078 rx_ring = &qdev->rx_ring[i];
79 cqicb = (struct cqicb *)rx_ring;
Ron Mercer8306c952009-01-05 18:17:33 -080080 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
Ron Mercerc4e84bd2008-09-18 11:56:28 -040081 cqicb->pkt_delay =
Ron Mercer8306c952009-01-05 18:17:33 -080082 cpu_to_le16(qdev->rx_max_coalesced_frames);
Ron Mercerc4e84bd2008-09-18 11:56:28 -040083 cqicb->flags = FLAGS_LI;
Ron Mercere3324712009-07-02 06:06:13 +000084 status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
Ron Mercerc4e84bd2008-09-18 11:56:28 -040085 CFG_LCQ, rx_ring->cq_id);
86 if (status) {
87 QPRINTK(qdev, IFUP, ERR,
88 "Failed to load CQICB.\n");
89 goto exit;
90 }
91 }
92 }
93exit:
Ron Mercerc4e84bd2008-09-18 11:56:28 -040094 return status;
95}
96
Hannes Eder2f22d222008-12-26 00:04:53 -080097static void ql_update_stats(struct ql_adapter *qdev)
Ron Mercerc4e84bd2008-09-18 11:56:28 -040098{
99 u32 i;
100 u64 data;
101 u64 *iter = &qdev->nic_stats.tx_pkts;
102
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;
108 }
109 /*
110 * Get TX statistics.
111 */
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++;
120 }
121
122 /*
123 * Get RX statistics.
124 */
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++;
133 }
134
Ron Mercer6abd2342009-10-10 09:35:10 +0000135 /*
136 * Get Per-priority TX pause frame counter statistics.
137 */
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++;
146 }
147
148 /*
149 * Get Per-priority RX pause frame counter statistics.
150 */
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++;
159 }
160
161 /*
162 * Get RX NIC FIFO DROP statistics.
163 */
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;
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400170end:
171 ql_sem_unlock(qdev, qdev->xg_sem_mask);
172quit:
173 spin_unlock(&qdev->stats_lock);
174
175 QL_DUMP_STAT(qdev);
176
177 return;
178}
179
180static 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"},
Ron Mercer6abd2342009-10-10 09:35:10 +0000223 {"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"},
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400240};
241
242static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
243{
244 switch (stringset) {
245 case ETH_SS_STATS:
246 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
247 break;
248 }
249}
250
251static int ql_get_sset_count(struct net_device *dev, int sset)
252{
253 switch (sset) {
254 case ETH_SS_STATS:
255 return ARRAY_SIZE(ql_stats_str_arr);
256 default:
257 return -EOPNOTSUPP;
258 }
259}
260
261static void
262ql_get_ethtool_stats(struct net_device *ndev,
263 struct ethtool_stats *stats, u64 *data)
264{
265 struct ql_adapter *qdev = netdev_priv(ndev);
266 struct nic_stats *s = &qdev->nic_stats;
267
268 ql_update_stats(qdev);
269
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;
Ron Mercer6abd2342009-10-10 09:35:10 +0000312 *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;
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400329}
330
331static int ql_get_settings(struct net_device *ndev,
332 struct ethtool_cmd *ecmd)
333{
334 struct ql_adapter *qdev = netdev_priv(ndev);
335
336 ecmd->supported = SUPPORTED_10000baseT_Full;
337 ecmd->advertising = ADVERTISED_10000baseT_Full;
338 ecmd->autoneg = AUTONEG_ENABLE;
339 ecmd->transceiver = XCVR_EXTERNAL;
Ron Mercerb82808b2009-02-26 10:08:32 +0000340 if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
341 STS_LINK_TYPE_10GBASET) {
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400342 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;
349 }
350
351 ecmd->speed = SPEED_10000;
352 ecmd->duplex = DUPLEX_FULL;
353
354 return 0;
355}
356
357static void ql_get_drvinfo(struct net_device *ndev,
358 struct ethtool_drvinfo *drvinfo)
359{
360 struct ql_adapter *qdev = netdev_priv(ndev);
361 strncpy(drvinfo->driver, qlge_driver_name, 32);
362 strncpy(drvinfo->version, qlge_driver_version, 32);
Ron Mercercfec0cb2009-06-09 05:39:29 +0000363 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));
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400367 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;
372}
373
374static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
375{
376 struct ql_adapter *qdev = netdev_priv(dev);
377
378 c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
379 c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
380
381 /* This chip coalesces as follows:
382 * If a packet arrives, hold off interrupts until
383 * cqicb->int_delay expires, but if no other packets arrive don't
384 * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
385 * timer to coalesce on a frame basis. So, we have to take ethtool's
386 * max_coalesced_frames value and convert it to a delay in microseconds.
387 * We do this by using a basic thoughput of 1,000,000 frames per
388 * second @ (1024 bytes). This means one frame per usec. So it's a
389 * simple one to one ratio.
390 */
391 c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
392 c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
393
394 return 0;
395}
396
397static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
398{
399 struct ql_adapter *qdev = netdev_priv(ndev);
400
401 /* Validate user parameters. */
402 if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
403 return -EINVAL;
404 /* Don't wait more than 10 usec. */
405 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
406 return -EINVAL;
407 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
408 return -EINVAL;
409 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
410 return -EINVAL;
411
412 /* Verify a change took place before updating the hardware. */
413 if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
414 qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
415 qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
416 qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
417 return 0;
418
419 qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
420 qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
421 qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
422 qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
423
424 return ql_update_ring_coalescing(qdev);
425}
426
Ron Mercer1d30df22009-10-21 11:07:38 +0000427static void ql_get_pauseparam(struct net_device *netdev,
428 struct ethtool_pauseparam *pause)
429{
430 struct ql_adapter *qdev = netdev_priv(netdev);
431
432 ql_mb_get_port_cfg(qdev);
433 if (qdev->link_config & CFG_PAUSE_STD) {
434 pause->rx_pause = 1;
435 pause->tx_pause = 1;
436 }
437}
438
439static int ql_set_pauseparam(struct net_device *netdev,
440 struct ethtool_pauseparam *pause)
441{
442 struct ql_adapter *qdev = netdev_priv(netdev);
443 int status = 0;
444
445 if ((pause->rx_pause) && (pause->tx_pause))
446 qdev->link_config |= CFG_PAUSE_STD;
447 else if (!pause->rx_pause && !pause->tx_pause)
448 qdev->link_config &= ~CFG_PAUSE_STD;
449 else
450 return -EINVAL;
451
452 status = ql_mb_set_port_cfg(qdev);
453 if (status)
454 return status;
455 return status;
456}
457
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400458static u32 ql_get_rx_csum(struct net_device *netdev)
459{
460 struct ql_adapter *qdev = netdev_priv(netdev);
461 return qdev->rx_csum;
462}
463
464static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
465{
466 struct ql_adapter *qdev = netdev_priv(netdev);
467 qdev->rx_csum = data;
468 return 0;
469}
470
471static int ql_set_tso(struct net_device *ndev, uint32_t data)
472{
473
474 if (data) {
475 ndev->features |= NETIF_F_TSO;
476 ndev->features |= NETIF_F_TSO6;
477 } else {
478 ndev->features &= ~NETIF_F_TSO;
479 ndev->features &= ~NETIF_F_TSO6;
480 }
481 return 0;
482}
483
484static u32 ql_get_msglevel(struct net_device *ndev)
485{
486 struct ql_adapter *qdev = netdev_priv(ndev);
487 return qdev->msg_enable;
488}
489
490static void ql_set_msglevel(struct net_device *ndev, u32 value)
491{
492 struct ql_adapter *qdev = netdev_priv(ndev);
493 qdev->msg_enable = value;
494}
495
496const struct ethtool_ops qlge_ethtool_ops = {
497 .get_settings = ql_get_settings,
498 .get_drvinfo = ql_get_drvinfo,
499 .get_msglevel = ql_get_msglevel,
500 .set_msglevel = ql_set_msglevel,
501 .get_link = ethtool_op_get_link,
Ron Mercer1d30df22009-10-21 11:07:38 +0000502 .get_pauseparam = ql_get_pauseparam,
503 .set_pauseparam = ql_set_pauseparam,
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400504 .get_rx_csum = ql_get_rx_csum,
505 .set_rx_csum = ql_set_rx_csum,
506 .get_tx_csum = ethtool_op_get_tx_csum,
Ron Mercer00acd0d2009-06-09 05:39:31 +0000507 .set_tx_csum = ethtool_op_set_tx_csum,
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400508 .get_sg = ethtool_op_get_sg,
509 .set_sg = ethtool_op_set_sg,
510 .get_tso = ethtool_op_get_tso,
511 .set_tso = ql_set_tso,
512 .get_coalesce = ql_get_coalesce,
513 .set_coalesce = ql_set_coalesce,
514 .get_sset_count = ql_get_sset_count,
515 .get_strings = ql_get_strings,
516 .get_ethtool_stats = ql_get_ethtool_stats,
517};
518