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