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