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]
23 * Copyright (c) 1982, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2016 Nexenta Systems, Inc.
28 * Configure root, swap and dump devices.
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/sysmacros.h>
34 #include <sys/signal.h>
40 #include <sys/systm.h>
42 #include <sys/reboot.h>
45 #include <sys/vnode.h>
46 #include <sys/errno.h>
50 #include <sys/mount.h>
52 #include <sys/bootconf.h>
53 #include <sys/sysconf.h>
54 #include <sys/modctl.h>
55 #include <sys/autoconf.h>
56 #include <sys/debug.h>
57 #include <sys/fs/snode.h>
58 #include <sys/fs_subr.h>
59 #include <sys/socket.h>
62 #include <sys/mkdev.h>
63 #include <sys/cmn_err.h>
64 #include <sys/console.h>
68 #include <sys/sunddi.h>
69 #include <sys/hwconf.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 * Run _init on the root filesystem (we already loaded it
133 * but we've been waiting until now to _init it) which will
134 * have the side-effect of running vsw_init() on this vfs.
135 * Because all the nfs filesystems are lumped into one
136 * module we need to special case it.
138 if (strncmp(rootfs
.bo_fstype
, "nfs", 3) == 0) {
139 if (modload("fs", "nfs") == -1) {
140 cmn_err(CE_CONT
, "Cannot initialize %s filesystem\n",
145 if (modload("fs", rootfs
.bo_fstype
) == -1) {
146 cmn_err(CE_CONT
, "Cannot initialize %s filesystem\n",
152 vsw
= vfs_getvfsswbyname(rootfs
.bo_fstype
);
155 cmn_err(CE_CONT
, "Cannot find %s filesystem\n",
159 VFS_INIT(rootvfs
, &vsw
->vsw_vfsops
, (caddr_t
)0);
163 * This pm-releated call has to occur before root is mounted since we
164 * need to power up all devices. It is placed after VFS_INIT() such
165 * that opening a device via ddi_lyr_ interface just before root has
166 * been mounted would work.
170 if (netboot
&& iscsiboot_prop
) {
171 cmn_err(CE_WARN
, "NFS boot and iSCSI boot"
172 " shouldn't happen in the same time");
176 if (netboot
|| iscsiboot_prop
) {
179 cmn_err(CE_WARN
, "Cannot plumb network device %d", ret
);
184 if ((ret
== 0) && iscsiboot_prop
) {
185 ret
= modload("drv", "iscsi");
186 /* -1 indicates fail */
188 cmn_err(CE_WARN
, "Failed to load iscsi module");
189 iscsi_boot_prop_free();
192 if (!i_ddi_attach_pseudo_node("iscsi")) {
194 "Failed to attach iscsi driver");
195 iscsi_boot_prop_free();
202 * ufs_mountroot() ends up calling getrootdev()
203 * (below) which actually triggers the _init, identify,
204 * probe and attach of the drivers that make up root device
205 * bush; these are also quietly waiting in memory.
207 BMDPRINTF(("rootconf: calling VFS_MOUNTROOT %s\n", rootfs
.bo_fstype
));
209 error
= VFS_MOUNTROOT(rootvfs
, ROOT_INIT
);
211 rootdev
= rootvfs
->vfs_dev
;
214 cmn_err(CE_CONT
, "Cannot mount root on %s fstype %s\n",
215 rootfs
.bo_name
, rootfs
.bo_fstype
);
217 cmn_err(CE_CONT
, "?root on %s fstype %s\n",
218 rootfs
.bo_name
, rootfs
.bo_fstype
);
223 * Under the assumption that our root file system is on a
224 * disk partition, get the dev_t of the partition in question.
226 * By now, boot has faithfully loaded all our modules into memory, and
227 * we've taken over resource management. Before we go any further, we
228 * have to fire up the device drivers and stuff we need to mount the
229 * root filesystem. That's what we do here. Fingers crossed.
236 d
= ddi_pathname_to_dev_t(rootfs
.bo_name
);
237 if ((d
== NODEV
) && (iscsiboot_prop
!= NULL
)) {
238 /* Give it another try with the 'disk' path */
239 get_iscsi_bootpath_phy(rootfs
.bo_name
);
240 d
= ddi_pathname_to_dev_t(rootfs
.bo_name
);
243 cmn_err(CE_CONT
, "Cannot assemble drivers for root %s\n",
249 * If booted with ASKNAME, prompt on the console for a filesystem
250 * name and return it.
253 getfsname(char *askfor
, char *name
, size_t namelen
)
255 if (boothowto
& RB_ASKNAME
) {
256 printf("%s name: ", askfor
);
257 console_gets(name
, namelen
);
263 preload_module(struct sysparam
*sysp
, void *p
)
265 static char *wmesg
= "forceload of %s failed";
268 name
= sysp
->sys_ptr
;
269 BMDPRINTF(("preload_module: %s\n", name
));
270 if (modloadonly(NULL
, name
) < 0)
271 cmn_err(CE_WARN
, wmesg
, name
);
276 * We want to load all the modules needed to mount the root filesystem,
277 * so that when we start the ball rolling in 'getrootdev', every module
278 * should already be in memory, just waiting to be init-ed.
282 loadrootmodules(void)
289 extern char *impl_module_list
[];
290 extern char *platform_module_list
[];
292 /* Make sure that the PROM's devinfo tree has been created */
293 ASSERT(ddi_root_node());
295 BMDPRINTF(("loadrootmodules: fstype %s\n", rootfs
.bo_fstype
));
296 BMDPRINTF(("loadrootmodules: name %s\n", rootfs
.bo_name
));
297 BMDPRINTF(("loadrootmodules: flags 0x%x\n", rootfs
.bo_flags
));
300 * Get the root fstype and root device path from boot.
302 rootfs
.bo_fstype
[0] = '\0';
303 rootfs
.bo_name
[0] = '\0';
306 * This lookup will result in modloadonly-ing the root
307 * filesystem module - it gets _init-ed in rootconf()
309 if ((vsw
= getfstype("root", rootfs
.bo_fstype
, BO_MAXFSNAME
)) == NULL
)
310 return (ENXIO
); /* in case we have no file system types */
312 (void) strcpy(rootfs
.bo_fstype
, vsw
->vsw_name
);
317 * Load the favored drivers of the implementation.
318 * e.g. 'sbus' and possibly 'zs' (even).
320 * Called whilst boot is still loaded (because boot does
321 * the i/o for us), and DDI services are unavailable.
323 BMDPRINTF(("loadrootmodules: impl_module_list\n"));
324 for (i
= 0; (this = impl_module_list
[i
]) != NULL
; i
++) {
325 if ((err
= load_boot_driver(this)) != 0) {
326 cmn_err(CE_WARN
, "Cannot load drv/%s", this);
331 * Now load the platform modules (if any)
333 BMDPRINTF(("loadrootmodules: platform_module_list\n"));
334 for (i
= 0; (this = platform_module_list
[i
]) != NULL
; i
++) {
335 if ((err
= load_boot_platform_modules(this)) != 0) {
336 cmn_err(CE_WARN
, "Cannot load drv/%s", this);
342 (void) getphysdev("root", rootfs
.bo_name
, BO_MAXOBJNAME
);
344 * Given a physical pathname, load the correct set of driver
345 * modules into memory, including all possible parents.
347 * NB: The code sets the variable 'name' for error reporting.
350 BMDPRINTF(("loadrootmodules: rootfs %s\n", rootfs
.bo_name
));
351 name
= rootfs
.bo_name
;
352 err
= load_bootpath_drivers(rootfs
.bo_name
);
355 * Load driver modules in obp_bootpath, this is always
356 * required for mountroot to succeed. obp_bootpath is
357 * is set if rootdev is set via /etc/system.
359 if ((err
== 0) && obp_bootpath
[0] != '\0') {
360 BMDPRINTF(("loadrootmodules: obp_bootpath %s\n", obp_bootpath
));
362 err
= load_bootpath_drivers(obp_bootpath
);
366 cmn_err(CE_CONT
, "Cannot load drivers for %s\n", name
);
371 * Check to see if the booter performed DHCP configuration
372 * ("bootp-response" boot property exists). If so, then before
373 * bootops disappears we need to save the value of this property
374 * such that the userland dhcpagent can adopt the DHCP management
375 * of our primary network interface.
377 proplen
= BOP_GETPROPLEN(bootops
, "bootp-response");
379 dhcack
= kmem_zalloc(proplen
, KM_SLEEP
);
380 if (BOP_GETPROP(bootops
, "bootp-response", dhcack
) == -1) {
381 cmn_err(CE_WARN
, "BOP_GETPROP of "
382 "\"bootp-response\" failed\n");
383 kmem_free(dhcack
, dhcacklen
);
390 * Fetch the "netdev-path" boot property (if it exists), and
391 * stash it for later use by sysinfo(SI_DHCP_CACHE, ...).
393 proplen
= BOP_GETPROPLEN(bootops
, "netdev-path");
395 netdev_path
= kmem_zalloc(proplen
, KM_SLEEP
);
396 if (BOP_GETPROP(bootops
, "netdev-path",
397 (uchar_t
*)netdev_path
) == -1) {
398 cmn_err(CE_WARN
, "BOP_GETPROP of "
399 "\"netdev-path\" failed\n");
400 kmem_free(netdev_path
, proplen
);
407 * Preload (load-only, no init) all modules which
408 * were added to the /etc/system file with the
411 BMDPRINTF(("loadrootmodules: preload_module\n"));
412 (void) mod_sysctl_type(MOD_FORCELOAD
, preload_module
, NULL
);
415 * If we booted otw then load in the plumbing
416 * routine now while we still can. If we didn't
417 * boot otw then we will load strplumb in main().
419 * NFS is actually a set of modules, the core routines,
420 * a diskless helper module, rpcmod, and the tli interface. Load
421 * them now while we still can.
423 * Because we glomb all versions of nfs into a single module
424 * we check based on the initial string "nfs".
426 * XXX: A better test for this is to see if device_type
427 * XXX: from the PROM is "network".
430 if (strncmp(rootfs
.bo_fstype
, "nfs", 3) == 0) {
434 * Preload (load-only, no init) the dacf module. We cannot
435 * init the module because one of its requisite modules is
436 * dld whose _init function will call taskq_create(), which
437 * will panic the system at this point.
439 if ((err
= modloadonly("dacf", "net_dacf")) < 0) {
440 cmn_err(CE_CONT
, "Cannot load dacf/net_dacf\n");
443 if ((err
= modload("misc", "tlimod")) < 0) {
444 cmn_err(CE_CONT
, "Cannot load misc/tlimod\n");
447 if ((err
= modload("strmod", "rpcmod")) < 0) {
448 cmn_err(CE_CONT
, "Cannot load strmod/rpcmod\n");
451 if ((err
= modload("misc", "nfs_dlboot")) < 0) {
452 cmn_err(CE_CONT
, "Cannot load misc/nfs_dlboot\n");
455 if ((err
= modload("mac", "mac_ether")) < 0) {
456 cmn_err(CE_CONT
, "Cannot load mac/mac_ether\n");
459 if ((err
= modload("misc", "strplumb")) < 0) {
460 cmn_err(CE_CONT
, "Cannot load misc/strplumb\n");
463 if ((err
= strplumb_load()) < 0) {
467 if (netboot_over_iscsi() == B_TRUE
) {
469 if ((err
= modloadonly("dacf", "net_dacf")) < 0) {
470 cmn_err(CE_CONT
, "Cannot load dacf/net_dacf\n");
473 if ((err
= modload("misc", "tlimod")) < 0) {
474 cmn_err(CE_CONT
, "Cannot load misc/tlimod\n");
477 if ((err
= modload("mac", "mac_ether")) < 0) {
478 cmn_err(CE_CONT
, "Cannot load mac/mac_ether\n");
481 if ((err
= modloadonly("drv", "iscsi")) < 0) {
482 cmn_err(CE_CONT
, "Cannot load drv/iscsi\n");
485 if ((err
= modloadonly("drv", "ssd")) < 0) {
486 cmn_err(CE_CONT
, "Cannot load drv/ssd\n");
489 if ((err
= modloadonly("drv", "sd")) < 0) {
490 cmn_err(CE_CONT
, "Cannot load drv/sd\n");
493 if ((err
= modload("misc", "strplumb")) < 0) {
494 cmn_err(CE_CONT
, "Cannot load misc/strplumb\n");
497 if ((err
= strplumb_load()) < 0) {
503 if (err
!= 0 && (boothowto
& RB_ASKNAME
))
510 get_bootpath_prop(char *bootpath
)
512 if (root_is_ramdisk
) {
513 if (BOP_GETPROP(bootops
, "bootarchive", bootpath
) == -1)
515 (void) strlcat(bootpath
, ":a", BO_MAXOBJNAME
);
518 * Look for the 1275 compliant name 'bootpath' first,
519 * but make certain it has a non-NULL value as well.
521 if ((BOP_GETPROP(bootops
, "bootpath", bootpath
) == -1) ||
522 strlen(bootpath
) == 0) {
523 if (BOP_GETPROP(bootops
,
524 "boot-path", bootpath
) == -1)
527 if (memcmp(bootpath
, BP_ISCSI_DISK
,
528 strlen(BP_ISCSI_DISK
)) == 0) {
530 get_iscsi_bootpath_vhci(bootpath
);
537 get_fstype_prop(char *fstype
)
539 char *prop
= (root_is_ramdisk
) ? "archive-fstype" : "fstype";
541 return (BOP_GETPROP(bootops
, prop
, fstype
));
545 * Get the name of the root or swap filesystem type, and return
546 * the corresponding entry in the vfs switch.
548 * If we're not asking the user, and we're trying to find the
549 * root filesystem type, we ask boot for the filesystem
550 * type that it came from and use that. Similarly, if we're
551 * trying to find the swap filesystem, we try and derive it from
552 * the root filesystem type.
554 * If we are booting via NFS we currently have these options:
555 * nfs - dynamically choose NFS V2. V3, or V4 (default)
556 * nfs2 - force NFS V2
557 * nfs3 - force NFS V3
558 * nfs4 - force NFS V4
559 * Because we need to maintain backward compatibility with the naming
560 * convention that the NFS V2 filesystem name is "nfs" (see vfs_conf.c)
561 * we need to map "nfs" => "nfsdyn" and "nfs2" => "nfs". The dynamic
562 * nfs module will map the type back to either "nfs", "nfs3", or "nfs4".
563 * This is only for root filesystems, all other uses will expect
564 * that "nfs" == NFS V2.
566 * If the filesystem isn't already loaded, vfs_getvfssw() will load
567 * it for us, but if (at the time we call it) modrootloaded is
568 * still not set, it won't run the filesystems _init routine (and
569 * implicitly it won't run the filesystems vsw_init() entry either).
570 * We do that explicitly in rootconf().
572 static struct vfssw
*
573 getfstype(char *askfor
, char *fsname
, size_t fsnamelen
)
576 static char defaultfs
[BO_MAXFSNAME
];
579 if (strcmp(askfor
, "root") == 0) {
580 (void) get_fstype_prop(defaultfs
);
583 (void) strcpy(defaultfs
, "swapfs");
586 if (boothowto
& RB_ASKNAME
) {
587 for (*fsname
= '\0'; *fsname
== '\0'; *fsname
= '\0') {
588 printf("%s filesystem type [%s]: ", askfor
, defaultfs
);
589 console_gets(fsname
, fsnamelen
);
591 (void) strcpy(fsname
, defaultfs
);
593 if (strcmp(fsname
, "nfs2") == 0)
594 (void) strcpy(fsname
, "nfs");
595 else if (strcmp(fsname
, "nfs") == 0)
596 (void) strcpy(fsname
, "nfsdyn");
598 if ((vsw
= vfs_getvfssw(fsname
)) != NULL
)
600 printf("Unknown filesystem type '%s'\n", fsname
);
602 } else if (*fsname
== '\0') {
605 if (*fsname
== '\0') {
610 if (strcmp(fsname
, "nfs2") == 0)
611 (void) strcpy(fsname
, "nfs");
612 else if (strcmp(fsname
, "nfs") == 0)
613 (void) strcpy(fsname
, "nfsdyn");
616 return (vfs_getvfssw(fsname
));
621 * Get a physical device name, and maybe load and attach
624 * XXX Need better checking of whether or not a device
625 * actually exists if the user typed in a pathname.
627 * XXX Are we sure we want to expose users to this sort
628 * of physical namespace gobbledygook (now there's
629 * a word to conjure with..)
631 * XXX Note that on an OBP machine, we can easily ask the
632 * prom and pretty-print some plausible set of bootable
633 * devices. We can also user the prom to verify any
634 * such device. Later tim.. later.
637 getphysdev(char *askfor
, char *name
, size_t namelen
)
639 static char fmt
[] = "Enter physical name of %s device\n[%s]: ";
641 static char defaultpath
[BO_MAXOBJNAME
];
644 * Establish 'default' values - we get the root device from
645 * boot, and we infer the swap device is the same but with
646 * a 'b' on the end instead of an 'a'. A first stab at
649 if (strcmp(askfor
, "root") == 0) {
650 if (get_bootpath_prop(defaultpath
) == -1)
651 boothowto
|= RB_ASKNAME
| RB_VERBOSE
;
653 (void) strcpy(defaultpath
, rootfs
.bo_name
);
654 defaultpath
[strlen(defaultpath
) - 1] = 'b';
658 if (boothowto
& RB_ASKNAME
) {
659 printf(fmt
, askfor
, defaultpath
);
660 console_gets(name
, namelen
);
663 (void) strcpy(name
, defaultpath
);
665 if (strcmp(askfor
, "swap") == 0) {
668 * Try to load and install the swap device driver.
670 dev
= ddi_pathname_to_dev_t(name
);
672 if (dev
== (dev_t
)-1) {
673 printf("Not a supported device for swap.\n");
674 boothowto
|= RB_ASKNAME
| RB_VERBOSE
;
679 * Ensure that we're not trying to swap on the floppy.
681 if (strncmp(ddi_major_to_name(getmajor(dev
)), "fd", 2) == 0) {
682 printf("Too dangerous to swap on the floppy\n");
683 if (boothowto
& RB_ASKNAME
)
694 * Load a driver needed to boot.
697 load_boot_driver(char *drv
)
702 struct devnames
*dnp
;
710 if ((major
= ddi_name_to_major(drv
)) == DDI_MAJOR_T_NONE
) {
711 cmn_err(CE_CONT
, "%s: no major number\n", drv
);
717 drvname
= ddi_major_to_name(major
);
720 if (strcmp(drv
, drvname
) == 0) {
721 BMDPRINTF(("load_boot_driver: %s\n", drv
));
723 BMDPRINTF(("load_boot_driver: %s -> %s\n", drv
, drvname
));
727 if (modloadonly("drv", drvname
) == -1) {
728 cmn_err(CE_CONT
, "%s: cannot load driver\n", drvname
);
734 * NOTE: this can be removed when newboot-sparc is delivered.
736 * Check to see if the driver had a 'ddi-forceload' global driver.conf
737 * property to identify additional modules that need to be loaded.
738 * The driver still needs to use ddi_modopen() to open these modules,
739 * but the 'ddi-forceload' property allows the modules to be loaded
740 * into memory prior to lights-out, so that driver ddi_modopen()
741 * calls during lights-out (when mounting root) will work correctly.
742 * Use of 'ddi-forceload' is only required for drivers involved in
743 * getting root mounted.
745 dnp
= &devnamesp
[major
];
746 if (dnp
->dn_global_prop_ptr
&& dnp
->dn_global_prop_ptr
->prop_list
&&
747 ((propp
= i_ddi_prop_search(DDI_DEV_T_ANY
,
748 "ddi-forceload", DDI_PROP_TYPE_STRING
,
749 &dnp
->dn_global_prop_ptr
->prop_list
)) != NULL
)) {
751 module
= (char *)propp
->prop_val
;
752 plen
= propp
->prop_len
;
754 mlen
= strlen(module
);
755 mf
= strrchr(module
, '/');
758 *mf
++ = '\0'; /* '/' -> '\0' */
763 if (modloadonly(dir
, mf
) == -1)
765 "misc/%s: can't load module\n", mf
);
767 *(mf
- 1) = '/'; /* '\0' -> '/' */
780 * For a given instance, load that driver and its parents
783 load_parent_drivers(dev_info_t
*dip
, char *path
)
786 major_t major
= DDI_MAJOR_T_NONE
;
791 /* check for path-oriented alias */
793 major
= ddi_name_to_major(path
);
795 major
= DDI_MAJOR_T_NONE
;
797 if (major
!= DDI_MAJOR_T_NONE
)
798 drv
= ddi_major_to_name(major
);
800 drv
= ddi_binding_name(dip
);
802 if (load_boot_driver(drv
) != 0)
805 dip
= ddi_get_parent(dip
);
807 p
= strrchr(path
, '/');
818 * For a given path to a boot device,
819 * load that driver and all its parents.
822 load_bootpath_drivers(char *bootpath
)
830 char iscsi_network_path
[BO_MAXOBJNAME
];
832 if (bootpath
== NULL
|| *bootpath
== 0)
835 BMDPRINTF(("load_bootpath_drivers: %s\n", bootpath
));
837 if (netboot_over_iscsi()) {
839 if (root_is_ramdisk
) {
840 if (modloadonly("drv", "ramdisk") < 0)
843 proplen
= BOP_GETPROPLEN(bootops
, BP_ISCSI_NETWORK_BOOTPATH
);
845 if (BOP_GETPROP(bootops
, BP_ISCSI_NETWORK_BOOTPATH
,
846 iscsi_network_path
) > 0) {
847 p
= strchr(iscsi_network_path
, ':');
851 pathcopy
= i_ddi_strdup(iscsi_network_path
,
853 pathcopy_len
= strlen(pathcopy
) + 1;
862 pathcopy
= i_ddi_strdup(bootpath
, KM_SLEEP
);
863 pathcopy_len
= strlen(pathcopy
) + 1;
867 dip
= path_to_devinfo(pathcopy
);
869 #if defined(__i386) || defined(__amd64)
871 * i386 does not provide stub nodes for all boot devices,
872 * but we should be able to find the node for the parent,
873 * and the leaf of the boot path should be the driver name,
874 * which we go ahead and load here.
880 * Find last slash to build the full path to the
881 * parent of the leaf boot device
883 p
= strrchr(pathcopy
, '/');
887 * Now isolate the driver name of the leaf device
890 p
= strchr(leaf
, '@');
893 BMDPRINTF(("load_bootpath_drivers: parent=%s leaf=%s\n",
896 dip
= path_to_devinfo(pathcopy
);
898 rval
= load_boot_driver(leaf
, NULL
);
900 kmem_free(pathcopy
, pathcopy_len
);
908 cmn_err(CE_WARN
, "can't bind driver for boot path <%s>",
910 kmem_free(pathcopy
, pathcopy_len
);
915 * Load IP over IB driver when netbooting over IB.
916 * As per IB 1275 binding, IP over IB is represented as
917 * service on the top of the HCA node. So, there is no
918 * PROM node and generic framework cannot pre-load
919 * IP over IB driver based on the bootpath. The following
920 * code preloads IP over IB driver when doing netboot over
923 if (netboot_over_ib(bootpath
) &&
924 modloadonly("drv", "ibp") == -1) {
925 cmn_err(CE_CONT
, "ibp: cannot load platform driver\n");
926 kmem_free(pathcopy
, pathcopy_len
);
931 * The PROM node for hubs have incomplete compatible
932 * properties and therefore do not bind to the hubd driver.
933 * As a result load_bootpath_drivers() loads the usb_mid driver
934 * for hub nodes rather than the hubd driver. This causes
935 * mountroot failures when booting off USB storage. To prevent
936 * this, if we are booting via USB hubs, we preload the hubd driver.
938 if (strstr(bootpath
, "/hub@") && modloadonly("drv", "hubd") == -1) {
939 cmn_err(CE_WARN
, "bootpath contains a USB hub, "
940 "but cannot load hubd driver");
943 /* get rid of minor node at end of copy (if not already done above) */
944 p
= strrchr(pathcopy
, '/');
951 rval
= load_parent_drivers(dip
, pathcopy
);
952 kmem_free(pathcopy
, pathcopy_len
);
960 * Load drivers required for a platform
961 * Since all hardware nodes should be available in the device
962 * tree, walk the per-driver list and load the parents of
963 * each node found. If not a hardware node, try to load it.
964 * Pseudo nexus is already loaded.
967 load_boot_platform_modules(char *drv
)
974 if ((major
= ddi_name_to_major(drv
)) == DDI_MAJOR_T_NONE
) {
975 cmn_err(CE_CONT
, "%s: no major number\n", drv
);
982 drvname
= ddi_major_to_name(major
);
983 if ((major
= ddi_name_to_major(drvname
)) == DDI_MAJOR_T_NONE
)
987 if (strcmp(drv
, drvname
) == 0) {
988 BMDPRINTF(("load_boot_platform_modules: %s\n", drv
));
990 BMDPRINTF(("load_boot_platform_modules: %s -> %s\n",
995 dip
= devnamesp
[major
].dn_head
;
997 /* pseudo node, not-enumerated, needs to be loaded */
998 if (modloadonly("drv", drvname
) == -1) {
999 cmn_err(CE_CONT
, "%s: cannot load platform driver\n",
1005 if (load_parent_drivers(dip
, NULL
) != 0)
1007 dip
= ddi_get_next(dip
);
1016 * i_find_node: Internal routine used by path_to_devinfo
1017 * to locate a given nodeid in the device tree.
1019 struct i_path_findnode
{
1025 i_path_find_node(dev_info_t
*dev
, void *arg
)
1027 struct i_path_findnode
*f
= (struct i_path_findnode
*)arg
;
1030 if (ddi_get_nodeid(dev
) == (int)f
->nodeid
) {
1032 return (DDI_WALK_TERMINATE
);
1034 return (DDI_WALK_CONTINUE
);
1038 * Return the devinfo node to a boot device
1041 path_to_devinfo(char *path
)
1043 struct i_path_findnode fn
;
1044 extern dev_info_t
*top_devinfo
;
1047 * Get the nodeid of the given pathname, if such a mapping exists.
1050 fn
.nodeid
= prom_finddevice(path
);
1051 if (fn
.nodeid
!= OBP_BADNODE
) {
1053 * Find the nodeid in our copy of the device tree and return
1054 * whatever name we used to bind this node to a driver.
1056 ddi_walk_devs(top_devinfo
, i_path_find_node
, (void *)(&fn
));
1061 * If we're bound to something other than the nodename,
1062 * note that in the message buffer and system log.
1067 p
= ddi_binding_name(fn
.dip
);
1068 q
= ddi_node_name(fn
.dip
);
1069 if (p
&& q
&& (strcmp(p
, q
) != 0)) {
1070 BMDPRINTF(("path_to_devinfo: %s bound to %s\n",
1080 * This routine returns B_TRUE if the bootpath corresponds to
1081 * IP over IB driver.
1083 * The format of the bootpath for the IP over IB looks like
1084 * /pci@1f,700000/pci@1/ib@0:port=1,pkey=8001,protocol=ip
1086 * The minor node portion "port=1,pkey=8001,protocol=ip" represents
1087 * IP over IB driver.
1090 netboot_over_ib(char *bootpath
)
1094 boolean_t ret
= B_FALSE
;
1095 pnode_t node
= prom_finddevice(bootpath
);
1097 char devicetype
[OBP_MAXDRVNAME
];
1099 /* Is this IB node ? */
1100 if (node
== OBP_BADNODE
|| node
== OBP_NONODE
) {
1103 len
= prom_getproplen(node
, OBP_DEVICETYPE
);
1104 if (len
<= 1 || len
>= OBP_MAXDRVNAME
)
1107 (void) prom_getprop(node
, OBP_DEVICETYPE
, (caddr_t
)devicetype
);
1109 if (strncmp("ib", devicetype
, 2) == 0) {
1110 /* Check for proper IP over IB string */
1111 if ((temp
= strstr(bootpath
, ":port=")) != NULL
) {
1112 if ((temp
= strstr(temp
, ",pkey=")) != NULL
)
1113 if ((temp
= strstr(temp
,
1114 ",protocol=ip")) != NULL
) {
1123 netboot_over_iscsi(void)
1126 boolean_t ret
= B_FALSE
;
1127 char bootpath
[OBP_MAXPATHLEN
];
1129 proplen
= BOP_GETPROPLEN(bootops
, BP_BOOTPATH
);
1131 if (BOP_GETPROP(bootops
, BP_BOOTPATH
, bootpath
) > 0) {
1132 if (memcmp(bootpath
, BP_ISCSI_DISK
,
1133 strlen(BP_ISCSI_DISK
)) == 0) {