From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bilemail1.empirix.com (bilemail1.empirix.com [208.67.76.245]) by dpdk.org (Postfix) with ESMTP id 3F7121B808 for ; Tue, 10 Apr 2018 12:55:21 +0200 (CEST) Received: from BILEMAIL2.empirix.com (10.17.8.31) by bilemail1.empirix.com (10.17.8.30) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 10 Apr 2018 06:55:20 -0400 Received: from BILEMAIL2.empirix.com ([fe80::d87e:1501:61f7:93ba]) by bilemail2.empirix.com ([fe80::d87e:1501:61f7:93ba%22]) with mapi id 15.00.1178.000; Tue, 10 Apr 2018 06:55:20 -0400 From: "Tosatti, Giovanni" To: "dev@dpdk.org" Thread-Topic: Add option to dpdk-devbind.py to restore kernel driver binding Thread-Index: AdPB430fyPU88x6JTs+XbXjNGRGulQO1WKHQ Date: Tue, 10 Apr 2018 10:55:19 +0000 Message-ID: <40ff3805d8a647f8bda4a386cc6a3987@bilemail2.empirix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.12.50.126] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: [dpdk-dev] Add option to dpdk-devbind.py to restore kernel driver binding 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, 10 Apr 2018 10:55:21 -0000 This patch adds a " --restore" option that will unbind all devices currentl= y bound to DPDK PMDs back to the kernel driver. --- /opt/Perforce/gtosatti_centos/E-XMS/CSA-Mainline/Third-Party/dpdk/dpdk-= 16.07.orig/tools/dpdk-devbind.py +++ /opt/Perforce/gtosatti_centos/E-XMS/CSA-Mainline/Third-Party/dpdk/dpdk-= 16.07/tools/dpdk-devbind.py @@ -91,6 +91,9 @@ -u, --unbind: Unbind a device (Equivalent to \"-b none\") =20 + -r, --restore + Restore ALL the DPDK devices to their kernel drivers + --force: By default, devices which are used by Linux - as indicated by havi= ng routes in the routing table - cannot be modified. Using the --forc= e @@ -448,6 +451,21 @@ if "Driver_str" in devices[d]: unbind_one(d, force) =20 +def restore_all_to_kernel(): + global force_flag + # List all the available devices + for d in devices.keys(): + if not has_driver(d): + # Discard the unbinded devices + continue + if devices[d]["Driver_str"] in dpdk_drivers: + # List the unused Drivers of the the DPDK Devices... =20 + unused_drivers =3D devices[d]["Module_str"].split(",") + print("Restoring kernel driver for: %s '%s' '%s'" % (devices[d= ]["Slot"], + devices[d]["Device_str"], devices[d]["Module_str"])) + # Bind the current Device to the FIRST unused Driver + if unused_drivers: + bind_one(devices[d]["Slot"], unused_drivers[0], force_flag= ) =20 def display_devices(title, dev_list, extra_params=3DNone): '''Displays to the user the details of a list of devices given in @@ -513,7 +531,7 @@ try: opts, args =3D getopt.getopt(sys.argv[1:], "b:us", ["help", "usage", "status", "force", - "bind=3D", "unbind"]) + "bind=3D", "unbind", "restore"]) except getopt.GetoptError as error: print(str(error)) print("Run '%s --usage' for further information" % sys.argv[0]) @@ -527,11 +545,15 @@ status_flag =3D True if opt =3D=3D "--force": force_flag =3D True - if opt =3D=3D "-b" or opt =3D=3D "-u" or opt =3D=3D "--bind" or op= t =3D=3D "--unbind": + if (opt =3D=3D "-b" or opt =3D=3D "--bind" or + opt =3D=3D "-u" or opt =3D=3D "--unbind" or + opt =3D=3D "-r" or opt =3D=3D "--restore"): if b_flag is not None: print("Error - Only one bind or unbind may be specified\n"= ) sys.exit(1) - if opt =3D=3D "-u" or opt =3D=3D "--unbind": + if opt =3D=3D "-r" or opt =3D=3D "--restore": + b_flag =3D "restore" + elif opt =3D=3D "-u" or opt =3D=3D "--unbind": b_flag =3D "none" else: b_flag =3D arg @@ -551,11 +573,14 @@ sys.exit(1) =20 if b_flag is not None and len(args) =3D=3D 0: - print("Error: No devices specified.") - print("Run '%s --usage' for further information" % sys.argv[0]) - sys.exit(1) - - if b_flag =3D=3D "none" or b_flag =3D=3D "None": + if b_flag !=3D "restore": + print("Error: No devices specified.") + print("Run '%s --usage' for further information" % sys.argv[0]= ) + sys.exit(1) + + if b_flag =3D=3D "restore": + restore_all_to_kernel() + elif b_flag =3D=3D "none" or b_flag =3D=3D "None": unbind_all(args, force_flag) elif b_flag is not None: bind_all(args, b_flag, force_flag)