net/tap: define offload capabilities constants
[dpdk.git] / drivers / net / tap / rte_eth_tap.c
index e592a46..c515de3 100644 (file)
@@ -7,8 +7,8 @@
 #include <rte_byteorder.h>
 #include <rte_common.h>
 #include <rte_mbuf.h>
-#include <rte_ethdev_driver.h>
-#include <rte_ethdev_vdev.h>
+#include <ethdev_driver.h>
+#include <ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_bus_vdev.h>
 #include <rte_kvargs.h>
 
 #define TAP_IOV_DEFAULT_MAX 1024
 
+#define TAP_RX_OFFLOAD (DEV_RX_OFFLOAD_SCATTER |       \
+                       DEV_RX_OFFLOAD_IPV4_CKSUM |     \
+                       DEV_RX_OFFLOAD_UDP_CKSUM |      \
+                       DEV_RX_OFFLOAD_TCP_CKSUM)
+
+#define TAP_TX_OFFLOAD (DEV_TX_OFFLOAD_MULTI_SEGS |    \
+                       DEV_TX_OFFLOAD_IPV4_CKSUM |     \
+                       DEV_TX_OFFLOAD_UDP_CKSUM |      \
+                       DEV_TX_OFFLOAD_TCP_CKSUM |      \
+                       DEV_TX_OFFLOAD_TCP_TSO)
+
 static int tap_devices_count;
 
 static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {
@@ -303,6 +314,7 @@ tap_verify_csum(struct rte_mbuf *mbuf)
        uint16_t cksum = 0;
        void *l3_hdr;
        void *l4_hdr;
+       struct rte_udp_hdr *udp_hdr;
 
        if (l2 == RTE_PTYPE_L2_ETHER_VLAN)
                l2_len += 4;
@@ -341,42 +353,44 @@ tap_verify_csum(struct rte_mbuf *mbuf)
                                rte_pktmbuf_data_len(mbuf))
                        return;
        } else {
-               /* IPv6 extensions are not supported */
+               /* - RTE_PTYPE_L3_IPV4_EXT_UNKNOWN cannot happen because
+                *   mbuf->packet_type is filled by rte_net_get_ptype() which
+                *   never returns this value.
+                * - IPv6 extensions are not supported.
+                */
                return;
        }
        if (l4 == RTE_PTYPE_L4_UDP || l4 == RTE_PTYPE_L4_TCP) {
+               int cksum_ok;
+
                l4_hdr = rte_pktmbuf_mtod_offset(mbuf, void *, l2_len + l3_len);
                /* Don't verify checksum for multi-segment packets. */
                if (mbuf->nb_segs > 1)
                        return;
-               if (l3 == RTE_PTYPE_L3_IPV4)
-                       cksum = ~rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr);
-               else if (l3 == RTE_PTYPE_L3_IPV6)
-                       cksum = ~rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr);
-               mbuf->ol_flags |= cksum ?
-                       PKT_RX_L4_CKSUM_BAD :
-                       PKT_RX_L4_CKSUM_GOOD;
+               if (l3 == RTE_PTYPE_L3_IPV4 || l3 == RTE_PTYPE_L3_IPV4_EXT) {
+                       if (l4 == RTE_PTYPE_L4_UDP) {
+                               udp_hdr = (struct rte_udp_hdr *)l4_hdr;
+                               if (udp_hdr->dgram_cksum == 0) {
+                                       /*
+                                        * For IPv4, a zero UDP checksum
+                                        * indicates that the sender did not
+                                        * generate one [RFC 768].
+                                        */
+                                       mbuf->ol_flags |= PKT_RX_L4_CKSUM_NONE;
+                                       return;
+                               }
+                       }
+                       cksum_ok = !rte_ipv4_udptcp_cksum_verify(l3_hdr,
+                                                                l4_hdr);
+               } else { /* l3 == RTE_PTYPE_L3_IPV6, checked above */
+                       cksum_ok = !rte_ipv6_udptcp_cksum_verify(l3_hdr,
+                                                                l4_hdr);
+               }
+               mbuf->ol_flags |= cksum_ok ?
+                       PKT_RX_L4_CKSUM_GOOD : PKT_RX_L4_CKSUM_BAD;
        }
 }
 
-static uint64_t
-tap_rx_offload_get_port_capa(void)
-{
-       /*
-        * No specific port Rx offload capabilities.
-        */
-       return 0;
-}
-
-static uint64_t
-tap_rx_offload_get_queue_capa(void)
-{
-       return DEV_RX_OFFLOAD_SCATTER |
-              DEV_RX_OFFLOAD_IPV4_CKSUM |
-              DEV_RX_OFFLOAD_UDP_CKSUM |
-              DEV_RX_OFFLOAD_TCP_CKSUM;
-}
-
 static void
 tap_rxq_pool_free(struct rte_mbuf *pool)
 {
@@ -492,25 +506,6 @@ end:
        return num_rx;
 }
 
