lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <16e05c84-f13f-456e-b462-5f273a8f29b1@oracle.com>
Date: Sat, 27 Sep 2025 20:33:11 +0530
From: ALOK TIWARI <alok.a.tiwari@...cle.com>
To: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, netdev@...r.kernel.org
Cc: Andrew Lunn <andrew+netdev@...n.ch>,
        "David S. Miller"
 <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, Wen Gu <guwen@...ux.alibaba.com>,
        Philo Lu <lulie@...ux.alibaba.com>,
        Lorenzo Bianconi <lorenzo@...nel.org>,
        Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
        Lukas Bulwahn <lukas.bulwahn@...hat.com>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        Vivian Wang <wangruikang@...as.ac.cn>,
        Troy Mitchell <troy.mitchell@...ux.spacemit.com>,
        Dust Li <dust.li@...ux.alibaba.com>
Subject: Re: [External] : [PATCH net-next v4] eea: Add basic driver framework
 for Alibaba Elastic Ethernet Adaptor


> +struct eea_aq_cdesc {
> +	__le16 flags;
> +	__le16 id;
> +#define EEA_OK     0
> +#define EEA_ERR    0xffffffff
> +	__le32 status;
> +	__le32 reply_len;
> +	__le32 reserved1;
> +
> +	__le64 reserved2;
> +	__le64 reserved3;
> +};
> +
> +struct eea_rx_desc {
> +	__le16 flags;
> +	__le16 id;
> +	__le16 len;
> +	__le16 reserved1;
> +
> +	__le64 addr;
> +
> +	__le64 hdr_addr;
> +	__le32 reserved2;
> +	__le32 reserved3;
> +};
> +
> +#define EEA_RX_CDEC_HDR_LEN_MASK GENMASK(9, 0)

typo EEA_RX_CDEC_HDR_LEN_MASK -> EEA_RX_CDESC_HDR_LEN_MASK

