2018-08-13 07:45:38

by Ooi, Joyce

[permalink] [raw]
Subject: [PATCH] net: stmmac: Add SMC support for EMAC System Manager register

As there is restriction to access to EMAC System Manager registers in
the kernel for Intel Stratix10, the use of SMC calls are required and
added in dwmac-socfpga driver.

Signed-off-by: Ooi, Joyce <[email protected]>
---
This patch is dependent on https://lkml.org/lkml/2018/7/26/624
---
.../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 74 +++++++++++++++++++-
1 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index c3a78c1..2cea97d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -23,6 +23,9 @@
#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/stmmac.h>
+#ifdef CONFIG_HAVE_ARM_SMCCC
+#include <linux/stratix10-smc.h>
+#endif

#include "stmmac.h"
#include "stmmac_platform.h"
@@ -52,6 +55,7 @@ struct socfpga_dwmac {
int interface;
u32 reg_offset;
u32 reg_shift;
+ u32 sysmgr_reg;
struct device *dev;
struct regmap *sys_mgr_base_addr;
struct reset_control *stmmac_rst;
@@ -61,6 +65,48 @@ struct socfpga_dwmac {
struct tse_pcs pcs;
};

+#ifdef CONFIG_HAVE_ARM_SMCCC
+/**************** Stratix 10 EMAC Memory Controller Functions ************/
+
+/* s10_protected_reg_write
+ * Write to a protected SMC register.
+ * @reg: Address of register
+ * @value: Value to write
+ * Return: INTEL_SIP_SMC_STATUS_OK (0) on success
+ * INTEL_SIP_SMC_REG_ERROR on error
+ * INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION if not supported
+ */
+static int s10_protected_reg_write(unsigned int reg, unsigned int val)
+{
+ struct arm_smccc_res result;
+
+ arm_smccc_smc(INTEL_SIP_SMC_REG_WRITE, reg, val, 0, 0,
+ 0, 0, 0, &result);
+
+ return (int)result.a0;
+}
+
+/* s10_protected_reg_read
+ * Read the status of a protected SMC register
+ * @reg: Address of register
+ * @value: Value read.
+ * Return: INTEL_SIP_SMC_STATUS_OK (0) on success
+ * INTEL_SIP_SMC_REG_ERROR on error
+ * INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION if not supported
+ */
+static int s10_protected_reg_read(unsigned int reg, unsigned int *val)
+{
+ struct arm_smccc_res result;
+
+ arm_smccc_smc(INTEL_SIP_SMC_REG_READ, reg, 0, 0, 0,
+ 0, 0, 0, &result);
+
+ *val = (unsigned int)result.a1;
+
+ return (int)result.a0;
+}
+#endif
+
static void socfpga_dwmac_fix_mac_speed(void *priv, unsigned int speed)
{
struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)priv;
@@ -104,10 +150,11 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
{
struct device_node *np = dev->of_node;
struct regmap *sys_mgr_base_addr;
- u32 reg_offset, reg_shift;
+ u32 reg_offset, reg_shift, sysmgr_reg;
int ret, index;
struct device_node *np_splitter = NULL;
struct device_node *np_sgmii_adapter = NULL;
+ struct device_node *np_sysmgr = NULL;
struct resource res_splitter;
struct resource res_tse_pcs;
struct resource res_sgmii_adapter;
@@ -132,6 +179,16 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
return -EINVAL;
}

+ np_sysmgr = of_parse_phandle(np, "altr,sysmgr-syscon", 0);
+ if (np_sysmgr) {
+ ret = of_property_read_u32_index(np_sysmgr, "reg", 0,
+ &sysmgr_reg);
+ if (ret) {
+ dev_info(dev, "Could not read sysmgr register address\n");
+ return -EINVAL;
+ }
+ }
+
dwmac->f2h_ptp_ref_clk = of_property_read_bool(np, "altr,f2h_ptp_ref_clk");

np_splitter = of_parse_phandle(np, "altr,emac-splitter", 0);
@@ -221,6 +278,7 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
}
dwmac->reg_offset = reg_offset;
dwmac->reg_shift = reg_shift;
+ dwmac->sysmgr_reg = sysmgr_reg;
dwmac->sys_mgr_base_addr = sys_mgr_base_addr;
dwmac->dev = dev;
of_node_put(np_sgmii_adapter);
@@ -238,7 +296,9 @@ static int socfpga_dwmac_set_phy_mode(struct socfpga_dwmac *dwmac)
int phymode = dwmac->interface;
u32 reg_offset = dwmac->reg_offset;
u32 reg_shift = dwmac->reg_shift;
+ u32 sysmgr_reg = dwmac->sysmgr_reg;
u32 ctrl, val, module;
+ int ret = 0;

