Path: blob/main/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
39566 views
/*-1* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.02*3* Copyright (c) 2007 Mellanox Technologies. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#include <sys/cdefs.h>35#include <linux/kernel.h>36#include <linux/netdevice.h>3738#include "ipoib.h"3940static void ipoib_get_drvinfo(if_t netdev,41struct ethtool_drvinfo *drvinfo)42{43strncpy(drvinfo->driver, "ipoib", sizeof(drvinfo->driver) - 1);44}4546static u32 ipoib_get_rx_csum(if_t dev)47{48struct ipoib_dev_priv *priv = dev->if_softc;49return test_bit(IPOIB_FLAG_CSUM, &priv->flags) &&50!test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);51}5253static int ipoib_get_coalesce(if_t dev,54struct ethtool_coalesce *coal)55{56struct ipoib_dev_priv *priv = dev->if_softc;5758coal->rx_coalesce_usecs = priv->ethtool.coalesce_usecs;59coal->tx_coalesce_usecs = priv->ethtool.coalesce_usecs;60coal->rx_max_coalesced_frames = priv->ethtool.max_coalesced_frames;61coal->tx_max_coalesced_frames = priv->ethtool.max_coalesced_frames;6263return 0;64}6566static int ipoib_set_coalesce(if_t dev,67struct ethtool_coalesce *coal)68{69struct ipoib_dev_priv *priv = dev->if_softc;70int ret;7172/*73* Since IPoIB uses a single CQ for both rx and tx, we assume74* that rx params dictate the configuration. These values are75* saved in the private data and returned when ipoib_get_coalesce()76* is called.77*/78if (coal->rx_coalesce_usecs > 0xffff ||79coal->rx_max_coalesced_frames > 0xffff)80return -EINVAL;8182if (coal->rx_max_coalesced_frames | coal->rx_coalesce_usecs) {83if (!coal->rx_max_coalesced_frames)84coal->rx_max_coalesced_frames = 0xffff;85else if (!coal->rx_coalesce_usecs)86coal->rx_coalesce_usecs = 0xffff;87}8889ret = ib_modify_cq(priv->recv_cq, coal->rx_max_coalesced_frames,90coal->rx_coalesce_usecs);91if (ret && ret != -ENOSYS) {92ipoib_warn(priv, "failed modifying CQ (%d)\n", ret);93return ret;94}9596coal->tx_coalesce_usecs = coal->rx_coalesce_usecs;97coal->tx_max_coalesced_frames = coal->rx_max_coalesced_frames;98priv->ethtool.coalesce_usecs = coal->rx_coalesce_usecs;99priv->ethtool.max_coalesced_frames = coal->rx_max_coalesced_frames;100101return 0;102}103104static const char ipoib_stats_keys[][ETH_GSTRING_LEN] = {105"LRO aggregated", "LRO flushed",106"LRO avg aggr", "LRO no desc"107};108109static void ipoib_get_strings(if_t netdev, u32 stringset, u8 *data)110{111switch (stringset) {112case ETH_SS_STATS:113memcpy(data, *ipoib_stats_keys, sizeof(ipoib_stats_keys));114break;115}116}117118static int ipoib_get_sset_count(if_t dev, int sset)119{120switch (sset) {121case ETH_SS_STATS:122return ARRAY_SIZE(ipoib_stats_keys);123default:124return -EOPNOTSUPP;125}126}127128static void ipoib_get_ethtool_stats(if_t dev,129struct ethtool_stats *stats, uint64_t *data)130{131struct ipoib_dev_priv *priv = dev->if_softc;132int index = 0;133134/* Get LRO statistics */135data[index++] = priv->lro.lro_mgr.stats.aggregated;136data[index++] = priv->lro.lro_mgr.stats.flushed;137if (priv->lro.lro_mgr.stats.flushed)138data[index++] = priv->lro.lro_mgr.stats.aggregated /139priv->lro.lro_mgr.stats.flushed;140else141data[index++] = 0;142data[index++] = priv->lro.lro_mgr.stats.no_desc;143}144145static const struct ethtool_ops ipoib_ethtool_ops = {146.get_drvinfo = ipoib_get_drvinfo,147.get_rx_csum = ipoib_get_rx_csum,148.get_coalesce = ipoib_get_coalesce,149.set_coalesce = ipoib_set_coalesce,150.get_flags = ethtool_op_get_flags,151.set_flags = ethtool_op_set_flags,152.get_strings = ipoib_get_strings,153.get_sset_count = ipoib_get_sset_count,154.get_ethtool_stats = ipoib_get_ethtool_stats,155};156157void ipoib_set_ethtool_ops(if_t dev)158{159SET_ETHTOOL_OPS(dev, &ipoib_ethtool_ops);160}161162163