xref: /titanic_50/usr/src/cmd/devfsadm/smp_link.c (revision 989f28072d20c73ae0955d6a1e3e2fc74831cb39)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <devfsadm.h>
30 #include <strings.h>
31 #include <stdlib.h>
32 #include <limits.h>
33 #include <bsm/devalloc.h>
34 
35 #define	SMP_LINK_RE	"^smp/expd[0-9]+$"
36 #define	SMP_CLASS	"sas"
37 #define	SMP_DRV_NAME	"smp"
38 
39 static int smp_callback(di_minor_t minor, di_node_t node);
40 
41 static devfsadm_create_t smp_create_cbt[] = {
42 	{ SMP_CLASS, "ddi_sas_smp", SMP_DRV_NAME,
43 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, smp_callback
44 	}
45 };
46 
47 DEVFSADM_CREATE_INIT_V0(smp_create_cbt);
48 
49 /*
50  * HOT auto cleanup of smp links not desired.
51  */
52 static devfsadm_remove_t smp_remove_cbt[] = {
53 	{ SMP_CLASS, SMP_LINK_RE, RM_PRE,
54 		ILEVEL_0, devfsadm_rm_all
55 	}
56 };
57 
58 DEVFSADM_REMOVE_INIT_V0(smp_remove_cbt);
59 
60 /*
61  * Create link for expander devices as form
62  * dev/smp/expd0 -> ../../devices/pci@0,0/.../smp@w5001636000005aff:smp
63  */
64 static int
65 smp_callback(di_minor_t minor, di_node_t node)
66 {
67 	char l_path[PATH_MAX + 1];
68 	char *buf;
69 	char *mn;
70 	char *devfspath;
71 	devfsadm_enumerate_t rules[1] = {"smp/expd([0-9]+)", 1, MATCH_ADDR};
72 
73 	mn = di_minor_name(minor);
74 
75 	devfspath = di_devfs_path(node);
76 
77 	(void) strcpy(l_path, devfspath);
78 	(void) strcat(l_path, ":");
79 	(void) strcat(l_path, mn);
80 
81 	di_devfs_path_free(devfspath);
82 
83 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
84 		return (DEVFSADM_CONTINUE);
85 	}
86 
87 	(void) strcpy(l_path, "smp/expd");
88 	(void) strcat(l_path, buf);
89 	free(buf);
90 
91 	(void) devfsadm_mklink(l_path, node, minor, 0);
92 
93 	return (DEVFSADM_CONTINUE);
94 }
95