[XFS] Fix merge failures
[pandora-kernel.git] / drivers / net / qlge / qlge_ethtool.c
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>
35
36 #include <linux/version.h>
37
38 #include "qlge.h"
39
40 static int ql_update_ring_coalescing(struct ql_adapter *qdev)
41 {
42         int i, status = 0;
43         struct rx_ring *rx_ring;
44         struct cqicb *cqicb;
45
46         if (!netif_running(qdev->ndev))
47                 return status;
48
49         spin_lock(&qdev->hw_lock);
50         /* Skip the default queue, and update the outbound handler
51          * queues if they changed.
52          */
53         cqicb = (struct cqicb *)&qdev->rx_ring[1];
54         if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
55             le16_to_cpu(cqicb->pkt_delay) != qdev->tx_max_coalesced_frames) {
56                 for (i = 1; i < qdev->rss_ring_first_cq_id; i++, rx_ring++) {
57                         rx_ring = &qdev->rx_ring[i];
58                         cqicb = (struct cqicb *)rx_ring;
59                         cqicb->irq_delay = le16_to_cpu(qdev->tx_coalesce_usecs);
60                         cqicb->pkt_delay =
61                             le16_to_cpu(qdev->tx_max_coalesced_frames);
62                         cqicb->flags = FLAGS_LI;
63                         status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
64                                                 CFG_LCQ, rx_ring->cq_id);
65                         if (status) {
66                                 QPRINTK(qdev, IFUP, ERR,
67                                         "Failed to load CQICB.\n");
68                                 goto exit;
69                         }
70                 }
71         }
72
73         /* Update the inbound (RSS) handler queues if they changed. */
74         cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_first_cq_id];
75         if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
76             le16_to_cpu(cqicb->pkt_delay) != qdev->rx_max_coalesced_frames) {
77                 for (i = qdev->rss_ring_first_cq_id;
78                      i <= qdev->rss_ring_first_cq_id + qdev->rss_ring_count;
79                      i++) {
80                         rx_ring = &qdev->rx_ring[i];
81                         cqicb = (struct cqicb *)rx_ring;
82                         cqicb->irq_delay = le16_to_cpu(qdev->rx_coalesce_usecs);
83                         cqicb->pkt_delay =
84                             le16_to_cpu(qdev->rx_max_coalesced_frames);
85                         cqicb->flags = FLAGS_LI;
86                         status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
87                                                 CFG_LCQ, rx_ring->cq_id);
88                         if (status) {
89                                 QPRINTK(qdev, IFUP, ERR,
90                                         "Failed to load CQICB.\n");
91                                 goto exit;
92                         }
93                 }
94         }
95 exit:
96         spin_unlock(&qdev->hw_lock);
97         return status;
98 }
99
100 static void ql_update_stats(struct ql_adapter *qdev)
101 {
102         u32 i;
103         u64 data;
104         u64 *iter = &qdev->nic_stats.tx_pkts;
105
106         spin_lock(&qdev->stats_lock);
107         if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
108                         QPRINTK(qdev, DRV, ERR,
109                                 "Couldn't get xgmac sem.\n");
110                 goto quit;
111         }
112         /*
113          * Get TX statistics.
114          */
115         for (i = 0x200; i < 0x280; i += 8) {
116                 if (ql_read_xgmac_reg64(qdev, i, &data)) {
117                         QPRINTK(qdev, DRV, ERR,
118                                 "Error reading status register 0x%.04x.\n", i);
119                         goto end;
120                 } else
121                         *iter = data;
122                 iter++;
123         }
124
125         /*
126          * Get RX statistics.
127          */
128         for (i = 0x300; i < 0x3d0; i += 8) {
129                 if (ql_read_xgmac_reg64(qdev, i, &data)) {
130                         QPRINTK(qdev, DRV, ERR,
131                                 "Error reading status register 0x%.04x.\n", i);
132                         goto end;
133                 } else
134                         *iter = data;
135                 iter++;
136         }
137
138 end:
139         ql_sem_unlock(qdev, qdev->xg_sem_mask);
140 quit:
141         spin_unlock(&qdev->stats_lock);
142
143         QL_DUMP_STAT(qdev);
144
145         return;
146 }
147
148 static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
149         {"tx_pkts"},
150         {"tx_bytes"},
151         {"tx_mcast_pkts"},
152         {"tx_bcast_pkts"},
153         {"tx_ucast_pkts"},
154         {"tx_ctl_pkts"},
155         {"tx_pause_pkts"},
156         {"tx_64_pkts"},
157         {"tx_65_to_127_pkts"},
158         {"tx_128_to_255_pkts"},
159         {"tx_256_511_pkts"},
160         {"tx_512_to_1023_pkts"},
161         {"tx_1024_to_1518_pkts"},
162         {"tx_1519_to_max_pkts"},
163         {"tx_undersize_pkts"},
164         {"tx_oversize_pkts"},
165         {"rx_bytes"},
166         {"rx_bytes_ok"},
167         {"rx_pkts"},
168         {"rx_pkts_ok"},
169         {"rx_bcast_pkts"},
170         {"rx_mcast_pkts"},
171         {"rx_ucast_pkts"},
172         {"rx_undersize_pkts"},
173         {"rx_oversize_pkts"},
174         {"rx_jabber_pkts"},
175         {"rx_undersize_fcerr_pkts"},
176         {"rx_drop_events"},
177         {"rx_fcerr_pkts"},
178         {"rx_align_err"},
179         {"rx_symbol_err"},
180         {"rx_mac_err"},
181         {"rx_ctl_pkts"},
182         {"rx_pause_pkts"},
183         {"rx_64_pkts"},
184         {"rx_65_to_127_pkts"},
185         {"rx_128_255_pkts"},
186         {"rx_256_511_pkts"},
187         {"rx_512_to_1023_pkts"},
188         {"rx_1024_to_1518_pkts"},
189         {"rx_1519_to_max_pkts"},
190         {"rx_len_err_pkts"},
191 };
192
193 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
194 {
195         switch (stringset) {
196         case ETH_SS_STATS:
197                 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
198                 break;
199         }
200 }
201
202 static int ql_get_sset_count(struct net_device *dev, int sset)
203 {
204         switch (sset) {
205         case ETH_SS_STATS:
206                 return ARRAY_SIZE(ql_stats_str_arr);
207         default:
208                 return -EOPNOTSUPP;
209         }
210 }
211
212 static void
213 ql_get_ethtool_stats(struct net_device *ndev,
214                      struct ethtool_stats *stats, u64 *data)
215 {
216         struct ql_adapter *qdev = netdev_priv(ndev);
217         struct nic_stats *s = &qdev->nic_stats;
218
219         ql_update_stats(qdev);
220
221         *data++ = s->tx_pkts;
222         *data++ = s->tx_bytes;
223         *data++ = s->tx_mcast_pkts;
224         *data++ = s->tx_bcast_pkts;
225         *data++ = s->tx_ucast_pkts;
226         *data++ = s->tx_ctl_pkts;
227         *data++ = s->tx_pause_pkts;
228         *data++ = s->tx_64_pkt;
229         *data++ = s->tx_65_to_127_pkt;
230         *data++ = s->tx_128_to_255_pkt;
231         *data++ = s->tx_256_511_pkt;
232         *data++ = s->tx_512_to_1023_pkt;
233         *data++ = s->tx_1024_to_1518_pkt;
234         *data++ = s->tx_1519_to_max_pkt;
235         *data++ = s->tx_undersize_pkt;
236         *data++ = s->tx_oversize_pkt;
237         *data++ = s->rx_bytes;
238         *data++ = s->rx_bytes_ok;
239         *data++ = s->rx_pkts;
240         *data++ = s->rx_pkts_ok;
241         *data++ = s->rx_bcast_pkts;
242         *data++ = s->rx_mcast_pkts;
243         *data++ = s->rx_ucast_pkts;
244         *data++ = s->rx_undersize_pkts;
245         *data++ = s->rx_oversize_pkts;
246         *data++ = s->rx_jabber_pkts;
247         *data++ = s->rx_undersize_fcerr_pkts;
248         *data++ = s->rx_drop_events;
249         *data++ = s->rx_fcerr_pkts;
250         *data++ = s->rx_align_err;
251         *data++ = s->rx_symbol_err;
252         *data++ = s->rx_mac_err;
253         *data++ = s->rx_ctl_pkts;
254         *data++ = s->rx_pause_pkts;
255         *data++ = s->rx_64_pkts;
256         *data++ = s->rx_65_to_127_pkts;
257         *data++ = s->rx_128_255_pkts;
258         *data++ = s->rx_256_511_pkts;
259         *data++ = s->rx_512_to_1023_pkts;
260         *data++ = s->rx_1024_to_1518_pkts;
261         *data++ = s->rx_1519_to_max_pkts;
262         *data++ = s->rx_len_err_pkts;
263 }
264
265 static int ql_get_settings(struct net_device *ndev,
266                               struct ethtool_cmd *ecmd)
267 {
268         struct ql_adapter *qdev = netdev_priv(ndev);
269
270         ecmd->supported = SUPPORTED_10000baseT_Full;
271         ecmd->advertising = ADVERTISED_10000baseT_Full;
272         ecmd->autoneg = AUTONEG_ENABLE;
273         ecmd->transceiver = XCVR_EXTERNAL;
274         if ((qdev->link_status & LINK_TYPE_MASK) == 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;
282         }
283
284         ecmd->speed = SPEED_10000;
285         ecmd->duplex = DUPLEX_FULL;
286
287         return 0;
288 }
289
290 static void ql_get_drvinfo(struct net_device *ndev,
291                            struct ethtool_drvinfo *drvinfo)
292 {
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         strncpy(drvinfo->fw_version, "N/A", 32);
297         strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
298         drvinfo->n_stats = 0;
299         drvinfo->testinfo_len = 0;
300         drvinfo->regdump_len = 0;
301         drvinfo->eedump_len = 0;
302 }
303
304 static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
305 {
306         struct ql_adapter *qdev = netdev_priv(dev);
307
308         c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
309         c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
310
311         /* This chip coalesces as follows:
312          * If a packet arrives, hold off interrupts until
313          * cqicb->int_delay expires, but if no other packets arrive don't
314          * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
315          * timer to coalesce on a frame basis.  So, we have to take ethtool's
316          * max_coalesced_frames value and convert it to a delay in microseconds.
317          * We do this by using a basic thoughput of 1,000,000 frames per
318          * second @ (1024 bytes).  This means one frame per usec. So it's a
319          * simple one to one ratio.
320          */
321         c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
322         c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
323
324         return 0;
325 }
326
327 static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
328 {
329         struct ql_adapter *qdev = netdev_priv(ndev);
330
331         /* Validate user parameters. */
332         if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
333                 return -EINVAL;
334        /* Don't wait more than 10 usec. */
335         if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
336                 return -EINVAL;
337         if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
338                 return -EINVAL;
339         if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
340                 return -EINVAL;
341
342         /* Verify a change took place before updating the hardware. */
343         if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
344             qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
345             qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
346             qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
347                 return 0;
348
349         qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
350         qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
351         qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
352         qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
353
354         return ql_update_ring_coalescing(qdev);
355 }
356
357 static u32 ql_get_rx_csum(struct net_device *netdev)
358 {
359         struct ql_adapter *qdev = netdev_priv(netdev);
360         return qdev->rx_csum;
361 }
362
363 static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
364 {
365         struct ql_adapter *qdev = netdev_priv(netdev);
366         qdev->rx_csum = data;
367         return 0;
368 }
369
370 static int ql_set_tso(struct net_device *ndev, uint32_t data)
371 {
372
373         if (data) {
374                 ndev->features |= NETIF_F_TSO;
375                 ndev->features |= NETIF_F_TSO6;
376         } else {
377                 ndev->features &= ~NETIF_F_TSO;
378                 ndev->features &= ~NETIF_F_TSO6;
379         }
380         return 0;
381 }
382
383 static u32 ql_get_msglevel(struct net_device *ndev)
384 {
385         struct ql_adapter *qdev = netdev_priv(ndev);
386         return qdev->msg_enable;
387 }
388
389 static void ql_set_msglevel(struct net_device *ndev, u32 value)
390 {
391         struct ql_adapter *qdev = netdev_priv(ndev);
392         qdev->msg_enable = value;
393 }
394
395 const struct ethtool_ops qlge_ethtool_ops = {
396         .get_settings = ql_get_settings,
397         .get_drvinfo = ql_get_drvinfo,
398         .get_msglevel = ql_get_msglevel,
399         .set_msglevel = ql_set_msglevel,
400         .get_link = ethtool_op_get_link,
401         .get_rx_csum = ql_get_rx_csum,
402         .set_rx_csum = ql_set_rx_csum,
403         .get_tx_csum = ethtool_op_get_tx_csum,
404         .get_sg = ethtool_op_get_sg,
405         .set_sg = ethtool_op_set_sg,
406         .get_tso = ethtool_op_get_tso,
407         .set_tso = ql_set_tso,
408         .get_coalesce = ql_get_coalesce,
409         .set_coalesce = ql_set_coalesce,
410         .get_sset_count = ql_get_sset_count,
411         .get_strings = ql_get_strings,
412         .get_ethtool_stats = ql_get_ethtool_stats,
413 };
414