182c24c18SEli Cohen /* 282c24c18SEli Cohen * Copyright (c) 2007 Mellanox Technologies. All rights reserved. 382c24c18SEli Cohen * 482c24c18SEli Cohen * This software is available to you under a choice of one of two 582c24c18SEli Cohen * licenses. You may choose to be licensed under the terms of the GNU 682c24c18SEli Cohen * General Public License (GPL) Version 2, available from the file 782c24c18SEli Cohen * COPYING in the main directory of this source tree, or the 882c24c18SEli Cohen * OpenIB.org BSD license below: 982c24c18SEli Cohen * 1082c24c18SEli Cohen * Redistribution and use in source and binary forms, with or 1182c24c18SEli Cohen * without modification, are permitted provided that the following 1282c24c18SEli Cohen * conditions are met: 1382c24c18SEli Cohen * 1482c24c18SEli Cohen * - Redistributions of source code must retain the above 1582c24c18SEli Cohen * copyright notice, this list of conditions and the following 1682c24c18SEli Cohen * disclaimer. 1782c24c18SEli Cohen * 1882c24c18SEli Cohen * - Redistributions in binary form must reproduce the above 1982c24c18SEli Cohen * copyright notice, this list of conditions and the following 2082c24c18SEli Cohen * disclaimer in the documentation and/or other materials 2182c24c18SEli Cohen * provided with the distribution. 2282c24c18SEli Cohen * 2382c24c18SEli Cohen * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 2482c24c18SEli Cohen * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2582c24c18SEli Cohen * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2682c24c18SEli Cohen * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 2782c24c18SEli Cohen * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 2882c24c18SEli Cohen * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2982c24c18SEli Cohen * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 3082c24c18SEli Cohen * SOFTWARE. 3182c24c18SEli Cohen */ 3282c24c18SEli Cohen 3382c24c18SEli Cohen #include <linux/kernel.h> 3482c24c18SEli Cohen #include <linux/ethtool.h> 3582c24c18SEli Cohen #include <linux/netdevice.h> 3682c24c18SEli Cohen 3782c24c18SEli Cohen #include "ipoib.h" 3882c24c18SEli Cohen 3982c24c18SEli Cohen static void ipoib_get_drvinfo(struct net_device *netdev, 4082c24c18SEli Cohen struct ethtool_drvinfo *drvinfo) 4182c24c18SEli Cohen { 424b48680bSYan Burman struct ipoib_dev_priv *priv = netdev_priv(netdev); 434b48680bSYan Burman struct ib_device_attr *attr; 444b48680bSYan Burman 454b48680bSYan Burman attr = kmalloc(sizeof(*attr), GFP_KERNEL); 464b48680bSYan Burman if (attr && !ib_query_device(priv->ca, attr)) 474b48680bSYan Burman snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), 484b48680bSYan Burman "%d.%d.%d", (int)(attr->fw_ver >> 32), 494b48680bSYan Burman (int)(attr->fw_ver >> 16) & 0xffff, 504b48680bSYan Burman (int)attr->fw_ver & 0xffff); 514b48680bSYan Burman kfree(attr); 524b48680bSYan Burman 534b48680bSYan Burman strlcpy(drvinfo->bus_info, dev_name(priv->ca->dma_device), 544b48680bSYan Burman sizeof(drvinfo->bus_info)); 554b48680bSYan Burman 564b48680bSYan Burman strlcpy(drvinfo->version, ipoib_driver_version, 574b48680bSYan Burman sizeof(drvinfo->version)); 584b48680bSYan Burman 594b48680bSYan Burman strlcpy(drvinfo->driver, "ib_ipoib", sizeof(drvinfo->driver)); 6082c24c18SEli Cohen } 6182c24c18SEli Cohen 6228d52b3cSEli Cohen static int ipoib_get_coalesce(struct net_device *dev, 6328d52b3cSEli Cohen struct ethtool_coalesce *coal) 6428d52b3cSEli Cohen { 6528d52b3cSEli Cohen struct ipoib_dev_priv *priv = netdev_priv(dev); 6628d52b3cSEli Cohen 6728d52b3cSEli Cohen coal->rx_coalesce_usecs = priv->ethtool.coalesce_usecs; 6828d52b3cSEli Cohen coal->rx_max_coalesced_frames = priv->ethtool.max_coalesced_frames; 6928d52b3cSEli Cohen 7028d52b3cSEli Cohen return 0; 7128d52b3cSEli Cohen } 7228d52b3cSEli Cohen 7328d52b3cSEli Cohen static int ipoib_set_coalesce(struct net_device *dev, 7428d52b3cSEli Cohen struct ethtool_coalesce *coal) 7528d52b3cSEli Cohen { 7628d52b3cSEli Cohen struct ipoib_dev_priv *priv = netdev_priv(dev); 7728d52b3cSEli Cohen int ret; 7828d52b3cSEli Cohen 7928d52b3cSEli Cohen /* 80757bebb3SOr Gerlitz * These values are saved in the private data and returned 81757bebb3SOr Gerlitz * when ipoib_get_coalesce() is called 8228d52b3cSEli Cohen */ 8328d52b3cSEli Cohen if (coal->rx_coalesce_usecs > 0xffff || 8428d52b3cSEli Cohen coal->rx_max_coalesced_frames > 0xffff) 8528d52b3cSEli Cohen return -EINVAL; 8628d52b3cSEli Cohen 87f56bcd80SEli Cohen ret = ib_modify_cq(priv->recv_cq, coal->rx_max_coalesced_frames, 8828d52b3cSEli Cohen coal->rx_coalesce_usecs); 8928d52b3cSEli Cohen if (ret && ret != -ENOSYS) { 9028d52b3cSEli Cohen ipoib_warn(priv, "failed modifying CQ (%d)\n", ret); 9128d52b3cSEli Cohen return ret; 9228d52b3cSEli Cohen } 9328d52b3cSEli Cohen 9428d52b3cSEli Cohen priv->ethtool.coalesce_usecs = coal->rx_coalesce_usecs; 9528d52b3cSEli Cohen priv->ethtool.max_coalesced_frames = coal->rx_max_coalesced_frames; 9628d52b3cSEli Cohen 9728d52b3cSEli Cohen return 0; 9828d52b3cSEli Cohen } 9928d52b3cSEli Cohen 10082c24c18SEli Cohen static const struct ethtool_ops ipoib_ethtool_ops = { 10182c24c18SEli Cohen .get_drvinfo = ipoib_get_drvinfo, 10228d52b3cSEli Cohen .get_coalesce = ipoib_get_coalesce, 10328d52b3cSEli Cohen .set_coalesce = ipoib_set_coalesce, 10482c24c18SEli Cohen }; 10582c24c18SEli Cohen 10682c24c18SEli Cohen void ipoib_set_ethtool_ops(struct net_device *dev) 10782c24c18SEli Cohen { 10882c24c18SEli Cohen SET_ETHTOOL_OPS(dev, &ipoib_ethtool_ops); 10982c24c18SEli Cohen } 110