From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0063.outbound.protection.outlook.com [104.47.0.63]) by dpdk.org (Postfix) with ESMTP id F14C71B122 for ; Tue, 23 Oct 2018 20:26:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wQiLtTme2Yc0fErDI3WMmNp4pBIu0XIu7Suf/Glh+5A=; b=Y3UnZ95pViFrVB6/96qkZISNsFWBbVqUxkKtazydwVgcRnUTtWmUjWHBdTDKji8P33No/FByUrrADLLh3oXgHX9/+0l2/fBtsEEKMjD8vLnA5Thpr0ICZIIyYSA9GUqBN5jHrc2HOSrYjqKqkc2OCK7YZuz7OC7fMZftbmB6zQs= Received: from AM6PR0502MB3735.eurprd05.prod.outlook.com (52.133.21.12) by AM6PR0502MB3624.eurprd05.prod.outlook.com (52.133.20.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1273.18; Tue, 23 Oct 2018 18:26:05 +0000 Received: from AM6PR0502MB3735.eurprd05.prod.outlook.com ([fe80::5416:c31f:6c60:b280]) by AM6PR0502MB3735.eurprd05.prod.outlook.com ([fe80::5416:c31f:6c60:b280%5]) with mapi id 15.20.1250.028; Tue, 23 Oct 2018 18:26:05 +0000 From: Ophir Munk To: "dev@dpdk.org" , Yongseok Koh , Ophir Munk CC: Thomas Monjalon , Olga Shern , Asaf Penso , Shahaf Shuler Thread-Topic: [PATCH v4 3/3] net/mlx5: close all ports on remove Thread-Index: AQHUav3cJq1CQ8aGDU20yHd6qNxMBQ== Date: Tue, 23 Oct 2018 18:26:05 +0000 Message-ID: <1540319157-11191-3-git-send-email-ophirmu@mellanox.com> References: <1539936770-24252-1-git-send-email-ophirmu@mellanox.com> <1540319157-11191-1-git-send-email-ophirmu@mellanox.com> In-Reply-To: <1540319157-11191-1-git-send-email-ophirmu@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0388.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f::16) To AM6PR0502MB3735.eurprd05.prod.outlook.com (2603:10a6:209:a::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR0502MB3624; 6:5a2eRUBNFCJEf9djFwAyAWXIFfbHHEOPnm5ENfDviKBaNjFuZDBPhj1Vy9rMmbZb7HYvcmvFR2vf5OScrR/ydoSIVbUWfvxjk88JeSAXcMm8dgMPN5dYae9FMgFo91PZMSUFEkHwrSfr4RnBaW5X7ZLnvhkQHMNEa+4KjU59WMfE8NQnQ08ote+yj8Ijt73gsmqZ3IpOv1XucxzEP7C/vzKS8RyGT7IdTXuL8bDmoyOpqDrOYoi5g4F50ssrM2T2H2r6fx0pIQvDLLYUm6NhS6hwbi6qSaifr0uDqoTDFQNLynCJWOYCbkyTfvA4iugbVnH3Z+JAoGRerGlXLoFTZEYrAgzzVL8UI3jdQ0sGpSmViyB4osgdy/N4P419Mu2Pn/IKXa8TQ95zM7luoenjR/9O1sQhnX/VLtFyEPRwSF7LZHGEBK6L9RpERGa2MK7um9K+sqCrCZya8BSU2y3uTw==; 5:/embR07z+X3TpNxlveyZOezbWOsqxsrZyi5fKBuB7qFaCf8ozoCXVBrzj5a9qN9rSQZQV8q1aV3QY4SXgvPhMBR1Uy4X/I9TwfJo1nLEZoyqmNHc+dZt6nzIh9iGT9xZxh2U2mavYH4ST0N4x95JGBmIsx/KUat6tiyySyxxsdE=; 7:nTddUKLKq/OpEGidTtmrSauAorML7YJLZywxsvimRpIToT49WFvK+Y6rsuAjnCHwfUjIdbSaKA2HiMowQs6fEupeBSIGbaENZj6+3gcxUgszhQoD7mIJRBuisOEQ0OLivdDzLe2uqaQmSmyAxyKkRg== x-ms-office365-filtering-correlation-id: 8ea9d4f8-6ae6-4ae9-05b7-08d63914fea2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:AM6PR0502MB3624; x-ms-traffictypediagnostic: AM6PR0502MB3624: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:AM6PR0502MB3624; BCL:0; PCL:0; RULEID:; SRVR:AM6PR0502MB3624; x-forefront-prvs: 0834BAF534 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(136003)(396003)(346002)(366004)(39860400002)(199004)(189003)(2501003)(316002)(6512007)(81156014)(86362001)(5250100002)(11346002)(446003)(2616005)(476003)(25786009)(8936002)(2900100001)(110136005)(7049001)(54906003)(66066001)(97736004)(107886003)(68736007)(4326008)(71190400001)(71200400001)(5024004)(8676002)(478600001)(14444005)(256004)(81166006)(486006)(53936002)(76176011)(186003)(3846002)(99286004)(5660300001)(6116002)(6506007)(6436002)(105586002)(2906002)(106356001)(14454004)(305945005)(7736002)(6486002)(26005)(52116002)(386003)(36756003)(102836004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3624; H:AM6PR0502MB3735.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: UdUK5r1AOlhpddwk8cZTfDS2JJ06X1Kg1RFojNWU8TeQAB59DTZjvqVbHJF+31quxfib/kb5E6LoBLhmPmn+JhscDbpQedrlrvv9w3Oyh48WvKyP8p+7fPZ1u0dIkgPuRUAx3+UXCc/9j62/uiebSdxRqMa6eifVuMUD48W7tCiYQlXpEhLVNRt/jG7CCuapZ9zT9sI7fWIFC+NMlDV1yNdMywxNA/Uo6NnAPlj93AtxzPOV7a/YPgDRIeRxVMAPzX1I4Oyjn0lQCefKnq7MLpvUeGEIFSJMgMhyyqdOKtQ4NjmCo3MA/C5ik30lIeA9i9hUS/8E2gLuwdOT8nZREIiB7rZ3zIrvibBmac2Ve+Q= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ea9d4f8-6ae6-4ae9-05b7-08d63914fea2 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Oct 2018 18:26:05.7414 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3624 Subject: [dpdk-dev] [PATCH v4 3/3] net/mlx5: close all ports on remove 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: Tue, 23 Oct 2018 18:26:07 -0000 With the introduction of representors several eth devices are using the same rte device (e.g. a PCI bus). When calling port detach on one eth device it is required that all eth devices belonging to the same rte device have been closed in advance, then the rte device itself can be removed/detached. This commit implements this requirement implicitly by adding a remove callback to struct rte_pci_driver. The new behavior can be demonstrated in testpmd. First we attach a representor 0 using PCI address 0000:08:00.0 testpmd> port attach 0000:08:00.0,representor=3D[0] Attaching a new port... EAL: PCI device 0000:08:00.0 on NUMA socket 0 EAL: probe driver: 15b3:1013 net_mlx5 Port 0 is attached. Done Port 1 is attached. Done Port 0 is the master device (PF) - an ethdev of the PCI address. Port 1 is representor 0 - another ethdev (representing a VF) using the same PCI address. Next we detach port 1 testpmd> port detach 1 Removing a device... Port 0 is closed Port 1 is closed Now total ports is 0 Done Since port 0 has been implicitly closed we cannot act on it anymore. testpmd> port stop 0 Invalid port 0 Signed-off-by: Ophir Munk --- v1-v3 This patch was not part of the serie v4: Initial version drivers/net/mlx5/mlx5.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 7a8b45a..9f7a099 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1485,6 +1485,22 @@ struct mlx5_dev_spawn_data { return ret; } =20 +static int +mlx5_pci_remove(struct rte_pci_device *pci_dev) +{ + uint16_t port_id; + struct rte_eth_dev *port; + + for (port_id =3D 0; port_id < RTE_MAX_ETHPORTS; port_id++) { + port =3D &rte_eth_devices[port_id]; + if (port->state !=3D RTE_ETH_DEV_UNUSED && + port->device =3D=3D &pci_dev->device) + rte_eth_dev_close(port_id); + } + + return 0; +} + static const struct rte_pci_id mlx5_pci_id_map[] =3D { { RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, @@ -1537,6 +1553,7 @@ struct mlx5_dev_spawn_data { }, .id_table =3D mlx5_pci_id_map, .probe =3D mlx5_pci_probe, + .remove =3D mlx5_pci_remove, .drv_flags =3D RTE_PCI_DRV_INTR_LSC | RTE_PCI_DRV_INTR_RMV | RTE_PCI_DRV_PROBE_AGAIN, }; --=20 1.8.3.1