From patchwork Tue Sep 12 14:21:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381781 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06BAF18AF6 for ; Tue, 12 Sep 2023 14:22:27 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2074.outbound.protection.outlook.com [40.107.94.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 372EE110 for ; Tue, 12 Sep 2023 07:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oOI7lwDrsJnoMCRDjgdQTY3F6UFUYulLQi6PeLuHhfDKhho/u7Qj90m8Xuh+IZfdL0EsqavOTCspzo4pjig9iHZWNQbnXNDdXSpRtCSFg12wMblzQwe/W/jGW5r8wB+TYZCmPgOLCLVfpUBe0LPiwRImQ+ieefKYApTqDS0Mv7WL/ZXwzry/IoO52YjAubgGAvA8g190NEFiHUnmQXtqCohdxYUC5UNSCwN9VENm5JgUnh9KgaUI9ZFXLT2iqyvsvKRp1CaVSZbXvUH+wiPbTY96Fq1OxLOfCkdhdYyqq5ANloNawSiHXRMTi6Y71oar0C5o0Afpd3QEgixsVDB2qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XyQ0LQ+/SNivvskOlp1J2glz9ePHfisIbNz/6KIe+w0=; b=eE6Vkjq1s8t/i21MWWJv6AVAn+wFAijgQwn4e45YM+lDkoIC4cEbs6Q1Cxj0m0ypUmI7YO8lTJ3FCWf0WcuSBB/W4FGC1ueA4tdx8asFqwQaFadZKC4rXPZqEMseurpxAym1myhnG8wq+9S4MTNnZcIYGyJqB/BUv+5NSznuSgs8+YN+xVp7Iu/+MB+U2Z4xFqvTWVlOj0dZIFgCmfjY9XoEFItbgbV3wHoCHahiS2Nsya3pmR2qGQ06MuC/tcqV6iEaFRwfTodRHn6us5hhDkVw71U/tltycMPffqaBZ8Y5CjoLgB3UuTymfGlToe40MeDRDhy69cV6GUkUAWrgVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=net-swift.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XyQ0LQ+/SNivvskOlp1J2glz9ePHfisIbNz/6KIe+w0=; b=U54WW1YqGTiWZZegpN1EM+gNJgMRjzGSY438hyL3bvp5LLXpkqlvO5hN5jCm0II7Cka5uWR8qPj73Ify6ACexXHbKLKOepYezKuCNFPbauc3Ogw1B0kTFl4+RdqXoGoXls1rIwrcsSmEXQRQL1sTzpKMHJaNcZTxGV+Tzvh8ykE= Received: from DS7PR05CA0070.namprd05.prod.outlook.com (2603:10b6:8:57::28) by SN7PR12MB7853.namprd12.prod.outlook.com (2603:10b6:806:348::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.36; Tue, 12 Sep 2023 14:22:24 +0000 Received: from DS3PEPF000099DB.namprd04.prod.outlook.com (2603:10b6:8:57:cafe::5b) by DS7PR05CA0070.outlook.office365.com (2603:10b6:8:57::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 14:22:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DB.mail.protection.outlook.com (10.167.17.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 14:22:23 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:22 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 07:22:22 -0700 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:20 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 1/7] net: move ethtool-related netdev state into its own struct Date: Tue, 12 Sep 2023 15:21:36 +0100 Message-ID: <8b586b4d19b9473d0678dcd012c54bc1b87a5c3d.1694443665.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DB:EE_|SN7PR12MB7853:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c7d6b83-d560-4512-c2da-08dbb39baef6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /sU94DDpJJIaIICfbW/Y29Vn5g8NJu0BiUUjBnvIoPwv5lTaZNiBXly+GKfvE7PkuC+VcLqZpuXTDjC9lkQdQbrhvjqQcT3g9GFXzedvsnfMNgb95OTD04QGHBCauNT8GTao1M2uhGW9raUtjTfm/fxIDZbGu4tcpiOxYJWIuElSWkegq4QXYRThWQnJ4CtNzxh02B3UVEaDJZ7PMJF7fM/jUZ35EIYEUkFm80t/W+hzdqCKqhh78o133dqzumw1q0vd6pv8CmLTavAyy/NS1oTmh5vav6OdrliykxVZr4o79JsnewCpFN0OapQ/eFEUDtW7hBsgA+ymFdgmzkEFTJ7zZckH8Xyb/ImTQa5t/D8lZ3d1c/9tm339PzHzxKOffgBCp6B20aTA/c06bMcNGFRGTezM+filQQ6NtdCgpvl8n0pmkX1CQcCNgiavXc4IflPep1R+oIugJPab2DJTN0srROlYxMQL4phtkDDV+klBI4mujmRnPiV2AaVsXtxVQLpJs0AOvm48UxLQp5st+vTE3TM8f03gNX15Jda1tPTBQXMji2RROLKRBrL4p1gNcKLpti+2u1HKyX86C0ckLQg5FsuaFpHMcqO+n+lJrNYIL31VKsDy6c8OHO0hEUNAHX0JfVA8V7hmpvDxQ25x7OGlC95EF2IxTgwwk2pAoBpG/i4P5EeKKUys6NWU5TVsfg1jCDvnWYE3h1nwJVKXuqloRa/gVh0n+NHuAQgFylpEmK9YmrQNe00JlcgVZlsIBMtHfy7XthnuCnqc5EVTUrdkusFtkCdwaXIrSpHFcjk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(39860400002)(376002)(136003)(186009)(1800799009)(82310400011)(451199024)(40470700004)(36840700001)(46966006)(81166007)(6666004)(7416002)(55446002)(356005)(478600001)(47076005)(9686003)(36756003)(82740400003)(40460700003)(40480700001)(86362001)(336012)(26005)(426003)(2906002)(83380400001)(54906003)(2876002)(41300700001)(8936002)(70206006)(36860700001)(110136005)(5660300002)(4326008)(316002)(8676002)(70586007)(36900700001)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:23.8985 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c7d6b83-d560-4512-c2da-08dbb39baef6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7853 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree net_dev->ethtool is a pointer to new struct ethtool_netdev_state, which currently contains only the wol_enabled field. Suggested-by: Jakub Kicinski Signed-off-by: Edward Cree --- RealTek and WangXun maintainers, I only CCed you on this patch rather than the whole series, to avoid spamming you with a discussion that's likely not to be relevant to you. Hope that's okay. drivers/net/ethernet/realtek/r8169_main.c | 4 ++-- drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c | 4 ++-- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 2 +- drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_device.c | 5 +++-- drivers/net/phy/phylink.c | 2 +- include/linux/ethtool.h | 8 ++++++++ include/linux/netdevice.h | 7 ++++--- net/core/dev.c | 4 ++++ net/ethtool/ioctl.c | 2 +- net/ethtool/wol.c | 2 +- 11 files changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 6351a2dc13bc..fe69416f2a93 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -1455,7 +1455,7 @@ static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) if (tp->dash_type == RTL_DASH_NONE) { rtl_set_d3_pll_down(tp, !wolopts); - tp->dev->wol_enabled = wolopts ? 1 : 0; + tp->dev->ethtool->wol_enabled = wolopts ? 1 : 0; } } @@ -5321,7 +5321,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) rtl_set_d3_pll_down(tp, true); } else { rtl_set_d3_pll_down(tp, false); - dev->wol_enabled = 1; + dev->ethtool->wol_enabled = 1; } jumbo_max = rtl_jumbo_max(tp); diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c index ec0e869e9aac..091ee3d3e74d 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c @@ -34,9 +34,9 @@ static int ngbe_set_wol(struct net_device *netdev, wx->wol = 0; if (wol->wolopts & WAKE_MAGIC) wx->wol = WX_PSR_WKUP_CTL_MAG; - netdev->wol_enabled = !!(wx->wol); + netdev->ethtool->wol_enabled = !!(wx->wol); wr32(wx, WX_PSR_WKUP_CTL, wx->wol); - device_set_wakeup_enable(&pdev->dev, netdev->wol_enabled); + device_set_wakeup_enable(&pdev->dev, netdev->ethtool->wol_enabled); return 0; } diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index 2b431db6085a..6752f8d04d9c 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -636,7 +636,7 @@ static int ngbe_probe(struct pci_dev *pdev, if (wx->wol_hw_supported) wx->wol = NGBE_PSR_WKUP_CTL_MAG; - netdev->wol_enabled = !!(wx->wol); + netdev->ethtool->wol_enabled = !!(wx->wol); wr32(wx, NGBE_PSR_WKUP_CTL, wx->wol); device_set_wakeup_enable(&pdev->dev, wx->wol); diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index df54c137c5f5..6eeec338dfbf 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1283,7 +1283,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) if (netdev) { struct device *parent = netdev->dev.parent; - if (netdev->wol_enabled) + if (netdev->ethtool->wol_enabled) pm_system_wakeup(); else if (device_may_wakeup(&netdev->dev)) pm_wakeup_dev_event(&netdev->dev, 0, true); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2ce74593d6e4..62afc0424fbd 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -285,7 +285,7 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) if (!netdev) goto out; - if (netdev->wol_enabled) + if (netdev->ethtool->wol_enabled) return false; /* As long as not all affected network drivers support the @@ -1859,7 +1859,8 @@ int phy_suspend(struct phy_device *phydev) return 0; phy_ethtool_get_wol(phydev, &wol); - phydev->wol_enabled = wol.wolopts || (netdev && netdev->wol_enabled); + phydev->wol_enabled = wol.wolopts || + (netdev && netdev->ethtool->wol_enabled); /* If the device has WOL enabled, we cannot suspend the PHY */ if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND)) return -EBUSY; diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 0d7354955d62..b808ba1197c3 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2172,7 +2172,7 @@ void phylink_suspend(struct phylink *pl, bool mac_wol) { ASSERT_RTNL(); - if (mac_wol && (!pl->netdev || pl->netdev->wol_enabled)) { + if (mac_wol && (!pl->netdev || pl->netdev->ethtool->wol_enabled)) { /* Wake-on-Lan enabled, MAC handling */ mutex_lock(&pl->state_mutex); diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 62b61527bcc4..8aeefc0b4e10 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -935,6 +935,14 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev, const struct ethtool_link_ksettings *cmd, u32 *dev_speed, u8 *dev_duplex); +/** + * struct ethtool_netdev_state - per-netdevice state for ethtool features + * @wol_enabled: Wake-on-LAN is enabled + */ +struct ethtool_netdev_state { + unsigned wol_enabled:1; +}; + struct phy_device; struct phy_tdr_config; struct phy_plca_cfg; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0896aaa91dd7..efedfac436ad 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -79,6 +79,7 @@ struct xdp_buff; struct xdp_frame; struct xdp_metadata_ops; struct xdp_md; +struct ethtool_netdev_state; typedef u32 xdp_features_t; @@ -2011,8 +2012,6 @@ enum netdev_ml_priv_type { * switch driver and used to set the phys state of the * switch port. * - * @wol_enabled: Wake-on-LAN is enabled - * * @threaded: napi threaded mode is enabled * * @net_notifier_list: List of per-net netdev notifier block @@ -2024,6 +2023,7 @@ enum netdev_ml_priv_type { * @udp_tunnel_nic_info: static structure describing the UDP tunnel * offload capabilities of the device * @udp_tunnel_nic: UDP tunnel offload state + * @ethtool: ethtool related state * @xdp_state: stores info on attached XDP BPF programs * * @nested_level: Used as a parameter of spin_lock_nested() of @@ -2383,7 +2383,6 @@ struct net_device { struct sfp_bus *sfp_bus; struct lock_class_key *qdisc_tx_busylock; bool proto_down; - unsigned wol_enabled:1; unsigned threaded:1; struct list_head net_notifier_list; @@ -2395,6 +2394,8 @@ struct net_device { const struct udp_tunnel_nic_info *udp_tunnel_nic_info; struct udp_tunnel_nic *udp_tunnel_nic; + struct ethtool_netdev_state *ethtool; + /* protected by rtnl_lock */ struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE]; diff --git a/net/core/dev.c b/net/core/dev.c index ccff2b6ef958..bb3841371349 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10747,6 +10747,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, dev->real_num_rx_queues = rxqs; if (netif_alloc_rx_queues(dev)) goto free_all; + dev->ethtool = kzalloc(sizeof(*dev->ethtool), GFP_KERNEL_ACCOUNT); + if (!dev->ethtool) + goto free_all; strcpy(dev->name, name); dev->name_assign_type = name_assign_type; @@ -10797,6 +10800,7 @@ void free_netdev(struct net_device *dev) return; } + kfree(dev->ethtool); netif_free_tx_queues(dev); netif_free_rx_queues(dev); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0b0ce4f81c01..de78b24fffc9 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1461,7 +1461,7 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) if (ret) return ret; - dev->wol_enabled = !!wol.wolopts; + dev->ethtool->wol_enabled = !!wol.wolopts; ethtool_notify(dev, ETHTOOL_MSG_WOL_NTF, NULL); return 0; diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index 0ed56c9ac1bc..a39d8000d808 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -137,7 +137,7 @@ ethnl_set_wol(struct ethnl_req_info *req_info, struct genl_info *info) ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret; - dev->wol_enabled = !!wol.wolopts; + dev->ethtool->wol_enabled = !!wol.wolopts; return 1; } From patchwork Tue Sep 12 14:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381782 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2AB918AEE for ; Tue, 12 Sep 2023 14:22:30 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2075.outbound.protection.outlook.com [40.107.94.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E22E3110 for ; Tue, 12 Sep 2023 07:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gsAuwwy8RX79iBgdKSuwOFaXK46sUklnFsxlGlLMx9GYU+hUxbhp6ydjXG7BQzNy0EBIgYiShTTIuU/BS8mh3FeXDKLM0hw+BukBZUELdBKvPzMnU7x+tDF+0mS278lPRCbRC7YrR/VhvZHaKtZTCw0tMk1db2vspj3tMAGhx8PY1RkX26LMftvsGTQiu7QRiLNvMBH8zUIaDK5Ag7Ol+0weswF5zhNupBsD94HEcW4HkOsSEF5uzhjlILBKtpZ1Ua/g1INAefnyVYQxMeFLRV1BFHnyp7blHX1Uk29dkxiBnh5grnK7AeI2oQPSPNbivgx8/3T/CKf1ywIhuj0J+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z34O/3YzNNi/Ujyu7vTVxznFFfXItspFLIU2m4qlqvI=; b=YJdz4+sP6xiJwdyUvhGS9eJWFGSdWNRI9RikW5wCeEbDLs+T3adfeh/x443SgQBORd444nX6nH+aH4OBkf15N9IDZZenc5jEw+zjzE3jUFo+X9SR6rGgh7gii8Z2CB2G1vE1Ik1sRb4WYBc0urtlW+mv/JuPBTXCQm1oXQtgtN68O3dJPz7q+OM9tOBd8sZ9z44kWl438JrV/VT/8zukMuCZgPe+Ln6Ebwf3rnlNbRuogik++q9/jNMowxxK0HkMoMkb1GvrayyWccpFP4puwE1R0vVQFWyhPan97ATVBXgTV9ubQjf9nh8JNN6PHDIuTp5HTwRt7BzkekyYRwpvHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z34O/3YzNNi/Ujyu7vTVxznFFfXItspFLIU2m4qlqvI=; b=GI0xwe78xxk4QgnHVni0lXXqXdyY7Ie07+AEHwYdFzkslkBNzgJDZUuZ29EknFeewNWu2LaiIgjhA5SE5525RuENRTlHHUv93le4H5cReSsRZUkSmFnUXPnfP7YKO91iCrtCbiMzoqYcHrrx/aKLOwfVnfBOmQ+n/OzIrKPI+iQ= Received: from DS7PR05CA0065.namprd05.prod.outlook.com (2603:10b6:8:57::10) by MW6PR12MB8867.namprd12.prod.outlook.com (2603:10b6:303:249::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Tue, 12 Sep 2023 14:22:26 +0000 Received: from DS3PEPF000099DB.namprd04.prod.outlook.com (2603:10b6:8:57:cafe::1) by DS7PR05CA0065.outlook.office365.com (2603:10b6:8:57::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 14:22:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DB.mail.protection.outlook.com (10.167.17.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 14:22:26 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:25 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 07:22:25 -0700 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:22 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 2/7] net: ethtool: attach an IDR of custom RSS contexts to a netdevice Date: Tue, 12 Sep 2023 15:21:37 +0100 Message-ID: <9c71d5168e1ee22b40625eec53a8bb00456d60ed.1694443665.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DB:EE_|MW6PR12MB8867:EE_ X-MS-Office365-Filtering-Correlation-Id: 977b8bce-65bb-4f50-136e-08dbb39bb06d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lYSTLr/DOKy++WQRhKLk/hLutEGcAfLGnEApJH2O1wQihhTWNgORxIulsxbs/eE9U6qNEDaR5XHj+oK1H5ykPzcXvKwPqOd0ik69vRxK3w3ie2a98j9nEpHJzGQil0lSEdE+dvF7ey+lUPdGwBvXEMKF9jamokAM6JfHkevb5emHyqtjrCutCTmdjVCGoGbAwvwH+XFQP5QwNkLFgH4iOlRO4P+DI4JTI24R0ZHE30cbXPFkSjypqLvP66AxSlwmymWj1aJl/+zSXptcbhYGMnM6XTGUTbKfHLvS/PeaAySnSiGPk0QYQf/LvkCDoHep3mTZAkGidNUwQLph8b4+xLKO/18DiIowMkMEQazq+g95eQi1QAfCWss4aknjUhY+RD6xxEXrD3QciGBaKqpwgxTB7fMUfmQBRzNFk06pda52+qad0hrb7e2EfrwQcTA+gZDs2N7yxhZ5YfuJ+6pnUWl2Ya9cphuDJckI7Firoihu1qVvS3Y9LCZxFAaZMfH06B3mdgp7dO97D3b22DSlldKeIa89jy6zUUgGhuovRkNi6/Cnlo+gubDA9vi0zlKonK3KWubrZdZZjhFPMgqIAJny+hwtZyxuDPJaZIZYGZuZkGpt8vhuWuaCb8J518GqM7zLjwOjiKhpOZpnxsPXFFi/Q7hthIK2c0nZ6uOdsFCnEt/CHZSuuNf9CpuNCMzNjwpIJEa9/vanhoNxY9UNjVA8bogCP63csXcp3rg3EQoFJE9FnNMn0Oq2H7xlkKeP18vM5MkoAQnL2flThu7aJA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(39860400002)(136003)(346002)(186009)(451199024)(1800799009)(82310400011)(46966006)(36840700001)(40470700004)(81166007)(41300700001)(316002)(7416002)(26005)(40480700001)(336012)(426003)(2876002)(110136005)(54906003)(8676002)(4326008)(70586007)(70206006)(2906002)(8936002)(478600001)(5660300002)(6666004)(40460700003)(9686003)(36756003)(36860700001)(47076005)(83380400001)(86362001)(55446002)(82740400003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:26.3517 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 977b8bce-65bb-4f50-136e-08dbb39bb06d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8867 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree Each context stores the RXFH settings (indir, key, and hfunc) as well as optionally some driver private data. Delete any still-existing contexts at netdev unregister time. Signed-off-by: Edward Cree --- include/linux/ethtool.h | 43 ++++++++++++++++++++++++++++++++++++++++- net/core/dev.c | 23 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 8aeefc0b4e10..c770e32d79e6 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -157,6 +157,43 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) return index % n_rx_rings; } +/** + * struct ethtool_rxfh_context - a custom RSS context configuration + * @indir_size: Number of u32 entries in indirection table + * @key_size: Size of hash key, in bytes + * @hfunc: RSS hash function identifier. One of the %ETH_RSS_HASH_* + * @priv_size: Size of driver private data, in bytes + * @indir_no_change: indir was not specified at create time + * @key_no_change: hkey was not specified at create time + */ +struct ethtool_rxfh_context { + u32 indir_size; + u32 key_size; + u8 hfunc; + u16 priv_size; + u8 indir_no_change:1; + u8 key_no_change:1; + /* private: driver private data, indirection table, and hash key are + * stored sequentially in @data area. Use below helpers to access. + */ + u8 data[] __aligned(sizeof(void *)); +}; + +static inline void *ethtool_rxfh_context_priv(struct ethtool_rxfh_context *ctx) +{ + return ctx->data; +} + +static inline u32 *ethtool_rxfh_context_indir(struct ethtool_rxfh_context *ctx) +{ + return (u32 *)(ctx->data + ALIGN(ctx->priv_size, sizeof(u32))); +} + +static inline u8 *ethtool_rxfh_context_key(struct ethtool_rxfh_context *ctx) +{ + return (u8 *)(ethtool_rxfh_context_indir(ctx) + ctx->indir_size); +} + /* declare a link mode bitmap */ #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) @@ -937,10 +974,14 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev, /** * struct ethtool_netdev_state - per-netdevice state for ethtool features + * @rss_ctx: IDR storing custom RSS context state + * @rss_ctx_max_id: maximum (exclusive) supported RSS context ID * @wol_enabled: Wake-on-LAN is enabled */ struct ethtool_netdev_state { - unsigned wol_enabled:1; + struct idr rss_ctx; + u32 rss_ctx_max_id; + u32 wol_enabled:1; }; struct phy_device; diff --git a/net/core/dev.c b/net/core/dev.c index bb3841371349..4bbb6bda7b7e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10050,6 +10050,9 @@ int register_netdevice(struct net_device *dev) if (ret) return ret; + /* rss ctx ID 0 is reserved for the default context, start from 1 */ + idr_init_base(&dev->ethtool->rss_ctx, 1); + spin_lock_init(&dev->addr_list_lock); netdev_set_addr_lockdep_class(dev); @@ -10852,6 +10855,24 @@ void synchronize_net(void) } EXPORT_SYMBOL(synchronize_net); +static void netdev_rss_contexts_free(struct net_device *dev) +{ + struct ethtool_rxfh_context *ctx; + u32 context; + + if (!dev->ethtool_ops->set_rxfh_context) + return; + idr_for_each_entry(&dev->ethtool->rss_ctx, ctx, context) { + u32 *indir = ethtool_rxfh_context_indir(ctx); + u8 *key = ethtool_rxfh_context_key(ctx); + + idr_remove(&dev->ethtool->rss_ctx, context); + dev->ethtool_ops->set_rxfh_context(dev, indir, key, ctx->hfunc, + &context, true); + kfree(ctx); + } +} + /** * unregister_netdevice_queue - remove device from the kernel * @dev: device @@ -10956,6 +10977,8 @@ void unregister_netdevice_many_notify(struct list_head *head, netdev_name_node_alt_flush(dev); netdev_name_node_free(dev->name_node); + netdev_rss_contexts_free(dev); + call_netdevice_notifiers(NETDEV_PRE_UNINIT, dev); if (dev->netdev_ops->ndo_uninit) From patchwork Tue Sep 12 14:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381783 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7E5D18C05 for ; Tue, 12 Sep 2023 14:22:31 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2043.outbound.protection.outlook.com [40.107.237.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E045110 for ; Tue, 12 Sep 2023 07:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UbfRkWKMukW1pBn3IV5vE5ba1J82N4o9/ZkikX5l+E9X1XHQS7wLsPbgDSbC9e1aA9p8GW0VZ80Z/iNcY1TWXH/f4eUiX64CktO/sEJJElTiJi1B3JuIsSr3mE0hhJ3akaYVsU+vu5RykJRHiS9YOvf9Lf3pekzMQDa3MrYQM8PESGcACFgqhAXghe0K8gPNsEAmzcgsPj+1/cXs8eEK0riD/WvKHYYm66v5DM63mN7V9eRH9iFQHsNwydB85y5v6MKMhfv0GCTRGOBXZnJhI5tGR9ugmeBbFp3xfQpGqPVnGa5qnUBdjPbpgHelWfiEZDYFHnsJjJMi8oA0cjB/sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JkPZIOvLmcamijvDNSr4ylLqPQE0tipxzzi5aW58+3I=; b=SFskCVs2H0I1FguBhVuqGze3wZ1MjJZ9W4XkdOUrixa+kub6C8kAjXyj8qSzSlQisO2hljTunNVqlvPPB4vFp4D4Wn+IAwt4UCbHv/HA/d5+9vgVsXDq5dclR8HrItG5iN5b6m0XrEM+1QSNUn25nz7qJXOfjbsJ/eNZrAuDxFyEY59fxnQTsoQ139byAUBcaGgG6yqo2PawN5oJvF10LmcAtBYt0VMSKHgf5MTklSLw2J9HBJpKDI0gGafKSdKyE3P/KpvBNz4zeIOIwHYbZx3VLHqIxIVlbBBMIEUV26LGG5wqJ1LefgVC2OH+Aec1qT4QLDVvyGaOufcmjAr+dA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JkPZIOvLmcamijvDNSr4ylLqPQE0tipxzzi5aW58+3I=; b=j5lBCwzuURSvsnKB071gb1SZxP9LQ+IkefTjPVmcGFiu5ZYUvn+4/WR+OqOU6vdWOsxKclAb/tw7yXDzqina1d6ev3zWZLbIXhsATVjSFCpWXyWwNynE4bDiKhSOXKtYP2ITPWwnPvNEvPz+8pa0emclIKEOhEPmSulmxGUOtzU= Received: from CH2PR15CA0001.namprd15.prod.outlook.com (2603:10b6:610:51::11) by CYYPR12MB8752.namprd12.prod.outlook.com (2603:10b6:930:b9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.37; Tue, 12 Sep 2023 14:22:28 +0000 Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:610:51:cafe::b2) by CH2PR15CA0001.outlook.office365.com (2603:10b6:610:51::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.41 via Frontend Transport; Tue, 12 Sep 2023 14:22:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DC.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 14:22:28 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:27 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 07:22:27 -0700 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:25 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 3/7] net: ethtool: record custom RSS contexts in the IDR Date: Tue, 12 Sep 2023 15:21:38 +0100 Message-ID: <455d409bd1f54dcf552c6c60c46167ea726bbab5.1694443665.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DC:EE_|CYYPR12MB8752:EE_ X-MS-Office365-Filtering-Correlation-Id: bce80659-563b-4915-07aa-08dbb39bb177 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bGYY3BGaS0BcGYUmdusRbWPhClrRxK6E7oM9yz8ykVk3CQ8Snl6meDju3thMyPNwwUIFLs1HiRK7wjte6LGJW5GhcPCYXOWtQhpb9xP8CHbRDsAT+FgCweWjPXxWSFpUbpe+x2iyCb+Gr4+M0KwPcHVGAWCXjYNfDUnt4modx36HWAgquHQhrGepq8A+rsXYrVXjT/ZRvGUv9TGBqK3v1PqcosSePwFxSvepZIx8EAdfGR8sggSD7pDaRdNWRX0YZeG2sVxQZpquCFtcQgrh8jRYhH+BknOH03JqLFFMW4NtJq5q8dosNlOo1R4tTIFbOhVw3LnJQWkmfCJtb9ESV5QliRwUXoiaJXH9KgZHxdwUR1og0BLmL2cFCG7SFSBMVsxT7NwIoT6OOWOf/BUVA6mYrk+cnD0poPPbZ5S/DKf65DvihrXZNOE9d8XhK6vjbnyH+te4bDXVQpmMYCrwylUJ7SNKLNuL++U7VMmdKH9HbzVZMRvMB2JEmMSO47a/zgVdlvkbweWt7t0OxrrD6oe4FGSYx9/RtRICPNdQf6cZLYKxJ87VnftXAXL8efeWvw+kv1igChls00h59rXx2Wtzy5eVXO3Yb3zfusvAEvRDdGzwAN46weAdsZzpDC4d5eM2iGltaeEPL6t5s8U9BEczM7WiVJhmSd5punnJ8eHXE+/qpYkUguQjVSpnM8m8hYCOhqGnbdXWEZ9Qe6rVHHx2cPMQSf0cFw/N+yK0ow83wlOFXGXF45BTpjKlirry5x5k9RGd1gCe8exBqRy1cA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(376002)(39860400002)(346002)(451199024)(82310400011)(186009)(1800799009)(46966006)(40470700004)(36840700001)(8676002)(86362001)(8936002)(66899024)(40480700001)(55446002)(5660300002)(4326008)(2906002)(40460700003)(2876002)(36756003)(9686003)(82740400003)(6666004)(356005)(426003)(336012)(7416002)(81166007)(70586007)(478600001)(26005)(47076005)(36860700001)(83380400001)(54906003)(110136005)(41300700001)(70206006)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:28.0946 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bce80659-563b-4915-07aa-08dbb39bb177 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8752 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree Since drivers are still choosing the context IDs, we have to force the IDR to use the ID they've chosen rather than picking one ourselves. Signed-off-by: Edward Cree --- include/linux/ethtool.h | 14 ++++++++ net/ethtool/ioctl.c | 71 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index c770e32d79e6..f7317b53ab61 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -194,6 +194,17 @@ static inline u8 *ethtool_rxfh_context_key(struct ethtool_rxfh_context *ctx) return (u8 *)(ethtool_rxfh_context_indir(ctx) + ctx->indir_size); } +static inline size_t ethtool_rxfh_context_size(u32 indir_size, u32 key_size, + u16 priv_size) +{ + size_t indir_bytes = array_size(indir_size, sizeof(u32)); + size_t flex_len; + + flex_len = size_add(size_add(indir_bytes, key_size), + ALIGN(priv_size, sizeof(u32))); + return struct_size((struct ethtool_rxfh_context *)0, data, flex_len); +} + /* declare a link mode bitmap */ #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) @@ -731,6 +742,8 @@ struct ethtool_mm_stats { * will remain unchanged. * Returns a negative error code or zero. An error code must be returned * if at least one unsupported change was requested. + * @rxfh_priv_size: size of the driver private data area the core should + * allocate for an RSS context. * @get_rxfh_context: Get the contents of the RX flow hash indirection table, * hash key, and/or hash function assiciated to the given rss context. * Returns a negative error code or zero. @@ -824,6 +837,7 @@ struct ethtool_ops { u32 cap_link_lanes_supported:1; u32 supported_coalesce_params; u32 supported_ring_params; + u16 rxfh_priv_size; void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *); int (*get_regs_len)(struct net_device *); void (*get_regs)(struct net_device *, struct ethtool_regs *, void *); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index de78b24fffc9..db596b61c6ab 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1249,6 +1249,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, { int ret; const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_rxfh_context *ctx = NULL; struct ethtool_rxnfc rx_rings; struct ethtool_rxfh rxfh; u32 dev_indir_size = 0, dev_key_size = 0, i; @@ -1256,7 +1257,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, u8 *hkey = NULL; u8 *rss_config; u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]); - bool delete = false; + bool create = false, delete = false; if (!ops->get_rxnfc || !ops->set_rxfh) return -EOPNOTSUPP; @@ -1275,6 +1276,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, /* Most drivers don't handle rss_context, check it's 0 as well */ if (rxfh.rss_context && !ops->set_rxfh_context) return -EOPNOTSUPP; + create = rxfh.rss_context == ETH_RXFH_CONTEXT_ALLOC; /* If either indir, hash key or function is valid, proceed further. * Must request at least one change: indir size, hash key or function. @@ -1332,13 +1334,42 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } } + if (create) { + if (delete) { + ret = -EINVAL; + goto out; + } + ctx = kzalloc(ethtool_rxfh_context_size(dev_indir_size, + dev_key_size, + ops->rxfh_priv_size), + GFP_KERNEL_ACCOUNT); + if (!ctx) { + ret = -ENOMEM; + goto out; + } + ctx->indir_size = dev_indir_size; + ctx->key_size = dev_key_size; + ctx->hfunc = rxfh.hfunc; + ctx->priv_size = ops->rxfh_priv_size; + } else if (rxfh.rss_context) { + ctx = idr_find(&dev->ethtool->rss_ctx, rxfh.rss_context); + if (!ctx) { + ret = -ENOENT; + goto out; + } + } + if (rxfh.rss_context) ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc, &rxfh.rss_context, delete); else ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc); - if (ret) + if (ret) { + if (create) + /* failed to create, free our new tracking entry */ + kfree(ctx); goto out; + } if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, rss_context), &rxfh.rss_context, sizeof(rxfh.rss_context))) @@ -1351,6 +1382,42 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, else if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) dev->priv_flags |= IFF_RXFH_CONFIGURED; } + /* Update rss_ctx tracking */ + if (create) { + /* Ideally this should happen before calling the driver, + * so that we can fail more cleanly; but we don't have the + * context ID until the driver picks it, so we have to + * wait until after. + */ + if (WARN_ON(idr_find(&dev->ethtool->rss_ctx, rxfh.rss_context))) { + /* context ID reused, our tracking is screwed */ + kfree(ctx); + goto out; + } + /* Allocate the exact ID the driver gave us */ + WARN_ON(idr_alloc(&dev->ethtool->rss_ctx, ctx, rxfh.rss_context, + rxfh.rss_context + 1, GFP_KERNEL) != + rxfh.rss_context); + ctx->indir_no_change = rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE; + ctx->key_no_change = !rxfh.key_size; + } + if (delete) { + WARN_ON(idr_remove(&dev->ethtool->rss_ctx, rxfh.rss_context) != ctx); + kfree(ctx); + } else if (ctx) { + if (indir) { + for (i = 0; i < dev_indir_size; i++) + ethtool_rxfh_context_indir(ctx)[i] = indir[i]; + ctx->indir_no_change = 0; + } + if (hkey) { + memcpy(ethtool_rxfh_context_key(ctx), hkey, + dev_key_size); + ctx->key_no_change = 0; + } + if (rxfh.hfunc != ETH_RSS_HASH_NO_CHANGE) + ctx->hfunc = rxfh.hfunc; + } out: kfree(rss_config); From patchwork Tue Sep 12 14:21:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381784 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F73F18C05 for ; Tue, 12 Sep 2023 14:22:34 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2047.outbound.protection.outlook.com [40.107.237.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FA9110 for ; Tue, 12 Sep 2023 07:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DAaHx8u26epG7YsB89xiIeRhaB84NpHOLENYYrygR6FEtPLwQaZ/eAvFfvTEycJyk58tuaqS3KKK6jvLPq7DoJKPqdfXpreLZefNdgOs/RhJpbNWBoPLd67H6lnRtJXGp8zbcN/igbEzw5KvYkCgCr7NuUK3QHFM9Q3wzaZvICxFC2LQTQyJABthBsBdz6l00lxAC58VhEculXjnxTuUPr5+Ne5vssenDy28DP9MUIn5IfRJ4+gkfynBIt3Z9KvF3bAtGktYTsAG6cCc+TxgRmzbR+PHfji7Gviv/H3JTi16eRXq1LPJen7cBPAgQjBHB/V4M907p1xhVAKDUyW6tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jto2N4hXTY1Y1s32B6HG8MYviT2F0gqZBT+K2zwtYdQ=; b=ZzppZKgxerEPxUpZ6Xo0UEfZXCmlT6tmfHXYd3zUhArgSsCGXS2eu8gL0Xmi1ibalWXL1MQIU7XD1HVGjpKLFgNvUzEQLrK6Kp34TW3TPySoOoXulKcrWaX7z2bH9wA9lvcsL5auS4SKVsT0V4T9DzIUmqRZ/XNxvETqmSinJbCSeOra8SlnUIzaPO8qH3yc/+EdfqOFufB27N0+VHiD8Y7WcbKeipuQbt6Yr8DKuQe2J7DSddoTAXIBrEpszVCN5MNItWbdULo88oNiV8sBeMOYVnlEP+TAMeewnyp6n70dSLWWCQ+IVvDvfv+PxCX0Nk9P2gIGkRkKnSbYKdhVCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jto2N4hXTY1Y1s32B6HG8MYviT2F0gqZBT+K2zwtYdQ=; b=iUnAAC+avzhogmsGbjZqTepvWjHzNPnSv9IWZkil/r4giFGdZtWPNTNYD6zec7A8GCQFKO+Kiz2AdOErGHKq4svvn4OmZ7dn9rozUwvEdXGkT8Y4nlt28kfqH7VoB3XYPZ8gF1Lwc6JYHfOxbeU64v+ZWJP1R06hYfuBDGKc4hs= Received: from BYAPR05CA0042.namprd05.prod.outlook.com (2603:10b6:a03:74::19) by BN9PR12MB5308.namprd12.prod.outlook.com (2603:10b6:408:105::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Tue, 12 Sep 2023 14:22:30 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:a03:74:cafe::e3) by BYAPR05CA0042.outlook.office365.com (2603:10b6:a03:74::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.16 via Frontend Transport; Tue, 12 Sep 2023 14:22:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.11 via Frontend Transport; Tue, 12 Sep 2023 14:22:30 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:30 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:29 -0500 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:27 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 4/7] net: ethtool: let the core choose RSS context IDs Date: Tue, 12 Sep 2023 15:21:39 +0100 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|BN9PR12MB5308:EE_ X-MS-Office365-Filtering-Correlation-Id: 9190fe5c-427e-4301-b056-08dbb39bb2d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JKL1u+oJdj4AC1NLqAssF5n9yVY0WiEW4zy9BLlYFm61+EZWuzJat1u+886Syd7Y1VvnNC+xDG+QXgvffGAljfZoRUqm/gZ5MKm3OzfsNlLg7VSSEH6/Bd4vc2IGS6OZ2t7ulaBaTGh1U8jEgVmSDhD/SkBpkD2KFLUy+VdWgkzGfte8k+EFvfgxL3P4vhtJ1KQ2FNysBl0SBikl0v4uo1kJQn5HSnMIuaNbNwjxccDKd4MpKD9A8/7Hkfme77Oh8KPPF1k7aFGaC+tTtbd7p6YlxAvhaIAkUXQmOgzBKTImzFgjqi4ryhNgTvD6Yj4qyCJmBLd/YesbntBpOMw5KsPZt+j1wUwTqlx4ju+vTR5vZZHG8Uh0bydTvo1tCFezAyXMZjV3X2ggzVlDe54RBtKsJZk+s0bUvVV9pHCbIQmDmkU28KDqwsYFdG+x7MN9aqZf342Xqhz3dCe8VkPsrDythlSrKR2UCedx2kEXxIwx/EdtT1ysDwAVP/CBvcjafvjDftiZe6+sYsFTnPooG4FdqxD9r+GOoHHhG5RfWN5PsrY64FvsI5uynU0ha2jsJRXq1T6OlEWP6LqgN6woahIT9KaG3iQLoOaz54DtsRmfQJzOYxs2cpbggUNRz+luYN6KnfU/gtyn+vF6Okx2cw6y8ym25JBx5+epAD6TFeggQcinmgKyHWSx+MvOWn6QbeoQsb2CPpCWh4XIFj7SbhPWB2ee5DoIXfBmpzHQ/Uo14/Zz+dVETjkbxp5LZ0nhKHLHCMsf98xDeRgC7CU53g== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(136003)(376002)(396003)(451199024)(186009)(1800799009)(82310400011)(46966006)(40470700004)(36840700001)(6666004)(9686003)(478600001)(41300700001)(83380400001)(426003)(26005)(336012)(7416002)(54906003)(8936002)(70206006)(70586007)(5660300002)(2876002)(110136005)(316002)(2906002)(4326008)(8676002)(40460700003)(82740400003)(47076005)(36860700001)(86362001)(36756003)(40480700001)(55446002)(356005)(81166007)(66899024)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:30.4124 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9190fe5c-427e-4301-b056-08dbb39bb2d8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5308 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree Add a new API to create/modify/remove RSS contexts, that passes in the newly-chosen context ID (not as a pointer) rather than leaving the driver to choose it on create. Also pass in the ctx, allowing drivers to easily use its private data area to store their hardware-specific state. Keep the existing .set_rxfh_context API for now as a fallback, but deprecate it. Signed-off-by: Edward Cree --- include/linux/ethtool.h | 40 ++++++++++++++++++++++++-- net/core/dev.c | 11 +++++-- net/ethtool/ioctl.c | 64 +++++++++++++++++++++++++++++++---------- 3 files changed, 94 insertions(+), 21 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index f7317b53ab61..4fa2a7f6ed4c 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -747,10 +747,33 @@ struct ethtool_mm_stats { * @get_rxfh_context: Get the contents of the RX flow hash indirection table, * hash key, and/or hash function assiciated to the given rss context. * Returns a negative error code or zero. - * @set_rxfh_context: Create, remove and configure RSS contexts. Allows setting + * @create_rxfh_context: Create a new RSS context with the specified RX flow + * hash indirection table, hash key, and hash function. + * Arguments which are set to %NULL or zero will be populated to + * appropriate defaults by the driver. + * The &struct ethtool_rxfh_context for this context is passed in @ctx; + * note that the indir table, hkey and hfunc are not yet populated as + * of this call. The driver does not need to update these; the core + * will do so if this op succeeds. + * If the driver provides this method, it must also provide + * @modify_rxfh_context and @remove_rxfh_context. + * Returns a negative error code or zero. + * @modify_rxfh_context: Reconfigure the specified RSS context. Allows setting * the contents of the RX flow hash indirection table, hash key, and/or - * hash function associated to the given context. Arguments which are set - * to %NULL or zero will remain unchanged. + * hash function associated with the given context. + * Arguments which are set to %NULL or zero will remain unchanged. + * The &struct ethtool_rxfh_context for this context is passed in @ctx; + * note that it will still contain the *old* settings. The driver does + * not need to update these; the core will do so if this op succeeds. + * Returns a negative error code or zero. An error code must be returned + * if at least one unsupported change was requested. + * @remove_rxfh_context: Remove the specified RSS context. + * The &struct ethtool_rxfh_context for this context is passed in @ctx. + * Returns a negative error code or zero. + * @set_rxfh_context: Deprecated API to create, remove and configure RSS + * contexts. Allows setting the contents of the RX flow hash indirection + * table, hash key, and/or hash function associated to the given context. + * Arguments which are set to %NULL or zero will remain unchanged. * Returns a negative error code or zero. An error code must be returned * if at least one unsupported change was requested. * @get_channels: Get number of channels. @@ -901,6 +924,17 @@ struct ethtool_ops { const u8 *key, const u8 hfunc); int (*get_rxfh_context)(struct net_device *, u32 *indir, u8 *key, u8 *hfunc, u32 rss_context); + int (*create_rxfh_context)(struct net_device *, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context); + int (*modify_rxfh_context)(struct net_device *, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context); + int (*remove_rxfh_context)(struct net_device *, + struct ethtool_rxfh_context *ctx, + u32 rss_context); int (*set_rxfh_context)(struct net_device *, const u32 *indir, const u8 *key, const u8 hfunc, u32 *rss_context, bool delete); diff --git a/net/core/dev.c b/net/core/dev.c index 4bbb6bda7b7e..6b8e5fd8691b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10860,15 +10860,20 @@ static void netdev_rss_contexts_free(struct net_device *dev) struct ethtool_rxfh_context *ctx; u32 context; - if (!dev->ethtool_ops->set_rxfh_context) + if (!dev->ethtool_ops->create_rxfh_context && + !dev->ethtool_ops->set_rxfh_context) return; idr_for_each_entry(&dev->ethtool->rss_ctx, ctx, context) { u32 *indir = ethtool_rxfh_context_indir(ctx); u8 *key = ethtool_rxfh_context_key(ctx); idr_remove(&dev->ethtool->rss_ctx, context); - dev->ethtool_ops->set_rxfh_context(dev, indir, key, ctx->hfunc, - &context, true); + if (dev->ethtool_ops->create_rxfh_context) + dev->ethtool_ops->remove_rxfh_context(dev, ctx, context); + else + dev->ethtool_ops->set_rxfh_context(dev, indir, key, + ctx->hfunc, + &context, true); kfree(ctx); } } diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index db596b61c6ab..4ce960a5ad4c 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1274,7 +1274,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32) return -EINVAL; /* Most drivers don't handle rss_context, check it's 0 as well */ - if (rxfh.rss_context && !ops->set_rxfh_context) + if (rxfh.rss_context && !(ops->create_rxfh_context || + ops->set_rxfh_context)) return -EOPNOTSUPP; create = rxfh.rss_context == ETH_RXFH_CONTEXT_ALLOC; @@ -1349,8 +1350,28 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } ctx->indir_size = dev_indir_size; ctx->key_size = dev_key_size; - ctx->hfunc = rxfh.hfunc; ctx->priv_size = ops->rxfh_priv_size; + /* Initialise to an empty context */ + ctx->indir_no_change = ctx->key_no_change = 1; + ctx->hfunc = ETH_RSS_HASH_NO_CHANGE; + if (ops->create_rxfh_context) { + int ctx_id; + + /* driver uses new API, core allocates ID */ + /* if rss_ctx_max_id is not specified (left as 0), it is + * treated as INT_MAX + 1 by idr_alloc + */ + ctx_id = idr_alloc(&dev->ethtool->rss_ctx, ctx, 1, + dev->ethtool->rss_ctx_max_id, + GFP_KERNEL_ACCOUNT); + /* 0 is not allowed, so treat it like an error here */ + if (ctx_id <= 0) { + kfree(ctx); + ret = -ENOMEM; + goto out; + } + rxfh.rss_context = ctx_id; + } } else if (rxfh.rss_context) { ctx = idr_find(&dev->ethtool->rss_ctx, rxfh.rss_context); if (!ctx) { @@ -1359,15 +1380,34 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } } - if (rxfh.rss_context) - ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc, - &rxfh.rss_context, delete); - else + if (rxfh.rss_context) { + if (ops->create_rxfh_context) { + if (create) + ret = ops->create_rxfh_context(dev, ctx, indir, + hkey, rxfh.hfunc, + rxfh.rss_context); + else if (delete) + ret = ops->remove_rxfh_context(dev, ctx, + rxfh.rss_context); + else + ret = ops->modify_rxfh_context(dev, ctx, indir, + hkey, rxfh.hfunc, + rxfh.rss_context); + } else { + ret = ops->set_rxfh_context(dev, indir, hkey, + rxfh.hfunc, + &rxfh.rss_context, delete); + } + } else { ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc); + } if (ret) { - if (create) + if (create) { /* failed to create, free our new tracking entry */ + if (ops->create_rxfh_context) + idr_remove(&dev->ethtool->rss_ctx, rxfh.rss_context); kfree(ctx); + } goto out; } @@ -1383,12 +1423,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, dev->priv_flags |= IFF_RXFH_CONFIGURED; } /* Update rss_ctx tracking */ - if (create) { - /* Ideally this should happen before calling the driver, - * so that we can fail more cleanly; but we don't have the - * context ID until the driver picks it, so we have to - * wait until after. - */ + if (create && !ops->create_rxfh_context) { + /* driver uses old API, it chose context ID */ if (WARN_ON(idr_find(&dev->ethtool->rss_ctx, rxfh.rss_context))) { /* context ID reused, our tracking is screwed */ kfree(ctx); @@ -1398,8 +1434,6 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, WARN_ON(idr_alloc(&dev->ethtool->rss_ctx, ctx, rxfh.rss_context, rxfh.rss_context + 1, GFP_KERNEL) != rxfh.rss_context); - ctx->indir_no_change = rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE; - ctx->key_no_change = !rxfh.key_size; } if (delete) { WARN_ON(idr_remove(&dev->ethtool->rss_ctx, rxfh.rss_context) != ctx); From patchwork Tue Sep 12 14:21:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381786 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F8CA18C05 for ; Tue, 12 Sep 2023 14:22:40 +0000 (UTC) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2082.outbound.protection.outlook.com [40.107.244.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2925C118 for ; Tue, 12 Sep 2023 07:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ewOqTjKl0Cv+jvbq4w6UY4m+GNEFA1ltdqZuNAkieBJZMmuow2R9DlJpDMOrbr6eYC1gvyq9pYF5M04R2za4GYWMPPZKkBOvejwmQG/MJzHUDXucoRmOfFY4OSe+nR5wDXHjUMEzc3UgAJGIRIB9P1LgfGaVssaYUBENBCvoccnIY23Mi6OaeB16GtrDPKsLMnomjLsoZV/QOFRI523spFxslg7x0IX8/Z3L4qkcgoYb06jxIkIzBntndT01FcKTklMJZH0E9bXDncA2RsppVK4RYefrnS3HRMhTlv1K2wJoR+Wq1hWGWCuOgF4s9BYLBDb1hz59L284hGpUMErKvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dSyVKPtcvQCog7oYOnrncxzQ89nafW1rmDsCQfCgs+g=; b=m6sWDZGhyd5DClLi7py0Aa3YXP1smLeaphCLyx3N4KZNDrMjwcuwuOY5WDcwMjvDUZB4BiSzPk92hESOck7b5svhZvwHURZurgrYp+HufVQlXwVBSt3PkDELjH4MZM1SwObaxDqQKKWXMFloP79HPTrEXY//6YRTP0O/4cmIBbxkhSWNavSI8wFxzOdL30MSQgpAs4ctJaHfCuPJ5JmqKRzMtUMMv8GKDxKh6vMeXejnLg1nSz4tfQU/SIwQ2pjIHoX7cLKrae6PsNVzZgjBz4TJXZuAIw1ZWF/ij9Og8dgxyBB9v9GGA5DxgjNLlIe2zkPuDJ8ym7SjEBmDglf6Ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dSyVKPtcvQCog7oYOnrncxzQ89nafW1rmDsCQfCgs+g=; b=oW8Zdh7SnxxOCFtC4lkK3zQRVXnhwxCwWCNzIA1sP4PQ65P+tCOh88UgPofmRACov6v89i31yFR8HxaeaSztnqw+bpf0mEz0rZ8+sk6Rv7KrZisa4OXd1bbKt/8M68wz50J9rzEwjIEL4X+NX04BhGWg28vtivnBMBzdsFgCvj0= Received: from CY5PR16CA0025.namprd16.prod.outlook.com (2603:10b6:930:10::17) by CH3PR12MB9341.namprd12.prod.outlook.com (2603:10b6:610:1cd::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.31; Tue, 12 Sep 2023 14:22:36 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:930:10:cafe::bc) by CY5PR16CA0025.outlook.office365.com (2603:10b6:930:10::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.19 via Frontend Transport; Tue, 12 Sep 2023 14:22:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.16 via Frontend Transport; Tue, 12 Sep 2023 14:22:35 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:32 -0500 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:30 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 5/7] net: ethtool: add an extack parameter to new rxfh_context APIs Date: Tue, 12 Sep 2023 15:21:40 +0100 Message-ID: <741a59efee97edc978f0f65d1d1f48edbdc38e2d.1694443665.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC1:EE_|CH3PR12MB9341:EE_ X-MS-Office365-Filtering-Correlation-Id: 7aad1343-fa41-457f-7548-08dbb39bb62d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EpzxLKqXF/OKTbCNnQsVB0CHMjZA4CmXsX71LLGLL+htObI7ZPRC5u+hpiPXRRWWPI5NnIOGxMr9+Fb0OrH406LPLi+vVDky9IPid6lR+z1XC+g+tVGd7ilBTwjTVk1szWCeXxIosUbZ18s96l9RDTyMKnm9NtvoCn34nDsizwTqcFL3wNCJK7jE4037/dXqCHnJY9wnYpGw+AJnI3D81FmA0z44FrXZILCzqnrzUZrMYw+Tk/223PSD+O2gEDDFthjTV+HatLBzYLua598s/OdS+3QXRYIueg94Oxrz2Oxzv6c6zU/HSzUnrCHhn48c5JHKJBU/6jkZt5JADlpK/aV7yPXArqH4vwUflwT7Pdbm7ZSTSh/JMTIcZox4FUlHgiJRo10fgIP2vK4hqxw+7S4M3DM/qfjlG2Uaq3sMA+tTGLzFrRN2YP4I6ST+UNKO5i2bj+VSm3UAyXjagYjZ+Nd946mMvm/u+wn3ZRjAuJreKnaDFAm1GxgtMGox9nKQdZb1JusF2HWzBRrYGsGikyk4moHm0gyneQq5SKkQ6m5xNP6jQWmdTEjOzbUr1KbwZAcG8vm76c1SL6RsQMxjM1aRkvc/bH9irmlh4YvSKfXIE63Jc3INJTr+RHjxdo48YZ6Fdjn8jKBuPa/JmMi6rffD01gjofBaLBFJlLicDGbN6F8cMHjSoTyg6luIEp6tpxBG2AfSVPMdYldDFm/9RprrPxlagUcaLrwh55XeBNop5FDtEKFzIzRg0l7g/7qL6S3p/ZUx7LUCkPW3PJAKfQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(346002)(39860400002)(396003)(186009)(451199024)(1800799009)(82310400011)(40470700004)(46966006)(36840700001)(9686003)(478600001)(8676002)(336012)(2876002)(40460700003)(55446002)(7416002)(36756003)(86362001)(82740400003)(356005)(81166007)(5660300002)(40480700001)(316002)(36860700001)(47076005)(83380400001)(4326008)(8936002)(2906002)(110136005)(426003)(41300700001)(26005)(54906003)(6666004)(70586007)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:35.9229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7aad1343-fa41-457f-7548-08dbb39bb62d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9341 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree Currently passed as NULL, but will allow drivers to report back errors when ethnl support for these ops is added. Signed-off-by: Edward Cree --- include/linux/ethtool.h | 9 ++++++--- net/core/dev.c | 3 ++- net/ethtool/ioctl.c | 9 ++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 4fa2a7f6ed4c..8977aa8523e3 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -927,14 +927,17 @@ struct ethtool_ops { int (*create_rxfh_context)(struct net_device *, struct ethtool_rxfh_context *ctx, const u32 *indir, const u8 *key, - const u8 hfunc, u32 rss_context); + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack); int (*modify_rxfh_context)(struct net_device *, struct ethtool_rxfh_context *ctx, const u32 *indir, const u8 *key, - const u8 hfunc, u32 rss_context); + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack); int (*remove_rxfh_context)(struct net_device *, struct ethtool_rxfh_context *ctx, - u32 rss_context); + u32 rss_context, + struct netlink_ext_ack *extack); int (*set_rxfh_context)(struct net_device *, const u32 *indir, const u8 *key, const u8 hfunc, u32 *rss_context, bool delete); diff --git a/net/core/dev.c b/net/core/dev.c index 6b8e5fd8691b..f12767466427 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10869,7 +10869,8 @@ static void netdev_rss_contexts_free(struct net_device *dev) idr_remove(&dev->ethtool->rss_ctx, context); if (dev->ethtool_ops->create_rxfh_context) - dev->ethtool_ops->remove_rxfh_context(dev, ctx, context); + dev->ethtool_ops->remove_rxfh_context(dev, ctx, context, + NULL); else dev->ethtool_ops->set_rxfh_context(dev, indir, key, ctx->hfunc, diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 4ce960a5ad4c..5b943db75974 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1385,14 +1385,17 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, if (create) ret = ops->create_rxfh_context(dev, ctx, indir, hkey, rxfh.hfunc, - rxfh.rss_context); + rxfh.rss_context, + NULL); else if (delete) ret = ops->remove_rxfh_context(dev, ctx, - rxfh.rss_context); + rxfh.rss_context, + NULL); else ret = ops->modify_rxfh_context(dev, ctx, indir, hkey, rxfh.hfunc, - rxfh.rss_context); + rxfh.rss_context, + NULL); } else { ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc, From patchwork Tue Sep 12 14:21:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381785 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7038118C05 for ; Tue, 12 Sep 2023 14:22:40 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5062115 for ; Tue, 12 Sep 2023 07:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=de/qqtoM3Y0HSTDsiCg9Nzv6FNfWfrblKfGGPq5XjtrcsxcxPGE+g2Y3VRfcr/zCvv5KM1ML/0Dj1E4gR2eRBrIRQhXljbq27r3MxM59XMc+qPtYGwEzFA7/IDNAY+MNeKkqndgtz40lL/C9Gs6Z3N90JG9e+STwypkb2c8yAsDoKdn3YJgLJFlyEc1psd77ZKi6/EM9mwe3dfybfFiMB/t57TKPUKoBaVlDIb/WDaaGYBtLEdb4x/Fy1sM6noJ5Lt0M6OERU6xjuK/WlVbs4VyWDCdLI1InvJ04pU5yad13HxtJjLoeknWbWEv/KJEDA88g3fCxmHbVoyJUpuL02Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3T9CcoNhkRi4iaP/doZOZKehp9MN19NM0+iK/AYfz/4=; b=DJLcaMkd38eHKqHtf3rtFWNhDfMXdPdOfQ4zcmXt07T27j5mWaH4HmPwJd2meCvo8NEdphFq2zYNte4R8ABS/vTZJ4opePDL/OOrbfy48yhooQ6k4OWj4eXYGcKoPrxsyQoVBEqUB7SjfsnI7ZsfJwr8bmnUoGbyV1QPI6VxN65vsMMmPN18mjvsEK1jSiA0+ZR+6M/Sfou6G/ocX2Gdf04wI858EdzLv3k0gGQGbVzYFSXcnzjiwKdcnAHtjnml+Nn8os2u+R9VN/Fo748jURNdpsLYpamv/np5tsLK0g5R3N9bDrgj0FMILrpxyeZxYh91ZPnb7UTsmHnHItCAig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3T9CcoNhkRi4iaP/doZOZKehp9MN19NM0+iK/AYfz/4=; b=fLJrGBnlQwrGcz+Y3WLEvdUuH5kVhljyDrfY/QB3Hn6oFHnW4RMuQ0oG7KjMgWwHHff8jDpw/PTw7fxU/82Bep/LGGW0p4wPzco1M2UC9fR4LttuiHEwgAHcWDU6aqvdD4CK/XgjqflBWVuCUulKhXSEegYF0CaE6xp53GFiwAQ= Received: from CY5PR16CA0013.namprd16.prod.outlook.com (2603:10b6:930:10::32) by BN9PR12MB5241.namprd12.prod.outlook.com (2603:10b6:408:11e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.37; Tue, 12 Sep 2023 14:22:37 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:930:10:cafe::8) by CY5PR16CA0013.outlook.office365.com (2603:10b6:930:10::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.19 via Frontend Transport; Tue, 12 Sep 2023 14:22:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.16 via Frontend Transport; Tue, 12 Sep 2023 14:22:37 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:34 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:34 -0500 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:32 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 6/7] net: ethtool: add a mutex protecting RSS contexts Date: Tue, 12 Sep 2023 15:21:41 +0100 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC1:EE_|BN9PR12MB5241:EE_ X-MS-Office365-Filtering-Correlation-Id: f174c0ca-d156-4fea-a7fb-08dbb39bb6e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TK8zh0jBbcdsHE0zHH6wiA8qEO0JspcuIKCL+HwymtgwwAOz3rFqXXUnF9UBV64DoKYEc88Kya6QaJIJV6O77Kq+CiOVPkKzTRHwhTUQR39uWmi8MMZk2qK4G47YGdytUpxBeMkt3m5vP8wT4888vjAp8HGDgIvQH1K2QLcN9fXwVMSlZ3JN+LRHhCRxrPYqBppRJrdiInqgmWl2SdiyEmq8TQ7GIqzMoVhDrkX0kAbunBZYdb7JkLF89EsTQDIRzzFAnLwmT0jpXX/UxUqr4WtijAVNesq+7MHDTTdSc5OCAqE9I7K0IlWUWqz2htzd7HchYvqzGZtabYhzRJv/VDZHwvh+E8f4NeTzqQPXVC6D15sNMh1bSaGdehfCkioTItkuFLdNUEdk2ff+Y4FMKRehM2hrRgBlo7DJB4V3eOhVk6JqYDqcIOE9fAc2/SuCLCMgo7tXkLYHDqMOpUqinuiPdH88rGpEz1AHY2/RTjtasfJ09Tl2wDuvvGwiGhg3/tl3OwMnAwobYlas60yQdeLDZi9gJjiZeU1T8yM+cy0laiejs8tsWxTq0jURrVrvMBBMeJlfOaUgnIgKYs6ehIiXI5GvsaZMRJ7Wdf5Umjq8F16CtahnGcwlYUZTrLqtZXmY2kAGroXYXuPGYv8xQkd9Im6Ui5cxCjNnCcvDCgnxIBART2lRuuR9Ddcwr6T48E6NiYelbHn186QQpBZMtcVE4HWoXVSzwROWbKdx2WZEz3UOHsgfavgsOTHI3YljS+WE9YuG9f6TOsaAMySvHA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(136003)(39860400002)(346002)(82310400011)(451199024)(1800799009)(186009)(36840700001)(40470700004)(46966006)(47076005)(36860700001)(336012)(83380400001)(426003)(26005)(110136005)(41300700001)(81166007)(6666004)(82740400003)(356005)(70586007)(70206006)(8936002)(8676002)(478600001)(4326008)(54906003)(5660300002)(316002)(7416002)(2876002)(2906002)(55446002)(86362001)(36756003)(9686003)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:37.1573 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f174c0ca-d156-4fea-a7fb-08dbb39bb6e2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5241 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree While this is not needed to serialise the ethtool entry points (which are all under RTNL), drivers may have cause to asynchronously access dev->ethtool->rss_ctx; taking dev->ethtool->rss_lock allows them to do this safely without needing to take the RTNL. Signed-off-by: Edward Cree --- include/linux/ethtool.h | 3 +++ net/core/dev.c | 5 +++++ net/ethtool/ioctl.c | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 8977aa8523e3..1f8293deebd5 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1026,11 +1026,14 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev, /** * struct ethtool_netdev_state - per-netdevice state for ethtool features * @rss_ctx: IDR storing custom RSS context state + * @rss_lock: Protects entries in @rss_ctx. May be taken from + * within RTNL. * @rss_ctx_max_id: maximum (exclusive) supported RSS context ID * @wol_enabled: Wake-on-LAN is enabled */ struct ethtool_netdev_state { struct idr rss_ctx; + struct mutex rss_lock; u32 rss_ctx_max_id; u32 wol_enabled:1; }; diff --git a/net/core/dev.c b/net/core/dev.c index f12767466427..2acb4d8cd4c7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10054,6 +10054,7 @@ int register_netdevice(struct net_device *dev) idr_init_base(&dev->ethtool->rss_ctx, 1); spin_lock_init(&dev->addr_list_lock); + mutex_init(&dev->ethtool->rss_lock); netdev_set_addr_lockdep_class(dev); ret = dev_get_valid_name(net, dev, dev->name); @@ -10863,6 +10864,7 @@ static void netdev_rss_contexts_free(struct net_device *dev) if (!dev->ethtool_ops->create_rxfh_context && !dev->ethtool_ops->set_rxfh_context) return; + mutex_lock(&dev->ethtool->rss_lock); idr_for_each_entry(&dev->ethtool->rss_ctx, ctx, context) { u32 *indir = ethtool_rxfh_context_indir(ctx); u8 *key = ethtool_rxfh_context_key(ctx); @@ -10877,6 +10879,7 @@ static void netdev_rss_contexts_free(struct net_device *dev) &context, true); kfree(ctx); } + mutex_unlock(&dev->ethtool->rss_lock); } /** @@ -10990,6 +10993,8 @@ void unregister_netdevice_many_notify(struct list_head *head, if (dev->netdev_ops->ndo_uninit) dev->netdev_ops->ndo_uninit(dev); + mutex_destroy(&dev->ethtool->rss_lock); + if (skb) rtmsg_ifinfo_send(skb, dev, GFP_KERNEL, portid, nlh); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 5b943db75974..70cca80cea70 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1258,6 +1258,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, u8 *rss_config; u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]); bool create = false, delete = false; + bool locked = false; /* dev->ethtool->rss_lock taken */ if (!ops->get_rxnfc || !ops->set_rxfh) return -EOPNOTSUPP; @@ -1335,6 +1336,10 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } } + if (rxfh.rss_context) { + mutex_lock(&dev->ethtool->rss_lock); + locked = true; + } if (create) { if (delete) { ret = -EINVAL; @@ -1457,6 +1462,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } out: + if (locked) + mutex_unlock(&dev->ethtool->rss_lock); kfree(rss_config); return ret; } From patchwork Tue Sep 12 14:21:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13381787 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39A3D18AE9 for ; Tue, 12 Sep 2023 14:22:47 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF4910D for ; Tue, 12 Sep 2023 07:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T65EeC2oaJRR63ImyWLosZB8IyJR7GEnbwnieuMlYxtdYFKdGmEZvf0x2viZl25K7aBhLm8DAPkHaMqCAMPLXmb4v+iKzDvglA442kD6bqMDEJ7Jm3FUIR6ql9JPEq9K6J7foSKtL1vdjFInDEMEtmV3+RIflIefkth8K7uPc0CShbbQmas2CWi3B/Urn5nwwwUd3N9X66Fztqxs10Acp9dRI1DBcWa+7PNKDDg/2bJl57QLyw1KBSd/UmKqNtmIEUldtrL98f3E02E9fHNhpWbbRSuWk2dGthtaSyzlon2l9xa8mjTvEs3j/5vogl3Cur+4i+7lAvly2kjGC6MFig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=P/w/qaqYuQAcZwkoqfZm1ohvTaNx83SPqo9FaDXvo98=; b=cuZuzNdIdLF+9y1jG7AlCxDbQs+SpacwwRJcX/yKFEaQTJPp1Q4GV0eYSM2YjRaqIOb97MnkNqq6rzF0PC2REJowi+jwOq1tN6WsHKUyCrSEor4ewWYm9dHIy7dlKDQNxsTmUPY/PXJgO/X8Cn+pzMXOEgdhqkiJFBgZ1odNf6CzA6DJliIK2OVIs5NpufHApRsT+OuKFRjDeaUCXUJxUmkrYgXqWIYrb4mF4XlbG9vsJFldx52vK+HHm9K4Pn3jGA3uWdoEYWFQRaeVvTBTNpJmAb5BmkqVfsRPxHLVGgwyZbyH8R8PIDztKskMuA8tUlYtObpBDutk8vmsuRddhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P/w/qaqYuQAcZwkoqfZm1ohvTaNx83SPqo9FaDXvo98=; b=0QZ4ni+i9/ehxzO1UteLtyEoVmZdOargHT8yArDfSMYjW1hopAGQoUlhrcdpaOccz7GXHjLqvICyGtsMveshpX6E+k0CdBCNxv371NQgUf0uMAA/3WNU+xZJe410omMq7nyNnyJxNVIl6lrn6o6I3GnAaZzZl98rqgtfiaYYmCI= Received: from CY5PR16CA0020.namprd16.prod.outlook.com (2603:10b6:930:10::16) by BL1PR12MB5269.namprd12.prod.outlook.com (2603:10b6:208:30b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.19; Tue, 12 Sep 2023 14:22:38 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:930:10:cafe::55) by CY5PR16CA0020.outlook.office365.com (2603:10b6:930:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.36 via Frontend Transport; Tue, 12 Sep 2023 14:22:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.16 via Frontend Transport; Tue, 12 Sep 2023 14:22:37 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 09:22:37 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 12 Sep 2023 07:22:36 -0700 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 12 Sep 2023 09:22:34 -0500 From: To: , , , , CC: Edward Cree , , , , , , , , , , , , , Subject: [RFC PATCH v3 net-next 7/7] sfc: use new rxfh_context API Date: Tue, 12 Sep 2023 15:21:42 +0100 Message-ID: <3ccb1df9d4aef7dbbfb3eec2abaaf9f48e9ed6b6.1694443665.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC1:EE_|BL1PR12MB5269:EE_ X-MS-Office365-Filtering-Correlation-Id: b5bf7617-42d7-43b1-7cd4-08dbb39bb738 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kp4iBfXvdqk+1kJMQc/9bQ8FzsvE/L8Z0G1yuyxmpvUSHUAOZqBy9A4vj2PYtSO2TDANVK83NxAUilM/HuJCuEZ73K2Xvv7qWmc27FnYrogrnn1GlMR03GgwBXzrKRbrBHG+4ivMR9h0RegVbzJJzUDTD5RFiGvSZoFfdyKglKieXDTaG1dz399dfghyUbgbDQ/1iS5gF0DB1tKw5xpz9XH7D5Jo4qL3VsiI5qXYXm+jOaInY2awcyAPFuyYmaRRaRbRnDxpmoZCKJmeb2AfNKTtCJP5XhZHIMz1FU1ZBnBXj11LSPrwJvFJvN4aXupukadl80ZJw7H0TbXLC+MtabiCaADHhqcUX9WPnpIYsdB17xF4UhVyFNzmH5QPXbWV8Gfy6F3uEP5LAKE2Vg0JD705H6o15pNHO4D8IOuG2L9/diu+kgK/gTCgS/Vy5P5aUBX7kDLdy/lDQQdg1vu3O8H4Op5d8PhMw948rVdqDZ2qBjO4UYjHGsFC8SqAjghdIfabmwSPukmwZWkqzy4iyk/n8TsDqZbGMNtvLMRd9ho/gq6upvZ2Qzh7E5tfP+JUfIRref+OSi+39qRKONjm9nbq92etcXWrlO+pBsc+scZYZ8tznwyO8/E4NZ9O4t+o6UxFmEntX/zr6zWY62+NfPq5ig/2Ph7X7NQJ27fpu1CBxqNM923F2EE6GARimpvzUKHBKdWotlR1UsPS79ePqHjZOhfCFgozYbAagRSvr1eY5kuFiV+BxGBd+2JYGg56V5JVmjTq+r2dFvG3SW9m+A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(39860400002)(376002)(136003)(451199024)(82310400011)(1800799009)(186009)(46966006)(40470700004)(36840700001)(40480700001)(40460700003)(30864003)(54906003)(316002)(70206006)(478600001)(110136005)(81166007)(70586007)(2906002)(2876002)(7416002)(55446002)(86362001)(8676002)(4326008)(8936002)(41300700001)(36860700001)(5660300002)(83380400001)(47076005)(9686003)(6666004)(82740400003)(356005)(426003)(336012)(26005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 14:22:37.7042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5bf7617-42d7-43b1-7cd4-08dbb39bb738 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5269 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Edward Cree The core is now responsible for allocating IDs and a memory region for us to store our state (struct efx_rss_context_priv), so we no longer need efx_alloc_rss_context_entry() and friends. Since the contexts are now maintained by the core, use the core's lock (net_dev->ethtool->rss_lock), rather than our own mutex (efx->rss_lock), to serialise access against changes; and remove the now-unused efx->rss_lock from struct efx_nic. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/ef100_ethtool.c | 5 +- drivers/net/ethernet/sfc/efx.c | 2 +- drivers/net/ethernet/sfc/efx.h | 2 +- drivers/net/ethernet/sfc/efx_common.c | 10 +- drivers/net/ethernet/sfc/ethtool.c | 5 +- drivers/net/ethernet/sfc/ethtool_common.c | 147 +++++++++++++--------- drivers/net/ethernet/sfc/ethtool_common.h | 18 ++- drivers/net/ethernet/sfc/mcdi_filters.c | 133 ++++++++++---------- drivers/net/ethernet/sfc/mcdi_filters.h | 8 +- drivers/net/ethernet/sfc/net_driver.h | 28 ++--- drivers/net/ethernet/sfc/rx_common.c | 64 ++-------- drivers/net/ethernet/sfc/rx_common.h | 8 +- 13 files changed, 213 insertions(+), 219 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index 6dfa062feebc..e20305461b57 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -1396,7 +1396,7 @@ static void efx_ef10_table_reset_mc_allocations(struct efx_nic *efx) efx_mcdi_filter_table_reset_mc_allocations(efx); nic_data->must_restore_piobufs = true; efx_ef10_forget_old_piobufs(efx); - efx->rss_context.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; + efx->rss_context.priv.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; /* Driver-created vswitches and vports must be re-created */ nic_data->must_probe_vswitching = true; diff --git a/drivers/net/ethernet/sfc/ef100_ethtool.c b/drivers/net/ethernet/sfc/ef100_ethtool.c index 702abbe59b76..c5f82eb0e5b4 100644 --- a/drivers/net/ethernet/sfc/ef100_ethtool.c +++ b/drivers/net/ethernet/sfc/ef100_ethtool.c @@ -58,10 +58,13 @@ const struct ethtool_ops ef100_ethtool_ops = { .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, .get_rxfh_key_size = efx_ethtool_get_rxfh_key_size, + .rxfh_priv_size = sizeof(struct efx_rss_context_priv), .get_rxfh = efx_ethtool_get_rxfh, .set_rxfh = efx_ethtool_set_rxfh, .get_rxfh_context = efx_ethtool_get_rxfh_context, - .set_rxfh_context = efx_ethtool_set_rxfh_context, + .create_rxfh_context = efx_ethtool_create_rxfh_context, + .modify_rxfh_context = efx_ethtool_modify_rxfh_context, + .remove_rxfh_context = efx_ethtool_remove_rxfh_context, .get_module_info = efx_ethtool_get_module_info, .get_module_eeprom = efx_ethtool_get_module_eeprom, diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index 19f4b4d0b851..6ae84356797f 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -299,7 +299,7 @@ static int efx_probe_nic(struct efx_nic *efx) if (efx->n_channels > 1) netdev_rss_key_fill(efx->rss_context.rx_hash_key, sizeof(efx->rss_context.rx_hash_key)); - efx_set_default_rx_indir_table(efx, &efx->rss_context); + efx_set_default_rx_indir_table(efx, efx->rss_context.rx_indir_table); /* Initialise the interrupt moderation settings */ efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000); diff --git a/drivers/net/ethernet/sfc/efx.h b/drivers/net/ethernet/sfc/efx.h index 48d3623735ba..7a6cab883d66 100644 --- a/drivers/net/ethernet/sfc/efx.h +++ b/drivers/net/ethernet/sfc/efx.h @@ -158,7 +158,7 @@ static inline s32 efx_filter_get_rx_ids(struct efx_nic *efx, } /* RSS contexts */ -static inline bool efx_rss_active(struct efx_rss_context *ctx) +static inline bool efx_rss_active(struct efx_rss_context_priv *ctx) { return ctx->context_id != EFX_MCDI_RSS_CONTEXT_INVALID; } diff --git a/drivers/net/ethernet/sfc/efx_common.c b/drivers/net/ethernet/sfc/efx_common.c index 175bd9cdfdac..2cd92e1f68db 100644 --- a/drivers/net/ethernet/sfc/efx_common.c +++ b/drivers/net/ethernet/sfc/efx_common.c @@ -714,7 +714,7 @@ void efx_reset_down(struct efx_nic *efx, enum reset_type method) mutex_lock(&efx->mac_lock); down_write(&efx->filter_sem); - mutex_lock(&efx->rss_lock); + mutex_lock(&efx->net_dev->ethtool->rss_lock); efx->type->fini(efx); } @@ -777,7 +777,7 @@ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) if (efx->type->rx_restore_rss_contexts) efx->type->rx_restore_rss_contexts(efx); - mutex_unlock(&efx->rss_lock); + mutex_unlock(&efx->net_dev->ethtool->rss_lock); efx->type->filter_table_restore(efx); up_write(&efx->filter_sem); @@ -793,7 +793,7 @@ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok) fail: efx->port_initialized = false; - mutex_unlock(&efx->rss_lock); + mutex_unlock(&efx->net_dev->ethtool->rss_lock); up_write(&efx->filter_sem); mutex_unlock(&efx->mac_lock); @@ -1000,9 +1000,7 @@ int efx_init_struct(struct efx_nic *efx, struct pci_dev *pci_dev) efx->type->rx_hash_offset - efx->type->rx_prefix_size; efx->rx_packet_ts_offset = efx->type->rx_ts_offset - efx->type->rx_prefix_size; - INIT_LIST_HEAD(&efx->rss_context.list); - efx->rss_context.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; - mutex_init(&efx->rss_lock); + efx->rss_context.priv.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; efx->vport_id = EVB_PORT_ID_ASSIGNED; spin_lock_init(&efx->stats_lock); efx->vi_stride = EFX_DEFAULT_VI_STRIDE; diff --git a/drivers/net/ethernet/sfc/ethtool.c b/drivers/net/ethernet/sfc/ethtool.c index 364323599f7b..f5fb7464e025 100644 --- a/drivers/net/ethernet/sfc/ethtool.c +++ b/drivers/net/ethernet/sfc/ethtool.c @@ -267,10 +267,13 @@ const struct ethtool_ops efx_ethtool_ops = { .set_rxnfc = efx_ethtool_set_rxnfc, .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, .get_rxfh_key_size = efx_ethtool_get_rxfh_key_size, + .rxfh_priv_size = sizeof(struct efx_rss_context_priv), .get_rxfh = efx_ethtool_get_rxfh, .set_rxfh = efx_ethtool_set_rxfh, .get_rxfh_context = efx_ethtool_get_rxfh_context, - .set_rxfh_context = efx_ethtool_set_rxfh_context, + .create_rxfh_context = efx_ethtool_create_rxfh_context, + .modify_rxfh_context = efx_ethtool_modify_rxfh_context, + .remove_rxfh_context = efx_ethtool_remove_rxfh_context, .get_ts_info = efx_ethtool_get_ts_info, .get_module_info = efx_ethtool_get_module_info, .get_module_eeprom = efx_ethtool_get_module_eeprom, diff --git a/drivers/net/ethernet/sfc/ethtool_common.c b/drivers/net/ethernet/sfc/ethtool_common.c index a8cbceeb301b..7cd01012152e 100644 --- a/drivers/net/ethernet/sfc/ethtool_common.c +++ b/drivers/net/ethernet/sfc/ethtool_common.c @@ -820,10 +820,10 @@ int efx_ethtool_get_rxnfc(struct net_device *net_dev, return 0; case ETHTOOL_GRXFH: { - struct efx_rss_context *ctx = &efx->rss_context; + struct efx_rss_context_priv *ctx = &efx->rss_context.priv; __u64 data; - mutex_lock(&efx->rss_lock); + mutex_lock(&net_dev->ethtool->rss_lock); if (info->flow_type & FLOW_RSS && info->rss_context) { ctx = efx_find_rss_context_entry(efx, info->rss_context); if (!ctx) { @@ -864,7 +864,7 @@ int efx_ethtool_get_rxnfc(struct net_device *net_dev, out_setdata_unlock: info->data = data; out_unlock: - mutex_unlock(&efx->rss_lock); + mutex_unlock(&net_dev->ethtool->rss_lock); return rc; } @@ -1207,96 +1207,121 @@ int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir, u8 *key, u8 *hfunc, u32 rss_context) { struct efx_nic *efx = efx_netdev_priv(net_dev); - struct efx_rss_context *ctx; + struct efx_rss_context_priv *ctx_priv; + struct efx_rss_context ctx; int rc = 0; if (!efx->type->rx_pull_rss_context_config) return -EOPNOTSUPP; - mutex_lock(&efx->rss_lock); - ctx = efx_find_rss_context_entry(efx, rss_context); - if (!ctx) { + mutex_lock(&net_dev->ethtool->rss_lock); + ctx_priv = efx_find_rss_context_entry(efx, rss_context); + if (!ctx_priv) { rc = -ENOENT; goto out_unlock; } - rc = efx->type->rx_pull_rss_context_config(efx, ctx); + ctx.priv = *ctx_priv; + rc = efx->type->rx_pull_rss_context_config(efx, &ctx); if (rc) goto out_unlock; if (hfunc) *hfunc = ETH_RSS_HASH_TOP; if (indir) - memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table)); + memcpy(indir, ctx.rx_indir_table, sizeof(ctx.rx_indir_table)); if (key) - memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size); + memcpy(key, ctx.rx_hash_key, efx->type->rx_hash_key_size); out_unlock: - mutex_unlock(&efx->rss_lock); + mutex_unlock(&net_dev->ethtool->rss_lock); return rc; } -int efx_ethtool_set_rxfh_context(struct net_device *net_dev, - const u32 *indir, const u8 *key, - const u8 hfunc, u32 *rss_context, - bool delete) +int efx_ethtool_modify_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack) { struct efx_nic *efx = efx_netdev_priv(net_dev); - struct efx_rss_context *ctx; - bool allocated = false; - int rc; + struct efx_rss_context_priv *priv; - if (!efx->type->rx_push_rss_context_config) + if (!efx->type->rx_push_rss_context_config) { + NL_SET_ERR_MSG_MOD(extack, + "NIC type does not support custom contexts"); return -EOPNOTSUPP; + } /* Hash function is Toeplitz, cannot be changed */ - if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) + if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) { + NL_SET_ERR_MSG_MOD(extack, "Only Toeplitz hash is supported"); return -EOPNOTSUPP; + } - mutex_lock(&efx->rss_lock); + priv = ethtool_rxfh_context_priv(ctx); - if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) { - if (delete) { - /* alloc + delete == Nothing to do */ - rc = -EINVAL; - goto out_unlock; - } - ctx = efx_alloc_rss_context_entry(efx); - if (!ctx) { - rc = -ENOMEM; - goto out_unlock; - } - ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID; - /* Initialise indir table and key to defaults */ - efx_set_default_rx_indir_table(efx, ctx); - netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key)); - allocated = true; - } else { - ctx = efx_find_rss_context_entry(efx, *rss_context); - if (!ctx) { - rc = -ENOENT; - goto out_unlock; - } - } + if (!key) + key = ethtool_rxfh_context_key(ctx); + if (!indir) + indir = ethtool_rxfh_context_indir(ctx); - if (delete) { - /* delete this context */ - rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL); - if (!rc) - efx_free_rss_context_entry(ctx); - goto out_unlock; + return efx->type->rx_push_rss_context_config(efx, priv, indir, key, + false); +} + +int efx_ethtool_create_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack) +{ + struct efx_nic *efx = efx_netdev_priv(net_dev); + struct efx_rss_context_priv *priv; + + if (!efx->type->rx_push_rss_context_config) { + NL_SET_ERR_MSG_MOD(extack, + "NIC type does not support custom contexts"); + return -EOPNOTSUPP; + } + /* Hash function is Toeplitz, cannot be changed */ + if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) { + NL_SET_ERR_MSG_MOD(extack, "Only Toeplitz hash is supported"); + return -EOPNOTSUPP; } - if (!key) - key = ctx->rx_hash_key; + priv = ethtool_rxfh_context_priv(ctx); + + priv->context_id = EFX_MCDI_RSS_CONTEXT_INVALID; + priv->rx_hash_udp_4tuple = false; + /* Generate default indir table and/or key if not specified. + * We use ctx as a place to store these; this is fine because + * we're doing a create, so if we fail then the ctx will just + * be deleted. + */ if (!indir) - indir = ctx->rx_indir_table; + efx_set_default_rx_indir_table(efx, ethtool_rxfh_context_indir(ctx)); + if (!key) + netdev_rss_key_fill(ethtool_rxfh_context_key(ctx), + ctx->key_size); + return efx_ethtool_modify_rxfh_context(net_dev, ctx, indir, key, hfunc, + rss_context, extack); +} - rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key); - if (rc && allocated) - efx_free_rss_context_entry(ctx); - else - *rss_context = ctx->user_id; -out_unlock: - mutex_unlock(&efx->rss_lock); - return rc; +int efx_ethtool_remove_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + u32 rss_context, + struct netlink_ext_ack *extack) +{ + struct efx_nic *efx = efx_netdev_priv(net_dev); + struct efx_rss_context_priv *priv; + + if (!efx->type->rx_push_rss_context_config) { + NL_SET_ERR_MSG_MOD(extack, + "NIC type does not support custom contexts"); + return -EOPNOTSUPP; + } + + priv = ethtool_rxfh_context_priv(ctx); + return efx->type->rx_push_rss_context_config(efx, priv, NULL, NULL, + true); } int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) diff --git a/drivers/net/ethernet/sfc/ethtool_common.h b/drivers/net/ethernet/sfc/ethtool_common.h index 659491932101..3df852eaab20 100644 --- a/drivers/net/ethernet/sfc/ethtool_common.h +++ b/drivers/net/ethernet/sfc/ethtool_common.h @@ -50,10 +50,20 @@ int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir, const u8 *key, const u8 hfunc); int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir, u8 *key, u8 *hfunc, u32 rss_context); -int efx_ethtool_set_rxfh_context(struct net_device *net_dev, - const u32 *indir, const u8 *key, - const u8 hfunc, u32 *rss_context, - bool delete); +int efx_ethtool_create_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack); +int efx_ethtool_modify_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + const u32 *indir, const u8 *key, + const u8 hfunc, u32 rss_context, + struct netlink_ext_ack *extack); +int efx_ethtool_remove_rxfh_context(struct net_device *net_dev, + struct ethtool_rxfh_context *ctx, + u32 rss_context, + struct netlink_ext_ack *extack); int efx_ethtool_reset(struct net_device *net_dev, u32 *flags); int efx_ethtool_get_module_eeprom(struct net_device *net_dev, struct ethtool_eeprom *ee, diff --git a/drivers/net/ethernet/sfc/mcdi_filters.c b/drivers/net/ethernet/sfc/mcdi_filters.c index 4ff6586116ee..fa6eb4ec170a 100644 --- a/drivers/net/ethernet/sfc/mcdi_filters.c +++ b/drivers/net/ethernet/sfc/mcdi_filters.c @@ -194,7 +194,7 @@ efx_mcdi_filter_push_prep_set_match_fields(struct efx_nic *efx, static void efx_mcdi_filter_push_prep(struct efx_nic *efx, const struct efx_filter_spec *spec, efx_dword_t *inbuf, u64 handle, - struct efx_rss_context *ctx, + struct efx_rss_context_priv *ctx, bool replacing) { u32 flags = spec->flags; @@ -245,7 +245,7 @@ static void efx_mcdi_filter_push_prep(struct efx_nic *efx, static int efx_mcdi_filter_push(struct efx_nic *efx, const struct efx_filter_spec *spec, u64 *handle, - struct efx_rss_context *ctx, bool replacing) + struct efx_rss_context_priv *ctx, bool replacing) { MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN); MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN); @@ -345,9 +345,9 @@ static s32 efx_mcdi_filter_insert_locked(struct efx_nic *efx, bool replace_equal) { DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); + struct efx_rss_context_priv *ctx = NULL; struct efx_mcdi_filter_table *table; struct efx_filter_spec *saved_spec; - struct efx_rss_context *ctx = NULL; unsigned int match_pri, hash; unsigned int priv_flags; bool rss_locked = false; @@ -380,12 +380,12 @@ static s32 efx_mcdi_filter_insert_locked(struct efx_nic *efx, bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); if (spec->flags & EFX_FILTER_FLAG_RX_RSS) { - mutex_lock(&efx->rss_lock); + mutex_lock(&efx->net_dev->ethtool->rss_lock); rss_locked = true; if (spec->rss_context) ctx = efx_find_rss_context_entry(efx, spec->rss_context); else - ctx = &efx->rss_context; + ctx = &efx->rss_context.priv; if (!ctx) { rc = -ENOENT; goto out_unlock; @@ -548,7 +548,7 @@ static s32 efx_mcdi_filter_insert_locked(struct efx_nic *efx, out_unlock: if (rss_locked) - mutex_unlock(&efx->rss_lock); + mutex_unlock(&efx->net_dev->ethtool->rss_lock); up_write(&table->lock); return rc; } @@ -611,13 +611,13 @@ static int efx_mcdi_filter_remove_internal(struct efx_nic *efx, new_spec.priority = EFX_FILTER_PRI_AUTO; new_spec.flags = (EFX_FILTER_FLAG_RX | - (efx_rss_active(&efx->rss_context) ? + (efx_rss_active(&efx->rss_context.priv) ? EFX_FILTER_FLAG_RX_RSS : 0)); new_spec.dmaq_id = 0; new_spec.rss_context = 0; rc = efx_mcdi_filter_push(efx, &new_spec, &table->entry[filter_idx].handle, - &efx->rss_context, + &efx->rss_context.priv, true); if (rc == 0) @@ -764,7 +764,7 @@ static int efx_mcdi_filter_insert_addr_list(struct efx_nic *efx, ids = vlan->uc; } - filter_flags = efx_rss_active(&efx->rss_context) ? EFX_FILTER_FLAG_RX_RSS : 0; + filter_flags = efx_rss_active(&efx->rss_context.priv) ? EFX_FILTER_FLAG_RX_RSS : 0; /* Insert/renew filters */ for (i = 0; i < addr_count; i++) { @@ -833,7 +833,7 @@ static int efx_mcdi_filter_insert_def(struct efx_nic *efx, int rc; u16 *id; - filter_flags = efx_rss_active(&efx->rss_context) ? EFX_FILTER_FLAG_RX_RSS : 0; + filter_flags = efx_rss_active(&efx->rss_context.priv) ? EFX_FILTER_FLAG_RX_RSS : 0; efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0); @@ -1375,8 +1375,8 @@ void efx_mcdi_filter_table_restore(struct efx_nic *efx) struct efx_mcdi_filter_table *table = efx->filter_state; unsigned int invalid_filters = 0, failed = 0; struct efx_mcdi_filter_vlan *vlan; + struct efx_rss_context_priv *ctx; struct efx_filter_spec *spec; - struct efx_rss_context *ctx; unsigned int filter_idx; u32 mcdi_flags; int match_pri; @@ -1388,7 +1388,7 @@ void efx_mcdi_filter_table_restore(struct efx_nic *efx) return; down_write(&table->lock); - mutex_lock(&efx->rss_lock); + mutex_lock(&efx->net_dev->ethtool->rss_lock); for (filter_idx = 0; filter_idx < EFX_MCDI_FILTER_TBL_ROWS; filter_idx++) { spec = efx_mcdi_filter_entry_spec(table, filter_idx); @@ -1407,7 +1407,7 @@ void efx_mcdi_filter_table_restore(struct efx_nic *efx) if (spec->rss_context) ctx = efx_find_rss_context_entry(efx, spec->rss_context); else - ctx = &efx->rss_context; + ctx = &efx->rss_context.priv; if (spec->flags & EFX_FILTER_FLAG_RX_RSS) { if (!ctx) { netif_warn(efx, drv, efx->net_dev, @@ -1444,7 +1444,7 @@ void efx_mcdi_filter_table_restore(struct efx_nic *efx) } } - mutex_unlock(&efx->rss_lock); + mutex_unlock(&efx->net_dev->ethtool->rss_lock); up_write(&table->lock); /* @@ -1861,7 +1861,8 @@ bool efx_mcdi_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\ RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN) -int efx_mcdi_get_rss_context_flags(struct efx_nic *efx, u32 context, u32 *flags) +static int efx_mcdi_get_rss_context_flags(struct efx_nic *efx, u32 context, + u32 *flags) { /* * Firmware had a bug (sfc bug 61952) where it would not actually @@ -1909,8 +1910,8 @@ int efx_mcdi_get_rss_context_flags(struct efx_nic *efx, u32 context, u32 *flags) * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we * just need to set the UDP ports flags (for both IP versions). */ -void efx_mcdi_set_rss_context_flags(struct efx_nic *efx, - struct efx_rss_context *ctx) +static void efx_mcdi_set_rss_context_flags(struct efx_nic *efx, + struct efx_rss_context_priv *ctx) { MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN); u32 flags; @@ -1931,7 +1932,7 @@ void efx_mcdi_set_rss_context_flags(struct efx_nic *efx, } static int efx_mcdi_filter_alloc_rss_context(struct efx_nic *efx, bool exclusive, - struct efx_rss_context *ctx, + struct efx_rss_context_priv *ctx, unsigned *context_size) { MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); @@ -2032,25 +2033,26 @@ void efx_mcdi_rx_free_indir_table(struct efx_nic *efx) { int rc; - if (efx->rss_context.context_id != EFX_MCDI_RSS_CONTEXT_INVALID) { - rc = efx_mcdi_filter_free_rss_context(efx, efx->rss_context.context_id); + if (efx->rss_context.priv.context_id != EFX_MCDI_RSS_CONTEXT_INVALID) { + rc = efx_mcdi_filter_free_rss_context(efx, efx->rss_context.priv.context_id); WARN_ON(rc != 0); } - efx->rss_context.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; + efx->rss_context.priv.context_id = EFX_MCDI_RSS_CONTEXT_INVALID; } static int efx_mcdi_filter_rx_push_shared_rss_config(struct efx_nic *efx, unsigned *context_size) { struct efx_mcdi_filter_table *table = efx->filter_state; - int rc = efx_mcdi_filter_alloc_rss_context(efx, false, &efx->rss_context, - context_size); + int rc = efx_mcdi_filter_alloc_rss_context(efx, false, + &efx->rss_context.priv, + context_size); if (rc != 0) return rc; table->rx_rss_context_exclusive = false; - efx_set_default_rx_indir_table(efx, &efx->rss_context); + efx_set_default_rx_indir_table(efx, efx->rss_context.rx_indir_table); return 0; } @@ -2058,26 +2060,27 @@ static int efx_mcdi_filter_rx_push_exclusive_rss_config(struct efx_nic *efx, const u32 *rx_indir_table, const u8 *key) { + u32 old_rx_rss_context = efx->rss_context.priv.context_id; struct efx_mcdi_filter_table *table = efx->filter_state; - u32 old_rx_rss_context = efx->rss_context.context_id; int rc; - if (efx->rss_context.context_id == EFX_MCDI_RSS_CONTEXT_INVALID || + if (efx->rss_context.priv.context_id == EFX_MCDI_RSS_CONTEXT_INVALID || !table->rx_rss_context_exclusive) { - rc = efx_mcdi_filter_alloc_rss_context(efx, true, &efx->rss_context, - NULL); + rc = efx_mcdi_filter_alloc_rss_context(efx, true, + &efx->rss_context.priv, + NULL); if (rc == -EOPNOTSUPP) return rc; else if (rc != 0) goto fail1; } - rc = efx_mcdi_filter_populate_rss_table(efx, efx->rss_context.context_id, - rx_indir_table, key); + rc = efx_mcdi_filter_populate_rss_table(efx, efx->rss_context.priv.context_id, + rx_indir_table, key); if (rc != 0) goto fail2; - if (efx->rss_context.context_id != old_rx_rss_context && + if (efx->rss_context.priv.context_id != old_rx_rss_context && old_rx_rss_context != EFX_MCDI_RSS_CONTEXT_INVALID) WARN_ON(efx_mcdi_filter_free_rss_context(efx, old_rx_rss_context) != 0); table->rx_rss_context_exclusive = true; @@ -2091,9 +2094,9 @@ static int efx_mcdi_filter_rx_push_exclusive_rss_config(struct efx_nic *efx, return 0; fail2: - if (old_rx_rss_context != efx->rss_context.context_id) { - WARN_ON(efx_mcdi_filter_free_rss_context(efx, efx->rss_context.context_id) != 0); - efx->rss_context.context_id = old_rx_rss_context; + if (old_rx_rss_context != efx->rss_context.priv.context_id) { + WARN_ON(efx_mcdi_filter_free_rss_context(efx, efx->rss_context.priv.context_id) != 0); + efx->rss_context.priv.context_id = old_rx_rss_context; } fail1: netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); @@ -2101,33 +2104,28 @@ static int efx_mcdi_filter_rx_push_exclusive_rss_config(struct efx_nic *efx, } int efx_mcdi_rx_push_rss_context_config(struct efx_nic *efx, - struct efx_rss_context *ctx, + struct efx_rss_context_priv *ctx, const u32 *rx_indir_table, - const u8 *key) + const u8 *key, bool delete) { int rc; - WARN_ON(!mutex_is_locked(&efx->rss_lock)); + WARN_ON(!mutex_is_locked(&efx->net_dev->ethtool->rss_lock)); if (ctx->context_id == EFX_MCDI_RSS_CONTEXT_INVALID) { + if (delete) + /* already wasn't in HW, nothing to do */ + return 0; rc = efx_mcdi_filter_alloc_rss_context(efx, true, ctx, NULL); if (rc) return rc; } - if (!rx_indir_table) /* Delete this context */ + if (delete) /* Delete this context */ return efx_mcdi_filter_free_rss_context(efx, ctx->context_id); - rc = efx_mcdi_filter_populate_rss_table(efx, ctx->context_id, - rx_indir_table, key); - if (rc) - return rc; - - memcpy(ctx->rx_indir_table, rx_indir_table, - sizeof(efx->rss_context.rx_indir_table)); - memcpy(ctx->rx_hash_key, key, efx->type->rx_hash_key_size); - - return 0; + return efx_mcdi_filter_populate_rss_table(efx, ctx->context_id, + rx_indir_table, key); } int efx_mcdi_rx_pull_rss_context_config(struct efx_nic *efx, @@ -2139,16 +2137,16 @@ int efx_mcdi_rx_pull_rss_context_config(struct efx_nic *efx, size_t outlen; int rc, i; - WARN_ON(!mutex_is_locked(&efx->rss_lock)); + WARN_ON(!mutex_is_locked(&efx->net_dev->ethtool->rss_lock)); BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN != MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN); - if (ctx->context_id == EFX_MCDI_RSS_CONTEXT_INVALID) + if (ctx->priv.context_id == EFX_MCDI_RSS_CONTEXT_INVALID) return -ENOENT; MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID, - ctx->context_id); + ctx->priv.context_id); BUILD_BUG_ON(ARRAY_SIZE(ctx->rx_indir_table) != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN); rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf), @@ -2164,7 +2162,7 @@ int efx_mcdi_rx_pull_rss_context_config(struct efx_nic *efx, RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i]; MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID, - ctx->context_id); + ctx->priv.context_id); BUILD_BUG_ON(ARRAY_SIZE(ctx->rx_hash_key) != MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf), @@ -2186,35 +2184,42 @@ int efx_mcdi_rx_pull_rss_config(struct efx_nic *efx) { int rc; - mutex_lock(&efx->rss_lock); + mutex_lock(&efx->net_dev->ethtool->rss_lock); rc = efx_mcdi_rx_pull_rss_context_config(efx, &efx->rss_context); - mutex_unlock(&efx->rss_lock); + mutex_unlock(&efx->net_dev->ethtool->rss_lock); return rc; } void efx_mcdi_rx_restore_rss_contexts(struct efx_nic *efx) { struct efx_mcdi_filter_table *table = efx->filter_state; - struct efx_rss_context *ctx; + struct ethtool_rxfh_context *ctx; + u32 context; int rc; - WARN_ON(!mutex_is_locked(&efx->rss_lock)); + WARN_ON(!mutex_is_locked(&efx->net_dev->ethtool->rss_lock)); if (!table->must_restore_rss_contexts) return; - list_for_each_entry(ctx, &efx->rss_context.list, list) { + idr_for_each_entry(&efx->net_dev->ethtool->rss_ctx, ctx, context) { + struct efx_rss_context_priv *priv; + u32 *indir; + u8 *key; + + priv = ethtool_rxfh_context_priv(ctx); /* previous NIC RSS context is gone */ - ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID; + priv->context_id = EFX_MCDI_RSS_CONTEXT_INVALID; /* so try to allocate a new one */ - rc = efx_mcdi_rx_push_rss_context_config(efx, ctx, - ctx->rx_indir_table, - ctx->rx_hash_key); + indir = ethtool_rxfh_context_indir(ctx); + key = ethtool_rxfh_context_key(ctx); + rc = efx_mcdi_rx_push_rss_context_config(efx, priv, indir, key, + false); if (rc) netif_warn(efx, probe, efx->net_dev, "failed to restore RSS context %u, rc=%d" "; RSS filters may fail to be applied\n", - ctx->user_id, rc); + context, rc); } table->must_restore_rss_contexts = false; } @@ -2276,7 +2281,7 @@ int efx_mcdi_vf_rx_push_rss_config(struct efx_nic *efx, bool user, { if (user) return -EOPNOTSUPP; - if (efx->rss_context.context_id != EFX_MCDI_RSS_CONTEXT_INVALID) + if (efx->rss_context.priv.context_id != EFX_MCDI_RSS_CONTEXT_INVALID) return 0; return efx_mcdi_filter_rx_push_shared_rss_config(efx, NULL); } @@ -2295,7 +2300,7 @@ int efx_mcdi_push_default_indir_table(struct efx_nic *efx, efx_mcdi_rx_free_indir_table(efx); if (rss_spread > 1) { - efx_set_default_rx_indir_table(efx, &efx->rss_context); + efx_set_default_rx_indir_table(efx, efx->rss_context.rx_indir_table); rc = efx->type->rx_push_rss_config(efx, false, efx->rss_context.rx_indir_table, NULL); } diff --git a/drivers/net/ethernet/sfc/mcdi_filters.h b/drivers/net/ethernet/sfc/mcdi_filters.h index c0d6558b9fd2..11b9f87ed9e1 100644 --- a/drivers/net/ethernet/sfc/mcdi_filters.h +++ b/drivers/net/ethernet/sfc/mcdi_filters.h @@ -145,9 +145,9 @@ void efx_mcdi_filter_del_vlan(struct efx_nic *efx, u16 vid); void efx_mcdi_rx_free_indir_table(struct efx_nic *efx); int efx_mcdi_rx_push_rss_context_config(struct efx_nic *efx, - struct efx_rss_context *ctx, + struct efx_rss_context_priv *ctx, const u32 *rx_indir_table, - const u8 *key); + const u8 *key, bool delete); int efx_mcdi_pf_rx_push_rss_config(struct efx_nic *efx, bool user, const u32 *rx_indir_table, const u8 *key); @@ -161,10 +161,6 @@ int efx_mcdi_push_default_indir_table(struct efx_nic *efx, int efx_mcdi_rx_pull_rss_config(struct efx_nic *efx); int efx_mcdi_rx_pull_rss_context_config(struct efx_nic *efx, struct efx_rss_context *ctx); -int efx_mcdi_get_rss_context_flags(struct efx_nic *efx, u32 context, - u32 *flags); -void efx_mcdi_set_rss_context_flags(struct efx_nic *efx, - struct efx_rss_context *ctx); void efx_mcdi_rx_restore_rss_contexts(struct efx_nic *efx); static inline void efx_mcdi_update_rx_scatter(struct efx_nic *efx) diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 27d86e90a3bb..d2a54a03f84d 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -737,21 +737,24 @@ struct vfdi_status; /* The reserved RSS context value */ #define EFX_MCDI_RSS_CONTEXT_INVALID 0xffffffff /** - * struct efx_rss_context - A user-defined RSS context for filtering - * @list: node of linked list on which this struct is stored + * struct efx_rss_context_priv - driver private data for an RSS context * @context_id: the RSS_CONTEXT_ID returned by MC firmware, or * %EFX_MCDI_RSS_CONTEXT_INVALID if this context is not present on the NIC. - * For Siena, 0 if RSS is active, else %EFX_MCDI_RSS_CONTEXT_INVALID. - * @user_id: the rss_context ID exposed to userspace over ethtool. * @rx_hash_udp_4tuple: UDP 4-tuple hashing enabled + */ +struct efx_rss_context_priv { + u32 context_id; + bool rx_hash_udp_4tuple; +}; + +/** + * struct efx_rss_context - an RSS context + * @priv: hardware-specific state * @rx_hash_key: Toeplitz hash key for this RSS context * @indir_table: Indirection table for this RSS context */ struct efx_rss_context { - struct list_head list; - u32 context_id; - u32 user_id; - bool rx_hash_udp_4tuple; + struct efx_rss_context_priv priv; u8 rx_hash_key[40]; u32 rx_indir_table[128]; }; @@ -883,9 +886,7 @@ struct efx_mae; * @rx_packet_ts_offset: Offset of timestamp from start of packet data * (valid only if channel->sync_timestamps_enabled; always negative) * @rx_scatter: Scatter mode enabled for receives - * @rss_context: Main RSS context. Its @list member is the head of the list of - * RSS contexts created by user requests - * @rss_lock: Protects custom RSS context software state in @rss_context.list + * @rss_context: Main RSS context. * @vport_id: The function's vport ID, only relevant for PFs * @int_error_count: Number of internal errors seen recently * @int_error_expire: Time at which error count will be expired @@ -1052,7 +1053,6 @@ struct efx_nic { int rx_packet_ts_offset; bool rx_scatter; struct efx_rss_context rss_context; - struct mutex rss_lock; u32 vport_id; unsigned int_error_count; @@ -1416,9 +1416,9 @@ struct efx_nic_type { const u32 *rx_indir_table, const u8 *key); int (*rx_pull_rss_config)(struct efx_nic *efx); int (*rx_push_rss_context_config)(struct efx_nic *efx, - struct efx_rss_context *ctx, + struct efx_rss_context_priv *ctx, const u32 *rx_indir_table, - const u8 *key); + const u8 *key, bool delete); int (*rx_pull_rss_context_config)(struct efx_nic *efx, struct efx_rss_context *ctx); void (*rx_restore_rss_contexts)(struct efx_nic *efx); diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c index d2f35ee15eff..f5632c210ab2 100644 --- a/drivers/net/ethernet/sfc/rx_common.c +++ b/drivers/net/ethernet/sfc/rx_common.c @@ -556,69 +556,25 @@ efx_rx_packet_gro(struct efx_channel *channel, struct efx_rx_buffer *rx_buf, napi_gro_frags(napi); } -/* RSS contexts. We're using linked lists and crappy O(n) algorithms, because - * (a) this is an infrequent control-plane operation and (b) n is small (max 64) - */ -struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx) +struct efx_rss_context_priv *efx_find_rss_context_entry(struct efx_nic *efx, + u32 id) { - struct list_head *head = &efx->rss_context.list; - struct efx_rss_context *ctx, *new; - u32 id = 1; /* Don't use zero, that refers to the master RSS context */ - - WARN_ON(!mutex_is_locked(&efx->rss_lock)); + struct ethtool_rxfh_context *ctx; - /* Search for first gap in the numbering */ - list_for_each_entry(ctx, head, list) { - if (ctx->user_id != id) - break; - id++; - /* Check for wrap. If this happens, we have nearly 2^32 - * allocated RSS contexts, which seems unlikely. - */ - if (WARN_ON_ONCE(!id)) - return NULL; - } + WARN_ON(!mutex_is_locked(&efx->net_dev->ethtool->rss_lock)); - /* Create the new entry */ - new = kmalloc(sizeof(*new), GFP_KERNEL); - if (!new) + ctx = idr_find(&efx->net_dev->ethtool->rss_ctx, id); + if (!ctx) return NULL; - new->context_id = EFX_MCDI_RSS_CONTEXT_INVALID; - new->rx_hash_udp_4tuple = false; - - /* Insert the new entry into the gap */ - new->user_id = id; - list_add_tail(&new->list, &ctx->list); - return new; -} - -struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id) -{ - struct list_head *head = &efx->rss_context.list; - struct efx_rss_context *ctx; - - WARN_ON(!mutex_is_locked(&efx->rss_lock)); - - list_for_each_entry(ctx, head, list) - if (ctx->user_id == id) - return ctx; - return NULL; -} - -void efx_free_rss_context_entry(struct efx_rss_context *ctx) -{ - list_del(&ctx->list); - kfree(ctx); + return ethtool_rxfh_context_priv(ctx); } -void efx_set_default_rx_indir_table(struct efx_nic *efx, - struct efx_rss_context *ctx) +void efx_set_default_rx_indir_table(struct efx_nic *efx, u32 *indir) { size_t i; - for (i = 0; i < ARRAY_SIZE(ctx->rx_indir_table); i++) - ctx->rx_indir_table[i] = - ethtool_rxfh_indir_default(i, efx->rss_spread); + for (i = 0; i < ARRAY_SIZE(efx->rss_context.rx_indir_table); i++) + indir[i] = ethtool_rxfh_indir_default(i, efx->rss_spread); } /** diff --git a/drivers/net/ethernet/sfc/rx_common.h b/drivers/net/ethernet/sfc/rx_common.h index fbd2769307f9..75fa84192362 100644 --- a/drivers/net/ethernet/sfc/rx_common.h +++ b/drivers/net/ethernet/sfc/rx_common.h @@ -84,11 +84,9 @@ void efx_rx_packet_gro(struct efx_channel *channel, struct efx_rx_buffer *rx_buf, unsigned int n_frags, u8 *eh, __wsum csum); -struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx); -struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id); -void efx_free_rss_context_entry(struct efx_rss_context *ctx); -void efx_set_default_rx_indir_table(struct efx_nic *efx, - struct efx_rss_context *ctx); +struct efx_rss_context_priv *efx_find_rss_context_entry(struct efx_nic *efx, + u32 id); +void efx_set_default_rx_indir_table(struct efx_nic *efx, u32 *indir); bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec); bool efx_filter_spec_equal(const struct efx_filter_spec *left,