From owner-svn-src-all@freebsd.org Tue Sep 3 14:08:01 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C7D5DDD54E; Tue, 3 Sep 2019 14:07:08 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80D40N6z4QHD; Tue, 3 Sep 2019 14:07:08 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id E95A91B135; Tue, 3 Sep 2019 14:06:28 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 7BBDE179C0; Fri, 19 Apr 2019 13:18:59 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 31FE876BF4; Fri, 19 Apr 2019 13:18:59 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1A62F179BE; Fri, 19 Apr 2019 13:18:59 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 95DD9179BC for ; Fri, 19 Apr 2019 13:18:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 496AB76BEC; Fri, 19 Apr 2019 13:18:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 264802EC66; Fri, 19 Apr 2019 13:18:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3JDIuqE094907; Fri, 19 Apr 2019 13:18:56 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3JDItK0094902; Fri, 19 Apr 2019 13:18:55 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904191318.x3JDItK0094902@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r346384 - in stable/11: lib/libdevctl usr.sbin/devctl X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/11: lib/libdevctl usr.sbin/devctl X-SVN-Commit-Revision: 346384 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 31FE876BF4 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.983,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:08:01 -0000 X-Original-Date: Fri, 19 Apr 2019 13:18:55 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:08:01 -0000 Author: kib Date: Fri Apr 19 13:18:54 2019 New Revision: 346384 URL: https://svnweb.freebsd.org/changeset/base/346384 Log: MFC r345966, r345968: Implement devctl(8) command 'reset', using DEV_RESET /dev/devctl2 ioctl. Modified: stable/11/lib/libdevctl/devctl.3 stable/11/lib/libdevctl/devctl.c stable/11/lib/libdevctl/devctl.h stable/11/usr.sbin/devctl/devctl.8 stable/11/usr.sbin/devctl/devctl.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libdevctl/devctl.3 ============================================================================== --- stable/11/lib/libdevctl/devctl.3 Fri Apr 19 13:09:16 2019 (r346383) +++ stable/11/lib/libdevctl/devctl.3 Fri Apr 19 13:18:54 2019 (r346384) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 29, 2016 +.Dd April 4, 2019 .Dt DEVCTL 3 .Os .Sh NAME @@ -37,6 +37,7 @@ .Nm devctl_disable , .Nm devctl_enable , .Nm devctl_rescan , +.Nm devctl_reset , .Nm devctl_resume , .Nm devctl_set_driver , .Nm devctl_suspend @@ -60,6 +61,8 @@ .Ft int .Fn devctl_rescan "const char *device" .Ft int +.Fn devctl_reset "const char *device" "bool detach" +.Ft int .Fn devctl_resume "const char *device" .Ft int .Fn devctl_set_driver "const char *device" "const char *driver" "bool force" @@ -189,6 +192,15 @@ The .Fn devctl_rescan function rescans a bus device checking for devices that have been added or removed. +.Pp +The +.Fn devctl_reset +function resets the specified device using bus-specific reset method. +The +.Fa detach +argument, if true, specifies that the device driver is detached before +the reset, and re-attached afterwards. +If false, the device is suspended before the reset, and resumed after. .Sh RETURN VALUES .Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \ devctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \ @@ -362,6 +374,21 @@ is false. .Fa dev is the root device of the device tree. .El +.Pp +The +.Fn devctl_reset +function may fail if: +.Bl -tag -width Er +.It Bq Er ENXIO +The bus does not implement the reset method. +.It Bq Er ETIMEDOUT +The device failed to respond after the reset in the time limits +specific to the bus. +.El +The +.Fn devctl_reset +function may also return errors caused by the attach, detach, suspend, +and resume methods of the device driver. .Sh SEE ALSO .Xr devinfo 3 , .Xr devstat 3 , @@ -376,3 +403,20 @@ If a device is suspended individually via .Fn devctl_suspend and the entire machine is subsequently suspended, the device will be resumed when the machine resumes. +.Pp +Similarly, if the device is suspended, and +.Fn devctl_reset +is called on the device with +.Fa detach +set to +.Va false , +the device is resumed by the +.Fn devctl_reset +call. +Or, if the driver for the device is detached manually, and +.Fn devctl_reset +is called on the device with +.Fa detach +set to +.Va true , +device reset re-attaches the driver. Modified: stable/11/lib/libdevctl/devctl.c ============================================================================== --- stable/11/lib/libdevctl/devctl.c Fri Apr 19 13:09:16 2019 (r346383) +++ stable/11/lib/libdevctl/devctl.c Fri Apr 19 13:18:54 2019 (r346384) @@ -145,3 +145,11 @@ devctl_delete(const char *device, bool force) return (devctl_simple_request(DEV_DELETE, device, force ? DEVF_FORCE_DELETE : 0)); } + +int +devctl_reset(const char *device, bool detach) +{ + + return (devctl_simple_request(DEV_RESET, device, detach ? + DEVF_RESET_DETACH : 0)); +} Modified: stable/11/lib/libdevctl/devctl.h ============================================================================== --- stable/11/lib/libdevctl/devctl.h Fri Apr 19 13:09:16 2019 (r346383) +++ stable/11/lib/libdevctl/devctl.h Fri Apr 19 13:18:54 2019 (r346384) @@ -42,6 +42,7 @@ int devctl_set_driver(const char *device, const char * int devctl_clear_driver(const char *device, bool force); int devctl_rescan(const char *device); int devctl_delete(const char *device, bool force); +int devctl_reset(const char *device, bool detach); __END_DECLS #endif /* !__DEVCTL_H__ */ Modified: stable/11/usr.sbin/devctl/devctl.8 ============================================================================== --- stable/11/usr.sbin/devctl/devctl.8 Fri Apr 19 13:09:16 2019 (r346383) +++ stable/11/usr.sbin/devctl/devctl.8 Fri Apr 19 13:18:54 2019 (r346384) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 29, 2016 +.Dd April 4, 2019 .Dt DEVCTL 8 .Os .Sh NAME @@ -67,6 +67,10 @@ .Cm delete .Op Fl f .Ar device +.Nm +.Cm reset +.Op Fl d +.Ar device .Sh DESCRIPTION The .Nm @@ -167,7 +171,35 @@ the device will be deleted even if it is physically pr This command should be used with care as a device that is deleted but present can no longer be used unless the parent bus device rediscovers the device via a rescan request. +.It Xo Cm reset +.Op Fl d +.Ar device +.Xc +Reset the device, using bus-specific reset method. +Drivers for the devices being reset are suspended around the reset. +If the +.Fl d +option is specified, drivers are detached instead. +.Pp +Currently, resets are implemented for PCIe buses and PCI devices. +For PCIe bus, the link is disabled and then re-trained, causing all +children of the bus to reset. +Use +.Fl p +option of +.Xr devinfo 8 +tool to report parent bus for the device. +For PCI device, if Function-Level Reset is implemented by it, FLR is +tried first; if failed or not implemented, power reset is tried. +.Pp +If you have detached or suspended a child device explicitly and then +do a reset, the child device will end up attached. .El +.Sh BUGS +Currently there is no administrative flag to prevent re-attach or resume +of the manually detached or suspended devices after reset. +Similarly, there is no flag to prevent un-suspending of the the manually +suspended devices after system resume. .Sh SEE ALSO .Xr devctl 3 , .Xr devinfo 8 Modified: stable/11/usr.sbin/devctl/devctl.c ============================================================================== --- stable/11/usr.sbin/devctl/devctl.c Fri Apr 19 13:09:16 2019 (r346383) +++ stable/11/usr.sbin/devctl/devctl.c Fri Apr 19 13:18:54 2019 (r346384) @@ -71,7 +71,7 @@ DEVCTL_TABLE(top, set); static void usage(void) { - fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", + fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "usage: devctl attach device", " devctl detach [-f] device", " devctl disable [-f] device", @@ -81,7 +81,9 @@ usage(void) " devctl set driver [-f] device driver", " devctl clear driver [-f] device", " devctl rescan device", - " devctl delete [-f] device"); + " devctl delete [-f] device", + " devctl reset [-d] device" + ); exit(1); } @@ -342,6 +344,40 @@ delete(int ac, char **av) return (0); } DEVCTL_COMMAND(top, delete, delete); + +static void +reset_usage(void) +{ + + fprintf(stderr, "usage: devctl reset [-d] device\n"); + exit(1); +} + +static int +reset(int ac, char **av) +{ + bool detach_drv; + int ch; + + detach_drv = false; + while ((ch = getopt(ac, av, "d")) != -1) + switch (ch) { + case 'd': + detach_drv = true; + break; + default: + reset_usage(); + } + ac -= optind; + av += optind; + + if (ac != 1) + reset_usage(); + if (devctl_reset(av[0], detach_drv) < 0) + err(1, "Failed to reset %s", av[0]); + return (0); +} +DEVCTL_COMMAND(top, reset, reset); int main(int ac, char *av[])