c3a494
From a3e660ae9fdeb53000eceeaf393e03cd087e37f7 Mon Sep 17 00:00:00 2001
984fc8
From: Tom Lendacky <thomas.lendacky@amd.com>
984fc8
Date: Tue, 17 Mar 2015 10:58:38 -0500
c3a494
Subject: [PATCH 2/2] amd-xgbe-phy-a0: Add support for XGBE PHY on A0
984fc8
984fc8
Add XGBE phy driver support for A0 hardware.
984fc8
984fc8
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
c3a494
[Add back AMD_XGBE_PHY removed upstream for B0 driver]
c3a494
Signed-off-by: Mark Salter <msalter@redhat.com>
984fc8
---
c3a494
 drivers/net/phy/Kconfig           |    7 +
c3a494
 drivers/net/phy/Makefile          |    1 +
984fc8
 drivers/net/phy/amd-xgbe-phy-a0.c | 1814 +++++++++++++++++++++++++++++++++++++
c3a494
 3 files changed, 1822 insertions(+)
984fc8
 create mode 100644 drivers/net/phy/amd-xgbe-phy-a0.c
984fc8
c3a494
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
c3a494
index cb86d7a..a3138b1 100644
c3a494
--- a/drivers/net/phy/Kconfig
c3a494
+++ b/drivers/net/phy/Kconfig
c3a494
@@ -24,6 +24,13 @@ config AMD_PHY
c3a494
 	---help---
c3a494
 	  Currently supports the am79c874
c3a494
 
c3a494
+config AMD_XGBE_PHY
c3a494
+       tristate "Driver for the AMD 10GbE (amd-xgbe) PHYs"
c3a494
+       depends on (OF || ACPI) && HAS_IOMEM
c3a494
+       depends on ARM64 || COMPILE_TEST
c3a494
+       ---help---
c3a494
+         Currently supports the AMD 10GbE PHY
c3a494
+
c3a494
 config MARVELL_PHY
c3a494
 	tristate "Drivers for Marvell PHYs"
c3a494
 	---help---
984fc8
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
c3a494
index fcc25a0..6ebb9ba 100644
984fc8
--- a/drivers/net/phy/Makefile
984fc8
+++ b/drivers/net/phy/Makefile
c3a494
@@ -29,6 +29,7 @@ obj-$(CONFIG_MDIO_OCTEON)	+= mdio-octeon.o
c3a494
 obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
c3a494
 obj-$(CONFIG_AT803X_PHY)	+= at803x.o
c3a494
 obj-$(CONFIG_AMD_PHY)		+= amd.o
984fc8
+obj-$(CONFIG_AMD_XGBE_PHY)	+= amd-xgbe-phy-a0.o
c3a494
 obj-$(CONFIG_MDIO_BUS_MUX)	+= mdio-mux.o
c3a494
 obj-$(CONFIG_MDIO_BUS_MUX_GPIO)	+= mdio-mux-gpio.o
c3a494
 obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
