1252268Sjimharris/*-
2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3330449Seadler *
4252268Sjimharris * Copyright (C) 2012-2013 Intel Corporation
5252268Sjimharris * All rights reserved.
6252268Sjimharris *
7252268Sjimharris * Redistribution and use in source and binary forms, with or without
8252268Sjimharris * modification, are permitted provided that the following conditions
9252268Sjimharris * are met:
10252268Sjimharris * 1. Redistributions of source code must retain the above copyright
11252268Sjimharris *    notice, this list of conditions and the following disclaimer.
12252268Sjimharris * 2. Redistributions in binary form must reproduce the above copyright
13252268Sjimharris *    notice, this list of conditions and the following disclaimer in the
14252268Sjimharris *    documentation and/or other materials provided with the distribution.
15252268Sjimharris *
16252268Sjimharris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17252268Sjimharris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18252268Sjimharris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19252268Sjimharris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20252268Sjimharris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21252268Sjimharris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22252268Sjimharris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23252268Sjimharris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24252268Sjimharris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25252268Sjimharris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26252268Sjimharris * SUCH DAMAGE.
27252268Sjimharris */
28252268Sjimharris
29252268Sjimharris#include <sys/cdefs.h>
30252268Sjimharris__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/reset.c 330449 2018-03-05 07:26:05Z eadler $");
31252268Sjimharris
32252268Sjimharris#include <sys/param.h>
33252268Sjimharris#include <sys/ioccom.h>
34252268Sjimharris
35253109Sjimharris#include <err.h>
36252268Sjimharris#include <fcntl.h>
37252268Sjimharris#include <stdio.h>
38252268Sjimharris#include <stdlib.h>
39252268Sjimharris#include <string.h>
40252268Sjimharris#include <unistd.h>
41252268Sjimharris
42252268Sjimharris#include "nvmecontrol.h"
43252268Sjimharris
44252268Sjimharrisstatic void
45252268Sjimharrisreset_usage(void)
46252268Sjimharris{
47252268Sjimharris	fprintf(stderr, "usage:\n");
48252268Sjimharris	fprintf(stderr, RESET_USAGE);
49253109Sjimharris	exit(1);
50252268Sjimharris}
51252268Sjimharris
52252268Sjimharrisvoid
53252268Sjimharrisreset(int argc, char *argv[])
54252268Sjimharris{
55252268Sjimharris	int	ch, fd;
56252268Sjimharris
57252268Sjimharris	while ((ch = getopt(argc, argv, "")) != -1) {
58252268Sjimharris		switch ((char)ch) {
59252268Sjimharris		default:
60252268Sjimharris			reset_usage();
61252268Sjimharris		}
62252268Sjimharris	}
63252268Sjimharris
64252274Sjimharris	/* Check that a controller was specified. */
65252274Sjimharris	if (optind >= argc)
66252274Sjimharris		reset_usage();
67252274Sjimharris
68252268Sjimharris	open_dev(argv[optind], &fd, 1, 1);
69253109Sjimharris	if (ioctl(fd, NVME_RESET_CONTROLLER) < 0)
70253109Sjimharris		err(1, "reset request to %s failed", argv[optind]);
71252268Sjimharris
72253109Sjimharris	exit(0);
73252268Sjimharris}
74