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 #include <devfsadm.h> 28 #include <strings.h> 29 #include <stdlib.h> 30 #include <limits.h> 31 #include <bsm/devalloc.h> 32 33 #define SMP_LINK_RE "^smp/expd[0-9]+$" 34 #define SMP_CLASS "sas" 35 #define SMP_DRV_NAME "smp" 36 37 static int smp_callback(di_minor_t minor, di_node_t node); 38 39 static devfsadm_create_t smp_create_cbt[] = { 40 { SMP_CLASS, "ddi_sas_smp", SMP_DRV_NAME, 41 TYPE_EXACT | DRV_EXACT, ILEVEL_0, smp_callback 42 } 43 }; 44 45 DEVFSADM_CREATE_INIT_V0(smp_create_cbt); 46 47 /* 48 * HOT auto cleanup of smp links not desired. 49 */ 50 static devfsadm_remove_t smp_remove_cbt[] = { 51 { SMP_CLASS, SMP_LINK_RE, RM_PRE, 52 ILEVEL_0, devfsadm_rm_all 53 } 54 }; 55 56 DEVFSADM_REMOVE_INIT_V0(smp_remove_cbt); 57 58 /* 59 * Create link for expander devices as form 60 * dev/smp/expd0 -> ../../devices/pci@0,0/.../smp@w5001636000005aff:smp 61 */ 62 static int 63 smp_callback(di_minor_t minor, di_node_t node) 64 { 65 char l_path[PATH_MAX + 1]; 66 char *buf; 67 char *mn; 68 char *devfspath; 69 devfsadm_enumerate_t rules[1] = {"smp/expd([0-9]+)", 1, MATCH_ADDR}; 70 71 mn = di_minor_name(minor); 72 73 devfspath = di_devfs_path(node); 74 75 (void) strcpy(l_path, devfspath); 76 (void) strcat(l_path, ":"); 77 (void) strcat(l_path, mn); 78 79 di_devfs_path_free(devfspath); 80 81 if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) { 82 return (DEVFSADM_CONTINUE); 83 } 84 85 (void) strcpy(l_path, "smp/expd"); 86 (void) strcat(l_path, buf); 87 free(buf); 88 89 (void) devfsadm_mklink(l_path, node, minor, 0); 90 91 return (DEVFSADM_CONTINUE); 92 } 93