> +
> +struct eea_rx_cdesc {
> +#define EEA_DESC_F_DATA_VALID	BIT(6)
> +#define EEA_DESC_F_SPLIT_HDR	BIT(5)
> +	__le16 flags;
> +	__le16 id;
> +	__le16 len;
> +#define EEA_NET_PT_NONE      0
> +#define EEA_NET_PT_IPv4      1
> +#define EEA_NET_PT_TCPv4     2
> +#define EEA_NET_PT_UDPv4     3
> +#define EEA_NET_PT_IPv6      4
> +#define EEA_NET_PT_TCPv6     5
> +#define EEA_NET_PT_UDPv6     6
> +#define EEA_NET_PT_IPv6_EX   7
> +#define EEA_NET_PT_TCPv6_EX  8
> +#define EEA_NET_PT_UDPv6_EX  9
> +	/* [9:0] is packet type. */
> +	__le16 type;
> +
> +	/* hw timestamp [0:47]: ts */
> +	__le64 ts;
> +
> +	__le32 hash;
> +
> +	/* 0-9: hdr_len  split header
> +	 * 10-15: reserved1
> +	 */
> +	__le16 len_ex;
> +	__le16 reserved2;
> +
> +	__le32 reserved3;
> +	__le32 reserved4;
> +};
> +
> +#define EEA_TX_GSO_NONE   0
> +#define EEA_TX_GSO_TCPV4  1
> +#define EEA_TX_GSO_TCPV6  4
> +#define EEA_TX_GSO_UDP_L4 5
> +#define EEA_TX_GSO_ECN    0x80
> +
> +struct eea_tx_desc {
> +#define EEA_DESC_F_DO_CSUM	BIT(6)
> +	__le16 flags;
> +	__le16 id;
> +	__le16 len;
> +	__le16 reserved1;
> +
> +	__le64 addr;
> +
> +	__le16 csum_start;
> +	__le16 csum_offset;
> +	u8 gso_type;
> +	u8 reserved2;
> +	__le16 gso_size;
> +	__le64 reserved3;
> +};
> +
> +struct eea_tx_cdesc {
> +	__le16 flags;
> +	__le16 id;
> +	__le16 len;
> +	__le16 reserved1;
> +
> +	/* hw timestamp [0:47]: ts */
> +	__le64 ts;
> +	__le64 reserved2;
> +	__le64 reserved3;
> +};
> +
> +struct eea_db {
> +#define EEA_IDX_PRESENT   BIT(0)
> +#define EEA_IRQ_MASK      BIT(1)
> +#define EEA_IRQ_UNMASK    BIT(2)
> +#define EEA_DIRECT_INLINE BIT(3)
> +#define EEA_DIRECT_DESC   BIT(4)
> +	u8 kick_flags;
> +	u8 reserved;
> +	__le16 idx;
> +
> +	__le16 tx_cq_head;
> +	__le16 rx_cq_head;
> +};
> +
> +struct eea_db_direct {
> +	u8 kick_flags;
> +	u8 reserved;
> +	__le16 idx;
> +
> +	__le16 tx_cq_head;
> +	__le16 rx_cq_head;
> +
> +	u8 desc[24];
> +};
> +
> +static_assert(sizeof(struct eea_rx_desc) == 32, "rx desc size does not match");
> +static_assert(sizeof(struct eea_rx_cdesc) == 32,
> +	      "rx cdesc size does not match");
> +static_assert(sizeof(struct eea_tx_desc) == 32, "tx desc size does not match");
> +static_assert(sizeof(struct eea_tx_cdesc) == 32,
> +	      "tx cdesc size does not match");
> +static_assert(sizeof(struct eea_db_direct) == 32,
> +	      "db direct size does not match");
> +#endif
> diff --git a/drivers/net/ethernet/alibaba/eea/eea_ethtool.c b/drivers/net/ethernet/alibaba/eea/eea_ethtool.c
> new file mode 100644
> index 000000000000..c1a273e3f0fd
> --- /dev/null
> +++ b/drivers/net/ethernet/alibaba/eea/eea_ethtool.c
> @@ -0,0 +1,314 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Alibaba Elastic Ethernet Adaptor.
> + *
> + * Copyright (C) 2025 Alibaba Inc.
> + */
> +
> +#include <linux/ethtool.h>
> +#include <linux/ethtool_netlink.h>
> +
> +#include "eea_adminq.h"
> +
> +struct eea_stat_desc {
> +	char desc[ETH_GSTRING_LEN];
> +	size_t offset;
> +};
> +
> +#define EEA_TX_STAT(m)	{#m, offsetof(struct eea_tx_stats, m)}
> +#define EEA_RX_STAT(m)	{#m, offsetof(struct eea_rx_stats, m)}
> +
> +static const struct eea_stat_desc eea_rx_stats_desc[] = {
> +	EEA_RX_STAT(descs),
> +	EEA_RX_STAT(drops),
> +	EEA_RX_STAT(kicks),
> +	EEA_RX_STAT(split_hdr_bytes),
> +	EEA_RX_STAT(split_hdr_packets),
> +};
> +
> +static const struct eea_stat_desc eea_tx_stats_desc[] = {
> +	EEA_TX_STAT(descs),
> +	EEA_TX_STAT(drops),
> +	EEA_TX_STAT(kicks),
> +	EEA_TX_STAT(timeouts),
> +};
> +
> +#define EEA_TX_STATS_LEN	ARRAY_SIZE(eea_tx_stats_desc)
> +#define EEA_RX_STATS_LEN	ARRAY_SIZE(eea_rx_stats_desc)
> +
> +static void eea_get_drvinfo(struct net_device *netdev,
> +			    struct ethtool_drvinfo *info)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +	struct eea_device *edev = enet->edev;
> +
> +	strscpy(info->driver,   KBUILD_MODNAME,     sizeof(info->driver));
> +	strscpy(info->bus_info, eea_pci_name(edev), sizeof(info->bus_info));
> +}
> +
> +static void eea_get_ringparam(struct net_device *netdev,
> +			      struct ethtool_ringparam *ring,
> +			      struct kernel_ethtool_ringparam *kernel_ring,
> +			      struct netlink_ext_ack *extack)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +
> +	ring->rx_max_pending = enet->cfg_hw.rx_ring_depth;
> +	ring->tx_max_pending = enet->cfg_hw.tx_ring_depth;
> +	ring->rx_pending = enet->cfg.rx_ring_depth;
> +	ring->tx_pending = enet->cfg.tx_ring_depth;
> +
> +	kernel_ring->tcp_data_split = enet->cfg.split_hdr ?
> +				      ETHTOOL_TCP_DATA_SPLIT_ENABLED :
> +				      ETHTOOL_TCP_DATA_SPLIT_DISABLED;
> +}
> +
> +static int eea_set_ringparam(struct net_device *netdev,
> +			     struct ethtool_ringparam *ring,
> +			     struct kernel_ethtool_ringparam *kernel_ring,
> +			     struct netlink_ext_ack *extack)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +	struct eea_net_tmp tmp = {};
> +	bool need_update = false;
> +	struct eea_net_cfg *cfg;
> +	bool sh;
> +
> +	enet_mk_tmp_cfg(enet, &tmp);
> +
> +	cfg = &tmp.cfg;
> +
> +	if (ring->rx_mini_pending || ring->rx_jumbo_pending) {
> +		NL_SET_ERR_MSG_FMT_MOD(extack,
> +				       "not support rx_mini_pending/rx_jumbo_pending");
> +		return -EINVAL;
> +	}
> +
> +	if (ring->rx_pending > enet->cfg_hw.rx_ring_depth) {
> +		NL_SET_ERR_MSG_FMT_MOD(extack, "rx (%d) > max (%d)",
> +				       ring->rx_pending,
> +				       enet->cfg_hw.rx_ring_depth);
> +		return -EINVAL;
> +	}
> +
> +	if (ring->tx_pending > enet->cfg_hw.tx_ring_depth) {
> +		NL_SET_ERR_MSG_FMT_MOD(extack, "tx (%d) > max (%d)",
> +				       ring->tx_pending,
> +				       enet->cfg_hw.tx_ring_depth);
> +		return -EINVAL;
> +	}
> +
> +	if (ring->rx_pending != cfg->rx_ring_depth)
> +		need_update = true;
> +
> +	if (ring->tx_pending != cfg->tx_ring_depth)
> +		need_update = true;
> +
> +	sh = kernel_ring->tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED;
> +	if (sh != !!(cfg->split_hdr))
> +		need_update = true;
> +
> +	if (!need_update)
> +		return 0;
> +
> +	cfg->rx_ring_depth = ring->rx_pending;
> +	cfg->tx_ring_depth = ring->tx_pending;
> +
> +	cfg->split_hdr = sh ? enet->cfg_hw.split_hdr : 0;
> +
> +	return eea_reset_hw_resources(enet, &tmp);
> +}
> +
> +static int eea_set_channels(struct net_device *netdev,
> +			    struct ethtool_channels *channels)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +	u16 queue_pairs = channels->combined_count;
> +	struct eea_net_tmp tmp = {};
> +	struct eea_net_cfg *cfg;
> +
> +	enet_mk_tmp_cfg(enet, &tmp);
> +
> +	cfg = &tmp.cfg;
> +
> +	if (channels->rx_count || channels->tx_count || channels->other_count)
> +		return -EINVAL;
> +
> +	if (queue_pairs > enet->cfg_hw.rx_ring_num || queue_pairs == 0)
> +		return -EINVAL;
> +
> +	if (queue_pairs == enet->cfg.rx_ring_num &&
> +	    queue_pairs == enet->cfg.tx_ring_num)
> +		return 0;
> +
> +	cfg->rx_ring_num = queue_pairs;
> +	cfg->tx_ring_num = queue_pairs;
> +
> +	return eea_reset_hw_resources(enet, &tmp);
> +}
> +
> +static void eea_get_channels(struct net_device *netdev,
> +			     struct ethtool_channels *channels)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +
> +	channels->combined_count = enet->cfg.rx_ring_num;
> +	channels->max_combined   = enet->cfg_hw.rx_ring_num;
> +	channels->max_other      = 0;
> +	channels->rx_count       = 0;
> +	channels->tx_count       = 0;
> +	channels->other_count    = 0;
> +}
> +
> +static void eea_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +	u8 *p = data;
> +	u32 i, j;
> +
> +	if (stringset != ETH_SS_STATS)
> +		return;
> +
> +	for (i = 0; i < enet->cfg.rx_ring_num; i++) {
> +		for (j = 0; j < EEA_RX_STATS_LEN; j++)
> +			ethtool_sprintf(&p, "rx%u_%s", i,
> +					eea_rx_stats_desc[j].desc);
> +	}
> +
> +	for (i = 0; i < enet->cfg.tx_ring_num; i++) {
> +		for (j = 0; j < EEA_TX_STATS_LEN; j++)
> +			ethtool_sprintf(&p, "tx%u_%s", i,
> +					eea_tx_stats_desc[j].desc);
> +	}
> +}
> +
> +static int eea_get_sset_count(struct net_device *netdev, int sset)
> +{
> +	struct eea_net *enet = netdev_priv(netdev);
> +
> +	if (sset != ETH_SS_STATS)
> +		return -EOPNOTSUPP;
> +
> +	return enet->cfg.rx_ring_num * (EEA_RX_STATS_LEN + EEA_TX_STATS_LEN);

what about return enet->cfg.rx_ring_num * EEA_RX_STATS_LEN +
        enet->cfg.tx_ring_num * EEA_TX_STATS_LEN; ?

> +}
> +
> +static void eea_stats_fill_for_q(struct u64_stats_sync *syncp, u32 num,
> +				 const struct eea_stat_desc *desc,
> +				 u64 *data, u32 idx)
> +{
> +	void *stats_base = syncp;
> +	u32 start, i;
> +
> +	do {
> +		start = u64_stats_fetch_begin(syncp);
> +		for (i = 0; i < num; i++)
> +			data[idx + i] =
> +				u64_stats_read(stats_base + desc[i].offset);
> +
> +	} while (u64_stats_fetch_retry(syncp, start));
> +}
> +
[clip]
> +/* sq api */
> +void *ering_sq_alloc_desc(struct eea_ring *ering, u16 id, bool is_last,
> +			  u16 flags)
> +{
> +	struct eea_ring_sq *sq = &ering->sq;
> +	struct eea_common_desc *desc;
> +
> +	if (!sq->shadow_num) {
> +		sq->shadow_idx = sq->head;
> +		sq->shadow_id = cpu_to_le16(id);
> +	}
> +
> +	if (!is_last)
> +		flags |= EEA_RING_DESC_F_MORE;
> +
> +	desc = sq->desc + (sq->shadow_idx << sq->desc_size_shift);
> +
> +	desc->flags = cpu_to_le16(flags);
> +	desc->id = sq->shadow_id;
> +
> +	if (unlikely(++sq->shadow_idx >= ering->num))
> +		sq->shadow_idx = 0;
> +
> +	++sq->shadow_num;
> +
> +	return desc;
> +}
> +
> +void *ering_aq_alloc_desc(struct eea_ring *ering)


