Project

General

Profile

Bug #5698 » mptreset.c

Origin: https://github.com/kojack/mptsastools/blob/master/mptreset.c - Marcel Telka, 2017-01-19 04:23 PM

 
1
/*
2
 * Utility to send chip reset ioctl to mpt_sas driver on an illumos 
3
 * platform.
4
 *
5
 * Originally from J. Molanus
6
 *
7
 * Type in the command with no parameter and it will give
8
 * you the correct devhdl device path. Then type command
9
 * again with the suggested device path.
10
 */
11
#include <stdlib.h>
12
#include <sys/types.h>
13
#include <fcntl.h>
14
#include <string.h>
15
#include <stdio.h>
16
#include "mpi2_type.h"
17
#include "mpi2.h"
18
#include "mpi2_init.h"
19
#include "mptsas_ioctl.h"
20
#include <assert.h>
21

    
22
#include <errno.h>
23
#include <libdevice.h>
24
#include <libdevinfo.h>
25

    
26
static int
27
proces_node(di_node_t d, di_minor_t dm, void *arg)
28
{
29

    
30
    char *name;
31

    
32
    if ((name = di_devfs_path(d)) != NULL) {
33

    
34
            char *dname = di_driver_name(d);
35

    
36
            if ((strcmp(dname, "mpt_sas") == 0)  &&
37
                (strstr(name, "iport") == NULL)) {
38
                    printf("%s%d : /devices%s:devctl\n", dname, di_instance(d),
39
                       name);
40
            }
41
    }
42

    
43
}
44
void
45
list_mptsas()
46
{
47
    di_node_t d;
48

    
49
    d = di_init("/", DINFOSUBTREE | DINFOMINOR);
50
    assert (d != NULL);
51

    
52
    di_walk_minor(d, DDI_NT_NEXUS, NULL, 0, &proces_node);
53
    di_fini(d);
54

    
55
    exit(0);
56
}
57

    
58
int main(int argc, char *argv[])
59
{
60

    
61
    int i = 0;
62
    int fd;
63

    
64
    if (argc < 2) {
65
            printf("need mptsas card as argument\n");
66
                list_mptsas();
67
                return (-1);
68

    
69
    }
70

    
71
    if ((fd = open(argv[1], O_RDWR)) == -1) {
72
        printf("Failed to open %s : %s", argv[1], strerror(errno));
73
        return (-1);
74
    }
75

    
76
    if (ioctl(fd, (MPTIOCTL | 3), NULL) == -1) {
77
        printf("reset failed %s", strerror(errno));
78

    
79
        return (-1);
80
    }
81

    
82
    if (fd >0)
83
        close(fd);
84
    return (0);
85
}
(2-2/2)