/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Instance number assignment code
*/
#include <sys/autoconf.h>
#include <sys/systeminfo.h>
#include <sys/ddi_impldefs.h>
#include <sys/instance.h>
#include <sys/sysevent.h>
#include <sys/sysmacros.h>
static void in_preassign_instance(void);
static void i_log_devfs_instance_mod(void);
static int in_get_infile(char *);
static int in_eqstr(char *a, char *b);
static int in_next_instance_block(major_t, int);
static int in_next_instance(major_t);
/* external functions */
extern char *i_binding_to_drv_name(char *bname);
extern void plat_ioaliases_init(void);
/*
* This plus devnames defines the entire software state of the instance world.
*/
typedef struct in_softstate {
/*
* Used to serialize access to data structures
*/
void *ins_thread;
int ins_busy;
/*
* State transition information:
* e_ddi_inst_state contains, among other things, the root of a tree of
* device nodes used to track instance number assignments.
* Each device node may contain multiple driver bindings, represented
* by a linked list of in_drv_t nodes, each with an instance assignment
* (except for root node). Each in_drv node can be in one of 3 states,
* indicated by ind_state:
*
* IN_UNKNOWN: Each node created in this state. The instance number of
* this node is not known. ind_instance is set to -1.
* IN_PROVISIONAL: When a node is assigned an instance number in
* e_ddi_assign_instance(), its state is set to IN_PROVISIONAL.
* Subsequently, the framework will always call either
* e_ddi_keep_instance() which makes the node IN_PERMANENT
* or e_ddi_free_instance(), which deletes the node.
* IN_PERMANENT:
* If e_ddi_keep_instance() is called on an IN_PROVISIONAL node,
* its state is set to IN_PERMANENT.
*/
/*
* Return values for in_get_infile().
*/
#define PTI_FOUND 0
/*
* Path to instance file magic string used for first time boot after
* an install. If this is the first string in the file we will
* automatically rebuild the file.
*/
void
e_ddi_instance_init(void)
{
char *file;
/*
* Only one thread is allowed to change the state of the instance
* number assignments on the system at any given time.
* Note that this is not really necessary, as we are single-threaded
* here, but it won't hurt, and it allows us to keep ASSERTS for
* our assumptions in the code.
*/
/*
* Init the ioaliases if the platform supports it
*/
if (&plat_ioaliases_init)
/*
* Create the root node, instance zallocs to 0.
* The name and address of this node never get examined, we always
* start searching with its first child.
*/
switch (in_get_infile(file)) {
default:
case PTI_NOT_FOUND:
/* make sure path_to_inst is recreated */
boothowto |= RB_RECONFIG;
/*
* Something is wrong. First try the backup file.
* If not found, rebuild path_to_inst. Emit a
* message about the problem.
*/
break;
}
/*FALLTHROUGH*/
case PTI_FOUND:
/*
* We've got a readable file
* parse the file into the instance tree
*/
rebuild = 0;
break;
case PTI_REBUILD:
/*
* path_to_inst has magic str requesting a create
* Convert boot to reconfig boot to ensure /dev is
* in sync with new path_to_inst.
*/
boothowto |= RB_RECONFIG;
"?Using default device instance data\n");
break;
}
/*
* The OBP device tree has been copied to the kernel and
* bound to drivers at this point. We walk the per-driver
* list to preassign instances. Since the bus addr is
* unknown at this point, we cannot place the instance
* number in the instance tree. This will be done at
* a later time.
*/
if (rebuild)
}
static void
{
major_t m;
for (m = 0; m < devcnt; m++) {
while (dip) {
dnp->dn_instance++;
}
/*
* The preassign instance numbers are not fully
* accounted for until e_ddi_assign_instance().
* We can't fully account for them now because we
* don't currently have a unit-address. Because of
* this, we need to remember the preassign boundary
* to avoid ordering issues related to
* e_ddi_assign_instance of a preassigned value .vs.
* re-assignment of the same value for a dynamic
* SID node created by bus_config.
*/
}
}
/*
* Checks to see if the /etc/path_to_inst file exists and whether or not
* it has the magic string in it.
*
* Returns one of the following:
*
* PTI_FOUND - We have found the /etc/path_to_inst file
* PTI_REBUILD - We have found the /etc/path_to_inst file and the
* first line was PTI_MAGIC_STR.
* PTI_NOT_FOUND - We did not find the /etc/path_to_inst file
*
*/
static int
{
int return_val;
/*
* Try to open the file.
*/
return (PTI_NOT_FOUND);
}
/*
* Read the first PTI_MAGIC_STR_LEN bytes from the file to see if
* it contains the magic string. If there aren't that many bytes
* in the file, then assume file is correct and no magic string
* and move on.
*/
case PTI_MAGIC_STR_LEN:
/*
* If the first PTI_MAGIC_STR_LEN bytes are the magic string
* then return PTI_REBUILD.
*/
break;
case 0:
/*
* If the file is zero bytes in length, then consider the
* file to not be found
*/
default: /* Do nothing we have a good file */
break;
}
return (return_val);
}
int
{
return (1);
}
return (0);
}
static void
{
/* use preassigned instance if available */
else
}
/*
* Return 1 if instance block was assigned for the path.
*
* For multi-port NIC cards, sequential instance assignment across all
* ports on a card is highly desirable since the ppa is typically the
* same as the instance number, and the ppa is used in the NIC's public
* /dev name. This sequential assignment typically occurs as a result
* of in_preassign_instance() after initial install, or by
* i_ndi_init_hw_children() for NIC ports that share a common parent.
*
* Some NIC cards however use multi-function bridge chips, and to
* support sequential instance assignment accross all ports, without
* disabling multi-threaded attach, we have a (currently) undocumented
* hack to allocate instance numbers in contiguous blocks based on
* driver.conf properties.
*
* ^
* /---------- ------------\
* pci@0 pci@0,1 MULTI-FUNCTION BRIDGE CHIP
* / \ / \
* FJSV,e4ta@4 FJSV,e4ta@4,1 FJSV,e4ta@6 FJSV,e4ta@6,1 NIC PORTS
* n n+2 n+2 n+3 INSTANCE
*
* For the above example, the following driver.conf properties would be
* used to guarantee sequential instance number assignment.
*
* ddi-instance-blocks ="ib-FJSVe4ca", "ib-FJSVe4ta", "ib-generic";
* ib-FJSVe4ca = "/pci@0/FJSV,e4ca@4", "/pci@0/FJSV,e4ca@4,1",
* "/pci@0,1/FJSV,e4ca@6", "/pci@0,1/FJSV,e4ca@6,1";
* ib-FJSVe4ta = "/pci@0/FJSV,e4ta@4", "/pci@0/FJSV,e4ta@4,1",
* "/pci@0,1/FJSV,e4ta@6", "/pci@0,1/FJSV,e4ta@6,1";
* ib-generic = "/pci@0/network@4", "/pci@0/network@4,1",
* "/pci@0,1/network@6", "/pci@0,1/network@6,1";
*
* The value of the 'ddi-instance-blocks' property references a series
* of card specific properties, like 'ib-FJSV-e4ta', who's value
* defines a single 'instance block'. The 'instance block' describes
* all the paths below a multi-function bridge, where each path is
* called an 'instance path'. The 'instance block' property value is a
* series of 'instance paths'. The number of 'instance paths' in an
* 'instance block' defines the size of the instance block, and the
* ordering of the 'instance paths' defines the instance number
* assignment order for paths going through the 'instance block'.
*
* In the instance assignment code below, if a (path, driver) that
* currently has no instance number has a path that goes through an
* 'instance block', then block instance number allocation occurs. The
* block allocation code will find a sequential set of unused instance
* numbers, and assign instance numbers for all the paths in the
* 'instance block'. Each path is assigned a persistent instance
* number, even paths that don't exist in the device tree or fail
* probe(9E).
*/
static int
{
char *driver;
char *path;
char *addr;
int plen;
char *ipath;
int instance_base;
int splice;
int i;
/* check for fresh install case (in miniroot) */
return (0); /* already assigned */
/*
* Check to see if we need to allocate a block of contiguous instance
* numbers by looking for the 'ddi-instance-blocks' property.
*/
return (0); /* no instance block needed */
/*
* Get information out about node we are processing.
*
* NOTE: Since the node is not yet at DS_INITIALIZED, ddi_pathname()
* will not return the unit-address of the final path component even
* though the node has an established devi_addr unit-address - so we
* need to add the unit-address by hand.
*/
}
/* loop through instance block names */
continue;
/* lookup instance block */
"no devinition for instance block '%s' in %s.conf",
continue;
}
/* Does 'path' go through this instance block? */
continue;
break;
}
continue; /* no try next instance block */
}
/* yes, allocate and assign instances for all paths in block */
/*
* determine where we splice in instance paths and verify
* that none of the paths are too long.
*/
for (i = 0; i < nibp; i++) {
"path %d through instance block '%s' from "
break;
}
}
if (i < nibp) {
continue; /* too long */
}
/* allocate the instance block - no more failures */
continue;
}
/* free allocations */
/* notify devfsadmd to sync of path_to_inst file */
return (1);
}
/* our path did not go through any of of the instance blocks */
return (0);
}
/*
* Look up an instance number for a dev_info node, and assign one if it does
* not have one (the dev_info node has devi_name and devi_addr already set).
*/
{
char *name;
char *bname;
/*
* Allow implementation to override
*/
return (ret);
/*
* If this is a pseudo-device, use the instance number
* assigned by the pseudo nexus driver. The mutex is
* not needed since the instance tree is not used.
*/
if (is_pseudo_device(dip)) {
return (ddi_get_instance(dip));
}
/*
* Only one thread is allowed to change the state of the instance
* number assignments on the system at any given time.
*/
/*
* Look for instance node, allocate one if not found
*/
if (in_assign_instance_block(dip)) {
} else {
}
}
/*
* Link the devinfo node and in_node_t
*/
"interlink fields are not NULL", (void *)np);
}
/*
* Look for driver entry, allocate one if not found
*/
if (ddi_aliases_present == B_TRUE) {
}
in_hashdrv(dp);
} else {
}
}
return (ret);
}
static int
{
int len_needed;
return (DDI_SUCCESS);
return (DDI_FAILURE);
if (np->in_unit_addr) {
}
/*
* XX complain
*/
if (len_needed > len)
return (DDI_FAILURE);
else
np->in_unit_addr);
return (DDI_SUCCESS);
}
/*
* produce the path to the given instance of a major number.
* path must hold MAXPATHLEN string
*/
int
{
int ret;
/* look for the instance threaded off major */
break;
/* produce path from the node that uses the instance */
if (dp) {
*path = 0;
} else
ret = DDI_FAILURE;
return (ret);
}
/*
* Allocate a sequential block of instance numbers for the specified driver,
* and return the base instance number of the block. The implementation
* depends on the list being sorted in ascending instance number sequence.
* When there are no 'holes' in the allocation sequence, dn_instance is the
* next available instance number. When dn_instance is IN_SEARCHME, hole(s)
* exists and a slower code path executes which tries to fill holes.
*
* The block returned can't be in the preassigned range.
*/
static int
{
int prev;
int base;
int hole;
/* check to see if we can do a quick allocation */
return (base);
}
/*
* Use more complex code path, start by skipping preassign entries.
*/
break; /* beyond preassign */
/* No non-preassign entries, allocate block at preassign base. */
if (base == 0)
return (base);
}
/* See if we fit in hole at beginning (after preassigns) */
/* search the list for a large enough hole */
hole++; /* we have a hole */
break; /* we fit in hole */
}
/*
* If hole is zero then all holes are patched and we can resume
* quick allocations, but don't resume quick allocation if there is
* a preassign.
*/
return (prev + 1);
}
/* assign instance block of size 1 */
static int
{
}
/*
* This call causes us to *forget* the instance number we've generated
* for a given device if it was not permanent.
*/
void
{
char *name;
/*
* Allow implementation override
*/
return;
/*
* If this is a pseudo-device, no instance number
* was assigned.
*/
if (is_pseudo_device(dip)) {
return;
}
/*
* Only one thread is allowed to change the state of the instance
* number assignments on the system at any given time.
*/
/*
* Break the interlink between dip and np
*/
"wrong instance node: %p", (void *)np);
}
}
}
}
/*
* This makes our memory of an instance assignment permanent
*/
void
{
/* Don't make nulldriver instance assignments permanent */
return;
/*
* Allow implementation override
*/
return;
/*
* Nothing to do for pseudo devices.
*/
if (is_pseudo_device(dip))
return;
/*
* Only one thread is allowed to change the state of the instance
* number assignments on the system at any given time.
*/
}
}
/*
* A new major has been added to the system. Run through the orphan list
* and try to attach each one to a driver's list.
*/
void
{
/*
* disconnect the orphan list, and call in_hashdrv for each item
* on it
*/
/*
* Only one thread is allowed to change the state of the instance
* number assignments on the system at any given time.
*/
return;
}
/*
* Hash instance list to devnames structure of major.
* Note that if there is not a valid major number for the
* node, in_hashdrv will put it back on the no_major list.
*/
while (dp) {
in_hashdrv(dp);
}
}
static void
{
/*
* Assertion: parents are always instantiated by the framework
* before their children, destroyed after them
*/
/*
* Assertion: drv entries are always removed before their owning nodes
*/
/*
* Take the node out of the tree
*/
return;
} else {
return;
}
}
}
}
/*
* Recursive ascent
*
* This now only does half the job. It finds the node, then the caller
* has to search the node for the binding name
*/
static in_node_t *
{
char *name;
if (dip == ddi_root_node()) {
return (e_ddi_inst_state.ins_root);
}
/*
* call up to find parent, then look through the list of kids
* for a match
*/
return (np);
while (np) {
return (np);
}
}
return (np);
}
/*
* Create a node specified by cp and assign it the given instance no.
*/
static int
{
char *name;
/*
* Give a warning to the console.
* return value ignored
*/
"invalid instance file entry %s %d",
return (0);
}
"multiple instance number assignments for "
"'%s' (driver %s), %d used",
return (0);
}
return (0);
}
in_hashdrv(dp);
return (0);
}
/*
* Create (or find) the node named by path by recursively descending from the
* root's first child (we ignore the root, which is never named)
*/
static in_node_t *
{
return (NULL);
/*
* In S9 and earlier releases, the path_to_inst file
* SunCluster was prepended with "/node@#". This was
* removed in S10. We skip the prefix if the prefix
* still exists in /etc/path_to_inst. It is needed for
* various forms of Solaris upgrade to work properly
* in the SunCluster environment.
*/
if ((cluster_bootflags & CLUSTER_CONFIGURED) &&
while (name) {
return (np);
} else {
}
}
}
return (rp);
}
/*
* Insert node np into the tree as one of ap's children.
*/
static void
{
/*
* Make this node some other node's child or child's sibling
*/
} else {
break;
}
}
}
/*
* Insert drv entry dp onto a node's driver list
*/
static void
{
}
/*
* Parse the next name out of the path, null terminate it and update cp.
* caller has copied string so we can mess with it.
* Upon return *cpp points to the next section to be parsed, *addrp points
* to the current address substring (or NULL if none) and we return the
* current name substring (or NULL if none). name and address substrings
* are null terminated in place.
*/
static char *
{
return (NULL);
}
*sp = '\0';
} else { /* this is last component. */
}
} else {
}
return (namep);
}
/*
* Allocate a node and storage for name and addr strings, and fill them in.
*/
static in_node_t *
{
char *cp;
/*
* Has name or will become root
*/
addr = "";
namelen = 0;
else
KM_SLEEP);
if (name) {
}
return (np);
}
/*
* Allocate a drv entry and storage for binding name string, and fill it in.
*/
static in_drv_t *
{
char *cp;
/*
* Has name or will become root
*/
if (bindingname == NULL)
namelen = 0;
else
if (bindingname) {
}
return (dp);
}
static void
{
/*
* The root node can never be de-allocated
*/
}
static void
{
+ 1);
}
/*
* Handle the various possible versions of "no address"
*/
static int
in_eqstr(char *a, char *b)
{
if (a == b) /* covers case where both are nulls */
return (1);
if (a == NULL && *b == 0)
return (1);
if (b == NULL && *a == 0)
return (1);
return (0);
return (strcmp(a, b) == 0);
}
/*
* Returns true if instance no. is already in use by named driver
*/
static int
{
/*
* For now, if we've never heard of this device we assume it is not
* in use, since we can't tell
* XXX could do the weaker search through the nomajor list checking
* XXX for the same name
*/
return (0);
while (dp) {
return (1);
}
return (0);
}
static void
{
/* hash to no major list */
if (major == DDI_MAJOR_T_NONE) {
return;
}
/*
* dnp->dn_inlist is sorted by instance number.
* Adding a new instance entry may introduce holes,
* set dn_instance to IN_SEARCHME so the next instance
* assignment may fill in holes.
*/
/* prepend as the first entry, turn on IN_SEARCHME */
return;
}
}
} else {
}
}
/*
* Remove a driver entry from the list, given a previous pointer
*/
static void
{
return;
}
break;
}
}
}
static void
{
return;
}
return;
}
}
panic("in_dq_drv: in_drv not found on node driver list");
}
in_drv_t *
{
char *name;
while (dp) {
== NULL) {
}
break;
}
}
return (dp);
}
static void
i_log_devfs_instance_mod(void)
{
static int sent_one = 0;
/*
* Prevent unnecessary event generation. Do not generate more than
* one event during boot.
*/
if (sent_one && !i_ddi_io_initialized())
return;
return;
}
"event");
} else {
sent_one = 1;
}
}
void
e_ddi_enter_instance(void)
{
else {
while (e_ddi_inst_state.ins_busy)
}
}
void
e_ddi_exit_instance(void)
{
if (e_ddi_inst_state.ins_busy == 0) {
}
}
int
e_ddi_instance_is_clean(void)
{
}
void
e_ddi_instance_set_clean(void)
{
}
e_ddi_instance_root(void)
{
return (e_ddi_inst_state.ins_root);
}
/*
* Visit a node in the instance tree
*/
static int
{
char *next;
if (np->in_unit_addr[0] == 0)
else
np->in_unit_addr);
if (rval == INST_WALK_TERMINATE)
break;
}
}
if (rval == INST_WALK_TERMINATE)
break;
}
}
return (rval);
}
/*
* A general interface for walking the instance tree,
* calling a user-supplied callback for each node.
*/
int
e_ddi_walk_instances(int (*f)(const char *,
{
int rval;
char *path;
root = e_ddi_instance_root();
return (rval);
}
{
return (np);
}
return (NULL);
}
void
{
char *alias;
/*NOTREACHED*/
}
if (cnp->in_drivers) {
/* there can be multiple drivers bound */
}
/* bail here if the alias matches any other current path or itself */
(ddi_curr_redirect(alias) != 0))) {
goto out;
}
/*
* Since pcieb nodes can split and merge, it is dangerous
* to borrow and instance for them. However since they do
* not expose their instance numbers it is safe to never
* borrow one.
*/
goto out;
}
}
out:
}
void
{
char *alias;
/*NOTREACHED*/
}
if (addr) {
}
/*NOTREACHED*/
}
}
}