ethdev: fix missing imissed counter in xstats
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index 0b1e928..4f492e3 100644 (file)
@@ -47,7 +47,6 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_interrupts.h>
-#include <rte_pci.h>
 #include <rte_memory.h>
 #include <rte_memcpy.h>
 #include <rte_memzone.h>
@@ -94,6 +93,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
        {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
        {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
        {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
+       {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
        {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
        {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
        {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
@@ -301,6 +301,13 @@ rte_eth_dev_socket_id(uint16_t port_id)
        return rte_eth_devices[port_id].data->numa_node;
 }
 
+void *
+rte_eth_dev_get_sec_ctx(uint8_t port_id)
+{
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
+       return rte_eth_devices[port_id].security_ctx;
+}
+
 uint16_t
 rte_eth_dev_count(void)
 {
@@ -356,21 +363,6 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
        return -ENODEV;
 }
 
-static int
-rte_eth_dev_is_detachable(uint16_t port_id)
-{
-       uint32_t dev_flags;
-
-       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
-
-       dev_flags = rte_eth_devices[port_id].data->dev_flags;
-       if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
-               (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
-               return 0;
-       else
-               return 1;
-}
-
 /* attach the new device, then store port_id of the device */
 int
 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
@@ -421,16 +413,23 @@ err:
 int
 rte_eth_dev_detach(uint16_t port_id, char *name)
 {
+       uint32_t dev_flags;
        int ret = -1;
 
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
+
        if (name == NULL) {
                ret = -EINVAL;
                goto err;
        }
 
-       /* FIXME: move this to eal, once device flags are relocated there */
-       if (rte_eth_dev_is_detachable(port_id))
+       dev_flags = rte_eth_devices[port_id].data->dev_flags;
+       if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
+               RTE_LOG(ERR, EAL, "Port %" PRIu16 " is bonded, cannot detach\n",
+                       port_id);
+               ret = -ENOTSUP;
                goto err;
+       }
 
        snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
                 "%s", rte_eth_devices[port_id].data->name);
@@ -712,6 +711,8 @@ rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
                offloads |= DEV_RX_OFFLOAD_TCP_LRO;
        if (rxmode->hw_timestamp == 1)
                offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
+       if (rxmode->security == 1)
+               offloads |= DEV_RX_OFFLOAD_SECURITY;
 
        *rx_offloads = offloads;
 }
@@ -764,6 +765,10 @@ rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
                rxmode->hw_timestamp = 1;
        else
                rxmode->hw_timestamp = 0;
+       if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
+               rxmode->security = 1;
+       else
+               rxmode->security = 0;
 }
 
 int
@@ -1550,6 +1555,22 @@ rte_eth_stats_reset(uint16_t port_id)
        return 0;
 }
 
+static inline int
+get_xstats_basic_count(struct rte_eth_dev *dev)
+{
+       uint16_t nb_rxqs, nb_txqs;
+       int count;
+
+       nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+       nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+
+       count = RTE_NB_STATS;
+       count += nb_rxqs * RTE_NB_RXQ_STATS;
+       count += nb_txqs * RTE_NB_TXQ_STATS;
+
+       return count;
+}
+
 static int
 get_xstats_count(uint16_t port_id)
 {
@@ -1571,11 +1592,9 @@ get_xstats_count(uint16_t port_id)
        } else
                count = 0;
 
-       count += RTE_NB_STATS;
-       count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-                RTE_NB_RXQ_STATS;
-       count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
-                RTE_NB_TXQ_STATS;
+
+       count += get_xstats_basic_count(dev);
+
        return count;
 }
 
@@ -1630,14 +1649,20 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
        uint64_t *ids)
 {
        struct rte_eth_xstat_name *xstats_names_copy;
+       unsigned int no_basic_stat_requested = 1;
        unsigned int expected_entries;
        struct rte_eth_dev *dev;
        unsigned int i;
+       int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-       expected_entries = get_xstats_count(port_id);
        dev = &rte_eth_devices[port_id];
 
+       ret = get_xstats_count(port_id);
+       if (ret < 0)
+               return ret;
+       expected_entries = (unsigned int)ret;
+
        /* Return max number of stats if no ids given */
        if (!ids) {
                if (!xstats_names)
@@ -1649,9 +1674,27 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id,
        if (ids && !xstats_names)
                return -EINVAL;
 
-       if (dev->dev_ops->xstats_get_names_by_id != NULL)
-               return (*dev->dev_ops->xstats_get_names_by_id)(
-                               dev, xstats_names, ids, size);
+       if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
+               unsigned int basic_count = get_xstats_basic_count(dev);
+               uint64_t ids_copy[size];
+
+               for (i = 0; i < size; i++) {
+                       if (ids[i] < basic_count) {
+                               no_basic_stat_requested = 0;
+                               break;
+                       }
+
+                       /*
+                        * Convert ids to xstats ids that PMD knows.
+                        * ids known by user are basic + extended stats.
+                        */
+                       ids_copy[i] = ids[i] - basic_count;
+               }
+
+               if (no_basic_stat_requested)
+                       return (*dev->dev_ops->xstats_get_names_by_id)(dev,
+                                       xstats_names, ids_copy, size);
+       }
 
        /* Retrieve all stats */
        if (!ids) {
@@ -1758,10 +1801,12 @@ int
 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
                         uint64_t *values, unsigned int size)
 {
+       unsigned int no_basic_stat_requested = 1;
        unsigned int num_xstats_filled;
        uint16_t expected_entries;
        struct rte_eth_dev *dev;
        unsigned int i;
+       int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        expected_entries = get_xstats_count(port_id);
@@ -1779,13 +1824,33 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
        if (ids && !values)
                return -EINVAL;
 
-       if (dev->dev_ops->xstats_get_by_id != NULL)
-               return (*dev->dev_ops->xstats_get_by_id)(dev, ids, values,
-                       size);
+       if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
+               unsigned int basic_count = get_xstats_basic_count(dev);
+               uint64_t ids_copy[size];
+
+               for (i = 0; i < size; i++) {
+                       if (ids[i] < basic_count) {
+                               no_basic_stat_requested = 0;
+                               break;
+                       }
+
+                       /*
+                        * Convert ids to xstats ids that PMD knows.
+                        * ids known by user are basic + extended stats.
+                        */
+                       ids_copy[i] = ids[i] - basic_count;
+               }
+
+               if (no_basic_stat_requested)
+                       return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
+                                       values, size);
+       }
 
        /* Fill the xstats structure */
-       num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
-               expected_entries);
+       ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
+       if (ret < 0)
+               return ret;
+       num_xstats_filled = (unsigned int)ret;
 
        /* Return all stats */
        if (!ids) {
@@ -2120,10 +2185,14 @@ rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
        int ret = 0;
        int mask = 0;
        int cur, org = 0;
+       uint64_t orig_offloads;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
+       /* save original values in case of failure */
+       orig_offloads = dev->data->dev_conf.rxmode.offloads;
+
        /*check which option changed by application*/
        cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
        org = !!(dev->data->dev_conf.rxmode.offloads &
@@ -2176,7 +2245,13 @@ rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
         */
        rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
                                    &dev->data->dev_conf.rxmode);
-       (*dev->dev_ops->vlan_offload_set)(dev, mask);
+       ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
+       if (ret) {
+               /* hit an error restore  original values */
+               dev->data->dev_conf.rxmode.offloads = orig_offloads;
+               rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
+                                           &dev->data->dev_conf.rxmode);
+       }
 
        return ret;
 }