From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 91690239 for ; Fri, 1 Mar 2019 06:17:24 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2019 21:17:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,426,1544515200"; d="scan'208";a="151051767" Received: from map1.sh.intel.com ([10.67.111.124]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2019 21:17:22 -0800 From: Qiming Yang To: dev@dpdk.org Cc: Qiming Yang Date: Fri, 1 Mar 2019 20:46:12 +0800 Message-Id: <20190301124613.66527-1-qiming.yang@intel.com> X-Mailer: git-send-email 2.9.5 Subject: [dpdk-dev] [PATCH 1/2] net/ice: suppport package download X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Mar 2019 05:17:25 -0000 Columbiaville requires a package to be downloaded if need advanced features. This patch add package download support in two ways. If it configured package path in devargs, will use this path, if not, will load the package at /lib/firmware/intel/ice/ddp/ice.pkg. When package download failed, will initialize in safe mode, some advanced features will not be supported. Signed-off-by: Qiming Yang --- drivers/net/ice/ice_ethdev.c | 134 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/ice/ice_ethdev.h | 2 + 2 files changed, 136 insertions(+) diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c index a23c63a..c097259 100644 --- a/drivers/net/ice/ice_ethdev.c +++ b/drivers/net/ice/ice_ethdev.c @@ -2,12 +2,19 @@ * Copyright(c) 2018 Intel Corporation */ +#include +#include +#include +#include + #include #include "base/ice_sched.h" #include "ice_ethdev.h" #include "ice_rxtx.h" +#define ETH_ICE_PKG_PATH_ARG "package_path" + #define ICE_MAX_QP_NUM "max_queue_pair_num" #define ICE_DFLT_OUTER_TAG_TYPE ICE_AQ_VSI_OUTER_TAG_VLAN_9100 @@ -72,6 +79,10 @@ static int ice_xstats_get_names(struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, unsigned int limit); +static const char *const valid_keys[] = { + ETH_ICE_PKG_PATH_ARG, + NULL}; + static const struct rte_pci_id pci_id_ice_map[] = { { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) }, { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_QSFP) }, @@ -1260,6 +1271,119 @@ ice_pf_setup(struct ice_pf *pf) } static int +ice_parse_pkg_path_handler(__rte_unused const char *key, + const char *value, + void *opaque) +{ + struct ice_adapter *ad; + + ad = (struct ice_adapter *)opaque; + ad->pkg_path = value; + + return 0; +} + +static void +ice_find_pkg_path(struct rte_eth_dev *dev) +{ + struct rte_kvargs *kvlist; + struct ice_adapter *ad = + ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); + int kvargs_count; + + if (!(dev->device->devargs)) + return; + + kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys); + if (kvlist == NULL) + return; + + kvargs_count = rte_kvargs_count(kvlist, ETH_ICE_PKG_PATH_ARG); + + if (!kvargs_count) { + rte_kvargs_free(kvlist); + return; + } + + if (kvargs_count > 1) + PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only " + "the first invalid or last valid one is used !", + ETH_ICE_PKG_PATH_ARG); + + if (rte_kvargs_process(kvlist, ETH_ICE_PKG_PATH_ARG, + ice_parse_pkg_path_handler, ad) < 0) { + rte_kvargs_free(kvlist); + return; + } + rte_kvargs_free(kvlist); +} + +static int ice_load_pkg(struct rte_eth_dev *dev, const char *pkg_path) +{ + struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct ice_adapter *ad = + ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); + int err; + uint8_t *buf; + int buf_len; + FILE *file; + struct stat fstat; + + file = fopen(pkg_path, "rb"); + if (file == NULL) { + PMD_INIT_LOG(ERR, "failed to open file"); + return 0; + } + + err = stat(pkg_path, &fstat); + if (err) { + PMD_INIT_LOG(ERR, "failed to get file stats"); + fclose(file); + return 0; + } + + buf_len = fstat.st_size; + printf("buf_len = %d\n", buf_len); + buf = rte_malloc(NULL, buf_len, 0); + + if (buf == NULL) { + PMD_INIT_LOG(ERR, "failed to allocate buf for package"); + fclose(file); + return 0; + } + + err = fread(buf, buf_len, 1, file); + if (err != 1) { + PMD_INIT_LOG(ERR, "failed to read package data"); + fclose(file); + return 0; + } + + 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 err_go_to_safe_mode; + } + + err = ice_init_hw_tbls(hw); + if (err) { + PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d\n", err); + goto err_go_to_safe_mode; + } + + ad->is_safe_mode = 0; + return 0; + +err_go_to_safe_mode: + ad->is_safe_mode = 1; + + return err; +} + +static int ice_dev_init(struct rte_eth_dev *dev) { struct rte_pci_device *pci_dev; @@ -1267,6 +1391,7 @@ ice_dev_init(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 ice_vsi *vsi; + const char *pkg_path; int ret; dev->dev_ops = &ice_eth_dev_ops; @@ -1322,6 +1447,15 @@ ice_dev_init(struct rte_eth_dev *dev) goto err_pf_setup; } + ice_find_pkg_path(dev); + if (!(pf->adapter->pkg_path)) + pkg_path = "/lib/firmware/intel/ice/ddp/ice.pkg"; + else + pkg_path = pf->adapter->pkg_path; + ret = ice_load_pkg(dev, pkg_path); + if (ret) + PMD_INIT_LOG(ERR, "Failed to load default OS package"); + vsi = pf->main_vsi; /* Disable double vlan by default */ diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h index 3cefa5b..796459a 100644 --- a/drivers/net/ice/ice_ethdev.h +++ b/drivers/net/ice/ice_ethdev.h @@ -264,6 +264,8 @@ struct ice_adapter { bool tx_simple_allowed; /* ptype mapping table */ uint32_t ptype_tbl[ICE_MAX_PKT_TYPE] __rte_cache_min_aligned; + const char *pkg_path; + bool is_safe_mode; }; struct ice_vsi_vlan_pvid_info { -- 2.9.5