net/failsafe: support Rx offload capabilities
[dpdk.git] / drivers / net / failsafe / failsafe_ops.c
index fdef019..ac3257e 100644 (file)
@@ -36,6 +36,7 @@
 #include <rte_debug.h>
 #include <rte_ethdev.h>
 #include <rte_malloc.h>
+#include <rte_flow.h>
 
 #include "failsafe_private.h"
 
@@ -62,19 +63,146 @@ static struct rte_eth_dev_info default_infos = {
                .nb_seg_max = UINT16_MAX,
                .nb_mtu_seg_max = UINT16_MAX,
        },
-       /* Set of understood capabilities */
-       .rx_offload_capa = 0x0,
+       /*
+        * Set of capabilities that can be verified upon
+        * configuring a sub-device.
+        */
+       .rx_offload_capa =
+               DEV_RX_OFFLOAD_VLAN_STRIP |
+               DEV_RX_OFFLOAD_QINQ_STRIP |
+               DEV_RX_OFFLOAD_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_UDP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_LRO,
        .tx_offload_capa = 0x0,
        .flow_type_rss_offloads = 0x0,
 };
 
+/**
+ * Check whether a specific offloading capability
+ * is supported by a sub_device.
+ *
+ * @return
+ *   0: all requested capabilities are supported by the sub_device
+ *   positive value: This flag at least is not supported by the sub_device
+ */
+static int
+fs_port_offload_validate(struct rte_eth_dev *dev,
+                        struct sub_device *sdev)
+{
+       struct rte_eth_dev_info infos = {0};
+       struct rte_eth_conf *cf;
+       uint32_t cap;
+
+       cf = &dev->data->dev_conf;
+       SUBOPS(sdev, dev_infos_get)(ETH(sdev), &infos);
+       /* RX capabilities */
+       cap = infos.rx_offload_capa;
+       if (cf->rxmode.hw_vlan_strip &&
+           ((cap & DEV_RX_OFFLOAD_VLAN_STRIP) == 0)) {
+               WARN("VLAN stripping offload requested but not supported by sub_device %d",
+                     SUB_ID(sdev));
+               return DEV_RX_OFFLOAD_VLAN_STRIP;
+       }
+       if (cf->rxmode.hw_ip_checksum &&
+           ((cap & (DEV_RX_OFFLOAD_IPV4_CKSUM |
+                    DEV_RX_OFFLOAD_UDP_CKSUM |
+                    DEV_RX_OFFLOAD_TCP_CKSUM)) !=
+            (DEV_RX_OFFLOAD_IPV4_CKSUM |
+             DEV_RX_OFFLOAD_UDP_CKSUM |
+             DEV_RX_OFFLOAD_TCP_CKSUM))) {
+               WARN("IP checksum offload requested but not supported by sub_device %d",
+                     SUB_ID(sdev));
+               return DEV_RX_OFFLOAD_IPV4_CKSUM |
+                      DEV_RX_OFFLOAD_UDP_CKSUM |
+                      DEV_RX_OFFLOAD_TCP_CKSUM;
+       }
+       if (cf->rxmode.enable_lro &&
+           ((cap & DEV_RX_OFFLOAD_TCP_LRO) == 0)) {
+               WARN("TCP LRO offload requested but not supported by sub_device %d",
+                     SUB_ID(sdev));
+               return DEV_RX_OFFLOAD_TCP_LRO;
+       }
+       if (cf->rxmode.hw_vlan_extend &&
+           ((cap & DEV_RX_OFFLOAD_QINQ_STRIP) == 0)) {
+               WARN("Stacked VLAN stripping offload requested but not supported by sub_device %d",
+                     SUB_ID(sdev));
+               return DEV_RX_OFFLOAD_QINQ_STRIP;
+       }
+       /* TX capabilities */
+       /* Nothing to do, no tx capa supported */
+       return 0;
+}
+
+/*
+ * Disable the dev_conf flag related to an offload capability flag
+ * within an ethdev configuration.
+ */
+static int
+fs_port_disable_offload(struct rte_eth_conf *cf,
+                       uint32_t ol_cap)
+{
+       switch (ol_cap) {
+       case DEV_RX_OFFLOAD_VLAN_STRIP:
+               INFO("Disabling VLAN stripping offload");
+               cf->rxmode.hw_vlan_strip = 0;
+               break;
+       case DEV_RX_OFFLOAD_IPV4_CKSUM:
+       case DEV_RX_OFFLOAD_UDP_CKSUM:
+       case DEV_RX_OFFLOAD_TCP_CKSUM:
+       case (DEV_RX_OFFLOAD_IPV4_CKSUM |
+             DEV_RX_OFFLOAD_UDP_CKSUM |
+             DEV_RX_OFFLOAD_TCP_CKSUM):
+               INFO("Disabling IP checksum offload");
+               cf->rxmode.hw_ip_checksum = 0;
+               break;
+       case DEV_RX_OFFLOAD_TCP_LRO:
+               INFO("Disabling TCP LRO offload");
+               cf->rxmode.enable_lro = 0;
+               break;
+       case DEV_RX_OFFLOAD_QINQ_STRIP:
+               INFO("Disabling stacked VLAN stripping offload");
+               cf->rxmode.hw_vlan_extend = 0;
+               break;
+       default:
+               DEBUG("Unable to disable offload capability: %" PRIx32,
+                     ol_cap);
+               return -1;
+       }
+       return 0;
+}
+
 static int
 fs_dev_configure(struct rte_eth_dev *dev)
 {
        struct sub_device *sdev;
        uint8_t i;
+       int capa_flag;
        int ret;
 
+       FOREACH_SUBDEV(sdev, i, dev) {
+               if (sdev->state != DEV_PROBED)
+                       continue;
+               DEBUG("Checking capabilities for sub_device %d", i);
+               while ((capa_flag = fs_port_offload_validate(dev, sdev))) {
+                       /*
+                        * Refuse to change configuration if multiple devices
+                        * are present and we already have configured at least
+                        * some of them.
+                        */
+                       if (PRIV(dev)->state >= DEV_ACTIVE &&
+                           PRIV(dev)->subs_tail > 1) {
+                               ERROR("device already configured, cannot fix live configuration");
+                               return -1;
+                       }
+                       ret = fs_port_disable_offload(&dev->data->dev_conf,
+                                                     capa_flag);
+                       if (ret) {
+                               ERROR("Unable to disable offload capability");
+                               return ret;
+                       }
+               }
+       }
        FOREACH_SUBDEV(sdev, i, dev) {
                if (sdev->state != DEV_PROBED)
                        continue;
@@ -627,6 +755,33 @@ fs_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
                rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
 }
 
+static int
+fs_filter_ctrl(struct rte_eth_dev *dev,
+               enum rte_filter_type type,
+               enum rte_filter_op op,
+               void *arg)
+{
+       struct sub_device *sdev;
+       uint8_t i;
+       int ret;
+
+       if (type == RTE_ETH_FILTER_GENERIC &&
+           op == RTE_ETH_FILTER_GET) {
+               *(const void **)arg = &fs_flow_ops;
+               return 0;
+       }
+       FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
+               DEBUG("Calling rte_eth_dev_filter_ctrl on sub_device %d", i);
+               ret = rte_eth_dev_filter_ctrl(PORT_ID(sdev), type, op, arg);
+               if (ret) {
+                       ERROR("Operation rte_eth_dev_filter_ctrl failed for sub_device %d"
+                             " with error %d", i, ret);
+                       return ret;
+               }
+       }
+       return 0;
+}
+
 const struct eth_dev_ops failsafe_ops = {
        .dev_configure = fs_dev_configure,
        .dev_start = fs_dev_start,
@@ -654,4 +809,5 @@ const struct eth_dev_ops failsafe_ops = {
        .mac_addr_remove = fs_mac_addr_remove,
        .mac_addr_add = fs_mac_addr_add,
        .mac_addr_set = fs_mac_addr_set,
+       .filter_ctrl = fs_filter_ctrl,
 };