From patchwork Thu Oct 12 12:19:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 30268 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0B1481B30C; Thu, 12 Oct 2017 14:20:41 +0200 (CEST) Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id 613991B2F6 for ; Thu, 12 Oct 2017 14:20:30 +0200 (CEST) Received: by mail-wm0-f49.google.com with SMTP id m72so12691783wmc.1 for ; Thu, 12 Oct 2017 05:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aM1Z+rzlL3yNh6z+0hTIuOMqAQ4kg3ErALqccZlb7Ts=; b=lQXSp9mW0M50mULTzDqM33wZy9IX0FyR4j3F28mSM60R7pwFGj4dEYpFFw/TlnADWF 30OLH7wEjk8A8NWMCoIe0MWKrDy4NQuYjtWizqLDRahyWcIoCovwPOgd2Sy3wzx30h45 zOb0M+6fs0G3NcvCYdDB7Z96oiLp87jZnZvY/LGOt3RZqy6ifRf86PR7yMQuHqicKhJ4 VRpAVgZ/PkegelvxWztx1S77c88w+JfTgOZG7Xg1oxHjCumErmnH3pxtDuMYel2FH1aA Y7TY9MJXUSlLW2vLzW6bDLuMkYDzHHhVfzMlIco7c8o8zfZLm2nj5/yEJC4Ltv8yMob+ 30fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aM1Z+rzlL3yNh6z+0hTIuOMqAQ4kg3ErALqccZlb7Ts=; b=tAukyE1UtS2ERi3HfJYy/MOaF53/nr8yWeLxMMmLyN+H4hHcXv0/2f/7ycx4bPB5rJ S2gJ8vf775Xr01nTR8lw8QIM6QQTM0S+6ZYQjEaHQ4lwZTSNpsErMHMY9rVbZJgZtjws lYW/SPLnsW9AQwbrWvOZ+huGGcA6VbHweDBUXNB2yb1G5txb3aP4LZkhqbM3W3+f2Hy8 tLrrwJdA+NPYVz2Q+fyasg9IAjcroA10EATTQE9ag+rIc0DvL+3IQPKrUo21h8FZAx/p fmanqnvloPQ4QzE++aGh760rt0ghOCrvE3PZwX2hos0a2RSeiS2XdTwh+KxYl6WUJ71X Pcnw== X-Gm-Message-State: AMCzsaVSgTAnZgVLBmAClPXI8G2vDMmaSOkJRAcg8yxLfCNXlpoOsfHY wG1uvQOUYwYCKAXtWibyhTYw+Q== X-Google-Smtp-Source: AOwi7QAF4AqxJCkNgnkcx2taCkjQIZUgMpcXRrKaDjHOOWs0DKk5BatPDEbT5dUBT5LZVM9Nwqz/yg== X-Received: by 10.223.142.45 with SMTP id n42mr1847442wrb.278.1507810829947; Thu, 12 Oct 2017 05:20:29 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id d40sm95771wma.48.2017.10.12.05.20.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Oct 2017 05:20:29 -0700 (PDT) From: Adrien Mazarguil To: Ferruh Yigit Cc: Nelio Laranjeiro , dev@dpdk.org Date: Thu, 12 Oct 2017 14:19:31 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 17/29] net/mlx4: add MAC addresses configuration support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit brings back support for configuring up to 128 MAC addresses on a port through internal flow rules automatically generated on demand. Unlike its previous incarnation, the necessary extra flow rule for broadcast traffic does not consume an entry from the MAC array anymore. Signed-off-by: Adrien Mazarguil Acked-by: Nelio Laranjeiro --- doc/guides/nics/features/mlx4.ini | 1 + drivers/net/mlx4/mlx4.c | 7 ++- drivers/net/mlx4/mlx4.h | 10 +++- drivers/net/mlx4/mlx4_ethdev.c | 87 +++++++++++++++++++++++++++++++- drivers/net/mlx4/mlx4_flow.c | 90 ++++++++++++++++++++++++++++------ drivers/net/mlx4/mlx4_flow.h | 2 + 6 files changed, 177 insertions(+), 20 deletions(-) diff --git a/doc/guides/nics/features/mlx4.ini b/doc/guides/nics/features/mlx4.ini index 0812a30..d17774f 100644 --- a/doc/guides/nics/features/mlx4.ini +++ b/doc/guides/nics/features/mlx4.ini @@ -12,6 +12,7 @@ Rx interrupt = Y Queue start/stop = Y MTU update = Y Jumbo frame = Y +Unicast MAC filter = Y SR-IOV = Y Basic stats = Y Stats per queue = Y diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 256aa3d..99c87ff 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -221,6 +221,9 @@ static const struct eth_dev_ops mlx4_dev_ops = { .dev_set_link_up = mlx4_dev_set_link_up, .dev_close = mlx4_dev_close, .link_update = mlx4_link_update, + .mac_addr_remove = mlx4_mac_addr_remove, + .mac_addr_add = mlx4_mac_addr_add, + .mac_addr_set = mlx4_mac_addr_set, .stats_get = mlx4_stats_get, .stats_reset = mlx4_stats_reset, .dev_infos_get = mlx4_dev_infos_get, @@ -552,7 +555,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) mac.addr_bytes[2], mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); /* Register MAC address. */ - priv->mac = mac; + priv->mac[0] = mac; #ifndef NDEBUG { char ifname[IF_NAMESIZE]; @@ -581,7 +584,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) goto port_error; } eth_dev->data->dev_private = priv; - eth_dev->data->mac_addrs = &priv->mac; + eth_dev->data->mac_addrs = priv->mac; eth_dev->device = &pci_dev->device; rte_eth_copy_pci_info(eth_dev, pci_dev); eth_dev->device->driver = &mlx4_driver.driver; diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index fb4708d..15ecd95 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -52,6 +52,9 @@ #include #include +/** Maximum number of simultaneous MAC addresses. This value is arbitrary. */ +#define MLX4_MAX_MAC_ADDRESSES 128 + /** Request send completion once in every 64 sends, might be less. */ #define MLX4_PMD_TX_PER_COMP_REQ 64 @@ -99,7 +102,6 @@ struct priv { struct ibv_context *ctx; /**< Verbs context. */ struct ibv_device_attr device_attr; /**< Device properties. */ struct ibv_pd *pd; /**< Protection Domain. */ - struct ether_addr mac; /**< MAC address. */ /* Device properties. */ uint16_t mtu; /**< Configured MTU. */ uint8_t port; /**< Physical port number. */ @@ -110,6 +112,8 @@ struct priv { struct rte_intr_handle intr_handle; /**< Port interrupt handle. */ struct mlx4_drop *drop; /**< Shared resources for drop flow rules. */ LIST_HEAD(, rte_flow) flows; /**< Configured flow rule handles. */ + struct ether_addr mac[MLX4_MAX_MAC_ADDRESSES]; + /**< Configured MAC addresses. Unused entries are zeroed. */ }; /* mlx4_ethdev.c */ @@ -120,6 +124,10 @@ int mlx4_mtu_get(struct priv *priv, uint16_t *mtu); int mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); int mlx4_dev_set_link_down(struct rte_eth_dev *dev); int mlx4_dev_set_link_up(struct rte_eth_dev *dev); +void mlx4_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); +int mlx4_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr, + uint32_t index, uint32_t vmdq); +void mlx4_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr); int mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); void mlx4_stats_reset(struct rte_eth_dev *dev); void mlx4_dev_infos_get(struct rte_eth_dev *dev, diff --git a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c index 8962be1..52924df 100644 --- a/drivers/net/mlx4/mlx4_ethdev.c +++ b/drivers/net/mlx4/mlx4_ethdev.c @@ -64,9 +64,11 @@ #include #include #include +#include #include #include "mlx4.h" +#include "mlx4_flow.h" #include "mlx4_rxtx.h" #include "mlx4_utils.h" @@ -518,6 +520,88 @@ mlx4_dev_set_link_up(struct rte_eth_dev *dev) } /** + * DPDK callback to remove a MAC address. + * + * @param dev + * Pointer to Ethernet device structure. + * @param index + * MAC address index. + */ +void +mlx4_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) +{ + struct priv *priv = dev->data->dev_private; + struct rte_flow_error error; + + if (index >= RTE_DIM(priv->mac)) { + rte_errno = EINVAL; + return; + } + memset(&priv->mac[index], 0, sizeof(priv->mac[index])); + if (!mlx4_flow_sync(priv, &error)) + return; + ERROR("failed to synchronize flow rules after removing MAC address" + " at index %d (code %d, \"%s\")," + " flow error type %d, cause %p, message: %s", + index, rte_errno, strerror(rte_errno), error.type, error.cause, + error.message ? error.message : "(unspecified)"); +} + +/** + * DPDK callback to add a MAC address. + * + * @param dev + * Pointer to Ethernet device structure. + * @param mac_addr + * MAC address to register. + * @param index + * MAC address index. + * @param vmdq + * VMDq pool index to associate address with (ignored). + * + * @return + * 0 on success, negative errno value otherwise and rte_errno is set. + */ +int +mlx4_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr, + uint32_t index, uint32_t vmdq) +{ + struct priv *priv = dev->data->dev_private; + struct rte_flow_error error; + int ret; + + (void)vmdq; + if (index >= RTE_DIM(priv->mac)) { + rte_errno = EINVAL; + return -rte_errno; + } + memcpy(&priv->mac[index], mac_addr, sizeof(priv->mac[index])); + ret = mlx4_flow_sync(priv, &error); + if (!ret) + return 0; + ERROR("failed to synchronize flow rules after adding MAC address" + " at index %d (code %d, \"%s\")," + " flow error type %d, cause %p, message: %s", + index, rte_errno, strerror(rte_errno), error.type, error.cause, + error.message ? error.message : "(unspecified)"); + return ret; +} + +/** + * DPDK callback to set the primary MAC address. + * + * @param dev + * Pointer to Ethernet device structure. + * @param mac_addr + * MAC address to register. + */ +void +mlx4_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) +{ + mlx4_mac_addr_add(dev, mac_addr, 0, 0); +} + +/** * DPDK callback to get information about the device. * * @param dev @@ -549,8 +633,7 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) max = 65535; info->max_rx_queues = max; info->max_tx_queues = max; - /* Last array entry is reserved for broadcast. */ - info->max_mac_addrs = 1; + info->max_mac_addrs = RTE_DIM(priv->mac); info->rx_offload_capa = 0; info->tx_offload_capa = 0; if (mlx4_get_ifname(priv, &ifname) == 0) diff --git a/drivers/net/mlx4/mlx4_flow.c b/drivers/net/mlx4/mlx4_flow.c index 3af83f2..14d2ed3 100644 --- a/drivers/net/mlx4/mlx4_flow.c +++ b/drivers/net/mlx4/mlx4_flow.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -1010,6 +1011,10 @@ mlx4_flow_flush(struct rte_eth_dev *dev, /** * Generate internal flow rules. * + * - MAC flow rules are generated from @p dev->data->mac_addrs + * (@p priv->mac array). + * - An additional flow rule for Ethernet broadcasts is also generated. + * * @param priv * Pointer to private structure. * @param[out] error @@ -1025,18 +1030,18 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error) .priority = MLX4_FLOW_PRIORITY_LAST, .ingress = 1, }; + struct rte_flow_item_eth eth_spec; + const struct rte_flow_item_eth eth_mask = { + .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff", + }; struct rte_flow_item pattern[] = { { .type = MLX4_FLOW_ITEM_TYPE_INTERNAL, }, { .type = RTE_FLOW_ITEM_TYPE_ETH, - .spec = &(struct rte_flow_item_eth){ - .dst = priv->mac, - }, - .mask = &(struct rte_flow_item_eth){ - .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff", - }, + .spec = ð_spec, + .mask = ð_mask, }, { .type = RTE_FLOW_ITEM_TYPE_END, @@ -1053,10 +1058,69 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error) .type = RTE_FLOW_ACTION_TYPE_END, }, }; + struct ether_addr *rule_mac = ð_spec.dst; + struct rte_flow *flow; + unsigned int i; + int err = 0; - if (!mlx4_flow_create(priv->dev, &attr, pattern, actions, error)) - return -rte_errno; - return 0; + for (i = 0; i != RTE_DIM(priv->mac) + 1; ++i) { + const struct ether_addr *mac; + + /* Broadcasts are handled by an extra iteration. */ + if (i < RTE_DIM(priv->mac)) + mac = &priv->mac[i]; + else + mac = ð_mask.dst; + if (is_zero_ether_addr(mac)) + continue; + /* Check if MAC flow rule is already present. */ + for (flow = LIST_FIRST(&priv->flows); + flow && flow->internal; + flow = LIST_NEXT(flow, next)) { + const struct ibv_flow_spec_eth *eth = + (const void *)((uintptr_t)flow->ibv_attr + + sizeof(*flow->ibv_attr)); + unsigned int j; + + if (!flow->mac) + continue; + assert(flow->ibv_attr->type == IBV_FLOW_ATTR_NORMAL); + assert(flow->ibv_attr->num_of_specs == 1); + assert(eth->type == IBV_FLOW_SPEC_ETH); + for (j = 0; j != sizeof(mac->addr_bytes); ++j) + if (eth->val.dst_mac[j] != mac->addr_bytes[j] || + eth->mask.dst_mac[j] != UINT8_C(0xff) || + eth->val.src_mac[j] != UINT8_C(0x00) || + eth->mask.src_mac[j] != UINT8_C(0x00)) + break; + if (j == sizeof(mac->addr_bytes)) + break; + } + if (!flow || !flow->internal) { + /* Not found, create a new flow rule. */ + memcpy(rule_mac, mac, sizeof(*mac)); + flow = mlx4_flow_create(priv->dev, &attr, pattern, + actions, error); + if (!flow) { + err = -rte_errno; + break; + } + } + flow->select = 1; + flow->mac = 1; + } + /* Clear selection and clean up stale MAC flow rules. */ + flow = LIST_FIRST(&priv->flows); + while (flow && flow->internal) { + struct rte_flow *next = LIST_NEXT(flow, next); + + if (flow->mac && !flow->select) + claim_zero(mlx4_flow_destroy(priv->dev, flow, error)); + else + flow->select = 0; + flow = next; + } + return err; } /** @@ -1090,12 +1154,8 @@ mlx4_flow_sync(struct priv *priv, struct rte_flow_error *error) flow && flow->internal; flow = LIST_FIRST(&priv->flows)) claim_zero(mlx4_flow_destroy(priv->dev, flow, error)); - } else if (!LIST_FIRST(&priv->flows) || - !LIST_FIRST(&priv->flows)->internal) { - /* - * If the first rule is not internal outside isolated mode, - * they must be added back. - */ + } else { + /* Refresh internal rules. */ ret = mlx4_flow_internal(priv, error); if (ret) return ret; diff --git a/drivers/net/mlx4/mlx4_flow.h b/drivers/net/mlx4/mlx4_flow.h index 3036ff5..fcdf461 100644 --- a/drivers/net/mlx4/mlx4_flow.h +++ b/drivers/net/mlx4/mlx4_flow.h @@ -64,7 +64,9 @@ struct rte_flow { struct ibv_flow *ibv_flow; /**< Verbs flow. */ struct ibv_flow_attr *ibv_attr; /**< Pointer to Verbs attributes. */ uint32_t ibv_attr_size; /**< Size of Verbs attributes. */ + uint32_t select:1; /**< Used by operations on the linked list. */ uint32_t internal:1; /**< Internal flow rule outside isolated mode. */ + uint32_t mac:1; /**< Rule associated with a configured MAC address. */ uint32_t promisc:1; /**< This rule matches everything. */ uint32_t drop:1; /**< This rule drops packets. */ uint32_t queue:1; /**< Target is a receive queue. */