1*936b7af6Sjw /*
2*936b7af6Sjw * CDDL HEADER START
3*936b7af6Sjw *
4*936b7af6Sjw * The contents of this file are subject to the terms of the
5*936b7af6Sjw * Common Development and Distribution License (the "License").
6*936b7af6Sjw * You may not use this file except in compliance with the License.
7*936b7af6Sjw *
8*936b7af6Sjw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*936b7af6Sjw * or http://www.opensolaris.org/os/licensing.
10*936b7af6Sjw * See the License for the specific language governing permissions
11*936b7af6Sjw * and limitations under the License.
12*936b7af6Sjw *
13*936b7af6Sjw * When distributing Covered Code, include this CDDL HEADER in each
14*936b7af6Sjw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*936b7af6Sjw * If applicable, add the following below this CDDL HEADER, with the
16*936b7af6Sjw * fields enclosed by brackets "[]" replaced with your own identifying
17*936b7af6Sjw * information: Portions Copyright [yyyy] [name of copyright owner]
18*936b7af6Sjw *
19*936b7af6Sjw * CDDL HEADER END
20*936b7af6Sjw */
21*936b7af6Sjw
22*936b7af6Sjw /*
23*936b7af6Sjw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*936b7af6Sjw * Use is subject to license terms.
25*936b7af6Sjw */
26*936b7af6Sjw
27*936b7af6Sjw #include <devfsadm.h>
28*936b7af6Sjw #include <strings.h>
29*936b7af6Sjw #include <stdlib.h>
30*936b7af6Sjw #include <limits.h>
31*936b7af6Sjw #include <bsm/devalloc.h>
32*936b7af6Sjw
33*936b7af6Sjw #define SMP_LINK_RE "^smp/expd[0-9]+$"
34*936b7af6Sjw #define SMP_CLASS "sas"
35*936b7af6Sjw #define SMP_DRV_NAME "smp"
36*936b7af6Sjw
37*936b7af6Sjw static int smp_callback(di_minor_t minor, di_node_t node);
38*936b7af6Sjw
39*936b7af6Sjw static devfsadm_create_t smp_create_cbt[] = {
40*936b7af6Sjw { SMP_CLASS, "ddi_sas_smp", SMP_DRV_NAME,
41*936b7af6Sjw TYPE_EXACT | DRV_EXACT, ILEVEL_0, smp_callback
42*936b7af6Sjw }
43*936b7af6Sjw };
44*936b7af6Sjw
45*936b7af6Sjw DEVFSADM_CREATE_INIT_V0(smp_create_cbt);
46*936b7af6Sjw
47*936b7af6Sjw /*
48*936b7af6Sjw * HOT auto cleanup of smp links not desired.
49*936b7af6Sjw */
50*936b7af6Sjw static devfsadm_remove_t smp_remove_cbt[] = {
51*936b7af6Sjw { SMP_CLASS, SMP_LINK_RE, RM_PRE,
52*936b7af6Sjw ILEVEL_0, devfsadm_rm_all
53*936b7af6Sjw }
54*936b7af6Sjw };
55*936b7af6Sjw
56*936b7af6Sjw DEVFSADM_REMOVE_INIT_V0(smp_remove_cbt);
57*936b7af6Sjw
58*936b7af6Sjw /*
59*936b7af6Sjw * Create link for expander devices as form
60*936b7af6Sjw * dev/smp/expd0 -> ../../devices/pci@0,0/.../smp@w5001636000005aff:smp
61*936b7af6Sjw */
62*936b7af6Sjw static int
smp_callback(di_minor_t minor,di_node_t node)63*936b7af6Sjw smp_callback(di_minor_t minor, di_node_t node)
64*936b7af6Sjw {
65*936b7af6Sjw char l_path[PATH_MAX + 1];
66*936b7af6Sjw char *buf;
67*936b7af6Sjw char *mn;
68*936b7af6Sjw char *devfspath;
69*936b7af6Sjw devfsadm_enumerate_t rules[1] = {"smp/expd([0-9]+)", 1, MATCH_ADDR};
70*936b7af6Sjw
71*936b7af6Sjw mn = di_minor_name(minor);
72*936b7af6Sjw
73*936b7af6Sjw devfspath = di_devfs_path(node);
74*936b7af6Sjw
75*936b7af6Sjw (void) strcpy(l_path, devfspath);
76*936b7af6Sjw (void) strcat(l_path, ":");
77*936b7af6Sjw (void) strcat(l_path, mn);
78*936b7af6Sjw
79*936b7af6Sjw di_devfs_path_free(devfspath);
80*936b7af6Sjw
81*936b7af6Sjw if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
82*936b7af6Sjw return (DEVFSADM_CONTINUE);
83*936b7af6Sjw }
84*936b7af6Sjw
85*936b7af6Sjw (void) strcpy(l_path, "smp/expd");
86*936b7af6Sjw (void) strcat(l_path, buf);
87*936b7af6Sjw free(buf);
88*936b7af6Sjw
89*936b7af6Sjw (void) devfsadm_mklink(l_path, node, minor, 0);
90*936b7af6Sjw
91*936b7af6Sjw return (DEVFSADM_CONTINUE);
92*936b7af6Sjw }
93