OMAP3: PM: decouple PER and CORE context save and restore
[linux-ginger.git] / drivers / net / qlge / qlge_ethtool.c
blob52073946bce35cec6da556f032f1ae4c8b2cc746
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++;
135 end:
136 ql_sem_unlock(qdev, qdev->xg_sem_mask);
137 quit:
138 spin_unlock(&qdev->stats_lock);
140 QL_DUMP_STAT(qdev);
142 return;
145 static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
146 {"tx_pkts"},
147 {"tx_bytes"},
148 {"tx_mcast_pkts"},
149 {"tx_bcast_pkts"},
150 {"tx_ucast_pkts"},
151 {"tx_ctl_pkts"},
152 {"tx_pause_pkts"},
153 {"tx_64_pkts"},
154 {"tx_65_to_127_pkts"},
155 {"tx_128_to_255_pkts"},
156 {"tx_256_511_pkts"},
157 {"tx_512_to_1023_pkts"},
158 {"tx_1024_to_1518_pkts"},
159 {"tx_1519_to_max_pkts"},
160 {"tx_undersize_pkts"},
161 {"tx_oversize_pkts"},
162 {"rx_bytes"},
163 {"rx_bytes_ok"},
164 {"rx_pkts"},
165 {"rx_pkts_ok"},
166 {"rx_bcast_pkts"},
167 {"rx_mcast_pkts"},
168 {"rx_ucast_pkts"},
169 {"rx_undersize_pkts"},
170 {"rx_oversize_pkts"},
171 {"rx_jabber_pkts"},
172 {"rx_undersize_fcerr_pkts"},
173 {"rx_drop_events"},
174 {"rx_fcerr_pkts"},
175 {"rx_align_err"},
176 {"rx_symbol_err"},
177 {"rx_mac_err"},
178 {"rx_ctl_pkts"},
179 {"rx_pause_pkts"},
180 {"rx_64_pkts"},
181 {"rx_65_to_127_pkts"},
182 {"rx_128_255_pkts"},
183 {"rx_256_511_pkts"},
184 {"rx_512_to_1023_pkts"},
185 {"rx_1024_to_1518_pkts"},
186 {"rx_1519_to_max_pkts"},
187 {"rx_len_err_pkts"},
190 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
192 switch (stringset) {
193 case ETH_SS_STATS:
194 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
195 break;
199 static int ql_get_sset_count(struct net_device *dev, int sset)
201 switch (sset) {
202 case ETH_SS_STATS:
203 return ARRAY_SIZE(ql_stats_str_arr);
204 default:
205 return -EOPNOTSUPP;
209 static void
210 ql_get_ethtool_stats(struct net_device *ndev,
211 struct ethtool_stats *stats, u64 *data)
213 struct ql_adapter *qdev = netdev_priv(ndev);
214 struct nic_stats *s = &qdev->nic_stats;
216 ql_update_stats(qdev);
218 *data++ = s->tx_pkts;
219 *data++ = s->tx_bytes;
220 *data++ = s->tx_mcast_pkts;
221 *data++ = s->tx_bcast_pkts;
222 *data++ = s->tx_ucast_pkts;
223 *data++ = s->tx_ctl_pkts;
224 *data++ = s->tx_pause_pkts;
225 *data++ = s->tx_64_pkt;
226 *data++ = s->tx_65_to_127_pkt;
227 *data++ = s->tx_128_to_255_pkt;
228 *data++ = s->tx_256_511_pkt;
229 *data++ = s->tx_512_to_1023_pkt;
230 *data++ = s->tx_1024_to_1518_pkt;
231 *data++ = s->tx_1519_to_max_pkt;
232 *data++ = s->tx_undersize_pkt;
233 *data++ = s->tx_oversize_pkt;
234 *data++ = s->rx_bytes;
235 *data++ = s->rx_bytes_ok;
236 *data++ = s->rx_pkts;
237 *data++ = s->rx_pkts_ok;
238 *data++ = s->rx_bcast_pkts;
239 *data++ = s->rx_mcast_pkts;
240 *data++ = s->rx_ucast_pkts;
241 *data++ = s->rx_undersize_pkts;
242 *data++ = s->rx_oversize_pkts;
243 *data++ = s->rx_jabber_pkts;
244 *data++ = s->rx_undersize_fcerr_pkts;
245 *data++ = s->rx_drop_events;
246 *data++ = s->rx_fcerr_pkts;
247 *data++ = s->rx_align_err;
248 *data++ = s->rx_symbol_err;
249 *data++ = s->rx_mac_err;
250 *data++ = s->rx_ctl_pkts;
251 *data++ = s->rx_pause_pkts;
252 *data++ = s->rx_64_pkts;
253 *data++ = s->rx_65_to_127_pkts;
254 *data++ = s->rx_128_255_pkts;
255 *data++ = s->rx_256_511_pkts;
256 *data++ = s->rx_512_to_1023_pkts;
257 *data++ = s->rx_1024_to_1518_pkts;
258 *data++ = s->rx_1519_to_max_pkts;
259 *data++ = s->rx_len_err_pkts;
262 static int ql_get_settings(struct net_device *ndev,
263 struct ethtool_cmd *ecmd)
265 struct ql_adapter *qdev = netdev_priv(ndev);
267 ecmd->supported = SUPPORTED_10000baseT_Full;
268 ecmd->advertising = ADVERTISED_10000baseT_Full;
269 ecmd->autoneg = AUTONEG_ENABLE;
270 ecmd->transceiver = XCVR_EXTERNAL;
271 if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
272 STS_LINK_TYPE_10GBASET) {
273 ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
274 ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
275 ecmd->port = PORT_TP;
276 } else {
277 ecmd->supported |= SUPPORTED_FIBRE;
278 ecmd->advertising |= ADVERTISED_FIBRE;
279 ecmd->port = PORT_FIBRE;
282 ecmd->speed = SPEED_10000;
283 ecmd->duplex = DUPLEX_FULL;
285 return 0;
288 static void ql_get_drvinfo(struct net_device *ndev,
289 struct ethtool_drvinfo *drvinfo)
291 struct ql_adapter *qdev = netdev_priv(ndev);
292 strncpy(drvinfo->driver, qlge_driver_name, 32);
293 strncpy(drvinfo->version, qlge_driver_version, 32);
294 snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
295 (qdev->fw_rev_id & 0x00ff0000) >> 16,
296 (qdev->fw_rev_id & 0x0000ff00) >> 8,
297 (qdev->fw_rev_id & 0x000000ff));
298 strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
299 drvinfo->n_stats = 0;
300 drvinfo->testinfo_len = 0;
301 drvinfo->regdump_len = 0;
302 drvinfo->eedump_len = 0;
305 static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
307 struct ql_adapter *qdev = netdev_priv(dev);
309 c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
310 c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
312 /* This chip coalesces as follows:
313 * If a packet arrives, hold off interrupts until
314 * cqicb->int_delay expires, but if no other packets arrive don't
315 * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
316 * timer to coalesce on a frame basis. So, we have to take ethtool's
317 * max_coalesced_frames value and convert it to a delay in microseconds.
318 * We do this by using a basic thoughput of 1,000,000 frames per
319 * second @ (1024 bytes). This means one frame per usec. So it's a
320 * simple one to one ratio.
322 c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
323 c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
325 return 0;
328 static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
330 struct ql_adapter *qdev = netdev_priv(ndev);
332 /* Validate user parameters. */
333 if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
334 return -EINVAL;
335 /* Don't wait more than 10 usec. */
336 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
337 return -EINVAL;
338 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
339 return -EINVAL;
340 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
341 return -EINVAL;
343 /* Verify a change took place before updating the hardware. */
344 if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
345 qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
346 qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
347 qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
348 return 0;
350 qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
351 qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
352 qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
353 qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
355 return ql_update_ring_coalescing(qdev);
358 static u32 ql_get_rx_csum(struct net_device *netdev)
360 struct ql_adapter *qdev = netdev_priv(netdev);
361 return qdev->rx_csum;
364 static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
366 struct ql_adapter *qdev = netdev_priv(netdev);
367 qdev->rx_csum = data;
368 return 0;
371 static int ql_set_tso(struct net_device *ndev, uint32_t data)
374 if (data) {
375 ndev->features |= NETIF_F_TSO;
376 ndev->features |= NETIF_F_TSO6;
377 } else {
378 ndev->features &= ~NETIF_F_TSO;
379 ndev->features &= ~NETIF_F_TSO6;
381 return 0;
384 static u32 ql_get_msglevel(struct net_device *ndev)
386 struct ql_adapter *qdev = netdev_priv(ndev);
387 return qdev->msg_enable;
390 static void ql_set_msglevel(struct net_device *ndev, u32 value)
392 struct ql_adapter *qdev = netdev_priv(ndev);
393 qdev->msg_enable = value;
396 const struct ethtool_ops qlge_ethtool_ops = {
397 .get_settings = ql_get_settings,
398 .get_drvinfo = ql_get_drvinfo,
399 .get_msglevel = ql_get_msglevel,
400 .set_msglevel = ql_set_msglevel,
401 .get_link = ethtool_op_get_link,
402 .get_rx_csum = ql_get_rx_csum,
403 .set_rx_csum = ql_set_rx_csum,
404 .get_tx_csum = ethtool_op_get_tx_csum,
405 .set_tx_csum = ethtool_op_set_tx_csum,
406 .get_sg = ethtool_op_get_sg,
407 .set_sg = ethtool_op_set_sg,
408 .get_tso = ethtool_op_get_tso,
409 .set_tso = ql_set_tso,
410 .get_coalesce = ql_get_coalesce,
411 .set_coalesce = ql_set_coalesce,
412 .get_sset_count = ql_get_sset_count,
413 .get_strings = ql_get_strings,
414 .get_ethtool_stats = ql_get_ethtool_stats,