1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM *
4*7836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM *
8*7836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM * and limitations under the License.
12*7836SJohn.Forte@Sun.COM *
13*7836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM *
19*7836SJohn.Forte@Sun.COM * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*7836SJohn.Forte@Sun.COM * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM */
25*7836SJohn.Forte@Sun.COM
26*7836SJohn.Forte@Sun.COM /*
27*7836SJohn.Forte@Sun.COM * SDBC user level ioctl interface
28*7836SJohn.Forte@Sun.COM */
29*7836SJohn.Forte@Sun.COM
30*7836SJohn.Forte@Sun.COM #include <stdio.h>
31*7836SJohn.Forte@Sun.COM #include <unistd.h>
32*7836SJohn.Forte@Sun.COM #include <stdlib.h>
33*7836SJohn.Forte@Sun.COM #include <sys/types.h>
34*7836SJohn.Forte@Sun.COM #include <fcntl.h>
35*7836SJohn.Forte@Sun.COM #include <strings.h>
36*7836SJohn.Forte@Sun.COM
37*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sd_cache.h>
38*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sd_conf.h>
39*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sdbc_ioctl.h>
40*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
41*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_u.h>
42*7836SJohn.Forte@Sun.COM
43*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sv.h>
44*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sv_impl.h>
45*7836SJohn.Forte@Sun.COM
46*7836SJohn.Forte@Sun.COM
47*7836SJohn.Forte@Sun.COM const char *__sdbc_dev = "/dev/sdbc";
48*7836SJohn.Forte@Sun.COM static int __sdbc_fd;
49*7836SJohn.Forte@Sun.COM
50*7836SJohn.Forte@Sun.COM
51*7836SJohn.Forte@Sun.COM static int
__sdbc_open(void)52*7836SJohn.Forte@Sun.COM __sdbc_open(void)
53*7836SJohn.Forte@Sun.COM {
54*7836SJohn.Forte@Sun.COM int fd;
55*7836SJohn.Forte@Sun.COM
56*7836SJohn.Forte@Sun.COM fd = open("/dev/nsctl", O_RDONLY);
57*7836SJohn.Forte@Sun.COM if (fd >= 0)
58*7836SJohn.Forte@Sun.COM (void) close(fd);
59*7836SJohn.Forte@Sun.COM
60*7836SJohn.Forte@Sun.COM fd = open(__sdbc_dev, O_RDONLY);
61*7836SJohn.Forte@Sun.COM if (fd < 0)
62*7836SJohn.Forte@Sun.COM return (-1);
63*7836SJohn.Forte@Sun.COM
64*7836SJohn.Forte@Sun.COM return (__sdbc_fd = fd);
65*7836SJohn.Forte@Sun.COM }
66*7836SJohn.Forte@Sun.COM
67*7836SJohn.Forte@Sun.COM
68*7836SJohn.Forte@Sun.COM static void
sv_list()69*7836SJohn.Forte@Sun.COM sv_list()
70*7836SJohn.Forte@Sun.COM {
71*7836SJohn.Forte@Sun.COM sv_name_t svn[1];
72*7836SJohn.Forte@Sun.COM sv_name_t *svn_system;
73*7836SJohn.Forte@Sun.COM sv_list_t svl;
74*7836SJohn.Forte@Sun.COM static int fd = -1;
75*7836SJohn.Forte@Sun.COM
76*7836SJohn.Forte@Sun.COM if (fd < 0)
77*7836SJohn.Forte@Sun.COM fd = open(SV_DEVICE, O_RDONLY);
78*7836SJohn.Forte@Sun.COM if (fd < 0)
79*7836SJohn.Forte@Sun.COM return;
80*7836SJohn.Forte@Sun.COM
81*7836SJohn.Forte@Sun.COM bzero(&svl, sizeof (svl));
82*7836SJohn.Forte@Sun.COM bzero(&svn[0], sizeof (svn));
83*7836SJohn.Forte@Sun.COM
84*7836SJohn.Forte@Sun.COM svl.svl_names = &svn[0];
85*7836SJohn.Forte@Sun.COM svl.svl_error = spcs_s_ucreate();
86*7836SJohn.Forte@Sun.COM
87*7836SJohn.Forte@Sun.COM if (ioctl(fd, SVIOC_LIST, &svl) < 0)
88*7836SJohn.Forte@Sun.COM return;
89*7836SJohn.Forte@Sun.COM
90*7836SJohn.Forte@Sun.COM svn_system = calloc(svl.svl_maxdevs, sizeof (*svn));
91*7836SJohn.Forte@Sun.COM if (svn_system == NULL)
92*7836SJohn.Forte@Sun.COM return;
93*7836SJohn.Forte@Sun.COM
94*7836SJohn.Forte@Sun.COM /* Grab the system list from the driver */
95*7836SJohn.Forte@Sun.COM svl.svl_count = svl.svl_maxdevs;
96*7836SJohn.Forte@Sun.COM svl.svl_names = svn_system;
97*7836SJohn.Forte@Sun.COM
98*7836SJohn.Forte@Sun.COM (void) ioctl(fd, SVIOC_LIST, &svl);
99*7836SJohn.Forte@Sun.COM
100*7836SJohn.Forte@Sun.COM free(svn_system);
101*7836SJohn.Forte@Sun.COM spcs_s_ufree(&svl.svl_error);
102*7836SJohn.Forte@Sun.COM }
103*7836SJohn.Forte@Sun.COM
104*7836SJohn.Forte@Sun.COM
105*7836SJohn.Forte@Sun.COM int
sdbc_ioctl(long cmd,long a0,long a1,long a2,long a3,long a4,spcs_s_info_t * ustatus)106*7836SJohn.Forte@Sun.COM sdbc_ioctl(long cmd, long a0, long a1, long a2, long a3, long a4,
107*7836SJohn.Forte@Sun.COM spcs_s_info_t *ustatus)
108*7836SJohn.Forte@Sun.COM {
109*7836SJohn.Forte@Sun.COM _sdbc_ioctl_t args;
110*7836SJohn.Forte@Sun.COM int rc;
111*7836SJohn.Forte@Sun.COM
112*7836SJohn.Forte@Sun.COM *ustatus = NULL;
113*7836SJohn.Forte@Sun.COM
114*7836SJohn.Forte@Sun.COM if (!__sdbc_fd && __sdbc_open() < 0)
115*7836SJohn.Forte@Sun.COM return (-1);
116*7836SJohn.Forte@Sun.COM
117*7836SJohn.Forte@Sun.COM switch (cmd) {
118*7836SJohn.Forte@Sun.COM /*
119*7836SJohn.Forte@Sun.COM * These ioctls work on open cache descriptors. The sv_list() function
120*7836SJohn.Forte@Sun.COM * has the side-effect of re-opening all configured descriptors.
121*7836SJohn.Forte@Sun.COM * Without this call, devices seem to "disappear" from the system when
122*7836SJohn.Forte@Sun.COM * certain reconfiguration operations, for example II or SNDR disable,
123*7836SJohn.Forte@Sun.COM * are done.
124*7836SJohn.Forte@Sun.COM * It does rely on SV being configured, so in an STE-only environment
125*7836SJohn.Forte@Sun.COM * the disappearing will still seem to happen.
126*7836SJohn.Forte@Sun.COM */
127*7836SJohn.Forte@Sun.COM case SDBC_SET_CD_HINT:
128*7836SJohn.Forte@Sun.COM case SDBC_GET_CD_HINT:
129*7836SJohn.Forte@Sun.COM case SDBC_STATS:
130*7836SJohn.Forte@Sun.COM case SDBC_GET_CD_BLK:
131*7836SJohn.Forte@Sun.COM case SDBC_INJ_IOERR:
132*7836SJohn.Forte@Sun.COM case SDBC_CLR_IOERR:
133*7836SJohn.Forte@Sun.COM sv_list();
134*7836SJohn.Forte@Sun.COM break;
135*7836SJohn.Forte@Sun.COM
136*7836SJohn.Forte@Sun.COM default:
137*7836SJohn.Forte@Sun.COM break;
138*7836SJohn.Forte@Sun.COM }
139*7836SJohn.Forte@Sun.COM
140*7836SJohn.Forte@Sun.COM args.arg0 = a0;
141*7836SJohn.Forte@Sun.COM args.arg1 = a1;
142*7836SJohn.Forte@Sun.COM args.arg2 = a2;
143*7836SJohn.Forte@Sun.COM args.arg3 = a3;
144*7836SJohn.Forte@Sun.COM args.arg4 = a4;
145*7836SJohn.Forte@Sun.COM args.magic = _SD_MAGIC; /* for versioning */
146*7836SJohn.Forte@Sun.COM args.sdbc_ustatus = spcs_s_ucreate();
147*7836SJohn.Forte@Sun.COM
148*7836SJohn.Forte@Sun.COM if ((rc = ioctl(__sdbc_fd, cmd, &args)) < 0) {
149*7836SJohn.Forte@Sun.COM *ustatus = args.sdbc_ustatus;
150*7836SJohn.Forte@Sun.COM } else {
151*7836SJohn.Forte@Sun.COM spcs_s_ufree(&args.sdbc_ustatus);
152*7836SJohn.Forte@Sun.COM *ustatus = NULL;
153*7836SJohn.Forte@Sun.COM }
154*7836SJohn.Forte@Sun.COM
155*7836SJohn.Forte@Sun.COM return (rc);
156*7836SJohn.Forte@Sun.COM }
157