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]
22 * Copyright (c) 1982, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 * Configure root, swap and dump devices.
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/sysmacros.h>
33 #include <sys/signal.h>
39 #include <sys/systm.h>
41 #include <sys/reboot.h>
44 #include <sys/vnode.h>
45 #include <sys/errno.h>
49 #include <sys/mount.h>
51 #include <sys/bootconf.h>
52 #include <sys/sysconf.h>
53 #include <sys/modctl.h>
54 #include <sys/autoconf.h>
55 #include <sys/debug.h>
56 #include <sys/fs/snode.h>
57 #include <fs/fs_subr.h>
58 #include <sys/socket.h>
61 #include <sys/mkdev.h>
62 #include <sys/cmn_err.h>
63 #include <sys/console.h>
67 #include <sys/sunddi.h>
68 #include <sys/hwconf.h>
69 #include <sys/dc_ki.h>
70 #include <sys/promif.h>
71 #include <sys/bootprops.h>
76 static int preload_module(struct sysparam
*, void *);
77 static struct vfssw
*getfstype(char *, char *, size_t);
78 static int getphysdev(char *, char *, size_t);
79 static int load_bootpath_drivers(char *bootpath
);
80 static int load_boot_driver(char *drv
);
81 static int load_boot_platform_modules(char *drv
);
82 static dev_info_t
*path_to_devinfo(char *path
);
83 static boolean_t
netboot_over_ib(char *bootpath
);
84 static boolean_t
netboot_over_iscsi(void);
87 * Module linkage information for the kernel.
89 static struct modlmisc modlmisc
= {
90 &mod_miscops
, "root and swap configuration"
93 static struct modlinkage modlinkage
= {
94 MODREV_1
, (void *)&modlmisc
, NULL
100 return (mod_install(&modlinkage
));
106 return (mod_remove(&modlinkage
));
110 _info(struct modinfo
*modinfop
)
112 return (mod_info(&modlinkage
, modinfop
));
115 extern ib_boot_prop_t
*iscsiboot_prop
;
117 * Configure root file system.
124 extern void pm_init(void);
126 BMDPRINTF(("rootconf: fstype %s\n", rootfs
.bo_fstype
));
127 BMDPRINTF(("rootconf: name %s\n", rootfs
.bo_name
));
128 BMDPRINTF(("rootconf: flags 0x%x\n", rootfs
.bo_flags
));
129 BMDPRINTF(("rootconf: obp_bootpath %s\n", obp_bootpath
));
132 * Install cluster modules that were only loaded during
135 if (error
= clboot_rootconf())
139 (void) strncpy(rootfs
.bo_name
, obp_bootpath
, BO_MAXOBJNAME
);
141 BMDPRINTF(("rootconf: svm: rootfs name %s\n", rootfs
.bo_name
));
142 BMDPRINTF(("rootconf: svm: svm name %s\n", svm_bootpath
));
146 * Run _init on the root filesystem (we already loaded it
147 * but we've been waiting until now to _init it) which will
148 * have the side-effect of running vsw_init() on this vfs.
149 * Because all the nfs filesystems are lumped into one
150 * module we need to special case it.
152 if (strncmp(rootfs
.bo_fstype
, "nfs", 3) == 0) {
153 if (modload("fs", "nfs") == -1) {
154 cmn_err(CE_CONT
, "Cannot initialize %s filesystem\n",
159 if (modload("fs", rootfs
.bo_fstype
) == -1) {
160 cmn_err(CE_CONT
, "Cannot initialize %s filesystem\n",
166 vsw
= vfs_getvfsswbyname(rootfs
.bo_fstype
);
169 cmn_err(CE_CONT
, "Cannot find %s filesystem\n",
173 VFS_INIT(rootvfs
, &vsw
->vsw_vfsops
, (caddr_t
)0);
177 rootvfs
->vfs_flag
|= VFS_RDONLY
;
181 * This pm-releated call has to occur before root is mounted since we
182 * need to power up all devices. It is placed after VFS_INIT() such
183 * that opening a device via ddi_lyr_ interface just before root has
184 * been mounted would work.
188 if (netboot
&& iscsiboot_prop
) {
189 cmn_err(CE_WARN
, "NFS boot and iSCSI boot"
190 " shouldn't happen in the same time");
194 if (netboot
|| iscsiboot_prop
) {
197 cmn_err(CE_WARN
, "Cannot plumb network device %d", ret
);
202 if ((ret
== 0) && iscsiboot_prop
) {
203 ret
= modload("drv", "iscsi");
204 /* -1 indicates fail */
206 cmn_err(CE_WARN
, "Failed to load iscsi module");
207 iscsi_boot_prop_free();
210 if (!i_ddi_attach_pseudo_node("iscsi")) {
212 "Failed to attach iscsi driver");
213 iscsi_boot_prop_free();
220 * ufs_mountroot() ends up calling getrootdev()
221 * (below) which actually triggers the _init, identify,
222 * probe and attach of the drivers that make up root device
223 * bush; these are also quietly waiting in memory.
225 BMDPRINTF(("rootconf: calling VFS_MOUNTROOT %s\n", rootfs
.bo_fstype
));
227 error
= VFS_MOUNTROOT(rootvfs
, ROOT_INIT
);
229 rootdev
= rootvfs
->vfs_dev
;
232 cmn_err(CE_CONT
, "Cannot mount root on %s fstype %s\n",
233 rootfs
.bo_name
, rootfs
.bo_fstype
);
235 cmn_err(CE_CONT
, "?root on %s fstype %s\n",
236 rootfs
.bo_name
, rootfs
.bo_fstype
);
241 * Remount root on an SVM mirror root device
242 * Only supported on UFS filesystems at present
248 extern int ufs_remountroot(struct vfs
*vfsp
);
250 ASSERT(root_is_svm
== 1);
252 if (strcmp(rootfs
.bo_fstype
, "ufs") != 0) {
253 cmn_err(CE_CONT
, "Mounting root on %s with filesystem "
254 "type %s is not supported\n",
255 rootfs
.bo_name
, rootfs
.bo_fstype
);
259 (void) strncpy(rootfs
.bo_name
, svm_bootpath
, BO_MAXOBJNAME
);
261 BMDPRINTF(("svm_rootconf: rootfs %s\n", rootfs
.bo_name
));
263 error
= ufs_remountroot(rootvfs
);
266 cmn_err(CE_CONT
, "Cannot remount root on %s fstype %s\n",
267 rootfs
.bo_name
, rootfs
.bo_fstype
);
269 cmn_err(CE_CONT
, "?root remounted on %s fstype %s\n",
270 rootfs
.bo_name
, rootfs
.bo_fstype
);
276 * Under the assumption that our root file system is on a
277 * disk partition, get the dev_t of the partition in question.
279 * By now, boot has faithfully loaded all our modules into memory, and
280 * we've taken over resource management. Before we go any further, we
281 * have to fire up the device drivers and stuff we need to mount the
282 * root filesystem. That's what we do here. Fingers crossed.
289 d
= ddi_pathname_to_dev_t(rootfs
.bo_name
);
290 if ((d
== NODEV
) && (iscsiboot_prop
!= NULL
)) {
291 /* Give it another try with the 'disk' path */
292 get_iscsi_bootpath_phy(rootfs
.bo_name
);
293 d
= ddi_pathname_to_dev_t(rootfs
.bo_name
);
296 cmn_err(CE_CONT
, "Cannot assemble drivers for root %s\n",
302 * If booted with ASKNAME, prompt on the console for a filesystem
303 * name and return it.
306 getfsname(char *askfor
, char *name
, size_t namelen
)
308 if (boothowto
& RB_ASKNAME
) {
309 printf("%s name: ", askfor
);
310 console_gets(name
, namelen
);
316 preload_module(struct sysparam
*sysp
, void *p
)
318 static char *wmesg
= "forceload of %s failed";
321 name
= sysp
->sys_ptr
;
322 BMDPRINTF(("preload_module: %s\n", name
));
323 if (modloadonly(NULL
, name
) < 0)
324 cmn_err(CE_WARN
, wmesg
, name
);
329 * We want to load all the modules needed to mount the root filesystem,
330 * so that when we start the ball rolling in 'getrootdev', every module
331 * should already be in memory, just waiting to be init-ed.
335 loadrootmodules(void)
342 extern char *impl_module_list
[];
343 extern char *platform_module_list
[];
345 /* Make sure that the PROM's devinfo tree has been created */
346 ASSERT(ddi_root_node());
348 BMDPRINTF(("loadrootmodules: fstype %s\n", rootfs
.bo_fstype
));
349 BMDPRINTF(("loadrootmodules: name %s\n", rootfs
.bo_name
));
350 BMDPRINTF(("loadrootmodules: flags 0x%x\n", rootfs
.bo_flags
));
353 * zzz We need to honor what's in rootfs if it's not null.
354 * non-null means use what's there. This way we can
355 * change rootfs with /etc/system AND with tunetool.
358 /* user replaced rootdev, record obp_bootpath */
359 obp_bootpath
[0] = '\0';
360 (void) getphysdev("root", obp_bootpath
, BO_MAXOBJNAME
);
361 BMDPRINTF(("loadrootmodules: obp_bootpath %s\n", obp_bootpath
));
364 * Get the root fstype and root device path from boot.
366 rootfs
.bo_fstype
[0] = '\0';
367 rootfs
.bo_name
[0] = '\0';
371 * This lookup will result in modloadonly-ing the root
372 * filesystem module - it gets _init-ed in rootconf()
374 if ((vsw
= getfstype("root", rootfs
.bo_fstype
, BO_MAXFSNAME
)) == NULL
)
375 return (ENXIO
); /* in case we have no file system types */
377 (void) strcpy(rootfs
.bo_fstype
, vsw
->vsw_name
);
382 * Load the favored drivers of the implementation.
383 * e.g. 'sbus' and possibly 'zs' (even).
385 * Called whilst boot is still loaded (because boot does
386 * the i/o for us), and DDI services are unavailable.
388 BMDPRINTF(("loadrootmodules: impl_module_list\n"));
389 for (i
= 0; (this = impl_module_list
[i
]) != NULL
; i
++) {
390 if ((err
= load_boot_driver(this)) != 0) {
391 cmn_err(CE_WARN
, "Cannot load drv/%s", this);
396 * Now load the platform modules (if any)
398 BMDPRINTF(("loadrootmodules: platform_module_list\n"));
399 for (i
= 0; (this = platform_module_list
[i
]) != NULL
; i
++) {
400 if ((err
= load_boot_platform_modules(this)) != 0) {
401 cmn_err(CE_WARN
, "Cannot load drv/%s", this);
407 (void) getphysdev("root", rootfs
.bo_name
, BO_MAXOBJNAME
);
409 * Given a physical pathname, load the correct set of driver
410 * modules into memory, including all possible parents.
412 * NB: The code sets the variable 'name' for error reporting.
415 BMDPRINTF(("loadrootmodules: rootfs %s\n", rootfs
.bo_name
));
416 if (root_is_svm
== 0) {
417 BMDPRINTF(("loadrootmodules: rootfs %s\n", rootfs
.bo_name
));
418 name
= rootfs
.bo_name
;
419 err
= load_bootpath_drivers(rootfs
.bo_name
);
423 * Load driver modules in obp_bootpath, this is always
424 * required for mountroot to succeed. obp_bootpath is
425 * is set if rootdev is set via /etc/system, which is
426 * the case if booting of a SVM/VxVM mirror.
428 if ((err
== 0) && obp_bootpath
[0] != '\0') {
429 BMDPRINTF(("loadrootmodules: obp_bootpath %s\n", obp_bootpath
));
431 err
= load_bootpath_drivers(obp_bootpath
);
435 cmn_err(CE_CONT
, "Cannot load drivers for %s\n", name
);
440 * Check to see if the booter performed DHCP configuration
441 * ("bootp-response" boot property exists). If so, then before
442 * bootops disappears we need to save the value of this property
443 * such that the userland dhcpagent can adopt the DHCP management
444 * of our primary network interface.
446 proplen
= BOP_GETPROPLEN(bootops
, "bootp-response");
448 dhcack
= kmem_zalloc(proplen
, KM_SLEEP
);
449 if (BOP_GETPROP(bootops
, "bootp-response", dhcack
) == -1) {
450 cmn_err(CE_WARN
, "BOP_GETPROP of "
451 "\"bootp-response\" failed\n");
452 kmem_free(dhcack
, dhcacklen
);
459 * Fetch the "netdev-path" boot property (if it exists), and
460 * stash it for later use by sysinfo(SI_DHCP_CACHE, ...).
462 proplen
= BOP_GETPROPLEN(bootops
, "netdev-path");
464 netdev_path
= kmem_zalloc(proplen
, KM_SLEEP
);
465 if (BOP_GETPROP(bootops
, "netdev-path",
466 (uchar_t
*)netdev_path
) == -1) {
467 cmn_err(CE_WARN
, "BOP_GETPROP of "
468 "\"netdev-path\" failed\n");
469 kmem_free(netdev_path
, proplen
);
476 * Preload (load-only, no init) all modules which
477 * were added to the /etc/system file with the
480 BMDPRINTF(("loadrootmodules: preload_module\n"));
481 (void) mod_sysctl_type(MOD_FORCELOAD
, preload_module
, NULL
);
484 * If we booted otw then load in the plumbing
485 * routine now while we still can. If we didn't
486 * boot otw then we will load strplumb in main().
488 * NFS is actually a set of modules, the core routines,
489 * a diskless helper module, rpcmod, and the tli interface. Load
490 * them now while we still can.
492 * Because we glomb all versions of nfs into a single module
493 * we check based on the initial string "nfs".
495 * XXX: A better test for this is to see if device_type
496 * XXX: from the PROM is "network".
499 if (strncmp(rootfs
.bo_fstype
, "nfs", 3) == 0) {
503 * Preload (load-only, no init) the dacf module. We cannot
504 * init the module because one of its requisite modules is
505 * dld whose _init function will call taskq_create(), which
506 * will panic the system at this point.
508 if ((err
= modloadonly("dacf", "net_dacf")) < 0) {
509 cmn_err(CE_CONT
, "Cannot load dacf/net_dacf\n");
512 if ((err
= modload("misc", "tlimod")) < 0) {
513 cmn_err(CE_CONT
, "Cannot load misc/tlimod\n");
516 if ((err
= modload("strmod", "rpcmod")) < 0) {
517 cmn_err(CE_CONT
, "Cannot load strmod/rpcmod\n");
520 if ((err
= modload("misc", "nfs_dlboot")) < 0) {
521 cmn_err(CE_CONT
, "Cannot load misc/nfs_dlboot\n");
524 if ((err
= modload("mac", "mac_ether")) < 0) {
525 cmn_err(CE_CONT
, "Cannot load mac/mac_ether\n");
528 if ((err
= modload("misc", "strplumb")) < 0) {
529 cmn_err(CE_CONT
, "Cannot load misc/strplumb\n");
532 if ((err
= strplumb_load()) < 0) {
536 if (netboot_over_iscsi() == B_TRUE
) {
538 if ((err
= modloadonly("dacf", "net_dacf")) < 0) {
539 cmn_err(CE_CONT
, "Cannot load dacf/net_dacf\n");
542 if ((err
= modload("misc", "tlimod")) < 0) {
543 cmn_err(CE_CONT
, "Cannot load misc/tlimod\n");
546 if ((err
= modload("mac", "mac_ether")) < 0) {
547 cmn_err(CE_CONT
, "Cannot load mac/mac_ether\n");
550 if ((err
= modloadonly("drv", "iscsi")) < 0) {
551 cmn_err(CE_CONT
, "Cannot load drv/iscsi\n");
554 if ((err
= modloadonly("drv", "ssd")) < 0) {
555 cmn_err(CE_CONT
, "Cannot load drv/ssd\n");
558 if ((err
= modloadonly("drv", "sd")) < 0) {
559 cmn_err(CE_CONT
, "Cannot load drv/sd\n");
562 if ((err
= modload("misc", "strplumb")) < 0) {
563 cmn_err(CE_CONT
, "Cannot load misc/strplumb\n");
566 if ((err
= strplumb_load()) < 0) {
571 * Preload modules needed for booting as a cluster.
573 err
= clboot_loadrootmodules();
576 if (err
!= 0 && (boothowto
& RB_ASKNAME
))
583 get_bootpath_prop(char *bootpath
)
585 if (root_is_ramdisk
) {
586 if (BOP_GETPROP(bootops
, "bootarchive", bootpath
) == -1)
588 (void) strlcat(bootpath
, ":a", BO_MAXOBJNAME
);
591 * Look for the 1275 compliant name 'bootpath' first,
592 * but make certain it has a non-NULL value as well.
594 if ((BOP_GETPROP(bootops
, "bootpath", bootpath
) == -1) ||
595 strlen(bootpath
) == 0) {
596 if (BOP_GETPROP(bootops
,
597 "boot-path", bootpath
) == -1)
600 if (memcmp(bootpath
, BP_ISCSI_DISK
,
601 strlen(BP_ISCSI_DISK
)) == 0) {
603 get_iscsi_bootpath_vhci(bootpath
);
610 get_fstype_prop(char *fstype
)
612 char *prop
= (root_is_ramdisk
) ? "archive-fstype" : "fstype";
614 return (BOP_GETPROP(bootops
, prop
, fstype
));
618 * Get the name of the root or swap filesystem type, and return
619 * the corresponding entry in the vfs switch.
621 * If we're not asking the user, and we're trying to find the
622 * root filesystem type, we ask boot for the filesystem
623 * type that it came from and use that. Similarly, if we're
624 * trying to find the swap filesystem, we try and derive it from
625 * the root filesystem type.
627 * If we are booting via NFS we currently have these options:
628 * nfs - dynamically choose NFS V2. V3, or V4 (default)
629 * nfs2 - force NFS V2
630 * nfs3 - force NFS V3
631 * nfs4 - force NFS V4
632 * Because we need to maintain backward compatibility with the naming
633 * convention that the NFS V2 filesystem name is "nfs" (see vfs_conf.c)
634 * we need to map "nfs" => "nfsdyn" and "nfs2" => "nfs". The dynamic
635 * nfs module will map the type back to either "nfs", "nfs3", or "nfs4".
636 * This is only for root filesystems, all other uses will expect
637 * that "nfs" == NFS V2.
639 * If the filesystem isn't already loaded, vfs_getvfssw() will load
640 * it for us, but if (at the time we call it) modrootloaded is
641 * still not set, it won't run the filesystems _init routine (and
642 * implicitly it won't run the filesystems vsw_init() entry either).
643 * We do that explicitly in rootconf().
645 static struct vfssw
*
646 getfstype(char *askfor
, char *fsname
, size_t fsnamelen
)
649 static char defaultfs
[BO_MAXFSNAME
];
652 if (strcmp(askfor
, "root") == 0) {
653 (void) get_fstype_prop(defaultfs
);
656 (void) strcpy(defaultfs
, "swapfs");
659 if (boothowto
& RB_ASKNAME
) {
660 for (*fsname
= '\0'; *fsname
== '\0'; *fsname
= '\0') {
661 printf("%s filesystem type [%s]: ", askfor
, defaultfs
);
662 console_gets(fsname
, fsnamelen
);
664 (void) strcpy(fsname
, defaultfs
);
666 if (strcmp(fsname
, "nfs2") == 0)
667 (void) strcpy(fsname
, "nfs");
668 else if (strcmp(fsname
, "nfs") == 0)
669 (void) strcpy(fsname
, "nfsdyn");
671 if ((vsw
= vfs_getvfssw(fsname
)) != NULL
)
673 printf("Unknown filesystem type '%s'\n", fsname
);
675 } else if (*fsname
== '\0') {
678 if (*fsname
== '\0') {
683 if (strcmp(fsname
, "nfs2") == 0)
684 (void) strcpy(fsname
, "nfs");
685 else if (strcmp(fsname
, "nfs") == 0)
686 (void) strcpy(fsname
, "nfsdyn");
689 return (vfs_getvfssw(fsname
));
694 * Get a physical device name, and maybe load and attach
697 * XXX Need better checking of whether or not a device
698 * actually exists if the user typed in a pathname.
700 * XXX Are we sure we want to expose users to this sort
701 * of physical namespace gobbledygook (now there's
702 * a word to conjure with..)
704 * XXX Note that on an OBP machine, we can easily ask the
705 * prom and pretty-print some plausible set of bootable
706 * devices. We can also user the prom to verify any
707 * such device. Later tim.. later.
710 getphysdev(char *askfor
, char *name
, size_t namelen
)
712 static char fmt
[] = "Enter physical name of %s device\n[%s]: ";
714 static char defaultpath
[BO_MAXOBJNAME
];
717 * Establish 'default' values - we get the root device from
718 * boot, and we infer the swap device is the same but with
719 * a 'b' on the end instead of an 'a'. A first stab at
722 if (strcmp(askfor
, "root") == 0) {
723 if (get_bootpath_prop(defaultpath
) == -1)
724 boothowto
|= RB_ASKNAME
| RB_VERBOSE
;
726 (void) strcpy(defaultpath
, rootfs
.bo_name
);
727 defaultpath
[strlen(defaultpath
) - 1] = 'b';
731 if (boothowto
& RB_ASKNAME
) {
732 printf(fmt
, askfor
, defaultpath
);
733 console_gets(name
, namelen
);
736 (void) strcpy(name
, defaultpath
);
738 if (strcmp(askfor
, "swap") == 0) {
741 * Try to load and install the swap device driver.
743 dev
= ddi_pathname_to_dev_t(name
);
745 if (dev
== (dev_t
)-1) {
746 printf("Not a supported device for swap.\n");
747 boothowto
|= RB_ASKNAME
| RB_VERBOSE
;
752 * Ensure that we're not trying to swap on the floppy.
754 if (strncmp(ddi_major_to_name(getmajor(dev
)), "fd", 2) == 0) {
755 printf("Too dangerous to swap on the floppy\n");
756 if (boothowto
& RB_ASKNAME
)
767 * Load a driver needed to boot.
770 load_boot_driver(char *drv
)
775 struct devnames
*dnp
;
783 if ((major
= ddi_name_to_major(drv
)) == DDI_MAJOR_T_NONE
) {
784 cmn_err(CE_CONT
, "%s: no major number\n", drv
);
790 drvname
= ddi_major_to_name(major
);
793 if (strcmp(drv
, drvname
) == 0) {
794 BMDPRINTF(("load_boot_driver: %s\n", drv
));
796 BMDPRINTF(("load_boot_driver: %s -> %s\n", drv
, drvname
));
800 if (modloadonly("drv", drvname
) == -1) {
801 cmn_err(CE_CONT
, "%s: cannot load driver\n", drvname
);
807 * NOTE: this can be removed when newboot-sparc is delivered.
809 * Check to see if the driver had a 'ddi-forceload' global driver.conf
810 * property to identify additional modules that need to be loaded.
811 * The driver still needs to use ddi_modopen() to open these modules,
812 * but the 'ddi-forceload' property allows the modules to be loaded
813 * into memory prior to lights-out, so that driver ddi_modopen()
814 * calls during lights-out (when mounting root) will work correctly.
815 * Use of 'ddi-forceload' is only required for drivers involved in
816 * getting root mounted.
818 dnp
= &devnamesp
[major
];
819 if (dnp
->dn_global_prop_ptr
&& dnp
->dn_global_prop_ptr
->prop_list
&&
820 ((propp
= i_ddi_prop_search(DDI_DEV_T_ANY
,
821 "ddi-forceload", DDI_PROP_TYPE_STRING
,
822 &dnp
->dn_global_prop_ptr
->prop_list
)) != NULL
)) {
824 module
= (char *)propp
->prop_val
;
825 plen
= propp
->prop_len
;
827 mlen
= strlen(module
);
828 mf
= strrchr(module
, '/');
831 *mf
++ = '\0'; /* '/' -> '\0' */
836 if (modloadonly(dir
, mf
) == -1)
838 "misc/%s: can't load module\n", mf
);
840 *(mf
- 1) = '/'; /* '\0' -> '/' */
853 * For a given instance, load that driver and its parents
856 load_parent_drivers(dev_info_t
*dip
, char *path
)
859 major_t major
= DDI_MAJOR_T_NONE
;
864 /* check for path-oriented alias */
866 major
= ddi_name_to_major(path
);
868 major
= DDI_MAJOR_T_NONE
;
870 if (major
!= DDI_MAJOR_T_NONE
)
871 drv
= ddi_major_to_name(major
);
873 drv
= ddi_binding_name(dip
);
875 if (load_boot_driver(drv
) != 0)
878 dip
= ddi_get_parent(dip
);
880 p
= strrchr(path
, '/');
891 * For a given path to a boot device,
892 * load that driver and all its parents.
895 load_bootpath_drivers(char *bootpath
)
903 char iscsi_network_path
[BO_MAXOBJNAME
];
905 if (bootpath
== NULL
|| *bootpath
== 0)
908 BMDPRINTF(("load_bootpath_drivers: %s\n", bootpath
));
910 if (netboot_over_iscsi()) {
912 if (root_is_ramdisk
) {
913 if (modloadonly("drv", "ramdisk") < 0)
916 proplen
= BOP_GETPROPLEN(bootops
, BP_ISCSI_NETWORK_BOOTPATH
);
918 if (BOP_GETPROP(bootops
, BP_ISCSI_NETWORK_BOOTPATH
,
919 iscsi_network_path
) > 0) {
920 p
= strchr(iscsi_network_path
, ':');
924 pathcopy
= i_ddi_strdup(iscsi_network_path
,
926 pathcopy_len
= strlen(pathcopy
) + 1;
935 pathcopy
= i_ddi_strdup(bootpath
, KM_SLEEP
);
936 pathcopy_len
= strlen(pathcopy
) + 1;
940 dip
= path_to_devinfo(pathcopy
);
942 #if defined(__i386) || defined(__amd64)
944 * i386 does not provide stub nodes for all boot devices,
945 * but we should be able to find the node for the parent,
946 * and the leaf of the boot path should be the driver name,
947 * which we go ahead and load here.
953 * Find last slash to build the full path to the
954 * parent of the leaf boot device
956 p
= strrchr(pathcopy
, '/');
960 * Now isolate the driver name of the leaf device
963 p
= strchr(leaf
, '@');
966 BMDPRINTF(("load_bootpath_drivers: parent=%s leaf=%s\n",
969 dip
= path_to_devinfo(pathcopy
);
971 rval
= load_boot_driver(leaf
, NULL
);
973 kmem_free(pathcopy
, pathcopy_len
);
981 cmn_err(CE_WARN
, "can't bind driver for boot path <%s>",
983 kmem_free(pathcopy
, pathcopy_len
);
988 * Load IP over IB driver when netbooting over IB.
989 * As per IB 1275 binding, IP over IB is represented as
990 * service on the top of the HCA node. So, there is no
991 * PROM node and generic framework cannot pre-load
992 * IP over IB driver based on the bootpath. The following
993 * code preloads IP over IB driver when doing netboot over
996 if (netboot_over_ib(bootpath
) &&
997 modloadonly("drv", "ibp") == -1) {
998 cmn_err(CE_CONT
, "ibp: cannot load platform driver\n");
999 kmem_free(pathcopy
, pathcopy_len
);
1004 * The PROM node for hubs have incomplete compatible
1005 * properties and therefore do not bind to the hubd driver.
1006 * As a result load_bootpath_drivers() loads the usb_mid driver
1007 * for hub nodes rather than the hubd driver. This causes
1008 * mountroot failures when booting off USB storage. To prevent
1009 * this, if we are booting via USB hubs, we preload the hubd driver.
1011 if (strstr(bootpath
, "/hub@") && modloadonly("drv", "hubd") == -1) {
1012 cmn_err(CE_WARN
, "bootpath contains a USB hub, "
1013 "but cannot load hubd driver");
1016 /* get rid of minor node at end of copy (if not already done above) */
1017 p
= strrchr(pathcopy
, '/');
1024 rval
= load_parent_drivers(dip
, pathcopy
);
1025 kmem_free(pathcopy
, pathcopy_len
);
1033 * Load drivers required for a platform
1034 * Since all hardware nodes should be available in the device
1035 * tree, walk the per-driver list and load the parents of
1036 * each node found. If not a hardware node, try to load it.
1037 * Pseudo nexus is already loaded.
1040 load_boot_platform_modules(char *drv
)
1047 if ((major
= ddi_name_to_major(drv
)) == DDI_MAJOR_T_NONE
) {
1048 cmn_err(CE_CONT
, "%s: no major number\n", drv
);
1055 drvname
= ddi_major_to_name(major
);
1056 if ((major
= ddi_name_to_major(drvname
)) == DDI_MAJOR_T_NONE
)
1060 if (strcmp(drv
, drvname
) == 0) {
1061 BMDPRINTF(("load_boot_platform_modules: %s\n", drv
));
1063 BMDPRINTF(("load_boot_platform_modules: %s -> %s\n",
1068 dip
= devnamesp
[major
].dn_head
;
1070 /* pseudo node, not-enumerated, needs to be loaded */
1071 if (modloadonly("drv", drvname
) == -1) {
1072 cmn_err(CE_CONT
, "%s: cannot load platform driver\n",
1078 if (load_parent_drivers(dip
, NULL
) != 0)
1080 dip
= ddi_get_next(dip
);
1089 * i_find_node: Internal routine used by path_to_devinfo
1090 * to locate a given nodeid in the device tree.
1092 struct i_path_findnode
{
1098 i_path_find_node(dev_info_t
*dev
, void *arg
)
1100 struct i_path_findnode
*f
= (struct i_path_findnode
*)arg
;
1103 if (ddi_get_nodeid(dev
) == (int)f
->nodeid
) {
1105 return (DDI_WALK_TERMINATE
);
1107 return (DDI_WALK_CONTINUE
);
1111 * Return the devinfo node to a boot device
1114 path_to_devinfo(char *path
)
1116 struct i_path_findnode fn
;
1117 extern dev_info_t
*top_devinfo
;
1120 * Get the nodeid of the given pathname, if such a mapping exists.
1123 fn
.nodeid
= prom_finddevice(path
);
1124 if (fn
.nodeid
!= OBP_BADNODE
) {
1126 * Find the nodeid in our copy of the device tree and return
1127 * whatever name we used to bind this node to a driver.
1129 ddi_walk_devs(top_devinfo
, i_path_find_node
, (void *)(&fn
));
1134 * If we're bound to something other than the nodename,
1135 * note that in the message buffer and system log.
1140 p
= ddi_binding_name(fn
.dip
);
1141 q
= ddi_node_name(fn
.dip
);
1142 if (p
&& q
&& (strcmp(p
, q
) != 0)) {
1143 BMDPRINTF(("path_to_devinfo: %s bound to %s\n",
1153 * This routine returns B_TRUE if the bootpath corresponds to
1154 * IP over IB driver.
1156 * The format of the bootpath for the IP over IB looks like
1157 * /pci@1f,700000/pci@1/ib@0:port=1,pkey=8001,protocol=ip
1159 * The minor node portion "port=1,pkey=8001,protocol=ip" represents
1160 * IP over IB driver.
1163 netboot_over_ib(char *bootpath
)
1167 boolean_t ret
= B_FALSE
;
1168 pnode_t node
= prom_finddevice(bootpath
);
1170 char devicetype
[OBP_MAXDRVNAME
];
1172 /* Is this IB node ? */
1173 if (node
== OBP_BADNODE
|| node
== OBP_NONODE
) {
1176 len
= prom_getproplen(node
, OBP_DEVICETYPE
);
1177 if (len
<= 1 || len
>= OBP_MAXDRVNAME
)
1180 (void) prom_getprop(node
, OBP_DEVICETYPE
, (caddr_t
)devicetype
);
1182 if (strncmp("ib", devicetype
, 2) == 0) {
1183 /* Check for proper IP over IB string */
1184 if ((temp
= strstr(bootpath
, ":port=")) != NULL
) {
1185 if ((temp
= strstr(temp
, ",pkey=")) != NULL
)
1186 if ((temp
= strstr(temp
,
1187 ",protocol=ip")) != NULL
) {
1196 netboot_over_iscsi(void)
1199 boolean_t ret
= B_FALSE
;
1200 char bootpath
[OBP_MAXPATHLEN
];
1202 proplen
= BOP_GETPROPLEN(bootops
, BP_BOOTPATH
);
1204 if (BOP_GETPROP(bootops
, BP_BOOTPATH
, bootpath
) > 0) {
1205 if (memcmp(bootpath
, BP_ISCSI_DISK
,
1206 strlen(BP_ISCSI_DISK
)) == 0) {