Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/io/scsi/adapters/scsi_vhci/scsi_vhci.c @ 6023:9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
author | cm136836 |
---|---|
date | Fri, 15 Feb 2008 11:18:20 -0800 |
parents | f3b9c8c61dbe |
children | b578f00bc056 |
rev | line source |
---|---|
4851 | 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 /* | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
4851 | 23 * Use is subject to license terms. |
24 */ | |
25 #pragma ident "%Z%%M% %I% %E% SMI" | |
26 | |
27 /* | |
28 * Multiplexed I/O SCSI vHCI implementation | |
29 */ | |
30 | |
31 #include <sys/conf.h> | |
32 #include <sys/file.h> | |
33 #include <sys/ddi.h> | |
34 #include <sys/sunddi.h> | |
35 #include <sys/scsi/scsi.h> | |
36 #include <sys/scsi/impl/scsi_reset_notify.h> | |
37 #include <sys/sunmdi.h> | |
38 #include <sys/mdi_impldefs.h> | |
39 #include <sys/scsi/adapters/scsi_vhci.h> | |
40 #include <sys/disp.h> | |
41 #include <sys/byteorder.h> | |
42 | |
43 extern uintptr_t scsi_callback_id; | |
44 extern ddi_dma_attr_t scsi_alloc_attr; | |
45 | |
46 #ifdef DEBUG | |
47 int vhci_debug = VHCI_DEBUG_DEFAULT_VAL; | |
48 #endif | |
49 | |
50 /* retry for the vhci_do_prout command when a not ready is returned */ | |
51 int vhci_prout_not_ready_retry = 180; | |
52 | |
53 /* | |
54 * These values are defined to support the internal retry of | |
55 * SCSI packets for better sense code handling. | |
56 */ | |
57 #define VHCI_CMD_CMPLT 0 | |
58 #define VHCI_CMD_RETRY 1 | |
59 #define VHCI_CMD_ERROR -1 | |
60 | |
61 #define PROPFLAGS (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM) | |
62 #define VHCI_SCSI_PERR 0x47 | |
63 #define VHCI_PGR_ILLEGALOP -2 | |
64 #define VHCI_NUM_UPDATE_TASKQ 8 | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
65 /* changed to 132 to accomodate HDS */ |
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
66 #define VHCI_STD_INQ_SIZE 132 |
4851 | 67 |
68 /* | |
69 * Version Macros | |
70 */ | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
71 #define VHCI_NAME_VERSION "SCSI VHCI Driver 1.68" |
4851 | 72 char vhci_version_name[] = VHCI_NAME_VERSION; |
73 | |
74 int vhci_first_time = 0; | |
75 clock_t vhci_to_ticks = 0; | |
76 int vhci_init_wait_timeout = VHCI_INIT_WAIT_TIMEOUT; | |
77 kcondvar_t vhci_cv; | |
78 kmutex_t vhci_global_mutex; | |
79 void *vhci_softstate = NULL; /* for soft state */ | |
80 | |
81 /* | |
82 * Flag to delay the retry of the reserve command | |
83 */ | |
84 int vhci_reserve_delay = 100000; | |
85 static int vhci_path_quiesce_timeout = 60; | |
86 static uchar_t zero_key[MHIOC_RESV_KEY_SIZE]; | |
87 | |
88 /* uscsi delay for a TRAN_BUSY */ | |
89 static int vhci_uscsi_delay = 100000; | |
90 static int vhci_uscsi_retry_count = 180; | |
91 /* uscsi_restart_sense timeout id in case it needs to get canceled */ | |
92 static timeout_id_t vhci_restart_timeid = 0; | |
93 | |
94 /* | |
95 * Bidirectional map of 'target-port' to port id <pid> for support of | |
96 * iostat(1M) '-Xx' and '-Yx' output. | |
97 */ | |
98 static kmutex_t vhci_targetmap_mutex; | |
99 static uint_t vhci_targetmap_pid = 1; | |
100 static mod_hash_t *vhci_targetmap_bypid; /* <pid> -> 'target-port' */ | |
101 static mod_hash_t *vhci_targetmap_byport; /* 'target-port' -> <pid> */ | |
102 | |
103 /* | |
104 * functions exported by scsi_vhci struct cb_ops | |
105 */ | |
106 static int vhci_open(dev_t *, int, int, cred_t *); | |
107 static int vhci_close(dev_t, int, int, cred_t *); | |
108 static int vhci_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); | |
109 | |
110 /* | |
111 * functions exported by scsi_vhci struct dev_ops | |
112 */ | |
113 static int vhci_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); | |
114 static int vhci_attach(dev_info_t *, ddi_attach_cmd_t); | |
115 static int vhci_detach(dev_info_t *, ddi_detach_cmd_t); | |
116 | |
117 /* | |
118 * functions exported by scsi_vhci scsi_hba_tran_t transport table | |
119 */ | |
120 static int vhci_scsi_tgt_init(dev_info_t *, dev_info_t *, | |
121 scsi_hba_tran_t *, struct scsi_device *); | |
122 static void vhci_scsi_tgt_free(dev_info_t *, dev_info_t *, scsi_hba_tran_t *, | |
123 struct scsi_device *); | |
124 static int vhci_pgr_register_start(scsi_vhci_lun_t *, struct scsi_pkt *); | |
125 static int vhci_scsi_start(struct scsi_address *, struct scsi_pkt *); | |
126 static int vhci_scsi_abort(struct scsi_address *, struct scsi_pkt *); | |
127 static int vhci_scsi_reset(struct scsi_address *, int); | |
128 static int vhci_scsi_reset_target(struct scsi_address *, int level, | |
129 uint8_t select_path); | |
130 static int vhci_scsi_reset_bus(struct scsi_address *); | |
131 static int vhci_scsi_getcap(struct scsi_address *, char *, int); | |
132 static int vhci_scsi_setcap(struct scsi_address *, char *, int, int); | |
133 static int vhci_commoncap(struct scsi_address *, char *, int, int, int); | |
134 static int vhci_pHCI_cap(struct scsi_address *ap, char *cap, int val, int whom, | |
135 mdi_pathinfo_t *pip); | |
136 static struct scsi_pkt *vhci_scsi_init_pkt(struct scsi_address *, | |
137 struct scsi_pkt *, struct buf *, int, int, int, int, int (*)(), caddr_t); | |
138 static void vhci_scsi_destroy_pkt(struct scsi_address *, struct scsi_pkt *); | |
139 static void vhci_scsi_dmafree(struct scsi_address *, struct scsi_pkt *); | |
140 static void vhci_scsi_sync_pkt(struct scsi_address *, struct scsi_pkt *); | |
141 static int vhci_scsi_reset_notify(struct scsi_address *, int, void (*)(caddr_t), | |
142 caddr_t); | |
143 static int vhci_scsi_get_bus_addr(struct scsi_device *, char *, int); | |
144 static int vhci_scsi_get_name(struct scsi_device *, char *, int); | |
145 static int vhci_scsi_bus_power(dev_info_t *, void *, pm_bus_power_op_t, | |
146 void *, void *); | |
147 static int vhci_scsi_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, | |
148 void *, dev_info_t **); | |
149 | |
150 /* | |
151 * functions registered with the mpxio framework via mdi_vhci_ops_t | |
152 */ | |
153 static int vhci_pathinfo_init(dev_info_t *, mdi_pathinfo_t *, int); | |
154 static int vhci_pathinfo_uninit(dev_info_t *, mdi_pathinfo_t *, int); | |
155 static int vhci_pathinfo_state_change(dev_info_t *, mdi_pathinfo_t *, | |
156 mdi_pathinfo_state_t, uint32_t, int); | |
157 static int vhci_pathinfo_online(dev_info_t *, mdi_pathinfo_t *, int); | |
158 static int vhci_pathinfo_offline(dev_info_t *, mdi_pathinfo_t *, int); | |
159 static int vhci_failover(dev_info_t *, dev_info_t *, int); | |
160 static void vhci_client_attached(dev_info_t *); | |
161 | |
162 static int vhci_ctl(dev_t, int, intptr_t, int, cred_t *, int *); | |
163 static int vhci_devctl(dev_t, int, intptr_t, int, cred_t *, int *); | |
164 static int vhci_ioc_get_phci_path(sv_iocdata_t *, caddr_t, int, caddr_t); | |
165 static int vhci_ioc_get_client_path(sv_iocdata_t *, caddr_t, int, caddr_t); | |
166 static int vhci_ioc_get_paddr(sv_iocdata_t *, caddr_t, int, caddr_t); | |
167 static int vhci_ioc_send_client_path(caddr_t, sv_iocdata_t *, int, caddr_t); | |
168 static void vhci_ioc_devi_to_path(dev_info_t *, caddr_t); | |
169 static int vhci_get_phci_path_list(dev_info_t *, sv_path_info_t *, uint_t); | |
170 static int vhci_get_client_path_list(dev_info_t *, sv_path_info_t *, uint_t); | |
171 static int vhci_get_iocdata(const void *, sv_iocdata_t *, int, caddr_t); | |
172 static int vhci_get_iocswitchdata(const void *, sv_switch_to_cntlr_iocdata_t *, | |
173 int, caddr_t); | |
174 static int vhci_ioc_alloc_pathinfo(sv_path_info_t **, sv_path_info_t **, | |
175 uint_t, sv_iocdata_t *, int, caddr_t); | |
176 static void vhci_ioc_free_pathinfo(sv_path_info_t *, sv_path_info_t *, uint_t); | |
177 static int vhci_ioc_send_pathinfo(sv_path_info_t *, sv_path_info_t *, uint_t, | |
178 sv_iocdata_t *, int, caddr_t); | |
179 static int vhci_handle_ext_fo(struct scsi_pkt *, int); | |
180 static int vhci_efo_watch_cb(caddr_t, struct scsi_watch_result *); | |
181 static int vhci_quiesce_lun(struct scsi_vhci_lun *); | |
182 static int vhci_pgr_validate_and_register(scsi_vhci_priv_t *); | |
183 static void vhci_dispatch_scsi_start(void *); | |
184 static void vhci_efo_done(void *); | |
185 static void vhci_initiate_auto_failback(void *); | |
186 static void vhci_update_pHCI_pkt(struct vhci_pkt *, struct scsi_pkt *); | |
187 static int vhci_update_pathinfo(struct scsi_device *, mdi_pathinfo_t *, | |
188 struct scsi_failover_ops *, scsi_vhci_lun_t *, struct scsi_vhci *); | |
189 static void vhci_kstat_create_pathinfo(mdi_pathinfo_t *); | |
190 static int vhci_quiesce_paths(dev_info_t *, dev_info_t *, | |
191 scsi_vhci_lun_t *, char *, char *); | |
192 | |
193 static char *vhci_devnm_to_guid(char *); | |
194 static int vhci_bind_transport(struct scsi_address *, struct vhci_pkt *, | |
195 int, int (*func)(caddr_t)); | |
196 static void vhci_intr(struct scsi_pkt *); | |
197 static int vhci_do_prout(scsi_vhci_priv_t *); | |
198 static void vhci_run_cmd(void *); | |
199 static int vhci_do_prin(struct vhci_pkt **); | |
200 static struct scsi_pkt *vhci_create_retry_pkt(struct vhci_pkt *); | |
201 static struct vhci_pkt *vhci_sync_retry_pkt(struct vhci_pkt *); | |
202 static struct scsi_vhci_lun *vhci_lun_lookup(dev_info_t *); | |
203 static struct scsi_vhci_lun *vhci_lun_lookup_alloc(dev_info_t *, char *, int *); | |
204 static void vhci_lun_free(dev_info_t *); | |
205 static int vhci_recovery_reset(scsi_vhci_lun_t *, struct scsi_address *, | |
206 uint8_t, uint8_t); | |
207 void vhci_update_pathstates(void *); | |
208 | |
209 #ifdef DEBUG | |
210 static void vhci_print_prin_keys(vhci_prin_readkeys_t *, int); | |
211 #endif | |
212 static void vhci_print_prout_keys(scsi_vhci_lun_t *, char *); | |
213 static void vhci_uscsi_iodone(struct scsi_pkt *pkt); | |
214 | |
215 /* | |
216 * MP-API related functions | |
217 */ | |
218 extern int vhci_mpapi_init(struct scsi_vhci *); | |
219 extern void vhci_mpapi_add_dev_prod(struct scsi_vhci *, char *); | |
220 extern int vhci_mpapi_ctl(dev_t, int, intptr_t, int, cred_t *, int *); | |
221 extern void vhci_update_mpapi_data(struct scsi_vhci *, | |
222 scsi_vhci_lun_t *, mdi_pathinfo_t *); | |
223 extern void* vhci_get_mpapi_item(struct scsi_vhci *, mpapi_list_header_t *, | |
224 uint8_t, void*); | |
225 extern void vhci_mpapi_set_path_state(dev_info_t *, mdi_pathinfo_t *, int); | |
226 extern int vhci_mpapi_update_tpg_acc_state_for_lu(struct scsi_vhci *, | |
227 scsi_vhci_lun_t *); | |
228 | |
229 /* Special export to MP-API of tpgs non-'fops' entry point */ | |
230 int (*tpgs_set_target_groups)(struct scsi_address *, int, int); | |
231 | |
232 #define VHCI_DMA_MAX_XFER_CAP 0xffffffffULL | |
233 | |
234 #define VHCI_MAX_PGR_RETRIES 3 | |
235 | |
236 /* | |
237 * Macros for the device-type mpxio options | |
238 */ | |
239 #define LOAD_BALANCE_OPTIONS "load-balance-options" | |
240 #define LOGICAL_BLOCK_REGION_SIZE "region-size" | |
241 #define MPXIO_OPTIONS_LIST "device-type-mpxio-options-list" | |
242 #define DEVICE_TYPE_STR "device-type" | |
243 #define isdigit(ch) ((ch) >= '0' && (ch) <= '9') | |
244 | |
245 static struct cb_ops vhci_cb_ops = { | |
246 vhci_open, /* open */ | |
247 vhci_close, /* close */ | |
248 nodev, /* strategy */ | |
249 nodev, /* print */ | |
250 nodev, /* dump */ | |
251 nodev, /* read */ | |
252 nodev, /* write */ | |
253 vhci_ioctl, /* ioctl */ | |
254 nodev, /* devmap */ | |
255 nodev, /* mmap */ | |
256 nodev, /* segmap */ | |
257 nochpoll, /* chpoll */ | |
258 ddi_prop_op, /* cb_prop_op */ | |
259 0, /* streamtab */ | |
260 D_NEW | D_MP, /* cb_flag */ | |
261 CB_REV, /* rev */ | |
262 nodev, /* aread */ | |
263 nodev /* awrite */ | |
264 }; | |
265 | |
266 static struct dev_ops vhci_ops = { | |
267 DEVO_REV, | |
268 0, | |
269 vhci_getinfo, | |
270 nulldev, /* identify */ | |
271 nulldev, /* probe */ | |
272 vhci_attach, /* attach and detach are mandatory */ | |
273 vhci_detach, | |
274 nodev, /* reset */ | |
275 &vhci_cb_ops, /* cb_ops */ | |
276 NULL, /* bus_ops */ | |
277 NULL, /* power */ | |
278 }; | |
279 | |
280 extern struct mod_ops mod_driverops; | |
281 | |
282 static struct modldrv modldrv = { | |
283 &mod_driverops, | |
284 vhci_version_name, /* module name */ | |
285 &vhci_ops | |
286 }; | |
287 | |
288 static struct modlinkage modlinkage = { | |
289 MODREV_1, | |
290 &modldrv, | |
291 NULL | |
292 }; | |
293 | |
294 static mdi_vhci_ops_t vhci_opinfo = { | |
295 MDI_VHCI_OPS_REV, | |
296 vhci_pathinfo_init, /* Pathinfo node init callback */ | |
297 vhci_pathinfo_uninit, /* Pathinfo uninit callback */ | |
298 vhci_pathinfo_state_change, /* Pathinfo node state change */ | |
299 vhci_failover, /* failover callback */ | |
300 vhci_client_attached /* client attached callback */ | |
301 }; | |
302 | |
303 /* | |
304 * The scsi_failover table defines an ordered set of 'fops' modules supported | |
305 * by scsi_vhci. Currently, initialize this table from the 'ddi-forceload' | |
306 * property specified in scsi_vhci.conf. | |
307 */ | |
308 struct scsi_failover { | |
309 ddi_modhandle_t sf_mod; | |
310 struct scsi_failover_ops *sf_sfo; | |
311 } *scsi_failover_table; | |
312 uint_t scsi_nfailover; | |
313 | |
314 int | |
315 _init(void) | |
316 { | |
317 int rval; | |
318 | |
319 /* | |
320 * Allocate soft state and prepare to do ddi_soft_state_zalloc() | |
321 * before registering with the transport first. | |
322 */ | |
323 if ((rval = ddi_soft_state_init(&vhci_softstate, | |
324 sizeof (struct scsi_vhci), 1)) != 0) { | |
325 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
326 "!_init:soft state init failed\n")); | |
327 return (rval); | |
328 } | |
329 | |
330 if ((rval = scsi_hba_init(&modlinkage)) != 0) { | |
331 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
332 "!_init: scsi hba init failed\n")); | |
333 ddi_soft_state_fini(&vhci_softstate); | |
334 return (rval); | |
335 } | |
336 | |
337 mutex_init(&vhci_global_mutex, NULL, MUTEX_DRIVER, NULL); | |
338 cv_init(&vhci_cv, NULL, CV_DRIVER, NULL); | |
339 | |
340 mutex_init(&vhci_targetmap_mutex, NULL, MUTEX_DRIVER, NULL); | |
341 vhci_targetmap_byport = mod_hash_create_strhash( | |
342 "vhci_targetmap_byport", 256, mod_hash_null_valdtor); | |
343 vhci_targetmap_bypid = mod_hash_create_idhash( | |
344 "vhci_targetmap_bypid", 256, mod_hash_null_valdtor); | |
345 | |
346 if ((rval = mod_install(&modlinkage)) != 0) { | |
347 VHCI_DEBUG(1, (CE_NOTE, NULL, "!_init: mod_install failed\n")); | |
348 if (vhci_targetmap_bypid) | |
349 mod_hash_destroy_idhash(vhci_targetmap_bypid); | |
350 if (vhci_targetmap_byport) | |
351 mod_hash_destroy_strhash(vhci_targetmap_byport); | |
352 mutex_destroy(&vhci_targetmap_mutex); | |
353 cv_destroy(&vhci_cv); | |
354 mutex_destroy(&vhci_global_mutex); | |
355 scsi_hba_fini(&modlinkage); | |
356 ddi_soft_state_fini(&vhci_softstate); | |
357 } | |
358 return (rval); | |
359 } | |
360 | |
361 | |
362 /* | |
363 * the system is done with us as a driver, so clean up | |
364 */ | |
365 int | |
366 _fini(void) | |
367 { | |
368 int rval; | |
369 | |
370 /* | |
371 * don't start cleaning up until we know that the module remove | |
372 * has worked -- if this works, then we know that each instance | |
373 * has successfully been DDI_DETACHed | |
374 */ | |
375 if ((rval = mod_remove(&modlinkage)) != 0) { | |
376 VHCI_DEBUG(4, (CE_NOTE, NULL, "!_fini: mod_remove failed\n")); | |
377 return (rval); | |
378 } | |
379 | |
380 if (vhci_targetmap_bypid) | |
381 mod_hash_destroy_idhash(vhci_targetmap_bypid); | |
382 if (vhci_targetmap_byport) | |
383 mod_hash_destroy_strhash(vhci_targetmap_byport); | |
384 mutex_destroy(&vhci_targetmap_mutex); | |
385 cv_destroy(&vhci_cv); | |
386 mutex_destroy(&vhci_global_mutex); | |
387 scsi_hba_fini(&modlinkage); | |
388 ddi_soft_state_fini(&vhci_softstate); | |
389 | |
390 return (rval); | |
391 } | |
392 | |
393 int | |
394 _info(struct modinfo *modinfop) | |
395 { | |
396 return (mod_info(&modlinkage, modinfop)); | |
397 } | |
398 | |
399 /* | |
400 * Lookup scsi_failover by "short name" of failover module. | |
401 */ | |
402 struct scsi_failover_ops * | |
403 vhci_failover_ops_by_name(char *name) | |
404 { | |
405 struct scsi_failover *sf; | |
406 | |
407 for (sf = scsi_failover_table; sf->sf_mod; sf++) { | |
408 if (sf->sf_sfo == NULL) | |
409 continue; | |
410 if (strcmp(sf->sf_sfo->sfo_name, name) == 0) | |
411 return (sf->sf_sfo); | |
412 } | |
413 return (NULL); | |
414 } | |
415 | |
416 /* | |
417 * Load all scsi_failover_ops 'fops' modules. | |
418 */ | |
419 static void | |
420 vhci_failover_modopen(struct scsi_vhci *vhci) | |
421 { | |
422 char **module; | |
423 int i; | |
424 struct scsi_failover *sf; | |
425 char **dt; | |
426 int e; | |
427 | |
428 if (scsi_failover_table) | |
429 return; | |
430 | |
431 /* Get the list of modules from scsi_vhci.conf */ | |
432 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, | |
433 vhci->vhci_dip, DDI_PROP_DONTPASS, "ddi-forceload", | |
434 &module, &scsi_nfailover) != DDI_PROP_SUCCESS) { | |
435 cmn_err(CE_WARN, "scsi_vhci: " | |
436 "scsi_vhci.conf is missing 'ddi-forceload'"); | |
437 return; | |
438 } | |
439 if (scsi_nfailover == 0) { | |
440 cmn_err(CE_WARN, "scsi_vhci: " | |
441 "scsi_vhci.conf has empty 'ddi-forceload'"); | |
4949
f3b9c8c61dbe
6594740 vhci_failover_modopen leaks "ddi-forceload" property
cth
parents:
4896
diff
changeset
|
442 ddi_prop_free(module); |
4851 | 443 return; |
444 } | |
445 | |
446 /* allocate failover table based on number of modules */ | |
447 scsi_failover_table = (struct scsi_failover *) | |
448 kmem_zalloc(sizeof (struct scsi_failover) * (scsi_nfailover + 1), | |
449 KM_SLEEP); | |
450 | |
451 /* loop over modules specified in scsi_vhci.conf and open each module */ | |
452 for (i = 0, sf = scsi_failover_table; i < scsi_nfailover; i++) { | |
453 if (module[i] == NULL) | |
454 continue; | |
455 | |
456 sf->sf_mod = ddi_modopen(module[i], KRTLD_MODE_FIRST, &e); | |
457 if (sf->sf_mod == NULL) { | |
458 /* | |
459 * A module returns EEXIST if other software is | |
460 * supporting the intended function: for example | |
461 * the scsi_vhci_f_sum_emc module returns EEXIST | |
462 * from _init if EMC powerpath software is installed. | |
463 */ | |
464 if (e != EEXIST) | |
465 cmn_err(CE_WARN, "scsi_vhci: unable to open " | |
466 "module '%s', error %d", module[i], e); | |
467 continue; | |
468 } | |
469 sf->sf_sfo = ddi_modsym(sf->sf_mod, | |
470 "scsi_vhci_failover_ops", &e); | |
471 if (sf->sf_sfo == NULL) { | |
472 cmn_err(CE_WARN, "scsi_vhci: " | |
473 "unable to import 'scsi_failover_ops' from '%s', " | |
474 "error %d", module[i], e); | |
475 (void) ddi_modclose(sf->sf_mod); | |
476 sf->sf_mod = NULL; | |
477 continue; | |
478 } | |
479 | |
480 /* register vid/pid of devices supported with mpapi */ | |
481 for (dt = sf->sf_sfo->sfo_devices; *dt; dt++) | |
482 vhci_mpapi_add_dev_prod(vhci, *dt); | |
483 | |
484 /* | |
485 * Special processing for SFO_NAME_TPGS module, which contains | |
486 * the `tpgs_set_target_groups` implementation needed by the | |
487 * MP-API code. | |
488 */ | |
489 if (strcmp(sf->sf_sfo->sfo_name, SFO_NAME_TPGS) == 0) { | |
490 tpgs_set_target_groups = | |
491 (int (*)(struct scsi_address *, int, int)) | |
492 ddi_modsym(sf->sf_mod, "std_set_target_groups", &e); | |
493 if (tpgs_set_target_groups == NULL) { | |
494 cmn_err(CE_WARN, "scsi_vhci: " | |
495 "unable to import 'std_set_target_groups' " | |
496 "from '%s', error %d", module[i], e); | |
497 } | |
498 } | |
499 | |
500 sf++; | |
501 } | |
502 | |
503 /* verify that at least the "well-known" modules were there */ | |
504 if (vhci_failover_ops_by_name(SFO_NAME_SYM) == NULL) | |
505 cmn_err(CE_WARN, "scsi_vhci: well-known module \"" | |
506 SFO_NAME_SYM "\" not defined in scsi_vhci.conf's " | |
507 "'ddi-forceload'"); | |
508 if (vhci_failover_ops_by_name(SFO_NAME_TPGS) == NULL) | |
509 cmn_err(CE_WARN, "scsi_vhci: well-known module \"" | |
510 SFO_NAME_TPGS "\" not defined in scsi_vhci.conf's " | |
511 "'ddi-forceload'"); | |
512 | |
513 /* call sfo_init for modules that need it */ | |
514 for (sf = scsi_failover_table; sf->sf_mod; sf++) { | |
515 if (sf->sf_sfo && sf->sf_sfo->sfo_init) | |
516 (*sf->sf_sfo->sfo_init)(); | |
517 } | |
4949
f3b9c8c61dbe
6594740 vhci_failover_modopen leaks "ddi-forceload" property
cth
parents:
4896
diff
changeset
|
518 |
f3b9c8c61dbe
6594740 vhci_failover_modopen leaks "ddi-forceload" property
cth
parents:
4896
diff
changeset
|
519 ddi_prop_free(module); |
4851 | 520 } |
521 | |
522 /* | |
523 * unload all loaded scsi_failover_ops modules | |
524 */ | |
525 static void | |
526 vhci_failover_modclose() | |
527 { | |
528 struct scsi_failover *sf; | |
529 | |
530 for (sf = scsi_failover_table; sf->sf_mod; sf++) { | |
531 if ((sf->sf_mod == NULL) || (sf->sf_sfo == NULL)) | |
532 continue; | |
533 (void) ddi_modclose(sf->sf_mod); | |
534 sf->sf_mod = NULL; | |
535 sf->sf_sfo = NULL; | |
536 } | |
537 | |
538 if (scsi_failover_table && scsi_nfailover) | |
539 kmem_free(scsi_failover_table, | |
540 sizeof (struct scsi_failover) * (scsi_nfailover + 1)); | |
541 scsi_failover_table = NULL; | |
542 scsi_nfailover = 0; | |
543 } | |
544 | |
545 /* ARGSUSED */ | |
546 static int | |
547 vhci_open(dev_t *devp, int flag, int otype, cred_t *credp) | |
548 { | |
549 struct scsi_vhci *vhci; | |
550 | |
551 if (otype != OTYP_CHR) { | |
552 return (EINVAL); | |
553 } | |
554 | |
555 vhci = ddi_get_soft_state(vhci_softstate, MINOR2INST(getminor(*devp))); | |
556 if (vhci == NULL) { | |
557 VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_open: failed ENXIO\n")); | |
558 return (ENXIO); | |
559 } | |
560 | |
561 mutex_enter(&vhci->vhci_mutex); | |
562 if ((flag & FEXCL) && (vhci->vhci_state & VHCI_STATE_OPEN)) { | |
563 mutex_exit(&vhci->vhci_mutex); | |
564 vhci_log(CE_NOTE, vhci->vhci_dip, | |
565 "!vhci%d: Already open\n", getminor(*devp)); | |
566 return (EBUSY); | |
567 } | |
568 | |
569 vhci->vhci_state |= VHCI_STATE_OPEN; | |
570 mutex_exit(&vhci->vhci_mutex); | |
571 return (0); | |
572 } | |
573 | |
574 | |
575 /* ARGSUSED */ | |
576 static int | |
577 vhci_close(dev_t dev, int flag, int otype, cred_t *credp) | |
578 { | |
579 struct scsi_vhci *vhci; | |
580 | |
581 if (otype != OTYP_CHR) { | |
582 return (EINVAL); | |
583 } | |
584 | |
585 vhci = ddi_get_soft_state(vhci_softstate, MINOR2INST(getminor(dev))); | |
586 if (vhci == NULL) { | |
587 VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_close: failed ENXIO\n")); | |
588 return (ENXIO); | |
589 } | |
590 | |
591 mutex_enter(&vhci->vhci_mutex); | |
592 vhci->vhci_state &= ~VHCI_STATE_OPEN; | |
593 mutex_exit(&vhci->vhci_mutex); | |
594 | |
595 return (0); | |
596 } | |
597 | |
598 /* ARGSUSED */ | |
599 static int | |
600 vhci_ioctl(dev_t dev, int cmd, intptr_t data, int mode, | |
601 cred_t *credp, int *rval) | |
602 { | |
603 if (IS_DEVCTL(cmd)) { | |
604 return (vhci_devctl(dev, cmd, data, mode, credp, rval)); | |
605 } else if (cmd == MP_CMD) { | |
606 return (vhci_mpapi_ctl(dev, cmd, data, mode, credp, rval)); | |
607 } else { | |
608 return (vhci_ctl(dev, cmd, data, mode, credp, rval)); | |
609 } | |
610 } | |
611 | |
612 /* | |
613 * attach the module | |
614 */ | |
615 static int | |
616 vhci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) | |
617 { | |
618 int rval = DDI_FAILURE; | |
619 int scsi_hba_attached = 0; | |
620 int vhci_attached = 0; | |
621 int mutex_initted = 0; | |
622 int instance; | |
623 struct scsi_vhci *vhci; | |
624 scsi_hba_tran_t *tran; | |
625 char cache_name_buf[64]; | |
626 char *data; | |
627 | |
628 VHCI_DEBUG(4, (CE_NOTE, NULL, "vhci_attach: cmd=0x%x\n", cmd)); | |
629 | |
630 instance = ddi_get_instance(dip); | |
631 | |
632 switch (cmd) { | |
633 case DDI_ATTACH: | |
634 break; | |
635 | |
636 case DDI_RESUME: | |
637 case DDI_PM_RESUME: | |
638 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_attach: resume not yet" | |
639 "implemented\n")); | |
640 return (rval); | |
641 | |
642 default: | |
643 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
644 "!vhci_attach: unknown ddi command\n")); | |
645 return (rval); | |
646 } | |
647 | |
648 /* | |
649 * Allocate vhci data structure. | |
650 */ | |
651 if (ddi_soft_state_zalloc(vhci_softstate, instance) != DDI_SUCCESS) { | |
652 VHCI_DEBUG(1, (CE_NOTE, dip, "!vhci_attach:" | |
653 "soft state alloc failed\n")); | |
654 return (DDI_FAILURE); | |
655 } | |
656 | |
657 if ((vhci = ddi_get_soft_state(vhci_softstate, instance)) == NULL) { | |
658 VHCI_DEBUG(1, (CE_NOTE, dip, "!vhci_attach:" | |
659 "bad soft state\n")); | |
660 ddi_soft_state_free(vhci_softstate, instance); | |
661 return (DDI_FAILURE); | |
662 } | |
663 | |
664 /* Allocate packet cache */ | |
665 (void) snprintf(cache_name_buf, sizeof (cache_name_buf), | |
666 "vhci%d_cache", instance); | |
667 | |
668 mutex_init(&vhci->vhci_mutex, NULL, MUTEX_DRIVER, NULL); | |
669 mutex_initted++; | |
670 | |
671 /* | |
672 * Allocate a transport structure | |
673 */ | |
674 tran = scsi_hba_tran_alloc(dip, SCSI_HBA_CANSLEEP); | |
675 ASSERT(tran != NULL); | |
676 | |
677 vhci->vhci_tran = tran; | |
678 vhci->vhci_dip = dip; | |
679 vhci->vhci_instance = instance; | |
680 | |
681 tran->tran_hba_private = vhci; | |
682 tran->tran_tgt_private = NULL; | |
683 tran->tran_tgt_init = vhci_scsi_tgt_init; | |
684 tran->tran_tgt_probe = NULL; | |
685 tran->tran_tgt_free = vhci_scsi_tgt_free; | |
686 | |
687 tran->tran_start = vhci_scsi_start; | |
688 tran->tran_abort = vhci_scsi_abort; | |
689 tran->tran_reset = vhci_scsi_reset; | |
690 tran->tran_getcap = vhci_scsi_getcap; | |
691 tran->tran_setcap = vhci_scsi_setcap; | |
692 tran->tran_init_pkt = vhci_scsi_init_pkt; | |
693 tran->tran_destroy_pkt = vhci_scsi_destroy_pkt; | |
694 tran->tran_dmafree = vhci_scsi_dmafree; | |
695 tran->tran_sync_pkt = vhci_scsi_sync_pkt; | |
696 tran->tran_reset_notify = vhci_scsi_reset_notify; | |
697 | |
698 tran->tran_get_bus_addr = vhci_scsi_get_bus_addr; | |
699 tran->tran_get_name = vhci_scsi_get_name; | |
700 tran->tran_bus_reset = NULL; | |
701 tran->tran_quiesce = NULL; | |
702 tran->tran_unquiesce = NULL; | |
703 | |
704 /* | |
705 * register event notification routines with scsa | |
706 */ | |
707 tran->tran_get_eventcookie = NULL; | |
708 tran->tran_add_eventcall = NULL; | |
709 tran->tran_remove_eventcall = NULL; | |
710 tran->tran_post_event = NULL; | |
711 | |
712 tran->tran_bus_power = vhci_scsi_bus_power; | |
713 | |
714 tran->tran_bus_config = vhci_scsi_bus_config; | |
715 | |
716 /* | |
717 * Attach this instance with the mpxio framework | |
718 */ | |
719 if (mdi_vhci_register(MDI_HCI_CLASS_SCSI, dip, &vhci_opinfo, 0) | |
720 != MDI_SUCCESS) { | |
721 VHCI_DEBUG(1, (CE_NOTE, dip, "!vhci_attach:" | |
722 "mdi_vhci_register failed\n")); | |
723 goto attach_fail; | |
724 } | |
725 vhci_attached++; | |
726 | |
727 /* | |
728 * Attach this instance of the hba. | |
729 * | |
730 * Regarding dma attributes: Since scsi_vhci is a virtual scsi HBA | |
731 * driver, it has nothing to do with DMA. However, when calling | |
732 * scsi_hba_attach_setup() we need to pass something valid in the | |
733 * dma attributes parameter. So we just use scsi_alloc_attr. | |
734 * SCSA itself seems to care only for dma_attr_minxfer and | |
735 * dma_attr_burstsizes fields of dma attributes structure. | |
736 * It expects those fileds to be non-zero. | |
737 */ | |
738 if (scsi_hba_attach_setup(dip, &scsi_alloc_attr, tran, | |
739 SCSI_HBA_TRAN_CLONE) != DDI_SUCCESS) { | |
740 VHCI_DEBUG(1, (CE_NOTE, dip, "!vhci_attach:" | |
741 "hba attach failed\n")); | |
742 goto attach_fail; | |
743 } | |
744 scsi_hba_attached++; | |
745 | |
746 if (ddi_create_minor_node(dip, "devctl", S_IFCHR, | |
747 INST2DEVCTL(instance), DDI_NT_SCSI_NEXUS, 0) != DDI_SUCCESS) { | |
748 VHCI_DEBUG(1, (CE_NOTE, dip, "!vhci_attach:" | |
749 " ddi_create_minor_node failed\n")); | |
750 goto attach_fail; | |
751 } | |
752 | |
753 /* | |
754 * Set pm-want-child-notification property for | |
755 * power management of the phci and client | |
756 */ | |
757 if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, | |
758 "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { | |
759 cmn_err(CE_WARN, | |
760 "%s%d fail to create pm-want-child-notification? prop", | |
761 ddi_driver_name(dip), ddi_get_instance(dip)); | |
762 goto attach_fail; | |
763 } | |
764 | |
765 vhci->vhci_taskq = taskq_create("vhci_taskq", 1, MINCLSYSPRI, 1, 4, 0); | |
766 vhci->vhci_update_pathstates_taskq = | |
767 taskq_create("vhci_update_pathstates", VHCI_NUM_UPDATE_TASKQ, | |
768 MINCLSYSPRI, 1, 4, 0); | |
769 ASSERT(vhci->vhci_taskq); | |
770 ASSERT(vhci->vhci_update_pathstates_taskq); | |
771 | |
772 /* | |
773 * Set appropriate configuration flags based on options set in | |
774 * conf file. | |
775 */ | |
776 vhci->vhci_conf_flags = 0; | |
777 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, PROPFLAGS, | |
778 "auto-failback", &data) == DDI_SUCCESS) { | |
779 if (strcmp(data, "enable") == 0) | |
780 vhci->vhci_conf_flags |= VHCI_CONF_FLAGS_AUTO_FAILBACK; | |
781 ddi_prop_free(data); | |
782 } | |
783 | |
784 if (!(vhci->vhci_conf_flags & VHCI_CONF_FLAGS_AUTO_FAILBACK)) | |
785 vhci_log(CE_NOTE, dip, "!Auto-failback capability " | |
786 "disabled through scsi_vhci.conf file."); | |
787 | |
788 /* | |
789 * Allocate an mpapi private structure | |
790 */ | |
791 vhci->mp_priv = kmem_zalloc(sizeof (mpapi_priv_t), KM_SLEEP); | |
792 if (vhci_mpapi_init(vhci) != 0) { | |
793 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_attach: " | |
794 "vhci_mpapi_init() failed")); | |
795 } | |
796 | |
797 vhci_failover_modopen(vhci); /* load failover modules */ | |
798 | |
799 ddi_report_dev(dip); | |
800 return (DDI_SUCCESS); | |
801 | |
802 attach_fail: | |
803 if (vhci_attached) | |
804 (void) mdi_vhci_unregister(dip, 0); | |
805 | |
806 if (scsi_hba_attached) | |
807 (void) scsi_hba_detach(dip); | |
808 | |
809 if (vhci->vhci_tran) | |
810 scsi_hba_tran_free(vhci->vhci_tran); | |
811 | |
812 if (mutex_initted) { | |
813 mutex_destroy(&vhci->vhci_mutex); | |
814 } | |
815 | |
816 ddi_soft_state_free(vhci_softstate, instance); | |
817 return (DDI_FAILURE); | |
818 } | |
819 | |
820 | |
821 /*ARGSUSED*/ | |
822 static int | |
823 vhci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) | |
824 { | |
825 int instance = ddi_get_instance(dip); | |
826 scsi_hba_tran_t *tran; | |
827 struct scsi_vhci *vhci; | |
828 | |
829 VHCI_DEBUG(4, (CE_NOTE, NULL, "vhci_detach: cmd=0x%x\n", cmd)); | |
830 | |
831 if ((tran = ddi_get_driver_private(dip)) == NULL) | |
832 return (DDI_FAILURE); | |
833 | |
834 vhci = TRAN2HBAPRIVATE(tran); | |
835 if (!vhci) { | |
836 return (DDI_FAILURE); | |
837 } | |
838 | |
839 switch (cmd) { | |
840 case DDI_DETACH: | |
841 break; | |
842 | |
843 case DDI_SUSPEND: | |
844 case DDI_PM_SUSPEND: | |
845 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_detach: suspend/pm not yet" | |
846 "implemented\n")); | |
847 return (DDI_FAILURE); | |
848 | |
849 default: | |
850 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
851 "!vhci_detach: unknown ddi command\n")); | |
852 return (DDI_FAILURE); | |
853 } | |
854 | |
855 (void) mdi_vhci_unregister(dip, 0); | |
856 (void) scsi_hba_detach(dip); | |
857 scsi_hba_tran_free(tran); | |
858 | |
859 if (ddi_prop_remove(DDI_DEV_T_NONE, dip, | |
860 "pm-want-child-notification?") != DDI_PROP_SUCCESS) { | |
861 cmn_err(CE_WARN, | |
862 "%s%d unable to remove prop pm-want_child_notification?", | |
863 ddi_driver_name(dip), ddi_get_instance(dip)); | |
864 } | |
865 if (vhci_restart_timeid != 0) { | |
866 (void) untimeout(vhci_restart_timeid); | |
867 } | |
868 vhci_restart_timeid = 0; | |
869 | |
870 mutex_destroy(&vhci->vhci_mutex); | |
871 vhci->vhci_dip = NULL; | |
872 vhci->vhci_tran = NULL; | |
873 taskq_destroy(vhci->vhci_taskq); | |
874 taskq_destroy(vhci->vhci_update_pathstates_taskq); | |
875 ddi_remove_minor_node(dip, NULL); | |
876 ddi_soft_state_free(vhci_softstate, instance); | |
877 | |
878 vhci_failover_modclose(); /* unload failover modules */ | |
879 return (DDI_SUCCESS); | |
880 } | |
881 | |
882 /* | |
883 * vhci_getinfo() | |
884 * Given the device number, return the devinfo pointer or the | |
885 * instance number. | |
886 * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. | |
887 */ | |
888 | |
889 /*ARGSUSED*/ | |
890 static int | |
891 vhci_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) | |
892 { | |
893 struct scsi_vhci *vhcip; | |
894 int instance = MINOR2INST(getminor((dev_t)arg)); | |
895 | |
896 switch (cmd) { | |
897 case DDI_INFO_DEVT2DEVINFO: | |
898 vhcip = ddi_get_soft_state(vhci_softstate, instance); | |
899 if (vhcip != NULL) | |
900 *result = vhcip->vhci_dip; | |
901 else { | |
902 *result = NULL; | |
903 return (DDI_FAILURE); | |
904 } | |
905 break; | |
906 | |
907 case DDI_INFO_DEVT2INSTANCE: | |
908 *result = (void *)(uintptr_t)instance; | |
909 break; | |
910 | |
911 default: | |
912 return (DDI_FAILURE); | |
913 } | |
914 | |
915 return (DDI_SUCCESS); | |
916 } | |
917 | |
918 | |
919 /*ARGSUSED*/ | |
920 static int | |
921 vhci_scsi_tgt_init(dev_info_t *hba_dip, dev_info_t *tgt_dip, | |
922 scsi_hba_tran_t *hba_tran, struct scsi_device *sd) | |
923 { | |
924 char *guid; | |
925 scsi_vhci_lun_t *vlun; | |
926 struct scsi_vhci *vhci; | |
927 clock_t from_ticks; | |
928 mdi_pathinfo_t *pip; | |
929 int rval; | |
930 | |
931 ASSERT(hba_dip != NULL); | |
932 ASSERT(tgt_dip != NULL); | |
933 | |
934 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(hba_dip)); | |
935 ASSERT(vhci != NULL); | |
936 | |
937 VHCI_DEBUG(4, (CE_NOTE, hba_dip, | |
938 "!tgt_init: called for %s (instance %d)\n", | |
939 ddi_driver_name(tgt_dip), ddi_get_instance(tgt_dip))); | |
940 | |
941 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, tgt_dip, PROPFLAGS, | |
942 MDI_CLIENT_GUID_PROP, &guid) != DDI_SUCCESS) { | |
943 /* | |
944 * This must be the .conf node. The ssd node under | |
945 * fp already inserts a delay, so we just return from here. | |
946 * We rely on this delay to have all dips be posted to | |
947 * the ndi hotplug thread's newdev list. This is | |
948 * necessary for the deferred attach mechanism to work | |
949 * and opens() done soon after boot to succeed. | |
950 */ | |
951 VHCI_DEBUG(4, (CE_WARN, hba_dip, "tgt_init: lun guid " | |
952 "property failed")); | |
953 return (DDI_NOT_WELL_FORMED); | |
954 } | |
955 | |
956 vlun = vhci_lun_lookup(tgt_dip); | |
957 | |
958 mutex_enter(&vhci_global_mutex); | |
959 | |
960 from_ticks = ddi_get_lbolt(); | |
961 if (vhci_to_ticks == 0) { | |
962 vhci_to_ticks = from_ticks + | |
963 drv_usectohz(vhci_init_wait_timeout); | |
964 } | |
965 | |
966 #if DEBUG | |
967 if (vlun) { | |
968 VHCI_DEBUG(1, (CE_WARN, hba_dip, "tgt_init: " | |
969 "vhci_scsi_tgt_init: guid %s : found vlun 0x%p " | |
970 "from_ticks %lx to_ticks %lx", | |
971 guid, (void *)vlun, from_ticks, vhci_to_ticks)); | |
972 } else { | |
973 VHCI_DEBUG(1, (CE_WARN, hba_dip, "tgt_init: " | |
974 "vhci_scsi_tgt_init: guid %s : vlun not found " | |
975 "from_ticks %lx to_ticks %lx", guid, from_ticks, | |
976 vhci_to_ticks)); | |
977 } | |
978 #endif | |
979 | |
980 rval = mdi_select_path(tgt_dip, NULL, | |
981 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), NULL, &pip); | |
982 if (rval == MDI_SUCCESS) { | |
983 mdi_rele_path(pip); | |
984 } | |
985 | |
986 /* | |
987 * Wait for the following conditions : | |
988 * 1. no vlun available yet | |
989 * 2. no path established | |
990 * 3. timer did not expire | |
991 */ | |
992 while ((vlun == NULL) || (mdi_client_get_path_count(tgt_dip) == 0) || | |
993 (rval != MDI_SUCCESS)) { | |
994 if (vlun && vlun->svl_not_supported) { | |
995 VHCI_DEBUG(1, (CE_WARN, hba_dip, "tgt_init: " | |
996 "vlun 0x%p lun guid %s not supported!", | |
997 (void *)vlun, guid)); | |
998 mutex_exit(&vhci_global_mutex); | |
999 ddi_prop_free(guid); | |
1000 return (DDI_NOT_WELL_FORMED); | |
1001 } | |
1002 if ((vhci_first_time == 0) && (from_ticks >= vhci_to_ticks)) { | |
1003 vhci_first_time = 1; | |
1004 } | |
1005 if (vhci_first_time == 1) { | |
1006 VHCI_DEBUG(1, (CE_WARN, hba_dip, "vhci_scsi_tgt_init: " | |
1007 "no wait for %s. from_tick %lx, to_tick %lx", | |
1008 guid, from_ticks, vhci_to_ticks)); | |
1009 mutex_exit(&vhci_global_mutex); | |
1010 ddi_prop_free(guid); | |
1011 return (DDI_NOT_WELL_FORMED); | |
1012 } | |
1013 | |
1014 if (cv_timedwait(&vhci_cv, | |
1015 &vhci_global_mutex, vhci_to_ticks) == -1) { | |
1016 /* Timed out */ | |
1017 #ifdef DEBUG | |
1018 if (vlun == NULL) { | |
1019 VHCI_DEBUG(1, (CE_WARN, hba_dip, | |
1020 "tgt_init: no vlun for %s!", guid)); | |
1021 } else if (mdi_client_get_path_count(tgt_dip) == 0) { | |
1022 VHCI_DEBUG(1, (CE_WARN, hba_dip, | |
1023 "tgt_init: client path count is " | |
1024 "zero for %s!", guid)); | |
1025 } else { | |
1026 VHCI_DEBUG(1, (CE_WARN, hba_dip, | |
1027 "tgt_init: client path not " | |
1028 "available yet for %s!", guid)); | |
1029 } | |
1030 #endif /* DEBUG */ | |
1031 mutex_exit(&vhci_global_mutex); | |
1032 ddi_prop_free(guid); | |
1033 return (DDI_NOT_WELL_FORMED); | |
1034 } | |
1035 vlun = vhci_lun_lookup(tgt_dip); | |
1036 rval = mdi_select_path(tgt_dip, NULL, | |
1037 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
1038 NULL, &pip); | |
1039 if (rval == MDI_SUCCESS) { | |
1040 mdi_rele_path(pip); | |
1041 } | |
1042 from_ticks = ddi_get_lbolt(); | |
1043 } | |
1044 mutex_exit(&vhci_global_mutex); | |
1045 | |
1046 ASSERT(vlun != NULL); | |
1047 ddi_prop_free(guid); | |
1048 hba_tran->tran_tgt_private = vlun; | |
1049 | |
1050 return (DDI_SUCCESS); | |
1051 } | |
1052 | |
1053 /*ARGSUSED*/ | |
1054 static void | |
1055 vhci_scsi_tgt_free(dev_info_t *hba_dip, dev_info_t *tgt_dip, | |
1056 scsi_hba_tran_t *hba_tran, struct scsi_device *sd) | |
1057 { | |
1058 } | |
1059 | |
1060 /* | |
1061 * a PGR register command has started; copy the info we need | |
1062 */ | |
1063 int | |
1064 vhci_pgr_register_start(scsi_vhci_lun_t *vlun, struct scsi_pkt *pkt) | |
1065 { | |
1066 struct vhci_pkt *vpkt = TGTPKT2VHCIPKT(pkt); | |
1067 void *addr; | |
1068 | |
1069 if (!vpkt->vpkt_tgt_init_bp) | |
1070 return (TRAN_BADPKT); | |
1071 | |
1072 addr = bp_mapin_common(vpkt->vpkt_tgt_init_bp, | |
1073 (vpkt->vpkt_flags & CFLAG_NOWAIT) ? VM_NOSLEEP : VM_SLEEP); | |
1074 if (addr == NULL) | |
1075 return (TRAN_BUSY); | |
1076 | |
1077 mutex_enter(&vlun->svl_mutex); | |
1078 | |
1079 vhci_print_prout_keys(vlun, "v_pgr_reg_start: before bcopy:"); | |
1080 | |
1081 bcopy(addr, &vlun->svl_prout, sizeof (vhci_prout_t) - | |
1082 (2 * MHIOC_RESV_KEY_SIZE*sizeof (char))); | |
1083 bcopy(pkt->pkt_cdbp, vlun->svl_cdb, sizeof (vlun->svl_cdb)); | |
1084 | |
1085 vhci_print_prout_keys(vlun, "v_pgr_reg_start: after bcopy:"); | |
1086 | |
1087 vlun->svl_time = pkt->pkt_time; | |
1088 vlun->svl_bcount = vpkt->vpkt_tgt_init_bp->b_bcount; | |
1089 vlun->svl_first_path = vpkt->vpkt_path; | |
1090 mutex_exit(&vlun->svl_mutex); | |
1091 return (0); | |
1092 } | |
1093 | |
1094 /* | |
1095 * Function name : vhci_scsi_start() | |
1096 * | |
1097 * Return Values : TRAN_FATAL_ERROR - vhci has been shutdown | |
1098 * or other fatal failure | |
1099 * preventing packet transportation | |
1100 * TRAN_BUSY - request queue is full | |
1101 * TRAN_ACCEPT - pkt has been submitted to phci | |
1102 * (or is held in the waitQ) | |
1103 * Description : Implements SCSA's tran_start() entry point for | |
1104 * packet transport | |
1105 * | |
1106 */ | |
1107 static int | |
1108 vhci_scsi_start(struct scsi_address *ap, struct scsi_pkt *pkt) | |
1109 { | |
1110 int rval = TRAN_ACCEPT; | |
1111 int instance, held; | |
1112 struct scsi_vhci *vhci = ADDR2VHCI(ap); | |
1113 struct scsi_vhci_lun *vlun = ADDR2VLUN(ap); | |
1114 struct vhci_pkt *vpkt = TGTPKT2VHCIPKT(pkt); | |
1115 int flags = 0; | |
1116 scsi_vhci_priv_t *svp; | |
1117 dev_info_t *cdip; | |
1118 client_lb_t lbp; | |
1119 int restore_lbp = 0; | |
1120 /* set if pkt is SCSI-II RESERVE cmd */ | |
1121 int pkt_reserve_cmd = 0; | |
1122 int reserve_failed = 0; | |
1123 | |
1124 ASSERT(vhci != NULL); | |
1125 ASSERT(vpkt != NULL); | |
1126 ASSERT(vpkt->vpkt_state != VHCI_PKT_ISSUED); | |
1127 cdip = ADDR2DIP(ap); | |
1128 | |
1129 /* | |
1130 * Block IOs if LUN is held or QUIESCED for IOs. | |
1131 */ | |
1132 if ((VHCI_LUN_IS_HELD(vlun)) || | |
1133 ((vlun->svl_flags & VLUN_QUIESCED_FLG) == VLUN_QUIESCED_FLG)) { | |
1134 return (TRAN_BUSY); | |
1135 } | |
1136 | |
1137 /* | |
1138 * vhci_lun needs to be quiesced before SCSI-II RESERVE command | |
1139 * can be issued. This may require a cv_timedwait, which is | |
1140 * dangerous to perform in an interrupt context. So if this | |
1141 * is a RESERVE command a taskq is dispatched to service it. | |
1142 * This taskq shall again call vhci_scsi_start, but we shall be | |
1143 * sure its not in an interrupt context. | |
1144 */ | |
1145 if ((pkt->pkt_cdbp[0] == SCMD_RESERVE) || | |
1146 (pkt->pkt_cdbp[0] == SCMD_RESERVE_G1)) { | |
1147 if (!(vpkt->vpkt_state & VHCI_PKT_THRU_TASKQ)) { | |
1148 if (taskq_dispatch(vhci->vhci_taskq, | |
1149 vhci_dispatch_scsi_start, (void *) vpkt, | |
1150 KM_NOSLEEP)) { | |
1151 return (TRAN_ACCEPT); | |
1152 } else { | |
1153 return (TRAN_BUSY); | |
1154 } | |
1155 } | |
1156 | |
1157 /* | |
1158 * Here we ensure that simultaneous SCSI-II RESERVE cmds don't | |
1159 * get serviced for a lun. | |
1160 */ | |
1161 VHCI_HOLD_LUN(vlun, VH_NOSLEEP, held); | |
1162 if (!held) { | |
1163 return (TRAN_BUSY); | |
1164 } else if ((vlun->svl_flags & VLUN_QUIESCED_FLG) == | |
1165 VLUN_QUIESCED_FLG) { | |
1166 VHCI_RELEASE_LUN(vlun); | |
1167 return (TRAN_BUSY); | |
1168 } | |
1169 | |
1170 /* | |
1171 * To ensure that no IOs occur for this LUN for the duration | |
1172 * of this pkt set the VLUN_QUIESCED_FLG. | |
1173 * In case this routine needs to exit on error make sure that | |
1174 * this flag is cleared. | |
1175 */ | |
1176 vlun->svl_flags |= VLUN_QUIESCED_FLG; | |
1177 pkt_reserve_cmd = 1; | |
1178 | |
1179 /* | |
1180 * if this is a SCSI-II RESERVE command, set load balancing | |
1181 * policy to be ALTERNATE PATH to ensure that all subsequent | |
1182 * IOs are routed on the same path. This is because if commands | |
1183 * are routed across multiple paths then IOs on paths other than | |
1184 * the one on which the RESERVE was executed will get a | |
1185 * RESERVATION CONFLICT | |
1186 */ | |
1187 lbp = mdi_get_lb_policy(cdip); | |
1188 if (lbp != LOAD_BALANCE_NONE) { | |
1189 if (vhci_quiesce_lun(vlun) != 1) { | |
1190 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
1191 VHCI_RELEASE_LUN(vlun); | |
1192 return (TRAN_FATAL_ERROR); | |
1193 } | |
1194 vlun->svl_lb_policy_save = lbp; | |
1195 if (mdi_set_lb_policy(cdip, LOAD_BALANCE_NONE) != | |
1196 MDI_SUCCESS) { | |
1197 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
1198 VHCI_RELEASE_LUN(vlun); | |
1199 return (TRAN_FATAL_ERROR); | |
1200 } | |
1201 restore_lbp = 1; | |
1202 } | |
1203 /* | |
1204 * See comments for VLUN_RESERVE_ACTIVE_FLG in scsi_vhci.h | |
1205 * To narrow this window where a reserve command may be sent | |
1206 * down an inactive path the path states first need to be | |
1207 * updated. Before calling vhci_update_pathstates reset | |
1208 * VLUN_RESERVE_ACTIVE_FLG, just in case it was already set | |
1209 * for this lun. This shall prevent an unnecessary reset | |
1210 * from being sent out. | |
1211 */ | |
1212 vlun->svl_flags &= ~VLUN_RESERVE_ACTIVE_FLG; | |
1213 vhci_update_pathstates((void *)vlun); | |
1214 } | |
1215 | |
1216 instance = ddi_get_instance(vhci->vhci_dip); | |
1217 | |
1218 /* | |
1219 * If the command is PRIN with action of zero, then the cmd | |
1220 * is reading PR keys which requires filtering on completion. | |
1221 * Data cache sync must be guaranteed. | |
1222 */ | |
1223 if ((pkt->pkt_cdbp[0] == SCMD_PRIN) && | |
1224 (pkt->pkt_cdbp[1] == 0) && | |
1225 (vpkt->vpkt_org_vpkt == NULL)) { | |
1226 vpkt->vpkt_tgt_init_pkt_flags |= PKT_CONSISTENT; | |
1227 } | |
1228 | |
1229 /* | |
1230 * Do not defer bind for PKT_DMA_PARTIAL | |
1231 */ | |
1232 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
1233 | |
1234 /* This is a non pkt_dma_partial case */ | |
1235 if ((rval = vhci_bind_transport( | |
1236 ap, vpkt, vpkt->vpkt_tgt_init_pkt_flags, NULL_FUNC)) | |
1237 != TRAN_ACCEPT) { | |
1238 VHCI_DEBUG(6, (CE_WARN, vhci->vhci_dip, | |
1239 "!vhci%d %x: failed to bind transport: " | |
1240 "vlun 0x%p pkt_reserved %x restore_lbp %x," | |
1241 "lbp %x", instance, rval, (void *)vlun, | |
1242 pkt_reserve_cmd, restore_lbp, lbp)); | |
1243 if (restore_lbp) | |
1244 (void) mdi_set_lb_policy(cdip, lbp); | |
1245 if (pkt_reserve_cmd) | |
1246 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
1247 return (rval); | |
1248 } | |
1249 VHCI_DEBUG(8, (CE_NOTE, NULL, | |
1250 "vhci_scsi_start: v_b_t called 0x%p\n", (void *)vpkt)); | |
1251 } | |
1252 ASSERT(vpkt->vpkt_hba_pkt != NULL); | |
1253 ASSERT(vpkt->vpkt_path != NULL); | |
1254 | |
1255 /* | |
1256 * This is the chance to adjust the pHCI's pkt and other information | |
1257 * from target driver's pkt. | |
1258 */ | |
1259 VHCI_DEBUG(8, (CE_NOTE, vhci->vhci_dip, "vhci_scsi_start vpkt %p\n", | |
1260 (void *)vpkt)); | |
1261 vhci_update_pHCI_pkt(vpkt, pkt); | |
1262 | |
1263 if (vlun->svl_flags & VLUN_RESERVE_ACTIVE_FLG) { | |
1264 if (vpkt->vpkt_path != vlun->svl_resrv_pip) { | |
1265 VHCI_DEBUG(1, (CE_WARN, vhci->vhci_dip, | |
1266 "!vhci_bind: reserve flag set for vlun 0x%p, but, " | |
1267 "pktpath 0x%p resrv path 0x%p differ. lb_policy %x", | |
1268 (void *)vlun, (void *)vpkt->vpkt_path, | |
1269 (void *)vlun->svl_resrv_pip, | |
1270 mdi_get_lb_policy(cdip))); | |
1271 reserve_failed = 1; | |
1272 } | |
1273 } | |
1274 | |
1275 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private( | |
1276 vpkt->vpkt_path); | |
1277 if (svp == NULL || reserve_failed) { | |
1278 if (pkt_reserve_cmd) { | |
1279 VHCI_DEBUG(6, (CE_WARN, vhci->vhci_dip, | |
1280 "!vhci_bind returned null svp vlun 0x%p", | |
1281 (void *)vlun)); | |
1282 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
1283 if (restore_lbp) | |
1284 (void) mdi_set_lb_policy(cdip, lbp); | |
1285 } | |
1286 pkt_cleanup: | |
1287 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
1288 scsi_destroy_pkt(vpkt->vpkt_hba_pkt); | |
1289 vpkt->vpkt_hba_pkt = NULL; | |
1290 if (vpkt->vpkt_path) { | |
1291 mdi_rele_path(vpkt->vpkt_path); | |
1292 vpkt->vpkt_path = NULL; | |
1293 } | |
1294 } | |
1295 if ((pkt->pkt_cdbp[0] == SCMD_PROUT) && | |
1296 (((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_REGISTER) || | |
1297 ((pkt->pkt_cdbp[1] & 0x1f) == | |
1298 VHCI_PROUT_R_AND_IGNORE))) { | |
1299 sema_v(&vlun->svl_pgr_sema); | |
1300 } | |
1301 return (TRAN_BUSY); | |
1302 } | |
1303 | |
1304 VHCI_INCR_PATH_CMDCOUNT(svp); | |
1305 | |
1306 /* | |
1307 * Ensure that no other IOs raced ahead, while a RESERVE cmd was | |
1308 * QUIESCING the same lun. | |
1309 */ | |
1310 if ((!pkt_reserve_cmd) && | |
1311 ((vlun->svl_flags & VLUN_QUIESCED_FLG) == VLUN_QUIESCED_FLG)) { | |
1312 VHCI_DECR_PATH_CMDCOUNT(svp); | |
1313 goto pkt_cleanup; | |
1314 } | |
1315 | |
1316 if ((pkt->pkt_cdbp[0] == SCMD_PRIN) || | |
1317 (pkt->pkt_cdbp[0] == SCMD_PROUT)) { | |
1318 /* | |
1319 * currently this thread only handles running PGR | |
1320 * commands, so don't bother creating it unless | |
1321 * something interesting is going to happen (like | |
1322 * either a PGR out, or a PGR in with enough space | |
1323 * to hold the keys that are getting returned) | |
1324 */ | |
1325 mutex_enter(&vlun->svl_mutex); | |
1326 if (((vlun->svl_flags & VLUN_TASK_D_ALIVE_FLG) == 0) && | |
1327 (pkt->pkt_cdbp[0] == SCMD_PROUT)) { | |
1328 vlun->svl_taskq = taskq_create("vlun_pgr_task_daemon", | |
1329 1, MINCLSYSPRI, 1, 4, 0); | |
1330 vlun->svl_flags |= VLUN_TASK_D_ALIVE_FLG; | |
1331 } | |
1332 mutex_exit(&vlun->svl_mutex); | |
1333 if ((pkt->pkt_cdbp[0] == SCMD_PROUT) && | |
1334 (((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_REGISTER) || | |
1335 ((pkt->pkt_cdbp[1] & 0x1f) == | |
1336 VHCI_PROUT_R_AND_IGNORE))) { | |
1337 if (rval = vhci_pgr_register_start(vlun, pkt)) { | |
1338 /* an error */ | |
1339 sema_v(&vlun->svl_pgr_sema); | |
1340 return (rval); | |
1341 } | |
1342 } | |
1343 } | |
1344 | |
1345 /* | |
1346 * SCSI-II RESERVE cmd is not expected in polled mode. | |
1347 * If this changes it needs to be handled for the polled scenario. | |
1348 */ | |
1349 flags = vpkt->vpkt_hba_pkt->pkt_flags; | |
1350 rval = scsi_transport(vpkt->vpkt_hba_pkt); | |
1351 if (rval == TRAN_ACCEPT) { | |
1352 if (flags & FLAG_NOINTR) { | |
1353 struct scsi_pkt *tpkt = vpkt->vpkt_tgt_pkt; | |
1354 struct scsi_pkt *pkt = vpkt->vpkt_hba_pkt; | |
1355 | |
1356 ASSERT(tpkt != NULL); | |
1357 *(tpkt->pkt_scbp) = *(pkt->pkt_scbp); | |
1358 tpkt->pkt_resid = pkt->pkt_resid; | |
1359 tpkt->pkt_state = pkt->pkt_state; | |
1360 tpkt->pkt_statistics = pkt->pkt_statistics; | |
1361 tpkt->pkt_reason = pkt->pkt_reason; | |
1362 | |
1363 if ((*(pkt->pkt_scbp) == STATUS_CHECK) && | |
1364 (pkt->pkt_state & STATE_ARQ_DONE)) { | |
1365 bcopy(pkt->pkt_scbp, tpkt->pkt_scbp, | |
1366 vpkt->vpkt_tgt_init_scblen); | |
1367 } | |
1368 | |
1369 VHCI_DECR_PATH_CMDCOUNT(svp); | |
1370 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
1371 scsi_destroy_pkt(vpkt->vpkt_hba_pkt); | |
1372 vpkt->vpkt_hba_pkt = NULL; | |
1373 if (vpkt->vpkt_path) { | |
1374 mdi_rele_path(vpkt->vpkt_path); | |
1375 vpkt->vpkt_path = NULL; | |
1376 } | |
1377 } | |
1378 /* | |
1379 * This path will not automatically retry pkts | |
1380 * internally, therefore, vpkt_org_vpkt should | |
1381 * never be set. | |
1382 */ | |
1383 ASSERT(vpkt->vpkt_org_vpkt == NULL); | |
1384 if (tpkt->pkt_comp) { | |
1385 (*tpkt->pkt_comp)(tpkt); | |
1386 } | |
1387 } | |
1388 return (rval); | |
1389 } else if ((pkt->pkt_cdbp[0] == SCMD_PROUT) && | |
1390 (((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_REGISTER) || | |
1391 ((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_R_AND_IGNORE))) { | |
1392 /* the command exited with bad status */ | |
1393 sema_v(&vlun->svl_pgr_sema); | |
1394 } else if (vpkt->vpkt_tgt_pkt->pkt_cdbp[0] == SCMD_PRIN) { | |
1395 /* the command exited with bad status */ | |
1396 sema_v(&vlun->svl_pgr_sema); | |
1397 } else if (pkt_reserve_cmd) { | |
1398 VHCI_DEBUG(6, (CE_WARN, vhci->vhci_dip, | |
1399 "!vhci_scsi_start: reserve failed vlun 0x%p", | |
1400 (void *)vlun)); | |
1401 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
1402 if (restore_lbp) | |
1403 (void) mdi_set_lb_policy(cdip, lbp); | |
1404 } | |
1405 | |
1406 ASSERT(vpkt->vpkt_hba_pkt != NULL); | |
1407 VHCI_DECR_PATH_CMDCOUNT(svp); | |
1408 | |
1409 /* Do not destroy phci packet information for PKT_DMA_PARTIAL */ | |
1410 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
1411 scsi_destroy_pkt(vpkt->vpkt_hba_pkt); | |
1412 vpkt->vpkt_hba_pkt = NULL; | |
1413 if (vpkt->vpkt_path) { | |
1414 MDI_PI_ERRSTAT(vpkt->vpkt_path, MDI_PI_TRANSERR); | |
1415 mdi_rele_path(vpkt->vpkt_path); | |
1416 vpkt->vpkt_path = NULL; | |
1417 } | |
1418 } | |
1419 return (TRAN_BUSY); | |
1420 } | |
1421 | |
1422 /* | |
1423 * Function name : vhci_scsi_reset() | |
1424 * | |
1425 * Return Values : 0 - reset failed | |
1426 * 1 - reset succeeded | |
1427 */ | |
1428 | |
1429 /* ARGSUSED */ | |
1430 static int | |
1431 vhci_scsi_reset(struct scsi_address *ap, int level) | |
1432 { | |
1433 int rval = 0; | |
1434 | |
1435 cmn_err(CE_WARN, "!vhci_scsi_reset 0x%x", level); | |
1436 if ((level == RESET_TARGET) || (level == RESET_LUN)) { | |
1437 return (vhci_scsi_reset_target(ap, level, TRUE)); | |
1438 } else if (level == RESET_ALL) { | |
1439 return (vhci_scsi_reset_bus(ap)); | |
1440 } | |
1441 | |
1442 return (rval); | |
1443 } | |
1444 | |
1445 /* | |
1446 * vhci_recovery_reset: | |
1447 * Issues reset to the device | |
1448 * Input: | |
1449 * vlun - vhci lun pointer of the device | |
1450 * ap - address of the device | |
1451 * select_path: | |
1452 * If select_path is FALSE, then the address specified in ap is | |
1453 * the path on which reset will be issued. | |
1454 * If select_path is TRUE, then path is obtained by calling | |
1455 * mdi_select_path. | |
1456 * | |
1457 * recovery_depth: | |
1458 * Caller can specify the level of reset. | |
1459 * VHCI_DEPTH_LUN - | |
1460 * Issues LUN RESET if device supports lun reset. | |
1461 * VHCI_DEPTH_TARGET - | |
1462 * If Lun Reset fails or the device does not support | |
1463 * Lun Reset, issues TARGET RESET | |
1464 * VHCI_DEPTH_ALL - | |
1465 * If Lun Reset fails or the device does not support | |
1466 * Lun Reset, issues TARGET RESET. | |
1467 * If TARGET RESET does not succeed, issues Bus Reset. | |
1468 */ | |
1469 | |
1470 static int | |
1471 vhci_recovery_reset(scsi_vhci_lun_t *vlun, struct scsi_address *ap, | |
1472 uint8_t select_path, uint8_t recovery_depth) | |
1473 { | |
1474 int ret = 0; | |
1475 | |
1476 ASSERT(ap != NULL); | |
1477 | |
1478 if (vlun && vlun->svl_support_lun_reset == 1) { | |
1479 ret = vhci_scsi_reset_target(ap, RESET_LUN, | |
1480 select_path); | |
1481 } | |
1482 | |
1483 recovery_depth--; | |
1484 | |
1485 if ((ret == 0) && recovery_depth) { | |
1486 ret = vhci_scsi_reset_target(ap, RESET_TARGET, | |
1487 select_path); | |
1488 recovery_depth--; | |
1489 } | |
1490 | |
1491 if ((ret == 0) && recovery_depth) { | |
1492 (void) scsi_reset(ap, RESET_ALL); | |
1493 } | |
1494 | |
1495 return (ret); | |
1496 } | |
1497 | |
1498 /* | |
1499 * Note: The scsi_address passed to this routine could be the scsi_address | |
1500 * for the virtual device or the physical device. No assumptions should be | |
1501 * made in this routine about the ap structure and a_hba_tran->tran_tgt_private | |
1502 * field of ap can not be assumed to be the vhci structure. | |
1503 * Further note that the child dip would be the dip of the ssd node irrespective | |
1504 * of the scsi_address passed. | |
1505 */ | |
1506 | |
1507 static int | |
1508 vhci_scsi_reset_target(struct scsi_address *ap, int level, uint8_t select_path) | |
1509 { | |
1510 dev_info_t *vdip, *pdip, *cdip = ADDR2DIP(ap); | |
1511 mdi_pathinfo_t *pip = NULL; | |
1512 mdi_pathinfo_t *npip = NULL; | |
1513 int rval = -1; | |
1514 scsi_vhci_priv_t *svp = NULL; | |
1515 struct scsi_address *pap = NULL; | |
1516 scsi_hba_tran_t *hba = NULL; | |
1517 int sps; | |
1518 struct scsi_vhci *vhci = NULL; | |
1519 | |
1520 if (select_path != TRUE) { | |
1521 ASSERT(ap != NULL); | |
1522 if (level == RESET_LUN) { | |
1523 hba = ap->a_hba_tran; | |
1524 ASSERT(hba != NULL); | |
1525 return ((*hba->tran_reset)(ap, RESET_LUN)); | |
1526 } | |
1527 return (scsi_reset(ap, level)); | |
1528 } | |
1529 | |
1530 ASSERT(cdip != NULL); | |
1531 vdip = ddi_get_parent(cdip); | |
1532 ASSERT(vdip != NULL); | |
1533 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(vdip)); | |
1534 ASSERT(vhci != NULL); | |
1535 | |
1536 rval = mdi_select_path(cdip, NULL, MDI_SELECT_ONLINE_PATH, NULL, &pip); | |
1537 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
1538 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_scsi_reset_target: " | |
1539 "Unable to get a path, dip 0x%p", (void *)cdip)); | |
1540 return (0); | |
1541 } | |
1542 again: | |
1543 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
1544 if (svp == NULL) { | |
1545 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_scsi_reset_target: " | |
1546 "priv is NULL, pip 0x%p", (void *)pip)); | |
1547 mdi_rele_path(pip); | |
1548 return (0); | |
1549 } | |
1550 | |
1551 if (svp->svp_psd == NULL) { | |
1552 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_scsi_reset_target: " | |
1553 "psd is NULL, pip 0x%p, svp 0x%p", | |
1554 (void *)pip, (void *)svp)); | |
1555 mdi_rele_path(pip); | |
1556 return (0); | |
1557 } | |
1558 | |
1559 pap = &svp->svp_psd->sd_address; | |
1560 hba = pap->a_hba_tran; | |
1561 | |
1562 ASSERT(pap != NULL); | |
1563 ASSERT(hba != NULL); | |
1564 | |
1565 if (hba->tran_reset != NULL) { | |
1566 if ((*hba->tran_reset)(pap, level) == 0) { | |
1567 pdip = mdi_pi_get_phci(pip); | |
1568 vhci_log(CE_WARN, vdip, "!(%s%d):" | |
1569 " path (%s%d), reset %d failed", | |
1570 ddi_driver_name(cdip), ddi_get_instance(cdip), | |
1571 ddi_driver_name(pdip), ddi_get_instance(pdip), | |
1572 level); | |
1573 | |
1574 /* | |
1575 * Select next path and issue the reset, repeat | |
1576 * until all paths are exhausted | |
1577 */ | |
1578 sps = mdi_select_path(cdip, NULL, | |
1579 MDI_SELECT_ONLINE_PATH, pip, &npip); | |
1580 if ((sps != MDI_SUCCESS) || (npip == NULL)) { | |
1581 mdi_rele_path(pip); | |
1582 return (0); | |
1583 } | |
1584 mdi_rele_path(pip); | |
1585 pip = npip; | |
1586 goto again; | |
1587 } | |
1588 mdi_rele_path(pip); | |
1589 mutex_enter(&vhci->vhci_mutex); | |
1590 scsi_hba_reset_notify_callback(&vhci->vhci_mutex, | |
1591 &vhci->vhci_reset_notify_listf); | |
1592 mutex_exit(&vhci->vhci_mutex); | |
1593 VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_scsi_reset_target: " | |
1594 "reset %d sent down pip:%p for cdip:%p\n", level, | |
1595 (void *)pip, (void *)cdip)); | |
1596 return (1); | |
1597 } | |
1598 mdi_rele_path(pip); | |
1599 return (0); | |
1600 } | |
1601 | |
1602 | |
1603 /* ARGSUSED */ | |
1604 static int | |
1605 vhci_scsi_reset_bus(struct scsi_address *ap) | |
1606 { | |
1607 return (1); | |
1608 } | |
1609 | |
1610 | |
1611 /* | |
1612 * called by vhci_getcap and vhci_setcap to get and set (respectively) | |
1613 * SCSI capabilities | |
1614 */ | |
1615 /* ARGSUSED */ | |
1616 static int | |
1617 vhci_commoncap(struct scsi_address *ap, char *cap, | |
1618 int val, int tgtonly, int doset) | |
1619 { | |
1620 struct scsi_vhci *vhci = ADDR2VHCI(ap); | |
1621 struct scsi_vhci_lun *vlun = ADDR2VLUN(ap); | |
1622 int cidx; | |
1623 int rval = 0; | |
1624 | |
1625 if (cap == (char *)0) { | |
1626 VHCI_DEBUG(3, (CE_WARN, vhci->vhci_dip, | |
1627 "!vhci_commoncap: invalid arg")); | |
1628 return (rval); | |
1629 } | |
1630 | |
4882
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1631 if (vlun == NULL) { |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1632 VHCI_DEBUG(3, (CE_WARN, vhci->vhci_dip, |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1633 "!vhci_commoncap: vlun is null")); |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1634 return (rval); |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1635 } |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
1636 |
4851 | 1637 if ((cidx = scsi_hba_lookup_capstr(cap)) == -1) { |
1638 return (UNDEFINED); | |
1639 } | |
1640 | |
1641 /* | |
1642 * Process setcap request. | |
1643 */ | |
1644 if (doset) { | |
1645 /* | |
1646 * At present, we can only set binary (0/1) values | |
1647 */ | |
1648 switch (cidx) { | |
1649 case SCSI_CAP_ARQ: | |
1650 if (val == 0) { | |
1651 rval = 0; | |
1652 } else { | |
1653 rval = 1; | |
1654 } | |
1655 break; | |
1656 | |
1657 case SCSI_CAP_LUN_RESET: | |
1658 if (tgtonly == 0) { | |
1659 VHCI_DEBUG(1, (CE_WARN, vhci->vhci_dip, | |
1660 "scsi_vhci_setcap: " | |
1661 "Returning error since whom = 0")); | |
1662 rval = -1; | |
1663 break; | |
1664 } | |
1665 /* | |
1666 * Set the capability accordingly. | |
1667 */ | |
1668 mutex_enter(&vlun->svl_mutex); | |
1669 vlun->svl_support_lun_reset = val; | |
1670 rval = val; | |
1671 mutex_exit(&vlun->svl_mutex); | |
1672 break; | |
1673 | |
1674 case SCSI_CAP_SECTOR_SIZE: | |
1675 mutex_enter(&vlun->svl_mutex); | |
1676 vlun->svl_sector_size = val; | |
1677 vlun->svl_setcap_done = 1; | |
1678 mutex_exit(&vlun->svl_mutex); | |
1679 (void) vhci_pHCI_cap(ap, cap, val, tgtonly, NULL); | |
1680 | |
1681 /* Always return success */ | |
1682 rval = 1; | |
1683 break; | |
1684 | |
1685 default: | |
1686 VHCI_DEBUG(6, (CE_WARN, vhci->vhci_dip, | |
1687 "!vhci_setcap: unsupported %d", cidx)); | |
1688 rval = UNDEFINED; | |
1689 break; | |
1690 } | |
1691 | |
1692 VHCI_DEBUG(6, (CE_NOTE, vhci->vhci_dip, | |
1693 "!set cap: cap=%s, val/tgtonly/doset/rval = " | |
1694 "0x%x/0x%x/0x%x/%d\n", | |
1695 cap, val, tgtonly, doset, rval)); | |
1696 | |
1697 } else { | |
1698 /* | |
1699 * Process getcap request. | |
1700 */ | |
1701 switch (cidx) { | |
1702 case SCSI_CAP_DMA_MAX: | |
1703 rval = (int)VHCI_DMA_MAX_XFER_CAP; | |
1704 break; | |
1705 | |
1706 case SCSI_CAP_INITIATOR_ID: | |
1707 rval = 0x00; | |
1708 break; | |
1709 | |
1710 case SCSI_CAP_ARQ: | |
1711 case SCSI_CAP_RESET_NOTIFICATION: | |
1712 case SCSI_CAP_TAGGED_QING: | |
1713 rval = 1; | |
1714 break; | |
1715 | |
1716 case SCSI_CAP_SCSI_VERSION: | |
1717 rval = 3; | |
1718 break; | |
1719 | |
1720 case SCSI_CAP_INTERCONNECT_TYPE: | |
1721 rval = INTERCONNECT_FABRIC; | |
1722 break; | |
1723 | |
1724 case SCSI_CAP_LUN_RESET: | |
1725 /* | |
1726 * scsi_vhci will always return success for LUN reset. | |
1727 * When request for doing LUN reset comes | |
1728 * through scsi_reset entry point, at that time attempt | |
1729 * will be made to do reset through all the possible | |
1730 * paths. | |
1731 */ | |
1732 mutex_enter(&vlun->svl_mutex); | |
1733 rval = vlun->svl_support_lun_reset; | |
1734 mutex_exit(&vlun->svl_mutex); | |
1735 VHCI_DEBUG(4, (CE_WARN, vhci->vhci_dip, | |
1736 "scsi_vhci_getcap:" | |
1737 "Getting the Lun reset capability %d", rval)); | |
1738 break; | |
1739 | |
1740 case SCSI_CAP_SECTOR_SIZE: | |
1741 mutex_enter(&vlun->svl_mutex); | |
1742 rval = vlun->svl_sector_size; | |
1743 mutex_exit(&vlun->svl_mutex); | |
1744 break; | |
1745 | |
1746 default: | |
1747 VHCI_DEBUG(6, (CE_WARN, vhci->vhci_dip, | |
1748 "!vhci_getcap: unsupported %d", cidx)); | |
1749 rval = UNDEFINED; | |
1750 break; | |
1751 } | |
1752 | |
1753 VHCI_DEBUG(6, (CE_NOTE, vhci->vhci_dip, | |
1754 "!get cap: cap=%s, val/tgtonly/doset/rval = " | |
1755 "0x%x/0x%x/0x%x/%d\n", | |
1756 cap, val, tgtonly, doset, rval)); | |
1757 } | |
1758 return (rval); | |
1759 } | |
1760 | |
1761 | |
1762 /* | |
1763 * Function name : vhci_scsi_getcap() | |
1764 * | |
1765 */ | |
1766 static int | |
1767 vhci_scsi_getcap(struct scsi_address *ap, char *cap, int whom) | |
1768 { | |
1769 return (vhci_commoncap(ap, cap, 0, whom, 0)); | |
1770 } | |
1771 | |
1772 static int | |
1773 vhci_scsi_setcap(struct scsi_address *ap, char *cap, int value, int whom) | |
1774 { | |
1775 return (vhci_commoncap(ap, cap, value, whom, 1)); | |
1776 } | |
1777 | |
1778 /* | |
1779 * Function name : vhci_scsi_abort() | |
1780 */ | |
1781 /* ARGSUSED */ | |
1782 static int | |
1783 vhci_scsi_abort(struct scsi_address *ap, struct scsi_pkt *pkt) | |
1784 { | |
1785 return (0); | |
1786 } | |
1787 | |
1788 /* | |
1789 * Function name : vhci_scsi_init_pkt | |
1790 * | |
1791 * Return Values : pointer to scsi_pkt, or NULL | |
1792 */ | |
1793 /* ARGSUSED */ | |
1794 static struct scsi_pkt * | |
1795 vhci_scsi_init_pkt(struct scsi_address *ap, struct scsi_pkt *pkt, | |
1796 struct buf *bp, int cmdlen, int statuslen, int tgtlen, | |
1797 int flags, int (*callback)(caddr_t), caddr_t arg) | |
1798 { | |
1799 struct scsi_vhci *vhci = ADDR2VHCI(ap); | |
1800 struct vhci_pkt *vpkt; | |
1801 int rval; | |
1802 int newpkt = 0; | |
1803 struct scsi_pkt *pktp; | |
1804 | |
1805 | |
1806 if (pkt == NULL) { | |
1807 if (cmdlen > VHCI_SCSI_CDB_SIZE) { | |
1808 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
1809 "!init pkt: cdb size not supported\n")); | |
1810 return (NULL); | |
1811 } | |
1812 | |
1813 pktp = scsi_hba_pkt_alloc(vhci->vhci_dip, | |
1814 ap, cmdlen, statuslen, tgtlen, sizeof (*vpkt), callback, | |
1815 arg); | |
1816 | |
1817 if (pktp == NULL) { | |
1818 return (NULL); | |
1819 } | |
1820 | |
1821 /* Get the vhci's private structure */ | |
1822 vpkt = (struct vhci_pkt *)(pktp->pkt_ha_private); | |
1823 ASSERT(vpkt); | |
1824 | |
1825 /* Save the target driver's packet */ | |
1826 vpkt->vpkt_tgt_pkt = pktp; | |
1827 | |
1828 /* | |
1829 * Save pkt_tgt_init_pkt fields if deferred binding | |
1830 * is needed or for other purposes. | |
1831 */ | |
1832 vpkt->vpkt_tgt_init_pkt_flags = flags; | |
1833 vpkt->vpkt_flags = (callback == NULL_FUNC) ? CFLAG_NOWAIT : 0; | |
1834 vpkt->vpkt_state = VHCI_PKT_IDLE; | |
1835 vpkt->vpkt_tgt_init_cdblen = cmdlen; | |
1836 vpkt->vpkt_tgt_init_scblen = statuslen; | |
1837 vpkt->vpkt_tgt_init_privlen = tgtlen; | |
1838 newpkt = 1; | |
1839 } else { /* pkt not NULL */ | |
1840 vpkt = pkt->pkt_ha_private; | |
1841 } | |
1842 | |
1843 VHCI_DEBUG(8, (CE_NOTE, NULL, "vhci_scsi_init_pkt " | |
1844 "vpkt %p flags %x\n", (void *)vpkt, flags)); | |
1845 | |
1846 /* Clear any stale error flags */ | |
1847 if (bp) { | |
1848 bioerror(bp, 0); | |
1849 } | |
1850 | |
1851 vpkt->vpkt_tgt_init_bp = bp; | |
1852 | |
1853 if (flags & PKT_DMA_PARTIAL) { | |
1854 | |
1855 /* | |
1856 * Immediate binding is needed. | |
1857 * Target driver may not set this flag in next invocation. | |
1858 * vhci has to remember this flag was set during first | |
1859 * invocation of vhci_scsi_init_pkt. | |
1860 */ | |
1861 vpkt->vpkt_flags |= CFLAG_DMA_PARTIAL; | |
1862 } | |
1863 | |
1864 if (vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) { | |
1865 | |
1866 /* | |
1867 * Re-initialize some of the target driver packet state | |
1868 * information. | |
1869 */ | |
1870 vpkt->vpkt_tgt_pkt->pkt_state = 0; | |
1871 vpkt->vpkt_tgt_pkt->pkt_statistics = 0; | |
1872 vpkt->vpkt_tgt_pkt->pkt_reason = 0; | |
1873 | |
1874 /* | |
1875 * Binding a vpkt->vpkt_path for this IO at init_time. | |
1876 * If an IO error happens later, target driver will clear | |
1877 * this vpkt->vpkt_path binding before re-init IO again. | |
1878 */ | |
1879 VHCI_DEBUG(8, (CE_NOTE, NULL, | |
1880 "vhci_scsi_init_pkt: calling v_b_t %p, newpkt %d\n", | |
1881 (void *)vpkt, newpkt)); | |
1882 if (pkt && vpkt->vpkt_hba_pkt) { | |
1883 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
1884 "v_s_i_p calling update_pHCI_pkt resid %ld\n", | |
1885 pkt->pkt_resid)); | |
1886 vhci_update_pHCI_pkt(vpkt, pkt); | |
1887 } | |
1888 if (callback == SLEEP_FUNC) { | |
1889 rval = vhci_bind_transport( | |
1890 ap, vpkt, flags, callback); | |
1891 } else { | |
1892 rval = vhci_bind_transport( | |
1893 ap, vpkt, flags, NULL_FUNC); | |
1894 } | |
1895 VHCI_DEBUG(8, (CE_NOTE, NULL, | |
1896 "vhci_scsi_init_pkt: v_b_t called 0x%p rval 0x%x\n", | |
1897 (void *)vpkt, rval)); | |
1898 if (bp) { | |
1899 if (rval == TRAN_FATAL_ERROR) { | |
1900 /* | |
1901 * No paths available. Could not bind | |
1902 * any pHCI. Setting EFAULT as a way | |
1903 * to indicate no DMA is mapped. | |
1904 */ | |
1905 bioerror(bp, EFAULT); | |
1906 } else { | |
1907 /* | |
1908 * Do not indicate any pHCI errors to | |
1909 * target driver otherwise. | |
1910 */ | |
1911 bioerror(bp, 0); | |
1912 } | |
1913 } | |
1914 if (rval != TRAN_ACCEPT) { | |
1915 VHCI_DEBUG(8, (CE_NOTE, NULL, | |
1916 "vhci_scsi_init_pkt: " | |
1917 "v_b_t failed 0x%p newpkt %x\n", | |
1918 (void *)vpkt, newpkt)); | |
1919 if (newpkt) { | |
1920 scsi_hba_pkt_free(ap, | |
1921 vpkt->vpkt_tgt_pkt); | |
1922 } | |
1923 return (NULL); | |
1924 } | |
1925 ASSERT(vpkt->vpkt_hba_pkt != NULL); | |
1926 ASSERT(vpkt->vpkt_path != NULL); | |
1927 | |
1928 /* Update the resid for the target driver */ | |
1929 vpkt->vpkt_tgt_pkt->pkt_resid = | |
1930 vpkt->vpkt_hba_pkt->pkt_resid; | |
1931 } | |
1932 | |
1933 return (vpkt->vpkt_tgt_pkt); | |
1934 } | |
1935 | |
1936 /* | |
1937 * Function name : vhci_scsi_destroy_pkt | |
1938 * | |
1939 * Return Values : none | |
1940 */ | |
1941 static void | |
1942 vhci_scsi_destroy_pkt(struct scsi_address *ap, struct scsi_pkt *pkt) | |
1943 { | |
1944 struct vhci_pkt *vpkt = (struct vhci_pkt *)pkt->pkt_ha_private; | |
1945 | |
1946 VHCI_DEBUG(8, (CE_NOTE, NULL, | |
1947 "vhci_scsi_destroy_pkt: vpkt 0x%p\n", (void *)vpkt)); | |
1948 | |
1949 vpkt->vpkt_tgt_init_pkt_flags = 0; | |
1950 if (vpkt->vpkt_hba_pkt) { | |
1951 scsi_destroy_pkt(vpkt->vpkt_hba_pkt); | |
1952 vpkt->vpkt_hba_pkt = NULL; | |
1953 } | |
1954 if (vpkt->vpkt_path) { | |
1955 mdi_rele_path(vpkt->vpkt_path); | |
1956 vpkt->vpkt_path = NULL; | |
1957 } | |
1958 | |
1959 ASSERT(vpkt->vpkt_state != VHCI_PKT_ISSUED); | |
1960 scsi_hba_pkt_free(ap, vpkt->vpkt_tgt_pkt); | |
1961 } | |
1962 | |
1963 /* | |
1964 * Function name : vhci_scsi_dmafree() | |
1965 * | |
1966 * Return Values : none | |
1967 */ | |
1968 /*ARGSUSED*/ | |
1969 static void | |
1970 vhci_scsi_dmafree(struct scsi_address *ap, struct scsi_pkt *pkt) | |
1971 { | |
1972 struct vhci_pkt *vpkt = (struct vhci_pkt *)pkt->pkt_ha_private; | |
1973 | |
1974 VHCI_DEBUG(6, (CE_NOTE, NULL, | |
1975 "vhci_scsi_dmafree: vpkt 0x%p\n", (void *)vpkt)); | |
1976 | |
1977 ASSERT(vpkt != NULL); | |
1978 if (vpkt->vpkt_hba_pkt) { | |
1979 scsi_destroy_pkt(vpkt->vpkt_hba_pkt); | |
1980 vpkt->vpkt_hba_pkt = NULL; | |
1981 } | |
1982 if (vpkt->vpkt_path) { | |
1983 mdi_rele_path(vpkt->vpkt_path); | |
1984 vpkt->vpkt_path = NULL; | |
1985 } | |
1986 } | |
1987 | |
1988 /* | |
1989 * Function name : vhci_scsi_sync_pkt() | |
1990 * | |
1991 * Return Values : none | |
1992 */ | |
1993 /*ARGSUSED*/ | |
1994 static void | |
1995 vhci_scsi_sync_pkt(struct scsi_address *ap, struct scsi_pkt *pkt) | |
1996 { | |
1997 struct vhci_pkt *vpkt = (struct vhci_pkt *)pkt->pkt_ha_private; | |
1998 | |
1999 ASSERT(vpkt != NULL); | |
2000 if (vpkt->vpkt_hba_pkt) { | |
2001 scsi_sync_pkt(vpkt->vpkt_hba_pkt); | |
2002 } | |
2003 } | |
2004 | |
2005 /* | |
2006 * routine for reset notification setup, to register or cancel. | |
2007 */ | |
2008 static int | |
2009 vhci_scsi_reset_notify(struct scsi_address *ap, int flag, | |
2010 void (*callback)(caddr_t), caddr_t arg) | |
2011 { | |
2012 struct scsi_vhci *vhci = ADDR2VHCI(ap); | |
2013 return (scsi_hba_reset_notify_setup(ap, flag, callback, arg, | |
2014 &vhci->vhci_mutex, &vhci->vhci_reset_notify_listf)); | |
2015 } | |
2016 | |
2017 static int | |
2018 vhci_scsi_get_name_bus_addr(struct scsi_device *sd, | |
2019 char *name, int len, int bus_addr) | |
2020 { | |
2021 dev_info_t *cdip; | |
2022 char *guid; | |
2023 scsi_vhci_lun_t *vlun; | |
2024 | |
2025 ASSERT(sd != NULL); | |
2026 ASSERT(name != NULL); | |
2027 | |
2028 cdip = sd->sd_dev; | |
2029 | |
2030 ASSERT(cdip != NULL); | |
2031 | |
2032 if (mdi_component_is_client(cdip, NULL) != MDI_SUCCESS) { | |
2033 name[0] = '\0'; | |
2034 return (1); | |
2035 } | |
2036 | |
2037 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, cdip, PROPFLAGS, | |
2038 MDI_CLIENT_GUID_PROP, &guid) != DDI_SUCCESS) { | |
2039 name[0] = '\0'; | |
2040 return (1); | |
2041 } | |
2042 | |
2043 vlun = ADDR2VLUN(&sd->sd_address); | |
2044 if (bus_addr && vlun && vlun->svl_fops_name) { | |
2045 /* report the guid and the name of the failover module */ | |
2046 (void) snprintf(name, len, "g%s %s", guid, vlun->svl_fops_name); | |
2047 } else { | |
2048 /* report the guid */ | |
2049 (void) snprintf(name, len, "g%s", guid); | |
2050 } | |
2051 | |
2052 ddi_prop_free(guid); | |
2053 return (1); | |
2054 } | |
2055 | |
2056 static int | |
2057 vhci_scsi_get_bus_addr(struct scsi_device *sd, char *name, int len) | |
2058 { | |
2059 return (vhci_scsi_get_name_bus_addr(sd, name, len, 1)); | |
2060 } | |
2061 | |
2062 static int | |
2063 vhci_scsi_get_name(struct scsi_device *sd, char *name, int len) | |
2064 { | |
2065 return (vhci_scsi_get_name_bus_addr(sd, name, len, 0)); | |
2066 } | |
2067 | |
2068 /* | |
2069 * Return a pointer to the guid part of the devnm. | |
2070 * devnm format is "nodename@busaddr", busaddr format is "gGUID". | |
2071 */ | |
2072 static char * | |
2073 vhci_devnm_to_guid(char *devnm) | |
2074 { | |
2075 char *cp = devnm; | |
2076 | |
2077 if (devnm == NULL) | |
2078 return (NULL); | |
2079 | |
2080 while (*cp != '\0' && *cp != '@') | |
2081 cp++; | |
2082 if (*cp == '@' && *(cp + 1) == 'g') | |
2083 return (cp + 2); | |
2084 return (NULL); | |
2085 } | |
2086 | |
2087 static int | |
2088 vhci_bind_transport(struct scsi_address *ap, struct vhci_pkt *vpkt, int flags, | |
2089 int (*func)(caddr_t)) | |
2090 { | |
2091 struct scsi_vhci *vhci = ADDR2VHCI(ap); | |
2092 dev_info_t *cdip = ADDR2DIP(ap); | |
2093 mdi_pathinfo_t *pip = NULL; | |
2094 mdi_pathinfo_t *npip = NULL; | |
2095 scsi_vhci_priv_t *svp = NULL; | |
2096 struct scsi_device *psd = NULL; | |
2097 struct scsi_address *address = NULL; | |
2098 struct scsi_pkt *pkt = NULL; | |
2099 int rval = -1; | |
2100 int pgr_sema_held = 0; | |
2101 int held; | |
2102 int mps_flag = MDI_SELECT_ONLINE_PATH; | |
2103 struct scsi_vhci_lun *vlun; | |
2104 time_t tnow; | |
2105 | |
2106 vlun = ADDR2VLUN(ap); | |
2107 ASSERT(vlun != 0); | |
2108 | |
2109 if ((vpkt->vpkt_tgt_pkt->pkt_cdbp[0] == SCMD_PROUT) && | |
2110 (((vpkt->vpkt_tgt_pkt->pkt_cdbp[1] & 0x1f) == | |
2111 VHCI_PROUT_REGISTER) || | |
2112 ((vpkt->vpkt_tgt_pkt->pkt_cdbp[1] & 0x1f) == | |
2113 VHCI_PROUT_R_AND_IGNORE))) { | |
2114 if (!sema_tryp(&vlun->svl_pgr_sema)) | |
2115 return (TRAN_BUSY); | |
2116 pgr_sema_held = 1; | |
2117 if (vlun->svl_first_path != NULL) { | |
2118 rval = mdi_select_path(cdip, NULL, | |
2119 MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH, | |
2120 NULL, &pip); | |
2121 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
2122 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2123 "vhci_bind_transport: path select fail\n")); | |
2124 } else { | |
2125 npip = pip; | |
2126 do { | |
2127 if (npip == vlun->svl_first_path) { | |
2128 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2129 "vhci_bind_transport: " | |
2130 "valid first path 0x%p\n", | |
2131 (void *) | |
2132 vlun->svl_first_path)); | |
2133 pip = vlun->svl_first_path; | |
2134 goto bind_path; | |
2135 } | |
2136 pip = npip; | |
2137 rval = mdi_select_path(cdip, NULL, | |
2138 MDI_SELECT_ONLINE_PATH | | |
2139 MDI_SELECT_STANDBY_PATH, | |
2140 pip, &npip); | |
2141 mdi_rele_path(pip); | |
2142 } while ((rval == MDI_SUCCESS) && | |
2143 (npip != NULL)); | |
2144 } | |
2145 } | |
2146 | |
2147 if (vlun->svl_first_path) { | |
2148 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2149 "vhci_bind_transport: invalid first path 0x%p\n", | |
2150 (void *)vlun->svl_first_path)); | |
2151 vlun->svl_first_path = NULL; | |
2152 } | |
2153 } else if (vpkt->vpkt_tgt_pkt->pkt_cdbp[0] == SCMD_PRIN) { | |
2154 if ((vpkt->vpkt_state & VHCI_PKT_THRU_TASKQ) == 0) { | |
2155 if (!sema_tryp(&vlun->svl_pgr_sema)) | |
2156 return (TRAN_BUSY); | |
2157 } | |
2158 pgr_sema_held = 1; | |
2159 } | |
2160 | |
2161 /* | |
2162 * If the path is already bound for PKT_PARTIAL_DMA case, | |
2163 * try to use the same path. | |
2164 */ | |
2165 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) && vpkt->vpkt_path) { | |
2166 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2167 "vhci_bind_transport: PKT_PARTIAL_DMA " | |
2168 "vpkt 0x%p, path 0x%p\n", | |
2169 (void *)vpkt, (void *)vpkt->vpkt_path)); | |
2170 pip = vpkt->vpkt_path; | |
2171 goto bind_path; | |
2172 } | |
2173 | |
2174 /* | |
2175 * If reservation is active bind the transport directly to the pip | |
2176 * with the reservation. | |
2177 */ | |
2178 if (vpkt->vpkt_hba_pkt == NULL) { | |
2179 if (vlun->svl_flags & VLUN_RESERVE_ACTIVE_FLG) { | |
2180 if (MDI_PI_IS_ONLINE(vlun->svl_resrv_pip)) { | |
2181 pip = vlun->svl_resrv_pip; | |
2182 mdi_hold_path(pip); | |
2183 vlun->svl_waiting_for_activepath = 0; | |
2184 rval = MDI_SUCCESS; | |
2185 goto bind_path; | |
2186 } else { | |
2187 if (pgr_sema_held) { | |
2188 sema_v(&vlun->svl_pgr_sema); | |
2189 } | |
2190 return (TRAN_BUSY); | |
2191 } | |
2192 } | |
2193 try_again: | |
2194 rval = mdi_select_path(cdip, vpkt->vpkt_tgt_init_bp, 0, NULL, | |
2195 &pip); | |
2196 if (rval == MDI_BUSY) { | |
2197 if (pgr_sema_held) { | |
2198 sema_v(&vlun->svl_pgr_sema); | |
2199 } | |
2200 return (TRAN_BUSY); | |
2201 } else if (rval == MDI_DEVI_ONLINING) { | |
2202 /* | |
2203 * if we are here then we are in the midst of | |
2204 * an attach/probe of the client device. | |
2205 * We attempt to bind to ONLINE path if available, | |
2206 * else it is OK to bind to a STANDBY path (instead | |
2207 * of triggering a failover) because IO associated | |
2208 * with attach/probe (eg. INQUIRY, block 0 read) | |
2209 * are completed by targets even on passive paths | |
2210 * If no ONLINE paths available, it is important | |
2211 * to set svl_waiting_for_activepath for two | |
2212 * reasons: (1) avoid sense analysis in the | |
2213 * "external failure detection" codepath in | |
2214 * vhci_intr(). Failure to do so will result in | |
2215 * infinite loop (unless an ONLINE path becomes | |
2216 * available at some point) (2) avoid | |
2217 * unnecessary failover (see "---Waiting For Active | |
2218 * Path---" comment below). | |
2219 */ | |
2220 VHCI_DEBUG(1, (CE_NOTE, NULL, "!%p in onlining " | |
2221 "state\n", (void *)cdip)); | |
2222 pip = NULL; | |
2223 rval = mdi_select_path(cdip, vpkt->vpkt_tgt_init_bp, | |
2224 mps_flag, NULL, &pip); | |
2225 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
2226 if (vlun->svl_waiting_for_activepath == 0) { | |
2227 vlun->svl_waiting_for_activepath = 1; | |
2228 vlun->svl_wfa_time = ddi_get_time(); | |
2229 } | |
2230 mps_flag |= MDI_SELECT_STANDBY_PATH; | |
2231 rval = mdi_select_path(cdip, | |
2232 vpkt->vpkt_tgt_init_bp, | |
2233 mps_flag, NULL, &pip); | |
2234 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
2235 if (pgr_sema_held) { | |
2236 sema_v(&vlun->svl_pgr_sema); | |
2237 } | |
2238 return (TRAN_FATAL_ERROR); | |
2239 } | |
2240 goto bind_path; | |
2241 } | |
2242 } else if (rval == MDI_FAILURE) { | |
2243 if (pgr_sema_held) { | |
2244 sema_v(&vlun->svl_pgr_sema); | |
2245 } | |
2246 return (TRAN_FATAL_ERROR); | |
2247 } | |
2248 | |
2249 if ((pip == NULL) || (rval == MDI_NOPATH)) { | |
2250 while (vlun->svl_waiting_for_activepath) { | |
2251 /* | |
2252 * ---Waiting For Active Path--- | |
2253 * This device was discovered across a | |
2254 * passive path; lets wait for a little | |
2255 * bit, hopefully an active path will | |
2256 * show up obviating the need for a | |
2257 * failover | |
2258 */ | |
2259 tnow = ddi_get_time(); | |
2260 if (tnow - vlun->svl_wfa_time >= 60) { | |
2261 vlun->svl_waiting_for_activepath = 0; | |
2262 } else { | |
2263 drv_usecwait(1000); | |
2264 if (vlun->svl_waiting_for_activepath | |
2265 == 0) { | |
2266 /* | |
2267 * an active path has come | |
2268 * online! | |
2269 */ | |
2270 goto try_again; | |
2271 } | |
2272 } | |
2273 } | |
2274 VHCI_HOLD_LUN(vlun, VH_NOSLEEP, held); | |
2275 if (!held) { | |
2276 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2277 "!Lun not held\n")); | |
2278 if (pgr_sema_held) { | |
2279 sema_v(&vlun->svl_pgr_sema); | |
2280 } | |
2281 return (TRAN_BUSY); | |
2282 } | |
2283 /* | |
2284 * now that the LUN is stable, one last check | |
2285 * to make sure no other changes sneaked in | |
2286 * (like a path coming online or a | |
2287 * failover initiated by another thread) | |
2288 */ | |
2289 pip = NULL; | |
2290 rval = mdi_select_path(cdip, vpkt->vpkt_tgt_init_bp, | |
2291 0, NULL, &pip); | |
2292 if (pip != NULL) { | |
2293 VHCI_RELEASE_LUN(vlun); | |
2294 vlun->svl_waiting_for_activepath = 0; | |
2295 goto bind_path; | |
2296 } | |
2297 | |
2298 /* | |
2299 * Check if there is an ONLINE path OR a STANDBY path | |
2300 * available. If none is available, do not attempt | |
2301 * to do a failover, just return a fatal error at this | |
2302 * point. | |
2303 */ | |
2304 npip = NULL; | |
2305 rval = mdi_select_path(cdip, NULL, | |
2306 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
2307 NULL, &npip); | |
2308 if ((npip == NULL) || (rval != MDI_SUCCESS)) { | |
2309 /* | |
2310 * No paths available, jus return FATAL error. | |
2311 */ | |
2312 VHCI_RELEASE_LUN(vlun); | |
2313 if (pgr_sema_held) { | |
2314 sema_v(&vlun->svl_pgr_sema); | |
2315 } | |
2316 return (TRAN_FATAL_ERROR); | |
2317 } | |
2318 mdi_rele_path(npip); | |
2319 VHCI_DEBUG(1, (CE_NOTE, NULL, "!invoking " | |
2320 "mdi_failover\n")); | |
2321 rval = mdi_failover(vhci->vhci_dip, cdip, | |
2322 MDI_FAILOVER_ASYNC); | |
2323 if (rval == MDI_FAILURE) { | |
2324 VHCI_RELEASE_LUN(vlun); | |
2325 if (pgr_sema_held) { | |
2326 sema_v(&vlun->svl_pgr_sema); | |
2327 } | |
2328 return (TRAN_FATAL_ERROR); | |
2329 } else if (rval == MDI_BUSY) { | |
2330 VHCI_RELEASE_LUN(vlun); | |
2331 if (pgr_sema_held) { | |
2332 sema_v(&vlun->svl_pgr_sema); | |
2333 } | |
2334 return (TRAN_BUSY); | |
2335 } else { | |
2336 if (pgr_sema_held) { | |
2337 sema_v(&vlun->svl_pgr_sema); | |
2338 } | |
2339 return (TRAN_BUSY); | |
2340 } | |
2341 } | |
2342 vlun->svl_waiting_for_activepath = 0; | |
2343 bind_path: | |
2344 vpkt->vpkt_path = pip; | |
2345 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
2346 ASSERT(svp != NULL); | |
2347 | |
2348 psd = svp->svp_psd; | |
2349 ASSERT(psd != NULL); | |
2350 address = &psd->sd_address; | |
2351 } else { | |
2352 pkt = vpkt->vpkt_hba_pkt; | |
2353 address = &pkt->pkt_address; | |
2354 } | |
2355 | |
2356 /* | |
2357 * For PKT_PARTIAL_DMA case, call pHCI's scsi_init_pkt whenever | |
2358 * target driver calls vhci_scsi_init_pkt. | |
2359 */ | |
2360 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) && | |
2361 vpkt->vpkt_path && vpkt->vpkt_hba_pkt) { | |
2362 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2363 "vhci_bind_transport: PKT_PARTIAL_DMA " | |
2364 "vpkt 0x%p, path 0x%p hba_pkt 0x%p\n", | |
2365 (void *)vpkt, (void *)vpkt->vpkt_path, (void *)pkt)); | |
2366 pkt = vpkt->vpkt_hba_pkt; | |
2367 address = &pkt->pkt_address; | |
2368 } | |
2369 | |
2370 if (pkt == NULL || (vpkt->vpkt_flags & CFLAG_DMA_PARTIAL)) { | |
2371 pkt = scsi_init_pkt(address, pkt, | |
2372 vpkt->vpkt_tgt_init_bp, vpkt->vpkt_tgt_init_cdblen, | |
2373 vpkt->vpkt_tgt_init_scblen, | |
2374 vpkt->vpkt_tgt_init_privlen, flags, func, NULL); | |
2375 | |
2376 if (pkt == NULL) { | |
2377 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2378 "!bind transport: 0x%p 0x%p 0x%p\n", | |
2379 (void *)vhci, (void *)psd, (void *)vpkt)); | |
2380 if ((vpkt->vpkt_hba_pkt == NULL) && vpkt->vpkt_path) { | |
2381 MDI_PI_ERRSTAT(vpkt->vpkt_path, | |
2382 MDI_PI_TRANSERR); | |
2383 mdi_rele_path(vpkt->vpkt_path); | |
2384 vpkt->vpkt_path = NULL; | |
2385 } | |
2386 if (pgr_sema_held) { | |
2387 sema_v(&vlun->svl_pgr_sema); | |
2388 } | |
2389 /* | |
2390 * Looks like a fatal error. | |
2391 * May be device disappeared underneath. | |
2392 * Give another chance to target driver for a retry to | |
2393 * get another path. | |
2394 */ | |
2395 return (TRAN_BUSY); | |
2396 } | |
2397 } | |
2398 | |
2399 pkt->pkt_private = vpkt; | |
2400 vpkt->vpkt_hba_pkt = pkt; | |
2401 return (TRAN_ACCEPT); | |
2402 } | |
2403 | |
2404 | |
2405 /*PRINTFLIKE3*/ | |
2406 void | |
2407 vhci_log(int level, dev_info_t *dip, const char *fmt, ...) | |
2408 { | |
2409 char buf[256]; | |
2410 va_list ap; | |
2411 | |
2412 va_start(ap, fmt); | |
2413 (void) vsprintf(buf, fmt, ap); | |
2414 va_end(ap); | |
2415 | |
2416 scsi_log(dip, "scsi_vhci", level, buf); | |
2417 } | |
2418 | |
2419 /* do a PGR out with the information we've saved away */ | |
2420 static int | |
2421 vhci_do_prout(scsi_vhci_priv_t *svp) | |
2422 { | |
2423 | |
2424 struct scsi_pkt *new_pkt; | |
2425 struct buf *bp; | |
2426 scsi_vhci_lun_t *vlun; | |
2427 int rval, retry, nr_retry, ua_retry; | |
2428 struct scsi_extended_sense *sns; | |
2429 | |
2430 bp = getrbuf(KM_SLEEP); | |
2431 bp->b_flags = B_WRITE; | |
2432 bp->b_resid = 0; | |
2433 | |
2434 VHCI_INCR_PATH_CMDCOUNT(svp); | |
2435 vlun = svp->svp_svl; | |
2436 | |
2437 new_pkt = scsi_init_pkt(&svp->svp_psd->sd_address, NULL, bp, | |
2438 CDB_GROUP1, sizeof (struct scsi_arq_status), 0, 0, | |
2439 SLEEP_FUNC, NULL); | |
2440 if (new_pkt == NULL) { | |
2441 VHCI_DECR_PATH_CMDCOUNT(svp); | |
2442 freerbuf(bp); | |
2443 cmn_err(CE_WARN, "!vhci_do_prout: scsi_init_pkt failed"); | |
2444 return (0); | |
2445 } | |
2446 mutex_enter(&vlun->svl_mutex); | |
2447 bp->b_un.b_addr = (caddr_t)&vlun->svl_prout; | |
2448 bp->b_bcount = vlun->svl_bcount; | |
2449 bcopy(vlun->svl_cdb, new_pkt->pkt_cdbp, | |
2450 sizeof (vlun->svl_cdb)); | |
2451 new_pkt->pkt_time = vlun->svl_time; | |
2452 mutex_exit(&vlun->svl_mutex); | |
2453 new_pkt->pkt_flags = FLAG_NOINTR; | |
2454 | |
2455 ua_retry = nr_retry = retry = 0; | |
2456 again: | |
2457 rval = vhci_do_scsi_cmd(new_pkt); | |
2458 if (rval != 1) { | |
2459 if ((new_pkt->pkt_reason == CMD_CMPLT) && | |
2460 (SCBP_C(new_pkt) == STATUS_CHECK) && | |
2461 (new_pkt->pkt_state & STATE_ARQ_DONE)) { | |
2462 sns = &(((struct scsi_arq_status *)(uintptr_t) | |
2463 (new_pkt->pkt_scbp))->sts_sensedata); | |
2464 if ((sns->es_key == KEY_UNIT_ATTENTION) || | |
2465 (sns->es_key == KEY_NOT_READY)) { | |
2466 int max_retry; | |
2467 struct scsi_failover_ops *fops; | |
2468 fops = vlun->svl_fops; | |
2469 rval = (*fops->sfo_analyze_sense) | |
2470 (svp->svp_psd, sns, | |
2471 vlun->svl_fops_ctpriv); | |
2472 if (rval == SCSI_SENSE_NOT_READY) { | |
2473 max_retry = vhci_prout_not_ready_retry; | |
2474 retry = nr_retry++; | |
2475 delay(1*drv_usectohz(1000000)); | |
2476 } else { | |
2477 /* chk for state change and update */ | |
2478 if (rval == SCSI_SENSE_STATE_CHANGED) { | |
2479 int held; | |
2480 VHCI_HOLD_LUN(vlun, | |
2481 VH_NOSLEEP, held); | |
2482 if (!held) { | |
2483 rval = TRAN_BUSY; | |
2484 } else { | |
2485 /* chk for alua first */ | |
2486 vhci_update_pathstates( | |
2487 (void *)vlun); | |
2488 } | |
2489 } | |
2490 retry = ua_retry++; | |
2491 max_retry = VHCI_MAX_PGR_RETRIES; | |
2492 } | |
2493 if (retry < max_retry) { | |
2494 VHCI_DEBUG(4, (CE_WARN, NULL, | |
2495 "!vhci_do_prout retry 0x%x " | |
2496 "(0x%x 0x%x 0x%x)", | |
2497 SCBP_C(new_pkt), | |
2498 new_pkt->pkt_cdbp[0], | |
2499 new_pkt->pkt_cdbp[1], | |
2500 new_pkt->pkt_cdbp[2])); | |
2501 goto again; | |
2502 } | |
2503 rval = 0; | |
2504 VHCI_DEBUG(4, (CE_WARN, NULL, | |
2505 "!vhci_do_prout 0x%x " | |
2506 "(0x%x 0x%x 0x%x)", | |
2507 SCBP_C(new_pkt), | |
2508 new_pkt->pkt_cdbp[0], | |
2509 new_pkt->pkt_cdbp[1], | |
2510 new_pkt->pkt_cdbp[2])); | |
2511 } else if (sns->es_key == KEY_ILLEGAL_REQUEST) | |
2512 rval = VHCI_PGR_ILLEGALOP; | |
2513 } | |
2514 } else { | |
2515 rval = 1; | |
2516 } | |
2517 scsi_destroy_pkt(new_pkt); | |
2518 VHCI_DECR_PATH_CMDCOUNT(svp); | |
2519 freerbuf(bp); | |
2520 return (rval); | |
2521 } | |
2522 | |
2523 static void | |
2524 vhci_run_cmd(void *arg) | |
2525 { | |
2526 struct scsi_pkt *pkt = (struct scsi_pkt *)arg; | |
2527 struct scsi_pkt *tpkt; | |
2528 scsi_vhci_priv_t *svp; | |
2529 mdi_pathinfo_t *pip, *npip; | |
2530 scsi_vhci_lun_t *vlun; | |
2531 dev_info_t *cdip; | |
2532 scsi_vhci_priv_t *nsvp; | |
2533 int fail = 0; | |
2534 int rval; | |
2535 struct vhci_pkt *vpkt; | |
2536 uchar_t cdb_1; | |
2537 vhci_prout_t *prout; | |
2538 | |
2539 vpkt = (struct vhci_pkt *)pkt->pkt_private; | |
2540 tpkt = vpkt->vpkt_tgt_pkt; | |
2541 pip = vpkt->vpkt_path; | |
2542 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
2543 if (svp == NULL) { | |
2544 tpkt->pkt_reason = CMD_TRAN_ERR; | |
2545 tpkt->pkt_statistics = STAT_ABORTED; | |
2546 goto done; | |
2547 } | |
2548 vlun = svp->svp_svl; | |
2549 prout = &vlun->svl_prout; | |
2550 if (SCBP_C(pkt) != STATUS_GOOD) | |
2551 fail++; | |
2552 cdip = vlun->svl_dip; | |
2553 pip = npip = NULL; | |
2554 rval = mdi_select_path(cdip, NULL, | |
2555 MDI_SELECT_ONLINE_PATH|MDI_SELECT_STANDBY_PATH, NULL, &npip); | |
2556 if ((rval != MDI_SUCCESS) || (npip == NULL)) { | |
2557 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2558 "vhci_run_cmd: no path! 0x%p\n", (void *)svp)); | |
2559 tpkt->pkt_reason = CMD_TRAN_ERR; | |
2560 tpkt->pkt_statistics = STAT_ABORTED; | |
2561 goto done; | |
2562 } | |
2563 | |
2564 cdb_1 = vlun->svl_cdb[1]; | |
2565 vlun->svl_cdb[1] &= 0xe0; | |
2566 vlun->svl_cdb[1] |= VHCI_PROUT_R_AND_IGNORE; | |
2567 | |
2568 do { | |
2569 nsvp = (scsi_vhci_priv_t *) | |
2570 mdi_pi_get_vhci_private(npip); | |
2571 if (nsvp == NULL) { | |
2572 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
2573 "vhci_run_cmd: no " | |
2574 "client priv! 0x%p offlined?\n", | |
2575 (void *)npip)); | |
2576 goto next_path; | |
2577 } | |
2578 if (vlun->svl_first_path == npip) { | |
2579 goto next_path; | |
2580 } else { | |
2581 if (vhci_do_prout(nsvp) != 1) | |
2582 fail++; | |
2583 } | |
2584 next_path: | |
2585 pip = npip; | |
2586 rval = mdi_select_path(cdip, NULL, | |
2587 MDI_SELECT_ONLINE_PATH|MDI_SELECT_STANDBY_PATH, | |
2588 pip, &npip); | |
2589 mdi_rele_path(pip); | |
2590 } while ((rval == MDI_SUCCESS) && (npip != NULL)); | |
2591 | |
2592 vlun->svl_cdb[1] = cdb_1; | |
2593 | |
2594 if (fail) { | |
2595 VHCI_DEBUG(4, (CE_WARN, NULL, "%s%d: key registration failed, " | |
2596 "couldn't be replicated on all paths", | |
2597 ddi_driver_name(cdip), ddi_get_instance(cdip))); | |
2598 vhci_print_prout_keys(vlun, "vhci_run_cmd: "); | |
2599 | |
2600 if (SCBP_C(pkt) != STATUS_GOOD) { | |
2601 tpkt->pkt_reason = CMD_TRAN_ERR; | |
2602 tpkt->pkt_statistics = STAT_ABORTED; | |
2603 } | |
2604 } else { | |
2605 vlun->svl_pgr_active = 1; | |
2606 vhci_print_prout_keys(vlun, "vhci_run_cmd: before bcopy:"); | |
2607 | |
2608 bcopy((const void *)prout->service_key, | |
2609 (void *)prout->active_service_key, MHIOC_RESV_KEY_SIZE); | |
2610 bcopy((const void *)prout->res_key, | |
2611 (void *)prout->active_res_key, MHIOC_RESV_KEY_SIZE); | |
2612 | |
2613 vhci_print_prout_keys(vlun, "vhci_run_cmd: after bcopy:"); | |
2614 } | |
2615 done: | |
2616 if (SCBP_C(pkt) == STATUS_GOOD) | |
2617 vlun->svl_first_path = NULL; | |
2618 | |
2619 if (svp) | |
2620 VHCI_DECR_PATH_CMDCOUNT(svp); | |
2621 | |
2622 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
2623 scsi_destroy_pkt(pkt); | |
2624 vpkt->vpkt_hba_pkt = NULL; | |
2625 if (vpkt->vpkt_path) { | |
2626 mdi_rele_path(vpkt->vpkt_path); | |
2627 vpkt->vpkt_path = NULL; | |
2628 } | |
2629 } | |
2630 | |
2631 sema_v(&vlun->svl_pgr_sema); | |
2632 /* | |
2633 * The PROUT commands are not included in the automatic retry | |
2634 * mechanism, therefore, vpkt_org_vpkt should never be set here. | |
2635 */ | |
2636 ASSERT(vpkt->vpkt_org_vpkt == NULL); | |
2637 if (tpkt->pkt_comp) | |
2638 (*tpkt->pkt_comp)(tpkt); | |
2639 | |
2640 } | |
2641 | |
2642 /* | |
2643 * Get the keys registered with this target. Since we will have | |
2644 * registered the same key with multiple initiators, strip out | |
2645 * any duplicate keys. | |
2646 * | |
2647 * The pointers which will be used to filter the registered keys from | |
2648 * the device will be stored in filter_prin and filter_pkt. If the | |
2649 * allocation length of the buffer was sufficient for the number of | |
2650 * parameter data bytes available to be returned by the device then the | |
2651 * key filtering will use the keylist returned from the original | |
2652 * request. If the allocation length of the buffer was not sufficient, | |
2653 * then the filtering will use the keylist returned from the request | |
2654 * that is resent below. | |
2655 * | |
2656 * If the device returns an additional length field that is greater than | |
2657 * the allocation length of the buffer, then allocate a new buffer which | |
2658 * can accommodate the number of parameter data bytes available to be | |
2659 * returned. Resend the scsi PRIN command, filter out the duplicate | |
2660 * keys and return as many of the unique keys found that was originally | |
2661 * requested and set the additional length field equal to the data bytes | |
2662 * of unique reservation keys available to be returned. | |
2663 * | |
2664 * If the device returns an additional length field that is less than or | |
2665 * equal to the allocation length of the buffer, then all the available | |
2666 * keys registered were returned by the device. Filter out the | |
2667 * duplicate keys and return all of the unique keys found and set the | |
2668 * additional length field equal to the data bytes of the reservation | |
2669 * keys to be returned. | |
2670 */ | |
2671 static int | |
2672 vhci_do_prin(struct vhci_pkt **vpkt) | |
2673 { | |
2674 scsi_vhci_priv_t *svp = (scsi_vhci_priv_t *) | |
2675 mdi_pi_get_vhci_private((*vpkt)->vpkt_path); | |
2676 vhci_prin_readkeys_t *prin; | |
2677 scsi_vhci_lun_t *vlun = svp->svp_svl; | |
2678 struct scsi_vhci *vhci = | |
2679 ADDR2VHCI(&((*vpkt)->vpkt_tgt_pkt->pkt_address)); | |
2680 | |
2681 struct buf *new_bp = NULL; | |
2682 struct scsi_pkt *new_pkt = NULL; | |
2683 struct vhci_pkt *new_vpkt = NULL; | |
2684 int hdr_len = 0; | |
2685 int rval = VHCI_CMD_CMPLT; | |
2686 uint32_t prin_length = 0; | |
2687 uint32_t svl_prin_length = 0; | |
2688 | |
2689 prin = (vhci_prin_readkeys_t *) | |
2690 bp_mapin_common((*vpkt)->vpkt_tgt_init_bp, VM_NOSLEEP); | |
2691 | |
2692 if (prin != NULL) { | |
2693 prin_length = BE_32(prin->length); | |
2694 } | |
2695 | |
2696 if (prin == NULL) { | |
2697 VHCI_DEBUG(5, (CE_WARN, NULL, | |
2698 "vhci_do_prin: bp_mapin_common failed.")); | |
2699 rval = VHCI_CMD_ERROR; | |
2700 } else { | |
2701 /* | |
2702 * According to SPC-3r22, sec 4.3.4.6: "If the amount of | |
2703 * information to be transferred exceeds the maximum value | |
2704 * that the ALLOCATION LENGTH field is capable of specifying, | |
2705 * the device server shall...terminate the command with CHECK | |
2706 * CONDITION status". The ALLOCATION LENGTH field of the | |
2707 * PERSISTENT RESERVE IN command is 2 bytes. We should never | |
2708 * get here with an ADDITIONAL LENGTH greater than 0xFFFF | |
2709 * so if we do, then it is an error! | |
2710 */ | |
2711 | |
2712 hdr_len = sizeof (prin->length) + sizeof (prin->generation); | |
2713 | |
2714 if ((prin_length + hdr_len) > 0xFFFF) { | |
2715 VHCI_DEBUG(5, (CE_NOTE, NULL, | |
2716 "vhci_do_prin: Device returned invalid " | |
2717 "length 0x%x\n", prin_length)); | |
2718 rval = VHCI_CMD_ERROR; | |
2719 } | |
2720 } | |
2721 | |
2722 /* | |
2723 * If prin->length is greater than the byte count allocated in the | |
2724 * original buffer, then resend the request with enough buffer | |
2725 * allocated to get all of the available registered keys. | |
2726 */ | |
2727 if (rval != VHCI_CMD_ERROR) { | |
2728 if (((*vpkt)->vpkt_tgt_init_bp->b_bcount - hdr_len) < | |
2729 prin_length) { | |
2730 if ((*vpkt)->vpkt_org_vpkt == NULL) { | |
2731 new_pkt = vhci_create_retry_pkt(*vpkt); | |
2732 if (new_pkt != NULL) { | |
2733 new_vpkt = TGTPKT2VHCIPKT(new_pkt); | |
2734 | |
2735 /* | |
2736 * This is the buf with buffer pointer | |
2737 * where the prin readkeys will be | |
2738 * returned from the device | |
2739 */ | |
2740 new_bp = scsi_alloc_consistent_buf( | |
2741 &svp->svp_psd->sd_address, | |
2742 NULL, (prin_length + hdr_len), | |
2743 ((*vpkt)->vpkt_tgt_init_bp-> | |
2744 b_flags & (B_READ | B_WRITE)), | |
2745 NULL_FUNC, NULL); | |
2746 if (new_bp != NULL) { | |
2747 if (new_bp->b_un.b_addr != | |
2748 NULL) { | |
2749 | |
2750 new_bp->b_bcount = | |
2751 prin_length + | |
2752 hdr_len; | |
2753 | |
2754 new_pkt->pkt_cdbp[7] = | |
2755 (uchar_t)(new_bp-> | |
2756 b_bcount >> 8); | |
2757 new_pkt->pkt_cdbp[8] = | |
2758 (uchar_t)new_bp-> | |
2759 b_bcount; | |
2760 | |
2761 rval = VHCI_CMD_RETRY; | |
2762 } else { | |
2763 rval = VHCI_CMD_ERROR; | |
2764 } | |
2765 } else { | |
2766 rval = VHCI_CMD_ERROR; | |
2767 } | |
2768 } else { | |
2769 rval = VHCI_CMD_ERROR; | |
2770 } | |
2771 } else { | |
2772 rval = VHCI_CMD_ERROR; | |
2773 } | |
2774 } | |
2775 } | |
2776 | |
2777 if (rval == VHCI_CMD_RETRY) { | |
2778 new_vpkt->vpkt_tgt_init_bp = new_bp; | |
2779 | |
2780 /* | |
2781 * Release the old path because it does not matter which path | |
2782 * this command is sent down. This allows the normal bind | |
2783 * transport mechanism to be used. | |
2784 */ | |
2785 if ((*vpkt)->vpkt_path != NULL) { | |
2786 mdi_rele_path((*vpkt)->vpkt_path); | |
2787 (*vpkt)->vpkt_path = NULL; | |
2788 } | |
2789 | |
2790 /* | |
2791 * Dispatch the retry command | |
2792 */ | |
2793 if (taskq_dispatch(vhci->vhci_taskq, vhci_dispatch_scsi_start, | |
2794 (void *) new_vpkt, KM_NOSLEEP) == NULL) { | |
2795 rval = VHCI_CMD_ERROR; | |
2796 } else { | |
2797 /* | |
2798 * If we return VHCI_CMD_RETRY, that means the caller | |
2799 * is going to bail and wait for the reissued command | |
2800 * to complete. In that case, we need to decrement | |
2801 * the path command count right now. In any other | |
2802 * case, it'll be decremented by the caller. | |
2803 */ | |
2804 VHCI_DECR_PATH_CMDCOUNT(svp); | |
2805 } | |
2806 } | |
2807 | |
2808 if ((rval != VHCI_CMD_ERROR) && (rval != VHCI_CMD_RETRY)) { | |
2809 int new, old; | |
2810 int data_len = 0; | |
2811 | |
2812 data_len = prin_length / MHIOC_RESV_KEY_SIZE; | |
2813 VHCI_DEBUG(4, (CE_NOTE, NULL, "vhci_do_prin: %d keys read\n", | |
2814 data_len)); | |
2815 | |
2816 #ifdef DEBUG | |
2817 VHCI_DEBUG(5, (CE_NOTE, NULL, "vhci_do_prin: from storage\n")); | |
2818 if (vhci_debug == 5) | |
2819 vhci_print_prin_keys(prin, data_len); | |
2820 VHCI_DEBUG(5, (CE_NOTE, NULL, | |
2821 "vhci_do_prin: MPxIO old keys:\n")); | |
2822 if (vhci_debug == 5) | |
2823 vhci_print_prin_keys(&vlun->svl_prin, data_len); | |
2824 #endif | |
2825 | |
2826 /* | |
2827 * Filter out all duplicate keys returned from the device | |
2828 * We know that we use a different key for every host, so we | |
2829 * can simply strip out duplicates. Otherwise we would need to | |
2830 * do more bookkeeping to figure out which keys to strip out. | |
2831 */ | |
2832 | |
2833 new = 0; | |
2834 | |
2835 if (data_len > 0) { | |
2836 vlun->svl_prin.keylist[0] = prin->keylist[0]; | |
2837 new++; | |
2838 } | |
2839 | |
2840 for (old = 1; old < data_len; old++) { | |
2841 int j; | |
2842 int match = 0; | |
2843 for (j = 0; j < new; j++) { | |
2844 if (bcmp(&prin->keylist[old], | |
2845 &vlun->svl_prin.keylist[j], | |
2846 sizeof (mhioc_resv_key_t)) == 0) { | |
2847 match = 1; | |
2848 break; | |
2849 } | |
2850 } | |
2851 if (!match) { | |
2852 vlun->svl_prin.keylist[new] = | |
2853 prin->keylist[old]; | |
2854 new++; | |
2855 } | |
2856 } | |
2857 | |
2858 vlun->svl_prin.generation = prin->generation; | |
2859 svl_prin_length = new * MHIOC_RESV_KEY_SIZE; | |
2860 vlun->svl_prin.length = BE_32(svl_prin_length); | |
2861 | |
2862 /* | |
2863 * If we arrived at this point after issuing a retry, make sure | |
2864 * that we put everything back the way it originally was so | |
2865 * that the target driver can complete the command correctly. | |
2866 */ | |
2867 if ((*vpkt)->vpkt_org_vpkt != NULL) { | |
2868 new_bp = (*vpkt)->vpkt_tgt_init_bp; | |
2869 | |
2870 scsi_free_consistent_buf(new_bp); | |
2871 | |
2872 *vpkt = vhci_sync_retry_pkt(*vpkt); | |
2873 | |
2874 /* | |
2875 * Make sure the original buffer is mapped into kernel | |
2876 * space before we try to copy the filtered keys into | |
2877 * it. | |
2878 */ | |
2879 prin = (vhci_prin_readkeys_t *)bp_mapin_common( | |
2880 (*vpkt)->vpkt_tgt_init_bp, VM_NOSLEEP); | |
2881 } | |
2882 | |
2883 /* | |
2884 * Now copy the desired number of prin keys into the original | |
2885 * target buffer. | |
2886 */ | |
2887 if (svl_prin_length <= | |
2888 ((*vpkt)->vpkt_tgt_init_bp->b_bcount - hdr_len)) { | |
2889 /* | |
2890 * It is safe to return all of the available unique | |
2891 * keys | |
2892 */ | |
2893 bcopy(&vlun->svl_prin, prin, svl_prin_length + hdr_len); | |
2894 } else { | |
2895 /* | |
2896 * Not all of the available keys were requested by the | |
2897 * original command. | |
2898 */ | |
2899 bcopy(&vlun->svl_prin, prin, | |
2900 (*vpkt)->vpkt_tgt_init_bp->b_bcount); | |
2901 } | |
2902 #ifdef DEBUG | |
2903 VHCI_DEBUG(5, (CE_NOTE, NULL, | |
2904 "vhci_do_prin: To Application:\n")); | |
2905 if (vhci_debug == 5) | |
2906 vhci_print_prin_keys(prin, new); | |
2907 VHCI_DEBUG(5, (CE_NOTE, NULL, | |
2908 "vhci_do_prin: MPxIO new keys:\n")); | |
2909 if (vhci_debug == 5) | |
2910 vhci_print_prin_keys(&vlun->svl_prin, new); | |
2911 #endif | |
2912 } | |
2913 | |
2914 if (rval == VHCI_CMD_ERROR) { | |
2915 /* | |
2916 * If we arrived at this point after issuing a | |
2917 * retry, make sure that we put everything back | |
2918 * the way it originally was so that ssd can | |
2919 * complete the command correctly. | |
2920 */ | |
2921 | |
2922 if ((*vpkt)->vpkt_org_vpkt != NULL) { | |
2923 new_bp = (*vpkt)->vpkt_tgt_init_bp; | |
2924 if (new_bp != NULL) { | |
2925 scsi_free_consistent_buf(new_bp); | |
2926 } | |
2927 | |
2928 new_vpkt = *vpkt; | |
2929 *vpkt = (*vpkt)->vpkt_org_vpkt; | |
2930 | |
2931 vhci_scsi_destroy_pkt(&svp->svp_psd->sd_address, | |
2932 new_vpkt->vpkt_tgt_pkt); | |
2933 } | |
2934 | |
2935 /* | |
2936 * Mark this command completion as having an error so that | |
2937 * ssd will retry the command. | |
2938 */ | |
2939 | |
2940 (*vpkt)->vpkt_tgt_pkt->pkt_reason = CMD_ABORTED; | |
2941 (*vpkt)->vpkt_tgt_pkt->pkt_statistics |= STAT_ABORTED; | |
2942 | |
2943 rval = VHCI_CMD_CMPLT; | |
2944 } | |
2945 | |
2946 /* | |
2947 * Make sure that the semaphore is only released once. | |
2948 */ | |
2949 if (rval == VHCI_CMD_CMPLT) { | |
2950 sema_v(&vlun->svl_pgr_sema); | |
2951 } | |
2952 | |
2953 return (rval); | |
2954 } | |
2955 | |
2956 static void | |
2957 vhci_intr(struct scsi_pkt *pkt) | |
2958 { | |
2959 struct vhci_pkt *vpkt = (struct vhci_pkt *)pkt->pkt_private; | |
2960 struct scsi_pkt *tpkt; | |
2961 scsi_vhci_priv_t *svp; | |
2962 scsi_vhci_lun_t *vlun; | |
2963 int rval, held; | |
2964 struct scsi_failover_ops *fops; | |
2965 struct scsi_extended_sense *sns; | |
2966 mdi_pathinfo_t *lpath; | |
2967 static char *timeout_err = "Command Timeout"; | |
2968 static char *parity_err = "Parity Error"; | |
2969 char *err_str = NULL; | |
2970 dev_info_t *vdip, *cdip, *pdip; | |
2971 char *cpath, *dpath; | |
2972 | |
2973 ASSERT(vpkt != NULL); | |
2974 tpkt = vpkt->vpkt_tgt_pkt; | |
2975 ASSERT(tpkt != NULL); | |
2976 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(vpkt->vpkt_path); | |
2977 ASSERT(svp != NULL); | |
2978 vlun = svp->svp_svl; | |
2979 ASSERT(vlun != NULL); | |
2980 lpath = vpkt->vpkt_path; | |
2981 | |
2982 /* | |
2983 * sync up the target driver's pkt with the pkt that | |
2984 * we actually used | |
2985 */ | |
2986 *(tpkt->pkt_scbp) = *(pkt->pkt_scbp); | |
2987 tpkt->pkt_resid = pkt->pkt_resid; | |
2988 tpkt->pkt_state = pkt->pkt_state; | |
2989 tpkt->pkt_statistics = pkt->pkt_statistics; | |
2990 tpkt->pkt_reason = pkt->pkt_reason; | |
2991 | |
2992 if (pkt->pkt_cdbp[0] == SCMD_PROUT && | |
2993 ((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_REGISTER) || | |
2994 ((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_R_AND_IGNORE)) { | |
2995 if ((SCBP_C(pkt) != STATUS_GOOD) || | |
2996 (pkt->pkt_reason != CMD_CMPLT)) { | |
2997 sema_v(&vlun->svl_pgr_sema); | |
2998 } | |
2999 } else if (pkt->pkt_cdbp[0] == SCMD_PRIN) { | |
3000 if (pkt->pkt_reason != CMD_CMPLT || | |
3001 (SCBP_C(pkt) != STATUS_GOOD)) { | |
3002 sema_v(&vlun->svl_pgr_sema); | |
3003 } | |
3004 } | |
3005 | |
3006 switch (pkt->pkt_reason) { | |
3007 case CMD_CMPLT: | |
3008 /* | |
3009 * cmd completed successfully, check for scsi errors | |
3010 */ | |
3011 switch (*(pkt->pkt_scbp)) { | |
3012 case STATUS_CHECK: | |
3013 if (pkt->pkt_state & STATE_ARQ_DONE) { | |
3014 sns = &(((struct scsi_arq_status *)(uintptr_t) | |
3015 (pkt->pkt_scbp))->sts_sensedata); | |
3016 fops = vlun->svl_fops; | |
3017 ASSERT(fops != NULL); | |
3018 VHCI_DEBUG(4, (CE_NOTE, NULL, "vhci_intr: " | |
3019 "Received sns key %x esc %x escq %x\n", | |
3020 sns->es_key, sns->es_add_code, | |
3021 sns->es_qual_code)); | |
3022 | |
3023 if (vlun->svl_waiting_for_activepath == 1) { | |
3024 /* | |
3025 * if we are here it means we are | |
3026 * in the midst of a probe/attach | |
3027 * through a passive path; this | |
3028 * case is exempt from sense analysis | |
3029 * for detection of ext. failover | |
3030 * because that would unnecessarily | |
3031 * increase attach time. | |
3032 */ | |
3033 bcopy(pkt->pkt_scbp, tpkt->pkt_scbp, | |
3034 vpkt->vpkt_tgt_init_scblen); | |
3035 break; | |
3036 } | |
3037 if (sns->es_add_code == VHCI_SCSI_PERR) { | |
3038 /* | |
3039 * parity error | |
3040 */ | |
3041 err_str = parity_err; | |
3042 bcopy(pkt->pkt_scbp, tpkt->pkt_scbp, | |
3043 vpkt->vpkt_tgt_init_scblen); | |
3044 break; | |
3045 } | |
3046 rval = (*fops->sfo_analyze_sense) | |
3047 (svp->svp_psd, sns, vlun->svl_fops_ctpriv); | |
3048 if ((rval == SCSI_SENSE_NOFAILOVER) || | |
3049 (rval == SCSI_SENSE_UNKNOWN) || | |
3050 (rval == SCSI_SENSE_NOT_READY)) { | |
3051 bcopy(pkt->pkt_scbp, tpkt->pkt_scbp, | |
3052 vpkt->vpkt_tgt_init_scblen); | |
3053 break; | |
3054 } else if (rval == SCSI_SENSE_STATE_CHANGED) { | |
3055 struct scsi_vhci *vhci; | |
3056 vhci = ADDR2VHCI(&tpkt->pkt_address); | |
3057 VHCI_HOLD_LUN(vlun, VH_NOSLEEP, held); | |
3058 if (!held) { | |
3059 /* | |
3060 * looks like some other thread | |
3061 * has already detected this | |
3062 * condition | |
3063 */ | |
3064 tpkt->pkt_state &= | |
3065 ~STATE_ARQ_DONE; | |
3066 *(tpkt->pkt_scbp) = | |
3067 STATUS_BUSY; | |
3068 break; | |
3069 } | |
3070 (void) taskq_dispatch( | |
3071 vhci->vhci_update_pathstates_taskq, | |
3072 vhci_update_pathstates, | |
3073 (void *)vlun, KM_SLEEP); | |
3074 } else { | |
3075 /* | |
3076 * externally initiated failover | |
3077 * has occurred or is in progress | |
3078 */ | |
3079 VHCI_HOLD_LUN(vlun, VH_NOSLEEP, held); | |
3080 if (!held) { | |
3081 /* | |
3082 * looks like some other thread | |
3083 * has already detected this | |
3084 * condition | |
3085 */ | |
3086 tpkt->pkt_state &= | |
3087 ~STATE_ARQ_DONE; | |
3088 *(tpkt->pkt_scbp) = | |
3089 STATUS_BUSY; | |
3090 break; | |
3091 } else { | |
3092 rval = vhci_handle_ext_fo | |
3093 (pkt, rval); | |
3094 if (rval == BUSY_RETURN) { | |
3095 tpkt->pkt_state &= | |
3096 ~STATE_ARQ_DONE; | |
3097 *(tpkt->pkt_scbp) = | |
3098 STATUS_BUSY; | |
3099 break; | |
3100 } | |
3101 bcopy(pkt->pkt_scbp, | |
3102 tpkt->pkt_scbp, | |
3103 vpkt->vpkt_tgt_init_scblen); | |
3104 break; | |
3105 } | |
3106 } | |
3107 } | |
3108 break; | |
3109 | |
3110 /* | |
3111 * If this is a good SCSI-II RELEASE cmd completion then restore | |
3112 * the load balancing policy and reset VLUN_RESERVE_ACTIVE_FLG. | |
3113 * If this is a good SCSI-II RESERVE cmd completion then set | |
3114 * VLUN_RESERVE_ACTIVE_FLG. | |
3115 */ | |
3116 case STATUS_GOOD: | |
3117 if ((pkt->pkt_cdbp[0] == SCMD_RELEASE) || | |
3118 (pkt->pkt_cdbp[0] == SCMD_RELEASE_G1)) { | |
3119 (void) mdi_set_lb_policy(vlun->svl_dip, | |
3120 vlun->svl_lb_policy_save); | |
3121 vlun->svl_flags &= ~VLUN_RESERVE_ACTIVE_FLG; | |
3122 VHCI_DEBUG(1, (CE_WARN, NULL, | |
3123 "!vhci_intr: vlun 0x%p release path 0x%p", | |
3124 (void *)vlun, (void *)vpkt->vpkt_path)); | |
3125 } | |
3126 | |
3127 if ((pkt->pkt_cdbp[0] == SCMD_RESERVE) || | |
3128 (pkt->pkt_cdbp[0] == SCMD_RESERVE_G1)) { | |
3129 vlun->svl_flags |= VLUN_RESERVE_ACTIVE_FLG; | |
3130 vlun->svl_resrv_pip = vpkt->vpkt_path; | |
3131 VHCI_DEBUG(1, (CE_WARN, NULL, | |
3132 "!vhci_intr: vlun 0x%p reserved path 0x%p", | |
3133 (void *)vlun, (void *)vpkt->vpkt_path)); | |
3134 } | |
3135 break; | |
3136 | |
3137 case STATUS_RESERVATION_CONFLICT: | |
3138 VHCI_DEBUG(1, (CE_WARN, NULL, | |
3139 "!vhci_intr: vlun 0x%p " | |
3140 "reserve conflict on path 0x%p", | |
3141 (void *)vlun, (void *)vpkt->vpkt_path)); | |
3142 /* FALLTHROUGH */ | |
3143 default: | |
3144 break; | |
3145 } | |
3146 | |
3147 /* | |
3148 * Update I/O completion statistics for the path | |
3149 */ | |
3150 mdi_pi_kstat_iosupdate(vpkt->vpkt_path, vpkt->vpkt_tgt_init_bp); | |
3151 | |
3152 /* | |
3153 * Command completed successfully, release the dma binding and | |
3154 * destroy the transport side of the packet. | |
3155 */ | |
3156 if ((pkt->pkt_cdbp[0] == SCMD_PROUT) && | |
3157 (((pkt->pkt_cdbp[1] & 0x1f) == VHCI_PROUT_REGISTER) || | |
3158 ((pkt->pkt_cdbp[1] & 0x1f) == | |
3159 VHCI_PROUT_R_AND_IGNORE))) { | |
3160 if (SCBP_C(pkt) == STATUS_GOOD) { | |
3161 ASSERT(vlun->svl_taskq); | |
3162 svp->svp_last_pkt_reason = pkt->pkt_reason; | |
3163 (void) taskq_dispatch(vlun->svl_taskq, | |
3164 vhci_run_cmd, pkt, KM_SLEEP); | |
3165 return; | |
3166 } | |
3167 } | |
3168 if ((SCBP_C(pkt) == STATUS_GOOD) && | |
3169 (pkt->pkt_cdbp[0] == SCMD_PRIN) && | |
3170 vpkt->vpkt_tgt_init_bp) { | |
3171 /* | |
3172 * If the action (value in byte 1 of the cdb) is zero, | |
3173 * we're reading keys, and that's the only condition | |
3174 * where we need to be concerned with filtering keys | |
3175 * and potential retries. Otherwise, we simply signal | |
3176 * the semaphore and move on. | |
3177 */ | |
3178 if (pkt->pkt_cdbp[1] == 0) { | |
3179 /* | |
3180 * If this is the completion of an internal | |
3181 * retry then we need to make sure that the | |
3182 * pkt and tpkt pointers are readjusted so | |
3183 * the calls to scsi_destroy_pkt and pkt_comp | |
3184 * below work * correctly. | |
3185 */ | |
3186 if (vpkt->vpkt_org_vpkt != NULL) { | |
3187 pkt = vpkt->vpkt_org_vpkt->vpkt_hba_pkt; | |
3188 tpkt = vpkt->vpkt_org_vpkt-> | |
3189 vpkt_tgt_pkt; | |
3190 | |
3191 /* | |
3192 * If this command was issued through | |
3193 * the taskq then we need to clear | |
3194 * this flag for proper processing in | |
3195 * the case of a retry from the target | |
3196 * driver. | |
3197 */ | |
3198 vpkt->vpkt_state &= | |
3199 ~VHCI_PKT_THRU_TASKQ; | |
3200 } | |
3201 | |
3202 /* | |
3203 * if vhci_do_prin returns VHCI_CMD_CMPLT then | |
3204 * vpkt will contain the address of the | |
3205 * original vpkt | |
3206 */ | |
3207 if (vhci_do_prin(&vpkt) == VHCI_CMD_RETRY) { | |
3208 /* | |
3209 * The command has been resent to get | |
3210 * all the keys from the device. Don't | |
3211 * complete the command with ssd until | |
3212 * the retry completes. | |
3213 */ | |
3214 return; | |
3215 } | |
3216 } else { | |
3217 sema_v(&vlun->svl_pgr_sema); | |
3218 } | |
3219 } | |
3220 | |
3221 break; | |
3222 | |
3223 case CMD_TIMEOUT: | |
3224 if ((pkt->pkt_statistics & | |
3225 (STAT_BUS_RESET|STAT_DEV_RESET|STAT_ABORTED)) == 0) { | |
3226 | |
3227 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
3228 "!scsi vhci timeout invoked\n")); | |
3229 | |
3230 (void) vhci_recovery_reset(vlun, &pkt->pkt_address, | |
3231 FALSE, VHCI_DEPTH_ALL); | |
3232 } | |
3233 MDI_PI_ERRSTAT(lpath, MDI_PI_TRANSERR); | |
3234 tpkt->pkt_statistics |= STAT_ABORTED; | |
3235 err_str = timeout_err; | |
3236 break; | |
3237 | |
3238 case CMD_TRAN_ERR: | |
3239 /* | |
3240 * This status is returned if the transport has sent the cmd | |
3241 * down the link to the target and then some error occurs. | |
3242 * In case of SCSI-II RESERVE cmd, we don't know if the | |
3243 * reservation been accepted by the target or not, so we need | |
3244 * to clear the reservation. | |
3245 */ | |
3246 if ((pkt->pkt_cdbp[0] == SCMD_RESERVE) || | |
3247 (pkt->pkt_cdbp[0] == SCMD_RESERVE_G1)) { | |
3248 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_intr received" | |
3249 " cmd_tran_err for scsi-2 reserve cmd\n")); | |
3250 if (!vhci_recovery_reset(vlun, &pkt->pkt_address, | |
3251 TRUE, VHCI_DEPTH_TARGET)) { | |
3252 VHCI_DEBUG(1, (CE_WARN, NULL, | |
3253 "!vhci_intr cmd_tran_err reset failed!")); | |
3254 } | |
3255 } | |
3256 break; | |
3257 | |
3258 case CMD_DEV_GONE: | |
3259 tpkt->pkt_reason = CMD_CMPLT; | |
3260 tpkt->pkt_state = STATE_GOT_BUS | | |
3261 STATE_GOT_TARGET | STATE_SENT_CMD | | |
3262 STATE_GOT_STATUS; | |
3263 *(tpkt->pkt_scbp) = STATUS_BUSY; | |
3264 break; | |
3265 | |
3266 default: | |
3267 break; | |
3268 } | |
3269 | |
3270 /* | |
3271 * SCSI-II RESERVE cmd has been serviced by the lower layers clear | |
3272 * the flag so the lun is not QUIESCED any longer. | |
3273 * Also clear the VHCI_PKT_THRU_TASKQ flag, to ensure that if this pkt | |
3274 * is retried, a taskq shall again be dispatched to service it. Else | |
3275 * it may lead to a system hang if the retry is within interrupt | |
3276 * context. | |
3277 */ | |
3278 if ((pkt->pkt_cdbp[0] == SCMD_RESERVE) || | |
3279 (pkt->pkt_cdbp[0] == SCMD_RESERVE_G1)) { | |
3280 vlun->svl_flags &= ~VLUN_QUIESCED_FLG; | |
3281 vpkt->vpkt_state &= ~VHCI_PKT_THRU_TASKQ; | |
3282 } | |
3283 | |
3284 /* | |
3285 * vpkt_org_vpkt should always be NULL here if the retry command | |
3286 * has been successfully processed. If vpkt_org_vpkt != NULL at | |
3287 * this point, it is an error so restore the original vpkt and | |
3288 * return an error to the target driver so it can retry the | |
3289 * command as appropriate. | |
3290 */ | |
3291 if (vpkt->vpkt_org_vpkt != NULL) { | |
3292 struct vhci_pkt *new_vpkt = vpkt; | |
3293 vpkt = vpkt->vpkt_org_vpkt; | |
3294 | |
3295 vhci_scsi_destroy_pkt(&svp->svp_psd->sd_address, | |
3296 new_vpkt->vpkt_tgt_pkt); | |
3297 | |
3298 /* | |
3299 * Mark this command completion as having an error so that | |
3300 * ssd will retry the command. | |
3301 */ | |
3302 vpkt->vpkt_tgt_pkt->pkt_reason = CMD_ABORTED; | |
3303 vpkt->vpkt_tgt_pkt->pkt_statistics |= STAT_ABORTED; | |
3304 | |
3305 pkt = vpkt->vpkt_hba_pkt; | |
3306 tpkt = vpkt->vpkt_tgt_pkt; | |
3307 } | |
3308 | |
3309 if ((err_str != NULL) && (pkt->pkt_reason != | |
3310 svp->svp_last_pkt_reason)) { | |
3311 cdip = vlun->svl_dip; | |
3312 pdip = mdi_pi_get_phci(vpkt->vpkt_path); | |
3313 vdip = ddi_get_parent(cdip); | |
3314 cpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3315 dpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3316 vhci_log(CE_WARN, vdip, "!%s (%s%d): %s on path %s (%s%d)", | |
3317 ddi_pathname(cdip, cpath), ddi_driver_name(cdip), | |
3318 ddi_get_instance(cdip), err_str, | |
3319 ddi_pathname(pdip, dpath), ddi_driver_name(pdip), | |
3320 ddi_get_instance(pdip)); | |
3321 kmem_free(cpath, MAXPATHLEN); | |
3322 kmem_free(dpath, MAXPATHLEN); | |
3323 } | |
3324 svp->svp_last_pkt_reason = pkt->pkt_reason; | |
3325 VHCI_DECR_PATH_CMDCOUNT(svp); | |
3326 | |
3327 /* | |
3328 * For PARTIAL_DMA, vhci should not free the path. | |
3329 * Target driver will call into vhci_scsi_dmafree or | |
3330 * destroy pkt to release this path. | |
3331 */ | |
3332 if ((vpkt->vpkt_flags & CFLAG_DMA_PARTIAL) == 0) { | |
3333 scsi_destroy_pkt(pkt); | |
3334 vpkt->vpkt_hba_pkt = NULL; | |
3335 if (vpkt->vpkt_path) { | |
3336 mdi_rele_path(vpkt->vpkt_path); | |
3337 vpkt->vpkt_path = NULL; | |
3338 } | |
3339 } | |
3340 | |
3341 if (tpkt->pkt_comp) { | |
3342 (*tpkt->pkt_comp)(tpkt); | |
3343 } | |
3344 } | |
3345 | |
3346 /* | |
3347 * two possibilities: (1) failover has completed | |
3348 * or (2) is in progress; update our path states for | |
3349 * the former case; for the latter case, | |
3350 * initiate a scsi_watch request to | |
3351 * determine when failover completes - vlun is HELD | |
3352 * until failover completes; BUSY is returned to upper | |
3353 * layer in both the cases | |
3354 */ | |
3355 static int | |
3356 vhci_handle_ext_fo(struct scsi_pkt *pkt, int fostat) | |
3357 { | |
3358 struct vhci_pkt *vpkt = (struct vhci_pkt *)pkt->pkt_private; | |
3359 struct scsi_pkt *tpkt; | |
3360 scsi_vhci_priv_t *svp; | |
3361 scsi_vhci_lun_t *vlun; | |
3362 struct scsi_vhci *vhci; | |
3363 scsi_vhci_swarg_t *swarg; | |
3364 char *path; | |
3365 | |
3366 ASSERT(vpkt != NULL); | |
3367 tpkt = vpkt->vpkt_tgt_pkt; | |
3368 ASSERT(tpkt != NULL); | |
3369 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(vpkt->vpkt_path); | |
3370 ASSERT(svp != NULL); | |
3371 vlun = svp->svp_svl; | |
3372 ASSERT(vlun != NULL); | |
3373 ASSERT(VHCI_LUN_IS_HELD(vlun)); | |
3374 | |
3375 vhci = ADDR2VHCI(&tpkt->pkt_address); | |
3376 | |
3377 if (fostat == SCSI_SENSE_INACTIVE) { | |
3378 VHCI_DEBUG(1, (CE_NOTE, NULL, "!Failover " | |
3379 "detected for %s; updating path states...\n", | |
3380 vlun->svl_lun_wwn)); | |
3381 /* | |
3382 * set the vlun flag to indicate to the task that the target | |
3383 * port group needs updating | |
3384 */ | |
3385 vlun->svl_flags |= VLUN_UPDATE_TPG; | |
3386 (void) taskq_dispatch(vhci->vhci_update_pathstates_taskq, | |
3387 vhci_update_pathstates, (void *)vlun, KM_SLEEP); | |
3388 } else { | |
3389 path = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3390 vhci_log(CE_NOTE, ddi_get_parent(vlun->svl_dip), | |
3391 "!%s (%s%d): Waiting for externally initiated failover " | |
3392 "to complete", ddi_pathname(vlun->svl_dip, path), | |
3393 ddi_driver_name(vlun->svl_dip), | |
3394 ddi_get_instance(vlun->svl_dip)); | |
3395 kmem_free(path, MAXPATHLEN); | |
3396 swarg = kmem_alloc(sizeof (*swarg), KM_NOSLEEP); | |
3397 if (swarg == NULL) { | |
3398 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_handle_ext_fo: " | |
3399 "request packet allocation for %s failed....\n", | |
3400 vlun->svl_lun_wwn)); | |
3401 VHCI_RELEASE_LUN(vlun); | |
3402 return (PKT_RETURN); | |
3403 } | |
3404 swarg->svs_svp = svp; | |
3405 swarg->svs_tos = ddi_get_time(); | |
3406 swarg->svs_pi = vpkt->vpkt_path; | |
3407 swarg->svs_release_lun = 0; | |
3408 swarg->svs_done = 0; | |
3409 /* | |
3410 * place a hold on the path...we don't want it to | |
3411 * vanish while scsi_watch is in progress | |
3412 */ | |
3413 mdi_hold_path(vpkt->vpkt_path); | |
3414 svp->svp_sw_token = scsi_watch_request_submit(svp->svp_psd, | |
3415 VHCI_FOWATCH_INTERVAL, SENSE_LENGTH, vhci_efo_watch_cb, | |
3416 (caddr_t)swarg); | |
3417 } | |
3418 return (BUSY_RETURN); | |
3419 } | |
3420 | |
3421 /* | |
3422 * vhci_efo_watch_cb: | |
3423 * Callback from scsi_watch request to check the failover status. | |
3424 * Completion is either due to successful failover or timeout. | |
3425 * Upon successful completion, vhci_update_path_states is called. | |
3426 * For timeout condition, vhci_efo_done is called. | |
3427 * Always returns 0 to scsi_watch to keep retrying till vhci_efo_done | |
3428 * terminates this request properly in a separate thread. | |
3429 */ | |
3430 | |
3431 static int | |
3432 vhci_efo_watch_cb(caddr_t arg, struct scsi_watch_result *resultp) | |
3433 { | |
3434 struct scsi_status *statusp = resultp->statusp; | |
3435 struct scsi_extended_sense *sensep = resultp->sensep; | |
3436 struct scsi_pkt *pkt = resultp->pkt; | |
3437 scsi_vhci_swarg_t *swarg; | |
3438 scsi_vhci_priv_t *svp; | |
3439 scsi_vhci_lun_t *vlun; | |
3440 struct scsi_vhci *vhci; | |
3441 dev_info_t *vdip; | |
3442 int rval, updt_paths; | |
3443 | |
3444 swarg = (scsi_vhci_swarg_t *)(uintptr_t)arg; | |
3445 svp = swarg->svs_svp; | |
3446 if (swarg->svs_done) { | |
3447 /* | |
3448 * Already completed failover or timedout. | |
3449 * Waiting for vhci_efo_done to terminate this scsi_watch. | |
3450 */ | |
3451 return (0); | |
3452 } | |
3453 | |
3454 ASSERT(svp != NULL); | |
3455 vlun = svp->svp_svl; | |
3456 ASSERT(vlun != NULL); | |
3457 ASSERT(VHCI_LUN_IS_HELD(vlun)); | |
3458 vlun->svl_efo_update_path = 0; | |
3459 vdip = ddi_get_parent(vlun->svl_dip); | |
3460 vhci = ddi_get_soft_state(vhci_softstate, | |
3461 ddi_get_instance(vdip)); | |
3462 | |
3463 updt_paths = 0; | |
3464 | |
3465 if (pkt->pkt_reason != CMD_CMPLT) { | |
3466 if ((ddi_get_time() - swarg->svs_tos) >= VHCI_EXTFO_TIMEOUT) { | |
3467 swarg->svs_release_lun = 1; | |
3468 goto done; | |
3469 } | |
3470 return (0); | |
3471 } | |
3472 if (*((unsigned char *)statusp) == STATUS_CHECK) { | |
3473 rval = (*(vlun->svl_fops->sfo_analyze_sense)) | |
3474 (svp->svp_psd, sensep, vlun->svl_fops_ctpriv); | |
3475 switch (rval) { | |
3476 /* | |
3477 * Only update path states in case path is definitely | |
3478 * inactive, or no failover occurred. For all other | |
3479 * check conditions continue pinging. A unexpected | |
3480 * check condition shouldn't cause pinging to complete | |
3481 * prematurely. | |
3482 */ | |
3483 case SCSI_SENSE_INACTIVE: | |
3484 case SCSI_SENSE_NOFAILOVER: | |
3485 updt_paths = 1; | |
3486 break; | |
3487 default: | |
3488 if ((ddi_get_time() - swarg->svs_tos) | |
3489 >= VHCI_EXTFO_TIMEOUT) { | |
3490 swarg->svs_release_lun = 1; | |
3491 goto done; | |
3492 } | |
3493 return (0); | |
3494 } | |
3495 } else if (*((unsigned char *)statusp) == | |
3496 STATUS_RESERVATION_CONFLICT) { | |
3497 updt_paths = 1; | |
3498 } else if ((*((unsigned char *)statusp)) & | |
3499 (STATUS_BUSY | STATUS_QFULL)) { | |
3500 return (0); | |
3501 } | |
3502 if ((*((unsigned char *)statusp) == STATUS_GOOD) || | |
3503 (updt_paths == 1)) { | |
3504 /* | |
3505 * we got here because we had detected an | |
3506 * externally initiated failover; things | |
3507 * have settled down now, so let's | |
3508 * start up a task to update the | |
3509 * path states and target port group | |
3510 */ | |
3511 vlun->svl_efo_update_path = 1; | |
3512 swarg->svs_done = 1; | |
3513 vlun->svl_swarg = swarg; | |
3514 vlun->svl_flags |= VLUN_UPDATE_TPG; | |
3515 (void) taskq_dispatch(vhci->vhci_update_pathstates_taskq, | |
3516 vhci_update_pathstates, (void *)vlun, | |
3517 KM_SLEEP); | |
3518 return (0); | |
3519 } | |
3520 if ((ddi_get_time() - swarg->svs_tos) >= VHCI_EXTFO_TIMEOUT) { | |
3521 swarg->svs_release_lun = 1; | |
3522 goto done; | |
3523 } | |
3524 return (0); | |
3525 done: | |
3526 swarg->svs_done = 1; | |
3527 (void) taskq_dispatch(vhci->vhci_taskq, | |
3528 vhci_efo_done, (void *)swarg, KM_SLEEP); | |
3529 return (0); | |
3530 } | |
3531 | |
3532 /* | |
3533 * vhci_efo_done: | |
3534 * cleanly terminates scsi_watch and free up resources. | |
3535 * Called as taskq function in vhci_efo_watch_cb for EFO timeout condition | |
3536 * or by vhci_update_path_states invoked during external initiated | |
3537 * failover completion. | |
3538 */ | |
3539 static void | |
3540 vhci_efo_done(void *arg) | |
3541 { | |
3542 scsi_vhci_lun_t *vlun; | |
3543 scsi_vhci_swarg_t *swarg = (scsi_vhci_swarg_t *)arg; | |
3544 scsi_vhci_priv_t *svp = swarg->svs_svp; | |
3545 ASSERT(svp); | |
3546 | |
3547 vlun = svp->svp_svl; | |
3548 ASSERT(vlun); | |
3549 | |
3550 /* Wait for clean termination of scsi_watch */ | |
3551 (void) scsi_watch_request_terminate(svp->svp_sw_token, | |
3552 SCSI_WATCH_TERMINATE_WAIT); | |
3553 svp->svp_sw_token = NULL; | |
3554 | |
3555 /* release path and freeup resources to indicate failover completion */ | |
3556 mdi_rele_path(swarg->svs_pi); | |
3557 if (swarg->svs_release_lun) { | |
3558 VHCI_RELEASE_LUN(vlun); | |
3559 } | |
3560 kmem_free((void *)swarg, sizeof (*swarg)); | |
3561 } | |
3562 | |
3563 /* | |
3564 * Update the path states | |
3565 * vlun should be HELD when this is invoked. | |
3566 * Calls vhci_efo_done to cleanup resources allocated for EFO. | |
3567 */ | |
3568 void | |
3569 vhci_update_pathstates(void *arg) | |
3570 { | |
3571 mdi_pathinfo_t *pip, *npip; | |
3572 dev_info_t *dip, *pdip; | |
3573 struct scsi_failover_ops *fo; | |
3574 struct scsi_vhci_priv *svp; | |
3575 struct scsi_device *psd; | |
3576 struct scsi_path_opinfo opinfo; | |
3577 char *pclass, *tptr; | |
3578 struct scsi_vhci_lun *vlun = (struct scsi_vhci_lun *)arg; | |
3579 int sps; /* mdi_select_path() status */ | |
3580 char *cpath, *dpath; | |
3581 struct scsi_vhci *vhci; | |
3582 struct scsi_pkt *pkt; | |
3583 struct buf *bp; | |
3584 int reserve_conflict = 0; | |
3585 | |
3586 ASSERT(VHCI_LUN_IS_HELD(vlun)); | |
3587 dip = vlun->svl_dip; | |
3588 pip = npip = NULL; | |
3589 | |
3590 vhci = ddi_get_soft_state(vhci_softstate, | |
3591 ddi_get_instance(ddi_get_parent(dip))); | |
3592 | |
3593 sps = mdi_select_path(dip, NULL, (MDI_SELECT_ONLINE_PATH | | |
3594 MDI_SELECT_STANDBY_PATH), NULL, &npip); | |
3595 if ((npip == NULL) || (sps != MDI_SUCCESS)) { | |
3596 goto done; | |
3597 } | |
3598 | |
3599 fo = vlun->svl_fops; | |
3600 do { | |
3601 pip = npip; | |
3602 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
3603 psd = svp->svp_psd; | |
3604 if ((*fo->sfo_path_get_opinfo)(psd, &opinfo, | |
3605 vlun->svl_fops_ctpriv) != 0) { | |
3606 sps = mdi_select_path(dip, NULL, | |
3607 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
3608 pip, &npip); | |
3609 mdi_rele_path(pip); | |
3610 continue; | |
3611 } | |
3612 | |
3613 if (mdi_prop_lookup_string(pip, "path-class", &pclass) != | |
3614 MDI_SUCCESS) { | |
3615 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
3616 "!vhci_update_pathstates: prop lookup failed for " | |
3617 "path 0x%p\n", (void *)pip)); | |
3618 sps = mdi_select_path(dip, NULL, | |
3619 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
3620 pip, &npip); | |
3621 mdi_rele_path(pip); | |
3622 continue; | |
3623 } | |
3624 | |
3625 /* | |
3626 * Need to update the "path-class" property | |
3627 * value in the device tree if different | |
3628 * from the existing value. | |
3629 */ | |
3630 if (strcmp(pclass, opinfo.opinfo_path_attr) != 0) { | |
3631 (void) mdi_prop_update_string(pip, "path-class", | |
3632 opinfo.opinfo_path_attr); | |
3633 } | |
3634 | |
3635 /* | |
3636 * Only change the state if needed. i.e. Don't call | |
3637 * mdi_pi_set_state to ONLINE a path if its already | |
3638 * ONLINE. Same for STANDBY paths. | |
3639 */ | |
3640 | |
3641 if ((opinfo.opinfo_path_state == SCSI_PATH_ACTIVE || | |
3642 opinfo.opinfo_path_state == SCSI_PATH_ACTIVE_NONOPT)) { | |
3643 if (!(MDI_PI_IS_ONLINE(pip))) { | |
3644 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
3645 "!vhci_update_pathstates: marking path" | |
3646 " 0x%p as ONLINE\n", (void *)pip)); | |
3647 pdip = mdi_pi_get_phci(pip); | |
3648 cpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3649 dpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3650 vhci_log(CE_NOTE, ddi_get_parent(dip), "!%s" | |
3651 " (%s%d): path %s (%s%d) target address %s" | |
3652 " is now ONLINE because of" | |
3653 " an externally initiated failover", | |
3654 ddi_pathname(dip, cpath), | |
3655 ddi_driver_name(dip), | |
3656 ddi_get_instance(dip), | |
3657 ddi_pathname(pdip, dpath), | |
3658 ddi_driver_name(pdip), | |
3659 ddi_get_instance(pdip), | |
3660 mdi_pi_get_addr(pip)); | |
3661 kmem_free(cpath, MAXPATHLEN); | |
3662 kmem_free(dpath, MAXPATHLEN); | |
3663 mdi_pi_set_state(pip, | |
3664 MDI_PATHINFO_STATE_ONLINE); | |
3665 mdi_pi_set_preferred(pip, | |
3666 opinfo.opinfo_preferred); | |
3667 tptr = kmem_alloc(strlen | |
3668 (opinfo.opinfo_path_attr)+1, KM_SLEEP); | |
3669 (void) strlcpy(tptr, opinfo.opinfo_path_attr, | |
3670 (strlen(opinfo.opinfo_path_attr)+1)); | |
3671 mutex_enter(&vlun->svl_mutex); | |
3672 if (vlun->svl_active_pclass != NULL) { | |
3673 kmem_free(vlun->svl_active_pclass, | |
3674 strlen(vlun->svl_active_pclass)+1); | |
3675 } | |
3676 vlun->svl_active_pclass = tptr; | |
3677 if (vlun->svl_waiting_for_activepath) { | |
3678 vlun->svl_waiting_for_activepath = 0; | |
3679 } | |
3680 mutex_exit(&vlun->svl_mutex); | |
3681 /* Check for Reservation Conflict */ | |
3682 bp = scsi_alloc_consistent_buf( | |
3683 &svp->svp_psd->sd_address, | |
3684 (struct buf *)NULL, DEV_BSIZE, B_READ, | |
3685 NULL, NULL); | |
3686 if (!bp) { | |
3687 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
3688 "vhci_update_pathstates: " | |
3689 "!No resources (buf)\n")); | |
3690 mdi_rele_path(pip); | |
3691 goto done; | |
3692 } | |
3693 pkt = scsi_init_pkt(&svp->svp_psd->sd_address, | |
3694 NULL, bp, CDB_GROUP1, | |
3695 sizeof (struct scsi_arq_status), 0, | |
3696 PKT_CONSISTENT, NULL, NULL); | |
3697 if (pkt) { | |
3698 (void) scsi_setup_cdb((union scsi_cdb *) | |
3699 (uintptr_t)pkt->pkt_cdbp, | |
3700 SCMD_READ, 1, 1, 0); | |
3701 pkt->pkt_time = 3*30; | |
3702 pkt->pkt_flags = FLAG_NOINTR; | |
3703 if ((scsi_transport(pkt) == | |
3704 TRAN_ACCEPT) && (pkt->pkt_reason | |
3705 == CMD_CMPLT) && (SCBP_C(pkt) == | |
3706 STATUS_RESERVATION_CONFLICT)) { | |
3707 reserve_conflict = 1; | |
3708 } | |
3709 scsi_destroy_pkt(pkt); | |
3710 } | |
3711 scsi_free_consistent_buf(bp); | |
3712 } else if (MDI_PI_IS_ONLINE(pip)) { | |
3713 if (strcmp(pclass, opinfo.opinfo_path_attr) | |
3714 != 0) { | |
3715 mdi_pi_set_preferred(pip, | |
3716 opinfo.opinfo_preferred); | |
3717 mutex_enter(&vlun->svl_mutex); | |
3718 if (vlun->svl_active_pclass == NULL || | |
3719 strcmp(opinfo.opinfo_path_attr, | |
3720 vlun->svl_active_pclass) != 0) { | |
3721 mutex_exit(&vlun->svl_mutex); | |
3722 tptr = kmem_alloc(strlen | |
3723 (opinfo.opinfo_path_attr)+1, | |
3724 KM_SLEEP); | |
3725 (void) strlcpy(tptr, | |
3726 opinfo.opinfo_path_attr, | |
3727 (strlen | |
3728 (opinfo.opinfo_path_attr) | |
3729 +1)); | |
3730 mutex_enter(&vlun->svl_mutex); | |
3731 } else { | |
3732 /* | |
3733 * No need to update | |
3734 * svl_active_pclass | |
3735 */ | |
3736 tptr = NULL; | |
3737 mutex_exit(&vlun->svl_mutex); | |
3738 } | |
3739 if (tptr) { | |
3740 if (vlun->svl_active_pclass | |
3741 != NULL) { | |
3742 kmem_free(vlun-> | |
3743 svl_active_pclass, | |
3744 strlen(vlun-> | |
3745 svl_active_pclass) | |
3746 +1); | |
3747 } | |
3748 vlun->svl_active_pclass = tptr; | |
3749 mutex_exit(&vlun->svl_mutex); | |
3750 } | |
3751 } | |
3752 } | |
3753 } else if ((opinfo.opinfo_path_state == SCSI_PATH_INACTIVE) && | |
3754 !(MDI_PI_IS_STANDBY(pip))) { | |
3755 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
3756 "!vhci_update_pathstates: marking path" | |
3757 " 0x%p as STANDBY\n", (void *)pip)); | |
3758 pdip = mdi_pi_get_phci(pip); | |
3759 cpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3760 dpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | |
3761 vhci_log(CE_NOTE, ddi_get_parent(dip), "!%s" | |
3762 " (%s%d): path %s (%s%d) target address %s" | |
3763 " is now STANDBY because of" | |
3764 " an externally initiated failover", | |
3765 ddi_pathname(dip, cpath), | |
3766 ddi_driver_name(dip), | |
3767 ddi_get_instance(dip), | |
3768 ddi_pathname(pdip, dpath), | |
3769 ddi_driver_name(pdip), | |
3770 ddi_get_instance(pdip), | |
3771 mdi_pi_get_addr(pip)); | |
3772 kmem_free(cpath, MAXPATHLEN); | |
3773 kmem_free(dpath, MAXPATHLEN); | |
3774 mdi_pi_set_state(pip, | |
3775 MDI_PATHINFO_STATE_STANDBY); | |
3776 mdi_pi_set_preferred(pip, | |
3777 opinfo.opinfo_preferred); | |
3778 mutex_enter(&vlun->svl_mutex); | |
3779 if (vlun->svl_active_pclass != NULL) { | |
3780 if (strcmp(vlun->svl_active_pclass, | |
3781 opinfo.opinfo_path_attr) == 0) { | |
3782 kmem_free(vlun-> | |
3783 svl_active_pclass, | |
3784 strlen(vlun-> | |
3785 svl_active_pclass)+1); | |
3786 vlun->svl_active_pclass = NULL; | |
3787 } | |
3788 } | |
3789 mutex_exit(&vlun->svl_mutex); | |
3790 } | |
3791 (void) mdi_prop_free(pclass); | |
3792 sps = mdi_select_path(dip, NULL, | |
3793 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
3794 pip, &npip); | |
3795 mdi_rele_path(pip); | |
3796 | |
3797 } while ((npip != NULL) && (sps == MDI_SUCCESS)); | |
3798 | |
3799 /* | |
3800 * Check to see if this vlun has an active SCSI-II RESERVE. If so | |
3801 * clear the reservation by sending a reset, so the host doesn't | |
3802 * receive a reservation conflict. | |
3803 * Reset VLUN_RESERVE_ACTIVE_FLG for this vlun. Also notify ssd | |
3804 * of the reset, explicitly. | |
3805 */ | |
3806 if (vlun->svl_flags & VLUN_RESERVE_ACTIVE_FLG) { | |
3807 if (reserve_conflict && (vlun->svl_xlf_capable == 0)) { | |
3808 (void) vhci_recovery_reset(vlun, | |
3809 &svp->svp_psd->sd_address, FALSE, | |
3810 VHCI_DEPTH_TARGET); | |
3811 } | |
3812 vlun->svl_flags &= ~VLUN_RESERVE_ACTIVE_FLG; | |
3813 mutex_enter(&vhci->vhci_mutex); | |
3814 scsi_hba_reset_notify_callback(&vhci->vhci_mutex, | |
3815 &vhci->vhci_reset_notify_listf); | |
3816 mutex_exit(&vhci->vhci_mutex); | |
3817 } | |
3818 if (vlun->svl_flags & VLUN_UPDATE_TPG) { | |
3819 /* | |
3820 * Update the AccessState of related MP-API TPGs | |
3821 */ | |
3822 (void) vhci_mpapi_update_tpg_acc_state_for_lu(vhci, vlun); | |
3823 vlun->svl_flags &= ~VLUN_UPDATE_TPG; | |
3824 } | |
3825 done: | |
3826 if (vlun->svl_efo_update_path) { | |
3827 vlun->svl_efo_update_path = 0; | |
3828 vhci_efo_done(vlun->svl_swarg); | |
3829 vlun->svl_swarg = 0; | |
3830 } | |
3831 VHCI_RELEASE_LUN(vlun); | |
3832 } | |
3833 | |
3834 /* ARGSUSED */ | |
3835 static int | |
3836 vhci_pathinfo_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) | |
3837 { | |
3838 scsi_hba_tran_t *hba = NULL; | |
3839 struct scsi_device *psd = NULL; | |
3840 scsi_vhci_lun_t *vlun = NULL; | |
3841 dev_info_t *pdip = NULL; | |
3842 dev_info_t *tgt_dip; | |
3843 struct scsi_vhci *vhci; | |
3844 char *guid; | |
3845 scsi_vhci_priv_t *svp = NULL; | |
3846 int rval = MDI_FAILURE; | |
3847 int vlun_alloced = 0; | |
3848 | |
3849 ASSERT(vdip != NULL); | |
3850 ASSERT(pip != NULL); | |
3851 | |
3852 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(vdip)); | |
3853 ASSERT(vhci != NULL); | |
3854 | |
3855 pdip = mdi_pi_get_phci(pip); | |
3856 ASSERT(pdip != NULL); | |
3857 | |
3858 hba = ddi_get_driver_private(pdip); | |
3859 ASSERT(hba != NULL); | |
3860 | |
3861 tgt_dip = mdi_pi_get_client(pip); | |
3862 ASSERT(tgt_dip != NULL); | |
3863 | |
3864 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, tgt_dip, PROPFLAGS, | |
3865 MDI_CLIENT_GUID_PROP, &guid) != DDI_SUCCESS) { | |
3866 VHCI_DEBUG(1, (CE_WARN, NULL, | |
3867 "vhci_pathinfo_init: lun guid property failed")); | |
3868 goto failure; | |
3869 } | |
3870 | |
3871 vlun = vhci_lun_lookup_alloc(tgt_dip, guid, &vlun_alloced); | |
3872 ddi_prop_free(guid); | |
3873 | |
3874 vlun->svl_dip = tgt_dip; | |
3875 | |
3876 svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); | |
3877 svp->svp_svl = vlun; | |
3878 | |
3879 vlun->svl_lb_policy_save = mdi_get_lb_policy(tgt_dip); | |
3880 mutex_init(&svp->svp_mutex, NULL, MUTEX_DRIVER, NULL); | |
3881 cv_init(&svp->svp_cv, NULL, CV_DRIVER, NULL); | |
3882 | |
3883 psd = kmem_zalloc(sizeof (*psd), KM_SLEEP); | |
3884 mutex_init(&psd->sd_mutex, NULL, MUTEX_DRIVER, NULL); | |
3885 | |
3886 /* | |
3887 * Clone transport structure if requested, so | |
3888 * Self enumerating HBAs always need to use cloning | |
3889 */ | |
3890 | |
3891 if (hba->tran_hba_flags & SCSI_HBA_TRAN_CLONE) { | |
3892 scsi_hba_tran_t *clone = | |
3893 kmem_alloc(sizeof (scsi_hba_tran_t), KM_SLEEP); | |
3894 bcopy(hba, clone, sizeof (scsi_hba_tran_t)); | |
3895 hba = clone; | |
3896 hba->tran_sd = psd; | |
3897 } else { | |
3898 ASSERT(hba->tran_sd == NULL); | |
3899 } | |
3900 psd->sd_dev = tgt_dip; | |
3901 psd->sd_address.a_hba_tran = hba; | |
3902 psd->sd_private = (caddr_t)pip; | |
3903 svp->svp_psd = psd; | |
3904 mdi_pi_set_vhci_private(pip, (caddr_t)svp); | |
3905 | |
3906 /* | |
3907 * call hba's target init entry point if it exists | |
3908 */ | |
3909 if (hba->tran_tgt_init != NULL) { | |
3910 if ((rval = (*hba->tran_tgt_init)(pdip, tgt_dip, | |
3911 hba, psd)) != DDI_SUCCESS) { | |
3912 VHCI_DEBUG(1, (CE_WARN, pdip, | |
3913 "!vhci_pathinfo_init: tran_tgt_init failed for " | |
3914 "path=0x%p rval=%x", (void *)pip, rval)); | |
3915 goto failure; | |
3916 } | |
3917 } | |
3918 | |
3919 svp->svp_new_path = 1; | |
3920 | |
3921 psd->sd_inq = NULL; | |
3922 | |
3923 VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_pathinfo_init: path:%p\n", | |
3924 (void *)pip)); | |
3925 return (MDI_SUCCESS); | |
3926 | |
3927 failure: | |
3928 if (psd) { | |
3929 mutex_destroy(&psd->sd_mutex); | |
3930 kmem_free(psd, sizeof (*psd)); | |
3931 } | |
3932 if (svp) { | |
3933 mdi_pi_set_vhci_private(pip, NULL); | |
3934 mutex_destroy(&svp->svp_mutex); | |
3935 cv_destroy(&svp->svp_cv); | |
3936 kmem_free(svp, sizeof (*svp)); | |
3937 } | |
3938 if (hba && hba->tran_hba_flags & SCSI_HBA_TRAN_CLONE) | |
3939 kmem_free(hba, sizeof (scsi_hba_tran_t)); | |
3940 | |
3941 if (vlun_alloced) | |
3942 vhci_lun_free(tgt_dip); | |
3943 | |
3944 return (rval); | |
3945 } | |
3946 | |
3947 /* ARGSUSED */ | |
3948 static int | |
3949 vhci_pathinfo_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) | |
3950 { | |
3951 scsi_hba_tran_t *hba = NULL; | |
3952 struct scsi_device *psd = NULL; | |
3953 dev_info_t *pdip = NULL; | |
3954 dev_info_t *cdip = NULL; | |
3955 scsi_vhci_priv_t *svp = NULL; | |
3956 | |
3957 ASSERT(vdip != NULL); | |
3958 ASSERT(pip != NULL); | |
3959 | |
3960 pdip = mdi_pi_get_phci(pip); | |
3961 ASSERT(pdip != NULL); | |
3962 | |
3963 cdip = mdi_pi_get_client(pip); | |
3964 ASSERT(cdip != NULL); | |
3965 | |
3966 hba = ddi_get_driver_private(pdip); | |
3967 ASSERT(hba != NULL); | |
3968 | |
3969 vhci_mpapi_set_path_state(vdip, pip, MP_DRVR_PATH_STATE_REMOVED); | |
3970 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
3971 if (svp == NULL) { | |
3972 /* path already freed. Nothing to do. */ | |
3973 return (MDI_SUCCESS); | |
3974 } | |
3975 | |
3976 psd = svp->svp_psd; | |
3977 ASSERT(psd != NULL); | |
3978 | |
3979 if (hba->tran_hba_flags & SCSI_HBA_TRAN_CLONE) { | |
3980 hba = psd->sd_address.a_hba_tran; | |
3981 ASSERT(hba->tran_hba_flags & SCSI_HBA_TRAN_CLONE); | |
3982 ASSERT(hba->tran_sd == psd); | |
3983 } else { | |
3984 ASSERT(hba->tran_sd == NULL); | |
3985 } | |
3986 | |
3987 if (hba->tran_tgt_free != NULL) { | |
3988 (*hba->tran_tgt_free) (pdip, cdip, hba, psd); | |
3989 } | |
3990 mutex_destroy(&psd->sd_mutex); | |
3991 if (hba->tran_hba_flags & SCSI_HBA_TRAN_CLONE) { | |
3992 kmem_free(hba, sizeof (*hba)); | |
3993 } | |
3994 | |
3995 mdi_pi_set_vhci_private(pip, NULL); | |
3996 kmem_free((caddr_t)psd, sizeof (*psd)); | |
3997 | |
3998 mutex_destroy(&svp->svp_mutex); | |
3999 cv_destroy(&svp->svp_cv); | |
4000 kmem_free((caddr_t)svp, sizeof (*svp)); | |
4001 | |
4002 /* | |
4003 * If this is the last path to the client, | |
4004 * then free up the vlun as well. | |
4005 */ | |
4006 if (mdi_client_get_path_count(cdip) == 1) { | |
4007 vhci_lun_free(cdip); | |
4008 } | |
4009 | |
4010 VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_pathinfo_uninit: path=0x%p\n", | |
4011 (void *)pip)); | |
4012 return (MDI_SUCCESS); | |
4013 } | |
4014 | |
4015 /* ARGSUSED */ | |
4016 static int | |
4017 vhci_pathinfo_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip, | |
4018 mdi_pathinfo_state_t state, uint32_t ext_state, int flags) | |
4019 { | |
4020 int rval = MDI_SUCCESS; | |
4021 scsi_vhci_priv_t *svp; | |
4022 scsi_vhci_lun_t *vlun; | |
4023 int held; | |
4024 int op = (flags & 0xf00) >> 8; | |
4025 struct scsi_vhci *vhci; | |
4026 | |
4027 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(vdip)); | |
4028 | |
4029 if (flags & MDI_EXT_STATE_CHANGE) { | |
4030 /* | |
4031 * We do not want to issue any commands down the path in case | |
4032 * sync flag is set. Lower layers might not be ready to accept | |
4033 * any I/O commands. | |
4034 */ | |
4035 if (op == DRIVER_DISABLE) | |
4036 return (MDI_SUCCESS); | |
4037 | |
4038 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
4039 if (svp == NULL) { | |
4040 return (MDI_FAILURE); | |
4041 } | |
4042 vlun = svp->svp_svl; | |
4043 | |
4044 if (flags & MDI_BEFORE_STATE_CHANGE) { | |
4045 /* | |
4046 * Hold the LUN. | |
4047 */ | |
4048 VHCI_HOLD_LUN(vlun, VH_SLEEP, held); | |
4049 if (flags & MDI_DISABLE_OP) { | |
4050 /* | |
4051 * Issue scsi reset if it happens to be | |
4052 * reserved path. | |
4053 */ | |
4054 if (vlun->svl_flags & VLUN_RESERVE_ACTIVE_FLG) { | |
4055 /* | |
4056 * if reservation pending on | |
4057 * this path, dont' mark the | |
4058 * path busy | |
4059 */ | |
4060 if (op == DRIVER_DISABLE_TRANSIENT) { | |
4061 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
4062 "!vhci_pathinfo" | |
4063 "_state_change (pip:%p): " | |
4064 " reservation: fail busy\n", | |
4065 (void *)pip)); | |
4066 return (MDI_FAILURE); | |
4067 } | |
4068 if (pip == vlun->svl_resrv_pip) { | |
4069 if (vhci_recovery_reset( | |
4070 svp->svp_svl, | |
4071 &svp->svp_psd->sd_address, | |
4072 TRUE, | |
4073 VHCI_DEPTH_TARGET) == 0) { | |
4074 VHCI_DEBUG(1, | |
4075 (CE_NOTE, NULL, | |
4076 "!vhci_pathinfo" | |
4077 "_state_change " | |
4078 " (pip:%p): " | |
4079 "reset failed, " | |
4080 "give up!\n", | |
4081 (void *)pip)); | |
4082 } | |
4083 vlun->svl_flags &= | |
4084 ~VLUN_RESERVE_ACTIVE_FLG; | |
4085 } | |
4086 } | |
4087 } else if (flags & MDI_ENABLE_OP) { | |
4088 if (((vhci->vhci_conf_flags & | |
4089 VHCI_CONF_FLAGS_AUTO_FAILBACK) == | |
4090 VHCI_CONF_FLAGS_AUTO_FAILBACK) && | |
4091 MDI_PI_IS_USER_DISABLE(pip) && | |
4092 MDI_PI_IS_STANDBY(pip)) { | |
4093 struct scsi_failover_ops *fo; | |
4094 char *best_pclass, *pclass = NULL; | |
4095 int best_class, rv; | |
4096 /* | |
4097 * Failback if enabling a standby path | |
4098 * and it is the primary class or | |
4099 * preferred class | |
4100 */ | |
4101 best_class = mdi_pi_get_preferred(pip); | |
4102 if (best_class == 0) { | |
4103 /* | |
4104 * if not preferred - compare | |
4105 * path-class with class | |
4106 */ | |
4107 fo = vlun->svl_fops; | |
4108 (*fo->sfo_pathclass_next)(NULL, | |
4109 &best_pclass, | |
4110 vlun->svl_fops_ctpriv); | |
4111 pclass = NULL; | |
4112 rv = mdi_prop_lookup_string(pip, | |
4113 "path-class", &pclass); | |
4114 if (rv != MDI_SUCCESS || | |
4115 pclass == NULL) { | |
4116 vhci_log(CE_NOTE, vdip, | |
4117 "!path-class " | |
4118 " lookup " | |
4119 "failed. rv: %d" | |
4120 "class: %p", rv, | |
4121 (void *)pclass); | |
4122 } else if (strncmp(pclass, | |
4123 best_pclass, | |
4124 strlen(best_pclass)) == 0) { | |
4125 best_class = 1; | |
4126 } | |
4127 if (rv == MDI_SUCCESS && | |
4128 pclass != NULL) { | |
4129 rv = mdi_prop_free( | |
4130 pclass); | |
4131 if (rv != | |
4132 DDI_PROP_SUCCESS) { | |
4133 vhci_log( | |
4134 CE_NOTE, | |
4135 vdip, | |
4136 "!path-" | |
4137 "class" | |
4138 " free" | |
4139 " failed" | |
4140 " rv: %d" | |
4141 " class: " | |
4142 "%p", | |
4143 rv, | |
4144 (void *) | |
4145 pclass); | |
4146 } | |
4147 } | |
4148 } | |
4149 if (best_class == 1) { | |
4150 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
4151 "preferred path: %p " | |
4152 "USER_DISABLE->USER_ENABLE " | |
4153 "transition for lun %s\n", | |
4154 (void *)pip, | |
4155 vlun->svl_lun_wwn)); | |
4156 (void) taskq_dispatch( | |
4157 vhci->vhci_taskq, | |
4158 vhci_initiate_auto_failback, | |
4159 (void *) vlun, KM_SLEEP); | |
4160 } | |
4161 } | |
4162 /* | |
4163 * if PGR is active, revalidate key and | |
4164 * register on this path also, if key is | |
4165 * still valid | |
4166 */ | |
4167 sema_p(&vlun->svl_pgr_sema); | |
4168 if (vlun->svl_pgr_active) | |
4169 (void) | |
4170 vhci_pgr_validate_and_register(svp); | |
4171 sema_v(&vlun->svl_pgr_sema); | |
4172 /* | |
4173 * Inform target driver about any | |
4174 * reservations to be reinstated if target | |
4175 * has dropped reservation during the busy | |
4176 * period. | |
4177 */ | |
4178 mutex_enter(&vhci->vhci_mutex); | |
4179 scsi_hba_reset_notify_callback( | |
4180 &vhci->vhci_mutex, | |
4181 &vhci->vhci_reset_notify_listf); | |
4182 mutex_exit(&vhci->vhci_mutex); | |
4183 } | |
4184 } | |
4185 if (flags & MDI_AFTER_STATE_CHANGE) { | |
4186 if (flags & MDI_ENABLE_OP) { | |
4187 mutex_enter(&vhci_global_mutex); | |
4188 cv_broadcast(&vhci_cv); | |
4189 mutex_exit(&vhci_global_mutex); | |
4190 } | |
4191 if (vlun->svl_setcap_done) { | |
4192 (void) vhci_pHCI_cap(&svp->svp_psd->sd_address, | |
4193 "sector-size", vlun->svl_sector_size, | |
4194 1, pip); | |
4195 } | |
4196 | |
4197 /* | |
4198 * Release the LUN | |
4199 */ | |
4200 VHCI_RELEASE_LUN(vlun); | |
4201 | |
4202 /* | |
4203 * Path transition is complete. | |
4204 * Run callback to indicate target driver to | |
4205 * retry to prevent IO starvation. | |
4206 */ | |
4207 if (scsi_callback_id != 0) { | |
4208 ddi_run_callback(&scsi_callback_id); | |
4209 } | |
4210 } | |
4211 } else { | |
4212 switch (state) { | |
4213 case MDI_PATHINFO_STATE_ONLINE: | |
4214 rval = vhci_pathinfo_online(vdip, pip, flags); | |
4215 break; | |
4216 | |
4217 case MDI_PATHINFO_STATE_OFFLINE: | |
4218 rval = vhci_pathinfo_offline(vdip, pip, flags); | |
4219 break; | |
4220 | |
4221 default: | |
4222 break; | |
4223 } | |
4224 /* | |
4225 * Path transition is complete. | |
4226 * Run callback to indicate target driver to | |
4227 * retry to prevent IO starvation. | |
4228 */ | |
4229 if ((rval == MDI_SUCCESS) && (scsi_callback_id != 0)) { | |
4230 ddi_run_callback(&scsi_callback_id); | |
4231 } | |
4232 return (rval); | |
4233 } | |
4234 | |
4235 return (MDI_SUCCESS); | |
4236 } | |
4237 | |
4238 /* | |
4239 * Parse the mpxio load balancing options. The datanameptr | |
4240 * will point to a string containing the load-balance-options value. | |
4241 * The load-balance-options value will be a property that | |
4242 * defines the load-balance algorithm and any arguments to that | |
4243 * algorithm. | |
4244 * For example: | |
4245 * device-type-mpxio-options-list= | |
4246 * "device-type=SUN SENA", "load-balance-options=logical-block-options" | |
4247 * "device-type=SUN SE6920", "round-robin-options"; | |
4248 * logical-block-options="load-balance=logical-block", "region-size=15"; | |
4249 * round-robin-options="load-balance=round-robin"; | |
4250 * | |
4251 * If the load-balance is not defined the load balance algorithm will | |
4252 * default to the global setting. There will be default values assigned | |
4253 * to the arguments (region-size=18) and if an argument is one | |
4254 * that is not known, it will be ignored. | |
4255 */ | |
4256 static void | |
4257 vhci_parse_mpxio_lb_options(dev_info_t *dip, dev_info_t *cdip, | |
4258 caddr_t datanameptr) | |
4259 { | |
4260 char *dataptr, *next_entry; | |
4261 caddr_t config_list = NULL; | |
4262 int config_list_len = 0, list_len = 0; | |
4263 int region_size = -1; | |
4264 client_lb_t load_balance; | |
4265 | |
4266 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, datanameptr, | |
4267 (caddr_t)&config_list, &config_list_len) != DDI_PROP_SUCCESS) { | |
4268 return; | |
4269 } | |
4270 | |
4271 list_len = config_list_len; | |
4272 next_entry = config_list; | |
4273 while (config_list_len > 0) { | |
4274 dataptr = next_entry; | |
4275 | |
4276 if (strncmp(mdi_load_balance, dataptr, | |
4277 strlen(mdi_load_balance)) == 0) { | |
4278 /* get the load-balance scheme */ | |
4279 dataptr += strlen(mdi_load_balance) + 1; | |
4280 if (strcmp(dataptr, LOAD_BALANCE_PROP_RR) == 0) { | |
4281 (void) mdi_set_lb_policy(cdip, LOAD_BALANCE_RR); | |
4282 load_balance = LOAD_BALANCE_RR; | |
4283 } else if (strcmp(dataptr, | |
4284 LOAD_BALANCE_PROP_LBA) == 0) { | |
4285 (void) mdi_set_lb_policy(cdip, | |
4286 LOAD_BALANCE_LBA); | |
4287 load_balance = LOAD_BALANCE_LBA; | |
4288 } else if (strcmp(dataptr, | |
4289 LOAD_BALANCE_PROP_NONE) == 0) { | |
4290 (void) mdi_set_lb_policy(cdip, | |
4291 LOAD_BALANCE_NONE); | |
4292 load_balance = LOAD_BALANCE_NONE; | |
4293 } | |
4294 } else if (strncmp(dataptr, LOGICAL_BLOCK_REGION_SIZE, | |
4295 strlen(LOGICAL_BLOCK_REGION_SIZE)) == 0) { | |
4296 int i = 0; | |
4297 char *ptr; | |
4298 char *tmp; | |
4299 | |
4300 tmp = dataptr + (strlen(LOGICAL_BLOCK_REGION_SIZE) + 1); | |
4301 /* check for numeric value */ | |
4302 for (ptr = tmp; i < strlen(tmp); i++, ptr++) { | |
4303 if (!isdigit(*ptr)) { | |
4304 cmn_err(CE_WARN, | |
4305 "Illegal region size: %s." | |
4306 " Setting to default value: %d", | |
4307 tmp, | |
4308 LOAD_BALANCE_DEFAULT_REGION_SIZE); | |
4309 region_size = | |
4310 LOAD_BALANCE_DEFAULT_REGION_SIZE; | |
4311 break; | |
4312 } | |
4313 } | |
4314 if (i >= strlen(tmp)) { | |
4315 region_size = stoi(&tmp); | |
4316 } | |
4317 (void) mdi_set_lb_region_size(cdip, region_size); | |
4318 } | |
4319 config_list_len -= (strlen(next_entry) + 1); | |
4320 next_entry += strlen(next_entry) + 1; | |
4321 } | |
4322 #ifdef DEBUG | |
4323 if ((region_size >= 0) && (load_balance != LOAD_BALANCE_LBA)) { | |
4324 VHCI_DEBUG(1, (CE_NOTE, dip, | |
4325 "!vhci_parse_mpxio_lb_options: region-size: %d" | |
4326 "only valid for load-balance=logical-block\n", | |
4327 region_size)); | |
4328 } | |
4329 #endif | |
4330 if ((region_size == -1) && (load_balance == LOAD_BALANCE_LBA)) { | |
4331 VHCI_DEBUG(1, (CE_NOTE, dip, | |
4332 "!vhci_parse_mpxio_lb_options: No region-size" | |
4333 " defined load-balance=logical-block." | |
4334 " Default to: %d\n", LOAD_BALANCE_DEFAULT_REGION_SIZE)); | |
4335 (void) mdi_set_lb_region_size(cdip, | |
4336 LOAD_BALANCE_DEFAULT_REGION_SIZE); | |
4337 } | |
4338 if (list_len > 0) { | |
4339 kmem_free(config_list, list_len); | |
4340 } | |
4341 } | |
4342 | |
4343 /* | |
4344 * Parse the device-type-mpxio-options-list looking for the key of | |
4345 * "load-balance-options". If found, parse the load balancing options. | |
4346 * Check the comment of the vhci_get_device_type_mpxio_options() | |
4347 * for the device-type-mpxio-options-list. | |
4348 */ | |
4349 static void | |
4350 vhci_parse_mpxio_options(dev_info_t *dip, dev_info_t *cdip, | |
4351 caddr_t datanameptr, int list_len) | |
4352 { | |
4353 char *dataptr; | |
4354 int len; | |
4355 | |
4356 /* | |
4357 * get the data list | |
4358 */ | |
4359 dataptr = datanameptr; | |
4360 len = 0; | |
4361 while (len < list_len && | |
4362 strncmp(dataptr, DEVICE_TYPE_STR, strlen(DEVICE_TYPE_STR)) | |
4363 != 0) { | |
4364 if (strncmp(dataptr, LOAD_BALANCE_OPTIONS, | |
4365 strlen(LOAD_BALANCE_OPTIONS)) == 0) { | |
4366 len += strlen(LOAD_BALANCE_OPTIONS) + 1; | |
4367 dataptr += strlen(LOAD_BALANCE_OPTIONS) + 1; | |
4368 vhci_parse_mpxio_lb_options(dip, cdip, dataptr); | |
4369 } | |
4370 len += strlen(dataptr) + 1; | |
4371 dataptr += strlen(dataptr) + 1; | |
4372 } | |
4373 } | |
4374 | |
4375 /* | |
4376 * Check the inquriy string returned from the device wiith the device-type | |
4377 * Check for the existence of the device-type-mpxio-options-list and | |
4378 * if found parse the list checking for a match with the device-type | |
4379 * value and the inquiry string returned from the device. If a match | |
4380 * is found, parse the mpxio options list. The format of the | |
4381 * device-type-mpxio-options-list is: | |
4382 * device-type-mpxio-options-list= | |
4383 * "device-type=SUN SENA", "load-balance-options=logical-block-options" | |
4384 * "device-type=SUN SE6920", "round-robin-options"; | |
4385 * logical-block-options="load-balance=logical-block", "region-size=15"; | |
4386 * round-robin-options="load-balance=round-robin"; | |
4387 */ | |
4388 void | |
4389 vhci_get_device_type_mpxio_options(dev_info_t *dip, dev_info_t *cdip, | |
4390 struct scsi_device *devp) | |
4391 { | |
4392 | |
4393 caddr_t config_list = NULL; | |
4394 caddr_t vidptr, datanameptr; | |
4395 int vidlen, dupletlen = 0; | |
4396 int config_list_len = 0, len; | |
4397 struct scsi_inquiry *inq = devp->sd_inq; | |
4398 | |
4399 /* | |
4400 * look up the device-type-mpxio-options-list and walk thru | |
4401 * the list compare the vendor ids of the earlier inquiry command and | |
4402 * with those vids in the list if there is a match, lookup | |
4403 * the mpxio-options value | |
4404 */ | |
4405 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, | |
4406 MPXIO_OPTIONS_LIST, | |
4407 (caddr_t)&config_list, &config_list_len) == DDI_PROP_SUCCESS) { | |
4408 | |
4409 /* | |
4410 * Compare vids in each duplet - if it matches, | |
4411 * parse the mpxio options list. | |
4412 */ | |
4413 for (len = config_list_len, vidptr = config_list; len > 0; | |
4414 len -= dupletlen) { | |
4415 | |
4416 dupletlen = 0; | |
4417 | |
4418 if (strlen(vidptr) != 0 && | |
4419 strncmp(vidptr, DEVICE_TYPE_STR, | |
4420 strlen(DEVICE_TYPE_STR)) == 0) { | |
4421 /* point to next duplet */ | |
4422 datanameptr = vidptr + strlen(vidptr) + 1; | |
4423 /* add len of this duplet */ | |
4424 dupletlen += strlen(vidptr) + 1; | |
4425 /* get to device type */ | |
4426 vidptr += strlen(DEVICE_TYPE_STR) + 1; | |
4427 vidlen = strlen(vidptr); | |
4428 if ((vidlen != 0) && | |
4429 bcmp(inq->inq_vid, vidptr, vidlen) == 0) { | |
4430 vhci_parse_mpxio_options(dip, cdip, | |
4431 datanameptr, len - dupletlen); | |
4432 break; | |
4433 } | |
4434 /* get to next duplet */ | |
4435 vidptr += strlen(vidptr) + 1; | |
4436 } | |
4437 /* get to the next device-type */ | |
4438 while (len - dupletlen > 0 && | |
4439 strlen(vidptr) != 0 && | |
4440 strncmp(vidptr, DEVICE_TYPE_STR, | |
4441 strlen(DEVICE_TYPE_STR)) != 0) { | |
4442 dupletlen += strlen(vidptr) + 1; | |
4443 vidptr += strlen(vidptr) + 1; | |
4444 } | |
4445 } | |
4446 if (config_list_len > 0) { | |
4447 kmem_free(config_list, config_list_len); | |
4448 } | |
4449 } | |
4450 } | |
4451 | |
4452 static int | |
4453 vhci_update_pathinfo(struct scsi_device *psd, mdi_pathinfo_t *pip, | |
4454 struct scsi_failover_ops *fo, | |
4455 scsi_vhci_lun_t *vlun, | |
4456 struct scsi_vhci *vhci) | |
4457 { | |
4458 struct scsi_path_opinfo opinfo; | |
4459 char *pclass, *best_pclass; | |
4460 | |
4461 if ((*fo->sfo_path_get_opinfo)(psd, &opinfo, | |
4462 vlun->svl_fops_ctpriv) != 0) { | |
4463 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_update_pathinfo: " | |
4464 "Failed to get operation info for path:%p\n", (void *)pip)); | |
4465 return (MDI_FAILURE); | |
4466 } | |
4467 /* set the xlf capable flag in the vlun for future use */ | |
4468 vlun->svl_xlf_capable = opinfo.opinfo_xlf_capable; | |
4469 (void) mdi_prop_update_string(pip, "path-class", | |
4470 opinfo.opinfo_path_attr); | |
4471 | |
4472 pclass = opinfo.opinfo_path_attr; | |
4473 if (opinfo.opinfo_path_state == SCSI_PATH_ACTIVE) { | |
4474 mutex_enter(&vlun->svl_mutex); | |
4475 if (vlun->svl_active_pclass != NULL) { | |
4476 if (strcmp(vlun->svl_active_pclass, pclass) != 0) { | |
4477 mutex_exit(&vlun->svl_mutex); | |
4478 /* | |
4479 * Externally initiated failover has happened; | |
4480 * force the path state to be STANDBY/ONLINE, | |
4481 * next IO will trigger failover and thus | |
4482 * sync-up the pathstates. Reason we don't | |
4483 * sync-up immediately by invoking | |
4484 * vhci_update_pathstates() is because it | |
4485 * needs a VHCI_HOLD_LUN() and we don't | |
4486 * want to block here. | |
4487 * | |
4488 * Further, if the device is an ALUA device, | |
4489 * then failure to exactly match 'pclass' and | |
4490 * 'svl_active_pclass'(as is the case here) | |
4491 * indicates that the currently active path | |
4492 * is a 'non-optimized' path - which means | |
4493 * that 'svl_active_pclass' needs to be | |
4494 * replaced with opinfo.opinfo_path_state | |
4495 * value. | |
4496 */ | |
4497 | |
4498 if (SCSI_FAILOVER_IS_TPGS(vlun->svl_fops)) { | |
4499 char *tptr; | |
4500 | |
4501 /* | |
4502 * The device is ALUA compliant. The | |
4503 * state need to be changed to online | |
4504 * rather than standby state which is | |
4505 * done typically for a asymmetric | |
4506 * device that is non ALUA compliant. | |
4507 */ | |
4508 mdi_pi_set_state(pip, | |
4509 MDI_PATHINFO_STATE_ONLINE); | |
4510 tptr = kmem_alloc(strlen | |
4511 (opinfo.opinfo_path_attr)+1, | |
4512 KM_SLEEP); | |
4513 (void) strlcpy(tptr, | |
4514 opinfo.opinfo_path_attr, | |
4515 (strlen(opinfo.opinfo_path_attr) | |
4516 +1)); | |
4517 mutex_enter(&vlun->svl_mutex); | |
4518 kmem_free(vlun->svl_active_pclass, | |
4519 strlen(vlun->svl_active_pclass)+1); | |
4520 vlun->svl_active_pclass = tptr; | |
4521 mutex_exit(&vlun->svl_mutex); | |
4522 } else { | |
4523 /* | |
4524 * Non ALUA device case. | |
4525 */ | |
4526 mdi_pi_set_state(pip, | |
4527 MDI_PATHINFO_STATE_STANDBY); | |
4528 } | |
4529 vlun->svl_fo_support = opinfo.opinfo_mode; | |
4530 mdi_pi_set_preferred(pip, | |
4531 opinfo.opinfo_preferred); | |
4532 return (MDI_SUCCESS); | |
4533 } | |
4534 } else { | |
4535 char *tptr; | |
4536 | |
4537 /* | |
4538 * lets release the mutex before we try to | |
4539 * allocate since the potential to sleep is | |
4540 * possible. | |
4541 */ | |
4542 mutex_exit(&vlun->svl_mutex); | |
4543 tptr = kmem_alloc(strlen(pclass)+1, KM_SLEEP); | |
4544 (void) strlcpy(tptr, pclass, (strlen(pclass)+1)); | |
4545 mutex_enter(&vlun->svl_mutex); | |
4546 vlun->svl_active_pclass = tptr; | |
4547 } | |
4548 mutex_exit(&vlun->svl_mutex); | |
4549 mdi_pi_set_state(pip, MDI_PATHINFO_STATE_ONLINE); | |
4550 vlun->svl_waiting_for_activepath = 0; | |
4551 } else if (opinfo.opinfo_path_state == SCSI_PATH_ACTIVE_NONOPT) { | |
4552 mutex_enter(&vlun->svl_mutex); | |
4553 if (vlun->svl_active_pclass == NULL) { | |
4554 char *tptr; | |
4555 | |
4556 mutex_exit(&vlun->svl_mutex); | |
4557 tptr = kmem_alloc(strlen(pclass)+1, KM_SLEEP); | |
4558 (void) strlcpy(tptr, pclass, (strlen(pclass)+1)); | |
4559 mutex_enter(&vlun->svl_mutex); | |
4560 vlun->svl_active_pclass = tptr; | |
4561 } | |
4562 mutex_exit(&vlun->svl_mutex); | |
4563 mdi_pi_set_state(pip, MDI_PATHINFO_STATE_ONLINE); | |
4564 vlun->svl_waiting_for_activepath = 0; | |
4565 } else if (opinfo.opinfo_path_state == SCSI_PATH_INACTIVE) { | |
4566 mutex_enter(&vlun->svl_mutex); | |
4567 if (vlun->svl_active_pclass != NULL) { | |
4568 if (strcmp(vlun->svl_active_pclass, pclass) == 0) { | |
4569 mutex_exit(&vlun->svl_mutex); | |
4570 /* | |
4571 * externally initiated failover has happened; | |
4572 * force state to ONLINE (see comment above) | |
4573 */ | |
4574 mdi_pi_set_state(pip, | |
4575 MDI_PATHINFO_STATE_ONLINE); | |
4576 vlun->svl_fo_support = opinfo.opinfo_mode; | |
4577 mdi_pi_set_preferred(pip, | |
4578 opinfo.opinfo_preferred); | |
4579 return (MDI_SUCCESS); | |
4580 } | |
4581 } | |
4582 mutex_exit(&vlun->svl_mutex); | |
4583 mdi_pi_set_state(pip, MDI_PATHINFO_STATE_STANDBY); | |
4584 | |
4585 /* | |
4586 * Initiate auto-failback, if enabled, for path if path-state | |
4587 * is transitioning from OFFLINE->STANDBY and pathclass is the | |
4588 * prefered pathclass for this storage. | |
4589 * NOTE: In case where opinfo_path_state is SCSI_PATH_ACTIVE | |
4590 * (above), where the pi state is set to STANDBY, we don't | |
4591 * initiate auto-failback as the next IO shall take care of. | |
4592 * this. See comment above. | |
4593 */ | |
4594 (*fo->sfo_pathclass_next)(NULL, &best_pclass, | |
4595 vlun->svl_fops_ctpriv); | |
4596 if (((vhci->vhci_conf_flags & VHCI_CONF_FLAGS_AUTO_FAILBACK) == | |
4597 VHCI_CONF_FLAGS_AUTO_FAILBACK) && | |
4598 ((strcmp(pclass, best_pclass) == 0) || | |
4599 mdi_pi_get_preferred(pip) == 1) && | |
4600 ((MDI_PI_OLD_STATE(pip) == MDI_PATHINFO_STATE_OFFLINE)|| | |
4601 (MDI_PI_OLD_STATE(pip) == MDI_PATHINFO_STATE_INIT))) { | |
4602 VHCI_DEBUG(1, (CE_NOTE, NULL, "%s pathclass path: %p" | |
4603 " OFFLINE->STANDBY transition for lun %s\n", | |
4604 best_pclass, (void *)pip, vlun->svl_lun_wwn)); | |
4605 (void) taskq_dispatch(vhci->vhci_taskq, | |
4606 vhci_initiate_auto_failback, (void *) vlun, | |
4607 KM_SLEEP); | |
4608 } | |
4609 } | |
4610 vlun->svl_fo_support = opinfo.opinfo_mode; | |
4611 mdi_pi_set_preferred(pip, opinfo.opinfo_preferred); | |
4612 | |
4613 VHCI_DEBUG(8, (CE_NOTE, NULL, "vhci_update_pathinfo: opinfo_rev = %x," | |
4614 " opinfo_path_state = %x opinfo_preferred = %x, opinfo_mode = %x\n", | |
4615 opinfo.opinfo_rev, opinfo.opinfo_path_state, | |
4616 opinfo.opinfo_preferred, opinfo.opinfo_mode)); | |
4617 | |
4618 return (MDI_SUCCESS); | |
4619 } | |
4620 | |
4621 /* | |
4622 * Form the kstat name and and call mdi_pi_kstat_create() | |
4623 */ | |
4624 void | |
4625 vhci_kstat_create_pathinfo(mdi_pathinfo_t *pip) | |
4626 { | |
4627 dev_info_t *tgt_dip; | |
4628 dev_info_t *pdip; | |
4629 char *guid; | |
4630 char *target_port, *target_port_dup; | |
4631 char ks_name[KSTAT_STRLEN]; | |
4632 uint_t pid; | |
4633 int by_id; | |
4634 mod_hash_val_t hv; | |
4635 | |
4636 | |
4637 /* return if we have already allocated kstats */ | |
4638 if (mdi_pi_kstat_exists(pip)) | |
4639 return; | |
4640 | |
4641 /* | |
4642 * We need instance numbers to create a kstat name, return if we don't | |
4643 * have instance numbers assigned yet. | |
4644 */ | |
4645 tgt_dip = mdi_pi_get_client(pip); | |
4646 pdip = mdi_pi_get_phci(pip); | |
4647 if ((ddi_get_instance(tgt_dip) == -1) || (ddi_get_instance(pdip) == -1)) | |
4648 return; | |
4649 | |
4650 /* | |
4651 * A path oriented kstat has a ks_name of the form: | |
4652 * | |
4653 * <client-driver><instance>.t<pid>.<pHCI-driver><instance> | |
4654 * | |
4655 * We maintain a bidirectional 'target-port' to <pid> map, | |
4656 * called targetmap. All pathinfo nodes with the same | |
4657 * 'target-port' map to the same <pid>. The iostat(1M) code, | |
4658 * when parsing a path oriented kstat name, uses the <pid> as | |
4659 * a SCSI_VHCI_GET_TARGET_LONGNAME ioctl argument in order | |
4660 * to get the 'target-port'. For KSTAT_FLAG_PERSISTENT kstats, | |
4661 * this ioctl needs to translate a <pid> to a 'target-port' | |
4662 * even after all pathinfo nodes associated with the | |
4663 * 'target-port' have been destroyed. This is needed to support | |
4664 * consistent first-iteration activity-since-boot iostat(1M) | |
4665 * output. Because of this requirement, the mapping can't be | |
4666 * based on pathinfo information in a devinfo snapshot. | |
4667 */ | |
4668 | |
4669 /* determine 'target-port' */ | |
4670 if (mdi_prop_lookup_string(pip, | |
4671 "target-port", &target_port) == MDI_SUCCESS) { | |
4672 target_port_dup = i_ddi_strdup(target_port, KM_SLEEP); | |
4673 (void) mdi_prop_free(target_port); | |
4674 by_id = 1; | |
4675 } else { | |
4676 /* | |
4677 * If the pHCI did not set up 'target-port' on this | |
4678 * pathinfo node, assume that our client is the only | |
4679 * one with paths to the device by using the guid | |
4680 * value as the 'target-port'. Since no other client | |
4681 * will have the same guid, no other client will use | |
4682 * the same <pid>. NOTE: a client with an instance | |
4683 * number always has a guid. | |
4684 */ | |
4685 (void) ddi_prop_lookup_string(DDI_DEV_T_ANY, tgt_dip, | |
4686 PROPFLAGS, MDI_CLIENT_GUID_PROP, &guid); | |
4687 target_port_dup = i_ddi_strdup(guid, KM_SLEEP); | |
4688 ddi_prop_free(guid); | |
4689 | |
4690 /* | |
4691 * For this type of mapping we don't want the | |
4692 * <id> -> 'target-port' mapping to be made. This | |
4693 * will cause the SCSI_VHCI_GET_TARGET_LONGNAME ioctl | |
4694 * to fail, and the iostat(1M) long '-n' output will | |
4695 * still use the <pid>. We do this because we just | |
4696 * made up the 'target-port' using the guid, and we | |
4697 * don't want to expose that fact in iostat output. | |
4698 */ | |
4699 by_id = 0; | |
4700 } | |
4701 | |
4702 /* find/establish <pid> given 'target-port' */ | |
4703 mutex_enter(&vhci_targetmap_mutex); | |
4704 if (mod_hash_find(vhci_targetmap_byport, | |
4705 (mod_hash_key_t)target_port_dup, &hv) == 0) { | |
4706 pid = (int)(intptr_t)hv; /* mapping exists */ | |
4707 } else { | |
4708 pid = vhci_targetmap_pid++; /* new mapping */ | |
4709 | |
4710 (void) mod_hash_insert(vhci_targetmap_byport, | |
4711 (mod_hash_key_t)target_port_dup, | |
4712 (mod_hash_val_t)(intptr_t)pid); | |
4713 if (by_id) { | |
4714 (void) mod_hash_insert(vhci_targetmap_bypid, | |
4715 (mod_hash_key_t)(uintptr_t)pid, | |
4716 (mod_hash_val_t)(uintptr_t)target_port_dup); | |
4717 } | |
4718 target_port_dup = NULL; /* owned by hash */ | |
4719 } | |
4720 mutex_exit(&vhci_targetmap_mutex); | |
4721 | |
4722 /* form kstat name */ | |
4723 (void) snprintf(ks_name, KSTAT_STRLEN, "%s%d.t%d.%s%d", | |
4724 ddi_driver_name(tgt_dip), ddi_get_instance(tgt_dip), | |
4725 pid, ddi_driver_name(pdip), ddi_get_instance(pdip)); | |
4726 | |
4727 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_path_online: path:%p " | |
4728 "kstat %s: pid %x <-> port %s\n", (void *)pip, | |
4729 ks_name, pid, target_port_dup)); | |
4730 if (target_port_dup) | |
4731 kmem_free(target_port_dup, strlen(target_port_dup) + 1); | |
4732 | |
4733 /* call mdi to create kstats with the name we built */ | |
4734 (void) mdi_pi_kstat_create(pip, ks_name); | |
4735 } | |
4736 | |
4737 /* ARGSUSED */ | |
4738 static int | |
4739 vhci_pathinfo_online(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) | |
4740 { | |
4741 scsi_hba_tran_t *hba = NULL; | |
4742 struct scsi_device *psd = NULL; | |
4743 scsi_vhci_lun_t *vlun = NULL; | |
4744 dev_info_t *pdip = NULL; | |
4745 dev_info_t *tgt_dip; | |
4746 struct scsi_vhci *vhci; | |
4747 char *guid; | |
4748 struct scsi_failover *sf; | |
4749 struct scsi_failover_ops *sfo; | |
4750 char *override; | |
4751 scsi_vhci_priv_t *svp = NULL; | |
4752 struct buf *bp; | |
4753 struct scsi_address *ap; | |
4754 struct scsi_pkt *pkt; | |
4755 int rval = MDI_FAILURE; | |
4756 uint_t inq_size = VHCI_STD_INQ_SIZE; | |
4757 mpapi_item_list_t *list_ptr; | |
4758 mpapi_lu_data_t *ld; | |
4759 | |
4760 ASSERT(vdip != NULL); | |
4761 ASSERT(pip != NULL); | |
4762 | |
4763 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(vdip)); | |
4764 ASSERT(vhci != NULL); | |
4765 | |
4766 pdip = mdi_pi_get_phci(pip); | |
4767 hba = ddi_get_driver_private(pdip); | |
4768 ASSERT(hba != NULL); | |
4769 | |
4770 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
4771 ASSERT(svp != NULL); | |
4772 | |
4773 tgt_dip = mdi_pi_get_client(pip); | |
4774 ASSERT(tgt_dip != NULL); | |
4775 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, tgt_dip, PROPFLAGS, | |
4776 MDI_CLIENT_GUID_PROP, &guid) != DDI_SUCCESS) { | |
4777 VHCI_DEBUG(1, (CE_WARN, NULL, "vhci_path_online: lun guid " | |
4778 "property failed")); | |
4779 goto failure; | |
4780 } | |
4781 | |
4782 vlun = vhci_lun_lookup(tgt_dip); | |
4783 ASSERT(vlun != NULL); | |
4784 | |
4785 ddi_prop_free(guid); | |
4786 | |
4787 vlun->svl_dip = mdi_pi_get_client(pip); | |
4788 ASSERT(vlun->svl_dip != NULL); | |
4789 | |
4790 psd = svp->svp_psd; | |
4791 ASSERT(psd != NULL); | |
4792 | |
4793 /* | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
4794 * For INQUIRY response buffer size, we use VHCI_STD_INQ_SIZE(132bytes) |
4851 | 4795 * instead of SUN_INQSIZE(48bytes) which is used in sd layer. This is |
4796 * because we could get the Vendor specific parameters(present 97th | |
4797 * byte onwards) which are required to process Vendor specific data | |
4798 * based on array type. | |
4799 * This INQUIRY buffer is freed in vhci_pathinfo_offline but NEVER | |
4800 * in a different layer like sd/phci transport. In other words, vhci | |
4801 * maintains its own copy of scsi_device and scsi_inquiry data on a | |
4802 * per-path basis. | |
4803 */ | |
4804 if (psd->sd_inq == NULL) { | |
4805 psd->sd_inq = (struct scsi_inquiry *) | |
4806 kmem_zalloc(inq_size, KM_SLEEP); | |
4807 } | |
4808 | |
4809 tgt_dip = psd->sd_dev; | |
4810 ASSERT(tgt_dip != NULL); | |
4811 | |
4812 /* | |
4813 * do inquiry to pass into probe routine; this | |
4814 * will avoid each probe routine doing scsi inquiry | |
4815 */ | |
4816 bp = getrbuf(KM_SLEEP); | |
4817 bp->b_un.b_addr = (caddr_t)psd->sd_inq; | |
4818 bp->b_flags = B_READ; | |
4819 bp->b_bcount = inq_size; | |
4820 bp->b_resid = 0; | |
4821 | |
4822 ap = &psd->sd_address; | |
4823 pkt = scsi_init_pkt(ap, NULL, bp, CDB_GROUP0, | |
4824 sizeof (struct scsi_arq_status), 0, 0, SLEEP_FUNC, NULL); | |
4825 if (pkt == NULL) { | |
4826 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_pathinfo_online: " | |
4827 "Inquiry init_pkt failed :%p\n", (void *)pip)); | |
4828 rval = MDI_FAILURE; | |
4829 goto failure; | |
4830 } | |
4831 pkt->pkt_cdbp[0] = SCMD_INQUIRY; | |
4832 pkt->pkt_cdbp[4] = (uchar_t)inq_size; | |
4833 pkt->pkt_time = 60; | |
4834 | |
4835 rval = vhci_do_scsi_cmd(pkt); | |
4836 scsi_destroy_pkt(pkt); | |
4837 freerbuf(bp); | |
4838 if (rval == 0) { | |
4839 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_pathinfo_online: " | |
4840 "Failover Inquiry failed path:%p rval:%x\n", | |
4841 (void *)pip, rval)); | |
4842 rval = MDI_FAILURE; | |
4843 goto failure; | |
4844 } | |
4845 | |
4846 /* | |
4847 * Determine if device is supported under scsi_vhci, and select | |
4848 * failover module. | |
4849 * | |
4850 * See if there is a scsi_vhci.conf file override for this devices's | |
4851 * VID/PID. The following values can be returned: | |
4852 * | |
4853 * NULL If the NULL is returned then there is no scsi_vhci.conf | |
4854 * override. For NULL, we determine the failover_ops for | |
4855 * this device by checking the sfo_device_probe entry | |
4856 * point for each 'fops' module, in order. | |
4857 * | |
4858 * NOTE: Correct operation may depend on module ordering | |
4859 * of 'specific' (failover modules that are completely | |
4860 * VID/PID table based) to 'generic' (failover modules | |
4861 * that based on T10 standards like TPGS). Currently, | |
4862 * the value of 'ddi-forceload' in scsi_vhci.conf is used | |
4863 * to establish the module list and probe order. | |
4864 * | |
4865 * "NONE" If value "NONE" is returned then there is a | |
4866 * scsi_vhci.conf VID/PID override to indicate the device | |
4867 * should not be supported under scsi_vhci (even if there | |
4868 * is an 'fops' module supporting the device). | |
4869 * | |
4870 * "<other>" If another value is returned then that value is the | |
4871 * name of the 'fops' module that should be used. | |
4872 */ | |
4873 sfo = NULL; /* "NONE" */ | |
4874 override = scsi_get_device_type_string( | |
4875 "scsi-vhci-failover-override", vdip, psd); | |
4876 | |
4877 if (override == NULL) { | |
4878 /* NULL: default: select based on sfo_device_probe results */ | |
4879 for (sf = scsi_failover_table; sf->sf_mod; sf++) { | |
4880 if ((sf->sf_sfo == NULL) || | |
4881 ((*sf->sf_sfo->sfo_device_probe) (psd, | |
4882 psd->sd_inq, &vlun->svl_fops_ctpriv) == | |
4883 SFO_DEVICE_PROBE_PHCI)) | |
4884 continue; | |
4885 | |
4886 /* found failover module, supported under scsi_vhci */ | |
4887 sfo = sf->sf_sfo; | |
4888 vlun->svl_fops_name = | |
4889 i_ddi_strdup(sfo->sfo_name, KM_SLEEP); | |
4890 break; | |
4891 } | |
4892 } else if (strcmp(override, "NONE") && strcmp(override, "none")) { | |
4893 /* !"NONE": select based on driver.conf specified name */ | |
4894 for (sf = scsi_failover_table, sfo = NULL; sf->sf_mod; sf++) { | |
4895 if ((sf->sf_sfo == NULL) || | |
4896 (sf->sf_sfo->sfo_name == NULL) || | |
4897 strcmp(override, sf->sf_sfo->sfo_name)) | |
4898 continue; | |
4899 | |
4900 /* found failover module, supported under scsi_vhci */ | |
4901 sfo = sf->sf_sfo; | |
4902 vlun->svl_fops_name = kmem_alloc(strlen("conf ") + | |
4903 strlen(sfo->sfo_name) + 1, KM_SLEEP); | |
4904 (void) sprintf(vlun->svl_fops_name, "conf %s", | |
4905 sfo->sfo_name); | |
4906 break; | |
4907 } | |
4908 } | |
4909 if (override) | |
4910 kmem_free(override, strlen(override) + 1); | |
4911 | |
4912 if (sfo == NULL) { | |
4913 /* no failover module - device not supported */ | |
4914 VHCI_DEBUG(1, (CE_NOTE, vhci->vhci_dip, | |
4915 "!vhci_pathinfo_online: dev (path 0x%p) not " | |
4916 "supported\n", (void *)pip)); | |
4917 vlun->svl_not_supported = 1; | |
4918 rval = MDI_NOT_SUPPORTED; | |
4919 goto done; | |
4920 } | |
4921 | |
4922 /* failover supported for device - save failover_ops in vlun */ | |
4923 vlun->svl_fops = sfo; | |
4924 | |
4925 /* | |
4926 * Obtain the device-type based mpxio options as specified in | |
4927 * scsi_vhci.conf file. | |
4928 * | |
4929 * NOTE: currently, the end result is a call to | |
4930 * mdi_set_lb_region_size(). | |
4931 */ | |
4932 vhci_get_device_type_mpxio_options(vdip, tgt_dip, psd); | |
4933 | |
4934 /* | |
4935 * if PGR is active, revalidate key and register on this path also, | |
4936 * if key is still valid | |
4937 */ | |
4938 sema_p(&vlun->svl_pgr_sema); | |
4939 if (vlun->svl_pgr_active) { | |
4940 rval = vhci_pgr_validate_and_register(svp); | |
4941 if (rval != 1) { | |
4942 rval = MDI_FAILURE; | |
4943 sema_v(&vlun->svl_pgr_sema); | |
4944 goto failure; | |
4945 } | |
4946 } | |
4947 sema_v(&vlun->svl_pgr_sema); | |
4948 | |
4949 if (svp->svp_new_path) { | |
4950 /* | |
4951 * Last chance to perform any cleanup operations on this | |
4952 * new path before making this path completely online. | |
4953 */ | |
4954 svp->svp_new_path = 0; | |
4955 | |
4956 /* | |
4957 * If scsi_vhci knows the lun is alread RESERVE'd, | |
4958 * then skip the issue of RELEASE on new path. | |
4959 */ | |
4960 if ((vlun->svl_flags & VLUN_RESERVE_ACTIVE_FLG) == 0) { | |
4961 /* | |
4962 * Issue SCSI-2 RELEASE only for the first time on | |
4963 * a new path just in case the host rebooted and | |
4964 * a reservation is still pending on this path. | |
4965 * IBM Shark storage does not clear RESERVE upon | |
4966 * host reboot. | |
4967 */ | |
4968 ap = &psd->sd_address; | |
4969 pkt = scsi_init_pkt(ap, NULL, NULL, CDB_GROUP0, | |
4970 sizeof (struct scsi_arq_status), 0, 0, | |
4971 SLEEP_FUNC, NULL); | |
4972 if (pkt == NULL) { | |
4973 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
4974 "!vhci_pathinfo_online: " | |
4975 "Release init_pkt failed :%p\n", | |
4976 (void *)pip)); | |
4977 rval = MDI_FAILURE; | |
4978 goto failure; | |
4979 } | |
4980 pkt->pkt_cdbp[0] = SCMD_RELEASE; | |
4981 pkt->pkt_time = 60; | |
4982 | |
4983 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
4984 "!vhci_path_online: path:%p " | |
4985 "Issued SCSI-2 RELEASE\n", (void *)pip)); | |
4986 | |
4987 /* Ignore the return value */ | |
4988 (void) vhci_do_scsi_cmd(pkt); | |
4989 scsi_destroy_pkt(pkt); | |
4990 } | |
4991 } | |
4992 | |
4993 rval = vhci_update_pathinfo(psd, pip, sfo, vlun, vhci); | |
4994 if (rval == MDI_FAILURE) { | |
4995 goto failure; | |
4996 } | |
4997 | |
4998 /* Initialize MP-API data */ | |
4999 vhci_update_mpapi_data(vhci, vlun, pip); | |
5000 | |
5001 /* | |
5002 * MP-API also needs the Inquiry data to be maintained in the | |
5003 * mp_vendor_prop_t structure, so find the lun and update its | |
5004 * structure with this data. | |
5005 */ | |
5006 list_ptr = (mpapi_item_list_t *)vhci_get_mpapi_item(vhci, NULL, | |
5007 MP_OBJECT_TYPE_MULTIPATH_LU, (void *)vlun); | |
5008 ld = (mpapi_lu_data_t *)list_ptr->item->idata; | |
5009 if (ld != NULL) { | |
5010 bcopy(psd->sd_inq->inq_vid, ld->prop.prodInfo.vendor, 8); | |
5011 bcopy(psd->sd_inq->inq_pid, ld->prop.prodInfo.product, 16); | |
5012 bcopy(psd->sd_inq->inq_revision, ld->prop.prodInfo.revision, 4); | |
5013 } else { | |
5014 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_pathinfo_online: " | |
5015 "mpapi_lu_data_t is NULL")); | |
5016 } | |
5017 | |
5018 /* create kstats for path */ | |
5019 vhci_kstat_create_pathinfo(pip); | |
5020 | |
5021 done: | |
5022 mutex_enter(&vhci_global_mutex); | |
5023 cv_broadcast(&vhci_cv); | |
5024 mutex_exit(&vhci_global_mutex); | |
5025 | |
5026 if (vlun->svl_setcap_done) { | |
5027 (void) vhci_pHCI_cap(ap, "sector-size", | |
5028 vlun->svl_sector_size, 1, pip); | |
5029 } | |
5030 | |
5031 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_path_online: path:%p\n", | |
5032 (void *)pip)); | |
5033 | |
5034 failure: | |
5035 if ((rval != MDI_SUCCESS) && psd->sd_inq) { | |
5036 kmem_free((caddr_t)psd->sd_inq, inq_size); | |
5037 psd->sd_inq = (struct scsi_inquiry *)NULL; | |
5038 } | |
5039 return (rval); | |
5040 } | |
5041 | |
5042 /* | |
5043 * path offline handler. Release all bindings that will not be | |
5044 * released by the normal packet transport/completion code path. | |
5045 * Since we don't (presently) keep any bindings alive outside of | |
5046 * the in-transport packets (which will be released on completion) | |
5047 * there is not much to do here. | |
5048 */ | |
5049 /* ARGSUSED */ | |
5050 static int | |
5051 vhci_pathinfo_offline(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) | |
5052 { | |
5053 scsi_hba_tran_t *hba = NULL; | |
5054 struct scsi_device *psd = NULL; | |
5055 dev_info_t *pdip = NULL; | |
5056 dev_info_t *cdip = NULL; | |
5057 scsi_vhci_priv_t *svp = NULL; | |
5058 uint_t inq_size = VHCI_STD_INQ_SIZE; | |
5059 | |
5060 ASSERT(vdip != NULL); | |
5061 ASSERT(pip != NULL); | |
5062 | |
5063 pdip = mdi_pi_get_phci(pip); | |
5064 ASSERT(pdip != NULL); | |
5065 if (pdip == NULL) { | |
5066 VHCI_DEBUG(1, (CE_WARN, vdip, "Invalid path 0x%p: NULL " | |
5067 "phci dip", (void *)pip)); | |
5068 return (MDI_FAILURE); | |
5069 } | |
5070 | |
5071 cdip = mdi_pi_get_client(pip); | |
5072 ASSERT(cdip != NULL); | |
5073 if (cdip == NULL) { | |
5074 VHCI_DEBUG(1, (CE_WARN, vdip, "Invalid path 0x%p: NULL " | |
5075 "client dip", (void *)pip)); | |
5076 return (MDI_FAILURE); | |
5077 } | |
5078 | |
5079 hba = ddi_get_driver_private(pdip); | |
5080 ASSERT(hba != NULL); | |
5081 | |
5082 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
5083 if (svp == NULL) { | |
5084 /* | |
5085 * mdi_pathinfo node in INIT state can have vHCI private | |
5086 * information set to null | |
5087 */ | |
5088 VHCI_DEBUG(1, (CE_NOTE, vdip, "!vhci_pathinfo_offline: " | |
5089 "svp is NULL for pip 0x%p\n", (void *)pip)); | |
5090 return (MDI_SUCCESS); | |
5091 } | |
5092 | |
5093 psd = svp->svp_psd; | |
5094 ASSERT(psd != NULL); | |
5095 | |
5096 mutex_enter(&svp->svp_mutex); | |
5097 | |
5098 VHCI_DEBUG(1, (CE_NOTE, vdip, "!vhci_pathinfo_offline: " | |
5099 "%d cmds pending on path: 0x%p\n", svp->svp_cmds, (void *)pip)); | |
5100 while (svp->svp_cmds != 0) { | |
5101 if (cv_timedwait(&svp->svp_cv, &svp->svp_mutex, | |
5102 ddi_get_lbolt() + | |
5103 drv_usectohz(vhci_path_quiesce_timeout * 1000000)) == -1) { | |
5104 /* | |
5105 * The timeout time reached without the condition | |
5106 * being signaled. | |
5107 */ | |
5108 VHCI_DEBUG(1, (CE_NOTE, vdip, "!vhci_pathinfo_offline: " | |
5109 "Timeout reached on path 0x%p without the cond\n", | |
5110 (void *)pip)); | |
5111 VHCI_DEBUG(1, (CE_NOTE, vdip, "!vhci_pathinfo_offline: " | |
5112 "%d cmds still pending on path: 0x%p\n", | |
5113 svp->svp_cmds, (void *)pip)); | |
5114 break; | |
5115 } | |
5116 } | |
5117 mutex_exit(&svp->svp_mutex); | |
5118 | |
5119 /* | |
5120 * Check to see if this vlun has an active SCSI-II RESERVE. And this | |
5121 * is the pip for the path that has been reserved. | |
5122 * If so clear the reservation by sending a reset, so the host will not | |
5123 * get a reservation conflict. Reset the flag VLUN_RESERVE_ACTIVE_FLG | |
5124 * for this lun. Also a reset notify is sent to the target driver | |
5125 * just in case the POR check condition is cleared by some other layer | |
5126 * in the stack. | |
5127 */ | |
5128 if (svp->svp_svl->svl_flags & VLUN_RESERVE_ACTIVE_FLG) { | |
5129 if (pip == svp->svp_svl->svl_resrv_pip) { | |
5130 if (vhci_recovery_reset(svp->svp_svl, | |
5131 &svp->svp_psd->sd_address, TRUE, | |
5132 VHCI_DEPTH_TARGET) == 0) { | |
5133 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
5134 "!vhci_pathinfo_offline (pip:%p):" | |
5135 "reset failed, retrying\n", (void *)pip)); | |
5136 delay(1*drv_usectohz(1000000)); | |
5137 if (vhci_recovery_reset(svp->svp_svl, | |
5138 &svp->svp_psd->sd_address, TRUE, | |
5139 VHCI_DEPTH_TARGET) == 0) { | |
5140 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
5141 "!vhci_pathinfo_offline " | |
5142 "(pip:%p): reset failed, " | |
5143 "giving up!\n", (void *)pip)); | |
5144 } | |
5145 } | |
5146 svp->svp_svl->svl_flags &= ~VLUN_RESERVE_ACTIVE_FLG; | |
5147 } | |
5148 } | |
5149 | |
5150 mdi_pi_set_state(pip, MDI_PATHINFO_STATE_OFFLINE); | |
5151 if (psd->sd_inq) { | |
5152 kmem_free((caddr_t)psd->sd_inq, inq_size); | |
5153 psd->sd_inq = (struct scsi_inquiry *)NULL; | |
5154 } | |
5155 vhci_mpapi_set_path_state(vdip, pip, MP_DRVR_PATH_STATE_REMOVED); | |
5156 | |
5157 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
5158 "!vhci_pathinfo_offline: offlined path 0x%p\n", (void *)pip)); | |
5159 return (MDI_SUCCESS); | |
5160 } | |
5161 | |
5162 | |
5163 /* | |
5164 * routine for SCSI VHCI IOCTL implementation. | |
5165 */ | |
5166 /* ARGSUSED */ | |
5167 static int | |
5168 vhci_ctl(dev_t dev, int cmd, intptr_t data, int mode, cred_t *credp, int *rval) | |
5169 { | |
5170 struct scsi_vhci *vhci; | |
5171 dev_info_t *vdip; | |
5172 mdi_pathinfo_t *pip; | |
5173 int instance, held; | |
5174 int retval = 0; | |
5175 caddr_t phci_path = NULL, client_path = NULL; | |
5176 caddr_t paddr = NULL; | |
5177 sv_iocdata_t ioc; | |
5178 sv_iocdata_t *pioc = &ioc; | |
5179 sv_switch_to_cntlr_iocdata_t iocsc; | |
5180 sv_switch_to_cntlr_iocdata_t *piocsc = &iocsc; | |
5181 caddr_t s; | |
5182 scsi_vhci_lun_t *vlun; | |
5183 struct scsi_failover_ops *fo; | |
5184 char *pclass; | |
5185 | |
5186 /* Check for validity of vhci structure */ | |
5187 vhci = ddi_get_soft_state(vhci_softstate, MINOR2INST(getminor(dev))); | |
5188 if (vhci == NULL) { | |
5189 return (ENXIO); | |
5190 } | |
5191 | |
5192 mutex_enter(&vhci->vhci_mutex); | |
5193 if ((vhci->vhci_state & VHCI_STATE_OPEN) == 0) { | |
5194 mutex_exit(&vhci->vhci_mutex); | |
5195 return (ENXIO); | |
5196 } | |
5197 mutex_exit(&vhci->vhci_mutex); | |
5198 | |
5199 /* Get the vhci dip */ | |
5200 vdip = vhci->vhci_dip; | |
5201 ASSERT(vdip != NULL); | |
5202 instance = ddi_get_instance(vdip); | |
5203 | |
5204 /* Allocate memory for getting parameters from userland */ | |
5205 phci_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP); | |
5206 client_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP); | |
5207 paddr = kmem_zalloc(MAXNAMELEN, KM_SLEEP); | |
5208 | |
5209 /* | |
5210 * Set a local variable indicating the ioctl name. Used for | |
5211 * printing debug strings. | |
5212 */ | |
5213 switch (cmd) { | |
5214 case SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO: | |
5215 s = "GET_CLIENT_MULTIPATH_INFO"; | |
5216 break; | |
5217 | |
5218 case SCSI_VHCI_GET_PHCI_MULTIPATH_INFO: | |
5219 s = "GET_PHCI_MULTIPATH_INFO"; | |
5220 break; | |
5221 | |
5222 case SCSI_VHCI_GET_CLIENT_NAME: | |
5223 s = "GET_CLIENT_NAME"; | |
5224 break; | |
5225 | |
5226 case SCSI_VHCI_PATH_ONLINE: | |
5227 s = "PATH_ONLINE"; | |
5228 break; | |
5229 | |
5230 case SCSI_VHCI_PATH_OFFLINE: | |
5231 s = "PATH_OFFLINE"; | |
5232 break; | |
5233 | |
5234 case SCSI_VHCI_PATH_STANDBY: | |
5235 s = "PATH_STANDBY"; | |
5236 break; | |
5237 | |
5238 case SCSI_VHCI_PATH_TEST: | |
5239 s = "PATH_TEST"; | |
5240 break; | |
5241 | |
5242 case SCSI_VHCI_SWITCH_TO_CNTLR: | |
5243 s = "SWITCH_TO_CNTLR"; | |
5244 break; | |
5245 case SCSI_VHCI_PATH_DISABLE: | |
5246 s = "PATH_DISABLE"; | |
5247 break; | |
5248 case SCSI_VHCI_PATH_ENABLE: | |
5249 s = "PATH_ENABLE"; | |
5250 break; | |
5251 | |
5252 case SCSI_VHCI_GET_TARGET_LONGNAME: | |
5253 s = "GET_TARGET_LONGNAME"; | |
5254 break; | |
5255 | |
5256 #ifdef DEBUG | |
5257 case SCSI_VHCI_CONFIGURE_PHCI: | |
5258 s = "CONFIGURE_PHCI"; | |
5259 break; | |
5260 | |
5261 case SCSI_VHCI_UNCONFIGURE_PHCI: | |
5262 s = "UNCONFIGURE_PHCI"; | |
5263 break; | |
5264 #endif | |
5265 | |
5266 default: | |
5267 s = "Unknown"; | |
5268 vhci_log(CE_NOTE, vdip, | |
5269 "!vhci%d: ioctl %x (unsupported ioctl)", instance, cmd); | |
5270 retval = ENOTSUP; | |
5271 break; | |
5272 } | |
5273 if (retval != 0) { | |
5274 goto end; | |
5275 } | |
5276 | |
5277 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci%d: ioctl <%s>", instance, s)); | |
5278 | |
5279 /* | |
5280 * Get IOCTL parameters from userland | |
5281 */ | |
5282 switch (cmd) { | |
5283 case SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO: | |
5284 case SCSI_VHCI_GET_PHCI_MULTIPATH_INFO: | |
5285 case SCSI_VHCI_GET_CLIENT_NAME: | |
5286 case SCSI_VHCI_PATH_ONLINE: | |
5287 case SCSI_VHCI_PATH_OFFLINE: | |
5288 case SCSI_VHCI_PATH_STANDBY: | |
5289 case SCSI_VHCI_PATH_TEST: | |
5290 case SCSI_VHCI_PATH_DISABLE: | |
5291 case SCSI_VHCI_PATH_ENABLE: | |
5292 case SCSI_VHCI_GET_TARGET_LONGNAME: | |
5293 #ifdef DEBUG | |
5294 case SCSI_VHCI_CONFIGURE_PHCI: | |
5295 case SCSI_VHCI_UNCONFIGURE_PHCI: | |
5296 #endif | |
5297 retval = vhci_get_iocdata((const void *)data, pioc, mode, s); | |
5298 break; | |
5299 | |
5300 case SCSI_VHCI_SWITCH_TO_CNTLR: | |
5301 retval = vhci_get_iocswitchdata((const void *)data, piocsc, | |
5302 mode, s); | |
5303 break; | |
5304 } | |
5305 if (retval != 0) { | |
5306 goto end; | |
5307 } | |
5308 | |
5309 | |
5310 /* | |
5311 * Process the IOCTL | |
5312 */ | |
5313 switch (cmd) { | |
5314 case SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO: | |
5315 { | |
5316 uint_t num_paths; /* Num paths to client dev */ | |
5317 sv_path_info_t *upibuf = NULL; /* To keep userland values */ | |
5318 sv_path_info_t *kpibuf = NULL; /* Kernel data for ioctls */ | |
5319 dev_info_t *cdip; /* Client device dip */ | |
5320 | |
5321 if (pioc->ret_elem == NULL) { | |
5322 retval = EINVAL; | |
5323 break; | |
5324 } | |
5325 | |
5326 /* Get client device path from user land */ | |
5327 if (vhci_ioc_get_client_path(pioc, client_path, mode, s)) { | |
5328 retval = EFAULT; | |
5329 break; | |
5330 } | |
5331 | |
5332 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5333 "client <%s>", s, client_path)); | |
5334 | |
5335 /* Get number of paths to this client device */ | |
5336 if ((cdip = mdi_client_path2devinfo(vdip, client_path)) | |
5337 == NULL) { | |
5338 retval = ENXIO; | |
5339 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5340 "client dip doesn't exist. invalid path <%s>", | |
5341 s, client_path)); | |
5342 break; | |
5343 } | |
5344 num_paths = mdi_client_get_path_count(cdip); | |
5345 | |
5346 if (ddi_copyout(&num_paths, pioc->ret_elem, | |
5347 sizeof (num_paths), mode)) { | |
5348 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5349 "num_paths copyout failed", s)); | |
5350 retval = EFAULT; | |
5351 break; | |
5352 } | |
5353 | |
5354 /* If user just wanted num_paths, then return */ | |
5355 if (pioc->buf_elem == 0 || pioc->ret_buf == NULL || | |
5356 num_paths == 0) { | |
5357 break; | |
5358 } | |
5359 | |
5360 /* Set num_paths to value as much as can be sent to userland */ | |
5361 if (num_paths > pioc->buf_elem) { | |
5362 num_paths = pioc->buf_elem; | |
5363 } | |
5364 | |
5365 /* Allocate memory and get userland pointers */ | |
5366 if (vhci_ioc_alloc_pathinfo(&upibuf, &kpibuf, num_paths, | |
5367 pioc, mode, s) != 0) { | |
5368 retval = EFAULT; | |
5369 break; | |
5370 } | |
5371 ASSERT(upibuf != NULL); | |
5372 ASSERT(kpibuf != NULL); | |
5373 | |
5374 /* | |
5375 * Get the path information and send it to userland. | |
5376 */ | |
5377 if (vhci_get_client_path_list(cdip, kpibuf, num_paths) | |
5378 != MDI_SUCCESS) { | |
5379 retval = ENXIO; | |
5380 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5381 break; | |
5382 } | |
5383 | |
5384 if (vhci_ioc_send_pathinfo(upibuf, kpibuf, num_paths, | |
5385 pioc, mode, s)) { | |
5386 retval = EFAULT; | |
5387 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5388 break; | |
5389 } | |
5390 | |
5391 /* Free the memory allocated for path information */ | |
5392 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5393 break; | |
5394 } | |
5395 | |
5396 case SCSI_VHCI_GET_PHCI_MULTIPATH_INFO: | |
5397 { | |
5398 uint_t num_paths; /* Num paths to client dev */ | |
5399 sv_path_info_t *upibuf = NULL; /* To keep userland values */ | |
5400 sv_path_info_t *kpibuf = NULL; /* Kernel data for ioctls */ | |
5401 dev_info_t *pdip; /* PHCI device dip */ | |
5402 | |
5403 if (pioc->ret_elem == NULL) { | |
5404 retval = EINVAL; | |
5405 break; | |
5406 } | |
5407 | |
5408 /* Get PHCI device path from user land */ | |
5409 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s)) { | |
5410 retval = EFAULT; | |
5411 break; | |
5412 } | |
5413 | |
5414 VHCI_DEBUG(6, (CE_WARN, vdip, | |
5415 "!vhci_ioctl: ioctl <%s> phci <%s>", s, phci_path)); | |
5416 | |
5417 /* Get number of devices associated with this PHCI device */ | |
5418 if ((pdip = mdi_phci_path2devinfo(vdip, phci_path)) == NULL) { | |
5419 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5420 "phci dip doesn't exist. invalid path <%s>", | |
5421 s, phci_path)); | |
5422 retval = ENXIO; | |
5423 break; | |
5424 } | |
5425 | |
5426 num_paths = mdi_phci_get_path_count(pdip); | |
5427 | |
5428 if (ddi_copyout(&num_paths, pioc->ret_elem, | |
5429 sizeof (num_paths), mode)) { | |
5430 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5431 "num_paths copyout failed", s)); | |
5432 retval = EFAULT; | |
5433 break; | |
5434 } | |
5435 | |
5436 /* If user just wanted num_paths, then return */ | |
5437 if (pioc->buf_elem == 0 || pioc->ret_buf == NULL || | |
5438 num_paths == 0) { | |
5439 break; | |
5440 } | |
5441 | |
5442 /* Set num_paths to value as much as can be sent to userland */ | |
5443 if (num_paths > pioc->buf_elem) { | |
5444 num_paths = pioc->buf_elem; | |
5445 } | |
5446 | |
5447 /* Allocate memory and get userland pointers */ | |
5448 if (vhci_ioc_alloc_pathinfo(&upibuf, &kpibuf, num_paths, | |
5449 pioc, mode, s) != 0) { | |
5450 retval = EFAULT; | |
5451 break; | |
5452 } | |
5453 ASSERT(upibuf != NULL); | |
5454 ASSERT(kpibuf != NULL); | |
5455 | |
5456 /* | |
5457 * Get the path information and send it to userland. | |
5458 */ | |
5459 if (vhci_get_phci_path_list(pdip, kpibuf, num_paths) | |
5460 != MDI_SUCCESS) { | |
5461 retval = ENXIO; | |
5462 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5463 break; | |
5464 } | |
5465 | |
5466 if (vhci_ioc_send_pathinfo(upibuf, kpibuf, num_paths, | |
5467 pioc, mode, s)) { | |
5468 retval = EFAULT; | |
5469 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5470 break; | |
5471 } | |
5472 | |
5473 /* Free the memory allocated for path information */ | |
5474 vhci_ioc_free_pathinfo(upibuf, kpibuf, num_paths); | |
5475 break; | |
5476 } | |
5477 | |
5478 case SCSI_VHCI_GET_CLIENT_NAME: | |
5479 { | |
5480 dev_info_t *cdip, *pdip; | |
5481 | |
5482 /* Get PHCI path and device address from user land */ | |
5483 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s) || | |
5484 vhci_ioc_get_paddr(pioc, paddr, mode, s)) { | |
5485 retval = EFAULT; | |
5486 break; | |
5487 } | |
5488 | |
5489 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5490 "phci <%s>, paddr <%s>", s, phci_path, paddr)); | |
5491 | |
5492 /* Get the PHCI dip */ | |
5493 if ((pdip = mdi_phci_path2devinfo(vdip, phci_path)) == NULL) { | |
5494 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5495 "phci dip doesn't exist. invalid path <%s>", | |
5496 s, phci_path)); | |
5497 retval = ENXIO; | |
5498 break; | |
5499 } | |
5500 | |
5501 if ((pip = mdi_pi_find(pdip, NULL, paddr)) == NULL) { | |
5502 VHCI_DEBUG(1, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5503 "pathinfo doesn't exist. invalid device addr", s)); | |
5504 retval = ENXIO; | |
5505 break; | |
5506 } | |
5507 | |
5508 /* Get the client device pathname and send to userland */ | |
5509 cdip = mdi_pi_get_client(pip); | |
5510 vhci_ioc_devi_to_path(cdip, client_path); | |
5511 | |
5512 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5513 "client <%s>", s, client_path)); | |
5514 | |
5515 if (vhci_ioc_send_client_path(client_path, pioc, mode, s)) { | |
5516 retval = EFAULT; | |
5517 break; | |
5518 } | |
5519 break; | |
5520 } | |
5521 | |
5522 case SCSI_VHCI_PATH_ONLINE: | |
5523 case SCSI_VHCI_PATH_OFFLINE: | |
5524 case SCSI_VHCI_PATH_STANDBY: | |
5525 case SCSI_VHCI_PATH_TEST: | |
5526 { | |
5527 dev_info_t *pdip; /* PHCI dip */ | |
5528 | |
5529 /* Get PHCI path and device address from user land */ | |
5530 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s) || | |
5531 vhci_ioc_get_paddr(pioc, paddr, mode, s)) { | |
5532 retval = EFAULT; | |
5533 break; | |
5534 } | |
5535 | |
5536 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5537 "phci <%s>, paddr <%s>", s, phci_path, paddr)); | |
5538 | |
5539 /* Get the PHCI dip */ | |
5540 if ((pdip = mdi_phci_path2devinfo(vdip, phci_path)) == NULL) { | |
5541 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5542 "phci dip doesn't exist. invalid path <%s>", | |
5543 s, phci_path)); | |
5544 retval = ENXIO; | |
5545 break; | |
5546 } | |
5547 | |
5548 if ((pip = mdi_pi_find(pdip, NULL, paddr)) == NULL) { | |
5549 VHCI_DEBUG(1, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5550 "pathinfo doesn't exist. invalid device addr", s)); | |
5551 retval = ENXIO; | |
5552 break; | |
5553 } | |
5554 | |
5555 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5556 "Calling MDI function to change device state", s)); | |
5557 | |
5558 switch (cmd) { | |
5559 case SCSI_VHCI_PATH_ONLINE: | |
5560 retval = mdi_pi_online(pip, 0); | |
5561 break; | |
5562 | |
5563 case SCSI_VHCI_PATH_OFFLINE: | |
5564 retval = mdi_pi_offline(pip, 0); | |
5565 break; | |
5566 | |
5567 case SCSI_VHCI_PATH_STANDBY: | |
5568 retval = mdi_pi_standby(pip, 0); | |
5569 break; | |
5570 | |
5571 case SCSI_VHCI_PATH_TEST: | |
5572 break; | |
5573 } | |
5574 break; | |
5575 } | |
5576 | |
5577 case SCSI_VHCI_SWITCH_TO_CNTLR: | |
5578 { | |
5579 dev_info_t *cdip; | |
5580 struct scsi_device *devp; | |
5581 | |
5582 /* Get the client device pathname */ | |
5583 if (ddi_copyin(piocsc->client, client_path, | |
5584 MAXPATHLEN, mode)) { | |
5585 VHCI_DEBUG(2, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5586 "client_path copyin failed", s)); | |
5587 retval = EFAULT; | |
5588 break; | |
5589 } | |
5590 | |
5591 /* Get the path class to which user wants to switch */ | |
5592 if (ddi_copyin(piocsc->class, paddr, MAXNAMELEN, mode)) { | |
5593 VHCI_DEBUG(2, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5594 "controller_class copyin failed", s)); | |
5595 retval = EFAULT; | |
5596 break; | |
5597 } | |
5598 | |
5599 /* Perform validity checks */ | |
5600 if ((cdip = mdi_client_path2devinfo(vdip, | |
5601 client_path)) == NULL) { | |
5602 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5603 "client dip doesn't exist. invalid path <%s>", | |
5604 s, client_path)); | |
5605 retval = ENXIO; | |
5606 break; | |
5607 } | |
5608 | |
5609 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: Calling MDI func " | |
5610 "to switch controller")); | |
5611 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: client <%s> " | |
5612 "class <%s>", client_path, paddr)); | |
5613 | |
5614 if (strcmp(paddr, PCLASS_PRIMARY) && | |
5615 strcmp(paddr, PCLASS_SECONDARY)) { | |
5616 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5617 "invalid path class <%s>", s, paddr)); | |
5618 retval = ENXIO; | |
5619 break; | |
5620 } | |
5621 | |
5622 devp = ddi_get_driver_private(cdip); | |
5623 if (devp == NULL) { | |
5624 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5625 "invalid scsi device <%s>", s, client_path)); | |
5626 retval = ENXIO; | |
5627 break; | |
5628 } | |
5629 vlun = ADDR2VLUN(&devp->sd_address); | |
5630 ASSERT(vlun); | |
5631 | |
5632 /* | |
5633 * Checking to see if device has only one pclass, PRIMARY. | |
5634 * If so this device doesn't support failovers. Assumed | |
5635 * that the devices with one pclass is PRIMARY, as thats the | |
5636 * case today. If this is not true and in future other | |
5637 * symmetric devices are supported with other pclass, this | |
5638 * IOCTL shall have to be overhauled anyways as now the only | |
5639 * arguments it accepts are PRIMARY and SECONDARY. | |
5640 */ | |
5641 fo = vlun->svl_fops; | |
5642 if ((*fo->sfo_pathclass_next)(PCLASS_PRIMARY, &pclass, | |
5643 vlun->svl_fops_ctpriv)) { | |
5644 retval = ENOTSUP; | |
5645 break; | |
5646 } | |
5647 | |
5648 VHCI_HOLD_LUN(vlun, VH_SLEEP, held); | |
5649 mutex_enter(&vlun->svl_mutex); | |
5650 if (vlun->svl_active_pclass != NULL) { | |
5651 if (strcmp(vlun->svl_active_pclass, paddr) == 0) { | |
5652 mutex_exit(&vlun->svl_mutex); | |
5653 retval = EALREADY; | |
5654 VHCI_RELEASE_LUN(vlun); | |
5655 break; | |
5656 } | |
5657 } | |
5658 mutex_exit(&vlun->svl_mutex); | |
5659 /* Call mdi function to cause a switch over */ | |
5660 retval = mdi_failover(vdip, cdip, MDI_FAILOVER_SYNC); | |
5661 if (retval == MDI_SUCCESS) { | |
5662 retval = 0; | |
5663 } else if (retval == MDI_BUSY) { | |
5664 retval = EBUSY; | |
5665 } else { | |
5666 retval = EIO; | |
5667 } | |
5668 VHCI_RELEASE_LUN(vlun); | |
5669 break; | |
5670 } | |
5671 | |
5672 case SCSI_VHCI_PATH_ENABLE: | |
5673 case SCSI_VHCI_PATH_DISABLE: | |
5674 { | |
5675 dev_info_t *cdip, *pdip; | |
5676 | |
5677 /* | |
5678 * Get client device path from user land | |
5679 */ | |
5680 if (vhci_ioc_get_client_path(pioc, client_path, mode, s)) { | |
5681 retval = EFAULT; | |
5682 break; | |
5683 } | |
5684 | |
5685 /* | |
5686 * Get Phci device path from user land | |
5687 */ | |
5688 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s)) { | |
5689 retval = EFAULT; | |
5690 break; | |
5691 } | |
5692 | |
5693 /* | |
5694 * Get the devinfo for the Phci. | |
5695 */ | |
5696 if ((pdip = mdi_phci_path2devinfo(vdip, phci_path)) == NULL) { | |
5697 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5698 "phci dip doesn't exist. invalid path <%s>", | |
5699 s, phci_path)); | |
5700 retval = ENXIO; | |
5701 break; | |
5702 } | |
5703 | |
5704 /* | |
5705 * If the client path is set to /scsi_vhci then we need | |
5706 * to do the operation on all the clients so set cdip to NULL. | |
5707 * Else, try to get the client dip. | |
5708 */ | |
5709 if (strcmp(client_path, "/scsi_vhci") == 0) { | |
5710 cdip = NULL; | |
5711 } else { | |
5712 if ((cdip = mdi_client_path2devinfo(vdip, | |
5713 client_path)) == NULL) { | |
5714 retval = ENXIO; | |
5715 VHCI_DEBUG(1, (CE_WARN, NULL, | |
5716 "!vhci_ioctl: ioctl <%s> client dip " | |
5717 "doesn't exist. invalid path <%s>", | |
5718 s, client_path)); | |
5719 break; | |
5720 } | |
5721 } | |
5722 | |
5723 if (cmd == SCSI_VHCI_PATH_ENABLE) | |
5724 retval = mdi_pi_enable(cdip, pdip, USER_DISABLE); | |
5725 else | |
5726 retval = mdi_pi_disable(cdip, pdip, USER_DISABLE); | |
5727 | |
5728 break; | |
5729 } | |
5730 | |
5731 case SCSI_VHCI_GET_TARGET_LONGNAME: | |
5732 { | |
5733 uint_t pid = pioc->buf_elem; | |
5734 char *target_port; | |
5735 mod_hash_val_t hv; | |
5736 | |
5737 /* targetmap lookup of 'target-port' by <pid> */ | |
5738 if (mod_hash_find(vhci_targetmap_bypid, | |
5739 (mod_hash_key_t)(uintptr_t)pid, &hv) != 0) { | |
5740 /* | |
5741 * NOTE: failure to find the mapping is OK for guid | |
5742 * based 'target-port' values. | |
5743 */ | |
5744 VHCI_DEBUG(3, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5745 "targetport mapping doesn't exist: pid %d", | |
5746 s, pid)); | |
5747 retval = ENXIO; | |
5748 break; | |
5749 } | |
5750 | |
5751 /* copyout 'target-port' result */ | |
5752 target_port = (char *)hv; | |
5753 if (copyoutstr(target_port, pioc->addr, MAXNAMELEN, NULL)) { | |
5754 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5755 "targetport copyout failed: len: %d", | |
5756 s, (int)strlen(target_port))); | |
5757 retval = EFAULT; | |
5758 } | |
5759 break; | |
5760 } | |
5761 | |
5762 #ifdef DEBUG | |
5763 case SCSI_VHCI_CONFIGURE_PHCI: | |
5764 { | |
5765 dev_info_t *pdip; | |
5766 | |
5767 /* Get PHCI path and device address from user land */ | |
5768 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s)) { | |
5769 retval = EFAULT; | |
5770 break; | |
5771 } | |
5772 | |
5773 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5774 "phci <%s>", s, phci_path)); | |
5775 | |
5776 /* Get the PHCI dip */ | |
5777 if ((pdip = e_ddi_hold_devi_by_path(phci_path, 0)) == NULL) { | |
5778 VHCI_DEBUG(3, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5779 "phci dip doesn't exist. invalid path <%s>", | |
5780 s, phci_path)); | |
5781 retval = ENXIO; | |
5782 break; | |
5783 } | |
5784 | |
5785 if (ndi_devi_config(pdip, | |
5786 NDI_DEVFS_CLEAN|NDI_DEVI_PERSIST) != NDI_SUCCESS) { | |
5787 retval = EIO; | |
5788 } | |
5789 | |
5790 ddi_release_devi(pdip); | |
5791 break; | |
5792 } | |
5793 | |
5794 case SCSI_VHCI_UNCONFIGURE_PHCI: | |
5795 { | |
5796 dev_info_t *pdip; | |
5797 | |
5798 /* Get PHCI path and device address from user land */ | |
5799 if (vhci_ioc_get_phci_path(pioc, phci_path, mode, s)) { | |
5800 retval = EFAULT; | |
5801 break; | |
5802 } | |
5803 | |
5804 VHCI_DEBUG(6, (CE_WARN, vdip, "!vhci_ioctl: ioctl <%s> " | |
5805 "phci <%s>", s, phci_path)); | |
5806 | |
5807 /* Get the PHCI dip */ | |
5808 if ((pdip = e_ddi_hold_devi_by_path(phci_path, 0)) == NULL) { | |
5809 VHCI_DEBUG(3, (CE_WARN, NULL, "!vhci_ioctl: ioctl <%s> " | |
5810 "phci dip doesn't exist. invalid path <%s>", | |
5811 s, phci_path)); | |
5812 retval = ENXIO; | |
5813 break; | |
5814 } | |
5815 | |
5816 if (ndi_devi_unconfig(pdip, | |
5817 NDI_DEVI_REMOVE|NDI_DEVFS_CLEAN) != NDI_SUCCESS) { | |
5818 retval = EBUSY; | |
5819 } | |
5820 | |
5821 ddi_release_devi(pdip); | |
5822 break; | |
5823 } | |
5824 #endif | |
5825 } | |
5826 | |
5827 end: | |
5828 /* Free the memory allocated above */ | |
5829 if (phci_path != NULL) { | |
5830 kmem_free(phci_path, MAXPATHLEN); | |
5831 } | |
5832 if (client_path != NULL) { | |
5833 kmem_free(client_path, MAXPATHLEN); | |
5834 } | |
5835 if (paddr != NULL) { | |
5836 kmem_free(paddr, MAXNAMELEN); | |
5837 } | |
5838 return (retval); | |
5839 } | |
5840 | |
5841 /* | |
5842 * devctl IOCTL support for client device DR | |
5843 */ | |
5844 /* ARGSUSED */ | |
5845 int | |
5846 vhci_devctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, | |
5847 int *rvalp) | |
5848 { | |
5849 dev_info_t *self; | |
5850 dev_info_t *child; | |
5851 scsi_hba_tran_t *hba; | |
5852 struct devctl_iocdata *dcp; | |
5853 struct scsi_vhci *vhci; | |
5854 int rv = 0; | |
5855 int retval = 0; | |
5856 scsi_vhci_priv_t *svp; | |
5857 mdi_pathinfo_t *pip; | |
5858 | |
5859 if ((vhci = ddi_get_soft_state(vhci_softstate, | |
5860 MINOR2INST(getminor(dev)))) == NULL) | |
5861 return (ENXIO); | |
5862 | |
5863 /* | |
5864 * check if :devctl minor device has been opened | |
5865 */ | |
5866 mutex_enter(&vhci->vhci_mutex); | |
5867 if ((vhci->vhci_state & VHCI_STATE_OPEN) == 0) { | |
5868 mutex_exit(&vhci->vhci_mutex); | |
5869 return (ENXIO); | |
5870 } | |
5871 mutex_exit(&vhci->vhci_mutex); | |
5872 | |
5873 self = vhci->vhci_dip; | |
5874 hba = ddi_get_driver_private(self); | |
5875 if (hba == NULL) | |
5876 return (ENXIO); | |
5877 | |
5878 /* | |
5879 * We can use the generic implementation for these ioctls | |
5880 */ | |
5881 switch (cmd) { | |
5882 case DEVCTL_DEVICE_GETSTATE: | |
5883 case DEVCTL_DEVICE_ONLINE: | |
5884 case DEVCTL_DEVICE_OFFLINE: | |
5885 case DEVCTL_DEVICE_REMOVE: | |
5886 case DEVCTL_BUS_GETSTATE: | |
5887 return (ndi_devctl_ioctl(self, cmd, arg, mode, 0)); | |
5888 } | |
5889 | |
5890 /* | |
5891 * read devctl ioctl data | |
5892 */ | |
5893 if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) | |
5894 return (EFAULT); | |
5895 | |
5896 switch (cmd) { | |
5897 | |
5898 case DEVCTL_DEVICE_RESET: | |
5899 /* | |
5900 * lookup and hold child device | |
5901 */ | |
5902 if ((child = ndi_devi_find(self, ndi_dc_getname(dcp), | |
5903 ndi_dc_getaddr(dcp))) == NULL) { | |
5904 rv = ENXIO; | |
5905 break; | |
5906 } | |
5907 retval = mdi_select_path(child, NULL, | |
5908 (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH), | |
5909 NULL, &pip); | |
5910 if ((retval != MDI_SUCCESS) || (pip == NULL)) { | |
5911 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioctl:" | |
5912 "Unable to get a path, dip 0x%p", (void *)child)); | |
5913 rv = ENXIO; | |
5914 break; | |
5915 } | |
5916 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
5917 if (vhci_recovery_reset(svp->svp_svl, | |
5918 &svp->svp_psd->sd_address, TRUE, | |
5919 VHCI_DEPTH_TARGET) == 0) { | |
5920 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
5921 "!vhci_ioctl(pip:%p): " | |
5922 "reset failed\n", (void *)pip)); | |
5923 rv = ENXIO; | |
5924 } | |
5925 mdi_rele_path(pip); | |
5926 break; | |
5927 | |
5928 case DEVCTL_BUS_QUIESCE: | |
5929 case DEVCTL_BUS_UNQUIESCE: | |
5930 case DEVCTL_BUS_RESET: | |
5931 case DEVCTL_BUS_RESETALL: | |
5932 #ifdef DEBUG | |
5933 case DEVCTL_BUS_CONFIGURE: | |
5934 case DEVCTL_BUS_UNCONFIGURE: | |
5935 #endif | |
5936 rv = ENOTSUP; | |
5937 break; | |
5938 | |
5939 default: | |
5940 rv = ENOTTY; | |
5941 } /* end of outer switch */ | |
5942 | |
5943 ndi_dc_freehdl(dcp); | |
5944 return (rv); | |
5945 } | |
5946 | |
5947 /* | |
5948 * Routine to get the PHCI pathname from ioctl structures in userland | |
5949 */ | |
5950 /* ARGSUSED */ | |
5951 static int | |
5952 vhci_ioc_get_phci_path(sv_iocdata_t *pioc, caddr_t phci_path, | |
5953 int mode, caddr_t s) | |
5954 { | |
5955 int retval = 0; | |
5956 | |
5957 if (ddi_copyin(pioc->phci, phci_path, MAXPATHLEN, mode)) { | |
5958 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioc_get_phci: ioctl <%s> " | |
5959 "phci_path copyin failed", s)); | |
5960 retval = EFAULT; | |
5961 } | |
5962 return (retval); | |
5963 | |
5964 } | |
5965 | |
5966 | |
5967 /* | |
5968 * Routine to get the Client device pathname from ioctl structures in userland | |
5969 */ | |
5970 /* ARGSUSED */ | |
5971 static int | |
5972 vhci_ioc_get_client_path(sv_iocdata_t *pioc, caddr_t client_path, | |
5973 int mode, caddr_t s) | |
5974 { | |
5975 int retval = 0; | |
5976 | |
5977 if (ddi_copyin(pioc->client, client_path, MAXPATHLEN, mode)) { | |
5978 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioc_get_client: " | |
5979 "ioctl <%s> client_path copyin failed", s)); | |
5980 retval = EFAULT; | |
5981 } | |
5982 return (retval); | |
5983 } | |
5984 | |
5985 | |
5986 /* | |
5987 * Routine to get physical device address from ioctl structure in userland | |
5988 */ | |
5989 /* ARGSUSED */ | |
5990 static int | |
5991 vhci_ioc_get_paddr(sv_iocdata_t *pioc, caddr_t paddr, int mode, caddr_t s) | |
5992 { | |
5993 int retval = 0; | |
5994 | |
5995 if (ddi_copyin(pioc->addr, paddr, MAXNAMELEN, mode)) { | |
5996 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioc_get_paddr: " | |
5997 "ioctl <%s> device addr copyin failed", s)); | |
5998 retval = EFAULT; | |
5999 } | |
6000 return (retval); | |
6001 } | |
6002 | |
6003 | |
6004 /* | |
6005 * Routine to send client device pathname to userland. | |
6006 */ | |
6007 /* ARGSUSED */ | |
6008 static int | |
6009 vhci_ioc_send_client_path(caddr_t client_path, sv_iocdata_t *pioc, | |
6010 int mode, caddr_t s) | |
6011 { | |
6012 int retval = 0; | |
6013 | |
6014 if (ddi_copyout(client_path, pioc->client, MAXPATHLEN, mode)) { | |
6015 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_ioc_send_client: " | |
6016 "ioctl <%s> client_path copyout failed", s)); | |
6017 retval = EFAULT; | |
6018 } | |
6019 return (retval); | |
6020 } | |
6021 | |
6022 | |
6023 /* | |
6024 * Routine to translated dev_info pointer (dip) to device pathname. | |
6025 */ | |
6026 static void | |
6027 vhci_ioc_devi_to_path(dev_info_t *dip, caddr_t path) | |
6028 { | |
6029 (void) ddi_pathname(dip, path); | |
6030 } | |
6031 | |
6032 | |
6033 /* | |
6034 * vhci_get_phci_path_list: | |
6035 * get information about devices associated with a | |
6036 * given PHCI device. | |
6037 * | |
6038 * Return Values: | |
6039 * path information elements | |
6040 */ | |
6041 int | |
6042 vhci_get_phci_path_list(dev_info_t *pdip, sv_path_info_t *pibuf, | |
6043 uint_t num_elems) | |
6044 { | |
6045 uint_t count, done; | |
6046 mdi_pathinfo_t *pip; | |
6047 sv_path_info_t *ret_pip; | |
6048 int status; | |
6049 size_t prop_size; | |
6050 int circular; | |
6051 | |
6052 /* | |
6053 * Get the PHCI structure and retrieve the path information | |
6054 * from the GUID hash table. | |
6055 */ | |
6056 | |
6057 ret_pip = pibuf; | |
6058 count = 0; | |
6059 | |
6060 ndi_devi_enter(pdip, &circular); | |
6061 | |
6062 done = (count >= num_elems); | |
6063 pip = mdi_get_next_client_path(pdip, NULL); | |
6064 while (pip && !done) { | |
6065 mdi_pi_lock(pip); | |
6066 (void) ddi_pathname(mdi_pi_get_phci(pip), | |
6067 ret_pip->device.ret_phci); | |
6068 (void) strcpy(ret_pip->ret_addr, mdi_pi_get_addr(pip)); | |
6069 (void) mdi_pi_get_state2(pip, &ret_pip->ret_state, | |
6070 &ret_pip->ret_ext_state); | |
6071 | |
6072 status = mdi_prop_size(pip, &prop_size); | |
6073 if (status == MDI_SUCCESS && ret_pip->ret_prop.ret_buf_size) { | |
6074 *ret_pip->ret_prop.ret_buf_size = (uint_t)prop_size; | |
6075 } | |
6076 | |
6077 #ifdef DEBUG | |
6078 if (status != MDI_SUCCESS) { | |
6079 VHCI_DEBUG(2, (CE_WARN, NULL, | |
6080 "!vhci_get_phci_path_list: " | |
6081 "phci <%s>, prop size failure 0x%x", | |
6082 ret_pip->device.ret_phci, status)); | |
6083 } | |
6084 #endif /* DEBUG */ | |
6085 | |
6086 | |
6087 if (status == MDI_SUCCESS && ret_pip->ret_prop.buf && | |
6088 prop_size && ret_pip->ret_prop.buf_size >= prop_size) { | |
6089 status = mdi_prop_pack(pip, | |
6090 &ret_pip->ret_prop.buf, | |
6091 ret_pip->ret_prop.buf_size); | |
6092 | |
6093 #ifdef DEBUG | |
6094 if (status != MDI_SUCCESS) { | |
6095 VHCI_DEBUG(2, (CE_WARN, NULL, | |
6096 "!vhci_get_phci_path_list: " | |
6097 "phci <%s>, prop pack failure 0x%x", | |
6098 ret_pip->device.ret_phci, status)); | |
6099 } | |
6100 #endif /* DEBUG */ | |
6101 } | |
6102 | |
6103 mdi_pi_unlock(pip); | |
6104 pip = mdi_get_next_client_path(pdip, pip); | |
6105 ret_pip++; | |
6106 count++; | |
6107 done = (count >= num_elems); | |
6108 } | |
6109 | |
6110 ndi_devi_exit(pdip, circular); | |
6111 | |
6112 return (MDI_SUCCESS); | |
6113 } | |
6114 | |
6115 | |
6116 /* | |
6117 * vhci_get_client_path_list: | |
6118 * get information about various paths associated with a | |
6119 * given client device. | |
6120 * | |
6121 * Return Values: | |
6122 * path information elements | |
6123 */ | |
6124 int | |
6125 vhci_get_client_path_list(dev_info_t *cdip, sv_path_info_t *pibuf, | |
6126 uint_t num_elems) | |
6127 { | |
6128 uint_t count, done; | |
6129 mdi_pathinfo_t *pip; | |
6130 sv_path_info_t *ret_pip; | |
6131 int status; | |
6132 size_t prop_size; | |
6133 int circular; | |
6134 | |
6135 ret_pip = pibuf; | |
6136 count = 0; | |
6137 | |
6138 ndi_devi_enter(cdip, &circular); | |
6139 | |
6140 done = (count >= num_elems); | |
6141 pip = mdi_get_next_phci_path(cdip, NULL); | |
6142 while (pip && !done) { | |
6143 mdi_pi_lock(pip); | |
6144 (void) ddi_pathname(mdi_pi_get_phci(pip), | |
6145 ret_pip->device.ret_phci); | |
6146 (void) strcpy(ret_pip->ret_addr, mdi_pi_get_addr(pip)); | |
6147 (void) mdi_pi_get_state2(pip, &ret_pip->ret_state, | |
6148 &ret_pip->ret_ext_state); | |
6149 | |
6150 status = mdi_prop_size(pip, &prop_size); | |
6151 if (status == MDI_SUCCESS && ret_pip->ret_prop.ret_buf_size) { | |
6152 *ret_pip->ret_prop.ret_buf_size = (uint_t)prop_size; | |
6153 } | |
6154 | |
6155 #ifdef DEBUG | |
6156 if (status != MDI_SUCCESS) { | |
6157 VHCI_DEBUG(2, (CE_WARN, NULL, | |
6158 "!vhci_get_client_path_list: " | |
6159 "phci <%s>, prop size failure 0x%x", | |
6160 ret_pip->device.ret_phci, status)); | |
6161 } | |
6162 #endif /* DEBUG */ | |
6163 | |
6164 | |
6165 if (status == MDI_SUCCESS && ret_pip->ret_prop.buf && | |
6166 prop_size && ret_pip->ret_prop.buf_size >= prop_size) { | |
6167 status = mdi_prop_pack(pip, | |
6168 &ret_pip->ret_prop.buf, | |
6169 ret_pip->ret_prop.buf_size); | |
6170 | |
6171 #ifdef DEBUG | |
6172 if (status != MDI_SUCCESS) { | |
6173 VHCI_DEBUG(2, (CE_WARN, NULL, | |
6174 "!vhci_get_client_path_list: " | |
6175 "phci <%s>, prop pack failure 0x%x", | |
6176 ret_pip->device.ret_phci, status)); | |
6177 } | |
6178 #endif /* DEBUG */ | |
6179 } | |
6180 | |
6181 mdi_pi_unlock(pip); | |
6182 pip = mdi_get_next_phci_path(cdip, pip); | |
6183 ret_pip++; | |
6184 count++; | |
6185 done = (count >= num_elems); | |
6186 } | |
6187 | |
6188 ndi_devi_exit(cdip, circular); | |
6189 | |
6190 return (MDI_SUCCESS); | |
6191 } | |
6192 | |
6193 | |
6194 /* | |
6195 * Routine to get ioctl argument structure from userland. | |
6196 */ | |
6197 /* ARGSUSED */ | |
6198 static int | |
6199 vhci_get_iocdata(const void *data, sv_iocdata_t *pioc, int mode, caddr_t s) | |
6200 { | |
6201 int retval = 0; | |
6202 | |
6203 #ifdef _MULTI_DATAMODEL | |
6204 switch (ddi_model_convert_from(mode & FMODELS)) { | |
6205 case DDI_MODEL_ILP32: | |
6206 { | |
6207 sv_iocdata32_t ioc32; | |
6208 | |
6209 if (ddi_copyin(data, &ioc32, sizeof (ioc32), mode)) { | |
6210 retval = EFAULT; | |
6211 break; | |
6212 } | |
6213 pioc->client = (caddr_t)(uintptr_t)ioc32.client; | |
6214 pioc->phci = (caddr_t)(uintptr_t)ioc32.phci; | |
6215 pioc->addr = (caddr_t)(uintptr_t)ioc32.addr; | |
6216 pioc->buf_elem = (uint_t)ioc32.buf_elem; | |
6217 pioc->ret_buf = (sv_path_info_t *)(uintptr_t)ioc32.ret_buf; | |
6218 pioc->ret_elem = (uint_t *)(uintptr_t)ioc32.ret_elem; | |
6219 break; | |
6220 } | |
6221 | |
6222 case DDI_MODEL_NONE: | |
6223 if (ddi_copyin(data, pioc, sizeof (*pioc), mode)) { | |
6224 retval = EFAULT; | |
6225 break; | |
6226 } | |
6227 break; | |
6228 } | |
6229 #else /* _MULTI_DATAMODEL */ | |
6230 if (ddi_copyin(data, pioc, sizeof (*pioc), mode)) { | |
6231 retval = EFAULT; | |
6232 } | |
6233 #endif /* _MULTI_DATAMODEL */ | |
6234 | |
6235 #ifdef DEBUG | |
6236 if (retval) { | |
6237 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_get_ioc: cmd <%s> " | |
6238 "iocdata copyin failed", s)); | |
6239 } | |
6240 #endif | |
6241 | |
6242 return (retval); | |
6243 } | |
6244 | |
6245 | |
6246 /* | |
6247 * Routine to get the ioctl argument for ioctl causing controller switchover. | |
6248 */ | |
6249 /* ARGSUSED */ | |
6250 static int | |
6251 vhci_get_iocswitchdata(const void *data, sv_switch_to_cntlr_iocdata_t *piocsc, | |
6252 int mode, caddr_t s) | |
6253 { | |
6254 int retval = 0; | |
6255 | |
6256 #ifdef _MULTI_DATAMODEL | |
6257 switch (ddi_model_convert_from(mode & FMODELS)) { | |
6258 case DDI_MODEL_ILP32: | |
6259 { | |
6260 sv_switch_to_cntlr_iocdata32_t ioc32; | |
6261 | |
6262 if (ddi_copyin(data, &ioc32, sizeof (ioc32), mode)) { | |
6263 retval = EFAULT; | |
6264 break; | |
6265 } | |
6266 piocsc->client = (caddr_t)(uintptr_t)ioc32.client; | |
6267 piocsc->class = (caddr_t)(uintptr_t)ioc32.class; | |
6268 break; | |
6269 } | |
6270 | |
6271 case DDI_MODEL_NONE: | |
6272 if (ddi_copyin(data, piocsc, sizeof (*piocsc), mode)) { | |
6273 retval = EFAULT; | |
6274 } | |
6275 break; | |
6276 } | |
6277 #else /* _MULTI_DATAMODEL */ | |
6278 if (ddi_copyin(data, piocsc, sizeof (*piocsc), mode)) { | |
6279 retval = EFAULT; | |
6280 } | |
6281 #endif /* _MULTI_DATAMODEL */ | |
6282 | |
6283 #ifdef DEBUG | |
6284 if (retval) { | |
6285 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_get_ioc: cmd <%s> " | |
6286 "switch_to_cntlr_iocdata copyin failed", s)); | |
6287 } | |
6288 #endif | |
6289 | |
6290 return (retval); | |
6291 } | |
6292 | |
6293 | |
6294 /* | |
6295 * Routine to allocate memory for the path information structures. | |
6296 * It allocates two chunks of memory - one for keeping userland | |
6297 * pointers/values for path information and path properties, second for | |
6298 * keeping allocating kernel memory for path properties. These path | |
6299 * properties are finally copied to userland. | |
6300 */ | |
6301 /* ARGSUSED */ | |
6302 static int | |
6303 vhci_ioc_alloc_pathinfo(sv_path_info_t **upibuf, sv_path_info_t **kpibuf, | |
6304 uint_t num_paths, sv_iocdata_t *pioc, int mode, caddr_t s) | |
6305 { | |
6306 sv_path_info_t *pi; | |
6307 uint_t bufsize; | |
6308 int retval = 0; | |
6309 int index; | |
6310 | |
6311 /* Allocate memory */ | |
6312 *upibuf = (sv_path_info_t *) | |
6313 kmem_zalloc(sizeof (sv_path_info_t) * num_paths, KM_SLEEP); | |
6314 ASSERT(*upibuf != NULL); | |
6315 *kpibuf = (sv_path_info_t *) | |
6316 kmem_zalloc(sizeof (sv_path_info_t) * num_paths, KM_SLEEP); | |
6317 ASSERT(*kpibuf != NULL); | |
6318 | |
6319 /* | |
6320 * Get the path info structure from the user space. | |
6321 * We are interested in the following fields: | |
6322 * - user size of buffer for per path properties. | |
6323 * - user address of buffer for path info properties. | |
6324 * - user pointer for returning actual buffer size | |
6325 * Keep these fields in the 'upibuf' structures. | |
6326 * Allocate buffer for per path info properties in kernel | |
6327 * structure ('kpibuf'). | |
6328 * Size of these buffers will be equal to the size of buffers | |
6329 * in the user space. | |
6330 */ | |
6331 #ifdef _MULTI_DATAMODEL | |
6332 switch (ddi_model_convert_from(mode & FMODELS)) { | |
6333 case DDI_MODEL_ILP32: | |
6334 { | |
6335 sv_path_info32_t *src; | |
6336 sv_path_info32_t pi32; | |
6337 | |
6338 src = (sv_path_info32_t *)pioc->ret_buf; | |
6339 pi = (sv_path_info_t *)*upibuf; | |
6340 for (index = 0; index < num_paths; index++, src++, pi++) { | |
6341 if (ddi_copyin(src, &pi32, sizeof (pi32), mode)) { | |
6342 retval = EFAULT; | |
6343 break; | |
6344 } | |
6345 | |
6346 pi->ret_prop.buf_size = | |
6347 (uint_t)pi32.ret_prop.buf_size; | |
6348 pi->ret_prop.ret_buf_size = | |
6349 (uint_t *)(uintptr_t)pi32.ret_prop.ret_buf_size; | |
6350 pi->ret_prop.buf = | |
6351 (caddr_t)(uintptr_t)pi32.ret_prop.buf; | |
6352 } | |
6353 break; | |
6354 } | |
6355 | |
6356 case DDI_MODEL_NONE: | |
6357 if (ddi_copyin(pioc->ret_buf, *upibuf, | |
6358 sizeof (sv_path_info_t) * num_paths, mode)) { | |
6359 retval = EFAULT; | |
6360 } | |
6361 break; | |
6362 } | |
6363 #else /* _MULTI_DATAMODEL */ | |
6364 if (ddi_copyin(pioc->ret_buf, *upibuf, | |
6365 sizeof (sv_path_info_t) * num_paths, mode)) { | |
6366 retval = EFAULT; | |
6367 } | |
6368 #endif /* _MULTI_DATAMODEL */ | |
6369 | |
6370 if (retval != 0) { | |
6371 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_alloc_path_info: " | |
6372 "ioctl <%s> normal: path_info copyin failed", s)); | |
6373 kmem_free(*upibuf, sizeof (sv_path_info_t) * num_paths); | |
6374 kmem_free(*kpibuf, sizeof (sv_path_info_t) * num_paths); | |
6375 *upibuf = NULL; | |
6376 *kpibuf = NULL; | |
6377 return (retval); | |
6378 } | |
6379 | |
6380 /* | |
6381 * Allocate memory for per path properties. | |
6382 */ | |
6383 for (index = 0, pi = *kpibuf; index < num_paths; index++, pi++) { | |
6384 bufsize = (*upibuf)[index].ret_prop.buf_size; | |
6385 | |
6386 if (bufsize && bufsize <= SV_PROP_MAX_BUF_SIZE) { | |
6387 pi->ret_prop.buf_size = bufsize; | |
6388 pi->ret_prop.buf = (caddr_t) | |
6389 kmem_zalloc(bufsize, KM_SLEEP); | |
6390 ASSERT(pi->ret_prop.buf != NULL); | |
6391 } else { | |
6392 pi->ret_prop.buf_size = 0; | |
6393 pi->ret_prop.buf = NULL; | |
6394 } | |
6395 | |
6396 if ((*upibuf)[index].ret_prop.ret_buf_size != NULL) { | |
6397 pi->ret_prop.ret_buf_size = (uint_t *)kmem_zalloc( | |
6398 sizeof (*pi->ret_prop.ret_buf_size), KM_SLEEP); | |
6399 ASSERT(pi->ret_prop.ret_buf_size != NULL); | |
6400 } else { | |
6401 pi->ret_prop.ret_buf_size = NULL; | |
6402 } | |
6403 } | |
6404 | |
6405 return (0); | |
6406 } | |
6407 | |
6408 | |
6409 /* | |
6410 * Routine to free memory for the path information structures. | |
6411 * This is the memory which was allocated earlier. | |
6412 */ | |
6413 /* ARGSUSED */ | |
6414 static void | |
6415 vhci_ioc_free_pathinfo(sv_path_info_t *upibuf, sv_path_info_t *kpibuf, | |
6416 uint_t num_paths) | |
6417 { | |
6418 sv_path_info_t *pi; | |
6419 int index; | |
6420 | |
6421 /* Free memory for per path properties */ | |
6422 for (index = 0, pi = kpibuf; index < num_paths; index++, pi++) { | |
6423 if (pi->ret_prop.ret_buf_size != NULL) { | |
6424 kmem_free(pi->ret_prop.ret_buf_size, | |
6425 sizeof (*pi->ret_prop.ret_buf_size)); | |
6426 } | |
6427 | |
6428 if (pi->ret_prop.buf != NULL) { | |
6429 kmem_free(pi->ret_prop.buf, pi->ret_prop.buf_size); | |
6430 } | |
6431 } | |
6432 | |
6433 /* Free memory for path info structures */ | |
6434 kmem_free(upibuf, sizeof (sv_path_info_t) * num_paths); | |
6435 kmem_free(kpibuf, sizeof (sv_path_info_t) * num_paths); | |
6436 } | |
6437 | |
6438 | |
6439 /* | |
6440 * Routine to copy path information and path properties to userland. | |
6441 */ | |
6442 /* ARGSUSED */ | |
6443 static int | |
6444 vhci_ioc_send_pathinfo(sv_path_info_t *upibuf, sv_path_info_t *kpibuf, | |
6445 uint_t num_paths, sv_iocdata_t *pioc, int mode, caddr_t s) | |
6446 { | |
6447 int retval = 0, index; | |
6448 sv_path_info_t *upi_ptr; | |
6449 sv_path_info32_t *upi32_ptr; | |
6450 | |
6451 #ifdef _MULTI_DATAMODEL | |
6452 switch (ddi_model_convert_from(mode & FMODELS)) { | |
6453 case DDI_MODEL_ILP32: | |
6454 goto copy_32bit; | |
6455 | |
6456 case DDI_MODEL_NONE: | |
6457 goto copy_normal; | |
6458 } | |
6459 #else /* _MULTI_DATAMODEL */ | |
6460 | |
6461 goto copy_normal; | |
6462 | |
6463 #endif /* _MULTI_DATAMODEL */ | |
6464 | |
6465 copy_normal: | |
6466 | |
6467 /* | |
6468 * Copy path information and path properties to user land. | |
6469 * Pointer fields inside the path property structure were | |
6470 * saved in the 'upibuf' structure earlier. | |
6471 */ | |
6472 upi_ptr = pioc->ret_buf; | |
6473 for (index = 0; index < num_paths; index++) { | |
6474 if (ddi_copyout(kpibuf[index].device.ret_ct, | |
6475 upi_ptr[index].device.ret_ct, MAXPATHLEN, mode)) { | |
6476 retval = EFAULT; | |
6477 break; | |
6478 } | |
6479 | |
6480 if (ddi_copyout(kpibuf[index].ret_addr, | |
6481 upi_ptr[index].ret_addr, MAXNAMELEN, mode)) { | |
6482 retval = EFAULT; | |
6483 break; | |
6484 } | |
6485 | |
6486 if (ddi_copyout(&kpibuf[index].ret_state, | |
6487 &upi_ptr[index].ret_state, sizeof (kpibuf[index].ret_state), | |
6488 mode)) { | |
6489 retval = EFAULT; | |
6490 break; | |
6491 } | |
6492 | |
6493 if (ddi_copyout(&kpibuf[index].ret_ext_state, | |
6494 &upi_ptr[index].ret_ext_state, | |
6495 sizeof (kpibuf[index].ret_ext_state), mode)) { | |
6496 retval = EFAULT; | |
6497 break; | |
6498 } | |
6499 | |
6500 if ((kpibuf[index].ret_prop.ret_buf_size != NULL) && | |
6501 ddi_copyout(kpibuf[index].ret_prop.ret_buf_size, | |
6502 upibuf[index].ret_prop.ret_buf_size, | |
6503 sizeof (*upibuf[index].ret_prop.ret_buf_size), mode)) { | |
6504 retval = EFAULT; | |
6505 break; | |
6506 } | |
6507 | |
6508 if ((kpibuf[index].ret_prop.buf != NULL) && | |
6509 ddi_copyout(kpibuf[index].ret_prop.buf, | |
6510 upibuf[index].ret_prop.buf, | |
6511 upibuf[index].ret_prop.buf_size, mode)) { | |
6512 retval = EFAULT; | |
6513 break; | |
6514 } | |
6515 } | |
6516 | |
6517 #ifdef DEBUG | |
6518 if (retval) { | |
6519 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_get_ioc: ioctl <%s> " | |
6520 "normal: path_info copyout failed", s)); | |
6521 } | |
6522 #endif | |
6523 | |
6524 return (retval); | |
6525 | |
6526 copy_32bit: | |
6527 /* | |
6528 * Copy path information and path properties to user land. | |
6529 * Pointer fields inside the path property structure were | |
6530 * saved in the 'upibuf' structure earlier. | |
6531 */ | |
6532 upi32_ptr = (sv_path_info32_t *)pioc->ret_buf; | |
6533 for (index = 0; index < num_paths; index++) { | |
6534 if (ddi_copyout(kpibuf[index].device.ret_ct, | |
6535 upi32_ptr[index].device.ret_ct, MAXPATHLEN, mode)) { | |
6536 retval = EFAULT; | |
6537 break; | |
6538 } | |
6539 | |
6540 if (ddi_copyout(kpibuf[index].ret_addr, | |
6541 upi32_ptr[index].ret_addr, MAXNAMELEN, mode)) { | |
6542 retval = EFAULT; | |
6543 break; | |
6544 } | |
6545 | |
6546 if (ddi_copyout(&kpibuf[index].ret_state, | |
6547 &upi32_ptr[index].ret_state, | |
6548 sizeof (kpibuf[index].ret_state), mode)) { | |
6549 retval = EFAULT; | |
6550 break; | |
6551 } | |
6552 | |
6553 if (ddi_copyout(&kpibuf[index].ret_ext_state, | |
6554 &upi32_ptr[index].ret_ext_state, | |
6555 sizeof (kpibuf[index].ret_ext_state), mode)) { | |
6556 retval = EFAULT; | |
6557 break; | |
6558 } | |
6559 if ((kpibuf[index].ret_prop.ret_buf_size != NULL) && | |
6560 ddi_copyout(kpibuf[index].ret_prop.ret_buf_size, | |
6561 upibuf[index].ret_prop.ret_buf_size, | |
6562 sizeof (*upibuf[index].ret_prop.ret_buf_size), mode)) { | |
6563 retval = EFAULT; | |
6564 break; | |
6565 } | |
6566 | |
6567 if ((kpibuf[index].ret_prop.buf != NULL) && | |
6568 ddi_copyout(kpibuf[index].ret_prop.buf, | |
6569 upibuf[index].ret_prop.buf, | |
6570 upibuf[index].ret_prop.buf_size, mode)) { | |
6571 retval = EFAULT; | |
6572 break; | |
6573 } | |
6574 } | |
6575 | |
6576 #ifdef DEBUG | |
6577 if (retval) { | |
6578 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_get_ioc: ioctl <%s> " | |
6579 "normal: path_info copyout failed", s)); | |
6580 } | |
6581 #endif | |
6582 | |
6583 return (retval); | |
6584 } | |
6585 | |
6586 | |
6587 /* | |
6588 * vhci_failover() | |
6589 * This routine expects VHCI_HOLD_LUN before being invoked. It can be invoked | |
6590 * as MDI_FAILOVER_ASYNC or MDI_FAILOVER_SYNC. For Asynchronous failovers | |
6591 * this routine shall VHCI_RELEASE_LUN on exiting. For synchronous failovers | |
6592 * it is the callers responsibility to release lun. | |
6593 */ | |
6594 | |
6595 /* ARGSUSED */ | |
6596 static int | |
6597 vhci_failover(dev_info_t *vdip, dev_info_t *cdip, int flags) | |
6598 { | |
6599 char *guid; | |
6600 scsi_vhci_lun_t *vlun = NULL; | |
6601 struct scsi_vhci *vhci; | |
6602 mdi_pathinfo_t *pip, *npip; | |
6603 char *s_pclass, *pclass1, *pclass2, *pclass; | |
6604 char active_pclass_copy[255], *active_pclass_ptr; | |
6605 char *ptr1, *ptr2; | |
6606 mdi_pathinfo_state_t pi_state; | |
6607 uint32_t pi_ext_state; | |
6608 scsi_vhci_priv_t *svp; | |
6609 struct scsi_device *sd; | |
6610 struct scsi_failover_ops *sfo; | |
6611 int sps; /* mdi_select_path() status */ | |
6612 int activation_done = 0; | |
6613 int rval, retval = MDI_FAILURE; | |
6614 int reserve_pending, check_condition, UA_condition; | |
6615 struct scsi_pkt *pkt; | |
6616 struct buf *bp; | |
6617 | |
6618 vhci = ddi_get_soft_state(vhci_softstate, ddi_get_instance(vdip)); | |
6619 sd = ddi_get_driver_private(cdip); | |
6620 vlun = ADDR2VLUN(&sd->sd_address); | |
6621 ASSERT(vlun != 0); | |
6622 ASSERT(VHCI_LUN_IS_HELD(vlun)); | |
6623 guid = vlun->svl_lun_wwn; | |
6624 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(1): guid %s\n", guid)); | |
6625 vhci_log(CE_NOTE, vdip, "!Initiating failover for device %s " | |
6626 "(GUID %s)", ddi_node_name(cdip), guid); | |
6627 | |
6628 /* | |
6629 * Lets maintain a local copy of the vlun->svl_active_pclass | |
6630 * for the rest of the processing. Accessing the field | |
6631 * directly in the loop below causes loop logic to break | |
6632 * especially when the field gets updated by other threads | |
6633 * update path status etc and causes 'paths are not currently | |
6634 * available' condition to be declared prematurely. | |
6635 */ | |
6636 mutex_enter(&vlun->svl_mutex); | |
6637 if (vlun->svl_active_pclass != NULL) { | |
6638 (void) strlcpy(active_pclass_copy, vlun->svl_active_pclass, | |
6639 sizeof (active_pclass_copy)); | |
6640 active_pclass_ptr = &active_pclass_copy[0]; | |
6641 mutex_exit(&vlun->svl_mutex); | |
6642 if (vhci_quiesce_paths(vdip, cdip, vlun, guid, | |
6643 active_pclass_ptr) != 0) { | |
6644 retval = MDI_FAILURE; | |
6645 } | |
6646 } else { | |
6647 /* | |
6648 * can happen only when the available path to device | |
6649 * discovered is a STANDBY path. | |
6650 */ | |
6651 mutex_exit(&vlun->svl_mutex); | |
6652 active_pclass_copy[0] = '\0'; | |
6653 active_pclass_ptr = NULL; | |
6654 } | |
6655 | |
6656 sfo = vlun->svl_fops; | |
6657 ASSERT(sfo != NULL); | |
6658 pclass1 = s_pclass = active_pclass_ptr; | |
6659 VHCI_DEBUG(1, (CE_NOTE, NULL, "!(%s)failing over from %s\n", guid, | |
6660 (s_pclass == NULL ? "<none>" : s_pclass))); | |
6661 | |
6662 next_pathclass: | |
6663 | |
6664 rval = (*sfo->sfo_pathclass_next)(pclass1, &pclass2, | |
6665 vlun->svl_fops_ctpriv); | |
6666 if (rval == ENOENT) { | |
6667 if (s_pclass == NULL) { | |
6668 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(4)(%s): " | |
6669 "failed, no more pathclasses\n", guid)); | |
6670 goto done; | |
6671 } else { | |
6672 (*sfo->sfo_pathclass_next)(NULL, &pclass2, | |
6673 vlun->svl_fops_ctpriv); | |
6674 } | |
6675 } else if (rval == EINVAL) { | |
6676 vhci_log(CE_NOTE, vdip, "!Failover operation failed for " | |
6677 "device %s (GUID %s): Invalid path-class %s", | |
6678 ddi_node_name(cdip), guid, | |
6679 ((pclass1 == NULL) ? "<none>" : pclass1)); | |
6680 goto done; | |
6681 } | |
6682 if ((s_pclass != NULL) && (strcmp(pclass2, s_pclass) == 0)) { | |
6683 /* | |
6684 * paths are not currently available | |
6685 */ | |
6686 vhci_log(CE_NOTE, vdip, "!Failover path currently unavailable" | |
6687 " for device %s (GUID %s)", | |
6688 ddi_node_name(cdip), guid); | |
6689 goto done; | |
6690 } | |
6691 pip = npip = NULL; | |
6692 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(5.2)(%s): considering " | |
6693 "%s as failover destination\n", guid, pclass2)); | |
6694 sps = mdi_select_path(cdip, NULL, MDI_SELECT_STANDBY_PATH, NULL, &npip); | |
6695 if ((npip == NULL) || (sps != MDI_SUCCESS)) { | |
6696 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(%s): no " | |
6697 "STANDBY paths found (status:%x)!\n", guid, sps)); | |
6698 pclass1 = pclass2; | |
6699 goto next_pathclass; | |
6700 } | |
6701 do { | |
6702 pclass = NULL; | |
6703 if ((mdi_prop_lookup_string(npip, "path-class", | |
6704 &pclass) != MDI_SUCCESS) || (strcmp(pclass2, | |
6705 pclass) != 0)) { | |
6706 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6707 "!vhci_failover(5.5)(%s): skipping path " | |
6708 "%p(%s)...\n", guid, (void *)npip, pclass)); | |
6709 pip = npip; | |
6710 sps = mdi_select_path(cdip, NULL, | |
6711 MDI_SELECT_STANDBY_PATH, pip, &npip); | |
6712 mdi_rele_path(pip); | |
6713 (void) mdi_prop_free(pclass); | |
6714 continue; | |
6715 } | |
6716 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(npip); | |
6717 | |
6718 /* | |
6719 * Issue READ at non-zer block on this STANDBY path. | |
6720 * Purple returns | |
6721 * 1. RESERVATION_CONFLICT if reservation is pending | |
6722 * 2. POR check condition if it reset happened. | |
6723 * 2. failover Check Conditions if one is already in progress. | |
6724 */ | |
6725 reserve_pending = 0; | |
6726 check_condition = 0; | |
6727 UA_condition = 0; | |
6728 | |
6729 bp = scsi_alloc_consistent_buf(&svp->svp_psd->sd_address, | |
6730 (struct buf *)NULL, DEV_BSIZE, B_READ, NULL, NULL); | |
6731 if (!bp) { | |
6732 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6733 "vhci_failover !No resources (buf)\n")); | |
6734 mdi_rele_path(npip); | |
6735 goto done; | |
6736 } | |
6737 pkt = scsi_init_pkt(&svp->svp_psd->sd_address, NULL, bp, | |
6738 CDB_GROUP1, sizeof (struct scsi_arq_status), 0, | |
6739 PKT_CONSISTENT, NULL, NULL); | |
6740 if (pkt) { | |
6741 (void) scsi_setup_cdb((union scsi_cdb *)(uintptr_t) | |
6742 pkt->pkt_cdbp, SCMD_READ, 1, 1, 0); | |
6743 pkt->pkt_flags = FLAG_NOINTR; | |
6744 check_path_again: | |
6745 pkt->pkt_time = 3*30; | |
6746 if (scsi_transport(pkt) == TRAN_ACCEPT) { | |
6747 switch (pkt->pkt_reason) { | |
6748 case CMD_CMPLT: | |
6749 switch (SCBP_C(pkt)) { | |
6750 case STATUS_GOOD: | |
6751 /* Already failed over */ | |
6752 activation_done = 1; | |
6753 break; | |
6754 case STATUS_RESERVATION_CONFLICT: | |
6755 reserve_pending = 1; | |
6756 break; | |
6757 case STATUS_CHECK: | |
6758 check_condition = 1; | |
6759 break; | |
6760 } | |
6761 } | |
6762 } | |
6763 if (check_condition && | |
6764 (pkt->pkt_state & STATE_ARQ_DONE)) { | |
6765 struct scsi_extended_sense *sns = | |
6766 &(((struct scsi_arq_status *)(uintptr_t) | |
6767 (pkt->pkt_scbp))->sts_sensedata); | |
6768 if (sns->es_key == KEY_UNIT_ATTENTION && | |
6769 sns->es_add_code == 0x29) { | |
6770 /* Already failed over */ | |
6771 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6772 "!vhci_failover(7)(%s): " | |
6773 "path 0x%p POR UA condition\n", | |
6774 guid, (void *)npip)); | |
6775 if (UA_condition == 0) { | |
6776 UA_condition = 1; | |
6777 goto check_path_again; | |
6778 } | |
6779 } else { | |
6780 activation_done = 0; | |
6781 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6782 "!vhci_failover(%s): path 0x%p " | |
6783 "unhandled chkcond %x %x %x\n", | |
6784 guid, (void *)npip, sns->es_key, | |
6785 sns->es_add_code, | |
6786 sns->es_qual_code)); | |
6787 } | |
6788 } | |
6789 scsi_destroy_pkt(pkt); | |
6790 } | |
6791 scsi_free_consistent_buf(bp); | |
6792 | |
6793 if (activation_done) { | |
6794 mdi_rele_path(npip); | |
6795 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(7)(%s): " | |
6796 "path 0x%p already failedover\n", guid, | |
6797 (void *)npip)); | |
6798 break; | |
6799 } | |
6800 if (reserve_pending && (vlun->svl_xlf_capable == 0)) { | |
6801 (void) vhci_recovery_reset(vlun, | |
6802 &svp->svp_psd->sd_address, | |
6803 FALSE, VHCI_DEPTH_ALL); | |
6804 } | |
6805 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(6)(%s): " | |
6806 "activating path 0x%p(psd:%p)\n", guid, (void *)npip, | |
6807 (void *)svp->svp_psd)); | |
6808 if ((*sfo->sfo_path_activate)(svp->svp_psd, pclass2, | |
6809 vlun->svl_fops_ctpriv) == 0) { | |
6810 activation_done = 1; | |
6811 mdi_rele_path(npip); | |
6812 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(7)(%s): " | |
6813 "path 0x%p successfully activated\n", guid, | |
6814 (void *)npip)); | |
6815 break; | |
6816 } | |
6817 pip = npip; | |
6818 sps = mdi_select_path(cdip, NULL, MDI_SELECT_STANDBY_PATH, | |
6819 pip, &npip); | |
6820 mdi_rele_path(pip); | |
6821 } while ((npip != NULL) && (sps == MDI_SUCCESS)); | |
6822 if (activation_done == 0) { | |
6823 pclass1 = pclass2; | |
6824 goto next_pathclass; | |
6825 } | |
6826 | |
6827 /* | |
6828 * if we are here, we have succeeded in activating path npip of | |
6829 * pathclass pclass2; let us validate all paths of pclass2 by | |
6830 * "ping"-ing each one and mark the good ones ONLINE | |
6831 * Also, set the state of the paths belonging to the previously | |
6832 * active pathclass to STANDBY | |
6833 */ | |
6834 pip = npip = NULL; | |
6835 sps = mdi_select_path(cdip, NULL, (MDI_SELECT_ONLINE_PATH | | |
6836 MDI_SELECT_STANDBY_PATH | MDI_SELECT_USER_DISABLE_PATH), | |
6837 NULL, &npip); | |
6838 if (npip == NULL || sps != MDI_SUCCESS) { | |
6839 VHCI_DEBUG(1, (CE_NOTE, NULL, "!Failover operation failed for " | |
6840 "device %s (GUID %s): paths may be busy\n", | |
6841 ddi_node_name(cdip), guid)); | |
6842 goto done; | |
6843 } | |
6844 do { | |
6845 (void) mdi_pi_get_state2(npip, &pi_state, &pi_ext_state); | |
6846 if (mdi_prop_lookup_string(npip, "path-class", &pclass) | |
6847 != MDI_SUCCESS) { | |
6848 pip = npip; | |
6849 sps = mdi_select_path(cdip, NULL, | |
6850 (MDI_SELECT_ONLINE_PATH | | |
6851 MDI_SELECT_STANDBY_PATH | | |
6852 MDI_SELECT_USER_DISABLE_PATH), | |
6853 pip, &npip); | |
6854 mdi_rele_path(pip); | |
6855 continue; | |
6856 } | |
6857 if (strcmp(pclass, pclass2) == 0) { | |
6858 if (pi_state == MDI_PATHINFO_STATE_STANDBY) { | |
6859 svp = (scsi_vhci_priv_t *) | |
6860 mdi_pi_get_vhci_private(npip); | |
6861 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6862 "!vhci_failover(8)(%s): " | |
6863 "pinging path 0x%p\n", | |
6864 guid, (void *)npip)); | |
6865 if ((*sfo->sfo_path_ping)(svp->svp_psd, | |
6866 vlun->svl_fops_ctpriv) == 1) { | |
6867 mdi_pi_set_state(npip, | |
6868 MDI_PATHINFO_STATE_ONLINE); | |
6869 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6870 "!vhci_failover(9)(%s): " | |
6871 "path 0x%p ping successful, " | |
6872 "marked online\n", guid, | |
6873 (void *)npip)); | |
6874 MDI_PI_ERRSTAT(npip, MDI_PI_FAILTO); | |
6875 } | |
6876 } | |
6877 } else if ((s_pclass != NULL) && (strcmp(pclass, s_pclass) | |
6878 == 0)) { | |
6879 if (pi_state == MDI_PATHINFO_STATE_ONLINE) { | |
6880 mdi_pi_set_state(npip, | |
6881 MDI_PATHINFO_STATE_STANDBY); | |
6882 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6883 "!vhci_failover(10)(%s): path 0x%p marked " | |
6884 "STANDBY\n", guid, (void *)npip)); | |
6885 MDI_PI_ERRSTAT(npip, MDI_PI_FAILFROM); | |
6886 } | |
6887 } | |
6888 (void) mdi_prop_free(pclass); | |
6889 pip = npip; | |
6890 sps = mdi_select_path(cdip, NULL, (MDI_SELECT_ONLINE_PATH | | |
6891 MDI_SELECT_STANDBY_PATH|MDI_SELECT_USER_DISABLE_PATH), | |
6892 pip, &npip); | |
6893 mdi_rele_path(pip); | |
6894 } while ((npip != NULL) && (sps == MDI_SUCCESS)); | |
6895 | |
6896 /* | |
6897 * Update the AccessState of related MP-API TPGs | |
6898 */ | |
6899 (void) vhci_mpapi_update_tpg_acc_state_for_lu(vhci, vlun); | |
6900 | |
6901 vhci_log(CE_NOTE, vdip, "!Failover operation completed successfully " | |
6902 "for device %s (GUID %s): failed over from %s to %s", | |
6903 ddi_node_name(cdip), guid, ((s_pclass == NULL) ? "<none>" : | |
6904 s_pclass), pclass2); | |
6905 ptr1 = kmem_alloc(strlen(pclass2)+1, KM_SLEEP); | |
6906 (void) strlcpy(ptr1, pclass2, (strlen(pclass2)+1)); | |
6907 mutex_enter(&vlun->svl_mutex); | |
6908 ptr2 = vlun->svl_active_pclass; | |
6909 vlun->svl_active_pclass = ptr1; | |
6910 mutex_exit(&vlun->svl_mutex); | |
6911 if (ptr2) { | |
6912 kmem_free(ptr2, strlen(ptr2)+1); | |
6913 } | |
6914 mutex_enter(&vhci->vhci_mutex); | |
6915 scsi_hba_reset_notify_callback(&vhci->vhci_mutex, | |
6916 &vhci->vhci_reset_notify_listf); | |
6917 /* All reservations are cleared upon these resets. */ | |
6918 vlun->svl_flags &= ~VLUN_RESERVE_ACTIVE_FLG; | |
6919 mutex_exit(&vhci->vhci_mutex); | |
6920 VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_failover(11): DONE! Active " | |
6921 "pathclass for %s is now %s\n", guid, pclass2)); | |
6922 retval = MDI_SUCCESS; | |
6923 | |
6924 done: | |
6925 if (flags == MDI_FAILOVER_ASYNC) { | |
6926 VHCI_RELEASE_LUN(vlun); | |
6927 VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_failover(12): DONE! " | |
6928 "releasing lun, as failover was ASYNC\n")); | |
6929 } else { | |
6930 VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_failover(12): DONE! " | |
6931 "NOT releasing lun, as failover was SYNC\n")); | |
6932 } | |
6933 return (retval); | |
6934 } | |
6935 | |
6936 /* | |
6937 * vhci_client_attached is called after the successful attach of a | |
6938 * client devinfo node. | |
6939 */ | |
6940 static void | |
6941 vhci_client_attached(dev_info_t *cdip) | |
6942 { | |
6943 mdi_pathinfo_t *pip; | |
6944 int circular; | |
6945 | |
6946 /* | |
6947 * At this point the client has attached and it's instance number is | |
6948 * valid, so we can set up kstats. We need to do this here because it | |
6949 * is possible for paths to go online prior to client attach, in which | |
6950 * case the call to vhci_kstat_create_pathinfo in vhci_pathinfo_online | |
6951 * was a noop. | |
6952 */ | |
6953 ndi_devi_enter(cdip, &circular); | |
6954 for (pip = mdi_get_next_phci_path(cdip, NULL); pip; | |
6955 pip = mdi_get_next_phci_path(cdip, pip)) | |
6956 vhci_kstat_create_pathinfo(pip); | |
6957 ndi_devi_exit(cdip, circular); | |
6958 } | |
6959 | |
6960 /* | |
6961 * quiesce all of the online paths | |
6962 */ | |
6963 static int | |
6964 vhci_quiesce_paths(dev_info_t *vdip, dev_info_t *cdip, scsi_vhci_lun_t *vlun, | |
6965 char *guid, char *active_pclass_ptr) | |
6966 { | |
6967 scsi_vhci_priv_t *svp; | |
6968 char *s_pclass = NULL; | |
6969 mdi_pathinfo_t *npip, *pip; | |
6970 int sps; | |
6971 | |
6972 /* quiesce currently active paths */ | |
6973 s_pclass = NULL; | |
6974 pip = npip = NULL; | |
6975 sps = mdi_select_path(cdip, NULL, MDI_SELECT_ONLINE_PATH, NULL, &npip); | |
6976 if ((npip == NULL) || (sps != MDI_SUCCESS)) { | |
6977 return (1); | |
6978 } | |
6979 do { | |
6980 if (mdi_prop_lookup_string(npip, "path-class", | |
6981 &s_pclass) != MDI_SUCCESS) { | |
6982 mdi_rele_path(npip); | |
6983 vhci_log(CE_NOTE, vdip, "!Failover operation failed " | |
6984 "for device %s (GUID %s) due to an internal " | |
6985 "error", ddi_node_name(cdip), guid); | |
6986 return (1); | |
6987 } | |
6988 if (strcmp(s_pclass, active_pclass_ptr) == 0) { | |
6989 /* | |
6990 * quiesce path. Free s_pclass since | |
6991 * we don't need it anymore | |
6992 */ | |
6993 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
6994 "!vhci_failover(2)(%s): failing over " | |
6995 "from %s; quiescing path %p\n", | |
6996 guid, s_pclass, (void *)npip)); | |
6997 (void) mdi_prop_free(s_pclass); | |
6998 svp = (scsi_vhci_priv_t *) | |
6999 mdi_pi_get_vhci_private(npip); | |
7000 if (svp == NULL) { | |
7001 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
7002 "!vhci_failover(2.5)(%s): no " | |
7003 "client priv! %p offlined?\n", | |
7004 guid, (void *)npip)); | |
7005 pip = npip; | |
7006 sps = mdi_select_path(cdip, NULL, | |
7007 MDI_SELECT_ONLINE_PATH, pip, &npip); | |
7008 mdi_rele_path(pip); | |
7009 continue; | |
7010 } | |
7011 if (scsi_abort(&svp->svp_psd->sd_address, NULL) | |
7012 == 0) { | |
7013 (void) vhci_recovery_reset(vlun, | |
7014 &svp->svp_psd->sd_address, FALSE, | |
7015 VHCI_DEPTH_TARGET); | |
7016 } | |
7017 mutex_enter(&svp->svp_mutex); | |
7018 if (svp->svp_cmds == 0) { | |
7019 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
7020 "!vhci_failover(3)(%s):" | |
7021 "quiesced path %p\n", guid, (void *)npip)); | |
7022 } else { | |
7023 while (svp->svp_cmds != 0) { | |
7024 cv_wait(&svp->svp_cv, &svp->svp_mutex); | |
7025 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
7026 "!vhci_failover(3.cv)(%s):" | |
7027 "quiesced path %p\n", guid, | |
7028 (void *)npip)); | |
7029 } | |
7030 } | |
7031 mutex_exit(&svp->svp_mutex); | |
7032 } else { | |
7033 /* | |
7034 * make sure we freeup the memory | |
7035 */ | |
7036 (void) mdi_prop_free(s_pclass); | |
7037 } | |
7038 pip = npip; | |
7039 sps = mdi_select_path(cdip, NULL, MDI_SELECT_ONLINE_PATH, | |
7040 pip, &npip); | |
7041 mdi_rele_path(pip); | |
7042 } while ((npip != NULL) && (sps == MDI_SUCCESS)); | |
7043 return (0); | |
7044 } | |
7045 | |
7046 static struct scsi_vhci_lun * | |
7047 vhci_lun_lookup(dev_info_t *tgt_dip) | |
7048 { | |
7049 return ((struct scsi_vhci_lun *) | |
7050 mdi_client_get_vhci_private(tgt_dip)); | |
7051 } | |
7052 | |
7053 static struct scsi_vhci_lun * | |
7054 vhci_lun_lookup_alloc(dev_info_t *tgt_dip, char *guid, int *didalloc) | |
7055 { | |
7056 struct scsi_vhci_lun *svl; | |
7057 | |
7058 if (svl = vhci_lun_lookup(tgt_dip)) { | |
7059 return (svl); | |
7060 } | |
7061 | |
7062 svl = kmem_zalloc(sizeof (*svl), KM_SLEEP); | |
7063 svl->svl_lun_wwn = kmem_zalloc(strlen(guid)+1, KM_SLEEP); | |
7064 (void) strcpy(svl->svl_lun_wwn, guid); | |
7065 mutex_init(&svl->svl_mutex, NULL, MUTEX_DRIVER, NULL); | |
7066 cv_init(&svl->svl_cv, NULL, CV_DRIVER, NULL); | |
7067 sema_init(&svl->svl_pgr_sema, 1, NULL, SEMA_DRIVER, NULL); | |
7068 svl->svl_waiting_for_activepath = 1; | |
7069 svl->svl_sector_size = 1; | |
7070 mdi_client_set_vhci_private(tgt_dip, svl); | |
7071 *didalloc = 1; | |
7072 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
7073 "vhci_lun_lookup_alloc: guid %s vlun 0x%p\n", | |
7074 guid, (void *)svl)); | |
7075 return (svl); | |
7076 } | |
7077 | |
7078 static void | |
7079 vhci_lun_free(dev_info_t *tgt_dip) | |
7080 { | |
7081 struct scsi_vhci_lun *dvlp; | |
7082 char *guid; | |
4882
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7083 struct scsi_device *sd; |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7084 |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7085 /* |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7086 * The scsi_device was set to driver private during child node |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7087 * initialization in the scsi_hba_bus_ctl(). |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7088 */ |
272a171bc996
6531069 SCSI2 (tc_mhioctkown test cases) testing are showing UNRESOLVED results for ST2530
jw149990
parents:
4851
diff
changeset
|
7089 sd = (struct scsi_device *)ddi_get_driver_private(tgt_dip); |
4851 | 7090 |
7091 dvlp = (struct scsi_vhci_lun *) | |
7092 mdi_client_get_vhci_private(tgt_dip); | |
7093 ASSERT(dvlp != NULL); | |
7094 | |
7095 mdi_client_set_vhci_private(tgt_dip, NULL); | |
7096 | |
7097 guid = dvlp->svl_lun_wwn; | |
7098 ASSERT(guid != NULL); | |
7099 VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_lun_free: %s\n", guid)); | |
7100 | |
7101 mutex_enter(&dvlp->svl_mutex); | |
7102 if (dvlp->svl_active_pclass != NULL) { | |
7103 kmem_free(dvlp->svl_active_pclass, | |
7104 strlen(dvlp->svl_active_pclass)+1); | |
7105 } | |
7106 dvlp->svl_active_pclass = NULL; | |
7107 mutex_exit(&dvlp->svl_mutex); | |
7108 | |
7109 if (dvlp->svl_lun_wwn != NULL) { | |
7110 kmem_free(dvlp->svl_lun_wwn, strlen(dvlp->svl_lun_wwn)+1); | |
7111 } | |
7112 dvlp->svl_lun_wwn = NULL; | |
7113 | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
7114 |
4851 | 7115 if (dvlp->svl_fops_name) { |
7116 kmem_free(dvlp->svl_fops_name, strlen(dvlp->svl_fops_name)+1); | |
7117 } | |
7118 dvlp->svl_fops_name = NULL; | |
7119 | |
6023
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
7120 if (dvlp->svl_fops_ctpriv != NULL) { |
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
7121 dvlp->svl_fops->sfo_device_unprobe(sd, dvlp->svl_fops_ctpriv); |
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
7122 } |
9adf47ae28c4
6634757 add support for the HDS midrange array subsystem
cm136836
parents:
4949
diff
changeset
|
7123 |
4851 | 7124 if (dvlp->svl_flags & VLUN_TASK_D_ALIVE_FLG) |
7125 taskq_destroy(dvlp->svl_taskq); | |
7126 | |
7127 mutex_destroy(&dvlp->svl_mutex); | |
7128 cv_destroy(&dvlp->svl_cv); | |
7129 sema_destroy(&dvlp->svl_pgr_sema); | |
7130 kmem_free(dvlp, sizeof (*dvlp)); | |
4896
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7131 /* |
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7132 * vhci_lun_free may be called before the tgt_dip |
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7133 * initialization so check if the sd is NULL. |
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7134 */ |
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7135 if (sd != NULL) |
ff3edba9ce8c
6594084 fixing of 6591973 could cause system panic.
jw149990
parents:
4882
diff
changeset
|
7136 sd->sd_address.a_hba_tran->tran_tgt_private = NULL; |
4851 | 7137 } |
7138 | |
7139 | |
7140 int | |
7141 vhci_do_scsi_cmd(struct scsi_pkt *pkt) | |
7142 { | |
7143 int err = 0; | |
7144 int retry_cnt = 0; | |
7145 struct scsi_extended_sense *sns; | |
7146 | |
7147 retry: | |
7148 err = scsi_poll(pkt); | |
7149 if (err) { | |
7150 if (pkt->pkt_cdbp[0] == SCMD_RELEASE) { | |
7151 if (SCBP_C(pkt) == STATUS_RESERVATION_CONFLICT) { | |
7152 VHCI_DEBUG(1, (CE_NOTE, NULL, | |
7153 "!v_s_do_s_c: RELEASE conflict\n")); | |
7154 return (0); | |
7155 } | |
7156 } | |
7157 if (retry_cnt++ < 3) { | |
7158 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7159 "!v_s_do_s_c:retry packet 0x%p " | |
7160 "status 0x%x reason %s", | |
7161 (void *)pkt, SCBP_C(pkt), | |
7162 scsi_rname(pkt->pkt_reason))); | |
7163 if ((pkt->pkt_reason == CMD_CMPLT) && | |
7164 (SCBP_C(pkt) == STATUS_CHECK) && | |
7165 (pkt->pkt_state & STATE_ARQ_DONE)) { | |
7166 sns = &(((struct scsi_arq_status *)(uintptr_t) | |
7167 (pkt->pkt_scbp))->sts_sensedata); | |
7168 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7169 "!v_s_do_s_c:retry " | |
7170 "packet 0x%p sense data %s", (void *)pkt, | |
7171 scsi_sname(sns->es_key))); | |
7172 } | |
7173 goto retry; | |
7174 } | |
7175 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7176 "!v_s_do_s_c: failed transport 0x%p 0x%x", | |
7177 (void *)pkt, SCBP_C(pkt))); | |
7178 return (0); | |
7179 } | |
7180 | |
7181 switch (pkt->pkt_reason) { | |
7182 case CMD_TIMEOUT: | |
7183 VHCI_DEBUG(1, (CE_WARN, NULL, "!pkt timed " | |
7184 "out (pkt 0x%p)", (void *)pkt)); | |
7185 return (0); | |
7186 case CMD_CMPLT: | |
7187 switch (SCBP_C(pkt)) { | |
7188 case STATUS_GOOD: | |
7189 break; | |
7190 case STATUS_CHECK: | |
7191 if (pkt->pkt_state & STATE_ARQ_DONE) { | |
7192 sns = &((( | |
7193 struct scsi_arq_status *) | |
7194 (uintptr_t) | |
7195 (pkt->pkt_scbp))-> | |
7196 sts_sensedata); | |
7197 if ((sns->es_key == | |
7198 KEY_UNIT_ATTENTION) || | |
7199 (sns->es_key == | |
7200 KEY_NOT_READY)) { | |
7201 /* | |
7202 * clear unit attn. | |
7203 */ | |
7204 | |
7205 VHCI_DEBUG(1, | |
7206 (CE_WARN, NULL, | |
7207 "!v_s_do_s_c: " | |
7208 "retry " | |
7209 "packet 0x%p sense " | |
7210 "data %s", | |
7211 (void *)pkt, | |
7212 scsi_sname | |
7213 (sns->es_key))); | |
7214 goto retry; | |
7215 } | |
7216 VHCI_DEBUG(4, (CE_WARN, NULL, | |
7217 "!ARQ while " | |
7218 "transporting " | |
7219 "(pkt 0x%p)", | |
7220 (void *)pkt)); | |
7221 return (0); | |
7222 } | |
7223 return (0); | |
7224 default: | |
7225 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7226 "!Bad status returned " | |
7227 "(pkt 0x%p, status %x)", | |
7228 (void *)pkt, SCBP_C(pkt))); | |
7229 return (0); | |
7230 } | |
7231 break; | |
7232 case CMD_INCOMPLETE: | |
7233 case CMD_RESET: | |
7234 case CMD_ABORTED: | |
7235 case CMD_TRAN_ERR: | |
7236 if (retry_cnt++ < 1) { | |
7237 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7238 "!v_s_do_s_c: retry packet 0x%p %s", | |
7239 (void *)pkt, scsi_rname(pkt->pkt_reason))); | |
7240 goto retry; | |
7241 } | |
7242 /* FALLTHROUGH */ | |
7243 default: | |
7244 VHCI_DEBUG(1, (CE_WARN, NULL, "!pkt did not " | |
7245 "complete successfully (pkt 0x%p," | |
7246 "reason %x)", (void *)pkt, pkt->pkt_reason)); | |
7247 return (0); | |
7248 } | |
7249 return (1); | |
7250 } | |
7251 | |
7252 static int | |
7253 vhci_quiesce_lun(struct scsi_vhci_lun *vlun) | |
7254 { | |
7255 mdi_pathinfo_t *pip, *spip; | |
7256 dev_info_t *cdip; | |
7257 struct scsi_vhci_priv *svp; | |
7258 mdi_pathinfo_state_t pstate; | |
7259 uint32_t p_ext_state; | |
7260 int circular; | |
7261 | |
7262 cdip = vlun->svl_dip; | |
7263 pip = spip = NULL; | |
7264 ndi_devi_enter(cdip, &circular); | |
7265 pip = mdi_get_next_phci_path(cdip, NULL); | |
7266 while (pip != NULL) { | |
7267 (void) mdi_pi_get_state2(pip, &pstate, &p_ext_state); | |
7268 if (pstate != MDI_PATHINFO_STATE_ONLINE) { | |
7269 spip = pip; | |
7270 pip = mdi_get_next_phci_path(cdip, spip); | |
7271 continue; | |
7272 } | |
7273 mdi_hold_path(pip); | |
7274 ndi_devi_exit(cdip, circular); | |
7275 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
7276 mutex_enter(&svp->svp_mutex); | |
7277 while (svp->svp_cmds != 0) { | |
7278 if (cv_timedwait(&svp->svp_cv, &svp->svp_mutex, | |
7279 ddi_get_lbolt() + drv_usectohz | |
7280 (vhci_path_quiesce_timeout * 1000000)) == -1) { | |
7281 mutex_exit(&svp->svp_mutex); | |
7282 mdi_rele_path(pip); | |
7283 VHCI_DEBUG(1, (CE_WARN, NULL, | |
7284 "Quiesce of lun is not successful " | |
7285 "vlun: 0x%p.", (void *)vlun)); | |
7286 return (0); | |
7287 } | |
7288 } | |
7289 mutex_exit(&svp->svp_mutex); | |
7290 ndi_devi_enter(cdip, &circular); | |
7291 spip = pip; | |
7292 pip = mdi_get_next_phci_path(cdip, spip); | |
7293 mdi_rele_path(spip); | |
7294 } | |
7295 ndi_devi_exit(cdip, circular); | |
7296 return (1); | |
7297 } | |
7298 | |
7299 static int | |
7300 vhci_pgr_validate_and_register(scsi_vhci_priv_t *svp) | |
7301 { | |
7302 scsi_vhci_lun_t *vlun; | |
7303 vhci_prout_t *prout; | |
7304 int rval, success; | |
7305 mdi_pathinfo_t *pip, *npip; | |
7306 scsi_vhci_priv_t *osvp; | |
7307 dev_info_t *cdip; | |
7308 uchar_t cdb_1; | |
7309 uchar_t temp_res_key[MHIOC_RESV_KEY_SIZE]; | |
7310 | |
7311 | |
7312 /* | |
7313 * see if there are any other paths available; if none, | |
7314 * then there is nothing to do. | |
7315 */ | |
7316 cdip = svp->svp_svl->svl_dip; | |
7317 rval = mdi_select_path(cdip, NULL, MDI_SELECT_ONLINE_PATH | | |
7318 MDI_SELECT_STANDBY_PATH, NULL, &pip); | |
7319 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
7320 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7321 "%s%d: vhci_pgr_validate_and_register: first path\n", | |
7322 ddi_driver_name(cdip), ddi_get_instance(cdip))); | |
7323 return (1); | |
7324 } | |
7325 | |
7326 vlun = svp->svp_svl; | |
7327 prout = &vlun->svl_prout; | |
7328 ASSERT(vlun->svl_pgr_active != 0); | |
7329 | |
7330 /* | |
7331 * When the path was busy/offlined, some other host might have | |
7332 * cleared this key. Validate key on some other path first. | |
7333 * If it fails, return failure. | |
7334 */ | |
7335 | |
7336 npip = pip; | |
7337 pip = NULL; | |
7338 success = 0; | |
7339 | |
7340 /* Save the res key */ | |
7341 bcopy((const void *)prout->res_key, | |
7342 (void *)temp_res_key, MHIOC_RESV_KEY_SIZE); | |
7343 | |
7344 /* | |
7345 * Sometimes CDB from application can be a Register_And_Ignore. | |
7346 * Instead of validation, this cdb would result in force registration. | |
7347 * Convert it to normal cdb for validation. | |
7348 * After that be sure to restore the cdb. | |
7349 */ | |
7350 cdb_1 = vlun->svl_cdb[1]; | |
7351 vlun->svl_cdb[1] &= 0xe0; | |
7352 | |
7353 do { | |
7354 osvp = (scsi_vhci_priv_t *) | |
7355 mdi_pi_get_vhci_private(npip); | |
7356 if (osvp == NULL) { | |
7357 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7358 "vhci_pgr_validate_and_register: no " | |
7359 "client priv! 0x%p offlined?\n", | |
7360 (void *)npip)); | |
7361 goto next_path_1; | |
7362 } | |
7363 | |
7364 if (osvp == svp) { | |
7365 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7366 "vhci_pgr_validate_and_register: same svp 0x%p" | |
7367 " npip 0x%p vlun 0x%p\n", | |
7368 (void *)svp, (void *)npip, (void *)vlun)); | |
7369 goto next_path_1; | |
7370 } | |
7371 | |
7372 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7373 "vhci_pgr_validate_and_register: First validate on" | |
7374 " osvp 0x%p being done. vlun 0x%p thread 0x%p Before bcopy" | |
7375 " cdb1 %x\n", (void *)osvp, (void *)vlun, | |
7376 (void *)curthread, vlun->svl_cdb[1])); | |
7377 vhci_print_prout_keys(vlun, "v_pgr_val_reg: before bcopy:"); | |
7378 | |
7379 bcopy((const void *)prout->service_key, | |
7380 (void *)prout->res_key, MHIOC_RESV_KEY_SIZE); | |
7381 | |
7382 VHCI_DEBUG(4, (CE_WARN, NULL, "vlun 0x%p After bcopy", | |
7383 (void *)vlun)); | |
7384 vhci_print_prout_keys(vlun, "v_pgr_val_reg: after bcopy: "); | |
7385 | |
7386 rval = vhci_do_prout(osvp); | |
7387 if (rval == 1) { | |
7388 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7389 "%s%d: vhci_pgr_validate_and_register: key" | |
7390 " validated thread 0x%p\n", ddi_driver_name(cdip), | |
7391 ddi_get_instance(cdip), (void *)curthread)); | |
7392 pip = npip; | |
7393 success = 1; | |
7394 break; | |
7395 } else { | |
7396 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7397 "vhci_pgr_validate_and_register: First validation" | |
7398 " on osvp 0x%p failed %x\n", (void *)osvp, rval)); | |
7399 vhci_print_prout_keys(vlun, "v_pgr_val_reg: failed:"); | |
7400 } | |
7401 | |
7402 /* | |
7403 * Try other paths | |
7404 */ | |
7405 next_path_1: | |
7406 pip = npip; | |
7407 rval = mdi_select_path(cdip, NULL, | |
7408 MDI_SELECT_ONLINE_PATH|MDI_SELECT_STANDBY_PATH, | |
7409 pip, &npip); | |
7410 mdi_rele_path(pip); | |
7411 } while ((rval == MDI_SUCCESS) && (npip != NULL)); | |
7412 | |
7413 | |
7414 /* Be sure to restore original cdb */ | |
7415 vlun->svl_cdb[1] = cdb_1; | |
7416 | |
7417 /* Restore the res_key */ | |
7418 bcopy((const void *)temp_res_key, | |
7419 (void *)prout->res_key, MHIOC_RESV_KEY_SIZE); | |
7420 | |
7421 /* | |
7422 * If key could not be registered on any path for the first time, | |
7423 * return success as online should still continue. | |
7424 */ | |
7425 if (success == 0) { | |
7426 return (1); | |
7427 } | |
7428 | |
7429 ASSERT(pip != NULL); | |
7430 | |
7431 /* | |
7432 * Force register on new path | |
7433 */ | |
7434 cdb_1 = vlun->svl_cdb[1]; /* store the cdb */ | |
7435 | |
7436 vlun->svl_cdb[1] &= 0xe0; | |
7437 vlun->svl_cdb[1] |= VHCI_PROUT_R_AND_IGNORE; | |
7438 | |
7439 vhci_print_prout_keys(vlun, "v_pgr_val_reg: keys before bcopy: "); | |
7440 | |
7441 bcopy((const void *)prout->active_service_key, | |
7442 (void *)prout->service_key, MHIOC_RESV_KEY_SIZE); | |
7443 bcopy((const void *)prout->active_res_key, | |
7444 (void *)prout->res_key, MHIOC_RESV_KEY_SIZE); | |
7445 | |
7446 vhci_print_prout_keys(vlun, "v_pgr_val_reg:keys after bcopy: "); | |
7447 | |
7448 rval = vhci_do_prout(svp); | |
7449 vlun->svl_cdb[1] = cdb_1; /* restore the cdb */ | |
7450 if (rval != 1) { | |
7451 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7452 "vhci_pgr_validate_and_register: register on new" | |
7453 " path 0x%p svp 0x%p failed %x\n", | |
7454 (void *)pip, (void *)svp, rval)); | |
7455 vhci_print_prout_keys(vlun, "v_pgr_val_reg: reg failed: "); | |
7456 mdi_rele_path(pip); | |
7457 return (0); | |
7458 } | |
7459 | |
7460 if (bcmp(prout->service_key, zero_key, MHIOC_RESV_KEY_SIZE) == 0) { | |
7461 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7462 "vhci_pgr_validate_and_register: zero service key\n")); | |
7463 mdi_rele_path(pip); | |
7464 return (rval); | |
7465 } | |
7466 | |
7467 /* | |
7468 * While the key was force registered, some other host might have | |
7469 * cleared the key. Re-validate key on another pre-existing path | |
7470 * before declaring success. | |
7471 */ | |
7472 npip = pip; | |
7473 pip = NULL; | |
7474 | |
7475 /* | |
7476 * Sometimes CDB from application can be Register and Ignore. | |
7477 * Instead of validation, it would result in force registration. | |
7478 * Convert it to normal cdb for validation. | |
7479 * After that be sure to restore the cdb. | |
7480 */ | |
7481 cdb_1 = vlun->svl_cdb[1]; | |
7482 vlun->svl_cdb[1] &= 0xe0; | |
7483 success = 0; | |
7484 | |
7485 do { | |
7486 osvp = (scsi_vhci_priv_t *) | |
7487 mdi_pi_get_vhci_private(npip); | |
7488 if (osvp == NULL) { | |
7489 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7490 "vhci_pgr_validate_and_register: no " | |
7491 "client priv! 0x%p offlined?\n", | |
7492 (void *)npip)); | |
7493 goto next_path_2; | |
7494 } | |
7495 | |
7496 if (osvp == svp) { | |
7497 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7498 "vhci_pgr_validate_and_register: same osvp 0x%p" | |
7499 " npip 0x%p vlun 0x%p\n", | |
7500 (void *)svp, (void *)npip, (void *)vlun)); | |
7501 goto next_path_2; | |
7502 } | |
7503 | |
7504 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7505 "vhci_pgr_validate_and_register: Re-validation on" | |
7506 " osvp 0x%p being done. vlun 0x%p Before bcopy cdb1 %x\n", | |
7507 (void *)osvp, (void *)vlun, vlun->svl_cdb[1])); | |
7508 vhci_print_prout_keys(vlun, "v_pgr_val_reg: before bcopy: "); | |
7509 | |
7510 bcopy((const void *)prout->service_key, | |
7511 (void *)prout->res_key, MHIOC_RESV_KEY_SIZE); | |
7512 | |
7513 vhci_print_prout_keys(vlun, "v_pgr_val_reg: after bcopy: "); | |
7514 | |
7515 rval = vhci_do_prout(osvp); | |
7516 if (rval == 1) { | |
7517 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7518 "%s%d: vhci_pgr_validate_and_register: key" | |
7519 " validated thread 0x%p\n", ddi_driver_name(cdip), | |
7520 ddi_get_instance(cdip), (void *)curthread)); | |
7521 pip = npip; | |
7522 success = 1; | |
7523 break; | |
7524 } else { | |
7525 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7526 "vhci_pgr_validate_and_register: Re-validation on" | |
7527 " osvp 0x%p failed %x\n", (void *)osvp, rval)); | |
7528 vhci_print_prout_keys(vlun, | |
7529 "v_pgr_val_reg: reval failed: "); | |
7530 } | |
7531 | |
7532 /* | |
7533 * Try other paths | |
7534 */ | |
7535 next_path_2: | |
7536 pip = npip; | |
7537 rval = mdi_select_path(cdip, NULL, | |
7538 MDI_SELECT_ONLINE_PATH|MDI_SELECT_STANDBY_PATH, | |
7539 pip, &npip); | |
7540 mdi_rele_path(pip); | |
7541 } while ((rval == MDI_SUCCESS) && (npip != NULL)); | |
7542 | |
7543 /* Be sure to restore original cdb */ | |
7544 vlun->svl_cdb[1] = cdb_1; | |
7545 | |
7546 if (success == 1) { | |
7547 /* Successfully validated registration */ | |
7548 mdi_rele_path(pip); | |
7549 return (1); | |
7550 } | |
7551 | |
7552 VHCI_DEBUG(4, (CE_WARN, NULL, "key validation failed")); | |
7553 | |
7554 /* | |
7555 * key invalid, back out by registering key value of 0 | |
7556 */ | |
7557 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7558 "vhci_pgr_validate_and_register: backout on" | |
7559 " svp 0x%p being done\n", (void *)svp)); | |
7560 vhci_print_prout_keys(vlun, "v_pgr_val_reg: before bcopy: "); | |
7561 | |
7562 bcopy((const void *)prout->service_key, (void *)prout->res_key, | |
7563 MHIOC_RESV_KEY_SIZE); | |
7564 bzero((void *)prout->service_key, MHIOC_RESV_KEY_SIZE); | |
7565 | |
7566 vhci_print_prout_keys(vlun, "v_pgr_val_reg: before bcopy: "); | |
7567 | |
7568 /* | |
7569 * Get a new path | |
7570 */ | |
7571 rval = mdi_select_path(cdip, NULL, MDI_SELECT_ONLINE_PATH | | |
7572 MDI_SELECT_STANDBY_PATH, NULL, &pip); | |
7573 if ((rval != MDI_SUCCESS) || (pip == NULL)) { | |
7574 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7575 "%s%d: vhci_pgr_validate_and_register: no valid pip\n", | |
7576 ddi_driver_name(cdip), ddi_get_instance(cdip))); | |
7577 return (0); | |
7578 } | |
7579 | |
7580 if ((rval = vhci_do_prout(svp)) != 1) { | |
7581 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7582 "vhci_pgr_validate_and_register: backout on" | |
7583 " svp 0x%p failed\n", (void *)svp)); | |
7584 vhci_print_prout_keys(vlun, "backout failed"); | |
7585 | |
7586 VHCI_DEBUG(4, (CE_WARN, NULL, | |
7587 "%s%d: vhci_pgr_validate_and_register: key" | |
7588 " validation and backout failed", ddi_driver_name(cdip), | |
7589 ddi_get_instance(cdip))); | |
7590 if (rval == VHCI_PGR_ILLEGALOP) { | |
7591 VHCI_DEBUG(4, (CE_WARN, NULL, | |
7592 "%s%d: vhci_pgr_validate_and_register: key" | |
7593 " already cleared", ddi_driver_name(cdip), | |
7594 ddi_get_instance(cdip))); | |
7595 rval = 1; | |
7596 } else | |
7597 rval = 0; | |
7598 } else { | |
7599 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
7600 "%s%d: vhci_pgr_validate_and_register: key" | |
7601 " validation failed, key backed out\n", | |
7602 ddi_driver_name(cdip), ddi_get_instance(cdip))); | |
7603 vhci_print_prout_keys(vlun, "v_pgr_val_reg: key backed out: "); | |
7604 } | |
7605 mdi_rele_path(pip); | |
7606 | |
7607 return (rval); | |
7608 } | |
7609 | |
7610 /* | |
7611 * taskq routine to dispatch a scsi cmd to vhci_scsi_start. This ensures | |
7612 * that vhci_scsi_start is not called in interrupt context. | |
7613 * As the upper layer gets TRAN_ACCEPT when the command is dispatched, we | |
7614 * need to complete the command if something goes wrong. | |
7615 */ | |
7616 static void | |
7617 vhci_dispatch_scsi_start(void *arg) | |
7618 { | |
7619 struct vhci_pkt *vpkt = (struct vhci_pkt *)arg; | |
7620 struct scsi_pkt *tpkt = vpkt->vpkt_tgt_pkt; | |
7621 int rval = TRAN_BUSY; | |
7622 | |
7623 VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_dispatch_scsi_start: sending" | |
7624 " scsi-2 reserve for 0x%p\n", | |
7625 (void *)ADDR2DIP(&(vpkt->vpkt_tgt_pkt->pkt_address)))); | |
7626 | |
7627 /* | |
7628 * To prevent the taskq from being called recursively we set the | |
7629 * the VHCI_PKT_THRU_TASKQ bit in the vhci_pkt_states. | |
7630 */ | |
7631 vpkt->vpkt_state |= VHCI_PKT_THRU_TASKQ; | |
7632 | |
7633 /* | |
7634 * Wait for the transport to get ready to send packets | |
7635 * and if it times out, it will return something other than | |
7636 * TRAN_BUSY. The vhci_reserve_delay may want to | |
7637 * get tuned for other transports and is therefore a global. | |
7638 * Using delay since this routine is called by taskq dispatch | |
7639 * and not called during interrupt context. | |
7640 */ | |
7641 while ((rval = vhci_scsi_start(&(vpkt->vpkt_tgt_pkt->pkt_address), | |
7642 vpkt->vpkt_tgt_pkt)) == TRAN_BUSY) { | |
7643 delay(drv_usectohz(vhci_reserve_delay)); | |
7644 } | |
7645 | |
7646 switch (rval) { | |
7647 case TRAN_ACCEPT: | |
7648 return; | |
7649 | |
7650 default: | |
7651 /* | |
7652 * This pkt shall be retried, and to ensure another taskq | |
7653 * is dispatched for it, clear the VHCI_PKT_THRU_TASKQ | |
7654 * flag. | |
7655 */ | |
7656 vpkt->vpkt_state &= ~VHCI_PKT_THRU_TASKQ; | |
7657 | |
7658 /* Ensure that the pkt is retried without a reset */ | |
7659 tpkt->pkt_reason = CMD_ABORTED; | |
7660 tpkt->pkt_statistics |= STAT_ABORTED; | |
7661 VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_dispatch_scsi_start: " | |
7662 "TRAN_rval %d returned for dip 0x%p", rval, | |
7663 (void *)ADDR2DIP(&(vpkt->vpkt_tgt_pkt->pkt_address)))); | |
7664 break; | |
7665 } | |
7666 | |
7667 /* | |
7668 * vpkt_org_vpkt should always be NULL here if the retry command | |
7669 * has been successfully dispatched. If vpkt_org_vpkt != NULL at | |
7670 * this point, it is an error so restore the original vpkt and | |
7671 * return an error to the target driver so it can retry the | |
7672 * command as appropriate. | |
7673 */ | |
7674 if (vpkt->vpkt_org_vpkt != NULL) { | |
7675 struct vhci_pkt *new_vpkt = vpkt; | |
7676 scsi_vhci_priv_t *svp = (scsi_vhci_priv_t *) | |
7677 mdi_pi_get_vhci_private(vpkt->vpkt_path); | |
7678 | |
7679 vpkt = vpkt->vpkt_org_vpkt; | |
7680 | |
7681 vpkt->vpkt_tgt_pkt->pkt_reason = tpkt->pkt_reason; | |
7682 vpkt->vpkt_tgt_pkt->pkt_statistics = tpkt->pkt_statistics; | |
7683 | |
7684 vhci_scsi_destroy_pkt(&svp->svp_psd->sd_address, | |
7685 new_vpkt->vpkt_tgt_pkt); | |
7686 | |
7687 tpkt = vpkt->vpkt_tgt_pkt; | |
7688 } | |
7689 | |
7690 if (tpkt->pkt_comp) { | |
7691 (*tpkt->pkt_comp)(tpkt); | |
7692 } | |
7693 } | |
7694 | |
7695 static void | |
7696 vhci_initiate_auto_failback(void *arg) | |
7697 { | |
7698 struct scsi_vhci_lun *vlun = (struct scsi_vhci_lun *)arg; | |
7699 dev_info_t *vdip, *cdip; | |
7700 int held; | |
7701 | |
7702 cdip = vlun->svl_dip; | |
7703 vdip = ddi_get_parent(cdip); | |
7704 | |
7705 VHCI_HOLD_LUN(vlun, VH_SLEEP, held); | |
7706 | |
7707 /* | |
7708 * Perform a final check to see if the active path class is indeed | |
7709 * not the prefered path class. As in the time the auto failback | |
7710 * was dispatched, an external failover could have been detected. | |
7711 * [Some other host could have detected this condition and triggered | |
7712 * the auto failback before]. | |
7713 * In such a case if we go ahead with failover we will be negating the | |
7714 * whole purpose of auto failback. | |
7715 */ | |
7716 mutex_enter(&vlun->svl_mutex); | |
7717 if (vlun->svl_active_pclass != NULL) { | |
7718 char *best_pclass; | |
7719 struct scsi_failover_ops *fo; | |
7720 | |
7721 fo = vlun->svl_fops; | |
7722 | |
7723 (*fo->sfo_pathclass_next)(NULL, &best_pclass, | |
7724 vlun->svl_fops_ctpriv); | |
7725 if (strcmp(vlun->svl_active_pclass, best_pclass) == 0) { | |
7726 mutex_exit(&vlun->svl_mutex); | |
7727 VHCI_RELEASE_LUN(vlun); | |
7728 VHCI_DEBUG(1, (CE_NOTE, NULL, "Not initiating " | |
7729 "auto failback for %s as %s pathclass already " | |
7730 "active.\n", vlun->svl_lun_wwn, best_pclass)); | |
7731 return; | |
7732 } | |
7733 } | |
7734 mutex_exit(&vlun->svl_mutex); | |
7735 if (mdi_failover(vdip, vlun->svl_dip, MDI_FAILOVER_SYNC) | |
7736 == MDI_SUCCESS) { | |
7737 vhci_log(CE_NOTE, vdip, "!Auto failback operation " | |
7738 "succeeded for device %s (GUID %s)", | |
7739 ddi_node_name(cdip), vlun->svl_lun_wwn); | |
7740 } else { | |
7741 vhci_log(CE_NOTE, vdip, "!Auto failback operation " | |
7742 "failed for device %s (GUID %s)", | |
7743 ddi_node_name(cdip), vlun->svl_lun_wwn); | |
7744 } | |
7745 VHCI_RELEASE_LUN(vlun); | |
7746 } | |
7747 | |
7748 #ifdef DEBUG | |
7749 static void | |
7750 vhci_print_prin_keys(vhci_prin_readkeys_t *prin, int numkeys) | |
7751 { | |
7752 uchar_t index = 0; | |
7753 char buf[100]; | |
7754 | |
7755 VHCI_DEBUG(5, (CE_NOTE, NULL, "num keys %d\n", numkeys)); | |
7756 | |
7757 while (index < numkeys) { | |
7758 bcopy(&prin->keylist[index], buf, MHIOC_RESV_KEY_SIZE); | |
7759 VHCI_DEBUG(5, (CE_NOTE, NULL, | |
7760 "%02x%02x%02x%02x%02x%02x%02x%02x\t", | |
7761 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], | |
7762 buf[7])); | |
7763 index++; | |
7764 } | |
7765 } | |
7766 #endif | |
7767 | |
7768 static void | |
7769 vhci_print_prout_keys(scsi_vhci_lun_t *vlun, char *msg) | |
7770 { | |
7771 int i; | |
7772 vhci_prout_t *prout; | |
7773 char buf1[4*MHIOC_RESV_KEY_SIZE + 1]; | |
7774 char buf2[4*MHIOC_RESV_KEY_SIZE + 1]; | |
7775 char buf3[4*MHIOC_RESV_KEY_SIZE + 1]; | |
7776 char buf4[4*MHIOC_RESV_KEY_SIZE + 1]; | |
7777 | |
7778 prout = &vlun->svl_prout; | |
7779 | |
7780 for (i = 0; i < MHIOC_RESV_KEY_SIZE; i++) | |
7781 (void) sprintf(&buf1[4*i], "[%02x]", prout->res_key[i]); | |
7782 for (i = 0; i < MHIOC_RESV_KEY_SIZE; i++) | |
7783 (void) sprintf(&buf2[(4*i)], "[%02x]", prout->service_key[i]); | |
7784 for (i = 0; i < MHIOC_RESV_KEY_SIZE; i++) | |
7785 (void) sprintf(&buf3[4*i], "[%02x]", prout->active_res_key[i]); | |
7786 for (i = 0; i < MHIOC_RESV_KEY_SIZE; i++) | |
7787 (void) sprintf(&buf4[4*i], "[%02x]", | |
7788 prout->active_service_key[i]); | |
7789 | |
7790 /* Printing all in one go. Otherwise it will jumble up */ | |
7791 VHCI_DEBUG(5, (CE_CONT, NULL, "%s vlun 0x%p, thread 0x%p\n" | |
7792 "res_key: : %s\n" | |
7793 "service_key : %s\n" | |
7794 "active_res_key : %s\n" | |
7795 "active_service_key: %s\n", | |
7796 msg, (void *)vlun, (void *)curthread, buf1, buf2, buf3, buf4)); | |
7797 } | |
7798 | |
7799 /* | |
7800 * Called from vhci_scsi_start to update the pHCI pkt with target packet. | |
7801 */ | |
7802 static void | |
7803 vhci_update_pHCI_pkt(struct vhci_pkt *vpkt, struct scsi_pkt *pkt) | |
7804 { | |
7805 | |
7806 ASSERT(vpkt->vpkt_hba_pkt); | |
7807 | |
7808 vpkt->vpkt_hba_pkt->pkt_flags = pkt->pkt_flags; | |
7809 vpkt->vpkt_hba_pkt->pkt_flags |= FLAG_NOQUEUE; | |
7810 | |
7811 if ((vpkt->vpkt_hba_pkt->pkt_flags & FLAG_NOINTR) || | |
7812 MDI_PI_IS_SUSPENDED(vpkt->vpkt_path)) { | |
7813 /* | |
7814 * Polled Command is requested or HBA is in | |
7815 * suspended state | |
7816 */ | |
7817 vpkt->vpkt_hba_pkt->pkt_flags |= FLAG_NOINTR; | |
7818 vpkt->vpkt_hba_pkt->pkt_comp = NULL; | |
7819 } else { | |
7820 vpkt->vpkt_hba_pkt->pkt_comp = vhci_intr; | |
7821 } | |
7822 vpkt->vpkt_hba_pkt->pkt_time = pkt->pkt_time; | |
7823 bcopy(pkt->pkt_cdbp, vpkt->vpkt_hba_pkt->pkt_cdbp, | |
7824 vpkt->vpkt_tgt_init_cdblen); | |
7825 vpkt->vpkt_hba_pkt->pkt_resid = pkt->pkt_resid; | |
7826 | |
7827 /* Re-initialize the following pHCI packet state information */ | |
7828 vpkt->vpkt_hba_pkt->pkt_state = 0; | |
7829 vpkt->vpkt_hba_pkt->pkt_statistics = 0; | |
7830 vpkt->vpkt_hba_pkt->pkt_reason = 0; | |
7831 } | |
7832 | |
7833 static int | |
7834 vhci_scsi_bus_power(dev_info_t *parent, void *impl_arg, pm_bus_power_op_t op, | |
7835 void *arg, void *result) | |
7836 { | |
7837 int ret = DDI_SUCCESS; | |
7838 | |
7839 /* | |
7840 * Generic processing in MPxIO framework | |
7841 */ | |
7842 ret = mdi_bus_power(parent, impl_arg, op, arg, result); | |
7843 | |
7844 switch (ret) { | |
7845 case MDI_SUCCESS: | |
7846 ret = DDI_SUCCESS; | |
7847 break; | |
7848 case MDI_FAILURE: | |
7849 ret = DDI_FAILURE; | |
7850 break; | |
7851 default: | |
7852 break; | |
7853 } | |
7854 | |
7855 return (ret); | |
7856 } | |
7857 | |
7858 static int | |
7859 vhci_pHCI_cap(struct scsi_address *ap, char *cap, int val, int whom, | |
7860 mdi_pathinfo_t *pip) | |
7861 { | |
7862 dev_info_t *cdip; | |
7863 mdi_pathinfo_t *npip = NULL; | |
7864 scsi_vhci_priv_t *svp = NULL; | |
7865 struct scsi_address *pap = NULL; | |
7866 scsi_hba_tran_t *hba = NULL; | |
7867 int sps; | |
7868 int mps_flag; | |
7869 int rval = 0; | |
7870 | |
7871 mps_flag = (MDI_SELECT_ONLINE_PATH | MDI_SELECT_STANDBY_PATH); | |
7872 if (pip) { | |
7873 /* | |
7874 * If the call is from vhci_pathinfo_state_change, | |
7875 * then this path was busy and is becoming ready to accept IO. | |
7876 */ | |
7877 ASSERT(ap != NULL); | |
7878 hba = ap->a_hba_tran; | |
7879 ASSERT(hba != NULL); | |
7880 rval = scsi_ifsetcap(ap, cap, val, whom); | |
7881 | |
7882 VHCI_DEBUG(2, (CE_NOTE, NULL, | |
7883 "!vhci_pHCI_cap: only on path %p, ap %p, rval %x\n", | |
7884 (void *)pip, (void *)ap, rval)); | |
7885 | |
7886 return (rval); | |
7887 } | |
7888 | |
7889 /* | |
7890 * Set capability on all the pHCIs. | |
7891 * If any path is busy, then the capability would be set by | |
7892 * vhci_pathinfo_state_change. | |
7893 */ | |
7894 | |
7895 cdip = ADDR2DIP(ap); | |
7896 ASSERT(cdip != NULL); | |
7897 sps = mdi_select_path(cdip, NULL, mps_flag, NULL, &pip); | |
7898 if ((sps != MDI_SUCCESS) || (pip == NULL)) { | |
7899 VHCI_DEBUG(2, (CE_WARN, NULL, | |
7900 "!vhci_pHCI_cap: Unable to get a path, dip 0x%p", | |
7901 (void *)cdip)); | |
7902 return (0); | |
7903 } | |
7904 | |
7905 again: | |
7906 svp = (scsi_vhci_priv_t *)mdi_pi_get_vhci_private(pip); | |
7907 if (svp == NULL) { | |
7908 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_pHCI_cap: " | |
7909 "priv is NULL, pip 0x%p", (void *)pip)); | |
7910 mdi_rele_path(pip); | |
7911 return (rval); | |
7912 } | |
7913 | |
7914 if (svp->svp_psd == NULL) { | |
7915 VHCI_DEBUG(2, (CE_WARN, NULL, "!vhci_pHCI_cap: " | |
7916 "psd is NULL, pip 0x%p, svp 0x%p", | |
7917 (void *)pip, (void *)svp)); | |
7918 mdi_rele_path(pip); | |
7919 return (rval); | |
7920 } | |
7921 | |
7922 pap = &svp->svp_psd->sd_address; | |
7923 ASSERT(pap != NULL); | |
7924 hba = pap->a_hba_tran; | |
7925 ASSERT(hba != NULL); | |
7926 | |
7927 if (hba->tran_setcap != NULL) { | |
7928 rval = scsi_ifsetcap(pap, cap, val, whom); | |
7929 | |
7930 VHCI_DEBUG(2, (CE_NOTE, NULL, | |
7931 "!vhci_pHCI_cap: path %p, ap %p, rval %x\n", | |
7932 (void *)pip, (void *)ap, rval)); | |
7933 | |
7934 /* | |
7935 * Select next path and issue the setcap, repeat | |
7936 * until all paths are exhausted | |
7937 */ | |
7938 sps = mdi_select_path(cdip, NULL, mps_flag, pip, &npip); | |
7939 if ((sps != MDI_SUCCESS) || (npip == NULL)) { | |
7940 mdi_rele_path(pip); | |
7941 return (1); | |
7942 } | |
7943 mdi_rele_path(pip); | |
7944 pip = npip; | |
7945 goto again; | |
7946 } | |
7947 mdi_rele_path(pip); | |
7948 return (rval); | |
7949 } | |
7950 | |
7951 static int | |
7952 vhci_scsi_bus_config(dev_info_t *pdip, uint_t flags, ddi_bus_config_op_t op, | |
7953 void *arg, dev_info_t **child) | |
7954 { | |
7955 char *guid; | |
7956 | |
7957 if (op == BUS_CONFIG_ONE || op == BUS_UNCONFIG_ONE) | |
7958 guid = vhci_devnm_to_guid((char *)arg); | |
7959 else | |
7960 guid = NULL; | |
7961 | |
7962 if (mdi_vhci_bus_config(pdip, flags, op, arg, child, guid) | |
7963 == MDI_SUCCESS) | |
7964 return (NDI_SUCCESS); | |
7965 else | |
7966 return (NDI_FAILURE); | |
7967 } | |
7968 | |
7969 /* | |
7970 * Take the original vhci_pkt, create a duplicate of the pkt for resending | |
7971 * as though it originated in ssd. | |
7972 */ | |
7973 static struct scsi_pkt * | |
7974 vhci_create_retry_pkt(struct vhci_pkt *vpkt) | |
7975 { | |
7976 struct vhci_pkt *new_vpkt = NULL; | |
7977 struct scsi_pkt *pkt = NULL; | |
7978 | |
7979 scsi_vhci_priv_t *svp = (scsi_vhci_priv_t *) | |
7980 mdi_pi_get_vhci_private(vpkt->vpkt_path); | |
7981 | |
7982 /* | |
7983 * Ensure consistent data at completion time by setting PKT_CONSISTENT | |
7984 */ | |
7985 pkt = vhci_scsi_init_pkt(&svp->svp_psd->sd_address, pkt, | |
7986 vpkt->vpkt_tgt_init_bp, vpkt->vpkt_tgt_init_cdblen, | |
7987 vpkt->vpkt_tgt_init_scblen, vpkt->vpkt_tgt_init_privlen, | |
7988 PKT_CONSISTENT, | |
7989 NULL_FUNC, NULL); | |
7990 if (pkt != NULL) { | |
7991 new_vpkt = TGTPKT2VHCIPKT(pkt); | |
7992 | |
7993 pkt->pkt_address = vpkt->vpkt_tgt_pkt->pkt_address; | |
7994 pkt->pkt_flags = vpkt->vpkt_tgt_pkt->pkt_flags; | |
7995 pkt->pkt_time = vpkt->vpkt_tgt_pkt->pkt_time; | |
7996 pkt->pkt_comp = vpkt->vpkt_tgt_pkt->pkt_comp; | |
7997 | |
7998 pkt->pkt_resid = 0; | |
7999 pkt->pkt_statistics = 0; | |
8000 pkt->pkt_reason = 0; | |
8001 | |
8002 bcopy(vpkt->vpkt_tgt_pkt->pkt_cdbp, | |
8003 pkt->pkt_cdbp, vpkt->vpkt_tgt_init_cdblen); | |
8004 | |
8005 /* | |
8006 * Save a pointer to the original vhci_pkt | |
8007 */ | |
8008 new_vpkt->vpkt_org_vpkt = vpkt; | |
8009 } | |
8010 | |
8011 return (pkt); | |
8012 } | |
8013 | |
8014 /* | |
8015 * Copy the successful completion information from the hba packet into | |
8016 * the original target pkt from the upper layer. Returns the original | |
8017 * vpkt and destroys the new vpkt from the internal retry. | |
8018 */ | |
8019 static struct vhci_pkt * | |
8020 vhci_sync_retry_pkt(struct vhci_pkt *vpkt) | |
8021 { | |
8022 struct vhci_pkt *ret_vpkt = NULL; | |
8023 struct scsi_pkt *tpkt = NULL; | |
8024 struct scsi_pkt *hba_pkt = NULL; | |
8025 scsi_vhci_priv_t *svp = (scsi_vhci_priv_t *) | |
8026 mdi_pi_get_vhci_private(vpkt->vpkt_path); | |
8027 | |
8028 ASSERT(vpkt->vpkt_org_vpkt != NULL); | |
8029 VHCI_DEBUG(0, (CE_NOTE, NULL, "vhci_sync_retry_pkt: Retry pkt " | |
8030 "completed successfully!\n")); | |
8031 | |
8032 ret_vpkt = vpkt->vpkt_org_vpkt; | |
8033 tpkt = ret_vpkt->vpkt_tgt_pkt; | |
8034 hba_pkt = vpkt->vpkt_hba_pkt; | |
8035 | |
8036 /* | |
8037 * Copy the good status into the target driver's packet | |
8038 */ | |
8039 *(tpkt->pkt_scbp) = *(hba_pkt->pkt_scbp); | |
8040 tpkt->pkt_resid = hba_pkt->pkt_resid; | |
8041 tpkt->pkt_state = hba_pkt->pkt_state; | |
8042 tpkt->pkt_statistics = hba_pkt->pkt_statistics; | |
8043 tpkt->pkt_reason = hba_pkt->pkt_reason; | |
8044 | |
8045 /* | |
8046 * Destroy the internally created vpkt for the retry | |
8047 */ | |
8048 vhci_scsi_destroy_pkt(&svp->svp_psd->sd_address, | |
8049 vpkt->vpkt_tgt_pkt); | |
8050 | |
8051 return (ret_vpkt); | |
8052 } | |
8053 | |
8054 /* restart the request sense request */ | |
8055 static void | |
8056 vhci_uscsi_restart_sense(void *arg) | |
8057 { | |
8058 struct buf *rqbp; | |
8059 struct buf *bp; | |
8060 struct scsi_pkt *rqpkt = (struct scsi_pkt *)arg; | |
8061 mp_uscsi_cmd_t *mp_uscmdp; | |
8062 | |
8063 VHCI_DEBUG(4, (CE_WARN, NULL, | |
8064 "vhci_uscsi_restart_sense: enter: rqpkt: %p", (void *)rqpkt)); | |
8065 | |
8066 if (scsi_transport(rqpkt) != TRAN_ACCEPT) { | |
8067 /* if it fails - need to wakeup the original command */ | |
8068 mp_uscmdp = rqpkt->pkt_private; | |
8069 bp = mp_uscmdp->cmdbp; | |
8070 rqbp = mp_uscmdp->rqbp; | |
8071 ASSERT(mp_uscmdp && bp && rqbp); | |
8072 scsi_free_consistent_buf(rqbp); | |
8073 scsi_destroy_pkt(rqpkt); | |
8074 bp->b_resid = bp->b_bcount; | |
8075 bioerror(bp, EIO); | |
8076 biodone(bp); | |
8077 } | |
8078 } | |
8079 | |
8080 /* | |
8081 * auto-rqsense is not enabled so we have to retrieve the request sense | |
8082 * manually. | |
8083 */ | |
8084 static int | |
8085 vhci_uscsi_send_sense(struct scsi_pkt *pkt, mp_uscsi_cmd_t *mp_uscmdp) | |
8086 { | |
8087 struct buf *rqbp, *cmdbp; | |
8088 struct scsi_pkt *rqpkt; | |
8089 int rval = 0; | |
8090 | |
8091 cmdbp = mp_uscmdp->cmdbp; | |
8092 ASSERT(cmdbp != NULL); | |
8093 | |
8094 VHCI_DEBUG(4, (CE_WARN, NULL, | |
8095 "vhci_uscsi_send_sense: enter: bp: %p pkt: %p scmd: %p", | |
8096 (void *)cmdbp, (void *)pkt, (void *)mp_uscmdp)); | |
8097 /* set up the packet information and cdb */ | |
8098 if ((rqbp = scsi_alloc_consistent_buf(mp_uscmdp->ap, NULL, | |
8099 SENSE_LENGTH, B_READ, NULL, NULL)) == NULL) { | |
8100 return (-1); | |
8101 } | |
8102 | |
8103 if ((rqpkt = scsi_init_pkt(mp_uscmdp->ap, NULL, rqbp, | |
8104 CDB_GROUP0, 1, 0, PKT_CONSISTENT, NULL, NULL)) == NULL) { | |
8105 scsi_free_consistent_buf(rqbp); | |
8106 return (-1); | |
8107 } | |
8108 | |
8109 (void) scsi_setup_cdb((union scsi_cdb *)(intptr_t)rqpkt->pkt_cdbp, | |
8110 SCMD_REQUEST_SENSE, 0, SENSE_LENGTH, 0); | |
8111 | |
8112 mp_uscmdp->rqbp = rqbp; | |
8113 rqbp->b_private = mp_uscmdp; | |
8114 rqpkt->pkt_flags |= FLAG_SENSING; | |
8115 rqpkt->pkt_time = 60; | |
8116 rqpkt->pkt_comp = vhci_uscsi_iodone; | |
8117 rqpkt->pkt_private = mp_uscmdp; | |
8118 | |
8119 /* get her done */ | |
8120 switch (scsi_transport(rqpkt)) { | |
8121 case TRAN_ACCEPT: | |
8122 VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_uscsi_send_sense: " | |
8123 "transport accepted.")); | |
8124 break; | |
8125 case TRAN_BUSY: | |
8126 VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_uscsi_send_sense: " | |
8127 "transport busy, setting timeout.")); | |
8128 vhci_restart_timeid = timeout(vhci_uscsi_restart_sense, rqpkt, | |
8129 (drv_usectohz(5 * 1000000))); | |
8130 break; | |
8131 default: | |
8132 VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_uscsi_send_sense: " | |
8133 "transport failed")); | |
8134 scsi_free_consistent_buf(rqbp); | |
8135 scsi_destroy_pkt(rqpkt); | |
8136 rval = -1; | |
8137 } | |
8138 | |
8139 return (rval); | |
8140 } | |
8141 | |
8142 /* | |
8143 * done routine for the mpapi uscsi command - this is behaving as though | |
8144 * FLAG_DIAGNOSE is set meaning there are no retries except for a manual | |
8145 * request sense. | |
8146 */ | |
8147 void | |
8148 vhci_uscsi_iodone(struct scsi_pkt *pkt) | |
8149 { | |
8150 struct buf *bp; | |
8151 mp_uscsi_cmd_t *mp_uscmdp; | |
8152 struct uscsi_cmd *uscmdp; | |
8153 struct scsi_arq_status *arqstat; | |
8154 int err; | |
8155 | |
8156 mp_uscmdp = (mp_uscsi_cmd_t *)pkt->pkt_private; | |
8157 uscmdp = mp_uscmdp->uscmdp; | |
8158 bp = mp_uscmdp->cmdbp; | |
8159 ASSERT(bp != NULL); | |
8160 VHCI_DEBUG(4, (CE_WARN, NULL, | |
8161 "vhci_uscsi_iodone: enter: bp: %p pkt: %p scmd: %p", | |
8162 (void *)bp, (void *)pkt, (void *)mp_uscmdp)); | |
8163 /* Save the status and the residual into the uscsi_cmd struct */ | |
8164 uscmdp->uscsi_status = ((*(pkt)->pkt_scbp) & STATUS_MASK); | |
8165 uscmdp->uscsi_resid = bp->b_resid; | |
8166 | |
8167 /* return on a very successful command */ | |
8168 if (pkt->pkt_reason == CMD_CMPLT && | |
8169 SCBP_C(pkt) == 0 && ((pkt->pkt_flags & FLAG_SENSING) == 0) && | |
8170 pkt->pkt_resid == 0) { | |
8171 mdi_pi_kstat_iosupdate(mp_uscmdp->pip, bp); | |
8172 scsi_destroy_pkt(pkt); | |
8173 biodone(bp); | |
8174 return; | |
8175 } | |
8176 VHCI_DEBUG(4, (CE_NOTE, NULL, "iodone: reason=0x%x " | |
8177 " pkt_resid=%ld pkt_state: 0x%x b_count: %ld b_resid: %ld", | |
8178 pkt->pkt_reason, pkt->pkt_resid, | |
8179 pkt->pkt_state, bp->b_bcount, bp->b_resid)); | |
8180 | |
8181 err = EIO; | |
8182 | |
8183 arqstat = (struct scsi_arq_status *)(intptr_t)(pkt->pkt_scbp); | |
8184 if (pkt->pkt_reason != CMD_CMPLT) { | |
8185 /* | |
8186 * The command did not complete. | |
8187 */ | |
8188 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8189 "vhci_uscsi_iodone: command did not complete." | |
8190 " reason: %x flag: %x", pkt->pkt_reason, pkt->pkt_flags)); | |
8191 if (pkt->pkt_flags & FLAG_SENSING) { | |
8192 MDI_PI_ERRSTAT(mp_uscmdp->pip, MDI_PI_TRANSERR); | |
8193 } else if (pkt->pkt_reason == CMD_TIMEOUT) { | |
8194 MDI_PI_ERRSTAT(mp_uscmdp->pip, MDI_PI_HARDERR); | |
8195 err = ETIMEDOUT; | |
8196 } | |
8197 } else if (pkt->pkt_state & STATE_ARQ_DONE && mp_uscmdp->arq_enabled) { | |
8198 /* | |
8199 * The auto-rqsense happened, and the packet has a filled-in | |
8200 * scsi_arq_status structure, pointed to by pkt_scbp. | |
8201 */ | |
8202 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8203 "vhci_uscsi_iodone: received auto-requested sense")); | |
8204 if (uscmdp->uscsi_flags & USCSI_RQENABLE) { | |
8205 /* get the amount of data to copy into rqbuf */ | |
8206 int rqlen = SENSE_LENGTH - arqstat->sts_rqpkt_resid; | |
8207 rqlen = min(((int)uscmdp->uscsi_rqlen), rqlen); | |
8208 uscmdp->uscsi_rqresid = uscmdp->uscsi_rqlen - rqlen; | |
8209 uscmdp->uscsi_rqstatus = | |
8210 *((char *)&arqstat->sts_rqpkt_status); | |
8211 if (uscmdp->uscsi_rqbuf && uscmdp->uscsi_rqlen && | |
8212 rqlen != 0) { | |
8213 bcopy(&(arqstat->sts_sensedata), | |
8214 uscmdp->uscsi_rqbuf, rqlen); | |
8215 } | |
8216 mdi_pi_kstat_iosupdate(mp_uscmdp->pip, bp); | |
8217 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8218 "vhci_uscsi_iodone: ARQ " | |
8219 "uscsi_rqstatus=0x%x uscsi_rqresid=%d rqlen: %d " | |
8220 "xfer: %d rqpkt_resid: %d\n", | |
8221 uscmdp->uscsi_rqstatus, uscmdp->uscsi_rqresid, | |
8222 uscmdp->uscsi_rqlen, rqlen, | |
8223 arqstat->sts_rqpkt_resid)); | |
8224 } | |
8225 } else if (pkt->pkt_flags & FLAG_SENSING) { | |
8226 struct buf *rqbp; | |
8227 struct scsi_status *rqstatus; | |
8228 | |
8229 rqstatus = (struct scsi_status *)pkt->pkt_scbp; | |
8230 /* a manual request sense was done - get the information */ | |
8231 if (uscmdp->uscsi_flags & USCSI_RQENABLE) { | |
8232 int rqlen = SENSE_LENGTH - pkt->pkt_resid; | |
8233 | |
8234 rqbp = mp_uscmdp->rqbp; | |
8235 /* get the amount of data to copy into rqbuf */ | |
8236 rqlen = min(((int)uscmdp->uscsi_rqlen), rqlen); | |
8237 uscmdp->uscsi_rqresid = uscmdp->uscsi_rqlen - rqlen; | |
8238 uscmdp->uscsi_rqstatus = *((char *)rqstatus); | |
8239 if (uscmdp->uscsi_rqlen && uscmdp->uscsi_rqbuf) { | |
8240 bcopy(rqbp->b_un.b_addr, uscmdp->uscsi_rqbuf, | |
8241 rqlen); | |
8242 } | |
8243 MDI_PI_ERRSTAT(mp_uscmdp->pip, MDI_PI_TRANSERR); | |
8244 scsi_free_consistent_buf(rqbp); | |
8245 } | |
8246 VHCI_DEBUG(4, (CE_NOTE, NULL, "vhci_uscsi_iodone: FLAG_SENSING" | |
8247 "uscsi_rqstatus=0x%x uscsi_rqresid=%d\n", | |
8248 uscmdp->uscsi_rqstatus, uscmdp->uscsi_rqresid)); | |
8249 } else { | |
8250 struct scsi_status *status = | |
8251 (struct scsi_status *)pkt->pkt_scbp; | |
8252 /* | |
8253 * Command completed and we're not getting sense. Check for | |
8254 * errors and decide what to do next. | |
8255 */ | |
8256 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8257 "vhci_uscsi_iodone: command appears complete: reason: %x", | |
8258 pkt->pkt_reason)); | |
8259 if (status->sts_chk) { | |
8260 /* need to manually get the request sense */ | |
8261 if (vhci_uscsi_send_sense(pkt, mp_uscmdp) == 0) { | |
8262 scsi_destroy_pkt(pkt); | |
8263 return; | |
8264 } | |
8265 } else { | |
8266 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8267 "vhci_chk_err: appears complete")); | |
8268 err = 0; | |
8269 mdi_pi_kstat_iosupdate(mp_uscmdp->pip, bp); | |
8270 if (pkt->pkt_resid) { | |
8271 bp->b_resid += pkt->pkt_resid; | |
8272 } | |
8273 } | |
8274 } | |
8275 | |
8276 if (err) { | |
8277 if (bp->b_resid == 0) | |
8278 bp->b_resid = bp->b_bcount; | |
8279 bioerror(bp, err); | |
8280 bp->b_flags |= B_ERROR; | |
8281 } | |
8282 | |
8283 scsi_destroy_pkt(pkt); | |
8284 biodone(bp); | |
8285 | |
8286 VHCI_DEBUG(4, (CE_WARN, NULL, "vhci_uscsi_iodone: exit")); | |
8287 } | |
8288 | |
8289 /* | |
8290 * start routine for the mpapi uscsi command | |
8291 */ | |
8292 int | |
8293 vhci_uscsi_iostart(struct buf *bp) | |
8294 { | |
8295 struct scsi_pkt *pkt; | |
8296 struct uscsi_cmd *uscmdp; | |
8297 mp_uscsi_cmd_t *mp_uscmdp; | |
8298 int stat_size, rval; | |
8299 int retry = 0; | |
8300 | |
8301 ASSERT(bp->b_private != NULL); | |
8302 | |
8303 mp_uscmdp = (mp_uscsi_cmd_t *)bp->b_private; | |
8304 uscmdp = mp_uscmdp->uscmdp; | |
8305 if (uscmdp->uscsi_flags & USCSI_RQENABLE) { | |
8306 stat_size = SENSE_LENGTH; | |
8307 } else { | |
8308 stat_size = 1; | |
8309 } | |
8310 | |
8311 pkt = scsi_init_pkt(mp_uscmdp->ap, NULL, bp, uscmdp->uscsi_cdblen, | |
8312 stat_size, 0, 0, SLEEP_FUNC, NULL); | |
8313 if (pkt == NULL) { | |
8314 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8315 "vhci_uscsi_iostart: rval: EINVAL")); | |
8316 bp->b_resid = bp->b_bcount; | |
8317 uscmdp->uscsi_resid = bp->b_bcount; | |
8318 bioerror(bp, EINVAL); | |
8319 biodone(bp); | |
8320 return (EINVAL); | |
8321 } | |
8322 | |
8323 pkt->pkt_time = uscmdp->uscsi_timeout; | |
8324 bcopy(uscmdp->uscsi_cdb, pkt->pkt_cdbp, (size_t)uscmdp->uscsi_cdblen); | |
8325 pkt->pkt_comp = vhci_uscsi_iodone; | |
8326 pkt->pkt_private = mp_uscmdp; | |
8327 if (uscmdp->uscsi_flags & USCSI_SILENT) | |
8328 pkt->pkt_flags |= FLAG_SILENT; | |
8329 if (uscmdp->uscsi_flags & USCSI_ISOLATE) | |
8330 pkt->pkt_flags |= FLAG_ISOLATE; | |
8331 if (uscmdp->uscsi_flags & USCSI_DIAGNOSE) | |
8332 pkt->pkt_flags |= FLAG_DIAGNOSE; | |
8333 if (uscmdp->uscsi_flags & USCSI_RENEGOT) { | |
8334 pkt->pkt_flags |= FLAG_RENEGOTIATE_WIDE_SYNC; | |
8335 } | |
8336 VHCI_DEBUG(4, (CE_WARN, NULL, | |
8337 "vhci_uscsi_iostart: ap: %p pkt: %p pcdbp: %p uscmdp: %p" | |
8338 " ucdbp: %p pcdblen: %d bp: %p count: %ld pip: %p" | |
8339 " stat_size: %d", | |
8340 (void *)mp_uscmdp->ap, (void *)pkt, (void *)pkt->pkt_cdbp, | |
8341 (void *)uscmdp, (void *)uscmdp->uscsi_cdb, pkt->pkt_cdblen, | |
8342 (void *)bp, bp->b_bcount, (void *)mp_uscmdp->pip, stat_size)); | |
8343 | |
8344 while (((rval = scsi_transport(pkt)) == TRAN_BUSY) && | |
8345 retry < vhci_uscsi_retry_count) { | |
8346 delay(drv_usectohz(vhci_uscsi_delay)); | |
8347 retry++; | |
8348 } | |
8349 if (retry >= vhci_uscsi_retry_count) { | |
8350 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8351 "vhci_uscsi_iostart: tran_busy - retry: %d", retry)); | |
8352 } | |
8353 switch (rval) { | |
8354 case TRAN_ACCEPT: | |
8355 rval = 0; | |
8356 break; | |
8357 | |
8358 default: | |
8359 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8360 "vhci_uscsi_iostart: rval: %d count: %ld res: %ld", | |
8361 rval, bp->b_bcount, bp->b_resid)); | |
8362 bp->b_resid = bp->b_bcount; | |
8363 uscmdp->uscsi_resid = bp->b_bcount; | |
8364 bioerror(bp, EIO); | |
8365 scsi_destroy_pkt(pkt); | |
8366 biodone(bp); | |
8367 rval = EIO; | |
8368 MDI_PI_ERRSTAT(mp_uscmdp->pip, MDI_PI_TRANSERR); | |
8369 break; | |
8370 } | |
8371 VHCI_DEBUG(4, (CE_NOTE, NULL, | |
8372 "vhci_uscsi_iostart: exit: rval: %d", rval)); | |
8373 return (rval); | |
8374 } |