dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / mpapi / libmpscsi_vhci / common / Sun_MP_SendScsiCmd.c
blobb78705784ed3ea82499568bd693ab094bc0e6e26
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <syslog.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <stropts.h>
30 #include <sys/scsi/impl/uscsi.h>
32 #include "mp_utils.h"
36 * Called by the common layer to request to steer a path
39 MP_STATUS
40 Sun_MP_SendScsiCmd(MP_OID pathOid, struct uscsi_cmd *cmd)
42 mp_iocdata_t mp_ioctl;
44 int ioctlStatus = 0;
46 MP_STATUS mpStatus = MP_STATUS_SUCCESS;
48 log(LOG_INFO, "Sun_MP_SendScsiCmd()", " - enter");
50 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
51 "pathOid.objectSequenceNumber = %llx",
52 pathOid.objectSequenceNumber);
54 if (g_scsi_vhci_fd < 0) {
55 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
56 "invalid driver file handle");
57 log(LOG_INFO, "Sun_MP_SendScsiCmd()", " - error exit");
58 return (MP_STATUS_FAILED);
61 (void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
63 mp_ioctl.mp_cmd = MP_SEND_SCSI_CMD;
64 mp_ioctl.mp_ibuf = (caddr_t)&pathOid.objectSequenceNumber;
65 mp_ioctl.mp_ilen = sizeof (pathOid.objectSequenceNumber);
66 mp_ioctl.mp_xfer =
67 ((cmd->uscsi_flags & USCSI_READ) ? MP_XFER_READ : MP_XFER_WRITE);
68 mp_ioctl.mp_obuf = (char *)cmd;
69 mp_ioctl.mp_olen = sizeof (*cmd);
71 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
72 "mp_ioctl.mp_cmd (MP_SEND_SCSI_CMD) : %d",
73 mp_ioctl.mp_cmd);
75 ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
77 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
78 " IOCTL call returned: %d", ioctlStatus);
80 if (ioctlStatus < 0) {
81 ioctlStatus = errno;
84 if (ioctlStatus != 0) {
85 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
86 "IOCTL call failed. IOCTL error is: %d",
87 ioctlStatus);
88 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
89 "IOCTL call failed. IOCTL error is: %s",
90 strerror(ioctlStatus));
91 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
92 "IOCTL call failed. mp_ioctl.mp_errno: %x",
93 mp_ioctl.mp_errno);
95 if (ENOTSUP == ioctlStatus) {
96 mpStatus = MP_STATUS_UNSUPPORTED;
97 } else if (EPERM == ioctlStatus) {
98 mpStatus = MP_STATUS_NOT_PERMITTED;
99 } else if (0 == mp_ioctl.mp_errno) {
100 mpStatus = MP_STATUS_FAILED;
101 } else {
102 mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
105 log(LOG_INFO, "Sun_MP_SendScsiCmd()",
106 " - error exit");
108 return (mpStatus);
112 log(LOG_INFO, "Sun_MP_SendScsiCmd()", " - exit");
114 return (MP_STATUS_SUCCESS);