From: Yisen Zhuang <Yisen.Zhuang@huawei.com>
To: <devicetree@vger.kernel.org>, <netdev@vger.kernel.org>
Cc: <robh+dt@kernel.org>, <pawel.moll@arm.com>,
<mark.rutland@arm.com>, <ijc+devicetree@hellion.org.uk>,
<galak@codeaurora.org>, <davem@davemloft.net>,
<yankejian@huawei.com>, <huangdaode@hisilicon.com>,
<salil.mehta@huawei.com>, <lipeng321@huawei.com>,
<liguozhu@huawei.com>, <xieqianqian@huawei.com>,
<linuxarm@huawei.com>
Subject: [PATCH net-next 10/10] net: hns: add attribute port-mode-offset for dsaf port node
Date: Fri, 22 Apr 2016 15:20:19 +0800 [thread overview]
Message-ID: <1461309619-167621-11-git-send-email-Yisen.Zhuang@huawei.com> (raw)
In-Reply-To: <1461309619-167621-1-git-send-email-Yisen.Zhuang@huawei.com>
Port mode offset for each dsaf port is different. The current code is not
so readability. This patch adds configuration named port-mode-offset to
make the code more simple and readability. If port-mode-offset doesn't
exist, default value 0 will be used.
Signed-off-by: Daode Huang <huangdaode@hisilicon.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
---
.../devicetree/bindings/net/hisilicon-hns-dsaf.txt | 3 +-
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 10 +++++
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h | 1 +
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 44 ++++++++++------------
4 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt b/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt
index 2afc3fa..5ccd4f0 100644
--- a/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt
+++ b/Documentation/devicetree/bindings/net/hisilicon-hns-dsaf.txt
@@ -45,7 +45,8 @@ Required properties:
cpld-syscon.
- port-rst-offset: is offset of reset field for each port in dsaf. Its value
depends on the hardware user manual.
-
+- port-mode-offset: is offset of port mode field for each port in dsaf. Its
+ value depends on the hardware user manual.
[1] Documentation/devicetree/bindings/net/phy.txt
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 52d757d..1c8fdd3 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -665,6 +665,7 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->max_frm = MAC_DEFAULT_MTU;
mac_cb->tx_pause_frm_time = MAC_DEFAULT_PAUSE_TIME;
mac_cb->port_rst_off = mac_cb->mac_id;
+ mac_cb->port_mode_off = 0;
/* if the dsaf node doesn't contain a port subnode, get phy-handle
* from dsaf node
@@ -703,6 +704,15 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id);
}
+ ret = fwnode_property_read_u32(mac_cb->fw_port,
+ "port-mode-offset",
+ &mac_cb->port_mode_off);
+ if (ret) {
+ dev_dbg(mac_cb->dev,
+ "mac%d port-mode-offset not found, use default value.\n",
+ mac_cb->mac_id);
+ }
+
syscon = syscon_node_to_regmap(
of_parse_phandle(to_of_node(mac_cb->fw_port),
"cpld-syscon", 0));
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index 7be7104..97ce9a7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -319,6 +319,7 @@ struct hns_mac_cb {
struct regmap *cpld_ctrl;
u32 cpld_ctrl_reg;
u32 port_rst_off;
+ u32 port_mode_off;
struct mac_entry_idx addr_entry_idx[DSAF_MAX_VM_NUM];
u8 sfp_prsnt;
u8 cpld_led_value;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index e549a11..a837bb9 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -265,37 +265,31 @@ phy_interface_t hns_mac_get_phy_if(struct hns_mac_cb *mac_cb)
{
u32 mode;
u32 reg;
- u32 shift;
- u32 phy_offset;
bool is_ver1 = AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver);
int mac_id = mac_cb->mac_id;
- phy_interface_t phy_if = PHY_INTERFACE_MODE_NA;
+ phy_interface_t phy_if;
- if (is_ver1 && HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) {
- phy_if = PHY_INTERFACE_MODE_SGMII;
- } else if (mac_id >= 0 && mac_id <= 3 &&
- !HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) {
- reg = is_ver1 ? HNS_MAC_HILINK4_REG : HNS_MAC_HILINK4V2_REG;
- mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
- /* mac_id 0, 1, 2, 3 ---> hilink4 lane 0, 1, 2, 3 */
- shift = is_ver1 ? 0 : mac_id;
- if (dsaf_get_bit(mode, shift))
- phy_if = PHY_INTERFACE_MODE_XGMII;
+ if (is_ver1) {
+ if (HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev))
+ return PHY_INTERFACE_MODE_SGMII;
+
+ if (mac_id >= 0 && mac_id <= 3)
+ reg = HNS_MAC_HILINK4_REG;
else
- phy_if = PHY_INTERFACE_MODE_SGMII;
- } else {
- reg = is_ver1 ? HNS_MAC_HILINK3_REG : HNS_MAC_HILINK3V2_REG;
- mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
- /* mac_id 4, 5,---> hilink3 lane 2, 3
- * debug port 0(6), 1(7) ---> hilink3 lane 0, 1
- */
- phy_offset = mac_cb->dsaf_dev->reset_offset - 1;
- shift = is_ver1 ? 0 : mac_id >= 4 ? mac_id - 2 : phy_offset;
- if (dsaf_get_bit(mode, shift))
- phy_if = PHY_INTERFACE_MODE_XGMII;
+ reg = HNS_MAC_HILINK3_REG;
+ } else{
+ if (!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev) && mac_id <= 3)
+ reg = HNS_MAC_HILINK4V2_REG;
else
- phy_if = PHY_INTERFACE_MODE_SGMII;
+ reg = HNS_MAC_HILINK3V2_REG;
}
+
+ mode = dsaf_read_sub(mac_cb->dsaf_dev, reg);
+ if (dsaf_get_bit(mode, mac_cb->port_mode_off))
+ phy_if = PHY_INTERFACE_MODE_XGMII;
+ else
+ phy_if = PHY_INTERFACE_MODE_SGMII;
+
return phy_if;
}
--
1.9.1
next prev parent reply other threads:[~2016-04-22 7:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 7:20 [PATCH net-next 00/10] net: hns: add support of debug dsaf device Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 02/10] net: hns: set debug port irq index to 0 Yisen Zhuang
[not found] ` <1461309619-167621-1-git-send-email-Yisen.Zhuang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-04-22 7:20 ` [PATCH net-next 01/10] net: hns: add a new dsaf mode for debug port Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 03/10] net: hns: add attribute port-idx-in-ae in enet node Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 04/10] net: hns: add attribute reset-field-offset for dsaf node Yisen Zhuang
2016-04-22 20:44 ` Rob Herring
2016-04-23 1:41 ` Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 06/10] net: hns: sort the header file by alphabetical order Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 09/10] net: hns: add attribute port-rst-offset for dsaf port node Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 05/10] net: hns: add syscon operation for dsaf Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 07/10] net: hns: separate debug and service device from dsaf device Yisen Zhuang
2016-04-22 7:20 ` [PATCH net-next 08/10] net: hns: add attribute cpld_ctrl for dsaf port node Yisen Zhuang
2016-04-22 7:20 ` Yisen Zhuang [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-04-28 7:01 [PATCH net-next 00/10] net: hns: add support of debug dsaf device Yisen Zhuang
[not found] ` <1461826902-51368-1-git-send-email-Yisen.Zhuang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2016-04-28 7:01 ` [PATCH net-next 10/10] net: hns: add attribute port-mode-offset for dsaf port node Yisen Zhuang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461309619-167621-11-git-send-email-Yisen.Zhuang@huawei.com \
--to=yisen.zhuang@huawei.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=huangdaode@hisilicon.com \
--cc=ijc+devicetree@hellion.org.uk \
--cc=liguozhu@huawei.com \
--cc=linuxarm@huawei.com \
--cc=lipeng321@huawei.com \
--cc=mark.rutland@arm.com \
--cc=netdev@vger.kernel.org \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=salil.mehta@huawei.com \
--cc=xieqianqian@huawei.com \
--cc=yankejian@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).