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 B8A6FA00C5; Tue, 21 Jun 2022 12:34:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A899F427E9; Tue, 21 Jun 2022 12:34:00 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2104.outbound.protection.outlook.com [40.107.237.104]) by mails.dpdk.org (Postfix) with ESMTP id 33246427EE for ; Tue, 21 Jun 2022 12:33:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNJivqDvmjtwSzBslmiXdbdISWV/vZoQKhGqYlzsvf0qiE/hQKuMr1mjwWbfJBy40h2LYzuYBhyfhjPy7Pl9k9LXnKS3/6zzK/ivX0+iSsvikqlPOHIsrWHnFZo3nHbA0mDIc9AfZs3Hio6YPcgS3A/JIMdhe5KyNdvhwDF3K1e6KM4majrx1ao9sllLQUmcYealNDUSPTWPCdwDEcLfldGewYXao1EwGDW+ZrSWCQ9I26IjUMbfmnY14aOpEPLU9yY9Am8XHzZ4dPpYV0xVlUFnr3nK/gEtksfGclSxY/bMgicMlqmk3N5RNtXrgZC+53+FJ9EvhDlhPf1XetXVhA== 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=IZpEocxG8MSfXwbJVoMiggWrgELxSCOi4Qp5T//d1yY=; b=nNR7jYX1WGHLDQRqHRyTe28Jfz/znrBcKHTwEzAM0eGIp2JGazkdMsoz0fH/5/uQoZZgu9hVOOPCd8OZr3hPPbDJDNudgoRPW5Daox87VUYS0k2rmaLyveRwzaEdgESVLcgdFKmvsSJ35nW60sxLMonTEiF7flegQ1CsAufDvAGAc87ANIhbzSZwTAQTPiXA05Tbe/5jWWv2ter4ty8fRkzsnDCGvAgrNYIomLpo5MbFAtQ85S5yklG9xlaWjzXAO7O0j6IhCoKGbod7cJ50/6Dm/C4tiu3+2o7U2I7Rac3G2uYz2JnVPT+F7G82io9V1o/HbCQRG8pLF7f09cTMgQ== 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=IZpEocxG8MSfXwbJVoMiggWrgELxSCOi4Qp5T//d1yY=; b=b0rP47iqnpl79xNuutfHm3XIrOFfJ7RxpGnai+t9Z4Oc7mUGC0PMrvzLhiifzxffTkFZzukubMYnX9o6vJMPvzwXaXq14dt+Xgz64NKBbHTu5aVc82ultG8GO0whZOdi0H9KhNWCibxALal0uDmKNXFQIhJvtm78npTnLqWxXGU= 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 MN2PR13MB3086.namprd13.prod.outlook.com (2603:10b6:208:135::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Tue, 21 Jun 2022 10:33:57 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021%7]) with mapi id 15.20.5373.015; Tue, 21 Jun 2022 10:33:57 +0000 From: Chaoyong He To: dev@dpdk.org Cc: niklas.soderlund@corigine.com, Chaoyong He , Heinrich Kuhn Subject: [PATCH v2 01/12] net/nfp: move app specific attributes to own struct Date: Tue, 21 Jun 2022 18:32:57 +0800 Message-Id: <1655807588-7320-2-git-send-email-chaoyong.he@corigine.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1655807588-7320-1-git-send-email-chaoyong.he@corigine.com> References: <1655807588-7320-1-git-send-email-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: OS0PR01CA0018.jpnprd01.prod.outlook.com (2603:1096:604:24::23) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 02293930-3265-432f-7a31-08da53718c11 X-MS-TrafficTypeDiagnostic: MN2PR13MB3086:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OaanwhMWe8UEYMFLTJvJmh7C8sfPNXF9clMU6u6lRg6KMImig2VAhKu+GyNbabVOy2BRFYpYt4IPBpGnJeUhNlN2gMTNKDMFxe9Rht3XbXMdyPbL1qUUT+jf5Ew76uuNSzuozwJZ+WzZBHxixkT+OW5kVpcsy7wLaA5Uzp/pZqKxO8L2YL+pVkuWAH07+HYj68tK5f733xUvg+FsAflb24aTUT/wlDGxYUpgZEpN6MoXSh9fG3QfM/OR9OSgLWpSWe1/q3BsW5hK4nZpp5bPG39xBtwOBCXj87LHBHXHnB5yi3KmPL5OvMsKji7jdjJZG5z4sOXbPUVuIfcTwGCBsNKFr4GPLHvCzeL3tuqgyshgU1YG3qQwr9imX7pKbWJAyO11mYUV7bgAmBoe7buyPusxMnPVG06NHpYFQFKOxQbcI8uEk5yO4ACOuX/63Om8H1O1SAlIgJ2du1RLs9oKDjesIZJPLhc3mGdUHuF/wrj9NnJbnshTDowjdnDQsn7leIX4heKFPxC4mA0pvlxpc2vjg8/nim+khJT+wG8uE4t2zfHBYNnvwgglCvZbXEFbMyOOB3OYnNb7fq4JqektlGOtlLQh2NwcSsskViIZA9ekCj6GXReDm0lvgau3QtdzAWPUhFtmKTRItS7oo3oN6BlnWOWU73wnyZJEITkgluzs62Tt7MeXOjWDOu9Lka1LSs2L3Sp+sTQb3J+QdRRrYnfMTzZzxSOP1gR+nYUex4oFO51Q2+sCJMtdIkdoYJvj 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:(13230016)(4636009)(376002)(396003)(136003)(366004)(39830400003)(346002)(83380400001)(107886003)(186003)(66574015)(41300700001)(2616005)(38100700002)(38350700002)(30864003)(66476007)(4326008)(86362001)(5660300002)(8936002)(44832011)(6506007)(2906002)(52116002)(26005)(6512007)(6916009)(54906003)(316002)(8676002)(66556008)(66946007)(6486002)(478600001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VjNRNU5qQVl0VDRVK0xDZGNET0dKVFdzOVBTbGlXa0FBcHg4cm41QWpNaVgv?= =?utf-8?B?UnVlUTMzdndhdnBTNThqK004VHlTSlhKU0hISmtaT2VxRHljVzZaTjkyd3BY?= =?utf-8?B?dmw4cno1WFgwVFpoay9MeHd1ZU1WUWk0WWdxN0FWSHFUb2w0dnBaaG52RDBu?= =?utf-8?B?WlptZEtiY1g4SGN5S0VpUDFvc254STBBZ1FRaTJ3bFZBclRLdlJYcUhVellK?= =?utf-8?B?aGJ6aFBCbzg0aVNNdUFjZUZ5ZjdHaWppYUE3M285RDlaODhzNW1iS3h4Y0hL?= =?utf-8?B?QUgwdVoxai9UL083a3Y2aklHdHYwWU9vYlJyeUw4RlRrMk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Z3hDL3huT2xvV0ppeDlzNUtTYjgvbzdWOHd2WVd5SmVUY0pt?= =?utf-8?B?UldHYVZ0QzFvTHZLNTlERmNLS20wS0lsZUpCcUhMYlJGdGpUK3hLR2JPKzg4?= =?utf-8?B?SUpsbTZtU2Y2VFVZL1dGaFdFVHlzbThyL2NmcUVYNnl0WmVFQXJwNDN2aFZy?= =?utf-8?B?cCtjUkd3UUN2ZUExRVNuRUZiRzQ1Q1RyUWZieXJHS0VBWHVkczVYRXRPVHZU?= =?utf-8?Q?aZfMyl3gbJRvw1Yo=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02293930-3265-432f-7a31-08da53718c11 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 10:33:57.3490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bdC83hAsGbgsKXeZLeNB1hQduEoO4OBvZ+qGS9d60eN/c40Cj2xS3b4cLL+VndSAuH2z/yBC7hb6cZXJKuKVCK7pkIIeYSVIGqgyrIaIEEI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR13MB3086 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 firmware applications. Currently only the CoreNIC application is supported. This commit makes needed infrastructure changes in order to support other firmware applications too. Clearer separation is made between the PF device and any application specific concepts. The PF struct is now generic regardless of the application loaded. A new struct is also made for the CoreNIC application. Future additions to support other applications should also add an applications specific struct. Signed-off-by: Chaoyong He Signed-off-by: Heinrich Kuhn Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfp_common.h | 33 +++++++- drivers/net/nfp/nfp_ethdev.c | 196 +++++++++++++++++++++++++++---------------- 2 files changed, 154 insertions(+), 75 deletions(-) diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 6d917e4..2aaf1d6 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -111,6 +111,14 @@ #include #include +/* Firmware application ID's */ +enum nfp_app_id { + NFP_APP_CORE_NIC = 0x1, + NFP_APP_BPF_NIC = 0x2, + NFP_APP_FLOWER_NIC = 0x3, + NFP_APP_ACTIVE_BUFFER_MGMT_NIC = 0x4, +}; + /* nfp_qcp_ptr - Read or Write Pointer of a queue */ enum nfp_qcp_ptr { NFP_QCP_READ_PTR = 0, @@ -121,8 +129,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_id app_id; + + /* Pointer to the app running on the PF */ + void *app_priv; /* Current values for control */ uint32_t ctrl; @@ -151,8 +161,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 +169,20 @@ struct nfp_pf_dev { uint32_t nfp_cpp_service_id; }; +struct nfp_app_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 +446,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_APP_PRIV_TO_APP_NIC(app_priv)\ + ((struct nfp_app_nic *)app_priv) + #endif /* _NFP_COMMON_H_ */ /* * Local variables: diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 5cdd34e..3c4b0ac 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_nic *app_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_nic->ports[port]; - nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp); + nfp_eth_table = nfp_eth_read_ports(app_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_nic *app_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_nic = NFP_APP_PRIV_TO_APP_NIC(pf_dev->app_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_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_nic *app_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_nic = NFP_APP_PRIV_TO_APP_NIC(pf_dev->app_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_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_nic->total_phyports; i++) { /* Check to see if ports are still in use */ - if (pf_dev->ports[i]) + if (app_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_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_nic *app_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_nic = NFP_APP_PRIV_TO_APP_NIC(pf_dev->app_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_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_nic, port); nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr); tmp_ether_addr = (struct rte_ether_addr *)&hw->mac_addr; @@ -718,25 +727,67 @@ } static int -nfp_init_phyports(struct nfp_pf_dev *pf_dev) +nfp_init_app_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_nic *app_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_nic = rte_zmalloc("nfp_app_nic", sizeof(*app_nic), 0); + if (app_nic == NULL) + return -ENOMEM; + + /* Point the app_priv pointer in the PF to the coreNIC app */ + pf_dev->app_priv = app_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 || 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_nic->total_phyports = total_vnics; + app_nic->pf_dev = pf_dev; + if (total_vnics > 1) + app_nic->multiport = true; + + /* Map the symbol table */ + pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0", + app_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_nic->total_phyports; i++) { snprintf(port_name, sizeof(port_name), "%s_port%d", pf_dev->pci_dev->device.name, i); @@ -760,7 +811,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_nic->ports[i] = hw; hw->pf_dev = pf_dev; hw->cpp = pf_dev->cpp; @@ -783,20 +834,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_nic->total_phyports; i++) { + if (app_nic->ports[i] && app_nic->ports[i]->eth_dev) { struct rte_eth_dev *tmp_dev; - tmp_dev = pf_dev->ports[i]->eth_dev; + tmp_dev = app_nic->ports[i]->eth_dev; rte_eth_dev_release_port(tmp_dev); - pf_dev->ports[i] = NULL; + app_nic->ports[i] = NULL; } } -eth_table_cleanup: - free(nfp_eth_table); + nfp_cpp_area_free(pf_dev->ctrl_area); +app_cleanup: + rte_free(app_nic); return ret; } @@ -804,11 +856,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_id app_id; struct nfp_pf_dev *pf_dev; struct nfp_hwinfo *hwinfo; char name[RTE_ETH_NAME_MAX_LEN]; @@ -840,9 +892,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"); @@ -865,20 +918,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_id = nfp_rtsym_read_le(sym_tbl, "_pf0_net_app_id", &err); + if (err) { + PMD_INIT_LOG(ERR, "Couldn't read app_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); @@ -888,27 +935,12 @@ } /* Populate the newly created PF device */ + pf_dev->app_id = app_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: @@ -923,7 +955,7 @@ default: PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); err = -ENODEV; - goto ctrl_area_cleanup; + goto pf_cleanup; } pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0, @@ -932,18 +964,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_id) { + case NFP_APP_CORE_NIC: + PMD_INIT_LOG(INFO, "Initializing coreNIC"); + ret = nfp_init_app_nic(pf_dev, nfp_eth_table); + if (ret) { + 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; } @@ -954,8 +995,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: @@ -964,6 +1003,8 @@ free(nfp_eth_table); hwinfo_cleanup: free(hwinfo); +cpp_cleanup: + nfp_cpp_free(cpp); error: return ret; } @@ -977,7 +1018,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; @@ -1015,6 +1057,11 @@ } total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err); + if (err || 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; @@ -1028,7 +1075,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); @@ -1041,10 +1089,16 @@ rte_eth_dev_probing_finish(eth_dev); } + if (ret) + goto sym_tbl_cleanup; + /* 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