-/* Enable l2 tunnel forwarding */
-static int
-ixgbe_dev_l2_tunnel_forwarding_enable
- (struct rte_eth_dev *dev,
- enum rte_eth_tunnel_type l2_tunnel_type)
-{
- struct ixgbe_l2_tn_info *l2_tn_info =
- IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
- int ret = 0;
-
- switch (l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- l2_tn_info->e_tag_fwd_en = TRUE;
- ret = ixgbe_e_tag_forwarding_en_dis(dev, 1);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-/* Disable l2 tunnel forwarding */
-static int
-ixgbe_dev_l2_tunnel_forwarding_disable
- (struct rte_eth_dev *dev,
- enum rte_eth_tunnel_type l2_tunnel_type)
-{
- struct ixgbe_l2_tn_info *l2_tn_info =
- IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
- int ret = 0;
-
- switch (l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- l2_tn_info->e_tag_fwd_en = FALSE;
- ret = ixgbe_e_tag_forwarding_en_dis(dev, 0);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-static int
-ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
- struct rte_eth_l2_tunnel_conf *l2_tunnel,
- bool en)
-{
- struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
- int ret = 0;
- uint32_t vmtir, vmvir;
- struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-
- if (l2_tunnel->vf_id >= pci_dev->max_vfs) {
- PMD_DRV_LOG(ERR,
- "VF id %u should be less than %u",
- l2_tunnel->vf_id,
- pci_dev->max_vfs);
- return -EINVAL;
- }
-
- if (hw->mac.type != ixgbe_mac_X550 &&
- hw->mac.type != ixgbe_mac_X550EM_x &&
- hw->mac.type != ixgbe_mac_X550EM_a) {
- return -ENOTSUP;
- }
-
- if (en)
- vmtir = l2_tunnel->tunnel_id;
- else
- vmtir = 0;
-
- IXGBE_WRITE_REG(hw, IXGBE_VMTIR(l2_tunnel->vf_id), vmtir);
-
- vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id));
- vmvir &= ~IXGBE_VMVIR_TAGA_MASK;
- if (en)
- vmvir |= IXGBE_VMVIR_TAGA_ETAG_INSERT;
- IXGBE_WRITE_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id), vmvir);
-
- return ret;
-}
-
-/* Enable l2 tunnel tag insertion */
-static int
-ixgbe_dev_l2_tunnel_insertion_enable(struct rte_eth_dev *dev,
- struct rte_eth_l2_tunnel_conf *l2_tunnel)
-{
- int ret = 0;
-
- switch (l2_tunnel->l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 1);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-/* Disable l2 tunnel tag insertion */
-static int
-ixgbe_dev_l2_tunnel_insertion_disable
- (struct rte_eth_dev *dev,
- struct rte_eth_l2_tunnel_conf *l2_tunnel)
-{
- int ret = 0;
-
- switch (l2_tunnel->l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 0);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-static int
-ixgbe_e_tag_stripping_en_dis(struct rte_eth_dev *dev,
- bool en)
-{
- int ret = 0;
- uint32_t qde;
- struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-
- if (hw->mac.type != ixgbe_mac_X550 &&
- hw->mac.type != ixgbe_mac_X550EM_x &&
- hw->mac.type != ixgbe_mac_X550EM_a) {
- return -ENOTSUP;
- }
-
- qde = IXGBE_READ_REG(hw, IXGBE_QDE);
- if (en)
- qde |= IXGBE_QDE_STRIP_TAG;
- else
- qde &= ~IXGBE_QDE_STRIP_TAG;
- qde &= ~IXGBE_QDE_READ;
- qde |= IXGBE_QDE_WRITE;
- IXGBE_WRITE_REG(hw, IXGBE_QDE, qde);
-
- return ret;
-}
-
-/* Enable l2 tunnel tag stripping */
-static int
-ixgbe_dev_l2_tunnel_stripping_enable
- (struct rte_eth_dev *dev,
- enum rte_eth_tunnel_type l2_tunnel_type)
-{
- int ret = 0;
-
- switch (l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- ret = ixgbe_e_tag_stripping_en_dis(dev, 1);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-/* Disable l2 tunnel tag stripping */
-static int
-ixgbe_dev_l2_tunnel_stripping_disable
- (struct rte_eth_dev *dev,
- enum rte_eth_tunnel_type l2_tunnel_type)
-{
- int ret = 0;
-
- switch (l2_tunnel_type) {
- case RTE_L2_TUNNEL_TYPE_E_TAG:
- ret = ixgbe_e_tag_stripping_en_dis(dev, 0);
- break;
- default:
- PMD_DRV_LOG(ERR, "Invalid tunnel type");
- ret = -EINVAL;
- break;
- }
-
- return ret;
-}
-
-/* Enable/disable l2 tunnel offload functions */
-static int
-ixgbe_dev_l2_tunnel_offload_set
- (struct rte_eth_dev *dev,
- struct rte_eth_l2_tunnel_conf *l2_tunnel,
- uint32_t mask,
- uint8_t en)
-{
- int ret = 0;
-
- if (l2_tunnel == NULL)
- return -EINVAL;
-
- ret = -EINVAL;
- if (mask & ETH_L2_TUNNEL_ENABLE_MASK) {
- if (en)
- ret = ixgbe_dev_l2_tunnel_enable(
- dev,
- l2_tunnel->l2_tunnel_type);
- else
- ret = ixgbe_dev_l2_tunnel_disable(
- dev,
- l2_tunnel->l2_tunnel_type);
- }
-
- if (mask & ETH_L2_TUNNEL_INSERTION_MASK) {
- if (en)
- ret = ixgbe_dev_l2_tunnel_insertion_enable(
- dev,
- l2_tunnel);
- else
- ret = ixgbe_dev_l2_tunnel_insertion_disable(
- dev,
- l2_tunnel);
- }
-
- if (mask & ETH_L2_TUNNEL_STRIPPING_MASK) {
- if (en)
- ret = ixgbe_dev_l2_tunnel_stripping_enable(
- dev,
- l2_tunnel->l2_tunnel_type);
- else
- ret = ixgbe_dev_l2_tunnel_stripping_disable(
- dev,
- l2_tunnel->l2_tunnel_type);
- }
-
- if (mask & ETH_L2_TUNNEL_FORWARDING_MASK) {
- if (en)
- ret = ixgbe_dev_l2_tunnel_forwarding_enable(
- dev,
- l2_tunnel->l2_tunnel_type);
- else
- ret = ixgbe_dev_l2_tunnel_forwarding_disable(
- dev,
- l2_tunnel->l2_tunnel_type);
- }
-
- return ret;
-}
-