3 # Copyright (c) 2014 Juniper Networks, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # Convert a NIC driver to use the procdural API.
32 # It doesn't take care of all the # cases yet,
33 # but still does about 95% of work.
35 # Author: Sreekanth Rupavatharam
40 echo " $0 <driver source (e.g., if_em.c)>";
44 # XXX - This needs to change if the data structure uses different name
79 # Handle the case where $__ifp__->if_blah = XX;
81 set=`echo $line| grep "$__ifp__->.* = "`
84 word
=`echo $line | awk -F "if_" ' { print $2 }' | awk -F" =" '{ print $1 }'`
85 value
=`echo $line | awk -F "=" '{ print $2 }' | sed -e 's/;//g'`
86 new
=`echo if_set$word"\($__ifp__,"$value");"`
87 new
=`echo $new | sed -e 's/&/\\\&/'`
88 old
=`echo $line|sed -e 's/^[ ]*//'`
89 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
97 inc
=`echo $line | grep "$__ifp__->.*++\|++$__ifp__->.*"`
100 word
=`echo $line | awk -F"if_" '{ print $2 }'|awk -F"\+" '{ print $1}'`
102 old
=`echo $line|sed -e 's/^[ ]*//'`
103 new
=`echo if_inc$word"\($__ifp__,"$value");"`
104 new
=`echo $new | sed -e 's/&/\\\&/'`
105 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
113 add
=`echo $line|grep "$__ifp__->.*+= "`
116 word
=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'`
117 value
=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'`
118 new
=`echo if_inc$word"\($__ifp__,$value);"`
119 new
=`echo $new | sed -e 's/&/\\\&/'`
120 old
=`echo $line|sed -e 's/^[ ]*//'`
121 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
130 or
=`echo $line|grep "$__ifp__->.*|= "`
133 word
=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'`
134 value
=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'`
135 new
=`echo if_set${word}bit"($__ifp__,$value, 0);"`
136 new
=`echo $new | sed -e 's/&/\\\&/'`
137 #line=`echo $line|sed -e 's/&/\\&/'`
138 old
=`echo $line|sed -e 's/^[ ]*//'`
139 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
148 or
=`echo $line|grep "$__ifp__->.*&= "`
151 word
=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'`
152 value
=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'`
153 value
=`echo $value | sed -e's/~//g'`
154 new
=`echo if_set${word}bit"\($__ifp__, 0,$value);"`
155 new
=`echo $new | sed -e 's/&/\\\&/'`
156 old
=`echo $line|sed -e 's/^[ ]*//'`
157 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
166 if [ ! -z `echo $line | grep "\^="` ]
168 line
=`echo $line | sed -e 's/'"$__ifp__"'->if_\(.*\) ^=\(.*\);/if_toggle\1('"$__ifp__"',\2);/g'`
175 # XXX - this needs updating
178 get
=`echo $line | grep "if_capabilities\|if_flags\|if_softc\|if_capenable\|if_mtu\|if_drv_flags"`
181 word
=`echo $line |awk -F"$__ifp__->if_" '{ print $2 }' | \
182 sed -e's/[^a-zA-Z0-9_]/\@/'|awk -F"\@" '{ print $1}'`
183 old
=`echo "$__ifp__->if_"${word}`
184 new
=`echo "if_get"${word}"($__ifp__)"`
185 new
=`echo $new | sed -e 's/&/\\\&/'`
186 line
=`echo $line| sed -e's/'$old'/'$new'/g'`
198 line
=`echo $line | sed -e 's/'"$orig"'\(.*\)/'"$new"'\1/g'`
202 # Handle special cases which do not fall under regular patterns
206 replace_str
$line "(\*$__ifp__->if_input)" "if_input"
207 replace_str
$line "if_setinit" "if_setinitfn"
208 replace_str
$line "if_setioctl" "if_setioctlfn"
209 replace_str
$line "if_getdrv_flags" "if_getdrvflags"
210 replace_str
$line "if_setdrv_flagsbit" "if_setdrvflagbits"
211 replace_str
$line "if_setstart" "if_setstartfn"
212 replace_str
$line "if_sethwassistbit" "if_sethwassistbits"
213 replace_str
$line "ifmedia_init" "ifmedia_init_drv"
214 replace_str
$line "IFQ_DRV_IS_EMPTY(&$__ifp__->if_snd)" "if_sendq_empty($__ifp__)"
215 replace_str
$line "IFQ_DRV_PREPEND(&$__ifp__->if_snd" "if_sendq_prepend($__ifp__"
216 replace_str
$line "IFQ_SET_READY(&ifp->if_snd)" "if_setsendqready($__ifp__)"
217 line
=`echo $line | sed -e 's/IFQ_SET_MAXLEN(&'$__ifp__'->if_snd, \(.*\))/if_setsendqlen('$__ifp__', \1)/g'`
218 line
=`echo $line | sed -e 's/IFQ_DRV_DEQUEUE(&'$__ifp__'->if_snd, \(.*\))/\1 = if_dequeue('$__ifp__')/g'`
227 echo -n "Conversion for $file started, please wait: "
228 FAIL_PAT
="XXX - DRVAPI"
230 cat $1 |
while read -r line
232 count
=`expr $count + 1`
234 pat
=`echo $line | grep "$__ifp__->"`
235 while [ "$pat" != "" ]
237 pat
=`echo $line | grep "$__ifp__->"`
238 if [ ! -z `echo $pat | grep "$FAIL_PAT"` ]
280 if [ ! -z `echo $line | grep "$__ifp__->"` ]
282 line
=`echo $line | sed -e 's:$: \/* '${FAIL_PAT}' *\/:g'`
285 line
=`echo "$line" | sed -e 's:VLAN_CAPABILITIES('$__ifp__'):if_vlancap('$__ifp__'):g'`
286 # Replace the ifnet * with if_t
287 if [ ! -z `echo $line | grep "struct ifnet"` ]
289 line
=`echo $line | sed -e 's/struct ifnet[ \t]*\*/if_t /g'`
291 echo "$line" >> $file.tmp
294 count
=`grep $FAIL_PAT $file.tmp | wc -l`
297 echo "$count lines could not be converted to DRVAPI"
298 echo "Look for /* $FAIL_PAT */ in the converted file"
300 echo "original $file has been moved to $file.orig"