From patchwork Fri Jul 1 02:20:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaoyong He X-Patchwork-Id: 113583 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 75A68A0093; Fri, 1 Jul 2022 04:21:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 66FC240A80; Fri, 1 Jul 2022 04:21:11 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by mails.dpdk.org (Postfix) with ESMTP id C6F7740A7F for ; Fri, 1 Jul 2022 04:21:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QSK2VsA03wckGI4J1y34kwcV0GQ/9udV49E/zZwb/jX7HMbsWXuFL/ORj+nfstgo8CvWW8s25IXXRcsrPGpMPScMNIK0B2b7S+BWWxHg1dbPcKZU78yHzzmZSVmYeballMpaxkhczgo0LdwV0EBZMfl9psbFCm2Iv8ym1t78kex9NizSEpjlUhqkKuHr0NQAOIo/py/pH00EIOEbnfMkB5m4/Ju521Ni3n9dOfSDOunlnRc+HaKJkzeUD56BJky5keEj6XPfc5en16jE/gkDsq5TiC933ExeY+p63aBWVvCgCu/JPxPpKnV5L7euzgTxTGy31pu4Tuun31+NjIM3iQ== 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=ezv67g2tTHEGOqTOxjcjc+t88QymzMp4vObeeV9faAVkrs1BnN50ELe24mgm4wLaNnrusK86YpxCC9YQCSWwS9X37j4i8a3M1CbvqmxSMgtVXPCovAxYATW5u1w8rOLXKq+JWNkZfSeJ+/Y+lu1M3xV9DOn5b92QQEvxeENqteWTLSckfNC6TnVlWt5lnKUW57QRHIZkRqvXhXycNFMIR3FIhXOWf7DYgqMNW3ddNcTwdpZ444wHK3GhM5F9xKI1o8CpswLUXKqSgmO3VQmtP0bUHfBLIfmwMZv+zbPdcEXv9Md3OBKQ16gt9fWh9sTIykh1eEclDMYhoV9koNp/7A== 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=OTR1OaZEuLJWyJ5hrWZDLqQb7d01A7aFvf47MeeHk0eIqSqD5XsREJ1XDaHMpNzRhOISGFM8H7//ozYPO8WNsfu02e2E5VH9o12DKUKUOFH1IM6bmDYW25RYXPG9CPiQ6H+tZYU7ICHG3PUNcoMBkWmIp5swnIvcdnuCdJjdSpI= 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 CH2PR13MB4459.namprd13.prod.outlook.com (2603:10b6:610:35::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.11; Fri, 1 Jul 2022 02:21:07 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5d9e:9ce5:51d1:2021%9]) with mapi id 15.20.5395.014; Fri, 1 Jul 2022 02:21:07 +0000 From: Chaoyong He To: dev@dpdk.org Cc: niklas.soderlund@corigine.com, Chaoyong He , Heinrich Kuhn Subject: [PATCH v4 01/12] net/nfp: move app specific attributes to own struct Date: Fri, 1 Jul 2022 10:20:06 +0800 Message-Id: <1656642017-8992-2-git-send-email-chaoyong.he@corigine.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656642017-8992-1-git-send-email-chaoyong.he@corigine.com> References: <1656642017-8992-1-git-send-email-chaoyong.he@corigine.com> X-ClientProxiedBy: SG2PR02CA0079.apcprd02.prod.outlook.com (2603:1096:4:90::19) 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: 96ab7021-9493-40f8-c009-08da5b085b10 X-MS-TrafficTypeDiagnostic: CH2PR13MB4459:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a7trIJEpOYWrBp9IPfe5rT1dmJE8KleskgQ1NkBtv8usMcHtf2VD81kN2P2478wnyj9dA9f2e3dT3lB0+S64B6nohIDdMl8l6Jswy1WrO0s2fY9WIlNjdAJJfsXQHZxfnC16ME2mz0t4TBVte5YlXGv0xASKAzcHxAzAuBKT+KF2NsT9OjDucgkF7p3BtvGhN6lqR4BW5QCYnfpdElqCdfv4+hTkd8u6dZmWjt9O5OfA9nmDnJM+yFr8wiLOlVqS+1hTO9EFf9djRIps9NHiGeT++W+u0ppjgyLN23uuOYkJjzo6VO3/sKNfAaKMG6/nKiQWJxH5BXlimVk2d6Wa9XcA4S1CsK88iJmrKnPeOcQ9QsSzAP6LG5idTHtT1rgS83Tj8+FtwOl14Dn1+xuHGt/+lIG5j3dKzfexjBpVRM/8JKj999GB+pM6gtSjz9DLhf8LtHSD/2d4a6H46HbVVxZp57IxErHKe7Px1lAoYd1gNeqC6xLrLmr/Yq5l+ONxDUz7RBvjwW46LnDxyDM25pX9XKMgDUM0A7S2k2J1GtUACndXH//yumUMoa29kbjBVoR8ig9/Ldvyk9laOBO17o9d8o7GcxmGmDqardSgUI0h+BjaBxzm8AAsIOqhzUWj/YTaVYT0s6lYLO6i5SLUXRcKRDO9YR17YT8Q4xGtZTDBqAMFXTUhMvo+xTkx41xZs9NcpEz14/SOlrfl10VADfJfaioR577u2ZAlp24fz6uVd5ShKs4ISbW0crLuRK/yr1X+BaNr+IQ96WyejB1SMpDVgora5BdYxwtMOcqyOrwk8mOEawX+FytBM7PcOw8OTbBNk2/4s/nQPetM1OHcnW25E00d4thRCHR+3H4bih/Ei40quOdnXUK60Tv9B62F 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)(39840400004)(346002)(376002)(366004)(396003)(136003)(6486002)(4326008)(186003)(36756003)(26005)(66476007)(66556008)(2616005)(8676002)(83380400001)(6512007)(107886003)(38350700002)(5660300002)(66946007)(8936002)(38100700002)(2906002)(54906003)(478600001)(30864003)(44832011)(6916009)(6506007)(316002)(52116002)(41300700001)(66574015)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rSrC+CkS792VngRUEIIhJKemTVox?= =?utf-8?q?nYVZnTN6KRUU5HaFh6i1FREGekJyHcIfKevI0fYMPBUtxNU8canOIbpvM1BJcY0V4?= =?utf-8?q?KLVDgLuC27df+8x88C4btLCbdENyhfn/paeASyLKGuz/QNrTavvF1djCoaVl8cZQv?= =?utf-8?q?4bezxFE56G61vfWtrHVLCI7sc1X/xmACdBiGCYhmnvxqu7ZOpCGjH4Min9NV1EIr3?= =?utf-8?q?J/BbskCV8rLrymBT9GNbZuA6ASg8vHD7Ej8sv9Wq+3cXhAqNkam6v5MhCnBqv6TZA?= =?utf-8?q?oK4XKO0wK8RE1BArx7fCngiQI/i5ke+D+GQn5Zsv5z+iY3KXZFC6AF7TYgfI2Pmnx?= =?utf-8?q?8502NoTL/c0RblSyjIvp0HMvq7eHDM2d8IbUEBjgDhW7COlcU3VmP3rY5GcqmxvT4?= =?utf-8?q?wHoU7GLMh48lVaIZQLFdCX1aiq0jubmxGyAekry5GIf8tD3OLE8aI+RXqggfybCTe?= =?utf-8?q?lC7vcYpUhw1KJ/H/wqKOTyfEuUvTG12vvieVCxRbnMpmMAz6V30M0JjJPAST5IS0R?= =?utf-8?q?d69noViO10zVT++sUugpZD1V/qzXTaCrxymT843SrC8cJ1NY+NlllORmyoGqlzjyw?= =?utf-8?q?pcQegm1GuLae4tiwoAVLl8CufZWgDxFrohJJeMQxuFXt0Tn+646iaCMC331LuJF8p?= =?utf-8?q?iCtVFF5HhdBI1vSsz+6vNbjl+kzpSic+btYLkkaR8uX/kDLJZh277rjp1qqYB85Hl?= =?utf-8?q?DF08YmJhkCkobU7SUtVM3cYX8EnJ4rh7E9Y+Fx0Ae5lwNIk0uzm+wdEKsmAwH3sh/?= =?utf-8?q?wTQC5Tfqd/YDbuX+SdXKNBTDDkZBcaadlaeIbcbwWvb8Su8M8rIVzSAEMuLxdEd0u?= =?utf-8?q?z7eNHpJEfTAQgf7bX/w+zDfxJDehRez91N7kbkrRdbQnGQiO6jZa0raq8Jc0yctpe?= =?utf-8?q?aVT5yBp6h5Kr0o+xQ4+3EKgId5N0vn7Amz4iJCjdCSnVeFVAiEMfATSHWdMQ81KlE?= =?utf-8?q?I/9DlzYpxc6JUxYMuYoOzNuC//jdZ6NE9OAfsvAQh2ezShHvTxxC1qvBoGYIJBhiF?= =?utf-8?q?b+z53svIjEXPDs3lRmX91TiapRw6xAZOu+zO5AaDgXsMsc+tOyuxH/WyOVwWBuqAk?= =?utf-8?q?+dfsslG7b6Sb/RL0ttHo4RgVaUFDlMAYnS83E4Wwv+Ezhv0Z9F136d9qUWoK6KzKi?= =?utf-8?q?BulkZPdtefF43rC3RvRQgRpsaonQvdZG/YJ9h91E6oMUz64xX+aBLONxQsUOWZTu0?= =?utf-8?q?ZZDT3BWcmMADOhcrkh45feSDEhnXEofCUOR9+/YnjZgWpTKwdsXvPJtqo/LYIgOoF?= =?utf-8?q?apQGevbvIMV+jIghCs+8PRHlhscmP+tnyZvay2wb87Lc40Pzx+sIg8edbocavIQxE?= =?utf-8?q?2VK/QUpX2voRq2RuuBpUHe4v1vlwwGPmkXThfO9AKEjHw6SJpwt7rLZDXpt6hgDi5?= =?utf-8?q?sCpBuWW5kKZN3HB5VE0j9GJdFhsuYBpay9DGCMBkyMruYgrn93hNH4S7QUB4Oi25A?= =?utf-8?q?jmgADoqZ6fNbBi8NLEh7WdGc+u4PukW90CS2hwdk06QcM0zgERuTI0TvDScAgt9LN?= =?utf-8?q?9osKrBh2+W10SzeKQpmlFqXkwuu6aibs4w=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96ab7021-9493-40f8-c009-08da5b085b10 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2022 02:21:07.2818 (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: zYNyzMD7Q/TJx34rduE7ZQMQhLItxEFeEsnK3rAVRPkXsE9EdItzf3uME/aJHEcZkU/m6/GutXx+9Y5Nn5G7mtdGhlpWp8qxkyv4hKQUMDo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR13MB4459 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