From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 776A8B391 for ; Tue, 12 Aug 2014 05:09:31 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 11 Aug 2014 20:06:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,846,1400050800"; d="scan'208";a="557194076" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 11 Aug 2014 20:12:22 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s7C3CKQm012538; Tue, 12 Aug 2014 11:12:20 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s7C3CHMU011110; Tue, 12 Aug 2014 11:12:19 +0800 Received: (from jijiangl@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s7C3CHmr011106; Tue, 12 Aug 2014 11:12:17 +0800 From: Jijiang Liu To: dev@dpdk.org Date: Tue, 12 Aug 2014 11:12:02 +0800 Message-Id: <1407813127-10991-2-git-send-email-jijiang.liu@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1407813127-10991-1-git-send-email-jijiang.liu@intel.com> References: <1407813127-10991-1-git-send-email-jijiang.liu@intel.com> Subject: [dpdk-dev] [PATCH 1/6]i40e:vxlan packet identification X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 03:09:32 -0000 VxLAN UDP port configuration on i40e, it includes - VxLAN UDP port initialization - Add VxLAN UDP port API Signed-off-by: jijiangl Acked-by: Helin Zhang Acked-by: Jingjing Wu Acked-by: Jing Chen --- lib/librte_ether/rte_ethdev.c | 63 ++++++++++++ lib/librte_ether/rte_ethdev.h | 76 ++++++++++++++ lib/librte_ether/rte_ether.h | 10 ++ lib/librte_pmd_i40e/i40e_ethdev.c | 199 ++++++++++++++++++++++++++++++++++++- lib/librte_pmd_i40e/i40e_ethdev.h | 5 + 5 files changed, 352 insertions(+), 1 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index fd1010a..325edb1 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1892,6 +1892,69 @@ rte_eth_dev_rss_hash_conf_get(uint8_t port_id, } int +rte_eth_dev_udp_tunnel_add(uint8_t port_id, + struct rte_eth_udp_tunnel *udp_tunnel, + uint8_t count) +{ + uint8_t i; + struct rte_eth_dev *dev; + struct rte_eth_udp_tunnel *tunnel; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -ENODEV; + } + + if (udp_tunnel == NULL) { + PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n"); + return -EINVAL; + } + tunnel = udp_tunnel; + + for (i = 0; i < count; i++, tunnel++) { + if (tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { + PMD_DEBUG_TRACE("Invalid tunnel type\n"); + return -EINVAL; + } + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP); + return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel, count); +} + +int +rte_eth_dev_udp_tunnel_delete(uint8_t port_id, + struct rte_eth_udp_tunnel *udp_tunnel, + uint8_t count) +{ + uint8_t i; + struct rte_eth_dev *dev; + struct rte_eth_udp_tunnel *tunnel; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -ENODEV; + } + dev = &rte_eth_devices[port_id]; + + if (udp_tunnel == NULL) { + PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n"); + return -EINVAL; + } + tunnel = udp_tunnel; + for (i = 0; i < count; i++, tunnel++) { + if (tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { + PMD_DEBUG_TRACE("Invalid tunnel type\n"); + return -EINVAL; + } + } + + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP); + return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel, count); +} + +int rte_eth_led_on(uint8_t port_id) { struct rte_eth_dev *dev; diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 50df654..d24907f 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -708,6 +708,26 @@ struct rte_fdir_conf { }; /** + * Tunneled type. + */ +enum rte_eth_tunnel_type { + RTE_TUNNEL_TYPE_NONE = 0, + RTE_TUNNEL_TYPE_VXLAN, + RTE_TUNNEL_TYPE_GENEVE, + RTE_TUNNEL_TYPE_TEREDO, + RTE_TUNNEL_TYPE_NVGRE, + RTE_TUNNEL_TYPE_MAX, +}; + +/** + * UDP tunneling configuration. + */ +struct rte_eth_udp_tunnel { + uint16_t udp_port; + uint8_t prot_type; +}; + +/** * Possible l4type of FDIR filters. */ enum rte_l4type { @@ -829,6 +849,7 @@ struct rte_intr_conf { * configuration settings may be needed. */ struct rte_eth_conf { + enum rte_eth_tunnel_type tunnel_type; uint16_t link_speed; /**< ETH_LINK_SPEED_10[0|00|000], or 0 for autonegotation */ uint16_t link_duplex; @@ -1240,6 +1261,17 @@ typedef int (*eth_mirror_rule_reset_t)(struct rte_eth_dev *dev, uint8_t rule_id); /**< @internal Remove a traffic mirroring rule on an Ethernet device */ +typedef int (*eth_udp_tunnel_add_t)(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *tunnel_udp, + uint8_t count); +/**< @internal Add tunneling UDP info */ + +typedef int (*eth_udp_tunnel_del_t)(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *tunnel_udp, + uint8_t count); +/**< @internal Delete tunneling UDP info */ + + #ifdef RTE_NIC_BYPASS enum { @@ -1412,6 +1444,8 @@ struct eth_dev_ops { eth_set_vf_rx_t set_vf_rx; /**< enable/disable a VF receive */ eth_set_vf_tx_t set_vf_tx; /**< enable/disable a VF transmit */ eth_set_vf_vlan_filter_t set_vf_vlan_filter; /**< Set VF VLAN filter */ + eth_udp_tunnel_add_t udp_tunnel_add; + eth_udp_tunnel_del_t udp_tunnel_del; eth_set_queue_rate_limit_t set_queue_rate_limit; /**< Set queue rate limit */ eth_set_vf_rate_limit_t set_vf_rate_limit; /**< Set VF rate limit */ @@ -3268,6 +3302,48 @@ int rte_eth_dev_rss_hash_conf_get(uint8_t port_id, struct rte_eth_rss_conf *rss_conf); + /** + * Add tunneling UDP port configuration of Ethernet device + * + * @param port_id + * The port identifier of the Ethernet device. + * @param tunnel_udp + * Where to store the current Tunneling UDP configuration + * of the Ethernet device. + * @param count + * How many configurations are going to added. + * + * @return + * - (0) if successful. + * - (-ENODEV) if port identifier is invalid. + * - (-ENOTSUP) if hardware doesn't support tunnel type. + */ +int +rte_eth_dev_udp_tunnel_add(uint8_t port_id, + struct rte_eth_udp_tunnel *tunnel_udp, + uint8_t count); + + /** + * Detete tunneling UDP port configuration of Ethernet device + * + * @param port_id + * The port identifier of the Ethernet device. + * @param tunnel_udp + * Where to store the current Tunneling UDP configuration + * of the Ethernet device. + * @param count + * How many configurations are going to deleted. + * + * @return + * - (0) if successful. + * - (-ENODEV) if port identifier is invalid. + * - (-ENOTSUP) if hardware doesn't support tunnel type. + */ +int +rte_eth_dev_udp_tunnel_delete(uint8_t port_id, + struct rte_eth_udp_tunnel *tunnel_udp, + uint8_t count); + /** * add syn filter * diff --git a/lib/librte_ether/rte_ether.h b/lib/librte_ether/rte_ether.h index 2e08f23..604712a 100644 --- a/lib/librte_ether/rte_ether.h +++ b/lib/librte_ether/rte_ether.h @@ -69,6 +69,8 @@ extern "C" { #define ETHER_MIN_MTU 68 /**< Minimum MTU for IPv4 packets, see RFC 791. */ +#define ETHER_VXLAN_UDP_PORT 4789 /** < default port assigned to VxLAN */ + /** * Ethernet address: * A universally administered address is uniquely assigned to a device by its @@ -286,6 +288,12 @@ struct vlan_hdr { uint16_t eth_proto;/**< Ethernet type of encapsulated frame. */ } __attribute__((__packed__)); +/* VXLAN protocol header */ +struct vxlan_hdr { + uint32_t vx_flags; /**< VxLAN flag. */ + uint32_t vx_vni; /**< VxLAN ID. */ +} __attribute__((__packed__)); + /* Ethernet frame types */ #define ETHER_TYPE_IPv4 0x0800 /**< IPv4 Protocol. */ #define ETHER_TYPE_IPv6 0x86DD /**< IPv6 Protocol. */ @@ -294,6 +302,8 @@ struct vlan_hdr { #define ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */ #define ETHER_TYPE_1588 0x88F7 /**< IEEE 802.1AS 1588 Precise Time Protocol. */ +#define ETHER_VXLAN_HLEN (sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr)) + #ifdef __cplusplus } #endif diff --git a/lib/librte_pmd_i40e/i40e_ethdev.c b/lib/librte_pmd_i40e/i40e_ethdev.c index 9ed31b5..bb3d39a 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev.c +++ b/lib/librte_pmd_i40e/i40e_ethdev.c @@ -187,7 +187,7 @@ static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool, static int i40e_dev_init_vlan(struct rte_eth_dev *dev); static int i40e_veb_release(struct i40e_veb *veb); static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, - struct i40e_vsi *vsi); + struct i40e_vsi *vsi); static int i40e_pf_config_mq_rx(struct i40e_pf *pf); static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on); static inline int i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi, @@ -203,6 +203,13 @@ static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf); static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf); +static int i40e_dev_udp_tunnel_add(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *udp_tunnel, + uint8_t count); +static int i40e_dev_udp_tunnel_del(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *udp_tunnel, + uint8_t count); +static int i40e_pf_config_vxlan(struct i40e_pf *pf); /* Default hash key buffer for RSS */ static uint32_t rss_key_default[I40E_PFQF_HKEY_MAX_INDEX + 1]; @@ -248,6 +255,8 @@ static struct eth_dev_ops i40e_eth_dev_ops = { .reta_query = i40e_dev_rss_reta_query, .rss_hash_update = i40e_dev_rss_hash_update, .rss_hash_conf_get = i40e_dev_rss_hash_conf_get, + .udp_tunnel_add = i40e_dev_udp_tunnel_add, + .udp_tunnel_del = i40e_dev_udp_tunnel_del, }; static struct eth_driver rte_i40e_pmd = { @@ -2365,6 +2374,34 @@ i40e_vsi_dump_bw_config(struct i40e_vsi *vsi) return 0; } +static int +i40e_vxlan_filters_init(struct i40e_pf *pf) +{ + uint8_t filter_index; + int ret = 0; + struct i40e_hw *hw = I40E_PF_TO_HW(pf); + + if (!(pf->flags & I40E_FLAG_VXLAN)) + return 0; + + /* Init first entry in tunneling UDP table */ + ret = i40e_aq_add_udp_tunnel(hw, ETHER_VXLAN_UDP_PORT, + I40E_AQC_TUNNEL_TYPE_VXLAN, + &filter_index, NULL); + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to add UDP tunnel port %d " + "with index=%d\n", RTE_VXLAN_UDP_PORT, + filter_index); + } else { + pf->vxlan_bitmap |= 1; + pf->vxlan_ports[0] = ETHER_VXLAN_UDP_PORT; + PMD_DRV_LOG(INFO, "Added UDP tunnel port %d with " + "index=%d\n", RTE_VXLAN_UDP_PORT, filter_index); + } + + return ret; +} + /* Setup a VSI */ struct i40e_vsi * i40e_vsi_setup(struct i40e_pf *pf, @@ -2988,6 +3025,12 @@ i40e_vsi_rx_init(struct i40e_vsi *vsi) uint16_t i; i40e_pf_config_mq_rx(pf); + + if (data->dev_conf.tunnel_type == RTE_TUNNEL_TYPE_VXLAN) { + pf->flags |= I40E_FLAG_VXLAN; + i40e_pf_config_vxlan(pf); + } + for (i = 0; i < data->nb_rx_queues; i++) { ret = i40e_rx_queue_init(data->rx_queues[i]); if (ret != I40E_SUCCESS) { @@ -3904,6 +3947,150 @@ i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev, return 0; } +static int +i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port) +{ + uint8_t i; + + for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { + if (pf->vxlan_ports[i] == port) + return i; + } + + return -1; +} + +static int +i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port) +{ + int idx, ret; + uint8_t filter_idx; + struct i40e_hw *hw = I40E_PF_TO_HW(pf); + + if (!(pf->flags & I40E_FLAG_VXLAN)) { + PMD_DRV_LOG(ERR, "VxLAN tunneling mode is not configured\n"); + return -EINVAL; + } + + idx = i40e_get_vxlan_port_idx(pf, port); + + /* Check if port already exists */ + if (idx >= 0) { + PMD_DRV_LOG(ERR, "Port %d already offloaded\n", port); + return -1; + } + + /* Now check if there is space to add the new port */ + idx = i40e_get_vxlan_port_idx(pf, 0); + if (idx < 0) { + PMD_DRV_LOG(ERR, "Maximum number of UDP ports reached," + "not adding port %d\n", port); + return -ENOSPC; + } + + ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN, + &filter_idx, NULL); + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to add VxLAN UDP port %d\n", port); + return -1; + } + + PMD_DRV_LOG(INFO, "Added %s port %d with AQ command with index %d\n", + port, filter_index); + + /* New port: add it and mark its index in the bitmap */ + pf->vxlan_ports[idx] = port; + pf->vxlan_bitmap |= (1 << idx); + + return 0; +} + +static int +i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port) +{ + int idx; + struct i40e_hw *hw = I40E_PF_TO_HW(pf); + + idx = i40e_get_vxlan_port_idx(pf, port); + + if (idx < 0) { + PMD_DRV_LOG(ERR, "Port %d doesn't exist\n", port); + return -1; + } + + if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) { + PMD_DRV_LOG(ERR, "Failed to delete VxLAN UDP port %d\n", port); + return -1; + } + + PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d\n", + port, idx); + + pf->vxlan_ports[idx] = 0; + pf->vxlan_bitmap &= ~(1 << idx); + + return 0; +} + +/* configure port of UDP tunneling */ +static int +i40e_dev_udp_tunnel_add(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *udp_tunnel, uint8_t count) +{ + uint16_t i; + int ret = 0; + struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private); + + for (i = 0; i < count; i++, udp_tunnel++) { + switch (udp_tunnel->prot_type) { + case RTE_TUNNEL_TYPE_VXLAN: + ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port); + break; + + case RTE_TUNNEL_TYPE_GENEVE: + case RTE_TUNNEL_TYPE_TEREDO: + PMD_DRV_LOG(ERR, "Tunnel type is not supported now.\n"); + ret = -1; + break; + + default: + PMD_DRV_LOG(ERR, "Invalid tunnel type\n"); + ret = -1; + break; + } + } + + return ret; +} + +static int +i40e_dev_udp_tunnel_del(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *udp_tunnel, uint8_t count) +{ + uint16_t i; + int ret = 0; + struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private); + + for (i = 0; i < count; i++, udp_tunnel++) { + switch (udp_tunnel->prot_type) { + case RTE_TUNNEL_TYPE_VXLAN: + ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port); + break; + case RTE_TUNNEL_TYPE_GENEVE: + case RTE_TUNNEL_TYPE_TEREDO: + PMD_DRV_LOG(ERR, "Tunnel type is not supported now.\n"); + ret = -1; + break; + default: + PMD_DRV_LOG(ERR, "Invalid tunnel type\n"); + ret = -1; + break; + } + } + + return ret; +} + /* Configure RSS */ static int i40e_pf_config_rss(struct i40e_pf *pf) @@ -3940,6 +4127,16 @@ i40e_pf_config_rss(struct i40e_pf *pf) return i40e_hw_rss_hash_set(hw, &rss_conf); } +/* Configure VxLAN */ +static int +i40e_pf_config_vxlan(struct i40e_pf *pf) +{ + if (pf->flags & I40E_FLAG_VXLAN) + i40e_vxlan_filters_init(pf); + + return 0; +} + static int i40e_pf_config_mq_rx(struct i40e_pf *pf) { diff --git a/lib/librte_pmd_i40e/i40e_ethdev.h b/lib/librte_pmd_i40e/i40e_ethdev.h index 64deef2..22d0628 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev.h +++ b/lib/librte_pmd_i40e/i40e_ethdev.h @@ -60,6 +60,7 @@ #define I40E_FLAG_HEADER_SPLIT_DISABLED (1ULL << 4) #define I40E_FLAG_HEADER_SPLIT_ENABLED (1ULL << 5) #define I40E_FLAG_FDIR (1ULL << 6) +#define I40E_FLAG_VXLAN (1ULL << 7) #define I40E_FLAG_ALL (I40E_FLAG_RSS | \ I40E_FLAG_DCB | \ I40E_FLAG_VMDQ | \ @@ -216,6 +217,10 @@ struct i40e_pf { uint16_t vmdq_nb_qps; /* The number of queue pairs of VMDq */ uint16_t vf_nb_qps; /* The number of queue pairs of VF */ uint16_t fdir_nb_qps; /* The number of queue pairs of Flow Director */ + + /* store VxLAN UDP ports */ + uint16_t vxlan_ports[I40E_MAX_PF_UDP_OFFLOAD_PORTS]; + uint16_t vxlan_bitmap; /* Vxlan bit mask */ }; enum pending_msg { -- 1.7.7.6