From patchwork Wed Jan 3 02:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 184582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4801652dyb; Tue, 2 Jan 2024 18:55:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTk+4Mv5/G9DmIP84mS4KyeLhAIIro6vX4HfKYq44oHaxqFuzMkSxDmod70GOGyWb8TI9f X-Received: by 2002:a17:902:e88c:b0:1d4:c4db:fd0c with SMTP id w12-20020a170902e88c00b001d4c4dbfd0cmr1524968plg.28.1704250521382; Tue, 02 Jan 2024 18:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704250521; cv=none; d=google.com; s=arc-20160816; b=ZfK41bL6+wKTQFbypUZy8PZNDS8xhYDs0PvpwiyXnKbRifHKu8urnly03hrUOF+15w lWCxMvsfAqvjzMEjkpS/g6BL5QfczCgHcmF5S0JRXvjuhKKtSkQMqOnJUcXVylVnR2Ys HGfQHxeiZRqEewzr5DDxk2uzRkVh6AlyW9kzeEAFnW70bj4d5TxwM8tb8FCNhFYznuv2 oeT2tXr6MPR3MP4eWNqDdgl0oFCAV3s75vPCeI4MqX1QpULYdxLPyvPIM71kgfWv+GYX FaTo0njMDaPz4WdjBGAM93NCcNsZc3Cy74pb5CvoL/A+TSMJWugwl6A3rSM951Smh2/U 4Q9Q== 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=rMt7lZjCiYyD0IatuGzXYEdVsPArKyHXFkUBPDO+8is=; fh=ofXRanw8b8V3fyRJsU3Dni1vkxaQb8bG8RTS/EfAsMo=; b=I+H9DwR+WvGNJblA2YyJPchBu8QmLRFRzbYRh5rdpD3dW1tfVsnA9Go5TyplGOZLry eDHefo2KfmcJ1K7w4QocYE4S1dvcRIz05UMFEjw3Cq06IvUHzRb4xJvtSSfBaWuqkEFX YttEjcnKxA5W/oEweDnTqQ2GBIvAGAXIZyZRHEL+8UwS59zrivk3h1ij3n4h7OyVgU2G LnqDGFcUM9bCykbUQjyHJawCwwnMK+dHi3Y6sK0s2ZrIWCTn/9AmFBuFidrYcHyoOzIC jkQfwyrS1BvTsFTTndUO66+f1HGhBDyt2CFZPYuFaAaGbE6LPdDyMKWjAnYcy4aehrGZ iaPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=rzbiOiqo; spf=pass (google.com: domain of linux-kernel+bounces-15099-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15099-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a9-20020a170902ecc900b001d4ac76e4ffsi5435615plh.322.2024.01.02.18.55.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 18:55:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15099-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=rzbiOiqo; spf=pass (google.com: domain of linux-kernel+bounces-15099-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15099-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 2D1A6281AFF for ; Wed, 3 Jan 2024 02:55:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87C91179AC; Wed, 3 Jan 2024 02:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rzbiOiqo" X-Original-To: linux-kernel@vger.kernel.org Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 5C71817996 for ; Wed, 3 Jan 2024 02:54:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1704250461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rMt7lZjCiYyD0IatuGzXYEdVsPArKyHXFkUBPDO+8is=; b=rzbiOiqonwmAWpfAUA7RmoR8Qvz7aff/QP18gShTRo4K9/ITTdPBOBMGsQzFginEwyNYuR GS1Tm+z8D3XBADkl2sA26vGJdGx7xgZz97WKh8donTMzdRViHmO67seZGdknyVH26wGMbr RE4OZyJDrXhHqineE2q4jcdvLJACU0Q= From: Yajun Deng To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: andrew@lunn.ch, olteanv@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, przemyslaw.kitszel@intel.com, rmk+kernel@armlinux.org.uk, kabel@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, Yajun Deng Subject: [PATCH net-next v2 2/2] net: phy: Introduce is_phy_device() Date: Wed, 3 Jan 2024 10:53:34 +0800 Message-Id: <20240103025334.541682-3-yajun.deng@linux.dev> In-Reply-To: <20240103025334.541682-1-yajun.deng@linux.dev> References: <20240103025334.541682-1-yajun.deng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787036194557428143 X-GMAIL-MSGID: 1787036194557428143 MDIO_DEVICE_FLAG_PHY is the only flag that can be set in the struct mdio_device. This flag is used to test that if it is a phy device. We can test that the type of the device is equal to mdio_bus_phy_type, so that, the flags in struct mdio_device can be removed. Introduce is_phy_device(), use it to test that if the device is a phy device. Signed-off-by: Yajun Deng --- drivers/net/phy/mdio_bus.c | 7 +++---- drivers/net/phy/phy_device.c | 8 ++++++-- include/linux/mdio.h | 3 --- include/linux/phy.h | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 69b8ddef9500..a80e6a7cbca5 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -75,7 +75,7 @@ int mdiobus_register_device(struct mdio_device *mdiodev) if (mdiodev->bus->mdio_map[mdiodev->addr]) return -EBUSY; - if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) { + if (is_phy_device(&mdiodev->dev)) { err = mdiobus_register_gpiod(mdiodev); if (err) return err; @@ -125,7 +125,7 @@ struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) if (!mdiodev) return NULL; - if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY)) + if (!is_phy_device(&mdiodev->dev)) return NULL; return container_of(mdiodev, struct phy_device, mdio); @@ -1345,8 +1345,7 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) struct mdio_device *mdio = to_mdio_device(dev); /* Both the driver and device must type-match */ - if (is_phy_driver(&mdiodrv->driver) == - !(mdio->flags & MDIO_DEVICE_FLAG_PHY)) + if (is_phy_driver(&mdiodrv->driver) != is_phy_device(&mdio->dev)) return 0; if (of_driver_match_device(dev, drv)) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 732cfec293dd..1e19956e9e8d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -640,6 +640,11 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id) return 0; } +bool is_phy_device(struct device *dev) +{ + return dev->type == &mdio_bus_phy_type; +} + struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids) @@ -660,7 +665,6 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, mdiodev->bus = bus; mdiodev->bus_match = phy_bus_match; mdiodev->addr = addr; - mdiodev->flags = MDIO_DEVICE_FLAG_PHY; mdiodev->device_free = phy_mdio_device_free; mdiodev->device_remove = phy_mdio_device_remove; mdiodev->reset_state = -1; @@ -3266,7 +3270,7 @@ struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) if (!mdiodev) return NULL; - if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + if (is_phy_device(&mdiodev->dev)) return to_phy_device(&mdiodev->dev); put_device(&mdiodev->dev); diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 852f838f52f5..8364e2d0c269 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -37,7 +37,6 @@ struct mdio_device { /* Bus address of the MDIO device (0-31) */ int addr; - int flags; int reset_state; struct gpio_desc *reset_gpio; struct reset_control *reset_ctrl; @@ -50,8 +49,6 @@ static inline struct mdio_device *to_mdio_device(const struct device *dev) return container_of(dev, struct mdio_device, dev); } -#define MDIO_DEVICE_FLAG_PHY 1 - /* struct mdio_driver: Generic MDIO driver */ struct mdio_driver { struct device_driver driver; diff --git a/include/linux/phy.h b/include/linux/phy.h index 603c440f09f6..7d10b44a475b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2156,5 +2156,6 @@ module_exit(phy_module_exit) bool phy_driver_is_genphy(struct phy_device *phydev); bool phy_driver_is_genphy_10g(struct phy_device *phydev); bool is_phy_driver(struct device_driver *driver); +bool is_phy_device(struct device *dev); #endif /* __PHY_H */