typo ering_aq_alloc_desc -> ering_sq_alloc_desc

> +{
> +	struct eea_ring_sq *sq = &ering->sq;
> +	struct eea_common_desc *desc;
> +
> +	sq->shadow_idx = sq->head;
> +
> +	desc = sq->desc + (sq->shadow_idx << sq->desc_size_shift);
> +
> +	if (unlikely(++sq->shadow_idx >= ering->num))
> +		sq->shadow_idx = 0;
> +
> +	++sq->shadow_num;
> +
> +	return desc;
> +}
> +
[clip]
> +void *ering_cq_get_desc(const struct eea_ring *ering);
> +#endif
> diff --git a/drivers/net/ethernet/alibaba/eea/eea_rx.c b/drivers/net/ethernet/alibaba/eea/eea_rx.c
> new file mode 100644
> index 000000000000..3b55d8f534ad
> --- /dev/null
> +++ b/drivers/net/ethernet/alibaba/eea/eea_rx.c
> @@ -0,0 +1,787 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Alibaba Elastic Ethernet Adaptor.
> + *
> + * Copyright (C) 2025 Alibaba Inc.
> + */
> +
> +#include <net/netdev_rx_queue.h>
> +#include <net/page_pool/helpers.h>
> +
> +#include "eea_adminq.h"
> +#include "eea_net.h"
> +#include "eea_ring.h"
> +
> +#define EEA_SETUP_F_NAPI         BIT(0)
> +#define EEA_SETUP_F_IRQ          BIT(1)
> +#define EEA_ENABLE_F_NAPI        BIT(2)
> +
> +#define EEA_PAGE_FRGAS_NUM 1024

