Print this page
Adding AoE support to nza-kernel
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/os/autoconf.c
+++ new/usr/src/uts/common/os/autoconf.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 27 /*
27 28 * This file contains ddi functions needed during boot and DR.
28 29 * Many functions in swapgeneric.c can be moved here.
29 30 *
30 31 * The object file is currently linked into unix.
31 32 */
32 33
33 34 #include <sys/bootconf.h>
34 35 #include <sys/conf.h>
35 36 #include <sys/ddi_impldefs.h>
36 37 #include <sys/ddi_implfuncs.h>
37 38 #include <sys/hwconf.h>
38 39 #include <sys/instance.h>
39 40 #include <sys/kmem.h>
40 41 #include <sys/modctl.h>
41 42 #include <sys/promif.h>
42 43 #include <sys/sunndi.h>
43 44 #include <sys/ndi_impldefs.h>
44 45 #include <sys/systeminfo.h>
45 46 #include <sys/hwconf.h>
46 47 #include <sys/sysevent_impl.h>
47 48 #include <sys/sunldi_impl.h>
48 49 #include <sys/disp.h>
49 50 #include <sys/bootconf.h>
50 51 #include <sys/fm/util.h>
51 52 #include <sys/ddifm_impl.h>
52 53
53 54 extern dev_info_t *top_devinfo;
54 55 extern dev_info_t *scsi_vhci_dip;
55 56 extern struct hwc_class *hcl_head;
56 57 static char *rootname; /* node name of top_devinfo */
57 58
58 59 /*
59 60 * This lock must be held while updating devi_sibling pointers of
60 61 * rootnex immediate children
61 62 */
62 63 kmutex_t global_vhci_lock;
63 64
64 65 major_t mm_major;
65 66 major_t nulldriver_major;
66 67
67 68 /*
|
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
68 69 * Forward declarations
69 70 */
70 71 static void impl_create_root_class(void);
71 72 static void create_devinfo_tree(void);
72 73
73 74 #if defined(__x86)
74 75 char *bootpath_prop = NULL;
75 76 char *fstype_prop = NULL;
76 77 #endif
77 78
79 +char *aoepath_prop = NULL;
80 +
78 81 /*
79 82 * Setup the DDI but don't necessarily init the DDI. This will happen
80 83 * later once /boot is released.
81 84 */
82 85 void
83 86 setup_ddi(void)
84 87 {
85 88 impl_ddi_init_nodeid();
86 89 impl_create_root_class();
87 90 create_devinfo_tree();
88 91 e_ddi_instance_init();
89 92 impl_ddi_callback_init();
90 93 log_event_init();
91 94 fm_init();
92 95 ndi_fm_init();
93 96 irm_init();
94 97
95 98 (void) i_ddi_load_drvconf(DDI_MAJOR_T_NONE);
96 99
97 100 ldi_init();
98 101
99 102 i_ddi_devices_init();
100 103 i_ddi_read_devices_files();
101 104 }
102 105
103 106 /*
104 107 * Perform setup actions post startup (i_ddi_io_initialized)
105 108 */
106 109 void
107 110 setup_ddi_poststartup(void)
108 111 {
109 112 extern void i_ddi_start_flush_daemon(void);
110 113 extern void i_ddi_irm_poststartup(void);
111 114 extern void i_ddi_intr_redist_all_cpus(void);
112 115
113 116 i_ddi_start_flush_daemon();
114 117
115 118 /* Startup Interrupt Resource Management (IRM) */
116 119 i_ddi_irm_poststartup();
117 120
118 121 /*
119 122 * For platforms that support INTR_WEIGHTED_DIST, we perform a
120 123 * redistribution at this point (after NICs configured) so that
121 124 * "isolation" relative to "ddi-intr-weight" occurs.
122 125 */
123 126 i_ddi_intr_redist_all_cpus();
124 127 }
125 128
126 129 /*
127 130 * Create classes and major number bindings for the name of my root.
128 131 * Called immediately before 'loadrootmodules'
129 132 */
130 133 static void
131 134 impl_create_root_class(void)
132 135 {
133 136 major_t major;
134 137 size_t size;
135 138 char *cp;
136 139
137 140 /*
138 141 * The name for the root nexus is exactly as the manufacturer
139 142 * placed it in the prom name property. No translation.
140 143 */
141 144 if ((major = ddi_name_to_major("rootnex")) == DDI_MAJOR_T_NONE)
142 145 panic("Couldn't find major number for 'rootnex'");
143 146
144 147 /*
145 148 * C OBP (Serengeti) does not include the NULL when returning
146 149 * the length of the name property, while this violates 1275,
147 150 * Solaris needs to work around this by allocating space for
148 151 * an extra character.
149 152 */
150 153 size = (size_t)BOP_GETPROPLEN(bootops, "mfg-name") + 1;
151 154 rootname = kmem_zalloc(size, KM_SLEEP);
152 155 (void) BOP_GETPROP(bootops, "mfg-name", rootname);
153 156
154 157 /*
155 158 * Fix conflict between OBP names and filesystem names.
156 159 * Substitute '_' for '/' in the name. Ick. This is only
157 160 * needed for the root node since '/' is not a legal name
158 161 * character in an OBP device name.
159 162 */
160 163 for (cp = rootname; *cp; cp++)
161 164 if (*cp == '/')
162 165 *cp = '_';
163 166
164 167 /*
165 168 * Bind rootname to rootnex driver
166 169 */
167 170 if (make_mbind(rootname, major, NULL, mb_hashtab) != 0) {
168 171 cmn_err(CE_WARN, "A driver or driver alias has already "
169 172 "registered the name \"%s\". The root nexus needs to "
170 173 "use this name, and will override the existing entry. "
171 174 "Please correct /etc/name_to_major and/or "
172 175 "/etc/driver_aliases and reboot.", rootname);
173 176
174 177 /*
175 178 * Resort to the emergency measure of blowing away the
176 179 * existing hash entry and replacing it with rootname's.
177 180 */
178 181 delete_mbind(rootname, mb_hashtab);
179 182 if (make_mbind(rootname, major, NULL, mb_hashtab) != 0)
180 183 panic("mb_hashtab: inconsistent state.");
181 184 }
182 185
|
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
183 186 /*
184 187 * The `platform' or `implementation architecture' name has been
185 188 * translated by boot to be proper for file system use. It is
186 189 * the `name' of the platform actually booted. Note the assumption
187 190 * is that the name will `fit' in the buffer platform (which is
188 191 * of size SYS_NMLN, which is far bigger than will actually ever
189 192 * be needed).
190 193 */
191 194 (void) BOP_GETPROP(bootops, "impl-arch-name", platform);
192 195
196 + /*
197 + * If boot-aoepath is defined, assume it's AoE boot and set bootpath to
198 + * aoeblk/blkdev device corresponding to specified shelf.slot numbers.
199 + */
200 + size = (size_t)BOP_GETPROPLEN(bootops, "boot-aoepath");
201 + if (size != -1) {
202 + char aoedev[MAXPATHLEN];
203 + char *delim;
204 + int shelf, slot;
205 +
206 + aoepath_prop = kmem_zalloc(size, KM_SLEEP);
207 + (void) BOP_GETPROP(bootops, "boot-aoepath", aoepath_prop);
208 + /*
209 + * If boot-aoepath is set to "auto", device will be
210 + * configured later during AoE autoconfiguration.
211 + */
212 + if (strcmp(aoepath_prop, "auto") != 0) {
213 + if ((delim = strchr(aoepath_prop, '.')) != NULL)
214 + *delim++ = '\0';
215 + if (ddi_strtol(aoepath_prop, (char **)NULL, 10,
216 + (long *)&shelf) != 0)
217 + shelf = 0;
218 + if (delim == NULL ||
219 + ddi_strtol(delim, (char **)NULL, 10,
220 + (long *)&slot) != 0)
221 + slot = 0;
222 + /* FIXME aoeblk@0,0 ?! */
223 + (void) snprintf(aoedev, MAXPATHLEN,
224 + "/aoe/aoeblk@0,0/blkdev@%d,%d",
225 + shelf, slot);
226 + setbootpath(aoedev);
227 + }
228 + }
229 +
193 230 #if defined(__x86)
194 231 /*
195 232 * Retrieve and honor the bootpath and optional fstype properties
196 233 */
197 234 size = (size_t)BOP_GETPROPLEN(bootops, "bootpath");
198 235 if (size != -1) {
199 236 bootpath_prop = kmem_zalloc(size, KM_SLEEP);
200 237 (void) BOP_GETPROP(bootops, "bootpath", bootpath_prop);
201 238 setbootpath(bootpath_prop);
202 239 }
203 240
204 241 size = (size_t)BOP_GETPROPLEN(bootops, "fstype");
205 242 if (size != -1) {
206 243 fstype_prop = kmem_zalloc(size, KM_SLEEP);
207 244 (void) BOP_GETPROP(bootops, "fstype", fstype_prop);
208 245 setbootfstype(fstype_prop);
209 246 }
210 247 #endif
211 248 }
212 249
213 250 /*
214 251 * Note that this routine does not take into account the endianness
215 252 * of the host or the device (or PROM) when retrieving properties.
216 253 */
217 254 static int
218 255 getlongprop_buf(int id, char *name, char *buf, int maxlen)
219 256 {
220 257 int size;
221 258
222 259 size = prom_getproplen((pnode_t)id, name);
223 260 if (size <= 0 || (size > maxlen - 1))
224 261 return (-1);
225 262
226 263 if (-1 == prom_getprop((pnode_t)id, name, buf))
227 264 return (-1);
228 265
229 266 /*
230 267 * Workaround for bugid 1085575 - OBP may return a "name" property
231 268 * without null terminating the string with '\0'. When this occurs,
232 269 * append a '\0' and return (size + 1).
233 270 */
234 271 if (strcmp("name", name) == 0) {
235 272 if (buf[size - 1] != '\0') {
236 273 buf[size] = '\0';
237 274 size += 1;
238 275 }
239 276 }
240 277
241 278 return (size);
242 279 }
243 280
244 281 /*ARGSUSED1*/
245 282 static int
246 283 get_neighbors(dev_info_t *di, int flag)
247 284 {
248 285 register int nid, snid, cnid;
249 286 dev_info_t *parent;
250 287 char buf[OBP_MAXPROPNAME];
251 288
252 289 if (di == NULL)
253 290 return (DDI_WALK_CONTINUE);
254 291
255 292 nid = ddi_get_nodeid(di);
256 293
257 294 snid = cnid = 0;
258 295 switch (flag) {
259 296 case DDI_WALK_PRUNESIB:
260 297 cnid = (int)prom_childnode((pnode_t)nid);
261 298 break;
262 299 case DDI_WALK_PRUNECHILD:
263 300 snid = (int)prom_nextnode((pnode_t)nid);
264 301 break;
265 302 case 0:
266 303 snid = (int)prom_nextnode((pnode_t)nid);
267 304 cnid = (int)prom_childnode((pnode_t)nid);
268 305 break;
269 306 default:
270 307 return (DDI_WALK_TERMINATE);
271 308 }
272 309
273 310
274 311 if (snid && (snid != -1) && ((parent = ddi_get_parent(di)) != NULL)) {
275 312 /*
276 313 * add the first sibling that passes check_status()
277 314 */
278 315 for (; snid && (snid != -1);
279 316 snid = (int)prom_nextnode((pnode_t)snid)) {
280 317 if (getlongprop_buf(snid, OBP_NAME, buf,
281 318 sizeof (buf)) > 0) {
282 319 if (check_status(snid, buf, parent) ==
283 320 DDI_SUCCESS) {
284 321 (void) ddi_add_child(parent, buf,
285 322 snid, -1);
286 323 break;
287 324 }
288 325 }
289 326 }
290 327 }
291 328
292 329 if (cnid && (cnid != -1)) {
293 330 /*
294 331 * add the first child that passes check_status()
295 332 */
296 333 if (getlongprop_buf(cnid, OBP_NAME, buf, sizeof (buf)) > 0) {
297 334 if (check_status(cnid, buf, di) == DDI_SUCCESS) {
298 335 (void) ddi_add_child(di, buf, cnid, -1);
299 336 } else {
300 337 for (cnid = (int)prom_nextnode((pnode_t)cnid);
301 338 cnid && (cnid != -1);
302 339 cnid = (int)prom_nextnode((pnode_t)cnid)) {
303 340 if (getlongprop_buf(cnid, OBP_NAME,
304 341 buf, sizeof (buf)) > 0) {
305 342 if (check_status(cnid, buf, di)
306 343 == DDI_SUCCESS) {
307 344 (void) ddi_add_child(
308 345 di, buf, cnid, -1);
309 346 break;
310 347 }
311 348 }
312 349 }
313 350 }
314 351 }
315 352 }
316 353
317 354 return (DDI_WALK_CONTINUE);
318 355 }
319 356
320 357 static void
321 358 di_dfs(dev_info_t *devi, int (*f)(dev_info_t *, int), caddr_t arg)
322 359 {
323 360 (void) (*f)(devi, 0);
324 361 if (devi) {
325 362 di_dfs((dev_info_t *)DEVI(devi)->devi_child, f, arg);
326 363 di_dfs((dev_info_t *)DEVI(devi)->devi_sibling, f, arg);
327 364 }
328 365 }
329 366
330 367 dev_info_t *
331 368 i_ddi_create_branch(dev_info_t *pdip, int nid)
332 369 {
333 370 char *buf;
334 371 dev_info_t *dip = NULL;
335 372
336 373 if (pdip == NULL || nid == OBP_NONODE || nid == OBP_BADNODE)
337 374 return (NULL);
338 375
339 376 buf = kmem_alloc(OBP_MAXPROPNAME, KM_SLEEP);
340 377
341 378 if (getlongprop_buf(nid, OBP_NAME, buf, OBP_MAXPROPNAME) > 0) {
342 379 if (check_status(nid, buf, pdip) == DDI_SUCCESS)
343 380 dip = ddi_add_child(pdip, buf, nid, -1);
344 381 }
345 382
346 383 kmem_free(buf, OBP_MAXPROPNAME);
347 384
348 385 if (dip == NULL)
349 386 return (NULL);
350 387
351 388 /*
352 389 * Don't create any siblings of the branch root, just
353 390 * children.
354 391 */
355 392 (void) get_neighbors(dip, DDI_WALK_PRUNESIB);
356 393
357 394 di_dfs(ddi_get_child(dip), get_neighbors, 0);
358 395
359 396 return (dip);
360 397 }
361 398
362 399 static void
363 400 create_devinfo_tree(void)
364 401 {
365 402 major_t major;
366 403 pnode_t nodeid;
367 404
368 405 i_ddi_node_cache_init();
369 406 #if defined(__sparc)
370 407 nodeid = prom_nextnode(0);
371 408 #else /* x86 */
372 409 nodeid = DEVI_SID_NODEID;
373 410 #endif
374 411 top_devinfo = i_ddi_alloc_node(NULL, rootname,
375 412 nodeid, -1, NULL, KM_SLEEP);
376 413 ndi_hold_devi(top_devinfo); /* never release the root */
377 414
378 415 i_ddi_add_devimap(top_devinfo);
379 416
380 417 /*
381 418 * Bind root node.
382 419 * This code is special because root node has no parent
383 420 */
384 421 major = ddi_name_to_major("rootnex");
385 422 ASSERT(major != DDI_MAJOR_T_NONE);
386 423 DEVI(top_devinfo)->devi_major = major;
387 424 devnamesp[major].dn_head = top_devinfo;
388 425 i_ddi_set_binding_name(top_devinfo, rootname);
389 426 i_ddi_set_node_state(top_devinfo, DS_BOUND);
390 427
391 428 /*
392 429 * Record that devinfos have been made for "rootnex."
393 430 * di_dfs() is used to read the prom because it doesn't get the
394 431 * next sibling until the function returns, unlike ddi_walk_devs().
395 432 */
396 433 di_dfs(ddi_root_node(), get_neighbors, 0);
397 434
398 435 #if !defined(__sparc)
399 436 /*
400 437 * On x86, there is no prom. Create device tree by
401 438 * probing pci config space
402 439 */
403 440 {
404 441 extern void impl_setup_ddi(void);
405 442 impl_setup_ddi();
406 443 }
407 444 #endif /* x86 */
408 445 }
409 446
410 447 /*
411 448 * Init and attach the root node. root node is the first one to be
412 449 * attached, so the process is somewhat "handcrafted".
413 450 */
414 451 void
415 452 i_ddi_init_root()
416 453 {
417 454 #ifdef DDI_PROP_DEBUG
418 455 (void) ddi_prop_debug(1); /* Enable property debugging */
419 456 #endif /* DDI_PROP_DEBUG */
420 457
421 458 /*
422 459 * Initialize root node
423 460 */
424 461 if (impl_ddi_sunbus_initchild(top_devinfo) != DDI_SUCCESS)
425 462 panic("Could not initialize root nexus");
426 463
427 464 /*
428 465 * Attach root node (no need to probe)
429 466 * Hold both devinfo and rootnex driver so they can't go away.
430 467 */
431 468 DEVI(top_devinfo)->devi_ops = ndi_hold_driver(top_devinfo);
432 469 ASSERT(DEV_OPS_HELD(DEVI(top_devinfo)->devi_ops));
433 470 DEVI(top_devinfo)->devi_instance = e_ddi_assign_instance(top_devinfo);
434 471
435 472 (void) i_ddi_load_drvconf(DEVI(top_devinfo)->devi_major);
436 473
437 474 mutex_enter(&(DEVI(top_devinfo)->devi_lock));
438 475 DEVI_SET_ATTACHING(top_devinfo);
439 476 mutex_exit(&(DEVI(top_devinfo)->devi_lock));
440 477
441 478 if (devi_attach(top_devinfo, DDI_ATTACH) != DDI_SUCCESS)
442 479 panic("Could not attach root nexus");
443 480
444 481 mutex_enter(&(DEVI(top_devinfo)->devi_lock));
445 482 DEVI_CLR_ATTACHING(top_devinfo);
446 483 mutex_exit(&(DEVI(top_devinfo)->devi_lock));
447 484
448 485 mutex_init(&global_vhci_lock, NULL, MUTEX_DEFAULT, NULL);
449 486
450 487 ndi_hold_devi(top_devinfo); /* hold it forever */
451 488 i_ddi_set_node_state(top_devinfo, DS_READY);
452 489
453 490 /*
454 491 * Now, expand .conf children of root
455 492 */
456 493 (void) i_ndi_make_spec_children(top_devinfo, 0);
457 494
458 495 /*
459 496 * Must be set up before attaching root or pseudo drivers
460 497 */
461 498 pm_init_locks();
462 499
463 500 /*
464 501 * Attach options dip
465 502 */
466 503 options_dip = i_ddi_attach_pseudo_node("options");
467 504
468 505 /*
469 506 * Attach pseudo nexus and enumerate its children
470 507 */
471 508 pseudo_dip = i_ddi_attach_pseudo_node(DEVI_PSEUDO_NEXNAME);
472 509 (void) i_ndi_make_spec_children(pseudo_dip, 0);
473 510
474 511 /*
475 512 * Attach and hold clone dip
476 513 */
477 514 clone_dip = i_ddi_attach_pseudo_node("clone");
478 515 clone_major = ddi_driver_major(clone_dip);
479 516 mm_major = ddi_name_to_major("mm");
480 517 nulldriver_major = ddi_name_to_major("nulldriver");
481 518
482 519 /*
483 520 * Attach scsi_vhci for MPXIO, this registers scsi vhci class
484 521 * with the MPXIO framework.
485 522 */
486 523 scsi_vhci_dip = i_ddi_attach_pseudo_node("scsi_vhci");
487 524 }
|
↓ open down ↓ |
285 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX