Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Vasundhara Volam | c7bb15a | 2013-03-06 20:05:05 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2013 Emulex |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 19 | #include "be_cmds.h" |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 20 | #include <linux/ethtool.h> |
| 21 | |
| 22 | struct be_ethtool_stat { |
| 23 | char desc[ETH_GSTRING_LEN]; |
| 24 | int type; |
| 25 | int size; |
| 26 | int offset; |
| 27 | }; |
| 28 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 29 | enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT}; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 30 | #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \ |
| 31 | offsetof(_struct, field) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 32 | #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\ |
| 33 | FIELDINFO(struct be_tx_stats, field) |
| 34 | #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\ |
| 35 | FIELDINFO(struct be_rx_stats, field) |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 36 | #define DRVSTAT_INFO(field) #field, DRVSTAT,\ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 37 | FIELDINFO(struct be_drv_stats, field) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 38 | |
| 39 | static const struct be_ethtool_stat et_stats[] = { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 40 | {DRVSTAT_INFO(rx_crc_errors)}, |
| 41 | {DRVSTAT_INFO(rx_alignment_symbol_errors)}, |
| 42 | {DRVSTAT_INFO(rx_pause_frames)}, |
| 43 | {DRVSTAT_INFO(rx_control_frames)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 44 | /* Received packets dropped when the Ethernet length field |
| 45 | * is not equal to the actual Ethernet data length. |
| 46 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 47 | {DRVSTAT_INFO(rx_in_range_errors)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 48 | /* Received packets dropped when their length field is >= 1501 bytes |
| 49 | * and <= 1535 bytes. |
| 50 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 51 | {DRVSTAT_INFO(rx_out_range_errors)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 52 | /* Received packets dropped when they are longer than 9216 bytes */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 53 | {DRVSTAT_INFO(rx_frame_too_long)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 54 | /* Received packets dropped when they don't pass the unicast or |
| 55 | * multicast address filtering. |
| 56 | */ |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 57 | {DRVSTAT_INFO(rx_address_filtered)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 58 | /* Received packets dropped when IP packet length field is less than |
| 59 | * the IP header length field. |
| 60 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 61 | {DRVSTAT_INFO(rx_dropped_too_small)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 62 | /* Received packets dropped when IP length field is greater than |
| 63 | * the actual packet length. |
| 64 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 65 | {DRVSTAT_INFO(rx_dropped_too_short)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 66 | /* Received packets dropped when the IP header length field is less |
| 67 | * than 5. |
| 68 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 69 | {DRVSTAT_INFO(rx_dropped_header_too_small)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 70 | /* Received packets dropped when the TCP header length field is less |
| 71 | * than 5 or the TCP header length + IP header length is more |
| 72 | * than IP packet length. |
| 73 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 74 | {DRVSTAT_INFO(rx_dropped_tcp_length)}, |
| 75 | {DRVSTAT_INFO(rx_dropped_runt)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 76 | /* Number of received packets dropped when a fifo for descriptors going |
| 77 | * into the packet demux block overflows. In normal operation, this |
| 78 | * fifo must never overflow. |
| 79 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 80 | {DRVSTAT_INFO(rxpp_fifo_overflow_drop)}, |
| 81 | {DRVSTAT_INFO(rx_input_fifo_overflow_drop)}, |
| 82 | {DRVSTAT_INFO(rx_ip_checksum_errs)}, |
| 83 | {DRVSTAT_INFO(rx_tcp_checksum_errs)}, |
| 84 | {DRVSTAT_INFO(rx_udp_checksum_errs)}, |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 85 | {DRVSTAT_INFO(tx_pauseframes)}, |
| 86 | {DRVSTAT_INFO(tx_controlframes)}, |
| 87 | {DRVSTAT_INFO(rx_priority_pause_frames)}, |
Ajit Khaparde | b5adffc4 | 2013-05-01 09:38:00 +0000 | [diff] [blame] | 88 | {DRVSTAT_INFO(tx_priority_pauseframes)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 89 | /* Received packets dropped when an internal fifo going into |
| 90 | * main packet buffer tank (PMEM) overflows. |
| 91 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 92 | {DRVSTAT_INFO(pmem_fifo_overflow_drop)}, |
| 93 | {DRVSTAT_INFO(jabber_events)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 94 | /* Received packets dropped due to lack of available HW packet buffers |
| 95 | * used to temporarily hold the received packets. |
| 96 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 97 | {DRVSTAT_INFO(rx_drops_no_pbuf)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 98 | /* Received packets dropped due to input receive buffer |
| 99 | * descriptor fifo overflowing. |
| 100 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 101 | {DRVSTAT_INFO(rx_drops_no_erx_descr)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 102 | /* Packets dropped because the internal FIFO to the offloaded TCP |
| 103 | * receive processing block is full. This could happen only for |
| 104 | * offloaded iSCSI or FCoE trarffic. |
| 105 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 106 | {DRVSTAT_INFO(rx_drops_no_tpre_descr)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 107 | /* Received packets dropped when they need more than 8 |
| 108 | * receive buffers. This cannot happen as the driver configures |
| 109 | * 2048 byte receive buffers. |
| 110 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 111 | {DRVSTAT_INFO(rx_drops_too_many_frags)}, |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 112 | {DRVSTAT_INFO(forwarded_packets)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 113 | /* Received packets dropped when the frame length |
| 114 | * is more than 9018 bytes |
| 115 | */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 116 | {DRVSTAT_INFO(rx_drops_mtu)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 117 | /* Number of packets dropped due to random early drop function */ |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 118 | {DRVSTAT_INFO(eth_red_drops)}, |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 119 | {DRVSTAT_INFO(be_on_die_temperature)} |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 120 | }; |
| 121 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) |
| 122 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 123 | /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts |
| 124 | * are first and second members respectively. |
| 125 | */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 126 | static const struct be_ethtool_stat et_rx_stats[] = { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 127 | {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */ |
| 128 | {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 129 | {DRVSTAT_RX_INFO(rx_compl)}, |
| 130 | {DRVSTAT_RX_INFO(rx_mcast_pkts)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 131 | /* Number of page allocation failures while posting receive buffers |
| 132 | * to HW. |
| 133 | */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 134 | {DRVSTAT_RX_INFO(rx_post_fail)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 135 | /* Recevied packets dropped due to skb allocation failure */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 136 | {DRVSTAT_RX_INFO(rx_drops_no_skbs)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 137 | /* Received packets dropped due to lack of available fetched buffers |
| 138 | * posted by the driver. |
| 139 | */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 140 | {DRVSTAT_RX_INFO(rx_drops_no_frags)} |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 141 | }; |
| 142 | #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) |
| 143 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 144 | /* Stats related to multi TX queues: get_stats routine assumes compl is the |
| 145 | * first member |
| 146 | */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 147 | static const struct be_ethtool_stat et_tx_stats[] = { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 148 | {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 149 | {DRVSTAT_TX_INFO(tx_bytes)}, |
| 150 | {DRVSTAT_TX_INFO(tx_pkts)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 151 | /* Number of skbs queued for trasmission by the driver */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 152 | {DRVSTAT_TX_INFO(tx_reqs)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 153 | /* Number of TX work request blocks DMAed to HW */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 154 | {DRVSTAT_TX_INFO(tx_wrbs)}, |
Sathya Perla | d45b9d3 | 2012-01-29 20:17:39 +0000 | [diff] [blame] | 155 | /* Number of times the TX queue was stopped due to lack |
| 156 | * of spaces in the TXQ. |
| 157 | */ |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 158 | {DRVSTAT_TX_INFO(tx_stops)} |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 159 | }; |
| 160 | #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats)) |
| 161 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 162 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
| 163 | "MAC Loopback test", |
| 164 | "PHY Loopback test", |
| 165 | "External Loopback test", |
Ajit Khaparde | 4ee7721 | 2011-02-20 11:41:20 +0000 | [diff] [blame] | 166 | "DDR DMA test", |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 167 | "Link test" |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) |
| 171 | #define BE_MAC_LOOPBACK 0x0 |
| 172 | #define BE_PHY_LOOPBACK 0x1 |
| 173 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 174 | #define BE_NO_LOOPBACK 0xff |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 175 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 176 | static void be_get_drvinfo(struct net_device *netdev, |
| 177 | struct ethtool_drvinfo *drvinfo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 178 | { |
| 179 | struct be_adapter *adapter = netdev_priv(netdev); |
| 180 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 181 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 182 | strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version)); |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 183 | if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN)) |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 184 | strlcpy(drvinfo->fw_version, adapter->fw_ver, |
| 185 | sizeof(drvinfo->fw_version)); |
| 186 | else |
| 187 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 188 | "%s [%s]", adapter->fw_ver, adapter->fw_on_flash); |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 189 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 190 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), |
| 191 | sizeof(drvinfo->bus_info)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 192 | drvinfo->testinfo_len = 0; |
| 193 | drvinfo->regdump_len = 0; |
| 194 | drvinfo->eedump_len = 0; |
| 195 | } |
| 196 | |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 197 | static u32 |
| 198 | lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name) |
| 199 | { |
| 200 | u32 data_read = 0, eof; |
| 201 | u8 addn_status; |
| 202 | struct be_dma_mem data_len_cmd; |
| 203 | int status; |
| 204 | |
| 205 | memset(&data_len_cmd, 0, sizeof(data_len_cmd)); |
| 206 | /* data_offset and data_size should be 0 to get reg len */ |
| 207 | status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, |
| 208 | file_name, &data_read, &eof, &addn_status); |
| 209 | |
| 210 | return data_read; |
| 211 | } |
| 212 | |
| 213 | static int |
| 214 | lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name, |
| 215 | u32 buf_len, void *buf) |
| 216 | { |
| 217 | struct be_dma_mem read_cmd; |
| 218 | u32 read_len = 0, total_read_len = 0, chunk_size; |
| 219 | u32 eof = 0; |
| 220 | u8 addn_status; |
| 221 | int status = 0; |
| 222 | |
| 223 | read_cmd.size = LANCER_READ_FILE_CHUNK; |
| 224 | read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size, |
| 225 | &read_cmd.dma); |
| 226 | |
| 227 | if (!read_cmd.va) { |
| 228 | dev_err(&adapter->pdev->dev, |
| 229 | "Memory allocation failure while reading dump\n"); |
| 230 | return -ENOMEM; |
| 231 | } |
| 232 | |
| 233 | while ((total_read_len < buf_len) && !eof) { |
| 234 | chunk_size = min_t(u32, (buf_len - total_read_len), |
| 235 | LANCER_READ_FILE_CHUNK); |
| 236 | chunk_size = ALIGN(chunk_size, 4); |
| 237 | status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size, |
| 238 | total_read_len, file_name, &read_len, |
| 239 | &eof, &addn_status); |
| 240 | if (!status) { |
| 241 | memcpy(buf + total_read_len, read_cmd.va, read_len); |
| 242 | total_read_len += read_len; |
| 243 | eof &= LANCER_READ_FILE_EOF_MASK; |
| 244 | } else { |
| 245 | status = -EIO; |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va, |
| 250 | read_cmd.dma); |
| 251 | |
| 252 | return status; |
| 253 | } |
| 254 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 255 | static int |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 256 | be_get_reg_len(struct net_device *netdev) |
| 257 | { |
| 258 | struct be_adapter *adapter = netdev_priv(netdev); |
| 259 | u32 log_size = 0; |
| 260 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 261 | if (!check_privilege(adapter, MAX_PRIVILEGES)) |
| 262 | return 0; |
| 263 | |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 264 | if (be_physfn(adapter)) { |
| 265 | if (lancer_chip(adapter)) |
| 266 | log_size = lancer_cmd_get_file_len(adapter, |
| 267 | LANCER_FW_DUMP_FILE); |
| 268 | else |
| 269 | be_cmd_get_reg_len(adapter, &log_size); |
| 270 | } |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 271 | return log_size; |
| 272 | } |
| 273 | |
| 274 | static void |
| 275 | be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf) |
| 276 | { |
| 277 | struct be_adapter *adapter = netdev_priv(netdev); |
| 278 | |
Ajit Khaparde | 16a871e | 2011-04-19 12:10:43 +0000 | [diff] [blame] | 279 | if (be_physfn(adapter)) { |
| 280 | memset(buf, 0, regs->len); |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 281 | if (lancer_chip(adapter)) |
| 282 | lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE, |
| 283 | regs->len, buf); |
| 284 | else |
| 285 | be_cmd_get_regs(adapter, regs->len, buf); |
Ajit Khaparde | 16a871e | 2011-04-19 12:10:43 +0000 | [diff] [blame] | 286 | } |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 289 | static int be_get_coalesce(struct net_device *netdev, |
| 290 | struct ethtool_coalesce *et) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 291 | { |
| 292 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 293 | struct be_aic_obj *aic = &adapter->aic_obj[0]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 294 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 295 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 296 | et->rx_coalesce_usecs = aic->prev_eqd; |
| 297 | et->rx_coalesce_usecs_high = aic->max_eqd; |
| 298 | et->rx_coalesce_usecs_low = aic->min_eqd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 299 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 300 | et->tx_coalesce_usecs = aic->prev_eqd; |
| 301 | et->tx_coalesce_usecs_high = aic->max_eqd; |
| 302 | et->tx_coalesce_usecs_low = aic->min_eqd; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 303 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 304 | et->use_adaptive_rx_coalesce = aic->enable; |
| 305 | et->use_adaptive_tx_coalesce = aic->enable; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 310 | /* TX attributes are ignored. Only RX attributes are considered |
| 311 | * eqd cmd is issued in the worker thread. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 312 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 313 | static int be_set_coalesce(struct net_device *netdev, |
| 314 | struct ethtool_coalesce *et) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 315 | { |
| 316 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 317 | struct be_aic_obj *aic = &adapter->aic_obj[0]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 318 | struct be_eq_obj *eqo; |
| 319 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 320 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 321 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame^] | 322 | aic->enable = et->use_adaptive_rx_coalesce; |
| 323 | aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD); |
| 324 | aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd); |
| 325 | aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd); |
| 326 | aic->et_eqd = max(aic->et_eqd, aic->min_eqd); |
| 327 | aic++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 333 | static void |
| 334 | be_get_ethtool_stats(struct net_device *netdev, |
| 335 | struct ethtool_stats *stats, uint64_t *data) |
| 336 | { |
| 337 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 338 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 339 | struct be_tx_obj *txo; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 340 | void *p; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 341 | unsigned int i, j, base = 0, start; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 342 | |
| 343 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 344 | p = (u8 *)&adapter->drv_stats + et_stats[i].offset; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 345 | data[i] = *(u32 *)p; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 346 | } |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 347 | base += ETHTOOL_STATS_NUM; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 348 | |
| 349 | for_all_rx_queues(adapter, rxo, j) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 350 | struct be_rx_stats *stats = rx_stats(rxo); |
| 351 | |
| 352 | do { |
| 353 | start = u64_stats_fetch_begin_bh(&stats->sync); |
| 354 | data[base] = stats->rx_bytes; |
| 355 | data[base + 1] = stats->rx_pkts; |
| 356 | } while (u64_stats_fetch_retry_bh(&stats->sync, start)); |
| 357 | |
| 358 | for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) { |
| 359 | p = (u8 *)stats + et_rx_stats[i].offset; |
| 360 | data[base + i] = *(u32 *)p; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 361 | } |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 362 | base += ETHTOOL_RXSTATS_NUM; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 363 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 364 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 365 | for_all_tx_queues(adapter, txo, j) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 366 | struct be_tx_stats *stats = tx_stats(txo); |
| 367 | |
| 368 | do { |
| 369 | start = u64_stats_fetch_begin_bh(&stats->sync_compl); |
| 370 | data[base] = stats->tx_compl; |
| 371 | } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start)); |
| 372 | |
| 373 | do { |
| 374 | start = u64_stats_fetch_begin_bh(&stats->sync); |
| 375 | for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) { |
| 376 | p = (u8 *)stats + et_tx_stats[i].offset; |
| 377 | data[base + i] = |
| 378 | (et_tx_stats[i].size == sizeof(u64)) ? |
| 379 | *(u64 *)p : *(u32 *)p; |
| 380 | } |
| 381 | } while (u64_stats_fetch_retry_bh(&stats->sync, start)); |
| 382 | base += ETHTOOL_TXSTATS_NUM; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 383 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void |
| 387 | be_get_stat_strings(struct net_device *netdev, uint32_t stringset, |
| 388 | uint8_t *data) |
| 389 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 390 | struct be_adapter *adapter = netdev_priv(netdev); |
| 391 | int i, j; |
| 392 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 393 | switch (stringset) { |
| 394 | case ETH_SS_STATS: |
| 395 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 396 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); |
| 397 | data += ETH_GSTRING_LEN; |
| 398 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 399 | for (i = 0; i < adapter->num_rx_qs; i++) { |
| 400 | for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { |
| 401 | sprintf(data, "rxq%d: %s", i, |
| 402 | et_rx_stats[j].desc); |
| 403 | data += ETH_GSTRING_LEN; |
| 404 | } |
| 405 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 406 | for (i = 0; i < adapter->num_tx_qs; i++) { |
| 407 | for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) { |
| 408 | sprintf(data, "txq%d: %s", i, |
| 409 | et_tx_stats[j].desc); |
| 410 | data += ETH_GSTRING_LEN; |
| 411 | } |
| 412 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 413 | break; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 414 | case ETH_SS_TEST: |
| 415 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { |
| 416 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); |
| 417 | data += ETH_GSTRING_LEN; |
| 418 | } |
| 419 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 423 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 424 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 425 | struct be_adapter *adapter = netdev_priv(netdev); |
| 426 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 427 | switch (stringset) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 428 | case ETH_SS_TEST: |
| 429 | return ETHTOOL_TESTS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 430 | case ETH_SS_STATS: |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 431 | return ETHTOOL_STATS_NUM + |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 432 | adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM + |
| 433 | adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 434 | default: |
| 435 | return -EINVAL; |
| 436 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 439 | static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len) |
| 440 | { |
| 441 | u32 port; |
| 442 | |
| 443 | switch (phy_type) { |
| 444 | case PHY_TYPE_BASET_1GB: |
| 445 | case PHY_TYPE_BASEX_1GB: |
| 446 | case PHY_TYPE_SGMII: |
| 447 | port = PORT_TP; |
| 448 | break; |
| 449 | case PHY_TYPE_SFP_PLUS_10GB: |
| 450 | port = dac_cable_len ? PORT_DA : PORT_FIBRE; |
| 451 | break; |
| 452 | case PHY_TYPE_XFP_10GB: |
| 453 | case PHY_TYPE_SFP_1GB: |
| 454 | port = PORT_FIBRE; |
| 455 | break; |
| 456 | case PHY_TYPE_BASET_10GB: |
| 457 | port = PORT_TP; |
| 458 | break; |
| 459 | default: |
| 460 | port = PORT_OTHER; |
| 461 | } |
| 462 | |
| 463 | return port; |
| 464 | } |
| 465 | |
| 466 | static u32 convert_to_et_setting(u32 if_type, u32 if_speeds) |
| 467 | { |
| 468 | u32 val = 0; |
| 469 | |
| 470 | switch (if_type) { |
| 471 | case PHY_TYPE_BASET_1GB: |
| 472 | case PHY_TYPE_BASEX_1GB: |
| 473 | case PHY_TYPE_SGMII: |
| 474 | val |= SUPPORTED_TP; |
| 475 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) |
| 476 | val |= SUPPORTED_1000baseT_Full; |
| 477 | if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) |
| 478 | val |= SUPPORTED_100baseT_Full; |
| 479 | if (if_speeds & BE_SUPPORTED_SPEED_10MBPS) |
| 480 | val |= SUPPORTED_10baseT_Full; |
| 481 | break; |
| 482 | case PHY_TYPE_KX4_10GB: |
| 483 | val |= SUPPORTED_Backplane; |
| 484 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) |
| 485 | val |= SUPPORTED_1000baseKX_Full; |
| 486 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) |
| 487 | val |= SUPPORTED_10000baseKX4_Full; |
| 488 | break; |
| 489 | case PHY_TYPE_KR_10GB: |
| 490 | val |= SUPPORTED_Backplane | |
| 491 | SUPPORTED_10000baseKR_Full; |
| 492 | break; |
| 493 | case PHY_TYPE_SFP_PLUS_10GB: |
| 494 | case PHY_TYPE_XFP_10GB: |
| 495 | case PHY_TYPE_SFP_1GB: |
| 496 | val |= SUPPORTED_FIBRE; |
| 497 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) |
| 498 | val |= SUPPORTED_10000baseT_Full; |
| 499 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) |
| 500 | val |= SUPPORTED_1000baseT_Full; |
| 501 | break; |
| 502 | case PHY_TYPE_BASET_10GB: |
| 503 | val |= SUPPORTED_TP; |
| 504 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) |
| 505 | val |= SUPPORTED_10000baseT_Full; |
| 506 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) |
| 507 | val |= SUPPORTED_1000baseT_Full; |
| 508 | if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) |
| 509 | val |= SUPPORTED_100baseT_Full; |
| 510 | break; |
| 511 | default: |
| 512 | val |= SUPPORTED_TP; |
| 513 | } |
| 514 | |
| 515 | return val; |
| 516 | } |
| 517 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 518 | bool be_pause_supported(struct be_adapter *adapter) |
| 519 | { |
| 520 | return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB || |
| 521 | adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ? |
| 522 | false : true; |
| 523 | } |
| 524 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 525 | static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 526 | { |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 527 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 528 | u8 link_status; |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 529 | u16 link_speed = 0; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 530 | int status; |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 531 | u32 auto_speeds; |
| 532 | u32 fixed_speeds; |
| 533 | u32 dac_cable_len; |
| 534 | u16 interface_type; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 535 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 536 | if (adapter->phy.link_speed < 0) { |
| 537 | status = be_cmd_link_status_query(adapter, &link_speed, |
| 538 | &link_status, 0); |
| 539 | if (!status) |
| 540 | be_link_status_update(adapter, link_status); |
| 541 | ethtool_cmd_speed_set(ecmd, link_speed); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 542 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 543 | status = be_cmd_get_phy_info(adapter); |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 544 | if (!status) { |
| 545 | interface_type = adapter->phy.interface_type; |
| 546 | auto_speeds = adapter->phy.auto_speeds_supported; |
| 547 | fixed_speeds = adapter->phy.fixed_speeds_supported; |
| 548 | dac_cable_len = adapter->phy.dac_cable_len; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 549 | |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 550 | ecmd->supported = |
| 551 | convert_to_et_setting(interface_type, |
| 552 | auto_speeds | |
| 553 | fixed_speeds); |
| 554 | ecmd->advertising = |
| 555 | convert_to_et_setting(interface_type, |
| 556 | auto_speeds); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 557 | |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 558 | ecmd->port = be_get_port_type(interface_type, |
| 559 | dac_cable_len); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 560 | |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 561 | if (adapter->phy.auto_speeds_supported) { |
| 562 | ecmd->supported |= SUPPORTED_Autoneg; |
| 563 | ecmd->autoneg = AUTONEG_ENABLE; |
| 564 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 565 | } |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 566 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 567 | ecmd->supported |= SUPPORTED_Pause; |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 568 | if (be_pause_supported(adapter)) |
| 569 | ecmd->advertising |= ADVERTISED_Pause; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 570 | |
Padmanabh Ratnakar | db15dfa | 2012-10-20 06:03:04 +0000 | [diff] [blame] | 571 | switch (adapter->phy.interface_type) { |
| 572 | case PHY_TYPE_KR_10GB: |
| 573 | case PHY_TYPE_KX4_10GB: |
| 574 | ecmd->transceiver = XCVR_INTERNAL; |
| 575 | break; |
| 576 | default: |
| 577 | ecmd->transceiver = XCVR_EXTERNAL; |
| 578 | break; |
| 579 | } |
| 580 | } else { |
| 581 | ecmd->port = PORT_OTHER; |
| 582 | ecmd->autoneg = AUTONEG_DISABLE; |
| 583 | ecmd->transceiver = XCVR_DUMMY1; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 584 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 585 | |
| 586 | /* Save for future use */ |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 587 | adapter->phy.link_speed = ethtool_cmd_speed(ecmd); |
| 588 | adapter->phy.port_type = ecmd->port; |
| 589 | adapter->phy.transceiver = ecmd->transceiver; |
| 590 | adapter->phy.autoneg = ecmd->autoneg; |
| 591 | adapter->phy.advertising = ecmd->advertising; |
| 592 | adapter->phy.supported = ecmd->supported; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 593 | } else { |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 594 | ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed); |
| 595 | ecmd->port = adapter->phy.port_type; |
| 596 | ecmd->transceiver = adapter->phy.transceiver; |
| 597 | ecmd->autoneg = adapter->phy.autoneg; |
| 598 | ecmd->advertising = adapter->phy.advertising; |
| 599 | ecmd->supported = adapter->phy.supported; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 600 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 601 | |
Somnath Kotur | 682256d | 2012-05-02 03:40:32 +0000 | [diff] [blame] | 602 | ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 603 | ecmd->phy_address = adapter->port_num; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 604 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
Sathya Perla | 110b82b | 2011-12-13 00:58:49 +0000 | [diff] [blame] | 608 | static void be_get_ringparam(struct net_device *netdev, |
| 609 | struct ethtool_ringparam *ring) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 610 | { |
| 611 | struct be_adapter *adapter = netdev_priv(netdev); |
| 612 | |
Sathya Perla | 110b82b | 2011-12-13 00:58:49 +0000 | [diff] [blame] | 613 | ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len; |
| 614 | ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static void |
| 618 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 619 | { |
| 620 | struct be_adapter *adapter = netdev_priv(netdev); |
| 621 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 622 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 623 | ecmd->autoneg = adapter->phy.fc_autoneg; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static int |
| 627 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 628 | { |
| 629 | struct be_adapter *adapter = netdev_priv(netdev); |
| 630 | int status; |
| 631 | |
Padmanabh Ratnakar | c871c5f | 2012-07-12 03:56:11 +0000 | [diff] [blame] | 632 | if (ecmd->autoneg != adapter->phy.fc_autoneg) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 633 | return -EINVAL; |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 634 | adapter->tx_fc = ecmd->tx_pause; |
| 635 | adapter->rx_fc = ecmd->rx_pause; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 636 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 637 | status = be_cmd_set_flow_control(adapter, |
| 638 | adapter->tx_fc, adapter->rx_fc); |
| 639 | if (status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 640 | dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); |
| 641 | |
| 642 | return status; |
| 643 | } |
| 644 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 645 | static int |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 646 | be_set_phys_id(struct net_device *netdev, |
| 647 | enum ethtool_phys_id_state state) |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 648 | { |
| 649 | struct be_adapter *adapter = netdev_priv(netdev); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 650 | |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 651 | switch (state) { |
| 652 | case ETHTOOL_ID_ACTIVE: |
| 653 | be_cmd_get_beacon_state(adapter, adapter->hba_port_num, |
| 654 | &adapter->beacon_state); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 655 | return 1; /* cycle on/off once per second */ |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 656 | |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 657 | case ETHTOOL_ID_ON: |
| 658 | be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, |
| 659 | BEACON_STATE_ENABLED); |
| 660 | break; |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 661 | |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 662 | case ETHTOOL_ID_OFF: |
| 663 | be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, |
| 664 | BEACON_STATE_DISABLED); |
| 665 | break; |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 666 | |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 667 | case ETHTOOL_ID_INACTIVE: |
| 668 | be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, |
| 669 | adapter->beacon_state); |
| 670 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 671 | |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 672 | return 0; |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 675 | static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump) |
| 676 | { |
| 677 | struct be_adapter *adapter = netdev_priv(netdev); |
| 678 | struct device *dev = &adapter->pdev->dev; |
| 679 | int status; |
| 680 | |
| 681 | if (!lancer_chip(adapter)) { |
| 682 | dev_err(dev, "FW dump not supported\n"); |
| 683 | return -EOPNOTSUPP; |
| 684 | } |
| 685 | |
| 686 | if (dump_present(adapter)) { |
| 687 | dev_err(dev, "Previous dump not cleared, not forcing dump\n"); |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | switch (dump->flag) { |
| 692 | case LANCER_INITIATE_FW_DUMP: |
| 693 | status = lancer_initiate_dump(adapter); |
| 694 | if (!status) |
| 695 | dev_info(dev, "F/w dump initiated successfully\n"); |
| 696 | break; |
| 697 | default: |
| 698 | dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag); |
| 699 | return -EINVAL; |
| 700 | } |
| 701 | return status; |
| 702 | } |
Ajit Khaparde | dcf96f1 | 2011-02-11 13:39:30 +0000 | [diff] [blame] | 703 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 704 | static void |
| 705 | be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 706 | { |
| 707 | struct be_adapter *adapter = netdev_priv(netdev); |
| 708 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 709 | if (be_is_wol_supported(adapter)) { |
| 710 | wol->supported |= WAKE_MAGIC; |
Sarveshwar Bandi | b424332 | 2013-04-25 00:56:56 +0000 | [diff] [blame] | 711 | if (adapter->wol) |
| 712 | wol->wolopts |= WAKE_MAGIC; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 713 | } else |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 714 | wol->wolopts = 0; |
| 715 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static int |
| 719 | be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 720 | { |
| 721 | struct be_adapter *adapter = netdev_priv(netdev); |
| 722 | |
| 723 | if (wol->wolopts & ~WAKE_MAGIC) |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 724 | return -EOPNOTSUPP; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 725 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 726 | if (!be_is_wol_supported(adapter)) { |
| 727 | dev_warn(&adapter->pdev->dev, "WOL not supported\n"); |
| 728 | return -EOPNOTSUPP; |
| 729 | } |
| 730 | |
| 731 | if (wol->wolopts & WAKE_MAGIC) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 732 | adapter->wol = true; |
| 733 | else |
| 734 | adapter->wol = false; |
| 735 | |
| 736 | return 0; |
| 737 | } |
| 738 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 739 | static int |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 740 | be_test_ddr_dma(struct be_adapter *adapter) |
| 741 | { |
| 742 | int ret, i; |
| 743 | struct be_dma_mem ddrdma_cmd; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 744 | static const u64 pattern[2] = { |
| 745 | 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL |
| 746 | }; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 747 | |
| 748 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 749 | ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size, |
| 750 | &ddrdma_cmd.dma, GFP_KERNEL); |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 751 | if (!ddrdma_cmd.va) |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 752 | return -ENOMEM; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 753 | |
| 754 | for (i = 0; i < 2; i++) { |
| 755 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], |
| 756 | 4096, &ddrdma_cmd); |
| 757 | if (ret != 0) |
| 758 | goto err; |
| 759 | } |
| 760 | |
| 761 | err: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 762 | dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, |
| 763 | ddrdma_cmd.dma); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 764 | return ret; |
| 765 | } |
| 766 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 767 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
| 768 | u64 *status) |
| 769 | { |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 770 | be_cmd_set_loopback(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 771 | loopback_type, 1); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 772 | *status = be_cmd_loopback_test(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 773 | loopback_type, 1500, |
| 774 | 2, 0xabc); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 775 | be_cmd_set_loopback(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 776 | BE_NO_LOOPBACK, 1); |
| 777 | return *status; |
| 778 | } |
| 779 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 780 | static void |
| 781 | be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) |
| 782 | { |
| 783 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 784 | int status; |
| 785 | u8 link_status = 0; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 786 | |
Suresh Reddy | 78d0b11 | 2013-04-25 23:03:22 +0000 | [diff] [blame] | 787 | if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { |
| 788 | dev_err(&adapter->pdev->dev, "Self test not supported\n"); |
| 789 | test->flags |= ETH_TEST_FL_FAILED; |
| 790 | return; |
| 791 | } |
| 792 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 793 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); |
| 794 | |
| 795 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 796 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, |
| 797 | &data[0]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 798 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 799 | } |
| 800 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, |
| 801 | &data[1]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 802 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 803 | } |
| 804 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, |
| 805 | &data[2]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 806 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 807 | } |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 808 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 809 | |
Padmanabh Ratnakar | a704739 | 2012-04-25 01:46:28 +0000 | [diff] [blame] | 810 | if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) { |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 811 | data[3] = 1; |
| 812 | test->flags |= ETH_TEST_FL_FAILED; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 815 | status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); |
| 816 | if (status) { |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 817 | test->flags |= ETH_TEST_FL_FAILED; |
| 818 | data[4] = -1; |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 819 | } else if (!link_status) { |
Ajit Khaparde | 4ee7721 | 2011-02-20 11:41:20 +0000 | [diff] [blame] | 820 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 821 | data[4] = 1; |
| 822 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static int |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 826 | be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) |
| 827 | { |
| 828 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 829 | |
Ben Hutchings | 786f528 | 2012-02-01 09:32:25 +0000 | [diff] [blame] | 830 | return be_load_fw(adapter, efl->data); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 833 | static int |
| 834 | be_get_eeprom_len(struct net_device *netdev) |
| 835 | { |
Padmanabh Ratnakar | af5875b | 2011-11-16 02:03:07 +0000 | [diff] [blame] | 836 | struct be_adapter *adapter = netdev_priv(netdev); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 837 | |
| 838 | if (!check_privilege(adapter, MAX_PRIVILEGES)) |
| 839 | return 0; |
| 840 | |
Padmanabh Ratnakar | af5875b | 2011-11-16 02:03:07 +0000 | [diff] [blame] | 841 | if (lancer_chip(adapter)) { |
| 842 | if (be_physfn(adapter)) |
| 843 | return lancer_cmd_get_file_len(adapter, |
| 844 | LANCER_VPD_PF_FILE); |
| 845 | else |
| 846 | return lancer_cmd_get_file_len(adapter, |
| 847 | LANCER_VPD_VF_FILE); |
| 848 | } else { |
| 849 | return BE_READ_SEEPROM_LEN; |
| 850 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static int |
| 854 | be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, |
| 855 | uint8_t *data) |
| 856 | { |
| 857 | struct be_adapter *adapter = netdev_priv(netdev); |
| 858 | struct be_dma_mem eeprom_cmd; |
| 859 | struct be_cmd_resp_seeprom_read *resp; |
| 860 | int status; |
| 861 | |
| 862 | if (!eeprom->len) |
| 863 | return -EINVAL; |
| 864 | |
Padmanabh Ratnakar | af5875b | 2011-11-16 02:03:07 +0000 | [diff] [blame] | 865 | if (lancer_chip(adapter)) { |
| 866 | if (be_physfn(adapter)) |
| 867 | return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE, |
| 868 | eeprom->len, data); |
| 869 | else |
| 870 | return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE, |
| 871 | eeprom->len, data); |
| 872 | } |
| 873 | |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 874 | eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); |
| 875 | |
| 876 | memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); |
| 877 | eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 878 | eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size, |
| 879 | &eeprom_cmd.dma, GFP_KERNEL); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 880 | |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 881 | if (!eeprom_cmd.va) |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 882 | return -ENOMEM; |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 883 | |
| 884 | status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); |
| 885 | |
| 886 | if (!status) { |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 887 | resp = eeprom_cmd.va; |
Ajit Khaparde | c0ad984 | 2010-02-08 17:51:26 +0000 | [diff] [blame] | 888 | memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 889 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 890 | dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, |
| 891 | eeprom_cmd.dma); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 892 | |
| 893 | return status; |
| 894 | } |
| 895 | |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 896 | static u32 be_get_msg_level(struct net_device *netdev) |
| 897 | { |
| 898 | struct be_adapter *adapter = netdev_priv(netdev); |
| 899 | |
| 900 | if (lancer_chip(adapter)) { |
| 901 | dev_err(&adapter->pdev->dev, "Operation not supported\n"); |
| 902 | return -EOPNOTSUPP; |
| 903 | } |
| 904 | |
| 905 | return adapter->msg_enable; |
| 906 | } |
| 907 | |
| 908 | static void be_set_fw_log_level(struct be_adapter *adapter, u32 level) |
| 909 | { |
| 910 | struct be_dma_mem extfat_cmd; |
| 911 | struct be_fat_conf_params *cfgs; |
| 912 | int status; |
| 913 | int i, j; |
| 914 | |
| 915 | memset(&extfat_cmd, 0, sizeof(struct be_dma_mem)); |
| 916 | extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps); |
| 917 | extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size, |
| 918 | &extfat_cmd.dma); |
| 919 | if (!extfat_cmd.va) { |
| 920 | dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n", |
| 921 | __func__); |
| 922 | goto err; |
| 923 | } |
| 924 | status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd); |
| 925 | if (!status) { |
| 926 | cfgs = (struct be_fat_conf_params *)(extfat_cmd.va + |
| 927 | sizeof(struct be_cmd_resp_hdr)); |
Anton Blanchard | ac46a46 | 2012-07-24 15:05:25 +0000 | [diff] [blame] | 928 | for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) { |
| 929 | u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes); |
| 930 | for (j = 0; j < num_modes; j++) { |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 931 | if (cfgs->module[i].trace_lvl[j].mode == |
| 932 | MODE_UART) |
| 933 | cfgs->module[i].trace_lvl[j].dbg_lvl = |
| 934 | cpu_to_le32(level); |
| 935 | } |
| 936 | } |
| 937 | status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, |
| 938 | cfgs); |
| 939 | if (status) |
| 940 | dev_err(&adapter->pdev->dev, |
| 941 | "Message level set failed\n"); |
| 942 | } else { |
| 943 | dev_err(&adapter->pdev->dev, "Message level get failed\n"); |
| 944 | } |
| 945 | |
| 946 | pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va, |
| 947 | extfat_cmd.dma); |
| 948 | err: |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | static void be_set_msg_level(struct net_device *netdev, u32 level) |
| 953 | { |
| 954 | struct be_adapter *adapter = netdev_priv(netdev); |
| 955 | |
| 956 | if (lancer_chip(adapter)) { |
| 957 | dev_err(&adapter->pdev->dev, "Operation not supported\n"); |
| 958 | return; |
| 959 | } |
| 960 | |
| 961 | if (adapter->msg_enable == level) |
| 962 | return; |
| 963 | |
| 964 | if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW)) |
| 965 | be_set_fw_log_level(adapter, level & NETIF_MSG_HW ? |
| 966 | FW_LOG_LEVEL_DEFAULT : FW_LOG_LEVEL_FATAL); |
| 967 | adapter->msg_enable = level; |
| 968 | |
| 969 | return; |
| 970 | } |
| 971 | |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 972 | static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type) |
| 973 | { |
| 974 | u64 data = 0; |
| 975 | |
| 976 | switch (flow_type) { |
| 977 | case TCP_V4_FLOW: |
| 978 | if (adapter->rss_flags & RSS_ENABLE_IPV4) |
| 979 | data |= RXH_IP_DST | RXH_IP_SRC; |
| 980 | if (adapter->rss_flags & RSS_ENABLE_TCP_IPV4) |
| 981 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 982 | break; |
| 983 | case UDP_V4_FLOW: |
| 984 | if (adapter->rss_flags & RSS_ENABLE_IPV4) |
| 985 | data |= RXH_IP_DST | RXH_IP_SRC; |
| 986 | if (adapter->rss_flags & RSS_ENABLE_UDP_IPV4) |
| 987 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 988 | break; |
| 989 | case TCP_V6_FLOW: |
| 990 | if (adapter->rss_flags & RSS_ENABLE_IPV6) |
| 991 | data |= RXH_IP_DST | RXH_IP_SRC; |
| 992 | if (adapter->rss_flags & RSS_ENABLE_TCP_IPV6) |
| 993 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 994 | break; |
| 995 | case UDP_V6_FLOW: |
| 996 | if (adapter->rss_flags & RSS_ENABLE_IPV6) |
| 997 | data |= RXH_IP_DST | RXH_IP_SRC; |
| 998 | if (adapter->rss_flags & RSS_ENABLE_UDP_IPV6) |
| 999 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1000 | break; |
| 1001 | } |
| 1002 | |
| 1003 | return data; |
| 1004 | } |
| 1005 | |
| 1006 | static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 1007 | u32 *rule_locs) |
| 1008 | { |
| 1009 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1010 | |
| 1011 | if (!be_multi_rxq(adapter)) { |
| 1012 | dev_info(&adapter->pdev->dev, |
| 1013 | "ethtool::get_rxnfc: RX flow hashing is disabled\n"); |
| 1014 | return -EINVAL; |
| 1015 | } |
| 1016 | |
| 1017 | switch (cmd->cmd) { |
| 1018 | case ETHTOOL_GRXFH: |
| 1019 | cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type); |
| 1020 | break; |
| 1021 | case ETHTOOL_GRXRINGS: |
| 1022 | cmd->data = adapter->num_rx_qs - 1; |
| 1023 | break; |
| 1024 | default: |
| 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | static int be_set_rss_hash_opts(struct be_adapter *adapter, |
| 1032 | struct ethtool_rxnfc *cmd) |
| 1033 | { |
| 1034 | struct be_rx_obj *rxo; |
| 1035 | int status = 0, i, j; |
| 1036 | u8 rsstable[128]; |
| 1037 | u32 rss_flags = adapter->rss_flags; |
| 1038 | |
| 1039 | if (cmd->data != L3_RSS_FLAGS && |
| 1040 | cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS)) |
| 1041 | return -EINVAL; |
| 1042 | |
| 1043 | switch (cmd->flow_type) { |
| 1044 | case TCP_V4_FLOW: |
| 1045 | if (cmd->data == L3_RSS_FLAGS) |
| 1046 | rss_flags &= ~RSS_ENABLE_TCP_IPV4; |
| 1047 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) |
| 1048 | rss_flags |= RSS_ENABLE_IPV4 | |
| 1049 | RSS_ENABLE_TCP_IPV4; |
| 1050 | break; |
| 1051 | case TCP_V6_FLOW: |
| 1052 | if (cmd->data == L3_RSS_FLAGS) |
| 1053 | rss_flags &= ~RSS_ENABLE_TCP_IPV6; |
| 1054 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) |
| 1055 | rss_flags |= RSS_ENABLE_IPV6 | |
| 1056 | RSS_ENABLE_TCP_IPV6; |
| 1057 | break; |
| 1058 | case UDP_V4_FLOW: |
| 1059 | if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && |
| 1060 | BEx_chip(adapter)) |
| 1061 | return -EINVAL; |
| 1062 | |
| 1063 | if (cmd->data == L3_RSS_FLAGS) |
| 1064 | rss_flags &= ~RSS_ENABLE_UDP_IPV4; |
| 1065 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) |
| 1066 | rss_flags |= RSS_ENABLE_IPV4 | |
| 1067 | RSS_ENABLE_UDP_IPV4; |
| 1068 | break; |
| 1069 | case UDP_V6_FLOW: |
| 1070 | if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && |
| 1071 | BEx_chip(adapter)) |
| 1072 | return -EINVAL; |
| 1073 | |
| 1074 | if (cmd->data == L3_RSS_FLAGS) |
| 1075 | rss_flags &= ~RSS_ENABLE_UDP_IPV6; |
| 1076 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) |
| 1077 | rss_flags |= RSS_ENABLE_IPV6 | |
| 1078 | RSS_ENABLE_UDP_IPV6; |
| 1079 | break; |
| 1080 | default: |
| 1081 | return -EINVAL; |
| 1082 | } |
| 1083 | |
| 1084 | if (rss_flags == adapter->rss_flags) |
| 1085 | return status; |
| 1086 | |
| 1087 | if (be_multi_rxq(adapter)) { |
| 1088 | for (j = 0; j < 128; j += adapter->num_rx_qs - 1) { |
| 1089 | for_all_rss_queues(adapter, rxo, i) { |
| 1090 | if ((j + i) >= 128) |
| 1091 | break; |
| 1092 | rsstable[j + i] = rxo->rss_id; |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | status = be_cmd_rss_config(adapter, rsstable, rss_flags, 128); |
| 1097 | if (!status) |
| 1098 | adapter->rss_flags = rss_flags; |
| 1099 | |
| 1100 | return status; |
| 1101 | } |
| 1102 | |
| 1103 | static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 1104 | { |
| 1105 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1106 | int status = 0; |
| 1107 | |
| 1108 | if (!be_multi_rxq(adapter)) { |
| 1109 | dev_err(&adapter->pdev->dev, |
| 1110 | "ethtool::set_rxnfc: RX flow hashing is disabled\n"); |
| 1111 | return -EINVAL; |
| 1112 | } |
| 1113 | |
| 1114 | switch (cmd->cmd) { |
| 1115 | case ETHTOOL_SRXFH: |
| 1116 | status = be_set_rss_hash_opts(adapter, cmd); |
| 1117 | break; |
| 1118 | default: |
| 1119 | return -EINVAL; |
| 1120 | } |
| 1121 | |
| 1122 | return status; |
| 1123 | } |
| 1124 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 1125 | static void be_get_channels(struct net_device *netdev, |
| 1126 | struct ethtool_channels *ch) |
| 1127 | { |
| 1128 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1129 | |
| 1130 | ch->combined_count = adapter->num_evt_qs; |
| 1131 | ch->max_combined = be_max_qs(adapter); |
| 1132 | } |
| 1133 | |
| 1134 | static int be_set_channels(struct net_device *netdev, |
| 1135 | struct ethtool_channels *ch) |
| 1136 | { |
| 1137 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1138 | |
| 1139 | if (ch->rx_count || ch->tx_count || ch->other_count || |
| 1140 | !ch->combined_count || ch->combined_count > be_max_qs(adapter)) |
| 1141 | return -EINVAL; |
| 1142 | |
| 1143 | adapter->cfg_num_qs = ch->combined_count; |
| 1144 | |
| 1145 | return be_update_queues(adapter); |
| 1146 | } |
| 1147 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1148 | const struct ethtool_ops be_ethtool_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1149 | .get_settings = be_get_settings, |
| 1150 | .get_drvinfo = be_get_drvinfo, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 1151 | .get_wol = be_get_wol, |
| 1152 | .set_wol = be_set_wol, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1153 | .get_link = ethtool_op_get_link, |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 1154 | .get_eeprom_len = be_get_eeprom_len, |
| 1155 | .get_eeprom = be_read_eeprom, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1156 | .get_coalesce = be_get_coalesce, |
| 1157 | .set_coalesce = be_set_coalesce, |
| 1158 | .get_ringparam = be_get_ringparam, |
| 1159 | .get_pauseparam = be_get_pauseparam, |
| 1160 | .set_pauseparam = be_set_pauseparam, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1161 | .get_strings = be_get_stat_strings, |
stephen hemminger | 1a64246 | 2011-04-04 11:06:40 +0000 | [diff] [blame] | 1162 | .set_phys_id = be_set_phys_id, |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 1163 | .set_dump = be_set_dump, |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 1164 | .get_msglevel = be_get_msg_level, |
| 1165 | .set_msglevel = be_set_msg_level, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 1166 | .get_sset_count = be_get_sset_count, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1167 | .get_ethtool_stats = be_get_ethtool_stats, |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1168 | .get_regs_len = be_get_reg_len, |
| 1169 | .get_regs = be_get_regs, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1170 | .flash_device = be_do_flash, |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 1171 | .self_test = be_self_test, |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 1172 | .get_rxnfc = be_get_rxnfc, |
| 1173 | .set_rxnfc = be_set_rxnfc, |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 1174 | .get_channels = be_get_channels, |
| 1175 | .set_channels = be_set_channels |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1176 | }; |