net/ice: load OS default package
[dpdk.git] / drivers / net / ice / ice_ethdev.c
index b450115..f38df0d 100644 (file)
@@ -4,12 +4,18 @@
 
 #include <rte_ethdev_pci.h>
 
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include "base/ice_sched.h"
 #include "ice_ethdev.h"
 #include "ice_rxtx.h"
 
 #define ICE_MAX_QP_NUM "max_queue_pair_num"
 #define ICE_DFLT_OUTER_TAG_TYPE ICE_AQ_VSI_OUTER_TAG_VLAN_9100
+#define ICE_DFLT_PKG_FILE "/lib/firmware/intel/ice/ddp/ice.pkg"
 
 int ice_logtype_init;
 int ice_logtype_driver;
@@ -1259,6 +1265,69 @@ ice_pf_setup(struct ice_pf *pf)
        return 0;
 }
 
+static int ice_load_pkg(struct rte_eth_dev *dev)
+{
+       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       const char *pkg_file = ICE_DFLT_PKG_FILE;
+       int err;
+       uint8_t *buf;
+       int buf_len;
+       FILE *file;
+       struct stat fstat;
+
+       file = fopen(pkg_file, "rb");
+       if (!file)  {
+               PMD_INIT_LOG(ERR, "failed to open file: %s\n", pkg_file);
+               return -1;
+       }
+
+       err = stat(pkg_file, &fstat);
+       if (err) {
+               PMD_INIT_LOG(ERR, "failed to get file stats\n");
+               fclose(file);
+               return err;
+       }
+
+       buf_len = fstat.st_size;
+       buf = rte_malloc(NULL, buf_len, 0);
+
+       if (!buf) {
+               PMD_INIT_LOG(ERR, "failed to allocate buf of size %d for package\n",
+                               buf_len);
+               fclose(file);
+               return -1;
+       }
+
+       err = fread(buf, buf_len, 1, file);
+       if (err != 1) {
+               PMD_INIT_LOG(ERR, "failed to read package data\n");
+               fclose(file);
+               err = -1;
+               goto fail_exit;
+       }
+
+       fclose(file);
+
+       err = ice_copy_and_init_pkg(hw, buf, buf_len);
+       if (err) {
+               PMD_INIT_LOG(ERR, "ice_copy_and_init_hw failed: %d\n", err);
+               goto fail_exit;
+       }
+       err = ice_init_hw_tbls(hw);
+       if (err) {
+               PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d\n", err);
+               goto fail_init_tbls;
+       }
+
+       return 0;
+
+fail_init_tbls:
+       rte_free(hw->pkg_copy);
+fail_exit:
+       rte_free(buf);
+       return err;
+}
+
 static int
 ice_dev_init(struct rte_eth_dev *dev)
 {
@@ -1298,6 +1367,12 @@ ice_dev_init(struct rte_eth_dev *dev)
                return -EINVAL;
        }
 
+       ret = ice_load_pkg(dev);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failed to load the DDP package");
+               goto err_load_pkg;
+       }
+
        PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
                     hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
                     hw->api_maj_ver, hw->api_min_ver);
@@ -1343,6 +1418,7 @@ err_pf_setup:
 err_msix_pool_init:
        rte_free(dev->data->mac_addrs);
 err_init_mac:
+err_load_pkg:
        ice_sched_cleanup_all(hw);
        rte_free(hw->port_info);
        ice_shutdown_all_ctrlq(hw);
@@ -1458,15 +1534,14 @@ ice_dev_close(struct rte_eth_dev *dev)
 
        ice_res_pool_destroy(&pf->msix_pool);
        ice_release_vsi(pf->main_vsi);
