net/ionic: allow separate L3 and L4 checksum offload
[dpdk.git] / drivers / net / ionic / ionic_ethdev.c
index fd7cd51..9a319df 100644 (file)
@@ -5,9 +5,9 @@
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
 #include <rte_ethdev.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_malloc.h>
-#include <rte_ethdev_pci.h>
+#include <ethdev_pci.h>
 
 #include "ionic_logs.h"
 #include "ionic.h"
@@ -276,7 +276,10 @@ ionic_dev_link_update(struct rte_eth_dev *eth_dev,
 
        /* Initialize */
        memset(&link, 0, sizeof(link));
-       link.link_autoneg = ETH_LINK_AUTONEG;
+
+       if (adapter->idev.port_info->config.an_enable) {
+               link.link_autoneg = ETH_LINK_AUTONEG;
+       }
 
        if (!adapter->link_up ||
            !(lif->state & IONIC_LIF_F_UP)) {
@@ -371,13 +374,15 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
        struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
        struct ionic_adapter *adapter = lif->adapter;
        struct ionic_identity *ident = &adapter->ident;
+       union ionic_lif_config *cfg = &ident->lif.eth.config;
 
        IONIC_PRINT_CALL();
 
        dev_info->max_rx_queues = (uint16_t)
-               ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
+               rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]);
        dev_info->max_tx_queues = (uint16_t)
-               ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ];
+               rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]);
+
        /* Also add ETHER_CRC_LEN if the adapter is able to keep CRC */
        dev_info->min_rx_bufsize = IONIC_MIN_MTU + RTE_ETHER_HDR_LEN;
        dev_info->max_rx_pktlen = IONIC_MAX_MTU + RTE_ETHER_HDR_LEN;
@@ -386,7 +391,7 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
        dev_info->max_mtu = IONIC_MAX_MTU;
 
        dev_info->hash_key_size = IONIC_RSS_HASH_KEY_SIZE;
-       dev_info->reta_size = ident->lif.eth.rss_ind_tbl_sz;
+       dev_info->reta_size = rte_le_to_cpu_16(ident->lif.eth.rss_ind_tbl_sz);
        dev_info->flow_type_rss_offloads = IONIC_ETH_RSS_OFFLOAD_ALL;
 
        dev_info->speed_capa =
@@ -397,25 +402,16 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
                ETH_LINK_SPEED_100G;
 
        /*
-        * Per-queue capabilities. Actually most of the offloads are enabled
-        * by default on the port and can be used on selected queues (by adding
-        * packet flags at runtime when required)
+        * Per-queue capabilities
+        * RTE does not support disabling a feature on a queue if it is
+        * enabled globally on the device. Thus the driver does not advertise
+        * capabilities like DEV_TX_OFFLOAD_IPV4_CKSUM as per-queue even
+        * though the driver would be otherwise capable of disabling it on
+        * a per-queue basis.
         */
 
-       dev_info->rx_queue_offload_capa =
-               DEV_RX_OFFLOAD_IPV4_CKSUM |
-               DEV_RX_OFFLOAD_UDP_CKSUM |
-               DEV_RX_OFFLOAD_TCP_CKSUM |
-               0;
-
-       dev_info->tx_queue_offload_capa =
-               DEV_TX_OFFLOAD_IPV4_CKSUM |
-               DEV_TX_OFFLOAD_UDP_CKSUM |
-               DEV_TX_OFFLOAD_TCP_CKSUM |
-               DEV_TX_OFFLOAD_VLAN_INSERT |
-               DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
-               DEV_TX_OFFLOAD_OUTER_UDP_CKSUM |
-               0;
+       dev_info->rx_queue_offload_capa = 0;
+       dev_info->tx_queue_offload_capa = 0;
 
        /*
         * Per-port capabilities
@@ -423,15 +419,25 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
         */
 
        dev_info->rx_offload_capa = dev_info->rx_queue_offload_capa |
+               DEV_RX_OFFLOAD_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_UDP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_CKSUM |
                DEV_RX_OFFLOAD_JUMBO_FRAME |
                DEV_RX_OFFLOAD_VLAN_FILTER |
                DEV_RX_OFFLOAD_VLAN_STRIP |
                DEV_RX_OFFLOAD_SCATTER |
