1 #!/sbin/sh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # 23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "%Z%%M% %I% %E% SMI" 27 # 28 29 # Function: check_add_drv() 30 # 31 # This function will check if the module has an entry in etc/name_to_major 32 # If not simply calls add_drv with the arguments given. If there is 33 # such an entry in name_to_major file, it adds entries in driver_aliases 34 # driver_classes and minor_perm if necessary. 35 # The syntax of this function is the same as add_drv. 36 37 check_add_drv() 38 { 39 if [ "$BASEDIR" = "" ] 40 then 41 BASEDIR=/ 42 fi 43 alias="" 44 class="" 45 ADD_ALIAS=0 46 ADD_CLASS=0 47 ADD_MINOR=0 48 OPTIND=1 49 IS_NET_DRIVER=0 50 51 cmd="add_drv" 52 53 NO_CMD= 54 while getopts i:b:m:c:N opt 55 do 56 case $opt in 57 N ) NO_CMD=1;; 58 i ) ADD_ALIAS=1 59 alias=$OPTARG 60 cmd=$cmd" -i '$alias'" 61 ;; 62 m ) ADD_MINOR=1 63 minor=$OPTARG 64 cmd=$cmd" -m '$minor'" 65 ;; 66 c) ADD_CLASS=1 67 class=$OPTARG 68 cmd=$cmd" -c $class" 69 ;; 70 b) BASEDIR=$OPTARG 71 cmd=$cmd" -b $BASEDIR" 72 ;; 73 \?) echo "check_add_drv can not handle this option" 74 return 75 ;; 76 esac 77 done 78 shift `/usr/bin/expr $OPTIND - 1` 79 80 drvname=$1 81 82 cmd=$cmd" "$drvname 83 84 drvname=`echo $drvname | /usr/bin/sed 's;.*/;;g'` 85 86 /usr/bin/grep "^$drvname[ ]" $BASEDIR/etc/name_to_major > /dev/null 2>&1 87 88 # 89 # NB: We really would have liked to use update_drv here, but 90 # since we can't do that (see CR 6281386), we have this code. 91 # Note that if we've never added this driver before, the add_drv 92 # below takes care of worrying about conflicting entries in 93 # /etc/driver_aliases. (It will fail if there is a conflicting 94 # driver squatting on the alias.) 95 # 96 if [ "$NO_CMD" = "" -a $? -ne 0 ] 97 then 98 eval $cmd 99 else 100 # entry already in name_to_major, add alias, class, minorperm 101 # if necessary 102 if [ $ADD_ALIAS = 1 ] 103 then 104 for i in $alias 105 do 106 /usr/bin/egrep "^$drvname[ ]+$i" $BASEDIR/etc/driver_aliases>/dev/null 2>&1 107 if [ $? -ne 0 ] 108 then 109 echo "$drvname $i" >> $BASEDIR/etc/driver_aliases 110 fi 111 done 112 fi 113 114 if [ $ADD_CLASS = 1 ] 115 then 116 /usr/bin/egrep "^$drvname[ ]+$class( | |$)" $BASEDIR/etc/driver_classes > /dev/null 2>&1 117 if [ $? -ne 0 ] 118 then 119 echo "$drvname\t$class" >> $BASEDIR/etc/driver_classes 120 fi 121 fi 122 123 if [ $ADD_MINOR = 1 ] 124 then 125 /usr/bin/grep "^$drvname:" $BASEDIR/etc/minor_perm > /dev/null 2>&1 126 if [ $? -ne 0 ] 127 then 128 minorentry="$drvname:$minor" 129 echo $minorentry >> $BASEDIR/etc/minor_perm 130 fi 131 fi 132 133 fi 134 135 136 } 137 138 # 139 # Okay, so 128h is not a legal PCI vendor id. But apparently some SPARC 140 # firmware creates the node with this id. Not sure why, possibly it is 141 # a firmware bug, possibly it was intended to prevent the driver from 142 # being used with 3rd party NICs. Whatever the reason, it isn't relevant 143 # anymore, but we still have to support the old node. 144 # 145 check_add_drv \ 146 -b "$BASEDIR" \ 147 -i '"pci128h,9102" "pci108e,9102" "pci1282,9102"' \ 148 dmfe 149