From: Andrew Lunn <andrew@lunn.ch>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: devicetree@vger.kernel.org, Felix Fietkau <nbd@openwrt.org>,
Arnd Bergmann <arnd@arndb.de>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
netdev@vger.kernel.org, Sean Wang <sean.wang@mediatek.com>,
linux-kernel@vger.kernel.org, Mark Lee <Mark-MC.Lee@mediatek.com>,
Fabien Parent <fparent@baylibre.com>,
Rob Herring <robh+dt@kernel.org>,
linux-mediatek@lists.infradead.org,
John Crispin <john@phrozen.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 06/11] net: ethernet: mtk-eth-mac: new driver
Date: Tue, 5 May 2020 19:47:09 +0200 [thread overview]
Message-ID: <20200505174709.GD224913@lunn.ch> (raw)
In-Reply-To: <20200505140231.16600-7-brgl@bgdev.pl>
> +static struct net_device *mtk_mac_get_netdev(struct mtk_mac_priv *priv)
> +{
> + char *ptr = (char *)priv;
> +
> + return (struct net_device *)(ptr - ALIGN(sizeof(struct net_device),
> + NETDEV_ALIGN));
> +}
Bit of an odd way to do it. It is much more normal to just have
return priv->netdev;
> +static struct sk_buff *mtk_mac_alloc_skb(struct net_device *ndev)
> +{
> + uintptr_t tail, offset;
> + struct sk_buff *skb;
> +
> + skb = dev_alloc_skb(MTK_MAC_MAX_FRAME_SIZE);
> + if (!skb)
> + return NULL;
> +
> + /* Align to 16 bytes. */
> + tail = (uintptr_t)skb_tail_pointer(skb);
> + if (tail & (MTK_MAC_SKB_ALIGNMENT - 1)) {
> + offset = tail & (MTK_MAC_SKB_ALIGNMENT - 1);
> + skb_reserve(skb, MTK_MAC_SKB_ALIGNMENT - offset);
> + }
> +
> + /* Ensure 16-byte alignment of the skb pointer: eth_type_trans() will
> + * extract the Ethernet header (14 bytes) so we need two more bytes.
> + */
> + skb_reserve(skb, 2);
NET_IP_ALIGN
There might also be something in skbuf.h which will do your 16 byte
alignment for you.
> +static int mtk_mac_enable(struct net_device *ndev)
> +{
> + struct mtk_mac_priv *priv = netdev_priv(ndev);
> + unsigned int val;
> + int ret;
> +
> + mtk_mac_nic_disable_pd(priv);
> + mtk_mac_intr_mask_all(priv);
> + mtk_mac_dma_stop(priv);
> + netif_carrier_off(ndev);
Attaching the PHY will turn the carrier off. If you are using phylib
correctly, you should not have to touch the carrier status, phylib
will do it for you.
> + /* Configure flow control */
> + val = MTK_MAC_VAL_FC_CFG_SEND_PAUSE_TH_2K;
> + val <<= MTK_MAC_OFF_FC_CFG_SEND_PAUSE_TH;
> + val |= MTK_MAC_BIT_FC_CFG_BP_EN;
> + val |= MTK_MAC_BIT_FC_CFG_UC_PAUSE_DIR;
> + regmap_write(priv->regs, MTK_MAC_REG_FC_CFG, val);
> +
> + /* Set SEND_PAUSE_RLS to 1K */
> + val = MTK_MAC_VAL_EXT_CFG_SND_PAUSE_RLS_1K;
> + val <<= MTK_MAC_OFF_EXT_CFG_SND_PAUSE_RLS;
> + regmap_write(priv->regs, MTK_MAC_REG_EXT_CFG, val);
Pause is something this is auto-negotiated. You should be setting this
in your link change notifier which phylib will call when the link goes
up.
> +static int mtk_mac_mdio_rwok_wait(struct mtk_mac_priv *priv)
> +{
> + unsigned long start = jiffies;
> + unsigned int val;
> +
> + for (;;) {
> + regmap_read(priv->regs, MTK_MAC_REG_PHY_CTRL0, &val);
> + if (val & MTK_MAC_BIT_PHY_CTRL0_RWOK)
> + break;
> +
> + udelay(10);
> + if (time_after(jiffies, start + MTK_MAC_WAIT_TIMEOUT))
> + return -ETIMEDOUT;
> + }
regmap_read_poll_timeout() ?
> +static int mtk_mac_mdio_read(struct mii_bus *mii, int phy_id, int regnum)
> +{
> + struct mtk_mac_priv *priv = mii->priv;
> + unsigned int val, data;
> + int ret;
It would be good if here and in _write() you check for C45 addresses
and return -EOPNOTSUP.
> +
> + mtk_mac_mdio_rwok_clear(priv);
> +
> + val = (regnum << MTK_MAC_OFF_PHY_CTRL0_PREG);
> + val &= MTK_MAC_MSK_PHY_CTRL0_PREG;
> + val |= MTK_MAC_BIT_PHY_CTRL0_RDCMD;
> +
> + regmap_write(priv->regs, MTK_MAC_REG_PHY_CTRL0, val);
> +
> + ret = mtk_mac_mdio_rwok_wait(priv);
> + if (ret)
> + return ret;
> +
> + regmap_read(priv->regs, MTK_MAC_REG_PHY_CTRL0, &data);
> +
> + data &= MTK_MAC_MSK_PHY_CTRL0_RWDATA;
> + data >>= MTK_MAC_OFF_PHY_CTRL0_RWDATA;
> +
> + return data;
> +}
> +static int mtk_mac_mdio_init(struct net_device *ndev)
> +{
> + struct mtk_mac_priv *priv = netdev_priv(ndev);
> + struct device *dev = mtk_mac_get_dev(priv);
> + struct device_node *of_node, *mdio_node;
> + int ret;
> +
> + of_node = dev->of_node;
> +
> + mdio_node = of_get_child_by_name(of_node, "mdio");
> + if (!mdio_node)
> + return -ENODEV;
> +
> + if (!of_device_is_available(mdio_node)) {
> + ret = -ENODEV;
> + goto out_put_node;
> + }
> +
> + priv->mii = devm_mdiobus_alloc(dev);
> + if (!priv->mii) {
> + ret = -ENOMEM;
> + goto out_put_node;
> + }
> +
> + snprintf(priv->mii->id, MII_BUS_ID_SIZE, "%s", dev_name(dev));
> + priv->mii->name = "mdio";
It is normal to include something like 'MTK' in the name.
> + priv->mii->parent = dev;
> + priv->mii->read = mtk_mac_mdio_read;
> + priv->mii->write = mtk_mac_mdio_write;
> + priv->mii->priv = priv;
> +
> + ret = of_mdiobus_register(priv->mii, mdio_node);
> +
> +out_put_node:
> + of_node_put(mdio_node);
> + return ret;
> +}
Andrew
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
next prev parent reply other threads:[~2020-05-05 17:47 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 14:02 [PATCH 00/11] mediatek: add support for MediaTek Ethernet MAC Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 01/11] dt-bindings: add a binding document for MediaTek PERICFG controller Bartosz Golaszewski
2020-05-13 2:38 ` Rob Herring
2020-05-13 8:09 ` Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 02/11] dt-bindings: new: add yaml bindings for MediaTek Ethernet MAC Bartosz Golaszewski
2020-05-13 2:41 ` Rob Herring
2020-05-05 14:02 ` [PATCH 03/11] net: ethernet: mediatek: rename Kconfig prompt Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 04/11] net: ethernet: mediatek: remove unnecessary spaces from Makefile Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 05/11] net: core: provide devm_register_netdev() Bartosz Golaszewski
2020-05-05 17:31 ` Jakub Kicinski
2020-05-06 6:39 ` Bartosz Golaszewski
2020-05-06 17:12 ` Jakub Kicinski
2020-05-07 9:25 ` Bartosz Golaszewski
2020-05-07 16:53 ` Jakub Kicinski
2020-05-07 17:03 ` Bartosz Golaszewski
2020-05-07 22:56 ` Jakub Kicinski
2020-05-08 5:54 ` Heiner Kallweit
2020-05-08 18:39 ` Bartosz Golaszewski
2020-05-05 19:25 ` Edwin Peer
2020-05-06 6:46 ` Bartosz Golaszewski
2020-05-06 18:20 ` Edwin Peer
2020-05-05 14:02 ` [PATCH 06/11] net: ethernet: mtk-eth-mac: new driver Bartosz Golaszewski
2020-05-05 17:47 ` Andrew Lunn [this message]
2020-05-06 7:02 ` Bartosz Golaszewski
2020-05-05 18:04 ` Jakub Kicinski
2020-05-06 7:09 ` Bartosz Golaszewski
2020-05-06 17:19 ` Jakub Kicinski
2020-05-06 19:16 ` Leon Romanovsky
2020-05-06 19:23 ` Jakub Kicinski
2020-05-07 5:55 ` Leon Romanovsky
2020-05-07 22:50 ` Jakub Kicinski
2020-05-06 19:24 ` Joe Perches
2020-05-07 9:46 ` Mark-MC.Lee
2020-05-07 10:50 ` Bartosz Golaszewski
2020-05-07 13:16 ` Andrew Lunn
2020-05-07 17:01 ` Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 07/11] ARM64: dts: mediatek: add pericfg syscon to mt8516.dtsi Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 08/11] ARM64: dts: mediatek: add the ethernet node " Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 09/11] ARM64: dts: mediatek: add an alias for ethernet0 for pumpkin boards Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 10/11] ARM64: dts: mediatek: add ethernet pins " Bartosz Golaszewski
2020-05-05 14:02 ` [PATCH 11/11] ARM64: dts: mediatek: enable ethernet on " Bartosz Golaszewski
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=20200505174709.GD224913@lunn.ch \
--to=andrew@lunn.ch \
--cc=Mark-MC.Lee@mediatek.com \
--cc=arnd@arndb.de \
--cc=bgolaszewski@baylibre.com \
--cc=brgl@bgdev.pl \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=fparent@baylibre.com \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@openwrt.org \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sean.wang@mediatek.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).