LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Michal Vokáč" <vokac.m@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	f.fainelli@gmail.com, vivien.didelot@savoirfairelinux.com,
	andrew@lunn.ch, mark.rutland@arm.com, robh+dt@kernel.org,
	davem@davemloft.net, michal.vokac@ysoft.com
Subject: [PATCH net-next v2 5/7] net: dsa: qca8k: Allow overwriting CPU port setting
Date: Tue, 22 May 2018 13:16:30 +0200	[thread overview]
Message-ID: <1526987792-56861-6-git-send-email-michal.vokac@ysoft.com> (raw)
In-Reply-To: <1526987792-56861-1-git-send-email-michal.vokac@ysoft.com>

Implement adjust_link function that allows to overwrite default CPU port
setting using fixed-link device tree subnode.

Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
Changes in v2:
 - Add "Reviewed-by" tags from Andrew and Florian.

 drivers/net/dsa/qca8k.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/qca8k.h |  1 +
 2 files changed, 44 insertions(+)

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 14a108b38..7eba987 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -636,6 +636,47 @@ qca8k_setup(struct dsa_switch *ds)
 	return 0;
 }
 
+static void
+qca8k_adjust_link(struct dsa_switch *ds, int port, struct phy_device *phy)
+{
+	struct qca8k_priv *priv = ds->priv;
+	u32 reg;
+
+	/* Force fixed-link setting for CPU port, skip others. */
+	if (!phy_is_pseudo_fixed_link(phy))
+		return;
+
+	/* Set port speed */
+	switch (phy->speed) {
+	case 10:
+		reg = QCA8K_PORT_STATUS_SPEED_10;
+		break;
+	case 100:
+		reg = QCA8K_PORT_STATUS_SPEED_100;
+		break;
+	case 1000:
+		reg = QCA8K_PORT_STATUS_SPEED_1000;
+		break;
+	default:
+		dev_dbg(priv->dev, "port%d link speed %dMbps not supported.\n",
+			port, phy->speed);
+		return;
+	}
+
+	/* Set duplex mode */
+	if (phy->duplex == DUPLEX_FULL)
+		reg |= QCA8K_PORT_STATUS_DUPLEX;
+
+	/* Force flow control */
+	if (dsa_is_cpu_port(ds, port))
+		reg |= QCA8K_PORT_STATUS_RXFLOW | QCA8K_PORT_STATUS_TXFLOW;
+
+	/* Force link down before changing MAC options */
+	qca8k_port_set_status(priv, port, 0);
+	qca8k_write(priv, QCA8K_REG_PORT_STATUS(port), reg);
+	qca8k_port_set_status(priv, port, 1);
+}
+
 static int
 qca8k_phy_read(struct dsa_switch *ds, int phy, int regnum)
 {
@@ -909,6 +950,7 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port)
 static const struct dsa_switch_ops qca8k_switch_ops = {
 	.get_tag_protocol	= qca8k_get_tag_protocol,
 	.setup			= qca8k_setup,
+	.adjust_link            = qca8k_adjust_link,
 	.get_strings		= qca8k_get_strings,
 	.phy_read		= qca8k_phy_read,
 	.phy_write		= qca8k_phy_write,
@@ -942,6 +984,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 		return -ENOMEM;
 
 	priv->bus = mdiodev->bus;
+	priv->dev = &mdiodev->dev;
 
 	/* read the switches ID register */
 	id = qca8k_read(priv, QCA8K_REG_MASK_CTRL);
diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
index 5bda165..613fe5c5 100644
--- a/drivers/net/dsa/qca8k.h
+++ b/drivers/net/dsa/qca8k.h
@@ -167,6 +167,7 @@ struct qca8k_priv {
 	struct ar8xxx_port_status port_sts[QCA8K_NUM_PORTS];
 	struct dsa_switch *ds;
 	struct mutex reg_mutex;
+	struct device *dev;
 };
 
 struct qca8k_mib_desc {
-- 
2.1.4

  parent reply	other threads:[~2018-05-22 11:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 11:16 [PATCH net-next v2 0/7] Add support for QCA8334 switch Michal Vokáč
2018-05-22 11:16 ` [PATCH net-next v2 1/7] net: dsa: qca8k: Add QCA8334 binding documentation Michal Vokáč
2018-05-22 19:40   ` Rob Herring
2018-05-22 20:50     ` Michal
2018-05-22 21:58   ` Andrew Lunn
2018-05-22 11:16 ` [PATCH net-next v2 2/7] net: dsa: qca8k: Add support for QCA8334 switch Michal Vokáč
2018-05-22 21:58   ` [PATCH net-next v2 2/7] net: dsa: qca8k: Add support for QCA8334 switch' Andrew Lunn
2018-05-22 11:16 ` [PATCH net-next v2 3/7] net: dsa: qca8k: Enable RXMAC when bringing up a port Michal Vokáč
2018-05-22 11:16 ` [PATCH net-next v2 4/7] net: dsa: qca8k: Force CPU port to its highest bandwidth Michal Vokáč
2018-05-22 11:16 ` Michal Vokáč [this message]
2018-05-22 11:16 ` [PATCH net-next v2 6/7] net: dsa: qca8k: Replace GPL boilerplate by SPDX Michal Vokáč
2018-05-22 11:16 ` [PATCH net-next v2 7/7] net: dsa: qca8k: Remove redundant parentheses Michal Vokáč

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=1526987792-56861-6-git-send-email-michal.vokac@ysoft.com \
    --to=vokac.m@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=michal.vokac@ysoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=vivien.didelot@savoirfairelinux.com \
    --subject='Re: [PATCH net-next v2 5/7] net: dsa: qca8k: Allow overwriting CPU port setting' \
    /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

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).