[PATCH net-next 05/10] net: phy: introduce a phy_driver macsec helper

From: Antoine Tenart
Date: Wed Jan 23 2019 - 10:59:26 EST


This patch introduces a phy_driver MACsec helper to allow PHYs to
implement a MACsec offloading solution. The phy_driver MACsec helper is
called through a wrapper, phy_macsec, to perform this call while holding
the phydev lock.

Signed-off-by: Antoine Tenart <antoine.tenart@xxxxxxxxxxx>
---
drivers/net/phy/phy.c | 17 +++++++++++++++++
include/linux/phy.h | 9 +++++++++
2 files changed, 26 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 631ed33fe9d9..6b37bb845ce9 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1095,6 +1095,23 @@ int phy_get_eee_err(struct phy_device *phydev)
}
EXPORT_SYMBOL(phy_get_eee_err);

+int phy_macsec(struct phy_device *phydev, struct netdev_macsec *macsec)
+{
+ int ret = -EOPNOTSUPP;
+
+ if (!phydev->drv)
+ return -EIO;
+
+ mutex_lock(&phydev->lock);
+
+ if (phydev->drv->macsec)
+ ret = phydev->drv->macsec(phydev, macsec);
+
+ mutex_unlock(&phydev->lock);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(phy_macsec);
+
/**
* phy_ethtool_get_eee - get EEE supported and status
* @phydev: target phy_device struct
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 1f3873a2ff29..21839f352e7c 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -27,6 +27,10 @@
#include <linux/workqueue.h>
#include <linux/mod_devicetable.h>

+#ifdef CONFIG_MACSEC
+#include <net/macsec.h>
+#endif
+
#include <linux/atomic.h>

#define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
@@ -630,6 +634,10 @@ struct phy_driver {
struct ethtool_tunable *tuna,
const void *data);
int (*set_loopback)(struct phy_device *dev, bool enable);
+
+#ifdef CONFIG_MACSEC
+ int (*macsec)(struct phy_device *dev, struct netdev_macsec *macsec);
+#endif
};
#define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
struct phy_driver, mdiodrv)
@@ -1072,6 +1080,7 @@ int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);

int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
int phy_get_eee_err(struct phy_device *phydev);
+int phy_macsec(struct phy_device *phydev, struct netdev_macsec *macsec);
int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
--
2.20.1