2 * Copyright 2013 Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 #include <linux/netdevice.h>
20 #include <linux/ethtool.h>
27 char name[ETH_GSTRING_LEN];
31 #define ENIC_TX_STAT(stat) { \
33 .index = offsetof(struct vnic_tx_stats, stat) / sizeof(u64) \
36 #define ENIC_RX_STAT(stat) { \
38 .index = offsetof(struct vnic_rx_stats, stat) / sizeof(u64) \
41 static const struct enic_stat enic_tx_stats[] = {
42 ENIC_TX_STAT(tx_frames_ok),
43 ENIC_TX_STAT(tx_unicast_frames_ok),
44 ENIC_TX_STAT(tx_multicast_frames_ok),
45 ENIC_TX_STAT(tx_broadcast_frames_ok),
46 ENIC_TX_STAT(tx_bytes_ok),
47 ENIC_TX_STAT(tx_unicast_bytes_ok),
48 ENIC_TX_STAT(tx_multicast_bytes_ok),
49 ENIC_TX_STAT(tx_broadcast_bytes_ok),
50 ENIC_TX_STAT(tx_drops),
51 ENIC_TX_STAT(tx_errors),
55 static const struct enic_stat enic_rx_stats[] = {
56 ENIC_RX_STAT(rx_frames_ok),
57 ENIC_RX_STAT(rx_frames_total),
58 ENIC_RX_STAT(rx_unicast_frames_ok),
59 ENIC_RX_STAT(rx_multicast_frames_ok),
60 ENIC_RX_STAT(rx_broadcast_frames_ok),
61 ENIC_RX_STAT(rx_bytes_ok),
62 ENIC_RX_STAT(rx_unicast_bytes_ok),
63 ENIC_RX_STAT(rx_multicast_bytes_ok),
64 ENIC_RX_STAT(rx_broadcast_bytes_ok),
65 ENIC_RX_STAT(rx_drop),
66 ENIC_RX_STAT(rx_no_bufs),
67 ENIC_RX_STAT(rx_errors),
69 ENIC_RX_STAT(rx_crc_errors),
70 ENIC_RX_STAT(rx_frames_64),
71 ENIC_RX_STAT(rx_frames_127),
72 ENIC_RX_STAT(rx_frames_255),
73 ENIC_RX_STAT(rx_frames_511),
74 ENIC_RX_STAT(rx_frames_1023),
75 ENIC_RX_STAT(rx_frames_1518),
76 ENIC_RX_STAT(rx_frames_to_max),
79 static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
80 static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
82 void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
87 for (i = 0; i < enic->rq_count; i++) {
88 intr = enic_msix_rq_intr(enic, i);
89 vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
93 static int enic_get_settings(struct net_device *netdev,
94 struct ethtool_cmd *ecmd)
96 struct enic *enic = netdev_priv(netdev);
98 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
99 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
100 ecmd->port = PORT_FIBRE;
101 ecmd->transceiver = XCVR_EXTERNAL;
103 if (netif_carrier_ok(netdev)) {
104 ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev));
105 ecmd->duplex = DUPLEX_FULL;
107 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
108 ecmd->duplex = DUPLEX_UNKNOWN;
111 ecmd->autoneg = AUTONEG_DISABLE;
116 static void enic_get_drvinfo(struct net_device *netdev,
117 struct ethtool_drvinfo *drvinfo)
119 struct enic *enic = netdev_priv(netdev);
120 struct vnic_devcmd_fw_info *fw_info;
122 enic_dev_fw_info(enic, &fw_info);
124 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
125 strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
126 strlcpy(drvinfo->fw_version, fw_info->fw_version,
127 sizeof(drvinfo->fw_version));
128 strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
129 sizeof(drvinfo->bus_info));
132 static void enic_get_strings(struct net_device *netdev, u32 stringset,
139 for (i = 0; i < enic_n_tx_stats; i++) {
140 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
141 data += ETH_GSTRING_LEN;
143 for (i = 0; i < enic_n_rx_stats; i++) {
144 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
145 data += ETH_GSTRING_LEN;
151 static int enic_get_sset_count(struct net_device *netdev, int sset)
155 return enic_n_tx_stats + enic_n_rx_stats;
161 static void enic_get_ethtool_stats(struct net_device *netdev,
162 struct ethtool_stats *stats, u64 *data)
164 struct enic *enic = netdev_priv(netdev);
165 struct vnic_stats *vstats;
168 enic_dev_stats_dump(enic, &vstats);
170 for (i = 0; i < enic_n_tx_stats; i++)
171 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
172 for (i = 0; i < enic_n_rx_stats; i++)
173 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
176 static u32 enic_get_msglevel(struct net_device *netdev)
178 struct enic *enic = netdev_priv(netdev);
179 return enic->msg_enable;
182 static void enic_set_msglevel(struct net_device *netdev, u32 value)
184 struct enic *enic = netdev_priv(netdev);
185 enic->msg_enable = value;
188 static int enic_get_coalesce(struct net_device *netdev,
189 struct ethtool_coalesce *ecmd)
191 struct enic *enic = netdev_priv(netdev);
192 struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
194 ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
195 ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
196 if (rxcoal->use_adaptive_rx_coalesce)
197 ecmd->use_adaptive_rx_coalesce = 1;
198 ecmd->rx_coalesce_usecs_low = rxcoal->small_pkt_range_start;
199 ecmd->rx_coalesce_usecs_high = rxcoal->range_end;
204 static int enic_set_coalesce(struct net_device *netdev,
205 struct ethtool_coalesce *ecmd)
207 struct enic *enic = netdev_priv(netdev);
208 u32 tx_coalesce_usecs;
209 u32 rx_coalesce_usecs;
210 u32 rx_coalesce_usecs_low;
211 u32 rx_coalesce_usecs_high;
212 u32 coalesce_usecs_max;
213 unsigned int i, intr;
214 struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
216 coalesce_usecs_max = vnic_dev_get_intr_coal_timer_max(enic->vdev);
217 tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
219 rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
222 rx_coalesce_usecs_low = min_t(u32, ecmd->rx_coalesce_usecs_low,
224 rx_coalesce_usecs_high = min_t(u32, ecmd->rx_coalesce_usecs_high,
227 switch (vnic_dev_get_intr_mode(enic->vdev)) {
228 case VNIC_DEV_INTR_MODE_INTX:
229 if (tx_coalesce_usecs != rx_coalesce_usecs)
231 if (ecmd->use_adaptive_rx_coalesce ||
232 ecmd->rx_coalesce_usecs_low ||
233 ecmd->rx_coalesce_usecs_high)
236 intr = enic_legacy_io_intr();
237 vnic_intr_coalescing_timer_set(&enic->intr[intr],
240 case VNIC_DEV_INTR_MODE_MSI:
241 if (tx_coalesce_usecs != rx_coalesce_usecs)
243 if (ecmd->use_adaptive_rx_coalesce ||
244 ecmd->rx_coalesce_usecs_low ||
245 ecmd->rx_coalesce_usecs_high)
248 vnic_intr_coalescing_timer_set(&enic->intr[0],
251 case VNIC_DEV_INTR_MODE_MSIX:
252 for (i = 0; i < enic->wq_count; i++) {
253 intr = enic_msix_wq_intr(enic, i);
254 vnic_intr_coalescing_timer_set(&enic->intr[intr],
258 if (rxcoal->use_adaptive_rx_coalesce) {
259 if (!ecmd->use_adaptive_rx_coalesce) {
260 rxcoal->use_adaptive_rx_coalesce = 0;
261 enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
264 if (ecmd->use_adaptive_rx_coalesce)
265 rxcoal->use_adaptive_rx_coalesce = 1;
267 enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
270 if (ecmd->rx_coalesce_usecs_high) {
271 if (rx_coalesce_usecs_high <
272 (rx_coalesce_usecs_low + ENIC_AIC_LARGE_PKT_DIFF))
274 rxcoal->range_end = rx_coalesce_usecs_high;
275 rxcoal->small_pkt_range_start = rx_coalesce_usecs_low;
276 rxcoal->large_pkt_range_start = rx_coalesce_usecs_low +
277 ENIC_AIC_LARGE_PKT_DIFF;
284 enic->tx_coalesce_usecs = tx_coalesce_usecs;
285 enic->rx_coalesce_usecs = rx_coalesce_usecs;
290 static const struct ethtool_ops enic_ethtool_ops = {
291 .get_settings = enic_get_settings,
292 .get_drvinfo = enic_get_drvinfo,
293 .get_msglevel = enic_get_msglevel,
294 .set_msglevel = enic_set_msglevel,
295 .get_link = ethtool_op_get_link,
296 .get_strings = enic_get_strings,
297 .get_sset_count = enic_get_sset_count,
298 .get_ethtool_stats = enic_get_ethtool_stats,
299 .get_coalesce = enic_get_coalesce,
300 .set_coalesce = enic_set_coalesce,
303 void enic_set_ethtool_ops(struct net_device *netdev)
305 netdev->ethtool_ops = &enic_ethtool_ops;