lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1456677700-23027-22-git-send-email-andrew@lunn.ch>
Date:	Sun, 28 Feb 2016 17:41:29 +0100
From:	Andrew Lunn <andrew@...n.ch>
To:	Florian Fainelli <f.fainelli@...il.com>,
	Vivien Didelot <vivien.didelot@...oirfairelinux.com>,
	netdev <netdev@...r.kernel.org>
Cc:	Andrew Lunn <andrew@...n.ch>
Subject: [PATCH RFC v2 21/32] net: mdio: Add mdiodev_{read|write} helpers

An mdio driver will want to perform reads/writes on its device.
Provide an abstraction over the mdiobus functions, which require more
knowledge of bus addresses.

Signed-off-by: Andrew Lunn <andrew@...n.ch>
---
 drivers/net/phy/mdio_device.c | 68 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/mdio.h          |  5 ++++
 2 files changed, 73 insertions(+)

diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index 9c88e6749b9a..5bf6a2b93773 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -23,6 +23,74 @@
 #include <linux/string.h>
 #include <linux/unistd.h>
 
+/**
+ * mdiodev_read_nested - Nested version of the mdiodev_read function
+ * @mdiodev: the mdio device to read
+ * @regnum: register number to read
+ *
+ * In case of nested MDIO bus access avoid lockdep false positives by
+ * using mutex_lock_nested().
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ */
+int mdiodev_read_nested(struct mdio_device *mdiodev, u32 regnum)
+{
+	return mdiobus_read_nested(mdiodev->bus, mdiodev->addr, regnum);
+}
+EXPORT_SYMBOL(mdiodev_read_nested);
+
+/**
+ * mdiodev_read - Convenience function for reading a given MII mgmt register
+ * @mdiodev: the mdio device to read
+ * @regnum: register number to read
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ */
+int mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
+{
+	return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
+}
+EXPORT_SYMBOL(mdiodev_read);
+
+/**
+ * mdiodev_write_nested - Nested version of the mdiodev_write function
+ * @mdiodev: the mdio device to read
+ * @regnum: register number to write
+ * @val: value to write to @regnum
+ *
+ * In case of nested MDIO bus access avoid lockdep false positives by
+ * using mutex_lock_nested().
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ */
+int mdiodev_write_nested(struct mdio_device *mdiodev, u32 regnum, u16 val)
+{
+	return mdiobus_write_nested(mdiodev->bus, mdiodev->addr, regnum, val);
+}
+EXPORT_SYMBOL(mdiodev_write_nested);
+
+/**
+ * mdiodev_write - Convenience function for writing a given MII mgmt register
+ * @mdiodev: the mdio device to read
+ * @regnum: register number to write
+ * @val: value to write to @regnum
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ */
+int mdiodev_write(struct mdio_device *mdiodev, u32 regnum, u16 val)
+{
+	return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
+}
+EXPORT_SYMBOL(mdiodev_write);
+
 void mdio_device_free(struct mdio_device *mdiodev)
 {
 	put_device(&mdiodev->dev);
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 5bfd99d1a40a..58e39fbaa3e8 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -227,6 +227,11 @@ int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
 
+int mdiodev_read(struct mdio_device *mdiodev, u32 regnum);
+int mdiodev_read_nested(struct mdio_device *mdiodev, u32 regnum);
+int mdiodev_write(struct mdio_device *mdiodev, u32 regnum, u16 val);
+int mdiodev_write_nested(struct mdio_device *mdiodev, u32 regnum, u16 val);
+
 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);
-- 
2.7.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