]>
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> | |
c4e84bde RM |
10 | #include <linux/dmapool.h> |
11 | #include <linux/mempool.h> | |
12 | #include <linux/spinlock.h> | |
13 | #include <linux/kthread.h> | |
14 | #include <linux/interrupt.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/ioport.h> | |
17 | #include <linux/in.h> | |
18 | #include <linux/ip.h> | |
19 | #include <linux/ipv6.h> | |
20 | #include <net/ipv6.h> | |
21 | #include <linux/tcp.h> | |
22 | #include <linux/udp.h> | |
23 | #include <linux/if_arp.h> | |
24 | #include <linux/if_ether.h> | |
25 | #include <linux/netdevice.h> | |
26 | #include <linux/etherdevice.h> | |
27 | #include <linux/ethtool.h> | |
28 | #include <linux/skbuff.h> | |
29 | #include <linux/rtnetlink.h> | |
30 | #include <linux/if_vlan.h> | |
c4e84bde RM |
31 | #include <linux/delay.h> |
32 | #include <linux/mm.h> | |
33 | #include <linux/vmalloc.h> | |
34 | ||
c4e84bde RM |
35 | |
36 | #include "qlge.h" | |
37 | ||
9dfbbaa6 RM |
38 | static const char ql_gstrings_test[][ETH_GSTRING_LEN] = { |
39 | "Loopback test (offline)" | |
40 | }; | |
41 | #define QLGE_TEST_LEN (sizeof(ql_gstrings_test) / ETH_GSTRING_LEN) | |
42 | ||
c4e84bde RM |
43 | static int ql_update_ring_coalescing(struct ql_adapter *qdev) |
44 | { | |
45 | int i, status = 0; | |
46 | struct rx_ring *rx_ring; | |
47 | struct cqicb *cqicb; | |
48 | ||
49 | if (!netif_running(qdev->ndev)) | |
50 | return status; | |
51 | ||
c4e84bde RM |
52 | /* Skip the default queue, and update the outbound handler |
53 | * queues if they changed. | |
54 | */ | |
b2014ff8 | 55 | cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count]; |
c4e84bde | 56 | if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs || |
b2014ff8 RM |
57 | le16_to_cpu(cqicb->pkt_delay) != |
58 | qdev->tx_max_coalesced_frames) { | |
59 | for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) { | |
c4e84bde RM |
60 | rx_ring = &qdev->rx_ring[i]; |
61 | cqicb = (struct cqicb *)rx_ring; | |
8306c952 | 62 | cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs); |
c4e84bde | 63 | cqicb->pkt_delay = |
8306c952 | 64 | cpu_to_le16(qdev->tx_max_coalesced_frames); |
c4e84bde | 65 | cqicb->flags = FLAGS_LI; |
e332471c | 66 | status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb), |
c4e84bde RM |
67 | CFG_LCQ, rx_ring->cq_id); |
68 | if (status) { | |
ae9540f7 JP |
69 | netif_err(qdev, ifup, qdev->ndev, |
70 | "Failed to load CQICB.\n"); | |
c4e84bde RM |
71 | goto exit; |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | /* Update the inbound (RSS) handler queues if they changed. */ | |
b2014ff8 | 77 | cqicb = (struct cqicb *)&qdev->rx_ring[0]; |
c4e84bde | 78 | if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs || |
b2014ff8 RM |
79 | le16_to_cpu(cqicb->pkt_delay) != |
80 | qdev->rx_max_coalesced_frames) { | |
81 | for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) { | |
c4e84bde RM |
82 | rx_ring = &qdev->rx_ring[i]; |
83 | cqicb = (struct cqicb *)rx_ring; | |
8306c952 | 84 | cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs); |
c4e84bde | 85 | cqicb->pkt_delay = |
8306c952 | 86 | cpu_to_le16(qdev->rx_max_coalesced_frames); |
c4e84bde | 87 | cqicb->flags = FLAGS_LI; |
e332471c | 88 | status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb), |
c4e84bde RM |
89 | CFG_LCQ, rx_ring->cq_id); |
90 | if (status) { | |
ae9540f7 JP |
91 | netif_err(qdev, ifup, qdev->ndev, |
92 | "Failed to load CQICB.\n"); | |
c4e84bde RM |
93 | goto exit; |
94 | } | |
95 | } | |
96 | } | |
97 | exit: | |
c4e84bde RM |
98 | return status; |
99 | } | |
100 | ||
2f22d22e | 101 | static void ql_update_stats(struct ql_adapter *qdev) |
c4e84bde RM |
102 | { |
103 | u32 i; | |
104 | u64 data; | |
105 | u64 *iter = &qdev->nic_stats.tx_pkts; | |
106 | ||
107 | spin_lock(&qdev->stats_lock); | |
108 | if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) { | |
ae9540f7 JP |
109 | netif_err(qdev, drv, qdev->ndev, |
110 | "Couldn't get xgmac sem.\n"); | |
c4e84bde RM |
111 | goto quit; |
112 | } | |
113 | /* | |
114 | * Get TX statistics. | |
115 | */ | |
116 | for (i = 0x200; i < 0x280; i += 8) { | |
117 | if (ql_read_xgmac_reg64(qdev, i, &data)) { | |
ae9540f7 JP |
118 | netif_err(qdev, drv, qdev->ndev, |
119 | "Error reading status register 0x%.04x.\n", | |
120 | i); | |
c4e84bde RM |
121 | goto end; |
122 | } else | |
123 | *iter = data; | |
124 | iter++; | |
125 | } | |
126 | ||
127 | /* | |
128 | * Get RX statistics. | |
129 | */ | |
130 | for (i = 0x300; i < 0x3d0; i += 8) { | |
131 | if (ql_read_xgmac_reg64(qdev, i, &data)) { | |
ae9540f7 JP |
132 | netif_err(qdev, drv, qdev->ndev, |
133 | "Error reading status register 0x%.04x.\n", | |
134 | i); | |
c4e84bde RM |
135 | goto end; |
136 | } else | |
137 | *iter = data; | |
138 | iter++; | |
139 | } | |
140 | ||
6abd2346 RM |
141 | /* |
142 | * Get Per-priority TX pause frame counter statistics. | |
143 | */ | |
144 | for (i = 0x500; i < 0x540; i += 8) { | |
145 | if (ql_read_xgmac_reg64(qdev, i, &data)) { | |
ae9540f7 JP |
146 | netif_err(qdev, drv, qdev->ndev, |
147 | "Error reading status register 0x%.04x.\n", | |
148 | i); | |
6abd2346 RM |
149 | goto end; |
150 | } else | |
151 | *iter = data; | |
152 | iter++; | |
153 | } | |
154 | ||
155 | /* | |
156 | * Get Per-priority RX pause frame counter statistics. | |
157 | */ | |
158 | for (i = 0x568; i < 0x5a8; i += 8) { | |
159 | if (ql_read_xgmac_reg64(qdev, i, &data)) { | |
ae9540f7 JP |
160 | netif_err(qdev, drv, qdev->ndev, |
161 | "Error reading status register 0x%.04x.\n", | |
162 | i); | |
6abd2346 RM |
163 | goto end; |
164 | } else | |
165 | *iter = data; | |
166 | iter++; | |
167 | } | |
168 | ||
169 | /* | |
170 | * Get RX NIC FIFO DROP statistics. | |
171 | */ | |
172 | if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) { | |
ae9540f7 JP |
173 | netif_err(qdev, drv, qdev->ndev, |
174 | "Error reading status register 0x%.04x.\n", i); | |
6abd2346 RM |
175 | goto end; |
176 | } else | |
177 | *iter = data; | |
c4e84bde RM |
178 | end: |
179 | ql_sem_unlock(qdev, qdev->xg_sem_mask); | |
180 | quit: | |
181 | spin_unlock(&qdev->stats_lock); | |
182 | ||
183 | QL_DUMP_STAT(qdev); | |
184 | ||
185 | return; | |
186 | } | |
187 | ||
188 | static char ql_stats_str_arr[][ETH_GSTRING_LEN] = { | |
189 | {"tx_pkts"}, | |
190 | {"tx_bytes"}, | |
191 | {"tx_mcast_pkts"}, | |
192 | {"tx_bcast_pkts"}, | |
193 | {"tx_ucast_pkts"}, | |
194 | {"tx_ctl_pkts"}, | |
195 | {"tx_pause_pkts"}, | |
196 | {"tx_64_pkts"}, | |
197 | {"tx_65_to_127_pkts"}, | |
198 | {"tx_128_to_255_pkts"}, | |
199 | {"tx_256_511_pkts"}, | |
200 | {"tx_512_to_1023_pkts"}, | |
201 | {"tx_1024_to_1518_pkts"}, | |
202 | {"tx_1519_to_max_pkts"}, | |
203 | {"tx_undersize_pkts"}, | |
204 | {"tx_oversize_pkts"}, | |
205 | {"rx_bytes"}, | |
206 | {"rx_bytes_ok"}, | |
207 | {"rx_pkts"}, | |
208 | {"rx_pkts_ok"}, | |
209 | {"rx_bcast_pkts"}, | |
210 | {"rx_mcast_pkts"}, | |
211 | {"rx_ucast_pkts"}, | |
212 | {"rx_undersize_pkts"}, | |
213 | {"rx_oversize_pkts"}, | |
214 | {"rx_jabber_pkts"}, | |
215 | {"rx_undersize_fcerr_pkts"}, | |
216 | {"rx_drop_events"}, | |
217 | {"rx_fcerr_pkts"}, | |
218 | {"rx_align_err"}, | |
219 | {"rx_symbol_err"}, | |
220 | {"rx_mac_err"}, | |
221 | {"rx_ctl_pkts"}, | |
222 | {"rx_pause_pkts"}, | |
223 | {"rx_64_pkts"}, | |
224 | {"rx_65_to_127_pkts"}, | |
225 | {"rx_128_255_pkts"}, | |
226 | {"rx_256_511_pkts"}, | |
227 | {"rx_512_to_1023_pkts"}, | |
228 | {"rx_1024_to_1518_pkts"}, | |
229 | {"rx_1519_to_max_pkts"}, | |
230 | {"rx_len_err_pkts"}, | |
6abd2346 RM |
231 | {"tx_cbfc_pause_frames0"}, |
232 | {"tx_cbfc_pause_frames1"}, | |
233 | {"tx_cbfc_pause_frames2"}, | |
234 | {"tx_cbfc_pause_frames3"}, | |
235 | {"tx_cbfc_pause_frames4"}, | |
236 | {"tx_cbfc_pause_frames5"}, | |
237 | {"tx_cbfc_pause_frames6"}, | |
238 | {"tx_cbfc_pause_frames7"}, | |
239 | {"rx_cbfc_pause_frames0"}, | |
240 | {"rx_cbfc_pause_frames1"}, | |
241 | {"rx_cbfc_pause_frames2"}, | |
242 | {"rx_cbfc_pause_frames3"}, | |
243 | {"rx_cbfc_pause_frames4"}, | |
244 | {"rx_cbfc_pause_frames5"}, | |
245 | {"rx_cbfc_pause_frames6"}, | |
246 | {"rx_cbfc_pause_frames7"}, | |
247 | {"rx_nic_fifo_drop"}, | |
c4e84bde RM |
248 | }; |
249 | ||
250 | static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf) | |
251 | { | |
252 | switch (stringset) { | |
253 | case ETH_SS_STATS: | |
254 | memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr)); | |
255 | break; | |
256 | } | |
257 | } | |
258 | ||
259 | static int ql_get_sset_count(struct net_device *dev, int sset) | |
260 | { | |
261 | switch (sset) { | |
9dfbbaa6 RM |
262 | case ETH_SS_TEST: |
263 | return QLGE_TEST_LEN; | |
c4e84bde RM |
264 | case ETH_SS_STATS: |
265 | return ARRAY_SIZE(ql_stats_str_arr); | |
266 | default: | |
267 | return -EOPNOTSUPP; | |
268 | } | |
269 | } | |
270 | ||
271 | static void | |
272 | ql_get_ethtool_stats(struct net_device *ndev, | |
273 | struct ethtool_stats *stats, u64 *data) | |
274 | { | |
275 | struct ql_adapter *qdev = netdev_priv(ndev); | |
276 | struct nic_stats *s = &qdev->nic_stats; | |
277 | ||
278 | ql_update_stats(qdev); | |
279 | ||
280 | *data++ = s->tx_pkts; | |
281 | *data++ = s->tx_bytes; | |
282 | *data++ = s->tx_mcast_pkts; | |
283 | *data++ = s->tx_bcast_pkts; | |
284 | *data++ = s->tx_ucast_pkts; | |
285 | *data++ = s->tx_ctl_pkts; | |
286 | *data++ = s->tx_pause_pkts; | |
287 | *data++ = s->tx_64_pkt; | |
288 | *data++ = s->tx_65_to_127_pkt; | |
289 | *data++ = s->tx_128_to_255_pkt; | |
290 | *data++ = s->tx_256_511_pkt; | |
291 | *data++ = s->tx_512_to_1023_pkt; | |
292 | *data++ = s->tx_1024_to_1518_pkt; | |
293 | *data++ = s->tx_1519_to_max_pkt; | |
294 | *data++ = s->tx_undersize_pkt; | |
295 | *data++ = s->tx_oversize_pkt; | |
296 | *data++ = s->rx_bytes; | |
297 | *data++ = s->rx_bytes_ok; | |
298 | *data++ = s->rx_pkts; | |
299 | *data++ = s->rx_pkts_ok; | |
300 | *data++ = s->rx_bcast_pkts; | |
301 | *data++ = s->rx_mcast_pkts; | |
302 | *data++ = s->rx_ucast_pkts; | |
303 | *data++ = s->rx_undersize_pkts; | |
304 | *data++ = s->rx_oversize_pkts; | |
305 | *data++ = s->rx_jabber_pkts; | |
306 | *data++ = s->rx_undersize_fcerr_pkts; | |
307 | *data++ = s->rx_drop_events; | |
308 | *data++ = s->rx_fcerr_pkts; | |
309 | *data++ = s->rx_align_err; | |
310 | *data++ = s->rx_symbol_err; | |
311 | *data++ = s->rx_mac_err; | |
312 | *data++ = s->rx_ctl_pkts; | |
313 | *data++ = s->rx_pause_pkts; | |
314 | *data++ = s->rx_64_pkts; | |
315 | *data++ = s->rx_65_to_127_pkts; | |
316 | *data++ = s->rx_128_255_pkts; | |
317 | *data++ = s->rx_256_511_pkts; | |
318 | *data++ = s->rx_512_to_1023_pkts; | |
319 | *data++ = s->rx_1024_to_1518_pkts; | |
320 | *data++ = s->rx_1519_to_max_pkts; | |
321 | *data++ = s->rx_len_err_pkts; | |
6abd2346 RM |
322 | *data++ = s->tx_cbfc_pause_frames0; |
323 | *data++ = s->tx_cbfc_pause_frames1; | |
324 | *data++ = s->tx_cbfc_pause_frames2; | |
325 | *data++ = s->tx_cbfc_pause_frames3; | |
326 | *data++ = s->tx_cbfc_pause_frames4; | |
327 | *data++ = s->tx_cbfc_pause_frames5; | |
328 | *data++ = s->tx_cbfc_pause_frames6; | |
329 | *data++ = s->tx_cbfc_pause_frames7; | |
330 | *data++ = s->rx_cbfc_pause_frames0; | |
331 | *data++ = s->rx_cbfc_pause_frames1; | |
332 | *data++ = s->rx_cbfc_pause_frames2; | |
333 | *data++ = s->rx_cbfc_pause_frames3; | |
334 | *data++ = s->rx_cbfc_pause_frames4; | |
335 | *data++ = s->rx_cbfc_pause_frames5; | |
336 | *data++ = s->rx_cbfc_pause_frames6; | |
337 | *data++ = s->rx_cbfc_pause_frames7; | |
338 | *data++ = s->rx_nic_fifo_drop; | |
c4e84bde RM |
339 | } |
340 | ||
341 | static int ql_get_settings(struct net_device *ndev, | |
342 | struct ethtool_cmd *ecmd) | |
343 | { | |
344 | struct ql_adapter *qdev = netdev_priv(ndev); | |
345 | ||
346 | ecmd->supported = SUPPORTED_10000baseT_Full; | |
347 | ecmd->advertising = ADVERTISED_10000baseT_Full; | |
348 | ecmd->autoneg = AUTONEG_ENABLE; | |
349 | ecmd->transceiver = XCVR_EXTERNAL; | |
b82808b7 RM |
350 | if ((qdev->link_status & STS_LINK_TYPE_MASK) == |
351 | STS_LINK_TYPE_10GBASET) { | |
c4e84bde RM |
352 | ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg); |
353 | ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg); | |
354 | ecmd->port = PORT_TP; | |
355 | } else { | |
356 | ecmd->supported |= SUPPORTED_FIBRE; | |
357 | ecmd->advertising |= ADVERTISED_FIBRE; | |
358 | ecmd->port = PORT_FIBRE; | |
359 | } | |
360 | ||
361 | ecmd->speed = SPEED_10000; | |
362 | ecmd->duplex = DUPLEX_FULL; | |
363 | ||
364 | return 0; | |
365 | } | |
366 | ||
367 | static void ql_get_drvinfo(struct net_device *ndev, | |
368 | struct ethtool_drvinfo *drvinfo) | |
369 | { | |
370 | struct ql_adapter *qdev = netdev_priv(ndev); | |
371 | strncpy(drvinfo->driver, qlge_driver_name, 32); | |
372 | strncpy(drvinfo->version, qlge_driver_version, 32); | |
cfec0cbc RM |
373 | snprintf(drvinfo->fw_version, 32, "v%d.%d.%d", |
374 | (qdev->fw_rev_id & 0x00ff0000) >> 16, | |
375 | (qdev->fw_rev_id & 0x0000ff00) >> 8, | |
376 | (qdev->fw_rev_id & 0x000000ff)); | |
c4e84bde RM |
377 | strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32); |
378 | drvinfo->n_stats = 0; | |
379 | drvinfo->testinfo_len = 0; | |
380 | drvinfo->regdump_len = 0; | |
381 | drvinfo->eedump_len = 0; | |
382 | } | |
383 | ||
bc083ce9 RM |
384 | static void ql_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
385 | { | |
386 | struct ql_adapter *qdev = netdev_priv(ndev); | |
387 | /* What we support. */ | |
388 | wol->supported = WAKE_MAGIC; | |
389 | /* What we've currently got set. */ | |
390 | wol->wolopts = qdev->wol; | |
391 | } | |
392 | ||
393 | static int ql_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) | |
394 | { | |
395 | struct ql_adapter *qdev = netdev_priv(ndev); | |
396 | int status; | |
397 | ||
398 | if (wol->wolopts & ~WAKE_MAGIC) | |
399 | return -EINVAL; | |
400 | qdev->wol = wol->wolopts; | |
401 | ||
ae9540f7 | 402 | netif_info(qdev, drv, qdev->ndev, "Set wol option 0x%x\n", qdev->wol); |
bc083ce9 RM |
403 | if (!qdev->wol) { |
404 | u32 wol = 0; | |
405 | status = ql_mb_wol_mode(qdev, wol); | |
ae9540f7 | 406 | netif_err(qdev, drv, qdev->ndev, "WOL %s (wol code 0x%x)\n", |
318ae2ed | 407 | status == 0 ? "cleared successfully" : "clear failed", |
ae9540f7 | 408 | wol); |
bc083ce9 RM |
409 | } |
410 | ||
411 | return 0; | |
412 | } | |
d8eb59dc RM |
413 | |
414 | static int ql_phys_id(struct net_device *ndev, u32 data) | |
415 | { | |
416 | struct ql_adapter *qdev = netdev_priv(ndev); | |
417 | u32 led_reg, i; | |
418 | int status; | |
419 | ||
420 | /* Save the current LED settings */ | |
421 | status = ql_mb_get_led_cfg(qdev); | |
422 | if (status) | |
423 | return status; | |
424 | led_reg = qdev->led_config; | |
425 | ||
426 | /* Start blinking the led */ | |
427 | if (!data || data > 300) | |
428 | data = 300; | |
429 | ||
430 | for (i = 0; i < (data * 10); i++) | |
431 | ql_mb_set_led_cfg(qdev, QL_LED_BLINK); | |
432 | ||
433 | /* Restore LED settings */ | |
434 | status = ql_mb_set_led_cfg(qdev, led_reg); | |
435 | if (status) | |
436 | return status; | |
437 | ||
438 | return 0; | |
439 | } | |
a61f8026 | 440 | |
9dfbbaa6 RM |
441 | static int ql_start_loopback(struct ql_adapter *qdev) |
442 | { | |
443 | if (netif_carrier_ok(qdev->ndev)) { | |
444 | set_bit(QL_LB_LINK_UP, &qdev->flags); | |
445 | netif_carrier_off(qdev->ndev); | |
446 | } else | |
447 | clear_bit(QL_LB_LINK_UP, &qdev->flags); | |
448 | qdev->link_config |= CFG_LOOPBACK_PCS; | |
449 | return ql_mb_set_port_cfg(qdev); | |
450 | } | |
451 | ||
452 | static void ql_stop_loopback(struct ql_adapter *qdev) | |
453 | { | |
454 | qdev->link_config &= ~CFG_LOOPBACK_PCS; | |
455 | ql_mb_set_port_cfg(qdev); | |
456 | if (test_bit(QL_LB_LINK_UP, &qdev->flags)) { | |
457 | netif_carrier_on(qdev->ndev); | |
458 | clear_bit(QL_LB_LINK_UP, &qdev->flags); | |
459 | } | |
460 | } | |
461 | ||
462 | static void ql_create_lb_frame(struct sk_buff *skb, | |
463 | unsigned int frame_size) | |
464 | { | |
465 | memset(skb->data, 0xFF, frame_size); | |
466 | frame_size &= ~1; | |
467 | memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); | |
468 | memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); | |
469 | memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); | |
470 | } | |
471 | ||
472 | void ql_check_lb_frame(struct ql_adapter *qdev, | |
473 | struct sk_buff *skb) | |
474 | { | |
475 | unsigned int frame_size = skb->len; | |
476 | ||
477 | if ((*(skb->data + 3) == 0xFF) && | |
478 | (*(skb->data + frame_size / 2 + 10) == 0xBE) && | |
479 | (*(skb->data + frame_size / 2 + 12) == 0xAF)) { | |
480 | atomic_dec(&qdev->lb_count); | |
481 | return; | |
482 | } | |
483 | } | |
484 | ||
485 | static int ql_run_loopback_test(struct ql_adapter *qdev) | |
486 | { | |
487 | int i; | |
488 | netdev_tx_t rc; | |
489 | struct sk_buff *skb; | |
490 | unsigned int size = SMALL_BUF_MAP_SIZE; | |
491 | ||
492 | for (i = 0; i < 64; i++) { | |
493 | skb = netdev_alloc_skb(qdev->ndev, size); | |
494 | if (!skb) | |
495 | return -ENOMEM; | |
496 | ||
497 | skb->queue_mapping = 0; | |
498 | skb_put(skb, size); | |
499 | ql_create_lb_frame(skb, size); | |
500 | rc = ql_lb_send(skb, qdev->ndev); | |
501 | if (rc != NETDEV_TX_OK) | |
502 | return -EPIPE; | |
503 | atomic_inc(&qdev->lb_count); | |
504 | } | |
aa13bd6e RM |
505 | /* Give queue time to settle before testing results. */ |
506 | msleep(2); | |
9dfbbaa6 RM |
507 | ql_clean_lb_rx_ring(&qdev->rx_ring[0], 128); |
508 | return atomic_read(&qdev->lb_count) ? -EIO : 0; | |
509 | } | |
510 | ||
511 | static int ql_loopback_test(struct ql_adapter *qdev, u64 *data) | |
512 | { | |
513 | *data = ql_start_loopback(qdev); | |
514 | if (*data) | |
515 | goto out; | |
516 | *data = ql_run_loopback_test(qdev); | |
517 | out: | |
518 | ql_stop_loopback(qdev); | |
519 | return *data; | |
520 | } | |
521 | ||
522 | static void ql_self_test(struct net_device *ndev, | |
523 | struct ethtool_test *eth_test, u64 *data) | |
524 | { | |
525 | struct ql_adapter *qdev = netdev_priv(ndev); | |
526 | ||
527 | if (netif_running(ndev)) { | |
528 | set_bit(QL_SELFTEST, &qdev->flags); | |
529 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { | |
530 | /* Offline tests */ | |
531 | if (ql_loopback_test(qdev, &data[0])) | |
532 | eth_test->flags |= ETH_TEST_FL_FAILED; | |
533 | ||
534 | } else { | |
535 | /* Online tests */ | |
536 | data[0] = 0; | |
537 | } | |
538 | clear_bit(QL_SELFTEST, &qdev->flags); | |
aa13bd6e RM |
539 | /* Give link time to come up after |
540 | * port configuration changes. | |
541 | */ | |
542 | msleep_interruptible(4 * 1000); | |
9dfbbaa6 | 543 | } else { |
ae9540f7 JP |
544 | netif_err(qdev, drv, qdev->ndev, |
545 | "is down, Loopback test will fail.\n"); | |
9dfbbaa6 RM |
546 | eth_test->flags |= ETH_TEST_FL_FAILED; |
547 | } | |
548 | } | |
549 | ||
a61f8026 RM |
550 | static int ql_get_regs_len(struct net_device *ndev) |
551 | { | |
552 | return sizeof(struct ql_reg_dump); | |
553 | } | |
554 | ||
555 | static void ql_get_regs(struct net_device *ndev, | |
556 | struct ethtool_regs *regs, void *p) | |
557 | { | |
558 | struct ql_adapter *qdev = netdev_priv(ndev); | |
559 | ||
560 | ql_gen_reg_dump(qdev, p); | |
561 | } | |
562 | ||
c4e84bde RM |
563 | static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c) |
564 | { | |
565 | struct ql_adapter *qdev = netdev_priv(dev); | |
566 | ||
567 | c->rx_coalesce_usecs = qdev->rx_coalesce_usecs; | |
568 | c->tx_coalesce_usecs = qdev->tx_coalesce_usecs; | |
569 | ||
570 | /* This chip coalesces as follows: | |
571 | * If a packet arrives, hold off interrupts until | |
572 | * cqicb->int_delay expires, but if no other packets arrive don't | |
573 | * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a | |
574 | * timer to coalesce on a frame basis. So, we have to take ethtool's | |
575 | * max_coalesced_frames value and convert it to a delay in microseconds. | |
576 | * We do this by using a basic thoughput of 1,000,000 frames per | |
577 | * second @ (1024 bytes). This means one frame per usec. So it's a | |
578 | * simple one to one ratio. | |
579 | */ | |
580 | c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames; | |
581 | c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames; | |
582 | ||
583 | return 0; | |
584 | } | |
585 | ||
586 | static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c) | |
587 | { | |
588 | struct ql_adapter *qdev = netdev_priv(ndev); | |
589 | ||
590 | /* Validate user parameters. */ | |
591 | if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2) | |
592 | return -EINVAL; | |
593 | /* Don't wait more than 10 usec. */ | |
594 | if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT) | |
595 | return -EINVAL; | |
596 | if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2) | |
597 | return -EINVAL; | |
598 | if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT) | |
599 | return -EINVAL; | |
600 | ||
601 | /* Verify a change took place before updating the hardware. */ | |
602 | if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs && | |
603 | qdev->tx_coalesce_usecs == c->tx_coalesce_usecs && | |
604 | qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames && | |
605 | qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames) | |
606 | return 0; | |
607 | ||
608 | qdev->rx_coalesce_usecs = c->rx_coalesce_usecs; | |
609 | qdev->tx_coalesce_usecs = c->tx_coalesce_usecs; | |
610 | qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames; | |
611 | qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames; | |
612 | ||
613 | return ql_update_ring_coalescing(qdev); | |
614 | } | |
615 | ||
1d30df24 RM |
616 | static void ql_get_pauseparam(struct net_device *netdev, |
617 | struct ethtool_pauseparam *pause) | |
618 | { | |
619 | struct ql_adapter *qdev = netdev_priv(netdev); | |
620 | ||
621 | ql_mb_get_port_cfg(qdev); | |
622 | if (qdev->link_config & CFG_PAUSE_STD) { | |
623 | pause->rx_pause = 1; | |
624 | pause->tx_pause = 1; | |
625 | } | |
626 | } | |
627 | ||
628 | static int ql_set_pauseparam(struct net_device *netdev, | |
629 | struct ethtool_pauseparam *pause) | |
630 | { | |
631 | struct ql_adapter *qdev = netdev_priv(netdev); | |
632 | int status = 0; | |
633 | ||
634 | if ((pause->rx_pause) && (pause->tx_pause)) | |
635 | qdev->link_config |= CFG_PAUSE_STD; | |
636 | else if (!pause->rx_pause && !pause->tx_pause) | |
637 | qdev->link_config &= ~CFG_PAUSE_STD; | |
638 | else | |
639 | return -EINVAL; | |
640 | ||
641 | status = ql_mb_set_port_cfg(qdev); | |
642 | if (status) | |
643 | return status; | |
644 | return status; | |
645 | } | |
646 | ||
c4e84bde RM |
647 | static u32 ql_get_rx_csum(struct net_device *netdev) |
648 | { | |
649 | struct ql_adapter *qdev = netdev_priv(netdev); | |
650 | return qdev->rx_csum; | |
651 | } | |
652 | ||
653 | static int ql_set_rx_csum(struct net_device *netdev, uint32_t data) | |
654 | { | |
655 | struct ql_adapter *qdev = netdev_priv(netdev); | |
656 | qdev->rx_csum = data; | |
657 | return 0; | |
658 | } | |
659 | ||
660 | static int ql_set_tso(struct net_device *ndev, uint32_t data) | |
661 | { | |
662 | ||
663 | if (data) { | |
664 | ndev->features |= NETIF_F_TSO; | |
665 | ndev->features |= NETIF_F_TSO6; | |
666 | } else { | |
667 | ndev->features &= ~NETIF_F_TSO; | |
668 | ndev->features &= ~NETIF_F_TSO6; | |
669 | } | |
670 | return 0; | |
671 | } | |
672 | ||
673 | static u32 ql_get_msglevel(struct net_device *ndev) | |
674 | { | |
675 | struct ql_adapter *qdev = netdev_priv(ndev); | |
676 | return qdev->msg_enable; | |
677 | } | |
678 | ||
679 | static void ql_set_msglevel(struct net_device *ndev, u32 value) | |
680 | { | |
681 | struct ql_adapter *qdev = netdev_priv(ndev); | |
682 | qdev->msg_enable = value; | |
683 | } | |
684 | ||
685 | const struct ethtool_ops qlge_ethtool_ops = { | |
686 | .get_settings = ql_get_settings, | |
687 | .get_drvinfo = ql_get_drvinfo, | |
bc083ce9 RM |
688 | .get_wol = ql_get_wol, |
689 | .set_wol = ql_set_wol, | |
a61f8026 RM |
690 | .get_regs_len = ql_get_regs_len, |
691 | .get_regs = ql_get_regs, | |
c4e84bde RM |
692 | .get_msglevel = ql_get_msglevel, |
693 | .set_msglevel = ql_set_msglevel, | |
694 | .get_link = ethtool_op_get_link, | |
d8eb59dc | 695 | .phys_id = ql_phys_id, |
9dfbbaa6 | 696 | .self_test = ql_self_test, |
1d30df24 RM |
697 | .get_pauseparam = ql_get_pauseparam, |
698 | .set_pauseparam = ql_set_pauseparam, | |
c4e84bde RM |
699 | .get_rx_csum = ql_get_rx_csum, |
700 | .set_rx_csum = ql_set_rx_csum, | |
701 | .get_tx_csum = ethtool_op_get_tx_csum, | |
00acd0d2 | 702 | .set_tx_csum = ethtool_op_set_tx_csum, |
c4e84bde RM |
703 | .get_sg = ethtool_op_get_sg, |
704 | .set_sg = ethtool_op_set_sg, | |
705 | .get_tso = ethtool_op_get_tso, | |
706 | .set_tso = ql_set_tso, | |
707 | .get_coalesce = ql_get_coalesce, | |
708 | .set_coalesce = ql_set_coalesce, | |
709 | .get_sset_count = ql_get_sset_count, | |
710 | .get_strings = ql_get_strings, | |
711 | .get_ethtool_stats = ql_get_ethtool_stats, | |
712 | }; | |
713 |