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