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>
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>
20 #include <linux/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>
34 #include <linux/vmalloc.h>
39 static int ql_update_ring_coalescing(struct ql_adapter *qdev)
42 struct rx_ring *rx_ring;
45 if (!netif_running(qdev->ndev))
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);
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);
65 QPRINTK(qdev, IFUP, ERR,
66 "Failed to load CQICB.\n");
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;
79 rx_ring = &qdev->rx_ring[i];
80 cqicb = (struct cqicb *)rx_ring;
81 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
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);
88 QPRINTK(qdev, IFUP, ERR,
89 "Failed to load CQICB.\n");
95 spin_unlock(&qdev->hw_lock);
99 static void ql_update_stats(struct ql_adapter *qdev)
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");
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);
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);
138 ql_sem_unlock(qdev, qdev->xg_sem_mask);
140 spin_unlock(&qdev->stats_lock);
147 static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
156 {"tx_65_to_127_pkts"},
157 {"tx_128_to_255_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"},
171 {"rx_undersize_pkts"},
172 {"rx_oversize_pkts"},
174 {"rx_undersize_fcerr_pkts"},
183 {"rx_65_to_127_pkts"},
186 {"rx_512_to_1023_pkts"},
187 {"rx_1024_to_1518_pkts"},
188 {"rx_1519_to_max_pkts"},
192 static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
196 memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
201 static int ql_get_sset_count(struct net_device *dev, int sset)
205 return ARRAY_SIZE(ql_stats_str_arr);
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;
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;
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;
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)
337 /* Don't wait more than 10 usec. */
338 if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
340 if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
342 if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
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)
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;
373 static int ql_set_tso(struct net_device *ndev, uint32_t data)
377 ndev->features |= NETIF_F_TSO;
378 ndev->features |= NETIF_F_TSO6;
380 ndev->features &= ~NETIF_F_TSO;
381 ndev->features &= ~NETIF_F_TSO6;
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,