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