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