1219820Sjeff/* 2219820Sjeff * Copyright (c) 2007 Mellanox Technologies. All rights reserved. 3219820Sjeff * 4219820Sjeff * This software is available to you under a choice of one of two 5219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 6219820Sjeff * General Public License (GPL) Version 2, available from the file 7219820Sjeff * COPYING in the main directory of this source tree, or the 8219820Sjeff * OpenIB.org BSD license below: 9219820Sjeff * 10219820Sjeff * Redistribution and use in source and binary forms, with or 11219820Sjeff * without modification, are permitted provided that the following 12219820Sjeff * conditions are met: 13219820Sjeff * 14219820Sjeff * - Redistributions of source code must retain the above 15219820Sjeff * copyright notice, this list of conditions and the following 16219820Sjeff * disclaimer. 17219820Sjeff * 18219820Sjeff * - Redistributions in binary form must reproduce the above 19219820Sjeff * copyright notice, this list of conditions and the following 20219820Sjeff * disclaimer in the documentation and/or other materials 21219820Sjeff * provided with the distribution. 22219820Sjeff * 23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30219820Sjeff * SOFTWARE. 31219820Sjeff */ 32219820Sjeff 33219820Sjeff#include <linux/kernel.h> 34219820Sjeff#include <linux/ethtool.h> 35219820Sjeff#include <linux/netdevice.h> 36219820Sjeff 37219820Sjeff#include "ipoib.h" 38219820Sjeff 39219820Sjeffstatic void ipoib_get_drvinfo(struct ifnet *netdev, 40219820Sjeff struct ethtool_drvinfo *drvinfo) 41219820Sjeff{ 42219820Sjeff strncpy(drvinfo->driver, "ipoib", sizeof(drvinfo->driver) - 1); 43219820Sjeff} 44219820Sjeff 45219820Sjeffstatic u32 ipoib_get_rx_csum(struct ifnet *dev) 46219820Sjeff{ 47219820Sjeff struct ipoib_dev_priv *priv = dev->if_softc; 48219820Sjeff return test_bit(IPOIB_FLAG_CSUM, &priv->flags) && 49219820Sjeff !test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); 50219820Sjeff} 51219820Sjeff 52219820Sjeffstatic int ipoib_get_coalesce(struct ifnet *dev, 53219820Sjeff struct ethtool_coalesce *coal) 54219820Sjeff{ 55219820Sjeff struct ipoib_dev_priv *priv = dev->if_softc; 56219820Sjeff 57219820Sjeff coal->rx_coalesce_usecs = priv->ethtool.coalesce_usecs; 58219820Sjeff coal->tx_coalesce_usecs = priv->ethtool.coalesce_usecs; 59219820Sjeff coal->rx_max_coalesced_frames = priv->ethtool.max_coalesced_frames; 60219820Sjeff coal->tx_max_coalesced_frames = priv->ethtool.max_coalesced_frames; 61219820Sjeff 62219820Sjeff return 0; 63219820Sjeff} 64219820Sjeff 65219820Sjeffstatic int ipoib_set_coalesce(struct ifnet *dev, 66219820Sjeff struct ethtool_coalesce *coal) 67219820Sjeff{ 68219820Sjeff struct ipoib_dev_priv *priv = dev->if_softc; 69219820Sjeff int ret; 70219820Sjeff 71219820Sjeff /* 72219820Sjeff * Since IPoIB uses a single CQ for both rx and tx, we assume 73219820Sjeff * that rx params dictate the configuration. These values are 74219820Sjeff * saved in the private data and returned when ipoib_get_coalesce() 75219820Sjeff * is called. 76219820Sjeff */ 77219820Sjeff if (coal->rx_coalesce_usecs > 0xffff || 78219820Sjeff coal->rx_max_coalesced_frames > 0xffff) 79219820Sjeff return -EINVAL; 80219820Sjeff 81219820Sjeff if (coal->rx_max_coalesced_frames | coal->rx_coalesce_usecs) { 82219820Sjeff if (!coal->rx_max_coalesced_frames) 83219820Sjeff coal->rx_max_coalesced_frames = 0xffff; 84219820Sjeff else if (!coal->rx_coalesce_usecs) 85219820Sjeff coal->rx_coalesce_usecs = 0xffff; 86219820Sjeff } 87219820Sjeff 88219820Sjeff ret = ib_modify_cq(priv->recv_cq, coal->rx_max_coalesced_frames, 89219820Sjeff coal->rx_coalesce_usecs); 90219820Sjeff if (ret && ret != -ENOSYS) { 91219820Sjeff ipoib_warn(priv, "failed modifying CQ (%d)\n", ret); 92219820Sjeff return ret; 93219820Sjeff } 94219820Sjeff 95219820Sjeff coal->tx_coalesce_usecs = coal->rx_coalesce_usecs; 96219820Sjeff coal->tx_max_coalesced_frames = coal->rx_max_coalesced_frames; 97219820Sjeff priv->ethtool.coalesce_usecs = coal->rx_coalesce_usecs; 98219820Sjeff priv->ethtool.max_coalesced_frames = coal->rx_max_coalesced_frames; 99219820Sjeff 100219820Sjeff return 0; 101219820Sjeff} 102219820Sjeff 103219820Sjeffstatic const char ipoib_stats_keys[][ETH_GSTRING_LEN] = { 104219820Sjeff "LRO aggregated", "LRO flushed", 105219820Sjeff "LRO avg aggr", "LRO no desc" 106219820Sjeff}; 107219820Sjeff 108219820Sjeffstatic void ipoib_get_strings(struct ifnet *netdev, u32 stringset, u8 *data) 109219820Sjeff{ 110219820Sjeff switch (stringset) { 111219820Sjeff case ETH_SS_STATS: 112219820Sjeff memcpy(data, *ipoib_stats_keys, sizeof(ipoib_stats_keys)); 113219820Sjeff break; 114219820Sjeff } 115219820Sjeff} 116219820Sjeff 117219820Sjeffstatic int ipoib_get_sset_count(struct ifnet *dev, int sset) 118219820Sjeff{ 119219820Sjeff switch (sset) { 120219820Sjeff case ETH_SS_STATS: 121219820Sjeff return ARRAY_SIZE(ipoib_stats_keys); 122219820Sjeff default: 123219820Sjeff return -EOPNOTSUPP; 124219820Sjeff } 125219820Sjeff} 126219820Sjeff 127219820Sjeffstatic void ipoib_get_ethtool_stats(struct ifnet *dev, 128219820Sjeff struct ethtool_stats *stats, uint64_t *data) 129219820Sjeff{ 130219820Sjeff struct ipoib_dev_priv *priv = dev->if_softc; 131219820Sjeff int index = 0; 132219820Sjeff 133219820Sjeff /* Get LRO statistics */ 134219820Sjeff data[index++] = priv->lro.lro_mgr.stats.aggregated; 135219820Sjeff data[index++] = priv->lro.lro_mgr.stats.flushed; 136219820Sjeff if (priv->lro.lro_mgr.stats.flushed) 137219820Sjeff data[index++] = priv->lro.lro_mgr.stats.aggregated / 138219820Sjeff priv->lro.lro_mgr.stats.flushed; 139219820Sjeff else 140219820Sjeff data[index++] = 0; 141219820Sjeff data[index++] = priv->lro.lro_mgr.stats.no_desc; 142219820Sjeff} 143219820Sjeff 144219820Sjeffstatic const struct ethtool_ops ipoib_ethtool_ops = { 145219820Sjeff .get_drvinfo = ipoib_get_drvinfo, 146219820Sjeff .get_rx_csum = ipoib_get_rx_csum, 147219820Sjeff .get_coalesce = ipoib_get_coalesce, 148219820Sjeff .set_coalesce = ipoib_set_coalesce, 149219820Sjeff .get_flags = ethtool_op_get_flags, 150219820Sjeff .set_flags = ethtool_op_set_flags, 151219820Sjeff .get_strings = ipoib_get_strings, 152219820Sjeff .get_sset_count = ipoib_get_sset_count, 153219820Sjeff .get_ethtool_stats = ipoib_get_ethtool_stats, 154219820Sjeff}; 155219820Sjeff 156219820Sjeffvoid ipoib_set_ethtool_ops(struct ifnet *dev) 157219820Sjeff{ 158219820Sjeff SET_ETHTOOL_OPS(dev, &ipoib_ethtool_ops); 159219820Sjeff} 160