984fc8
diff --git a/drivers/net/phy/amd-xgbe-phy-a0.c b/drivers/net/phy/amd-xgbe-phy-a0.c
984fc8
new file mode 100644
c3a494
index 0000000..c352d5c
984fc8
--- /dev/null
984fc8
+++ b/drivers/net/phy/amd-xgbe-phy-a0.c
984fc8
@@ -0,0 +1,1814 @@
984fc8
+/*
984fc8
+ * AMD 10Gb Ethernet PHY driver
984fc8
+ *
984fc8
+ * This file is available to you under your choice of the following two
984fc8
+ * licenses:
984fc8
+ *
984fc8
+ * License 1: GPLv2
984fc8
+ *
984fc8
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
984fc8
+ *
984fc8
+ * This file is free software; you may copy, redistribute and/or modify
984fc8
+ * it under the terms of the GNU General Public License as published by
984fc8
+ * the Free Software Foundation, either version 2 of the License, or (at
984fc8
+ * your option) any later version.
984fc8
+ *
984fc8
+ * This file is distributed in the hope that it will be useful, but
984fc8
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
984fc8
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
984fc8
+ * General Public License for more details.
984fc8
+ *
984fc8
+ * You should have received a copy of the GNU General Public License
984fc8
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
984fc8
+ *
984fc8
+ *
984fc8
+ * License 2: Modified BSD
984fc8
+ *
984fc8
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
984fc8
+ * All rights reserved.
984fc8
+ *
984fc8
+ * Redistribution and use in source and binary forms, with or without
984fc8
+ * modification, are permitted provided that the following conditions are met:
984fc8
+ *     * Redistributions of source code must retain the above copyright
984fc8
+ *       notice, this list of conditions and the following disclaimer.
984fc8
+ *     * Redistributions in binary form must reproduce the above copyright
984fc8
+ *       notice, this list of conditions and the following disclaimer in the
984fc8
+ *       documentation and/or other materials provided with the distribution.
984fc8
+ *     * Neither the name of Advanced Micro Devices, Inc. nor the
984fc8
+ *       names of its contributors may be used to endorse or promote products
984fc8
+ *       derived from this software without specific prior written permission.
984fc8
+ *
984fc8
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
984fc8
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
984fc8
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
984fc8
+ * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
984fc8
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
984fc8
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
984fc8
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
984fc8
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
984fc8
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
984fc8
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
984fc8
+ */
984fc8
+
984fc8
+#include <linux/kernel.h>
984fc8
+#include <linux/device.h>
984fc8
+#include <linux/platform_device.h>
984fc8
+#include <linux/string.h>
984fc8
+#include <linux/errno.h>
984fc8
+#include <linux/unistd.h>
984fc8
+#include <linux/slab.h>
984fc8
+#include <linux/interrupt.h>
984fc8
+#include <linux/init.h>
984fc8
+#include <linux/delay.h>
984fc8
+#include <linux/workqueue.h>
984fc8
+#include <linux/netdevice.h>
984fc8
+#include <linux/etherdevice.h>
984fc8
+#include <linux/skbuff.h>
984fc8
+#include <linux/mm.h>
984fc8
+#include <linux/module.h>
984fc8
+#include <linux/mii.h>
984fc8
+#include <linux/ethtool.h>
984fc8
+#include <linux/phy.h>
984fc8
+#include <linux/mdio.h>
984fc8
+#include <linux/io.h>
984fc8
+#include <linux/of.h>
984fc8
+#include <linux/of_platform.h>
984fc8
+#include <linux/of_device.h>
984fc8
+#include <linux/uaccess.h>
984fc8
+#include <linux/bitops.h>
984fc8
+#include <linux/property.h>
984fc8
+#include <linux/acpi.h>
984fc8
+#include <linux/irq.h>
984fc8
+
984fc8
+MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
984fc8
+MODULE_LICENSE("Dual BSD/GPL");
984fc8
+MODULE_VERSION("0.0.0-a");
984fc8
+MODULE_DESCRIPTION("AMD 10GbE (amd-xgbe) PHY driver");
984fc8
+
984fc8
+#define XGBE_PHY_ID	0x7996ced0
984fc8
+#define XGBE_PHY_MASK	0xfffffff0
984fc8
+
984fc8
+#define XGBE_PHY_SERDES_RETRY		32
984fc8
+#define XGBE_PHY_CHANNEL_PROPERTY	"amd,serdes-channel"
984fc8
+#define XGBE_PHY_SPEEDSET_PROPERTY	"amd,speed-set"
984fc8
+#define XGBE_PHY_BLWC_PROPERTY		"amd,serdes-blwc"
984fc8
+#define XGBE_PHY_CDR_RATE_PROPERTY	"amd,serdes-cdr-rate"
984fc8
+#define XGBE_PHY_PQ_SKEW_PROPERTY	"amd,serdes-pq-skew"
984fc8
+#define XGBE_PHY_TX_AMP_PROPERTY	"amd,serdes-tx-amp"
984fc8
+
984fc8
+#define XGBE_PHY_SPEEDS			3
984fc8
+#define XGBE_PHY_SPEED_1000		0
984fc8
+#define XGBE_PHY_SPEED_2500		1
984fc8
+#define XGBE_PHY_SPEED_10000		2
984fc8
+
984fc8
+#define XGBE_AN_INT_CMPLT		0x01
984fc8
+#define XGBE_AN_INC_LINK		0x02
984fc8
+#define XGBE_AN_PG_RCV			0x04
984fc8
+#define XGBE_AN_INT_MASK		0x07
984fc8
+
984fc8
+#define XNP_MCF_NULL_MESSAGE		0x001
984fc8
+#define XNP_ACK_PROCESSED		BIT(12)
984fc8
+#define XNP_MP_FORMATTED		BIT(13)
984fc8
+#define XNP_NP_EXCHANGE			BIT(15)
984fc8
+
984fc8
+#define XGBE_PHY_RATECHANGE_COUNT	500
984fc8
+
984fc8
+#define XGBE_PHY_KR_TRAINING_START	0x01
984fc8
+#define XGBE_PHY_KR_TRAINING_ENABLE	0x02
984fc8
+
984fc8
+#define XGBE_PHY_FEC_ENABLE		0x01
984fc8
+#define XGBE_PHY_FEC_FORWARD		0x02
984fc8
+#define XGBE_PHY_FEC_MASK		0x03
984fc8
+
984fc8
+#ifndef MDIO_PMA_10GBR_PMD_CTRL
984fc8
+#define MDIO_PMA_10GBR_PMD_CTRL		0x0096
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_PMA_10GBR_FEC_ABILITY
984fc8
+#define MDIO_PMA_10GBR_FEC_ABILITY	0x00aa
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_PMA_10GBR_FEC_CTRL
984fc8
+#define MDIO_PMA_10GBR_FEC_CTRL		0x00ab
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_AN_XNP
984fc8
+#define MDIO_AN_XNP			0x0016
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_AN_LPX
984fc8
+#define MDIO_AN_LPX			0x0019
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_AN_INTMASK
984fc8
+#define MDIO_AN_INTMASK			0x8001
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_AN_INT
984fc8
+#define MDIO_AN_INT			0x8002
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_AN_KR_CTRL
984fc8
+#define MDIO_AN_KR_CTRL			0x8003
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_CTRL1_SPEED1G
984fc8
+#define MDIO_CTRL1_SPEED1G		(MDIO_CTRL1_SPEED10G & ~BMCR_SPEED100)
984fc8
+#endif
984fc8
+
984fc8
+#ifndef MDIO_KR_CTRL_PDETECT
984fc8
+#define MDIO_KR_CTRL_PDETECT		0x01
984fc8
+#endif
984fc8
+
984fc8
+#define GET_BITS(_var, _index, _width)					\
984fc8
+	(((_var) >> (_index)) & ((0x1 << (_width)) - 1))
984fc8
+
984fc8
+#define SET_BITS(_var, _index, _width, _val)				\
984fc8
+do {									\
984fc8
+	(_var) &= ~(((0x1 << (_width)) - 1) << (_index));		\
984fc8
+	(_var) |= (((_val) & ((0x1 << (_width)) - 1)) << (_index));	\
984fc8
+} while (0)
984fc8
+
984fc8
+#define XCMU_IOREAD(_priv, _reg)					\
984fc8
+	ioread16((_priv)->cmu_regs + _reg)
984fc8
+
984fc8
+#define XCMU_IOWRITE(_priv, _reg, _val)					\
984fc8
+	iowrite16((_val), (_priv)->cmu_regs + _reg)
984fc8
+
984fc8
+#define XRXTX_IOREAD(_priv, _reg)					\
984fc8
+	ioread16((_priv)->rxtx_regs + _reg)
984fc8
+
984fc8
+#define XRXTX_IOREAD_BITS(_priv, _reg, _field)				\
984fc8
+	GET_BITS(XRXTX_IOREAD((_priv), _reg),				\
984fc8
+		 _reg##_##_field##_INDEX,				\
984fc8
+		 _reg##_##_field##_WIDTH)
984fc8
+
984fc8
+#define XRXTX_IOWRITE(_priv, _reg, _val)				\
984fc8
+	iowrite16((_val), (_priv)->rxtx_regs + _reg)
984fc8
+
984fc8
+#define XRXTX_IOWRITE_BITS(_priv, _reg, _field, _val)			\
984fc8
+do {									\
984fc8
+	u16 reg_val = XRXTX_IOREAD((_priv), _reg);			\
984fc8
+	SET_BITS(reg_val,						\
984fc8
+		 _reg##_##_field##_INDEX,				\
984fc8
+		 _reg##_##_field##_WIDTH, (_val));			\
984fc8
+	XRXTX_IOWRITE((_priv), _reg, reg_val);				\
984fc8
+} while (0)
984fc8
+
984fc8
+/* SerDes CMU register offsets */
984fc8
+#define CMU_REG15			0x003c
984fc8
+#define CMU_REG16			0x0040
984fc8
+
984fc8
+/* SerDes CMU register entry bit positions and sizes */
984fc8
+#define CMU_REG16_TX_RATE_CHANGE_BASE	15
984fc8
+#define CMU_REG16_RX_RATE_CHANGE_BASE	14
984fc8
+#define CMU_REG16_RATE_CHANGE_DECR	2
984fc8
+
984fc8
+/* SerDes RxTx register offsets */
984fc8
+#define RXTX_REG2			0x0008
984fc8
+#define RXTX_REG3			0x000c
984fc8
+#define RXTX_REG5			0x0014
984fc8
+#define RXTX_REG6			0x0018
984fc8
+#define RXTX_REG20			0x0050
984fc8
+#define RXTX_REG53			0x00d4
984fc8
+#define RXTX_REG114			0x01c8
984fc8
+#define RXTX_REG115			0x01cc
984fc8
+#define RXTX_REG142			0x0238
984fc8
+
984fc8
+/* SerDes RxTx register entry bit positions and sizes */
984fc8
+#define RXTX_REG2_RESETB_INDEX			15
984fc8
+#define RXTX_REG2_RESETB_WIDTH			1
984fc8
+#define RXTX_REG3_TX_DATA_RATE_INDEX		14
984fc8
+#define RXTX_REG3_TX_DATA_RATE_WIDTH		2
984fc8
+#define RXTX_REG3_TX_WORD_MODE_INDEX		11
984fc8
+#define RXTX_REG3_TX_WORD_MODE_WIDTH		3
984fc8
+#define RXTX_REG5_TXAMP_CNTL_INDEX		7
984fc8
+#define RXTX_REG5_TXAMP_CNTL_WIDTH		4
984fc8
+#define RXTX_REG6_RX_DATA_RATE_INDEX		9
984fc8
+#define RXTX_REG6_RX_DATA_RATE_WIDTH		2
984fc8
+#define RXTX_REG6_RX_WORD_MODE_INDEX		11
984fc8
+#define RXTX_REG6_RX_WORD_MODE_WIDTH		3
984fc8
+#define RXTX_REG20_BLWC_ENA_INDEX		2
984fc8
+#define RXTX_REG20_BLWC_ENA_WIDTH		1
984fc8
+#define RXTX_REG53_RX_PLLSELECT_INDEX		15
984fc8
+#define RXTX_REG53_RX_PLLSELECT_WIDTH		1
984fc8
+#define RXTX_REG53_TX_PLLSELECT_INDEX		14
984fc8
+#define RXTX_REG53_TX_PLLSELECT_WIDTH		1
984fc8
+#define RXTX_REG53_PI_SPD_SEL_CDR_INDEX		10
984fc8
+#define RXTX_REG53_PI_SPD_SEL_CDR_WIDTH		4
984fc8
+#define RXTX_REG114_PQ_REG_INDEX		9
984fc8
+#define RXTX_REG114_PQ_REG_WIDTH		7
984fc8
+#define RXTX_REG115_FORCE_LAT_CAL_START_INDEX	2
984fc8
+#define RXTX_REG115_FORCE_LAT_CAL_START_WIDTH	1
984fc8
+#define RXTX_REG115_FORCE_SUM_CAL_START_INDEX	1
984fc8
+#define RXTX_REG115_FORCE_SUM_CAL_START_WIDTH	1
984fc8
+#define RXTX_REG142_SUM_CALIB_DONE_INDEX	15
984fc8
+#define RXTX_REG142_SUM_CALIB_DONE_WIDTH	1
984fc8
+#define RXTX_REG142_SUM_CALIB_ERR_INDEX		14
984fc8
+#define RXTX_REG142_SUM_CALIB_ERR_WIDTH		1
984fc8
+#define RXTX_REG142_LAT_CALIB_DONE_INDEX	11
984fc8
+#define RXTX_REG142_LAT_CALIB_DONE_WIDTH	1
984fc8
+
984fc8
+#define RXTX_FULL_RATE				0x0
984fc8
+#define RXTX_HALF_RATE				0x1
984fc8
+#define RXTX_FIFTH_RATE				0x3
984fc8
+#define RXTX_66BIT_WORD				0x7
984fc8
+#define RXTX_10BIT_WORD				0x1
984fc8
+#define RXTX_10G_BLWC				0x0
984fc8
+#define RXTX_1G_BLWC				0x1
984fc8
+#define RXTX_10G_TX_AMP				0xa
984fc8
+#define RXTX_1G_TX_AMP				0xf
984fc8
+#define RXTX_10G_CDR				0x7
984fc8
+#define RXTX_1G_CDR				0x2
984fc8
+#define RXTX_10G_PLL				0x1
984fc8
+#define RXTX_1G_PLL				0x0
984fc8
+#define RXTX_10G_PQ				0x1e
984fc8
+#define RXTX_1G_PQ				0xa
984fc8
+
984fc8
+DEFINE_SPINLOCK(cmu_lock);
984fc8
+
984fc8
+static const u32 amd_xgbe_phy_serdes_blwc[] = {
984fc8
+	RXTX_1G_BLWC,
984fc8
+	RXTX_1G_BLWC,
984fc8
+	RXTX_10G_BLWC,
984fc8
+};
984fc8
+
984fc8
+static const u32 amd_xgbe_phy_serdes_cdr_rate[] = {
984fc8
+	RXTX_1G_CDR,
984fc8
+	RXTX_1G_CDR,
984fc8
+	RXTX_10G_CDR,
984fc8
+};
984fc8
+
984fc8
+static const u32 amd_xgbe_phy_serdes_pq_skew[] = {
984fc8
+	RXTX_1G_PQ,
984fc8
+	RXTX_1G_PQ,
984fc8
+	RXTX_10G_PQ,
984fc8
+};
984fc8
+
984fc8
+static const u32 amd_xgbe_phy_serdes_tx_amp[] = {
984fc8
+	RXTX_1G_TX_AMP,
984fc8
+	RXTX_1G_TX_AMP,
984fc8
+	RXTX_10G_TX_AMP,
984fc8
+};
984fc8
+
984fc8
+enum amd_xgbe_phy_an {
984fc8
+	AMD_XGBE_AN_READY = 0,
984fc8
+	AMD_XGBE_AN_PAGE_RECEIVED,
984fc8
+	AMD_XGBE_AN_INCOMPAT_LINK,
984fc8
+	AMD_XGBE_AN_COMPLETE,
984fc8
+	AMD_XGBE_AN_NO_LINK,
984fc8
+	AMD_XGBE_AN_ERROR,
984fc8
+};
984fc8
+
984fc8
+enum amd_xgbe_phy_rx {
984fc8
+	AMD_XGBE_RX_BPA = 0,
984fc8
+	AMD_XGBE_RX_XNP,
984fc8
+	AMD_XGBE_RX_COMPLETE,
984fc8
+	AMD_XGBE_RX_ERROR,
984fc8
+};
984fc8
+
984fc8
+enum amd_xgbe_phy_mode {
984fc8
+	AMD_XGBE_MODE_KR,
984fc8
+	AMD_XGBE_MODE_KX,
984fc8
+};
984fc8
+
984fc8
+enum amd_xgbe_phy_speedset {
984fc8
+	AMD_XGBE_PHY_SPEEDSET_1000_10000 = 0,
984fc8
+	AMD_XGBE_PHY_SPEEDSET_2500_10000,
984fc8
+};
984fc8
+
984fc8
+struct amd_xgbe_phy_priv {
984fc8
+	struct platform_device *pdev;
984fc8
+	struct acpi_device *adev;
984fc8
+	struct device *dev;
984fc8
+
984fc8
+	struct phy_device *phydev;
984fc8
+
984fc8
+	/* SerDes related mmio resources */
984fc8
+	struct resource *rxtx_res;
984fc8
+	struct resource *cmu_res;
984fc8
+
984fc8
+	/* SerDes related mmio registers */
984fc8
+	void __iomem *rxtx_regs;	/* SerDes Rx/Tx CSRs */
984fc8
+	void __iomem *cmu_regs;		/* SerDes CMU CSRs */
984fc8
+
984fc8
+	int an_irq;
984fc8
+	char an_irq_name[IFNAMSIZ + 32];
984fc8
+	struct work_struct an_irq_work;
984fc8
+	unsigned int an_irq_allocated;
984fc8
+
984fc8
+	unsigned int serdes_channel;
984fc8
+	unsigned int speed_set;
984fc8
+
984fc8
+	/* Maintain link status for re-starting auto-negotiation */
984fc8
+	unsigned int link;
984fc8
+
984fc8
+	/* SerDes UEFI configurable settings.
984fc8
+	 *   Switching between modes/speeds requires new values for some
984fc8
+	 *   SerDes settings.  The values can be supplied as device
984fc8
+	 *   properties in array format.  The first array entry is for
984fc8
+	 *   1GbE, second for 2.5GbE and third for 10GbE
984fc8
+	 */
984fc8
+	u32 serdes_blwc[XGBE_PHY_SPEEDS];
984fc8
+	u32 serdes_cdr_rate[XGBE_PHY_SPEEDS];
984fc8
+	u32 serdes_pq_skew[XGBE_PHY_SPEEDS];
984fc8
+	u32 serdes_tx_amp[XGBE_PHY_SPEEDS];
984fc8
+
984fc8
+	/* Auto-negotiation state machine support */
984fc8
+	struct mutex an_mutex;
984fc8
+	enum amd_xgbe_phy_an an_result;
984fc8
+	enum amd_xgbe_phy_an an_state;
984fc8
+	enum amd_xgbe_phy_rx kr_state;
984fc8
+	enum amd_xgbe_phy_rx kx_state;
984fc8
+	struct work_struct an_work;
984fc8
+	struct workqueue_struct *an_workqueue;
984fc8
+	unsigned int an_supported;
984fc8
+	unsigned int parallel_detect;
984fc8
+	unsigned int fec_ability;
984fc8
+
984fc8
+	unsigned int lpm_ctrl;		/* CTRL1 for resume */
984fc8
+};
984fc8
+
984fc8
+static int amd_xgbe_an_disable_kr_training(struct phy_device *phydev)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~XGBE_PHY_KR_TRAINING_ENABLE;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL, ret);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_pcs_power_cycle(struct phy_device *phydev)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret |= MDIO_CTRL1_LPOWER;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	usleep_range(75, 100);
984fc8
+
984fc8
+	ret &= ~MDIO_CTRL1_LPOWER;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static void amd_xgbe_phy_serdes_start_ratechange(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	u16 val, mask;
984fc8
+
984fc8
+	/* Assert Rx and Tx ratechange in CMU_reg16 */
984fc8
+	val = XCMU_IOREAD(priv, CMU_REG16);
984fc8
+
984fc8
+	mask = (1 << (CMU_REG16_TX_RATE_CHANGE_BASE -
984fc8
+		      (priv->serdes_channel * CMU_REG16_RATE_CHANGE_DECR))) |
984fc8
+	       (1 << (CMU_REG16_RX_RATE_CHANGE_BASE -
984fc8
+		      (priv->serdes_channel * CMU_REG16_RATE_CHANGE_DECR)));
984fc8
+	val |= mask;
984fc8
+
984fc8
+	XCMU_IOWRITE(priv, CMU_REG16, val);
984fc8
+}
984fc8
+
984fc8
+static void amd_xgbe_phy_serdes_complete_ratechange(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	u16 val, mask;
984fc8
+	unsigned int wait;
984fc8
+
984fc8
+	/* Release Rx and Tx ratechange for proper channel in CMU_reg16 */
984fc8
+	val = XCMU_IOREAD(priv, CMU_REG16);
984fc8
+
984fc8
+	mask = (1 << (CMU_REG16_TX_RATE_CHANGE_BASE -
984fc8
+		      (priv->serdes_channel * CMU_REG16_RATE_CHANGE_DECR))) |
984fc8
+	       (1 << (CMU_REG16_RX_RATE_CHANGE_BASE -
984fc8
+		      (priv->serdes_channel * CMU_REG16_RATE_CHANGE_DECR)));
984fc8
+	val &= ~mask;
984fc8
+
984fc8
+	XCMU_IOWRITE(priv, CMU_REG16, val);
984fc8
+
984fc8
+	/* Wait for Rx and Tx ready in CMU_reg15 */
984fc8
+	mask = (1 << priv->serdes_channel) |
984fc8
+	       (1 << (priv->serdes_channel + 8));
984fc8
+	wait = XGBE_PHY_RATECHANGE_COUNT;
984fc8
+	while (wait--) {
984fc8
+		udelay(50);
984fc8
+
984fc8
+		val = XCMU_IOREAD(priv, CMU_REG15);
984fc8
+		if ((val & mask) == mask)
984fc8
+			return;
984fc8
+	}
984fc8
+
984fc8
+	netdev_dbg(phydev->attached_dev, "SerDes rx/tx not ready (%#hx)\n",
984fc8
+		   val);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_xgmii_mode(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Disable KR training */
984fc8
+	ret = amd_xgbe_an_disable_kr_training(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set PCS to KR/10G speed */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_PCS_CTRL2_TYPE;
984fc8
+	ret |= MDIO_PCS_CTRL2_10GBR;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret);
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_CTRL1_SPEEDSEL;
984fc8
+	ret |= MDIO_CTRL1_SPEED10G;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	ret = amd_xgbe_phy_pcs_power_cycle(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set SerDes to 10G speed */
984fc8
+	spin_lock(&cmu_lock);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_start_ratechange(phydev);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_DATA_RATE, RXTX_FULL_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_WORD_MODE, RXTX_66BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG5, TXAMP_CNTL,
984fc8
+			   priv->serdes_tx_amp[XGBE_PHY_SPEED_10000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_DATA_RATE, RXTX_FULL_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_WORD_MODE, RXTX_66BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA,
984fc8
+			   priv->serdes_blwc[XGBE_PHY_SPEED_10000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, RX_PLLSELECT, RXTX_10G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, TX_PLLSELECT, RXTX_10G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, PI_SPD_SEL_CDR,
984fc8
+			   priv->serdes_cdr_rate[XGBE_PHY_SPEED_10000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG,
984fc8
+			   priv->serdes_pq_skew[XGBE_PHY_SPEED_10000]);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_complete_ratechange(phydev);
984fc8
+
984fc8
+	spin_unlock(&cmu_lock);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_gmii_2500_mode(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Disable KR training */
984fc8
+	ret = amd_xgbe_an_disable_kr_training(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set PCS to KX/1G speed */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_PCS_CTRL2_TYPE;
984fc8
+	ret |= MDIO_PCS_CTRL2_10GBX;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret);
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_CTRL1_SPEEDSEL;
984fc8
+	ret |= MDIO_CTRL1_SPEED1G;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	ret = amd_xgbe_phy_pcs_power_cycle(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set SerDes to 2.5G speed */
984fc8
+	spin_lock(&cmu_lock);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_start_ratechange(phydev);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_DATA_RATE, RXTX_HALF_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_WORD_MODE, RXTX_10BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG5, TXAMP_CNTL,
984fc8
+			   priv->serdes_tx_amp[XGBE_PHY_SPEED_2500]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_DATA_RATE, RXTX_HALF_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_WORD_MODE, RXTX_10BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA,
984fc8
+			   priv->serdes_blwc[XGBE_PHY_SPEED_2500]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, RX_PLLSELECT, RXTX_1G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, TX_PLLSELECT, RXTX_1G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, PI_SPD_SEL_CDR,
984fc8
+			   priv->serdes_cdr_rate[XGBE_PHY_SPEED_2500]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG,
984fc8
+			   priv->serdes_pq_skew[XGBE_PHY_SPEED_2500]);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_complete_ratechange(phydev);
984fc8
+
984fc8
+	spin_unlock(&cmu_lock);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_gmii_mode(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Disable KR training */
984fc8
+	ret = amd_xgbe_an_disable_kr_training(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set PCS to KX/1G speed */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_PCS_CTRL2_TYPE;
984fc8
+	ret |= MDIO_PCS_CTRL2_10GBX;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret);
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_CTRL1_SPEEDSEL;
984fc8
+	ret |= MDIO_CTRL1_SPEED1G;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	ret = amd_xgbe_phy_pcs_power_cycle(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set SerDes to 1G speed */
984fc8
+	spin_lock(&cmu_lock);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_start_ratechange(phydev);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_DATA_RATE, RXTX_FIFTH_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG3, TX_WORD_MODE, RXTX_10BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG5, TXAMP_CNTL,
984fc8
+			   priv->serdes_tx_amp[XGBE_PHY_SPEED_1000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_DATA_RATE, RXTX_FIFTH_RATE);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RX_WORD_MODE, RXTX_10BIT_WORD);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA,
984fc8
+			   priv->serdes_blwc[XGBE_PHY_SPEED_1000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, RX_PLLSELECT, RXTX_1G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, TX_PLLSELECT, RXTX_1G_PLL);
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG53, PI_SPD_SEL_CDR,
984fc8
+			   priv->serdes_cdr_rate[XGBE_PHY_SPEED_1000]);
984fc8
+
984fc8
+	XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG,
984fc8
+			   priv->serdes_pq_skew[XGBE_PHY_SPEED_1000]);
984fc8
+
984fc8
+	amd_xgbe_phy_serdes_complete_ratechange(phydev);
984fc8
+
984fc8
+	spin_unlock(&cmu_lock);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_cur_mode(struct phy_device *phydev,
984fc8
+				 enum amd_xgbe_phy_mode *mode)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	if ((ret & MDIO_PCS_CTRL2_TYPE) == MDIO_PCS_CTRL2_10GBR)
984fc8
+		*mode = AMD_XGBE_MODE_KR;
984fc8
+	else
984fc8
+		*mode = AMD_XGBE_MODE_KX;
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static bool amd_xgbe_phy_in_kr_mode(struct phy_device *phydev)
984fc8
+{
984fc8
+	enum amd_xgbe_phy_mode mode;
984fc8
+
984fc8
+	if (amd_xgbe_phy_cur_mode(phydev, &mode))
984fc8
+		return false;
984fc8
+
984fc8
+	return (mode == AMD_XGBE_MODE_KR);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_switch_mode(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* If we are in KR switch to KX, and vice-versa */
984fc8
+	if (amd_xgbe_phy_in_kr_mode(phydev)) {
984fc8
+		if (priv->speed_set == AMD_XGBE_PHY_SPEEDSET_1000_10000)
984fc8
+			ret = amd_xgbe_phy_gmii_mode(phydev);
984fc8
+		else
984fc8
+			ret = amd_xgbe_phy_gmii_2500_mode(phydev);
984fc8
+	} else {
984fc8
+		ret = amd_xgbe_phy_xgmii_mode(phydev);
984fc8
+	}
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_set_mode(struct phy_device *phydev,
984fc8
+				 enum amd_xgbe_phy_mode mode)
984fc8
+{
984fc8
+	enum amd_xgbe_phy_mode cur_mode;
984fc8
+	int ret;
984fc8
+
984fc8
+	ret = amd_xgbe_phy_cur_mode(phydev, &cur_mode);
984fc8
+	if (ret)
984fc8
+		return ret;
984fc8
+
984fc8
+	if (mode != cur_mode)
984fc8
+		ret = amd_xgbe_phy_switch_mode(phydev);
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_set_an(struct phy_device *phydev, bool enable,
984fc8
+			       bool restart)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret &= ~MDIO_AN_CTRL1_ENABLE;
984fc8
+
984fc8
+	if (enable)
984fc8
+		ret |= MDIO_AN_CTRL1_ENABLE;
984fc8
+
984fc8
+	if (restart)
984fc8
+		ret |= MDIO_AN_CTRL1_RESTART;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_restart_an(struct phy_device *phydev)
984fc8
+{
984fc8
+	return amd_xgbe_phy_set_an(phydev, true, true);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_disable_an(struct phy_device *phydev)
984fc8
+{
984fc8
+	return amd_xgbe_phy_set_an(phydev, false, false);
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_tx_training(struct phy_device *phydev,
984fc8
+						    enum amd_xgbe_phy_rx *state)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ad_reg, lp_reg, ret;
984fc8
+
984fc8
+	*state = AMD_XGBE_RX_COMPLETE;
984fc8
+
984fc8
+	/* If we're not in KR mode then we're done */
984fc8
+	if (!amd_xgbe_phy_in_kr_mode(phydev))
984fc8
+		return AMD_XGBE_AN_PAGE_RECEIVED;
984fc8
+
984fc8
+	/* Enable/Disable FEC */
984fc8
+	ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2);
984fc8
+	if (ad_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 2);
984fc8
+	if (lp_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_CTRL);
984fc8
+	if (ret < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	ret &= ~XGBE_PHY_FEC_MASK;
984fc8
+	if ((ad_reg & 0xc000) && (lp_reg & 0xc000))
984fc8
+		ret |= priv->fec_ability;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_CTRL, ret);
984fc8
+
984fc8
+	/* Start KR training */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL);
984fc8
+	if (ret < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	if (ret & XGBE_PHY_KR_TRAINING_ENABLE) {
984fc8
+		ret |= XGBE_PHY_KR_TRAINING_START;
984fc8
+		phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL,
984fc8
+			      ret);
984fc8
+	}
984fc8
+
984fc8
+	return AMD_XGBE_AN_PAGE_RECEIVED;
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_tx_xnp(struct phy_device *phydev,
984fc8
+					       enum amd_xgbe_phy_rx *state)
984fc8
+{
984fc8
+	u16 msg;
984fc8
+
984fc8
+	*state = AMD_XGBE_RX_XNP;
984fc8
+
984fc8
+	msg = XNP_MCF_NULL_MESSAGE;
984fc8
+	msg |= XNP_MP_FORMATTED;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP + 2, 0);
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP + 1, 0);
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP, msg);
984fc8
+
984fc8
+	return AMD_XGBE_AN_PAGE_RECEIVED;
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_rx_bpa(struct phy_device *phydev,
984fc8
+					       enum amd_xgbe_phy_rx *state)
984fc8
+{
984fc8
+	unsigned int link_support;
984fc8
+	int ret, ad_reg, lp_reg;
984fc8
+
984fc8
+	/* Read Base Ability register 2 first */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 1);
984fc8
+	if (ret < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	/* Check for a supported mode, otherwise restart in a different one */
984fc8
+	link_support = amd_xgbe_phy_in_kr_mode(phydev) ? 0x80 : 0x20;
984fc8
+	if (!(ret & link_support))
984fc8
+		return AMD_XGBE_AN_INCOMPAT_LINK;
984fc8
+
984fc8
+	/* Check Extended Next Page support */
984fc8
+	ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
984fc8
+	if (ad_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA);
984fc8
+	if (lp_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	return ((ad_reg & XNP_NP_EXCHANGE) || (lp_reg & XNP_NP_EXCHANGE)) ?
984fc8
+	       amd_xgbe_an_tx_xnp(phydev, state) :
984fc8
+	       amd_xgbe_an_tx_training(phydev, state);
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_rx_xnp(struct phy_device *phydev,
984fc8
+					       enum amd_xgbe_phy_rx *state)
984fc8
+{
984fc8
+	int ad_reg, lp_reg;
984fc8
+
984fc8
+	/* Check Extended Next Page support */
984fc8
+	ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP);
984fc8
+	if (ad_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPX);
984fc8
+	if (lp_reg < 0)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	return ((ad_reg & XNP_NP_EXCHANGE) || (lp_reg & XNP_NP_EXCHANGE)) ?
984fc8
+	       amd_xgbe_an_tx_xnp(phydev, state) :
984fc8
+	       amd_xgbe_an_tx_training(phydev, state);
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_page_received(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	enum amd_xgbe_phy_rx *state;
984fc8
+	int ret;
984fc8
+
984fc8
+	state = amd_xgbe_phy_in_kr_mode(phydev) ? &priv->kr_state
984fc8
+						: &priv->kx_state;
984fc8
+
984fc8
+	switch (*state) {
984fc8
+	case AMD_XGBE_RX_BPA:
984fc8
+		ret = amd_xgbe_an_rx_bpa(phydev, state);
984fc8
+		break;
984fc8
+
984fc8
+	case AMD_XGBE_RX_XNP:
984fc8
+		ret = amd_xgbe_an_rx_xnp(phydev, state);
984fc8
+		break;
984fc8
+
984fc8
+	default:
984fc8
+		ret = AMD_XGBE_AN_ERROR;
984fc8
+	}
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static enum amd_xgbe_phy_an amd_xgbe_an_incompat_link(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Be sure we aren't looping trying to negotiate */
984fc8
+	if (amd_xgbe_phy_in_kr_mode(phydev)) {
984fc8
+		priv->kr_state = AMD_XGBE_RX_ERROR;
984fc8
+
984fc8
+		if (!(phydev->supported & SUPPORTED_1000baseKX_Full) &&
984fc8
+		    !(phydev->supported & SUPPORTED_2500baseX_Full))
984fc8
+			return AMD_XGBE_AN_NO_LINK;
984fc8
+
984fc8
+		if (priv->kx_state != AMD_XGBE_RX_BPA)
984fc8
+			return AMD_XGBE_AN_NO_LINK;
984fc8
+	} else {
984fc8
+		priv->kx_state = AMD_XGBE_RX_ERROR;
984fc8
+
984fc8
+		if (!(phydev->supported & SUPPORTED_10000baseKR_Full))
984fc8
+			return AMD_XGBE_AN_NO_LINK;
984fc8
+
984fc8
+		if (priv->kr_state != AMD_XGBE_RX_BPA)
984fc8
+			return AMD_XGBE_AN_NO_LINK;
984fc8
+	}
984fc8
+
984fc8
+	ret = amd_xgbe_phy_disable_an(phydev);
984fc8
+	if (ret)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	ret = amd_xgbe_phy_switch_mode(phydev);
984fc8
+	if (ret)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	ret = amd_xgbe_phy_restart_an(phydev);
984fc8
+	if (ret)
984fc8
+		return AMD_XGBE_AN_ERROR;
984fc8
+
984fc8
+	return AMD_XGBE_AN_INCOMPAT_LINK;
984fc8
+}
984fc8
+
984fc8
+static irqreturn_t amd_xgbe_an_isr(int irq, void *data)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = (struct amd_xgbe_phy_priv *)data;
984fc8
+
984fc8
+	/* Interrupt reason must be read and cleared outside of IRQ context */
984fc8
+	disable_irq_nosync(priv->an_irq);
984fc8
+
984fc8
+	queue_work(priv->an_workqueue, &priv->an_irq_work);
984fc8
+
984fc8
+	return IRQ_HANDLED;
984fc8
+}
984fc8
+
984fc8
+static void amd_xgbe_an_irq_work(struct work_struct *work)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = container_of(work,
984fc8
+						      struct amd_xgbe_phy_priv,
984fc8
+						      an_irq_work);
984fc8
+
984fc8
+	/* Avoid a race between enabling the IRQ and exiting the work by
984fc8
+	 * waiting for the work to finish and then queueing it
984fc8
+	 */
984fc8
+	flush_work(&priv->an_work);
984fc8
+	queue_work(priv->an_workqueue, &priv->an_work);
984fc8
+}
984fc8
+
984fc8
+static void amd_xgbe_an_state_machine(struct work_struct *work)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = container_of(work,
984fc8
+						      struct amd_xgbe_phy_priv,
984fc8
+						      an_work);
984fc8
+	struct phy_device *phydev = priv->phydev;
984fc8
+	enum amd_xgbe_phy_an cur_state = priv->an_state;
984fc8
+	int int_reg, int_mask;
984fc8
+
984fc8
+	mutex_lock(&priv->an_mutex);
984fc8
+
984fc8
+	/* Read the interrupt */
984fc8
+	int_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT);
984fc8
+	if (!int_reg)
984fc8
+		goto out;
984fc8
+
984fc8
+next_int:
984fc8
+	if (int_reg < 0) {
984fc8
+		priv->an_state = AMD_XGBE_AN_ERROR;
984fc8
+		int_mask = XGBE_AN_INT_MASK;
984fc8
+	} else if (int_reg & XGBE_AN_PG_RCV) {
984fc8
+		priv->an_state = AMD_XGBE_AN_PAGE_RECEIVED;
984fc8
+		int_mask = XGBE_AN_PG_RCV;
984fc8
+	} else if (int_reg & XGBE_AN_INC_LINK) {
984fc8
+		priv->an_state = AMD_XGBE_AN_INCOMPAT_LINK;
984fc8
+		int_mask = XGBE_AN_INC_LINK;
984fc8
+	} else if (int_reg & XGBE_AN_INT_CMPLT) {
984fc8
+		priv->an_state = AMD_XGBE_AN_COMPLETE;
984fc8
+		int_mask = XGBE_AN_INT_CMPLT;
984fc8
+	} else {
984fc8
+		priv->an_state = AMD_XGBE_AN_ERROR;
984fc8
+		int_mask = 0;
984fc8
+	}
984fc8
+
984fc8
+	/* Clear the interrupt to be processed */
984fc8
+	int_reg &= ~int_mask;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, int_reg);
984fc8
+
984fc8
+	priv->an_result = priv->an_state;
984fc8
+
984fc8
+again:
984fc8
+	cur_state = priv->an_state;
984fc8
+
984fc8
+	switch (priv->an_state) {
984fc8
+	case AMD_XGBE_AN_READY:
984fc8
+		priv->an_supported = 0;
984fc8
+		break;
984fc8
+
984fc8
+	case AMD_XGBE_AN_PAGE_RECEIVED:
984fc8
+		priv->an_state = amd_xgbe_an_page_received(phydev);
984fc8
+		priv->an_supported++;
984fc8
+		break;
984fc8
+
984fc8
+	case AMD_XGBE_AN_INCOMPAT_LINK:
984fc8
+		priv->an_supported = 0;
984fc8
+		priv->parallel_detect = 0;
984fc8
+		priv->an_state = amd_xgbe_an_incompat_link(phydev);
984fc8
+		break;
984fc8
+
984fc8
+	case AMD_XGBE_AN_COMPLETE:
984fc8
+		priv->parallel_detect = priv->an_supported ? 0 : 1;
984fc8
+		netdev_dbg(phydev->attached_dev, "%s successful\n",
984fc8
+			   priv->an_supported ? "Auto negotiation"
984fc8
+					      : "Parallel detection");
984fc8
+		break;
984fc8
+
984fc8
+	case AMD_XGBE_AN_NO_LINK:
984fc8
+		break;
984fc8
+
984fc8
+	default:
984fc8
+		priv->an_state = AMD_XGBE_AN_ERROR;
984fc8
+	}
984fc8
+
984fc8
+	if (priv->an_state == AMD_XGBE_AN_NO_LINK) {
984fc8
+		/* Disable auto-negotiation for now - it will be
984fc8
+		 * re-enabled once a link is established
984fc8
+		 */
984fc8
+		amd_xgbe_phy_disable_an(phydev);
984fc8
+
984fc8
+		int_reg = 0;
984fc8
+		phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0);
984fc8
+	} else if (priv->an_state == AMD_XGBE_AN_ERROR) {
984fc8
+		netdev_err(phydev->attached_dev,
984fc8
+			   "error during auto-negotiation, state=%u\n",
984fc8
+			   cur_state);
984fc8
+
984fc8
+		int_reg = 0;
984fc8
+		phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0);
984fc8
+	}
984fc8
+
984fc8
+	if (priv->an_state >= AMD_XGBE_AN_COMPLETE) {
984fc8
+		priv->an_result = priv->an_state;
984fc8
+		priv->an_state = AMD_XGBE_AN_READY;
984fc8
+		priv->kr_state = AMD_XGBE_RX_BPA;
984fc8
+		priv->kx_state = AMD_XGBE_RX_BPA;
984fc8
+	}
984fc8
+
984fc8
+	if (cur_state != priv->an_state)
984fc8
+		goto again;
984fc8
+
984fc8
+	if (int_reg)
984fc8
+		goto next_int;
984fc8
+
984fc8
+out:
984fc8
+	enable_irq(priv->an_irq);
984fc8
+
984fc8
+	mutex_unlock(&priv->an_mutex);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_an_init(struct phy_device *phydev)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Set up Advertisement register 3 first */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	if (phydev->supported & SUPPORTED_10000baseR_FEC)
984fc8
+		ret |= 0xc000;
984fc8
+	else
984fc8
+		ret &= ~0xc000;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2, ret);
984fc8
+
984fc8
+	/* Set up Advertisement register 2 next */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	if (phydev->supported & SUPPORTED_10000baseKR_Full)
984fc8
+		ret |= 0x80;
984fc8
+	else
984fc8
+		ret &= ~0x80;
984fc8
+
984fc8
+	if ((phydev->supported & SUPPORTED_1000baseKX_Full) ||
984fc8
+	    (phydev->supported & SUPPORTED_2500baseX_Full))
984fc8
+		ret |= 0x20;
984fc8
+	else
984fc8
+		ret &= ~0x20;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1, ret);
984fc8
+
984fc8
+	/* Set up Advertisement register 1 last */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	if (phydev->supported & SUPPORTED_Pause)
984fc8
+		ret |= 0x400;
984fc8
+	else
984fc8
+		ret &= ~0x400;
984fc8
+
984fc8
+	if (phydev->supported & SUPPORTED_Asym_Pause)
984fc8
+		ret |= 0x800;
984fc8
+	else
984fc8
+		ret &= ~0x800;
984fc8
+
984fc8
+	/* We don't intend to perform XNP */
984fc8
+	ret &= ~XNP_NP_EXCHANGE;
984fc8
+
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE, ret);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_soft_reset(struct phy_device *phydev)
984fc8
+{
984fc8
+	int count, ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret |= MDIO_CTRL1_RESET;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	count = 50;
984fc8
+	do {
984fc8
+		msleep(20);
984fc8
+		ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+		if (ret < 0)
984fc8
+			return ret;
984fc8
+	} while ((ret & MDIO_CTRL1_RESET) && --count);
984fc8
+
984fc8
+	if (ret & MDIO_CTRL1_RESET)
984fc8
+		return -ETIMEDOUT;
984fc8
+
984fc8
+	/* Disable auto-negotiation for now */
984fc8
+	ret = amd_xgbe_phy_disable_an(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Clear auto-negotiation interrupts */
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_config_init(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	struct net_device *netdev = phydev->attached_dev;
984fc8
+	int ret;
984fc8
+
984fc8
+	if (!priv->an_irq_allocated) {
984fc8
+		/* Allocate the auto-negotiation workqueue and interrupt */
984fc8
+		snprintf(priv->an_irq_name, sizeof(priv->an_irq_name) - 1,
984fc8
+			 "%s-pcs", netdev_name(netdev));
984fc8
+
984fc8
+		priv->an_workqueue =
984fc8
+			create_singlethread_workqueue(priv->an_irq_name);
984fc8
+		if (!priv->an_workqueue) {
984fc8
+			netdev_err(netdev, "phy workqueue creation failed\n");
984fc8
+			return -ENOMEM;
984fc8
+		}
984fc8
+
984fc8
+		ret = devm_request_irq(priv->dev, priv->an_irq,
984fc8
+				       amd_xgbe_an_isr, 0, priv->an_irq_name,
984fc8
+				       priv);
984fc8
+		if (ret) {
984fc8
+			netdev_err(netdev, "phy irq request failed\n");
984fc8
+			destroy_workqueue(priv->an_workqueue);
984fc8
+			return ret;
984fc8
+		}
984fc8
+
984fc8
+		priv->an_irq_allocated = 1;
984fc8
+	}
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_ABILITY);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+	priv->fec_ability = ret & XGBE_PHY_FEC_MASK;
984fc8
+
984fc8
+	/* Initialize supported features */
984fc8
+	phydev->supported = SUPPORTED_Autoneg;
984fc8
+	phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
984fc8
+	phydev->supported |= SUPPORTED_Backplane;
984fc8
+	phydev->supported |= SUPPORTED_10000baseKR_Full;
984fc8
+	switch (priv->speed_set) {
984fc8
+	case AMD_XGBE_PHY_SPEEDSET_1000_10000:
984fc8
+		phydev->supported |= SUPPORTED_1000baseKX_Full;
984fc8
+		break;
984fc8
+	case AMD_XGBE_PHY_SPEEDSET_2500_10000:
984fc8
+		phydev->supported |= SUPPORTED_2500baseX_Full;
984fc8
+		break;
984fc8
+	}
984fc8
+
984fc8
+	if (priv->fec_ability & XGBE_PHY_FEC_ENABLE)
984fc8
+		phydev->supported |= SUPPORTED_10000baseR_FEC;
984fc8
+
984fc8
+	phydev->advertising = phydev->supported;
984fc8
+
984fc8
+	/* Set initial mode - call the mode setting routines
984fc8
+	 * directly to insure we are properly configured
984fc8
+	 */
984fc8
+	if (phydev->supported & SUPPORTED_10000baseKR_Full)
984fc8
+		ret = amd_xgbe_phy_xgmii_mode(phydev);
984fc8
+	else if (phydev->supported & SUPPORTED_1000baseKX_Full)
984fc8
+		ret = amd_xgbe_phy_gmii_mode(phydev);
984fc8
+	else if (phydev->supported & SUPPORTED_2500baseX_Full)
984fc8
+		ret = amd_xgbe_phy_gmii_2500_mode(phydev);
984fc8
+	else
984fc8
+		ret = -EINVAL;
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Set up advertisement registers based on current settings */
984fc8
+	ret = amd_xgbe_an_init(phydev);
984fc8
+	if (ret)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Enable auto-negotiation interrupts */
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INTMASK, 0x07);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_setup_forced(struct phy_device *phydev)
984fc8
+{
984fc8
+	int ret;
984fc8
+
984fc8
+	/* Disable auto-negotiation */
984fc8
+	ret = amd_xgbe_phy_disable_an(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Validate/Set specified speed */
984fc8
+	switch (phydev->speed) {
984fc8
+	case SPEED_10000:
984fc8
+		ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR);
984fc8
+		break;
984fc8
+
984fc8
+	case SPEED_2500:
984fc8
+	case SPEED_1000:
984fc8
+		ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX);
984fc8
+		break;
984fc8
+
984fc8
+	default:
984fc8
+		ret = -EINVAL;
984fc8
+	}
984fc8
+
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Validate duplex mode */
984fc8
+	if (phydev->duplex != DUPLEX_FULL)
984fc8
+		return -EINVAL;
984fc8
+
984fc8
+	phydev->pause = 0;
984fc8
+	phydev->asym_pause = 0;
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int __amd_xgbe_phy_config_aneg(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	u32 mmd_mask = phydev->c45_ids.devices_in_package;
984fc8
+	int ret;
984fc8
+
984fc8
+	if (phydev->autoneg != AUTONEG_ENABLE)
984fc8
+		return amd_xgbe_phy_setup_forced(phydev);
984fc8
+
984fc8
+	/* Make sure we have the AN MMD present */
984fc8
+	if (!(mmd_mask & MDIO_DEVS_AN))
984fc8
+		return -EINVAL;
984fc8
+
984fc8
+	/* Disable auto-negotiation interrupt */
984fc8
+	disable_irq(priv->an_irq);
984fc8
+
984fc8
+	/* Start auto-negotiation in a supported mode */
984fc8
+	if (phydev->supported & SUPPORTED_10000baseKR_Full)
984fc8
+		ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR);
984fc8
+	else if ((phydev->supported & SUPPORTED_1000baseKX_Full) ||
984fc8
+		 (phydev->supported & SUPPORTED_2500baseX_Full))
984fc8
+		ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX);
984fc8
+	else
984fc8
+		ret = -EINVAL;
984fc8
+	if (ret < 0) {
984fc8
+		enable_irq(priv->an_irq);
984fc8
+		return ret;
984fc8
+	}
984fc8
+
984fc8
+	/* Disable and stop any in progress auto-negotiation */
984fc8
+	ret = amd_xgbe_phy_disable_an(phydev);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Clear any auto-negotitation interrupts */
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0);
984fc8
+
984fc8
+	priv->an_result = AMD_XGBE_AN_READY;
984fc8
+	priv->an_state = AMD_XGBE_AN_READY;
984fc8
+	priv->kr_state = AMD_XGBE_RX_BPA;
984fc8
+	priv->kx_state = AMD_XGBE_RX_BPA;
984fc8
+
984fc8
+	/* Re-enable auto-negotiation interrupt */
984fc8
+	enable_irq(priv->an_irq);
984fc8
+
984fc8
+	/* Set up advertisement registers based on current settings */
984fc8
+	ret = amd_xgbe_an_init(phydev);
984fc8
+	if (ret)
984fc8
+		return ret;
984fc8
+
984fc8
+	/* Enable and start auto-negotiation */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_KR_CTRL);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret |= MDIO_KR_CTRL_PDETECT;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_KR_CTRL, ret);
984fc8
+
984fc8
+	return amd_xgbe_phy_restart_an(phydev);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_config_aneg(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	mutex_lock(&priv->an_mutex);
984fc8
+
984fc8
+	ret = __amd_xgbe_phy_config_aneg(phydev);
984fc8
+
984fc8
+	mutex_unlock(&priv->an_mutex);
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_aneg_done(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+
984fc8
+	return (priv->an_result == AMD_XGBE_AN_COMPLETE);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_update_link(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	unsigned int check_again, autoneg;
984fc8
+	int ret;
984fc8
+
984fc8
+	/* If we're doing auto-negotiation don't report link down */
984fc8
+	if (priv->an_state != AMD_XGBE_AN_READY) {
984fc8
+		phydev->link = 1;
984fc8
+		return 0;
984fc8
+	}
984fc8
+
984fc8
+	/* Since the device can be in the wrong mode when a link is
984fc8
+	 * (re-)established (cable connected after the interface is
984fc8
+	 * up, etc.), the link status may report no link. If there
984fc8
+	 * is no link, try switching modes and checking the status
984fc8
+	 * again if auto negotiation is enabled.
984fc8
+	 */
984fc8
+	check_again = (phydev->autoneg == AUTONEG_ENABLE) ? 1 : 0;
984fc8
+again:
984fc8
+	/* Link status is latched low, so read once to clear
984fc8
+	 * and then read again to get current state
984fc8
+	 */
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_STAT1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_STAT1);
984fc8
+	if (ret < 0)
984fc8
+		return ret;
984fc8
+
984fc8
+	phydev->link = (ret & MDIO_STAT1_LSTATUS) ? 1 : 0;
984fc8
+
984fc8
+	if (!phydev->link) {
984fc8
+		if (check_again) {
984fc8
+			ret = amd_xgbe_phy_switch_mode(phydev);
984fc8
+			if (ret < 0)
984fc8
+				return ret;
984fc8
+			check_again = 0;
984fc8
+			goto again;
984fc8
+		}
984fc8
+	}
984fc8
+
984fc8
+	autoneg = (phydev->link && !priv->link) ? 1 : 0;
984fc8
+	priv->link = phydev->link;
984fc8
+	if (autoneg) {
984fc8
+		/* Link is (back) up, re-start auto-negotiation */
984fc8
+		ret = amd_xgbe_phy_config_aneg(phydev);
984fc8
+		if (ret < 0)
984fc8
+			return ret;
984fc8
+	}
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_read_status(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	u32 mmd_mask = phydev->c45_ids.devices_in_package;
984fc8
+	int ret, ad_ret, lp_ret;
984fc8
+
984fc8
+	ret = amd_xgbe_phy_update_link(phydev);
984fc8
+	if (ret)
984fc8
+		return ret;
984fc8
+
984fc8
+	if ((phydev->autoneg == AUTONEG_ENABLE) &&
984fc8
+	    !priv->parallel_detect) {
984fc8
+		if (!(mmd_mask & MDIO_DEVS_AN))
984fc8
+			return -EINVAL;
984fc8
+
984fc8
+		if (!amd_xgbe_phy_aneg_done(phydev))
984fc8
+			return 0;
984fc8
+
984fc8
+		/* Compare Advertisement and Link Partner register 1 */
984fc8
+		ad_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
984fc8
+		if (ad_ret < 0)
984fc8
+			return ad_ret;
984fc8
+		lp_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA);
984fc8
+		if (lp_ret < 0)
984fc8
+			return lp_ret;
984fc8
+
984fc8
+		ad_ret &= lp_ret;
984fc8
+		phydev->pause = (ad_ret & 0x400) ? 1 : 0;
984fc8
+		phydev->asym_pause = (ad_ret & 0x800) ? 1 : 0;
984fc8
+
984fc8
+		/* Compare Advertisement and Link Partner register 2 */
984fc8
+		ad_ret = phy_read_mmd(phydev, MDIO_MMD_AN,
984fc8
+				      MDIO_AN_ADVERTISE + 1);
984fc8
+		if (ad_ret < 0)
984fc8
+			return ad_ret;
984fc8
+		lp_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 1);
984fc8
+		if (lp_ret < 0)
984fc8
+			return lp_ret;
984fc8
+
984fc8
+		ad_ret &= lp_ret;
984fc8
+		if (ad_ret & 0x80) {
984fc8
+			phydev->speed = SPEED_10000;
984fc8
+			ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR);
984fc8
+			if (ret)
984fc8
+				return ret;
984fc8
+		} else {
984fc8
+			switch (priv->speed_set) {
984fc8
+			case AMD_XGBE_PHY_SPEEDSET_1000_10000:
984fc8
+				phydev->speed = SPEED_1000;
984fc8
+				break;
984fc8
+
984fc8
+			case AMD_XGBE_PHY_SPEEDSET_2500_10000:
984fc8
+				phydev->speed = SPEED_2500;
984fc8
+				break;
984fc8
+			}
984fc8
+
984fc8
+			ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX);
984fc8
+			if (ret)
984fc8
+				return ret;
984fc8
+		}
984fc8
+
984fc8
+		phydev->duplex = DUPLEX_FULL;
984fc8
+	} else {
984fc8
+		if (amd_xgbe_phy_in_kr_mode(phydev)) {
984fc8
+			phydev->speed = SPEED_10000;
984fc8
+		} else {
984fc8
+			switch (priv->speed_set) {
984fc8
+			case AMD_XGBE_PHY_SPEEDSET_1000_10000:
984fc8
+				phydev->speed = SPEED_1000;
984fc8
+				break;
984fc8
+
984fc8
+			case AMD_XGBE_PHY_SPEEDSET_2500_10000:
984fc8
+				phydev->speed = SPEED_2500;
984fc8
+				break;
984fc8
+			}
984fc8
+		}
984fc8
+		phydev->duplex = DUPLEX_FULL;
984fc8
+		phydev->pause = 0;
984fc8
+		phydev->asym_pause = 0;
984fc8
+	}
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_suspend(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	int ret;
984fc8
+
984fc8
+	mutex_lock(&phydev->lock);
984fc8
+
984fc8
+	ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1);
984fc8
+	if (ret < 0)
984fc8
+		goto unlock;
984fc8
+
984fc8
+	priv->lpm_ctrl = ret;
984fc8
+
984fc8
+	ret |= MDIO_CTRL1_LPOWER;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret);
984fc8
+
984fc8
+	ret = 0;
984fc8
+
984fc8
+unlock:
984fc8
+	mutex_unlock(&phydev->lock);
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_resume(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+
984fc8
+	mutex_lock(&phydev->lock);
984fc8
+
984fc8
+	priv->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
984fc8
+	phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, priv->lpm_ctrl);
984fc8
+
984fc8
+	mutex_unlock(&phydev->lock);
984fc8
+
984fc8
+	return 0;
984fc8
+}
984fc8
+
984fc8
+static unsigned int amd_xgbe_phy_resource_count(struct platform_device *pdev,
984fc8
+						unsigned int type)
984fc8
+{
984fc8
+	unsigned int count;
984fc8
+	int i;
984fc8
+
984fc8
+	for (i = 0, count = 0; i < pdev->num_resources; i++) {
984fc8
+		struct resource *r = &pdev->resource[i];
984fc8
+
984fc8
+		if (type == resource_type(r))
984fc8
+			count++;
984fc8
+	}
984fc8
+
984fc8
+	return count;
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_phy_probe(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv;
984fc8
+	struct platform_device *phy_pdev;
984fc8
+	struct device *dev, *phy_dev;
984fc8
+	unsigned int phy_resnum, phy_irqnum;
984fc8
+	int ret;
984fc8
+
984fc8
+	if (!phydev->bus || !phydev->bus->parent)
984fc8
+		return -EINVAL;
984fc8
+
984fc8
+	dev = phydev->bus->parent;
984fc8
+
984fc8
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
984fc8
+	if (!priv)
984fc8
+		return -ENOMEM;
984fc8
+
984fc8
+	priv->pdev = to_platform_device(dev);
984fc8
+	priv->adev = ACPI_COMPANION(dev);
984fc8
+	priv->dev = dev;
984fc8
+	priv->phydev = phydev;
984fc8
+	mutex_init(&priv->an_mutex);
984fc8
+	INIT_WORK(&priv->an_irq_work, amd_xgbe_an_irq_work);
984fc8
+	INIT_WORK(&priv->an_work, amd_xgbe_an_state_machine);
984fc8
+
984fc8
+	if (!priv->adev || acpi_disabled) {
984fc8
+		struct device_node *bus_node;
984fc8
+		struct device_node *phy_node;
984fc8
+
984fc8
+		bus_node = priv->dev->of_node;
984fc8
+		phy_node = of_parse_phandle(bus_node, "phy-handle", 0);
984fc8
+		if (!phy_node) {
984fc8
+			dev_err(dev, "unable to parse phy-handle\n");
984fc8
+			ret = -EINVAL;
984fc8
+			goto err_priv;
984fc8
+		}
984fc8
+
984fc8
+		phy_pdev = of_find_device_by_node(phy_node);
984fc8
+		of_node_put(phy_node);
984fc8
+
984fc8
+		if (!phy_pdev) {
984fc8
+			dev_err(dev, "unable to obtain phy device\n");
984fc8
+			ret = -EINVAL;
984fc8
+			goto err_priv;
984fc8
+		}
984fc8
+
984fc8
+		phy_resnum = 0;
984fc8
+		phy_irqnum = 0;
984fc8
+	} else {
984fc8
+		/* In ACPI, the XGBE and PHY resources are the grouped
984fc8
+		 * together with the PHY resources at the end
984fc8
+		 */
984fc8
+		phy_pdev = priv->pdev;
984fc8
+		phy_resnum = amd_xgbe_phy_resource_count(phy_pdev,
984fc8
+							 IORESOURCE_MEM) - 2;
984fc8
+		phy_irqnum = amd_xgbe_phy_resource_count(phy_pdev,
984fc8
+							 IORESOURCE_IRQ) - 1;
984fc8
+	}
984fc8
+	phy_dev = &phy_pdev->dev;
984fc8
+
984fc8
+	/* Get the device mmio areas */
984fc8
+	priv->rxtx_res = platform_get_resource(phy_pdev, IORESOURCE_MEM,
984fc8
+					       phy_resnum++);
984fc8
+	priv->rxtx_regs = devm_ioremap_resource(dev, priv->rxtx_res);
984fc8
+	if (IS_ERR(priv->rxtx_regs)) {
984fc8
+		dev_err(dev, "rxtx ioremap failed\n");
984fc8
+		ret = PTR_ERR(priv->rxtx_regs);
984fc8
+		goto err_put;
984fc8
+	}
984fc8
+
984fc8
+	/* All xgbe phy devices share the CMU registers so retrieve
984fc8
+	 * the resource and do the ioremap directly rather than
984fc8
+	 * the devm_ioremap_resource call
984fc8
+	 */
984fc8
+	priv->cmu_res = platform_get_resource(phy_pdev, IORESOURCE_MEM,
984fc8
+					      phy_resnum++);
984fc8
+	if (!priv->cmu_res) {
984fc8
+		dev_err(dev, "cmu invalid resource\n");
984fc8
+		ret = -EINVAL;
984fc8
+		goto err_rxtx;
984fc8
+	}
984fc8
+	priv->cmu_regs = devm_ioremap_nocache(dev, priv->cmu_res->start,
984fc8
+					      resource_size(priv->cmu_res));
984fc8
+	if (!priv->cmu_regs) {
984fc8
+		dev_err(dev, "cmu ioremap failed\n");
984fc8
+		ret = -ENOMEM;
984fc8
+		goto err_rxtx;
984fc8
+	}
984fc8
+
984fc8
+	/* Get the auto-negotiation interrupt */
984fc8
+	ret = platform_get_irq(phy_pdev, phy_irqnum);
984fc8
+	if (ret < 0) {
984fc8
+		dev_err(dev, "platform_get_irq failed\n");
984fc8
+		goto err_cmu;
984fc8
+	}
984fc8
+	if (priv->adev && !acpi_disabled && !phy_irqnum) {
984fc8
+		struct irq_data *d = irq_get_irq_data(ret);
984fc8
+		if (!d) {
984fc8
+			dev_err(dev, "unable to set AN interrupt\n");
984fc8
+			ret = -EINVAL;
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+
984fc8
+#ifdef CONFIG_ACPI
984fc8
+		ret = acpi_register_gsi(dev, d->hwirq - 2,
984fc8
+					ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH);
984fc8
+#else
984fc8
+		ret = -EINVAL;
984fc8
+#endif
984fc8
+		if (ret < 0) {
984fc8
+			dev_err(dev, "unable to set AN interrupt\n");
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+	}
984fc8
+	priv->an_irq = ret;
984fc8
+
984fc8
+	/* Get the device serdes channel property */
984fc8
+	ret = device_property_read_u32(phy_dev, XGBE_PHY_CHANNEL_PROPERTY,
984fc8
+				       &priv->serdes_channel);
984fc8
+	if (ret) {
984fc8
+		dev_err(dev, "invalid %s property\n",
984fc8
+			XGBE_PHY_CHANNEL_PROPERTY);
984fc8
+		goto err_cmu;
984fc8
+	}
984fc8
+
984fc8
+	/* Get the device speed set property */
984fc8
+	ret = device_property_read_u32(phy_dev, XGBE_PHY_SPEEDSET_PROPERTY,
984fc8
+				       &priv->speed_set);
984fc8
+	if (ret) {
984fc8
+		dev_err(dev, "invalid %s property\n",
984fc8
+			XGBE_PHY_SPEEDSET_PROPERTY);
984fc8
+		goto err_cmu;
984fc8
+	}
984fc8
+
984fc8
+	switch (priv->speed_set) {
984fc8
+	case AMD_XGBE_PHY_SPEEDSET_1000_10000:
984fc8
+	case AMD_XGBE_PHY_SPEEDSET_2500_10000:
984fc8
+		break;
984fc8
+	default:
984fc8
+		dev_err(dev, "invalid %s property\n",
984fc8
+			XGBE_PHY_SPEEDSET_PROPERTY);
984fc8
+		ret = -EINVAL;
984fc8
+		goto err_cmu;
984fc8
+	}
984fc8
+
984fc8
+	if (device_property_present(phy_dev, XGBE_PHY_BLWC_PROPERTY)) {
984fc8
+		ret = device_property_read_u32_array(phy_dev,
984fc8
+						     XGBE_PHY_BLWC_PROPERTY,
984fc8
+						     priv->serdes_blwc,
984fc8
+						     XGBE_PHY_SPEEDS);
984fc8
+		if (ret) {
984fc8
+			dev_err(dev, "invalid %s property\n",
984fc8
+				XGBE_PHY_BLWC_PROPERTY);
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+	} else {
984fc8
+		memcpy(priv->serdes_blwc, amd_xgbe_phy_serdes_blwc,
984fc8
+		       sizeof(priv->serdes_blwc));
984fc8
+	}
984fc8
+
984fc8
+	if (device_property_present(phy_dev, XGBE_PHY_CDR_RATE_PROPERTY)) {
984fc8
+		ret = device_property_read_u32_array(phy_dev,
984fc8
+						     XGBE_PHY_CDR_RATE_PROPERTY,
984fc8
+						     priv->serdes_cdr_rate,
984fc8
+						     XGBE_PHY_SPEEDS);
984fc8
+		if (ret) {
984fc8
+			dev_err(dev, "invalid %s property\n",
984fc8
+				XGBE_PHY_CDR_RATE_PROPERTY);
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+	} else {
984fc8
+		memcpy(priv->serdes_cdr_rate, amd_xgbe_phy_serdes_cdr_rate,
984fc8
+		       sizeof(priv->serdes_cdr_rate));
984fc8
+	}
984fc8
+
984fc8
+	if (device_property_present(phy_dev, XGBE_PHY_PQ_SKEW_PROPERTY)) {
984fc8
+		ret = device_property_read_u32_array(phy_dev,
984fc8
+						     XGBE_PHY_PQ_SKEW_PROPERTY,
984fc8
+						     priv->serdes_pq_skew,
984fc8
+						     XGBE_PHY_SPEEDS);
984fc8
+		if (ret) {
984fc8
+			dev_err(dev, "invalid %s property\n",
984fc8
+				XGBE_PHY_PQ_SKEW_PROPERTY);
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+	} else {
984fc8
+		memcpy(priv->serdes_pq_skew, amd_xgbe_phy_serdes_pq_skew,
984fc8
+		       sizeof(priv->serdes_pq_skew));
984fc8
+	}
984fc8
+
984fc8
+	if (device_property_present(phy_dev, XGBE_PHY_TX_AMP_PROPERTY)) {
984fc8
+		ret = device_property_read_u32_array(phy_dev,
984fc8
+						     XGBE_PHY_TX_AMP_PROPERTY,
984fc8
+						     priv->serdes_tx_amp,
984fc8
+						     XGBE_PHY_SPEEDS);
984fc8
+		if (ret) {
984fc8
+			dev_err(dev, "invalid %s property\n",
984fc8
+				XGBE_PHY_TX_AMP_PROPERTY);
984fc8
+			goto err_cmu;
984fc8
+		}
984fc8
+	} else {
984fc8
+		memcpy(priv->serdes_tx_amp, amd_xgbe_phy_serdes_tx_amp,
984fc8
+		       sizeof(priv->serdes_tx_amp));
984fc8
+	}
984fc8
+
984fc8
+	priv->link = 1;
984fc8
+
984fc8
+	phydev->priv = priv;
984fc8
+
984fc8
+	if (!priv->adev || acpi_disabled)
984fc8
+		platform_device_put(phy_pdev);
984fc8
+
984fc8
+	return 0;
984fc8
+
984fc8
+err_cmu:
984fc8
+	devm_iounmap(dev, priv->cmu_regs);
984fc8
+
984fc8
+err_rxtx:
984fc8
+	devm_iounmap(dev, priv->rxtx_regs);
984fc8
+	devm_release_mem_region(dev, priv->rxtx_res->start,
984fc8
+				resource_size(priv->rxtx_res));
984fc8
+
984fc8
+err_put:
984fc8
+	if (!priv->adev || acpi_disabled)
984fc8
+		platform_device_put(phy_pdev);
984fc8
+
984fc8
+err_priv:
984fc8
+	devm_kfree(dev, priv);
984fc8
+
984fc8
+	return ret;
984fc8
+}
984fc8
+
984fc8
+static void amd_xgbe_phy_remove(struct phy_device *phydev)
984fc8
+{
984fc8
+	struct amd_xgbe_phy_priv *priv = phydev->priv;
984fc8
+	struct device *dev = priv->dev;
984fc8
+
984fc8
+	if (priv->an_irq_allocated) {
984fc8
+		devm_free_irq(dev, priv->an_irq, priv);
984fc8
+
984fc8
+		flush_workqueue(priv->an_workqueue);
984fc8
+		destroy_workqueue(priv->an_workqueue);
984fc8
+	}
984fc8
+
984fc8
+	devm_iounmap(dev, priv->cmu_regs);
984fc8
+
984fc8
+	devm_iounmap(dev, priv->rxtx_regs);
984fc8
+	devm_release_mem_region(dev, priv->rxtx_res->start,
984fc8
+				resource_size(priv->rxtx_res));
984fc8
+
984fc8
+	devm_kfree(dev, priv);
984fc8
+}
984fc8
+
984fc8
+static int amd_xgbe_match_phy_device(struct phy_device *phydev)
984fc8
+{
984fc8
+	return phydev->c45_ids.device_ids[MDIO_MMD_PCS] == XGBE_PHY_ID;
984fc8
+}
984fc8
+
984fc8
+static struct phy_driver amd_xgbe_phy_a0_driver[] = {
984fc8
+	{
984fc8
+		.phy_id			= XGBE_PHY_ID,
984fc8
+		.phy_id_mask		= XGBE_PHY_MASK,
984fc8
+		.name			= "AMD XGBE PHY A0",
984fc8
+		.features		= 0,
984fc8
+		.probe			= amd_xgbe_phy_probe,
984fc8
+		.remove			= amd_xgbe_phy_remove,
984fc8
+		.soft_reset		= amd_xgbe_phy_soft_reset,
984fc8
+		.config_init		= amd_xgbe_phy_config_init,
984fc8
+		.suspend		= amd_xgbe_phy_suspend,
984fc8
+		.resume			= amd_xgbe_phy_resume,
984fc8
+		.config_aneg		= amd_xgbe_phy_config_aneg,
984fc8
+		.aneg_done		= amd_xgbe_phy_aneg_done,
984fc8
+		.read_status		= amd_xgbe_phy_read_status,
984fc8
+		.match_phy_device	= amd_xgbe_match_phy_device,
984fc8
+		.driver			= {
984fc8
+			.owner = THIS_MODULE,
984fc8
+		},
984fc8
+	},
984fc8
+};
984fc8
+
984fc8
+module_phy_driver(amd_xgbe_phy_a0_driver);
984fc8
+
984fc8
+static struct mdio_device_id __maybe_unused amd_xgbe_phy_a0_ids[] = {
984fc8
+	{ XGBE_PHY_ID, XGBE_PHY_MASK },
984fc8
+	{ }
984fc8
+};
984fc8
+MODULE_DEVICE_TABLE(mdio, amd_xgbe_phy_a0_ids);
c3a494
-- 
c3a494
2.4.5
c3a494