net/ionic: support FW version
[dpdk.git] / drivers / net / ionic / ionic_ethdev.c
index 0f5418f..363f0cf 100644 (file)
@@ -35,6 +35,29 @@ static int  ionic_flow_ctrl_get(struct rte_eth_dev *eth_dev,
 static int  ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
        struct rte_eth_fc_conf *fc_conf);
 static int  ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask);
+static int  ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
+       struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size);
+static int  ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
+       struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size);
+static int  ionic_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
+       struct rte_eth_rss_conf *rss_conf);
+static int  ionic_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
+       struct rte_eth_rss_conf *rss_conf);
+static int  ionic_dev_stats_get(struct rte_eth_dev *eth_dev,
+       struct rte_eth_stats *stats);
+static int  ionic_dev_stats_reset(struct rte_eth_dev *eth_dev);
+static int  ionic_dev_xstats_get(struct rte_eth_dev *dev,
+       struct rte_eth_xstat *xstats, unsigned int n);
+static int  ionic_dev_xstats_get_by_id(struct rte_eth_dev *dev,
+       const uint64_t *ids, uint64_t *values, unsigned int n);
+static int  ionic_dev_xstats_reset(struct rte_eth_dev *dev);
+static int  ionic_dev_xstats_get_names(struct rte_eth_dev *dev,
+       struct rte_eth_xstat_name *xstats_names, unsigned int size);
+static int  ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
+       struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
+       unsigned int limit);
+static int  ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
+       char *fw_version, size_t fw_size);
 
 int ionic_logtype;
 
@@ -90,8 +113,124 @@ static const struct eth_dev_ops ionic_eth_dev_ops = {
        .tx_queue_start         = ionic_dev_tx_queue_start,
        .tx_queue_stop          = ionic_dev_tx_queue_stop,
        .vlan_offload_set       = ionic_vlan_offload_set,
+       .reta_update            = ionic_dev_rss_reta_update,
+       .reta_query             = ionic_dev_rss_reta_query,
+       .rss_hash_conf_get      = ionic_dev_rss_hash_conf_get,
+       .rss_hash_update        = ionic_dev_rss_hash_update,
+       .stats_get              = ionic_dev_stats_get,
+       .stats_reset            = ionic_dev_stats_reset,
+       .xstats_get             = ionic_dev_xstats_get,
+       .xstats_get_by_id       = ionic_dev_xstats_get_by_id,
+       .xstats_reset           = ionic_dev_xstats_reset,
+       .xstats_get_names       = ionic_dev_xstats_get_names,
+       .xstats_get_names_by_id = ionic_dev_xstats_get_names_by_id,
+       .fw_version_get         = ionic_dev_fw_version_get,
 };
 
