-
Notifications
You must be signed in to change notification settings - Fork 0
/
mptreset.c
85 lines (67 loc) · 1.67 KB
/
mptreset.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Utility to send chip reset ioctl to mpt_sas driver on an illumos
* platform.
*
* Originally from J. Molanus
*
* Type in the command with no parameter and it will give
* you the correct devhdl device path. Then type command
* again with the suggested device path.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include "mpi2_type.h"
#include "mpi2.h"
#include "mpi2_init.h"
#include "mptsas_ioctl.h"
#include <assert.h>
#include <errno.h>
#include <libdevice.h>
#include <libdevinfo.h>
static int
proces_node(di_node_t d, di_minor_t dm, void *arg)
{
char *name;
if ((name = di_devfs_path(d)) != NULL) {
char *dname = di_driver_name(d);
if ((strcmp(dname, "mpt_sas") == 0) &&
(strstr(name, "iport") == NULL)) {
printf("%s%d : /devices%s:devctl\n", dname, di_instance(d),
name);
}
}
}
void
list_mptsas()
{
di_node_t d;
d = di_init("/", DINFOSUBTREE | DINFOMINOR);
assert (d != NULL);
di_walk_minor(d, DDI_NT_NEXUS, NULL, 0, &proces_node);
di_fini(d);
exit(0);
}
int main(int argc, char *argv[])
{
int i = 0;
int fd;
if (argc < 2) {
printf("need mptsas card as argument\n");
list_mptsas();
return (-1);
}
if ((fd = open(argv[1], O_RDWR)) == -1) {
printf("Failed to open %s : %s", argv[1], strerror(errno));
return (-1);
}
if (ioctl(fd, (MPTIOCTL | 3), NULL) == -1) {
printf("reset failed %s", strerror(errno));
return (-1);
}
if (fd >0)
close(fd);
return (0);
}