From patchwork Fri Dec 15 13:15:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 179272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9264885dys; Fri, 15 Dec 2023 05:16:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvA3E9QNlnWKb11YFjm2a+evnOwtY+pTND9cEQc4WBaosbElhj9MdeevkVIohXwp/dhZ10 X-Received: by 2002:a17:90a:d70d:b0:28a:f9d2:e58e with SMTP id y13-20020a17090ad70d00b0028af9d2e58emr2084950pju.33.1702646191850; Fri, 15 Dec 2023 05:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702646191; cv=none; d=google.com; s=arc-20160816; b=ky5JavqwQbX+t2LdUiiq/pz7/KiM2xOVM8ZKtH6i0+enF0I184XQh7wL1aV0BI4+i2 rn/oom8ZkmnCC7JFDmX9TjS2vCG2JzGrd90HRcbha4LtUfuabDf3DD99uO+4RFqugtTV QSwUcLmrmnmgeZxP8OcyDgbh+9Yz68rACs3sXmSo6zy69zSq8tcVxI28wKpY0koDIhjw EqGwPLf0FFPyxuh1L5odX9OM2E7i5I7IcDLaZSPqUkw3hd/5KFb6z8AuSTgLdTdC32jt 22Og4wk2xLqKqGYyWS3MOl42rQnqgpXFYhsosxdGkC5VMDZLts0R2zPdTpci5LReJWvg A+ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iioDY7je2sF6fbSitgQ396/5pChLBrfWf7mOLks6Yho=; fh=SMtxaQKMvEI7BG6lkR8YRVPMKkLsNzxoa7wuhYbp9hc=; b=ZdprLd8Kskrx3/SE2VMw0tjsyrtxeVvheqNzKFaA9q3j4XII1VUgBFPOAVMz4pyaez tA7HgDMBpmPtQEHYVfB8c3290uMoPEbrT//z7grB1v3E8MahGqcL+X5sqWQc+wXMRig5 ZLPj3emasrlRWb/D6AIOR53aniNTbhSp5rz3yJRTY5YNj4JAT7vKS4jq0XIewTK3uqkX bGeer5Fh9i0Gyj0QbKzgLqIGd0r0OGpchN9nQWyoxO2j27fwIGUEVrYB+Qjn//X+kLb7 hb2i3FqRKo+zfKU5gEImP6RWrBWYth8iOZCfAN1q5wwdnjaha6oVFdkB78eQ7476xdtc 2vnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZCyTOKhE; spf=pass (google.com: domain of linux-kernel+bounces-986-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-986-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kb4-20020a17090ae7c400b002871b0b4a11si13280109pjb.61.2023.12.15.05.16.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:16:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-986-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZCyTOKhE; spf=pass (google.com: domain of linux-kernel+bounces-986-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-986-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9AA2B286310 for ; Fri, 15 Dec 2023 13:16:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 339332E414; Fri, 15 Dec 2023 13:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZCyTOKhE" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAA61347BB; Fri, 15 Dec 2023 13:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40c580ba223so7859215e9.3; Fri, 15 Dec 2023 05:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702646141; x=1703250941; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iioDY7je2sF6fbSitgQ396/5pChLBrfWf7mOLks6Yho=; b=ZCyTOKhE0KwYiedZI6dbSYo52ZaISBE9ABpD706skGS+98cM6Ah2e7bcr6ARiVas8O 2adUzumroQhPSd0ZzWVrrU7t7YpdQSHtM38FIbExs05auT85O+gMbTEAzYr1/7j59UBo hP+2OZWTNJBv4fFGK3ZRMVAzyDfvvtPpQ59JzQiwKd7whOTzQPCXMfcMKJNABXiVF0U2 wNn4gwgYzmPvKAtZ0P6UK+THflAqljMe6m7nUFyIXaCE4vY8+FRV699YHhv6pKLLDSck S1yb0TAdvq9VfrOrnvI8aIZ0dkyEvJF1ywJDXrNtwVGf5uKeg/ENXORI/PK6dszDTnHh AdEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702646141; x=1703250941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iioDY7je2sF6fbSitgQ396/5pChLBrfWf7mOLks6Yho=; b=dtyjqpHWWhl7z/N0q/1jEydqFV2r2qPblOUOdajIoZ/a72IVkzXu8+4Z/oKh/EyqQt 3SfpO1Yp/8D5ZYyLn7cSsWvhXIFXrca2C0yx7465ShjGKioL1THe8JqLjqBSRksCEOO7 5aUOzM+vaiJnq1j8Wx74dLOqRSUpA1fvLuMxrz7DV7tYJhtzCyzS/i9I3PemtTfjlSZx mbTCVUOl6KcDAbFinVVAb8SZ9fvBbJL/Z58LqkjlzJQOXJGeTzy66wlAHuq18aTYKljo 4yEjr492llCTwl+9C4UZP2tkjHowMWx8R6WKq32jyCb1VRmIgRxhzOjkOmKqyQ+oWjUu DrdQ== X-Gm-Message-State: AOJu0YzoRjG/Jxy61OmoSPuf495rHL8imWNo9Q1pPoxF7VIhjNCuVCyD nlid8QxXSN/cwjFpxOiMf2g= X-Received: by 2002:a05:600c:221a:b0:40c:313a:f7c0 with SMTP id z26-20020a05600c221a00b0040c313af7c0mr6920223wml.7.1702646141057; Fri, 15 Dec 2023 05:15:41 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm21618324wmb.46.2023.12.15.05.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:15:40 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Epping , Vladimir Oltean , Christian Marangi , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Russell King Subject: [net-next PATCH v8 1/4] net: phy: make addr type u8 in phy_package_shared struct Date: Fri, 15 Dec 2023 14:15:31 +0100 Message-Id: <20231215131534.7188-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215131534.7188-1-ansuelsmth@gmail.com> References: <20231215131534.7188-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785353933189425643 X-GMAIL-MSGID: 1785353933189425643 Switch addr type in phy_package_shared struct to u8. The value is already checked to be non negative and to be less than PHY_MAX_ADDR, hence u8 is better suited than using int. Signed-off-by: Christian Marangi Reviewed-by: Russell King (Oracle) --- Changes v8: - Add Reviewed-by tag Changes v7: - Add this patch include/linux/phy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/phy.h b/include/linux/phy.h index e5f1f41e399c..e5e29fca4d17 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -338,7 +338,7 @@ struct mdio_bus_stats { * phy_package_leave(). */ struct phy_package_shared { - int addr; + u8 addr; refcount_t refcnt; unsigned long flags; size_t priv_size; From patchwork Fri Dec 15 13:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 179273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9265252dys; Fri, 15 Dec 2023 05:16:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+M7DYHUbNcJaRrF7SdBg1NY9cDbzLUYjJeR52I/tN6eZCjTbE+0kUPB3T039OqEYV74WW X-Received: by 2002:a2e:3513:0:b0:2cc:42ec:c065 with SMTP id z19-20020a2e3513000000b002cc42ecc065mr639681ljz.35.1702646219697; Fri, 15 Dec 2023 05:16:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702646219; cv=none; d=google.com; s=arc-20160816; b=daQrZWRFSzIsGkRIe90rfZVDF/BpS9YAW6NtL9YiLNxVilhw7Mj33hhLspQ17lrNiD s7va41cOU7DL7YSKrHhNVPnAdbXeiQ6TZ2HLJuSJazcTalFOTPbwmB6ofOwBtuUujMq3 wui05rtblCFkLpULbW8ZzgLYModsfCDck79zG98Cpsh4SB5PB+wni0CZrYTwgh5gdwRA ggpwbaP4shw6nNEebXoKBj9zc6ofqMqQPlm/psh4OKC6gcNo+RxWWLDb9hn4/gWJe/gU wbnhY6GYVaRKtT3WHznpqCmnUDge8oC5NxQPFYA2zQX5J8vcz2IeqnMzTpArVXJAFium L/Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=ml/FXyClSKp0yaU6QlaX2fxcMnEFxjSa/9Ko/pcKH7A=; fh=GTnkJNBIlVeBhBTe96ueQBNZ37qmUNj+HvaZTT9Obso=; b=ajsCqZNmYfkLDY7V7cmvDzGc3K/1YDyE/4iRcOcMqfDPf3yg+6KVSoZs8NLVmFVYh9 /PSYqMAOTaqTsKc52zYysQNrPCR89ksRhwc1IPLc8JUs6Z101Tz1EA8+Xu3lVNaGFdSD 3XDW4uxPHTIfBIGLSJiipC7zSei+kcWfzcc4u4tK6FfosT2MiykcVoCbVNsLrw5fzSw/ ZD+INtPAnsjJscECthH2jHSTTPXYPUg1cvSWxki0cleuCulpDpa3jcjyX734FzPLawH5 Sg3o4ezol29i70Bs+OIf4z5KU8/M4mhJZxOZcadEcLwf3WLaBFNBBHFJA69OmGaXbnKw 9j2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="AC/IctxJ"; spf=pass (google.com: domain of linux-kernel+bounces-987-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-987-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dg19-20020a0564021d1300b005528a17a05esi1034964edb.207.2023.12.15.05.16.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:16:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-987-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="AC/IctxJ"; spf=pass (google.com: domain of linux-kernel+bounces-987-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-987-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 247671F24A65 for ; Fri, 15 Dec 2023 13:16:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BD793034E; Fri, 15 Dec 2023 13:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AC/IctxJ" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 655282DB65; Fri, 15 Dec 2023 13:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-40c6e2a47f6so1586305e9.0; Fri, 15 Dec 2023 05:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702646142; x=1703250942; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ml/FXyClSKp0yaU6QlaX2fxcMnEFxjSa/9Ko/pcKH7A=; b=AC/IctxJI0qn3qa+V9uWZUt88m3YuQVQEBUKhLVYMr3xC1d5tYZDhxWb5YF+0n+AnF lRGhxxPeWyH0n9OlNEQ88Ln6qhOscJkk+jHDuXon+imrLkKLdTKmzkzpQwffp2JJ0UJV th7jPcnFedzk3R0LtgjCuvVMpcT0EdhbtKwKTqkEIINDbUb9nB2kTefRaIcC6tCRaNYZ A426olfYXwtze21lrMYxreK7Up7fM3YNFGMy1T1Ew8/vaOio2S7OCi1bfYwUcBA0pvHa RFLVXcig4hT6fIqv+2cp73X0yJ8tfX77PgPVJWtBcZFtmfuRZCTqumxEdzs3tR/DY+ti VBiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702646142; x=1703250942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ml/FXyClSKp0yaU6QlaX2fxcMnEFxjSa/9Ko/pcKH7A=; b=wnNncU/sqfS8T8HhyAnAesp5ulNlaDzbb1DU165hlKmRAGbDbxbnxfM9GGxdjDe/wx H2JB6vGLST+dt8T9wAIiRBZblnYAjbWlENe3rxHGT70hnrn5vj+ZG7a2qMdmbIy1Va3B S5rLo8OITkBDJsTWKnqzN0qfKl9E76Bzj6cspMfiUPDqstQvaJ/fvX8tUv9reJqUtVaZ tMdeHNYT+/lJAqm8+iM/gD2WX/sgYBI/ePg3xKyg7Pevq0e+gRlacRk+8xdA3UpvHMc0 WfxCnQJ+ARKR4k/xJ2g8glkILm5L7jGQ22NPA05GfDpscLOzekuNyGADmnw+qZosUQMn 4sFg== X-Gm-Message-State: AOJu0YyfrUk1ONVs+gVQmKLN8dOxp92QqAKE0LBLQ5gqnItJS/fQKUkE zTsFje88/9Psqf6wGkXrM/9sZdGoPS0= X-Received: by 2002:a05:600c:2948:b0:40c:333a:8ad with SMTP id n8-20020a05600c294800b0040c333a08admr2900724wmd.149.1702646142267; Fri, 15 Dec 2023 05:15:42 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm21618324wmb.46.2023.12.15.05.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:15:41 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Epping , Vladimir Oltean , Christian Marangi , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v8 2/4] net: phy: extend PHY package API to support multiple global address Date: Fri, 15 Dec 2023 14:15:32 +0100 Message-Id: <20231215131534.7188-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215131534.7188-1-ansuelsmth@gmail.com> References: <20231215131534.7188-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785353962181602695 X-GMAIL-MSGID: 1785353962181602695 Current API for PHY package are limited to single address to configure global settings for the PHY package. It was found that some PHY package (for example the qca807x, a PHY package that is shipped with a bundle of 5 PHY) requires multiple PHY address to configure global settings. An example scenario is a PHY that have a dedicated PHY for PSGMII/serdes calibrarion and have a specific PHY in the package where the global PHY mode is set and affects every other PHY in the package. Change the API in the following way: - Change phy_package_join() to take the base addr of the PHY package instead of the global PHY addr. - Make __/phy_package_write/read() require an additional arg that select what global PHY address to use by passing the offset from the base addr passed on phy_package_join(). Each user of this API is updated to follow this new implementation following a pattern where an enum is defined to declare the offset of the addr. We also drop the check if shared is defined as any user of the phy_package_read/write is expected to use phy_package_join first. Misuse of this will correctly trigger a kernel panic for NULL pointer exception. Signed-off-by: Christian Marangi --- Changes v8: - Introduce helper to validate final addr Changes v7: - Change addr to u8 Changes v2: - Make kernel panic if shared is not init (bugged scenario) - Fix some confusing comments drivers/net/phy/bcm54140.c | 16 ++++++-- drivers/net/phy/mscc/mscc.h | 5 +++ drivers/net/phy/mscc/mscc_main.c | 4 +- drivers/net/phy/phy_device.c | 35 +++++++++-------- include/linux/phy.h | 64 +++++++++++++++++++++----------- 5 files changed, 80 insertions(+), 44 deletions(-) diff --git a/drivers/net/phy/bcm54140.c b/drivers/net/phy/bcm54140.c index d43076592f81..2eea3d09b1e6 100644 --- a/drivers/net/phy/bcm54140.c +++ b/drivers/net/phy/bcm54140.c @@ -128,6 +128,10 @@ #define BCM54140_DEFAULT_DOWNSHIFT 5 #define BCM54140_MAX_DOWNSHIFT 9 +enum bcm54140_global_phy { + BCM54140_BASE_ADDR = 0, +}; + struct bcm54140_priv { int port; int base_addr; @@ -429,11 +433,13 @@ static int bcm54140_base_read_rdb(struct phy_device *phydev, u16 rdb) int ret; phy_lock_mdio_bus(phydev); - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_ADDR, rdb); if (ret < 0) goto out; - ret = __phy_package_read(phydev, MII_BCM54XX_RDB_DATA); + ret = __phy_package_read(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_DATA); out: phy_unlock_mdio_bus(phydev); @@ -446,11 +452,13 @@ static int bcm54140_base_write_rdb(struct phy_device *phydev, int ret; phy_lock_mdio_bus(phydev); - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_ADDR, rdb); if (ret < 0) goto out; - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_DATA, val); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_DATA, val); out: phy_unlock_mdio_bus(phydev); diff --git a/drivers/net/phy/mscc/mscc.h b/drivers/net/phy/mscc/mscc.h index 7a962050a4d4..6a3d8a754eb8 100644 --- a/drivers/net/phy/mscc/mscc.h +++ b/drivers/net/phy/mscc/mscc.h @@ -416,6 +416,11 @@ struct vsc8531_private { * gpio_lock: used for PHC operations. Common for all PHYs as the load/save GPIO * is shared. */ + +enum vsc85xx_global_phy { + VSC88XX_BASE_ADDR = 0, +}; + struct vsc85xx_shared_private { struct mutex gpio_lock; }; diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c index 4171f01d34e5..6f74ce0ab1aa 100644 --- a/drivers/net/phy/mscc/mscc_main.c +++ b/drivers/net/phy/mscc/mscc_main.c @@ -711,7 +711,7 @@ int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val) dump_stack(); } - return __phy_package_write(phydev, regnum, val); + return __phy_package_write(phydev, VSC88XX_BASE_ADDR, regnum, val); } /* phydev->bus->mdio_lock should be locked when using this function */ @@ -722,7 +722,7 @@ int phy_base_read(struct phy_device *phydev, u32 regnum) dump_stack(); } - return __phy_package_read(phydev, regnum); + return __phy_package_read(phydev, VSC88XX_BASE_ADDR, regnum); } u32 vsc85xx_csr_read(struct phy_device *phydev, diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 478126f6b5bc..424cbb13de13 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1648,20 +1648,22 @@ EXPORT_SYMBOL_GPL(phy_driver_is_genphy_10g); /** * phy_package_join - join a common PHY group * @phydev: target phy_device struct - * @addr: cookie and PHY address for global register access + * @base_addr: cookie and base PHY address of PHY package for offset + * calculation of global register access * @priv_size: if non-zero allocate this amount of bytes for private data * * This joins a PHY group and provides a shared storage for all phydevs in * this group. This is intended to be used for packages which contain * more than one PHY, for example a quad PHY transceiver. * - * The addr parameter serves as a cookie which has to have the same value - * for all members of one group and as a PHY address to access generic - * registers of a PHY package. Usually, one of the PHY addresses of the - * different PHYs in the package provides access to these global registers. + * The base_addr parameter serves as cookie which has to have the same values + * for all members of one group and as the base PHY address of the PHY package + * for offset calculation to access generic registers of a PHY package. + * Usually, one of the PHY addresses of the different PHYs in the package + * provides access to these global registers. * The address which is given here, will be used in the phy_package_read() - * and phy_package_write() convenience functions. If your PHY doesn't have - * global registers you can just pick any of the PHY addresses. + * and phy_package_write() convenience functions as base and added to the + * passed offset in those functions. * * This will set the shared pointer of the phydev to the shared storage. * If this is the first call for a this cookie the shared storage will be @@ -1671,17 +1673,17 @@ EXPORT_SYMBOL_GPL(phy_driver_is_genphy_10g); * Returns < 1 on error, 0 on success. Esp. calling phy_package_join() * with the same cookie but a different priv_size is an error. */ -int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size) +int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size) { struct mii_bus *bus = phydev->mdio.bus; struct phy_package_shared *shared; int ret; - if (addr < 0 || addr >= PHY_MAX_ADDR) + if (base_addr < 0 || base_addr >= PHY_MAX_ADDR) return -EINVAL; mutex_lock(&bus->shared_lock); - shared = bus->shared[addr]; + shared = bus->shared[base_addr]; if (!shared) { ret = -ENOMEM; shared = kzalloc(sizeof(*shared), GFP_KERNEL); @@ -1693,9 +1695,9 @@ int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size) goto err_free; shared->priv_size = priv_size; } - shared->addr = addr; + shared->base_addr = base_addr; refcount_set(&shared->refcnt, 1); - bus->shared[addr] = shared; + bus->shared[base_addr] = shared; } else { ret = -EINVAL; if (priv_size && priv_size != shared->priv_size) @@ -1733,7 +1735,7 @@ void phy_package_leave(struct phy_device *phydev) return; if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { - bus->shared[shared->addr] = NULL; + bus->shared[shared->base_addr] = NULL; mutex_unlock(&bus->shared_lock); kfree(shared->priv); kfree(shared); @@ -1752,7 +1754,8 @@ static void devm_phy_package_leave(struct device *dev, void *res) * devm_phy_package_join - resource managed phy_package_join() * @dev: device that is registering this PHY package * @phydev: target phy_device struct - * @addr: cookie and PHY address for global register access + * @base_addr: cookie and base PHY address of PHY package for offset + * calculation of global register access * @priv_size: if non-zero allocate this amount of bytes for private data * * Managed phy_package_join(). Shared storage fetched by this function, @@ -1760,7 +1763,7 @@ static void devm_phy_package_leave(struct device *dev, void *res) * phy_package_join() for more information. */ int devm_phy_package_join(struct device *dev, struct phy_device *phydev, - int addr, size_t priv_size) + int base_addr, size_t priv_size) { struct phy_device **ptr; int ret; @@ -1770,7 +1773,7 @@ int devm_phy_package_join(struct device *dev, struct phy_device *phydev, if (!ptr) return -ENOMEM; - ret = phy_package_join(phydev, addr, priv_size); + ret = phy_package_join(phydev, base_addr, priv_size); if (!ret) { *ptr = phydev; diff --git a/include/linux/phy.h b/include/linux/phy.h index e5e29fca4d17..85fdba43b813 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -327,7 +327,8 @@ struct mdio_bus_stats { /** * struct phy_package_shared - Shared information in PHY packages - * @addr: Common PHY address used to combine PHYs in one package + * @base_addr: Base PHY address of PHY package used to combine PHYs + * in one package and for offset calculation of phy_package_read/write * @refcnt: Number of PHYs connected to this shared data * @flags: Initialization of PHY package * @priv_size: Size of the shared private data @priv @@ -338,7 +339,7 @@ struct mdio_bus_stats { * phy_package_leave(). */ struct phy_package_shared { - u8 addr; + u8 base_addr; refcount_t refcnt; unsigned long flags; size_t priv_size; @@ -1972,10 +1973,10 @@ int phy_ethtool_get_link_ksettings(struct net_device *ndev, int phy_ethtool_set_link_ksettings(struct net_device *ndev, const struct ethtool_link_ksettings *cmd); int phy_ethtool_nway_reset(struct net_device *ndev); -int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size); +int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size); void phy_package_leave(struct phy_device *phydev); int devm_phy_package_join(struct device *dev, struct phy_device *phydev, - int addr, size_t priv_size); + int base_addr, size_t priv_size); int __init mdio_bus_init(void); void mdio_bus_exit(void); @@ -1998,46 +1999,65 @@ int __phy_hwtstamp_set(struct phy_device *phydev, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack); -static inline int phy_package_read(struct phy_device *phydev, u32 regnum) +static inline int phy_package_address(struct phy_device *phydev, + unsigned int addr_offset) { struct phy_package_shared *shared = phydev->shared; + u8 base_addr = shared->base_addr; - if (!shared) + if (addr_offset >= PHY_MAX_ADDR - base_addr) return -EIO; - return mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + /* we know that addr will be in the range 0..31 and thus the + * implicit cast to a signed int is not a problem. + */ + return base_addr + addr_offset; } -static inline int __phy_package_read(struct phy_device *phydev, u32 regnum) +static inline int phy_package_read(struct phy_device *phydev, + unsigned int addr_offset, u32 regnum) { - struct phy_package_shared *shared = phydev->shared; + int addr = phy_package_address(phydev, addr_offset); - if (!shared) - return -EIO; + if (addr < 0) + return addr; + + return mdiobus_read(phydev->mdio.bus, addr, regnum); +} + +static inline int __phy_package_read(struct phy_device *phydev, + unsigned int addr_offset, u32 regnum) +{ + int addr = phy_package_address(phydev, addr_offset); + + if (addr < 0) + return addr; - return __mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + return __mdiobus_read(phydev->mdio.bus, addr, regnum); } static inline int phy_package_write(struct phy_device *phydev, - u32 regnum, u16 val) + unsigned int addr_offset, u32 regnum, + u16 val) { - struct phy_package_shared *shared = phydev->shared; + int addr = phy_package_address(phydev, addr_offset); - if (!shared) - return -EIO; + if (addr < 0) + return addr; - return mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + return mdiobus_write(phydev->mdio.bus, addr, regnum, val); } static inline int __phy_package_write(struct phy_device *phydev, - u32 regnum, u16 val) + unsigned int addr_offset, u32 regnum, + u16 val) { - struct phy_package_shared *shared = phydev->shared; + int addr = phy_package_address(phydev, addr_offset); - if (!shared) - return -EIO; + if (addr < 0) + return addr; - return __mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } static inline bool __phy_package_set_once(struct phy_device *phydev, From patchwork Fri Dec 15 13:15:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 179274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9265464dys; Fri, 15 Dec 2023 05:17:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IELzHoeOBwniA9+xumA06DrKlQkCwdmjXIIB/lTjEEDMtd25e3r7fyafJ0TJmwFBZjbDqqB X-Received: by 2002:a17:902:e806:b0:1d3:3e61:eeca with SMTP id u6-20020a170902e80600b001d33e61eecamr3631010plg.82.1702646232970; Fri, 15 Dec 2023 05:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702646232; cv=none; d=google.com; s=arc-20160816; b=lp+nbjAnY/kEYgVl0kxJpxwpeCQEsm0ZeLznzNgY3n7VT7oh5yr9/YgTP3HhA0JkK/ Kdn8biWwSECAM5el0pvLyeugXL3EIrJW7MbKQtqWPmrGJ0RdzTrXmbY5f3Tgl6gnlSQl CF4PhMK0AxEKzx0vhSK7Sec8aWWHdeeb+kCBvCcJfUYbaVpebKbQp8qjNt+bF7akKfH1 HpQTtrpshDOXMpxsjUNwne9IPipko6SAKavku5h8XLp+wzLbMopqe2M5uaw2qdQSJB/F 8sQVTiJAyq0rYZy8FKJu8kfWtSA65+dGqiz9bTSbo/q9VOmE25uaw6aP6cNYjDW0vPwB 4Rvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vZZO03R1yzWivtorMM7YimtX2jOHr2R8ovLMDu2TRDw=; fh=SMtxaQKMvEI7BG6lkR8YRVPMKkLsNzxoa7wuhYbp9hc=; b=FPBF/RdAZ7Qgc5LaPfUKzAu2X2+R9xXKqoEUtAlSspFy+uwvCGHMiAQZLQXGZCmgTn oZDvf3LaiixwgZYAr6xroYgvLWlSry2knfDIFS9/4Fob4u8+KQe5KltxtBnLivrYFoQP LjFB8MpQMlXjH4UnkZeANYPWEim/9P+oe5yr4cTCzygmWzK2cwvxDpYxEZCo4BWTIqvR fCIH0j10ml0hcZQNDIKHmqbi6w2RcrewUT9sOIi/MZMybMLFCQSUTCkG/XrTQPyb+aYr zdgv6IGvLA23G5uD+f4AqlXD76zo4uFJWfYNVcXPojsEggi/xGoS30BRhKt3HTmabpBt ZdQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AcEjVaXE; spf=pass (google.com: domain of linux-kernel+bounces-988-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-988-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w13-20020a170902a70d00b001cfb4bd0b83si12960089plq.439.2023.12.15.05.17.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:17:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-988-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AcEjVaXE; spf=pass (google.com: domain of linux-kernel+bounces-988-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-988-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AC5C02864DF for ; Fri, 15 Dec 2023 13:17:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A75F30653; Fri, 15 Dec 2023 13:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AcEjVaXE" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0649E2DB9A; Fri, 15 Dec 2023 13:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3333074512bso1004931f8f.1; Fri, 15 Dec 2023 05:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702646144; x=1703250944; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vZZO03R1yzWivtorMM7YimtX2jOHr2R8ovLMDu2TRDw=; b=AcEjVaXEv5/SnCI96KCk4v11KGxh64AJLcsTVxF2k7Ys+Wm/cyBOw65UepsJr2YkNQ VHWXbrMwXgNQoi9dxCCNBb10Khe6pFEaD0rwF3PBWqGoAHluJiwAq4WpNMLV4RolRT0I Ku0GZ7i5SwrakkmaZpGBEk1+uFFAoHYmvtrJOZmxeK6ZDTSZlF1WmCqMMi+njNN4gKl0 mYlDqnAjrna8CXRK8CcCoBaeituqbCgHf8WP8fxSqFBQAOgQL0ZE2u7Wn5T5zRizXUcJ bx0QVvNPvBv2urVuNucRIXXE4BsfiGbLzvdVwLwqMgRGM6Zw2/rY8wq7qubxzCHHkymu gCaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702646144; x=1703250944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vZZO03R1yzWivtorMM7YimtX2jOHr2R8ovLMDu2TRDw=; b=IyHY4rBIIV3V2SCN47cUK62G3LqIlE7px2/6TWsZ25KlCasAL3PZ0I+OJKwQi9jRAm JGlvSfywIGcWJh6MLaSTzGEXWVffdiQfe20FEHRL2U7V2+x1jQRKJmn5D9q9lFvNUd58 AjUXAQTMkZ0Qy9bEHfUg4EqGX5/Y6ZfQiq7/CSBmAfBR+bYTflaZKV6rXURxfyhzHCyT Wd82f4IfhhLBeK6tyKvka3H5tGgSaso31nMPYaESBrw6CK+iwSbsXriAPJFZWD9RGgHh lvojbnWvE4+LpYQRRPYMWteqDE94K08rPlsODo1SlQWwC7eVA5WHEOv6l217hnKBvw4z PEuw== X-Gm-Message-State: AOJu0Yy6p4vOX2VjLJwTdQkZrIY4UYX0itJgPw2mmjdCm3/oET0PJV9X O7t68wQ2nrCAAN05l1Czc/o= X-Received: by 2002:a05:600c:4d0d:b0:40b:5e26:2376 with SMTP id u13-20020a05600c4d0d00b0040b5e262376mr5512604wmp.39.1702646144118; Fri, 15 Dec 2023 05:15:44 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm21618324wmb.46.2023.12.15.05.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:15:43 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Epping , Vladimir Oltean , Christian Marangi , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Russell King Subject: [net-next PATCH v8 3/4] net: phy: restructure __phy_write/read_mmd to helper and phydev user Date: Fri, 15 Dec 2023 14:15:33 +0100 Message-Id: <20231215131534.7188-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215131534.7188-1-ansuelsmth@gmail.com> References: <20231215131534.7188-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785353976419479733 X-GMAIL-MSGID: 1785353976419479733 Restructure phy_write_mmd and phy_read_mmd to implement generic helper for direct mdiobus access for mmd and use these helper for phydev user. This is needed in preparation of PHY package API that requires generic access to the mdiobus and are deatched from phydev struct but instead access them based on PHY package base_addr and offsets. Signed-off-by: Christian Marangi Reviewed-by: Russell King (Oracle) --- Changes v6: - Add Reviewed-by tag Changes v3: - Move to phy-core.c instead of inline in phy.h Changes v2: - Introduce this patch drivers/net/phy/phy-core.c | 64 ++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 966c93cbe616..b729ac8b2640 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -540,6 +540,28 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, devad | MII_MMD_CTRL_NOINCR); } +static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum) +{ + if (is_c45) + return __mdiobus_c45_read(bus, phy_addr, devad, regnum); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Read the content of the MMD's selected register */ + return __mdiobus_read(bus, phy_addr, MII_MMD_DATA); +} + +static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum, u16 val) +{ + if (is_c45) + return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Write the data into MMD's selected register */ + return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); +} + /** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. @@ -551,26 +573,14 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, */ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) { - int val; - if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->read_mmd) { - val = phydev->drv->read_mmd(phydev, devad, regnum); - } else if (phydev->is_c45) { - val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; + if (phydev->drv && phydev->drv->read_mmd) + return phydev->drv->read_mmd(phydev, devad, regnum); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Read the content of the MMD's selected register */ - val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); - } - return val; + return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum); } EXPORT_SYMBOL(__phy_read_mmd); @@ -607,28 +617,14 @@ EXPORT_SYMBOL(phy_read_mmd); */ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) { - int ret; - if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->write_mmd) { - ret = phydev->drv->write_mmd(phydev, devad, regnum, val); - } else if (phydev->is_c45) { - ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum, val); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; + if (phydev->drv && phydev->drv->write_mmd) + return phydev->drv->write_mmd(phydev, devad, regnum, val); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Write the data into MMD's selected register */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); - - ret = 0; - } - return ret; + return mmd_phy_write(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum, val); } EXPORT_SYMBOL(__phy_write_mmd); From patchwork Fri Dec 15 13:15:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 179275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9265627dys; Fri, 15 Dec 2023 05:17:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm8A+9sM6vsTKbrrLJyPe7dXfcizGIWDjUknbcQ6XeozSulgjfeiN8dcBOxkIOZipIdwnn X-Received: by 2002:a05:6808:1294:b0:3b9:e48f:d64f with SMTP id a20-20020a056808129400b003b9e48fd64fmr15007286oiw.71.1702646247373; Fri, 15 Dec 2023 05:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702646247; cv=none; d=google.com; s=arc-20160816; b=P+r2Kasbf1rIXrTDgz7ZYH+LaNRGTw5SOrWhZqjzf/qJj2O4etQxgfMqWx4v02KlPC CCnoNPPwW9ZW6O9CHrO29HurAQSyAnuJMaI325rKdfOBIX5CWLD3vWJUVU57iUtf4d2F VWbDPEPjADBq4dYCN7AHrHdXljp5pS9caxv+RD1Gy7zDmgWcYcIsRF79ztspbDGQOnJX mJDjsg1PbVKeHeepZQhK/R4eafg47xjNSqXYTMQh3mhQT8A5xjS2E2SFstlt3m0G33tM xItAqbm6JNBLLuCZQyVUvLUyn4juenseDQkiQlg1YqtcbHzCZfzt85MIVyCACkk7XUTZ 0Bgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=AbeZ6c53cwolfsJXL8W/mW8ZWbgFKNj82lz0nxrDSHc=; fh=GTnkJNBIlVeBhBTe96ueQBNZ37qmUNj+HvaZTT9Obso=; b=CSUlf/ojyAXpYaYZBML4h7f4ZjSJ8eCelMe6ESkw9/ZEelGhySvi0XC53NDoYcg3g7 Nr4G+ZO/tl79IgLILBuYep5TUdRkHR3PhQ+NyvfKSnrUjfd4BiUVkRtobDGSFvLrPD1I f9G9HoFNk3PrNEhbP4fzI4KsFGj77DQog2+EG7eGYZ3sj7NezAgFC0l/g7FbhNeYB1Pf nu/mOCUEdg1aja9PMSuiFrTkFkPNdk/1VqrCyX3+1CwXIVxXwq7DfxMlJjWncPrBs+Vt IrNGvAa2aZSdhWoJByGheCCQrxVVYEqUoJiaE0gtSx/6LwcBrSxs0KSgjP8/KOUvLHjQ kyHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Uc+ee6YL; spf=pass (google.com: domain of linux-kernel+bounces-989-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-989-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l3-20020a0561023f4300b004664a687484si1508280vsv.257.2023.12.15.05.17.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:17:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-989-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Uc+ee6YL; spf=pass (google.com: domain of linux-kernel+bounces-989-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-989-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 199EF1C23B11 for ; Fri, 15 Dec 2023 13:17:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C39E630D15; Fri, 15 Dec 2023 13:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uc+ee6YL" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED7E32DF8E; Fri, 15 Dec 2023 13:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40c256ffdbcso7456785e9.2; Fri, 15 Dec 2023 05:15:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702646146; x=1703250946; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AbeZ6c53cwolfsJXL8W/mW8ZWbgFKNj82lz0nxrDSHc=; b=Uc+ee6YLiHCJzkoOZdQuriSKXv5FOjkdoqRFPfju+Mzm7d3aiDgWzJE5HRyvjUYm0O H/7b61pRtwyfzwQtLnmm9cbq39midTKr7WQmqwYp8zFMOHlfP+XCVDxKxgyBO9nmcibQ cMpy7Iw7G7WzatKoA94wZyDUV3qq8UMnCULLP8AXMUvgxE7NtqGfpGEJfIFBl2KF2D38 fdD73C5ZWP7DSOnwhlCZxZH45owwWxZ9UI3fYb4j5cSboj1DfmCOitxLNxedZuDolIMK Mc00s2Kym1edn/kXniLgJe+Ar6ogLtbnXKAqvPGf3qXc34KJUgtMW9el+juvyesxwAq5 8x/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702646146; x=1703250946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AbeZ6c53cwolfsJXL8W/mW8ZWbgFKNj82lz0nxrDSHc=; b=XaG619by3+yleEiQWhZzkCaJrYHwDnrUMfCnTrxZsfav8eAKLmfpSqNINwN99qhrhU VdfpBBB9p/AQ7WKh9OXv1xnVGmbhYV0peVpqkZ0GsoQkGub70BOQyvUtFc6SwxXYS/wm QV9PjzpPnuIWZ1BOrNxi3DsJueqS6Waq+jdCZAGjQ+bjNFC8BcU8Kkx6rhKjVeVg/5MO wuQeCxWgNHeuW80iyzD0pnMxaZTn1YiON9nKzJw/wkxJfFLLLLbJ4yfQ1ZWsY8ON6TnZ A12ffJ6xI+Hfg3zqmynKJATPkgQmPho79Mehk52sq9vsXrul8c26gS74pNndq9zST3jL 8sHg== X-Gm-Message-State: AOJu0YxgoF7fEd4QqGYiyHZdqvv+KraiC132qGFqZvZp2L7R642axNRo eb3T2lZKOcY1E7+c7kaP8a8= X-Received: by 2002:a05:600c:5012:b0:40c:6bfc:4bb1 with SMTP id n18-20020a05600c501200b0040c6bfc4bb1mr407557wmr.38.1702646145765; Fri, 15 Dec 2023 05:15:45 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm21618324wmb.46.2023.12.15.05.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:15:45 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Epping , Vladimir Oltean , Christian Marangi , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v8 4/4] net: phy: add support for PHY package MMD read/write Date: Fri, 15 Dec 2023 14:15:34 +0100 Message-Id: <20231215131534.7188-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215131534.7188-1-ansuelsmth@gmail.com> References: <20231215131534.7188-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785353991460420108 X-GMAIL-MSGID: 1785353991460420108 Some PHY in PHY package may require to read/write MMD regs to correctly configure the PHY package. Add support for these additional required function in both lock and no lock variant. It's assumed that the entire PHY package is either C22 or C45. We use C22 or C45 way of writing/reading to mmd regs based on the passed phydev whether it's C22 or C45. Signed-off-by: Christian Marangi --- Changesv8: - Use helper to validate final addr Changes v7: - Change addr to u8 Changes v6: - Fix copy paste error for kdoc Changes v5: - Improve function description Changes v4: - Drop function comments in header file Changes v3: - Move in phy-core.c from phy.h - Base c45 from phydev Changes v2: - Rework to use newly introduced helper - Add common check for regnum and devad drivers/net/phy/phy-core.c | 140 +++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 +++++ 2 files changed, 156 insertions(+) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index b729ac8b2640..15f349e5995a 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -650,6 +650,146 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) } EXPORT_SYMBOL(phy_write_mmd); +/** + * __phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + int addr = phy_package_address(phydev, addr_offset); + + if (addr < 0) + return addr; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); +} +EXPORT_SYMBOL(__phy_package_read_mmd); + +/** + * phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + int addr = phy_package_address(phydev, addr_offset); + int val; + + if (addr < 0) + return addr; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + val = mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); + phy_unlock_mdio_bus(phydev); + + return val; +} +EXPORT_SYMBOL(phy_package_read_mmd); + +/** + * __phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + int addr = phy_package_address(phydev, addr_offset); + + if (addr < 0) + return addr; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); +} +EXPORT_SYMBOL(__phy_package_write_mmd); + +/** + * phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + int addr = phy_package_address(phydev, addr_offset); + int ret; + + if (addr < 0) + return addr; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + ret = mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); + phy_unlock_mdio_bus(phydev); + + return ret; +} +EXPORT_SYMBOL(phy_package_write_mmd); + /** * phy_modify_changed - Function for modifying a PHY register * @phydev: the phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index 85fdba43b813..191762d89ed8 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2060,6 +2060,22 @@ static inline int __phy_package_write(struct phy_device *phydev, return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + static inline bool __phy_package_set_once(struct phy_device *phydev, unsigned int b) {