🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23133

Re: [PATCH v1 07/15] net/xsc: add ethernet netdev registration

#23133
From: "Xin Tian"
Date: Thu, 26 Nov 2026 14:58
213 lines
15971 bytes
Hi Andrew,

Thanks for the review.  I've sent a v2 that is a much smaller
ethernet-only series, and gone through your comments.

On 11/8/2026 5:03 AM, Andrew Lunn wrote:
>> @@ -1,7 +1,6 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   # Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
>>   # All rights reserved.
>> -#
>>   # Yunsilicon driver configuration
>>   #
> Please don't include hunks like this. Was this added be a previous
> patch in this patchset? Then fix it back then. If this is already in
> mainline, add a patch making these 'whitespace' changed.
That Kconfig hunk is gone from v2.
>> +static int xsc_eth_open(struct net_device *netdev)
>> +{
>> +	struct xsc_adapter *adapter = netdev_priv(netdev);
>> +	int ret;
>> +
>> +	if (adapter->opened) {
>> +		netdev_err(adapter->netdev, "ndo_open on an already opened device\n");
>> +		return 0;
>> +	}
>> +
> How does this happen?
>
> And returning 0 seems odd. Something bad has happened, so at least
> EBUSY.
The "already opened" check is unreachable - the netdev core serialises
ndo_open against the interface state under the rtnl lock.  I dropped the
branch rather than return EBUSY.
>> +
>> +	xsc_set_default_xps_cpumasks(adapter);
>> +
>> +	ret = xsc_set_port_admin_status(adapter, XSC_PORT_UP);
>> +	if (ret)
>> +		netdev_err(netdev, "failed to set port admin status up, err=%d\n",
>> +			   ret);
>> +
>> +	return 0;
> return err?
>
I changed xsc_set_port_admin_status() to return void.  The open flow must
not depend on this call: it's issued after open has otherwise completed,
the firmware can legitimately reject it (VF, port_link_en, arbitration
between functions, old firmware), and the real carrier is driven by the
link events and QUERY_VPORT_STATE, not by its return value.  Failing open
on it would turn normal cases into errors, so we log and carry on.
>> +}
>> +
>> +static int xsc_eth_close(struct net_device *netdev)
>> +{
>> +	struct xsc_adapter *adapter = netdev_priv(netdev);
>> +	int ret;
>> +
>> +	if (!adapter->opened)
>> +		return 0;
> How does this happen?
>
> Is there an error code ENOTBUSY?
Same as above - unreachable, dropped the "not opened" branch.
>> +static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
>> +{
>> +	struct net_device *netdev = adapter->netdev;
>> +
>> +	/* Set up network device as normal. */
>> +	netdev->netdev_ops = &xsc_netdev_ops;
>> +
>> +	netdev->min_mtu = SW_DEFAULT_MTU;
>> +	netdev->max_mtu = SW_DEFAULT_MTU;
>> +	/*mtu - macheaderlen - ipheaderlen should be aligned in 8B*/
>> +	netdev->mtu = SW_DEFAULT_MTU;
> What has MTU got to do with alignment?
You're right, the comment made no sense.  Removed.
>> +static int xsc_eth_get_mac(struct xsc_core_device *xdev, char *mac)
>> +{
>> +	struct xsc_query_eth_mac_mbox_out *out;
>> +	struct xsc_query_eth_mac_mbox_in in;
>> +	int err;
>> +
>> +	out = kzalloc_obj(*out, GFP_KERNEL);
>> +	if (!out)
>> +		return -ENOMEM;
>> +
>> +	memset(&in, 0, sizeof(in));
>> +	in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_QUERY_ETH_MAC);
>> +
>> +	err = xsc_cmd_exec(xdev, &in, sizeof(in), out, sizeof(*out));
>> +	if (err || out->hdr.status) {
>> +		netdev_warn(xsc_dev_to_netdev(xdev),
>> +			    "get mac failed! err=%d, out.status=%u\n",
>> +			    err, out->hdr.status);
>> +		err = -ENOEXEC;
>> +		goto exit;
>> +	}
>> +
>> +	memcpy(mac, out->mac, ETH_ALEN);
> There are helpers for copying MAC addresses around.
Now uses ether_addr_copy().
>> +static int xsc_eth_probe(struct auxiliary_device *adev,
>> +			 const struct auxiliary_device_id *adev_id)
>> +{
> ...
>
>> +	err = register_netdev(netdev);
>> +	if (err) {
>> +		netdev_err(netdev, "register_netdev failed, err=%d\n", err);
>> +		goto err_free_stats;
>> +	}
> The stack can up the interface and start sending packets before this
> function call returns. NFS root often does that.
>
>> +
>> +	xdev->netdev = netdev;
>
> Does anything bad happens in open and packet Rx and Tx if xdev->netdev
> == NULL because this assignment has not happened yet.
>
>> +
>> +	xsc_irq_event_register(xdev, xsc_eth_link_event_handler);
> And does anything bad happen if the event handler is not registered?
The interface no longer keeps a xdev->netdev; it's looked up via
xdev->eth_priv, which is set before register_netdev(), so open/Rx/Tx
never see NULL.  The link event handler is now registered before
register_netdev(), so a port event that arrives right after
registration is not lost.
>> +static void xsc_eth_remove(struct auxiliary_device *adev)
>> +{
>> +	struct xsc_adev *xsc_adev = container_of(adev, struct xsc_adev, adev);
>> +	struct xsc_core_device *xdev = xsc_adev->xdev;
>> +	struct xsc_adapter *adapter;
>> +
>> +	if (!xdev)
>> +		return;
> How does that happen?
>> +
>> +	adapter = xdev->eth_priv;
>> +	if (!adapter)
>> +		return;
> How does that happen?
Both gone - the auxiliary bus only calls remove() for devices that
probed successfully, so the checks were dead.
>> +
>> +	/* Stop link events reaching this adapter and wait out one already in
>> +	 * flight, which would otherwise touch the memory freed below.
>> +	 */
>> +	xsc_irq_event_unregister(xdev);
>> +
>> +	/* Runs ndo_stop(), so the queues and the HCA are shut down first. */
>> +	unregister_netdev(adapter->netdev);
>> +
>> +	/* Must precede free_netdev(): the adapter lives in the netdev priv. */
>> +	xsc_eth_nic_cleanup(adapter);
>> +	kvfree(adapter->stats);
>> +	free_netdev(adapter->netdev);
>> +
>> +	xdev->netdev = NULL;
>> +	xdev->eth_priv = NULL;
>> +static inline void xsc_tx_dma_unmap(struct device *dev, struct xsc_sq_dma *dma)
>> +{
>> +	switch (dma->type) {
>> +	case XSC_DMA_MAP_SINGLE:
>> +		dma_unmap_single(dev, dma->addr, dma->size, DMA_TO_DEVICE);
>> +		break;
>> +	case XSC_DMA_MAP_PAGE:
>> +		dma_unmap_page(dev, dma->addr, dma->size, DMA_TO_DEVICE);
>> +		break;
>> +	default:
>> +		break;
>> +	}
> This should probably not be hiding away somewhere in a header file.
That whole tx_dma_unmap abstraction is gone in v2; TX unmaps directly
now.
>> +static inline struct xsc_cqe *xsc_cqwq_get_cqe(struct xsc_cqwq *wq)
>> +{
>> +	u32 ci = xsc_cqwq_get_ci(wq);
>> +	u8 cqe_ownership_bit;
>> +	struct xsc_cqe *cqe;
>> +	u8 sw_ownership_val;
>> +
>> +	cqe = xsc_cqwq_get_cqe_buff(wq, ci);
>> +
>> +	cqe_ownership_bit = !!(le32_to_cpu(cqe->data1) & XSC_CQE_DATA1_OWNER);
>> +	sw_ownership_val = xsc_cqwq_get_wrap_cnt(wq) & 1;
>> +
>> +	if (cqe_ownership_bit != sw_ownership_val)
>> +		return NULL;
>> +
>> +	/* ensure cqe content is read after cqe ownership bit */
>> +	dma_rmb();
>> +
>> +	return cqe;
> This is also a bit big for an include file inline. Plus that dma_rmb()
> should not be hiding, it should be in plain sight.
xsc_cqwq_get_cqe() moved into xsc_eth_txrx.c (the header only declares
it), and dma_rmb() is now at the call sites in the poll loop, in plain 
sight.

Thanks,

Xin
Technical Details
Message-ID: <25597ed8-a64d-4e6a-bce1-df4abd8cb302@yunsilicon.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372179-linux-kernel-netdev=dewy.ru
References: <20261104155650.37053-1-tianx@yunsilicon.com> <20261104155705.37053-8-tianx@yunsilicon.com> <7bf0875f-f5c5-4894-8e26-433aa40c2e04@lunn.ch>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372179-linux-kernel-netdev=dewy.ru
From: tianx@yunsilicon.com ("Xin Tian")
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v1 07/15] net/xsc: add ethernet netdev registration
Date: Thu, 26 Nov 2026 22:58:20 +0800
Organization: Usenet Network
Message-ID: <25597ed8-a64d-4e6a-bce1-df4abd8cb302@yunsilicon.com>
References: <20261104155650.37053-1-tianx@yunsilicon.com> <20261104155705.37053-8-tianx@yunsilicon.com> <7bf0875f-f5c5-4894-8e26-433aa40c2e04@lunn.ch>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network; logging-data="492033"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nYLhUioyRcymSuz0BLYqPLGS5oQ= sha256:ZSe/+ge1bh9viwge7wWow9SgIq3NIPiz4O1MotPxl1U= sha1:46kypVXPBDz+69KDzjHDRVR+SCI= sha256:TRGkbnj7ZcQKC7qbmrGbJtPbFpXaqoafndHA/yHyV5o=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id B8886125EE0; Thu, 26 Nov 2026 18:00:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=yunsilicon.com
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RPkB5wZzkU5j; Thu, 26 Nov 2026 17:59:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372179-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=yunsilicon.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 8E16D125EDC; Thu, 26 Nov 2026 17:59:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id DCB7162417; Thu, 26 Nov 2026 14:58:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795705114; b=ZznTxkgVD9okQRMFWE7iC2Gzh0YI9A2VgqVw0IIg59s6xIJE5LX1/kc9EgHewq5EtGRw QwmI65Qx1TXwnJWtA4BZgqQKQ2ZVLIrpWxiGYO6O144v5WHsBCdg0ZyhKg8TUDwoeCec1 2gMsm5l0+cH8E1HH4cLD9AZZ5EtXXQeNS/JwA9JglZ5lVGHAQT8ewD2AHqHXvQd1bw8+Z ZK8mSZxAuvZckv4RcZPkjPVDofhWXxOsNFHfhdYPikvQx1SIs2lWlj4K36M75YoWfhttx bBotwvrKQeHR7n0w3qwQGftV6AGEdCdsPD7+bGM+zHY8OeUjXnAU22nbcCBRwxZbCyw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795705114; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:From:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:Mime-Version:In-Reply-To: Message-Id:References:Received:Content-Transfer-Encoding:To:Cc: Subject:X-Original-From:X-Lms-Return-Path:User-Agent:Content-Type; bh=C8sOYIvaojnOxWbS1cwkZXUmkHLOzB4BNnadqUooFqc=; b=2YdgbgspXv95UcfghmsD4pjZsNOx0a7TuMHXSMR7YzXLRyrNQ2oCaTxgWbyv2XBtCstR lHMw3t0qYh+lSaojcZ379OxUlmRM75NQYWdrLieA0m6vGnXGqCHzy/R5uCokDqll0hPKo BiNpdsLCnMhrVa+wQrAQTnG9haQdcH201/9/50cMSQtG4FMTL1Iz8/UKRzz+qnUwA1jyf 9KdhqecI0Mk82T3tzRQnOIzxUOTm5heLTcD6MlwLZKYWRETNKVOyLKrxbTJ+tpN1maiVu HmSHycHw2RSxfIJvADdKO52MhK5PfTzFDjYuIGjY85kzwOBupTJZ7V4VJqC5yjPkRZg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=jV5keJl2; dmarc=none header.from=yunsilicon.com; spf=pass smtp.mailfrom=yunsilicon.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48C28606A32E; Thu, 26 Nov 2026 14:58:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=jV5keJl2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.16
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795705113; b=unqPv3my2issl0P5NcHgvteFbrj82YjDnfpUQ7Xzp4z9EzznlEMAkQfaMdmlwGj3uH7w Ox7jnyAxpUZ6dWD2E8kNUTxFZOAoK+Pu3s8OXqEDwXRLeew99t6ntynsBRf1DISg5YHWn BsEiuDXrVvRGiErGaFxkfiHZifkSLJzeLRp+f96sDlxnax+0P055bjIiZ2mzwLbgp7OWG n9Pw5mdM//H778+hvqGBCz3OzunD9aQMd5I5tlh9doFuTRZMqDO4o1bcmiRUWs3NDox3l NbP2pJ/HW4ha6RNkPbYG4pG1VTRLN6MkJPm7WZbfXyeuGfBfYtYjtHXRZ3rjUoi+BXA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795705113; h=DMARC-Filter:DKIM-Signature:From:Date:Mime-Version:In-Reply-To: Message-Id:References:Received:Content-Transfer-Encoding:To:Cc: Subject:X-Original-From:X-Lms-Return-Path:User-Agent:Content-Type; bh=C8sOYIvaojnOxWbS1cwkZXUmkHLOzB4BNnadqUooFqc=; b=ruGRoA/zodxDB4h9kZhnmtE5aNqK9Js/STG0mHwvUyZBootLizN0foD92tWrnY8Nj6ut xKD2yqBw9mXLZw1ux1ne6czFxalfwDGfiiPI/6FKnTj18UwWflIJWTdpLTjZXtUlDu1Zf +lZVuHwu/1261WSEVfrGhCUWob0kpput8sshDGha4+MUGHhTXsL+7SNXGQCG2zAJ1FXDR +1ow2oTR0Uso6YTnHHVr735Ty5u3wfEfSDL3awkJUc6RmEg0atqb3IwjeCtAbU5LomEja I7XCkH+cBceQOPzcijfi+JlJxJyo/okXB1B4j0lizwP+1fkST8u4jZQlDKMGmYEz2rA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=yunsilicon.com; spf=pass smtp.mailfrom=yunsilicon.com; dkim=pass header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=jV5keJl2; arc=none smtp.remote-ip=209.127.231.16
X-Received: from va-2-16.ptr.blmpb.com (va-2-16.ptr.blmpb.com [209.127.231.16]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 041D7606A31C for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 14:58:32 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 041D7606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yunsilicon.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yunsilicon.com
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1795705108; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=C8sOYIvaojnOxWbS1cwkZXUmkHLOzB4BNnadqUooFqc=; b=jV5keJl2V6uqHDHkDic8s/qaJpfC5Ysj2tSc/sfPyhj+yr+ct5QSIOF0KUYYLbGbf7QFh5 qVfkUZo5qhspwCzqwzFrlfjMrEM2z9tlXfxVdSeELn/O8GU5w49OCTsVzlekdY0GcG9h2I 8ehWc9envshkczgGxqmmg4MsJ3nS6oxRGFoykj9fTALSaNJmivOu9NVb1EgTcIGp+7A6kX O/yg4DGZ2QIToBkFvg+s6WP6WepD5uXv21LfSPJckhK5mLzs7LiirtxgPx6Z1jCiM0Endj qsd2w9b562uLijkeZv9F+HPCx8XaVEtZeUzZnjJji4RkN6GixxcMoW0XjpkLgw==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <7bf0875f-f5c5-4894-8e26-433aa40c2e04@lunn.ch>
X-Received: from [127.0.0.1] ([183.193.56.110]) by smtp.feishu.cn with ESMTPS; Thu, 26 Nov 2026 22:58:26 +0800
X-Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>, "David S. Miller" <davem@davemloft.net>, "Eric Dumazet" <edumazet@google.com>, "Jakub Kicinski" <kuba@kernel.org>, "Paolo Abeni" <pabeni@redhat.com>, "Jason Gunthorpe" <jgg@ziepe.ca>, "Leon Romanovsky" <leon@kernel.org>, "Junxian Huang" <huangjunxian6@hisilicon.com>, <weihg@yunsilicon.com>, <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>
X-Original-From: Xin Tian <tianx@yunsilicon.com>
X-Lms-Return-Path: <lba+26b084913+e148d3+vger.kernel.org+tianx@yunsilicon.com>
X-User-Agent: Mozilla Thunderbird