Commit 5e7350e8 authored by David S. Miller's avatar David S. Miller

Merge branch 'dpaa2-mac-protocol-change'

Ioana Ciornei says:

====================
dpaa2-mac: add support for changing the protocol at runtime

This patch set adds support for changing the Ethernet protocol at
runtime on Layerscape SoCs which have the Lynx 28G SerDes block.

The first two patches add a new generic PHY driver for the Lynx 28G and
the bindings file associated. The driver reads the PLL configuration at
probe time (the frequency provided to the lanes) and determines what
protocols can be supported.
Based on this the driver can deny or approve a request from the
dpaa2-mac to setup a new protocol.

The next 2 patches add some MC APIs for inquiring what is the running
version of firmware and setting up a new protocol on the MAC.

Moving along, we extract the code for setting up the supported
interfaces on a MAC on a different function since in the next patches
will update the logic.

In the next patch, the dpaa2-mac is updated so that it retrieves the
SerDes PHY based on the OF node and in case of a major reconfig, call
the PHY driver to set up the new protocol on the associated lane and the
MC firmware to reconfigure the MAC side of things.

Finally, the LX2160A dtsi is annotated with the SerDes PHY nodes for the
1st SerDes block. Beside this, the LX2160A Clearfog dtsi is annotated
with the 'phys' property for the exposed SFP cages.

Changes in v2:
	- 1/8: add MODULE_LICENSE
Changes in v3:
	- 2/8: fix 'make dt_binding_check' errors
	- 7/8: reverse order of dpaa2_mac_start() and phylink_start()
	- 7/8: treat all RGMII variants in dpmac_eth_if_mode
	- 7/8: remove the .mac_prepare callback
	- 7/8: ignore PHY_INTERFACE_MODE_NA in validate
Changes in v4:
	- 1/8: remove the DT nodes parsing
	- 1/8: add an xlate function
	- 2/8: remove the children phy nodes for each lane
	- 7/8: rework the of_phy_get if statement
	- 8/8: remove the DT nodes for each lane and the lane id in the
	  phys phandle