+               DEV_RX_OFFLOAD_RSS_HASH |
                0;
 
        dev_info->tx_offload_capa = dev_info->tx_queue_offload_capa |
+               DEV_TX_OFFLOAD_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_UDP_CKSUM |
+               DEV_TX_OFFLOAD_TCP_CKSUM |
+               DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_OUTER_UDP_CKSUM |
                DEV_TX_OFFLOAD_MULTI_SEGS |
                DEV_TX_OFFLOAD_TCP_TSO |
+               DEV_TX_OFFLOAD_VLAN_INSERT |
                0;
 
        dev_info->rx_desc_lim = rx_desc_lim;
@@ -445,6 +451,11 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
        dev_info->default_rxportconf.ring_size = IONIC_DEF_TXRX_DESC;
        dev_info->default_txportconf.ring_size = IONIC_DEF_TXRX_DESC;
 
+       dev_info->default_rxconf = (struct rte_eth_rxconf) {
+               /* Packets are always dropped if no desc are available */
+               .rx_drop_en = 1,
+       };
+
        return 0;
 }
 
@@ -457,7 +468,8 @@ ionic_flow_ctrl_get(struct rte_eth_dev *eth_dev,
        struct ionic_dev *idev = &adapter->idev;
 
        if (idev->port_info) {
-               fc_conf->autoneg = idev->port_info->config.an_enable;
+               /* Flow control autoneg not supported */
+               fc_conf->autoneg = 0;
 
                if (idev->port_info->config.pause_type)
                        fc_conf->mode = RTE_FC_FULL;
@@ -476,7 +488,12 @@ ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
        struct ionic_adapter *adapter = lif->adapter;
        struct ionic_dev *idev = &adapter->idev;
        uint8_t pause_type = IONIC_PORT_PAUSE_TYPE_NONE;
-       uint8_t an_enable;
+       int err;
+
+       if (fc_conf->autoneg) {
+               IONIC_PRINT(WARNING, "Flow control autoneg not supported");
+               return -ENOTSUP;
+       }
 
        switch (fc_conf->mode) {
        case RTE_FC_NONE:
@@ -490,46 +507,20 @@ ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
                return -ENOTSUP;
        }
 
-       an_enable = fc_conf->autoneg;
-
        ionic_dev_cmd_port_pause(idev, pause_type);
-       ionic_dev_cmd_port_autoneg(idev, an_enable);
+       err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+       if (err)
+               IONIC_PRINT(WARNING, "Failed to configure flow control");
 
-       return 0;
+       return err;
 }
 
 static int
 ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
 {
        struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
-       struct rte_eth_rxmode *rxmode;
-       rxmode = &eth_dev->data->dev_conf.rxmode;
-       int i;
-
-       if (mask & ETH_VLAN_STRIP_MASK) {
-               if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
-                       for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
-                               struct ionic_qcq *rxq =
-                                       eth_dev->data->rx_queues[i];
-                               rxq->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
-                       }
-                       lif->features |= IONIC_ETH_HW_VLAN_RX_STRIP;
-               } else {
-                       for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
-                               struct ionic_qcq *rxq =
-                                       eth_dev->data->rx_queues[i];
-                               rxq->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
-                       }
-                       lif->features &= ~IONIC_ETH_HW_VLAN_RX_STRIP;
-               }
-       }
 
-       if (mask & ETH_VLAN_FILTER_MASK) {
-               if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
-                       lif->features |= IONIC_ETH_HW_VLAN_RX_FILTER;
-               else
-                       lif->features &= ~IONIC_ETH_HW_VLAN_RX_FILTER;
-       }
+       ionic_lif_configure_vlan_offload(lif, mask);
 
        ionic_lif_set_features(lif);
 
@@ -545,6 +536,7 @@ ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
        struct ionic_adapter *adapter = lif->adapter;
        struct ionic_identity *ident = &adapter->ident;
        uint32_t i, j, index, num;
+       uint16_t tbl_sz = rte_le_to_cpu_16(ident->lif.eth.rss_ind_tbl_sz);
 
        IONIC_PRINT_CALL();
 
