From patchwork Tue Feb 21 02:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E97DC636D6 for ; Tue, 21 Feb 2023 02:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233125AbjBUCkl (ORCPT ); Mon, 20 Feb 2023 21:40:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233134AbjBUCk3 (ORCPT ); Mon, 20 Feb 2023 21:40:29 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D3A323671; Mon, 20 Feb 2023 18:40:12 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 9232F3F2FE; Tue, 21 Feb 2023 02:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947210; bh=ezbPlxDXhaV/sDJAItoixMIy3dMW2xrI6AAH/J1Y45I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ETctbcQNZLeQqgunhUqAiRSQAKR3iGoZpdxkpmEZjAHKoOakaT7ya1hEzA2o0NASo dYyNakLLya0F3VYLRyHMoJeuijhEdN1oxOlgwP3WZcRYU2lMK7M6pt6sAMoVvh6B+k uGbVNCPJ0LW9DwUtNFSszrq4/x23ZbY6QP+rD9Ri8nVGLrOuYj+dxnc/ubk3Yfi0av ACphm8gvbwhrEt6Xpc7VdLj6u8SLkKrO2a1Wv5s0YejhzmLg5C1WuaueFPtpoHnMk2 SpVszJOfpjtbMDukuMMcUiAloOXTmS2RM3RnqIVuEWnlUPjdCzhtNTb+LIA6imIxwW t5L8kQJCAztVQ== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 5/6] r8169: Use mutex to guard config register locking Date: Tue, 21 Feb 2023 10:38:48 +0800 Message-Id: <20230221023849.1906728-6-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Right now r8169 doesn't have parallel access to its config register, but the next patch makes the driver access config register at anytime. So add a mutex to protect the config register from any potential race. Signed-off-by: Kai-Heng Feng --- v8: - Swap the place when using the mutex. Protect when config register is unlocked. v7: - This is a new patch. drivers/net/ethernet/realtek/r8169_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index e40498dd08d17..897f90b48bba6 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -613,6 +613,8 @@ struct rtl8169_private { struct work_struct work; } wk; + struct mutex config_lock; + unsigned supports_gmii:1; unsigned aspm_manageable:1; dma_addr_t counters_phys_addr; @@ -662,10 +664,12 @@ static inline struct device *tp_to_dev(struct rtl8169_private *tp) static void rtl_lock_config_regs(struct rtl8169_private *tp) { RTL_W8(tp, Cfg9346, Cfg9346_Lock); + mutex_unlock(&tp->config_lock); } static void rtl_unlock_config_regs(struct rtl8169_private *tp) { + mutex_lock(&tp->config_lock); RTL_W8(tp, Cfg9346, Cfg9346_Unlock); } @@ -5217,6 +5221,8 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) return rc; } + mutex_init(&tp->config_lock); + tp->mmio_addr = pcim_iomap_table(pdev)[region]; xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf;