ethdev: query supported packet types
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index 98587e1..c0d85d6 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -495,7 +495,11 @@ rte_eth_dev_is_detachable(uint8_t port_id)
                return -ENOTSUP;
        }
        dev_flags = rte_eth_devices[port_id].data->dev_flags;
-       return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
+       if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
+               (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
+               return 0;
+       else
+               return 1;
 }
 
 /* attach the new physical device, then store port_id of the device */
@@ -1491,8 +1495,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
                /* Retrieve the xstats from the driver at the end of the
                 * xstats struct.
                 */
-               xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
-                        (n > count) ? n - count : 0);
+               xcount = (*dev->dev_ops->xstats_get)(dev,
+                                    xstats ? xstats + count : NULL,
+                                    (n > count) ? n - count : 0);
 
                if (xcount < 0)
                        return xcount;
@@ -1622,6 +1627,33 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
        dev_info->driver_name = dev->data->drv_name;
 }
 
+int
+rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
+                                uint32_t *ptypes, int num)
+{
+       int i, j;
+       struct rte_eth_dev *dev;
+       const uint32_t *all_ptypes;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       dev = &rte_eth_devices[port_id];
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get,
+                               -ENOTSUP);
+       all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
+
+       if (!all_ptypes)
+               return 0;
+
+       for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
+               if (all_ptypes[i] & ptype_mask) {
+                       if (j < num)
+                               ptypes[j] = all_ptypes[i];
+                       j++;
+               }
+
+       return j;
+}
+
 void
 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
 {
@@ -1703,16 +1735,17 @@ rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int o
 }
 
 int
-rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
+rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
+                               enum rte_vlan_type vlan_type,
+                               uint16_t tpid)
 {
        struct rte_eth_dev *dev;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
-       (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
 
-       return 0;
+       return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
 }
 
 int
@@ -1973,8 +2006,8 @@ 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)
+rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
+                               struct rte_eth_udp_tunnel *udp_tunnel)
 {
        struct rte_eth_dev *dev;
 
@@ -1990,13 +2023,13 @@ rte_eth_dev_udp_tunnel_add(uint8_t port_id,
        }
 
        dev = &rte_eth_devices[port_id];
-       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
-       return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
+       return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
 }
 
 int
-rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
-                             struct rte_eth_udp_tunnel *udp_tunnel)
+rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
+                                  struct rte_eth_udp_tunnel *udp_tunnel)
 {
        struct rte_eth_dev *dev;
 
@@ -2013,8 +2046,8 @@ rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
                return -EINVAL;
        }
 
-       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
-       return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
+       return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
 }
 
 int
@@ -3247,3 +3280,57 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de
        eth_dev->data->numa_node = pci_dev->numa_node;
        eth_dev->data->drv_name = pci_dev->driver->name;
 }
+
+int
+rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
+                                   struct rte_eth_l2_tunnel_conf *l2_tunnel)
+{
+       struct rte_eth_dev *dev;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       if (l2_tunnel == NULL) {
+               RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
+               return -EINVAL;
+       }
+
+       if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
+               RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
+               return -EINVAL;
+       }
+
+       dev = &rte_eth_devices[port_id];
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
+                               -ENOTSUP);
+       return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
+}
+
+int
+rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
+                                 struct rte_eth_l2_tunnel_conf *l2_tunnel,
+                                 uint32_t mask,
+                                 uint8_t en)
+{
+       struct rte_eth_dev *dev;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+       if (l2_tunnel == NULL) {
+               RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
+               return -EINVAL;
+       }
+
+       if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
+               RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
+               return -EINVAL;
+       }
+
+       if (mask == 0) {
+               RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
+               return -EINVAL;
+       }
+
+       dev = &rte_eth_devices[port_id];
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
+                               -ENOTSUP);
+       return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
+}