+struct rte_ionic_xstats_name_off {
+       char name[RTE_ETH_XSTATS_NAME_SIZE];
+       unsigned int offset;
+};
+
+static const struct rte_ionic_xstats_name_off rte_ionic_xstats_strings[] = {
+       /* RX */
+       {"rx_ucast_bytes", offsetof(struct ionic_lif_stats,
+                       rx_ucast_bytes)},
+       {"rx_ucast_packets", offsetof(struct ionic_lif_stats,
+                       rx_ucast_packets)},
+       {"rx_mcast_bytes", offsetof(struct ionic_lif_stats,
+                       rx_mcast_bytes)},
+       {"rx_mcast_packets", offsetof(struct ionic_lif_stats,
+                       rx_mcast_packets)},
+       {"rx_bcast_bytes", offsetof(struct ionic_lif_stats,
+                       rx_bcast_bytes)},
+       {"rx_bcast_packets", offsetof(struct ionic_lif_stats,
+                       rx_bcast_packets)},
+       /* RX drops */
+       {"rx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       rx_ucast_drop_bytes)},
+       {"rx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
+                       rx_ucast_drop_packets)},
+       {"rx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       rx_mcast_drop_bytes)},
+       {"rx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
+                       rx_mcast_drop_packets)},
+       {"rx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       rx_bcast_drop_bytes)},
+       {"rx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
+                       rx_bcast_drop_packets)},
+       {"rx_dma_error", offsetof(struct ionic_lif_stats,
+                       rx_dma_error)},
+       /* TX */
+       {"tx_ucast_bytes", offsetof(struct ionic_lif_stats,
+                       tx_ucast_bytes)},
+       {"tx_ucast_packets", offsetof(struct ionic_lif_stats,
+                       tx_ucast_packets)},
+       {"tx_mcast_bytes", offsetof(struct ionic_lif_stats,
+                       tx_mcast_bytes)},
+       {"tx_mcast_packets", offsetof(struct ionic_lif_stats,
+                       tx_mcast_packets)},
+       {"tx_bcast_bytes", offsetof(struct ionic_lif_stats,
+                       tx_bcast_bytes)},
+       {"tx_bcast_packets", offsetof(struct ionic_lif_stats,
+                       tx_bcast_packets)},
+       /* TX drops */
+       {"tx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       tx_ucast_drop_bytes)},
+       {"tx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
+                       tx_ucast_drop_packets)},
+       {"tx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       tx_mcast_drop_bytes)},
+       {"tx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
+                       tx_mcast_drop_packets)},
+       {"tx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
+                       tx_bcast_drop_bytes)},
+       {"tx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
+                       tx_bcast_drop_packets)},
+       {"tx_dma_error", offsetof(struct ionic_lif_stats,
+                       tx_dma_error)},
+       /* Rx Queue/Ring drops */
+       {"rx_queue_disabled", offsetof(struct ionic_lif_stats,
+                       rx_queue_disabled)},
+       {"rx_queue_empty", offsetof(struct ionic_lif_stats,
+                       rx_queue_empty)},
+       {"rx_queue_error", offsetof(struct ionic_lif_stats,
+                       rx_queue_error)},
+       {"rx_desc_fetch_error", offsetof(struct ionic_lif_stats,
+                       rx_desc_fetch_error)},
+       {"rx_desc_data_error", offsetof(struct ionic_lif_stats,
+                       rx_desc_data_error)},
+       /* Tx Queue/Ring drops */
+       {"tx_queue_disabled", offsetof(struct ionic_lif_stats,
+                       tx_queue_disabled)},
+       {"tx_queue_error", offsetof(struct ionic_lif_stats,
+                       tx_queue_error)},
+       {"tx_desc_fetch_error", offsetof(struct ionic_lif_stats,
+                       tx_desc_fetch_error)},
+       {"tx_desc_data_error", offsetof(struct ionic_lif_stats,
+                       tx_desc_data_error)},
+};
+
+#define IONIC_NB_HW_STATS (sizeof(rte_ionic_xstats_strings) / \
+               sizeof(rte_ionic_xstats_strings[0]))
+
+static int
+ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
+               char *fw_version, size_t fw_size)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       struct ionic_adapter *adapter = lif->adapter;
+
+       if (fw_version == NULL || fw_size <= 0)
+               return -EINVAL;
+
+       snprintf(fw_version, fw_size, "%s",
+                adapter->fw_version);
+       fw_version[fw_size - 1] = '\0';
+
+       return 0;
+}
+
 /*
  * Set device link up, enable tx.
  */
@@ -263,6 +402,10 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
        dev_info->min_mtu = IONIC_MIN_MTU;
        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->flow_type_rss_offloads = IONIC_ETH_RSS_OFFLOAD_ALL;
+
        dev_info->speed_capa =
                ETH_LINK_SPEED_10G |
                ETH_LINK_SPEED_25G |