typo EEA_PAGE_FRGAS_NUM -> EEA_PAGE_FRAGS_NUM

> +
> +struct eea_rx_ctx {
> +	void *buf;
> +
> +	u32 len;
> +	u32 hdr_len;
> +
> +	u16 flags;
> +	bool more;
> +
> +	u32 frame_sz;
> +
> +	struct eea_rx_meta *meta;
> +
> +	struct eea_rx_ctx_stats stats;
> +};
[clip]
> +
> +static void eea_tx_meta_put_and_unmap(struct eea_net_tx *tx,
> +				      struct eea_tx_meta *meta)
> +{
> +	struct eea_tx_meta *head;
> +
> +	head = meta;
> +
> +	while (true) {
> +		dma_unmap_single(tx->dma_dev, meta->dma_addr,
> +				 meta->dma_len, DMA_TO_DEVICE);
> +
> +		meta->data = NULL;
> +
> +		if (meta->next) {
> +			meta = meta->next;
> +			continue;
> +		}
> +
> +		break;
> +	}
> +
> +	meta->next = tx->free;
> +	tx->free = head;
> +}
> +
> +static void eea_meta_free_xmit(struct eea_net_tx *tx,
> +			       struct eea_tx_meta *meta,
> +			       bool in_napi,
> +			       struct eea_tx_cdesc *desc,
> +			       struct eea_sq_free_stats *stats)
> +{
> +	struct sk_buff *skb = meta->skb;
> +
> +	if (!skb) {
> +		netdev_err(tx->enet->netdev,
> +			   "tx meta.data is null. id %d num: %d\n",

tx meta.data is null -> tx meta->skb is null

> +			   meta->id, meta->num);
> +		return;
> +	}
> +
> +	if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && desc)) {
> +		struct skb_shared_hwtstamps ts = {};
> +
> +		ts.hwtstamp = EEA_DESC_TS(desc) + tx->enet->hw_ts_offset;
> +		skb_tstamp_tx(skb, &ts);
> +	}
> +
> +	stats->bytes += meta->skb->len;
> +	napi_consume_skb(meta->skb, in_napi);
> +}

Thanks,
Alok

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