x86, delay: tsc based udelay should have rdtsc_barrier
[linux-2.6/mini2440.git] / drivers / net / qlge / qlge_ethtool.c
blob37c99fe79770fc78de8c6a9cec9c15a743f50bef
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 spin_lock(&qdev->hw_lock);
49 /* Skip the default queue, and update the outbound handler
50 * queues if they changed.
52 cqicb = (struct cqicb *)&qdev->rx_ring[1];
53 if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
54 le16_to_cpu(cqicb->pkt_delay) != qdev->tx_max_coalesced_frames) {
55 for (i = 1; i < qdev->rss_ring_first_cq_id; i++, rx_ring++) {
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[qdev->rss_ring_first_cq_id];
74 if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
75 le16_to_cpu(cqicb->pkt_delay) != qdev->rx_max_coalesced_frames) {
76 for (i = qdev->rss_ring_first_cq_id;
77 i <= qdev->rss_ring_first_cq_id + qdev->rss_ring_count;
78 i++) {
79 rx_ring = &qdev->rx_ring[i];
80 cqicb = (struct cqicb *)rx_ring;
81 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
82 cqicb->pkt_delay =
83 cpu_to_le16(qdev->rx_max_coalesced_frames);
84 cqicb->flags = FLAGS_LI;
85 status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
86 CFG_LCQ, rx_ring->cq_id);
87 if (status) {
88 QPRINTK(qdev, IFUP, ERR,
89 "Failed to load CQICB.\n");
90 goto exit;
94 exit:
95 spin_unlock(&qdev->hw_lock);
96 return status;
99 static void ql_update_stats(struct ql_adapter *qdev)
101 u32 i;
102 u64 data;
103 u64 *iter = &qdev->nic_stats.tx_pkts;
105 spin_lock(&qdev->stats_lock);
106 if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
107 QPRINTK(qdev, DRV, ERR,
108 "Couldn't get xgmac sem.\n");
109 goto quit;
112 * Get TX statistics.
114 for (i = 0x200; i < 0x280; i += 8) {
115 if (ql_read_xgmac_reg64(qdev, i, &data)) {
116 QPRINTK(qdev, DRV, ERR,
117 "Error reading status register 0x%.04x.\n", i);
118 goto end;
119 } else
120 *iter = data;
121 iter++;
125 * Get RX statistics.
127 for (i = 0x300; i < 0x3d0; i += 8) {
128 if (ql_read_xgmac_reg64(qdev, i, &data)) {
129 QPRINTK(qdev, DRV, ERR,
130 "Error reading status register 0x%.04x.\n", i);
131 goto end;
132 } else
133 *iter = data;
134 iter++;
137 end:
138 ql_sem_unlock(qdev, qdev->xg_sem_mask);
139 quit:
140 spin_unlock(&qdev->stats_lock);
142 QL_DUMP_STAT(qdev);
144 return;
147 static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
148 {"tx_pkts"},
149 {"tx_bytes"},
150 {"tx_mcast_pkts"},
151 {"tx_bcast_pkts"},
152 {"tx_ucast_pkts"},
153 {"tx_ctl_pkts"},
154 {"tx_pause_pkts"},
155 {"tx_64_pkts"},
156 {"tx_65_to_127_pkts"},
157 {"tx_128_to_255_pkts"},
158 {"tx_256_511_pkts"},
159 {"tx_512_to_1023_pkts"},
160 {"tx_1024_to_1518_pkts"},
161 {"tx_1519_to_max_pkts"},
162 {"tx_undersize_pkts"},
163 {"tx_oversize_pkts"},
164 {"rx_bytes"},
165 {"rx_bytes_ok"},
166 {"rx_pkts"},
167 {"rx_pkts_ok"},
168 {"rx_bcast_pkts"},
169 {"rx_mcast_pkts"},
170 {"rx_ucast_pkts"},
171 {"rx_undersize_pkts"},
172 {"rx_oversize_pkts"},
173 {"rx_jabber_pkts"},
174 {"rx_undersize_fcerr_pkts"},
175 {"rx_drop_events"},
176 {"rx_fcerr_pkts"},
177 {"rx_align_err"},
178 {"rx_symbol_err"},
179 {"rx_mac_err"},
180 {"rx_ctl_pkts"},
181 {"rx_pause_pkts"},
182 {"rx_64_pkts"},
183 {"rx_65_to_127_pkts"},
184 {"rx_128_255_pkts"},
185 {"rx_256_511_pkts"},
186 {"rx_512_to_1023_pkts"},
187 {"rx_1024_to_1518_pkts"},
188 {"rx_1519_to_max_pkts"},
189 {"rx_len_err_pkts"},
192 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
194 switch (stringset) {
195 case ETH_SS_STATS:
196 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
197 break;
201 static int ql_get_sset_count(struct net_device *dev, int sset)
203 switch (sset) {
204 case ETH_SS_STATS:
205 return ARRAY_SIZE(ql_stats_str_arr);
206 default:
207 return -EOPNOTSUPP;
211 static void
212 ql_get_ethtool_stats(struct net_device *ndev,
213 struct ethtool_stats *stats, u64 *data)
215 struct ql_adapter *qdev = netdev_priv(ndev);
216 struct nic_stats *s = &qdev->nic_stats;
218 ql_update_stats(qdev);
220 *data++ = s->tx_pkts;
221 *data++ = s->tx_bytes;
222 *data++ = s->tx_mcast_pkts;
223 *data++ = s->tx_bcast_pkts;
224 *data++ = s->tx_ucast_pkts;
225 *data++ = s->tx_ctl_pkts;
226 *data++ = s->tx_pause_pkts;
227 *data++ = s->tx_64_pkt;
228 *data++ = s->tx_65_to_127_pkt;
229 *data++ = s->tx_128_to_255_pkt;
230 *data++ = s->tx_256_511_pkt;
231 *data++ = s->tx_512_to_1023_pkt;
232 *data++ = s->tx_1024_to_1518_pkt;
233 *data++ = s->tx_1519_to_max_pkt;
234 *data++ = s->tx_undersize_pkt;
235 *data++ = s->tx_oversize_pkt;
236 *data++ = s->rx_bytes;
237 *data++ = s->rx_bytes_ok;
238 *data++ = s->rx_pkts;
239 *data++ = s->rx_pkts_ok;
240 *data++ = s->rx_bcast_pkts;
241 *data++ = s->rx_mcast_pkts;
242 *data++ = s->rx_ucast_pkts;
243 *data++ = s->rx_undersize_pkts;
244 *data++ = s->rx_oversize_pkts;
245 *data++ = s->rx_jabber_pkts;
246 *data++ = s->rx_undersize_fcerr_pkts;
247 *data++ = s->rx_drop_events;
248 *data++ = s->rx_fcerr_pkts;
249 *data++ = s->rx_align_err;
250 *data++ = s->rx_symbol_err;
251 *data++ = s->rx_mac_err;
252 *data++ = s->rx_ctl_pkts;
253 *data++ = s->rx_pause_pkts;
254 *data++ = s->rx_64_pkts;
255 *data++ = s->rx_65_to_127_pkts;
256 *data++ = s->rx_128_255_pkts;
257 *data++ = s->rx_256_511_pkts;
258 *data++ = s->rx_512_to_1023_pkts;
259 *data++ = s->rx_1024_to_1518_pkts;
260 *data++ = s->rx_1519_to_max_pkts;
261 *data++ = s->rx_len_err_pkts;
264 static int ql_get_settings(struct net_device *ndev,
265 struct ethtool_cmd *ecmd)
267 struct ql_adapter *qdev = netdev_priv(ndev);
269 ecmd->supported = SUPPORTED_10000baseT_Full;
270 ecmd->advertising = ADVERTISED_10000baseT_Full;
271 ecmd->autoneg = AUTONEG_ENABLE;
272 ecmd->transceiver = XCVR_EXTERNAL;
273 if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
274 STS_LINK_TYPE_10GBASET) {
275 ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
276 ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
277 ecmd->port = PORT_TP;
278 } else {
279 ecmd->supported |= SUPPORTED_FIBRE;
280 ecmd->advertising |= ADVERTISED_FIBRE;
281 ecmd->port = PORT_FIBRE;
284 ecmd->speed = SPEED_10000;
285 ecmd->duplex = DUPLEX_FULL;
287 return 0;
290 static void ql_get_drvinfo(struct net_device *ndev,
291 struct ethtool_drvinfo *drvinfo)
293 struct ql_adapter *qdev = netdev_priv(ndev);
294 strncpy(drvinfo->driver, qlge_driver_name, 32);
295 strncpy(drvinfo->version, qlge_driver_version, 32);
296 snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
297 (qdev->fw_rev_id & 0x00ff0000) >> 16,
298 (qdev->fw_rev_id & 0x0000ff00) >> 8,
299 (qdev->fw_rev_id & 0x000000ff));
300 strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
301 drvinfo->n_stats = 0;
302 drvinfo->testinfo_len = 0;
303 drvinfo->regdump_len = 0;
304 drvinfo->eedump_len = 0;
307 static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
309 struct ql_adapter *qdev = netdev_priv(dev);
311 c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
312 c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
314 /* This chip coalesces as follows:
315 * If a packet arrives, hold off interrupts until
316 * cqicb->int_delay expires, but if no other packets arrive don't
317 * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
318 * timer to coalesce on a frame basis. So, we have to take ethtool's
319 * max_coalesced_frames value and convert it to a delay in microseconds.
320 * We do this by using a basic thoughput of 1,000,000 frames per
321 * second @ (1024 bytes). This means one frame per usec. So it's a
322 * simple one to one ratio.
324 c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
325 c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
327 return 0;
330 static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
332 struct ql_adapter *qdev = netdev_priv(ndev);
334 /* Validate user parameters. */
335 if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
336 return -EINVAL;
337 /* Don't wait more than 10 usec. */
338 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
339 return -EINVAL;
340 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
341 return -EINVAL;
342 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
343 return -EINVAL;
345 /* Verify a change took place before updating the hardware. */
346 if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
347 qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
348 qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
349 qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
350 return 0;
352 qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
353 qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
354 qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
355 qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
357 return ql_update_ring_coalescing(qdev);
360 static u32 ql_get_rx_csum(struct net_device *netdev)
362 struct ql_adapter *qdev = netdev_priv(netdev);
363 return qdev->rx_csum;
366 static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
368 struct ql_adapter *qdev = netdev_priv(netdev);
369 qdev->rx_csum = data;
370 return 0;
373 static int ql_set_tso(struct net_device *ndev, uint32_t data)
376 if (data) {
377 ndev->features |= NETIF_F_TSO;
378 ndev->features |= NETIF_F_TSO6;
379 } else {
380 ndev->features &= ~NETIF_F_TSO;
381 ndev->features &= ~NETIF_F_TSO6;
383 return 0;
386 static u32 ql_get_msglevel(struct net_device *ndev)
388 struct ql_adapter *qdev = netdev_priv(ndev);
389 return qdev->msg_enable;
392 static void ql_set_msglevel(struct net_device *ndev, u32 value)
394 struct ql_adapter *qdev = netdev_priv(ndev);
395 qdev->msg_enable = value;
398 const struct ethtool_ops qlge_ethtool_ops = {
399 .get_settings = ql_get_settings,
400 .get_drvinfo = ql_get_drvinfo,
401 .get_msglevel = ql_get_msglevel,
402 .set_msglevel = ql_set_msglevel,
403 .get_link = ethtool_op_get_link,
404 .get_rx_csum = ql_get_rx_csum,
405 .set_rx_csum = ql_set_rx_csum,
406 .get_tx_csum = ethtool_op_get_tx_csum,
407 .set_tx_csum = ethtool_op_set_tx_csum,
408 .get_sg = ethtool_op_get_sg,
409 .set_sg = ethtool_op_set_sg,
410 .get_tso = ethtool_op_get_tso,
411 .set_tso = ql_set_tso,
412 .get_coalesce = ql_get_coalesce,
413 .set_coalesce = ql_set_coalesce,
414 .get_sset_count = ql_get_sset_count,
415 .get_strings = ql_get_strings,
416 .get_ethtool_stats = ql_get_ethtool_stats,