switch (phymode) {
case PHY_INTERFACE_MODE_RGMII:
@@ -266,7 +326,13 @@ static int socfpga_dwmac_set_phy_mode(struct socfpga_dwmac *dwmac)
reset_control_assert(dwmac->stmmac_ocp_rst);
reset_control_assert(dwmac->stmmac_rst);

+#ifdef CONFIG_HAVE_ARM_SMCCC
+ ret = s10_protected_reg_read(sysmgr_reg + reg_offset, &ctrl);
+ if (ret)
+ dev_err(dwmac->dev, "error reading Sys Mgr %d\n", ret);
+#else
regmap_read(sys_mgr_base_addr, reg_offset, &ctrl);
+#endif
ctrl &= ~(SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << reg_shift);
ctrl |= val << reg_shift;

@@ -281,7 +347,13 @@ static int socfpga_dwmac_set_phy_mode(struct socfpga_dwmac *dwmac)
ctrl &= ~(SYSMGR_EMACGRP_CTRL_PTP_REF_CLK_MASK << (reg_shift / 2));
}

+#ifdef CONFIG_HAVE_ARM_SMCCC
+ ret = s10_protected_reg_write(sysmgr_reg + reg_offset, ctrl);
+ if (ret)
+ dev_err(dwmac->dev, "error writing Sys Mgr %d\n", ret);
+#else
regmap_write(sys_mgr_base_addr, reg_offset, ctrl);
+#endif

/* Deassert reset for the phy configuration to be sampled by
* the enet controller, and operation to start in requested mode
--
1.7.1



2018-08-13 17:54:03

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: stmmac: Add SMC support for EMAC System Manager register

From: "Ooi, Joyce" <[email protected]>
Date: Sun, 12 Aug 2018 23:41:34 -0700

> As there is restriction to access to EMAC System Manager registers in
> the kernel for Intel Stratix10, the use of SMC calls are required and
> added in dwmac-socfpga driver.
>
> Signed-off-by: Ooi, Joyce <[email protected]>
> ---
> This patch is dependent on https://lkml.org/lkml/2018/7/26/624

I guess I cannot apply this to my networking tree then.

I would suggest that you make a helper in a header file which dos the
special SMC EMAC accesses, or alternatively the regular regmap access,
based upon the CPP ifdef.

That way you won't have to put all of those CPP tests in the foo.c
code.

Thanks.

2018-08-13 21:43:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] net: stmmac: Add SMC support for EMAC System Manager register

Hi Joyce,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on v4.18 next-20180813]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Ooi-Joyce/net-stmmac-Add-SMC-support-for-EMAC-System-Manager-register/20180814-031821
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm

All errors (new ones prefixed by >>):

>> drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c:27:10: fatal error: linux/stratix10-smc.h: No such file or directory
#include <linux/stratix10-smc.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

vim +27 drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c

> 27 #include <linux/stratix10-smc.h>
28 #endif
29

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.30 kB)
.config.gz (42.94 kB)
Download all attachments

2018-08-16 07:54:23

by Ooi, Joyce

[permalink] [raw]
Subject: RE: [PATCH] net: stmmac: Add SMC support for EMAC System Manager register

> -----Original Message-----
> From: David Miller [mailto:[email protected]]
> Sent: Tuesday, August 14, 2018 12:48 AM
> To: Ooi, Joyce <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> Ong, Hean Loong <[email protected]>; Vandervennet, Yves
> <[email protected]>
> Subject: Re: [PATCH] net: stmmac: Add SMC support for EMAC System Manager
> register
>
> From: "Ooi, Joyce" <[email protected]>
> Date: Sun, 12 Aug 2018 23:41:34 -0700
>
> > As there is restriction to access to EMAC System Manager registers in
> > the kernel for Intel Stratix10, the use of SMC calls are required and
> > added in dwmac-socfpga driver.
> >
> > Signed-off-by: Ooi, Joyce <[email protected]>
> > ---
> > This patch is dependent on https://lkml.org/lkml/2018/7/26/624
>
> I guess I cannot apply this to my networking tree then.
>
> I would suggest that you make a helper in a header file which dos the special
> SMC EMAC accesses, or alternatively the regular regmap access, based upon the
> CPP ifdef.
Could you please explain what you mean by 'a helper in a header file'?

Thanks.
>
> That way you won't have to put all of those CPP tests in the foo.c code.
>
> Thanks.