From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3A93CA00C5; Thu, 15 Sep 2022 12:45:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C595040E50; Thu, 15 Sep 2022 12:44:56 +0200 (CEST) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2111.outbound.protection.outlook.com [40.107.101.111]) by mails.dpdk.org (Postfix) with ESMTP id B4C9A40A80 for ; Thu, 15 Sep 2022 12:44:55 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mTDxVuK2Bf+dW6UCWHGM9HP8uNZ1Rs09txvQLkEWtnoY1NKNpPmAHTi1hbrzD2aKwYd/wTB4QrSlh6hcYLWuklYl8csEGICjBfK6eQpsTuYJ5ngfrhccg0DdW/P2xynb+o4Ks0ip4eeRiBPtvW33J9u4lv6Igqd1gk1K1q/rPjx/HD14+JDDL0TC4ZqFpfniPg+pfJ+4rbUvHBYAH4CfQBwitbzdXLzrHLOFE8Iv0E9nx0sCWLFPFlZ8/032kT9YTvsvdlEjnOkunqA6wzzuGRwexsGMmrxBtqp7y3n32WZ864/z4MRSPNQCe0SB0hq8C3dqRMgqiarmtQ7YBCXczQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XzacKR4wOvQ4KWQDKh0D05Y9045dYoeD6+X41ThvLpA=; b=a9nI0V4di1dydDSqZ8oIewbNVp3GvtQBkb23y+os/jPLePjcTtZQfYPrNNXjlcU4e/+4cgcVibDkGv3ivhhLkzxPvy/PrZI+YYnoqGdwL4ifh1noT/JNyirpmj5GPfNkL+uqVJNKP5Wrdcw6AJ6YV4pUunIr9hSAuZ/uO/iHLtK4njUaNdA/eY4+yLMIiB8cvA0HVV5F0VCx4kFmvJUbM6xP5z3mvc+as4MXggMxwSBDvJXXnw9ITJ6wlvfkwncQ6PgTE8bnJkBBe+j1YfE0M4Hvu9pGz30sofZzEC3QYluCiXjJi9mGGa2qZKBfrmWZgl3VjZeOw+UZVL8MvIjD5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XzacKR4wOvQ4KWQDKh0D05Y9045dYoeD6+X41ThvLpA=; b=MKzgnH0nU9IKc2zq+g4N/dlNBmP1rOWwZxtDdZHbPRW2VLyCV+y74o1gVCI74lhUjI1vkhlIhXai+Dv2+xQZe6sEOcd7WECNsqCXkMtvmtTkajHlnth/b6qSa0ftaa6UQfWZuPnsa7Sa7aaKKePFhn4p/4akQW0Z3Tv1orEuiCk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by SA0PR13MB4158.namprd13.prod.outlook.com (2603:10b6:806:9b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.5; Thu, 15 Sep 2022 10:44:53 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::819:38c:6513:bf15]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::819:38c:6513:bf15%4]) with mapi id 15.20.5632.012; Thu, 15 Sep 2022 10:44:53 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He , Heinrich Kuhn Subject: [PATCH v9 01/12] net/nfp: move app specific attributes to own struct Date: Thu, 15 Sep 2022 18:44:18 +0800 Message-Id: <1663238669-12244-2-git-send-email-chaoyong.he@corigine.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1663238669-12244-1-git-send-email-chaoyong.he@corigine.com> References: <1663238669-12244-1-git-send-email-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: BYAPR11CA0071.namprd11.prod.outlook.com (2603:10b6:a03:80::48) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|SA0PR13MB4158:EE_ X-MS-Office365-Filtering-Correlation-Id: cc970311-3576-4247-e372-08da970752c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kHKzB7is2KB+1qMP8sehrZtk6KxIWUQztbzPXrXCkTdKZiOcCNBuP4FvQqwdNFR6fv0f6ZehFgAMMkKTkKho7+FL8XvrbHOfSy++ueX55YfCF/zmns3syLi/O3LFrbK+EUe7yV+xhPij1gsuevwwug2ShjquYwXsUhXl8xrWDoStGC0Lt/somSbzltjlqK+/kHmg46I7xwLCeq3QpcVVGAdky2zGWwh9gV+aoZWTFwwctVIc2Ej7hLrltG+olLTkAfxol06FNcJRIEQSv0B3j3+G/Xqs8CYKv5XK3HzVPy6KZNxm6OsITjEJ0K5Jj5QFngkef8chJQ8WcQWFQhnAswvLauRUEz2er79VINZi0i/ECvG2nBJKvTB+TjO9mF/kd2di5tukAQYTSlugvo3234qE/8661EJp6rzgkb5vEoLIhjNjidR3t+GPIYf3c097ihE/OmtaKYeWKERt9tWknJLAjbEBA8GYmFEDj9w2FBglPKcj0+WYsb/zHGKaa1MHWx/RDnDrp7nXbhQPA19IshVmai7acW5J6jNX4X7lnOMLwfjypppJTkg87JuoW7KtVIABXTcpzkkDtYIB2W5LDRCKW1wu15HJw01hfL84VVBIx5qeiUwcZiNmAWu9CgLGCJoOpIO2HyzUaOK11QWoOdV51nEdMzhkwxrP3zx954jv/6dd4uo8bWCgZmXVb2SlC+C3EjZ9o4a/bsCC8jydJF7NkEO7vVL8jVzH8RjWJ05QPI8A6gI0Gi8sBr20Exf4aP5dgIvuqLtYsfgX1SUEzg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(396003)(346002)(366004)(376002)(39840400004)(136003)(451199015)(2616005)(66574015)(38350700002)(38100700002)(186003)(86362001)(83380400001)(107886003)(8676002)(66946007)(66476007)(4326008)(66556008)(44832011)(8936002)(41300700001)(2906002)(5660300002)(6506007)(478600001)(6666004)(316002)(30864003)(6512007)(26005)(6486002)(52116002)(54906003)(6916009)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?L3VMUVpnTzlya3U2bmEyZ1oxall5ekQ4L09IbGx0M2hvZGozMDNKVVVqR21T?= =?utf-8?B?ZnhOUW94YUtlbnFEb2pEcnNmd3VQcnhCYWQvOHByTGM5eWpxWStRayt4QlA4?= =?utf-8?B?RkFoVjVKOVBHQVAydkEzS3hvaVprMCtBMmlwNW1kWkM0eHBHN1o1YnR6RUk2?= =?utf-8?B?enpXZExVM21Ga3lwbGRSQXBJbEs1WFhkOE1pRXVycWdHazkzaTAybXVpSkln?= =?utf-8?B?U0lnY3ZQWk1CQUZXWGgyZDlSQTZBeDJhaTdnRkM2a1VjQ1BpMWNuSXN6V24y?= =?utf-8?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jFPZ1NRajNzMjhobW96?= =?utf-8?B?ZE5ueFY1WW45ZnF2QXF1N1c0MmVPbC9WUkI5VTBRNVp3azgwQU1xZnNrYzZz?= =?utf-8?B?OHc9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR13MB4158 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The NFP card can load different application firmwares. Currently only the CoreNIC application firmware is supported. This commit makes needed infrastructure changes in order to support other application firmwares too. Clearer separation is made between the PF device and any application firmware specific concepts. The PF struct is now generic regardless of the application firmware loaded. A new struct is also made for the CoreNIC application firmware. Future additions to support other application firmwares should also add an application firmware specific struct. Signed-off-by: Chaoyong He Signed-off-by: Heinrich Kuhn Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfp_common.h | 30 ++++++- drivers/net/nfp/nfp_ethdev.c | 194 +++++++++++++++++++++++++++---------------- 2 files changed, 149 insertions(+), 75 deletions(-) diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 6d917e4..bea5f95 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -111,6 +111,11 @@ #include #include +/* Firmware application ID's */ +enum nfp_app_fw_id { + NFP_APP_FW_CORE_NIC = 0x1, +}; + /* nfp_qcp_ptr - Read or Write Pointer of a queue */ enum nfp_qcp_ptr { NFP_QCP_READ_PTR = 0, @@ -121,8 +126,10 @@ struct nfp_pf_dev { /* Backpointer to associated pci device */ struct rte_pci_device *pci_dev; - /* Array of physical ports belonging to this PF */ - struct nfp_net_hw *ports[NFP_MAX_PHYPORTS]; + enum nfp_app_fw_id app_fw_id; + + /* Pointer to the app running on the PF */ + void *app_fw_priv; /* Current values for control */ uint32_t ctrl; @@ -151,8 +158,6 @@ struct nfp_pf_dev { struct nfp_cpp_area *msix_area; uint8_t *hw_queues; - uint8_t total_phyports; - bool multiport; union eth_table_entry *eth_table; @@ -161,6 +166,20 @@ struct nfp_pf_dev { uint32_t nfp_cpp_service_id; }; +struct nfp_app_fw_nic { + /* Backpointer to the PF device */ + struct nfp_pf_dev *pf_dev; + + /* + * Array of physical ports belonging to the this CoreNIC app + * This is really a list of vNIC's. One for each physical port + */ + struct nfp_net_hw *ports[NFP_MAX_PHYPORTS]; + + bool multiport; + uint8_t total_phyports; +}; + struct nfp_net_hw { /* Backpointer to the PF this port belongs to */ struct nfp_pf_dev *pf_dev; @@ -424,6 +443,9 @@ int nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev, #define NFP_NET_DEV_PRIVATE_TO_PF(dev_priv)\ (((struct nfp_net_hw *)dev_priv)->pf_dev) +#define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\ + ((struct nfp_app_fw_nic *)app_fw_priv) + #endif /* _NFP_COMMON_H_ */ /* * Local variables: diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e9d01f4..40d21e4 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -39,15 +39,15 @@ #include "nfp_cpp_bridge.h" static int -nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port) +nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic, int port) { struct nfp_eth_table *nfp_eth_table; struct nfp_net_hw *hw = NULL; /* Grab a pointer to the correct physical port */ - hw = pf_dev->ports[port]; + hw = app_fw_nic->ports[port]; - nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp); + nfp_eth_table = nfp_eth_read_ports(app_fw_nic->pf_dev->cpp); nfp_eth_copy_mac((uint8_t *)&hw->mac_addr, (uint8_t *)&nfp_eth_table->ports[port].mac_addr); @@ -64,6 +64,7 @@ uint32_t new_ctrl, update = 0; struct nfp_net_hw *hw; struct nfp_pf_dev *pf_dev; + struct nfp_app_fw_nic *app_fw_nic; struct rte_eth_conf *dev_conf; struct rte_eth_rxmode *rxmode; uint32_t intr_vector; @@ -71,6 +72,7 @@ hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private); + app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv); PMD_INIT_LOG(DEBUG, "Start"); @@ -82,7 +84,7 @@ /* check and configure queue intr-vector mapping */ if (dev->data->dev_conf.intr_conf.rxq != 0) { - if (pf_dev->multiport) { + if (app_fw_nic->multiport) { PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported " "with NFP multiport PF"); return -EINVAL; @@ -250,6 +252,7 @@ struct nfp_net_hw *hw; struct rte_pci_device *pci_dev; struct nfp_pf_dev *pf_dev; + struct nfp_app_fw_nic *app_fw_nic; int i; if (rte_eal_process_type() != RTE_PROC_PRIMARY) @@ -260,6 +263,7 @@ pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private); hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); pci_dev = RTE_ETH_DEV_TO_PCI(dev); + app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv); /* * We assume that the DPDK application is stopping all the @@ -280,12 +284,12 @@ /* Only free PF resources after all physical ports have been closed */ /* Mark this port as unused and free device priv resources*/ nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff); - pf_dev->ports[hw->idx] = NULL; + app_fw_nic->ports[hw->idx] = NULL; rte_eth_dev_release_port(dev); - for (i = 0; i < pf_dev->total_phyports; i++) { + for (i = 0; i < app_fw_nic->total_phyports; i++) { /* Check to see if ports are still in use */ - if (pf_dev->ports[i]) + if (app_fw_nic->ports[i]) return 0; } @@ -296,6 +300,7 @@ free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); + rte_free(app_fw_nic); rte_free(pf_dev); rte_intr_disable(pci_dev->intr_handle); @@ -404,6 +409,7 @@ { struct rte_pci_device *pci_dev; struct nfp_pf_dev *pf_dev; + struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; uint64_t rx_bar_off = 0; @@ -420,6 +426,9 @@ /* Use backpointer here to the PF of this eth_dev */ pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(eth_dev->data->dev_private); + /* Use backpointer to the CoreNIC app struct */ + app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv); + /* NFP can not handle DMA addresses requiring more than 40 bits */ if (rte_mem_check_dma_mask(40)) { RTE_LOG(ERR, PMD, @@ -438,7 +447,7 @@ * Use PF array of physical ports to get pointer to * this specific port */ - hw = pf_dev->ports[port]; + hw = app_fw_nic->ports[port]; PMD_INIT_LOG(DEBUG, "Working with physical port number: %d, " "NFP internal port number: %d", port, hw->nfp_idx); @@ -568,7 +577,7 @@ goto dev_err_queues_map; } - nfp_net_pf_read_mac(pf_dev, port); + nfp_net_pf_read_mac(app_fw_nic, port); nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr); tmp_ether_addr = (struct rte_ether_addr *)&hw->mac_addr; @@ -720,25 +729,67 @@ } static int -nfp_init_phyports(struct nfp_pf_dev *pf_dev) +nfp_init_app_fw_nic(struct nfp_pf_dev *pf_dev, + struct nfp_eth_table *nfp_eth_table) { int i; - int ret = 0; + int ret; + int err = 0; + int total_vnics; struct nfp_net_hw *hw; + unsigned int numa_node; struct rte_eth_dev *eth_dev; - struct nfp_eth_table *nfp_eth_table; + struct nfp_app_fw_nic *app_fw_nic; + char port_name[RTE_ETH_NAME_MAX_LEN]; - nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp); - if (nfp_eth_table == NULL) { - PMD_INIT_LOG(ERR, "Error reading NFP ethernet table"); - return -EIO; + PMD_INIT_LOG(INFO, "Total physical ports: %d", nfp_eth_table->count); + + /* Allocate memory for the CoreNIC app */ + app_fw_nic = rte_zmalloc("nfp_app_fw_nic", sizeof(*app_fw_nic), 0); + if (app_fw_nic == NULL) + return -ENOMEM; + + /* Point the app_fw_priv pointer in the PF to the coreNIC app */ + pf_dev->app_fw_priv = app_fw_nic; + + /* Read the number of vNIC's created for the PF */ + total_vnics = nfp_rtsym_read_le(pf_dev->sym_tbl, "nfd_cfg_pf0_num_ports", &err); + if (err != 0 || total_vnics <= 0 || total_vnics > 8) { + PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value"); + ret = -ENODEV; + goto app_cleanup; } - /* Loop through all physical ports on PF */ - for (i = 0; i < pf_dev->total_phyports; i++) { - const unsigned int numa_node = rte_socket_id(); - char port_name[RTE_ETH_NAME_MAX_LEN]; + /* + * For coreNIC the number of vNICs exposed should be the same as the + * number of physical ports + */ + if (total_vnics != (int)nfp_eth_table->count) { + PMD_INIT_LOG(ERR, "Total physical ports do not match number of vNICs"); + ret = -ENODEV; + goto app_cleanup; + } + + /* Populate coreNIC app properties*/ + app_fw_nic->total_phyports = total_vnics; + app_fw_nic->pf_dev = pf_dev; + if (total_vnics > 1) + app_fw_nic->multiport = true; + /* Map the symbol table */ + pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0", + app_fw_nic->total_phyports * 32768, &pf_dev->ctrl_area); + if (pf_dev->ctrl_bar == NULL) { + PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar"); + ret = -EIO; + goto app_cleanup; + } + + PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar); + + /* Loop through all physical ports on PF */ + numa_node = rte_socket_id(); + for (i = 0; i < app_fw_nic->total_phyports; i++) { snprintf(port_name, sizeof(port_name), "%s_port%d", pf_dev->pci_dev->device.name, i); @@ -762,7 +813,7 @@ hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); /* Add this device to the PF's array of physical ports */ - pf_dev->ports[i] = hw; + app_fw_nic->ports[i] = hw; hw->pf_dev = pf_dev; hw->cpp = pf_dev->cpp; @@ -785,20 +836,21 @@ rte_eth_dev_probing_finish(eth_dev); } /* End loop, all ports on this PF */ - ret = 0; - goto eth_table_cleanup; + + return 0; port_cleanup: - for (i = 0; i < pf_dev->total_phyports; i++) { - if (pf_dev->ports[i] && pf_dev->ports[i]->eth_dev) { + for (i = 0; i < app_fw_nic->total_phyports; i++) { + if (app_fw_nic->ports[i] && app_fw_nic->ports[i]->eth_dev) { struct rte_eth_dev *tmp_dev; - tmp_dev = pf_dev->ports[i]->eth_dev; + tmp_dev = app_fw_nic->ports[i]->eth_dev; rte_eth_dev_release_port(tmp_dev); - pf_dev->ports[i] = NULL; + app_fw_nic->ports[i] = NULL; } } -eth_table_cleanup: - free(nfp_eth_table); + nfp_cpp_area_free(pf_dev->ctrl_area); +app_cleanup: + rte_free(app_fw_nic); return ret; } @@ -806,11 +858,11 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev) { - int err; - int ret = 0; + int ret; + int err = 0; uint64_t addr; - int total_ports; struct nfp_cpp *cpp; + enum nfp_app_fw_id app_fw_id; struct nfp_pf_dev *pf_dev; struct nfp_hwinfo *hwinfo; char name[RTE_ETH_NAME_MAX_LEN]; @@ -842,9 +894,10 @@ if (hwinfo == NULL) { PMD_INIT_LOG(ERR, "Error reading hwinfo table"); ret = -EIO; - goto error; + goto cpp_cleanup; } + /* Read the number of physical ports from hardware */ nfp_eth_table = nfp_eth_read_ports(cpp); if (nfp_eth_table == NULL) { PMD_INIT_LOG(ERR, "Error reading NFP ethernet table"); @@ -867,20 +920,14 @@ goto eth_table_cleanup; } - total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err); - if (total_ports != (int)nfp_eth_table->count) { - PMD_DRV_LOG(ERR, "Inconsistent number of ports"); + /* Read the app ID of the firmware loaded */ + app_fw_id = nfp_rtsym_read_le(sym_tbl, "_pf0_net_app_id", &err); + if (err != 0) { + PMD_INIT_LOG(ERR, "Couldn't read app_fw_id from fw"); ret = -EIO; goto sym_tbl_cleanup; } - PMD_INIT_LOG(INFO, "Total physical ports: %d", total_ports); - - if (total_ports <= 0 || total_ports > 8) { - PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value"); - ret = -ENODEV; - goto sym_tbl_cleanup; - } /* Allocate memory for the PF "device" */ snprintf(name, sizeof(name), "nfp_pf%d", 0); pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0); @@ -890,27 +937,12 @@ } /* Populate the newly created PF device */ + pf_dev->app_fw_id = app_fw_id; pf_dev->cpp = cpp; pf_dev->hwinfo = hwinfo; pf_dev->sym_tbl = sym_tbl; - pf_dev->total_phyports = total_ports; - - if (total_ports > 1) - pf_dev->multiport = true; - pf_dev->pci_dev = pci_dev; - /* Map the symbol table */ - pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0", - pf_dev->total_phyports * 32768, &pf_dev->ctrl_area); - if (pf_dev->ctrl_bar == NULL) { - PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar"); - ret = -EIO; - goto pf_cleanup; - } - - PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar); - /* configure access to tx/rx vNIC BARs */ switch (pci_dev->id.device_id) { case PCI_DEVICE_ID_NFP3800_PF_NIC: @@ -925,7 +957,8 @@ default: PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); err = -ENODEV; - goto ctrl_area_cleanup; + ret = -ENODEV; + goto pf_cleanup; } pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0, @@ -934,18 +967,27 @@ if (pf_dev->hw_queues == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; - goto ctrl_area_cleanup; + goto pf_cleanup; } PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); /* - * Initialize and prep physical ports now - * This will loop through all physical ports + * PF initialization has been done at this point. Call app specific + * init code now */ - ret = nfp_init_phyports(pf_dev); - if (ret) { - PMD_INIT_LOG(ERR, "Could not create physical ports"); + switch (pf_dev->app_fw_id) { + case NFP_APP_FW_CORE_NIC: + PMD_INIT_LOG(INFO, "Initializing coreNIC"); + ret = nfp_init_app_fw_nic(pf_dev, nfp_eth_table); + if (ret != 0) { + PMD_INIT_LOG(ERR, "Could not initialize coreNIC!"); + goto hwqueues_cleanup; + } + break; + default: + PMD_INIT_LOG(ERR, "Unsupported Firmware loaded"); + ret = -EINVAL; goto hwqueues_cleanup; } @@ -956,8 +998,6 @@ hwqueues_cleanup: nfp_cpp_area_free(pf_dev->hwqueues_area); -ctrl_area_cleanup: - nfp_cpp_area_free(pf_dev->ctrl_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: @@ -966,6 +1006,8 @@ free(nfp_eth_table); hwinfo_cleanup: free(hwinfo); +cpp_cleanup: + nfp_cpp_free(cpp); error: return ret; } @@ -979,7 +1021,8 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) { int i; - int err; + int err = 0; + int ret = 0; int total_ports; struct nfp_cpp *cpp; struct nfp_net_hw *hw; @@ -1017,6 +1060,11 @@ } total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err); + if (err != 0 || total_ports <= 0 || total_ports > 8) { + PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value"); + ret = -ENODEV; + goto sym_tbl_cleanup; + } for (i = 0; i < total_ports; i++) { struct rte_eth_dev *eth_dev; @@ -1030,7 +1078,8 @@ if (eth_dev == NULL) { RTE_LOG(ERR, EAL, "secondary process attach failed, ethdev doesn't exist"); - return -ENODEV; + ret = -ENODEV; + break; } hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); @@ -1046,7 +1095,10 @@ /* Register the CPP bridge service for the secondary too */ nfp_register_cpp_service(cpp); - return 0; +sym_tbl_cleanup: + free(sym_tbl); + + return ret; } static int -- 1.8.3.1