-static uint64_t
-tap_tx_offload_get_port_capa(void)
-{
-       /*
-        * No specific port Tx offload capabilities.
-        */
-       return 0;
-}
-
-static uint64_t
-tap_tx_offload_get_queue_capa(void)
-{
-       return DEV_TX_OFFLOAD_MULTI_SEGS |
-              DEV_TX_OFFLOAD_IPV4_CKSUM |
-              DEV_TX_OFFLOAD_UDP_CKSUM |
-              DEV_TX_OFFLOAD_TCP_CKSUM |
-              DEV_TX_OFFLOAD_TCP_TSO;
-}
-
 /* Finalize l4 checksum calculation */
 static void
 tap_tx_l4_cksum(uint16_t *l4_cksum, uint16_t l4_phdr_cksum,
@@ -751,8 +746,16 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
                        if (num_tso_mbufs < 0)
                                break;
 
-                       mbuf = gso_mbufs;
-                       num_mbufs = num_tso_mbufs;
+                       if (num_tso_mbufs >= 1) {
+                               mbuf = gso_mbufs;
+                               num_mbufs = num_tso_mbufs;
+                       } else {
+                               /* 0 means it can be transmitted directly
+                                * without gso.
+                                */
+                               mbuf = &mbuf_in;
+                               num_mbufs = 1;
+                       }
                } else {
                        /* stats.errs will be incremented */
                        if (rte_pktmbuf_pkt_len(mbuf_in) > max_size)
@@ -900,7 +903,7 @@ tap_dev_start(struct rte_eth_dev *dev)
 
 /* This function gets called when the current port gets stopped.
  */
-static void
+static int
 tap_dev_stop(struct rte_eth_dev *dev)
 {
        int i;
@@ -912,6 +915,8 @@ tap_dev_stop(struct rte_eth_dev *dev)
 
        tap_intr_handle_set(dev, 0);
        tap_link_set_down(dev);
+
+       return 0;
 }
 
 static int
@@ -991,12 +996,10 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->max_tx_queues = RTE_PMD_TAP_MAX_QUEUES;
        dev_info->min_rx_bufsize = 0;
        dev_info->speed_capa = tap_dev_speed_capa();
-       dev_info->rx_queue_offload_capa = tap_rx_offload_get_queue_capa();
-       dev_info->rx_offload_capa = tap_rx_offload_get_port_capa() |
-                                   dev_info->rx_queue_offload_capa;
-       dev_info->tx_queue_offload_capa = tap_tx_offload_get_queue_capa();
-       dev_info->tx_offload_capa = tap_tx_offload_get_port_capa() |
-                                   dev_info->tx_queue_offload_capa;
+       dev_info->rx_queue_offload_capa = TAP_RX_OFFLOAD;
+       dev_info->rx_offload_capa = dev_info->rx_queue_offload_capa;
+       dev_info->tx_queue_offload_capa = TAP_TX_OFFLOAD;
+       dev_info->tx_offload_capa = dev_info->tx_queue_offload_capa;
        dev_info->hash_key_size = TAP_RSS_HASH_KEY_SIZE;
        /*
         * limitation: TAP supports all of IP, UDP and TCP hash
@@ -1109,8 +1112,11 @@ tap_dev_close(struct rte_eth_dev *dev)
 
        if (internals->remote_if_index) {
                /* Restore initial remote state */
-               ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
+               int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
                                &internals->remote_initial_flags);
+               if (ret)
+                       TAP_LOG(ERR, "restore remote state failed: %d", ret);
+
        }
 
        rte_mempool_free(internals->gso_ctx_mp);
@@ -1133,7 +1139,6 @@ tap_dev_close(struct rte_eth_dev *dev)
                internals->ioctl_sock = -1;
        }
        rte_free(dev->process_private);
-       dev->process_private = NULL;
        if (tap_devices_count == 1)
                rte_mp_action_unregister(TAP_MP_KEY);
        tap_devices_count--;
@@ -1867,7 +1872,7 @@ static const struct eth_dev_ops ops = {
        .stats_reset            = tap_stats_reset,
        .dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
        .rss_hash_update        = tap_rss_hash_update,
-       .filter_ctrl            = tap_dev_filter_ctrl,
+       .flow_ops_get           = tap_dev_flow_ops_get,
 };
 
 static int
@@ -1921,7 +1926,8 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
        /* Setup some default values */
        data = dev->data;
        data->dev_private = pmd;
-       data->dev_flags = RTE_ETH_DEV_INTR_LSC;
+       data->dev_flags = RTE_ETH_DEV_INTR_LSC |
+                               RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
        data->numa_node = numa_node;
 
        data->dev_link = pmd_link;
@@ -2544,4 +2550,4 @@ RTE_PMD_REGISTER_PARAM_STRING(net_tap,
                              ETH_TAP_IFACE_ARG "=<string> "
                              ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_ARG_FMT " "
                              ETH_TAP_REMOTE_ARG "=<string>");
-RTE_LOG_REGISTER(tap_logtype, pmd.net.tap, NOTICE);
+RTE_LOG_REGISTER_DEFAULT(tap_logtype, NOTICE);