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