Changes in v5:
	- 2/8: use phy as the name of the DT node in the example
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 92ebb236 3cbe93a1
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/phy/fsl,lynx-28g.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Freescale Lynx 28G SerDes PHY binding
maintainers:
- Ioana Ciornei <ioana.ciornei@nxp.com>
properties:
compatible:
enum:
- fsl,lynx-28g
reg:
maxItems: 1
"#phy-cells":
const: 1
required:
- compatible
- reg
- "#phy-cells"
additionalProperties: false
examples:
- |
soc {
#address-cells = <2>;
#size-cells = <2>;
serdes_1: phy@1ea0000 {
compatible = "fsl,lynx-28g";
reg = <0x0 0x1ea0000 0x0 0x1e30>;
#phy-cells = <1>;
};
};
......@@ -11333,6 +11333,13 @@ S: Maintained
W: http://linux-test-project.github.io/
T: git git://github.com/linux-test-project/ltp.git
LYNX 28G SERDES PHY DRIVER
M: Ioana Ciornei <ioana.ciornei@nxp.com>
L: netdev@vger.kernel.org
S: Supported
F: Documentation/devicetree/bindings/phy/fsl,lynx-28g.yaml
F: drivers/phy/freescale/phy-fsl-lynx-28g.c
LYNX PCS MODULE
M: Ioana Ciornei <ioana.ciornei@nxp.com>
L: netdev@vger.kernel.org
......
......@@ -63,21 +63,25 @@ sfp3: sfp-3 {
&dpmac7 {
sfp = <&sfp0>;
managed = "in-band-status";
phys = <&serdes_1 3>;
};
&dpmac8 {
sfp = <&sfp1>;
managed = "in-band-status";
phys = <&serdes_1 2>;
};
&dpmac9 {
sfp = <&sfp2>;
managed = "in-band-status";
phys = <&serdes_1 1>;
};
&dpmac10 {
sfp = <&sfp3>;
managed = "in-band-status";
phys = <&serdes_1 0>;
};
&emdio2 {
......
......@@ -612,6 +612,12 @@ soc {
ranges;
dma-ranges = <0x0 0x0 0x0 0x0 0x10000 0x00000000>;
serdes_1: phy@1ea0000 {
compatible = "fsl,lynx-28g";
reg = <0x0 0x1ea0000 0x0 0x1e30>;
#phy-cells = <1>;
};
crypto: crypto@8000000 {
compatible = "fsl,sec-v5.0", "fsl,sec-v4.0";
fsl,sec-era = <10>;
......
......@@ -2077,8 +2077,10 @@ static int dpaa2_eth_open(struct net_device *net_dev)
goto enable_err;
}
if (dpaa2_eth_is_type_phy(priv))
if (dpaa2_eth_is_type_phy(priv)) {
dpaa2_mac_start(priv->mac);
phylink_start(priv->mac->phylink);
}
return 0;
......@@ -2153,6 +2155,7 @@ static int dpaa2_eth_stop(struct net_device *net_dev)
if (dpaa2_eth_is_type_phy(priv)) {
phylink_stop(priv->mac->phylink);
dpaa2_mac_stop(priv->mac);
} else {
netif_tx_stop_all_queues(net_dev);
netif_carrier_off(net_dev);
......
......@@ -3,6 +3,7 @@
#include <linux/acpi.h>
#include <linux/pcs-lynx.h>
#include <linux/phy/phy.h>
#include <linux/property.h>
#include "dpaa2-eth.h"
......@@ -11,6 +12,28 @@
#define phylink_to_dpaa2_mac(config) \
container_of((config), struct dpaa2_mac, phylink_config)
#define DPMAC_PROTOCOL_CHANGE_VER_MAJOR 4
#define DPMAC_PROTOCOL_CHANGE_VER_MINOR 8
#define DPAA2_MAC_FEATURE_PROTOCOL_CHANGE BIT(0)
static int dpaa2_mac_cmp_ver(struct dpaa2_mac *mac,
u16 ver_major, u16 ver_minor)
{
if (mac->ver_major == ver_major)
return mac->ver_minor - ver_minor;
return mac->ver_major - ver_major;
}
static void dpaa2_mac_detect_features(struct dpaa2_mac *mac)
{
mac->features = 0;
if (dpaa2_mac_cmp_ver(mac, DPMAC_PROTOCOL_CHANGE_VER_MAJOR,
DPMAC_PROTOCOL_CHANGE_VER_MINOR) >= 0)
mac->features |= DPAA2_MAC_FEATURE_PROTOCOL_CHANGE;
}
static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
{
*if_mode = PHY_INTERFACE_MODE_NA;
......@@ -38,6 +61,29 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
return 0;
}
static enum dpmac_eth_if dpmac_eth_if_mode(phy_interface_t if_mode)
{
switch (if_mode) {
case PHY_INTERFACE_MODE_RGMII:
case PHY_INTERFACE_MODE_RGMII_ID:
case PHY_INTERFACE_MODE_RGMII_RXID:
case PHY_INTERFACE_MODE_RGMII_TXID:
return DPMAC_ETH_IF_RGMII;
case PHY_INTERFACE_MODE_USXGMII:
return DPMAC_ETH_IF_USXGMII;
case PHY_INTERFACE_MODE_QSGMII:
return DPMAC_ETH_IF_QSGMII;
case PHY_INTERFACE_MODE_SGMII:
return DPMAC_ETH_IF_SGMII;
case PHY_INTERFACE_MODE_10GBASER:
return DPMAC_ETH_IF_XFI;
case PHY_INTERFACE_MODE_1000BASEX:
return DPMAC_ETH_IF_1000BASEX;
default:
return DPMAC_ETH_IF_MII;
}
}
static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
u16 dpmac_id)
{
......@@ -125,6 +171,19 @@ static void dpaa2_mac_config(struct phylink_config *config, unsigned int mode,
if (err)
netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n",
__func__, err);
if (!mac->serdes_phy)
return;
/* This happens only if we support changing of protocol at runtime */
err = dpmac_set_protocol(mac->mc_io, 0, mac->mc_dev->mc_handle,
dpmac_eth_if_mode(state->interface));
if (err)
netdev_err(mac->net_dev, "dpmac_set_protocol() = %d\n", err);
err = phy_set_mode_ext(mac->serdes_phy, PHY_MODE_ETHERNET, state->interface);
if (err)
netdev_err(mac->net_dev, "phy_set_mode_ext() = %d\n", err);
}
static void dpaa2_mac_link_up(struct phylink_config *config,
......@@ -235,10 +294,66 @@ static void dpaa2_pcs_destroy(struct dpaa2_mac *mac)
}
}
static void dpaa2_mac_set_supported_interfaces(struct dpaa2_mac *mac)
{
int intf, err;
/* We support the current interface mode, and if we have a PCS
* similar interface modes that do not require the SerDes lane to be
* reconfigured.
*/
__set_bit(mac->if_mode, mac->phylink_config.supported_interfaces);
if (mac->pcs) {
switch (mac->if_mode) {
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_SGMII:
__set_bit(PHY_INTERFACE_MODE_1000BASEX,
mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_SGMII,
mac->phylink_config.supported_interfaces);
break;
default:
break;
}
}
if (!mac->serdes_phy)
return;
/* In case we have access to the SerDes phy/lane, then ask the SerDes
* driver what interfaces are supported based on the current PLL
* configuration.
*/
for (intf = 0; intf < PHY_INTERFACE_MODE_MAX; intf++) {
if (intf == PHY_INTERFACE_MODE_NA)
continue;
err = phy_validate(mac->serdes_phy, PHY_MODE_ETHERNET, intf, NULL);
if (err)
continue;
__set_bit(intf, mac->phylink_config.supported_interfaces);
}
}
void dpaa2_mac_start(struct dpaa2_mac *mac)
{
if (mac->serdes_phy)
phy_power_on(mac->serdes_phy);
}
void dpaa2_mac_stop(struct dpaa2_mac *mac)
{
if (mac->serdes_phy)
phy_power_off(mac->serdes_phy);
}
int dpaa2_mac_connect(struct dpaa2_mac *mac)
{
struct net_device *net_dev = mac->net_dev;
struct fwnode_handle *dpmac_node;
struct phy *serdes_phy = NULL;
struct phylink *phylink;
int err;
......@@ -255,6 +370,20 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
return -EINVAL;
mac->if_mode = err;
if (mac->features & DPAA2_MAC_FEATURE_PROTOCOL_CHANGE &&
!phy_interface_mode_is_rgmii(mac->if_mode) &&
is_of_node(dpmac_node)) {
serdes_phy = of_phy_get(to_of_node(dpmac_node), NULL);
if (serdes_phy == ERR_PTR(-ENODEV))
serdes_phy = NULL;
else if (IS_ERR(serdes_phy))
return PTR_ERR(serdes_phy);
else
phy_init(serdes_phy);
}
mac->serdes_phy = serdes_phy;
/* The MAC does not have the capability to add RGMII delays so
* error out if the interface mode requests them and there is no PHY
* to act upon them
......@@ -283,25 +412,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FD | MAC_5000FD |
MAC_10000FD;
/* We support the current interface mode, and if we have a PCS
* similar interface modes that do not require the PLLs to be
* reconfigured.
*/
__set_bit(mac->if_mode, mac->phylink_config.supported_interfaces);
if (mac->pcs) {
switch (mac->if_mode) {
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_SGMII:
__set_bit(PHY_INTERFACE_MODE_1000BASEX,
mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_SGMII,
mac->phylink_config.supported_interfaces);
break;
default:
break;
}
}
dpaa2_mac_set_supported_interfaces(mac);
phylink = phylink_create(&mac->phylink_config,
dpmac_node, mac->if_mode,
......@@ -336,6 +447,8 @@ void dpaa2_mac_disconnect(struct dpaa2_mac *mac)
phylink_disconnect_phy(mac->phylink);
phylink_destroy(mac->phylink);
dpaa2_pcs_destroy(mac);
of_phy_put(mac->serdes_phy);
mac->serdes_phy = NULL;
}
int dpaa2_mac_open(struct dpaa2_mac *mac)
......@@ -359,6 +472,14 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
goto err_close_dpmac;
}
err = dpmac_get_api_version(mac->mc_io, 0, &mac->ver_major, &mac->ver_minor);
if (err) {
netdev_err(net_dev, "dpmac_get_api_version() = %d\n", err);
goto err_close_dpmac;
}
dpaa2_mac_detect_features(mac);
/* Find the device node representing the MAC device and link the device
* behind the associated netdev to it.
*/
......
......@@ -17,6 +17,8 @@ struct dpaa2_mac {
struct net_device *net_dev;
struct fsl_mc_io *mc_io;
struct dpmac_attr attr;
u16 ver_major, ver_minor;
unsigned long features;
struct phylink_config phylink_config;
struct phylink *phylink;
......@@ -24,6 +26,8 @@ struct dpaa2_mac {
enum dpmac_link_type if_link_type;
struct phylink_pcs *pcs;
struct fwnode_handle *fw_node;
struct phy *serdes_phy;
};
bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev,
......@@ -43,4 +47,8 @@ void dpaa2_mac_get_strings(u8 *data);
void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data);
void dpaa2_mac_start(struct dpaa2_mac *mac);
void dpaa2_mac_stop(struct dpaa2_mac *mac);
#endif /* DPAA2_MAC_H */
......@@ -703,8 +703,10 @@ static int dpaa2_switch_port_open(struct net_device *netdev)
dpaa2_switch_enable_ctrl_if_napi(ethsw);
if (dpaa2_switch_port_is_type_phy(port_priv))
if (dpaa2_switch_port_is_type_phy(port_priv)) {
dpaa2_mac_start(port_priv->mac);
phylink_start(port_priv->mac->phylink);
}
return 0;
}
......@@ -717,6 +719,7 @@ static int dpaa2_switch_port_stop(struct net_device *netdev)
if (dpaa2_switch_port_is_type_phy(port_priv)) {
phylink_stop(port_priv->mac->phylink);
dpaa2_mac_stop(port_priv->mac);
} else {
netif_tx_stop_all_queues(netdev);
netif_carrier_off(netdev);
......
......@@ -19,11 +19,15 @@
#define DPMAC_CMDID_CLOSE DPMAC_CMD(0x800)
#define DPMAC_CMDID_OPEN DPMAC_CMD(0x80c)
#define DPMAC_CMDID_GET_API_VERSION DPMAC_CMD(0xa0c)
#define DPMAC_CMDID_GET_ATTR DPMAC_CMD(0x004)
#define DPMAC_CMDID_SET_LINK_STATE DPMAC_CMD_V2(0x0c3)
#define DPMAC_CMDID_GET_COUNTER DPMAC_CMD(0x0c4)
#define DPMAC_CMDID_SET_PROTOCOL DPMAC_CMD(0x0c7)
/* Macros for accessing command fields smaller than 1byte */
#define DPMAC_MASK(field) \
GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \
......@@ -70,4 +74,12 @@ struct dpmac_rsp_get_counter {
__le64 counter;
};
struct dpmac_rsp_get_api_version {
__le16 major;
__le16 minor;
};
struct dpmac_cmd_set_protocol {
u8 eth_if;
};
#endif /* _FSL_DPMAC_CMD_H */
......@@ -181,3 +181,57 @@ int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
return 0;
}
/**
* dpmac_get_api_version() - Get Data Path MAC version
* @mc_io: Pointer to MC portal's I/O object
* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
* @major_ver: Major version of data path mac API
* @minor_ver: Minor version of data path mac API
*
* Return: '0' on Success; Error code otherwise.
*/
int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
u16 *major_ver, u16 *minor_ver)
{
struct dpmac_rsp_get_api_version *rsp_params;
struct fsl_mc_command cmd = { 0 };
int err;
cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION,
cmd_flags,
0);
err = mc_send_command(mc_io, &cmd);
if (err)
return err;
rsp_params = (struct dpmac_rsp_get_api_version *)cmd.params;
*major_ver = le16_to_cpu(rsp_params->major);
*minor_ver = le16_to_cpu(rsp_params->minor);
return 0;
}
/**
* dpmac_set_protocol() - Reconfigure the DPMAC protocol
* @mc_io: Pointer to opaque I/O object
* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
* @token: Token of DPMAC object
* @protocol: New protocol for the DPMAC to be reconfigured in.
*
* Return: '0' on Success; Error code otherwise.
*/
int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
enum dpmac_eth_if protocol)
{
struct dpmac_cmd_set_protocol *cmd_params;
struct fsl_mc_command cmd = { 0 };
cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_PROTOCOL,
cmd_flags, token);
cmd_params = (struct dpmac_cmd_set_protocol *)cmd.params;
cmd_params->eth_if = protocol;
return mc_send_command(mc_io, &cmd);
}
......@@ -205,4 +205,9 @@ enum dpmac_counter_id {
int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
enum dpmac_counter_id id, u64 *value);
int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
u16 *major_ver, u16 *minor_ver);
int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
enum dpmac_eth_if protocol);
#endif /* __FSL_DPMAC_H */
......@@ -22,3 +22,13 @@ config PHY_FSL_IMX8M_PCIE
help
Enable this to add support for the PCIE PHY as found on
i.MX8M family of SOCs.
config PHY_FSL_LYNX_28G
tristate "Freescale Layerscape Lynx 28G SerDes PHY support"
depends on OF
select GENERIC_PHY
help
Enable this to add support for the Lynx SerDes 28G PHY as
found on NXP's Layerscape platforms such as LX2160A.
Used to change the protocol running on SerDes lanes at runtime.
Only useful for a restricted set of Ethernet protocols.
......@@ -2,3 +2,4 @@
obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o
obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-fsl-imx8-mipi-dphy.o
obj-$(CONFIG_PHY_FSL_IMX8M_PCIE) += phy-fsl-imx8m-pcie.o
obj-$(CONFIG_PHY_FSL_LYNX_28G) += phy-fsl-lynx-28g.o
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment