From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0715BA00C5; Mon, 14 Feb 2022 12:26:11 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C620F4115E; Mon, 14 Feb 2022 12:25:51 +0100 (CET) Received: from office2.cesnet.cz (office2.cesnet.cz [195.113.144.244]) by mails.dpdk.org (Postfix) with ESMTP id 7040941156 for ; Mon, 14 Feb 2022 12:25:48 +0100 (CET) Received: from emil.fit.vutbr.cz (unknown [IPv6:2001:67c:1220:80c:eb:e00e:9e81:ff5f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id 497E5400079; Mon, 14 Feb 2022 12:25:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2-2020; t=1644837948; bh=KoN75frgfzi89htIcttfxyPVF7WiT2NeuCNdTYX9rZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iqplHJtBzgdrp0qldXZSzM4q8LNC6u8G5jdDAoOiiZWHgI8lRB1ZtFF/iHGUAjAuM ejXbGRpeNoMjwQHDR16qTpruuENjPOE07J7N0PcwpqEToiGat6x3Xh0LfpOfwh56Ni FBC1YuQbA21Jr+cE+zzo6digAxK2Jxtq8sDasPlCeCffmNCiVQzg0zwREhUoDPrbS+ ef7N3emhsr5TNT6Tb+ymZT8xVKqj8iof2w9AhX/eo8RFlFS+/tr9CAMXNhS0wsy+Q7 ir4DADoYEzrlSiBAmrPBzAk19j/PoPuk45cv90jpOIl0kDihZfav0Sf619S2C88+5k CV3KNo84X+Wfw== From: spinler@cesnet.cz To: dev@dpdk.org Cc: Martin Spinler Subject: [PATCH 6/6] drivers/nfb: add support for more MAC addresses Date: Mon, 14 Feb 2022 12:25:41 +0100 Message-Id: <20220214112541.29782-6-spinler@cesnet.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214112541.29782-1-spinler@cesnet.cz> References: <20220214112541.29782-1-spinler@cesnet.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Martin Spinler Extend the eth_dev_ops by add/remove MAC address functions. Signed-off-by: Martin Spinler --- drivers/net/nfb/nfb_ethdev.c | 69 ++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c index 5d503e131a..7dec8e022e 100644 --- a/drivers/net/nfb/nfb_ethdev.c +++ b/drivers/net/nfb/nfb_ethdev.c @@ -214,7 +214,19 @@ static int nfb_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - dev_info->max_mac_addrs = 1; + uint16_t i; + uint32_t max_mac_addrs; + struct pmd_internals *internals = dev->data->dev_private; + + dev_info->max_mac_addrs = (uint32_t)-1; + for (i = 0; i < internals->max_rxmac; i++) { + max_mac_addrs = nc_rxmac_mac_address_count(internals->rxmac[i]); + dev_info->max_mac_addrs = RTE_MIN(max_mac_addrs, + dev_info->max_mac_addrs); + } + if (internals->max_rxmac == 0) + dev_info->max_mac_addrs = 0; + dev_info->max_rx_pktlen = (uint32_t)-1; dev_info->max_rx_queues = dev->data->nb_rx_queues; dev_info->max_tx_queues = dev->data->nb_tx_queues; @@ -376,6 +388,18 @@ nfb_eth_dev_set_link_down(struct rte_eth_dev *dev) return 0; } +static uint64_t +nfb_eth_mac_addr_conv(struct rte_ether_addr *mac_addr) +{ + int i; + uint64_t res = 0; + for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) { + res <<= 8; + res |= mac_addr->addr_bytes[i] & 0xFF; + } + return res; +} + /** * DPDK callback to set primary MAC address. * @@ -392,26 +416,47 @@ nfb_eth_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) { unsigned int i; - uint64_t mac = 0; + uint64_t mac; struct rte_eth_dev_data *data = dev->data; struct pmd_internals *internals = (struct pmd_internals *) data->dev_private; - if (!rte_is_valid_assigned_ether_addr(mac_addr)) - return -EINVAL; + mac = nfb_eth_mac_addr_conv(mac_addr); + for (i = 0; i < internals->max_rxmac; ++i) + nc_rxmac_set_mac(internals->rxmac[i], 0, mac, 1); - for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) { - mac <<= 8; - mac |= mac_addr->addr_bytes[i] & 0xFF; - } + return 0; +} +static int +nfb_eth_mac_addr_add(struct rte_eth_dev *dev, + struct rte_ether_addr *mac_addr, uint32_t index, uint32_t pool __rte_unused) +{ + unsigned int i; + uint64_t mac = 0; + struct rte_eth_dev_data *data = dev->data; + struct pmd_internals *internals = (struct pmd_internals *) + data->dev_private; + + mac = nfb_eth_mac_addr_conv(mac_addr); for (i = 0; i < internals->max_rxmac; ++i) - nc_rxmac_set_mac(internals->rxmac[i], 0, mac, 1); + nc_rxmac_set_mac(internals->rxmac[i], index, mac, 1); - rte_ether_addr_copy(mac_addr, data->mac_addrs); return 0; } +static void +nfb_eth_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) +{ + unsigned int i; + struct rte_eth_dev_data *data = dev->data; + struct pmd_internals *internals = (struct pmd_internals *) + data->dev_private; + + for (i = 0; i < internals->max_rxmac; ++i) + nc_rxmac_set_mac(internals->rxmac[i], index, 0, 0); +} + static const struct eth_dev_ops ops = { .dev_start = nfb_eth_dev_start, .dev_stop = nfb_eth_dev_stop, @@ -436,6 +481,8 @@ static const struct eth_dev_ops ops = { .stats_get = nfb_eth_stats_get, .stats_reset = nfb_eth_stats_reset, .mac_addr_set = nfb_eth_mac_addr_set, + .mac_addr_add = nfb_eth_mac_addr_add, + .mac_addr_remove = nfb_eth_mac_addr_remove, }; /** @@ -530,7 +577,7 @@ nfb_eth_dev_init(struct rte_eth_dev *dev) eth_addr_init.addr_bytes[1] = eth_addr.addr_bytes[1]; eth_addr_init.addr_bytes[2] = eth_addr.addr_bytes[2]; - nfb_eth_mac_addr_set(dev, ð_addr_init); + rte_eth_dev_default_mac_addr_set(dev->data->port_id, ð_addr_init); data->promiscuous = nfb_eth_promiscuous_get(dev); data->all_multicast = nfb_eth_allmulticast_get(dev); -- 2.35.1