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