1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21fcf3ce44SJohn Forte /*
22*3270659fSSrikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fcf3ce44SJohn Forte * Use is subject to license terms.
24fcf3ce44SJohn Forte */
25fcf3ce44SJohn Forte
26fcf3ce44SJohn Forte #define _DSW_
27fcf3ce44SJohn Forte
28fcf3ce44SJohn Forte #include <sys/types.h>
29fcf3ce44SJohn Forte #include <sys/ksynch.h>
30fcf3ce44SJohn Forte #include <sys/kmem.h>
31fcf3ce44SJohn Forte #include <sys/errno.h>
32fcf3ce44SJohn Forte #include <sys/conf.h>
33fcf3ce44SJohn Forte #include <sys/cmn_err.h>
34fcf3ce44SJohn Forte #include <sys/modctl.h>
35fcf3ce44SJohn Forte #include <sys/cred.h>
36fcf3ce44SJohn Forte #include <sys/file.h>
37fcf3ce44SJohn Forte #include <sys/ddi.h>
38fcf3ce44SJohn Forte #include <sys/unistat/spcs_s.h>
39fcf3ce44SJohn Forte #include <sys/dkio.h>
40fcf3ce44SJohn Forte
41fcf3ce44SJohn Forte #ifdef DS_DDICT
42fcf3ce44SJohn Forte #include "../contract.h"
43fcf3ce44SJohn Forte #endif
44fcf3ce44SJohn Forte
45fcf3ce44SJohn Forte #include <sys/nsctl/nsctl.h>
46fcf3ce44SJohn Forte #include <sys/nsctl/nsvers.h>
47fcf3ce44SJohn Forte
48fcf3ce44SJohn Forte #include <sys/sdt.h> /* dtrace is S10 or later */
49fcf3ce44SJohn Forte
50fcf3ce44SJohn Forte #include "dsw.h"
51fcf3ce44SJohn Forte #include "dsw_dev.h"
52fcf3ce44SJohn Forte
53fcf3ce44SJohn Forte #define DIDINIT 0x01
54fcf3ce44SJohn Forte #define DIDNODES 0x02
55fcf3ce44SJohn Forte
56fcf3ce44SJohn Forte
57fcf3ce44SJohn Forte static int iiopen(dev_t *devp, int flag, int otyp, cred_t *crp);
58fcf3ce44SJohn Forte static int iiclose(dev_t dev, int flag, int otyp, cred_t *crp);
59fcf3ce44SJohn Forte static int iiprint(dev_t dev, char *str);
60fcf3ce44SJohn Forte static int iiioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *crp,
61fcf3ce44SJohn Forte int *rvp);
62fcf3ce44SJohn Forte static int iiprobe(dev_info_t *dip);
63fcf3ce44SJohn Forte static int iiattach(dev_info_t *dip, ddi_attach_cmd_t cmd);
64fcf3ce44SJohn Forte static int iidetach(dev_info_t *dip, ddi_detach_cmd_t cmd);
65fcf3ce44SJohn Forte static int iistrat(struct buf *);
66fcf3ce44SJohn Forte static int iiread();
67fcf3ce44SJohn Forte
68fcf3ce44SJohn Forte
69fcf3ce44SJohn Forte static kstat_t *ii_gkstat = NULL;
70fcf3ce44SJohn Forte iigkstat_t iigkstat = {
71fcf3ce44SJohn Forte { "ii_debug", KSTAT_DATA_ULONG },
72fcf3ce44SJohn Forte { "ii_bitmap", KSTAT_DATA_ULONG },
73fcf3ce44SJohn Forte { "ii_throttle_unit", KSTAT_DATA_ULONG },
74fcf3ce44SJohn Forte { "ii_throttle_delay", KSTAT_DATA_ULONG },
75fcf3ce44SJohn Forte { "ii_copy_direct", KSTAT_DATA_ULONG },
76fcf3ce44SJohn Forte { "num-sets", KSTAT_DATA_ULONG },
77fcf3ce44SJohn Forte { "assoc-over", KSTAT_DATA_ULONG },
78fcf3ce44SJohn Forte { "spilled-over", KSTAT_DATA_ULONG },
79fcf3ce44SJohn Forte };
80fcf3ce44SJohn Forte
81fcf3ce44SJohn Forte static struct cb_ops ii_cb_ops = {
82fcf3ce44SJohn Forte iiopen,
83fcf3ce44SJohn Forte iiclose,
84fcf3ce44SJohn Forte iistrat, /* dummy strategy */
85fcf3ce44SJohn Forte iiprint,
86fcf3ce44SJohn Forte nodev, /* no dump */
87fcf3ce44SJohn Forte iiread, /* dummy read */
88fcf3ce44SJohn Forte nodev, /* no write */
89fcf3ce44SJohn Forte iiioctl,
90fcf3ce44SJohn Forte nodev, /* no devmap */
91fcf3ce44SJohn Forte nodev, /* no mmap */
92fcf3ce44SJohn Forte nodev, /* no segmap */
93fcf3ce44SJohn Forte nochpoll,
94fcf3ce44SJohn Forte ddi_prop_op,
95fcf3ce44SJohn Forte NULL, /* not STREAMS */
96fcf3ce44SJohn Forte D_NEW | D_MP
97fcf3ce44SJohn Forte };
98fcf3ce44SJohn Forte
99fcf3ce44SJohn Forte static struct dev_ops ii_ops = {
100fcf3ce44SJohn Forte DEVO_REV,
101fcf3ce44SJohn Forte 0,
102fcf3ce44SJohn Forte nodev, /* no getinfo */
103fcf3ce44SJohn Forte nulldev,
104fcf3ce44SJohn Forte iiprobe,
105fcf3ce44SJohn Forte iiattach,
106fcf3ce44SJohn Forte iidetach,
107fcf3ce44SJohn Forte nodev, /* no reset */
108fcf3ce44SJohn Forte &ii_cb_ops,
109fcf3ce44SJohn Forte (struct bus_ops *)NULL
110fcf3ce44SJohn Forte };
111fcf3ce44SJohn Forte
112fcf3ce44SJohn Forte static struct modldrv ii_ldrv = {
113fcf3ce44SJohn Forte &mod_driverops,
114fcf3ce44SJohn Forte "nws:Point-in-Time:" ISS_VERSION_STR,
115fcf3ce44SJohn Forte &ii_ops
116fcf3ce44SJohn Forte };
117fcf3ce44SJohn Forte
118fcf3ce44SJohn Forte static struct modlinkage ii_modlinkage = {
119fcf3ce44SJohn Forte MODREV_1,
120fcf3ce44SJohn Forte &ii_ldrv,
121fcf3ce44SJohn Forte NULL
122fcf3ce44SJohn Forte };
123fcf3ce44SJohn Forte
124fcf3ce44SJohn Forte struct ii_state {
125fcf3ce44SJohn Forte dev_info_t *dip;
126fcf3ce44SJohn Forte int instance;
127fcf3ce44SJohn Forte };
128fcf3ce44SJohn Forte
129fcf3ce44SJohn Forte /* used for logging sysevent, gets set in _ii_attach */
130fcf3ce44SJohn Forte dev_info_t *ii_dip = NULL;
131fcf3ce44SJohn Forte
132fcf3ce44SJohn Forte extern _ii_info_t *_ii_info_top;
133fcf3ce44SJohn Forte extern _ii_lsthead_t *_ii_cluster_top;
134fcf3ce44SJohn Forte extern _ii_lsthead_t *_ii_group_top;
135fcf3ce44SJohn Forte extern kmutex_t _ii_cluster_mutex;
136fcf3ce44SJohn Forte extern kmutex_t _ii_group_mutex;
137fcf3ce44SJohn Forte
138fcf3ce44SJohn Forte const int dsw_major_rev = ISS_VERSION_MAJ; /* Major release number */
139fcf3ce44SJohn Forte const int dsw_minor_rev = ISS_VERSION_MIN; /* Minor release number */
140fcf3ce44SJohn Forte const int dsw_micro_rev = ISS_VERSION_MIC; /* Micro release number */
141fcf3ce44SJohn Forte const int dsw_baseline_rev = ISS_VERSION_NUM; /* Baseline revision */
142fcf3ce44SJohn Forte static void *ii_statep;
143fcf3ce44SJohn Forte
144fcf3ce44SJohn Forte extern int _ii_init_dev();
145fcf3ce44SJohn Forte extern void _ii_deinit_dev();
146fcf3ce44SJohn Forte extern int _ii_config(intptr_t arg, int ilp32, int *rvp, int iflags);
147fcf3ce44SJohn Forte extern int _ii_disable(intptr_t arg, int ilp32, int *rvp);
148fcf3ce44SJohn Forte extern int _ii_suspend(intptr_t arg, int ilp32, int *rvp);
149fcf3ce44SJohn Forte extern int _ii_bitmap(intptr_t arg, int ilp32, int *rvp);
150fcf3ce44SJohn Forte extern int _ii_segment(intptr_t arg, int ilp32, int *rvp);
151fcf3ce44SJohn Forte extern int _ii_abort(intptr_t arg, int ilp32, int *rvp);
152fcf3ce44SJohn Forte extern int _ii_acopy(intptr_t arg, int ilp32, int *rvp);
153fcf3ce44SJohn Forte extern int _ii_copy(intptr_t arg, int ilp32, int *rvp);
154fcf3ce44SJohn Forte extern int _ii_shutdown(intptr_t arg, int *rvp);
155fcf3ce44SJohn Forte extern int _ii_stat(intptr_t arg, int ilp32, int *rvp);
156fcf3ce44SJohn Forte extern int _ii_version(intptr_t arg, int ilp32, int *rvp);
157fcf3ce44SJohn Forte extern int _ii_wait(intptr_t arg, int ilp32, int *rvp);
158fcf3ce44SJohn Forte extern int _ii_reset(intptr_t arg, int ilp32, int *rvp);
159fcf3ce44SJohn Forte extern int _ii_offline(intptr_t arg, int ilp32, int *rvp);
160fcf3ce44SJohn Forte extern int _ii_list(intptr_t arg, int ilp32, int *rvp);
161fcf3ce44SJohn Forte extern int _ii_listlen(int cmd, int ilp32, int *rvp);
162fcf3ce44SJohn Forte extern int _ii_export(intptr_t arg, int ilp32, int *rvp);
163fcf3ce44SJohn Forte extern int _ii_join(intptr_t arg, int ilp32, int *rvp);
164fcf3ce44SJohn Forte extern int _ii_copyparm(intptr_t arg, int ilp32, int *rvp);
165fcf3ce44SJohn Forte extern int _ii_ocreate(intptr_t arg, int ilp32, int *rvp);
166fcf3ce44SJohn Forte extern int _ii_oattach(intptr_t arg, int ilp32, int *rvp);
167fcf3ce44SJohn Forte extern int _ii_odetach(intptr_t arg, int ilp32, int *rvp);
168fcf3ce44SJohn Forte extern int _ii_olist(intptr_t arg, int ilp32, int *rvp);
169fcf3ce44SJohn Forte extern int _ii_ostat(intptr_t arg, int ilp32, int *rvp, int is_iost_2);
170fcf3ce44SJohn Forte extern int _ii_bitsset(intptr_t arg, int ilp32, int cmd, int *rvp);
171fcf3ce44SJohn Forte extern int _ii_gc_list(intptr_t, int, int *, kmutex_t *, _ii_lsthead_t *);
172fcf3ce44SJohn Forte extern int _ii_clist(intptr_t arg, int ilp32, int *rvp);
173fcf3ce44SJohn Forte extern int _ii_move_grp(intptr_t arg, int ilp32, int *rvp);
174fcf3ce44SJohn Forte extern int _ii_change_tag(intptr_t arg, int ilp32, int *rvp);
175fcf3ce44SJohn Forte extern int ii_debug;
176fcf3ce44SJohn Forte extern int ii_throttle_unit;
177fcf3ce44SJohn Forte extern int ii_throttle_delay;
178fcf3ce44SJohn Forte extern int ii_copy_direct;
179fcf3ce44SJohn Forte extern int ii_bitmap;
180fcf3ce44SJohn Forte
181fcf3ce44SJohn Forte int
_init(void)182fcf3ce44SJohn Forte _init(void)
183fcf3ce44SJohn Forte {
184fcf3ce44SJohn Forte int error;
185fcf3ce44SJohn Forte
186fcf3ce44SJohn Forte error = ddi_soft_state_init(&ii_statep, sizeof (struct ii_state), 1);
187fcf3ce44SJohn Forte if (!error) {
188fcf3ce44SJohn Forte error = mod_install(&ii_modlinkage);
189fcf3ce44SJohn Forte if (error)
190fcf3ce44SJohn Forte ddi_soft_state_fini(&ii_statep);
191fcf3ce44SJohn Forte }
192fcf3ce44SJohn Forte
193fcf3ce44SJohn Forte return (error);
194fcf3ce44SJohn Forte }
195fcf3ce44SJohn Forte
196fcf3ce44SJohn Forte int
_fini(void)197fcf3ce44SJohn Forte _fini(void)
198fcf3ce44SJohn Forte {
199fcf3ce44SJohn Forte int error;
200fcf3ce44SJohn Forte
201fcf3ce44SJohn Forte error = mod_remove(&ii_modlinkage);
202fcf3ce44SJohn Forte if (!error)
203fcf3ce44SJohn Forte ddi_soft_state_fini(&ii_statep);
204fcf3ce44SJohn Forte
205fcf3ce44SJohn Forte return (error);
206fcf3ce44SJohn Forte }
207fcf3ce44SJohn Forte
208fcf3ce44SJohn Forte int
_info(struct modinfo * modinfop)209fcf3ce44SJohn Forte _info(struct modinfo *modinfop)
210fcf3ce44SJohn Forte {
211fcf3ce44SJohn Forte int rc;
212fcf3ce44SJohn Forte
213fcf3ce44SJohn Forte rc = mod_info(&ii_modlinkage, modinfop);
214fcf3ce44SJohn Forte
215fcf3ce44SJohn Forte return (rc);
216fcf3ce44SJohn Forte }
217fcf3ce44SJohn Forte
218fcf3ce44SJohn Forte /* ARGSUSED */
219fcf3ce44SJohn Forte
220fcf3ce44SJohn Forte static int
iiprobe(dev_info_t * dip)221fcf3ce44SJohn Forte iiprobe(dev_info_t *dip)
222fcf3ce44SJohn Forte {
223fcf3ce44SJohn Forte return (DDI_PROBE_SUCCESS);
224fcf3ce44SJohn Forte }
225fcf3ce44SJohn Forte
226fcf3ce44SJohn Forte /*ARGSUSED*/
227fcf3ce44SJohn Forte static int
ii_stats_update(kstat_t * ksp,int rw)228fcf3ce44SJohn Forte ii_stats_update(kstat_t *ksp, int rw)
229fcf3ce44SJohn Forte {
230fcf3ce44SJohn Forte if (KSTAT_WRITE == rw) {
231fcf3ce44SJohn Forte return (EACCES);
232fcf3ce44SJohn Forte }
233fcf3ce44SJohn Forte
234fcf3ce44SJohn Forte /*
235fcf3ce44SJohn Forte * We do nothing here for now -- the kstat structure is
236fcf3ce44SJohn Forte * updated in-place
237fcf3ce44SJohn Forte */
238fcf3ce44SJohn Forte
239fcf3ce44SJohn Forte return (0);
240fcf3ce44SJohn Forte }
241fcf3ce44SJohn Forte
242fcf3ce44SJohn Forte static void
ii_create_kstats()243fcf3ce44SJohn Forte ii_create_kstats()
244fcf3ce44SJohn Forte {
245fcf3ce44SJohn Forte /* create global info structure */
246fcf3ce44SJohn Forte if (!ii_gkstat) {
247fcf3ce44SJohn Forte ii_gkstat = kstat_create("ii", 0, "global", "StorEdge",
248fcf3ce44SJohn Forte KSTAT_TYPE_NAMED,
249fcf3ce44SJohn Forte sizeof (iigkstat) / sizeof (kstat_named_t),
250fcf3ce44SJohn Forte KSTAT_FLAG_VIRTUAL);
251fcf3ce44SJohn Forte if (ii_gkstat) {
252fcf3ce44SJohn Forte ii_gkstat->ks_data = &iigkstat;
253fcf3ce44SJohn Forte ii_gkstat->ks_update = ii_stats_update;
254fcf3ce44SJohn Forte ii_gkstat->ks_private = 0;
255fcf3ce44SJohn Forte kstat_install(ii_gkstat);
256fcf3ce44SJohn Forte
257fcf3ce44SJohn Forte /* fill in immutable values */
258fcf3ce44SJohn Forte iigkstat.ii_debug.value.ul = ii_debug;
259fcf3ce44SJohn Forte iigkstat.ii_bitmap.value.ul = ii_bitmap;
260fcf3ce44SJohn Forte iigkstat.ii_throttle_unit.value.ul = ii_throttle_unit;
261fcf3ce44SJohn Forte iigkstat.ii_throttle_delay.value.ul =
262fcf3ce44SJohn Forte ii_throttle_delay;
263fcf3ce44SJohn Forte iigkstat.ii_copy_direct.value.ul = ii_copy_direct;
264fcf3ce44SJohn Forte } else {
265*3270659fSSrikanth, Ramana cmn_err(CE_WARN, "!Unable to create II global stats");
266fcf3ce44SJohn Forte }
267fcf3ce44SJohn Forte }
268fcf3ce44SJohn Forte }
269fcf3ce44SJohn Forte
270fcf3ce44SJohn Forte static int
iiattach(dev_info_t * dip,ddi_attach_cmd_t cmd)271fcf3ce44SJohn Forte iiattach(dev_info_t *dip, ddi_attach_cmd_t cmd)
272fcf3ce44SJohn Forte {
273fcf3ce44SJohn Forte struct ii_state *xsp;
274fcf3ce44SJohn Forte int instance;
275fcf3ce44SJohn Forte int i;
276fcf3ce44SJohn Forte intptr_t flags;
277fcf3ce44SJohn Forte
278fcf3ce44SJohn Forte if (cmd != DDI_ATTACH) {
279fcf3ce44SJohn Forte return (DDI_FAILURE);
280fcf3ce44SJohn Forte }
281fcf3ce44SJohn Forte /* save the dev_info_t to be used in logging using ddi_log_sysevent */
282fcf3ce44SJohn Forte ii_dip = dip;
283fcf3ce44SJohn Forte
284fcf3ce44SJohn Forte instance = ddi_get_instance(dip);
285fcf3ce44SJohn Forte if (ddi_soft_state_zalloc(ii_statep, instance) != 0) {
286*3270659fSSrikanth, Ramana cmn_err(CE_WARN, "!ii: no memory for instance %d state.",
287fcf3ce44SJohn Forte instance);
288fcf3ce44SJohn Forte return (DDI_FAILURE);
289fcf3ce44SJohn Forte }
290fcf3ce44SJohn Forte
291fcf3ce44SJohn Forte flags = 0;
292fcf3ce44SJohn Forte xsp = ddi_get_soft_state(ii_statep, instance);
293fcf3ce44SJohn Forte if (xsp == NULL) {
294fcf3ce44SJohn Forte cmn_err(CE_WARN,
295*3270659fSSrikanth, Ramana "!ii: attach: could not get state for instance %d.",
296fcf3ce44SJohn Forte instance);
297fcf3ce44SJohn Forte goto out;
298fcf3ce44SJohn Forte }
299fcf3ce44SJohn Forte
300fcf3ce44SJohn Forte ii_debug = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
301fcf3ce44SJohn Forte DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ii_debug", 0);
302fcf3ce44SJohn Forte if (ii_debug != 0) {
303fcf3ce44SJohn Forte #ifdef DEBUG
304*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: initializing ii version %d.%d.%d.%d",
305fcf3ce44SJohn Forte dsw_major_rev, dsw_minor_rev,
306fcf3ce44SJohn Forte dsw_micro_rev, dsw_baseline_rev);
307fcf3ce44SJohn Forte #else
308fcf3ce44SJohn Forte if (dsw_micro_rev) {
309*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: initializing ii vers %d.%d.%d",
310fcf3ce44SJohn Forte dsw_major_rev, dsw_minor_rev, dsw_micro_rev);
311fcf3ce44SJohn Forte } else {
312*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: initializing ii version %d.%d",
313fcf3ce44SJohn Forte dsw_major_rev, dsw_minor_rev);
314fcf3ce44SJohn Forte }
315fcf3ce44SJohn Forte #endif
316fcf3ce44SJohn Forte switch (ii_debug) {
317fcf3ce44SJohn Forte case 1:
318fcf3ce44SJohn Forte case 2: cmn_err(CE_NOTE,
319*3270659fSSrikanth, Ramana "!ii: ii_debug=%d is enabled.", ii_debug);
320fcf3ce44SJohn Forte break;
321fcf3ce44SJohn Forte default:
322fcf3ce44SJohn Forte cmn_err(CE_WARN,
323*3270659fSSrikanth, Ramana "!ii: Value of ii_debug=%d is not 0,1 or 2.",
324fcf3ce44SJohn Forte ii_debug);
325fcf3ce44SJohn Forte }
326fcf3ce44SJohn Forte }
327fcf3ce44SJohn Forte
328fcf3ce44SJohn Forte ii_bitmap = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
329fcf3ce44SJohn Forte DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ii_bitmap", II_WTHRU);
330fcf3ce44SJohn Forte switch (ii_bitmap) {
331fcf3ce44SJohn Forte case II_KMEM:
332fcf3ce44SJohn Forte if (ii_debug > 0)
333*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: ii_bitmap is in memory");
334fcf3ce44SJohn Forte break;
335fcf3ce44SJohn Forte case II_FWC:
336fcf3ce44SJohn Forte if (ii_debug > 0)
337*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: ii_bitmap is on disk,"
338*3270659fSSrikanth, Ramana " no FWC");
339fcf3ce44SJohn Forte break;
340fcf3ce44SJohn Forte case II_WTHRU:
341fcf3ce44SJohn Forte if (ii_debug > 0)
342*3270659fSSrikanth, Ramana cmn_err(CE_NOTE, "!ii: ii_bitmap is on disk");
343fcf3ce44SJohn Forte break;
344fcf3ce44SJohn Forte default:
345fcf3ce44SJohn Forte cmn_err(CE_NOTE,
346*3270659fSSrikanth, Ramana "!ii: ii_bitmap=%d out of range; "
347*3270659fSSrikanth, Ramana "defaulting WTHRU(%d)", ii_bitmap, II_WTHRU);
348fcf3ce44SJohn Forte ii_bitmap = II_WTHRU;
349fcf3ce44SJohn Forte }
350fcf3ce44SJohn Forte
351fcf3ce44SJohn Forte /* pick up these values if in ii.conf, otherwise leave alone */
352fcf3ce44SJohn Forte i = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
353fcf3ce44SJohn Forte DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ii_throttle_unit", 0);
354fcf3ce44SJohn Forte if (i > 0) {
355fcf3ce44SJohn Forte ii_throttle_unit = i;
356fcf3ce44SJohn Forte if ((ii_throttle_unit < MIN_THROTTLE_UNIT) ||
357fcf3ce44SJohn Forte (ii_throttle_unit > MAX_THROTTLE_UNIT) ||
358fcf3ce44SJohn Forte (ii_debug > 0))
359fcf3ce44SJohn Forte cmn_err(CE_NOTE,
360*3270659fSSrikanth, Ramana "!ii: ii_throttle_unit=%d", ii_throttle_unit);
361fcf3ce44SJohn Forte }
362fcf3ce44SJohn Forte
363fcf3ce44SJohn Forte i = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
364fcf3ce44SJohn Forte DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ii_throttle_delay", 0);
365fcf3ce44SJohn Forte if (i > 0) {
366fcf3ce44SJohn Forte ii_throttle_delay = i;
367fcf3ce44SJohn Forte if ((ii_throttle_delay < MIN_THROTTLE_DELAY) ||
368fcf3ce44SJohn Forte (ii_throttle_delay > MIN_THROTTLE_DELAY) ||
369fcf3ce44SJohn Forte (ii_debug > 0))
370fcf3ce44SJohn Forte cmn_err(CE_NOTE,
371*3270659fSSrikanth, Ramana "!ii: ii_throttle_delay=%d", ii_throttle_delay);
372fcf3ce44SJohn Forte }
373fcf3ce44SJohn Forte
374fcf3ce44SJohn Forte ii_copy_direct = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
375fcf3ce44SJohn Forte DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ii_copy_direct", 1);
376fcf3ce44SJohn Forte if (i > 0) {
377fcf3ce44SJohn Forte ii_copy_direct = i;
378fcf3ce44SJohn Forte if ((ii_copy_direct < 0) || (ii_copy_direct > 1))
379fcf3ce44SJohn Forte cmn_err(CE_NOTE,
380*3270659fSSrikanth, Ramana "!ii: ii_copy_direct=%d", ii_copy_direct);
381fcf3ce44SJohn Forte }
382fcf3ce44SJohn Forte
383fcf3ce44SJohn Forte if (_ii_init_dev()) {
384*3270659fSSrikanth, Ramana cmn_err(CE_WARN, "!ii: _ii_init_dev failed");
385fcf3ce44SJohn Forte goto out;
386fcf3ce44SJohn Forte }
387fcf3ce44SJohn Forte flags |= DIDINIT;
388fcf3ce44SJohn Forte
389fcf3ce44SJohn Forte xsp->dip = dip;
390fcf3ce44SJohn Forte xsp->instance = instance;
391fcf3ce44SJohn Forte
392fcf3ce44SJohn Forte if (ddi_create_minor_node(dip, "ii", S_IFCHR, instance, DDI_PSEUDO, 0)
393fcf3ce44SJohn Forte != DDI_SUCCESS) {
394*3270659fSSrikanth, Ramana cmn_err(CE_WARN, "!ii: could not create node.");
395fcf3ce44SJohn Forte goto out;
396fcf3ce44SJohn Forte }
397fcf3ce44SJohn Forte flags |= DIDNODES;
398fcf3ce44SJohn Forte
399fcf3ce44SJohn Forte ddi_set_driver_private(dip, (caddr_t)flags);
400fcf3ce44SJohn Forte ddi_report_dev(dip);
401fcf3ce44SJohn Forte
402fcf3ce44SJohn Forte ii_create_kstats();
403fcf3ce44SJohn Forte
404fcf3ce44SJohn Forte return (DDI_SUCCESS);
405fcf3ce44SJohn Forte
406fcf3ce44SJohn Forte out:
407fcf3ce44SJohn Forte ddi_set_driver_private(dip, (caddr_t)flags);
408fcf3ce44SJohn Forte (void) iidetach(dip, DDI_DETACH);
409fcf3ce44SJohn Forte
410fcf3ce44SJohn Forte return (DDI_FAILURE);
411fcf3ce44SJohn Forte }
412fcf3ce44SJohn Forte
413fcf3ce44SJohn Forte static int
iidetach(dev_info_t * dip,ddi_detach_cmd_t cmd)414fcf3ce44SJohn Forte iidetach(dev_info_t *dip, ddi_detach_cmd_t cmd)
415fcf3ce44SJohn Forte {
416fcf3ce44SJohn Forte struct ii_state *xsp;
417fcf3ce44SJohn Forte int instance;
418fcf3ce44SJohn Forte intptr_t flags;
419fcf3ce44SJohn Forte
420fcf3ce44SJohn Forte if (cmd != DDI_DETACH) {
421fcf3ce44SJohn Forte return (DDI_FAILURE);
422fcf3ce44SJohn Forte }
423fcf3ce44SJohn Forte
424fcf3ce44SJohn Forte if (_ii_info_top) {
425fcf3ce44SJohn Forte return (DDI_FAILURE); /* busy */
426fcf3ce44SJohn Forte }
427fcf3ce44SJohn Forte
428fcf3ce44SJohn Forte instance = ddi_get_instance(dip);
429fcf3ce44SJohn Forte xsp = ddi_get_soft_state(ii_statep, instance);
430fcf3ce44SJohn Forte if (xsp == NULL) {
431fcf3ce44SJohn Forte cmn_err(CE_WARN,
432*3270659fSSrikanth, Ramana "!ii: detach: could not get state for instance %d.",
433fcf3ce44SJohn Forte instance);
434fcf3ce44SJohn Forte return (DDI_FAILURE);
435fcf3ce44SJohn Forte }
436fcf3ce44SJohn Forte
437fcf3ce44SJohn Forte flags = (intptr_t)ddi_get_driver_private(dip);
438fcf3ce44SJohn Forte if (flags & DIDNODES)
439fcf3ce44SJohn Forte ddi_remove_minor_node(dip, NULL);
440fcf3ce44SJohn Forte if (flags & DIDINIT)
441fcf3ce44SJohn Forte _ii_deinit_dev();
442fcf3ce44SJohn Forte
443fcf3ce44SJohn Forte ddi_soft_state_free(ii_statep, instance);
444fcf3ce44SJohn Forte
445fcf3ce44SJohn Forte if (ii_gkstat) {
446fcf3ce44SJohn Forte kstat_delete(ii_gkstat);
447fcf3ce44SJohn Forte ii_gkstat = NULL;
448fcf3ce44SJohn Forte }
449fcf3ce44SJohn Forte
450fcf3ce44SJohn Forte return (DDI_SUCCESS);
451fcf3ce44SJohn Forte }
452fcf3ce44SJohn Forte
453fcf3ce44SJohn Forte
454fcf3ce44SJohn Forte /* ARGSUSED */
455fcf3ce44SJohn Forte
456fcf3ce44SJohn Forte static int
iiopen(dev_t * devp,int flag,int otyp,cred_t * crp)457fcf3ce44SJohn Forte iiopen(dev_t *devp, int flag, int otyp, cred_t *crp)
458fcf3ce44SJohn Forte {
459fcf3ce44SJohn Forte int error;
460fcf3ce44SJohn Forte
461fcf3ce44SJohn Forte error = drv_priv(crp);
462fcf3ce44SJohn Forte
463fcf3ce44SJohn Forte return (error);
464fcf3ce44SJohn Forte }
465fcf3ce44SJohn Forte
466fcf3ce44SJohn Forte
467fcf3ce44SJohn Forte /* ARGSUSED */
468fcf3ce44SJohn Forte
469fcf3ce44SJohn Forte static int
iiclose(dev_t dev,int flag,int otyp,cred_t * crp)470fcf3ce44SJohn Forte iiclose(dev_t dev, int flag, int otyp, cred_t *crp)
471fcf3ce44SJohn Forte {
472fcf3ce44SJohn Forte return (0);
473fcf3ce44SJohn Forte }
474fcf3ce44SJohn Forte
475fcf3ce44SJohn Forte /* ARGSUSED */
476fcf3ce44SJohn Forte
477fcf3ce44SJohn Forte static int
iiprint(dev_t dev,char * str)478fcf3ce44SJohn Forte iiprint(dev_t dev, char *str)
479fcf3ce44SJohn Forte {
480fcf3ce44SJohn Forte int instance = 0;
481fcf3ce44SJohn Forte
482*3270659fSSrikanth, Ramana cmn_err(CE_WARN, "!ii%d: %s", instance, str);
483fcf3ce44SJohn Forte return (0);
484fcf3ce44SJohn Forte }
485fcf3ce44SJohn Forte
486fcf3ce44SJohn Forte /* ARGSUSED */
487fcf3ce44SJohn Forte
488fcf3ce44SJohn Forte static int
iiioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * crp,int * rvp)489fcf3ce44SJohn Forte iiioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *crp, int *rvp)
490fcf3ce44SJohn Forte {
491fcf3ce44SJohn Forte int rc;
492fcf3ce44SJohn Forte int ilp32;
493fcf3ce44SJohn Forte
494fcf3ce44SJohn Forte ilp32 = (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32);
495fcf3ce44SJohn Forte
496fcf3ce44SJohn Forte
497fcf3ce44SJohn Forte switch (cmd) {
498fcf3ce44SJohn Forte case DSWIOC_WAIT:
499fcf3ce44SJohn Forte rc = _ii_wait(arg, ilp32, rvp);
500fcf3ce44SJohn Forte break;
501fcf3ce44SJohn Forte
502fcf3ce44SJohn Forte case DSWIOC_RESET:
503fcf3ce44SJohn Forte rc = _ii_reset(arg, ilp32, rvp);
504fcf3ce44SJohn Forte break;
505fcf3ce44SJohn Forte
506fcf3ce44SJohn Forte case DSWIOC_VERSION:
507fcf3ce44SJohn Forte rc = _ii_version(arg, ilp32, rvp);
508fcf3ce44SJohn Forte break;
509fcf3ce44SJohn Forte
510fcf3ce44SJohn Forte case DSWIOC_ENABLE:
511fcf3ce44SJohn Forte rc = _ii_config(arg, ilp32, rvp, 0);
512fcf3ce44SJohn Forte break;
513fcf3ce44SJohn Forte
514fcf3ce44SJohn Forte case DSWIOC_RESUME:
515fcf3ce44SJohn Forte rc = _ii_config(arg, ilp32, rvp, II_EXISTING);
516fcf3ce44SJohn Forte break;
517fcf3ce44SJohn Forte
518fcf3ce44SJohn Forte case DSWIOC_DISABLE:
519fcf3ce44SJohn Forte rc = _ii_disable(arg, ilp32, rvp);
520fcf3ce44SJohn Forte break;
521fcf3ce44SJohn Forte
522fcf3ce44SJohn Forte case DSWIOC_SUSPEND:
523fcf3ce44SJohn Forte rc = _ii_suspend(arg, ilp32, rvp);
524fcf3ce44SJohn Forte break;
525fcf3ce44SJohn Forte
526fcf3ce44SJohn Forte case DSWIOC_ACOPY:
527fcf3ce44SJohn Forte rc = _ii_acopy(arg, ilp32, rvp);
528fcf3ce44SJohn Forte break;
529fcf3ce44SJohn Forte
530fcf3ce44SJohn Forte case DSWIOC_COPY:
531fcf3ce44SJohn Forte rc = _ii_copy(arg, ilp32, rvp);
532fcf3ce44SJohn Forte break;
533fcf3ce44SJohn Forte
534fcf3ce44SJohn Forte case DSWIOC_SHUTDOWN:
535fcf3ce44SJohn Forte rc = _ii_shutdown(arg, rvp);
536fcf3ce44SJohn Forte break;
537fcf3ce44SJohn Forte
538fcf3ce44SJohn Forte case DSWIOC_STAT:
539fcf3ce44SJohn Forte rc = _ii_stat(arg, ilp32, rvp);
540fcf3ce44SJohn Forte break;
541fcf3ce44SJohn Forte
542fcf3ce44SJohn Forte case DSWIOC_BITMAP:
543fcf3ce44SJohn Forte rc = _ii_bitmap(arg, ilp32, rvp);
544fcf3ce44SJohn Forte break;
545fcf3ce44SJohn Forte
546fcf3ce44SJohn Forte case DSWIOC_SEGMENT:
547fcf3ce44SJohn Forte rc = _ii_segment(arg, ilp32, rvp);
548fcf3ce44SJohn Forte break;
549fcf3ce44SJohn Forte
550fcf3ce44SJohn Forte case DSWIOC_ABORT:
551fcf3ce44SJohn Forte rc = _ii_abort(arg, ilp32, rvp);
552fcf3ce44SJohn Forte break;
553fcf3ce44SJohn Forte
554fcf3ce44SJohn Forte case DSWIOC_OFFLINE:
555fcf3ce44SJohn Forte rc = _ii_offline(arg, ilp32, rvp);
556fcf3ce44SJohn Forte break;
557fcf3ce44SJohn Forte
558fcf3ce44SJohn Forte case DSWIOC_LIST:
559fcf3ce44SJohn Forte rc = _ii_list(arg, ilp32, rvp);
560fcf3ce44SJohn Forte break;
561fcf3ce44SJohn Forte
562fcf3ce44SJohn Forte case DSWIOC_LISTLEN:
563fcf3ce44SJohn Forte case DSWIOC_OLISTLEN:
564fcf3ce44SJohn Forte rc = _ii_listlen(cmd, ilp32, rvp);
565fcf3ce44SJohn Forte break;
566fcf3ce44SJohn Forte
567fcf3ce44SJohn Forte case DSWIOC_EXPORT:
568fcf3ce44SJohn Forte rc = _ii_export(arg, ilp32, rvp);
569fcf3ce44SJohn Forte break;
570fcf3ce44SJohn Forte
571fcf3ce44SJohn Forte case DSWIOC_IMPORT:
572fcf3ce44SJohn Forte rc = _ii_config(arg, ilp32, rvp, II_IMPORT);
573fcf3ce44SJohn Forte break;
574fcf3ce44SJohn Forte
575fcf3ce44SJohn Forte case DSWIOC_JOIN:
576fcf3ce44SJohn Forte rc = _ii_join(arg, ilp32, rvp);
577fcf3ce44SJohn Forte break;
578fcf3ce44SJohn Forte
579fcf3ce44SJohn Forte case DSWIOC_COPYP:
580fcf3ce44SJohn Forte rc = _ii_copyparm(arg, ilp32, rvp);
581fcf3ce44SJohn Forte break;
582fcf3ce44SJohn Forte
583fcf3ce44SJohn Forte case DSWIOC_OCREAT:
584fcf3ce44SJohn Forte rc = _ii_ocreate(arg, ilp32, rvp);
585fcf3ce44SJohn Forte break;
586fcf3ce44SJohn Forte
587fcf3ce44SJohn Forte case DSWIOC_OATTACH:
588fcf3ce44SJohn Forte rc = _ii_oattach(arg, ilp32, rvp);
589fcf3ce44SJohn Forte break;
590fcf3ce44SJohn Forte
591fcf3ce44SJohn Forte case DSWIOC_ODETACH:
592fcf3ce44SJohn Forte rc = _ii_odetach(arg, ilp32, rvp);
593fcf3ce44SJohn Forte break;
594fcf3ce44SJohn Forte
595fcf3ce44SJohn Forte case DSWIOC_OLIST:
596fcf3ce44SJohn Forte rc = _ii_olist(arg, ilp32, rvp);
597fcf3ce44SJohn Forte break;
598fcf3ce44SJohn Forte
599fcf3ce44SJohn Forte case DSWIOC_OSTAT:
600fcf3ce44SJohn Forte rc = _ii_ostat(arg, ilp32, rvp, FALSE);
601fcf3ce44SJohn Forte break;
602fcf3ce44SJohn Forte
603fcf3ce44SJohn Forte case DSWIOC_OSTAT2:
604fcf3ce44SJohn Forte rc = _ii_ostat(arg, ilp32, rvp, TRUE);
605fcf3ce44SJohn Forte break;
606fcf3ce44SJohn Forte
607fcf3ce44SJohn Forte case DSWIOC_SBITSSET:
608fcf3ce44SJohn Forte case DSWIOC_CBITSSET:
609fcf3ce44SJohn Forte rc = _ii_bitsset(arg, ilp32, cmd, rvp);
610fcf3ce44SJohn Forte break;
611fcf3ce44SJohn Forte
612fcf3ce44SJohn Forte case DSWIOC_CLIST:
613fcf3ce44SJohn Forte rc = _ii_gc_list(arg, ilp32, rvp, &_ii_cluster_mutex,
614fcf3ce44SJohn Forte _ii_cluster_top);
615fcf3ce44SJohn Forte break;
616fcf3ce44SJohn Forte
617fcf3ce44SJohn Forte case DSWIOC_GLIST:
618fcf3ce44SJohn Forte rc = _ii_gc_list(arg, ilp32, rvp, &_ii_group_mutex,
619fcf3ce44SJohn Forte _ii_group_top);
620fcf3ce44SJohn Forte break;
621fcf3ce44SJohn Forte
622fcf3ce44SJohn Forte case DSWIOC_MOVEGRP:
623fcf3ce44SJohn Forte rc = _ii_move_grp(arg, ilp32, rvp);
624fcf3ce44SJohn Forte break;
625fcf3ce44SJohn Forte
626fcf3ce44SJohn Forte case DSWIOC_CHANGETAG:
627fcf3ce44SJohn Forte rc = _ii_change_tag(arg, ilp32, rvp);
628fcf3ce44SJohn Forte break;
629fcf3ce44SJohn Forte
630fcf3ce44SJohn Forte default:
631fcf3ce44SJohn Forte rc = EINVAL;
632fcf3ce44SJohn Forte break;
633fcf3ce44SJohn Forte }
634fcf3ce44SJohn Forte
635fcf3ce44SJohn Forte return (rc);
636fcf3ce44SJohn Forte }
637fcf3ce44SJohn Forte
638fcf3ce44SJohn Forte /*
639fcf3ce44SJohn Forte * dummy function
640fcf3ce44SJohn Forte */
641fcf3ce44SJohn Forte
642fcf3ce44SJohn Forte static int
iistrat(struct buf * bp)643fcf3ce44SJohn Forte iistrat(struct buf *bp)
644fcf3ce44SJohn Forte {
645fcf3ce44SJohn Forte bp->b_error = EIO;
646fcf3ce44SJohn Forte biodone(bp);
647fcf3ce44SJohn Forte
648fcf3ce44SJohn Forte return (0);
649fcf3ce44SJohn Forte }
650fcf3ce44SJohn Forte
651fcf3ce44SJohn Forte static int
iiread()652fcf3ce44SJohn Forte iiread()
653fcf3ce44SJohn Forte {
654fcf3ce44SJohn Forte return (EIO);
655fcf3ce44SJohn Forte }
656