linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: andrei.tachici@stud.acs.upb.ro
Cc: linux-kernel@vger.kernel.org, andrew@lunn.ch,
	hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
	vegard.nossum@oracle.com, joel@jms.id.au, l.stelmach@samsung.com,
	robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	devicetree@vger.kernel.org,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: Re: [net-next v5 2/3] net: ethernet: adi: Add ADIN1110 support
Date: Tue, 23 Aug 2022 16:02:41 -0700	[thread overview]
Message-ID: <20220823160241.36bc2480@kernel.org> (raw)
In-Reply-To: <20220819141941.39635-3-andrei.tachici@stud.acs.upb.ro>

On Fri, 19 Aug 2022 17:19:40 +0300 andrei.tachici@stud.acs.upb.ro wrote:
> +static int adin1110_ndo_set_mac_address(struct net_device *netdev, void *addr)
> +{
> +	struct sockaddr *sa = addr;
> +
> +	if (netif_running(netdev))
> +		return -EBUSY;

Please use eth_prepare_mac_addr_change() instead.

> +	return adin1110_set_mac_address(netdev, sa->sa_data);
> +}

> +static int adin1110_net_stop(struct net_device *net_dev)
> +{
> +	struct adin1110_port_priv *port_priv = netdev_priv(net_dev);
> +
> +	netif_stop_queue(port_priv->netdev);
> +	flush_work(&port_priv->tx_work);

What prevents the IRQ from firing right after this point and waking 
the queue again?

> +	phy_stop(port_priv->phydev);
> +
> +	return 0;
> +}
> +
> +static void adin1110_tx_work(struct work_struct *work)
> +{
> +	struct adin1110_port_priv *port_priv = container_of(work, struct adin1110_port_priv, tx_work);
> +	struct adin1110_priv *priv = port_priv->priv;
> +	struct sk_buff *txb;
> +	bool last;
> +	int ret;
> +
> +	mutex_lock(&priv->lock);
> +
> +	last = skb_queue_empty(&port_priv->txq);
> +
> +	while (!last) {
> +		txb = skb_dequeue(&port_priv->txq);
> +		last = skb_queue_empty(&port_priv->txq);

while ((txb = skb_dequeue(&port_priv->txq)))

> +		if (txb) {
> +			ret = adin1110_write_fifo(port_priv, txb);
> +			if (ret < 0)
> +				netdev_err(port_priv->netdev, "Frame write error: %d\n", ret);

This needs rate limiting.

> +			dev_kfree_skb(txb);
> +		}
> +	}
> +
> +	mutex_unlock(&priv->lock);
> +}
> +
> +static netdev_tx_t adin1110_start_xmit(struct sk_buff *skb, struct net_device *dev)
> +{
> +	struct adin1110_port_priv *port_priv = netdev_priv(dev);
> +	struct adin1110_priv *priv = port_priv->priv;
> +	netdev_tx_t netdev_ret = NETDEV_TX_OK;
> +	u32 tx_space_needed;
> +
> +	spin_lock(&priv->state_lock);
> +
> +	tx_space_needed = skb->len + ADIN1110_FRAME_HEADER_LEN + ADIN1110_INTERNAL_SIZE_HEADER_LEN;
> +	if (tx_space_needed > priv->tx_space) {
> +		netif_stop_queue(dev);
> +		netdev_ret = NETDEV_TX_BUSY;
> +	} else {
> +		priv->tx_space -= tx_space_needed;
> +		skb_queue_tail(&port_priv->txq, skb);
> +	}
> +
> +	spin_unlock(&priv->state_lock);

What is this lock protecting? There's already a lock around Tx.

> +	schedule_work(&port_priv->tx_work);
> +
> +	return netdev_ret;
> +}
> +

> +static int adin1110_net_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags,
> +				       struct netlink_ext_ack *extack)
> +{
> +	struct adin1110_port_priv *port_priv = netdev_priv(dev);
> +	struct nlattr *br_spec;
> +	struct nlattr *attr;
> +	int rem;
> +
> +	br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
> +	if (!br_spec)
> +		return -EINVAL;
> +
> +	nla_for_each_nested(attr, br_spec, rem) {
> +		u16 mode;
> +
> +		if (nla_type(attr) != IFLA_BRIDGE_MODE)
> +			continue;
> +
> +		if (nla_len(attr) < sizeof(mode))
> +			return -EINVAL;
> +
> +		port_priv->priv->br_mode = nla_get_u16(attr);
> +		adin1110_set_rx_mode(dev);
> +		break;
> +	}
> +
> +	return 0;
> +}

I thought this is a callback for legacy SR-IOV NICs. What are you using
it for in a HW device over SPI? :S

> +static int adin1110_port_set_forwarding_state(struct adin1110_port_priv *port_priv)
> +{
> +	struct adin1110_priv *priv = port_priv->priv;
> +	int ret;
> +
> +	port_priv->state = BR_STATE_FORWARDING;
> +
> +	if (adin1110_can_offload_forwarding(priv)) {
> +		ret = adin1110_hw_forwarding(priv, true);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	mutex_lock(&priv->lock);
> +	ret = adin1110_set_mac_address(port_priv->netdev, port_priv->netdev->dev_addr);
> +	if (ret < 0)
> +		goto out;
> +
> +	ret = adin1110_setup_rx_mode(port_priv);
> +out:
> +	mutex_unlock(&priv->lock);
> +
> +	return ret;
> +}

The bridge support looks quite incomplete here, no?
There's no access to the FDB of the switch.
You forward to the host based on the MAC addr of the port not 
the bridge.

  reply	other threads:[~2022-08-23 23:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19 14:19 [net-next v5 0/3] net: ethernet: adi: Add ADIN1110 support andrei.tachici
2022-08-19 14:19 ` [net-next v5 1/3] net: phy: adin1100: add PHY IDs of adin1110/adin2111 andrei.tachici
2022-08-19 14:19 ` [net-next v5 2/3] net: ethernet: adi: Add ADIN1110 support andrei.tachici
2022-08-23 23:02   ` Jakub Kicinski [this message]
2022-08-25 10:55     ` andrei.tachici
2022-08-25 16:08       ` Jakub Kicinski
2022-08-19 14:19 ` [net-next v5 3/3] dt-bindings: net: adin1110: Add docs andrei.tachici

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=20220823160241.36bc2480@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrei.tachici@stud.acs.upb.ro \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=joel@jms.id.au \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=l.stelmach@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=vegard.nossum@oracle.com \
    --cc=vladimir.oltean@nxp.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).