-
+       ice_sched_cleanup_all(hw);
+       rte_free(hw->port_info);
        ice_shutdown_all_ctrlq(hw);
 }
 
 static int
 ice_dev_uninit(struct rte_eth_dev *dev)
 {
-       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
@@ -1486,11 +1561,6 @@ ice_dev_uninit(struct rte_eth_dev *dev)
        rte_intr_callback_unregister(intr_handle,
                                     ice_interrupt_handler, dev);
 
-       ice_release_vsi(pf->main_vsi);
-       ice_sched_cleanup_all(hw);
-       rte_free(hw->port_info);
-       ice_shutdown_all_ctrlq(hw);
-
        return 0;
 }
 
@@ -1720,7 +1790,7 @@ ice_dev_start(struct rte_eth_dev *dev)
        struct ice_vsi *vsi = pf->main_vsi;
        uint16_t nb_rxq = 0;
        uint16_t nb_txq, i;
-       int ret;
+       int mask, ret;
 
        /* program Tx queues' context in hardware */
        for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
@@ -1747,6 +1817,15 @@ ice_dev_start(struct rte_eth_dev *dev)
        }
 
        ice_set_rx_function(dev);
+       ice_set_tx_function(dev);
+
+       mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
+                       ETH_VLAN_EXTEND_MASK;
+       ret = ice_vlan_offload_set(dev, mask);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
+               goto rx_err;
+       }
 
        /* enable Rx interrput and mapping Rx queue to interrupt vector */
        if (ice_rxq_intr_setup(dev))
@@ -1899,7 +1978,9 @@ ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                               ETH_LINK_SPEED_10G |
                               ETH_LINK_SPEED_20G |
                               ETH_LINK_SPEED_25G |
-                              ETH_LINK_SPEED_40G;
+                              ETH_LINK_SPEED_40G |
+                              ETH_LINK_SPEED_50G |
+                              ETH_LINK_SPEED_100G;
 
        dev_info->nb_rx_queues = dev->data->nb_rx_queues;
        dev_info->nb_tx_queues = dev->data->nb_tx_queues;
@@ -2010,6 +2091,12 @@ ice_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
        case ICE_AQ_LINK_SPEED_40GB:
                link.link_speed = ETH_SPEED_NUM_40G;
                break;
+       case ICE_AQ_LINK_SPEED_50GB:
+               link.link_speed = ETH_SPEED_NUM_50G;
+               break;
+       case ICE_AQ_LINK_SPEED_100GB:
+               link.link_speed = ETH_SPEED_NUM_100G;
+               break;
        case ICE_AQ_LINK_SPEED_UNKNOWN:
        default:
                PMD_DRV_LOG(ERR, "Unknown link speed");
@@ -2804,26 +2891,26 @@ ice_get_eeprom(struct rte_eth_dev *dev,
 {
        struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        uint16_t *data = eeprom->data;
-       uint16_t offset, length, i;
-       enum ice_status ret_code = ICE_SUCCESS;
+       uint16_t first_word, last_word, nwords;
+       enum ice_status status = ICE_SUCCESS;
 
-       offset = eeprom->offset >> 1;
-       length = eeprom->length >> 1;
+       first_word = eeprom->offset >> 1;
+       last_word = (eeprom->offset + eeprom->length - 1) >> 1;
+       nwords = last_word - first_word + 1;
 
-       if (offset > hw->nvm.sr_words ||
-           offset + length > hw->nvm.sr_words) {
+       if (first_word > hw->nvm.sr_words ||
+           last_word > hw->nvm.sr_words) {
                PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
                return -EINVAL;
        }
 
        eeprom->magic = hw->vendor_id | (hw->device_id << 16);
 
-       for (i = 0; i < length; i++) {
-               ret_code = ice_read_sr_word(hw, offset + i, &data[i]);
-               if (ret_code != ICE_SUCCESS) {
-                       PMD_DRV_LOG(ERR, "EEPROM read failed.");
-                       return -EIO;
-               }
+       status = ice_read_sr_buf(hw, first_word, &nwords, data);
+       if (status) {
+               PMD_DRV_LOG(ERR, "EEPROM read failed.");
+               eeprom->length = sizeof(uint16_t) * nwords;
+               return -EIO;
        }
 
        return 0;