@@ -554,15 +546,15 @@ ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
                return -EINVAL;
        }
 
-       if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
+       if (reta_size != tbl_sz) {
                IONIC_PRINT(ERR, "The size of hash lookup table configured "
                        "(%d) does not match the number hardware can support "
                        "(%d)",
-                       reta_size, ident->lif.eth.rss_ind_tbl_sz);
+                       reta_size, tbl_sz);
                return -EINVAL;
        }
 
-       num = lif->adapter->ident.lif.eth.rss_ind_tbl_sz / RTE_RETA_GROUP_SIZE;
+       num = tbl_sz / RTE_RETA_GROUP_SIZE;
 
        for (i = 0; i < num; i++) {
                for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
@@ -585,14 +577,15 @@ ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
        struct ionic_adapter *adapter = lif->adapter;
        struct ionic_identity *ident = &adapter->ident;
        int i, num;
+       uint16_t tbl_sz = rte_le_to_cpu_16(ident->lif.eth.rss_ind_tbl_sz);
 
        IONIC_PRINT_CALL();
 
-       if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
+       if (reta_size != tbl_sz) {
                IONIC_PRINT(ERR, "The size of hash lookup table configured "
                        "(%d) does not match the number hardware can support "
                        "(%d)",
-                       reta_size, ident->lif.eth.rss_ind_tbl_sz);
+                       reta_size, tbl_sz);
                return -EINVAL;
        }
 
@@ -845,15 +838,12 @@ static int
 ionic_dev_configure(struct rte_eth_dev *eth_dev)
 {
        struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
-       int err;
 
        IONIC_PRINT_CALL();
 
-       err = ionic_lif_configure(lif);
-       if (err) {
-               IONIC_PRINT(ERR, "Cannot configure LIF: %d", err);
-               return err;
-       }
+       ionic_lif_configure(lif);
+
+       ionic_lif_set_features(lif);
 
        return 0;
 }
@@ -886,7 +876,8 @@ ionic_dev_start(struct rte_eth_dev *eth_dev)
        struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
        struct ionic_adapter *adapter = lif->adapter;
        struct ionic_dev *idev = &adapter->idev;
-       uint32_t allowed_speeds;
+       uint32_t speed = 0, allowed_speeds;
+       uint8_t an_enable;
        int err;
 
        IONIC_PRINT_CALL();
@@ -913,11 +904,23 @@ ionic_dev_start(struct rte_eth_dev *eth_dev)
                return err;
        }
 
-       if (eth_dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
-               uint32_t speed = ionic_parse_link_speeds(dev_conf->link_speeds);
+       /* Configure link */
+       an_enable = (dev_conf->link_speeds & ETH_LINK_SPEED_FIXED) == 0;
 
-               if (speed)
-                       ionic_dev_cmd_port_speed(idev, speed);
+       ionic_dev_cmd_port_autoneg(idev, an_enable);
+       err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+       if (err)
+               IONIC_PRINT(WARNING, "Failed to %s autonegotiation",
+                       an_enable ? "enable" : "disable");
+
+       if (!an_enable)
+               speed = ionic_parse_link_speeds(dev_conf->link_speeds);
+       if (speed) {
+               ionic_dev_cmd_port_speed(idev, speed);
+               err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+               if (err)
+                       IONIC_PRINT(WARNING, "Failed to set link speed %u",
+                               speed);
        }
 
        ionic_dev_link_update(eth_dev, 0);
@@ -1229,11 +1232,12 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
                goto err_free_adapter;
        }
 
-       adapter->max_mac_addrs = adapter->ident.lif.eth.max_ucast_filters;
+       adapter->max_mac_addrs =
+               rte_le_to_cpu_32(adapter->ident.lif.eth.max_ucast_filters);
 
-       if (adapter->ident.dev.nlifs != 1) {
+       if (rte_le_to_cpu_32(adapter->ident.dev.nlifs) != 1) {
                IONIC_PRINT(ERR, "Unexpected request for %d LIFs",
-                       adapter->ident.dev.nlifs);
+                       rte_le_to_cpu_32(adapter->ident.dev.nlifs));
                goto err_free_adapter;
        }