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