Commit | Line | Data |
---|---|---|
c4e84bde RM |
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> | |
c4e84bde RM |
32 | #include <linux/delay.h> |
33 | #include <linux/mm.h> | |
34 | #include <linux/vmalloc.h> | |
35 | ||
c4e84bde RM |
36 | |
37 | #include "qlge.h" | |
38 | ||
39 | static 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 | ||
48 | spin_lock(&qdev->hw_lock); | |
49 | /* Skip the default queue, and update the outbound handler | |
50 | * queues if they changed. | |
51 | */ | |
b2014ff8 | 52 | cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count]; |
c4e84bde | 53 | if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs || |
b2014ff8 RM |
54 | le16_to_cpu(cqicb->pkt_delay) != |
55 | qdev->tx_max_coalesced_frames) { | |
56 | for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) { | |
c4e84bde RM |
57 | rx_ring = &qdev->rx_ring[i]; |
58 | cqicb = (struct cqicb *)rx_ring; | |
8306c952 | 59 | cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs); |
c4e84bde | 60 | cqicb->pkt_delay = |
8306c952 | 61 | cpu_to_le16(qdev->tx_max_coalesced_frames); |
c4e84bde | 62 | cqicb->flags = FLAGS_LI; |
e332471c | 63 | status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb), |
c4e84bde RM |
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. */ | |
b2014ff8 | 74 | cqicb = (struct cqicb *)&qdev->rx_ring[0]; |
c4e84bde | 75 | if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs || |
b2014ff8 RM |
76 | le16_to_cpu(cqicb->pkt_delay) != |
77 | qdev->rx_max_coalesced_frames) { | |
78 | for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) { | |
c4e84bde RM |
79 | rx_ring = &qdev->rx_ring[i]; |
80 | cqicb = (struct cqicb *)rx_ring; | |
8306c952 | 81 | cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs); |
c4e84bde | 82 | cqicb->pkt_delay = |
8306c952 | 83 | cpu_to_le16(qdev->rx_max_coalesced_frames); |
c4e84bde | 84 | cqicb->flags = FLAGS_LI; |
e332471c | 85 | status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb), |
c4e84bde RM |
86 | CFG_LCQ, rx_ring->cq_id); |
87 | if (status) { | |
88 | QPRINTK(qdev, IFUP, ERR, | |
89 | "Failed to load CQICB.\n"); | |
90 | goto exit; | |
91 | } | |
92 | } | |
93 | } | |
94 | exit: | |
95 | spin_unlock(&qdev->hw_lock); | |
96 | return status; | |
97 | } | |
98 | ||
2f22d22e | 99 | static void ql_update_stats(struct ql_adapter *qdev) |
c4e84bde RM |
100 | { |
101 | u32 i; | |
102 | u64 data; | |
103 | u64 *iter = &qdev->nic_stats.tx_pkts; | |
104 | ||
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; | |
110 | } | |
111 | /* | |
112 | * Get TX statistics. | |
113 | */ | |
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++; | |
122 | } | |
123 | ||
124 | /* | |
125 | * Get RX statistics. | |
126 | */ | |
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++; | |
135 | } | |
136 | ||
137 | end: | |
138 | ql_sem_unlock(qdev, qdev->xg_sem_mask); | |
139 | quit: | |
140 | spin_unlock(&qdev->stats_lock); | |
141 | ||
142 | QL_DUMP_STAT(qdev); | |
143 | ||
144 | return; | |
145 | } | |
146 | ||
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"}, | |
190 | }; | |
191 | ||
192 | static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf) | |
193 | { | |
194 | switch (stringset) { | |
195 | case ETH_SS_STATS: | |
196 | memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr)); | |
197 | break; | |
198 | } | |
199 | } | |
200 | ||
201 | static int ql_get_sset_count(struct net_device *dev, int sset) | |
202 | { | |
203 | switch (sset) { | |
204 | case ETH_SS_STATS: | |
205 | return ARRAY_SIZE(ql_stats_str_arr); | |
206 | default: | |
207 | return -EOPNOTSUPP; | |
208 | } | |
209 | } | |
210 | ||
211 | static void | |
212 | ql_get_ethtool_stats(struct net_device *ndev, | |
213 | struct ethtool_stats *stats, u64 *data) | |
214 | { | |
215 | struct ql_adapter *qdev = netdev_priv(ndev); | |
216 | struct nic_stats *s = &qdev->nic_stats; | |
217 | ||
218 | ql_update_stats(qdev); | |
219 | ||
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; | |
262 | } | |
263 | ||
264 | static int ql_get_settings(struct net_device *ndev, | |
265 | struct ethtool_cmd *ecmd) | |
266 | { | |
267 | struct ql_adapter *qdev = netdev_priv(ndev); | |
268 | ||
269 | ecmd->supported = SUPPORTED_10000baseT_Full; | |
270 | ecmd->advertising = ADVERTISED_10000baseT_Full; | |
271 | ecmd->autoneg = AUTONEG_ENABLE; | |
272 | ecmd->transceiver = XCVR_EXTERNAL; | |
b82808b7 RM |
273 | if ((qdev->link_status & STS_LINK_TYPE_MASK) == |
274 | STS_LINK_TYPE_10GBASET) { | |
c4e84bde RM |
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); | |
cfec0cbc RM |
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)); | |
c4e84bde RM |
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; | |
305 | } | |
306 | ||
307 | static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c) | |
308 | { | |
309 | struct ql_adapter *qdev = netdev_priv(dev); | |
310 | ||
311 | c->rx_coalesce_usecs = qdev->rx_coalesce_usecs; | |
312 | c->tx_coalesce_usecs = qdev->tx_coalesce_usecs; | |
313 | ||
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. | |
323 | */ | |
324 | c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames; | |
325 | c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames; | |
326 | ||
327 | return 0; | |
328 | } | |
329 | ||
330 | static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c) | |
331 | { | |
332 | struct ql_adapter *qdev = netdev_priv(ndev); | |
333 | ||
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; | |
344 | ||
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; | |
351 | ||
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; | |
356 | ||
357 | return ql_update_ring_coalescing(qdev); | |
358 | } | |
359 | ||
360 | static u32 ql_get_rx_csum(struct net_device *netdev) | |
361 | { | |
362 | struct ql_adapter *qdev = netdev_priv(netdev); | |
363 | return qdev->rx_csum; | |
364 | } | |
365 | ||
366 | static int ql_set_rx_csum(struct net_device *netdev, uint32_t data) | |
367 | { | |
368 | struct ql_adapter *qdev = netdev_priv(netdev); | |
369 | qdev->rx_csum = data; | |
370 | return 0; | |
371 | } | |
372 | ||
373 | static int ql_set_tso(struct net_device *ndev, uint32_t data) | |
374 | { | |
375 | ||
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; | |
382 | } | |
383 | return 0; | |
384 | } | |
385 | ||
386 | static u32 ql_get_msglevel(struct net_device *ndev) | |
387 | { | |
388 | struct ql_adapter *qdev = netdev_priv(ndev); | |
389 | return qdev->msg_enable; | |
390 | } | |
391 | ||
392 | static void ql_set_msglevel(struct net_device *ndev, u32 value) | |
393 | { | |
394 | struct ql_adapter *qdev = netdev_priv(ndev); | |
395 | qdev->msg_enable = value; | |
396 | } | |
397 | ||
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, | |
00acd0d2 | 407 | .set_tx_csum = ethtool_op_set_tx_csum, |
c4e84bde RM |
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, | |
417 | }; | |
418 |