@@ -283,7 +426,12 @@ ionic_dev_info_get(struct rte_eth_dev *eth_dev,
                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;
 
        /*
@@ -405,6 +553,311 @@ ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
        return 0;
 }
 
+static int
+ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
+               struct rte_eth_rss_reta_entry64 *reta_conf,
+               uint16_t reta_size)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       struct ionic_adapter *adapter = lif->adapter;
+       struct ionic_identity *ident = &adapter->ident;
+       uint32_t i, j, index, num;
+
+       IONIC_PRINT_CALL();
+
+       if (!lif->rss_ind_tbl) {
+               IONIC_PRINT(ERR, "RSS RETA not initialized, "
+                       "can't update the table");
+               return -EINVAL;
+       }
+
+       if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
+               IONIC_PRINT(ERR, "The size of hash lookup table configured "
+                       "(%d) doesn't match the number hardware can supported "
+                       "(%d)",
+                       reta_size, ident->lif.eth.rss_ind_tbl_sz);
+               return -EINVAL;
+       }
+
+       num = lif->adapter->ident.lif.eth.rss_ind_tbl_sz / RTE_RETA_GROUP_SIZE;
+
+       for (i = 0; i < num; i++) {
+               for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
+                       if (reta_conf[i].mask & ((uint64_t)1 << j)) {
+                               index = (i * RTE_RETA_GROUP_SIZE) + j;
+                               lif->rss_ind_tbl[index] = reta_conf[i].reta[j];
+                       }
+               }
+       }
+
+       return ionic_lif_rss_config(lif, lif->rss_types, NULL, NULL);
+}
+
+static int
+ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
+               struct rte_eth_rss_reta_entry64 *reta_conf,
+               uint16_t reta_size)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       struct ionic_adapter *adapter = lif->adapter;
+       struct ionic_identity *ident = &adapter->ident;
+       int i, num;
+
+       IONIC_PRINT_CALL();
+
+       if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
+               IONIC_PRINT(ERR, "The size of hash lookup table configured "
+                       "(%d) doesn't match the number hardware can supported "
+                       "(%d)",
+                       reta_size, ident->lif.eth.rss_ind_tbl_sz);
+               return -EINVAL;
+       }
+
+       if (!lif->rss_ind_tbl) {
+               IONIC_PRINT(ERR, "RSS RETA has not been built yet");
+               return -EINVAL;
+       }
+
+       num = reta_size / RTE_RETA_GROUP_SIZE;
+
+       for (i = 0; i < num; i++) {
+               memcpy(reta_conf->reta,
+                       &lif->rss_ind_tbl[i * RTE_RETA_GROUP_SIZE],
+                       RTE_RETA_GROUP_SIZE);
+               reta_conf++;
+       }
+
+       return 0;
+}
+
+static int
+ionic_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
+               struct rte_eth_rss_conf *rss_conf)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       uint64_t rss_hf = 0;
+
+       IONIC_PRINT_CALL();
+
+       if (!lif->rss_ind_tbl) {
+               IONIC_PRINT(NOTICE, "RSS not enabled");
+               return 0;
+       }
+
+       /* Get key value (if not null, rss_key is 40-byte) */
+       if (rss_conf->rss_key != NULL &&
+                       rss_conf->rss_key_len >= IONIC_RSS_HASH_KEY_SIZE)
+               memcpy(rss_conf->rss_key, lif->rss_hash_key,
+                       IONIC_RSS_HASH_KEY_SIZE);
+
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV4)
+               rss_hf |= ETH_RSS_IPV4;
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV4_TCP)
+               rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV4_UDP)
+               rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV6)
+               rss_hf |= ETH_RSS_IPV6;
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV6_TCP)
+               rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
+       if (lif->rss_types & IONIC_RSS_TYPE_IPV6_UDP)
+               rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
+
+       rss_conf->rss_hf = rss_hf;
+
+       return 0;
+}
+
+static int
+ionic_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
+               struct rte_eth_rss_conf *rss_conf)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       uint32_t rss_types = 0;
+       uint8_t *key = NULL;
+
+       IONIC_PRINT_CALL();
+
+       if (rss_conf->rss_key)
+               key = rss_conf->rss_key;
+
+       if ((rss_conf->rss_hf & IONIC_ETH_RSS_OFFLOAD_ALL) == 0) {
+               /*
+                * Can't disable rss through hash flags,
+                * if it is enabled by default during init
+                */
+               if (lif->rss_ind_tbl)
+                       return -EINVAL;
+       } else {
+               /* Can't enable rss if disabled by default during init */
+               if (!lif->rss_ind_tbl)
+                       return -EINVAL;
+
+               if (rss_conf->rss_hf & ETH_RSS_IPV4)
+                       rss_types |= IONIC_RSS_TYPE_IPV4;
+               if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
+                       rss_types |= IONIC_RSS_TYPE_IPV4_TCP;
+               if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
+                       rss_types |= IONIC_RSS_TYPE_IPV4_UDP;
+               if (rss_conf->rss_hf & ETH_RSS_IPV6)
+                       rss_types |= IONIC_RSS_TYPE_IPV6;
+               if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
+                       rss_types |= IONIC_RSS_TYPE_IPV6_TCP;
+               if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
+                       rss_types |= IONIC_RSS_TYPE_IPV6_UDP;
+
+               ionic_lif_rss_config(lif, rss_types, key, NULL);
+       }
+
+       return 0;
+}
+
+static int
+ionic_dev_stats_get(struct rte_eth_dev *eth_dev,
+               struct rte_eth_stats *stats)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+
+       ionic_lif_get_stats(lif, stats);
+
+       return 0;
+}
+
+static int
+ionic_dev_stats_reset(struct rte_eth_dev *eth_dev)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+
+       IONIC_PRINT_CALL();
+
+       ionic_lif_reset_stats(lif);
+
+       return 0;
+}
+
+static int
+ionic_dev_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,
+               struct rte_eth_xstat_name *xstats_names,
+               __rte_unused unsigned int size)
+{
+       unsigned int i;
+
+       if (xstats_names != NULL) {
+               for (i = 0; i < IONIC_NB_HW_STATS; i++) {
+                       snprintf(xstats_names[i].name,
+                                       sizeof(xstats_names[i].name),
+                                       "%s", rte_ionic_xstats_strings[i].name);
+               }
+       }
+
+       return IONIC_NB_HW_STATS;
+}
+
+static int
+ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
+               struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
+               unsigned int limit)
+{
+       struct rte_eth_xstat_name xstats_names_copy[IONIC_NB_HW_STATS];
+       uint16_t i;
+
+       if (!ids) {
+               if (xstats_names != NULL) {
+                       for (i = 0; i < IONIC_NB_HW_STATS; i++) {
+                               snprintf(xstats_names[i].name,
+                                       sizeof(xstats_names[i].name),
+                                       "%s", rte_ionic_xstats_strings[i].name);
+                       }
+               }
+
+               return IONIC_NB_HW_STATS;
+       }
+
+       ionic_dev_xstats_get_names_by_id(eth_dev, xstats_names_copy, NULL,
+               IONIC_NB_HW_STATS);
+
+       for (i = 0; i < limit; i++) {
+               if (ids[i] >= IONIC_NB_HW_STATS) {
+                       IONIC_PRINT(ERR, "id value isn't valid");
+                       return -1;
+               }
+
+               strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
+       }
+
+       return limit;
+}
+
+static int
+ionic_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
+               unsigned int n)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       struct ionic_lif_stats hw_stats;
+       uint16_t i;
+
+       if (n < IONIC_NB_HW_STATS)
+               return IONIC_NB_HW_STATS;
+
+       ionic_lif_get_hw_stats(lif, &hw_stats);
+
+       for (i = 0; i < IONIC_NB_HW_STATS; i++) {
+               xstats[i].value = *(uint64_t *)(((char *)&hw_stats) +
+                               rte_ionic_xstats_strings[i].offset);
+               xstats[i].id = i;
+       }
+
+       return IONIC_NB_HW_STATS;
+}
+
+static int
+ionic_dev_xstats_get_by_id(struct rte_eth_dev *eth_dev, const uint64_t *ids,
+               uint64_t *values, unsigned int n)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+       struct ionic_lif_stats hw_stats;
+       uint64_t values_copy[IONIC_NB_HW_STATS];
+       uint16_t i;
+
+       if (!ids) {
+               if (!ids && n < IONIC_NB_HW_STATS)
+                       return IONIC_NB_HW_STATS;
+
+               ionic_lif_get_hw_stats(lif, &hw_stats);
+
+               for (i = 0; i < IONIC_NB_HW_STATS; i++) {
+                       values[i] = *(uint64_t *)(((char *)&hw_stats) +
+                                       rte_ionic_xstats_strings[i].offset);
+               }
+
+               return IONIC_NB_HW_STATS;
+       }
+
+       ionic_dev_xstats_get_by_id(eth_dev, NULL, values_copy,
+                       IONIC_NB_HW_STATS);
+
+       for (i = 0; i < n; i++) {
+               if (ids[i] >= IONIC_NB_HW_STATS) {
+                       IONIC_PRINT(ERR, "id value isn't valid");
+                       return -1;
+               }
+
+               values[i] = values_copy[ids[i]];
+       }
+
+       return n;
+}
+
+static int
+ionic_dev_xstats_reset(struct rte_eth_dev *eth_dev)
+{
+       struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
+
+       ionic_lif_reset_hw_stats(lif);
+
+       return 0;
+}
+
 static int
 ionic_dev_configure(struct rte_eth_dev *eth_dev)
 {