Print this page
OS-2444 richmond hardware maps need to support ivy bridge (review fixes)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/fm/topo/modules/common/disk/disk_mptsas.c
+++ new/usr/src/lib/fm/topo/modules/common/disk/disk_mptsas.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11 /*
12 12 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
13 13 */
14 14
15 15 #include <stdlib.h>
16 16 #include <sys/types.h>
17 17 #include <sys/stat.h>
18 18 #include <fcntl.h>
19 19 #include <unistd.h>
20 20 #include <stropts.h>
21 21 #include <string.h>
22 22 #include <strings.h>
23 23
24 24 #include <fm/topo_mod.h>
25 25 #include <fm/topo_list.h>
26 26
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
27 27 #include <sys/scsi/adapters/mpt_sas/mpi/mpi2_type.h>
28 28 #include <sys/scsi/adapters/mpt_sas/mpi/mpi2.h>
29 29 #include <sys/scsi/adapters/mpt_sas/mpi/mpi2_init.h>
30 30 #include <sys/scsi/adapters/mpt_sas/mptsas_ioctl.h>
31 31
32 32 #include "disk.h"
33 33 #include "disk_drivers.h"
34 34
35 35 /*
36 36 * Request the SAS address of the disk (if any) attached to this mpt_sas
37 - * instance at (Enclosure Number, Slot Number).
38 - *
39 - * Returns:
40 - * -2 /devices node (*devctl) does not exist
41 - * -1 All other failures
42 - * 0 Success
37 + * instance at (Enclosure Number, Slot Number). The function returns
38 + * -1 on error and sets errno to ENOENT _only_ if the /devices node
39 + * (*devctl) does not exist.
43 40 */
44 41 static int
45 42 get_sas_address(topo_mod_t *mod, char *devctl, uint32_t enclosure,
46 43 uint32_t slot, char **sas_address)
47 44 {
48 - int fd, err, i;
45 + int ret = -1, en = ENXIO;
46 + int fd, i;
49 47 mptsas_get_disk_info_t gdi;
50 48 mptsas_disk_info_t *di;
51 49 size_t disz;
52 50
53 51 bzero(&gdi, sizeof (gdi));
54 52
55 53 if ((fd = open(devctl, O_RDWR)) == -1) {
56 - int rc = (errno == ENOENT ? -2 : -1);
54 + en = errno;
57 55 topo_mod_dprintf(mod, "could not open '%s' for ioctl: %s\n",
58 56 devctl, strerror(errno));
59 - return (rc);
57 + errno = en;
58 + return (-1);
60 59 }
61 60
62 61 if (ioctl(fd, MPTIOCTL_GET_DISK_INFO, &gdi) == -1) {
62 + if (errno != ENOENT)
63 + en = errno;
63 64 topo_mod_dprintf(mod, "ioctl 1 on '%s' failed: %s\n", devctl,
64 65 strerror(errno));
65 - (void) close(fd);
66 - return (-1);
66 + goto out;
67 67 }
68 68
69 69 gdi.DiskInfoArraySize = disz = sizeof (mptsas_disk_info_t) *
70 70 gdi.DiskCount;
71 71 gdi.PtrDiskInfoArray = di = topo_mod_alloc(mod, disz);
72 72 if (di == NULL) {
73 73 topo_mod_dprintf(mod, "memory allocation failed\n");
74 - (void) close(fd);
75 - return (-1);
74 + en = ENOMEM;
75 + goto out;
76 76 }
77 77
78 78 if (ioctl(fd, MPTIOCTL_GET_DISK_INFO, &gdi) == -1) {
79 + if (errno != ENOENT)
80 + en = errno;
79 81 topo_mod_dprintf(mod, "ioctl 2 on '%s' failed: %s\n", devctl,
80 82 strerror(errno));
81 83 topo_mod_free(mod, di, disz);
82 - (void) close(fd);
83 - return (-1);
84 + goto out;
84 85 }
85 86
86 - err = -1;
87 87 for (i = 0; i < gdi.DiskCount; i++) {
88 88 if (di[i].Enclosure == enclosure && di[i].Slot == slot) {
89 89 char sas[17]; /* 16 hex digits and NUL */
90 90 (void) snprintf(sas, 17, "%llx", di[i].SasAddress);
91 91 topo_mod_dprintf(mod, "found mpt_sas disk (%d/%d) "
92 92 "with adddress %s\n", enclosure, slot, sas);
93 93 *sas_address = topo_mod_strdup(mod, sas);
94 - err = 0;
94 + en = ret = 0;
95 95 break;
96 96 }
97 97 }
98 98
99 99 topo_mod_free(mod, di, disz);
100 +out:
100 101 (void) close(fd);
101 - return (err);
102 + errno = en;
103 + return (ret);
102 104 }
103 105
104 106 int
105 107 disk_mptsas_find_disk(topo_mod_t *mod, tnode_t *baynode, char **sas_address)
106 108 {
107 109 char *devctl = NULL;
108 110 uint32_t enclosure, slot;
109 111 int err;
110 112 char *elem, *lastp;
111 113 int ret = -1;
112 114
113 115 /*
114 116 * Get the required properties from the node. These come from
115 117 * the static XML mapping.
116 118 */
117 119 if (topo_prop_get_string(baynode, TOPO_PGROUP_BINDING,
118 120 TOPO_BINDING_DEVCTL, &devctl, &err) != 0 ||
119 121 topo_prop_get_uint32(baynode, TOPO_PGROUP_BINDING,
120 122 TOPO_BINDING_ENCLOSURE, &enclosure, &err) != 0 ||
121 123 topo_prop_get_uint32(baynode, TOPO_PGROUP_BINDING,
122 124 TOPO_BINDING_SLOT, &slot, &err) != 0) {
123 125 if (devctl != NULL)
124 126 topo_mod_strfree(mod, devctl);
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
125 127 topo_mod_dprintf(mod, "bay node was missing mpt_sas binding "
126 128 "properties\n");
127 129 return (-1);
128 130 }
129 131
130 132 /*
131 133 * devctl is a (potentially) pipe-separated list of different device
132 134 * paths to try.
133 135 */
134 136 if ((elem = topo_mod_strsplit(mod, devctl, "|", &lastp)) != NULL) {
137 + boolean_t done = B_FALSE;
135 138 do {
136 139 topo_mod_dprintf(mod, "trying mpt_sas instance at %s\n",
137 140 elem);
138 141
139 142 ret = get_sas_address(mod, elem, enclosure,
140 143 slot, sas_address);
141 144
142 - topo_mod_strfree(mod, elem);
143 -
144 145 /*
145 146 * Only try further devctl paths from the list if this
146 147 * one was not found:
147 148 */
148 - if (ret != -2) {
149 - break;
149 + if (ret == 0 || errno != ENOENT) {
150 + done = B_TRUE;
150 151 } else {
151 152 topo_mod_dprintf(mod, "instance not found\n");
152 153 }
153 154
154 - } while ((elem = topo_mod_strsplit(mod, NULL, "|",
155 + topo_mod_strfree(mod, elem);
156 +
157 + } while (!done && (elem = topo_mod_strsplit(mod, NULL, "|",
155 158 &lastp)) != NULL);
156 159 }
157 160
158 161 topo_mod_strfree(mod, devctl);
159 162 return (ret);
160 163 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX