From patchwork Fri Nov 6 22:17:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 320867 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1674432ilc; Fri, 6 Nov 2020 14:18:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeXCBJQuB5bzTBNFo5MydPbXByF+VlreMnwdF4KoMp9NI9GyHbcDDmC1eUSOep7muoEMO6 X-Received: by 2002:a17:906:6a15:: with SMTP id o21mr4110960ejr.305.1604701111353; Fri, 06 Nov 2020 14:18:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604701111; cv=none; d=google.com; s=arc-20160816; b=NVJZS1ebEHI3cJvsSoBepQ1b3gazFi5W8wvv5iyqAjIFUProWwpMq8SAxBtTvDIahR O9f9/f/Eo94aRkg/BznTvYnD9yLmElx5Vsic8ffRuY1YDsB6Fk4G7k2WhKpeIs1lXz7+ PPeJ7eH6tCuwiFL3nagLEWbRpztpAUEClMis5CwafrLz0UL2egAR4nC0KnNP0kosApjS xVifiYrRt7ZDk4ELuxORmUkoag5V5BFQidnA4TdvvvhTzL9NaTX2rKiTK+olV4ThPKwu P1shTe5EyEQL2CacLK3mrndmBLDeUjcF0wSpb5UEm+rw6K4xxbgv6uDYy4PeIqKJOXR8 lH9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xHUFZltFmB9gDjZJxNmxqlTHXWFWYbKEEJIvSaOIA20=; b=vMq8bVCuywCCUVZR+qcFYmws2Y5nwoT1/sliZ2Kl58uS5KGCGe2Ru6MuPwr4GUpOxY zXaeqYc2W2aBxwMwiDJBKe7y36yOcOrJ36F7oTrX1FPPwrqkjCamuo0RCx7hVab6Q4Ee ktqqA9sAq6BAV3uiA/uwEOTPcTvJROtBGSnmSYUwntnS4iYY7QAm3QfKVf2A3C6qnwv0 zoY9vc7nqZpiTjgdt1cCgL27PJmFbgfDxgy13A4gwnhCTBtKxuwQrKB30avxMN4ahfTV t2OES80capi8qL1lMcVqb8srkzofvNCYM8jNolk9R5+GRsuIFOBwsViGs+FaQogPyif5 p/cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+NDqiGA; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci4si1848008ejb.436.2020.11.06.14.18.31; Fri, 06 Nov 2020 14:18:31 -0800 (PST) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+NDqiGA; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729012AbgKFWSa (ORCPT + 8 others); Fri, 6 Nov 2020 17:18:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:41792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728967AbgKFWS1 (ORCPT ); Fri, 6 Nov 2020 17:18:27 -0500 Received: from localhost.localdomain (HSI-KBW-46-223-126-90.hsi.kabel-badenwuerttemberg.de [46.223.126.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEFC121556; Fri, 6 Nov 2020 22:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604701106; bh=zfW+TstbaETCjrecVXCK2p+9uJMUmc8aN3NLStSQrjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0+NDqiGAoaCCJhFts1rR200TkCd/gvtVzXpkBVmN5w7aYl97WcN+0oY3wBoZqBqGW 3F0gisLN/XVWNo8Xk4PtuyDrHuXyTQndBIFv0SmwZq2zOKLIPxKyo15BnVOPBRB8Oh Dln9WnKUO8/Ivp5n2dSR3tdfIYmdp0Ds4CprnUqc= From: Arnd Bergmann To: netdev@vger.kernel.org Cc: Arnd Bergmann , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, bridge@lists.linux-foundation.org, linux-hams@vger.kernel.org, Jakub Kicinski , Christoph Hellwig , Alexander Viro , Johannes Berg , Andrew Lunn , Heiner Kallweit Subject: [RFC net-next 11/28] hamachi: use ndo_siocdevprivate Date: Fri, 6 Nov 2020 23:17:26 +0100 Message-Id: <20201106221743.3271965-12-arnd@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201106221743.3271965-1-arnd@kernel.org> References: <20201106221743.3271965-1-arnd@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann hamachi has one command that overloads the ifreq argument and requires a conversion to ndo_siocdevprivate in order to make compat mode work, so split it from ndo_ioctl. Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/packetengines/hamachi.c | 63 ++++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/packetengines/hamachi.c b/drivers/net/ethernet/packetengines/hamachi.c index d058a63602a9..f6980fac8407 100644 --- a/drivers/net/ethernet/packetengines/hamachi.c +++ b/drivers/net/ethernet/packetengines/hamachi.c @@ -546,7 +546,9 @@ static int read_eeprom(void __iomem *ioaddr, int location); static int mdio_read(struct net_device *dev, int phy_id, int location); static void mdio_write(struct net_device *dev, int phy_id, int location, int value); static int hamachi_open(struct net_device *dev); -static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); +static int hamachi_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); +static int hamachi_siocdevprivate(struct net_device *dev, struct ifreq *rq, + void __user *data, int cmd); static void hamachi_timer(struct timer_list *t); static void hamachi_tx_timeout(struct net_device *dev, unsigned int txqueue); static void hamachi_init_ring(struct net_device *dev); @@ -571,7 +573,8 @@ static const struct net_device_ops hamachi_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = eth_mac_addr, .ndo_tx_timeout = hamachi_tx_timeout, - .ndo_do_ioctl = netdev_ioctl, + .ndo_do_ioctl = hamachi_ioctl, + .ndo_siocdevprivate = hamachi_siocdevprivate, }; @@ -1867,7 +1870,36 @@ static const struct ethtool_ops ethtool_ops_no_mii = { .get_drvinfo = hamachi_get_drvinfo, }; -static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) +/* private ioctl: set rx,tx intr params */ +static int hamachi_siocdevprivate(struct net_device *dev, struct ifreq *rq, + void __user *data, int cmd) +{ + struct hamachi_private *np = netdev_priv(dev); + u32 *d = (u32 *)&rq->ifr_ifru; + + if (!netif_running(dev)) + return -EINVAL; + + if (cmd != SIOCDEVPRIVATE+3) + return -EOPNOTSUPP; + + /* Should add this check here or an ordinary user can do nasty + * things. -KDU + * + * TODO: Shut down the Rx and Tx engines while doing this. + */ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + writel(d[0], np->base + TxIntrCtrl); + writel(d[1], np->base + RxIntrCtrl); + printk(KERN_NOTICE "%s: tx %08x, rx %08x intr\n", dev->name, + (u32) readl(np->base + TxIntrCtrl), + (u32) readl(np->base + RxIntrCtrl)); + + return 0; +} + +static int hamachi_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { struct hamachi_private *np = netdev_priv(dev); struct mii_ioctl_data *data = if_mii(rq); @@ -1876,28 +1908,9 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) if (!netif_running(dev)) return -EINVAL; - if (cmd == (SIOCDEVPRIVATE+3)) { /* set rx,tx intr params */ - u32 *d = (u32 *)&rq->ifr_ifru; - /* Should add this check here or an ordinary user can do nasty - * things. -KDU - * - * TODO: Shut down the Rx and Tx engines while doing this. - */ - if (!capable(CAP_NET_ADMIN)) - return -EPERM; - writel(d[0], np->base + TxIntrCtrl); - writel(d[1], np->base + RxIntrCtrl); - printk(KERN_NOTICE "%s: tx %08x, rx %08x intr\n", dev->name, - (u32) readl(np->base + TxIntrCtrl), - (u32) readl(np->base + RxIntrCtrl)); - rc = 0; - } - - else { - spin_lock_irq(&np->lock); - rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL); - spin_unlock_irq(&np->lock); - } + spin_lock_irq(&np->lock); + rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL); + spin_unlock_irq(&np->lock); return rc; }