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 62F3FA0560; Tue, 18 Oct 2022 21:44:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53CEB4114A; Tue, 18 Oct 2022 21:44:58 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.74]) by mails.dpdk.org (Postfix) with ESMTP id 0013D40395 for ; Tue, 18 Oct 2022 21:44:56 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CD4rK7BQkI37UIpoyD4meRUPw8NZ5SLTtRXK6x2qCJXIFmEPXJoh0mmt6+NuEc8Zn/j6/rSw8V/7/dWG4lFhR+6+XmeN/Q4v0TxHlAdSFApT6CgySKc/2pwCEDqLuY8agxFJN10+DMojdkcDBTRL7K29zr4mP7yTQj+lFzxcxdZS68TQZe0E7AP8lA6vB9ZFcgyN0U5ZaBCroCqr+9AsxIBncQfnqlnzXJC9mbK2xEBm8x8prKIvIEBfSm7DOrIccBAwyGKIASmGL5286mD96fWJLIldQTpL46I+hxnMM1mzmFw6OE4ZJXFx8J5uWNG/oNAt6CX44o5F0SfQbLqsxQ== 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=n6X1ALYtXHKDnxSFAnFX0O0AVPs3ovp88SXK9OaIurc=; b=N6WZLwlhqEupl6bUgBFgybl3zuH5s7pvyvQ1Gocxe1LKwZeNECQa3YddjQQRBJxHDA8VSWpQxqwIDKenSUTB8V/LsQfar7Vo6KNLmnQvJRYZEI8SLky3I0TuCAnp58SlW7US9crHHFZIL12PVRMGuVsi+cTOWHFpD4B43/OIQi30ydJJ0ldtt6WXkWerk4pPc0euvC+grohkfGm6zJBmEjFoMXnVBddQbrgAj78ZAyhbIP5K/HdsUxTFHnODLtmwEHQfCYzg/EG5BgY0Rgr0ZRSz7J3xm9/mk0Yl9m30MT+C2y+dYs88RChzARWJFpYSpuOfMFKgCh1ial5zeVIwow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=dpdk.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n6X1ALYtXHKDnxSFAnFX0O0AVPs3ovp88SXK9OaIurc=; b=jjmsZSUbGa0ZBhX6hEduUXF6H+KYBVGW6UZOf88tpkrisRuwe4lYtIR1RmXyVfSfOs8N9VxGK0cmHoRCb1EdicYAL3cyPUEupXI5W3amhC3rb1kqjaoZY9oMqr86Am0xq/ADhQ3ojfaWCZuAupd7OOnbMKtNWmI1kfBgePnFy/A= Received: from DS7PR03CA0188.namprd03.prod.outlook.com (2603:10b6:5:3b6::13) by DM8PR12MB5446.namprd12.prod.outlook.com (2603:10b6:8:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.34; Tue, 18 Oct 2022 19:44:55 +0000 Received: from DM6NAM11FT102.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::78) by DS7PR03CA0188.outlook.office365.com (2603:10b6:5:3b6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.33 via Frontend Transport; Tue, 18 Oct 2022 19:44:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT102.mail.protection.outlook.com (10.13.173.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5746.16 via Frontend Transport; Tue, 18 Oct 2022 19:44:54 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 18 Oct 2022 14:44:53 -0500 From: Andrew Boyer To: CC: Andrew Boyer , Neel Patel , "R Mohamed Shah" Subject: [PATCH v2 13/36] net/ionic: move PCI-specific code to a separate file Date: Tue, 18 Oct 2022 12:41:08 -0700 Message-ID: <20221018194131.23006-14-andrew.boyer@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221011005032.47584-1-andrew.boyer@amd.com> References: <20221011005032.47584-1-andrew.boyer@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT102:EE_|DM8PR12MB5446:EE_ X-MS-Office365-Filtering-Correlation-Id: 36565b5d-5e3c-48cf-d42a-08dab1413b26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VMVxBaAoTUV2FkcX2JSUH0yKTrpqMAA7JWjSAVO48dNPQIubXhO4tVecoCV2RhFo8dVWz1uTnPCHl2XMgCsoEzVvtNgma7qhXKmS2MqRR5hlPLHzrxUrCtuNRMTZ0sTT1edx6avHV5N6bb18gYsDoO7fO6IjuAy5ioxiV5ar+V8SxWKU27jFIaEhCwjUG6gB7N1qNMWZ0vgjyeYZz0KPvRWqXmt9jmxSA/rfKBK82+FEEt3fpiKSbcipRiyYxj1xyWGg8iC9CFNqx0l5mKJ02VpKduun2mnVxQdkff/fy5GNT2o+Xkj2xpbydLJSwuUbFktd2vIxDhnCksBFDuSC4gBcHdyy/MKXJGpW1JtSKKE/+Sw5mMx8x6OUuPt98YVd9AxOOjEtGibez0GHbl3wVjv+rIVy7Ie2IuLRKfGeshq3Wru+b0DGgvrUkmX0feyP723Oql6jMlAXDdqrRFTwYouyJN1BbYg28RB2m0UA/MeF80ju8730gkyuhEFKfwTn+gL5Nzu8bs5vqCqxJn0pBnQ4vl1zeb5V1jbuR/rqAnehLvtukkWi9DkngW31CKb12/QFmI/xGL+2aClUKHnBQA1tY98kx9P+Z5BFePpSkXTWvVZcCHPW59xLD8QfGaYkjEIDgQTJPehSULk37r/qsdPn0iMIT+IBugL4Kc4c5fHZFdK4EtE1yGJ34jOn+y3UCCBhLlWtpa27XepSXAL7BYb7aa/PJXHILUO+TVh8GyWOmTqskTgqdAiC+Kot32cqNXYbSMltxSL/+gzN7Td2gx05qcHytZ9HsQgD7BuEBFHVhWg1uCvZjiKMCzjXTqp/ X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230022)(4636009)(396003)(346002)(376002)(39860400002)(136003)(451199015)(36840700001)(40470700004)(46966006)(82740400003)(44832011)(70206006)(4326008)(2906002)(70586007)(81166007)(2616005)(356005)(30864003)(5660300002)(36860700001)(47076005)(336012)(16526019)(83380400001)(186003)(426003)(1076003)(86362001)(6666004)(26005)(54906003)(6916009)(40480700001)(316002)(8676002)(8936002)(41300700001)(36756003)(478600001)(40460700003)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2022 19:44:54.8956 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 36565b5d-5e3c-48cf-d42a-08dab1413b26 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT102.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5446 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 For future support of virtual devices, move the PCI code to its own file. Create a new device interface, struct ionic_dev_intf, to plug in to common code. Signed-off-by: Andrew Boyer Signed-off-by: Neel Patel Signed-off-by: R Mohamed Shah --- drivers/net/ionic/ionic.h | 13 +- drivers/net/ionic/ionic_dev.c | 62 --------- drivers/net/ionic/ionic_dev.h | 13 +- drivers/net/ionic/ionic_dev_pci.c | 216 ++++++++++++++++++++++++++++++ drivers/net/ionic/ionic_ethdev.c | 161 ++++++---------------- drivers/net/ionic/ionic_ethdev.h | 9 ++ drivers/net/ionic/ionic_main.c | 2 +- drivers/net/ionic/meson.build | 1 + 8 files changed, 286 insertions(+), 191 deletions(-) create mode 100644 drivers/net/ionic/ionic_dev_pci.c diff --git a/drivers/net/ionic/ionic.h b/drivers/net/ionic/ionic.h index 7c8710b637..8b0e85ea26 100644 --- a/drivers/net/ionic/ionic.h +++ b/drivers/net/ionic/ionic.h @@ -8,8 +8,6 @@ #include #include -#include - #include "ionic_dev.h" #include "ionic_if.h" #include "ionic_osdep.h" @@ -42,6 +40,11 @@ struct ionic_hw { uint16_t vendor_id; }; +struct ionic_bars { + struct ionic_dev_bar bar[IONIC_BARS_MAX]; + uint32_t num_bars; +}; + /* * Structure to store private data for each driver instance (for each adapter). */ @@ -49,10 +52,10 @@ struct ionic_adapter { struct ionic_hw hw; struct ionic_dev idev; const char *name; - struct ionic_dev_bar bars[IONIC_BARS_MAX]; + struct ionic_bars bars; + const struct ionic_dev_intf *intf; struct ionic_identity ident; struct ionic_lif *lif; - uint32_t num_bars; uint32_t max_ntxqs_per_lif; uint32_t max_nrxqs_per_lif; uint32_t max_mac_addrs; @@ -61,7 +64,7 @@ struct ionic_adapter { bool intrs[IONIC_INTR_CTRL_REGS_MAX]; bool link_up; char fw_version[IONIC_DEVINFO_FWVERS_BUFLEN]; - struct rte_pci_device *pci_dev; + void *bus_dev; }; /** ionic_admin_ctx - Admin command context. diff --git a/drivers/net/ionic/ionic_dev.c b/drivers/net/ionic/ionic_dev.c index 27abc29da4..1082a007d3 100644 --- a/drivers/net/ionic/ionic_dev.c +++ b/drivers/net/ionic/ionic_dev.c @@ -10,68 +10,6 @@ #include "ionic_lif.h" #include "ionic.h" -int -ionic_dev_setup(struct ionic_adapter *adapter) -{ - struct ionic_dev_bar *bar = adapter->bars; - unsigned int num_bars = adapter->num_bars; - struct ionic_dev *idev = &adapter->idev; - uint32_t sig; - u_char *bar0_base; - unsigned int i; - - /* BAR0: dev_cmd and interrupts */ - if (num_bars < 1) { - IONIC_PRINT(ERR, "No bars found, aborting"); - return -EFAULT; - } - - if (bar->len < IONIC_BAR0_SIZE) { - IONIC_PRINT(ERR, - "Resource bar size %lu too small, aborting", - bar->len); - return -EFAULT; - } - - bar0_base = bar->vaddr; - idev->dev_info = (union ionic_dev_info_regs *) - &bar0_base[IONIC_BAR0_DEV_INFO_REGS_OFFSET]; - idev->dev_cmd = (union ionic_dev_cmd_regs *) - &bar0_base[IONIC_BAR0_DEV_CMD_REGS_OFFSET]; - idev->intr_status = (struct ionic_intr_status *) - &bar0_base[IONIC_BAR0_INTR_STATUS_OFFSET]; - idev->intr_ctrl = (struct ionic_intr *) - &bar0_base[IONIC_BAR0_INTR_CTRL_OFFSET]; - - sig = ioread32(&idev->dev_info->signature); - if (sig != IONIC_DEV_INFO_SIGNATURE) { - IONIC_PRINT(ERR, "Incompatible firmware signature %" PRIx32 "", - sig); - return -EFAULT; - } - - for (i = 0; i < IONIC_DEVINFO_FWVERS_BUFLEN; i++) - adapter->fw_version[i] = - ioread8(&idev->dev_info->fw_version[i]); - adapter->fw_version[IONIC_DEVINFO_FWVERS_BUFLEN - 1] = '\0'; - - adapter->name = adapter->pci_dev->device.name; - - IONIC_PRINT(DEBUG, "%s firmware version: %s", - adapter->name, adapter->fw_version); - - /* BAR1: doorbells */ - bar++; - if (num_bars < 2) { - IONIC_PRINT(ERR, "Doorbell bar missing, aborting"); - return -EFAULT; - } - - idev->db_pages = bar->vaddr; - - return 0; -} - /* Devcmd Interface */ uint8_t diff --git a/drivers/net/ionic/ionic_dev.h b/drivers/net/ionic/ionic_dev.h index b284a36044..6dab7e5bbd 100644 --- a/drivers/net/ionic/ionic_dev.h +++ b/drivers/net/ionic/ionic_dev.h @@ -173,14 +173,23 @@ struct ionic_cq { struct ionic_lif; struct ionic_adapter; struct ionic_qcq; +struct rte_mempool; +struct rte_eth_dev; + +struct ionic_dev_intf { + int (*setup)(struct ionic_adapter *adapter); + void (*copy_bus_info)(struct ionic_adapter *adapter, + struct rte_eth_dev *eth_dev); + int (*configure_intr)(struct ionic_adapter *adapter); + void (*unconfigure_intr)(struct ionic_adapter *adapter); + void (*unmap_bars)(struct ionic_adapter *adapter); +}; void ionic_intr_init(struct ionic_dev *idev, struct ionic_intr_info *intr, unsigned long index); const char *ionic_opcode_to_str(enum ionic_cmd_opcode opcode); -int ionic_dev_setup(struct ionic_adapter *adapter); - void ionic_dev_cmd_go(struct ionic_dev *idev, union ionic_dev_cmd *cmd); uint8_t ionic_dev_cmd_status(struct ionic_dev *idev); bool ionic_dev_cmd_done(struct ionic_dev *idev); diff --git a/drivers/net/ionic/ionic_dev_pci.c b/drivers/net/ionic/ionic_dev_pci.c new file mode 100644 index 0000000000..5366cee56a --- /dev/null +++ b/drivers/net/ionic/ionic_dev_pci.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018-2022 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ionic.h" +#include "ionic_if.h" +#include "ionic_dev.h" +#include "ionic_ethdev.h" +#include "ionic_logs.h" + +static const struct rte_pci_id pci_id_ionic_map[] = { + { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_PF) }, + { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_VF) }, + { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_MGMT) }, + { .vendor_id = 0, /* sentinel */ }, +}; + +static int +ionic_pci_setup(struct ionic_adapter *adapter) +{ + struct ionic_dev_bar *bar = adapter->bars.bar; + unsigned int num_bars = adapter->bars.num_bars; + struct ionic_dev *idev = &adapter->idev; + struct rte_pci_device *bus_dev = adapter->bus_dev; + uint32_t sig; + u_char *bar0_base; + unsigned int i; + + /* BAR0: dev_cmd and interrupts */ + if (num_bars < 1) { + IONIC_PRINT(ERR, "No bars found, aborting\n"); + return -EFAULT; + } + + if (bar->len < IONIC_BAR0_SIZE) { + IONIC_PRINT(ERR, + "Resource bar size %lu too small, aborting\n", + bar->len); + return -EFAULT; + } + + bar0_base = bar->vaddr; + idev->dev_info = (union ionic_dev_info_regs *) + &bar0_base[IONIC_BAR0_DEV_INFO_REGS_OFFSET]; + idev->dev_cmd = (union ionic_dev_cmd_regs *) + &bar0_base[IONIC_BAR0_DEV_CMD_REGS_OFFSET]; + idev->intr_status = (struct ionic_intr_status *) + &bar0_base[IONIC_BAR0_INTR_STATUS_OFFSET]; + idev->intr_ctrl = (struct ionic_intr *) + &bar0_base[IONIC_BAR0_INTR_CTRL_OFFSET]; + + sig = ioread32(&idev->dev_info->signature); + if (sig != IONIC_DEV_INFO_SIGNATURE) { + IONIC_PRINT(ERR, "Incompatible firmware signature %#x", + sig); + return -EFAULT; + } + + for (i = 0; i < IONIC_DEVINFO_FWVERS_BUFLEN; i++) + adapter->fw_version[i] = + ioread8(&idev->dev_info->fw_version[i]); + adapter->fw_version[IONIC_DEVINFO_FWVERS_BUFLEN - 1] = '\0'; + + adapter->name = bus_dev->device.name; + + IONIC_PRINT(DEBUG, "%s firmware version: %s", + adapter->name, adapter->fw_version); + + /* BAR1: doorbells */ + bar++; + if (num_bars < 2) { + IONIC_PRINT(ERR, "Doorbell bar missing, aborting\n"); + return -EFAULT; + } + + idev->db_pages = bar->vaddr; + + return 0; +} + +static void +ionic_pci_copy_bus_info(struct ionic_adapter *adapter, + struct rte_eth_dev *eth_dev) +{ + rte_eth_copy_pci_info(eth_dev, adapter->bus_dev); +} + +static int +ionic_pci_configure_intr(struct ionic_adapter *adapter) +{ + struct rte_pci_device *pci_dev = + (struct rte_pci_device *)(adapter->bus_dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + int err; + + IONIC_PRINT(ERR, "Configuring %u intrs", adapter->nintrs); + + if (rte_intr_efd_enable(intr_handle, adapter->nintrs)) { + IONIC_PRINT(ERR, "Fail to create eventfd"); + return -1; + } + + if (rte_intr_dp_is_en(intr_handle)) { + IONIC_PRINT(NOTICE, + "Packet I/O interrupt on datapath is enabled"); + if (rte_intr_vec_list_alloc(intr_handle, "intr_vec", + adapter->nintrs)) { + IONIC_PRINT(ERR, "Failed to allocate %u vectors", + adapter->nintrs); + return -ENOMEM; + } + } + + err = rte_intr_callback_register(intr_handle, + ionic_dev_interrupt_handler, + adapter); + if (err) { + IONIC_PRINT(ERR, + "Failure registering interrupts handler (%d)", err); + return err; + } + + /* enable intr mapping */ + err = rte_intr_enable(intr_handle); + if (err) { + IONIC_PRINT(ERR, "Failure enabling interrupts (%d)", err); + return err; + } + + return 0; +} + +static void +ionic_pci_unconfigure_intr(struct ionic_adapter *adapter) +{ + struct rte_pci_device *pci_dev = + (struct rte_pci_device *)(adapter->bus_dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + + rte_intr_disable(intr_handle); + + rte_intr_callback_unregister(intr_handle, + ionic_dev_interrupt_handler, + adapter); +} + +static const struct ionic_dev_intf ionic_pci_intf = { + .setup = ionic_pci_setup, + .copy_bus_info = ionic_pci_copy_bus_info, + .configure_intr = ionic_pci_configure_intr, + .unconfigure_intr = ionic_pci_unconfigure_intr, +}; + +static int +eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + struct rte_mem_resource *resource; + struct ionic_bars bars; + unsigned long i; + + IONIC_PRINT(NOTICE, "Initializing device %s %s", + pci_dev->device.name, + rte_eal_process_type() == RTE_PROC_SECONDARY ? + "[SECONDARY]" : ""); + + bars.num_bars = 0; + for (i = 0; i < PCI_MAX_RESOURCE && i < IONIC_BARS_MAX; i++) { + resource = &pci_dev->mem_resource[i]; + if (resource->phys_addr == 0 || resource->len == 0) + continue; + + bars.bar[bars.num_bars].vaddr = resource->addr; + bars.bar[bars.num_bars].bus_addr = resource->phys_addr; + bars.bar[bars.num_bars].len = resource->len; + bars.num_bars++; + } + + return eth_ionic_dev_probe((void *)pci_dev, + &pci_dev->device, + &bars, + &ionic_pci_intf, + pci_dev->id.device_id, + pci_dev->id.vendor_id); +} + +static int +eth_ionic_pci_remove(struct rte_pci_device *pci_dev) +{ + return eth_ionic_dev_remove(&pci_dev->device); +} + +static struct rte_pci_driver rte_pci_ionic_pmd = { + .id_table = pci_id_ionic_map, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, + .probe = eth_ionic_pci_probe, + .remove = eth_ionic_pci_remove, +}; + +RTE_PMD_REGISTER_PCI(net_ionic_pci, rte_pci_ionic_pmd); +RTE_PMD_REGISTER_PCI_TABLE(net_ionic_pci, pci_id_ionic_map); +RTE_PMD_REGISTER_KMOD_DEP(net_ionic_pci, "* igb_uio | uio_pci_generic | vfio-pci"); diff --git a/drivers/net/ionic/ionic_ethdev.c b/drivers/net/ionic/ionic_ethdev.c index cabdfa1f21..7d95e52346 100644 --- a/drivers/net/ionic/ionic_ethdev.c +++ b/drivers/net/ionic/ionic_ethdev.c @@ -2,12 +2,9 @@ * Copyright 2018-2022 Advanced Micro Devices, Inc. */ -#include -#include #include #include #include -#include #include "ionic_logs.h" #include "ionic.h" @@ -57,13 +54,6 @@ static int ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, static int ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version, size_t fw_size); -static const struct rte_pci_id pci_id_ionic_map[] = { - { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_PF) }, - { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_VF) }, - { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_MGMT) }, - { .vendor_id = 0, /* sentinel */ }, -}; - static const struct rte_eth_desc_lim rx_desc_lim = { .nb_max = IONIC_MAX_RING_DESC, .nb_min = IONIC_MIN_RING_DESC, @@ -328,7 +318,7 @@ ionic_dev_link_update(struct rte_eth_dev *eth_dev, * @return * void */ -static void +void ionic_dev_interrupt_handler(void *param) { struct ionic_adapter *adapter = (struct ionic_adapter *)param; @@ -946,8 +936,6 @@ ionic_dev_stop(struct rte_eth_dev *eth_dev) return 0; } -static void ionic_unconfigure_intr(struct ionic_adapter *adapter); - /* * Reset and stop device. */ @@ -966,22 +954,24 @@ ionic_dev_close(struct rte_eth_dev *eth_dev) ionic_lif_free_queues(lif); IONIC_PRINT(NOTICE, "Removing device %s", eth_dev->device->name); - ionic_unconfigure_intr(adapter); + if (adapter->intf->unconfigure_intr) + (*adapter->intf->unconfigure_intr)(adapter); rte_eth_dev_destroy(eth_dev, eth_ionic_dev_uninit); ionic_port_reset(adapter); ionic_reset(adapter); + if (adapter->intf->unmap_bars) + (*adapter->intf->unmap_bars)(adapter); rte_free(adapter); return 0; } -static int +int eth_ionic_dev_init(struct rte_eth_dev *eth_dev, void *init_params) { - struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev); struct ionic_adapter *adapter = (struct ionic_adapter *)init_params; int err; @@ -997,7 +987,8 @@ eth_ionic_dev_init(struct rte_eth_dev *eth_dev, void *init_params) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - rte_eth_copy_pci_info(eth_dev, pci_dev); + if (adapter->intf->copy_bus_info) + (*adapter->intf->copy_bus_info)(adapter, eth_dev); eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; lif->eth_dev = eth_dev; @@ -1068,73 +1059,12 @@ eth_ionic_dev_uninit(struct rte_eth_dev *eth_dev) return 0; } -static int -ionic_configure_intr(struct ionic_adapter *adapter) -{ - struct rte_pci_device *pci_dev = adapter->pci_dev; - struct rte_intr_handle *intr_handle = pci_dev->intr_handle; - int err; - - IONIC_PRINT(DEBUG, "Configuring %u intrs", adapter->nintrs); - - if (rte_intr_efd_enable(intr_handle, adapter->nintrs)) { - IONIC_PRINT(ERR, "Fail to create eventfd"); - return -1; - } - - if (rte_intr_dp_is_en(intr_handle)) { - IONIC_PRINT(DEBUG, - "Packet I/O interrupt on datapath is enabled"); - - if (rte_intr_vec_list_alloc(intr_handle, "intr_vec", - adapter->nintrs)) { - IONIC_PRINT(ERR, "Failed to allocate %u vectors", - adapter->nintrs); - return -ENOMEM; - } - } - - err = rte_intr_callback_register(intr_handle, - ionic_dev_interrupt_handler, - adapter); - - if (err) { - IONIC_PRINT(ERR, - "Failure registering interrupts handler (%d)", - err); - return err; - } - - /* enable intr mapping */ - err = rte_intr_enable(intr_handle); - - if (err) { - IONIC_PRINT(ERR, "Failure enabling interrupts (%d)", err); - return err; - } - - return 0; -} - -static void -ionic_unconfigure_intr(struct ionic_adapter *adapter) -{ - struct rte_pci_device *pci_dev = adapter->pci_dev; - struct rte_intr_handle *intr_handle = pci_dev->intr_handle; - - rte_intr_disable(intr_handle); - - rte_intr_callback_unregister(intr_handle, - ionic_dev_interrupt_handler, - adapter); -} - -static int -eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, - struct rte_pci_device *pci_dev) +int +eth_ionic_dev_probe(void *bus_dev, struct rte_device *rte_dev, + struct ionic_bars *bars, const struct ionic_dev_intf *intf, + uint16_t device_id, uint16_t vendor_id) { char name[RTE_ETH_NAME_MAX_LEN]; - struct rte_mem_resource *resource; struct ionic_adapter *adapter; struct ionic_hw *hw; unsigned long i; @@ -1149,9 +1079,6 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto err; } - IONIC_PRINT(DEBUG, "Initializing device %s", - pci_dev->device.name); - adapter = rte_zmalloc("ionic", sizeof(*adapter), 0); if (!adapter) { IONIC_PRINT(ERR, "OOM"); @@ -1159,11 +1086,12 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto err; } - adapter->pci_dev = pci_dev; + adapter->bus_dev = bus_dev; hw = &adapter->hw; - hw->device_id = pci_dev->id.device_id; - hw->vendor_id = pci_dev->id.vendor_id; + /* Vendor and Device ID need to be set before init of shared code */ + hw->device_id = device_id; + hw->vendor_id = vendor_id; err = ionic_init_mac(hw); if (err != 0) { @@ -1172,19 +1100,21 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto err_free_adapter; } - adapter->num_bars = 0; - for (i = 0; i < PCI_MAX_RESOURCE && i < IONIC_BARS_MAX; i++) { - resource = &pci_dev->mem_resource[i]; - if (resource->phys_addr == 0 || resource->len == 0) - continue; - adapter->bars[adapter->num_bars].vaddr = resource->addr; - adapter->bars[adapter->num_bars].bus_addr = resource->phys_addr; - adapter->bars[adapter->num_bars].len = resource->len; - adapter->num_bars++; + adapter->bars.num_bars = bars->num_bars; + for (i = 0; i < bars->num_bars; i++) { + adapter->bars.bar[i].vaddr = bars->bar[i].vaddr; + adapter->bars.bar[i].bus_addr = bars->bar[i].bus_addr; + adapter->bars.bar[i].len = bars->bar[i].len; } - /* Discover ionic dev resources */ + if (intf->setup == NULL) { + IONIC_PRINT(ERR, "Device setup function is mandatory"); + goto err_free_adapter; + } + + adapter->intf = intf; + /* Discover ionic dev resources */ err = ionic_setup(adapter); if (err) { IONIC_PRINT(ERR, "Cannot setup device: %d, aborting", err); @@ -1241,20 +1171,20 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto err_free_adapter; } - snprintf(name, sizeof(name), "%s_lif", pci_dev->device.name); - err = rte_eth_dev_create(&pci_dev->device, - name, sizeof(struct ionic_lif), + snprintf(name, sizeof(name), "%s_lif", rte_dev->name); + err = rte_eth_dev_create(rte_dev, name, sizeof(struct ionic_lif), NULL, NULL, eth_ionic_dev_init, adapter); if (err) { IONIC_PRINT(ERR, "Cannot create eth device for %s", name); goto err_free_adapter; } - err = ionic_configure_intr(adapter); - - if (err) { - IONIC_PRINT(ERR, "Failed to configure interrupts"); - goto err_free_adapter; + if (adapter->intf->configure_intr) { + err = (*adapter->intf->configure_intr)(adapter); + if (err) { + IONIC_PRINT(ERR, "Failed to configure interrupts"); + goto err_free_adapter; + } } return 0; @@ -1265,33 +1195,22 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, return err; } -static int -eth_ionic_pci_remove(struct rte_pci_device *pci_dev) +int +eth_ionic_dev_remove(struct rte_device *rte_dev) { char name[RTE_ETH_NAME_MAX_LEN]; struct rte_eth_dev *eth_dev; /* Adapter lookup is using the eth_dev name */ - snprintf(name, sizeof(name), "%s_lif", pci_dev->device.name); + snprintf(name, sizeof(name), "%s_lif", rte_dev->name); eth_dev = rte_eth_dev_allocated(name); if (eth_dev) ionic_dev_close(eth_dev); else - IONIC_PRINT(DEBUG, "Cannot find device %s", - pci_dev->device.name); + IONIC_PRINT(DEBUG, "Cannot find device %s", rte_dev->name); return 0; } -static struct rte_pci_driver rte_ionic_pmd = { - .id_table = pci_id_ionic_map, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, - .probe = eth_ionic_pci_probe, - .remove = eth_ionic_pci_remove, -}; - -RTE_PMD_REGISTER_PCI(net_ionic, rte_ionic_pmd); -RTE_PMD_REGISTER_PCI_TABLE(net_ionic, pci_id_ionic_map); -RTE_PMD_REGISTER_KMOD_DEP(net_ionic, "* igb_uio | uio_pci_generic | vfio-pci"); RTE_LOG_REGISTER_DEFAULT(ionic_logtype, NOTICE); diff --git a/drivers/net/ionic/ionic_ethdev.h b/drivers/net/ionic/ionic_ethdev.h index 16077e2786..8dddef80d5 100644 --- a/drivers/net/ionic/ionic_ethdev.h +++ b/drivers/net/ionic/ionic_ethdev.h @@ -18,6 +18,15 @@ #define IONIC_ETH_DEV_TO_LIF(eth_dev) ((struct ionic_lif *) \ (eth_dev)->data->dev_private) +struct ionic_bars; +struct ionic_dev_intf; + +int eth_ionic_dev_probe(void *bus_dev, struct rte_device *rte_dev, + struct ionic_bars *bars, const struct ionic_dev_intf *intf, + uint16_t device_id, uint16_t vendor_id); +int eth_ionic_dev_remove(struct rte_device *rte_dev); + +void ionic_dev_interrupt_handler(void *param); int ionic_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete); #endif /* _IONIC_ETHDEV_H_ */ diff --git a/drivers/net/ionic/ionic_main.c b/drivers/net/ionic/ionic_main.c index 11b8a8a44b..05f1e90e30 100644 --- a/drivers/net/ionic/ionic_main.c +++ b/drivers/net/ionic/ionic_main.c @@ -336,7 +336,7 @@ ionic_dev_cmd_wait_check(struct ionic_dev *idev, unsigned long max_wait) int ionic_setup(struct ionic_adapter *adapter) { - return ionic_dev_setup(adapter); + return (*adapter->intf->setup)(adapter); } int diff --git a/drivers/net/ionic/meson.build b/drivers/net/ionic/meson.build index d122686b5a..00865c2139 100644 --- a/drivers/net/ionic/meson.build +++ b/drivers/net/ionic/meson.build @@ -9,6 +9,7 @@ endif sources = files( 'ionic_dev.c', + 'ionic_dev_pci.c', 'ionic_ethdev.c', 'ionic_lif.c', 'ionic_mac_api.c', -- 2.17.1