diff mbox series

[1/2] net: phy: Add fwnode helper functions

Message ID 1595938400-13279-2-git-send-email-vikas.singh@puresoftware.com
State Deferred
Delegated to: David Miller
Headers show
Series Add fwnode helper functions to MDIO bus driver | expand

Commit Message

Vikas Singh July 28, 2020, 12:13 p.m. UTC
Add support of fwnode helper functions to MDIO bus driver.
1. fwnode_phy_find_device() to find phy_device associated to a fwnod
2. fwnode_phy_connect() to attach the mac to the phy

Signed-off-by: Vikas Singh <vikas.singh@puresoftware.com>
---
 drivers/net/phy/mdio_bus.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mdio.h       |  4 +++
 2 files changed, 70 insertions(+)

Comments

kernel test robot Aug. 1, 2020, 8:10 a.m. UTC | #1
Hi Vikas,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc7 next-20200731]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Vikas-Singh/Add-fwnode-helper-functions-to-MDIO-bus-driver/20200728-201610
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 92ed301919932f777713b9172e525674157e983d
config: h8300-randconfig-s031-20200731 (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.2-115-g5fc204f2-dirty
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=h8300 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   h8300-linux-ld: drivers/net/phy/mdio_bus.o: in function `fwnode_phy_connect':
>> drivers/net/phy/mdio_bus.c:102: undefined reference to `phy_connect_direct'

vim +102 drivers/net/phy/mdio_bus.c

    76	
    77	/**
    78	 * fwnode_phy_connect - Connect to the phy described in the device tree
    79	 * @dev: pointer to net_device claiming the phy
    80	 * @phy_fwnode: Pointer to fwnode for the PHY
    81	 * @hndlr: Link state callback for the network device
    82	 * @flags: flags to pass to the PHY
    83	 * @iface: PHY data interface type
    84	 *
    85	 * If successful, returns a pointer to the phy_device with the embedded
    86	 * struct device refcount incremented by one, or NULL on failure. The
    87	 * refcount must be dropped by calling phy_disconnect() or phy_detach().
    88	 */
    89	struct phy_device *fwnode_phy_connect(
    90			struct net_device *dev, struct fwnode_handle *phy_fwnode,
    91			void (*hndlr)(struct net_device *), u32 flags, u32 iface)
    92	{
    93		struct phy_device *phy_dev;
    94	
    95		phy_dev = fwnode_phy_find_device(phy_fwnode);
    96		if (!phy_dev)
    97			return NULL;
    98	
    99		phy_dev->dev_flags = flags;
   100	
   101		/* If in case we fail to attach to PHY,then phy_dev must be NULL */
 > 102		if (phy_connect_direct(dev, phy_dev, hndlr, iface))
   103			return NULL;
   104	
   105		return phy_dev;
   106	}
   107	EXPORT_SYMBOL(fwnode_phy_connect);
   108	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 46b3370..ab8fcea 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -40,6 +40,72 @@ 
 
 #include "mdio-boardinfo.h"
 
+/* Helper function for fwnode_phy_find_device */
+static int fwnode_phy_match(struct device *dev, const void *phy_fwnode)
+{
+	return dev->fwnode == phy_fwnode;
+}
+
+/**
+ * fwnode_phy_find_device - find the phy_device associated to fwnode
+ * @phy_fwnode: Pointer to the PHY's fwnode
+ *
+ * If successful, returns a pointer to the phy_device with the
+ * embedded struct device refcount incremented by one, NULL on
+ * failure.
+ */
+struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
+{
+	struct device *d;
+	struct mdio_device *mdiodev;
+
+	if (!phy_fwnode)
+		return NULL;
+
+	d = bus_find_device(&mdio_bus_type, NULL, phy_fwnode, fwnode_phy_match);
+	if (d) {
+		mdiodev = to_mdio_device(d);
+		if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+			return to_phy_device(d);
+		put_device(d);
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(fwnode_phy_find_device);
+
+/**
+ * fwnode_phy_connect - Connect to the phy described in the device tree
+ * @dev: pointer to net_device claiming the phy
+ * @phy_fwnode: Pointer to fwnode for the PHY
+ * @hndlr: Link state callback for the network device
+ * @flags: flags to pass to the PHY
+ * @iface: PHY data interface type
+ *
+ * If successful, returns a pointer to the phy_device with the embedded
+ * struct device refcount incremented by one, or NULL on failure. The
+ * refcount must be dropped by calling phy_disconnect() or phy_detach().
+ */
+struct phy_device *fwnode_phy_connect(
+		struct net_device *dev, struct fwnode_handle *phy_fwnode,
+		void (*hndlr)(struct net_device *), u32 flags, u32 iface)
+{
+	struct phy_device *phy_dev;
+
+	phy_dev = fwnode_phy_find_device(phy_fwnode);
+	if (!phy_dev)
+		return NULL;
+
+	phy_dev->dev_flags = flags;
+
+	/* If in case we fail to attach to PHY,then phy_dev must be NULL */
+	if (phy_connect_direct(dev, phy_dev, hndlr, iface))
+		return NULL;
+
+	return phy_dev;
+}
+EXPORT_SYMBOL(fwnode_phy_connect);
+
 static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
 {
 	/* Deassert the optional reset signal */
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 898cbf0..501da6a 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -362,6 +362,10 @@  int mdiobus_register_device(struct mdio_device *mdiodev);
 int mdiobus_unregister_device(struct mdio_device *mdiodev);
 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
+struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
+struct phy_device *fwnode_phy_connect(
+		struct net_device *dev, struct fwnode_handle *phy_fwnode,
+		void (*hndlr)(struct net_device *), u32 flags, u32 iface);
 
 /**
  * mdio_module_driver() - Helper macro for registering mdio drivers